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"
19 #define SRAMC_SELF_FRESH_ACTIVE 0x01
20 #define SRAMC_SELF_FRESH_EXIT 0x00
28 * Wait until master clock is ready (after switching master clock source)
30 * @r_mckid: register holding master clock identifier
32 * Side effects: overwrites r7, r8
34 .macro wait_mckrdy r_mckid
35 #ifdef CONFIG_SOC_SAMA7
38 mov r7, #AT91_PMC_MCKXRDY
41 1: mov r7, #AT91_PMC_MCKRDY
42 2: ldr r8, [pmc, #AT91_PMC_SR]
49 * Wait until master oscillator has stabilized.
51 * Side effects: overwrites r7
54 1: ldr r7, [pmc, #AT91_PMC_SR]
55 tst r7, #AT91_PMC_MOSCS
60 * Wait for main oscillator selection is done
62 * Side effects: overwrites r7
65 1: ldr r7, [pmc, #AT91_PMC_SR]
66 tst r7, #AT91_PMC_MOSCSELS
71 * Put the processor to enter the idle state
73 * Side effects: overwrites r7
77 #if defined(CONFIG_CPU_V7)
79 str r7, [pmc, #AT91_PMC_SCDR]
83 wfi @ Wait For Interrupt
85 mcr p15, 0, tmp1, c7, c0, 4
91 * Set state for 2.5V low power regulator
92 * @ena: 0 - disable regulator
93 * 1 - enable regulator
95 * Side effects: overwrites r7, r8, r9, r10
97 .macro at91_2_5V_reg_set_low_power ena
98 #ifdef CONFIG_SOC_SAMA7
101 ldr r9, [r7, #AT91_SFRBU_25LDOCR]
102 orr r9, r9, #AT91_SFRBU_25LDOCR_LP
105 bic r9, r9, #AT91_SFRBU_25LDOCR_LP
107 ldr r10, =AT91_SFRBU_25LDOCR_LDOANAKEY
109 str r9, [r7, #AT91_SFRBU_25LDOCR]
113 .macro at91_backup_set_lpm reg
114 #ifdef CONFIG_SOC_SAMA7
115 orr \reg, \reg, #0x200000
123 #ifdef CONFIG_SOC_SAMA7
125 * Enable self-refresh
127 * Side effects: overwrites r2, r3, tmp1, tmp2, tmp3, r7
129 .macro at91_sramc_self_refresh_ena
131 ldr r3, .sramc_phy_base
136 /* Disable all AXI ports. */
137 ldr tmp1, [r2, #UDDRC_PCTRL_0]
139 str tmp1, [r2, #UDDRC_PCTRL_0]
141 ldr tmp1, [r2, #UDDRC_PCTRL_1]
143 str tmp1, [r2, #UDDRC_PCTRL_1]
145 ldr tmp1, [r2, #UDDRC_PCTRL_2]
147 str tmp1, [r2, #UDDRC_PCTRL_2]
149 ldr tmp1, [r2, #UDDRC_PCTRL_3]
151 str tmp1, [r2, #UDDRC_PCTRL_3]
153 ldr tmp1, [r2, #UDDRC_PCTRL_4]
155 str tmp1, [r2, #UDDRC_PCTRL_4]
158 /* Wait for all ports to disable. */
159 ldr tmp1, [r2, #UDDRC_PSTAT]
160 ldr tmp2, =UDDRC_PSTAT_ALL_PORTS
164 /* Switch to self-refresh. */
165 ldr tmp1, [r2, #UDDRC_PWRCTL]
166 orr tmp1, tmp1, #UDDRC_PWRCTL_SELFREF_SW
167 str tmp1, [r2, #UDDRC_PWRCTL]
170 /* Wait for self-refresh enter. */
171 ldr tmp1, [r2, #UDDRC_STAT]
172 bic tmp1, tmp1, #~UDDRC_STAT_SELFREF_TYPE_MSK
173 cmp tmp1, #UDDRC_STAT_SELFREF_TYPE_SW
176 /* Disable DX DLLs for non-backup modes. */
177 cmp r7, #AT91_PM_BACKUP
180 /* Do not soft reset the AC DLL. */
181 ldr tmp1, [r3, DDR3PHY_ACDLLCR]
182 bic tmp1, tmp1, DDR3PHY_ACDLLCR_DLLSRST
183 str tmp1, [r3, DDR3PHY_ACDLLCR]
185 /* Disable DX DLLs. */
186 ldr tmp1, [r3, #DDR3PHY_DX0DLLCR]
187 orr tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
188 str tmp1, [r3, #DDR3PHY_DX0DLLCR]
190 ldr tmp1, [r3, #DDR3PHY_DX1DLLCR]
191 orr tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
192 str tmp1, [r3, #DDR3PHY_DX1DLLCR]
195 /* Power down DDR PHY data receivers. */
196 ldr tmp1, [r3, #DDR3PHY_DXCCR]
197 orr tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
198 str tmp1, [r3, #DDR3PHY_DXCCR]
200 /* Power down ADDR/CMD IO. */
201 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
202 orr tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
203 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
204 orr tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
205 str tmp1, [r3, #DDR3PHY_ACIOCR]
207 /* Power down ODT. */
208 ldr tmp1, [r3, #DDR3PHY_DSGCR]
209 orr tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
210 str tmp1, [r3, #DDR3PHY_DSGCR]
214 * Disable self-refresh
216 * Side effects: overwrites r2, r3, tmp1, tmp2, tmp3
218 .macro at91_sramc_self_refresh_dis
220 ldr r3, .sramc_phy_base
222 /* Power up DDR PHY data receivers. */
223 ldr tmp1, [r3, #DDR3PHY_DXCCR]
224 bic tmp1, tmp1, #DDR3PHY_DXCCR_DXPDR
225 str tmp1, [r3, #DDR3PHY_DXCCR]
227 /* Power up the output of CK and CS pins. */
228 ldr tmp1, [r3, #DDR3PHY_ACIOCR]
229 bic tmp1, tmp1, #DDR3PHY_ACIORC_ACPDD
230 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CKPDD_CK0
231 bic tmp1, tmp1, #DDR3PHY_ACIOCR_CSPDD_CS0
232 str tmp1, [r3, #DDR3PHY_ACIOCR]
235 ldr tmp1, [r3, #DDR3PHY_DSGCR]
236 bic tmp1, tmp1, #DDR3PHY_DSGCR_ODTPDD_ODT0
237 str tmp1, [r3, #DDR3PHY_DSGCR]
239 /* Enable DX DLLs. */
240 ldr tmp1, [r3, #DDR3PHY_DX0DLLCR]
241 bic tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
242 str tmp1, [r3, #DDR3PHY_DX0DLLCR]
244 ldr tmp1, [r3, #DDR3PHY_DX1DLLCR]
245 bic tmp1, tmp1, #DDR3PHY_DXDLLCR_DLLDIS
246 str tmp1, [r3, #DDR3PHY_DX1DLLCR]
248 /* Enable quasi-dynamic programming. */
250 str tmp1, [r2, #UDDRC_SWCTRL]
252 /* De-assert SDRAM initialization. */
253 ldr tmp1, [r2, #UDDRC_DFIMISC]
254 bic tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
255 str tmp1, [r2, #UDDRC_DFIMISC]
257 /* Quasi-dynamic programming done. */
258 mov tmp1, #UDDRC_SWCTRL_SW_DONE
259 str tmp1, [r2, #UDDRC_SWCTRL]
262 ldr tmp1, [r2, #UDDRC_SWSTAT]
263 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
266 /* DLL soft-reset + DLL lock wait + ITM reset */
267 mov tmp1, #(DDR3PHY_PIR_INIT | DDR3PHY_PIR_DLLSRST | \
268 DDR3PHY_PIR_DLLLOCK | DDR3PHY_PIR_ITMSRST)
269 str tmp1, [r3, #DDR3PHY_PIR]
273 ldr tmp1, [r3, #DDR3PHY_PGSR]
274 tst tmp1, #DDR3PHY_PGSR_IDONE
277 /* Enable quasi-dynamic programming. */
279 str tmp1, [r2, #UDDRC_SWCTRL]
281 /* Assert PHY init complete enable signal. */
282 ldr tmp1, [r2, #UDDRC_DFIMISC]
283 orr tmp1, tmp1, #UDDRC_DFIMISC_DFI_INIT_COMPLETE_EN
284 str tmp1, [r2, #UDDRC_DFIMISC]
286 /* Programming is done. Set sw_done. */
287 mov tmp1, #UDDRC_SWCTRL_SW_DONE
288 str tmp1, [r2, #UDDRC_SWCTRL]
292 ldr tmp1, [r2, #UDDRC_SWSTAT]
293 tst tmp1, #UDDRC_SWSTAT_SW_DONE_ACK
296 /* Trigger self-refresh exit. */
297 ldr tmp1, [r2, #UDDRC_PWRCTL]
298 bic tmp1, tmp1, #UDDRC_PWRCTL_SELFREF_SW
299 str tmp1, [r2, #UDDRC_PWRCTL]
302 /* Wait for self-refresh exit done. */
303 ldr tmp1, [r2, #UDDRC_STAT]
304 bic tmp1, tmp1, #~UDDRC_STAT_OPMODE_MSK
305 cmp tmp1, #UDDRC_STAT_OPMODE_NORMAL
308 /* Enable all AXI ports. */
309 ldr tmp1, [r2, #UDDRC_PCTRL_0]
311 str tmp1, [r2, #UDDRC_PCTRL_0]
313 ldr tmp1, [r2, #UDDRC_PCTRL_1]
315 str tmp1, [r2, #UDDRC_PCTRL_1]
317 ldr tmp1, [r2, #UDDRC_PCTRL_2]
319 str tmp1, [r2, #UDDRC_PCTRL_2]
321 ldr tmp1, [r2, #UDDRC_PCTRL_3]
323 str tmp1, [r2, #UDDRC_PCTRL_3]
325 ldr tmp1, [r2, #UDDRC_PCTRL_4]
327 str tmp1, [r2, #UDDRC_PCTRL_4]
333 * Enable self-refresh
337 * @r2: base address of the sram controller
340 .macro at91_sramc_self_refresh_ena
344 cmp r1, #AT91_MEMCTRL_MC
347 /* Active SDRAM self-refresh mode */
349 str r3, [r2, #AT91_MC_SDRAMC_SRR]
353 cmp r1, #AT91_MEMCTRL_DDRSDR
357 * DDR Memory controller
360 /* LPDDR1 --> force DDR2 mode during self-refresh */
361 ldr r3, [r2, #AT91_DDRSDRC_MDR]
362 str r3, .saved_sam9_mdr
363 bic r3, r3, #~AT91_DDRSDRC_MD
364 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
365 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
366 biceq r3, r3, #AT91_DDRSDRC_MD
367 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
368 streq r3, [r2, #AT91_DDRSDRC_MDR]
370 /* Active DDRC self-refresh mode */
371 ldr r3, [r2, #AT91_DDRSDRC_LPR]
372 str r3, .saved_sam9_lpr
373 bic r3, r3, #AT91_DDRSDRC_LPCB
374 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
375 str r3, [r2, #AT91_DDRSDRC_LPR]
377 /* If using the 2nd ddr controller */
380 beq sr_ena_no_2nd_ddrc
382 ldr r3, [r2, #AT91_DDRSDRC_MDR]
383 str r3, .saved_sam9_mdr1
384 bic r3, r3, #~AT91_DDRSDRC_MD
385 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
386 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
387 biceq r3, r3, #AT91_DDRSDRC_MD
388 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
389 streq r3, [r2, #AT91_DDRSDRC_MDR]
391 /* Active DDRC self-refresh mode */
392 ldr r3, [r2, #AT91_DDRSDRC_LPR]
393 str r3, .saved_sam9_lpr1
394 bic r3, r3, #AT91_DDRSDRC_LPCB
395 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
396 str r3, [r2, #AT91_DDRSDRC_LPR]
402 * SDRAMC Memory controller
405 /* Active SDRAMC self-refresh mode */
406 ldr r3, [r2, #AT91_SDRAMC_LPR]
407 str r3, .saved_sam9_lpr
408 bic r3, r3, #AT91_SDRAMC_LPCB
409 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
410 str r3, [r2, #AT91_SDRAMC_LPR]
412 ldr r3, .saved_sam9_lpr
413 str r3, [r2, #AT91_SDRAMC_LPR]
419 * Disable self-refresh
423 * @r2: base address of the sram controller
426 .macro at91_sramc_self_refresh_dis
430 cmp r1, #AT91_MEMCTRL_MC
431 bne sr_dis_ddrc_exit_sf
434 * at91rm9200 Memory controller
438 * For exiting the self-refresh mode, do nothing,
439 * automatically exit the self-refresh mode.
444 cmp r1, #AT91_MEMCTRL_DDRSDR
447 /* DDR Memory controller */
449 /* Restore MDR in case of LPDDR1 */
450 ldr r3, .saved_sam9_mdr
451 str r3, [r2, #AT91_DDRSDRC_MDR]
452 /* Restore LPR on AT91 with DDRAM */
453 ldr r3, .saved_sam9_lpr
454 str r3, [r2, #AT91_DDRSDRC_LPR]
456 /* If using the 2nd ddr controller */
459 ldrne r3, .saved_sam9_mdr1
460 strne r3, [r2, #AT91_DDRSDRC_MDR]
461 ldrne r3, .saved_sam9_lpr1
462 strne r3, [r2, #AT91_DDRSDRC_LPR]
467 /* SDRAMC Memory controller */
468 ldr r3, .saved_sam9_lpr
469 str r3, [r2, #AT91_SDRAMC_LPR]
475 .macro at91_pm_ulp0_mode
478 ldr tmp3, .mckr_offset
480 /* Check if ULP0 fast variant has been requested. */
481 cmp tmp2, #AT91_PM_ULP0_FAST
484 /* Set highest prescaler for power saving */
485 ldr tmp1, [pmc, tmp3]
486 bic tmp1, tmp1, #AT91_PMC_PRES
487 orr tmp1, tmp1, #AT91_PMC_PRES_64
488 str tmp1, [pmc, tmp3]
495 /* Turn off the crystal oscillator */
496 ldr tmp1, [pmc, #AT91_CKGR_MOR]
497 bic tmp1, tmp1, #AT91_PMC_MOSCEN
498 orr tmp1, tmp1, #AT91_PMC_KEY
499 str tmp1, [pmc, #AT91_CKGR_MOR]
501 /* Save RC oscillator state */
502 ldr tmp1, [pmc, #AT91_PMC_SR]
503 str tmp1, .saved_osc_status
504 tst tmp1, #AT91_PMC_MOSCRCS
507 /* Turn off RC oscillator */
508 ldr tmp1, [pmc, #AT91_CKGR_MOR]
509 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
510 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
511 orr tmp1, tmp1, #AT91_PMC_KEY
512 str tmp1, [pmc, #AT91_CKGR_MOR]
514 /* Wait main RC disabled done */
515 2: ldr tmp1, [pmc, #AT91_PMC_SR]
516 tst tmp1, #AT91_PMC_MOSCRCS
519 /* Wait for interrupt */
522 /* Check if ULP0 fast variant has been requested. */
523 cmp tmp2, #AT91_PM_ULP0_FAST
526 /* Set lowest prescaler for fast resume. */
527 ldr tmp3, .mckr_offset
528 ldr tmp1, [pmc, tmp3]
529 bic tmp1, tmp1, #AT91_PMC_PRES
530 str tmp1, [pmc, tmp3]
536 5: /* Restore RC oscillator state */
537 ldr tmp1, .saved_osc_status
538 tst tmp1, #AT91_PMC_MOSCRCS
541 /* Turn on RC oscillator */
542 ldr tmp1, [pmc, #AT91_CKGR_MOR]
543 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
544 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
545 orr tmp1, tmp1, #AT91_PMC_KEY
546 str tmp1, [pmc, #AT91_CKGR_MOR]
548 /* Wait main RC stabilization */
549 3: ldr tmp1, [pmc, #AT91_PMC_SR]
550 tst tmp1, #AT91_PMC_MOSCRCS
553 /* Turn on the crystal oscillator */
554 4: ldr tmp1, [pmc, #AT91_CKGR_MOR]
555 orr tmp1, tmp1, #AT91_PMC_MOSCEN
556 orr tmp1, tmp1, #AT91_PMC_KEY
557 str tmp1, [pmc, #AT91_CKGR_MOR]
564 * Note: This procedure only applies on the platform which uses
565 * the external crystal oscillator as a main clock source.
567 .macro at91_pm_ulp1_mode
569 ldr tmp2, .mckr_offset
572 /* Save RC oscillator state and check if it is enabled. */
573 ldr tmp1, [pmc, #AT91_PMC_SR]
574 str tmp1, .saved_osc_status
575 tst tmp1, #AT91_PMC_MOSCRCS
578 /* Enable RC oscillator */
579 ldr tmp1, [pmc, #AT91_CKGR_MOR]
580 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
581 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
582 orr tmp1, tmp1, #AT91_PMC_KEY
583 str tmp1, [pmc, #AT91_CKGR_MOR]
585 /* Wait main RC stabilization */
586 1: ldr tmp1, [pmc, #AT91_PMC_SR]
587 tst tmp1, #AT91_PMC_MOSCRCS
590 /* Switch the main clock source to 12-MHz RC oscillator */
591 2: ldr tmp1, [pmc, #AT91_CKGR_MOR]
592 bic tmp1, tmp1, #AT91_PMC_MOSCSEL
593 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
594 orr tmp1, tmp1, #AT91_PMC_KEY
595 str tmp1, [pmc, #AT91_CKGR_MOR]
599 /* Disable the crystal oscillator */
600 ldr tmp1, [pmc, #AT91_CKGR_MOR]
601 bic tmp1, tmp1, #AT91_PMC_MOSCEN
602 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
603 orr tmp1, tmp1, #AT91_PMC_KEY
604 str tmp1, [pmc, #AT91_CKGR_MOR]
606 /* Switch the master clock source to main clock */
607 ldr tmp1, [pmc, tmp2]
608 bic tmp1, tmp1, #AT91_PMC_CSS
609 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
610 str tmp1, [pmc, tmp2]
614 /* Enter the ULP1 mode by set WAITMODE bit in CKGR_MOR */
615 ldr tmp1, [pmc, #AT91_CKGR_MOR]
616 orr tmp1, tmp1, #AT91_PMC_WAITMODE
617 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
618 orr tmp1, tmp1, #AT91_PMC_KEY
619 str tmp1, [pmc, #AT91_CKGR_MOR]
621 /* Quirk for SAM9X60's PMC */
627 /* Enable the crystal oscillator */
628 ldr tmp1, [pmc, #AT91_CKGR_MOR]
629 orr tmp1, tmp1, #AT91_PMC_MOSCEN
630 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
631 orr tmp1, tmp1, #AT91_PMC_KEY
632 str tmp1, [pmc, #AT91_CKGR_MOR]
636 /* Switch the master clock source to slow clock */
637 ldr tmp1, [pmc, tmp2]
638 bic tmp1, tmp1, #AT91_PMC_CSS
639 str tmp1, [pmc, tmp2]
643 /* Switch main clock source to crystal oscillator */
644 ldr tmp1, [pmc, #AT91_CKGR_MOR]
645 orr tmp1, tmp1, #AT91_PMC_MOSCSEL
646 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
647 orr tmp1, tmp1, #AT91_PMC_KEY
648 str tmp1, [pmc, #AT91_CKGR_MOR]
652 /* Switch the master clock source to main clock */
653 ldr tmp1, [pmc, tmp2]
654 bic tmp1, tmp1, #AT91_PMC_CSS
655 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
656 str tmp1, [pmc, tmp2]
660 /* Restore RC oscillator state */
661 ldr tmp1, .saved_osc_status
662 tst tmp1, #AT91_PMC_MOSCRCS
665 /* Disable RC oscillator */
666 ldr tmp1, [pmc, #AT91_CKGR_MOR]
667 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
668 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
669 orr tmp1, tmp1, #AT91_PMC_KEY
670 str tmp1, [pmc, #AT91_CKGR_MOR]
672 /* Wait RC oscillator disable done */
673 4: ldr tmp1, [pmc, #AT91_PMC_SR]
674 tst tmp1, #AT91_PMC_MOSCRCS
680 .macro at91_plla_disable
681 /* Save PLLA setting and disable it */
682 ldr tmp1, .pmc_version
683 cmp tmp1, #AT91_PMC_V1
686 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
687 /* Save PLLA settings. */
688 ldr tmp2, [pmc, #AT91_PMC_PLL_UPDT]
689 bic tmp2, tmp2, #AT91_PMC_PLL_UPDT_ID
690 str tmp2, [pmc, #AT91_PMC_PLL_UPDT]
694 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL0]
695 bic tmp2, tmp2, #0xffffff00
699 ldr tmp2, [pmc, #AT91_PMC_PLL_CTRL1]
700 bic tmp2, tmp2, #0xffffff
702 str tmp1, .saved_pllar
705 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
706 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
707 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
708 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
711 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
712 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
713 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
714 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
717 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
718 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
719 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
720 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
723 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
724 bic tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
725 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
728 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
729 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
730 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
731 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
736 1: /* Save PLLA setting and disable it */
737 ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
738 str tmp1, .saved_pllar
741 mov tmp1, #AT91_PMC_PLLCOUNT
742 orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
743 str tmp1, [pmc, #AT91_CKGR_PLLAR]
747 .macro at91_plla_enable
748 ldr tmp2, .saved_pllar
749 ldr tmp3, .pmc_version
750 cmp tmp3, #AT91_PMC_V1
753 #ifdef CONFIG_HAVE_AT91_SAM9X60_PLL
755 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
756 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
757 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
758 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
761 ldr tmp1, =AT91_PMC_PLL_ACR_DEFAULT_PLLA
762 str tmp1, [pmc, #AT91_PMC_PLL_ACR]
765 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
767 bic tmp3, tmp3, #0xffffff
769 str tmp1, [pmc, #AT91_PMC_PLL_CTRL1]
772 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
773 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
774 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
775 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
778 ldr tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
779 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENLOCK
780 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLL
781 orr tmp1, tmp1, #AT91_PMC_PLL_CTRL0_ENPLLCK
782 bic tmp1, tmp1, #0xff
784 bic tmp3, tmp3, #0xffffff00
786 str tmp1, [pmc, #AT91_PMC_PLL_CTRL0]
789 ldr tmp1, [pmc, #AT91_PMC_PLL_UPDT]
790 orr tmp1, tmp1, #AT91_PMC_PLL_UPDT_UPDATE
791 bic tmp1, tmp1, #AT91_PMC_PLL_UPDT_ID
792 str tmp1, [pmc, #AT91_PMC_PLL_UPDT]
795 3: ldr tmp1, [pmc, #AT91_PMC_PLL_ISR0]
801 /* Restore PLLA setting */
802 4: str tmp2, [pmc, #AT91_CKGR_PLLAR]
805 tst tmp2, #(AT91_PMC_MUL & 0xff0000)
807 tst tmp2, #(AT91_PMC_MUL & ~0xff0000)
810 1: ldr tmp1, [pmc, #AT91_PMC_SR]
811 tst tmp1, #AT91_PMC_LOCKA
817 * at91_mckx_ps_enable: save MCK1..4 settings and switch it to main clock
819 * Side effects: overwrites tmp1, tmp2
821 .macro at91_mckx_ps_enable
822 #ifdef CONFIG_SOC_SAMA7
825 /* There are 4 MCKs we need to handle: MCK1..4 */
830 /* Write MCK ID to retrieve the settings. */
831 str tmp1, [pmc, #AT91_PMC_MCR_V2]
832 ldr tmp2, [pmc, #AT91_PMC_MCR_V2]
837 str tmp2, .saved_mck1
843 str tmp2, .saved_mck2
849 str tmp2, .saved_mck3
853 str tmp2, .saved_mck4
856 /* Use CSS=MAINCK and DIV=1. */
857 bic tmp2, tmp2, #AT91_PMC_MCR_V2_CSS
858 bic tmp2, tmp2, #AT91_PMC_MCR_V2_DIV
859 orr tmp2, tmp2, #AT91_PMC_MCR_V2_CSS_MAINCK
860 orr tmp2, tmp2, #AT91_PMC_MCR_V2_DIV1
861 str tmp2, [pmc, #AT91_PMC_MCR_V2]
873 * at91_mckx_ps_restore: restore MCK1..4 settings
875 * Side effects: overwrites tmp1, tmp2
877 .macro at91_mckx_ps_restore
878 #ifdef CONFIG_SOC_SAMA7
881 /* There are 4 MCKs we need to handle: MCK1..4 */
889 ldr tmp2, .saved_mck1
895 ldr tmp2, .saved_mck2
901 ldr tmp2, .saved_mck3
905 ldr tmp2, .saved_mck4
908 /* Write MCK ID to retrieve the settings. */
909 str tmp1, [pmc, #AT91_PMC_MCR_V2]
910 ldr tmp3, [pmc, #AT91_PMC_MCR_V2]
912 /* We need to restore CSS and DIV. */
913 bic tmp3, tmp3, #AT91_PMC_MCR_V2_CSS
914 bic tmp3, tmp3, #AT91_PMC_MCR_V2_DIV
916 bic tmp3, tmp3, #AT91_PMC_MCR_V2_ID_MSK
918 orr tmp3, tmp3, #AT91_PMC_MCR_V2_CMD
919 str tmp2, [pmc, #AT91_PMC_MCR_V2]
933 ldr tmp2, .mckr_offset
936 /* Save Master clock setting */
937 ldr tmp1, [pmc, tmp2]
938 str tmp1, .saved_mckr
941 * Set master clock source to:
942 * - MAINCK if using ULP0 fast variant
943 * - slow clock, otherwise
945 bic tmp1, tmp1, #AT91_PMC_CSS
946 cmp tmp3, #AT91_PM_ULP0_FAST
948 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
950 str tmp1, [pmc, tmp2]
957 /* Enable low power mode for 2.5V regulator. */
958 at91_2_5V_reg_set_low_power 1
961 cmp tmp3, #AT91_PM_ULP1
972 /* Disable low power mode for 2.5V regulator. */
973 at91_2_5V_reg_set_low_power 0
980 * Restore master clock setting
982 ldr tmp1, .mckr_offset
983 ldr tmp2, .saved_mckr
984 str tmp2, [pmc, tmp1]
992 .macro at91_backup_mode
993 /* Switch the master clock source to slow clock. */
995 ldr tmp2, .mckr_offset
996 ldr tmp1, [pmc, tmp2]
997 bic tmp1, tmp1, #AT91_PMC_CSS
998 str tmp1, [pmc, tmp2]
1006 str tmp1, [r0, #0x10]
1009 1: ldr tmp1, [r0, #0x10]
1015 mov tmp1, #0xA5000000
1016 add tmp1, tmp1, #0x1
1017 at91_backup_set_lpm tmp1
1022 * void at91_suspend_sram_fn(struct at91_pm_data*)
1024 * @r0: base address of struct at91_pm_data
1026 /* at91_pm_suspend_in_sram must be 8-byte aligned per the requirements of fncpy() */
1028 ENTRY(at91_pm_suspend_in_sram)
1029 /* Save registers on stack */
1030 stmfd sp!, {r4 - r12, lr}
1032 /* Drain write buffer */
1034 mcr p15, 0, tmp1, c7, c10, 4
1038 mcr p15, 0, r4, c8, c7, 0
1040 ldr tmp1, [r0, #PM_DATA_PMC_MCKR_OFFSET]
1041 str tmp1, .mckr_offset
1042 ldr tmp1, [r0, #PM_DATA_PMC_VERSION]
1043 str tmp1, .pmc_version
1044 ldr tmp1, [r0, #PM_DATA_MEMCTRL]
1046 ldr tmp1, [r0, #PM_DATA_MODE]
1050 * ldrne below are here to preload their address in the TLB as access
1051 * to RAM may be limited while in self-refresh.
1053 ldr tmp1, [r0, #PM_DATA_PMC]
1056 ldrne tmp2, [tmp1, #0]
1058 ldr tmp1, [r0, #PM_DATA_RAMC0]
1059 str tmp1, .sramc_base
1061 ldrne tmp2, [tmp1, #0]
1063 ldr tmp1, [r0, #PM_DATA_RAMC1]
1064 str tmp1, .sramc1_base
1066 ldrne tmp2, [tmp1, #0]
1068 #ifndef CONFIG_SOC_SAM_V4_V5
1069 /* ldrne below are here to preload their address in the TLB */
1070 ldr tmp1, [r0, #PM_DATA_RAMC_PHY]
1071 str tmp1, .sramc_phy_base
1073 ldrne tmp2, [tmp1, #0]
1075 ldr tmp1, [r0, #PM_DATA_SHDWC]
1078 ldrne tmp2, [tmp1, #0]
1080 ldr tmp1, [r0, #PM_DATA_SFRBU]
1083 ldrne tmp2, [tmp1, #0x10]
1086 /* Active the self-refresh mode */
1087 at91_sramc_self_refresh_ena
1090 cmp r0, #AT91_PM_STANDBY
1092 cmp r0, #AT91_PM_BACKUP
1099 /* Wait for interrupt */
1108 /* Exit the self-refresh mode */
1109 at91_sramc_self_refresh_dis
1111 /* Restore registers, and return */
1112 ldmfd sp!, {r4 - r12, pc}
1113 ENDPROC(at91_pm_suspend_in_sram)
1149 #ifdef CONFIG_SOC_SAMA7
1160 ENTRY(at91_pm_suspend_in_sram_sz)
1161 .word .-at91_pm_suspend_in_sram