wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2007 |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <watchdog.h> |
Stefan Roese | 247e9d7 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 10 | #include <asm/ppc4xx-emac.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 11 | #include <asm/processor.h> |
Stefan Roese | de21eab | 2010-09-16 14:30:37 +0200 | [diff] [blame] | 12 | #include <asm/ppc4xx-gpio.h> |
Stefan Roese | 247e9d7 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 13 | #include <asm/ppc4xx.h> |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 14 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 15 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | #endif |
| 18 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 19 | #ifndef CONFIG_SYS_PLL_RECONFIG |
| 20 | #define CONFIG_SYS_PLL_RECONFIG 0 |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 21 | #endif |
| 22 | |
Stefan Roese | 5f52bd1 | 2010-05-19 11:13:24 +0200 | [diff] [blame] | 23 | #if defined(CONFIG_440EPX) || \ |
| 24 | defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 25 | static void reset_with_rli(void) |
| 26 | { |
| 27 | u32 reg; |
| 28 | |
| 29 | /* |
| 30 | * Set reload inhibit so configuration will persist across |
| 31 | * processor resets |
| 32 | */ |
| 33 | mfcpr(CPR0_ICFG, reg); |
| 34 | reg |= CPR0_ICFG_RLI_MASK; |
| 35 | mtcpr(CPR0_ICFG, reg); |
| 36 | |
| 37 | /* Reset processor if configuration changed */ |
| 38 | __asm__ __volatile__ ("sync; isync"); |
| 39 | mtspr(SPRN_DBCR0, 0x20000000); |
| 40 | } |
| 41 | #endif |
| 42 | |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 43 | void reconfigure_pll(u32 new_cpu_freq) |
| 44 | { |
| 45 | #if defined(CONFIG_440EPX) |
| 46 | int reset_needed = 0; |
| 47 | u32 reg, temp; |
| 48 | u32 prbdv0, target_prbdv0, /* CLK_PRIMBD */ |
| 49 | fwdva, target_fwdva, fwdvb, target_fwdvb, /* CLK_PLLD */ |
| 50 | fbdv, target_fbdv, lfbdv, target_lfbdv, |
| 51 | perdv0, target_perdv0, /* CLK_PERD */ |
| 52 | spcid0, target_spcid0; /* CLK_SPCID */ |
| 53 | |
| 54 | /* Reconfigure clocks if necessary. |
| 55 | * See PPC440EPx User's Manual, sections 8.2 and 14 */ |
| 56 | if (new_cpu_freq == 667) { |
| 57 | target_prbdv0 = 2; |
| 58 | target_fwdva = 2; |
| 59 | target_fwdvb = 4; |
| 60 | target_fbdv = 20; |
| 61 | target_lfbdv = 1; |
| 62 | target_perdv0 = 4; |
| 63 | target_spcid0 = 4; |
| 64 | |
Niklaus Giger | 728bd0a | 2009-10-04 20:04:20 +0200 | [diff] [blame] | 65 | mfcpr(CPR0_PRIMBD0, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 66 | temp = (reg & PRBDV_MASK) >> 24; |
| 67 | prbdv0 = temp ? temp : 8; |
| 68 | if (prbdv0 != target_prbdv0) { |
| 69 | reg &= ~PRBDV_MASK; |
| 70 | reg |= ((target_prbdv0 == 8 ? 0 : target_prbdv0) << 24); |
Niklaus Giger | 728bd0a | 2009-10-04 20:04:20 +0200 | [diff] [blame] | 71 | mtcpr(CPR0_PRIMBD0, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 72 | reset_needed = 1; |
| 73 | } |
| 74 | |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 75 | mfcpr(CPR0_PLLD, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 76 | |
| 77 | temp = (reg & PLLD_FWDVA_MASK) >> 16; |
| 78 | fwdva = temp ? temp : 16; |
| 79 | |
| 80 | temp = (reg & PLLD_FWDVB_MASK) >> 8; |
| 81 | fwdvb = temp ? temp : 8; |
| 82 | |
| 83 | temp = (reg & PLLD_FBDV_MASK) >> 24; |
| 84 | fbdv = temp ? temp : 32; |
| 85 | |
| 86 | temp = (reg & PLLD_LFBDV_MASK); |
| 87 | lfbdv = temp ? temp : 64; |
| 88 | |
| 89 | if (fwdva != target_fwdva || fbdv != target_fbdv || lfbdv != target_lfbdv) { |
| 90 | reg &= ~(PLLD_FWDVA_MASK | PLLD_FWDVB_MASK | |
| 91 | PLLD_FBDV_MASK | PLLD_LFBDV_MASK); |
| 92 | reg |= ((target_fwdva == 16 ? 0 : target_fwdva) << 16) | |
| 93 | ((target_fwdvb == 8 ? 0 : target_fwdvb) << 8) | |
| 94 | ((target_fbdv == 32 ? 0 : target_fbdv) << 24) | |
| 95 | (target_lfbdv == 64 ? 0 : target_lfbdv); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 96 | mtcpr(CPR0_PLLD, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 97 | reset_needed = 1; |
| 98 | } |
| 99 | |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 100 | mfcpr(CPR0_PERD, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 101 | perdv0 = (reg & CPR0_PERD_PERDV0_MASK) >> 24; |
| 102 | if (perdv0 != target_perdv0) { |
| 103 | reg &= ~CPR0_PERD_PERDV0_MASK; |
| 104 | reg |= (target_perdv0 << 24); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 105 | mtcpr(CPR0_PERD, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 106 | reset_needed = 1; |
| 107 | } |
| 108 | |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 109 | mfcpr(CPR0_SPCID, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 110 | temp = (reg & CPR0_SPCID_SPCIDV0_MASK) >> 24; |
| 111 | spcid0 = temp ? temp : 4; |
| 112 | if (spcid0 != target_spcid0) { |
| 113 | reg &= ~CPR0_SPCID_SPCIDV0_MASK; |
| 114 | reg |= ((target_spcid0 == 4 ? 0 : target_spcid0) << 24); |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 115 | mtcpr(CPR0_SPCID, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 116 | reset_needed = 1; |
| 117 | } |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* Get current value of FWDVA.*/ |
| 121 | mfcpr(CPR0_PLLD, reg); |
| 122 | temp = (reg & PLLD_FWDVA_MASK) >> 16; |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 123 | |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 124 | /* |
| 125 | * Check to see if FWDVA has been set to value of 1. if it has we must |
| 126 | * modify it. |
| 127 | */ |
| 128 | if (temp == 1) { |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 129 | /* |
| 130 | * Load register that contains current boot strapping option. |
| 131 | */ |
| 132 | mfcpr(CPR0_ICFG, reg); |
Stefan Roese | 0a9cc2f | 2010-08-26 17:14:51 +0200 | [diff] [blame] | 133 | /* |
| 134 | * Strapping option bits (ICS) are already in correct position, |
| 135 | * only masking needed. |
| 136 | */ |
| 137 | reg &= CPR0_ICFG_ICS_MASK; |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 138 | |
| 139 | if ((reg == BOOT_STRAP_OPTION_A) || (reg == BOOT_STRAP_OPTION_B) || |
| 140 | (reg == BOOT_STRAP_OPTION_D) || (reg == BOOT_STRAP_OPTION_E)) { |
Stefan Roese | 0a9cc2f | 2010-08-26 17:14:51 +0200 | [diff] [blame] | 141 | mfcpr(CPR0_PLLD, reg); |
| 142 | |
| 143 | /* Get current value of fbdv. */ |
| 144 | temp = (reg & PLLD_FBDV_MASK) >> 24; |
| 145 | fbdv = temp ? temp : 32; |
| 146 | |
| 147 | /* Get current value of lfbdv. */ |
| 148 | temp = (reg & PLLD_LFBDV_MASK); |
| 149 | lfbdv = temp ? temp : 64; |
| 150 | |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 151 | /* |
| 152 | * Get current value of FWDVA. Assign current FWDVA to |
| 153 | * new FWDVB. |
| 154 | */ |
| 155 | mfcpr(CPR0_PLLD, reg); |
| 156 | target_fwdvb = (reg & PLLD_FWDVA_MASK) >> 16; |
| 157 | fwdvb = target_fwdvb ? target_fwdvb : 8; |
Stefan Roese | 0a9cc2f | 2010-08-26 17:14:51 +0200 | [diff] [blame] | 158 | |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 159 | /* |
| 160 | * Get current value of FWDVB. Assign current FWDVB to |
| 161 | * new FWDVA. |
| 162 | */ |
| 163 | target_fwdva = (reg & PLLD_FWDVB_MASK) >> 8; |
| 164 | fwdva = target_fwdva ? target_fwdva : 16; |
Stefan Roese | 0a9cc2f | 2010-08-26 17:14:51 +0200 | [diff] [blame] | 165 | |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 166 | /* |
| 167 | * Update CPR0_PLLD with switched FWDVA and FWDVB. |
| 168 | */ |
| 169 | reg &= ~(PLLD_FWDVA_MASK | PLLD_FWDVB_MASK | |
| 170 | PLLD_FBDV_MASK | PLLD_LFBDV_MASK); |
| 171 | reg |= ((fwdva == 16 ? 0 : fwdva) << 16) | |
| 172 | ((fwdvb == 8 ? 0 : fwdvb) << 8) | |
| 173 | ((fbdv == 32 ? 0 : fbdv) << 24) | |
| 174 | (lfbdv == 64 ? 0 : lfbdv); |
| 175 | mtcpr(CPR0_PLLD, reg); |
Stefan Roese | 0a9cc2f | 2010-08-26 17:14:51 +0200 | [diff] [blame] | 176 | |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 177 | /* Acknowledge that a reset is required. */ |
| 178 | reset_needed = 1; |
| 179 | } |
| 180 | } |
| 181 | |
Stefan Roese | 5f52bd1 | 2010-05-19 11:13:24 +0200 | [diff] [blame] | 182 | /* Now reset the CPU if needed */ |
| 183 | if (reset_needed) |
| 184 | reset_with_rli(); |
| 185 | #endif |
| 186 | |
| 187 | #if defined(CONFIG_460EX) || defined(CONFIG_460GT) |
| 188 | u32 reg; |
| 189 | |
| 190 | /* |
| 191 | * See "9.2.1.1 Booting with Option E" in the 460EX/GT |
| 192 | * users manual |
| 193 | */ |
| 194 | mfcpr(CPR0_PLLC, reg); |
| 195 | if ((reg & (CPR0_PLLC_RST | CPR0_PLLC_ENG)) == CPR0_PLLC_RST) { |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 196 | /* |
Stefan Roese | 5f52bd1 | 2010-05-19 11:13:24 +0200 | [diff] [blame] | 197 | * Set engage bit |
Rupjyoti Sarmah | c9f731e | 2010-03-24 16:52:02 +0530 | [diff] [blame] | 198 | */ |
Stefan Roese | 5f52bd1 | 2010-05-19 11:13:24 +0200 | [diff] [blame] | 199 | reg = (reg & ~CPR0_PLLC_RST) | CPR0_PLLC_ENG; |
| 200 | mtcpr(CPR0_PLLC, reg); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 201 | |
Stefan Roese | 5f52bd1 | 2010-05-19 11:13:24 +0200 | [diff] [blame] | 202 | /* Now reset the CPU */ |
| 203 | reset_with_rli(); |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 204 | } |
| 205 | #endif |
| 206 | } |
| 207 | |
Steven A. Falco | 327ac78 | 2011-05-05 10:08:35 -0400 | [diff] [blame] | 208 | #ifdef CONFIG_SYS_4xx_CHIP_21_ERRATA |
| 209 | void |
| 210 | chip_21_errata(void) |
| 211 | { |
| 212 | /* |
| 213 | * See rev 1.09 of the 405EX/405EXr errata. CHIP_21 says that |
| 214 | * sometimes reading the PVR and/or SDR0_ECID results in incorrect |
| 215 | * values. Since the rev-D chip uses the SDR0_ECID bits to control |
| 216 | * internal features, that means the second PCIe or ethernet of an EX |
| 217 | * variant could fail to work. Also, security features of both EX and |
| 218 | * EXr might be incorrectly disabled. |
| 219 | * |
| 220 | * The suggested workaround is as follows (covering rev-C and rev-D): |
| 221 | * |
| 222 | * 1.Read the PVR and SDR0_ECID3. |
| 223 | * |
| 224 | * 2.If the PVR matches an expected Revision C PVR value AND if |
| 225 | * SDR0_ECID3[12:15] is different from PVR[28:31], then processor is |
| 226 | * Revision C: continue executing the initialization code (no reset |
| 227 | * required). else go to step 3. |
| 228 | * |
| 229 | * 3.If the PVR matches an expected Revision D PVR value AND if |
| 230 | * SDR0_ECID3[10:11] matches its expected value, then continue |
| 231 | * executing initialization code, no reset required. else write |
| 232 | * DBCR0[RST] = 0b11 to generate a SysReset. |
| 233 | */ |
| 234 | |
| 235 | u32 pvr; |
| 236 | u32 pvr_28_31; |
| 237 | u32 ecid3; |
| 238 | u32 ecid3_10_11; |
| 239 | u32 ecid3_12_15; |
| 240 | |
| 241 | /* Step 1: */ |
| 242 | pvr = get_pvr(); |
| 243 | mfsdr(SDR0_ECID3, ecid3); |
| 244 | |
| 245 | /* Step 2: */ |
| 246 | pvr_28_31 = pvr & 0xf; |
| 247 | ecid3_10_11 = (ecid3 >> 20) & 0x3; |
| 248 | ecid3_12_15 = (ecid3 >> 16) & 0xf; |
| 249 | if ((pvr == CONFIG_405EX_CHIP21_PVR_REV_C) && |
| 250 | (pvr_28_31 != ecid3_12_15)) { |
| 251 | /* No reset required. */ |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | /* Step 3: */ |
| 256 | if ((pvr == CONFIG_405EX_CHIP21_PVR_REV_D) && |
| 257 | (ecid3_10_11 == CONFIG_405EX_CHIP21_ECID3_REV_D)) { |
| 258 | /* No reset required. */ |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | /* Reset required. */ |
| 263 | __asm__ __volatile__ ("sync; isync"); |
| 264 | mtspr(SPRN_DBCR0, 0x30000000); |
| 265 | } |
| 266 | #endif |
| 267 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 268 | /* |
| 269 | * Breath some life into the CPU... |
| 270 | * |
Mike Nuss | 3073ecd | 2008-02-20 11:54:20 -0500 | [diff] [blame] | 271 | * Reconfigure PLL if necessary, |
| 272 | * set up the memory map, |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 273 | * initialize a bunch of registers |
| 274 | */ |
| 275 | void |
| 276 | cpu_init_f (void) |
| 277 | { |
Stefan Roese | 1abbbd0 | 2008-08-21 11:05:03 +0200 | [diff] [blame] | 278 | #if defined(CONFIG_WATCHDOG) || defined(CONFIG_440GX) || defined(CONFIG_460EX) |
Stefan Roese | 1b198df | 2008-06-28 14:56:17 +0200 | [diff] [blame] | 279 | u32 val; |
Wolfgang Denk | 8637071 | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 280 | #endif |
Stefan Roese | 51d6d5d | 2008-06-26 17:36:39 +0200 | [diff] [blame] | 281 | |
Steven A. Falco | 327ac78 | 2011-05-05 10:08:35 -0400 | [diff] [blame] | 282 | #ifdef CONFIG_SYS_4xx_CHIP_21_ERRATA |
| 283 | chip_21_errata(); |
| 284 | #endif |
| 285 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 286 | reconfigure_pll(CONFIG_SYS_PLL_RECONFIG); |
Wolfgang Denk | 8637071 | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 287 | |
Tirumala Marri | 95ac428 | 2010-09-28 14:15:14 -0700 | [diff] [blame] | 288 | #if (defined(CONFIG_405EP) || defined (CONFIG_405EX)) && \ |
| 289 | !defined(CONFIG_APM821XX) &&!defined(CONFIG_SYS_4xx_GPIO_TABLE) |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 290 | /* |
| 291 | * GPIO0 setup (select GPIO or alternate function) |
| 292 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 293 | #if defined(CONFIG_SYS_GPIO0_OR) |
| 294 | out32(GPIO0_OR, CONFIG_SYS_GPIO0_OR); /* set initial state of output pins */ |
Stefan Roese | 865b19e | 2006-10-12 19:43:29 +0200 | [diff] [blame] | 295 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 296 | #if defined(CONFIG_SYS_GPIO0_ODR) |
| 297 | out32(GPIO0_ODR, CONFIG_SYS_GPIO0_ODR); /* open-drain select */ |
Stefan Roese | 865b19e | 2006-10-12 19:43:29 +0200 | [diff] [blame] | 298 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 299 | out32(GPIO0_OSRH, CONFIG_SYS_GPIO0_OSRH); /* output select */ |
| 300 | out32(GPIO0_OSRL, CONFIG_SYS_GPIO0_OSRL); |
| 301 | out32(GPIO0_ISR1H, CONFIG_SYS_GPIO0_ISR1H); /* input select */ |
| 302 | out32(GPIO0_ISR1L, CONFIG_SYS_GPIO0_ISR1L); |
| 303 | out32(GPIO0_TSRH, CONFIG_SYS_GPIO0_TSRH); /* three-state select */ |
| 304 | out32(GPIO0_TSRL, CONFIG_SYS_GPIO0_TSRL); |
| 305 | #if defined(CONFIG_SYS_GPIO0_ISR2H) |
| 306 | out32(GPIO0_ISR2H, CONFIG_SYS_GPIO0_ISR2H); |
| 307 | out32(GPIO0_ISR2L, CONFIG_SYS_GPIO0_ISR2L); |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 308 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 309 | #if defined (CONFIG_SYS_GPIO0_TCR) |
| 310 | out32(GPIO0_TCR, CONFIG_SYS_GPIO0_TCR); /* enable output driver for outputs */ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 311 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 312 | #endif /* CONFIG_405EP ... && !CONFIG_SYS_4xx_GPIO_TABLE */ |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 313 | |
Stefan Roese | 3f47e7c | 2007-12-28 15:53:46 +0100 | [diff] [blame] | 314 | #if defined (CONFIG_405EP) |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 315 | /* |
| 316 | * Set EMAC noise filter bits |
| 317 | */ |
Stefan Roese | 8cb251a | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 318 | mtdcr(CPC0_EPCTL, CPC0_EPCTL_E0NFE | CPC0_EPCTL_E1NFE); |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 319 | #endif /* CONFIG_405EP */ |
| 320 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | #if defined(CONFIG_SYS_4xx_GPIO_TABLE) |
Stefan Roese | 80354e7 | 2007-03-24 15:57:09 +0100 | [diff] [blame] | 322 | gpio_set_chip_configuration(); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 323 | #endif /* CONFIG_SYS_4xx_GPIO_TABLE */ |
Stefan Roese | 9eba0c8 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 324 | |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 325 | /* |
| 326 | * External Bus Controller (EBC) Setup |
| 327 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 328 | #if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR)) |
Stefan Roese | 9eba0c8 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 329 | #if (defined(CONFIG_405GP) || defined(CONFIG_405CR) || \ |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 330 | defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 331 | defined(CONFIG_405EX) || defined(CONFIG_405)) |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 332 | /* |
| 333 | * Move the next instructions into icache, since these modify the flash |
| 334 | * we are running from! |
| 335 | */ |
| 336 | asm volatile(" bl 0f" ::: "lr"); |
| 337 | asm volatile("0: mflr 3" ::: "r3"); |
Wolfgang Denk | 70df7bc | 2007-06-22 23:59:00 +0200 | [diff] [blame] | 338 | asm volatile(" addi 4, 0, 14" ::: "r4"); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 339 | asm volatile(" mtctr 4" ::: "ctr"); |
| 340 | asm volatile("1: icbt 0, 3"); |
| 341 | asm volatile(" addi 3, 3, 32" ::: "r3"); |
| 342 | asm volatile(" bdnz 1b" ::: "ctr", "cr0"); |
| 343 | asm volatile(" addis 3, 0, 0x0" ::: "r3"); |
| 344 | asm volatile(" ori 3, 3, 0xA000" ::: "r3"); |
| 345 | asm volatile(" mtctr 3" ::: "ctr"); |
| 346 | asm volatile("2: bdnz 2b" ::: "ctr", "cr0"); |
Stefan Roese | 9eba0c8 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 347 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 348 | |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 349 | mtebc(PB0AP, CONFIG_SYS_EBC_PB0AP); |
| 350 | mtebc(PB0CR, CONFIG_SYS_EBC_PB0CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 351 | #endif |
| 352 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 353 | #if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 1)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 354 | mtebc(PB1AP, CONFIG_SYS_EBC_PB1AP); |
| 355 | mtebc(PB1CR, CONFIG_SYS_EBC_PB1CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 356 | #endif |
| 357 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 358 | #if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 2)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 359 | mtebc(PB2AP, CONFIG_SYS_EBC_PB2AP); |
| 360 | mtebc(PB2CR, CONFIG_SYS_EBC_PB2CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 361 | #endif |
| 362 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 363 | #if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 3)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 364 | mtebc(PB3AP, CONFIG_SYS_EBC_PB3AP); |
| 365 | mtebc(PB3CR, CONFIG_SYS_EBC_PB3CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 366 | #endif |
| 367 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 368 | #if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 4)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 369 | mtebc(PB4AP, CONFIG_SYS_EBC_PB4AP); |
| 370 | mtebc(PB4CR, CONFIG_SYS_EBC_PB4CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 371 | #endif |
| 372 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 373 | #if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 5)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 374 | mtebc(PB5AP, CONFIG_SYS_EBC_PB5AP); |
| 375 | mtebc(PB5CR, CONFIG_SYS_EBC_PB5CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 376 | #endif |
| 377 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 378 | #if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 6)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 379 | mtebc(PB6AP, CONFIG_SYS_EBC_PB6AP); |
| 380 | mtebc(PB6CR, CONFIG_SYS_EBC_PB6CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 381 | #endif |
| 382 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 383 | #if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 7)) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 384 | mtebc(PB7AP, CONFIG_SYS_EBC_PB7AP); |
| 385 | mtebc(PB7CR, CONFIG_SYS_EBC_PB7CR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 386 | #endif |
| 387 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 388 | #if defined (CONFIG_SYS_EBC_CFG) |
| 389 | mtebc(EBC0_CFG, CONFIG_SYS_EBC_CFG); |
Heiko Schocher | 3c58a99 | 2007-01-11 15:44:44 +0100 | [diff] [blame] | 390 | #endif |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 391 | |
Wolfgang Denk | 8637071 | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 392 | #if defined(CONFIG_WATCHDOG) |
Stefan Roese | 61138fe | 2010-10-04 11:09:40 +0200 | [diff] [blame] | 393 | val = mfspr(SPRN_TCR); |
Stefan Roese | b30f2a1 | 2005-08-08 12:42:22 +0200 | [diff] [blame] | 394 | #if defined(CONFIG_440EP) || defined(CONFIG_440GR) |
Stefan Roese | 326c971 | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 395 | val |= 0xb8000000; /* generate system reset after 1.34 seconds */ |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 396 | #elif defined(CONFIG_440EPX) |
| 397 | val |= 0xb0000000; /* generate system reset after 1.34 seconds */ |
Stefan Roese | 326c971 | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 398 | #else |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 399 | val |= 0xf0000000; /* generate system reset after 2.684 seconds */ |
Stefan Roese | 326c971 | 2005-08-01 16:41:48 +0200 | [diff] [blame] | 400 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 401 | #if defined(CONFIG_SYS_4xx_RESET_TYPE) |
Stefan Roese | 2a4a943 | 2006-11-27 14:12:17 +0100 | [diff] [blame] | 402 | val &= ~0x30000000; /* clear WRC bits */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 403 | val |= CONFIG_SYS_4xx_RESET_TYPE << 28; /* set board specific WRC type */ |
Stefan Roese | 2a4a943 | 2006-11-27 14:12:17 +0100 | [diff] [blame] | 404 | #endif |
Stefan Roese | 61138fe | 2010-10-04 11:09:40 +0200 | [diff] [blame] | 405 | mtspr(SPRN_TCR, val); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 406 | |
Stefan Roese | 61138fe | 2010-10-04 11:09:40 +0200 | [diff] [blame] | 407 | val = mfspr(SPRN_TSR); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 408 | val |= 0x80000000; /* enable watchdog timer */ |
Stefan Roese | 61138fe | 2010-10-04 11:09:40 +0200 | [diff] [blame] | 409 | mtspr(SPRN_TSR, val); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 410 | |
| 411 | reset_4xx_watchdog(); |
| 412 | #endif /* CONFIG_WATCHDOG */ |
Stefan Roese | 1b198df | 2008-06-28 14:56:17 +0200 | [diff] [blame] | 413 | |
Stefan Roese | 51d6d5d | 2008-06-26 17:36:39 +0200 | [diff] [blame] | 414 | #if defined(CONFIG_440GX) |
| 415 | /* Take the GX out of compatibility mode |
| 416 | * Travis Sawyer, 9 Mar 2004 |
| 417 | * NOTE: 440gx user manual inconsistency here |
| 418 | * Compatibility mode and Ethernet Clock select are not |
| 419 | * correct in the manual |
| 420 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 421 | mfsdr(SDR0_MFR, val); |
Stefan Roese | 51d6d5d | 2008-06-26 17:36:39 +0200 | [diff] [blame] | 422 | val &= ~0x10000000; |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 423 | mtsdr(SDR0_MFR,val); |
Stefan Roese | 51d6d5d | 2008-06-26 17:36:39 +0200 | [diff] [blame] | 424 | #endif /* CONFIG_440GX */ |
| 425 | |
Stefan Roese | 1b198df | 2008-06-28 14:56:17 +0200 | [diff] [blame] | 426 | #if defined(CONFIG_460EX) |
| 427 | /* |
| 428 | * Set SDR0_AHB_CFG[A2P_INCR4] (bit 24) and |
| 429 | * clear SDR0_AHB_CFG[A2P_PROT2] (bit 25) for a new 460EX errata |
| 430 | * regarding concurrent use of AHB USB OTG, USB 2.0 host and SATA |
| 431 | */ |
| 432 | mfsdr(SDR0_AHB_CFG, val); |
| 433 | val |= 0x80; |
| 434 | val &= ~0x40; |
| 435 | mtsdr(SDR0_AHB_CFG, val); |
| 436 | mfsdr(SDR0_USB2HOST_CFG, val); |
| 437 | val &= ~0xf00; |
| 438 | val |= 0x400; |
| 439 | mtsdr(SDR0_USB2HOST_CFG, val); |
| 440 | #endif /* CONFIG_460EX */ |
Prodyut Hazarika | 038f0d8 | 2008-08-20 09:38:51 -0700 | [diff] [blame] | 441 | |
Stefan Roese | 1abbbd0 | 2008-08-21 11:05:03 +0200 | [diff] [blame] | 442 | #if defined(CONFIG_405EX) || \ |
| 443 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Prodyut Hazarika | 038f0d8 | 2008-08-20 09:38:51 -0700 | [diff] [blame] | 444 | defined(CONFIG_460EX) || defined(CONFIG_460GT) || \ |
Tirumala Marri | 95ac428 | 2010-09-28 14:15:14 -0700 | [diff] [blame] | 445 | defined(CONFIG_460SX) || defined(CONFIG_APM821XX) |
Prodyut Hazarika | 038f0d8 | 2008-08-20 09:38:51 -0700 | [diff] [blame] | 446 | /* |
| 447 | * Set PLB4 arbiter (Segment 0 and 1) to 4 deep pipeline read |
| 448 | */ |
Stefan Roese | 95ca5fa | 2010-09-11 09:31:43 +0200 | [diff] [blame] | 449 | mtdcr(PLB4A0_ACR, (mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_RDP_MASK) | |
| 450 | PLB4Ax_ACR_RDP_4DEEP); |
| 451 | mtdcr(PLB4A1_ACR, (mfdcr(PLB4A1_ACR) & ~PLB4Ax_ACR_RDP_MASK) | |
| 452 | PLB4Ax_ACR_RDP_4DEEP); |
Prodyut Hazarika | 038f0d8 | 2008-08-20 09:38:51 -0700 | [diff] [blame] | 453 | #endif /* CONFIG_440SP/SPE || CONFIG_460EX/GT || CONFIG_405EX */ |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* |
| 457 | * initialize higher level parts of CPU like time base and timers |
| 458 | */ |
| 459 | int cpu_init_r (void) |
| 460 | { |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 461 | #if defined(CONFIG_405GP) |
stroese | 6030846 | 2003-03-20 15:21:50 +0000 | [diff] [blame] | 462 | uint pvr = get_pvr(); |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 463 | |
| 464 | /* |
stroese | 6030846 | 2003-03-20 15:21:50 +0000 | [diff] [blame] | 465 | * Set edge conditioning circuitry on PPC405GPr |
| 466 | * for compatibility to existing PPC405GP designs. |
| 467 | */ |
stroese | ff90f80 | 2003-04-04 16:00:33 +0000 | [diff] [blame] | 468 | if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 469 | mtdcr(CPC0_ECR, 0x60606000); |
stroese | 6030846 | 2003-03-20 15:21:50 +0000 | [diff] [blame] | 470 | } |
stroese | 434979e | 2003-05-23 11:18:02 +0000 | [diff] [blame] | 471 | #endif /* defined(CONFIG_405GP) */ |
Stefan Roese | cc019d1 | 2008-03-11 15:05:50 +0100 | [diff] [blame] | 472 | |
Stefan Roese | 29762f5 | 2009-02-23 16:42:51 +0100 | [diff] [blame] | 473 | return 0; |
wdenk | 4a9cbbe | 2002-08-27 09:48:53 +0000 | [diff] [blame] | 474 | } |
Stefan Roese | cd47b18 | 2009-10-19 14:06:23 +0200 | [diff] [blame] | 475 | |
| 476 | #if defined(CONFIG_PCI) && \ |
| 477 | (defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \ |
| 478 | defined(CONFIG_440GR) || defined(CONFIG_440GRX)) |
| 479 | /* |
| 480 | * 440EP(x)/GR(x) PCI async/sync clocking restriction: |
| 481 | * |
| 482 | * In asynchronous PCI mode, the synchronous PCI clock must meet |
| 483 | * certain requirements. The following equation describes the |
| 484 | * relationship that must be maintained between the asynchronous PCI |
| 485 | * clock and synchronous PCI clock. Select an appropriate PCI:PLB |
| 486 | * ratio to maintain the relationship: |
| 487 | * |
| 488 | * AsyncPCIClk - 1MHz <= SyncPCIclock <= (2 * AsyncPCIClk) - 1MHz |
| 489 | */ |
| 490 | static int ppc4xx_pci_sync_clock_ok(u32 sync, u32 async) |
| 491 | { |
| 492 | if (((async - 1000000) > sync) || (sync > ((2 * async) - 1000000))) |
| 493 | return 0; |
| 494 | else |
| 495 | return 1; |
| 496 | } |
| 497 | |
| 498 | int ppc4xx_pci_sync_clock_config(u32 async) |
| 499 | { |
| 500 | sys_info_t sys_info; |
| 501 | u32 sync; |
| 502 | int div; |
| 503 | u32 reg; |
| 504 | u32 spcid_val[] = { |
| 505 | CPR0_SPCID_SPCIDV0_DIV1, CPR0_SPCID_SPCIDV0_DIV2, |
| 506 | CPR0_SPCID_SPCIDV0_DIV3, CPR0_SPCID_SPCIDV0_DIV4 }; |
| 507 | |
| 508 | get_sys_info(&sys_info); |
| 509 | sync = sys_info.freqPCI; |
| 510 | |
| 511 | /* |
| 512 | * First check if the equation above is met |
| 513 | */ |
| 514 | if (!ppc4xx_pci_sync_clock_ok(sync, async)) { |
| 515 | /* |
| 516 | * Reconfigure PCI sync clock to meet the equation. |
| 517 | * Start with highest possible PCI sync frequency |
| 518 | * (divider 1). |
| 519 | */ |
| 520 | for (div = 1; div <= 4; div++) { |
| 521 | sync = sys_info.freqPLB / div; |
| 522 | if (ppc4xx_pci_sync_clock_ok(sync, async)) |
| 523 | break; |
| 524 | } |
| 525 | |
| 526 | if (div <= 4) { |
| 527 | mtcpr(CPR0_SPCID, spcid_val[div]); |
| 528 | |
| 529 | mfcpr(CPR0_ICFG, reg); |
| 530 | reg |= CPR0_ICFG_RLI_MASK; |
| 531 | mtcpr(CPR0_ICFG, reg); |
| 532 | |
| 533 | /* do chip reset */ |
| 534 | mtspr(SPRN_DBCR0, 0x20000000); |
| 535 | } else { |
| 536 | /* Impossible to configure the PCI sync clock */ |
| 537 | return -1; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | #endif |