1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm/mach-at91/pm_slow_clock.S
5 * Copyright (C) 2006 Savin Zlobec
8 * Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee>
10 #include <linux/linkage.h>
11 #include <linux/clk/at91_pmc.h>
13 #include "pm_data-offsets.h"
15 #define SRAMC_SELF_FRESH_ACTIVE 0x01
16 #define SRAMC_SELF_FRESH_EXIT 0x00
24 * Wait until master clock is ready (after switching master clock source)
26 * @r_mckid: register holding master clock identifier
28 * Side effects: overwrites r7, r8
30 .macro wait_mckrdy r_mckid
31 #ifdef CONFIG_SOC_SAMA7
34 mov r7, #AT91_PMC_MCKXRDY
37 1: mov r7, #AT91_PMC_MCKRDY
38 2: ldr r8, [pmc, #AT91_PMC_SR]
45 * Wait until master oscillator has stabilized.
47 * Side effects: overwrites r7
50 1: ldr r7, [pmc, #AT91_PMC_SR]
51 tst r7, #AT91_PMC_MOSCS
56 * Wait for main oscillator selection is done
58 * Side effects: overwrites r7
61 1: ldr r7, [pmc, #AT91_PMC_SR]
62 tst r7, #AT91_PMC_MOSCSELS
67 * Put the processor to enter the idle state
69 * Side effects: overwrites r7
73 #if defined(CONFIG_CPU_V7)
75 str r7, [pmc, #AT91_PMC_SCDR]
79 wfi @ Wait For Interrupt
81 mcr p15, 0, tmp1, c7, c0, 4
87 * Set state for 2.5V low power regulator
88 * @ena: 0 - disable regulator
89 * 1 - enable regulator
91 * Side effects: overwrites r7, r8, r9, r10
93 .macro at91_2_5V_reg_set_low_power ena
94 #ifdef CONFIG_SOC_SAMA7
97 ldr r9, [r7, #AT91_SFRBU_25LDOCR]
98 orr r9, r9, #AT91_SFRBU_25LDOCR_LP
101 bic r9, r9, #AT91_SFRBU_25LDOCR_LP
103 ldr r10, =AT91_SFRBU_25LDOCR_LDOANAKEY
105 str r9, [r7, #AT91_SFRBU_25LDOCR]
109 .macro at91_backup_set_lpm reg
110 #ifdef CONFIG_SOC_SAMA7
111 orr \reg, \reg, #0x200000
119 #ifdef CONFIG_SOC_SAMA7
121 * Enable self-refresh
123 * Side effects: overwrites r2, r3, tmp1, tmp2, tmp3, r7
125 .macro at91_sramc_self_refresh_ena
127 ldr r3, .sramc_phy_base
132 /* Disable all AXI ports. */
133 ldr tmp1, [r2, #UDDRC_PCTRL_0]
135 str tmp1, [r2, #UDDRC_PCTRL_0]
137 ldr tmp1, [r2, #UDDRC_PCTRL_1]
139 str tmp1, [r2, #UDDRC_PCTRL_1]
141 ldr tmp1, [r2, #UDDRC_PCTRL_2]
143 str tmp1, [r2, #UDDRC_PCTRL_2]
145 ldr tmp1, [r2, #UDDRC_PCTRL_3]
147 str tmp1, [r2, #UDDRC_PCTRL_3]
149 ldr tmp1, [r2, #UDDRC_PCTRL_4]
151 str tmp1, [r2, #UDDRC_PCTRL_4]
154 /* Wait for all ports to disable. */
155 ldr tmp1, [r2, #UDDRC_PSTAT]
156 ldr tmp2, =UDDRC_PSTAT_ALL_PORTS
160 /* Switch to self-refresh. */
161 ldr tmp1, [r2, #UDDRC_PWRCTL]
162 orr tmp1, tmp1, #UDDRC_PWRCTRL_SELFREF_SW
163 str tmp1, [r2, #UDDRC_PWRCTL]
166 /* Wait for self-refresh enter. */
167 ldr tmp1, [r2, #UDDRC_STAT]
168 bic tmp1, tmp1, #~UDDRC_STAT_SELFREF_TYPE_MSK
169 cmp tmp1, #UDDRC_STAT_SELFREF_TYPE_SW
172 /* Disable DX DLLs for non-backup modes. */
173 cmp r7, #AT91_PM_BACKUP
176 /* Do not soft reset the AC DLL. */
177 ldr tmp1, [r3, DDR3PHY_ACDLLCR]
178 bic tmp1, tmp1, DDR3PHY_ACDLLCR_DLLSRST
179 str tmp1, [r3, DDR3PHY_ACDLLCR]
181 /* Disable DX DLLs. */
182 ldr tmp1, [r3, #DDR3PHY_DX0DLLCR]
183 orr tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
184 str tmp1, [r3, #DDR3PHY_DX0DLLCR]
186 ldr tmp1, [r3, #DDR3PHY_DX1DLLCR]
187 orr tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
188 str tmp1, [r3, #DDR3PHY_DX1DLLCR]
191 /* Power down DDR PHY data receivers. */
192 ldr tmp1, [r3, #DDR3PHY_DXCCR]
193 orr tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
194 str tmp1, [r3, #DDR3PHY_DXCCR]
196 /* Power down ADDR/CMD IO. */
197 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
198 orr tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
199 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
200 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
201 str tmp1, [r3, #DDR3PHY_ACIOCR]
203 /* Power down ODT. */
204 ldr tmp1, [r3, #DDR3PHY_DSGCR]
205 orr tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
206 str tmp1, [r3, #DDR3PHY_DSGCR]
210 * Disable self-refresh
212 * Side effects: overwrites r2, r3, tmp1, tmp2, tmp3
214 .macro at91_sramc_self_refresh_dis
216 ldr r3, .sramc_phy_base
218 /* Power up DDR PHY data receivers. */
219 ldr tmp1, [r3, #DDR3PHY_DXCCR]
220 bic tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
221 str tmp1, [r3, #DDR3PHY_DXCCR]
223 /* Power up the output of CK and CS pins. */
224 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
225 bic tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
226 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
227 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
228 str tmp1, [r3, #DDR3PHY_ACIOCR]
231 ldr tmp1, [r3, #DDR3PHY_DSGCR]
232 bic tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
233 str tmp1, [r3, #DDR3PHY_DSGCR]
235 /* Enable DX DLLs. */
236 ldr tmp1, [r3, #DDR3PHY_DX0DLLCR]
237 bic tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
238 str tmp1, [r3, #DDR3PHY_DX0DLLCR]
240 ldr tmp1, [r3, #DDR3PHY_DX1DLLCR]
241 bic tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
242 str tmp1, [r3, #DDR3PHY_DX1DLLCR]
244 /* Enable quasi-dynamic programming. */
246 str tmp1, [r2, #UDDRC_SWCTRL]
248 /* De-assert SDRAM initialization. */
249 ldr tmp1, [r2, #UDDRC_DFIMISC]
250 bic tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
251 str tmp1, [r2, #UDDRC_DFIMISC]
253 /* Quasi-dynamic programming done. */
254 mov tmp1, #UDDRC_SWCTRL_SW_DONE
255 str tmp1, [r2, #UDDRC_SWCTRL]
258 ldr tmp1, [r2, #UDDRC_SWSTAT]
259 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
262 /* DLL soft-reset + DLL lock wait + ITM reset */
263 mov tmp1, #(DDR3PHY_PIR_INIT | DDR3PHY_PIR_DLLSRST | \
264 DDR3PHY_PIR_DLLLOCK | DDR3PHY_PIR_ITMSRST)
265 str tmp1, [r3, #DDR3PHY_PIR]
269 ldr tmp1, [r3, #DDR3PHY_PGSR]
270 tst tmp1, #DDR3PHY_PGSR_IDONE
273 /* Enable quasi-dynamic programming. */
275 str tmp1, [r2, #UDDRC_SWCTRL]
277 /* Assert PHY init complete enable signal. */
278 ldr tmp1, [r2, #UDDRC_DFIMISC]
279 orr tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
280 str tmp1, [r2, #UDDRC_DFIMISC]
282 /* Programming is done. Set sw_done. */
283 mov tmp1, #UDDRC_SWCTRL_SW_DONE
284 str tmp1, [r2, #UDDRC_SWCTRL]
288 ldr tmp1, [r2, #UDDRC_SWSTAT]
289 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
292 /* Trigger self-refresh exit. */
293 ldr tmp1, [r2, #UDDRC_PWRCTL]
294 bic tmp1, tmp1, #UDDRC_PWRCTRL_SELFREF_SW
295 str tmp1, [r2, #UDDRC_PWRCTL]
298 /* Wait for self-refresh exit done. */
299 ldr tmp1, [r2, #UDDRC_STAT]
300 bic tmp1, tmp1, #~UDDRC_STAT_OPMODE_MSK
301 cmp tmp1, #UDDRC_STAT_OPMODE_NORMAL
304 /* Enable all AXI ports. */
305 ldr tmp1, [r2, #UDDRC_PCTRL_0]
307 str tmp1, [r2, #UDDRC_PCTRL_0]
309 ldr tmp1, [r2, #UDDRC_PCTRL_1]
311 str tmp1, [r2, #UDDRC_PCTRL_1]
313 ldr tmp1, [r2, #UDDRC_PCTRL_2]
315 str tmp1, [r2, #UDDRC_PCTRL_2]
317 ldr tmp1, [r2, #UDDRC_PCTRL_3]
319 str tmp1, [r2, #UDDRC_PCTRL_3]
321 ldr tmp1, [r2, #UDDRC_PCTRL_4]
323 str tmp1, [r2, #UDDRC_PCTRL_4]
329 * Enable self-refresh
333 * @r2: base address of the sram controller
336 .macro at91_sramc_self_refresh_ena
340 cmp r1, #AT91_MEMCTRL_MC
343 /* Active SDRAM self-refresh mode */
345 str r3, [r2, #AT91_MC_SDRAMC_SRR]
349 cmp r1, #AT91_MEMCTRL_DDRSDR
353 * DDR Memory controller
356 /* LPDDR1 --> force DDR2 mode during self-refresh */
357 ldr r3, [r2, #AT91_DDRSDRC_MDR]
358 str r3, .saved_sam9_mdr
359 bic r3, r3, #~AT91_DDRSDRC_MD
360 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
361 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
362 biceq r3, r3, #AT91_DDRSDRC_MD
363 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
364 streq r3, [r2, #AT91_DDRSDRC_MDR]
366 /* Active DDRC self-refresh mode */
367 ldr r3, [r2, #AT91_DDRSDRC_LPR]
368 str r3, .saved_sam9_lpr
369 bic r3, r3, #AT91_DDRSDRC_LPCB
370 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
371 str r3, [r2, #AT91_DDRSDRC_LPR]
373 /* If using the 2nd ddr controller */
376 beq sr_ena_no_2nd_ddrc
378 ldr r3, [r2, #AT91_DDRSDRC_MDR]
379 str r3, .saved_sam9_mdr1
380 bic r3, r3, #~AT91_DDRSDRC_MD
381 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
382 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
383 biceq r3, r3, #AT91_DDRSDRC_MD
384 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
385 streq r3, [r2, #AT91_DDRSDRC_MDR]
387 /* Active DDRC self-refresh mode */
388 ldr r3, [r2, #AT91_DDRSDRC_LPR]
389 str r3, .saved_sam9_lpr1
390 bic r3, r3, #AT91_DDRSDRC_LPCB
391 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
392 str r3, [r2, #AT91_DDRSDRC_LPR]
398 * SDRAMC Memory controller
401 /* Active SDRAMC self-refresh mode */
402 ldr r3, [r2, #AT91_SDRAMC_LPR]
403 str r3, .saved_sam9_lpr
404 bic r3, r3, #AT91_SDRAMC_LPCB
405 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
406 str r3, [r2, #AT91_SDRAMC_LPR]
408 ldr r3, .saved_sam9_lpr
409 str r3, [r2, #AT91_SDRAMC_LPR]
415 * Disable self-refresh
419 * @r2: base address of the sram controller
422 .macro at91_sramc_self_refresh_dis
426 cmp r1, #AT91_MEMCTRL_MC
427 bne sr_dis_ddrc_exit_sf
430 * at91rm9200 Memory controller
434 * For exiting the self-refresh mode, do nothing,
435 * automatically exit the self-refresh mode.
440 cmp r1, #AT91_MEMCTRL_DDRSDR
443 /* DDR Memory controller */
445 /* Restore MDR in case of LPDDR1 */
446 ldr r3, .saved_sam9_mdr
447 str r3, [r2, #AT91_DDRSDRC_MDR]
448 /* Restore LPR on AT91 with DDRAM */
449 ldr r3, .saved_sam9_lpr
450 str r3, [r2, #AT91_DDRSDRC_LPR]
452 /* If using the 2nd ddr controller */
455 ldrne r3, .saved_sam9_mdr1
456 strne r3, [r2, #AT91_DDRSDRC_MDR]
457 ldrne r3, .saved_sam9_lpr1
458 strne r3, [r2, #AT91_DDRSDRC_LPR]
463 /* SDRAMC Memory controller */
464 ldr r3, .saved_sam9_lpr
465 str r3, [r2, #AT91_SDRAMC_LPR]
471 .macro at91_pm_ulp0_mode
474 ldr tmp3, .mckr_offset
476 /* Check if ULP0 fast variant has been requested. */
477 cmp tmp2, #AT91_PM_ULP0_FAST
480 /* Set highest prescaler for power saving */
481 ldr tmp1, [pmc, tmp3]
482 bic tmp1, tmp1, #AT91_PMC_PRES
483 orr tmp1, tmp1, #AT91_PMC_PRES_64
484 str tmp1, [pmc, tmp3]
491 /* Turn off the crystal oscillator */
492 ldr tmp1, [pmc, #AT91_CKGR_MOR]
493 bic tmp1, tmp1, #AT91_PMC_MOSCEN
494 orr tmp1, tmp1, #AT91_PMC_KEY
495 str tmp1, [pmc, #AT91_CKGR_MOR]
497 /* Save RC oscillator state */
498 ldr tmp1, [pmc, #AT91_PMC_SR]
499 str tmp1, .saved_osc_status
500 tst tmp1, #AT91_PMC_MOSCRCS
503 /* Turn off RC oscillator */
504 ldr tmp1, [pmc, #AT91_CKGR_MOR]
505 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
506 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
507 orr tmp1, tmp1, #AT91_PMC_KEY
508 str tmp1, [pmc, #AT91_CKGR_MOR]
510 /* Wait main RC disabled done */
511 2: ldr tmp1, [pmc, #AT91_PMC_SR]
512 tst tmp1, #AT91_PMC_MOSCRCS
515 /* Wait for interrupt */
518 /* Check if ULP0 fast variant has been requested. */
519 cmp tmp2, #AT91_PM_ULP0_FAST
522 /* Set lowest prescaler for fast resume. */
523 ldr tmp3, .mckr_offset
524 ldr tmp1, [pmc, tmp3]
525 bic tmp1, tmp1, #AT91_PMC_PRES
526 str tmp1, [pmc, tmp3]
532 5: /* Restore RC oscillator state */
533 ldr tmp1, .saved_osc_status
534 tst tmp1, #AT91_PMC_MOSCRCS
537 /* Turn on RC oscillator */
538 ldr tmp1, [pmc, #AT91_CKGR_MOR]
539 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
540 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
541 orr tmp1, tmp1, #AT91_PMC_KEY
542 str tmp1, [pmc, #AT91_CKGR_MOR]
544 /* Wait main RC stabilization */
545 3: ldr tmp1, [pmc, #AT91_PMC_SR]
546 tst tmp1, #AT91_PMC_MOSCRCS
549 /* Turn on the crystal oscillator */
550 4: ldr tmp1, [pmc, #AT91_CKGR_MOR]
551 orr tmp1, tmp1, #AT91_PMC_MOSCEN
552 orr tmp1, tmp1, #AT91_PMC_KEY
553 str tmp1, [pmc, #AT91_CKGR_MOR]
560 * Note: This procedure only applies on the platform which uses
561 * the external crystal oscillator as a main clock source.
563 .macro at91_pm_ulp1_mode
565 ldr tmp2, .mckr_offset
568 /* Save RC oscillator state and check if it is enabled. */
569 ldr tmp1, [pmc, #AT91_PMC_SR]
570 str tmp1, .saved_osc_status
571 tst tmp1, #AT91_PMC_MOSCRCS
574 /* Enable RC oscillator */
575 ldr tmp1, [pmc, #AT91_CKGR_MOR]
576 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
577 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
578 orr tmp1, tmp1, #AT91_PMC_KEY
579 str tmp1, [pmc, #AT91_CKGR_MOR]
581 /* Wait main RC stabilization */
582 1: ldr tmp1, [pmc, #AT91_PMC_SR]
583 tst tmp1, #AT91_PMC_MOSCRCS
586 /* Switch the main clock source to 12-MHz RC oscillator */
587 2: ldr tmp1, [pmc, #AT91_CKGR_MOR]
588 bic tmp1, tmp1, #AT91_PMC_MOSCSEL
589 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
590 orr tmp1, tmp1, #AT91_PMC_KEY
591 str tmp1, [pmc, #AT91_CKGR_MOR]
595 /* Disable the crystal oscillator */
596 ldr tmp1, [pmc, #AT91_CKGR_MOR]
597 bic tmp1, tmp1, #AT91_PMC_MOSCEN
598 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
599 orr tmp1, tmp1, #AT91_PMC_KEY
600 str tmp1, [pmc, #AT91_CKGR_MOR]
602 /* Switch the master clock source to main clock */
603 ldr tmp1, [pmc, tmp2]
604 bic tmp1, tmp1, #AT91_PMC_CSS
605 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
606 str tmp1, [pmc, tmp2]
610 /* Enter the ULP1 mode by set WAITMODE bit in CKGR_MOR */
611 ldr tmp1, [pmc, #AT91_CKGR_MOR]
612 orr tmp1, tmp1, #AT91_PMC_WAITMODE
613 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
614 orr tmp1, tmp1, #AT91_PMC_KEY
615 str tmp1, [pmc, #AT91_CKGR_MOR]
617 /* Quirk for SAM9X60's PMC */
623 /* Enable the crystal oscillator */
624 ldr tmp1, [pmc, #AT91_CKGR_MOR]
625 orr tmp1, tmp1, #AT91_PMC_MOSCEN
626 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
627 orr tmp1, tmp1, #AT91_PMC_KEY
628 str tmp1, [pmc, #AT91_CKGR_MOR]
632 /* Switch the master clock source to slow clock */
633 ldr tmp1, [pmc, tmp2]
634 bic tmp1, tmp1, #AT91_PMC_CSS
635 str tmp1, [pmc, tmp2]
639 /* Switch main clock source to crystal oscillator */
640 ldr tmp1, [pmc, #AT91_CKGR_MOR]
641 orr tmp1, tmp1, #AT91_PMC_MOSCSEL
642 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
643 orr tmp1, tmp1, #AT91_PMC_KEY
644 str tmp1, [pmc, #AT91_CKGR_MOR]
648 /* Switch the master clock source to main clock */
649 ldr tmp1, [pmc, tmp2]
650 bic tmp1, tmp1, #AT91_PMC_CSS
651 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
652 str tmp1, [pmc, tmp2]
656 /* Restore RC oscillator state */
657 ldr tmp1, .saved_osc_status
658 tst tmp1, #AT91_PMC_MOSCRCS
661 /* Disable RC oscillator */
662 ldr tmp1, [pmc, #AT91_CKGR_MOR]
663 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
664 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
665 orr tmp1, tmp1, #AT91_PMC_KEY
666 str tmp1, [pmc, #AT91_CKGR_MOR]
668 /* Wait RC oscillator disable done */
669 4: ldr tmp1, [pmc, #AT91_PMC_SR]
670 tst tmp1, #AT91_PMC_MOSCRCS
676 .macro at91_plla_disable
677 /* Save PLLA setting and disable it */
678 ldr tmp1, .pmc_version
679 cmp tmp1, #AT91_PMC_V1
682 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
683 /* Save PLLA settings. */
684 ldr tmp2, [pmc, #AT91_PMC_PLL_UPDT]
685 bic tmp2, tmp2, #AT91_PMC_PLL_UPDT_ID
686 str tmp2, [pmc, #AT91_PMC_PLL_UPDT]
690 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL0]
691 bic tmp2, tmp2, #0xffffff00
695 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL1]
696 bic tmp2, tmp2, #0xffffff
698 str tmp1, .saved_pllar
701 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
702 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
703 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
704 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
707 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
708 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
709 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
710 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
713 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
714 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
715 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
716 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
719 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
720 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
721 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
724 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
725 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
726 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
727 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
732 1: /* Save PLLA setting and disable it */
733 ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
734 str tmp1, .saved_pllar
737 mov tmp1, #AT91_PMC_PLLCOUNT
738 orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
739 str tmp1, [pmc, #AT91_CKGR_PLLAR]
743 .macro at91_plla_enable
744 ldr tmp2, .saved_pllar
745 ldr tmp3, .pmc_version
746 cmp tmp3, #AT91_PMC_V1
749 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
751 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
752 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
753 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
754 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
757 ldr tmp1, =AT91_PMC_PLL_ACR_DEFAULT_PLLA
758 str tmp1, [pmc, #AT91_PMC_PLL_ACR]
761 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
763 bic tmp3, tmp3, #0xffffff
765 str tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
768 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
769 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
770 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
771 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
774 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
775 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENLOCK
776 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
777 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
778 bic tmp1, tmp1, #0xff
780 bic tmp3, tmp3, #0xffffff00
782 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
785 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
786 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
787 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
788 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
791 3: ldr tmp1, [pmc, #AT91_PMC_PLL_ISR0]
797 /* Restore PLLA setting */
798 4: str tmp2, [pmc, #AT91_CKGR_PLLAR]
801 tst tmp2, #(AT91_PMC_MUL & 0xff0000)
803 tst tmp2, #(AT91_PMC_MUL & ~0xff0000)
806 1: ldr tmp1, [pmc, #AT91_PMC_SR]
807 tst tmp1, #AT91_PMC_LOCKA
813 * at91_mckx_ps_enable: save MCK1..4 settings and switch it to main clock
815 * Side effects: overwrites tmp1, tmp2
817 .macro at91_mckx_ps_enable
818 #ifdef CONFIG_SOC_SAMA7
821 /* There are 4 MCKs we need to handle: MCK1..4 */
826 /* Write MCK ID to retrieve the settings. */
827 str tmp1, [pmc, #AT91_PMC_MCR_V2]
828 ldr tmp2, [pmc, #AT91_PMC_MCR_V2]
833 str tmp2, .saved_mck1
839 str tmp2, .saved_mck2
845 str tmp2, .saved_mck3
849 str tmp2, .saved_mck4
852 /* Use CSS=MAINCK and DIV=1. */
853 bic tmp2, tmp2, #AT91_PMC_MCR_V2_CSS
854 bic tmp2, tmp2, #AT91_PMC_MCR_V2_DIV
855 orr tmp2, tmp2, #AT91_PMC_MCR_V2_CSS_MAINCK
856 orr tmp2, tmp2, #AT91_PMC_MCR_V2_DIV1
857 str tmp2, [pmc, #AT91_PMC_MCR_V2]
869 * at91_mckx_ps_restore: restore MCK1..4 settings
871 * Side effects: overwrites tmp1, tmp2
873 .macro at91_mckx_ps_restore
874 #ifdef CONFIG_SOC_SAMA7
877 /* There are 4 MCKs we need to handle: MCK1..4 */
885 ldr tmp2, .saved_mck1
891 ldr tmp2, .saved_mck2
897 ldr tmp2, .saved_mck3
901 ldr tmp2, .saved_mck4
904 /* Write MCK ID to retrieve the settings. */
905 str tmp1, [pmc, #AT91_PMC_MCR_V2]
906 ldr tmp3, [pmc, #AT91_PMC_MCR_V2]
908 /* We need to restore CSS and DIV. */
909 bic tmp3, tmp3, #AT91_PMC_MCR_V2_CSS
910 bic tmp3, tmp3, #AT91_PMC_MCR_V2_DIV
912 bic tmp3, tmp3, #AT91_PMC_MCR_V2_ID_MSK
914 orr tmp3, tmp3, #AT91_PMC_MCR_V2_CMD
915 str tmp2, [pmc, #AT91_PMC_MCR_V2]
929 ldr tmp2, .mckr_offset
932 /* Save Master clock setting */
933 ldr tmp1, [pmc, tmp2]
934 str tmp1, .saved_mckr
937 * Set master clock source to:
938 * - MAINCK if using ULP0 fast variant
939 * - slow clock, otherwise
941 bic tmp1, tmp1, #AT91_PMC_CSS
942 cmp tmp3, #AT91_PM_ULP0_FAST
944 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
946 str tmp1, [pmc, tmp2]
953 /* Enable low power mode for 2.5V regulator. */
954 at91_2_5V_reg_set_low_power 1
957 cmp tmp3, #AT91_PM_ULP1
968 /* Disable low power mode for 2.5V regulator. */
969 at91_2_5V_reg_set_low_power 0
976 * Restore master clock setting
978 ldr tmp1, .mckr_offset
979 ldr tmp2, .saved_mckr
980 str tmp2, [pmc, tmp1]
988 .macro at91_backup_mode
989 /* Switch the master clock source to slow clock. */
991 ldr tmp2, .mckr_offset
992 ldr tmp1, [pmc, tmp2]
993 bic tmp1, tmp1, #AT91_PMC_CSS
994 str tmp1, [pmc, tmp2]
1002 str tmp1, [r0, #0x10]
1005 1: ldr tmp1, [r0, #0x10]
1011 mov tmp1, #0xA5000000
1012 add tmp1, tmp1, #0x1
1013 at91_backup_set_lpm tmp1
1018 * void at91_suspend_sram_fn(struct at91_pm_data*)
1020 * @r0: base address of struct at91_pm_data
1022 /* at91_pm_suspend_in_sram must be 8-byte aligned per the requirements of fncpy() */
1024 ENTRY(at91_pm_suspend_in_sram)
1025 /* Save registers on stack */
1026 stmfd sp!, {r4 - r12, lr}
1028 /* Drain write buffer */
1030 mcr p15, 0, tmp1, c7, c10, 4
1034 mcr p15, 0, r4, c8, c7, 0
1036 ldr tmp1, [r0, #PM_DATA_PMC_MCKR_OFFSET]
1037 str tmp1, .mckr_offset
1038 ldr tmp1, [r0, #PM_DATA_PMC_VERSION]
1039 str tmp1, .pmc_version
1040 ldr tmp1, [r0, #PM_DATA_MEMCTRL]
1042 ldr tmp1, [r0, #PM_DATA_MODE]
1046 * ldrne below are here to preload their address in the TLB as access
1047 * to RAM may be limited while in self-refresh.
1049 ldr tmp1, [r0, #PM_DATA_PMC]
1052 ldrne tmp2, [tmp1, #0]
1054 ldr tmp1, [r0, #PM_DATA_RAMC0]
1055 str tmp1, .sramc_base
1057 ldrne tmp2, [tmp1, #0]
1059 ldr tmp1, [r0, #PM_DATA_RAMC1]
1060 str tmp1, .sramc1_base
1062 ldrne tmp2, [tmp1, #0]
1064 #ifndef CONFIG_SOC_SAM_V4_V5
1065 /* ldrne below are here to preload their address in the TLB */
1066 ldr tmp1, [r0, #PM_DATA_RAMC_PHY]
1067 str tmp1, .sramc_phy_base
1069 ldrne tmp2, [tmp1, #0]
1071 ldr tmp1, [r0, #PM_DATA_SHDWC]
1074 ldrne tmp2, [tmp1, #0]
1076 ldr tmp1, [r0, #PM_DATA_SFRBU]
1079 ldrne tmp2, [tmp1, #0x10]
1082 /* Active the self-refresh mode */
1083 at91_sramc_self_refresh_ena
1086 cmp r0, #AT91_PM_STANDBY
1088 cmp r0, #AT91_PM_BACKUP
1095 /* Wait for interrupt */
1104 /* Exit the self-refresh mode */
1105 at91_sramc_self_refresh_dis
1107 /* Restore registers, and return */
1108 ldmfd sp!, {r4 - r12, pc}
1109 ENDPROC(at91_pm_suspend_in_sram)
1145 #ifdef CONFIG_SOC_SAMA7
1156 ENTRY(at91_pm_suspend_in_sram_sz)
1157 .word .-at91_pm_suspend_in_sram