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 /* Put DDR PHY's DLL in bypass mode for non-backup modes. */
173 cmp r7, #AT91_PM_BACKUP
175 ldr tmp1, [r3, #DDR3PHY_PIR]
176 orr tmp1, tmp1, #DDR3PHY_PIR_DLLBYP
177 str tmp1, [r3, #DDR3PHY_PIR]
180 /* Power down DDR PHY data receivers. */
181 ldr tmp1, [r3, #DDR3PHY_DXCCR]
182 orr tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
183 str tmp1, [r3, #DDR3PHY_DXCCR]
185 /* Power down ADDR/CMD IO. */
186 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
187 orr tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
188 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
189 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
190 str tmp1, [r3, #DDR3PHY_ACIOCR]
192 /* Power down ODT. */
193 ldr tmp1, [r3, #DDR3PHY_DSGCR]
194 orr tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
195 str tmp1, [r3, #DDR3PHY_DSGCR]
199 * Disable self-refresh
201 * Side effects: overwrites r2, r3, tmp1, tmp2, tmp3
203 .macro at91_sramc_self_refresh_dis
205 ldr r3, .sramc_phy_base
207 /* Power up DDR PHY data receivers. */
208 ldr tmp1, [r3, #DDR3PHY_DXCCR]
209 bic tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
210 str tmp1, [r3, #DDR3PHY_DXCCR]
212 /* Power up the output of CK and CS pins. */
213 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
214 bic tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
215 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
216 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
217 str tmp1, [r3, #DDR3PHY_ACIOCR]
220 ldr tmp1, [r3, #DDR3PHY_DSGCR]
221 bic tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
222 str tmp1, [r3, #DDR3PHY_DSGCR]
224 /* Take DDR PHY's DLL out of bypass mode. */
225 ldr tmp1, [r3, #DDR3PHY_PIR]
226 bic tmp1, tmp1, #DDR3PHY_PIR_DLLBYP
227 str tmp1, [r3, #DDR3PHY_PIR]
229 /* Enable quasi-dynamic programming. */
231 str tmp1, [r2, #UDDRC_SWCTRL]
233 /* De-assert SDRAM initialization. */
234 ldr tmp1, [r2, #UDDRC_DFIMISC]
235 bic tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
236 str tmp1, [r2, #UDDRC_DFIMISC]
238 /* Quasi-dynamic programming done. */
239 mov tmp1, #UDDRC_SWCTRL_SW_DONE
240 str tmp1, [r2, #UDDRC_SWCTRL]
243 ldr tmp1, [r2, #UDDRC_SWSTAT]
244 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
247 /* DLL soft-reset + DLL lock wait + ITM reset */
248 mov tmp1, #(DDR3PHY_PIR_INIT | DDR3PHY_PIR_DLLSRST | \
249 DDR3PHY_PIR_DLLLOCK | DDR3PHY_PIR_ITMSRST)
250 str tmp1, [r3, #DDR3PHY_PIR]
254 ldr tmp1, [r3, #DDR3PHY_PGSR]
255 tst tmp1, #DDR3PHY_PGSR_IDONE
258 /* Enable quasi-dynamic programming. */
260 str tmp1, [r2, #UDDRC_SWCTRL]
262 /* Assert PHY init complete enable signal. */
263 ldr tmp1, [r2, #UDDRC_DFIMISC]
264 orr tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
265 str tmp1, [r2, #UDDRC_DFIMISC]
267 /* Programming is done. Set sw_done. */
268 mov tmp1, #UDDRC_SWCTRL_SW_DONE
269 str tmp1, [r2, #UDDRC_SWCTRL]
273 ldr tmp1, [r2, #UDDRC_SWSTAT]
274 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
277 /* Trigger self-refresh exit. */
278 ldr tmp1, [r2, #UDDRC_PWRCTL]
279 bic tmp1, tmp1, #UDDRC_PWRCTRL_SELFREF_SW
280 str tmp1, [r2, #UDDRC_PWRCTL]
283 /* Wait for self-refresh exit done. */
284 ldr tmp1, [r2, #UDDRC_STAT]
285 bic tmp1, tmp1, #~UDDRC_STAT_OPMODE_MSK
286 cmp tmp1, #UDDRC_STAT_OPMODE_NORMAL
289 /* Enable all AXI ports. */
290 ldr tmp1, [r2, #UDDRC_PCTRL_0]
292 str tmp1, [r2, #UDDRC_PCTRL_0]
294 ldr tmp1, [r2, #UDDRC_PCTRL_1]
296 str tmp1, [r2, #UDDRC_PCTRL_1]
298 ldr tmp1, [r2, #UDDRC_PCTRL_2]
300 str tmp1, [r2, #UDDRC_PCTRL_2]
302 ldr tmp1, [r2, #UDDRC_PCTRL_3]
304 str tmp1, [r2, #UDDRC_PCTRL_3]
306 ldr tmp1, [r2, #UDDRC_PCTRL_4]
308 str tmp1, [r2, #UDDRC_PCTRL_4]
314 * Enable self-refresh
318 * @r2: base address of the sram controller
321 .macro at91_sramc_self_refresh_ena
325 cmp r1, #AT91_MEMCTRL_MC
328 /* Active SDRAM self-refresh mode */
330 str r3, [r2, #AT91_MC_SDRAMC_SRR]
334 cmp r1, #AT91_MEMCTRL_DDRSDR
338 * DDR Memory controller
341 /* LPDDR1 --> force DDR2 mode during self-refresh */
342 ldr r3, [r2, #AT91_DDRSDRC_MDR]
343 str r3, .saved_sam9_mdr
344 bic r3, r3, #~AT91_DDRSDRC_MD
345 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
346 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
347 biceq r3, r3, #AT91_DDRSDRC_MD
348 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
349 streq r3, [r2, #AT91_DDRSDRC_MDR]
351 /* Active DDRC self-refresh mode */
352 ldr r3, [r2, #AT91_DDRSDRC_LPR]
353 str r3, .saved_sam9_lpr
354 bic r3, r3, #AT91_DDRSDRC_LPCB
355 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
356 str r3, [r2, #AT91_DDRSDRC_LPR]
358 /* If using the 2nd ddr controller */
361 beq sr_ena_no_2nd_ddrc
363 ldr r3, [r2, #AT91_DDRSDRC_MDR]
364 str r3, .saved_sam9_mdr1
365 bic r3, r3, #~AT91_DDRSDRC_MD
366 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
367 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
368 biceq r3, r3, #AT91_DDRSDRC_MD
369 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
370 streq r3, [r2, #AT91_DDRSDRC_MDR]
372 /* Active DDRC self-refresh mode */
373 ldr r3, [r2, #AT91_DDRSDRC_LPR]
374 str r3, .saved_sam9_lpr1
375 bic r3, r3, #AT91_DDRSDRC_LPCB
376 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
377 str r3, [r2, #AT91_DDRSDRC_LPR]
383 * SDRAMC Memory controller
386 /* Active SDRAMC self-refresh mode */
387 ldr r3, [r2, #AT91_SDRAMC_LPR]
388 str r3, .saved_sam9_lpr
389 bic r3, r3, #AT91_SDRAMC_LPCB
390 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
391 str r3, [r2, #AT91_SDRAMC_LPR]
393 ldr r3, .saved_sam9_lpr
394 str r3, [r2, #AT91_SDRAMC_LPR]
400 * Disable self-refresh
404 * @r2: base address of the sram controller
407 .macro at91_sramc_self_refresh_dis
411 cmp r1, #AT91_MEMCTRL_MC
412 bne sr_dis_ddrc_exit_sf
415 * at91rm9200 Memory controller
419 * For exiting the self-refresh mode, do nothing,
420 * automatically exit the self-refresh mode.
425 cmp r1, #AT91_MEMCTRL_DDRSDR
428 /* DDR Memory controller */
430 /* Restore MDR in case of LPDDR1 */
431 ldr r3, .saved_sam9_mdr
432 str r3, [r2, #AT91_DDRSDRC_MDR]
433 /* Restore LPR on AT91 with DDRAM */
434 ldr r3, .saved_sam9_lpr
435 str r3, [r2, #AT91_DDRSDRC_LPR]
437 /* If using the 2nd ddr controller */
440 ldrne r3, .saved_sam9_mdr1
441 strne r3, [r2, #AT91_DDRSDRC_MDR]
442 ldrne r3, .saved_sam9_lpr1
443 strne r3, [r2, #AT91_DDRSDRC_LPR]
448 /* SDRAMC Memory controller */
449 ldr r3, .saved_sam9_lpr
450 str r3, [r2, #AT91_SDRAMC_LPR]
456 .macro at91_pm_ulp0_mode
459 ldr tmp3, .mckr_offset
461 /* Check if ULP0 fast variant has been requested. */
462 cmp tmp2, #AT91_PM_ULP0_FAST
465 /* Set highest prescaler for power saving */
466 ldr tmp1, [pmc, tmp3]
467 bic tmp1, tmp1, #AT91_PMC_PRES
468 orr tmp1, tmp1, #AT91_PMC_PRES_64
469 str tmp1, [pmc, tmp3]
476 /* Turn off the crystal oscillator */
477 ldr tmp1, [pmc, #AT91_CKGR_MOR]
478 bic tmp1, tmp1, #AT91_PMC_MOSCEN
479 orr tmp1, tmp1, #AT91_PMC_KEY
480 str tmp1, [pmc, #AT91_CKGR_MOR]
482 /* Save RC oscillator state */
483 ldr tmp1, [pmc, #AT91_PMC_SR]
484 str tmp1, .saved_osc_status
485 tst tmp1, #AT91_PMC_MOSCRCS
488 /* Turn off RC oscillator */
489 ldr tmp1, [pmc, #AT91_CKGR_MOR]
490 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
491 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
492 orr tmp1, tmp1, #AT91_PMC_KEY
493 str tmp1, [pmc, #AT91_CKGR_MOR]
495 /* Wait main RC disabled done */
496 2: ldr tmp1, [pmc, #AT91_PMC_SR]
497 tst tmp1, #AT91_PMC_MOSCRCS
500 /* Wait for interrupt */
503 /* Check if ULP0 fast variant has been requested. */
504 cmp tmp2, #AT91_PM_ULP0_FAST
507 /* Set lowest prescaler for fast resume. */
508 ldr tmp3, .mckr_offset
509 ldr tmp1, [pmc, tmp3]
510 bic tmp1, tmp1, #AT91_PMC_PRES
511 str tmp1, [pmc, tmp3]
517 5: /* Restore RC oscillator state */
518 ldr tmp1, .saved_osc_status
519 tst tmp1, #AT91_PMC_MOSCRCS
522 /* Turn on RC oscillator */
523 ldr tmp1, [pmc, #AT91_CKGR_MOR]
524 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
525 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
526 orr tmp1, tmp1, #AT91_PMC_KEY
527 str tmp1, [pmc, #AT91_CKGR_MOR]
529 /* Wait main RC stabilization */
530 3: ldr tmp1, [pmc, #AT91_PMC_SR]
531 tst tmp1, #AT91_PMC_MOSCRCS
534 /* Turn on the crystal oscillator */
535 4: ldr tmp1, [pmc, #AT91_CKGR_MOR]
536 orr tmp1, tmp1, #AT91_PMC_MOSCEN
537 orr tmp1, tmp1, #AT91_PMC_KEY
538 str tmp1, [pmc, #AT91_CKGR_MOR]
545 * Note: This procedure only applies on the platform which uses
546 * the external crystal oscillator as a main clock source.
548 .macro at91_pm_ulp1_mode
550 ldr tmp2, .mckr_offset
553 /* Save RC oscillator state and check if it is enabled. */
554 ldr tmp1, [pmc, #AT91_PMC_SR]
555 str tmp1, .saved_osc_status
556 tst tmp1, #AT91_PMC_MOSCRCS
559 /* Enable RC oscillator */
560 ldr tmp1, [pmc, #AT91_CKGR_MOR]
561 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
562 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
563 orr tmp1, tmp1, #AT91_PMC_KEY
564 str tmp1, [pmc, #AT91_CKGR_MOR]
566 /* Wait main RC stabilization */
567 1: ldr tmp1, [pmc, #AT91_PMC_SR]
568 tst tmp1, #AT91_PMC_MOSCRCS
571 /* Switch the main clock source to 12-MHz RC oscillator */
572 2: ldr tmp1, [pmc, #AT91_CKGR_MOR]
573 bic tmp1, tmp1, #AT91_PMC_MOSCSEL
574 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
575 orr tmp1, tmp1, #AT91_PMC_KEY
576 str tmp1, [pmc, #AT91_CKGR_MOR]
580 /* Disable the crystal oscillator */
581 ldr tmp1, [pmc, #AT91_CKGR_MOR]
582 bic tmp1, tmp1, #AT91_PMC_MOSCEN
583 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
584 orr tmp1, tmp1, #AT91_PMC_KEY
585 str tmp1, [pmc, #AT91_CKGR_MOR]
587 /* Switch the master clock source to main clock */
588 ldr tmp1, [pmc, tmp2]
589 bic tmp1, tmp1, #AT91_PMC_CSS
590 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
591 str tmp1, [pmc, tmp2]
595 /* Enter the ULP1 mode by set WAITMODE bit in CKGR_MOR */
596 ldr tmp1, [pmc, #AT91_CKGR_MOR]
597 orr tmp1, tmp1, #AT91_PMC_WAITMODE
598 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
599 orr tmp1, tmp1, #AT91_PMC_KEY
600 str tmp1, [pmc, #AT91_CKGR_MOR]
602 /* Quirk for SAM9X60's PMC */
608 /* Enable the crystal oscillator */
609 ldr tmp1, [pmc, #AT91_CKGR_MOR]
610 orr tmp1, tmp1, #AT91_PMC_MOSCEN
611 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
612 orr tmp1, tmp1, #AT91_PMC_KEY
613 str tmp1, [pmc, #AT91_CKGR_MOR]
617 /* Switch the master clock source to slow clock */
618 ldr tmp1, [pmc, tmp2]
619 bic tmp1, tmp1, #AT91_PMC_CSS
620 str tmp1, [pmc, tmp2]
624 /* Switch main clock source to crystal oscillator */
625 ldr tmp1, [pmc, #AT91_CKGR_MOR]
626 orr tmp1, tmp1, #AT91_PMC_MOSCSEL
627 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
628 orr tmp1, tmp1, #AT91_PMC_KEY
629 str tmp1, [pmc, #AT91_CKGR_MOR]
633 /* Switch the master clock source to main clock */
634 ldr tmp1, [pmc, tmp2]
635 bic tmp1, tmp1, #AT91_PMC_CSS
636 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
637 str tmp1, [pmc, tmp2]
641 /* Restore RC oscillator state */
642 ldr tmp1, .saved_osc_status
643 tst tmp1, #AT91_PMC_MOSCRCS
646 /* Disable RC oscillator */
647 ldr tmp1, [pmc, #AT91_CKGR_MOR]
648 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
649 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
650 orr tmp1, tmp1, #AT91_PMC_KEY
651 str tmp1, [pmc, #AT91_CKGR_MOR]
653 /* Wait RC oscillator disable done */
654 4: ldr tmp1, [pmc, #AT91_PMC_SR]
655 tst tmp1, #AT91_PMC_MOSCRCS
661 .macro at91_plla_disable
662 /* Save PLLA setting and disable it */
663 ldr tmp1, .pmc_version
664 cmp tmp1, #AT91_PMC_V1
667 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
668 /* Save PLLA settings. */
669 ldr tmp2, [pmc, #AT91_PMC_PLL_UPDT]
670 bic tmp2, tmp2, #AT91_PMC_PLL_UPDT_ID
671 str tmp2, [pmc, #AT91_PMC_PLL_UPDT]
675 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL0]
676 bic tmp2, tmp2, #0xffffff00
680 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL1]
681 bic tmp2, tmp2, #0xffffff
683 str tmp1, .saved_pllar
686 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
687 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
688 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
689 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
692 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
693 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
694 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
695 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
698 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
699 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
700 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
701 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
704 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
705 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
706 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
709 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
710 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
711 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
712 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
717 1: /* Save PLLA setting and disable it */
718 ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
719 str tmp1, .saved_pllar
722 mov tmp1, #AT91_PMC_PLLCOUNT
723 orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
724 str tmp1, [pmc, #AT91_CKGR_PLLAR]
728 .macro at91_plla_enable
729 ldr tmp2, .saved_pllar
730 ldr tmp3, .pmc_version
731 cmp tmp3, #AT91_PMC_V1
734 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
736 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
737 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
738 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
739 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
742 ldr tmp1, =AT91_PMC_PLL_ACR_DEFAULT_PLLA
743 str tmp1, [pmc, #AT91_PMC_PLL_ACR]
746 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
748 bic tmp3, tmp3, #0xffffff
750 str tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
753 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
754 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
755 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
756 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
759 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
760 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENLOCK
761 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
762 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
763 bic tmp1, tmp1, #0xff
765 bic tmp3, tmp3, #0xffffff00
767 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
770 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
771 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
772 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
773 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
776 3: ldr tmp1, [pmc, #AT91_PMC_PLL_ISR0]
782 /* Restore PLLA setting */
783 4: str tmp2, [pmc, #AT91_CKGR_PLLAR]
786 tst tmp2, #(AT91_PMC_MUL & 0xff0000)
788 tst tmp2, #(AT91_PMC_MUL & ~0xff0000)
791 1: ldr tmp1, [pmc, #AT91_PMC_SR]
792 tst tmp1, #AT91_PMC_LOCKA
798 * at91_mckx_ps_enable: save MCK1..4 settings and switch it to main clock
800 * Side effects: overwrites tmp1, tmp2
802 .macro at91_mckx_ps_enable
803 #ifdef CONFIG_SOC_SAMA7
806 /* There are 4 MCKs we need to handle: MCK1..4 */
811 /* Write MCK ID to retrieve the settings. */
812 str tmp1, [pmc, #AT91_PMC_MCR_V2]
813 ldr tmp2, [pmc, #AT91_PMC_MCR_V2]
818 str tmp2, .saved_mck1
824 str tmp2, .saved_mck2
830 str tmp2, .saved_mck3
834 str tmp2, .saved_mck4
837 /* Use CSS=MAINCK and DIV=1. */
838 bic tmp2, tmp2, #AT91_PMC_MCR_V2_CSS
839 bic tmp2, tmp2, #AT91_PMC_MCR_V2_DIV
840 orr tmp2, tmp2, #AT91_PMC_MCR_V2_CSS_MAINCK
841 orr tmp2, tmp2, #AT91_PMC_MCR_V2_DIV1
842 str tmp2, [pmc, #AT91_PMC_MCR_V2]
854 * at91_mckx_ps_restore: restore MCK1..4 settings
856 * Side effects: overwrites tmp1, tmp2
858 .macro at91_mckx_ps_restore
859 #ifdef CONFIG_SOC_SAMA7
862 /* There are 4 MCKs we need to handle: MCK1..4 */
870 ldr tmp2, .saved_mck1
876 ldr tmp2, .saved_mck2
882 ldr tmp2, .saved_mck3
886 ldr tmp2, .saved_mck4
889 /* Write MCK ID to retrieve the settings. */
890 str tmp1, [pmc, #AT91_PMC_MCR_V2]
891 ldr tmp3, [pmc, #AT91_PMC_MCR_V2]
893 /* We need to restore CSS and DIV. */
894 bic tmp3, tmp3, #AT91_PMC_MCR_V2_CSS
895 bic tmp3, tmp3, #AT91_PMC_MCR_V2_DIV
897 bic tmp3, tmp3, #AT91_PMC_MCR_V2_ID_MSK
899 orr tmp3, tmp3, #AT91_PMC_MCR_V2_CMD
900 str tmp2, [pmc, #AT91_PMC_MCR_V2]
914 ldr tmp2, .mckr_offset
917 /* Save Master clock setting */
918 ldr tmp1, [pmc, tmp2]
919 str tmp1, .saved_mckr
922 * Set master clock source to:
923 * - MAINCK if using ULP0 fast variant
924 * - slow clock, otherwise
926 bic tmp1, tmp1, #AT91_PMC_CSS
927 cmp tmp3, #AT91_PM_ULP0_FAST
929 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
931 str tmp1, [pmc, tmp2]
938 /* Enable low power mode for 2.5V regulator. */
939 at91_2_5V_reg_set_low_power 1
942 cmp tmp3, #AT91_PM_ULP1
953 /* Disable low power mode for 2.5V regulator. */
954 at91_2_5V_reg_set_low_power 0
961 * Restore master clock setting
963 ldr tmp1, .mckr_offset
964 ldr tmp2, .saved_mckr
965 str tmp2, [pmc, tmp1]
973 .macro at91_backup_mode
974 /* Switch the master clock source to slow clock. */
976 ldr tmp2, .mckr_offset
977 ldr tmp1, [pmc, tmp2]
978 bic tmp1, tmp1, #AT91_PMC_CSS
979 str tmp1, [pmc, tmp2]
987 str tmp1, [r0, #0x10]
990 1: ldr tmp1, [r0, #0x10]
996 mov tmp1, #0xA5000000
998 at91_backup_set_lpm tmp1
1003 * void at91_suspend_sram_fn(struct at91_pm_data*)
1005 * @r0: base address of struct at91_pm_data
1007 /* at91_pm_suspend_in_sram must be 8-byte aligned per the requirements of fncpy() */
1009 ENTRY(at91_pm_suspend_in_sram)
1010 /* Save registers on stack */
1011 stmfd sp!, {r4 - r12, lr}
1013 /* Drain write buffer */
1015 mcr p15, 0, tmp1, c7, c10, 4
1017 ldr tmp1, [r0, #PM_DATA_PMC]
1019 ldr tmp1, [r0, #PM_DATA_RAMC0]
1020 str tmp1, .sramc_base
1021 ldr tmp1, [r0, #PM_DATA_RAMC1]
1022 str tmp1, .sramc1_base
1023 ldr tmp1, [r0, #PM_DATA_RAMC_PHY]
1024 str tmp1, .sramc_phy_base
1025 ldr tmp1, [r0, #PM_DATA_MEMCTRL]
1027 ldr tmp1, [r0, #PM_DATA_MODE]
1029 ldr tmp1, [r0, #PM_DATA_PMC_MCKR_OFFSET]
1030 str tmp1, .mckr_offset
1031 ldr tmp1, [r0, #PM_DATA_PMC_VERSION]
1032 str tmp1, .pmc_version
1033 /* Both ldrne below are here to preload their address in the TLB */
1034 ldr tmp1, [r0, #PM_DATA_SHDWC]
1037 ldrne tmp2, [tmp1, #0]
1038 ldr tmp1, [r0, #PM_DATA_SFRBU]
1041 ldrne tmp2, [tmp1, #0x10]
1043 /* Active the self-refresh mode */
1044 at91_sramc_self_refresh_ena
1047 cmp r0, #AT91_PM_STANDBY
1049 cmp r0, #AT91_PM_BACKUP
1056 /* Wait for interrupt */
1065 /* Exit the self-refresh mode */
1066 at91_sramc_self_refresh_dis
1068 /* Restore registers, and return */
1069 ldmfd sp!, {r4 - r12, pc}
1070 ENDPROC(at91_pm_suspend_in_sram)
1106 #ifdef CONFIG_SOC_SAMA7
1117 ENTRY(at91_pm_suspend_in_sram_sz)
1118 .word .-at91_pm_suspend_in_sram