blob: e66dbc26add1f1f8291e4461b3b2f9a000e86d3c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PXA250/210 Power Management Routines
3 *
4 * Original code for the SA11x0:
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
6 *
7 * Modified for the PXA250 by Nicolas Pitre:
8 * Copyright (c) 2002 Monta Vista Software, Inc.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
Richard Purdie756c7b72005-11-06 15:03:23 +000014#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/suspend.h>
16#include <linux/errno.h>
17#include <linux/time.h>
18
19#include <asm/hardware.h>
20#include <asm/memory.h>
21#include <asm/system.h>
Richard Purdie756c7b72005-11-06 15:03:23 +000022#include <asm/arch/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/arch/pxa-regs.h>
24#include <asm/arch/lubbock.h>
25#include <asm/mach/time.h>
26
27
28/*
29 * Debug macros
30 */
31#undef DEBUG
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define SAVE(x) sleep_save[SLEEP_SAVE_##x] = x
34#define RESTORE(x) x = sleep_save[SLEEP_SAVE_##x]
35
36#define RESTORE_GPLEVEL(n) do { \
37 GPSR##n = sleep_save[SLEEP_SAVE_GPLR##n]; \
38 GPCR##n = ~sleep_save[SLEEP_SAVE_GPLR##n]; \
39} while (0)
40
41/*
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.
45 */
46enum { SLEEP_SAVE_START = 0,
47
48 SLEEP_SAVE_GPLR0, SLEEP_SAVE_GPLR1, SLEEP_SAVE_GPLR2, SLEEP_SAVE_GPLR3,
49 SLEEP_SAVE_GPDR0, SLEEP_SAVE_GPDR1, SLEEP_SAVE_GPDR2, SLEEP_SAVE_GPDR3,
50 SLEEP_SAVE_GRER0, SLEEP_SAVE_GRER1, SLEEP_SAVE_GRER2, SLEEP_SAVE_GRER3,
51 SLEEP_SAVE_GFER0, SLEEP_SAVE_GFER1, SLEEP_SAVE_GFER2, SLEEP_SAVE_GFER3,
52 SLEEP_SAVE_PGSR0, SLEEP_SAVE_PGSR1, SLEEP_SAVE_PGSR2, SLEEP_SAVE_PGSR3,
53
54 SLEEP_SAVE_GAFR0_L, SLEEP_SAVE_GAFR0_U,
55 SLEEP_SAVE_GAFR1_L, SLEEP_SAVE_GAFR1_U,
56 SLEEP_SAVE_GAFR2_L, SLEEP_SAVE_GAFR2_U,
57 SLEEP_SAVE_GAFR3_L, SLEEP_SAVE_GAFR3_U,
58
59 SLEEP_SAVE_PSTR,
60
61 SLEEP_SAVE_ICMR,
62 SLEEP_SAVE_CKEN,
63
Todd Poynor87754202005-06-03 20:52:27 +010064#ifdef CONFIG_PXA27x
65 SLEEP_SAVE_MDREFR,
66 SLEEP_SAVE_PWER, SLEEP_SAVE_PCFR, SLEEP_SAVE_PRER,
67 SLEEP_SAVE_PFER, SLEEP_SAVE_PKWR,
68#endif
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 SLEEP_SAVE_CKSUM,
71
72 SLEEP_SAVE_SIZE
73};
74
75
Richard Purdie756c7b72005-11-06 15:03:23 +000076int pxa_pm_enter(suspend_state_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 unsigned long sleep_save[SLEEP_SAVE_SIZE];
79 unsigned long checksum = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 int i;
Todd Poynor87754202005-06-03 20:52:27 +010081 extern void pxa_cpu_pm_enter(suspend_state_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83#ifdef CONFIG_IWMMXT
84 /* force any iWMMXt context to ram **/
Lennert Buytenhekafe4b252006-12-03 18:51:14 +010085 if (elf_hwcap & HWCAP_IWMMXT)
86 iwmmxt_task_disable(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 SAVE(GPLR0); SAVE(GPLR1); SAVE(GPLR2);
90 SAVE(GPDR0); SAVE(GPDR1); SAVE(GPDR2);
91 SAVE(GRER0); SAVE(GRER1); SAVE(GRER2);
92 SAVE(GFER0); SAVE(GFER1); SAVE(GFER2);
93 SAVE(PGSR0); SAVE(PGSR1); SAVE(PGSR2);
94
95 SAVE(GAFR0_L); SAVE(GAFR0_U);
96 SAVE(GAFR1_L); SAVE(GAFR1_U);
97 SAVE(GAFR2_L); SAVE(GAFR2_U);
98
99#ifdef CONFIG_PXA27x
Todd Poynor87754202005-06-03 20:52:27 +0100100 SAVE(MDREFR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 SAVE(GPLR3); SAVE(GPDR3); SAVE(GRER3); SAVE(GFER3); SAVE(PGSR3);
102 SAVE(GAFR3_L); SAVE(GAFR3_U);
Todd Poynor87754202005-06-03 20:52:27 +0100103 SAVE(PWER); SAVE(PCFR); SAVE(PRER);
104 SAVE(PFER); SAVE(PKWR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#endif
106
107 SAVE(ICMR);
108 ICMR = 0;
109
110 SAVE(CKEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 SAVE(PSTR);
112
113 /* Note: wake up source are set up in each machine specific files */
114
115 /* clear GPIO transition detect bits */
116 GEDR0 = GEDR0; GEDR1 = GEDR1; GEDR2 = GEDR2;
117#ifdef CONFIG_PXA27x
118 GEDR3 = GEDR3;
119#endif
120
121 /* Clear sleep reset status */
122 RCSR = RCSR_SMR;
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* before sleeping, calculate and save a checksum */
125 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
126 checksum += sleep_save[i];
127 sleep_save[SLEEP_SAVE_CKSUM] = checksum;
128
129 /* *** go zzz *** */
Todd Poynor87754202005-06-03 20:52:27 +0100130 pxa_cpu_pm_enter(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Russell King36c5ed22005-06-19 18:39:33 +0100132 cpu_init();
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 /* after sleeping, validate the checksum */
135 checksum = 0;
136 for (i = 0; i < SLEEP_SAVE_SIZE - 1; i++)
137 checksum += sleep_save[i];
138
139 /* if invalid, display message and wait for a hardware reset */
140 if (checksum != sleep_save[SLEEP_SAVE_CKSUM]) {
141#ifdef CONFIG_ARCH_LUBBOCK
142 LUB_HEXLED = 0xbadbadc5;
143#endif
144 while (1)
Todd Poynor87754202005-06-03 20:52:27 +0100145 pxa_cpu_pm_enter(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
148 /* ensure not to come back here if it wasn't intended */
149 PSPR = 0;
150
151 /* restore registers */
Lothar Wassmann1ee95302005-12-12 16:44:05 +0000152 RESTORE_GPLEVEL(0); RESTORE_GPLEVEL(1); RESTORE_GPLEVEL(2);
153 RESTORE(GPDR0); RESTORE(GPDR1); RESTORE(GPDR2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 RESTORE(GAFR0_L); RESTORE(GAFR0_U);
155 RESTORE(GAFR1_L); RESTORE(GAFR1_U);
156 RESTORE(GAFR2_L); RESTORE(GAFR2_U);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 RESTORE(GRER0); RESTORE(GRER1); RESTORE(GRER2);
158 RESTORE(GFER0); RESTORE(GFER1); RESTORE(GFER2);
159 RESTORE(PGSR0); RESTORE(PGSR1); RESTORE(PGSR2);
160
161#ifdef CONFIG_PXA27x
Todd Poynor87754202005-06-03 20:52:27 +0100162 RESTORE(MDREFR);
Lothar Wassmann1ee95302005-12-12 16:44:05 +0000163 RESTORE_GPLEVEL(3); RESTORE(GPDR3);
164 RESTORE(GAFR3_L); RESTORE(GAFR3_U);
165 RESTORE(GRER3); RESTORE(GFER3); RESTORE(PGSR3);
Todd Poynor87754202005-06-03 20:52:27 +0100166 RESTORE(PWER); RESTORE(PCFR); RESTORE(PRER);
167 RESTORE(PFER); RESTORE(PKWR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#endif
169
170 PSSR = PSSR_RDH | PSSR_PH;
171
172 RESTORE(CKEN);
173
174 ICLR = 0;
175 ICCR = 1;
176 RESTORE(ICMR);
177
178 RESTORE(PSTR);
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#ifdef DEBUG
181 printk(KERN_DEBUG "*** made it back from resume\n");
182#endif
183
184 return 0;
185}
186
Richard Purdie756c7b72005-11-06 15:03:23 +0000187EXPORT_SYMBOL_GPL(pxa_pm_enter);
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189unsigned long sleep_phys_sp(void *sp)
190{
191 return virt_to_phys(sp);
192}