aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-tegra/sleep-t2.S
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-tegra/sleep-t2.S')
-rw-r--r--arch/arm/mach-tegra/sleep-t2.S574
1 files changed, 574 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/sleep-t2.S b/arch/arm/mach-tegra/sleep-t2.S
new file mode 100644
index 00000000000..f70360628f3
--- /dev/null
+++ b/arch/arm/mach-tegra/sleep-t2.S
@@ -0,0 +1,574 @@
1/*
2 * arch/arm/mach-tegra/include/mach/sleep-t2.S
3 *
4 * Copyright (c) 2010-2011, NVIDIA Corporation.
5 * Copyright (c) 2011, Google, Inc.
6 *
7 * Author: Colin Cross <ccross@android.com>
8 * Gary King <gking@nvidia.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25#include <linux/const.h>
26#include <linux/init.h>
27#include <linux/linkage.h>
28
29#include <asm/assembler.h>
30#include <asm/cache.h>
31#include <asm/domain.h>
32#include <asm/memory.h>
33#include <asm/page.h>
34#include <asm/ptrace.h>
35#include <asm/asm-offsets.h>
36#include <asm/glue-cache.h>
37#include <asm/glue-proc.h>
38#include <asm/system.h>
39
40#include <mach/iomap.h>
41#include <mach/io.h>
42
43#include "asm_macros.h"
44#include "sleep.h"
45
46#define EMC_CFG 0xc
47#define EMC_ADR_CFG 0x10
48#define EMC_REFRESH 0x70
49#define EMC_NOP 0xdc
50#define EMC_SELF_REF 0xe0
51#define EMC_REQ_CTRL 0x2b0
52#define EMC_EMC_STATUS 0x2b4
53
54#define CLK_RESET_CCLK_BURST 0x20
55#define CLK_RESET_CCLK_DIVIDER 0x24
56#define CLK_RESET_SCLK_BURST 0x28
57#define CLK_RESET_SCLK_DIVIDER 0x2c
58
59#define CLK_RESET_PLLC_BASE 0x80
60#define CLK_RESET_PLLM_BASE 0x90
61#define CLK_RESET_PLLP_BASE 0xa0
62#define CLK_RESET_PLLP_OUTA 0xa4
63#define CLK_RESET_PLLP_OUTB 0xa8
64#define CLK_RESET_PLLP_MISC 0xac
65#define CLK_RESET_PLLX_BASE 0xe0
66#define CLK_RESET_PLLX_MISC 0xe4
67
68#define CLK_RESET_RST_CPU_CMPLX_SET 0x340
69
70#define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT)
71#define TEGRA_ARM_PERIF_VIRT (TEGRA_ARM_PERIF_BASE - IO_CPU_PHYS + IO_CPU_VIRT)
72#define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS + IO_PPSB_VIRT)
73
74#ifdef CONFIG_HOTPLUG_CPU
75/*
76 * tegra2_hotplug_shutdown(void)
77 *
78 * puts the current cpu in reset
79 * should never return
80 */
81ENTRY(tegra2_hotplug_shutdown)
82 mov r6, lr
83 bl tegra_cpu_exit_coherency
84
85 /* Put this CPU into reset. */
86 cpu_id r0
87 bl tegra2_cpu_reset
88 mov pc, r6
89ENDPROC(tegra2_hotplug_shutdown)
90#endif
91
92#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
93/*
94 * tegra2_cpu_reset(int cpu)
95 *
96 * r0 is cpu to reset
97 *
98 * puts the specified CPU in wait-for-event mode on the flow controller
99 * and puts the CPU in reset
100 * can be called on the current cpu or another cpu
101 * if called on the current cpu, does not return
102 * MUST NOT BE CALLED FOR CPU 0.
103 *
104 * corrupts r0-r3, r12
105 */
106ENTRY(tegra2_cpu_reset)
107 cmp r0, #0
108 moveq pc, lr @ must not be called for CPU 0
109
110 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
111 mov r12, #CPU_RESETTABLE
112 str r12, [r1]
113
114 cpu_to_halt_reg r1, r0
115 mov32 r3, TEGRA_FLOW_CTRL_VIRT
116 mov r2, #FLOW_CTRL_WAITEVENT | FLOW_CTRL_JTAG_RESUME
117 str r2, [r3, r1] @ put flow controller in wait event mode
118 ldr r2, [r3, r1]
119 isb
120 dsb
121 movw r1, 0x1011
122 mov r1, r1, lsl r0
123 mov32 r3, TEGRA_CLK_RESET_VIRT
124 str r1, [r3, #CLK_RESET_RST_CPU_CMPLX_SET] @ put slave CPU in reset
125 isb
126 dsb
127 cpu_id r3
128 cmp r3, r0
129 beq .
130 mov pc, lr
131ENDPROC(tegra2_cpu_reset)
132#endif
133
134#ifdef CONFIG_PM_SLEEP
135/*
136 * tegra2_cpu_clear_resettable(void)
137 *
138 * Called to clear the "resettable soon" flag in PMC_SCRATCH41 when
139 * it is expected that the secondary CPU will be idle soon.
140 */
141ENTRY(tegra2_cpu_clear_resettable)
142 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
143 mov r12, #CPU_NOT_RESETTABLE
144 str r12, [r1]
145 mov pc, lr
146ENDPROC(tegra2_cpu_clear_resettable)
147
148/*
149 * tegra2_cpu_set_resettable_soon(void)
150 *
151 * Called to set the "resettable soon" flag in PMC_SCRATCH41 when
152 * it is expected that the secondary CPU will be idle soon.
153 */
154ENTRY(tegra2_cpu_set_resettable_soon)
155 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
156 mov r12, #CPU_RESETTABLE_SOON
157 str r12, [r1]
158 mov pc, lr
159ENDPROC(tegra2_cpu_set_resettable_soon)
160
161/*
162 * tegra2_cpu_is_resettable_soon(void)
163 *
164 * Returns true if the "resettable soon" flag in PMC_SCRATCH41 has been
165 * set because it is expected that the secondary CPU will be idle soon.
166 */
167ENTRY(tegra2_cpu_is_resettable_soon)
168 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
169 ldr r12, [r1]
170 cmp r12, #CPU_RESETTABLE_SOON
171 moveq r0, #1
172 movne r0, #0
173 mov pc, lr
174ENDPROC(tegra2_cpu_is_resettable_soon)
175
176/*
177 * tegra2_sleep_core(unsigned long v2p)
178 *
179 * enters suspend in LP0 or LP1 by turning off the mmu and jumping to
180 * tegra2_tear_down_core in IRAM
181 */
182ENTRY(tegra2_sleep_core)
183 mov r12, pc @ return here is via r12
184 b tegra_cpu_save
185 mov32 r1, tegra2_tear_down_core
186 mov32 r2, tegra2_iram_start
187 sub r1, r1, r2
188 mov32 r2, TEGRA_IRAM_CODE_AREA
189 add r1, r1, r2
190 b tegra_turn_off_mmu
191ENDPROC(tegra2_sleep_core)
192
193/*
194 * tegra2_sleep_wfi(unsigned long v2p)
195 */
196ENTRY(tegra2_sleep_wfi)
197 mrc p15, 0, r2, c1, c0, 1 @ save actlr before exiting coherency
198 mov r12, pc @ return here is via r12
199 b tegra_cpu_save
200 mov r11, r2
201
202 mov32 r0, TEGRA_PMC_VIRT + PMC_SCRATCH41
203 mov r3, #CPU_RESETTABLE
204 str r3, [r0]
205
206 bl tegra_cpu_wfi
207
208 mov32 r0, TEGRA_PMC_VIRT + PMC_SCRATCH41
209 mov r3, #CPU_NOT_RESETTABLE
210 str r3, [r0]
211
212 /*
213 * cpu may be reset while in wfi, which will return through
214 * tegra_resume to tegra_cpu_resume_phys to tegra_cpu_resume
215 * or interrupt may wake wfi, which will return here
216 * cpu state is unchanged - MMU is on, cache is on, coherency
217 * is off, and the data cache is off
218 *
219 * r11 contains the original actlr
220 */
221
222 mov sp, r7 @ restore SP for aborted suspend
223 bl tegra_pen_lock
224
225 mov32 r3, TEGRA_PMC_VIRT
226 add r0, r3, #PMC_SCRATCH41
227 mov r3, #CPU_NOT_RESETTABLE
228 str r3, [r0]
229
230 bl tegra_pen_unlock
231
232#if USE_TEGRA_CPU_SUSPEND
233 /* Enable the data cache and SMP coherency */
234 mrc p15, 0, r10, c1, c0, 0
235 orr r10, r10, #CR_C
236 dsb
237 mcr p15, 0, r10, c1, c0, 0
238 isb
239 mcr p15, 0, r11, c1, c0, 1 @ reenable coherency
240
241#else
242 mcr p15, 0, r11, c1, c0, 1 @ reenable coherency
243#endif
244 /* Invalidate the TLBs & BTAC */
245 mov r1, #0
246 mcr p15, 0, r1, c8, c3, 0 @ invalidate shared TLBs
247 mcr p15, 0, r1, c7, c1, 6 @ invalidate shared BTAC
248 dsb
249 isb
250
251 @ the cpu was running with coherency disabled, caches may be out of date
252#ifdef MULTI_CACHE
253 mov32 r10, cpu_cache
254 mov lr, pc
255 ldr pc, [r10, #CACHE_FLUSH_KERN_ALL]
256#else
257 bl __cpuc_flush_kern_all
258#endif
259
260#ifdef CONFIG_CACHE_L2X0
261 cpu_id r2
262 cmp r2, #0
263 bne no_l2_sync
264 /* Issue a PL310 cache sync operation */
265 dsb
266 mov32 r2, TEGRA_PL310_VIRT
267 movw r1, 0x730 @ cache sync
268 add r2, r2, r1
269 mov r1, #0
270 str r1, [r2]
271
272no_l2_sync:
273#endif
274
275 pop_ctx_regs r0, r1 @ restore context registers
276 mov pc, lr
277ENDPROC(tegra2_sleep_wfi)
278
279/*
280 * tegra2_tear_down_cpu
281 *
282 * Switches the CPU cluster to PLL-P and enters sleep.
283 */
284ENTRY(tegra2_tear_down_cpu)
285 bl tegra_cpu_pllp
286 b tegra2_enter_sleep
287ENDPROC(tegra2_tear_down_cpu)
288
289/* START OF ROUTINES COPIED TO IRAM */
290 .align L1_CACHE_SHIFT
291 .globl tegra2_iram_start
292tegra2_iram_start:
293
294/*
295 * tegra2_lp1_reset
296 *
297 * reset vector for LP1 restore; copied into IRAM during suspend.
298 * brings the system back up to a safe starting point (SDRAM out of
299 * self-refresh, PLLC, PLLM and PLLP reenabled, CPU running on PLLP,
300 * system clock running on the same PLL that it suspended at), and
301 * jumps to tegra_lp2_startup to restore PLLX and virtual addressing.
302 * physical address of tegra_lp2_startup expected to be stored in
303 * PMC_SCRATCH41
304 *
305 * NOTE: THIS *MUST* BE RELOCATED TO TEGRA_IRAM_CODE_AREA AND MUST BE FIRST.
306 */
307ENTRY(tegra2_lp1_reset)
308 /*
309 * the CPU and system bus are running at 32KHz and executing from
310 * IRAM when this code is executed; immediately switch to CLKM and
311 * enable PLLP.
312 */
313 mov32 r0, TEGRA_CLK_RESET_BASE
314#ifndef CONFIG_TRUSTED_FOUNDATIONS
315 /* secure code handles 32KHz to CLKM/OSC clock switch */
316 mov r1, #(1 << 28)
317 str r1, [r0, #CLK_RESET_SCLK_BURST]
318 str r1, [r0, #CLK_RESET_CCLK_BURST]
319 mov r1, #0
320 str r1, [r0, #CLK_RESET_SCLK_DIVIDER]
321 str r1, [r0, #CLK_RESET_CCLK_DIVIDER]
322#endif
323 ldr r1, [r0, #CLK_RESET_PLLM_BASE]
324 tst r1, #(1 << 30)
325 orreq r1, r1, #(1 << 30)
326 streq r1, [r0, #CLK_RESET_PLLM_BASE]
327 ldr r1, [r0, #CLK_RESET_PLLP_BASE]
328 tst r1, #(1 << 30)
329 orreq r1, r1, #(1 << 30)
330 streq r1, [r0, #CLK_RESET_PLLP_BASE]
331 ldr r1, [r0, #CLK_RESET_PLLC_BASE]
332 tst r1, #(1 << 30)
333 orreq r1, r1, #(1 << 30)
334 streq r1, [r0, #CLK_RESET_PLLC_BASE]
335
336 adr r2, tegra2_sdram_pad_address
337 adr r4, tegra2_sdram_pad_save
338 mov r5, #0
339
340padload:
341 ldr r0, [r2, r5] @ r0 is emc register address
342
343 ldr r1, [r4, r5]
344 str r1, [r0] @ set emc register to safe vals
345
346 add r5, r5, #4
347 ldr r0, tegra2_sdram_pad_size
348 cmp r0, r5
349 bne padload
350
351padload_done:
352 mov32 r7, TEGRA_TMRUS_BASE
353 ldr r1, [r7]
354 add r1, r1, #0xff @ 255uS delay for PLL stabilization
355
3561: ldr r0, [r7]
357 cmp r0, r1
358 dmb
359 bmi 1b
360
361 adr r4, tegra2_sclk_save
362 ldr r4, [r4]
363 mov32 r0, TEGRA_CLK_RESET_BASE
364 str r4, [r0, #CLK_RESET_SCLK_BURST]
365 ldr r4, =((1 << 28) | (4)) @ burst policy is PLLP
366 str r4, [r0, #CLK_RESET_CCLK_BURST]
367
368 mov32 r0, TEGRA_EMC_BASE
369 ldr r1, [r0, #EMC_CFG]
370 bic r1, r1, #(1 << 31) @ disable DRAM_CLK_STOP
371 str r1, [r0, #EMC_CFG]
372
373 mov r1, #0
374 str r1, [r0, #EMC_SELF_REF] @ take DRAM out of self refresh
375 mov r1, #1
376 str r1, [r0, #EMC_NOP]
377 str r1, [r0, #EMC_NOP]
378 str r1, [r0, #EMC_REFRESH]
379
380 ldr r1, [r0, #EMC_ADR_CFG]
381 tst r1, #(0x3 << 24)
382 moveq r1, #(0x1 << 8) @ just 1 device
383 movne r1, #(0x3 << 8) @ 2 devices
384
385exit_selfrefresh_loop:
386 ldr r2, [r0, #EMC_EMC_STATUS]
387 ands r2, r2, r1
388 bne exit_selfrefresh_loop
389
390 mov r1, #0
391 str r1, [r0, #EMC_REQ_CTRL]
392
393 mov32 r0, TEGRA_PMC_BASE
394 ldr r0, [r0, #PMC_SCRATCH41]
395 mov pc, r0
396ENDPROC(tegra2_lp1_reset)
397
398/*
399 * tegra2_tear_down_core
400 *
401 * copied into and executed from IRAM
402 * puts memory in self-refresh for LP0 and LP1
403 */
404tegra2_tear_down_core:
405 bl tegra2_sdram_self_refresh
406 bl tegra2_cpu_clk32k
407 b tegra2_enter_sleep
408
409/*
410 * tegra2_cpu_clk32k
411 *
412 * In LP0 and LP1 all plls will be turned off. Switch the CPU and system clock
413 * to the 32khz clock (clks)
414 */
415tegra2_cpu_clk32k:
416 /* start by jumping to clkm to safely disable PLLs, then jump
417 * to clks */
418 mov r0, #(1 << 28)
419 str r0, [r5, #CLK_RESET_SCLK_BURST]
420 str r0, [r5, #CLK_RESET_CCLK_BURST]
421 mov r0, #0
422 str r0, [r5, #CLK_RESET_CCLK_DIVIDER]
423 str r0, [r5, #CLK_RESET_SCLK_DIVIDER]
424
425 /* 2 us delay between changing sclk and disabling PLLs */
426 mov32 r7, TEGRA_TMRUS_BASE
427 ldr r1, [r7]
428 add r1, r1, #3
429
4301: ldr r0, [r7]
431 cmp r0, r1
432 dmb
433 bmi 1b
434
435 /* switch to CLKS */
436 mov r0, #0 /* burst policy = 32KHz */
437 str r0, [r5, #CLK_RESET_SCLK_BURST]
438
439 /* disable PLLP, PLLM, PLLC in LP0 and LP1 states */
440 ldr r0, [r5, #CLK_RESET_PLLM_BASE]
441 bic r0, r0, #(1 << 30)
442 str r0, [r5, #CLK_RESET_PLLM_BASE]
443 ldr r0, [r5, #CLK_RESET_PLLP_BASE]
444 bic r0, r0, #(1 << 30)
445 str r0, [r5, #CLK_RESET_PLLP_BASE]
446 ldr r0, [r5, #CLK_RESET_PLLC_BASE]
447 bic r0, r0, #(1 << 30)
448 str r0, [r5, #CLK_RESET_PLLC_BASE]
449 mov pc, lr
450
451/*
452 * tegra2_enter_sleep
453 *
454 * uses flow controller to enter sleep state
455 * executes from IRAM with SDRAM in selfrefresh when target state is LP0 and LP1
456 * executes from SDRAM with target state is LP2
457 */
458tegra2_enter_sleep:
459 mov32 r7, TEGRA_TMRUS_BASE
460 ldr r1, [r7]
461 mov32 r4, TEGRA_PMC_BASE
462 str r1, [r4, #PMC_SCRATCH38]
463 dsb
464 mov32 r6, TEGRA_FLOW_CTRL_BASE
465
466 mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
467 orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
468 cpu_id r1
469 cpu_to_halt_reg r1, r1
470 str r0, [r6, r1]
471 dsb
472 ldr r0, [r6, r1] /* memory barrier */
473
474halted: dsb
475 wfe /* CPU should be power gated here */
476 isb
477 b halted
478
479/*
480 * tegra2_sdram_self_refresh
481 *
482 * called with MMU off and caches disabled
483 * puts sdram in self refresh
484 * must execute from IRAM
485 */
486tegra2_sdram_self_refresh:
487 mov32 r1, TEGRA_EMC_BASE
488 mov r2, #3
489 str r2, [r1, #EMC_REQ_CTRL] @ stall incoming DRAM requests
490
491emcidle:ldr r2, [r1, #EMC_EMC_STATUS]
492 tst r2, #4
493 beq emcidle
494
495 mov r2, #1
496 str r2, [r1, #EMC_SELF_REF]
497
498 ldr r2, [r1, #EMC_ADR_CFG]
499 tst r2, #(0x3 << 24)
500 moveq r2, #(0x1 << 8) @ just 1 device
501 movne r2, #(0x3 << 8) @ 2 devices
502
503emcself:ldr r3, [r1, #EMC_EMC_STATUS]
504 and r3, r3, r2
505 cmp r3, r2
506 bne emcself @ loop until DDR in self-refresh
507
508 adr r2, tegra2_sdram_pad_address
509 adr r3, tegra2_sdram_pad_safe
510 adr r4, tegra2_sdram_pad_save
511 mov r5, #0
512
513padsave:
514 ldr r0, [r2, r5] @ r0 is emc register address
515
516 ldr r1, [r0]
517 str r1, [r4, r5] @ save emc register
518
519 ldr r1, [r3, r5]
520 str r1, [r0] @ set emc register to safe vals
521
522 add r5, r5, #4
523 ldr r0, tegra2_sdram_pad_size
524 cmp r0, r5
525 bne padsave
526padsave_done:
527
528 mov32 r5, TEGRA_CLK_RESET_BASE
529 ldr r0, [r5, #CLK_RESET_SCLK_BURST]
530 adr r2, tegra2_sclk_save
531 str r0, [r2]
532 dsb
533 mov pc, lr
534
535tegra2_sdram_pad_address:
536 .word TEGRA_APB_MISC_BASE + 0x8c8 /* XM2CFGCPADCTRL */
537 .word TEGRA_APB_MISC_BASE + 0x8cc /* XM2CFGDPADCTRL */
538 .word TEGRA_APB_MISC_BASE + 0x8d0 /* XM2CLKCFGPADCTRL */
539 .word TEGRA_APB_MISC_BASE + 0x8d4 /* XM2COMPPADCTRL */
540 .word TEGRA_APB_MISC_BASE + 0x8d8 /* XM2VTTGENPADCTRL */
541 .word TEGRA_APB_MISC_BASE + 0x8e4 /* XM2CFGCPADCTRL2 */
542 .word TEGRA_APB_MISC_BASE + 0x8e8 /* XM2CFGDPADCTRL2 */
543
544tegra2_sdram_pad_size:
545 .word tegra2_sdram_pad_size - tegra2_sdram_pad_address
546
547tegra2_sdram_pad_safe:
548 .word 0x8
549 .word 0x8
550 .word 0x0
551 .word 0x8
552 .word 0x5500
553 .word 0x08080040
554 .word 0x0
555
556tegra2_sclk_save:
557 .word 0x0
558
559tegra2_sdram_pad_save:
560 .word 0
561 .word 0
562 .word 0
563 .word 0
564 .word 0
565 .word 0
566 .word 0
567
568 .ltorg
569/* dummy symbol for end of IRAM */
570 .align L1_CACHE_SHIFT
571 .globl tegra2_iram_end
572tegra2_iram_end:
573 b .
574#endif