2 * linux/arch/arm/mach-omap2/sleep.S
6 * Karthik Dasu <karthik-dp@ti.com>
9 * Texas Instruments, <www.ti.com>
10 * Richard Woodruff <r-woodruff2@ti.com>
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.
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.
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,
27 #include <linux/linkage.h>
28 #include <asm/assembler.h>
30 #include <plat/control.h>
36 #define PM_PREPWSTST_CORE_V OMAP34XX_PRM_REGADDR(CORE_MOD, \
37 OMAP3430_PM_PREPWSTST)
38 #define PM_PREPWSTST_CORE_P 0x48306AE8
39 #define PM_PREPWSTST_MPU_V OMAP34XX_PRM_REGADDR(MPU_MOD, \
40 OMAP3430_PM_PREPWSTST)
41 #define PM_PWSTCTRL_MPU_P OMAP3430_PRM_BASE + MPU_MOD + PM_PWSTCTRL
42 #define CM_IDLEST1_CORE_V OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST1)
43 #define SRAM_BASE_P 0x40200000
44 #define CONTROL_STAT 0x480022F0
45 #define SCRATCHPAD_MEM_OFFS 0x310 /* Move this as correct place is
47 #define SCRATCHPAD_BASE_P (OMAP343X_CTRL_BASE + OMAP343X_CONTROL_MEM_WKUP\
48 + SCRATCHPAD_MEM_OFFS)
49 #define SDRC_POWER_V OMAP34XX_SDRC_REGADDR(SDRC_POWER)
50 #define SDRC_SYSCONFIG_P (OMAP343X_SDRC_BASE + SDRC_SYSCONFIG)
51 #define SDRC_MR_0_P (OMAP343X_SDRC_BASE + SDRC_MR_0)
52 #define SDRC_EMR2_0_P (OMAP343X_SDRC_BASE + SDRC_EMR2_0)
53 #define SDRC_MANUAL_0_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_0)
54 #define SDRC_MR_1_P (OMAP343X_SDRC_BASE + SDRC_MR_1)
55 #define SDRC_EMR2_1_P (OMAP343X_SDRC_BASE + SDRC_EMR2_1)
56 #define SDRC_MANUAL_1_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_1)
57 #define SDRC_DLLA_STATUS_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
58 #define SDRC_DLLA_CTRL_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
61 /* Function call to get the restore pointer for resume from OFF */
62 ENTRY(get_restore_pointer)
63 stmfd sp!, {lr} @ save registers on stack
65 ldmfd sp!, {pc} @ restore regs and return
66 ENTRY(get_restore_pointer_sz)
67 .word . - get_restore_pointer
70 /* Function call to get the restore pointer for for ES3 to resume from OFF */
71 ENTRY(get_es3_restore_pointer)
72 stmfd sp!, {lr} @ save registers on stack
74 ldmfd sp!, {pc} @ restore regs and return
75 ENTRY(get_es3_restore_pointer_sz)
76 .word . - get_es3_restore_pointer
79 ldr r4, sdrc_syscfg @ get config addr
80 ldr r5, [r4] @ get value
81 tst r5, #0x100 @ is part access blocked
83 biceq r5, r5, #0x100 @ clear bit if set
84 str r5, [r4] @ write back change
85 ldr r4, sdrc_mr_0 @ get config addr
86 ldr r5, [r4] @ get value
87 str r5, [r4] @ write back change
88 ldr r4, sdrc_emr2_0 @ get config addr
89 ldr r5, [r4] @ get value
90 str r5, [r4] @ write back change
91 ldr r4, sdrc_manual_0 @ get config addr
92 mov r5, #0x2 @ autorefresh command
93 str r5, [r4] @ kick off refreshes
94 ldr r4, sdrc_mr_1 @ get config addr
95 ldr r5, [r4] @ get value
96 str r5, [r4] @ write back change
97 ldr r4, sdrc_emr2_1 @ get config addr
98 ldr r5, [r4] @ get value
99 str r5, [r4] @ write back change
100 ldr r4, sdrc_manual_1 @ get config addr
101 mov r5, #0x2 @ autorefresh command
102 str r5, [r4] @ kick off refreshes
105 .word SDRC_SYSCONFIG_P
111 .word SDRC_MANUAL_0_P
117 .word SDRC_MANUAL_1_P
118 ENTRY(es3_sdrc_fix_sz)
119 .word . - es3_sdrc_fix
121 /* Function to call rom code to save secure ram context */
122 ENTRY(save_secure_ram_context)
123 stmfd sp!, {r1-r12, lr} @ save registers on stack
124 save_secure_ram_debug:
125 /* b save_secure_ram_debug */ @ enable to debug save code
126 adr r3, api_params @ r3 points to parameters
127 str r0, [r3,#0x4] @ r0 has sdram address
130 ldr r12, sram_phy_addr_mask
132 mov r0, #25 @ set service ID for PPA
133 mov r12, r0 @ copy secure service ID in r12
134 mov r1, #0 @ set task id for ROM code in r1
135 mov r2, #4 @ set some flags in r2, r6
137 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
138 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
139 .word 0xE1600071 @ call SMI monitor (smi #1)
144 ldmfd sp!, {r1-r12, pc}
150 .word 0x4, 0x0, 0x0, 0x1, 0x1
151 ENTRY(save_secure_ram_context_sz)
152 .word . - save_secure_ram_context
155 * Forces OMAP into idle state
157 * omap34xx_suspend() - This bit of code just executes the WFI
160 * Note: This code get's copied to internal SRAM at boot. When the OMAP
161 * wakes up it continues execution at the point it went to sleep.
163 ENTRY(omap34xx_cpu_suspend)
164 stmfd sp!, {r0-r12, lr} @ save registers on stack
166 /*b loop*/ @Enable to debug by stepping through code
167 /* r0 contains restore pointer in sdram */
168 /* r1 contains information about saving context */
169 ldr r4, sdrc_power @ read the SDRC_POWER register
170 ldr r5, [r4] @ read the contents of SDRC_POWER
171 orr r5, r5, #0x40 @ enable self refresh on idle req
172 str r5, [r4] @ write back to SDRC_POWER register
175 /* If context save is required, do that and execute wfi */
177 /* Data memory barrier and Data sync barrier */
179 mcr p15, 0, r1, c7, c10, 4
180 mcr p15, 0, r1, c7, c10, 5
182 wfi @ wait for interrupt
196 ldmfd sp!, {r0-r12, pc} @ restore regs and return
198 /*b restore_es3*/ @ Enable to debug restore code
199 ldr r5, pm_prepwstst_core_p
202 cmp r4, #0x0 @ Check if previous power state of CORE is OFF
206 ldr r2, es3_sdrc_fix_sz
209 ldmia r0!, {r3} @ val = *src
210 stmia r1!, {r3} @ *dst = val
211 subs r2, r2, #0x1 @ num_words--
216 /* b restore*/ @ Enable to debug restore code
217 /* Check what was the reason for mpu reset and store the reason in r9*/
218 /* 1 - Only L1 and logic lost */
219 /* 2 - Only L2 lost - In this case, we wont be here */
220 /* 3 - Both L1 and L2 lost */
221 ldr r1, pm_pwstctrl_mpu
224 cmp r2, #0x0 @ Check if target power state was OFF or RET
225 moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
226 movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
233 mov r0, #40 @ set service ID for PPA
234 mov r12, r0 @ copy secure Service ID in r12
235 mov r1, #0 @ set task id for ROM code in r1
236 mov r2, #4 @ set some flags in r2, r6
238 adr r3, l2_inv_api_params @ r3 points to dummy parameters
239 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
240 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
241 .word 0xE1600071 @ call SMI monitor (smi #1)
242 /* Write to Aux control register to set some bits */
243 mov r0, #42 @ 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
248 ldr r4, scratchpad_base
249 ldr r3, [r4, #0xBC] @ r3 points to parameters
250 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
251 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
252 .word 0xE1600071 @ call SMI monitor (smi #1)
258 /* Execute smi to invalidate L2 cache */
259 mov r12, #0x1 @ set up to invalide L2
260 smi: .word 0xE1600070 @ Call SMI monitor (smieq)
261 /* Write to Aux control register to set some bits */
262 ldr r4, scratchpad_base
266 .word 0xE1600070 @ Call SMI monitor (smieq)
269 /* Invalidate all instruction caches to PoU
270 * and flush branch target cache */
271 mcr p15, 0, r1, c7, c5, 0
273 ldr r4, scratchpad_base
282 /* Coprocessor access Control Register */
283 mcr p15, 0, r4, c1, c0, 2
286 MCR p15, 0, r5, c2, c0, 0
288 MCR p15, 0, r6, c2, c0, 1
289 /* Translation table base control register */
290 MCR p15, 0, r7, c2, c0, 2
291 /*domain access Control Register */
292 MCR p15, 0, r8, c3, c0, 0
293 /* data fault status Register */
294 MCR p15, 0, r9, c5, c0, 0
297 /* instruction fault status Register */
298 MCR p15, 0, r4, c5, c0, 1
299 /*Data Auxiliary Fault Status Register */
300 MCR p15, 0, r5, c5, c1, 0
301 /*Instruction Auxiliary Fault Status Register*/
302 MCR p15, 0, r6, c5, c1, 1
303 /*Data Fault Address Register */
304 MCR p15, 0, r7, c6, c0, 0
305 /*Instruction Fault Address Register*/
306 MCR p15, 0, r8, c6, c0, 2
309 /* user r/w thread and process ID */
310 MCR p15, 0, r4, c13, c0, 2
311 /* user ro thread and process ID */
312 MCR p15, 0, r5, c13, c0, 3
313 /*Privileged only thread and process ID */
314 MCR p15, 0, r6, c13, c0, 4
315 /* cache size selection */
316 MCR p15, 2, r7, c0, c0, 0
318 /* Data TLB lockdown registers */
319 MCR p15, 0, r4, c10, c0, 0
320 /* Instruction TLB lockdown registers */
321 MCR p15, 0, r5, c10, c0, 1
322 /* Secure or Nonsecure Vector Base Address */
323 MCR p15, 0, r6, c12, c0, 0
325 MCR p15, 0, r7, c13, c0, 0
327 MCR p15, 0, r8, c13, c0, 1
330 /* primary memory remap register */
331 MCR p15, 0, r4, c10, c2, 0
332 /*normal memory remap register */
333 MCR p15, 0, r5, c10, c2, 1
336 ldmia r3!,{r4} /*load CPSR from SDRAM*/
337 msr cpsr, r4 /*store cpsr */
339 /* Enabling MMU here */
340 mrc p15, 0, r7, c2, c0, 2 /* Read TTBRControl */
341 /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1*/
346 /* More work needs to be done to support N[0:2] value other than 0
347 * So looping here so that the error can be detected
351 mrc p15, 0, r2, c2, c0, 0
355 ldr r5, table_index_mask
356 and r4, r5 /* r4 = 31 to 20 bits of pc */
357 /* Extract the value to be written to table entry */
359 add r1, r1, r4 /* r1 has value to be written to table entry*/
360 /* Getting the address of table entry to modify */
362 add r2, r4 /* r2 has the location which needs to be modified */
363 /* Storing previous entry of location being modified */
364 ldr r5, scratchpad_base
367 /* Modify the table entry */
369 /* Storing address of entry being modified
370 * - will be restored after enabling MMU */
371 ldr r5, scratchpad_base
375 mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
376 mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
377 mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
378 mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
379 /* Restore control register but dont enable caches here*/
380 /* Caches will be enabled after restoring MMU table entry */
382 /* Store previous value of control register in scratchpad */
384 ldr r2, cache_pred_disable_mask
386 mcr p15, 0, r4, c1, c0, 0
388 ldmfd sp!, {r0-r12, pc} @ restore regs and return
390 /*b save_context_wfi*/ @ enable to debug save code
391 mov r8, r0 /* Store SDRAM address in r8 */
392 mrc p15, 0, r5, c1, c0, 1 @ Read Auxiliary Control Register
393 mov r4, #0x1 @ Number of parameters for restore call
395 /* Check what that target sleep state is:stored in r1*/
396 /* 1 - Only L1 and logic lost */
397 /* 2 - Only L2 lost */
398 /* 3 - Both L1 and L2 lost */
399 cmp r1, #0x2 /* Only L2 lost */
401 cmp r1, #0x1 /* L2 retained */
402 /* r9 stores whether to clean L2 or not*/
403 moveq r9, #0x0 /* Dont Clean L2 */
404 movne r9, #0x1 /* Clean L2 */
406 /* Store sp and spsr to SDRAM */
411 /* Save all ARM registers */
412 /* Coprocessor access control register */
413 mrc p15, 0, r6, c1, c0, 2
415 /* TTBR0, TTBR1 and Translation table base control */
416 mrc p15, 0, r4, c2, c0, 0
417 mrc p15, 0, r5, c2, c0, 1
418 mrc p15, 0, r6, c2, c0, 2
420 /* Domain access control register, data fault status register,
421 and instruction fault status register */
422 mrc p15, 0, r4, c3, c0, 0
423 mrc p15, 0, r5, c5, c0, 0
424 mrc p15, 0, r6, c5, c0, 1
426 /* Data aux fault status register, instruction aux fault status,
427 datat fault address register and instruction fault address register*/
428 mrc p15, 0, r4, c5, c1, 0
429 mrc p15, 0, r5, c5, c1, 1
430 mrc p15, 0, r6, c6, c0, 0
431 mrc p15, 0, r7, c6, c0, 2
433 /* user r/w thread and process ID, user r/o thread and process ID,
434 priv only thread and process ID, cache size selection */
435 mrc p15, 0, r4, c13, c0, 2
436 mrc p15, 0, r5, c13, c0, 3
437 mrc p15, 0, r6, c13, c0, 4
438 mrc p15, 2, r7, c0, c0, 0
440 /* Data TLB lockdown, instruction TLB lockdown registers */
441 mrc p15, 0, r5, c10, c0, 0
442 mrc p15, 0, r6, c10, c0, 1
444 /* Secure or non secure vector base address, FCSE PID, Context PID*/
445 mrc p15, 0, r4, c12, c0, 0
446 mrc p15, 0, r5, c13, c0, 0
447 mrc p15, 0, r6, c13, c0, 1
449 /* Primary remap, normal remap registers */
450 mrc p15, 0, r4, c10, c2, 0
451 mrc p15, 0, r5, c10, c2, 1
454 /* Store current cpsr*/
458 mrc p15, 0, r4, c1, c0, 0
459 /* save control register */
462 /* Clean Data or unified cache to POU*/
463 /* How to invalidate only L1 cache???? - #FIX_ME# */
464 /* mcr p15, 0, r11, c7, c11, 1 */
465 cmp r9, #1 /* Check whether L2 inval is required or not*/
469 mrc p15, 1, r0, c0, c0, 1
470 /* extract loc from clidr */
471 ands r3, r0, #0x7000000
472 /* left align loc bit field */
474 /* if loc is 0, then no need to clean */
476 /* start clean at cache level 0 */
479 /* work out 3x current cache level */
480 add r2, r10, r10, lsr #1
481 /* extract cache type bits from clidr*/
483 /* mask of the bits for current cache only */
485 /* see what cache we have at this level */
487 /* skip if no cache, or just i-cache */
489 /* select current cache level in cssr */
490 mcr p15, 2, r10, c0, c0, 0
491 /* isb to sych the new cssr&csidr */
493 /* read the new csidr */
494 mrc p15, 1, r1, c0, c0, 0
495 /* extract the length of the cache lines */
497 /* add 4 (line length offset) */
500 /* find maximum number on the way size */
501 ands r4, r4, r1, lsr #3
502 /* find bit position of way size increment */
505 /* extract max number of the index size*/
506 ands r7, r7, r1, lsr #13
509 /* create working copy of max way size*/
511 /* factor way and cache number into r11 */
512 orr r11, r10, r9, lsl r5
513 /* factor index number into r11 */
514 orr r11, r11, r7, lsl r2
515 /*clean & invalidate by set/way */
516 mcr p15, 0, r11, c7, c10, 2
517 /* decrement the way*/
520 /*decrement the index */
525 /* increment cache number */
529 /*swith back to cache level 0 */
531 /* select current cache level in cssr */
532 mcr p15, 2, r10, c0, c0, 0
535 /* Data memory barrier and Data sync barrier */
537 mcr p15, 0, r1, c7, c10, 4
538 mcr p15, 0, r1, c7, c10, 5
540 wfi @ wait for interrupt
552 /* restore regs and return */
553 ldmfd sp!, {r0-r12, pc}
555 /* Make sure SDRC accesses are ok */
557 ldr r4, cm_idlest1_core
567 /* Is dll in lock mode? */
568 ldr r4, sdrc_dlla_ctrl
572 /* wait till dll locks */
573 ldr r4, sdrc_dlla_status
581 .word CM_IDLEST1_CORE_V
583 .word SDRC_DLLA_STATUS_V
585 .word SDRC_DLLA_CTRL_V
587 .word PM_PREPWSTST_CORE_V
589 .word PM_PREPWSTST_CORE_P
591 .word PM_PREPWSTST_MPU_V
593 .word PM_PWSTCTRL_MPU_P
595 .word SCRATCHPAD_BASE_P
597 .word SRAM_BASE_P + 0x8000
612 cache_pred_disable_mask:
616 ENTRY(omap34xx_cpu_suspend_sz)
617 .word . - omap34xx_cpu_suspend