blob: 0d95f488b47a7fa40f7f837083e5b594c329dd65 [file] [log] [blame]
Andrew Victoreaad2db2008-09-21 21:35:18 +01001/*
2 * arch/arm/mach-at91/pm_slow_clock.S
3 *
4 * Copyright (C) 2006 Savin Zlobec
5 *
6 * AT91SAM9 support:
7 * Copyright (C) 2007 Anti Sullin <anti.sullin@artecdesign.ee
8 *
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.
12 *
13 */
Andrew Victoreaad2db2008-09-21 21:35:18 +010014#include <linux/linkage.h>
Boris BREZILLON2edb90a2013-10-11 09:37:45 +020015#include <linux/clk/at91_pmc.h>
Wenyou Yang23be4be2015-03-09 11:49:46 +080016#include "pm.h"
Andrew Victoreaad2db2008-09-21 21:35:18 +010017
Wenyou Yang0ab285c2015-03-09 11:48:26 +080018#define SRAMC_SELF_FRESH_ACTIVE 0x01
19#define SRAMC_SELF_FRESH_EXIT 0x00
20
Jean-Christophe PLAGNIOL-VILLARD8ff12ad32012-02-22 17:50:54 +010021pmc .req r0
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +010022tmp1 .req r4
23tmp2 .req r5
Andrew Victoreaad2db2008-09-21 21:35:18 +010024
25/*
26 * Wait until master clock is ready (after switching master clock source)
27 */
28 .macro wait_mckrdy
Sylvain Rochetad4a38d2015-02-05 14:00:37 +0800291: ldr tmp1, [pmc, #AT91_PMC_SR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +010030 tst tmp1, #AT91_PMC_MCKRDY
Andrew Victoreaad2db2008-09-21 21:35:18 +010031 beq 1b
Andrew Victoreaad2db2008-09-21 21:35:18 +010032 .endm
33
34/*
35 * Wait until master oscillator has stabilized.
36 */
37 .macro wait_moscrdy
Sylvain Rochetad4a38d2015-02-05 14:00:37 +0800381: ldr tmp1, [pmc, #AT91_PMC_SR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +010039 tst tmp1, #AT91_PMC_MOSCS
Andrew Victoreaad2db2008-09-21 21:35:18 +010040 beq 1b
Andrew Victoreaad2db2008-09-21 21:35:18 +010041 .endm
42
43/*
44 * Wait until PLLA has locked.
45 */
46 .macro wait_pllalock
Sylvain Rochetad4a38d2015-02-05 14:00:37 +0800471: ldr tmp1, [pmc, #AT91_PMC_SR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +010048 tst tmp1, #AT91_PMC_LOCKA
Andrew Victoreaad2db2008-09-21 21:35:18 +010049 beq 1b
Andrew Victoreaad2db2008-09-21 21:35:18 +010050 .endm
51
Wenyou Yang205676582015-03-09 11:53:46 +080052/*
53 * Put the processor to enter the idle state
54 */
55 .macro at91_cpu_idle
56
57#if defined(CONFIG_CPU_V7)
58 mov tmp1, #AT91_PMC_PCK
59 str tmp1, [pmc, #AT91_PMC_SCDR]
60
61 dsb
62
63 wfi @ Wait For Interrupt
64#else
65 mcr p15, 0, tmp1, c7, c0, 4
66#endif
67
68 .endm
69
Andrew Victoreaad2db2008-09-21 21:35:18 +010070 .text
71
Wenyou Yange7b848d2015-03-11 10:08:12 +080072 .arm
73
Wenyou Yang5726a8b2015-03-09 11:51:09 +080074/*
75 * void at91_pm_suspend_in_sram(void __iomem *pmc, void __iomem *sdramc,
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +010076 * void __iomem *ramc1, int memctrl)
Wenyou Yang5726a8b2015-03-09 11:51:09 +080077 * @input param:
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
81 * @r3: pm information
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +010082 */
Wenyou Yang5726a8b2015-03-09 11:51:09 +080083ENTRY(at91_pm_suspend_in_sram)
Andrew Victoreaad2db2008-09-21 21:35:18 +010084 /* Save registers on stack */
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +010085 stmfd sp!, {r4 - r12, lr}
Andrew Victoreaad2db2008-09-21 21:35:18 +010086
Andrew Victoreaad2db2008-09-21 21:35:18 +010087 /* Drain write buffer */
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +010088 mov tmp1, #0
89 mcr p15, 0, tmp1, c7, c10, 4
Andrew Victoreaad2db2008-09-21 21:35:18 +010090
Wenyou Yang0ab285c2015-03-09 11:48:26 +080091 str r0, .pmc_base
92 str r1, .sramc_base
93 str r2, .sramc1_base
Wenyou Yang23be4be2015-03-09 11:49:46 +080094
95 and r0, r3, #AT91_PM_MEMTYPE_MASK
96 str r0, .memtype
97
98 lsr r0, r3, #AT91_PM_MODE_OFFSET
99 and r0, r0, #AT91_PM_MODE_MASK
100 str r0, .pm_mode
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100101
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800102 /* Active the self-refresh mode */
103 mov r0, #SRAMC_SELF_FRESH_ACTIVE
104 bl at91_sramc_self_refresh
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100105
Wenyou Yang23be4be2015-03-09 11:49:46 +0800106 ldr r0, .pm_mode
107 tst r0, #AT91_PM_SLOW_CLOCK
108 beq skip_disable_main_clock
109
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800110 ldr pmc, .pmc_base
Andrew Victoreaad2db2008-09-21 21:35:18 +0100111
Andrew Victoreaad2db2008-09-21 21:35:18 +0100112 /* Save Master clock setting */
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800113 ldr tmp1, [pmc, #AT91_PMC_MCKR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100114 str tmp1, .saved_mckr
Andrew Victoreaad2db2008-09-21 21:35:18 +0100115
116 /*
117 * Set the Master clock source to slow clock
118 */
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100119 bic tmp1, tmp1, #AT91_PMC_CSS
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800120 str tmp1, [pmc, #AT91_PMC_MCKR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100121
122 wait_mckrdy
123
Andrew Victoreaad2db2008-09-21 21:35:18 +0100124 /* Save PLLA setting and disable it */
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800125 ldr tmp1, [pmc, #AT91_CKGR_PLLAR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100126 str tmp1, .saved_pllar
Andrew Victoreaad2db2008-09-21 21:35:18 +0100127
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100128 mov tmp1, #AT91_PMC_PLLCOUNT
129 orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800130 str tmp1, [pmc, #AT91_CKGR_PLLAR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100131
Andrew Victoreaad2db2008-09-21 21:35:18 +0100132 /* Turn off the main oscillator */
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800133 ldr tmp1, [pmc, #AT91_CKGR_MOR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100134 bic tmp1, tmp1, #AT91_PMC_MOSCEN
Patrice Vilchez59574572015-02-12 10:52:13 +0800135 orr tmp1, tmp1, #AT91_PMC_KEY
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800136 str tmp1, [pmc, #AT91_CKGR_MOR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100137
Wenyou Yang23be4be2015-03-09 11:49:46 +0800138skip_disable_main_clock:
139 ldr pmc, .pmc_base
140
Andrew Victoreaad2db2008-09-21 21:35:18 +0100141 /* Wait for interrupt */
Wenyou Yang205676582015-03-09 11:53:46 +0800142 at91_cpu_idle
Andrew Victoreaad2db2008-09-21 21:35:18 +0100143
Wenyou Yang23be4be2015-03-09 11:49:46 +0800144 ldr r0, .pm_mode
145 tst r0, #AT91_PM_SLOW_CLOCK
146 beq skip_enable_main_clock
147
148 ldr pmc, .pmc_base
149
Andrew Victoreaad2db2008-09-21 21:35:18 +0100150 /* Turn on the main oscillator */
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800151 ldr tmp1, [pmc, #AT91_CKGR_MOR]
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100152 orr tmp1, tmp1, #AT91_PMC_MOSCEN
Patrice Vilchez59574572015-02-12 10:52:13 +0800153 orr tmp1, tmp1, #AT91_PMC_KEY
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800154 str tmp1, [pmc, #AT91_CKGR_MOR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100155
156 wait_moscrdy
157
Andrew Victoreaad2db2008-09-21 21:35:18 +0100158 /* Restore PLLA setting */
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100159 ldr tmp1, .saved_pllar
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800160 str tmp1, [pmc, #AT91_CKGR_PLLAR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100161
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100162 tst tmp1, #(AT91_PMC_MUL & 0xff0000)
Anders Larsen9823f1a2010-04-08 11:48:16 +0100163 bne 3f
Jean-Christophe PLAGNIOL-VILLARD0dcfed12012-02-22 17:50:53 +0100164 tst tmp1, #(AT91_PMC_MUL & ~0xff0000)
Anders Larsen9823f1a2010-04-08 11:48:16 +0100165 beq 4f
1663:
Andrew Victoreaad2db2008-09-21 21:35:18 +0100167 wait_pllalock
Anders Larsen9823f1a2010-04-08 11:48:16 +01001684:
Andrew Victoreaad2db2008-09-21 21:35:18 +0100169
Andrew Victoreaad2db2008-09-21 21:35:18 +0100170 /*
171 * Restore master clock setting
172 */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800173 ldr tmp1, .saved_mckr
Jean-Christophe PLAGNIOL-VILLARDb5514952011-11-25 09:59:46 +0800174 str tmp1, [pmc, #AT91_PMC_MCKR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100175
176 wait_mckrdy
177
Wenyou Yang23be4be2015-03-09 11:49:46 +0800178skip_enable_main_clock:
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800179 /* Exit the self-refresh mode */
180 mov r0, #SRAMC_SELF_FRESH_EXIT
181 bl at91_sramc_self_refresh
182
183 /* Restore registers, and return */
184 ldmfd sp!, {r4 - r12, pc}
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800185ENDPROC(at91_pm_suspend_in_sram)
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800186
187/*
188 * void at91_sramc_self_refresh(unsigned int is_active)
189 *
190 * @input param:
191 * @r0: 1 - active self-refresh mode
192 * 0 - exit self-refresh mode
193 * register usage:
194 * @r1: memory type
195 * @r2: base address of the sram controller
196 */
197
198ENTRY(at91_sramc_self_refresh)
199 ldr r1, .memtype
200 ldr r2, .sramc_base
201
202 cmp r1, #AT91_MEMCTRL_MC
203 bne ddrc_sf
204
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100205 /*
206 * at91rm9200 Memory controller
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100207 */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800208
209 /*
210 * For exiting the self-refresh mode, do nothing,
211 * automatically exit the self-refresh mode.
212 */
213 tst r0, #SRAMC_SELF_FRESH_ACTIVE
214 beq exit_sramc_sf
215
216 /* Active SDRAM self-refresh mode */
217 mov r3, #1
Alexandre Bellonid7d45f22015-03-16 15:14:50 +0100218 str r3, [r2, #AT91_MC_SDRAMC_SRR]
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800219 b exit_sramc_sf
220
221ddrc_sf:
222 cmp r1, #AT91_MEMCTRL_DDRSDR
223 bne sdramc_sf
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100224
225 /*
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800226 * DDR Memory controller
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100227 */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800228 tst r0, #SRAMC_SELF_FRESH_ACTIVE
229 beq ddrc_exit_sf
230
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]
240
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]
247
248 /* If using the 2nd ddr controller */
249 ldr r2, .sramc1_base
250 cmp r2, #0
251 beq no_2nd_ddrc
252
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]
261
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]
268
269no_2nd_ddrc:
270 b exit_sramc_sf
271
272ddrc_exit_sf:
Peter Rosin02f513a2015-02-05 14:02:09 +0800273 /* Restore MDR in case of LPDDR1 */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800274 ldr r3, .saved_sam9_mdr
275 str r3, [r2, #AT91_DDRSDRC_MDR]
Nicolas Ferre7dca3342010-06-21 14:59:27 +0100276 /* Restore LPR on AT91 with DDRAM */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800277 ldr r3, .saved_sam9_lpr
278 str r3, [r2, #AT91_DDRSDRC_LPR]
Nicolas Ferre7dca3342010-06-21 14:59:27 +0100279
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800280 /* If using the 2nd ddr controller */
281 ldr r2, .sramc1_base
282 cmp r2, #0
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]
Nicolas Ferre7dca3342010-06-21 14:59:27 +0100287
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800288 b exit_sramc_sf
Jean-Christophe PLAGNIOL-VILLARDfb7e1972012-02-22 17:50:55 +0100289
290 /*
291 * SDRAMC Memory controller
292 */
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800293sdramc_sf:
294 tst r0, #SRAMC_SELF_FRESH_ACTIVE
295 beq sdramc_exit_sf
Andrew Victoreaad2db2008-09-21 21:35:18 +0100296
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800297 /* 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]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100303
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800304sdramc_exit_sf:
305 ldr r3, .saved_sam9_lpr
306 str r3, [r2, #AT91_SDRAMC_LPR]
Andrew Victoreaad2db2008-09-21 21:35:18 +0100307
Wenyou Yang0ab285c2015-03-09 11:48:26 +0800308exit_sramc_sf:
309 mov pc, lr
310ENDPROC(at91_sramc_self_refresh)
311
312.pmc_base:
313 .word 0
314.sramc_base:
315 .word 0
316.sramc1_base:
317 .word 0
318.memtype:
319 .word 0
Wenyou Yang23be4be2015-03-09 11:49:46 +0800320.pm_mode:
321 .word 0
Andrew Victoreaad2db2008-09-21 21:35:18 +0100322.saved_mckr:
323 .word 0
Andrew Victoreaad2db2008-09-21 21:35:18 +0100324.saved_pllar:
325 .word 0
Andrew Victoreaad2db2008-09-21 21:35:18 +0100326.saved_sam9_lpr:
327 .word 0
Nicolas Ferre7dca3342010-06-21 14:59:27 +0100328.saved_sam9_lpr1:
329 .word 0
Peter Rosin02f513a2015-02-05 14:02:09 +0800330.saved_sam9_mdr:
331 .word 0
Peter Rosin02f513a2015-02-05 14:02:09 +0800332.saved_sam9_mdr1:
333 .word 0
334
Wenyou Yang5726a8b2015-03-09 11:51:09 +0800335ENTRY(at91_pm_suspend_in_sram_sz)
336 .word .-at91_pm_suspend_in_sram