Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 1 | /* |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 2 | * (C) Copyright 2007-2008 |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 3 | * Larry Johnson, lrj@acm.org |
| 4 | * |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 5 | * (C) Copyright 2006-2007 |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 6 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 7 | * |
| 8 | * (C) Copyright 2006 |
| 9 | * Jacqueline Pira-Ferriol, AMCC/IBM, jpira-ferriol@fr.ibm.com |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 10 | * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 29 | #include <fdt_support.h> |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 30 | #include <i2c.h> |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 31 | #include <libfdt.h> |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 32 | #include <ppc440.h> |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 33 | #include <asm/bitops.h> |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 34 | #include <asm/gpio.h> |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 35 | #include <asm/io.h> |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 36 | #include <asm/ppc4xx-intvec.h> |
| 37 | #include <asm/processor.h> |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 41 | extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 42 | |
| 43 | ulong flash_get_size(ulong base, int banknum); |
| 44 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 45 | #if defined(CONFIG_KORAT_PERMANENT) |
| 46 | void korat_buzzer(int const on) |
| 47 | { |
| 48 | if (on) { |
| 49 | out_8((u8 *) CFG_CPLD_BASE + 0x05, |
| 50 | in_8((u8 *) CFG_CPLD_BASE + 0x05) | 0x80); |
| 51 | } else { |
| 52 | out_8((u8 *) CFG_CPLD_BASE + 0x05, |
| 53 | in_8((u8 *) CFG_CPLD_BASE + 0x05) & ~0x80); |
| 54 | } |
| 55 | } |
| 56 | #endif |
| 57 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 58 | int board_early_init_f(void) |
| 59 | { |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 60 | uint32_t sdr0_pfc1, sdr0_pfc2; |
| 61 | uint32_t reg; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 62 | int eth; |
| 63 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 64 | #if defined(CONFIG_KORAT_PERMANENT) |
| 65 | unsigned mscount; |
| 66 | |
| 67 | extern void korat_branch_absolute(uint32_t addr); |
| 68 | |
| 69 | for (mscount = 0; mscount < CFG_KORAT_MAN_RESET_MS; ++mscount) { |
| 70 | udelay(1000); |
| 71 | if (gpio_read_in_bit(CFG_GPIO_RESET_PRESSED_)) { |
| 72 | /* This call does not return. */ |
| 73 | korat_branch_absolute( |
| 74 | CFG_FLASH1_TOP - 2 * CFG_ENV_SECT_SIZE - 4); |
| 75 | } |
| 76 | } |
| 77 | korat_buzzer(1); |
| 78 | while (!gpio_read_in_bit(CFG_GPIO_RESET_PRESSED_)) |
| 79 | udelay(1000); |
| 80 | |
| 81 | korat_buzzer(0); |
| 82 | #endif |
| 83 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 84 | mtdcr(ebccfga, xbcfg); |
| 85 | mtdcr(ebccfgd, 0xb8400000); |
| 86 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 87 | /* |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 88 | * Setup the interrupt controller polarities, triggers, etc. |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 89 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 90 | mtdcr(uic0sr, 0xffffffff); /* clear all */ |
| 91 | mtdcr(uic0er, 0x00000000); /* disable all */ |
| 92 | mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */ |
| 93 | mtdcr(uic0pr, 0xfffff7ff); /* per ref-board manual */ |
| 94 | mtdcr(uic0tr, 0x00000000); /* per ref-board manual */ |
| 95 | mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */ |
| 96 | mtdcr(uic0sr, 0xffffffff); /* clear all */ |
| 97 | |
| 98 | mtdcr(uic1sr, 0xffffffff); /* clear all */ |
| 99 | mtdcr(uic1er, 0x00000000); /* disable all */ |
| 100 | mtdcr(uic1cr, 0x00000000); /* all non-critical */ |
| 101 | mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */ |
| 102 | mtdcr(uic1tr, 0x00000000); /* per ref-board manual */ |
| 103 | mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */ |
| 104 | mtdcr(uic1sr, 0xffffffff); /* clear all */ |
| 105 | |
| 106 | mtdcr(uic2sr, 0xffffffff); /* clear all */ |
| 107 | mtdcr(uic2er, 0x00000000); /* disable all */ |
| 108 | mtdcr(uic2cr, 0x00000000); /* all non-critical */ |
| 109 | mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */ |
| 110 | mtdcr(uic2tr, 0x00000000); /* per ref-board manual */ |
| 111 | mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */ |
| 112 | mtdcr(uic2sr, 0xffffffff); /* clear all */ |
| 113 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 114 | /* |
| 115 | * Take sim card reader and CF controller out of reset. Also enable PHY |
| 116 | * auto-detect until board-specific PHY resets are available. |
| 117 | */ |
| 118 | out_8((u8 *) CFG_CPLD_BASE + 0x02, 0xC0); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 119 | |
| 120 | /* Configure the two Ethernet PHYs. For each PHY, configure for fiber |
| 121 | * if the SFP module is present, and for copper if it is not present. |
| 122 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 123 | for (eth = 0; eth < 2; ++eth) { |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 124 | if (gpio_read_in_bit(CFG_GPIO_SFP0_PRESENT_ + eth)) { |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 125 | /* SFP module not present: configure PHY for copper. */ |
| 126 | /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 127 | out_8((u8 *) CFG_CPLD_BASE + 0x03, |
| 128 | in_8((u8 *) CFG_CPLD_BASE + 0x03) | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 129 | 0x06 << (4 * eth)); |
| 130 | } else { |
| 131 | /* SFP module present: configure PHY for fiber and |
| 132 | enable output */ |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 133 | gpio_write_bit(CFG_GPIO_PHY0_FIBER_SEL + eth, 1); |
| 134 | gpio_write_bit(CFG_GPIO_SFP0_TX_EN_ + eth, 0); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | /* enable Ethernet: set GPIO45 and GPIO46 to 1 */ |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 138 | gpio_write_bit(CFG_GPIO_PHY0_EN, 1); |
| 139 | gpio_write_bit(CFG_GPIO_PHY1_EN, 1); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 140 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 141 | /* Wait 1 ms, then enable Fiber signal detect to PHYs. */ |
| 142 | udelay(1000); |
| 143 | out_8((u8 *) CFG_CPLD_BASE + 0x03, |
| 144 | in_8((u8 *) CFG_CPLD_BASE + 0x03) | 0x88); |
| 145 | |
| 146 | /* select Ethernet (and optionally IIC1) pins */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 147 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 148 | sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 149 | SDR0_PFC1_SELECT_CONFIG_4; |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 150 | #ifdef CONFIG_I2C_MULTI_BUS |
| 151 | sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL); |
| 152 | #endif |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 153 | mfsdr(SDR0_PFC2, sdr0_pfc2); |
| 154 | sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 155 | SDR0_PFC2_SELECT_CONFIG_4; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 156 | mtsdr(SDR0_PFC2, sdr0_pfc2); |
| 157 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 158 | |
| 159 | /* PCI arbiter enabled */ |
| 160 | mfsdr(sdr_pci0, reg); |
| 161 | mtsdr(sdr_pci0, 0x80000000 | reg); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 166 | /* |
| 167 | * The boot flash on CS0 normally has its write-enable pin disabled, and so will |
| 168 | * not respond to CFI commands. This routine therefore fills in the flash |
| 169 | * information for the boot flash. (The flash at CS1 operates normally.) |
| 170 | */ |
| 171 | ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info) |
| 172 | { |
| 173 | uint32_t addr; |
| 174 | int i; |
| 175 | |
| 176 | if (1 != banknum) |
| 177 | return 0; |
| 178 | |
| 179 | info->size = CFG_FLASH0_SIZE; |
| 180 | info->sector_count = CFG_FLASH0_SIZE / 0x20000; |
| 181 | info->flash_id = 0x01000000; |
| 182 | info->portwidth = 2; |
| 183 | info->chipwidth = 2; |
| 184 | info->buffer_size = 32; |
| 185 | info->erase_blk_tout = 16384; |
| 186 | info->write_tout = 2; |
| 187 | info->buffer_write_tout = 5; |
| 188 | info->vendor = 2; |
| 189 | info->cmd_reset = 0x00F0; |
| 190 | info->interface = 2; |
| 191 | info->legacy_unlock = 0; |
| 192 | info->manufacturer_id = 1; |
| 193 | info->device_id = 0x007E; |
| 194 | |
| 195 | #if CFG_FLASH0_SIZE == 0x01000000 |
| 196 | info->device_id2 = 0x2101; |
| 197 | #elif CFG_FLASH0_SIZE == 0x04000000 |
| 198 | info->device_id2 = 0x2301; |
| 199 | #else |
| 200 | #error Unable to set device_id2 for current CFG_FLASH0_SIZE |
| 201 | #endif |
| 202 | |
| 203 | info->ext_addr = 0x0040; |
| 204 | info->cfi_version = 0x3133; |
| 205 | info->cfi_offset = 0x0055; |
| 206 | info->addr_unlock1 = 0x00000555; |
| 207 | info->addr_unlock2 = 0x000002AA; |
| 208 | info->name = "CFI conformant"; |
| 209 | for (i = 0, addr = -info->size; |
| 210 | i < info->sector_count; |
| 211 | ++i, addr += 0x20000) { |
| 212 | info->start[i] = addr; |
| 213 | info->protect[i] = 0x00; |
| 214 | } |
| 215 | return 1; |
| 216 | } |
| 217 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 218 | static int man_data_read(unsigned int addr) |
| 219 | { |
| 220 | /* |
| 221 | * Read an octet of data from address "addr" in the manufacturer's |
| 222 | * information serial EEPROM, or -1 on error. |
| 223 | */ |
| 224 | u8 data[2]; |
| 225 | |
| 226 | if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) || |
| 227 | 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) { |
| 228 | debug("man_data_read(0x%02X) failed\n", addr); |
| 229 | return -1; |
| 230 | } |
| 231 | debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]); |
| 232 | return data[0]; |
| 233 | } |
| 234 | |
| 235 | static unsigned int man_data_field_addr(unsigned int const field) |
| 236 | { |
| 237 | /* |
| 238 | * The manufacturer's information serial EEPROM contains a sequence of |
| 239 | * zero-delimited fields. Return the starting address of field "field", |
| 240 | * or 0 on error. |
| 241 | */ |
| 242 | unsigned addr, i; |
| 243 | |
| 244 | if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1)) |
| 245 | /* Only format "A" is currently supported */ |
| 246 | return 0; |
| 247 | |
| 248 | for (addr = 2, i = 1; i < field && addr < 256; ++addr) { |
| 249 | if ('\0' == man_data_read(addr)) |
| 250 | ++i; |
| 251 | } |
| 252 | return (addr < 256) ? addr : 0; |
| 253 | } |
| 254 | |
| 255 | static char *man_data_read_field(char s[], unsigned const field, |
| 256 | unsigned const length) |
| 257 | { |
| 258 | /* |
| 259 | * Place the null-terminated contents of field "field" of length |
| 260 | * "length" from the manufacturer's information serial EEPROM into |
| 261 | * string "s[length + 1]" and return a pointer to s, or return 0 on |
| 262 | * error. In either case the original contents of s[] is not preserved. |
| 263 | */ |
| 264 | unsigned addr, i; |
| 265 | |
| 266 | addr = man_data_field_addr(field); |
| 267 | if (0 == addr || addr + length >= 255) |
| 268 | return 0; |
| 269 | |
| 270 | for (i = 0; i < length; ++i) { |
| 271 | int const c = man_data_read(addr++); |
| 272 | |
| 273 | if (c <= 0) |
| 274 | return 0; |
| 275 | |
| 276 | s[i] = (char)c; |
| 277 | } |
| 278 | if (0 != man_data_read(addr)) |
| 279 | return 0; |
| 280 | |
| 281 | s[i] = '\0'; |
| 282 | return s; |
| 283 | } |
| 284 | |
| 285 | static void set_serial_number(void) |
| 286 | { |
| 287 | /* |
| 288 | * If the environmental variable "serial#" is not set, try to set it |
| 289 | * from the manufacturer's information serial EEPROM. |
| 290 | */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 291 | char s[MAN_INFO_LENGTH + MAN_MAC_ADDR_LENGTH + 2]; |
| 292 | |
| 293 | if (getenv("serial#")) |
| 294 | return; |
| 295 | |
| 296 | if (!man_data_read_field(s, MAN_INFO_FIELD, MAN_INFO_LENGTH)) |
| 297 | return; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 298 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 299 | s[MAN_INFO_LENGTH] = '-'; |
| 300 | if (!man_data_read_field(s + MAN_INFO_LENGTH + 1, MAN_MAC_ADDR_FIELD, |
| 301 | MAN_MAC_ADDR_LENGTH)) |
| 302 | return; |
| 303 | |
| 304 | setenv("serial#", s); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void set_mac_addresses(void) |
| 308 | { |
| 309 | /* |
| 310 | * If the environmental variables "ethaddr" and/or "eth1addr" are not |
| 311 | * set, try to set them from the manufacturer's information serial |
| 312 | * EEPROM. |
| 313 | */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 314 | |
| 315 | #if MAN_MAC_ADDR_LENGTH % 2 != 0 |
| 316 | #error MAN_MAC_ADDR_LENGTH must be an even number |
| 317 | #endif |
| 318 | |
| 319 | char s[(3 * MAN_MAC_ADDR_LENGTH) / 2]; |
| 320 | char *src; |
| 321 | char *dst; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 322 | |
| 323 | if (0 != getenv("ethaddr") && 0 != getenv("eth1addr")) |
| 324 | return; |
| 325 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 326 | if (0 == man_data_read_field(s + (MAN_MAC_ADDR_LENGTH / 2) - 1, |
| 327 | MAN_MAC_ADDR_FIELD, MAN_MAC_ADDR_LENGTH)) |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 328 | return; |
| 329 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 330 | for (src = s + (MAN_MAC_ADDR_LENGTH / 2) - 1, dst = s; src != dst;) { |
| 331 | *dst++ = *src++; |
| 332 | *dst++ = *src++; |
| 333 | *dst++ = ':'; |
| 334 | } |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 335 | if (0 == getenv("ethaddr")) |
| 336 | setenv("ethaddr", s); |
| 337 | |
| 338 | if (0 == getenv("eth1addr")) { |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 339 | ++s[((3 * MAN_MAC_ADDR_LENGTH) / 2) - 2]; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 340 | setenv("eth1addr", s); |
| 341 | } |
| 342 | } |
| 343 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 344 | int misc_init_r(void) |
| 345 | { |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 346 | uint32_t pbcr; |
| 347 | int size_val; |
| 348 | uint32_t reg; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 349 | unsigned long usb2d0cr = 0; |
| 350 | unsigned long usb2phy0cr, usb2h0cr = 0; |
| 351 | unsigned long sdr0_pfc1; |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 352 | uint32_t const flash1_size = gd->bd->bi_flashsize - CFG_FLASH0_SIZE; |
| 353 | char const *const act = getenv("usbact"); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 354 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 355 | /* |
| 356 | * Re-do FLASH1 sizing and adjust flash start and offset. |
| 357 | */ |
| 358 | gd->bd->bi_flashstart = CFG_FLASH1_TOP - flash1_size; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 359 | gd->bd->bi_flashoffset = 0; |
| 360 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 361 | mtdcr(ebccfga, pb1cr); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 362 | pbcr = mfdcr(ebccfgd); |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 363 | size_val = ffs(flash1_size) - 21; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 364 | pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17); |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 365 | mtdcr(ebccfga, pb1cr); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 366 | mtdcr(ebccfgd, pbcr); |
| 367 | |
| 368 | /* |
| 369 | * Re-check to get correct base address |
| 370 | */ |
| 371 | flash_get_size(gd->bd->bi_flashstart, 0); |
| 372 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 373 | /* |
| 374 | * Re-do FLASH1 sizing and adjust flash offset to reserve space for |
| 375 | * environment |
| 376 | */ |
| 377 | gd->bd->bi_flashoffset = |
| 378 | CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - CFG_FLASH1_ADDR; |
| 379 | |
| 380 | mtdcr(ebccfga, pb1cr); |
| 381 | pbcr = mfdcr(ebccfgd); |
| 382 | size_val = ffs(gd->bd->bi_flashsize - CFG_FLASH0_SIZE) - 21; |
| 383 | pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17); |
| 384 | mtdcr(ebccfga, pb1cr); |
| 385 | mtdcr(ebccfgd, pbcr); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 386 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 387 | /* Monitor protection ON by default */ |
| 388 | #if defined(CONFIG_KORAT_PERMANENT) |
| 389 | (void)flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE, |
| 390 | CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, |
| 391 | flash_info + 1); |
| 392 | #else |
| 393 | (void)flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE, |
| 394 | CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, |
| 395 | flash_info); |
| 396 | #endif |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 397 | /* Env protection ON by default */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 398 | (void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR, |
| 399 | CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1, |
| 400 | flash_info); |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 401 | (void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR_REDUND, |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 402 | CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1, |
| 403 | flash_info); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * USB suff... |
| 407 | */ |
| 408 | if (act == NULL || strcmp(act, "hostdev") == 0) { |
| 409 | /* SDR Setting */ |
| 410 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 411 | mfsdr(SDR0_USB2D0CR, usb2d0cr); |
| 412 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 413 | mfsdr(SDR0_USB2H0CR, usb2h0cr); |
| 414 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 415 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 416 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 417 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK; |
| 418 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; |
| 419 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 420 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; |
| 421 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 422 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; |
| 423 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 424 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 425 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 426 | /* |
| 427 | * An 8-bit/60MHz interface is the only possible alternative |
| 428 | * when connecting the Device to the PHY |
| 429 | */ |
| 430 | usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK; |
| 431 | usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 432 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 433 | /* |
| 434 | * To enable the USB 2.0 Device function |
| 435 | * through the UTMI interface |
| 436 | */ |
| 437 | usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK; |
| 438 | usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 439 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 440 | sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK; |
| 441 | sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 442 | |
| 443 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 444 | mtsdr(SDR0_USB2D0CR, usb2d0cr); |
| 445 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 446 | mtsdr(SDR0_USB2H0CR, usb2h0cr); |
| 447 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 448 | /* clear resets */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 449 | udelay(1000); |
| 450 | mtsdr(SDR0_SRST1, 0x00000000); |
| 451 | udelay(1000); |
| 452 | mtsdr(SDR0_SRST0, 0x00000000); |
| 453 | |
| 454 | printf("USB: Host(int phy) Device(ext phy)\n"); |
| 455 | |
| 456 | } else if (strcmp(act, "dev") == 0) { |
| 457 | /*-------------------PATCH-------------------------------*/ |
| 458 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 459 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 460 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 461 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 462 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 463 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; |
| 464 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 465 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; |
| 466 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 467 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 468 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 469 | |
| 470 | udelay(1000); |
| 471 | mtsdr(SDR0_SRST1, 0x672c6000); |
| 472 | |
| 473 | udelay(1000); |
| 474 | mtsdr(SDR0_SRST0, 0x00000080); |
| 475 | |
| 476 | udelay(1000); |
| 477 | mtsdr(SDR0_SRST1, 0x60206000); |
| 478 | |
| 479 | *(unsigned int *)(0xe0000350) = 0x00000001; |
| 480 | |
| 481 | udelay(1000); |
| 482 | mtsdr(SDR0_SRST1, 0x60306000); |
| 483 | /*-------------------PATCH-------------------------------*/ |
| 484 | |
| 485 | /* SDR Setting */ |
| 486 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 487 | mfsdr(SDR0_USB2H0CR, usb2h0cr); |
| 488 | mfsdr(SDR0_USB2D0CR, usb2d0cr); |
| 489 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 490 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 491 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 492 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 493 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK; |
| 494 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ; |
| 495 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 496 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; |
| 497 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 498 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV; |
| 499 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 500 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 501 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 502 | usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK; |
| 503 | usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 504 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 505 | usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK; |
| 506 | usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 507 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 508 | sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK; |
| 509 | sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 510 | |
| 511 | mtsdr(SDR0_USB2H0CR, usb2h0cr); |
| 512 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 513 | mtsdr(SDR0_USB2D0CR, usb2d0cr); |
| 514 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 515 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 516 | /* clear resets */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 517 | udelay(1000); |
| 518 | mtsdr(SDR0_SRST1, 0x00000000); |
| 519 | udelay(1000); |
| 520 | mtsdr(SDR0_SRST0, 0x00000000); |
| 521 | |
| 522 | printf("USB: Device(int phy)\n"); |
| 523 | } |
| 524 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 525 | mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 526 | reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0); |
| 527 | mtsdr(SDR0_SRST1, reg); |
| 528 | |
| 529 | /* |
| 530 | * Clear PLB4A0_ACR[WRP] |
| 531 | * This fix will make the MAL burst disabling patch for the Linux |
| 532 | * EMAC driver obsolete. |
| 533 | */ |
| 534 | reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP; |
| 535 | mtdcr(plb4_acr, reg); |
| 536 | |
| 537 | set_serial_number(); |
| 538 | set_mac_addresses(); |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 539 | gpio_write_bit(CFG_GPIO_ATMEGA_RESET_, 1); |
| 540 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | int checkboard(void) |
| 545 | { |
| 546 | char const *const s = getenv("serial#"); |
| 547 | u8 const rev = in_8((u8 *) CFG_CPLD_BASE + 0); |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 548 | |
| 549 | printf("Board: Korat, Rev. %X", rev); |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 550 | if (s) |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 551 | printf(", serial# %s", s); |
| 552 | |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 553 | printf(".\n Ethernet PHY 0: "); |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 554 | if (gpio_read_out_bit(CFG_GPIO_PHY0_FIBER_SEL)) |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 555 | printf("fiber"); |
| 556 | else |
| 557 | printf("copper"); |
| 558 | |
| 559 | printf(", PHY 1: "); |
Lawrence R. Johnson | 5989058 | 2008-01-03 15:02:02 -0500 | [diff] [blame] | 560 | if (gpio_read_out_bit(CFG_GPIO_PHY1_FIBER_SEL)) |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 561 | printf("fiber"); |
| 562 | else |
| 563 | printf("copper"); |
| 564 | |
| 565 | printf(".\n"); |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 566 | #if defined(CONFIG_KORAT_PERMANENT) |
| 567 | printf(" Executing permanent copy of U-Boot.\n"); |
| 568 | #endif |
| 569 | return 0; |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | #if defined(CFG_DRAM_TEST) |
| 573 | int testdram(void) |
| 574 | { |
| 575 | unsigned long *mem = (unsigned long *)0; |
| 576 | const unsigned long kend = (1024 / sizeof(unsigned long)); |
| 577 | unsigned long k, n; |
| 578 | |
| 579 | mtmsr(0); |
| 580 | |
| 581 | /* TODO: find correct size of SDRAM */ |
| 582 | for (k = 0; k < CFG_MBYTES_SDRAM; |
| 583 | ++k, mem += (1024 / sizeof(unsigned long))) { |
| 584 | if ((k & 1023) == 0) |
| 585 | printf("%3d MB\r", k / 1024); |
| 586 | |
| 587 | memset(mem, 0xaaaaaaaa, 1024); |
| 588 | for (n = 0; n < kend; ++n) { |
| 589 | if (mem[n] != 0xaaaaaaaa) { |
| 590 | printf("SDRAM test fails at: %08x\n", |
| 591 | (uint) & mem[n]); |
| 592 | return 1; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | memset(mem, 0x55555555, 1024); |
| 597 | for (n = 0; n < kend; ++n) { |
| 598 | if (mem[n] != 0x55555555) { |
| 599 | printf("SDRAM test fails at: %08x\n", |
| 600 | (uint) & mem[n]); |
| 601 | return 1; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | printf("SDRAM test passes\n"); |
| 606 | return 0; |
| 607 | } |
| 608 | #endif /* defined(CFG_DRAM_TEST) */ |
| 609 | |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 610 | #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP) |
| 611 | /* |
| 612 | * Assign interrupts to PCI devices. |
| 613 | */ |
| 614 | void korat_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 615 | { |
| 616 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIR2); |
| 617 | } |
| 618 | #endif |
| 619 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 620 | /* |
| 621 | * pci_pre_init |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 622 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 623 | * This routine is called just prior to registering the hose and gives |
| 624 | * the board the opportunity to check things. Returning a value of zero |
| 625 | * indicates that things are bad & PCI initialization should be aborted. |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 626 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 627 | * Different boards may wish to customize the pci controller structure |
| 628 | * (add regions, override default access routines, etc) or perform |
| 629 | * certain pre-initialization actions. |
| 630 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 631 | #if defined(CONFIG_PCI) |
| 632 | int pci_pre_init(struct pci_controller *hose) |
| 633 | { |
| 634 | unsigned long addr; |
| 635 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 636 | /* |
| 637 | * Set priority for all PLB3 devices to 0. |
| 638 | * Set PLB3 arbiter to fair mode. |
| 639 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 640 | mfsdr(sdr_amp1, addr); |
| 641 | mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00); |
| 642 | addr = mfdcr(plb3_acr); |
| 643 | mtdcr(plb3_acr, addr | 0x80000000); |
| 644 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 645 | /* |
| 646 | * Set priority for all PLB4 devices to 0. |
| 647 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 648 | mfsdr(sdr_amp0, addr); |
| 649 | mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00); |
| 650 | addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */ |
| 651 | mtdcr(plb4_acr, addr); |
| 652 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 653 | /* |
| 654 | * Set Nebula PLB4 arbiter to fair mode. |
| 655 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 656 | /* Segment0 */ |
| 657 | addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair; |
| 658 | addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled; |
| 659 | addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep; |
| 660 | addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep; |
| 661 | mtdcr(plb0_acr, addr); |
| 662 | |
| 663 | /* Segment1 */ |
| 664 | addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair; |
| 665 | addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled; |
| 666 | addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep; |
| 667 | addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep; |
| 668 | mtdcr(plb1_acr, addr); |
| 669 | |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 670 | #if defined(CONFIG_PCI_PNP) |
| 671 | hose->fixup_irq = korat_pci_fixup_irq; |
| 672 | #endif |
| 673 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 674 | return 1; |
| 675 | } |
| 676 | #endif /* defined(CONFIG_PCI) */ |
| 677 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 678 | /* |
| 679 | * pci_target_init |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 680 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 681 | * The bootstrap configuration provides default settings for the pci |
| 682 | * inbound map (PIM). But the bootstrap config choices are limited and |
| 683 | * may not be sufficient for a given board. |
| 684 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 685 | #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) |
| 686 | void pci_target_init(struct pci_controller *hose) |
| 687 | { |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 688 | /* |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 689 | * Set up Direct MMIO registers |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 690 | */ |
| 691 | /* |
| 692 | * PowerPC440EPX PCI Master configuration. |
| 693 | * Map one 1Gig range of PLB/processor addresses to PCI memory space. |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 694 | * PLB address 0x80000000-0xBFFFFFFF |
| 695 | * ==> PCI address 0x80000000-0xBFFFFFFF |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 696 | * Use byte reversed out routines to handle endianess. |
| 697 | * Make this region non-prefetchable. |
| 698 | */ |
| 699 | out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */ |
| 700 | /* - disabled b4 setting */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 701 | out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 702 | out32r(PCIX0_PMM0PCILA, |
| 703 | CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 704 | out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */ |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 705 | out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */ |
| 706 | /* and enable region */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 707 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 708 | out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */ |
| 709 | /* - disabled b4 setting */ |
Larry Johnson | 6768267 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 710 | out32r(PCIX0_PMM1LA, |
| 711 | CFG_PCI_MEMBASE + 0x20000000); /* PMM0 Local Address */ |
| 712 | out32r(PCIX0_PMM1PCILA, |
| 713 | CFG_PCI_MEMBASE + 0x20000000); /* PMM0 PCI Low Address */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 714 | out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */ |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 715 | out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */ |
| 716 | /* and enable region */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 717 | |
| 718 | out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */ |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 719 | out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */ |
| 720 | out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */ |
| 721 | out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 722 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 723 | /* |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 724 | * Set up Configuration registers |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 725 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 726 | |
| 727 | /* Program the board's subsystem id/vendor id */ |
| 728 | pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID, |
| 729 | CFG_PCI_SUBSYS_VENDORID); |
| 730 | pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID); |
| 731 | |
| 732 | /* Configure command register as bus master */ |
| 733 | pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 734 | |
| 735 | /* 240nS PCI clock */ |
| 736 | pci_write_config_word(0, PCI_LATENCY_TIMER, 1); |
| 737 | |
| 738 | /* No error reporting */ |
| 739 | pci_write_config_word(0, PCI_ERREN, 0); |
| 740 | |
| 741 | pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101); |
| 742 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 743 | /* |
| 744 | * Set up Configuration registers for on-board NEC uPD720101 USB |
| 745 | * controller. |
| 746 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 747 | pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020); |
| 748 | } |
| 749 | #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */ |
| 750 | |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 751 | #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) |
| 752 | void pci_master_init(struct pci_controller *hose) |
| 753 | { |
| 754 | unsigned short temp_short; |
| 755 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 756 | /* |
| 757 | * Write the PowerPC440 EP PCI Configuration regs. |
| 758 | * Enable PowerPC440 EP to be a master on the PCI bus (PMM). |
| 759 | * Enable PowerPC440 EP to act as a PCI memory target (PTM). |
| 760 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 761 | pci_read_config_word(0, PCI_COMMAND, &temp_short); |
| 762 | pci_write_config_word(0, PCI_COMMAND, |
| 763 | temp_short | PCI_COMMAND_MASTER | |
| 764 | PCI_COMMAND_MEMORY); |
| 765 | } |
| 766 | #endif |
| 767 | |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 768 | /* |
| 769 | * is_pci_host |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 770 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 771 | * This routine is called to determine if a pci scan should be |
| 772 | * performed. With various hardware environments (especially cPCI and |
| 773 | * PPMC) it's insufficient to depend on the state of the arbiter enable |
| 774 | * bit in the strap register, or generic host/adapter assumptions. |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 775 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 776 | * Rather than hard-code a bad assumption in the general 440 code, the |
| 777 | * 440 pci code requires the board to decide at runtime. |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 778 | * |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 779 | * Return 0 for adapter mode, non-zero for host (monarch) mode. |
| 780 | */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 781 | #if defined(CONFIG_PCI) |
| 782 | int is_pci_host(struct pci_controller *hose) |
| 783 | { |
| 784 | /* Korat is always configured as host. */ |
| 785 | return (1); |
| 786 | } |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 787 | #endif /* defined(CONFIG_PCI) */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 788 | |
| 789 | #if defined(CONFIG_POST) |
| 790 | /* |
| 791 | * Returns 1 if keys pressed to start the power-on long-running tests |
| 792 | * Called from board_init_f(). |
| 793 | */ |
| 794 | int post_hotkeys_pressed(void) |
| 795 | { |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 796 | return 0; /* No hotkeys supported */ |
Larry Johnson | 667a3d4 | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 797 | } |
Larry Johnson | e17c6f7 | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 798 | #endif /* CONFIG_POST */ |
Larry Johnson | fc39100 | 2008-06-14 16:53:02 -0400 | [diff] [blame^] | 799 | |
| 800 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 801 | void ft_board_setup(void *blob, bd_t *bd) |
| 802 | { |
| 803 | u32 val[4]; |
| 804 | int rc; |
| 805 | |
| 806 | ft_cpu_setup(blob, bd); |
| 807 | |
| 808 | /* Fixup NOR mapping */ |
| 809 | val[0] = 1; /* chip select number */ |
| 810 | val[1] = 0; /* always 0 */ |
| 811 | val[2] = gd->bd->bi_flashstart; |
| 812 | val[3] = gd->bd->bi_flashsize - CFG_FLASH0_SIZE; |
| 813 | rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges", |
| 814 | val, sizeof(val), 1); |
| 815 | if (rc) |
| 816 | printf("Unable to update property NOR mapping, err=%s\n", |
| 817 | fdt_strerror(rc)); |
| 818 | } |
| 819 | #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */ |