aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-at91
diff options
context:
space:
mode:
authorWenyou Yang <wenyou.yang@atmel.com>2015-03-08 23:48:26 -0400
committerNicolas Ferre <nicolas.ferre@atmel.com>2015-03-13 06:12:07 -0400
commit0ab285c2fafe90dfd665b29057666c3953b2592c (patch)
tree8877b0e66663718af88c00518e14183cc6ec0f0e /arch/arm/mach-at91
parentd18c570ef3fe9c3b394c0c215b04e9729d85d14f (diff)
ARM: at91/pm_slowclock: create the procedure to handle the sdram self-refresh
To decrease the duplicated code, create the procedure to contain both activing and exiting the sdram self-refresh mode. Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com> Tested-by: Sylvain Rochet <sylvain.rochet@finsecur.com> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Diffstat (limited to 'arch/arm/mach-at91')
-rw-r--r--arch/arm/mach-at91/pm_slowclock.S244
1 files changed, 139 insertions, 105 deletions
diff --git a/arch/arm/mach-at91/pm_slowclock.S b/arch/arm/mach-at91/pm_slowclock.S
index a207dea3a152..4c5a363646dd 100644
--- a/arch/arm/mach-at91/pm_slowclock.S
+++ b/arch/arm/mach-at91/pm_slowclock.S
@@ -16,10 +16,10 @@
16#include <mach/hardware.h> 16#include <mach/hardware.h>
17#include <mach/at91_ramc.h> 17#include <mach/at91_ramc.h>
18 18
19#define SRAMC_SELF_FRESH_ACTIVE 0x01
20#define SRAMC_SELF_FRESH_EXIT 0x00
21
19pmc .req r0 22pmc .req r0
20sdramc .req r1
21ramc1 .req r2
22memctrl .req r3
23tmp1 .req r4 23tmp1 .req r4
24tmp2 .req r5 24tmp2 .req r5
25 25
@@ -75,78 +75,17 @@ ENTRY(at91_slow_clock)
75 mov tmp1, #0 75 mov tmp1, #0
76 mcr p15, 0, tmp1, c7, c10, 4 76 mcr p15, 0, tmp1, c7, c10, 4
77 77
78 cmp memctrl, #AT91_MEMCTRL_MC 78 str r0, .pmc_base
79 bne ddr_sr_enable 79 str r1, .sramc_base
80 str r2, .sramc1_base
81 str r3, .memtype
80 82
81 /* 83 /* Active the self-refresh mode */
82 * at91rm9200 Memory controller 84 mov r0, #SRAMC_SELF_FRESH_ACTIVE
83 */ 85 bl at91_sramc_self_refresh
84 /* Put SDRAM in self-refresh mode */
85 mov tmp1, #1
86 str tmp1, [sdramc, #AT91RM9200_SDRAMC_SRR]
87 b sdr_sr_done
88 86
89 /* 87 ldr pmc, .pmc_base
90 * DDRSDR Memory controller
91 */
92ddr_sr_enable:
93 cmp memctrl, #AT91_MEMCTRL_DDRSDR
94 bne sdr_sr_enable
95 88
96 /* LPDDR1 --> force DDR2 mode during self-refresh */
97 ldr tmp1, [sdramc, #AT91_DDRSDRC_MDR]
98 str tmp1, .saved_sam9_mdr
99 bic tmp1, tmp1, #~AT91_DDRSDRC_MD
100 cmp tmp1, #AT91_DDRSDRC_MD_LOW_POWER_DDR
101 ldreq tmp1, [sdramc, #AT91_DDRSDRC_MDR]
102 biceq tmp1, tmp1, #AT91_DDRSDRC_MD
103 orreq tmp1, tmp1, #AT91_DDRSDRC_MD_DDR2
104 streq tmp1, [sdramc, #AT91_DDRSDRC_MDR]
105
106 /* prepare for DDRAM self-refresh mode */
107 ldr tmp1, [sdramc, #AT91_DDRSDRC_LPR]
108 str tmp1, .saved_sam9_lpr
109 bic tmp1, #AT91_DDRSDRC_LPCB
110 orr tmp1, #AT91_DDRSDRC_LPCB_SELF_REFRESH
111
112 /* figure out if we use the second ram controller */
113 cmp ramc1, #0
114 beq ddr_no_2nd_ctrl
115
116 ldr tmp2, [ramc1, #AT91_DDRSDRC_MDR]
117 str tmp2, .saved_sam9_mdr1
118 bic tmp2, tmp2, #~AT91_DDRSDRC_MD
119 cmp tmp2, #AT91_DDRSDRC_MD_LOW_POWER_DDR
120 ldreq tmp2, [ramc1, #AT91_DDRSDRC_MDR]
121 biceq tmp2, tmp2, #AT91_DDRSDRC_MD
122 orreq tmp2, tmp2, #AT91_DDRSDRC_MD_DDR2
123 streq tmp2, [ramc1, #AT91_DDRSDRC_MDR]
124
125 ldr tmp2, [ramc1, #AT91_DDRSDRC_LPR]
126 str tmp2, .saved_sam9_lpr1
127 bic tmp2, #AT91_DDRSDRC_LPCB
128 orr tmp2, #AT91_DDRSDRC_LPCB_SELF_REFRESH
129
130 /* Enable DDRAM self-refresh mode */
131 str tmp2, [ramc1, #AT91_DDRSDRC_LPR]
132ddr_no_2nd_ctrl:
133 str tmp1, [sdramc, #AT91_DDRSDRC_LPR]
134
135 b sdr_sr_done
136
137 /*
138 * SDRAMC Memory controller
139 */
140sdr_sr_enable:
141 /* Enable SDRAM self-refresh mode */
142 ldr tmp1, [sdramc, #AT91_SDRAMC_LPR]
143 str tmp1, .saved_sam9_lpr
144
145 bic tmp1, #AT91_SDRAMC_LPCB
146 orr tmp1, #AT91_SDRAMC_LPCB_SELF_REFRESH
147 str tmp1, [sdramc, #AT91_SDRAMC_LPR]
148
149sdr_sr_done:
150 /* Save Master clock setting */ 89 /* Save Master clock setting */
151 ldr tmp1, [pmc, #AT91_PMC_MCKR] 90 ldr tmp1, [pmc, #AT91_PMC_MCKR]
152 str tmp1, .saved_mckr 91 str tmp1, .saved_mckr
@@ -199,67 +138,162 @@ sdr_sr_done:
199 /* 138 /*
200 * Restore master clock setting 139 * Restore master clock setting
201 */ 140 */
2022: ldr tmp1, .saved_mckr 141 ldr tmp1, .saved_mckr
203 str tmp1, [pmc, #AT91_PMC_MCKR] 142 str tmp1, [pmc, #AT91_PMC_MCKR]
204 143
205 wait_mckrdy 144 wait_mckrdy
206 145
146 /* Exit the self-refresh mode */
147 mov r0, #SRAMC_SELF_FRESH_EXIT
148 bl at91_sramc_self_refresh
149
150 /* Restore registers, and return */
151 ldmfd sp!, {r4 - r12, pc}
152ENDPROC(at91_slow_clock)
153
154/*
155 * void at91_sramc_self_refresh(unsigned int is_active)
156 *
157 * @input param:
158 * @r0: 1 - active self-refresh mode
159 * 0 - exit self-refresh mode
160 * register usage:
161 * @r1: memory type
162 * @r2: base address of the sram controller
163 */
164
165ENTRY(at91_sramc_self_refresh)
166 ldr r1, .memtype
167 ldr r2, .sramc_base
168
169 cmp r1, #AT91_MEMCTRL_MC
170 bne ddrc_sf
171
207 /* 172 /*
208 * at91rm9200 Memory controller 173 * at91rm9200 Memory controller
209 * Do nothing - self-refresh is automatically disabled.
210 */ 174 */
211 cmp memctrl, #AT91_MEMCTRL_MC 175
212 beq ram_restored 176 /*
177 * For exiting the self-refresh mode, do nothing,
178 * automatically exit the self-refresh mode.
179 */
180 tst r0, #SRAMC_SELF_FRESH_ACTIVE
181 beq exit_sramc_sf
182
183 /* Active SDRAM self-refresh mode */
184 mov r3, #1
185 str r3, [r2, #AT91RM9200_SDRAMC_SRR]
186 b exit_sramc_sf
187
188ddrc_sf:
189 cmp r1, #AT91_MEMCTRL_DDRSDR
190 bne sdramc_sf
213 191
214 /* 192 /*
215 * DDRSDR Memory controller 193 * DDR Memory controller
216 */ 194 */
217 cmp memctrl, #AT91_MEMCTRL_DDRSDR 195 tst r0, #SRAMC_SELF_FRESH_ACTIVE
218 bne sdr_en_restore 196 beq ddrc_exit_sf
197
198 /* LPDDR1 --> force DDR2 mode during self-refresh */
199 ldr r3, [r2, #AT91_DDRSDRC_MDR]
200 str r3, .saved_sam9_mdr
201 bic r3, r3, #~AT91_DDRSDRC_MD
202 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
203 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
204 biceq r3, r3, #AT91_DDRSDRC_MD
205 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
206 streq r3, [r2, #AT91_DDRSDRC_MDR]
207
208 /* Active DDRC self-refresh mode */
209 ldr r3, [r2, #AT91_DDRSDRC_LPR]
210 str r3, .saved_sam9_lpr
211 bic r3, r3, #AT91_DDRSDRC_LPCB
212 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
213 str r3, [r2, #AT91_DDRSDRC_LPR]
214
215 /* If using the 2nd ddr controller */
216 ldr r2, .sramc1_base
217 cmp r2, #0
218 beq no_2nd_ddrc
219
220 ldr r3, [r2, #AT91_DDRSDRC_MDR]
221 str r3, .saved_sam9_mdr1
222 bic r3, r3, #~AT91_DDRSDRC_MD
223 cmp r3, #AT91_DDRSDRC_MD_LOW_POWER_DDR
224 ldreq r3, [r2, #AT91_DDRSDRC_MDR]
225 biceq r3, r3, #AT91_DDRSDRC_MD
226 orreq r3, r3, #AT91_DDRSDRC_MD_DDR2
227 streq r3, [r2, #AT91_DDRSDRC_MDR]
228
229 /* Active DDRC self-refresh mode */
230 ldr r3, [r2, #AT91_DDRSDRC_LPR]
231 str r3, .saved_sam9_lpr1
232 bic r3, r3, #AT91_DDRSDRC_LPCB
233 orr r3, r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
234 str r3, [r2, #AT91_DDRSDRC_LPR]
235
236no_2nd_ddrc:
237 b exit_sramc_sf
238
239ddrc_exit_sf:
219 /* Restore MDR in case of LPDDR1 */ 240 /* Restore MDR in case of LPDDR1 */
220 ldr tmp1, .saved_sam9_mdr 241 ldr r3, .saved_sam9_mdr
221 str tmp1, [sdramc, #AT91_DDRSDRC_MDR] 242 str r3, [r2, #AT91_DDRSDRC_MDR]
222 /* Restore LPR on AT91 with DDRAM */ 243 /* Restore LPR on AT91 with DDRAM */
223 ldr tmp1, .saved_sam9_lpr 244 ldr r3, .saved_sam9_lpr
224 str tmp1, [sdramc, #AT91_DDRSDRC_LPR] 245 str r3, [r2, #AT91_DDRSDRC_LPR]
225 246
226 /* if we use the second ram controller */ 247 /* If using the 2nd ddr controller */
227 cmp ramc1, #0 248 ldr r2, .sramc1_base
228 ldrne tmp2, .saved_sam9_mdr1 249 cmp r2, #0
229 strne tmp2, [ramc1, #AT91_DDRSDRC_MDR] 250 ldrne r3, .saved_sam9_mdr1
230 ldrne tmp2, .saved_sam9_lpr1 251 strne r3, [r2, #AT91_DDRSDRC_MDR]
231 strne tmp2, [ramc1, #AT91_DDRSDRC_LPR] 252 ldrne r3, .saved_sam9_lpr1
253 strne r3, [r2, #AT91_DDRSDRC_LPR]
232 254
233 b ram_restored 255 b exit_sramc_sf
234 256
235 /* 257 /*
236 * SDRAMC Memory controller 258 * SDRAMC Memory controller
237 */ 259 */
238sdr_en_restore: 260sdramc_sf:
239 /* Restore LPR on AT91 with SDRAM */ 261 tst r0, #SRAMC_SELF_FRESH_ACTIVE
240 ldr tmp1, .saved_sam9_lpr 262 beq sdramc_exit_sf
241 str tmp1, [sdramc, #AT91_SDRAMC_LPR] 263
242 264 /* Active SDRAMC self-refresh mode */
243ram_restored: 265 ldr r3, [r2, #AT91_SDRAMC_LPR]
244 /* Restore registers, and return */ 266 str r3, .saved_sam9_lpr
245 ldmfd sp!, {r4 - r12, pc} 267 bic r3, r3, #AT91_SDRAMC_LPCB
246 268 orr r3, r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
247 269 str r3, [r2, #AT91_SDRAMC_LPR]
270
271sdramc_exit_sf:
272 ldr r3, .saved_sam9_lpr
273 str r3, [r2, #AT91_SDRAMC_LPR]
274
275exit_sramc_sf:
276 mov pc, lr
277ENDPROC(at91_sramc_self_refresh)
278
279.pmc_base:
280 .word 0
281.sramc_base:
282 .word 0
283.sramc1_base:
284 .word 0
285.memtype:
286 .word 0
248.saved_mckr: 287.saved_mckr:
249 .word 0 288 .word 0
250
251.saved_pllar: 289.saved_pllar:
252 .word 0 290 .word 0
253
254.saved_sam9_lpr: 291.saved_sam9_lpr:
255 .word 0 292 .word 0
256
257.saved_sam9_lpr1: 293.saved_sam9_lpr1:
258 .word 0 294 .word 0
259
260.saved_sam9_mdr: 295.saved_sam9_mdr:
261 .word 0 296 .word 0
262
263.saved_sam9_mdr1: 297.saved_sam9_mdr1:
264 .word 0 298 .word 0
265 299