2 * Low-level PXA250/210 sleep/wakeUp support
5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
7 * Adapted for PXA 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.
14 #include <linux/linkage.h>
15 #include <asm/assembler.h>
16 #include <asm/hardware.h>
18 #include <asm/arch/pxa-regs.h>
20 #ifdef CONFIG_PXA27x // workaround for Errata 50
21 #define MDREFR_KDIV 0x200a4000 // all banks
22 #define CCCR_SLEEP 0x00000107 // L=7 2N=2 A=0 PPDIS=0 CPDIS=0
30 * Forces CPU into sleep state.
32 * r0 = value for PWRMODE M field for desired sleep state
35 ENTRY(pxa_cpu_suspend)
40 stmfd sp!, {r2 - r12, lr} @ save registers on stack
42 @ get coprocessor registers
43 mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
44 mrc p15, 0, r4, c15, c1, 0 @ CP access reg
45 mrc p15, 0, r5, c13, c0, 0 @ PID
46 mrc p15, 0, r6, c3, c0, 0 @ domain ID
47 mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
48 mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg
49 mrc p15, 0, r9, c1, c0, 0 @ control reg
51 bic r3, r3, #2 @ clear frequency change bit
53 @ store them plus current virtual stack ptr on stack
57 mov r5, r0 @ save sleep mode
58 @ preserve phys address of stack
61 ldr r1, =sleep_save_sp
65 bl xscale_flush_kern_cache_all
67 @ Put the processor to sleep
68 @ (also workaround for sighting 28071)
70 @ prepare value for sleep mode
71 mov r1, r5 @ sleep mode
73 @ prepare pointer to physical address 0 (virtual mapping in generic.c)
74 mov r2, #UNCACHED_PHYS_0
76 @ prepare SDRAM refresh settings
80 @ enable SDRAM self-refresh mode
81 orr r5, r5, #MDREFR_SLFRSH
84 @ set SDCLKx divide-by-2 bits (this is part of a workaround for Errata 50)
90 @ Intel PXA255 Specification Update notes problems
91 @ about suspending with PXBus operating above 133MHz
92 @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
94 @ We keep the change-down close to the actual suspend on SDRAM
95 @ as possible to eliminate messing about with the refresh clock
96 @ as the system will restore with the original speed settings
98 @ Ben Dooks, 13-Sep-2004
101 ldr r8, [r6] @ keep original value for resume
103 @ ensure x1 for run and turbo mode with memory clock
104 bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
105 orr r7, r7, #(1<<5) | (2<<7)
107 @ check that the memory frequency is within limits
108 and r14, r7, #CCCR_L_MASK
110 bicne r7, r7, #CCCR_L_MASK
111 orrne r7, r7, #1 @@ 99.53MHz
113 @ get ready for the change
115 @ note, turbo is not preserved over sleep so there is no
116 @ point in preserving it here. we save it on the stack with the
117 @ other CP registers instead.
119 mcr p14, 0, r0, c6, c0, 0
120 orr r0, r0, #2 @ initiate change bit
123 @ Intel PXA270 Specification Update notes problems sleeping
124 @ with core operating above 91 MHz
125 @ (see Errata 50, ...processor does not exit from sleep...)
128 ldr r8, [r6] @ keep original value for resume
130 ldr r7, =CCCR_SLEEP @ prepare CCCR sleep value
131 mov r0, #0x2 @ prepare value for CLKCFG
134 @ align execution to a cache line
141 @ All needed values are now in registers.
142 @ These last instructions should be in cache
144 #if defined(CONFIG_PXA25x) || defined(CONFIG_PXA27x)
145 @ initiate the frequency change...
147 mcr p14, 0, r0, c6, c0, 0
149 @ restore the original cpu speed value for resume
152 @ need 6 13-MHz cycles before changing PWRMODE
153 @ just set frequency to 91-MHz... 6*91/13 = 42
161 @ Intel PXA270 Specification Update notes problems performing
162 @ external accesses after SDRAM is put in self-refresh mode
163 @ (see Errata 39 ...hangs when entering self-refresh mode)
165 @ force address lines low by reading at physical address 0
168 @ put SDRAM into self-refresh
172 mcr p14, 0, r1, c7, c0, 0 @ PWRMODE
174 20: b 20b @ loop waiting for sleep
179 * entry point from bootloader into kernel during resume
181 * Note: Yes, part of the following code is located into the .data section.
182 * This is to allow sleep_save_sp to be accessed with a relative load
183 * while we can't rely on any MMU translation. We could have put
184 * sleep_save_sp in the .text section as well, but some setups might
185 * insist on it to be truly read-only.
190 ENTRY(pxa_cpu_resume)
191 mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
194 ldr r0, sleep_save_sp @ stack phys addr
195 ldr r2, =resume_after_mmu @ its absolute virtual address
196 ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
199 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
200 mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
202 #ifdef CONFIG_XSCALE_CACHE_ERRATA
203 bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
206 mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
207 mcr p15, 0, r4, c15, c1, 0 @ CP access reg
208 mcr p15, 0, r5, c13, c0, 0 @ PID
209 mcr p15, 0, r6, c3, c0, 0 @ domain ID
210 mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
211 mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
212 b resume_turn_on_mmu @ cache align execution
216 mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
218 @ Let us ensure we jump to resume_after_mmu only when the mcr above
219 @ actually took effect. They call it the "cpwait" operation.
220 mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
221 sub pc, r2, r1, lsr #32 @ jump to virtual addr
227 .word 0 @ preserve stack phys ptr here
231 #ifdef CONFIG_XSCALE_CACHE_ERRATA
232 bl cpu_xscale_proc_init
235 #ifndef CONFIG_IWMMXT
238 ldmfd sp!, {r4 - r12, pc} @ return to caller