2 * arch/arm/mach-pnx4008/pm.c
4 * Power Management driver for PNX4008
6 * Authors: Vitaly Wool, Dmitry Chigirev <source@mvista.com>
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
15 #include <linux/rtc.h>
16 #include <linux/sched.h>
17 #include <linux/proc_fs.h>
19 #include <linux/delay.h>
20 #include <linux/clk.h>
23 #include <asm/mach-types.h>
24 #include <asm/cacheflush.h>
25 #include <asm/arch/pm.h>
26 #include <asm/arch/clock.h>
28 #define SRAM_VA IO_ADDRESS(PNX4008_IRAM_BASE)
30 static void *saved_sram;
32 static struct clk *pll4_clk;
34 static inline void pnx4008_standby(void)
36 void (*pnx4008_cpu_standby_ptr) (void);
41 clk_disable(pll4_clk);
43 /*saving portion of SRAM to be used by suspend function. */
44 memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_standby_sz);
46 /*make sure SRAM copy gets physically written into SDRAM.
47 SDRAM will be placed into self-refresh during power down */
50 /*copy suspend function into SRAM */
51 memcpy((void *)SRAM_VA, pnx4008_cpu_standby, pnx4008_cpu_standby_sz);
54 pnx4008_cpu_standby_ptr = (void *)SRAM_VA;
55 pnx4008_cpu_standby_ptr();
57 /*restoring portion of SRAM that was used by suspend function */
58 memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_standby_sz);
66 static inline void pnx4008_suspend(void)
68 void (*pnx4008_cpu_suspend_ptr) (void);
73 clk_disable(pll4_clk);
75 __raw_writel(0xffffffff, START_INT_RSR_REG(SE_PIN_BASE_INT));
76 __raw_writel(0xffffffff, START_INT_RSR_REG(SE_INT_BASE_INT));
78 /*saving portion of SRAM to be used by suspend function. */
79 memcpy(saved_sram, (void *)SRAM_VA, pnx4008_cpu_suspend_sz);
81 /*make sure SRAM copy gets physically written into SDRAM.
82 SDRAM will be placed into self-refresh during power down */
85 /*copy suspend function into SRAM */
86 memcpy((void *)SRAM_VA, pnx4008_cpu_suspend, pnx4008_cpu_suspend_sz);
89 pnx4008_cpu_suspend_ptr = (void *)SRAM_VA;
90 pnx4008_cpu_suspend_ptr();
92 /*restoring portion of SRAM that was used by suspend function */
93 memcpy((void *)SRAM_VA, saved_sram, pnx4008_cpu_suspend_sz);
101 static int pnx4008_pm_enter(suspend_state_t state)
104 case PM_SUSPEND_STANDBY:
110 case PM_SUSPEND_DISK:
119 * Called after processes are frozen, but before we shut down devices.
121 static int pnx4008_pm_prepare(suspend_state_t state)
124 case PM_SUSPEND_STANDBY:
128 case PM_SUSPEND_DISK:
140 * Called after devices are re-setup, but before processes are thawed.
142 static int pnx4008_pm_finish(suspend_state_t state)
148 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
150 static struct pm_ops pnx4008_pm_ops = {
151 .prepare = pnx4008_pm_prepare,
152 .enter = pnx4008_pm_enter,
153 .finish = pnx4008_pm_finish,
156 static int __init pnx4008_pm_init(void)
158 u32 sram_size_to_allocate;
160 pll4_clk = clk_get(0, "ck_pll4");
161 if (IS_ERR(pll4_clk)) {
163 "PM Suspend cannot acquire ARM(PLL4) clock control\n");
164 return PTR_ERR(pll4_clk);
167 if (pnx4008_cpu_standby_sz > pnx4008_cpu_suspend_sz)
168 sram_size_to_allocate = pnx4008_cpu_standby_sz;
170 sram_size_to_allocate = pnx4008_cpu_suspend_sz;
172 saved_sram = kmalloc(sram_size_to_allocate, GFP_ATOMIC);
175 "PM Suspend: cannot allocate memory to save portion of SRAM\n");
180 pm_set_ops(&pnx4008_pm_ops);
184 late_initcall(pnx4008_pm_init);