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)]
180 /* Save PLLB setting and disable it */
181 ldr r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
184 mov r3, #AT91_PMC_PLLCOUNT
185 str r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
189 /* Turn off the main oscillator */
190 ldr r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
191 bic r3, r3, #AT91_PMC_MOSCEN
192 str r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
194 /* Wait for interrupt */
195 mcr p15, 0, r0, c7, c0, 4
197 /* Turn on the main oscillator */
198 ldr r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
199 orr r3, r3, #AT91_PMC_MOSCEN
200 str r3, [r1, #(AT91_CKGR_MOR - AT91_PMC)]
204 /* Restore PLLB setting */
206 str r3, [r1, #(AT91_CKGR_PLLBR - AT91_PMC)]
210 /* Restore PLLA setting */
212 str r3, [r1, #(AT91_CKGR_PLLAR - AT91_PMC)]
216 #ifdef SLOWDOWN_MASTER_CLOCK
218 * First set PRES if it was not 0,
219 * than set CSS and MDIV fields.
221 * See AT91RM9200 errata #27 and #28 for details.
224 tst r3, #AT91_PMC_PRES
226 and r3, r3, #AT91_PMC_PRES
227 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
233 * Restore master clock setting
235 2: ldr r3, .saved_mckr
236 str r3, [r1, #(AT91_PMC_MCKR - AT91_PMC)]
240 #ifdef CONFIG_ARCH_AT91RM9200
241 /* Do nothing - self-refresh is automatically disabled. */
242 #elif defined(CONFIG_ARCH_AT91CAP9)
243 /* Restore LPR on AT91CAP9 */
244 ldr r3, .saved_sam9_lpr
245 str r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
247 /* Restore LPR on AT91SAM9 */
248 ldr r3, .saved_sam9_lpr
249 str r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
252 /* Restore registers, and return */
253 ldmfd sp!, {r0 - r12, pc}
269 .word AT91_VA_BASE_SYS + AT91_PMC
271 #ifdef CONFIG_ARCH_AT91RM9200
272 .at91_va_base_sdramc:
273 .word AT91_VA_BASE_SYS
274 #elif defined(CONFIG_ARCH_AT91CAP9)
275 .at91_va_base_sdramc:
276 .word AT91_VA_BASE_SYS + AT91_DDRSDRC
278 .at91_va_base_sdramc:
279 .word AT91_VA_BASE_SYS + AT91_SDRAMC
282 ENTRY(at91_slow_clock_sz)
283 .word .-at91_slow_clock