Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-pnx4008/pm.c |
| 3 | * |
| 4 | * Power Management driver for PNX4008 |
| 5 | * |
| 6 | * Authors: Vitaly Wool, Dmitry Chigirev <source@mvista.com> |
| 7 | * |
| 8 | * 2005 (c) MontaVista Software, Inc. This file is licensed under |
| 9 | * the terms of the GNU General Public License version 2. This program |
| 10 | * is licensed "as is" without any warranty of any kind, whether express |
| 11 | * or implied. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/pm.h> |
| 15 | #include <linux/rtc.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/proc_fs.h> |
Rafael J. Wysocki | 95d9ffb | 2007-10-18 03:04:39 -0700 | [diff] [blame] | 18 | #include <linux/suspend.h> |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 22 | |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 23 | #include <asm/cacheflush.h> |
Russell King | 2781681 | 2009-11-21 11:43:33 +0000 | [diff] [blame^] | 24 | |
| 25 | #include <mach/hardware.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/pm.h> |
| 27 | #include <mach/clock.h> |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 28 | |
| 29 | #define SRAM_VA IO_ADDRESS(PNX4008_IRAM_BASE) |
| 30 | |
| 31 | static void *saved_sram; |
| 32 | |
| 33 | static struct clk *pll4_clk; |
| 34 | |
| 35 | static inline void pnx4008_standby(void) |
| 36 | { |
| 37 | void (*pnx4008_cpu_standby_ptr) (void); |
| 38 | |
| 39 | local_irq_disable(); |
| 40 | local_fiq_disable(); |
| 41 | |
| 42 | clk_disable(pll4_clk); |
| 43 | |
| 44 | /*saving portion of SRAM to be used by suspend function. */ |
| 45 | memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_standby_sz); |
| 46 | |
| 47 | /*make sure SRAM copy gets physically written into SDRAM. |
| 48 | SDRAM will be placed into self-refresh during power down */ |
| 49 | flush_cache_all(); |
| 50 | |
| 51 | /*copy suspend function into SRAM */ |
| 52 | memcpy((void *)SRAM_VA, pnx4008_cpu_standby, pnx4008_cpu_standby_sz); |
| 53 | |
| 54 | /*do suspend */ |
| 55 | pnx4008_cpu_standby_ptr = (void *)SRAM_VA; |
| 56 | pnx4008_cpu_standby_ptr(); |
| 57 | |
| 58 | /*restoring portion of SRAM that was used by suspend function */ |
| 59 | memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_standby_sz); |
| 60 | |
| 61 | clk_enable(pll4_clk); |
| 62 | |
| 63 | local_fiq_enable(); |
| 64 | local_irq_enable(); |
| 65 | } |
| 66 | |
| 67 | static inline void pnx4008_suspend(void) |
| 68 | { |
| 69 | void (*pnx4008_cpu_suspend_ptr) (void); |
| 70 | |
| 71 | local_irq_disable(); |
| 72 | local_fiq_disable(); |
| 73 | |
| 74 | clk_disable(pll4_clk); |
| 75 | |
| 76 | __raw_writel(0xffffffff, START_INT_RSR_REG(SE_PIN_BASE_INT)); |
| 77 | __raw_writel(0xffffffff, START_INT_RSR_REG(SE_INT_BASE_INT)); |
| 78 | |
| 79 | /*saving portion of SRAM to be used by suspend function. */ |
| 80 | memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_suspend_sz); |
| 81 | |
| 82 | /*make sure SRAM copy gets physically written into SDRAM. |
| 83 | SDRAM will be placed into self-refresh during power down */ |
| 84 | flush_cache_all(); |
| 85 | |
| 86 | /*copy suspend function into SRAM */ |
| 87 | memcpy((void *)SRAM_VA, pnx4008_cpu_suspend, pnx4008_cpu_suspend_sz); |
| 88 | |
| 89 | /*do suspend */ |
| 90 | pnx4008_cpu_suspend_ptr = (void *)SRAM_VA; |
| 91 | pnx4008_cpu_suspend_ptr(); |
| 92 | |
| 93 | /*restoring portion of SRAM that was used by suspend function */ |
| 94 | memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_suspend_sz); |
| 95 | |
| 96 | clk_enable(pll4_clk); |
| 97 | |
| 98 | local_fiq_enable(); |
| 99 | local_irq_enable(); |
| 100 | } |
| 101 | |
| 102 | static int pnx4008_pm_enter(suspend_state_t state) |
| 103 | { |
| 104 | switch (state) { |
| 105 | case PM_SUSPEND_STANDBY: |
| 106 | pnx4008_standby(); |
| 107 | break; |
| 108 | case PM_SUSPEND_MEM: |
| 109 | pnx4008_suspend(); |
| 110 | break; |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 115 | static int pnx4008_pm_valid(suspend_state_t state) |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 116 | { |
Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 117 | return (state == PM_SUSPEND_STANDBY) || |
| 118 | (state == PM_SUSPEND_MEM); |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 121 | static struct platform_suspend_ops pnx4008_pm_ops = { |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 122 | .enter = pnx4008_pm_enter, |
Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 123 | .valid = pnx4008_pm_valid, |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | static int __init pnx4008_pm_init(void) |
| 127 | { |
| 128 | u32 sram_size_to_allocate; |
| 129 | |
| 130 | pll4_clk = clk_get(0, "ck_pll4"); |
| 131 | if (IS_ERR(pll4_clk)) { |
| 132 | printk(KERN_ERR |
| 133 | "PM Suspend cannot acquire ARM(PLL4) clock control\n"); |
| 134 | return PTR_ERR(pll4_clk); |
| 135 | } |
| 136 | |
| 137 | if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz) |
| 138 | sram_size_to_allocate = pnx4008_cpu_standby_sz; |
| 139 | else |
| 140 | sram_size_to_allocate = pnx4008_cpu_suspend_sz; |
| 141 | |
| 142 | saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC); |
| 143 | if (!saved_sram) { |
| 144 | printk(KERN_ERR |
| 145 | "PM Suspend: cannot allocate memory to save portion of SRAM\n"); |
| 146 | clk_put(pll4_clk); |
| 147 | return -ENOMEM; |
| 148 | } |
| 149 | |
Rafael J. Wysocki | 26398a7 | 2007-10-18 03:04:40 -0700 | [diff] [blame] | 150 | suspend_set_ops(&pnx4008_pm_ops); |
Vitaly Wool | 78818e4 | 2006-05-16 11:54:37 +0100 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | late_initcall(pnx4008_pm_init); |