2 * arch/arm/mach-at91/pm_slow_clock.S
4 * Copyright (C) 2006 Savin Zlobec
7 * Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/linkage.h>
15 #include <linux/clk/at91_pmc.h>
18 #define SRAMC_SELF_FRESH_ACTIVE 0x01
19 #define SRAMC_SELF_FRESH_EXIT 0x00
26 * Wait until master clock is ready (after switching master clock source)
29 1: ldr tmp1, [pmc, #AT91_PMC_SR]
30 tst tmp1, #AT91_PMC_MCKRDY
35 * Wait until master oscillator has stabilized.
38 1: ldr tmp1, [pmc, #AT91_PMC_SR]
39 tst tmp1, #AT91_PMC_MOSCS
44 * Wait until PLLA has locked.
47 1: ldr tmp1, [pmc, #AT91_PMC_SR]
48 tst tmp1, #AT91_PMC_LOCKA
53 * Put the processor to enter the idle state
57 #if defined(CONFIG_CPU_V7)
58 mov tmp1, #AT91_PMC_PCK
59 str tmp1, [pmc, #AT91_PMC_SCDR]
63 wfi @ Wait For Interrupt
65 mcr p15, 0, tmp1, c7, c0, 4
75 * void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *sdramc,
76 * void __iomem *ramc1, int memctrl)
78 * @r0: base address of AT91_PMC
79 * @r1: base address of SDRAM Controller (SDRAM, DDRSDR, or AT91_SYS)
80 * @r2: base address of second SDRAM Controller or 0 if not present
83 ENTRY(at91_pm_suspend_in_sram)
84 /* Save registers on stack */
85 stmfd sp!, {r4 - r12, lr}
87 /* Drain write buffer */
89 mcr p15, 0, tmp1, c7, c10, 4
95 and r0, r3, #AT91_PM_MEMTYPE_MASK
98 lsr r0, r3, #AT91_PM_MODE_OFFSET
99 and r0, r0, #AT91_PM_MODE_MASK
102 /* Active the self-refresh mode */
103 mov r0, #SRAMC_SELF_FRESH_ACTIVE
104 bl at91_sramc_self_refresh
107 tst r0, #AT91_PM_SLOW_CLOCK
108 beq skip_disable_main_clock
112 /* Save Master clock setting */
113 ldr tmp1, [pmc, #AT91_PMC_MCKR]
114 str tmp1, .saved_mckr
117 * Set the Master clock source to slow clock
119 bic tmp1, tmp1, #AT91_PMC_CSS
120 str tmp1, [pmc, #AT91_PMC_MCKR]
124 /* Save PLLA setting and disable it */
125 ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
126 str tmp1, .saved_pllar
128 mov tmp1, #AT91_PMC_PLLCOUNT
129 orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
130 str tmp1, [pmc, #AT91_CKGR_PLLAR]
132 /* Turn off the main oscillator */
133 ldr tmp1, [pmc, #AT91_CKGR_MOR]
134 bic tmp1, tmp1, #AT91_PMC_MOSCEN
135 orr tmp1, tmp1, #AT91_PMC_KEY
136 str tmp1, [pmc, #AT91_CKGR_MOR]
138 skip_disable_main_clock:
141 /* Wait for interrupt */
145 tst r0, #AT91_PM_SLOW_CLOCK
146 beq skip_enable_main_clock
150 /* Turn on the main oscillator */
151 ldr tmp1, [pmc, #AT91_CKGR_MOR]
152 orr tmp1, tmp1, #AT91_PMC_MOSCEN
153 orr tmp1, tmp1, #AT91_PMC_KEY
154 str tmp1, [pmc, #AT91_CKGR_MOR]
158 /* Restore PLLA setting */
159 ldr tmp1, .saved_pllar
160 str tmp1, [pmc, #AT91_CKGR_PLLAR]
162 tst tmp1, #(AT91_PMC_MUL & 0xff0000)
164 tst tmp1, #(AT91_PMC_MUL & ~0xff0000)
171 * Restore master clock setting
173 ldr tmp1, .saved_mckr
174 str tmp1, [pmc, #AT91_PMC_MCKR]
178 skip_enable_main_clock:
179 /* Exit the self-refresh mode */
180 mov r0, #SRAMC_SELF_FRESH_EXIT
181 bl at91_sramc_self_refresh
183 /* Restore registers, and return */
184 ldmfd sp!, {r4 - r12, pc}
185 ENDPROC(at91_pm_suspend_in_sram)
188 * void at91_sramc_self_refresh(unsigned int is_active)
191 * @r0: 1 - active self-refresh mode
192 * 0 - exit self-refresh mode
195 * @r2: base address of the sram controller
198 ENTRY(at91_sramc_self_refresh)
202 cmp r1, #AT91_MEMCTRL_MC
206 * at91rm9200 Memory controller
210 * For exiting the self-refresh mode, do nothing,
211 * automatically exit the self-refresh mode.
213 tst r0, #SRAMC_SELF_FRESH_ACTIVE
216 /* Active SDRAM self-refresh mode */
218 str r3, [r2, #AT91_MC_SDRAMC_SRR]
222 cmp r1, #AT91_MEMCTRL_DDRSDR
226 * DDR Memory controller
228 tst r0, #SRAMC_SELF_FRESH_ACTIVE
231 /* LPDDR1 --> force DDR2 mode during self-refresh */
232 ldr r3, [r2, #AT91_DDRSDRC_MDR]
233 str r3, .saved_sam9_mdr
234 bic r3, r3, #~AT91_DDRSDRC_MD
235 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
236 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
237 biceq r3, r3, #AT91_DDRSDRC_MD
238 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
239 streq r3, [r2, #AT91_DDRSDRC_MDR]
241 /* Active DDRC self-refresh mode */
242 ldr r3, [r2, #AT91_DDRSDRC_LPR]
243 str r3, .saved_sam9_lpr
244 bic r3, r3, #AT91_DDRSDRC_LPCB
245 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
246 str r3, [r2, #AT91_DDRSDRC_LPR]
248 /* If using the 2nd ddr controller */
253 ldr r3, [r2, #AT91_DDRSDRC_MDR]
254 str r3, .saved_sam9_mdr1
255 bic r3, r3, #~AT91_DDRSDRC_MD
256 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
257 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
258 biceq r3, r3, #AT91_DDRSDRC_MD
259 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
260 streq r3, [r2, #AT91_DDRSDRC_MDR]
262 /* Active DDRC self-refresh mode */
263 ldr r3, [r2, #AT91_DDRSDRC_LPR]
264 str r3, .saved_sam9_lpr1
265 bic r3, r3, #AT91_DDRSDRC_LPCB
266 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
267 str r3, [r2, #AT91_DDRSDRC_LPR]
273 /* Restore MDR in case of LPDDR1 */
274 ldr r3, .saved_sam9_mdr
275 str r3, [r2, #AT91_DDRSDRC_MDR]
276 /* Restore LPR on AT91 with DDRAM */
277 ldr r3, .saved_sam9_lpr
278 str r3, [r2, #AT91_DDRSDRC_LPR]
280 /* If using the 2nd ddr controller */
283 ldrne r3, .saved_sam9_mdr1
284 strne r3, [r2, #AT91_DDRSDRC_MDR]
285 ldrne r3, .saved_sam9_lpr1
286 strne r3, [r2, #AT91_DDRSDRC_LPR]
291 * SDRAMC Memory controller
294 tst r0, #SRAMC_SELF_FRESH_ACTIVE
297 /* Active SDRAMC self-refresh mode */
298 ldr r3, [r2, #AT91_SDRAMC_LPR]
299 str r3, .saved_sam9_lpr
300 bic r3, r3, #AT91_SDRAMC_LPCB
301 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
302 str r3, [r2, #AT91_SDRAMC_LPR]
305 ldr r3, .saved_sam9_lpr
306 str r3, [r2, #AT91_SDRAMC_LPR]
310 ENDPROC(at91_sramc_self_refresh)
335 ENTRY(at91_pm_suspend_in_sram_sz)
336 .word .-at91_pm_suspend_in_sram