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/pxa-regs.h>
23 #include <asm/arch/lubbock.h>
24 #include <asm/mach/time.h>
32 extern void pxa_cpu_suspend(void);
33 extern void pxa_cpu_resume(void);
35 #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
36 #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
38 #define RESTORE_GPLEVEL(n) do { \
39 GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
40 GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
44 * List of global PXA peripheral registers to preserve.
45 * More ones like CP and general purpose register values are preserved
46 * with the stack pointer in sleep.S.
48 enum { SLEEP_SAVE_START = 0,
51 SLEEP_SAVE_OSMR0, SLEEP_SAVE_OSMR1, SLEEP_SAVE_OSMR2, SLEEP_SAVE_OSMR3,
53 SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2,
54 SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2,
55 SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2,
56 SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2,
57 SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR1_L, SLEEP_SAVE_GAFR2_L,
58 SLEEP_SAVE_GAFR0_U, SLEEP_SAVE_GAFR1_U, SLEEP_SAVE_GAFR2_U,
69 static int pxa_pm_enter(u32 state)
71 unsigned long sleep_save[SLEEP_SAVE_SIZE];
72 unsigned long checksum = 0;
73 struct timespec delta, rtc;
76 if (state != PM_SUSPEND_MEM)
79 /* preserve current time */
82 save_time_delta(&delta, &rtc);
84 /* save vital registers */
91 SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2);
92 SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2);
93 SAVE(GRER0); SAVE(GRER1); SAVE(GRER2);
94 SAVE(GFER0); SAVE(GFER1); SAVE(GFER2);
95 SAVE(GAFR0_L); SAVE(GAFR0_U);
96 SAVE(GAFR1_L); SAVE(GAFR1_U);
97 SAVE(GAFR2_L); SAVE(GAFR2_U);
105 /* Note: wake up source are set up in each machine specific files */
107 /* clear GPIO transition detect bits */
108 GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2;
110 /* Clear sleep reset status */
113 /* set resume return address */
114 PSPR = virt_to_phys(pxa_cpu_resume);
116 /* before sleeping, calculate and save a checksum */
117 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
118 checksum += sleep_save[i];
119 sleep_save[SLEEP_SAVE_CKSUM] = checksum;
124 /* after sleeping, validate the checksum */
126 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
127 checksum += sleep_save[i];
129 /* if invalid, display message and wait for a hardware reset */
130 if (checksum != sleep_save[SLEEP_SAVE_CKSUM]) {
131 #ifdef CONFIG_ARCH_LUBBOCK
132 LUB_HEXLED = 0xbadbadc5;
137 /* ensure not to come back here if it wasn't intended */
140 /* restore registers */
141 RESTORE(GAFR0_L); RESTORE(GAFR0_U);
142 RESTORE(GAFR1_L); RESTORE(GAFR1_U);
143 RESTORE(GAFR2_L); RESTORE(GAFR2_U);
144 RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
145 RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
146 RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2);
147 RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
149 PSSR = PSSR_RDH | PSSR_PH;
157 /* OSMR0 is the system timer: make sure OSCR is sufficiently behind */
158 OSCR = OSMR0 - LATCH;
166 /* restore current time */
168 restore_time_delta(&delta, &rtc);
171 printk(KERN_DEBUG "*** made it back from resume\n");
177 unsigned long sleep_phys_sp(void *sp)
179 return virt_to_phys(sp);
183 * Called after processes are frozen, but before we shut down devices.
185 static int pxa_pm_prepare(u32 state)
191 * Called after devices are re-setup, but before processes are thawed.
193 static int pxa_pm_finish(u32 state)
199 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
201 static struct pm_ops pxa_pm_ops = {
202 .pm_disk_mode = PM_DISK_FIRMWARE,
203 .prepare = pxa_pm_prepare,
204 .enter = pxa_pm_enter,
205 .finish = pxa_pm_finish,
208 static int __init pxa_pm_init(void)
210 pm_set_ops(&pxa_pm_ops);
214 late_initcall(pxa_pm_init);