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>
17 #include <asm/mach-types.h>
19 #include <asm/arch/pxa-regs.h>
21 #ifdef CONFIG_PXA27x // workaround for Errata 50
22 #define MDREFR_KDIV 0x200a4000 // all banks
23 #define CCCR_SLEEP 0xC0000107 // L=7 2N=2 A=0 PPDIS=1 CPDIS=1
31 * Forces CPU into sleep state.
33 * r0 = value for PWRMODE M field for desired sleep state
36 ENTRY(pxa_cpu_suspend)
41 stmfd sp!, {r2 - r12, lr} @ save registers on stack
43 @ get coprocessor registers
44 mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
45 mrc p15, 0, r4, c15, c1, 0 @ CP access reg
46 mrc p15, 0, r5, c13, c0, 0 @ PID
47 mrc p15, 0, r6, c3, c0, 0 @ domain ID
48 mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
49 mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg
50 mrc p15, 0, r9, c1, c0, 0 @ control reg
52 bic r3, r3, #2 @ clear frequency change bit
54 #ifndef CONFIG_PXA_SUSPEND_SAVE_EXTRA_REGS
55 @ store them plus current virtual stack ptr on stack
63 @ store CP registers, CCCR and current virtual stack ptr on stack
67 mov r5, r0 @ save sleep mode
68 @ preserve phys address of stack
71 ldr r1, =sleep_save_sp
75 bl xscale_flush_kern_cache_all
77 @ Put the processor to sleep
78 @ (also workaround for sighting 28071)
80 @ prepare value for sleep mode
81 mov r1, r5 @ sleep mode
83 @ prepare pointer to physical address 0 (virtual mapping in generic.c)
84 mov r2, #UNCACHED_PHYS_0
86 @ prepare SDRAM refresh settings
90 @ enable SDRAM self-refresh mode
91 orr r5, r5, #MDREFR_SLFRSH
94 @ set SDCLKx divide-by-2 bits (this is part of a workaround for Errata 50)
100 @ Intel PXA255 Specification Update notes problems
101 @ about suspending with PXBus operating above 133MHz
102 @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
104 @ We keep the change-down close to the actual suspend on SDRAM
105 @ as possible to eliminate messing about with the refresh clock
106 @ as the system will restore with the original speed settings
108 @ Ben Dooks, 13-Sep-2004
111 ldr r8, [r6] @ keep original value for resume
113 @ ensure x1 for run and turbo mode with memory clock
114 bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
115 orr r7, r7, #(1<<5) | (2<<7)
117 @ check that the memory frequency is within limits
118 and r14, r7, #CCCR_L_MASK
120 bicne r7, r7, #CCCR_L_MASK
121 orrne r7, r7, #1 @@ 99.53MHz
123 @ get ready for the change
125 @ note, turbo is not preserved over sleep so there is no
126 @ point in preserving it here. we save it on the stack with the
127 @ other CP registers instead.
129 mcr p14, 0, r0, c6, c0, 0
130 orr r0, r0, #2 @ initiate change bit
133 @ Intel PXA270 Specification Update notes problems sleeping
134 @ with core operating above 91 MHz
135 @ (see Errata 50, ...processor does not exit from sleep...)
138 ldr r8, [r6] @ keep original value for resume
140 ldr r7, =CCCR_SLEEP @ prepare CCCR sleep value
141 mov r0, #0x2 @ prepare value for CLKCFG
144 @ align execution to a cache line
151 @ All needed values are now in registers.
152 @ These last instructions should be in cache
154 #if defined(CONFIG_PXA25x) || defined(CONFIG_PXA27x)
155 @ initiate the frequency change...
157 mcr p14, 0, r0, c6, c0, 0
159 @ restore the original cpu speed value for resume
162 @ need 6 13-MHz cycles before changing PWRMODE
163 @ just set frequency to 91-MHz... 6*91/13 = 42
171 @ Intel PXA270 Specification Update notes problems performing
172 @ external accesses after SDRAM is put in self-refresh mode
173 @ (see Errata 39 ...hangs when entering self-refresh mode)
175 @ force address lines low by reading at physical address 0
178 @ put SDRAM into self-refresh
182 mcr p14, 0, r1, c7, c0, 0 @ PWRMODE
184 20: b 20b @ loop waiting for sleep
189 * entry point from bootloader into kernel during resume
191 * Note: Yes, part of the following code is located into the .data section.
192 * This is to allow sleep_save_sp to be accessed with a relative load
193 * while we can't rely on any MMU translation. We could have put
194 * sleep_save_sp in the .text section as well, but some setups might
195 * insist on it to be truly read-only.
200 ENTRY(pxa_cpu_resume)
201 # ifdef CONFIG_MACH_H4700
203 * The HX4700 contains newer Intel Strataflash that has all blocks
204 * locked on power-up. The mtd code does not support this yet, so I am
205 * putting the unlocking code here. During resume, we cannot do it
206 * from bootldr because bootldr is running from flash. Here, we are
207 * running from memory, and we can unlock the flash.
209 * Note that we have access to everything right here--the MMU is not
211 * Aric Blumer (aric email_at_sign sdgsystems period com)
214 ldr r0, =__machine_arch_type
215 ldr r1, =MACH_TYPE_H4700
216 sub r0, r0, #0x20000000
221 ldr r0, =0x40e00020 /* Set VPPEN */
225 ldr r0, =0x100000 /* We skip to 1MB offset so that we never
226 unlock the bootldr code */
227 ldr r2, =0x08000000 /* The end of the flash */
241 ldr r0, =0x40e0002c /* Clear vppen */
246 ldr r1, =0x00500050 /* Clear the status register */
252 mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
255 ldr r0, sleep_save_sp @ stack phys addr
256 ldr r2, =resume_after_mmu @ its absolute virtual address
257 #ifndef CONFIG_PXA_SUSPEND_SAVE_EXTRA_REGS
258 ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
260 ldmfd r0, {r3 - r10, sp} @ CP regs, stored CCCR + virt stack ptr
262 ldr r11, =0x41300000 @ restore CCCR in case the
263 str r10, [r11] @ bootloader overwrote it
267 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
268 mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
270 #ifdef CONFIG_XSCALE_CACHE_ERRATA
271 bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
274 mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
275 mcr p15, 0, r4, c15, c1, 0 @ CP access reg
276 mcr p15, 0, r5, c13, c0, 0 @ PID
277 mcr p15, 0, r6, c3, c0, 0 @ domain ID
278 mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
279 mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
280 b resume_turn_on_mmu @ cache align execution
284 mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
286 @ Let us ensure we jump to resume_after_mmu only when the mcr above
287 @ actually took effect. They call it the "cpwait" operation.
288 mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
289 sub pc, r2, r1, lsr #32 @ jump to virtual addr
295 .word 0 @ preserve stack phys ptr here
299 #ifdef CONFIG_XSCALE_CACHE_ERRATA
300 bl cpu_xscale_proc_init
303 #ifndef CONFIG_IWMMXT
306 ldmfd sp!, {r4 - r12, pc} @ return to caller