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/init.h>
14 #include <linux/module.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/pm.h>
23 #include <asm/arch/pxa-regs.h>
24 #include <asm/arch/pxa-pm_ll.h>
25 #include <asm/arch/lubbock.h>
26 #include <asm/mach/time.h>
34 #define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
35 #define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
37 #define RESTORE_GPLEVEL(n) do { \
38 GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
39 GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
43 * List of global PXA peripheral registers to preserve.
44 * More ones like CP and general purpose register values are preserved
45 * with the stack pointer in sleep.S.
47 enum { SLEEP_SAVE_START
= 0,
49 SLEEP_SAVE_GPLR0
, SLEEP_SAVE_GPLR1
, SLEEP_SAVE_GPLR2
, SLEEP_SAVE_GPLR3
,
50 SLEEP_SAVE_GPDR0
, SLEEP_SAVE_GPDR1
, SLEEP_SAVE_GPDR2
, SLEEP_SAVE_GPDR3
,
51 SLEEP_SAVE_GRER0
, SLEEP_SAVE_GRER1
, SLEEP_SAVE_GRER2
, SLEEP_SAVE_GRER3
,
52 SLEEP_SAVE_GFER0
, SLEEP_SAVE_GFER1
, SLEEP_SAVE_GFER2
, SLEEP_SAVE_GFER3
,
53 SLEEP_SAVE_PGSR0
, SLEEP_SAVE_PGSR1
, SLEEP_SAVE_PGSR2
, SLEEP_SAVE_PGSR3
,
55 SLEEP_SAVE_GAFR0_L
, SLEEP_SAVE_GAFR0_U
,
56 SLEEP_SAVE_GAFR1_L
, SLEEP_SAVE_GAFR1_U
,
57 SLEEP_SAVE_GAFR2_L
, SLEEP_SAVE_GAFR2_U
,
58 SLEEP_SAVE_GAFR3_L
, SLEEP_SAVE_GAFR3_U
,
67 SLEEP_SAVE_PWER
, SLEEP_SAVE_PCFR
, SLEEP_SAVE_PRER
,
68 SLEEP_SAVE_PFER
, SLEEP_SAVE_PKWR
,
77 static struct pxa_ll_pm_ops
*ll_ops
;
79 int pxa_pm_enter(suspend_state_t state
)
81 unsigned long sleep_save
[SLEEP_SAVE_SIZE
];
82 unsigned long checksum
= 0;
83 struct timespec delta
, rtc
;
85 extern void pxa_cpu_pm_enter(suspend_state_t state
);
86 extern void pxa_cpu_resume(void);
89 /* force any iWMMXt context to ram **/
90 iwmmxt_task_disable(NULL
);
93 /* preserve current time */
96 save_time_delta(&delta
, &rtc
);
98 SAVE(GPLR0
); SAVE(GPLR1
); SAVE(GPLR2
);
99 SAVE(GPDR0
); SAVE(GPDR1
); SAVE(GPDR2
);
100 SAVE(GRER0
); SAVE(GRER1
); SAVE(GRER2
);
101 SAVE(GFER0
); SAVE(GFER1
); SAVE(GFER2
);
102 SAVE(PGSR0
); SAVE(PGSR1
); SAVE(PGSR2
);
104 SAVE(GAFR0_L
); SAVE(GAFR0_U
);
105 SAVE(GAFR1_L
); SAVE(GAFR1_U
);
106 SAVE(GAFR2_L
); SAVE(GAFR2_U
);
110 SAVE(GPLR3
); SAVE(GPDR3
); SAVE(GRER3
); SAVE(GFER3
); SAVE(PGSR3
);
111 SAVE(GAFR3_L
); SAVE(GAFR3_U
);
112 SAVE(PWER
); SAVE(PCFR
); SAVE(PRER
);
113 SAVE(PFER
); SAVE(PKWR
);
122 /* Note: wake up source are set up in each machine specific files */
124 /* clear GPIO transition detect bits */
125 GEDR0
= GEDR0
; GEDR1
= GEDR1
; GEDR2
= GEDR2
;
130 /* Clear sleep reset status */
133 /* Set resume return address */
134 PSPR
= virt_to_phys(pxa_cpu_resume
);
136 /* If we have special sus/res logic, use it */
137 if(ll_ops
&& ll_ops
->suspend
) {
138 extern void pxa_cpu_resume(void);
139 ll_ops
->suspend(virt_to_phys(pxa_cpu_resume
));
142 /* before sleeping, calculate and save a checksum */
143 for (i
= 0; i
< SLEEP_SAVE_SIZE
- 1; i
++)
144 checksum
+= sleep_save
[i
];
145 sleep_save
[SLEEP_SAVE_CKSUM
] = checksum
;
148 pxa_cpu_pm_enter(state
);
152 /* after sleeping, validate the checksum */
154 for (i
= 0; i
< SLEEP_SAVE_SIZE
- 1; i
++)
155 checksum
+= sleep_save
[i
];
157 if(ll_ops
&& ll_ops
->resume
)
160 /* if invalid, display message and wait for a hardware reset */
161 if (checksum
!= sleep_save
[SLEEP_SAVE_CKSUM
]) {
162 #ifdef CONFIG_ARCH_LUBBOCK
163 LUB_HEXLED
= 0xbadbadc5;
166 pxa_cpu_pm_enter(state
);
169 /* ensure not to come back here if it wasn't intended */
172 /* restore registers */
173 RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
174 RESTORE(GPDR0
); RESTORE(GPDR1
); RESTORE(GPDR2
);
175 RESTORE(GAFR0_L
); RESTORE(GAFR0_U
);
176 RESTORE(GAFR1_L
); RESTORE(GAFR1_U
);
177 RESTORE(GAFR2_L
); RESTORE(GAFR2_U
);
178 RESTORE(GRER0
); RESTORE(GRER1
); RESTORE(GRER2
);
179 RESTORE(GFER0
); RESTORE(GFER1
); RESTORE(GFER2
);
180 RESTORE(PGSR0
); RESTORE(PGSR1
); RESTORE(PGSR2
);
184 RESTORE_GPLEVEL(3); RESTORE(GPDR3
);
185 RESTORE(GAFR3_L
); RESTORE(GAFR3_U
);
186 RESTORE(GRER3
); RESTORE(GFER3
); RESTORE(PGSR3
);
187 RESTORE(PWER
); RESTORE(PCFR
); RESTORE(PRER
);
188 RESTORE(PFER
); RESTORE(PKWR
);
191 PSSR
= PSSR_RDH
| PSSR_PH
;
201 /* restore current time */
203 restore_time_delta(&delta
, &rtc
);
206 printk(KERN_DEBUG
"*** made it back from resume\n");
212 EXPORT_SYMBOL_GPL(pxa_pm_enter
);
214 struct pxa_ll_pm_ops
*pxa_pm_set_ll_ops(struct pxa_ll_pm_ops
*new_ops
) {
215 struct pxa_ll_pm_ops
*old_ops
= ll_ops
;
219 EXPORT_SYMBOL(pxa_pm_set_ll_ops
);
221 unsigned long sleep_phys_sp(void *sp
)
223 return virt_to_phys(sp
);
227 * Called after processes are frozen, but before we shut down devices.
229 int pxa_pm_prepare(suspend_state_t state
)
231 extern int pxa_cpu_pm_prepare(suspend_state_t state
);
233 return pxa_cpu_pm_prepare(state
);
236 EXPORT_SYMBOL_GPL(pxa_pm_prepare
);
239 * Called after devices are re-setup, but before processes are thawed.
241 int pxa_pm_finish(suspend_state_t state
)
246 EXPORT_SYMBOL_GPL(pxa_pm_finish
);
249 * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
251 struct pm_ops pxa_pm_ops
= {
252 .pm_disk_mode
= PM_DISK_FIRMWARE
,
253 .prepare
= pxa_pm_prepare
,
254 .enter
= pxa_pm_enter
,
255 .finish
= pxa_pm_finish
,
257 EXPORT_SYMBOL(pxa_pm_ops
);
259 static int __init
pxa_pm_init(void)
261 pm_set_ops(&pxa_pm_ops
);
265 device_initcall(pxa_pm_init
);