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.
15 #include <linux/linkage.h>
16 #include <mach/hardware.h>
17 #include <mach/at91_pmc.h>
19 #ifdef CONFIG_ARCH_AT91RM9200
20 #include <mach/at91rm9200_mc.h>
21 #elif defined(CONFIG_ARCH_AT91CAP9)
22 #include <mach/at91cap9_ddrsdr.h>
24 #include <mach/at91sam9_sdramc.h>
28 #ifdef CONFIG_ARCH_AT91SAM9263
30 * FIXME either or both the SDRAM controllers (EB0, EB1) might be in use;
31 * handle those cases both here and in the Suspend-To-RAM support.
33 #define AT91_SDRAMC AT91_SDRAMC0
34 #warning Assuming EB1 SDRAM controller is *NOT* used
38 * When SLOWDOWN_MASTER_CLOCK is defined we will also slow down the Master
39 * clock during suspend by adjusting its prescalar and divisor.
40 * NOTE: This hasn't been shown to be stable on SAM9s; and on the RM9200 there
41 * are errata regarding adjusting the prescalar and divisor.
43 #undef SLOWDOWN_MASTER_CLOCK
45 #define MCKRDY_TIMEOUT 1000
46 #define MOSCRDY_TIMEOUT 1000
47 #define PLLALOCK_TIMEOUT 1000
48 #define PLLBLOCK_TIMEOUT 1000
52 * Wait until master clock is ready (after switching master clock source)
55 mov r4, #MCKRDY_TIMEOUT
59 ldr r3, [r1, #(AT91_PMC_SR - AT91_PMC)]
60 tst r3, #AT91_PMC_MCKRDY
66 * Wait until master oscillator has stabilized.
69 mov r4, #MOSCRDY_TIMEOUT
73 ldr r3, [r1, #(AT91_PMC_SR - AT91_PMC)]
74 tst r3, #AT91_PMC_MOSCS
80 * Wait until PLLA has locked.
83 mov r4, #PLLALOCK_TIMEOUT
87 ldr r3, [r1, #(AT91_PMC_SR - AT91_PMC)]
88 tst r3, #AT91_PMC_LOCKA
94 * Wait until PLLB has locked.
97 mov r4, #PLLBLOCK_TIMEOUT
101 ldr r3, [r1, #(AT91_PMC_SR - AT91_PMC)]
102 tst r3, #AT91_PMC_LOCKB
109 ENTRY(at91_slow_clock)
110 /* Save registers on stack */
111 stmfd sp!, {r0 - r12, lr}
115 * R1 = Base address of AT91_PMC
116 * R2 = Base address of AT91_SDRAMC (or AT91_SYS on AT91RM9200)
117 * R3 = temporary register
118 * R4 = temporary register
120 ldr r1, .at91_va_base_pmc
121 ldr r2, .at91_va_base_sdramc
123 /* Drain write buffer */
124 mcr p15, 0, r0, c7, c10, 4
126 #ifdef CONFIG_ARCH_AT91RM9200
127 /* Put SDRAM in self-refresh mode */
129 str r3, [r2, #AT91_SDRAMC_SRR]
130 #elif defined(CONFIG_ARCH_AT91CAP9)
131 /* Enable SDRAM self-refresh mode */
132 ldr r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
133 str r3, .saved_sam9_lpr
135 mov r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
136 str r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
138 /* Enable SDRAM self-refresh mode */
139 ldr r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
140 str r3, .saved_sam9_lpr
142 mov r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
143 str r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
146 /* Save Master clock setting */
147 ldr r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
151 * Set the Master clock source to slow clock
153 bic r3, r3, #AT91_PMC_CSS
154 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
158 #ifdef SLOWDOWN_MASTER_CLOCK
160 * Set the Master Clock PRES and MDIV fields.
162 * See AT91RM9200 errata #27 and #28 for details.
165 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
170 /* Save PLLA setting and disable it */
171 ldr r3, [r1, #(AT91_CKGR_PLLAR - AT91_PMC)]
174 mov r3, #AT91_PMC_PLLCOUNT
175 orr r3, r3, #(1 << 29) /* bit 29 always set */
176 str r3, [r1, #(AT91_CKGR_PLLAR - AT91_PMC)]
178 /* Save PLLB setting and disable it */
179 ldr r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
182 mov r3, #AT91_PMC_PLLCOUNT
183 str r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
185 /* Turn off the main oscillator */
186 ldr r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
187 bic r3, r3, #AT91_PMC_MOSCEN
188 str r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
190 /* Wait for interrupt */
191 mcr p15, 0, r0, c7, c0, 4
193 /* Turn on the main oscillator */
194 ldr r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
195 orr r3, r3, #AT91_PMC_MOSCEN
196 str r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
200 /* Restore PLLB setting */
202 str r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
204 tst r3, #(AT91_PMC_MUL & 0xff0000)
206 tst r3, #(AT91_PMC_MUL & ~0xff0000)
212 /* Restore PLLA setting */
214 str r3, [r1, #(AT91_CKGR_PLLAR - AT91_PMC)]
216 tst r3, #(AT91_PMC_MUL & 0xff0000)
218 tst r3, #(AT91_PMC_MUL & ~0xff0000)
224 #ifdef SLOWDOWN_MASTER_CLOCK
226 * First set PRES if it was not 0,
227 * than set CSS and MDIV fields.
229 * See AT91RM9200 errata #27 and #28 for details.
232 tst r3, #AT91_PMC_PRES
234 and r3, r3, #AT91_PMC_PRES
235 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
241 * Restore master clock setting
243 2: ldr r3, .saved_mckr
244 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
248 #ifdef CONFIG_ARCH_AT91RM9200
249 /* Do nothing - self-refresh is automatically disabled. */
250 #elif defined(CONFIG_ARCH_AT91CAP9)
251 /* Restore LPR on AT91CAP9 */
252 ldr r3, .saved_sam9_lpr
253 str r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
255 /* Restore LPR on AT91SAM9 */
256 ldr r3, .saved_sam9_lpr
257 str r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
260 /* Restore registers, and return */
261 ldmfd sp!, {r0 - r12, pc}
277 .word AT91_VA_BASE_SYS + AT91_PMC
279 #ifdef CONFIG_ARCH_AT91RM9200
280 .at91_va_base_sdramc:
281 .word AT91_VA_BASE_SYS
282 #elif defined(CONFIG_ARCH_AT91CAP9)
283 .at91_va_base_sdramc:
284 .word AT91_VA_BASE_SYS + AT91_DDRSDRC
286 .at91_va_base_sdramc:
287 .word AT91_VA_BASE_SYS + AT91_SDRAMC
290 ENTRY(at91_slow_clock_sz)
291 .word .-at91_slow_clock