2 * SA11x0 Assembler Sleep/WakeUp Management Routines
4 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License.
11 * 2001-02-06: Cliff Brake Initial code
13 * 2001-08-29: Nicolas Pitre Simplified.
15 * 2002-05-27: Nicolas Pitre Revisited, more cleanup and simplification.
16 * Storage is on the stack now.
19 #include <linux/linkage.h>
20 #include <asm/assembler.h>
21 #include <asm/hardware.h>
30 * sa1100_cpu_suspend()
32 * Causes sa11x0 to enter sleep state
36 ENTRY(sa1100_cpu_suspend)
38 stmfd sp!, {r4 - r12, lr} @ save registers on stack
40 @ get coprocessor registers
41 mrc p15, 0, r4, c3, c0, 0 @ domain ID
42 mrc p15, 0, r5, c2, c0, 0 @ translation table base addr
43 mrc p15, 0, r6, c13, c0, 0 @ PID
44 mrc p15, 0, r7, c1, c0, 0 @ control reg
46 @ store them plus current virtual stack ptr on stack
50 @ preserve phys address of stack
53 ldr r1, =sleep_save_sp
56 @ clean data cache and invalidate WB
57 bl v4wb_flush_kern_cache_all
59 @ disable clock switching
60 mcr p15, 0, r1, c15, c2, 2
62 @ Adjust memory timing before lowering CPU clock
63 @ Clock speed adjustment without changing memory timing makes
64 @ CPU hang in some cases
67 orr r1, r1, #MDREFR_K1DB2
70 @ delay 90us and set CPU PLL to lowest speed
71 @ fixes resume problem on high speed SA1110
81 * SA1110 SDRAM controller workaround. register values:
90 * r7 = first MDREFR value
91 * r8 = second MDREFR value
94 * r11 = third MDREFR value
96 * r13 = PMCR value (1)
104 bic r3, r3, #FMsk(MSC_RT)
105 bic r3, r3, #FMsk(MSC_RT)<<16
108 bic r4, r4, #FMsk(MSC_RT)
109 bic r4, r4, #FMsk(MSC_RT)<<16
112 bic r5, r5, #FMsk(MSC_RT)
113 bic r5, r5, #FMsk(MSC_RT)<<16
118 bic r7, r7, #0x0000FF00
119 bic r7, r7, #0x000000F0
120 orr r8, r7, #MDREFR_SLFRSH
124 bic r10, r10, #(MDCNFG_DE0+MDCNFG_DE1)
125 bic r10, r10, #(MDCNFG_DE2+MDCNFG_DE3)
127 bic r11, r8, #MDREFR_SLFRSH
128 bic r11, r11, #MDREFR_E1PIN
134 b sa1110_sdram_controller_fix
137 sa1110_sdram_controller_fix:
139 @ Step 1 clear RT field of all MSCx registers
144 @ Step 2 clear DRI field in MDREFR
147 @ Step 3 set SLFRSH bit in MDREFR
150 @ Step 4 clear DE bis in MDCNFG
153 @ Step 5 clear DRAM refresh control register
156 @ Wow, now the hardware suspend request pins can be used, that makes them functional for
157 @ about 7 ns out of the entire time that the CPU is running!
159 @ Step 6 set force sleep bit in PMCR
163 20: b 20b @ loop waiting for sleep
166 * cpu_sa1100_resume()
168 * entry point from bootloader into kernel during resume
170 * Note: Yes, part of the following code is located into the .data section.
171 * This is to allow sleep_save_sp to be accessed with a relative load
172 * while we can't rely on any MMU translation. We could have put
173 * sleep_save_sp in the .text section as well, but some setups might
174 * insist on it to be truly read-only.
179 ENTRY(sa1100_cpu_resume)
180 mov r0, #PSR_F_BIT | PSR_I_BIT | MODE_SVC
181 msr cpsr_c, r0 @ set SVC, irqs off
183 ldr r0, sleep_save_sp @ stack phys addr
184 ldr r2, =resume_after_mmu @ its absolute virtual address
185 ldmfd r0, {r4 - r7, sp} @ CP regs + virt stack ptr
188 mcr p15, 0, r1, c8, c7, 0 @ flush I+D TLBs
189 mcr p15, 0, r1, c7, c7, 0 @ flush I&D cache
190 mcr p15, 0, r1, c9, c0, 0 @ invalidate RB
191 mcr p15, 0, r1, c9, c0, 5 @ allow user space to use RB
193 mcr p15, 0, r4, c3, c0, 0 @ domain ID
194 mcr p15, 0, r5, c2, c0, 0 @ translation table base addr
195 mcr p15, 0, r6, c13, c0, 0 @ PID
196 b resume_turn_on_mmu @ cache align execution
200 mcr p15, 0, r7, c1, c0, 0 @ turn on MMU, caches, etc.
202 mov pc, r2 @ jump to virtual addr
208 .word 0 @ preserve stack phys ptr here
212 mcr p15, 0, r1, c15, c1, 2 @ enable clock switching
213 ldmfd sp!, {r4 - r12, pc} @ return to caller