2 * PXA250/210 Power Management Routines
4 * Original code for the SA11x0:
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
7 * Modified for the PXA250 by Nicolas Pitre:
8 * Copyright (c) 2002 Monta Vista Software, Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License.
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/suspend.h>
16 #include <linux/errno.h>
17 #include <linux/time.h>
19 #include <asm/hardware.h>
20 #include <asm/memory.h>
21 #include <asm/system.h>
22 #include <asm/arch/lubbock.h>
30 extern void pxa_cpu_suspend(void);
31 extern void pxa_cpu_resume(void);
33 #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
34 #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
36 #define RESTORE_GPLEVEL(n) do { \
37 GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
38 GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
42 * List of global PXA peripheral registers to preserve.
43 * More ones like CP and general purpose register values are preserved
44 * with the stack pointer in sleep.S.
46 enum { SLEEP_SAVE_START = 0,
48 SLEEP_SAVE_OSCR, SLEEP_SAVE_OIER,
49 SLEEP_SAVE_OSMR0, SLEEP_SAVE_OSMR1, SLEEP_SAVE_OSMR2, SLEEP_SAVE_OSMR3,
51 SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2,
52 SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2,
53 SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2,
54 SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2,
55 SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR1_L, SLEEP_SAVE_GAFR2_L,
56 SLEEP_SAVE_GAFR0_U, SLEEP_SAVE_GAFR1_U, SLEEP_SAVE_GAFR2_U,
67 static int pxa_pm_enter(u32 state)
69 unsigned long sleep_save[SLEEP_SAVE_SIZE];
70 unsigned long checksum = 0;
74 if (state != PM_SUSPEND_MEM)
77 /* preserve current time */
78 delta = xtime.tv_sec - RCNR;
80 /* save vital registers */
88 SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2);
89 SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2);
90 SAVE(GRER0); SAVE(GRER1); SAVE(GRER2);
91 SAVE(GFER0); SAVE(GFER1); SAVE(GFER2);
92 SAVE(GAFR0_L); SAVE(GAFR0_U);
93 SAVE(GAFR1_L); SAVE(GAFR1_U);
94 SAVE(GAFR2_L); SAVE(GAFR2_U);
102 /* Note: wake up source are set up in each machine specific files */
104 /* clear GPIO transition detect bits */
105 GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2;
107 /* Clear sleep reset status */
110 /* set resume return address */
111 PSPR = virt_to_phys(pxa_cpu_resume);
113 /* before sleeping, calculate and save a checksum */
114 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
115 checksum += sleep_save[i];
116 sleep_save[SLEEP_SAVE_CKSUM] = checksum;
121 /* after sleeping, validate the checksum */
123 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
124 checksum += sleep_save[i];
126 /* if invalid, display message and wait for a hardware reset */
127 if (checksum != sleep_save[SLEEP_SAVE_CKSUM]) {
128 #ifdef CONFIG_ARCH_LUBBOCK
129 LUB_HEXLED = 0xbadbadc5;
134 /* ensure not to come back here if it wasn't intended */
137 /* restore registers */
138 RESTORE(GAFR0_L); RESTORE(GAFR0_U);
139 RESTORE(GAFR1_L); RESTORE(GAFR1_U);
140 RESTORE(GAFR2_L); RESTORE(GAFR2_U);
141 RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
142 RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
143 RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2);
144 RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
146 PSSR = PSSR_RDH | PSSR_PH;
161 /* restore current time */
162 xtime.tv_sec = RCNR + delta;
165 printk(KERN_DEBUG "*** made it back from resume\n");
171 unsigned long sleep_phys_sp(void *sp)
173 return virt_to_phys(sp);
177 * Called after processes are frozen, but before we shut down devices.
179 static int pxa_pm_prepare(u32 state)
185 * Called after devices are re-setup, but before processes are thawed.
187 static int pxa_pm_finish(u32 state)
193 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
195 static struct pm_ops pxa_pm_ops = {
196 .pm_disk_mode = PM_DISK_FIRMWARE,
197 .prepare = pxa_pm_prepare,
198 .enter = pxa_pm_enter,
199 .finish = pxa_pm_finish,
202 static int __init pxa_pm_init(void)
204 pm_set_ops(&pxa_pm_ops);
208 late_initcall(pxa_pm_init);