blob: 17dfe30db3a7d1f6f8ace83f9b026c6d5b46073d [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
Jean Pihetf7dfe3d2010-12-18 16:44:45 +010074/*
75 * The "get_*restore_pointer" functions are used to provide a
76 * physical restore address where the ROM code jumps while waking
77 * up from MPU OFF/OSWR state.
78 * The restore pointer is stored into the scratchpad.
79 */
80
Kevin Hilman8bd22942009-05-28 10:56:16 -070081 .text
82/* Function call to get the restore pointer for resume from OFF */
83ENTRY(get_restore_pointer)
84 stmfd sp!, {lr} @ save registers on stack
85 adr r0, restore
86 ldmfd sp!, {pc} @ restore regs and return
87ENTRY(get_restore_pointer_sz)
Tero Kristo0795a752008-10-13 17:58:50 +030088 .word . - get_restore_pointer
Jean Pihet1e81bc02010-12-18 16:44:44 +010089
Nishanth Menon458e9992010-12-20 14:05:06 -060090 .text
91/* Function call to get the restore pointer for 3630 resume from OFF */
92ENTRY(get_omap3630_restore_pointer)
93 stmfd sp!, {lr} @ save registers on stack
94 adr r0, restore_3630
95 ldmfd sp!, {pc} @ restore regs and return
96ENTRY(get_omap3630_restore_pointer_sz)
97 .word . - get_omap3630_restore_pointer
Tero Kristo0795a752008-10-13 17:58:50 +030098
99 .text
Jean Pihet1e81bc02010-12-18 16:44:44 +0100100/* Function call to get the restore pointer for ES3 to resume from OFF */
101ENTRY(get_es3_restore_pointer)
102 stmfd sp!, {lr} @ save registers on stack
103 adr r0, restore_es3
104 ldmfd sp!, {pc} @ restore regs and return
105ENTRY(get_es3_restore_pointer_sz)
106 .word . - get_es3_restore_pointer
107
108 .text
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600109/*
110 * L2 cache needs to be toggled for stable OFF mode functionality on 3630.
Jean Pihet1e81bc02010-12-18 16:44:44 +0100111 * This function sets up a flag that will allow for this toggling to take
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100112 * place on 3630. Hopefully some version in the future may not need this.
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600113 */
114ENTRY(enable_omap3630_toggle_l2_on_restore)
115 stmfd sp!, {lr} @ save registers on stack
116 /* Setup so that we will disable and enable l2 */
117 mov r1, #0x1
118 str r1, l2dis_3630
119 ldmfd sp!, {pc} @ restore regs and return
120
Tero Kristo27d59a42008-10-13 13:15:00 +0300121/* Function to call rom code to save secure ram context */
122ENTRY(save_secure_ram_context)
123 stmfd sp!, {r1-r12, lr} @ save registers on stack
Jean Pihetd3cdfd22010-12-18 16:44:41 +0100124
Tero Kristo27d59a42008-10-13 13:15:00 +0300125 adr r3, api_params @ r3 points to parameters
126 str r0, [r3,#0x4] @ r0 has sdram address
127 ldr r12, high_mask
128 and r3, r3, r12
129 ldr r12, sram_phy_addr_mask
130 orr r3, r3, r12
131 mov r0, #25 @ set service ID for PPA
132 mov r12, r0 @ copy secure service ID in r12
133 mov r1, #0 @ set task id for ROM code in r1
Kalle Jokiniemiba50ea72009-03-26 15:59:00 +0200134 mov r2, #4 @ set some flags in r2, r6
Tero Kristo27d59a42008-10-13 13:15:00 +0300135 mov r6, #0xff
136 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
137 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
138 .word 0xE1600071 @ call SMI monitor (smi #1)
139 nop
140 nop
141 nop
142 nop
143 ldmfd sp!, {r1-r12, pc}
144sram_phy_addr_mask:
145 .word SRAM_BASE_P
146high_mask:
147 .word 0xffff
148api_params:
149 .word 0x4, 0x0, 0x0, 0x1, 0x1
150ENTRY(save_secure_ram_context_sz)
151 .word . - save_secure_ram_context
152
Kevin Hilman8bd22942009-05-28 10:56:16 -0700153/*
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100154 * ======================
155 * == Idle entry point ==
156 * ======================
157 */
158
159/*
Kevin Hilman8bd22942009-05-28 10:56:16 -0700160 * Forces OMAP into idle state
161 *
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100162 * omap34xx_cpu_suspend() - This bit of code saves the CPU context if needed
163 * and executes the WFI instruction. Calling WFI effectively changes the
164 * power domains states to the desired target power states.
Kevin Hilman8bd22942009-05-28 10:56:16 -0700165 *
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100166 *
167 * Notes:
168 * - this code gets copied to internal SRAM at boot. The execution pointer
169 * in SRAM is _omap_sram_idle.
170 * - when the OMAP wakes up it continues at different execution points
171 * depending on the low power mode (non-OFF vs OFF modes),
172 * cf. 'Resume path for xxx mode' comments.
Kevin Hilman8bd22942009-05-28 10:56:16 -0700173 */
174ENTRY(omap34xx_cpu_suspend)
175 stmfd sp!, {r0-r12, lr} @ save registers on stack
Jean Pihetd3cdfd22010-12-18 16:44:41 +0100176
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100177 /*
178 * r0 contains restore pointer in sdram
179 * r1 contains information about saving context:
180 * 0 - No context lost
181 * 1 - Only L1 and logic lost
182 * 2 - Only L2 lost
183 * 3 - Both L1 and L2 lost
184 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700185
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100186 /* Directly jump to WFI is the context save is not required */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700187 cmp r1, #0x0
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100188 beq omap3_do_wfi
189
190 /* Otherwise fall through to the save context code */
191save_context_wfi:
192 mov r8, r0 @ Store SDRAM address in r8
193 mrc p15, 0, r5, c1, c0, 1 @ Read Auxiliary Control Register
194 mov r4, #0x1 @ Number of parameters for restore call
195 stmia r8!, {r4-r5} @ Push parameters for restore call
196 mrc p15, 1, r5, c9, c0, 2 @ Read L2 AUX ctrl register
197 stmia r8!, {r4-r5} @ Push parameters for restore call
198
199 /* Check what that target sleep state is from r1 */
200 cmp r1, #0x2 @ Only L2 lost, no need to save context
201 beq clean_caches
202
203l1_logic_lost:
204 /* Store sp and spsr to SDRAM */
205 mov r4, sp
206 mrs r5, spsr
207 mov r6, lr
208 stmia r8!, {r4-r6}
209 /* Save all ARM registers */
210 /* Coprocessor access control register */
211 mrc p15, 0, r6, c1, c0, 2
212 stmia r8!, {r6}
213 /* TTBR0, TTBR1 and Translation table base control */
214 mrc p15, 0, r4, c2, c0, 0
215 mrc p15, 0, r5, c2, c0, 1
216 mrc p15, 0, r6, c2, c0, 2
217 stmia r8!, {r4-r6}
218 /*
219 * Domain access control register, data fault status register,
220 * and instruction fault status register
221 */
222 mrc p15, 0, r4, c3, c0, 0
223 mrc p15, 0, r5, c5, c0, 0
224 mrc p15, 0, r6, c5, c0, 1
225 stmia r8!, {r4-r6}
226 /*
227 * Data aux fault status register, instruction aux fault status,
228 * data fault address register and instruction fault address register
229 */
230 mrc p15, 0, r4, c5, c1, 0
231 mrc p15, 0, r5, c5, c1, 1
232 mrc p15, 0, r6, c6, c0, 0
233 mrc p15, 0, r7, c6, c0, 2
234 stmia r8!, {r4-r7}
235 /*
236 * user r/w thread and process ID, user r/o thread and process ID,
237 * priv only thread and process ID, cache size selection
238 */
239 mrc p15, 0, r4, c13, c0, 2
240 mrc p15, 0, r5, c13, c0, 3
241 mrc p15, 0, r6, c13, c0, 4
242 mrc p15, 2, r7, c0, c0, 0
243 stmia r8!, {r4-r7}
244 /* Data TLB lockdown, instruction TLB lockdown registers */
245 mrc p15, 0, r5, c10, c0, 0
246 mrc p15, 0, r6, c10, c0, 1
247 stmia r8!, {r5-r6}
248 /* Secure or non secure vector base address, FCSE PID, Context PID*/
249 mrc p15, 0, r4, c12, c0, 0
250 mrc p15, 0, r5, c13, c0, 0
251 mrc p15, 0, r6, c13, c0, 1
252 stmia r8!, {r4-r6}
253 /* Primary remap, normal remap registers */
254 mrc p15, 0, r4, c10, c2, 0
255 mrc p15, 0, r5, c10, c2, 1
256 stmia r8!,{r4-r5}
257
258 /* Store current cpsr*/
259 mrs r2, cpsr
260 stmia r8!, {r2}
261
262 mrc p15, 0, r4, c1, c0, 0
263 /* save control register */
264 stmia r8!, {r4}
265
266clean_caches:
267 /*
268 * Clean Data or unified cache to POU
269 * How to invalidate only L1 cache???? - #FIX_ME#
270 * mcr p15, 0, r11, c7, c11, 1
271 */
272 cmp r1, #0x1 @ Check whether L2 inval is required
273 beq omap3_do_wfi
274
275clean_l2:
276 /*
277 * jump out to kernel flush routine
278 * - reuse that code is better
279 * - it executes in a cached space so is faster than refetch per-block
280 * - should be faster and will change with kernel
281 * - 'might' have to copy address, load and jump to it
282 */
283 ldr r1, kernel_flush
284 mov lr, pc
285 bx r1
286
287omap3_do_wfi:
288 ldr r4, sdrc_power @ read the SDRC_POWER register
289 ldr r5, [r4] @ read the contents of SDRC_POWER
290 orr r5, r5, #0x40 @ enable self refresh on idle req
291 str r5, [r4] @ write back to SDRC_POWER register
292
Kevin Hilman8bd22942009-05-28 10:56:16 -0700293 /* Data memory barrier and Data sync barrier */
294 mov r1, #0
295 mcr p15, 0, r1, c7, c10, 4
296 mcr p15, 0, r1, c7, c10, 5
297
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100298/*
299 * ===================================
300 * == WFI instruction => Enter idle ==
301 * ===================================
302 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700303 wfi @ wait for interrupt
304
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100305/*
306 * ===================================
307 * == Resume path for non-OFF modes ==
308 * ===================================
309 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700310 nop
311 nop
312 nop
313 nop
314 nop
315 nop
316 nop
317 nop
318 nop
319 nop
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200320 bl wait_sdrc_ok
Kevin Hilman8bd22942009-05-28 10:56:16 -0700321
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100322/*
323 * ===================================
324 * == Exit point from non-OFF modes ==
325 * ===================================
326 */
327 ldmfd sp!, {r0-r12, pc} @ restore regs and return
328
329
330/*
331 * ==============================
332 * == Resume path for OFF mode ==
333 * ==============================
334 */
335
336/*
337 * The restore_* functions are called by the ROM code
338 * when back from WFI in OFF mode.
339 * Cf. the get_*restore_pointer functions.
340 *
341 * restore_es3: applies to 34xx >= ES3.0
342 * restore_3630: applies to 36xx
343 * restore: common code for 3xxx
344 */
Tero Kristo0795a752008-10-13 17:58:50 +0300345restore_es3:
Tero Kristo0795a752008-10-13 17:58:50 +0300346 ldr r5, pm_prepwstst_core_p
347 ldr r4, [r5]
348 and r4, r4, #0x3
349 cmp r4, #0x0 @ Check if previous power state of CORE is OFF
350 bne restore
351 adr r0, es3_sdrc_fix
352 ldr r1, sram_base
353 ldr r2, es3_sdrc_fix_sz
354 mov r2, r2, ror #2
355copy_to_sram:
356 ldmia r0!, {r3} @ val = *src
357 stmia r1!, {r3} @ *dst = val
358 subs r2, r2, #0x1 @ num_words--
359 bne copy_to_sram
360 ldr r1, sram_base
361 blx r1
Nishanth Menon458e9992010-12-20 14:05:06 -0600362 b restore
363
364restore_3630:
Nishanth Menon458e9992010-12-20 14:05:06 -0600365 ldr r1, pm_prepwstst_core_p
366 ldr r2, [r1]
367 and r2, r2, #0x3
368 cmp r2, #0x0 @ Check if previous power state of CORE is OFF
369 bne restore
370 /* Disable RTA before giving control */
371 ldr r1, control_mem_rta
372 mov r2, #OMAP36XX_RTA_DISABLE
373 str r2, [r1]
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100374
375 /* Fall through to common code for the remaining logic */
376
Kevin Hilman8bd22942009-05-28 10:56:16 -0700377restore:
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100378 /*
379 * Check what was the reason for mpu reset and store the reason in r9:
380 * 0 - No context lost
381 * 1 - Only L1 and logic lost
382 * 2 - Only L2 lost - In this case, we wont be here
383 * 3 - Both L1 and L2 lost
384 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700385 ldr r1, pm_pwstctrl_mpu
386 ldr r2, [r1]
387 and r2, r2, #0x3
388 cmp r2, #0x0 @ Check if target power state was OFF or RET
389 moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
390 movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
391 bne logic_l1_restore
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600392
393 ldr r0, l2dis_3630
394 cmp r0, #0x1 @ should we disable L2 on 3630?
395 bne skipl2dis
396 mrc p15, 0, r0, c1, c0, 1
397 bic r0, r0, #2 @ disable L2 cache
398 mcr p15, 0, r0, c1, c0, 1
399skipl2dis:
Tero Kristo27d59a42008-10-13 13:15:00 +0300400 ldr r0, control_stat
401 ldr r1, [r0]
402 and r1, #0x700
403 cmp r1, #0x300
404 beq l2_inv_gp
405 mov r0, #40 @ set service ID for PPA
406 mov r12, r0 @ copy secure Service ID in r12
407 mov r1, #0 @ set task id for ROM code in r1
408 mov r2, #4 @ set some flags in r2, r6
409 mov r6, #0xff
410 adr r3, l2_inv_api_params @ r3 points to dummy parameters
411 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
412 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
413 .word 0xE1600071 @ call SMI monitor (smi #1)
414 /* Write to Aux control register to set some bits */
415 mov r0, #42 @ set service ID for PPA
416 mov r12, r0 @ copy secure Service ID in r12
417 mov r1, #0 @ set task id for ROM code in r1
418 mov r2, #4 @ set some flags in r2, r6
419 mov r6, #0xff
Tero Kristoa087cad2009-11-12 12:07:20 +0200420 ldr r4, scratchpad_base
421 ldr r3, [r4, #0xBC] @ r3 points to parameters
Tero Kristo27d59a42008-10-13 13:15:00 +0300422 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
423 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
424 .word 0xE1600071 @ call SMI monitor (smi #1)
425
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200426#ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
427 /* Restore L2 aux control register */
428 @ set service ID for PPA
429 mov r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
430 mov r12, r0 @ copy service ID in r12
431 mov r1, #0 @ set task ID for ROM code in r1
432 mov r2, #4 @ set some flags in r2, r6
433 mov r6, #0xff
434 ldr r4, scratchpad_base
435 ldr r3, [r4, #0xBC]
436 adds r3, r3, #8 @ r3 points to parameters
437 mcr p15, 0, r0, c7, c10, 4 @ data write barrier
438 mcr p15, 0, r0, c7, c10, 5 @ data memory barrier
439 .word 0xE1600071 @ call SMI monitor (smi #1)
440#endif
Tero Kristo27d59a42008-10-13 13:15:00 +0300441 b logic_l1_restore
442l2_inv_api_params:
443 .word 0x1, 0x00
Tero Kristo27d59a42008-10-13 13:15:00 +0300444l2_inv_gp:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700445 /* Execute smi to invalidate L2 cache */
446 mov r12, #0x1 @ set up to invalide L2
Tero Kristo27d59a42008-10-13 13:15:00 +0300447smi: .word 0xE1600070 @ Call SMI monitor (smieq)
448 /* Write to Aux control register to set some bits */
Tero Kristoa087cad2009-11-12 12:07:20 +0200449 ldr r4, scratchpad_base
450 ldr r3, [r4,#0xBC]
451 ldr r0, [r3,#4]
Tero Kristo27d59a42008-10-13 13:15:00 +0300452 mov r12, #0x3
453 .word 0xE1600070 @ Call SMI monitor (smieq)
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200454 ldr r4, scratchpad_base
455 ldr r3, [r4,#0xBC]
456 ldr r0, [r3,#12]
457 mov r12, #0x2
458 .word 0xE1600070 @ Call SMI monitor (smieq)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700459logic_l1_restore:
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600460 ldr r1, l2dis_3630
461 cmp r1, #0x1 @ Do we need to re-enable L2 on 3630?
462 bne skipl2reen
463 mrc p15, 0, r1, c1, c0, 1
464 orr r1, r1, #2 @ re-enable L2 cache
465 mcr p15, 0, r1, c1, c0, 1
466skipl2reen:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700467 mov r1, #0
468 /* Invalidate all instruction caches to PoU
469 * and flush branch target cache */
470 mcr p15, 0, r1, c7, c5, 0
471
472 ldr r4, scratchpad_base
473 ldr r3, [r4,#0xBC]
Tero Kristo79dcfdd2009-11-12 12:07:22 +0200474 adds r3, r3, #16
Kevin Hilman8bd22942009-05-28 10:56:16 -0700475 ldmia r3!, {r4-r6}
476 mov sp, r4
477 msr spsr_cxsf, r5
478 mov lr, r6
479
480 ldmia r3!, {r4-r9}
481 /* Coprocessor access Control Register */
482 mcr p15, 0, r4, c1, c0, 2
483
484 /* TTBR0 */
485 MCR p15, 0, r5, c2, c0, 0
486 /* TTBR1 */
487 MCR p15, 0, r6, c2, c0, 1
488 /* Translation table base control register */
489 MCR p15, 0, r7, c2, c0, 2
490 /*domain access Control Register */
491 MCR p15, 0, r8, c3, c0, 0
492 /* data fault status Register */
493 MCR p15, 0, r9, c5, c0, 0
494
495 ldmia r3!,{r4-r8}
496 /* instruction fault status Register */
497 MCR p15, 0, r4, c5, c0, 1
498 /*Data Auxiliary Fault Status Register */
499 MCR p15, 0, r5, c5, c1, 0
500 /*Instruction Auxiliary Fault Status Register*/
501 MCR p15, 0, r6, c5, c1, 1
502 /*Data Fault Address Register */
503 MCR p15, 0, r7, c6, c0, 0
504 /*Instruction Fault Address Register*/
505 MCR p15, 0, r8, c6, c0, 2
506 ldmia r3!,{r4-r7}
507
508 /* user r/w thread and process ID */
509 MCR p15, 0, r4, c13, c0, 2
510 /* user ro thread and process ID */
511 MCR p15, 0, r5, c13, c0, 3
512 /*Privileged only thread and process ID */
513 MCR p15, 0, r6, c13, c0, 4
514 /* cache size selection */
515 MCR p15, 2, r7, c0, c0, 0
516 ldmia r3!,{r4-r8}
517 /* Data TLB lockdown registers */
518 MCR p15, 0, r4, c10, c0, 0
519 /* Instruction TLB lockdown registers */
520 MCR p15, 0, r5, c10, c0, 1
521 /* Secure or Nonsecure Vector Base Address */
522 MCR p15, 0, r6, c12, c0, 0
523 /* FCSE PID */
524 MCR p15, 0, r7, c13, c0, 0
525 /* Context PID */
526 MCR p15, 0, r8, c13, c0, 1
527
528 ldmia r3!,{r4-r5}
529 /* primary memory remap register */
530 MCR p15, 0, r4, c10, c2, 0
531 /*normal memory remap register */
532 MCR p15, 0, r5, c10, c2, 1
533
534 /* Restore cpsr */
535 ldmia r3!,{r4} /*load CPSR from SDRAM*/
536 msr cpsr, r4 /*store cpsr */
537
538 /* Enabling MMU here */
539 mrc p15, 0, r7, c2, c0, 2 /* Read TTBRControl */
540 /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1*/
541 and r7, #0x7
542 cmp r7, #0x0
543 beq usettbr0
544ttbr_error:
545 /* More work needs to be done to support N[0:2] value other than 0
546 * So looping here so that the error can be detected
547 */
548 b ttbr_error
549usettbr0:
550 mrc p15, 0, r2, c2, c0, 0
551 ldr r5, ttbrbit_mask
552 and r2, r5
553 mov r4, pc
554 ldr r5, table_index_mask
555 and r4, r5 /* r4 = 31 to 20 bits of pc */
556 /* Extract the value to be written to table entry */
557 ldr r1, table_entry
558 add r1, r1, r4 /* r1 has value to be written to table entry*/
559 /* Getting the address of table entry to modify */
560 lsr r4, #18
561 add r2, r4 /* r2 has the location which needs to be modified */
562 /* Storing previous entry of location being modified */
563 ldr r5, scratchpad_base
564 ldr r4, [r2]
565 str r4, [r5, #0xC0]
566 /* Modify the table entry */
567 str r1, [r2]
568 /* Storing address of entry being modified
569 * - will be restored after enabling MMU */
570 ldr r5, scratchpad_base
571 str r2, [r5, #0xC4]
572
573 mov r0, #0
574 mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
575 mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
576 mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
577 mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
578 /* Restore control register but dont enable caches here*/
579 /* Caches will be enabled after restoring MMU table entry */
580 ldmia r3!, {r4}
581 /* Store previous value of control register in scratchpad */
582 str r4, [r5, #0xC8]
583 ldr r2, cache_pred_disable_mask
584 and r4, r2
585 mcr p15, 0, r4, c1, c0, 0
586
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100587/*
588 * ==============================
589 * == Exit point from OFF mode ==
590 * ==============================
591 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700592 ldmfd sp!, {r0-r12, pc} @ restore regs and return
Kevin Hilman8bd22942009-05-28 10:56:16 -0700593
Jean Pihet1e81bc02010-12-18 16:44:44 +0100594
595/*
596 * Internal functions
597 */
598
Jean Pihet83521292010-12-18 16:44:46 +0100599/* This function implements the erratum ID i443 WA, applies to 34xx >= ES3.0 */
Jean Pihet1e81bc02010-12-18 16:44:44 +0100600 .text
601ENTRY(es3_sdrc_fix)
602 ldr r4, sdrc_syscfg @ get config addr
603 ldr r5, [r4] @ get value
604 tst r5, #0x100 @ is part access blocked
605 it eq
606 biceq r5, r5, #0x100 @ clear bit if set
607 str r5, [r4] @ write back change
608 ldr r4, sdrc_mr_0 @ get config addr
609 ldr r5, [r4] @ get value
610 str r5, [r4] @ write back change
611 ldr r4, sdrc_emr2_0 @ get config addr
612 ldr r5, [r4] @ get value
613 str r5, [r4] @ write back change
614 ldr r4, sdrc_manual_0 @ get config addr
615 mov r5, #0x2 @ autorefresh command
616 str r5, [r4] @ kick off refreshes
617 ldr r4, sdrc_mr_1 @ get config addr
618 ldr r5, [r4] @ get value
619 str r5, [r4] @ write back change
620 ldr r4, sdrc_emr2_1 @ get config addr
621 ldr r5, [r4] @ get value
622 str r5, [r4] @ write back change
623 ldr r4, sdrc_manual_1 @ get config addr
624 mov r5, #0x2 @ autorefresh command
625 str r5, [r4] @ kick off refreshes
626 bx lr
627
628sdrc_syscfg:
629 .word SDRC_SYSCONFIG_P
630sdrc_mr_0:
631 .word SDRC_MR_0_P
632sdrc_emr2_0:
633 .word SDRC_EMR2_0_P
634sdrc_manual_0:
635 .word SDRC_MANUAL_0_P
636sdrc_mr_1:
637 .word SDRC_MR_1_P
638sdrc_emr2_1:
639 .word SDRC_EMR2_1_P
640sdrc_manual_1:
641 .word SDRC_MANUAL_1_P
642ENTRY(es3_sdrc_fix_sz)
643 .word . - es3_sdrc_fix
644
Jean Pihet83521292010-12-18 16:44:46 +0100645/*
646 * This function implements the erratum ID i581 WA:
647 * SDRC state restore before accessing the SDRAM
648 *
649 * Only used at return from non-OFF mode. For OFF
650 * mode the ROM code configures the SDRC and
651 * the DPLL before calling the restore code directly
652 * from DDR.
653 */
654
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200655/* Make sure SDRC accesses are ok */
656wait_sdrc_ok:
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600657
658/* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this. */
659 ldr r4, cm_idlest_ckgen
660wait_dpll3_lock:
661 ldr r5, [r4]
662 tst r5, #1
663 beq wait_dpll3_lock
664
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200665 ldr r4, cm_idlest1_core
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600666wait_sdrc_ready:
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200667 ldr r5, [r4]
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600668 tst r5, #0x2
669 bne wait_sdrc_ready
670 /* allow DLL powerdown upon hw idle req */
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200671 ldr r4, sdrc_power
672 ldr r5, [r4]
673 bic r5, r5, #0x40
674 str r5, [r4]
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600675is_dll_in_lock_mode:
676
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200677 /* Is dll in lock mode? */
678 ldr r4, sdrc_dlla_ctrl
679 ldr r5, [r4]
680 tst r5, #0x4
681 bxne lr
682 /* wait till dll locks */
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600683wait_dll_lock_timed:
684 ldr r4, wait_dll_lock_counter
685 add r4, r4, #1
686 str r4, wait_dll_lock_counter
687 ldr r4, sdrc_dlla_status
688 mov r6, #8 /* Wait 20uS for lock */
689wait_dll_lock:
690 subs r6, r6, #0x1
691 beq kick_dll
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200692 ldr r5, [r4]
693 and r5, r5, #0x4
694 cmp r5, #0x4
695 bne wait_dll_lock
696 bx lr
Kevin Hilman8bd22942009-05-28 10:56:16 -0700697
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600698 /* disable/reenable DLL if not locked */
699kick_dll:
700 ldr r4, sdrc_dlla_ctrl
701 ldr r5, [r4]
702 mov r6, r5
703 bic r6, #(1<<3) /* disable dll */
704 str r6, [r4]
705 dsb
706 orr r6, r6, #(1<<3) /* enable dll */
707 str r6, [r4]
708 dsb
709 ldr r4, kick_counter
710 add r4, r4, #1
711 str r4, kick_counter
712 b wait_dll_lock_timed
713
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200714cm_idlest1_core:
715 .word CM_IDLEST1_CORE_V
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600716cm_idlest_ckgen:
717 .word CM_IDLEST_CKGEN_V
Peter 'p2' De Schrijver89139dc2009-01-16 18:53:48 +0200718sdrc_dlla_status:
719 .word SDRC_DLLA_STATUS_V
720sdrc_dlla_ctrl:
721 .word SDRC_DLLA_CTRL_V
Tero Kristo0795a752008-10-13 17:58:50 +0300722pm_prepwstst_core_p:
723 .word PM_PREPWSTST_CORE_P
Kevin Hilman8bd22942009-05-28 10:56:16 -0700724pm_pwstctrl_mpu:
725 .word PM_PWSTCTRL_MPU_P
726scratchpad_base:
727 .word SCRATCHPAD_BASE_P
Tero Kristo0795a752008-10-13 17:58:50 +0300728sram_base:
729 .word SRAM_BASE_P + 0x8000
Kevin Hilman8bd22942009-05-28 10:56:16 -0700730sdrc_power:
731 .word SDRC_POWER_V
Kevin Hilman8bd22942009-05-28 10:56:16 -0700732ttbrbit_mask:
733 .word 0xFFFFC000
734table_index_mask:
735 .word 0xFFF00000
736table_entry:
737 .word 0x00000C02
738cache_pred_disable_mask:
739 .word 0xFFFFE7FB
Tero Kristo27d59a42008-10-13 13:15:00 +0300740control_stat:
741 .word CONTROL_STAT
Nishanth Menon458e9992010-12-20 14:05:06 -0600742control_mem_rta:
743 .word CONTROL_MEM_RTA_CTRL
Richard Woodruff0bd40532010-12-20 14:05:03 -0600744kernel_flush:
745 .word v7_flush_dcache_all
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600746l2dis_3630:
747 .word 0
Peter 'p2' De Schrijver9d93b8a22010-12-20 14:05:04 -0600748 /*
749 * When exporting to userspace while the counters are in SRAM,
750 * these 2 words need to be at the end to facilitate retrival!
751 */
752kick_counter:
753 .word 0
754wait_dll_lock_counter:
755 .word 0
Jean Pihetf7dfe3d2010-12-18 16:44:45 +0100756
Kevin Hilman8bd22942009-05-28 10:56:16 -0700757ENTRY(omap34xx_cpu_suspend_sz)
758 .word . - omap34xx_cpu_suspend