blob: f33d0c4a96d687ad1e31ce9547f2a4290407aaca [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Low-level PXA250/210 sleep/wakeUp support
3 *
4 * Initial SA1110 code:
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
6 *
7 * Adapted for PXA 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 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/linkage.h>
15#include <asm/assembler.h>
16#include <asm/hardware.h>
17
18#include <asm/arch/pxa-regs.h>
Russell King8785a8f2008-01-14 17:02:33 +000019#include <asm/arch/pxa2xx-regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Jeff Lackey41130d32005-04-25 23:38:55 +010021#define MDREFR_KDIV 0x200a4000 // all banks
22#define CCCR_SLEEP 0x00000107 // L=7 2N=2 A=0 PPDIS=0 CPDIS=0
Jeff Lackey41130d32005-04-25 23:38:55 +010023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 .text
25
Eric Miaob750a092007-07-18 11:40:13 +010026pxa_cpu_save_cp:
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 @ get coprocessor registers
28 mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
29 mrc p15, 0, r4, c15, c1, 0 @ CP access reg
30 mrc p15, 0, r5, c13, c0, 0 @ PID
31 mrc p15, 0, r6, c3, c0, 0 @ domain ID
32 mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
33 mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg
34 mrc p15, 0, r9, c1, c0, 0 @ control reg
35
36 bic r3, r3, #2 @ clear frequency change bit
37
38 @ store them plus current virtual stack ptr on stack
39 mov r10, sp
40 stmfd sp!, {r3 - r10}
41
Eric Miaob750a092007-07-18 11:40:13 +010042 mov pc, lr
43
44pxa_cpu_save_sp:
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 @ preserve phys address of stack
46 mov r0, sp
Russell King3b1904d2008-01-11 12:23:58 +000047 str lr, [sp, #-4]!
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 bl sleep_phys_sp
49 ldr r1, =sleep_save_sp
50 str r0, [r1]
Russell King3b1904d2008-01-11 12:23:58 +000051 ldr pc, [sp], #4
Eric Miaob750a092007-07-18 11:40:13 +010052
53/*
54 * pxa27x_cpu_suspend()
55 *
56 * Forces CPU into sleep state.
57 *
58 * r0 = value for PWRMODE M field for desired sleep state
59 */
60
61ENTRY(pxa27x_cpu_suspend)
62
63#ifndef CONFIG_IWMMXT
64 mra r2, r3, acc0
65#endif
66 stmfd sp!, {r2 - r12, lr} @ save registers on stack
67
68 bl pxa_cpu_save_cp
69
70 mov r5, r0 @ save sleep mode
71 bl pxa_cpu_save_sp
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 @ clean data cache
74 bl xscale_flush_kern_cache_all
75
76 @ Put the processor to sleep
77 @ (also workaround for sighting 28071)
78
79 @ prepare value for sleep mode
Todd Poynor80a18572005-10-28 16:25:01 +010080 mov r1, r5 @ sleep mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 @ prepare pointer to physical address 0 (virtual mapping in generic.c)
83 mov r2, #UNCACHED_PHYS_0
84
Jeff Lackey41130d32005-04-25 23:38:55 +010085 @ prepare SDRAM refresh settings
86 ldr r4, =MDREFR
87 ldr r5, [r4]
88
89 @ enable SDRAM self-refresh mode
90 orr r5, r5, #MDREFR_SLFRSH
91
Jeff Lackey41130d32005-04-25 23:38:55 +010092 @ set SDCLKx divide-by-2 bits (this is part of a workaround for Errata 50)
93 ldr r6, =MDREFR_KDIV
94 orr r5, r5, r6
Jeff Lackey41130d32005-04-25 23:38:55 +010095
Eric Miaob750a092007-07-18 11:40:13 +010096 @ Intel PXA270 Specification Update notes problems sleeping
97 @ with core operating above 91 MHz
98 @ (see Errata 50, ...processor does not exit from sleep...)
99
100 ldr r6, =CCCR
101 ldr r8, [r6] @ keep original value for resume
102
103 ldr r7, =CCCR_SLEEP @ prepare CCCR sleep value
104 mov r0, #0x2 @ prepare value for CLKCFG
105
106 @ align execution to a cache line
107 b pxa_cpu_do_suspend
108
109/*
110 * pxa27x_cpu_suspend()
111 *
112 * Forces CPU into sleep state.
113 *
114 * r0 = value for PWRMODE M field for desired sleep state
115 */
116
117ENTRY(pxa25x_cpu_suspend)
118 stmfd sp!, {r2 - r12, lr} @ save registers on stack
119
120 bl pxa_cpu_save_cp
121
122 mov r5, r0 @ save sleep mode
123 bl pxa_cpu_save_sp
124
125 @ clean data cache
126 bl xscale_flush_kern_cache_all
127
128 @ prepare value for sleep mode
129 mov r1, r5 @ sleep mode
130
131 @ prepare pointer to physical address 0 (virtual mapping in generic.c)
132 mov r2, #UNCACHED_PHYS_0
133
134 @ prepare SDRAM refresh settings
135 ldr r4, =MDREFR
136 ldr r5, [r4]
137
138 @ enable SDRAM self-refresh mode
139 orr r5, r5, #MDREFR_SLFRSH
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 @ Intel PXA255 Specification Update notes problems
142 @ about suspending with PXBus operating above 133MHz
143 @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
144 @
145 @ We keep the change-down close to the actual suspend on SDRAM
146 @ as possible to eliminate messing about with the refresh clock
147 @ as the system will restore with the original speed settings
148 @
149 @ Ben Dooks, 13-Sep-2004
150
151 ldr r6, =CCCR
152 ldr r8, [r6] @ keep original value for resume
153
154 @ ensure x1 for run and turbo mode with memory clock
155 bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
156 orr r7, r7, #(1<<5) | (2<<7)
157
158 @ check that the memory frequency is within limits
159 and r14, r7, #CCCR_L_MASK
160 teq r14, #1
161 bicne r7, r7, #CCCR_L_MASK
162 orrne r7, r7, #1 @@ 99.53MHz
163
164 @ get ready for the change
165
166 @ note, turbo is not preserved over sleep so there is no
167 @ point in preserving it here. we save it on the stack with the
168 @ other CP registers instead.
169 mov r0, #0
170 mcr p14, 0, r0, c6, c0, 0
171 orr r0, r0, #2 @ initiate change bit
Eric Miaob750a092007-07-18 11:40:13 +0100172 b pxa_cpu_do_suspend
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 .ltorg
175 .align 5
Eric Miaob750a092007-07-18 11:40:13 +0100176pxa_cpu_do_suspend:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 @ All needed values are now in registers.
179 @ These last instructions should be in cache
180
181 @ initiate the frequency change...
182 str r7, [r6]
183 mcr p14, 0, r0, c6, c0, 0
184
185 @ restore the original cpu speed value for resume
186 str r8, [r6]
187
Jeff Lackey41130d32005-04-25 23:38:55 +0100188 @ need 6 13-MHz cycles before changing PWRMODE
189 @ just set frequency to 91-MHz... 6*91/13 = 42
190
191 mov r0, #42
19210: subs r0, r0, #1
193 bne 10b
Jeff Lackey41130d32005-04-25 23:38:55 +0100194
195 @ Do not reorder...
196 @ Intel PXA270 Specification Update notes problems performing
197 @ external accesses after SDRAM is put in self-refresh mode
198 @ (see Errata 39 ...hangs when entering self-refresh mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 @ force address lines low by reading at physical address 0
201 ldr r3, [r2]
202
Jeff Lackey41130d32005-04-25 23:38:55 +0100203 @ put SDRAM into self-refresh
204 str r5, [r4]
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 @ enter sleep mode
Jeff Lackey41130d32005-04-25 23:38:55 +0100207 mcr p14, 0, r1, c7, c0, 0 @ PWRMODE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
20920: b 20b @ loop waiting for sleep
210
211/*
212 * cpu_pxa_resume()
213 *
214 * entry point from bootloader into kernel during resume
215 *
216 * Note: Yes, part of the following code is located into the .data section.
217 * This is to allow sleep_save_sp to be accessed with a relative load
218 * while we can't rely on any MMU translation. We could have put
219 * sleep_save_sp in the .text section as well, but some setups might
220 * insist on it to be truly read-only.
221 */
222
223 .data
224 .align 5
225ENTRY(pxa_cpu_resume)
Russell King801194e2006-06-25 12:01:48 +0100226 mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 msr cpsr_c, r0
228
229 ldr r0, sleep_save_sp @ stack phys addr
230 ldr r2, =resume_after_mmu @ its absolute virtual address
231 ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
232
233 mov r1, #0
234 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
235 mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
236
237#ifdef CONFIG_XSCALE_CACHE_ERRATA
238 bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
239#endif
240
241 mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
242 mcr p15, 0, r4, c15, c1, 0 @ CP access reg
243 mcr p15, 0, r5, c13, c0, 0 @ PID
244 mcr p15, 0, r6, c3, c0, 0 @ domain ID
245 mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
246 mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
247 b resume_turn_on_mmu @ cache align execution
248
249 .align 5
250resume_turn_on_mmu:
251 mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
252
253 @ Let us ensure we jump to resume_after_mmu only when the mcr above
254 @ actually took effect. They call it the "cpwait" operation.
255 mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
256 sub pc, r2, r1, lsr #32 @ jump to virtual addr
257 nop
258 nop
259 nop
260
261sleep_save_sp:
262 .word 0 @ preserve stack phys ptr here
263
264 .text
265resume_after_mmu:
266#ifdef CONFIG_XSCALE_CACHE_ERRATA
267 bl cpu_xscale_proc_init
268#endif
269 ldmfd sp!, {r2, r3}
Jeff Lackey41130d32005-04-25 23:38:55 +0100270#ifndef CONFIG_IWMMXT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 mar acc0, r2, r3
Jeff Lackey41130d32005-04-25 23:38:55 +0100272#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 ldmfd sp!, {r4 - r12, pc} @ return to caller