2 * Copyright (C) 2015 Freescale Semiconductor, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the license, or
7 * (at your option) any later version.
9 * This program is distributed in teh hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/linkage.h>
17 #define PM_INFO_PM_INFO_SIZE_OFFSET 0x0
18 #define PM_INFO_TTBR_OFFSET 0x4
19 #define PM_INFO_MMDC_V_OFFSET 0x8
20 #define PM_INFO_IOMUXC_V_OFFSET 0xc
21 #define PM_INFO_CCM_V_OFFSET 0x10
22 #define PM_INFO_L2_V_OFFSET 0x14
23 #define PM_INFO_ANATOP_V_OFFSET 0x18
24 #define PM_INFO_IO_NUM_OFFSET 0x1c
25 #define PM_INFO_IO_VAL_OFFSET 0x20
27 #define MX6Q_MMDC_MAPSR 0x404
28 #define MX6Q_MMDC_MPDGCTRL0 0x83c
30 .global mx6sl_lpm_wfi_start
31 .global mx6sl_lpm_wfi_end
33 .macro pll_do_wait_lock
51 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
53 * if in audio_bus_freq_mode, skip to
54 * audio_mode low power setting.
59 * Now set DDR rate to 1MHz.
60 * DDR is from bypassed PLL2 on periph2_clk2 path.
61 * Set the periph2_clk2_podf to divide by 8.
67 /* Now set MMDC PODF to divide by 3. */
75 /* Set the AHB to 3MHz. AXI to 3MHz. */
77 /*r12 stores the origin AHB podf value */
85 /* Now set ARM to 24MHz.
86 * Move ARM to be sourced from step_clk
87 * after setting step_clk to 24MHz.
92 /*Now pll1_sw_clk to step_clk */
97 /* Bypass PLL1 and power it down */
98 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
104 * Set the ARM PODF to divide by 8.
105 * IPG is at 1.5MHz here, we need ARM to
106 * run at the 12:5 ratio (WAIT mode issue).
108 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
109 ldr r11, [r10, #0x10]
119 * MMDC is sourced from pll2_200M.
120 * Set the mmdc_podf to div by 8
122 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
129 * Bypass PLL1. the PLL1 output is disabled,
130 * need to enable its output.
132 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
138 * ARM is sourced from pll2_pfd2_400M here.
139 * switch ARM to bypassed PLL1
141 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
147 * set the arm_podf to divide by 3
148 * as IPG is at 4MHz, we cannot run
149 * arm clk above 9.6MHz when system
152 ldr r11, [r10, #0x10]
165 * If in audio_bus_freq_mode, skip to
166 * audio_mode ccm restore.
169 beq audio_ccm_restore
171 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
172 /* Power up PLL1 and un-bypass it. */
176 /* Wait for PLL1 to relock */
183 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
184 /* Set PLL1_sw_clk back to PLL1 */
189 /* Restore AHB/AXI back */
190 str r12, [r10, #0x14]
194 /* restore mmdc back to 24MHz*/
203 /* move arm clk back to pll2_pfd2_400M */
208 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
215 /* restore mmdc podf */
216 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
228 .macro check_pll_state
230 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
232 * Check whether any PLL is enabled, as only when
233 * there is no PLLs enabled, 2p5 can be off and
234 * only enable the weak one. PLL1 will be powered
235 * down late, so no need to check PLL1 state.
240 ands r6, r6, #(1 << 31)
245 ands r6, r6, #(1 << 31)
250 ands r6, r6, #(1 << 31)
255 ands r6, r6, #(1 << 31)
260 ands r6, r6, #(1 << 31)
265 ands r6, r6, #(1 << 31)
276 .macro anatop_enter_idle
278 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
280 beq anatop_enter_done
282 /* Disable 1p1 brown out. */
283 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
284 ldr r6, [r10, #0x110]
286 str r6, [r10, #0x110]
288 * Set the OSC bias current to -37.5%
289 * to drop the power on VDDHIGH.
291 ldr r6, [r10, #0x150]
293 str r6, [r10, #0x150]
296 * if the usb VBUS wakeup is enabled, skip
300 beq anatop_enter_done
302 /* Enable the week 2p5 */
303 ldr r6, [r10, #0x130]
305 str r6, [r10, #0x130]
307 /* Disable main 2p5. */
308 ldr r6, [r10, #0x130]
310 str r6, [r10, #0x130]
313 * Cannot diable regular bandgap
314 * in LDO-enable mode. The bandgap
315 * is required for ARM-LDO to regulate
318 ldr r6, [r10, #0x140]
321 bne anatop_enter_done
323 /* Enable low power bandgap */
324 ldr r6, [r10, #0x260]
326 str r6, [r10, #0x260]
329 * Turn off the bias current
330 * from the regular bandgap.
332 ldr r6, [r10, #0x260]
334 str r6, [r10, #0x260]
337 * Clear the REFTTOP+SELFBIASOFF,
338 * self_bais circuit of the band gap.
339 * Per RM, should be cleared when
340 * band gap is powered down.
342 ldr r6, [r10, #0x150]
344 str r6, [r10, #0x150]
346 /* Power down the regular bandgap */
347 ldr r6, [r10, #0x150]
349 str r6, [r10, #0x150]
354 .macro anatop_exit_idle
356 ldr r10, [r0, #PM_INFO_ANATOP_V_OFFSET]
358 beq skip_anatop_restore
361 beq ldo2p5_not_disabled
363 * Regular bandgap will not be disabled
364 * in LDO-enabled mode as it is required
365 * for ARM-LDO to reguulate the voltage.
367 ldr r6, [r10, #0x140]
370 bne skip_bandgap_restore
372 /* Power up the regular bandgap */
373 ldr r6, [r10, #0x150]
375 str r6, [r10, #0x150]
377 /* wait for bandgap stable */
379 ldr r6, [r10, #0x150]
384 /* now disable bandgap self-bias circuit */
385 ldr r6, [r10, #0x150]
387 str r6, [r10, #0x150]
389 /* Turn on the bias current
390 * from the regular bandgap.
392 ldr r6, [r10, #0x260]
394 str r6, [r10, #0x260]
396 /* Disable the low power bandgap */
397 ldr r6, [r10, #0x260]
399 str r6, [r10, #0x260]
401 skip_bandgap_restore:
402 /* Enable main 2p5. */
403 ldr r6, [r10, #0x130]
405 str r6, [r10, #0x130]
407 /* Ensure the 2p5 is up */
409 ldr r6, [r10, #0x130]
414 /* Disable the weak 2p5 */
415 ldr r6, [r10, #0x130]
417 str r6, [r10, #0x130]
421 * Set the OSC bias current to max
422 * value for normal operation.
424 ldr r6, [r10, #0x150]
426 str r6, [r10, #0x150]
428 /* Enable 1p1 brown out, */
429 ldr r6, [r10, #0x110]
431 str r6, [r10, #0x110]
437 .macro disable_l1_dcache
439 /* disable d-cache */
440 mrc p15, 0, r7, c1, c0, 0
441 bic r7, r7, #(1 << 2)
442 mcr p15, 0, r7, c1, c0, 0
449 .macro mmdc_enter_dvfs_mode
451 /* disable automatic power saving. */
452 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
454 str r7, [r10, #MX6Q_MMDC_MAPSR]
456 /* disable power down timer */
461 /* Make the DDR explicitly enter self-refresh. */
462 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
463 orr r7, r7, #(1 << 21)
464 str r7, [r10, #MX6Q_MMDC_MAPSR]
467 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
468 ands r7, r7, #(1 << 25)
471 /* set SBS step-by step mode */
472 ldr r7, [r10, #0x410]
474 str r7, [r10, #0x410]
479 /* restore MMDC IO */
480 ldr r10, [r0, #PM_INFO_IOMUXC_V_OFFSET]
482 ldr r6, [r0, #PM_INFO_IO_NUM_OFFSET]
483 ldr r7, =PM_INFO_IO_VAL_OFFSET
493 * Need to reset the FIFO to avoid MMDC lockup
494 * caused because of floating/changing the
495 * configuration of many DDR IO pads.
497 ldr r10, [r0, #PM_INFO_MMDC_V_OFFSET]
498 /* reset read FIFO, RST_RD_FIFO */
499 ldr r7, =MX6Q_MMDC_MPDGCTRL0
501 orr r6, r6, #(1 << 31)
505 ands r6, r6, #(1 << 31)
508 /* reset FIFO a second time */
509 ldr r7, =MX6Q_MMDC_MPDGCTRL0
511 orr r6, r6, #(1 << 31)
515 ands r6, r6, #(1 <<31)
518 ldr r10, [r0, #PM_INFO_MMDC_V_OFFSET]
519 /* Let DDR out of self-refresh */
520 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
521 bic r7, r7, #(1 << 21)
522 str r7, [r10, #MX6Q_MMDC_MAPSR]
524 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
525 ands r7, r7, #(1 << 25)
528 /* enable power down timer */
533 /* enable DDR auto power saving */
534 ldr r7, [r10, #MX6Q_MMDC_MAPSR]
536 str r7, [r10, #MX6Q_MMDC_MAPSR]
538 /* Clear SBS - unblock DDR accesses */
539 ldr r7, [r10, #0x410]
541 str r7, [r10, #0x410]
545 .macro tlb_set_to_ocram
548 mrc p15, 0, r7, c2, c0, 1
549 str r7, [r0, #PM_INFO_TTBR_OFFSET]
552 * To ensure no page table walks occur in DDR, we
553 * have a another page table stored in IRAM that only
554 * contains entries pointing to IRAM, AIPS1 and AIPS2.
555 * we need to set the TTBR1 to the new IRAM TLB.
556 * Do the following steps:
557 * 1. Flush the Branch Target Address Cache (BTAC)
558 * 2. Set TTBR1 to point to the IRAM page table.
559 * 3. Disable page table walks in TTBR0 (PD0 = 1)
560 * 4. Set TTBR0.N=1, implying 0-2G is transslated by TTBR0
561 * and 2-4G is translated by TTBR1.
564 ldr r6, =iram_tlb_phys_addr
567 /* Disable Branch Prediction, Z bit in SCTLR */
568 mrc p15, 0, r6, c1, c0, 0
570 mcr p15, 0, r6, c1, c0, 0
572 /* Flush the BTAC. */
574 mcr p15, 0, r6, c7, c1, 6
579 /* store the IRAM table in TTBR1 */
580 mcr p15, 0, r7, c2, c0, 1
581 /* Read TTBCR and set PD0=1, N=1 */
582 mrc p15, 0, r6, c2, c0, 2
584 mcr p15, 0, r6, c2, c0, 2
591 mcr p15, 0, r6, c8, c3, 0
595 .macro tlb_back_to_ddr
597 /* Restore the TTBCR */
601 /* Read TTBCR and set PD0=0, N=0 */
602 mrc p15, 0, r6, c2, c0, 2
604 mcr p15, 0, r6, c2, c0, 2
607 mcr p15, 0, r6, c8, c3, 0
612 /* Enable Branch Prediction, Z bit in SCTLR. */
613 mrc p15, 0, r6, c1, c0, 0
615 mcr p15, 0 ,r6, c1, c0, 0
616 /* Flush the Branch Target Address Cache (BTAC) */
618 mcr p15, 0, r6, c7, c1, 6
620 ldr r7, [r0, #PM_INFO_TTBR_OFFSET]
621 mcr p15, 0, r7, c2, c0, 1
625 .extern iram_tlb_phys_addr
628 * imx6sl_low_power_wfi code
629 * r0: wfi code base address
630 * r1: audio_bus_freq mode stat
631 * r2: vbus_ldo status
632 * r4: used for store the PLLs state
633 * r11: used for saving the ARM_PODF origin value
634 * r12: used for saving AHB_PODF origin value
637 ENTRY(imx6sl_low_power_wfi)
646 #ifdef CONFIG_CACHE_L2X0
648 ldr r10, [r0, #PM_INFO_L2_V_OFFSET]
649 /* Wait for background operations to complete. */
651 ldr r6, [r10, #0x730]
656 str r6, [r10, #0x730]
658 str r6, [r10, #0x100]
664 /* make sure MMDC in self-refresh */
665 ldr r10, [r0, #PM_INFO_MMDC_V_OFFSET]
667 /* save DDR IO settings and set to LPM mode*/
668 ldr r10, [r0, #PM_INFO_IOMUXC_V_OFFSET]
670 ldr r7, [r0, #PM_INFO_IO_NUM_OFFSET]
671 ldr r8, =PM_INFO_IO_VAL_OFFSET
674 /* imx6sl's last 3 IOs need special setting */
676 save_and_set_mmdc_io_lpm:
682 bne save_and_set_mmdc_io_lpm
699 /* check the PLLs lock state */
703 /* if in audio low power mode, no
704 * need to do anatop setting.
712 * Add these nops so that the
713 * prefetcher will not try to get
714 * any instrutions from DDR.
715 * The prefetch depth is about 23
716 * on A9, so adding 25 nops.
749 * restore the ARM PODF first to speed
750 * up the restore procedure
752 ldr r10, [r0, #PM_INFO_CCM_V_OFFSET]
753 /* Restore arm_clk_podf */
754 str r11, [r10, #0x10]
758 * if in audio low power mode, skip
759 * restore the anatop setting.
762 beq skip_analog_restore
770 mrc p15, 0, r7, c1, c0, 0
771 orr r7, r7, #(1 << 2)
772 mcr p15, 0, r7, c1, c0, 0
774 #ifdef CONFIG_CACHE_L2X0
775 ldr r10, [r0, #PM_INFO_L2_V_OFFSET]
778 str r7, [r10, #0x100]
782 /* Restore register */
787 * Add ltorg here to ensure that all
788 * literals are stored here and are
789 * within the text space.