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 adr r3, write_aux_control_params @ r3 points to 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)
256 write_aux_control_params:
259 /* Execute smi to invalidate L2 cache */
260 mov r12, #0x1 @ set up to invalide L2
261 smi: .word 0xE1600070 @ Call SMI monitor (smieq)
262 /* Write to Aux control register to set some bits */
265 .word 0xE1600070 @ Call SMI monitor (smieq)
268 /* Invalidate all instruction caches to PoU
269 * and flush branch target cache */
270 mcr p15, 0, r1, c7, c5, 0
272 ldr r4, scratchpad_base
280 /* Coprocessor access Control Register */
281 mcr p15, 0, r4, c1, c0, 2
284 MCR p15, 0, r5, c2, c0, 0
286 MCR p15, 0, r6, c2, c0, 1
287 /* Translation table base control register */
288 MCR p15, 0, r7, c2, c0, 2
289 /*domain access Control Register */
290 MCR p15, 0, r8, c3, c0, 0
291 /* data fault status Register */
292 MCR p15, 0, r9, c5, c0, 0
295 /* instruction fault status Register */
296 MCR p15, 0, r4, c5, c0, 1
297 /*Data Auxiliary Fault Status Register */
298 MCR p15, 0, r5, c5, c1, 0
299 /*Instruction Auxiliary Fault Status Register*/
300 MCR p15, 0, r6, c5, c1, 1
301 /*Data Fault Address Register */
302 MCR p15, 0, r7, c6, c0, 0
303 /*Instruction Fault Address Register*/
304 MCR p15, 0, r8, c6, c0, 2
307 /* user r/w thread and process ID */
308 MCR p15, 0, r4, c13, c0, 2
309 /* user ro thread and process ID */
310 MCR p15, 0, r5, c13, c0, 3
311 /*Privileged only thread and process ID */
312 MCR p15, 0, r6, c13, c0, 4
313 /* cache size selection */
314 MCR p15, 2, r7, c0, c0, 0
316 /* Data TLB lockdown registers */
317 MCR p15, 0, r4, c10, c0, 0
318 /* Instruction TLB lockdown registers */
319 MCR p15, 0, r5, c10, c0, 1
320 /* Secure or Nonsecure Vector Base Address */
321 MCR p15, 0, r6, c12, c0, 0
323 MCR p15, 0, r7, c13, c0, 0
325 MCR p15, 0, r8, c13, c0, 1
328 /* primary memory remap register */
329 MCR p15, 0, r4, c10, c2, 0
330 /*normal memory remap register */
331 MCR p15, 0, r5, c10, c2, 1
334 ldmia r3!,{r4} /*load CPSR from SDRAM*/
335 msr cpsr, r4 /*store cpsr */
337 /* Enabling MMU here */
338 mrc p15, 0, r7, c2, c0, 2 /* Read TTBRControl */
339 /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1*/
344 /* More work needs to be done to support N[0:2] value other than 0
345 * So looping here so that the error can be detected
349 mrc p15, 0, r2, c2, c0, 0
353 ldr r5, table_index_mask
354 and r4, r5 /* r4 = 31 to 20 bits of pc */
355 /* Extract the value to be written to table entry */
357 add r1, r1, r4 /* r1 has value to be written to table entry*/
358 /* Getting the address of table entry to modify */
360 add r2, r4 /* r2 has the location which needs to be modified */
361 /* Storing previous entry of location being modified */
362 ldr r5, scratchpad_base
365 /* Modify the table entry */
367 /* Storing address of entry being modified
368 * - will be restored after enabling MMU */
369 ldr r5, scratchpad_base
373 mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
374 mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
375 mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
376 mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
377 /* Restore control register but dont enable caches here*/
378 /* Caches will be enabled after restoring MMU table entry */
380 /* Store previous value of control register in scratchpad */
382 ldr r2, cache_pred_disable_mask
384 mcr p15, 0, r4, c1, c0, 0
386 ldmfd sp!, {r0-r12, pc} @ restore regs and return
388 /*b save_context_wfi*/ @ enable to debug save code
389 mov r8, r0 /* Store SDRAM address in r8 */
390 /* Check what that target sleep state is:stored in r1*/
391 /* 1 - Only L1 and logic lost */
392 /* 2 - Only L2 lost */
393 /* 3 - Both L1 and L2 lost */
394 cmp r1, #0x2 /* Only L2 lost */
396 cmp r1, #0x1 /* L2 retained */
397 /* r9 stores whether to clean L2 or not*/
398 moveq r9, #0x0 /* Dont Clean L2 */
399 movne r9, #0x1 /* Clean L2 */
401 /* Store sp and spsr to SDRAM */
406 /* Save all ARM registers */
407 /* Coprocessor access control register */
408 mrc p15, 0, r6, c1, c0, 2
410 /* TTBR0, TTBR1 and Translation table base control */
411 mrc p15, 0, r4, c2, c0, 0
412 mrc p15, 0, r5, c2, c0, 1
413 mrc p15, 0, r6, c2, c0, 2
415 /* Domain access control register, data fault status register,
416 and instruction fault status register */
417 mrc p15, 0, r4, c3, c0, 0
418 mrc p15, 0, r5, c5, c0, 0
419 mrc p15, 0, r6, c5, c0, 1
421 /* Data aux fault status register, instruction aux fault status,
422 datat fault address register and instruction fault address register*/
423 mrc p15, 0, r4, c5, c1, 0
424 mrc p15, 0, r5, c5, c1, 1
425 mrc p15, 0, r6, c6, c0, 0
426 mrc p15, 0, r7, c6, c0, 2
428 /* user r/w thread and process ID, user r/o thread and process ID,
429 priv only thread and process ID, cache size selection */
430 mrc p15, 0, r4, c13, c0, 2
431 mrc p15, 0, r5, c13, c0, 3
432 mrc p15, 0, r6, c13, c0, 4
433 mrc p15, 2, r7, c0, c0, 0
435 /* Data TLB lockdown, instruction TLB lockdown registers */
436 mrc p15, 0, r5, c10, c0, 0
437 mrc p15, 0, r6, c10, c0, 1
439 /* Secure or non secure vector base address, FCSE PID, Context PID*/
440 mrc p15, 0, r4, c12, c0, 0
441 mrc p15, 0, r5, c13, c0, 0
442 mrc p15, 0, r6, c13, c0, 1
444 /* Primary remap, normal remap registers */
445 mrc p15, 0, r4, c10, c2, 0
446 mrc p15, 0, r5, c10, c2, 1
449 /* Store current cpsr*/
453 mrc p15, 0, r4, c1, c0, 0
454 /* save control register */
457 /* Clean Data or unified cache to POU*/
458 /* How to invalidate only L1 cache???? - #FIX_ME# */
459 /* mcr p15, 0, r11, c7, c11, 1 */
460 cmp r9, #1 /* Check whether L2 inval is required or not*/
464 mrc p15, 1, r0, c0, c0, 1
465 /* extract loc from clidr */
466 ands r3, r0, #0x7000000
467 /* left align loc bit field */
469 /* if loc is 0, then no need to clean */
471 /* start clean at cache level 0 */
474 /* work out 3x current cache level */
475 add r2, r10, r10, lsr #1
476 /* extract cache type bits from clidr*/
478 /* mask of the bits for current cache only */
480 /* see what cache we have at this level */
482 /* skip if no cache, or just i-cache */
484 /* select current cache level in cssr */
485 mcr p15, 2, r10, c0, c0, 0
486 /* isb to sych the new cssr&csidr */
488 /* read the new csidr */
489 mrc p15, 1, r1, c0, c0, 0
490 /* extract the length of the cache lines */
492 /* add 4 (line length offset) */
495 /* find maximum number on the way size */
496 ands r4, r4, r1, lsr #3
497 /* find bit position of way size increment */
500 /* extract max number of the index size*/
501 ands r7, r7, r1, lsr #13
504 /* create working copy of max way size*/
506 /* factor way and cache number into r11 */
507 orr r11, r10, r9, lsl r5
508 /* factor index number into r11 */
509 orr r11, r11, r7, lsl r2
510 /*clean & invalidate by set/way */
511 mcr p15, 0, r11, c7, c10, 2
512 /* decrement the way*/
515 /*decrement the index */
520 /* increment cache number */
524 /*swith back to cache level 0 */
526 /* select current cache level in cssr */
527 mcr p15, 2, r10, c0, c0, 0
530 /* Data memory barrier and Data sync barrier */
532 mcr p15, 0, r1, c7, c10, 4
533 mcr p15, 0, r1, c7, c10, 5
535 wfi @ wait for interrupt
547 /* restore regs and return */
548 ldmfd sp!, {r0-r12, pc}
550 /* Make sure SDRC accesses are ok */
552 ldr r4, cm_idlest1_core
562 /* Is dll in lock mode? */
563 ldr r4, sdrc_dlla_ctrl
567 /* wait till dll locks */
568 ldr r4, sdrc_dlla_status
576 .word CM_IDLEST1_CORE_V
578 .word SDRC_DLLA_STATUS_V
580 .word SDRC_DLLA_CTRL_V
582 .word PM_PREPWSTST_CORE_V
584 .word PM_PREPWSTST_CORE_P
586 .word PM_PREPWSTST_MPU_V
588 .word PM_PWSTCTRL_MPU_P
590 .word SCRATCHPAD_BASE_P
592 .word SRAM_BASE_P + 0x8000
607 cache_pred_disable_mask:
611 ENTRY(omap34xx_cpu_suspend_sz)
612 .word . - omap34xx_cpu_suspend