blob: 5b978b8401c4da9439b124d7f6a107f4887b70b1 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * linux/arch/arm/mach-omap2/sleep.S
3 *
4 * (C) Copyright 2007
5 * Texas Instruments
6 * Karthik Dasu <karthik-dp@ti.com>
7 *
8 * (C) Copyright 2004
9 * Texas Instruments, <www.ti.com>
10 * Richard Woodruff <r-woodruff2@ti.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27#include <linux/linkage.h>
28#include <asm/assembler.h>
Jean Pihetb4b36fd2010-12-18 16:44:42 +010029#include <plat/sram.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070030#include <mach/io.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070031
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +020032#include "cm.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070033#include "prm.h"
34#include "sdrc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060035#include "control.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070036
Jean Pihetfe360e12010-12-18 16:44:43 +010037/*
38 * Registers access definitions
39 */
40#define SDRC_SCRATCHPAD_SEM_OFFS 0xc
41#define SDRC_SCRATCHPAD_SEM_V OMAP343X_SCRATCHPAD_REGADDR\
42 (SDRC_SCRATCHPAD_SEM_OFFS)
43#define PM_PREPWSTST_CORE_P OMAP3430_PRM_BASE + CORE_MOD +\
44 OMAP3430_PM_PREPWSTST
Abhijit Pagare37903002010-01-26 20:12:51 -070045#define PM_PWSTCTRL_MPU_P OMAP3430_PRM_BASE + MPU_MOD + OMAP2_PM_PWSTCTRL
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +020046#define CM_IDLEST1_CORE_V OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST1)
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -060047#define CM_IDLEST_CKGEN_V OMAP34XX_CM_REGADDR(PLL_MOD, CM_IDLEST)
Jean Pihetfe360e12010-12-18 16:44:43 +010048#define SRAM_BASE_P OMAP3_SRAM_PA
49#define CONTROL_STAT OMAP343X_CTRL_BASE + OMAP343X_CONTROL_STATUS
50#define CONTROL_MEM_RTA_CTRL (OMAP343X_CTRL_BASE +\
51 OMAP36XX_CONTROL_MEM_RTA_CTRL)
52
53/* Move this as correct place is available */
54#define SCRATCHPAD_MEM_OFFS 0x310
55#define SCRATCHPAD_BASE_P (OMAP343X_CTRL_BASE +\
56 OMAP343X_CONTROL_MEM_WKUP +\
57 SCRATCHPAD_MEM_OFFS)
Kevin Hilman8bd22942009-05-28 10:56:16 -070058#define SDRC_POWER_V OMAP34XX_SDRC_REGADDR(SDRC_POWER)
Tero Kristo0795a752008-10-13 17:58:50 +030059#define SDRC_SYSCONFIG_P (OMAP343X_SDRC_BASE + SDRC_SYSCONFIG)
60#define SDRC_MR_0_P (OMAP343X_SDRC_BASE + SDRC_MR_0)
61#define SDRC_EMR2_0_P (OMAP343X_SDRC_BASE + SDRC_EMR2_0)
62#define SDRC_MANUAL_0_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_0)
63#define SDRC_MR_1_P (OMAP343X_SDRC_BASE + SDRC_MR_1)
64#define SDRC_EMR2_1_P (OMAP343X_SDRC_BASE + SDRC_EMR2_1)
65#define SDRC_MANUAL_1_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_1)
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +020066#define SDRC_DLLA_STATUS_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
67#define SDRC_DLLA_CTRL_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
Kevin Hilman8bd22942009-05-28 10:56:16 -070068
Rajendra Nayaka89b6f02009-05-28 18:13:06 +053069
Jean Pihetd3cdfd22010-12-18 16:44:41 +010070/*
71 * API functions
72 */
Rajendra Nayaka89b6f02009-05-28 18:13:06 +053073
Kevin Hilman8bd22942009-05-28 10:56:16 -070074 .text
75/* Function call to get the restore pointer for resume from OFF */
76ENTRY(get_restore_pointer)
77 stmfd sp!, {lr} @ save registers on stack
78 adr r0, restore
79 ldmfd sp!, {pc} @ restore regs and return
80ENTRY(get_restore_pointer_sz)
Tero Kristo0795a752008-10-13 17:58:50 +030081 .word . - get_restore_pointer
Jean Pihet1e81bc02010-12-18 16:44:44 +010082
Nishanth Menon458e9992010-12-20 14:05:06 -060083 .text
84/* Function call to get the restore pointer for 3630 resume from OFF */
85ENTRY(get_omap3630_restore_pointer)
86 stmfd sp!, {lr} @ save registers on stack
87 adr r0, restore_3630
88 ldmfd sp!, {pc} @ restore regs and return
89ENTRY(get_omap3630_restore_pointer_sz)
90 .word . - get_omap3630_restore_pointer
Tero Kristo0795a752008-10-13 17:58:50 +030091
92 .text
Jean Pihet1e81bc02010-12-18 16:44:44 +010093/* Function call to get the restore pointer for ES3 to resume from OFF */
94ENTRY(get_es3_restore_pointer)
95 stmfd sp!, {lr} @ save registers on stack
96 adr r0, restore_es3
97 ldmfd sp!, {pc} @ restore regs and return
98ENTRY(get_es3_restore_pointer_sz)
99 .word . - get_es3_restore_pointer
100
101 .text
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600102/*
103 * L2 cache needs to be toggled for stable OFF mode functionality on 3630.
Jean Pihet1e81bc02010-12-18 16:44:44 +0100104 * This function sets up a flag that will allow for this toggling to take
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600105 * place on 3630. Hopefully some version in the future maynot need this
106 */
107ENTRY(enable_omap3630_toggle_l2_on_restore)
108 stmfd sp!, {lr} @ save registers on stack
109 /* Setup so that we will disable and enable l2 */
110 mov r1, #0x1
111 str r1, l2dis_3630
112 ldmfd sp!, {pc} @ restore regs and return
113
Tero Kristo27d59a42008-10-13 13:15:00 +0300114/* Function to call rom code to save secure ram context */
115ENTRY(save_secure_ram_context)
116 stmfd sp!, {r1-r12, lr} @ save registers on stack
Jean Pihetd3cdfd22010-12-18 16:44:41 +0100117
Tero Kristo27d59a42008-10-13 13:15:00 +0300118 adr r3, api_params @ r3 points to parameters
119 str r0, [r3,#0x4] @ r0 has sdram address
120 ldr r12, high_mask
121 and r3, r3, r12
122 ldr r12, sram_phy_addr_mask
123 orr r3, r3, r12
124 mov r0, #25 @ set service ID for PPA
125 mov r12, r0 @ copy secure service ID in r12
126 mov r1, #0 @ set task id for ROM code in r1
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +0200127 mov r2, #4 @ set some flags in r2, r6
Tero Kristo27d59a42008-10-13 13:15:00 +0300128 mov r6, #0xff
129 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
130 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
131 .word 0xE1600071 @ call SMI monitor (smi #1)
132 nop
133 nop
134 nop
135 nop
136 ldmfd sp!, {r1-r12, pc}
137sram_phy_addr_mask:
138 .word SRAM_BASE_P
139high_mask:
140 .word 0xffff
141api_params:
142 .word 0x4, 0x0, 0x0, 0x1, 0x1
143ENTRY(save_secure_ram_context_sz)
144 .word . - save_secure_ram_context
145
Kevin Hilman8bd22942009-05-28 10:56:16 -0700146/*
147 * Forces OMAP into idle state
148 *
149 * omap34xx_suspend() - This bit of code just executes the WFI
150 * for normal idles.
151 *
152 * Note: This code get's copied to internal SRAM at boot. When the OMAP
153 * wakes up it continues execution at the point it went to sleep.
154 */
155ENTRY(omap34xx_cpu_suspend)
156 stmfd sp!, {r0-r12, lr} @ save registers on stack
Jean Pihetd3cdfd22010-12-18 16:44:41 +0100157
Kevin Hilman8bd22942009-05-28 10:56:16 -0700158 /* r0 contains restore pointer in sdram */
159 /* r1 contains information about saving context */
160 ldr r4, sdrc_power @ read the SDRC_POWER register
161 ldr r5, [r4] @ read the contents of SDRC_POWER
162 orr r5, r5, #0x40 @ enable self refresh on idle req
163 str r5, [r4] @ write back to SDRC_POWER register
164
165 cmp r1, #0x0
166 /* If context save is required, do that and execute wfi */
167 bne save_context_wfi
168 /* Data memory barrier and Data sync barrier */
169 mov r1, #0
170 mcr p15, 0, r1, c7, c10, 4
171 mcr p15, 0, r1, c7, c10, 5
172
173 wfi @ wait for interrupt
174
175 nop
176 nop
177 nop
178 nop
179 nop
180 nop
181 nop
182 nop
183 nop
184 nop
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200185 bl wait_sdrc_ok
Kevin Hilman8bd22942009-05-28 10:56:16 -0700186
187 ldmfd sp!, {r0-r12, pc} @ restore regs and return
Tero Kristo0795a752008-10-13 17:58:50 +0300188restore_es3:
Tero Kristo0795a752008-10-13 17:58:50 +0300189 ldr r5, pm_prepwstst_core_p
190 ldr r4, [r5]
191 and r4, r4, #0x3
192 cmp r4, #0x0 @ Check if previous power state of CORE is OFF
193 bne restore
194 adr r0, es3_sdrc_fix
195 ldr r1, sram_base
196 ldr r2, es3_sdrc_fix_sz
197 mov r2, r2, ror #2
198copy_to_sram:
199 ldmia r0!, {r3} @ val = *src
200 stmia r1!, {r3} @ *dst = val
201 subs r2, r2, #0x1 @ num_words--
202 bne copy_to_sram
203 ldr r1, sram_base
204 blx r1
Nishanth Menon458e9992010-12-20 14:05:06 -0600205 b restore
206
207restore_3630:
Nishanth Menon458e9992010-12-20 14:05:06 -0600208 ldr r1, pm_prepwstst_core_p
209 ldr r2, [r1]
210 and r2, r2, #0x3
211 cmp r2, #0x0 @ Check if previous power state of CORE is OFF
212 bne restore
213 /* Disable RTA before giving control */
214 ldr r1, control_mem_rta
215 mov r2, #OMAP36XX_RTA_DISABLE
216 str r2, [r1]
217 /* Fall thru for the remaining logic */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700218restore:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700219 /* Check what was the reason for mpu reset and store the reason in r9*/
220 /* 1 - Only L1 and logic lost */
221 /* 2 - Only L2 lost - In this case, we wont be here */
222 /* 3 - Both L1 and L2 lost */
223 ldr r1, pm_pwstctrl_mpu
224 ldr r2, [r1]
225 and r2, r2, #0x3
226 cmp r2, #0x0 @ Check if target power state was OFF or RET
227 moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
228 movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
229 bne logic_l1_restore
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600230
231 ldr r0, l2dis_3630
232 cmp r0, #0x1 @ should we disable L2 on 3630?
233 bne skipl2dis
234 mrc p15, 0, r0, c1, c0, 1
235 bic r0, r0, #2 @ disable L2 cache
236 mcr p15, 0, r0, c1, c0, 1
237skipl2dis:
Tero Kristo27d59a42008-10-13 13:15:00 +0300238 ldr r0, control_stat
239 ldr r1, [r0]
240 and r1, #0x700
241 cmp r1, #0x300
242 beq l2_inv_gp
243 mov r0, #40 @ set service ID for PPA
244 mov r12, r0 @ copy secure Service ID in r12
245 mov r1, #0 @ set task id for ROM code in r1
246 mov r2, #4 @ set some flags in r2, r6
247 mov r6, #0xff
248 adr r3, l2_inv_api_params @ r3 points to dummy parameters
249 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
250 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
251 .word 0xE1600071 @ call SMI monitor (smi #1)
252 /* Write to Aux control register to set some bits */
253 mov r0, #42 @ set service ID for PPA
254 mov r12, r0 @ copy secure Service ID in r12
255 mov r1, #0 @ set task id for ROM code in r1
256 mov r2, #4 @ set some flags in r2, r6
257 mov r6, #0xff
Tero Kristoa087cad2009-11-12 12:07:20 +0200258 ldr r4, scratchpad_base
259 ldr r3, [r4, #0xBC] @ r3 points to parameters
Tero Kristo27d59a42008-10-13 13:15:00 +0300260 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
261 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
262 .word 0xE1600071 @ call SMI monitor (smi #1)
263
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200264#ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
265 /* Restore L2 aux control register */
266 @ set service ID for PPA
267 mov r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
268 mov r12, r0 @ copy service ID in r12
269 mov r1, #0 @ set task ID for ROM code in r1
270 mov r2, #4 @ set some flags in r2, r6
271 mov r6, #0xff
272 ldr r4, scratchpad_base
273 ldr r3, [r4, #0xBC]
274 adds r3, r3, #8 @ r3 points to parameters
275 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
276 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
277 .word 0xE1600071 @ call SMI monitor (smi #1)
278#endif
Tero Kristo27d59a42008-10-13 13:15:00 +0300279 b logic_l1_restore
280l2_inv_api_params:
281 .word 0x1, 0x00
Tero Kristo27d59a42008-10-13 13:15:00 +0300282l2_inv_gp:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700283 /* Execute smi to invalidate L2 cache */
284 mov r12, #0x1 @ set up to invalide L2
Tero Kristo27d59a42008-10-13 13:15:00 +0300285smi: .word 0xE1600070 @ Call SMI monitor (smieq)
286 /* Write to Aux control register to set some bits */
Tero Kristoa087cad2009-11-12 12:07:20 +0200287 ldr r4, scratchpad_base
288 ldr r3, [r4,#0xBC]
289 ldr r0, [r3,#4]
Tero Kristo27d59a42008-10-13 13:15:00 +0300290 mov r12, #0x3
291 .word 0xE1600070 @ Call SMI monitor (smieq)
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200292 ldr r4, scratchpad_base
293 ldr r3, [r4,#0xBC]
294 ldr r0, [r3,#12]
295 mov r12, #0x2
296 .word 0xE1600070 @ Call SMI monitor (smieq)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700297logic_l1_restore:
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600298 ldr r1, l2dis_3630
299 cmp r1, #0x1 @ Do we need to re-enable L2 on 3630?
300 bne skipl2reen
301 mrc p15, 0, r1, c1, c0, 1
302 orr r1, r1, #2 @ re-enable L2 cache
303 mcr p15, 0, r1, c1, c0, 1
304skipl2reen:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700305 mov r1, #0
306 /* Invalidate all instruction caches to PoU
307 * and flush branch target cache */
308 mcr p15, 0, r1, c7, c5, 0
309
310 ldr r4, scratchpad_base
311 ldr r3, [r4,#0xBC]
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200312 adds r3, r3, #16
Kevin Hilman8bd22942009-05-28 10:56:16 -0700313 ldmia r3!, {r4-r6}
314 mov sp, r4
315 msr spsr_cxsf, r5
316 mov lr, r6
317
318 ldmia r3!, {r4-r9}
319 /* Coprocessor access Control Register */
320 mcr p15, 0, r4, c1, c0, 2
321
322 /* TTBR0 */
323 MCR p15, 0, r5, c2, c0, 0
324 /* TTBR1 */
325 MCR p15, 0, r6, c2, c0, 1
326 /* Translation table base control register */
327 MCR p15, 0, r7, c2, c0, 2
328 /*domain access Control Register */
329 MCR p15, 0, r8, c3, c0, 0
330 /* data fault status Register */
331 MCR p15, 0, r9, c5, c0, 0
332
333 ldmia r3!,{r4-r8}
334 /* instruction fault status Register */
335 MCR p15, 0, r4, c5, c0, 1
336 /*Data Auxiliary Fault Status Register */
337 MCR p15, 0, r5, c5, c1, 0
338 /*Instruction Auxiliary Fault Status Register*/
339 MCR p15, 0, r6, c5, c1, 1
340 /*Data Fault Address Register */
341 MCR p15, 0, r7, c6, c0, 0
342 /*Instruction Fault Address Register*/
343 MCR p15, 0, r8, c6, c0, 2
344 ldmia r3!,{r4-r7}
345
346 /* user r/w thread and process ID */
347 MCR p15, 0, r4, c13, c0, 2
348 /* user ro thread and process ID */
349 MCR p15, 0, r5, c13, c0, 3
350 /*Privileged only thread and process ID */
351 MCR p15, 0, r6, c13, c0, 4
352 /* cache size selection */
353 MCR p15, 2, r7, c0, c0, 0
354 ldmia r3!,{r4-r8}
355 /* Data TLB lockdown registers */
356 MCR p15, 0, r4, c10, c0, 0
357 /* Instruction TLB lockdown registers */
358 MCR p15, 0, r5, c10, c0, 1
359 /* Secure or Nonsecure Vector Base Address */
360 MCR p15, 0, r6, c12, c0, 0
361 /* FCSE PID */
362 MCR p15, 0, r7, c13, c0, 0
363 /* Context PID */
364 MCR p15, 0, r8, c13, c0, 1
365
366 ldmia r3!,{r4-r5}
367 /* primary memory remap register */
368 MCR p15, 0, r4, c10, c2, 0
369 /*normal memory remap register */
370 MCR p15, 0, r5, c10, c2, 1
371
372 /* Restore cpsr */
373 ldmia r3!,{r4} /*load CPSR from SDRAM*/
374 msr cpsr, r4 /*store cpsr */
375
376 /* Enabling MMU here */
377 mrc p15, 0, r7, c2, c0, 2 /* Read TTBRControl */
378 /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1*/
379 and r7, #0x7
380 cmp r7, #0x0
381 beq usettbr0
382ttbr_error:
383 /* More work needs to be done to support N[0:2] value other than 0
384 * So looping here so that the error can be detected
385 */
386 b ttbr_error
387usettbr0:
388 mrc p15, 0, r2, c2, c0, 0
389 ldr r5, ttbrbit_mask
390 and r2, r5
391 mov r4, pc
392 ldr r5, table_index_mask
393 and r4, r5 /* r4 = 31 to 20 bits of pc */
394 /* Extract the value to be written to table entry */
395 ldr r1, table_entry
396 add r1, r1, r4 /* r1 has value to be written to table entry*/
397 /* Getting the address of table entry to modify */
398 lsr r4, #18
399 add r2, r4 /* r2 has the location which needs to be modified */
400 /* Storing previous entry of location being modified */
401 ldr r5, scratchpad_base
402 ldr r4, [r2]
403 str r4, [r5, #0xC0]
404 /* Modify the table entry */
405 str r1, [r2]
406 /* Storing address of entry being modified
407 * - will be restored after enabling MMU */
408 ldr r5, scratchpad_base
409 str r2, [r5, #0xC4]
410
411 mov r0, #0
412 mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
413 mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
414 mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
415 mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
416 /* Restore control register but dont enable caches here*/
417 /* Caches will be enabled after restoring MMU table entry */
418 ldmia r3!, {r4}
419 /* Store previous value of control register in scratchpad */
420 str r4, [r5, #0xC8]
421 ldr r2, cache_pred_disable_mask
422 and r4, r2
423 mcr p15, 0, r4, c1, c0, 0
424
425 ldmfd sp!, {r0-r12, pc} @ restore regs and return
426save_context_wfi:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700427 mov r8, r0 /* Store SDRAM address in r8 */
Tero Kristoa087cad2009-11-12 12:07:20 +0200428 mrc p15, 0, r5, c1, c0, 1 @ Read Auxiliary Control Register
429 mov r4, #0x1 @ Number of parameters for restore call
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200430 stmia r8!, {r4-r5} @ Push parameters for restore call
431 mrc p15, 1, r5, c9, c0, 2 @ Read L2 AUX ctrl register
432 stmia r8!, {r4-r5} @ Push parameters for restore call
Kevin Hilman8bd22942009-05-28 10:56:16 -0700433 /* Check what that target sleep state is:stored in r1*/
434 /* 1 - Only L1 and logic lost */
435 /* 2 - Only L2 lost */
436 /* 3 - Both L1 and L2 lost */
437 cmp r1, #0x2 /* Only L2 lost */
438 beq clean_l2
439 cmp r1, #0x1 /* L2 retained */
440 /* r9 stores whether to clean L2 or not*/
441 moveq r9, #0x0 /* Dont Clean L2 */
442 movne r9, #0x1 /* Clean L2 */
443l1_logic_lost:
444 /* Store sp and spsr to SDRAM */
445 mov r4, sp
446 mrs r5, spsr
447 mov r6, lr
448 stmia r8!, {r4-r6}
449 /* Save all ARM registers */
450 /* Coprocessor access control register */
451 mrc p15, 0, r6, c1, c0, 2
452 stmia r8!, {r6}
453 /* TTBR0, TTBR1 and Translation table base control */
454 mrc p15, 0, r4, c2, c0, 0
455 mrc p15, 0, r5, c2, c0, 1
456 mrc p15, 0, r6, c2, c0, 2
457 stmia r8!, {r4-r6}
458 /* Domain access control register, data fault status register,
459 and instruction fault status register */
460 mrc p15, 0, r4, c3, c0, 0
461 mrc p15, 0, r5, c5, c0, 0
462 mrc p15, 0, r6, c5, c0, 1
463 stmia r8!, {r4-r6}
464 /* Data aux fault status register, instruction aux fault status,
465 datat fault address register and instruction fault address register*/
466 mrc p15, 0, r4, c5, c1, 0
467 mrc p15, 0, r5, c5, c1, 1
468 mrc p15, 0, r6, c6, c0, 0
469 mrc p15, 0, r7, c6, c0, 2
470 stmia r8!, {r4-r7}
471 /* user r/w thread and process ID, user r/o thread and process ID,
472 priv only thread and process ID, cache size selection */
473 mrc p15, 0, r4, c13, c0, 2
474 mrc p15, 0, r5, c13, c0, 3
475 mrc p15, 0, r6, c13, c0, 4
476 mrc p15, 2, r7, c0, c0, 0
477 stmia r8!, {r4-r7}
478 /* Data TLB lockdown, instruction TLB lockdown registers */
479 mrc p15, 0, r5, c10, c0, 0
480 mrc p15, 0, r6, c10, c0, 1
481 stmia r8!, {r5-r6}
482 /* Secure or non secure vector base address, FCSE PID, Context PID*/
483 mrc p15, 0, r4, c12, c0, 0
484 mrc p15, 0, r5, c13, c0, 0
485 mrc p15, 0, r6, c13, c0, 1
486 stmia r8!, {r4-r6}
487 /* Primary remap, normal remap registers */
488 mrc p15, 0, r4, c10, c2, 0
489 mrc p15, 0, r5, c10, c2, 1
490 stmia r8!,{r4-r5}
491
492 /* Store current cpsr*/
493 mrs r2, cpsr
494 stmia r8!, {r2}
495
496 mrc p15, 0, r4, c1, c0, 0
497 /* save control register */
498 stmia r8!, {r4}
499clean_caches:
500 /* Clean Data or unified cache to POU*/
501 /* How to invalidate only L1 cache???? - #FIX_ME# */
502 /* mcr p15, 0, r11, c7, c11, 1 */
503 cmp r9, #1 /* Check whether L2 inval is required or not*/
504 bne skip_l2_inval
505clean_l2:
Richard Woodruff0bd40532010-12-20 14:05:03 -0600506 /*
507 * Jump out to kernel flush routine
508 * - reuse that code is better
509 * - it executes in a cached space so is faster than refetch per-block
510 * - should be faster and will change with kernel
511 * - 'might' have to copy address, load and jump to it
512 * - lr is used since we are running in SRAM currently.
513 */
514 ldr r1, kernel_flush
515 mov lr, pc
516 bx r1
517
Kevin Hilman8bd22942009-05-28 10:56:16 -0700518skip_l2_inval:
519 /* Data memory barrier and Data sync barrier */
520 mov r1, #0
521 mcr p15, 0, r1, c7, c10, 4
522 mcr p15, 0, r1, c7, c10, 5
523
524 wfi @ wait for interrupt
525 nop
526 nop
527 nop
528 nop
529 nop
530 nop
531 nop
532 nop
533 nop
534 nop
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200535 bl wait_sdrc_ok
Kevin Hilman8bd22942009-05-28 10:56:16 -0700536 /* restore regs and return */
537 ldmfd sp!, {r0-r12, pc}
538
Jean Pihet1e81bc02010-12-18 16:44:44 +0100539
540/*
541 * Internal functions
542 */
543
544 .text
545ENTRY(es3_sdrc_fix)
546 ldr r4, sdrc_syscfg @ get config addr
547 ldr r5, [r4] @ get value
548 tst r5, #0x100 @ is part access blocked
549 it eq
550 biceq r5, r5, #0x100 @ clear bit if set
551 str r5, [r4] @ write back change
552 ldr r4, sdrc_mr_0 @ get config addr
553 ldr r5, [r4] @ get value
554 str r5, [r4] @ write back change
555 ldr r4, sdrc_emr2_0 @ get config addr
556 ldr r5, [r4] @ get value
557 str r5, [r4] @ write back change
558 ldr r4, sdrc_manual_0 @ get config addr
559 mov r5, #0x2 @ autorefresh command
560 str r5, [r4] @ kick off refreshes
561 ldr r4, sdrc_mr_1 @ get config addr
562 ldr r5, [r4] @ get value
563 str r5, [r4] @ write back change
564 ldr r4, sdrc_emr2_1 @ get config addr
565 ldr r5, [r4] @ get value
566 str r5, [r4] @ write back change
567 ldr r4, sdrc_manual_1 @ get config addr
568 mov r5, #0x2 @ autorefresh command
569 str r5, [r4] @ kick off refreshes
570 bx lr
571
572sdrc_syscfg:
573 .word SDRC_SYSCONFIG_P
574sdrc_mr_0:
575 .word SDRC_MR_0_P
576sdrc_emr2_0:
577 .word SDRC_EMR2_0_P
578sdrc_manual_0:
579 .word SDRC_MANUAL_0_P
580sdrc_mr_1:
581 .word SDRC_MR_1_P
582sdrc_emr2_1:
583 .word SDRC_EMR2_1_P
584sdrc_manual_1:
585 .word SDRC_MANUAL_1_P
586ENTRY(es3_sdrc_fix_sz)
587 .word . - es3_sdrc_fix
588
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200589/* Make sure SDRC accesses are ok */
590wait_sdrc_ok:
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600591
592/* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this. */
593 ldr r4, cm_idlest_ckgen
594wait_dpll3_lock:
595 ldr r5, [r4]
596 tst r5, #1
597 beq wait_dpll3_lock
598
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200599 ldr r4, cm_idlest1_core
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600600wait_sdrc_ready:
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200601 ldr r5, [r4]
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600602 tst r5, #0x2
603 bne wait_sdrc_ready
604 /* allow DLL powerdown upon hw idle req */
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200605 ldr r4, sdrc_power
606 ldr r5, [r4]
607 bic r5, r5, #0x40
608 str r5, [r4]
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600609is_dll_in_lock_mode:
610
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200611 /* Is dll in lock mode? */
612 ldr r4, sdrc_dlla_ctrl
613 ldr r5, [r4]
614 tst r5, #0x4
615 bxne lr
616 /* wait till dll locks */
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600617wait_dll_lock_timed:
618 ldr r4, wait_dll_lock_counter
619 add r4, r4, #1
620 str r4, wait_dll_lock_counter
621 ldr r4, sdrc_dlla_status
622 mov r6, #8 /* Wait 20uS for lock */
623wait_dll_lock:
624 subs r6, r6, #0x1
625 beq kick_dll
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200626 ldr r5, [r4]
627 and r5, r5, #0x4
628 cmp r5, #0x4
629 bne wait_dll_lock
630 bx lr
Kevin Hilman8bd22942009-05-28 10:56:16 -0700631
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600632 /* disable/reenable DLL if not locked */
633kick_dll:
634 ldr r4, sdrc_dlla_ctrl
635 ldr r5, [r4]
636 mov r6, r5
637 bic r6, #(1<<3) /* disable dll */
638 str r6, [r4]
639 dsb
640 orr r6, r6, #(1<<3) /* enable dll */
641 str r6, [r4]
642 dsb
643 ldr r4, kick_counter
644 add r4, r4, #1
645 str r4, kick_counter
646 b wait_dll_lock_timed
647
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200648cm_idlest1_core:
649 .word CM_IDLEST1_CORE_V
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600650cm_idlest_ckgen:
651 .word CM_IDLEST_CKGEN_V
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200652sdrc_dlla_status:
653 .word SDRC_DLLA_STATUS_V
654sdrc_dlla_ctrl:
655 .word SDRC_DLLA_CTRL_V
Tero Kristo0795a752008-10-13 17:58:50 +0300656pm_prepwstst_core_p:
657 .word PM_PREPWSTST_CORE_P
Kevin Hilman8bd22942009-05-28 10:56:16 -0700658pm_pwstctrl_mpu:
659 .word PM_PWSTCTRL_MPU_P
660scratchpad_base:
661 .word SCRATCHPAD_BASE_P
Tero Kristo0795a752008-10-13 17:58:50 +0300662sram_base:
663 .word SRAM_BASE_P + 0x8000
Kevin Hilman8bd22942009-05-28 10:56:16 -0700664sdrc_power:
665 .word SDRC_POWER_V
Kevin Hilman8bd22942009-05-28 10:56:16 -0700666ttbrbit_mask:
667 .word 0xFFFFC000
668table_index_mask:
669 .word 0xFFF00000
670table_entry:
671 .word 0x00000C02
672cache_pred_disable_mask:
673 .word 0xFFFFE7FB
Tero Kristo27d59a42008-10-13 13:15:00 +0300674control_stat:
675 .word CONTROL_STAT
Nishanth Menon458e9992010-12-20 14:05:06 -0600676control_mem_rta:
677 .word CONTROL_MEM_RTA_CTRL
Richard Woodruff0bd40532010-12-20 14:05:03 -0600678kernel_flush:
679 .word v7_flush_dcache_all
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600680l2dis_3630:
681 .word 0
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600682 /*
683 * When exporting to userspace while the counters are in SRAM,
684 * these 2 words need to be at the end to facilitate retrival!
685 */
686kick_counter:
687 .word 0
688wait_dll_lock_counter:
689 .word 0
Kevin Hilman8bd22942009-05-28 10:56:16 -0700690ENTRY(omap34xx_cpu_suspend_sz)
691 .word . - omap34xx_cpu_suspend