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
23 * Wait until master clock is ready (after switching master clock source)
26 1: ldr tmp1, [pmc, #AT91_PMC_SR]
27 tst tmp1, #AT91_PMC_MCKRDY
32 * Wait until master oscillator has stabilized.
35 1: ldr tmp1, [pmc, #AT91_PMC_SR]
36 tst tmp1, #AT91_PMC_MOSCS
41 * Wait for main oscillator selection is done
44 1: ldr tmp1, [pmc, #AT91_PMC_SR]
45 tst tmp1, #AT91_PMC_MOSCSELS
50 * Put the processor to enter the idle state
54 #if defined(CONFIG_CPU_V7)
55 mov tmp1, #AT91_PMC_PCK
56 str tmp1, [pmc, #AT91_PMC_SCDR]
60 wfi @ Wait For Interrupt
62 mcr p15, 0, tmp1, c7, c0, 4
72 * void at91_suspend_sram_fn(struct at91_pm_data*)
74 * @r0: base address of struct at91_pm_data
76 /* at91_pm_suspend_in_sram must be 8-byte aligned per the requirements of fncpy() */
78 ENTRY(at91_pm_suspend_in_sram)
79 /* Save registers on stack */
80 stmfd sp!, {r4 - r12, lr}
82 /* Drain write buffer */
84 mcr p15, 0, tmp1, c7, c10, 4
86 ldr tmp1, [r0, #PM_DATA_PMC]
88 ldr tmp1, [r0, #PM_DATA_RAMC0]
90 ldr tmp1, [r0, #PM_DATA_RAMC1]
91 str tmp1, .sramc1_base
92 ldr tmp1, [r0, #PM_DATA_MEMCTRL]
94 ldr tmp1, [r0, #PM_DATA_MODE]
96 /* Both ldrne below are here to preload their address in the TLB */
97 ldr tmp1, [r0, #PM_DATA_SHDWC]
100 ldrne tmp2, [tmp1, #0]
101 ldr tmp1, [r0, #PM_DATA_SFRBU]
104 ldrne tmp2, [tmp1, #0x10]
106 /* Active the self-refresh mode */
107 mov r0, #SRAMC_SELF_FRESH_ACTIVE
108 bl at91_sramc_self_refresh
111 cmp r0, #AT91_PM_STANDBY
113 cmp r0, #AT91_PM_BACKUP
120 /* Wait for interrupt */
130 /* Exit the self-refresh mode */
131 mov r0, #SRAMC_SELF_FRESH_EXIT
132 bl at91_sramc_self_refresh
134 /* Restore registers, and return */
135 ldmfd sp!, {r4 - r12, pc}
136 ENDPROC(at91_pm_suspend_in_sram)
138 ENTRY(at91_backup_mode)
139 /* Switch the master clock source to slow clock. */
141 ldr tmp1, [pmc, #AT91_PMC_MCKR]
142 bic tmp1, tmp1, #AT91_PMC_CSS
143 str tmp1, [pmc, #AT91_PMC_MCKR]
150 str tmp1, [r0, #0x10]
154 mov tmp1, #0xA5000000
157 ENDPROC(at91_backup_mode)
159 .macro at91_pm_ulp0_mode
162 /* Turn off the crystal oscillator */
163 ldr tmp1, [pmc, #AT91_CKGR_MOR]
164 bic tmp1, tmp1, #AT91_PMC_MOSCEN
165 orr tmp1, tmp1, #AT91_PMC_KEY
166 str tmp1, [pmc, #AT91_CKGR_MOR]
168 /* Save RC oscillator state */
169 ldr tmp1, [pmc, #AT91_PMC_SR]
170 str tmp1, .saved_osc_status
171 tst tmp1, #AT91_PMC_MOSCRCS
174 /* Turn off RC oscillator */
175 ldr tmp1, [pmc, #AT91_CKGR_MOR]
176 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
177 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
178 orr tmp1, tmp1, #AT91_PMC_KEY
179 str tmp1, [pmc, #AT91_CKGR_MOR]
181 /* Wait main RC disabled done */
182 2: ldr tmp1, [pmc, #AT91_PMC_SR]
183 tst tmp1, #AT91_PMC_MOSCRCS
186 /* Wait for interrupt */
189 /* Restore RC oscillator state */
190 ldr tmp1, .saved_osc_status
191 tst tmp1, #AT91_PMC_MOSCRCS
194 /* Turn on RC oscillator */
195 ldr tmp1, [pmc, #AT91_CKGR_MOR]
196 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
197 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
198 orr tmp1, tmp1, #AT91_PMC_KEY
199 str tmp1, [pmc, #AT91_CKGR_MOR]
201 /* Wait main RC stabilization */
202 3: ldr tmp1, [pmc, #AT91_PMC_SR]
203 tst tmp1, #AT91_PMC_MOSCRCS
206 /* Turn on the crystal oscillator */
207 4: ldr tmp1, [pmc, #AT91_CKGR_MOR]
208 orr tmp1, tmp1, #AT91_PMC_MOSCEN
209 orr tmp1, tmp1, #AT91_PMC_KEY
210 str tmp1, [pmc, #AT91_CKGR_MOR]
216 * Note: This procedure only applies on the platform which uses
217 * the external crystal oscillator as a main clock source.
219 .macro at91_pm_ulp1_mode
222 /* Save RC oscillator state and check if it is enabled. */
223 ldr tmp1, [pmc, #AT91_PMC_SR]
224 str tmp1, .saved_osc_status
225 tst tmp1, #AT91_PMC_MOSCRCS
228 /* Enable RC oscillator */
229 ldr tmp1, [pmc, #AT91_CKGR_MOR]
230 orr tmp1, tmp1, #AT91_PMC_MOSCRCEN
231 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
232 orr tmp1, tmp1, #AT91_PMC_KEY
233 str tmp1, [pmc, #AT91_CKGR_MOR]
235 /* Wait main RC stabilization */
236 1: ldr tmp1, [pmc, #AT91_PMC_SR]
237 tst tmp1, #AT91_PMC_MOSCRCS
240 /* Switch the main clock source to 12-MHz RC oscillator */
241 2: ldr tmp1, [pmc, #AT91_CKGR_MOR]
242 bic tmp1, tmp1, #AT91_PMC_MOSCSEL
243 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
244 orr tmp1, tmp1, #AT91_PMC_KEY
245 str tmp1, [pmc, #AT91_CKGR_MOR]
249 /* Disable the crystal oscillator */
250 ldr tmp1, [pmc, #AT91_CKGR_MOR]
251 bic tmp1, tmp1, #AT91_PMC_MOSCEN
252 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
253 orr tmp1, tmp1, #AT91_PMC_KEY
254 str tmp1, [pmc, #AT91_CKGR_MOR]
256 /* Switch the master clock source to main clock */
257 ldr tmp1, [pmc, #AT91_PMC_MCKR]
258 bic tmp1, tmp1, #AT91_PMC_CSS
259 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
260 str tmp1, [pmc, #AT91_PMC_MCKR]
264 /* Enter the ULP1 mode by set WAITMODE bit in CKGR_MOR */
265 ldr tmp1, [pmc, #AT91_CKGR_MOR]
266 orr tmp1, tmp1, #AT91_PMC_WAITMODE
267 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
268 orr tmp1, tmp1, #AT91_PMC_KEY
269 str tmp1, [pmc, #AT91_CKGR_MOR]
273 /* Enable the crystal oscillator */
274 ldr tmp1, [pmc, #AT91_CKGR_MOR]
275 orr tmp1, tmp1, #AT91_PMC_MOSCEN
276 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
277 orr tmp1, tmp1, #AT91_PMC_KEY
278 str tmp1, [pmc, #AT91_CKGR_MOR]
282 /* Switch the master clock source to slow clock */
283 ldr tmp1, [pmc, #AT91_PMC_MCKR]
284 bic tmp1, tmp1, #AT91_PMC_CSS
285 str tmp1, [pmc, #AT91_PMC_MCKR]
289 /* Switch main clock source to crystal oscillator */
290 ldr tmp1, [pmc, #AT91_CKGR_MOR]
291 orr tmp1, tmp1, #AT91_PMC_MOSCSEL
292 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
293 orr tmp1, tmp1, #AT91_PMC_KEY
294 str tmp1, [pmc, #AT91_CKGR_MOR]
298 /* Switch the master clock source to main clock */
299 ldr tmp1, [pmc, #AT91_PMC_MCKR]
300 bic tmp1, tmp1, #AT91_PMC_CSS
301 orr tmp1, tmp1, #AT91_PMC_CSS_MAIN
302 str tmp1, [pmc, #AT91_PMC_MCKR]
306 /* Restore RC oscillator state */
307 ldr tmp1, .saved_osc_status
308 tst tmp1, #AT91_PMC_MOSCRCS
311 /* Disable RC oscillator */
312 ldr tmp1, [pmc, #AT91_CKGR_MOR]
313 bic tmp1, tmp1, #AT91_PMC_MOSCRCEN
314 bic tmp1, tmp1, #AT91_PMC_KEY_MASK
315 orr tmp1, tmp1, #AT91_PMC_KEY
316 str tmp1, [pmc, #AT91_CKGR_MOR]
318 /* Wait RC oscillator disable done */
319 4: ldr tmp1, [pmc, #AT91_PMC_SR]
320 tst tmp1, #AT91_PMC_MOSCRCS
329 /* Save Master clock setting */
330 ldr tmp1, [pmc, #AT91_PMC_MCKR]
331 str tmp1, .saved_mckr
334 * Set the Master clock source to slow clock
336 bic tmp1, tmp1, #AT91_PMC_CSS
337 str tmp1, [pmc, #AT91_PMC_MCKR]
342 cmp r0, #AT91_PM_ULP1
356 * Restore master clock setting
358 ldr tmp1, .saved_mckr
359 str tmp1, [pmc, #AT91_PMC_MCKR]
364 ENDPROC(at91_ulp_mode)
367 * void at91_sramc_self_refresh(unsigned int is_active)
370 * @r0: 1 - active self-refresh mode
371 * 0 - exit self-refresh mode
374 * @r2: base address of the sram controller
377 ENTRY(at91_sramc_self_refresh)
381 cmp r1, #AT91_MEMCTRL_MC
385 * at91rm9200 Memory controller
389 * For exiting the self-refresh mode, do nothing,
390 * automatically exit the self-refresh mode.
392 tst r0, #SRAMC_SELF_FRESH_ACTIVE
395 /* Active SDRAM self-refresh mode */
397 str r3, [r2, #AT91_MC_SDRAMC_SRR]
401 cmp r1, #AT91_MEMCTRL_DDRSDR
405 * DDR Memory controller
407 tst r0, #SRAMC_SELF_FRESH_ACTIVE
410 /* LPDDR1 --> force DDR2 mode during self-refresh */
411 ldr r3, [r2, #AT91_DDRSDRC_MDR]
412 str r3, .saved_sam9_mdr
413 bic r3, r3, #~AT91_DDRSDRC_MD
414 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
415 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
416 biceq r3, r3, #AT91_DDRSDRC_MD
417 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
418 streq r3, [r2, #AT91_DDRSDRC_MDR]
420 /* Active DDRC self-refresh mode */
421 ldr r3, [r2, #AT91_DDRSDRC_LPR]
422 str r3, .saved_sam9_lpr
423 bic r3, r3, #AT91_DDRSDRC_LPCB
424 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
425 str r3, [r2, #AT91_DDRSDRC_LPR]
427 /* If using the 2nd ddr controller */
432 ldr r3, [r2, #AT91_DDRSDRC_MDR]
433 str r3, .saved_sam9_mdr1
434 bic r3, r3, #~AT91_DDRSDRC_MD
435 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
436 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
437 biceq r3, r3, #AT91_DDRSDRC_MD
438 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
439 streq r3, [r2, #AT91_DDRSDRC_MDR]
441 /* Active DDRC self-refresh mode */
442 ldr r3, [r2, #AT91_DDRSDRC_LPR]
443 str r3, .saved_sam9_lpr1
444 bic r3, r3, #AT91_DDRSDRC_LPCB
445 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
446 str r3, [r2, #AT91_DDRSDRC_LPR]
452 /* Restore MDR in case of LPDDR1 */
453 ldr r3, .saved_sam9_mdr
454 str r3, [r2, #AT91_DDRSDRC_MDR]
455 /* Restore LPR on AT91 with DDRAM */
456 ldr r3, .saved_sam9_lpr
457 str r3, [r2, #AT91_DDRSDRC_LPR]
459 /* If using the 2nd ddr controller */
462 ldrne r3, .saved_sam9_mdr1
463 strne r3, [r2, #AT91_DDRSDRC_MDR]
464 ldrne r3, .saved_sam9_lpr1
465 strne r3, [r2, #AT91_DDRSDRC_LPR]
470 * SDRAMC Memory controller
473 tst r0, #SRAMC_SELF_FRESH_ACTIVE
476 /* Active SDRAMC self-refresh mode */
477 ldr r3, [r2, #AT91_SDRAMC_LPR]
478 str r3, .saved_sam9_lpr
479 bic r3, r3, #AT91_SDRAMC_LPCB
480 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
481 str r3, [r2, #AT91_SDRAMC_LPR]
484 ldr r3, .saved_sam9_lpr
485 str r3, [r2, #AT91_SDRAMC_LPR]
489 ENDPROC(at91_sramc_self_refresh)
518 ENTRY(at91_pm_suspend_in_sram_sz)
519 .word .-at91_pm_suspend_in_sram