Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 14 | |
| 15 | #include <linux/linkage.h> |
Boris BREZILLON | 2edb90a | 2013-10-11 09:37:45 +0200 | [diff] [blame] | 16 | #include <linux/clk/at91_pmc.h> |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 17 | #include <mach/hardware.h> |
Jean-Christophe PLAGNIOL-VILLARD | f363c40 | 2012-02-13 12:58:53 +0800 | [diff] [blame] | 18 | #include <mach/at91_ramc.h> |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 19 | |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 20 | /* |
| 21 | * When SLOWDOWN_MASTER_CLOCK is defined we will also slow down the Master |
| 22 | * clock during suspend by adjusting its prescalar and divisor. |
| 23 | * NOTE: This hasn't been shown to be stable on SAM9s; and on the RM9200 there |
| 24 | * are errata regarding adjusting the prescalar and divisor. |
| 25 | */ |
| 26 | #undef SLOWDOWN_MASTER_CLOCK |
| 27 | |
Jean-Christophe PLAGNIOL-VILLARD | 8ff12ad3 | 2012-02-22 17:50:54 +0100 | [diff] [blame] | 28 | pmc .req r0 |
| 29 | sdramc .req r1 |
| 30 | ramc1 .req r2 |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 31 | memctrl .req r3 |
| 32 | tmp1 .req r4 |
| 33 | tmp2 .req r5 |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Wait until master clock is ready (after switching master clock source) |
| 37 | */ |
| 38 | .macro wait_mckrdy |
Sylvain Rochet | ad4a38d | 2015-02-05 14:00:37 +0800 | [diff] [blame] | 39 | 1: ldr tmp1, [pmc, #AT91_PMC_SR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 40 | tst tmp1, #AT91_PMC_MCKRDY |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 41 | beq 1b |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 42 | .endm |
| 43 | |
| 44 | /* |
| 45 | * Wait until master oscillator has stabilized. |
| 46 | */ |
| 47 | .macro wait_moscrdy |
Sylvain Rochet | ad4a38d | 2015-02-05 14:00:37 +0800 | [diff] [blame] | 48 | 1: ldr tmp1, [pmc, #AT91_PMC_SR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 49 | tst tmp1, #AT91_PMC_MOSCS |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 50 | beq 1b |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 51 | .endm |
| 52 | |
| 53 | /* |
| 54 | * Wait until PLLA has locked. |
| 55 | */ |
| 56 | .macro wait_pllalock |
Sylvain Rochet | ad4a38d | 2015-02-05 14:00:37 +0800 | [diff] [blame] | 57 | 1: ldr tmp1, [pmc, #AT91_PMC_SR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 58 | tst tmp1, #AT91_PMC_LOCKA |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 59 | beq 1b |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 60 | .endm |
| 61 | |
| 62 | /* |
| 63 | * Wait until PLLB has locked. |
| 64 | */ |
| 65 | .macro wait_pllblock |
Sylvain Rochet | ad4a38d | 2015-02-05 14:00:37 +0800 | [diff] [blame] | 66 | 1: ldr tmp1, [pmc, #AT91_PMC_SR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 67 | tst tmp1, #AT91_PMC_LOCKB |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 68 | beq 1b |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 69 | .endm |
| 70 | |
| 71 | .text |
| 72 | |
Wenyou Yang | e7b848d | 2015-03-11 10:08:12 +0800 | [diff] [blame^] | 73 | .arm |
| 74 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 75 | /* void at91_slow_clock(void __iomem *pmc, void __iomem *sdramc, |
| 76 | * void __iomem *ramc1, int memctrl) |
| 77 | */ |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 78 | ENTRY(at91_slow_clock) |
| 79 | /* Save registers on stack */ |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 80 | stmfd sp!, {r4 - r12, lr} |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Register usage: |
Jean-Christophe PLAGNIOL-VILLARD | 8ff12ad3 | 2012-02-22 17:50:54 +0100 | [diff] [blame] | 84 | * R0 = Base address of AT91_PMC |
| 85 | * R1 = Base address of RAM Controller (SDRAM, DDRSDR, or AT91_SYS) |
| 86 | * R2 = Base address of second RAM Controller or 0 if not present |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 87 | * R3 = Memory controller |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 88 | * R4 = temporary register |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 89 | * R5 = temporary register |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 90 | */ |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 91 | |
| 92 | /* Drain write buffer */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 93 | mov tmp1, #0 |
| 94 | mcr p15, 0, tmp1, c7, c10, 4 |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 95 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 96 | cmp memctrl, #AT91_MEMCTRL_MC |
| 97 | bne ddr_sr_enable |
| 98 | |
| 99 | /* |
| 100 | * at91rm9200 Memory controller |
| 101 | */ |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 102 | /* Put SDRAM in self-refresh mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 103 | mov tmp1, #1 |
Jean-Christophe PLAGNIOL-VILLARD | 1a269ad | 2011-11-16 02:58:31 +0800 | [diff] [blame] | 104 | str tmp1, [sdramc, #AT91RM9200_SDRAMC_SRR] |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 105 | b sdr_sr_done |
| 106 | |
| 107 | /* |
| 108 | * DDRSDR Memory controller |
| 109 | */ |
| 110 | ddr_sr_enable: |
| 111 | cmp memctrl, #AT91_MEMCTRL_DDRSDR |
| 112 | bne sdr_sr_enable |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 113 | |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 114 | /* LPDDR1 --> force DDR2 mode during self-refresh */ |
| 115 | ldr tmp1, [sdramc, #AT91_DDRSDRC_MDR] |
| 116 | str tmp1, .saved_sam9_mdr |
| 117 | bic tmp1, tmp1, #~AT91_DDRSDRC_MD |
| 118 | cmp tmp1, #AT91_DDRSDRC_MD_LOW_POWER_DDR |
| 119 | ldreq tmp1, [sdramc, #AT91_DDRSDRC_MDR] |
| 120 | biceq tmp1, tmp1, #AT91_DDRSDRC_MD |
| 121 | orreq tmp1, tmp1, #AT91_DDRSDRC_MD_DDR2 |
| 122 | streq tmp1, [sdramc, #AT91_DDRSDRC_MDR] |
| 123 | |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 124 | /* prepare for DDRAM self-refresh mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 125 | ldr tmp1, [sdramc, #AT91_DDRSDRC_LPR] |
| 126 | str tmp1, .saved_sam9_lpr |
| 127 | bic tmp1, #AT91_DDRSDRC_LPCB |
| 128 | orr tmp1, #AT91_DDRSDRC_LPCB_SELF_REFRESH |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 129 | |
| 130 | /* figure out if we use the second ram controller */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 131 | cmp ramc1, #0 |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 132 | beq ddr_no_2nd_ctrl |
| 133 | |
| 134 | ldr tmp2, [ramc1, #AT91_DDRSDRC_MDR] |
| 135 | str tmp2, .saved_sam9_mdr1 |
| 136 | bic tmp2, tmp2, #~AT91_DDRSDRC_MD |
| 137 | cmp tmp2, #AT91_DDRSDRC_MD_LOW_POWER_DDR |
| 138 | ldreq tmp2, [ramc1, #AT91_DDRSDRC_MDR] |
| 139 | biceq tmp2, tmp2, #AT91_DDRSDRC_MD |
| 140 | orreq tmp2, tmp2, #AT91_DDRSDRC_MD_DDR2 |
| 141 | streq tmp2, [ramc1, #AT91_DDRSDRC_MDR] |
| 142 | |
| 143 | ldr tmp2, [ramc1, #AT91_DDRSDRC_LPR] |
| 144 | str tmp2, .saved_sam9_lpr1 |
| 145 | bic tmp2, #AT91_DDRSDRC_LPCB |
| 146 | orr tmp2, #AT91_DDRSDRC_LPCB_SELF_REFRESH |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 147 | |
| 148 | /* Enable DDRAM self-refresh mode */ |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 149 | str tmp2, [ramc1, #AT91_DDRSDRC_LPR] |
| 150 | ddr_no_2nd_ctrl: |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 151 | str tmp1, [sdramc, #AT91_DDRSDRC_LPR] |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 152 | |
| 153 | b sdr_sr_done |
| 154 | |
| 155 | /* |
| 156 | * SDRAMC Memory controller |
| 157 | */ |
| 158 | sdr_sr_enable: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 159 | /* Enable SDRAM self-refresh mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 160 | ldr tmp1, [sdramc, #AT91_SDRAMC_LPR] |
| 161 | str tmp1, .saved_sam9_lpr |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 162 | |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 163 | bic tmp1, #AT91_SDRAMC_LPCB |
| 164 | orr tmp1, #AT91_SDRAMC_LPCB_SELF_REFRESH |
| 165 | str tmp1, [sdramc, #AT91_SDRAMC_LPR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 166 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 167 | sdr_sr_done: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 168 | /* Save Master clock setting */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 169 | ldr tmp1, [pmc, #AT91_PMC_MCKR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 170 | str tmp1, .saved_mckr |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Set the Master clock source to slow clock |
| 174 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 175 | bic tmp1, tmp1, #AT91_PMC_CSS |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 176 | str tmp1, [pmc, #AT91_PMC_MCKR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 177 | |
| 178 | wait_mckrdy |
| 179 | |
| 180 | #ifdef SLOWDOWN_MASTER_CLOCK |
| 181 | /* |
| 182 | * Set the Master Clock PRES and MDIV fields. |
| 183 | * |
| 184 | * See AT91RM9200 errata #27 and #28 for details. |
| 185 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 186 | mov tmp1, #0 |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 187 | str tmp1, [pmc, #AT91_PMC_MCKR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 188 | |
| 189 | wait_mckrdy |
| 190 | #endif |
| 191 | |
| 192 | /* Save PLLA setting and disable it */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 193 | ldr tmp1, [pmc, #AT91_CKGR_PLLAR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 194 | str tmp1, .saved_pllar |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 195 | |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 196 | mov tmp1, #AT91_PMC_PLLCOUNT |
| 197 | orr tmp1, tmp1, #(1 << 29) /* bit 29 always set */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 198 | str tmp1, [pmc, #AT91_CKGR_PLLAR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 199 | |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 200 | /* Save PLLB setting and disable it */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 201 | ldr tmp1, [pmc, #AT91_CKGR_PLLBR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 202 | str tmp1, .saved_pllbr |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 203 | |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 204 | mov tmp1, #AT91_PMC_PLLCOUNT |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 205 | str tmp1, [pmc, #AT91_CKGR_PLLBR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 206 | |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 207 | /* Turn off the main oscillator */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 208 | ldr tmp1, [pmc, #AT91_CKGR_MOR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 209 | bic tmp1, tmp1, #AT91_PMC_MOSCEN |
Patrice Vilchez | 5957457 | 2015-02-12 10:52:13 +0800 | [diff] [blame] | 210 | orr tmp1, tmp1, #AT91_PMC_KEY |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 211 | str tmp1, [pmc, #AT91_CKGR_MOR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 212 | |
| 213 | /* Wait for interrupt */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 214 | mcr p15, 0, tmp1, c7, c0, 4 |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 215 | |
| 216 | /* Turn on the main oscillator */ |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 217 | ldr tmp1, [pmc, #AT91_CKGR_MOR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 218 | orr tmp1, tmp1, #AT91_PMC_MOSCEN |
Patrice Vilchez | 5957457 | 2015-02-12 10:52:13 +0800 | [diff] [blame] | 219 | orr tmp1, tmp1, #AT91_PMC_KEY |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 220 | str tmp1, [pmc, #AT91_CKGR_MOR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 221 | |
| 222 | wait_moscrdy |
| 223 | |
| 224 | /* Restore PLLB setting */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 225 | ldr tmp1, .saved_pllbr |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 226 | str tmp1, [pmc, #AT91_CKGR_PLLBR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 227 | |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 228 | tst tmp1, #(AT91_PMC_MUL & 0xff0000) |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 229 | bne 1f |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 230 | tst tmp1, #(AT91_PMC_MUL & ~0xff0000) |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 231 | beq 2f |
| 232 | 1: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 233 | wait_pllblock |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 234 | 2: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 235 | |
| 236 | /* Restore PLLA setting */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 237 | ldr tmp1, .saved_pllar |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 238 | str tmp1, [pmc, #AT91_CKGR_PLLAR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 239 | |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 240 | tst tmp1, #(AT91_PMC_MUL & 0xff0000) |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 241 | bne 3f |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 242 | tst tmp1, #(AT91_PMC_MUL & ~0xff0000) |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 243 | beq 4f |
| 244 | 3: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 245 | wait_pllalock |
Anders Larsen | 9823f1a | 2010-04-08 11:48:16 +0100 | [diff] [blame] | 246 | 4: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 247 | |
| 248 | #ifdef SLOWDOWN_MASTER_CLOCK |
| 249 | /* |
| 250 | * First set PRES if it was not 0, |
| 251 | * than set CSS and MDIV fields. |
| 252 | * |
| 253 | * See AT91RM9200 errata #27 and #28 for details. |
| 254 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 255 | ldr tmp1, .saved_mckr |
| 256 | tst tmp1, #AT91_PMC_PRES |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 257 | beq 2f |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 258 | and tmp1, tmp1, #AT91_PMC_PRES |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 259 | str tmp1, [pmc, #AT91_PMC_MCKR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 260 | |
| 261 | wait_mckrdy |
| 262 | #endif |
| 263 | |
| 264 | /* |
| 265 | * Restore master clock setting |
| 266 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 267 | 2: ldr tmp1, .saved_mckr |
Jean-Christophe PLAGNIOL-VILLARD | b551495 | 2011-11-25 09:59:46 +0800 | [diff] [blame] | 268 | str tmp1, [pmc, #AT91_PMC_MCKR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 269 | |
| 270 | wait_mckrdy |
| 271 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 272 | /* |
| 273 | * at91rm9200 Memory controller |
| 274 | * Do nothing - self-refresh is automatically disabled. |
| 275 | */ |
| 276 | cmp memctrl, #AT91_MEMCTRL_MC |
| 277 | beq ram_restored |
| 278 | |
| 279 | /* |
| 280 | * DDRSDR Memory controller |
| 281 | */ |
| 282 | cmp memctrl, #AT91_MEMCTRL_DDRSDR |
| 283 | bne sdr_en_restore |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 284 | /* Restore MDR in case of LPDDR1 */ |
| 285 | ldr tmp1, .saved_sam9_mdr |
| 286 | str tmp1, [sdramc, #AT91_DDRSDRC_MDR] |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 287 | /* Restore LPR on AT91 with DDRAM */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 288 | ldr tmp1, .saved_sam9_lpr |
| 289 | str tmp1, [sdramc, #AT91_DDRSDRC_LPR] |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 290 | |
| 291 | /* if we use the second ram controller */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 292 | cmp ramc1, #0 |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 293 | ldrne tmp2, .saved_sam9_mdr1 |
| 294 | strne tmp2, [ramc1, #AT91_DDRSDRC_MDR] |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 295 | ldrne tmp2, .saved_sam9_lpr1 |
| 296 | strne tmp2, [ramc1, #AT91_DDRSDRC_LPR] |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 297 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 298 | b ram_restored |
| 299 | |
| 300 | /* |
| 301 | * SDRAMC Memory controller |
| 302 | */ |
| 303 | sdr_en_restore: |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 304 | /* Restore LPR on AT91 with SDRAM */ |
Jean-Christophe PLAGNIOL-VILLARD | 0dcfed1 | 2012-02-22 17:50:53 +0100 | [diff] [blame] | 305 | ldr tmp1, .saved_sam9_lpr |
| 306 | str tmp1, [sdramc, #AT91_SDRAMC_LPR] |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 307 | |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 308 | ram_restored: |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 309 | /* Restore registers, and return */ |
Jean-Christophe PLAGNIOL-VILLARD | fb7e197 | 2012-02-22 17:50:55 +0100 | [diff] [blame] | 310 | ldmfd sp!, {r4 - r12, pc} |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 311 | |
| 312 | |
| 313 | .saved_mckr: |
| 314 | .word 0 |
| 315 | |
| 316 | .saved_pllar: |
| 317 | .word 0 |
| 318 | |
| 319 | .saved_pllbr: |
| 320 | .word 0 |
| 321 | |
| 322 | .saved_sam9_lpr: |
| 323 | .word 0 |
| 324 | |
Nicolas Ferre | 7dca334 | 2010-06-21 14:59:27 +0100 | [diff] [blame] | 325 | .saved_sam9_lpr1: |
| 326 | .word 0 |
| 327 | |
Peter Rosin | 02f513a | 2015-02-05 14:02:09 +0800 | [diff] [blame] | 328 | .saved_sam9_mdr: |
| 329 | .word 0 |
| 330 | |
| 331 | .saved_sam9_mdr1: |
| 332 | .word 0 |
| 333 | |
Andrew Victor | eaad2db | 2008-09-21 21:35:18 +0100 | [diff] [blame] | 334 | ENTRY(at91_slow_clock_sz) |
| 335 | .word .-at91_slow_clock |