wdenk | 11a72d9 | 2002-10-27 22:25:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Alex Zuepke <azu@sysgo.de> |
| 9 | * |
| 10 | * See file CREDITS for list of people who contributed to this |
| 11 | * project. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License as |
| 15 | * published by the Free Software Foundation; either version 2 of |
| 16 | * the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 26 | * MA 02111-1307 USA |
| 27 | */ |
| 28 | |
Marek Vasut | 3ba8bf7 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 29 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 677e62f | 2009-04-05 13:02:43 +0200 | [diff] [blame] | 30 | #include <asm/system.h> |
Marek Vasut | 3ba8bf7 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 31 | #include <command.h> |
| 32 | #include <common.h> |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 33 | #include <asm/arch/pxa-regs.h> |
wdenk | 11a72d9 | 2002-10-27 22:25:25 +0000 | [diff] [blame] | 34 | |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 35 | /* Flush I/D-cache */ |
| 36 | static void cache_flush(void) |
wdenk | 11a72d9 | 2002-10-27 22:25:25 +0000 | [diff] [blame] | 37 | { |
Jean-Christophe PLAGNIOL-VILLARD | b3acb6c | 2009-04-05 13:06:31 +0200 | [diff] [blame] | 38 | unsigned long i = 0; |
wdenk | 11a72d9 | 2002-10-27 22:25:25 +0000 | [diff] [blame] | 39 | |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 40 | asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i)); |
wdenk | 11a72d9 | 2002-10-27 22:25:25 +0000 | [diff] [blame] | 41 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 42 | |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 43 | int cleanup_before_linux(void) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 44 | { |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 45 | /* |
| 46 | * This function is called just before we call Linux. It prepares |
| 47 | * the processor for Linux by just disabling everything that can |
| 48 | * disturb booting Linux. |
| 49 | */ |
Marek Vasut | 3ba8bf7 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 50 | |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 51 | disable_interrupts(); |
| 52 | icache_disable(); |
| 53 | dcache_disable(); |
| 54 | cache_flush(); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 55 | |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 56 | return 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 57 | } |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 58 | |
| 59 | void pxa_wait_ticks(int ticks) |
| 60 | { |
| 61 | writel(0, OSCR); |
| 62 | while (readl(OSCR) < ticks) |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 63 | asm volatile("" : : : "memory"); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | inline void writelrb(uint32_t val, uint32_t addr) |
| 67 | { |
| 68 | writel(val, addr); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 69 | asm volatile("" : : : "memory"); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 70 | readl(addr); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 71 | asm volatile("" : : : "memory"); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void pxa_dram_init(void) |
| 75 | { |
| 76 | uint32_t tmp; |
| 77 | int i; |
| 78 | /* |
| 79 | * 1) Initialize Asynchronous static memory controller |
| 80 | */ |
| 81 | |
| 82 | writelrb(CONFIG_SYS_MSC0_VAL, MSC0); |
| 83 | writelrb(CONFIG_SYS_MSC1_VAL, MSC1); |
| 84 | writelrb(CONFIG_SYS_MSC2_VAL, MSC2); |
| 85 | /* |
| 86 | * 2) Initialize Card Interface |
| 87 | */ |
| 88 | |
| 89 | /* MECR: Memory Expansion Card Register */ |
| 90 | writelrb(CONFIG_SYS_MECR_VAL, MECR); |
| 91 | /* MCMEM0: Card Interface slot 0 timing */ |
| 92 | writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0); |
| 93 | /* MCMEM1: Card Interface slot 1 timing */ |
| 94 | writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1); |
| 95 | /* MCATT0: Card Interface Attribute Space Timing, slot 0 */ |
| 96 | writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0); |
| 97 | /* MCATT1: Card Interface Attribute Space Timing, slot 1 */ |
| 98 | writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1); |
| 99 | /* MCIO0: Card Interface I/O Space Timing, slot 0 */ |
| 100 | writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0); |
| 101 | /* MCIO1: Card Interface I/O Space Timing, slot 1 */ |
| 102 | writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1); |
| 103 | |
| 104 | /* |
| 105 | * 3) Configure Fly-By DMA register |
| 106 | */ |
| 107 | |
| 108 | writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG); |
| 109 | |
| 110 | /* |
| 111 | * 4) Initialize Timing for Sync Memory (SDCLK0) |
| 112 | */ |
| 113 | |
| 114 | /* |
| 115 | * Before accessing MDREFR we need a valid DRI field, so we set |
| 116 | * this to power on defaults + DRI field. |
| 117 | */ |
| 118 | |
| 119 | /* Read current MDREFR config and zero out DRI */ |
| 120 | tmp = readl(MDREFR) & ~0xfff; |
| 121 | /* Add user-specified DRI */ |
| 122 | tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff; |
| 123 | /* Configure important bits */ |
| 124 | tmp |= MDREFR_K0RUN | MDREFR_SLFRSH; |
| 125 | tmp &= ~(MDREFR_APD | MDREFR_E1PIN); |
| 126 | |
| 127 | /* Write MDREFR back */ |
| 128 | writelrb(tmp, MDREFR); |
| 129 | |
| 130 | /* |
| 131 | * 5) Initialize Synchronous Static Memory (Flash/Peripherals) |
| 132 | */ |
| 133 | |
| 134 | /* Initialize SXCNFG register. Assert the enable bits. |
| 135 | * |
| 136 | * Write SXMRS to cause an MRS command to all enabled banks of |
| 137 | * synchronous static memory. Note that SXLCR need not be written |
| 138 | * at this time. |
| 139 | */ |
| 140 | writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG); |
| 141 | |
| 142 | /* |
| 143 | * 6) Initialize SDRAM |
| 144 | */ |
| 145 | |
| 146 | writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR); |
| 147 | writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR); |
| 148 | |
| 149 | /* |
| 150 | * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure |
| 151 | * but not enable each SDRAM partition pair. |
| 152 | */ |
| 153 | |
| 154 | writelrb(CONFIG_SYS_MDCNFG_VAL & |
| 155 | ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG); |
| 156 | /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */ |
| 157 | pxa_wait_ticks(0x300); |
| 158 | |
| 159 | /* |
| 160 | * 8) Trigger a number (usually 8) refresh cycles by attempting |
| 161 | * non-burst read or write accesses to disabled SDRAM, as commonly |
| 162 | * specified in the power up sequence documented in SDRAM data |
| 163 | * sheets. The address(es) used for this purpose must not be |
| 164 | * cacheable. |
| 165 | */ |
| 166 | for (i = 9; i >= 0; i--) { |
| 167 | writel(i, 0xa0000000); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 168 | asm volatile("" : : : "memory"); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 169 | } |
| 170 | /* |
| 171 | * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1). |
| 172 | */ |
| 173 | |
| 174 | tmp = CONFIG_SYS_MDCNFG_VAL & |
| 175 | (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3); |
| 176 | tmp |= readl(MDCNFG); |
| 177 | writelrb(tmp, MDCNFG); |
| 178 | |
| 179 | /* |
| 180 | * 10) Write MDMRS. |
| 181 | */ |
| 182 | |
| 183 | writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS); |
| 184 | |
| 185 | /* |
| 186 | * 11) Enable APD |
| 187 | */ |
| 188 | |
| 189 | if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) { |
| 190 | tmp = readl(MDREFR); |
| 191 | tmp |= MDREFR_APD; |
| 192 | writelrb(tmp, MDREFR); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void pxa_gpio_setup(void) |
| 197 | { |
| 198 | writel(CONFIG_SYS_GPSR0_VAL, GPSR0); |
| 199 | writel(CONFIG_SYS_GPSR1_VAL, GPSR1); |
| 200 | writel(CONFIG_SYS_GPSR2_VAL, GPSR2); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 201 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 202 | writel(CONFIG_SYS_GPSR3_VAL, GPSR3); |
| 203 | #endif |
| 204 | |
| 205 | writel(CONFIG_SYS_GPCR0_VAL, GPCR0); |
| 206 | writel(CONFIG_SYS_GPCR1_VAL, GPCR1); |
| 207 | writel(CONFIG_SYS_GPCR2_VAL, GPCR2); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 208 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 209 | writel(CONFIG_SYS_GPCR3_VAL, GPCR3); |
| 210 | #endif |
| 211 | |
| 212 | writel(CONFIG_SYS_GPDR0_VAL, GPDR0); |
| 213 | writel(CONFIG_SYS_GPDR1_VAL, GPDR1); |
| 214 | writel(CONFIG_SYS_GPDR2_VAL, GPDR2); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 215 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 216 | writel(CONFIG_SYS_GPDR3_VAL, GPDR3); |
| 217 | #endif |
| 218 | |
| 219 | writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L); |
| 220 | writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U); |
| 221 | writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L); |
| 222 | writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U); |
| 223 | writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L); |
| 224 | writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 225 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 226 | writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L); |
| 227 | writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U); |
| 228 | #endif |
| 229 | |
| 230 | writel(CONFIG_SYS_PSSR_VAL, PSSR); |
| 231 | } |
| 232 | |
| 233 | void pxa_interrupt_setup(void) |
| 234 | { |
| 235 | writel(0, ICLR); |
| 236 | writel(0, ICMR); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 237 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 238 | writel(0, ICLR2); |
| 239 | writel(0, ICMR2); |
| 240 | #endif |
| 241 | } |
| 242 | |
| 243 | void pxa_clock_setup(void) |
| 244 | { |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 245 | writel(CONFIG_SYS_CKEN, CKEN); |
| 246 | writel(CONFIG_SYS_CCCR, CCCR); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 247 | asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(2)); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 248 | |
| 249 | /* enable the 32Khz oscillator for RTC and PowerManager */ |
| 250 | writel(OSCC_OON, OSCC); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 251 | while (!(readl(OSCC) & OSCC_OOK)) |
| 252 | asm volatile("" : : : "memory"); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void pxa_wakeup(void) |
| 256 | { |
| 257 | uint32_t rcsr; |
| 258 | |
| 259 | rcsr = readl(RCSR); |
| 260 | writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR); |
| 261 | |
| 262 | /* Wakeup */ |
| 263 | if (rcsr & RCSR_SMR) { |
| 264 | writel(PSSR_PH, PSSR); |
| 265 | pxa_dram_init(); |
| 266 | icache_disable(); |
| 267 | dcache_disable(); |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 268 | asm volatile("mov pc, %0" : : "r"(readl(PSPR))); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
| 272 | int arch_cpu_init(void) |
| 273 | { |
| 274 | pxa_gpio_setup(); |
Marek Vasut | 2cad92f | 2010-09-28 15:44:10 +0200 | [diff] [blame] | 275 | pxa_wakeup(); |
| 276 | pxa_interrupt_setup(); |
| 277 | pxa_clock_setup(); |
| 278 | return 0; |
| 279 | } |
Lei Wen | 3df619e | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 280 | |
| 281 | void i2c_clk_enable(void) |
| 282 | { |
Marek Vasut | d10237d | 2011-11-26 07:32:24 +0100 | [diff] [blame] | 283 | /* Set the global I2C clock on */ |
Lei Wen | 3df619e | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 284 | writel(readl(CKEN) | CKEN14_I2C, CKEN); |
Lei Wen | 3df619e | 2011-04-13 23:48:31 +0530 | [diff] [blame] | 285 | } |
Marek Vasut | 20f7b1b | 2011-10-31 14:12:39 +0100 | [diff] [blame] | 286 | |
| 287 | void reset_cpu(ulong ignored) __attribute__((noreturn)); |
| 288 | |
| 289 | void reset_cpu(ulong ignored) |
| 290 | { |
| 291 | uint32_t tmp; |
| 292 | |
| 293 | setbits_le32(OWER, OWER_WME); |
| 294 | |
| 295 | tmp = readl(OSCR); |
| 296 | tmp += 0x1000; |
| 297 | writel(tmp, OSMR3); |
| 298 | |
| 299 | for (;;) |
| 300 | ; |
| 301 | } |