1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
6 #include <linux/linkage.h>
8 #include <soc/tegra/flowctrl.h>
9 #include <soc/tegra/fuse.h>
11 #include <asm/asm-offsets.h>
12 #include <asm/assembler.h>
13 #include <asm/cache.h>
19 #define EMC_ADR_CFG 0x10
20 #define EMC_TIMING_CONTROL 0x28
22 #define EMC_SELF_REF 0xe0
24 #define EMC_FBIO_CFG5 0x104
25 #define EMC_AUTO_CAL_CONFIG 0x2a4
26 #define EMC_AUTO_CAL_INTERVAL 0x2a8
27 #define EMC_AUTO_CAL_STATUS 0x2ac
28 #define EMC_REQ_CTRL 0x2b0
29 #define EMC_CFG_DIG_DLL 0x2bc
30 #define EMC_EMC_STATUS 0x2b4
31 #define EMC_ZCAL_INTERVAL 0x2e0
32 #define EMC_ZQ_CAL 0x2ec
33 #define EMC_XM2VTTGENPADCTRL 0x310
34 #define EMC_XM2VTTGENPADCTRL2 0x314
37 #define PMC_CTRL_SIDE_EFFECT_LP0 (1 << 14) /* enter LP0 when CPU pwr gated */
39 #define PMC_PLLP_WB0_OVERRIDE 0xf8
40 #define PMC_IO_DPD_REQ 0x1b8
41 #define PMC_IO_DPD_STATUS 0x1bc
43 #define CLK_RESET_CCLK_BURST 0x20
44 #define CLK_RESET_CCLK_DIVIDER 0x24
45 #define CLK_RESET_SCLK_BURST 0x28
46 #define CLK_RESET_SCLK_DIVIDER 0x2c
48 #define CLK_RESET_PLLC_BASE 0x80
49 #define CLK_RESET_PLLC_MISC 0x8c
50 #define CLK_RESET_PLLM_BASE 0x90
51 #define CLK_RESET_PLLM_MISC 0x9c
52 #define CLK_RESET_PLLP_BASE 0xa0
53 #define CLK_RESET_PLLP_MISC 0xac
54 #define CLK_RESET_PLLA_BASE 0xb0
55 #define CLK_RESET_PLLA_MISC 0xbc
56 #define CLK_RESET_PLLX_BASE 0xe0
57 #define CLK_RESET_PLLX_MISC 0xe4
58 #define CLK_RESET_PLLX_MISC3 0x518
59 #define CLK_RESET_PLLX_MISC3_IDDQ 3
60 #define CLK_RESET_PLLM_MISC_IDDQ 5
61 #define CLK_RESET_PLLC_MISC_IDDQ 26
62 #define CLK_RESET_PLLP_RESHIFT 0x528
63 #define CLK_RESET_PLLP_RESHIFT_DEFAULT 0x3b
64 #define CLK_RESET_PLLP_RESHIFT_ENABLE 0x3
66 #define CLK_RESET_CLK_SOURCE_MSELECT 0x3b4
68 #define MSELECT_CLKM (0x3 << 30)
70 #define LOCK_DELAY 50 /* safety delay after lock is detected */
72 #define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
74 .macro emc_device_mask, rd, base
75 ldr \rd, [\base, #EMC_ADR_CFG]
77 moveq \rd, #(0x1 << 8) @ just 1 device
78 movne \rd, #(0x3 << 8) @ 2 devices
81 .macro emc_timing_update, rd, base
83 str \rd, [\base, #EMC_TIMING_CONTROL]
85 ldr \rd, [\base, #EMC_EMC_STATUS]
86 tst \rd, #(0x1<<23) @ wait EMC_STATUS_TIMING_UPDATE_STALLED is clear
90 .macro pll_enable, rd, r_car_base, pll_base, pll_misc
91 ldr \rd, [\r_car_base, #\pll_base]
93 orreq \rd, \rd, #(1 << 30)
94 streq \rd, [\r_car_base, #\pll_base]
95 /* Enable lock detector */
97 ldr \rd, [\r_car_base, #\pll_misc]
98 bic \rd, \rd, #(1 << 18)
99 str \rd, [\r_car_base, #\pll_misc]
100 ldr \rd, [\r_car_base, #\pll_misc]
101 ldr \rd, [\r_car_base, #\pll_misc]
102 orr \rd, \rd, #(1 << 18)
103 str \rd, [\r_car_base, #\pll_misc]
107 .macro pll_locked, rd, r_car_base, pll_base
109 ldr \rd, [\r_car_base, #\pll_base]
114 .macro pll_iddq_exit, rd, car, iddq, iddq_bit
115 ldr \rd, [\car, #\iddq]
116 bic \rd, \rd, #(1<<\iddq_bit)
117 str \rd, [\car, #\iddq]
120 .macro pll_iddq_entry, rd, car, iddq, iddq_bit
121 ldr \rd, [\car, #\iddq]
122 orr \rd, \rd, #(1<<\iddq_bit)
123 str \rd, [\car, #\iddq]
126 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
128 * tegra30_hotplug_shutdown(void)
130 * Powergates the current CPU.
131 * Should never return.
133 ENTRY(tegra30_hotplug_shutdown)
134 /* Powergate this CPU */
135 mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
136 bl tegra30_cpu_shutdown
137 ret lr @ should never get here
138 ENDPROC(tegra30_hotplug_shutdown)
141 * tegra30_cpu_shutdown(unsigned long flags)
143 * Puts the current CPU in wait-for-event mode on the flow controller
144 * and powergates it -- flags (in R0) indicate the request type.
147 * corrupts r0-r4, r10-r12
149 ENTRY(tegra30_cpu_shutdown)
151 tegra_get_soc_id TEGRA_APB_MISC_VIRT, r10
153 bne _no_cpu0_chk @ It's not Tegra30
156 reteq lr @ Must never be called for CPU 0
159 ldr r12, =TEGRA_FLOW_CTRL_VIRT
160 cpu_to_csr_reg r1, r3
161 add r1, r1, r12 @ virtual CSR address for this CPU
162 cpu_to_halt_reg r2, r3
163 add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
166 * Clear this CPU's "event" and "interrupt" flags and power gate
167 * it when halting but not before it is in the "WFE" state.
170 FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
173 moveq r4, #(1 << 4) @ wfe bitmap
174 movne r4, #(1 << 8) @ wfi bitmap
175 ARM( orr r12, r12, r4, lsl r3 )
176 THUMB( lsl r4, r4, r3 )
177 THUMB( orr r12, r12, r4 )
183 subs r3, r3, #1 @ delay as a part of wfe war.
185 cpsid a @ disable imprecise aborts.
186 ldr r3, [r1] @ read CSR
187 str r3, [r1] @ clear CSR
189 tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
190 beq flow_ctrl_setting_for_lp2
192 /* flow controller set up for hotplug */
193 mov r3, #FLOW_CTRL_WAITEVENT @ For hotplug
195 flow_ctrl_setting_for_lp2:
196 /* flow controller set up for LP2 */
198 moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
199 movne r3, #FLOW_CTRL_WAITEVENT
200 orrne r3, r3, #FLOW_CTRL_HALT_GIC_IRQ
201 orrne r3, r3, #FLOW_CTRL_HALT_GIC_FIQ
211 wfeeq @ CPU should be power gated here
217 * 38 nop's, which fills rest of wfe cache line and
218 * 4 more cachelines with nop
223 b . @ should never get here
225 ENDPROC(tegra30_cpu_shutdown)
228 #ifdef CONFIG_PM_SLEEP
230 * tegra30_sleep_core_finish(unsigned long v2p)
232 * Enters suspend in LP0 or LP1 by turning off the MMU and jumping to
233 * tegra30_tear_down_core in IRAM
235 ENTRY(tegra30_sleep_core_finish)
237 /* Flush, disable the L1 data cache and exit SMP */
238 mov r0, #TEGRA_FLUSH_CACHE_ALL
239 bl tegra_disable_clean_inv_dcache
243 * Preload all the address literals that are needed for the
244 * CPU power-gating process, to avoid loading from SDRAM which
245 * are not supported once SDRAM is put into self-refresh.
246 * LP0 / LP1 use physical address, since the MMU needs to be
247 * disabled before putting SDRAM into self-refresh to avoid
248 * memory access due to page table walks.
250 mov32 r4, TEGRA_PMC_BASE
251 mov32 r5, TEGRA_CLK_RESET_BASE
252 mov32 r6, TEGRA_FLOW_CTRL_BASE
253 mov32 r7, TEGRA_TMRUS_BASE
255 mov32 r3, tegra_shut_off_mmu
258 mov32 r0, tegra30_tear_down_core
259 mov32 r1, tegra30_iram_start
261 mov32 r1, TEGRA_IRAM_LPx_RESUME_AREA
265 ENDPROC(tegra30_sleep_core_finish)
268 * tegra30_pm_secondary_cpu_suspend(unsigned long unused_arg)
270 * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
272 ENTRY(tegra30_pm_secondary_cpu_suspend)
275 /* Flush and disable the L1 data cache */
276 mov r0, #TEGRA_FLUSH_CACHE_LOUIS
277 bl tegra_disable_clean_inv_dcache
279 /* Powergate this CPU. */
280 mov r0, #0 @ power mode flags (!hotplug)
281 bl tegra30_cpu_shutdown
282 mov r0, #1 @ never return here
284 ENDPROC(tegra30_pm_secondary_cpu_suspend)
287 * tegra30_tear_down_cpu
289 * Switches the CPU to enter sleep.
291 ENTRY(tegra30_tear_down_cpu)
292 mov32 r6, TEGRA_FLOW_CTRL_BASE
294 b tegra30_enter_sleep
295 ENDPROC(tegra30_tear_down_cpu)
297 /* START OF ROUTINES COPIED TO IRAM */
298 .align L1_CACHE_SHIFT
299 .globl tegra30_iram_start
305 * reset vector for LP1 restore; copied into IRAM during suspend.
306 * Brings the system back up to a safe staring point (SDRAM out of
307 * self-refresh, PLLC, PLLM and PLLP reenabled, CPU running on PLLX,
308 * system clock running on the same PLL that it suspended at), and
309 * jumps to tegra_resume to restore virtual addressing.
310 * The physical address of tegra_resume expected to be stored in
313 * NOTE: THIS *MUST* BE RELOCATED TO TEGRA_IRAM_LPx_RESUME_AREA.
315 ENTRY(tegra30_lp1_reset)
317 * The CPU and system bus are running at 32KHz and executing from
318 * IRAM when this code is executed; immediately switch to CLKM and
319 * enable PLLP, PLLM, PLLC, PLLA and PLLX.
321 mov32 r0, TEGRA_CLK_RESET_BASE
324 str r1, [r0, #CLK_RESET_SCLK_BURST]
325 str r1, [r0, #CLK_RESET_CCLK_BURST]
327 str r1, [r0, #CLK_RESET_CCLK_DIVIDER]
328 str r1, [r0, #CLK_RESET_SCLK_DIVIDER]
330 tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
332 beq _no_pll_iddq_exit
334 pll_iddq_exit r1, r0, CLK_RESET_PLLM_MISC, CLK_RESET_PLLM_MISC_IDDQ
335 pll_iddq_exit r1, r0, CLK_RESET_PLLC_MISC, CLK_RESET_PLLC_MISC_IDDQ
336 pll_iddq_exit r1, r0, CLK_RESET_PLLX_MISC3, CLK_RESET_PLLX_MISC3_IDDQ
338 mov32 r7, TEGRA_TMRUS_BASE
341 wait_until r1, r7, r3
343 /* enable PLLM via PMC */
344 mov32 r2, TEGRA_PMC_BASE
345 ldr r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
346 orr r1, r1, #(1 << 12)
347 str r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
349 pll_enable r1, r0, CLK_RESET_PLLM_BASE, 0
350 pll_enable r1, r0, CLK_RESET_PLLC_BASE, 0
351 pll_enable r1, r0, CLK_RESET_PLLX_BASE, 0
356 /* enable PLLM via PMC */
357 mov32 r2, TEGRA_PMC_BASE
358 ldr r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
359 orr r1, r1, #(1 << 12)
360 str r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
362 pll_enable r1, r0, CLK_RESET_PLLM_BASE, CLK_RESET_PLLM_MISC
363 pll_enable r1, r0, CLK_RESET_PLLC_BASE, CLK_RESET_PLLC_MISC
364 pll_enable r1, r0, CLK_RESET_PLLX_BASE, CLK_RESET_PLLX_MISC
367 pll_enable r1, r0, CLK_RESET_PLLP_BASE, CLK_RESET_PLLP_MISC
368 pll_enable r1, r0, CLK_RESET_PLLA_BASE, CLK_RESET_PLLA_MISC
370 pll_locked r1, r0, CLK_RESET_PLLM_BASE
371 pll_locked r1, r0, CLK_RESET_PLLP_BASE
372 pll_locked r1, r0, CLK_RESET_PLLA_BASE
373 pll_locked r1, r0, CLK_RESET_PLLC_BASE
374 pll_locked r1, r0, CLK_RESET_PLLX_BASE
376 tegra_get_soc_id TEGRA_APB_MISC_BASE, r1
380 ldr r1, [r0, #CLK_RESET_PLLP_BASE]
381 bic r1, r1, #(1<<31) @ disable PllP bypass
382 str r1, [r0, #CLK_RESET_PLLP_BASE]
384 mov r1, #CLK_RESET_PLLP_RESHIFT_DEFAULT
385 str r1, [r0, #CLK_RESET_PLLP_RESHIFT]
388 mov32 r7, TEGRA_TMRUS_BASE
390 add r1, r1, #LOCK_DELAY
391 wait_until r1, r7, r3
393 adr r5, tegra_sdram_pad_save
395 ldr r4, [r5, #0x18] @ restore CLK_SOURCE_MSELECT
396 str r4, [r0, #CLK_RESET_CLK_SOURCE_MSELECT]
398 ldr r4, [r5, #0x1C] @ restore SCLK_BURST
399 str r4, [r0, #CLK_RESET_SCLK_BURST]
402 movweq r4, #:lower16:((1 << 28) | (0x8)) @ burst policy is PLLX
403 movteq r4, #:upper16:((1 << 28) | (0x8))
404 movwne r4, #:lower16:((1 << 28) | (0xe))
405 movtne r4, #:upper16:((1 << 28) | (0xe))
406 str r4, [r0, #CLK_RESET_CCLK_BURST]
408 /* Restore pad power state to normal */
409 ldr r1, [r5, #0x14] @ PMC_IO_DPD_STATUS
411 bic r1, r1, #(1 << 31)
412 orr r1, r1, #(1 << 30)
413 str r1, [r2, #PMC_IO_DPD_REQ] @ DPD_OFF
416 movweq r0, #:lower16:TEGRA_EMC_BASE @ r0 reserved for emc base
417 movteq r0, #:upper16:TEGRA_EMC_BASE
419 movweq r0, #:lower16:TEGRA_EMC0_BASE
420 movteq r0, #:upper16:TEGRA_EMC0_BASE
422 movweq r0, #:lower16:TEGRA124_EMC_BASE
423 movteq r0, #:upper16:TEGRA124_EMC_BASE
426 ldr r1, [r5, #0xC] @ restore EMC_XM2VTTGENPADCTRL
427 str r1, [r0, #EMC_XM2VTTGENPADCTRL]
428 ldr r1, [r5, #0x10] @ restore EMC_XM2VTTGENPADCTRL2
429 str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
430 ldr r1, [r5, #0x8] @ restore EMC_AUTO_CAL_INTERVAL
431 str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
434 ldr r1, [r0, #EMC_CFG_DIG_DLL]
435 orr r1, r1, #(1 << 30) @ set DLL_RESET
436 str r1, [r0, #EMC_CFG_DIG_DLL]
438 emc_timing_update r1, r0
441 movweq r1, #:lower16:TEGRA_EMC1_BASE
442 movteq r1, #:upper16:TEGRA_EMC1_BASE
445 ldr r1, [r0, #EMC_AUTO_CAL_CONFIG]
446 orr r1, r1, #(1 << 31) @ set AUTO_CAL_ACTIVE
447 orreq r1, r1, #(1 << 27) @ set slave mode for channel 1
448 str r1, [r0, #EMC_AUTO_CAL_CONFIG]
450 emc_wait_auto_cal_onetime:
451 ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
452 tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
453 bne emc_wait_auto_cal_onetime
455 ldr r1, [r0, #EMC_CFG]
456 bic r1, r1, #(1 << 31) @ disable DRAM_CLK_STOP_PD
457 str r1, [r0, #EMC_CFG]
460 str r1, [r0, #EMC_SELF_REF] @ take DRAM out of self refresh
463 streq r1, [r0, #EMC_NOP]
464 streq r1, [r0, #EMC_NOP]
466 emc_device_mask r1, r0
468 exit_selfrefresh_loop:
469 ldr r2, [r0, #EMC_EMC_STATUS]
471 bne exit_selfrefresh_loop
473 lsr r1, r1, #8 @ devSel, bit0:dev0, bit1:dev1
475 mov32 r7, TEGRA_TMRUS_BASE
476 ldr r2, [r0, #EMC_FBIO_CFG5]
478 and r2, r2, #3 @ check DRAM_TYPE
482 /* Issue a ZQ_CAL for dev0 - DDR3 */
483 mov32 r2, 0x80000011 @ DEV_SELECTION=2, LENGTH=LONG, CMD=1
484 str r2, [r0, #EMC_ZQ_CAL]
487 wait_until r2, r7, r3
492 /* Issue a ZQ_CAL for dev1 - DDR3 */
493 mov32 r2, 0x40000011 @ DEV_SELECTION=1, LENGTH=LONG, CMD=1
494 str r2, [r0, #EMC_ZQ_CAL]
497 wait_until r2, r7, r3
501 /* Issue a ZQ_CAL for dev0 - LPDDR2 */
502 mov32 r2, 0x800A00AB @ DEV_SELECTION=2, MA=10, OP=0xAB
503 str r2, [r0, #EMC_MRW]
506 wait_until r2, r7, r3
511 /* Issue a ZQ_CAL for dev0 - LPDDR2 */
512 mov32 r2, 0x400A00AB @ DEV_SELECTION=1, MA=10, OP=0xAB
513 str r2, [r0, #EMC_MRW]
516 wait_until r2, r7, r3
519 mov r1, #0 @ unstall all transactions
520 str r1, [r0, #EMC_REQ_CTRL]
521 ldr r1, [r5, #0x4] @ restore EMC_ZCAL_INTERVAL
522 str r1, [r0, #EMC_ZCAL_INTERVAL]
523 ldr r1, [r5, #0x0] @ restore EMC_CFG
524 str r1, [r0, #EMC_CFG]
526 emc_timing_update r1, r0
528 /* Tegra114 had dual EMC channel, now config the other one */
530 bne __no_dual_emc_chanl
531 mov32 r1, TEGRA_EMC1_BASE
535 bne exit_self_refresh
538 mov32 r0, TEGRA_PMC_BASE
539 ldr r0, [r0, #PMC_SCRATCH41]
540 ret r0 @ jump to tegra_resume
541 ENDPROC(tegra30_lp1_reset)
543 .align L1_CACHE_SHIFT
544 tegra30_sdram_pad_address:
545 .word TEGRA_EMC_BASE + EMC_CFG @0x0
546 .word TEGRA_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
547 .word TEGRA_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
548 .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
549 .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
550 .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
551 .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
552 .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
553 tegra30_sdram_pad_address_end:
555 tegra114_sdram_pad_address:
556 .word TEGRA_EMC0_BASE + EMC_CFG @0x0
557 .word TEGRA_EMC0_BASE + EMC_ZCAL_INTERVAL @0x4
558 .word TEGRA_EMC0_BASE + EMC_AUTO_CAL_INTERVAL @0x8
559 .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL @0xc
560 .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
561 .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
562 .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
563 .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
564 .word TEGRA_EMC1_BASE + EMC_CFG @0x20
565 .word TEGRA_EMC1_BASE + EMC_ZCAL_INTERVAL @0x24
566 .word TEGRA_EMC1_BASE + EMC_AUTO_CAL_INTERVAL @0x28
567 .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL @0x2c
568 .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL2 @0x30
569 tegra114_sdram_pad_adress_end:
571 tegra124_sdram_pad_address:
572 .word TEGRA124_EMC_BASE + EMC_CFG @0x0
573 .word TEGRA124_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
574 .word TEGRA124_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
575 .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
576 .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
577 .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
578 .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
579 .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
580 tegra124_sdram_pad_address_end:
582 tegra30_sdram_pad_size:
583 .word tegra30_sdram_pad_address_end - tegra30_sdram_pad_address
585 tegra114_sdram_pad_size:
586 .word tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address
588 .type tegra_sdram_pad_save, %object
589 tegra_sdram_pad_save:
590 .rept (tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address) / 4
595 * tegra30_tear_down_core
597 * copied into and executed from IRAM
598 * puts memory in self-refresh for LP0 and LP1
600 tegra30_tear_down_core:
601 bl tegra30_sdram_self_refresh
602 bl tegra30_switch_cpu_to_clk32k
603 b tegra30_enter_sleep
606 * tegra30_switch_cpu_to_clk32k
608 * In LP0 and LP1 all PLLs will be turned off. Switching the CPU and System CLK
609 * to the 32KHz clock.
610 * r4 = TEGRA_PMC_BASE
611 * r5 = TEGRA_CLK_RESET_BASE
612 * r6 = TEGRA_FLOW_CTRL_BASE
613 * r7 = TEGRA_TMRUS_BASE
616 tegra30_switch_cpu_to_clk32k:
618 * start by jumping to CLKM to safely disable PLLs, then jump to
622 str r0, [r5, #CLK_RESET_SCLK_BURST]
623 /* 2uS delay delay between changing SCLK and CCLK */
626 wait_until r1, r7, r9
627 str r0, [r5, #CLK_RESET_CCLK_BURST]
629 str r0, [r5, #CLK_RESET_CCLK_DIVIDER]
630 str r0, [r5, #CLK_RESET_SCLK_DIVIDER]
632 /* switch the clock source of mselect to be CLK_M */
633 ldr r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
634 orr r0, r0, #MSELECT_CLKM
635 str r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
637 /* 2uS delay delay between changing SCLK and disabling PLLs */
640 wait_until r1, r7, r9
642 /* disable PLLM via PMC in LP1 */
643 ldr r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
644 bic r0, r0, #(1 << 12)
645 str r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
647 /* disable PLLP, PLLA, PLLC and PLLX */
648 tegra_get_soc_id TEGRA_APB_MISC_BASE, r1
650 ldr r0, [r5, #CLK_RESET_PLLP_BASE]
651 orrne r0, r0, #(1 << 31) @ enable PllP bypass on fast cluster
652 bic r0, r0, #(1 << 30)
653 str r0, [r5, #CLK_RESET_PLLP_BASE]
655 mov r0, #CLK_RESET_PLLP_RESHIFT_ENABLE
656 str r0, [r5, #CLK_RESET_PLLP_RESHIFT]
658 ldr r0, [r5, #CLK_RESET_PLLA_BASE]
659 bic r0, r0, #(1 << 30)
660 str r0, [r5, #CLK_RESET_PLLA_BASE]
661 ldr r0, [r5, #CLK_RESET_PLLC_BASE]
662 bic r0, r0, #(1 << 30)
663 str r0, [r5, #CLK_RESET_PLLC_BASE]
664 ldr r0, [r5, #CLK_RESET_PLLX_BASE]
665 bic r0, r0, #(1 << 30)
666 str r0, [r5, #CLK_RESET_PLLX_BASE]
670 pll_iddq_entry r1, r5, CLK_RESET_PLLX_MISC3, CLK_RESET_PLLX_MISC3_IDDQ
674 * Switch to clk_s (32KHz); bits 28:31=0
675 * Enable burst on CPU IRQ; bit 24=1
676 * Set IRQ burst clock source to clk_m; bits 10:8=0
679 str r0, [r5, #CLK_RESET_SCLK_BURST]
684 * tegra30_enter_sleep
686 * uses flow controller to enter sleep state
687 * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
688 * executes from SDRAM with target state is LP2
689 * r6 = TEGRA_FLOW_CTRL_BASE
694 cpu_to_csr_reg r2, r1
696 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
697 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
700 tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
702 mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
703 orreq r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
704 orrne r0, r0, #FLOW_CTRL_HALT_LIC_IRQ | FLOW_CTRL_HALT_LIC_FIQ
706 cpu_to_halt_reg r2, r1
709 ldr r0, [r6, r2] /* memory barrier */
715 wfine /* CPU should be power gated here */
718 /* !!!FIXME!!! Implement halt failure handler */
722 * tegra30_sdram_self_refresh
724 * called with MMU off and caches disabled
725 * must be executed from IRAM
726 * r4 = TEGRA_PMC_BASE
727 * r5 = TEGRA_CLK_RESET_BASE
728 * r6 = TEGRA_FLOW_CTRL_BASE
729 * r7 = TEGRA_TMRUS_BASE
732 tegra30_sdram_self_refresh:
734 adr r8, tegra_sdram_pad_save
735 tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
737 adreq r2, tegra30_sdram_pad_address
738 ldreq r3, tegra30_sdram_pad_size
740 adreq r2, tegra114_sdram_pad_address
741 ldreq r3, tegra114_sdram_pad_size
743 adreq r2, tegra124_sdram_pad_address
744 ldreq r3, tegra30_sdram_pad_size
749 ldr r0, [r2, r9] @ r0 is the addr in the pad_address
752 str r1, [r8, r9] @ save the content of the addr
762 ldreq r0, =TEGRA_EMC_BASE @ r0 reserved for emc base addr
764 ldreq r0, =TEGRA_EMC0_BASE
766 ldreq r0, =TEGRA124_EMC_BASE
771 str r1, [r0, #EMC_ZCAL_INTERVAL]
772 str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
773 ldr r1, [r0, #EMC_CFG]
774 bic r1, r1, #(1 << 28)
775 bicne r1, r1, #(1 << 29)
776 str r1, [r0, #EMC_CFG] @ disable DYN_SELF_REF
778 emc_timing_update r1, r0
782 wait_until r1, r7, r2
785 ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
786 tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
787 bne emc_wait_auto_cal
790 str r1, [r0, #EMC_REQ_CTRL] @ stall incoming DRAM requests
793 ldr r1, [r0, #EMC_EMC_STATUS]
798 str r1, [r0, #EMC_SELF_REF]
800 emc_device_mask r1, r0
803 ldr r2, [r0, #EMC_EMC_STATUS]
806 bne emcself @ loop until DDR in self-refresh
808 /* Put VTTGEN in the lowest power mode */
809 ldr r1, [r0, #EMC_XM2VTTGENPADCTRL]
810 mov32 r2, 0xF8F8FFFF @ clear XM2VTTGEN_DRVUP and XM2VTTGEN_DRVDN
812 str r1, [r0, #EMC_XM2VTTGENPADCTRL]
813 ldr r1, [r0, #EMC_XM2VTTGENPADCTRL2]
815 orreq r1, r1, #7 @ set E_NO_VTTGEN
817 str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
819 emc_timing_update r1, r0
821 /* Tegra114 had dual EMC channel, now config the other one */
823 bne no_dual_emc_chanl
824 mov32 r1, TEGRA_EMC1_BASE
827 bne enter_self_refresh
830 ldr r1, [r4, #PMC_CTRL]
831 tst r1, #PMC_CTRL_SIDE_EFFECT_LP0
834 * Put DDR_DATA, DISC_ADDR_CMD, DDR_ADDR_CMD, POP_ADDR_CMD, POP_CLK
835 * and COMP in the lowest power mode when LP1.
838 str r1, [r4, #PMC_IO_DPD_REQ]
846 /* dummy symbol for end of IRAM */
847 .align L1_CACHE_SHIFT
848 .global tegra30_iram_end