Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 1 | /* |
Larry Johnson | f20405e | 2009-01-28 15:30:02 -0500 | [diff] [blame] | 2 | * (C) Copyright 2007-2009 |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 3 | * Larry Johnson, lrj@acm.org |
| 4 | * |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 5 | * (C) Copyright 2006-2007 |
Larry Johnson | c591dff | 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 | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 10 | * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com |
Larry Johnson | c591dff | 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 | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 29 | #include <fdt_support.h> |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 30 | #include <i2c.h> |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 31 | #include <libfdt.h> |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 32 | #include <ppc440.h> |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 33 | #include <asm/bitops.h> |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 34 | #include <asm/gpio.h> |
| 35 | #include <asm/io.h> |
Stefan Roese | 6bd9138 | 2008-07-11 11:40:13 +0200 | [diff] [blame] | 36 | #include <asm/ppc4xx-uic.h> |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 37 | #include <asm/processor.h> |
Stefan Roese | 1095493 | 2009-11-12 12:00:49 +0100 | [diff] [blame^] | 38 | #include <asm/4xx_pci.h> |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 43 | |
| 44 | ulong flash_get_size(ulong base, int banknum); |
| 45 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 46 | #if defined(CONFIG_KORAT_PERMANENT) |
| 47 | void korat_buzzer(int const on) |
| 48 | { |
| 49 | if (on) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05, |
| 51 | in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) | 0x80); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 52 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05, |
| 54 | in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) & ~0x80); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | #endif |
| 58 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 59 | int board_early_init_f(void) |
| 60 | { |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 61 | uint32_t sdr0_pfc1, sdr0_pfc2; |
| 62 | uint32_t reg; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 63 | int eth; |
| 64 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 65 | #if defined(CONFIG_KORAT_PERMANENT) |
| 66 | unsigned mscount; |
| 67 | |
| 68 | extern void korat_branch_absolute(uint32_t addr); |
| 69 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | for (mscount = 0; mscount < CONFIG_SYS_KORAT_MAN_RESET_MS; ++mscount) { |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 71 | udelay(1000); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | if (gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) { |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 73 | /* This call does not return. */ |
| 74 | korat_branch_absolute( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | CONFIG_SYS_FLASH1_TOP - 2 * CONFIG_ENV_SECT_SIZE - 4); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | korat_buzzer(1); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | while (!gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 80 | udelay(1000); |
| 81 | |
| 82 | korat_buzzer(0); |
| 83 | #endif |
| 84 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 85 | mtdcr(EBC0_CFGADDR, EBC0_CFG); |
| 86 | mtdcr(EBC0_CFGDATA, 0xb8400000); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 87 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 88 | /* |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 89 | * Setup the interrupt controller polarities, triggers, etc. |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 90 | */ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 91 | mtdcr(UIC0SR, 0xffffffff); /* clear all */ |
| 92 | mtdcr(UIC0ER, 0x00000000); /* disable all */ |
| 93 | mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */ |
| 94 | mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */ |
| 95 | mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */ |
| 96 | mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */ |
| 97 | mtdcr(UIC0SR, 0xffffffff); /* clear all */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 98 | |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 99 | mtdcr(UIC1SR, 0xffffffff); /* clear all */ |
| 100 | mtdcr(UIC1ER, 0x00000000); /* disable all */ |
| 101 | mtdcr(UIC1CR, 0x00000000); /* all non-critical */ |
| 102 | mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */ |
| 103 | mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */ |
| 104 | mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */ |
| 105 | mtdcr(UIC1SR, 0xffffffff); /* clear all */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 106 | |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 107 | mtdcr(UIC2SR, 0xffffffff); /* clear all */ |
| 108 | mtdcr(UIC2ER, 0x00000000); /* disable all */ |
| 109 | mtdcr(UIC2CR, 0x00000000); /* all non-critical */ |
| 110 | mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */ |
| 111 | mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */ |
| 112 | mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */ |
| 113 | mtdcr(UIC2SR, 0xffffffff); /* clear all */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 114 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 115 | /* |
| 116 | * Take sim card reader and CF controller out of reset. Also enable PHY |
| 117 | * auto-detect until board-specific PHY resets are available. |
| 118 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 119 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02, 0xC0); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 120 | |
| 121 | /* Configure the two Ethernet PHYs. For each PHY, configure for fiber |
| 122 | * if the SFP module is present, and for copper if it is not present. |
| 123 | */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 124 | for (eth = 0; eth < 2; ++eth) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | if (gpio_read_in_bit(CONFIG_SYS_GPIO_SFP0_PRESENT_ + eth)) { |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 126 | /* SFP module not present: configure PHY for copper. */ |
| 127 | /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 128 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03, |
| 129 | in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 130 | 0x06 << (4 * eth)); |
| 131 | } else { |
| 132 | /* SFP module present: configure PHY for fiber and |
| 133 | enable output */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | gpio_write_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL + eth, 1); |
| 135 | gpio_write_bit(CONFIG_SYS_GPIO_SFP0_TX_EN_ + eth, 0); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | /* enable Ethernet: set GPIO45 and GPIO46 to 1 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 139 | gpio_write_bit(CONFIG_SYS_GPIO_PHY0_EN, 1); |
| 140 | gpio_write_bit(CONFIG_SYS_GPIO_PHY1_EN, 1); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 141 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 142 | /* Wait 1 ms, then enable Fiber signal detect to PHYs. */ |
| 143 | udelay(1000); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 144 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03, |
| 145 | in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) | 0x88); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 146 | |
| 147 | /* select Ethernet (and optionally IIC1) pins */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 148 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 149 | sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 150 | SDR0_PFC1_SELECT_CONFIG_4; |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 151 | #ifdef CONFIG_I2C_MULTI_BUS |
| 152 | sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL); |
| 153 | #endif |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 154 | mfsdr(SDR0_PFC2, sdr0_pfc2); |
| 155 | sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 156 | SDR0_PFC2_SELECT_CONFIG_4; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 157 | mtsdr(SDR0_PFC2, sdr0_pfc2); |
| 158 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 159 | |
| 160 | /* PCI arbiter enabled */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 161 | mfsdr(SDR0_PCI0, reg); |
| 162 | mtsdr(SDR0_PCI0, 0x80000000 | reg); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 167 | /* |
| 168 | * The boot flash on CS0 normally has its write-enable pin disabled, and so will |
| 169 | * not respond to CFI commands. This routine therefore fills in the flash |
| 170 | * information for the boot flash. (The flash at CS1 operates normally.) |
| 171 | */ |
| 172 | ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info) |
| 173 | { |
| 174 | uint32_t addr; |
| 175 | int i; |
| 176 | |
| 177 | if (1 != banknum) |
| 178 | return 0; |
| 179 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 180 | info->size = CONFIG_SYS_FLASH0_SIZE; |
| 181 | info->sector_count = CONFIG_SYS_FLASH0_SIZE / 0x20000; |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 182 | info->flash_id = 0x01000000; |
| 183 | info->portwidth = 2; |
| 184 | info->chipwidth = 2; |
| 185 | info->buffer_size = 32; |
| 186 | info->erase_blk_tout = 16384; |
| 187 | info->write_tout = 2; |
| 188 | info->buffer_write_tout = 5; |
| 189 | info->vendor = 2; |
| 190 | info->cmd_reset = 0x00F0; |
| 191 | info->interface = 2; |
| 192 | info->legacy_unlock = 0; |
| 193 | info->manufacturer_id = 1; |
| 194 | info->device_id = 0x007E; |
| 195 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | #if CONFIG_SYS_FLASH0_SIZE == 0x01000000 |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 197 | info->device_id2 = 0x2101; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 198 | #elif CONFIG_SYS_FLASH0_SIZE == 0x04000000 |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 199 | info->device_id2 = 0x2301; |
| 200 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 201 | #error Unable to set device_id2 for current CONFIG_SYS_FLASH0_SIZE |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 202 | #endif |
| 203 | |
| 204 | info->ext_addr = 0x0040; |
| 205 | info->cfi_version = 0x3133; |
| 206 | info->cfi_offset = 0x0055; |
| 207 | info->addr_unlock1 = 0x00000555; |
| 208 | info->addr_unlock2 = 0x000002AA; |
| 209 | info->name = "CFI conformant"; |
| 210 | for (i = 0, addr = -info->size; |
| 211 | i < info->sector_count; |
| 212 | ++i, addr += 0x20000) { |
| 213 | info->start[i] = addr; |
| 214 | info->protect[i] = 0x00; |
| 215 | } |
| 216 | return 1; |
| 217 | } |
| 218 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 219 | static int man_data_read(unsigned int addr) |
| 220 | { |
| 221 | /* |
| 222 | * Read an octet of data from address "addr" in the manufacturer's |
| 223 | * information serial EEPROM, or -1 on error. |
| 224 | */ |
| 225 | u8 data[2]; |
| 226 | |
| 227 | if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) || |
| 228 | 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) { |
| 229 | debug("man_data_read(0x%02X) failed\n", addr); |
| 230 | return -1; |
| 231 | } |
| 232 | debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]); |
| 233 | return data[0]; |
| 234 | } |
| 235 | |
| 236 | static unsigned int man_data_field_addr(unsigned int const field) |
| 237 | { |
| 238 | /* |
| 239 | * The manufacturer's information serial EEPROM contains a sequence of |
| 240 | * zero-delimited fields. Return the starting address of field "field", |
| 241 | * or 0 on error. |
| 242 | */ |
| 243 | unsigned addr, i; |
| 244 | |
| 245 | if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1)) |
| 246 | /* Only format "A" is currently supported */ |
| 247 | return 0; |
| 248 | |
| 249 | for (addr = 2, i = 1; i < field && addr < 256; ++addr) { |
| 250 | if ('\0' == man_data_read(addr)) |
| 251 | ++i; |
| 252 | } |
| 253 | return (addr < 256) ? addr : 0; |
| 254 | } |
| 255 | |
| 256 | static char *man_data_read_field(char s[], unsigned const field, |
| 257 | unsigned const length) |
| 258 | { |
| 259 | /* |
| 260 | * Place the null-terminated contents of field "field" of length |
| 261 | * "length" from the manufacturer's information serial EEPROM into |
| 262 | * string "s[length + 1]" and return a pointer to s, or return 0 on |
| 263 | * error. In either case the original contents of s[] is not preserved. |
| 264 | */ |
| 265 | unsigned addr, i; |
| 266 | |
| 267 | addr = man_data_field_addr(field); |
| 268 | if (0 == addr || addr + length >= 255) |
| 269 | return 0; |
| 270 | |
| 271 | for (i = 0; i < length; ++i) { |
| 272 | int const c = man_data_read(addr++); |
| 273 | |
| 274 | if (c <= 0) |
| 275 | return 0; |
| 276 | |
| 277 | s[i] = (char)c; |
| 278 | } |
| 279 | if (0 != man_data_read(addr)) |
| 280 | return 0; |
| 281 | |
| 282 | s[i] = '\0'; |
| 283 | return s; |
| 284 | } |
| 285 | |
| 286 | static void set_serial_number(void) |
| 287 | { |
| 288 | /* |
| 289 | * If the environmental variable "serial#" is not set, try to set it |
| 290 | * from the manufacturer's information serial EEPROM. |
| 291 | */ |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 292 | char s[MAN_INFO_LENGTH + MAN_MAC_ADDR_LENGTH + 2]; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 293 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 294 | if (getenv("serial#")) |
| 295 | return; |
| 296 | |
| 297 | if (!man_data_read_field(s, MAN_INFO_FIELD, MAN_INFO_LENGTH)) |
| 298 | return; |
| 299 | |
| 300 | s[MAN_INFO_LENGTH] = '-'; |
| 301 | if (!man_data_read_field(s + MAN_INFO_LENGTH + 1, MAN_MAC_ADDR_FIELD, |
| 302 | MAN_MAC_ADDR_LENGTH)) |
| 303 | return; |
| 304 | |
| 305 | setenv("serial#", s); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static void set_mac_addresses(void) |
| 309 | { |
| 310 | /* |
| 311 | * If the environmental variables "ethaddr" and/or "eth1addr" are not |
| 312 | * set, try to set them from the manufacturer's information serial |
| 313 | * EEPROM. |
| 314 | */ |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 315 | |
| 316 | #if MAN_MAC_ADDR_LENGTH % 2 != 0 |
| 317 | #error MAN_MAC_ADDR_LENGTH must be an even number |
| 318 | #endif |
| 319 | |
| 320 | char s[(3 * MAN_MAC_ADDR_LENGTH) / 2]; |
| 321 | char *src; |
| 322 | char *dst; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 323 | |
| 324 | if (0 != getenv("ethaddr") && 0 != getenv("eth1addr")) |
| 325 | return; |
| 326 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 327 | if (0 == man_data_read_field(s + (MAN_MAC_ADDR_LENGTH / 2) - 1, |
| 328 | MAN_MAC_ADDR_FIELD, MAN_MAC_ADDR_LENGTH)) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 329 | return; |
| 330 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 331 | for (src = s + (MAN_MAC_ADDR_LENGTH / 2) - 1, dst = s; src != dst;) { |
| 332 | *dst++ = *src++; |
| 333 | *dst++ = *src++; |
| 334 | *dst++ = ':'; |
| 335 | } |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 336 | if (0 == getenv("ethaddr")) |
| 337 | setenv("ethaddr", s); |
| 338 | |
| 339 | if (0 == getenv("eth1addr")) { |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 340 | ++s[((3 * MAN_MAC_ADDR_LENGTH) / 2) - 2]; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 341 | setenv("eth1addr", s); |
| 342 | } |
| 343 | } |
| 344 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 345 | int misc_init_r(void) |
| 346 | { |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 347 | uint32_t pbcr; |
| 348 | int size_val; |
| 349 | uint32_t reg; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 350 | unsigned long usb2d0cr = 0; |
| 351 | unsigned long usb2phy0cr, usb2h0cr = 0; |
| 352 | unsigned long sdr0_pfc1; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 353 | uint32_t const flash1_size = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE; |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 354 | char const *const act = getenv("usbact"); |
Larry Johnson | f20405e | 2009-01-28 15:30:02 -0500 | [diff] [blame] | 355 | char const *const usbcf = getenv("korat_usbcf"); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 356 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 357 | /* |
| 358 | * Re-do FLASH1 sizing and adjust flash start and offset. |
| 359 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 360 | gd->bd->bi_flashstart = CONFIG_SYS_FLASH1_TOP - flash1_size; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 361 | gd->bd->bi_flashoffset = 0; |
| 362 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 363 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 364 | pbcr = mfdcr(EBC0_CFGDATA); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 365 | size_val = ffs(flash1_size) - 21; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 366 | pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 367 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 368 | mtdcr(EBC0_CFGDATA, pbcr); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 369 | |
| 370 | /* |
| 371 | * Re-check to get correct base address |
| 372 | */ |
| 373 | flash_get_size(gd->bd->bi_flashstart, 0); |
| 374 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 375 | /* |
| 376 | * Re-do FLASH1 sizing and adjust flash offset to reserve space for |
| 377 | * environment |
| 378 | */ |
| 379 | gd->bd->bi_flashoffset = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 380 | CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - CONFIG_SYS_FLASH1_ADDR; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 381 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 382 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 383 | pbcr = mfdcr(EBC0_CFGDATA); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 384 | size_val = ffs(gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE) - 21; |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 385 | pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 386 | mtdcr(EBC0_CFGADDR, PB1CR); |
| 387 | mtdcr(EBC0_CFGDATA, pbcr); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 388 | |
| 389 | /* Monitor protection ON by default */ |
| 390 | #if defined(CONFIG_KORAT_PERMANENT) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 391 | (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE, |
| 392 | CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1, |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 393 | flash_info + 1); |
| 394 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 395 | (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE, |
| 396 | CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1, |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 397 | flash_info); |
| 398 | #endif |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 399 | /* Env protection ON by default */ |
Jean-Christophe PLAGNIOL-VILLARD | 0e8d158 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 400 | (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR, |
| 401 | CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 402 | flash_info); |
Jean-Christophe PLAGNIOL-VILLARD | 0e8d158 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 403 | (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND, |
| 404 | CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 405 | flash_info); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * USB suff... |
| 409 | */ |
Larry Johnson | f20405e | 2009-01-28 15:30:02 -0500 | [diff] [blame] | 410 | /* |
| 411 | * Select the USB controller on the 440EPx ("ppc") or on the PCI bus |
| 412 | * ("pci") for the CompactFlash. |
| 413 | */ |
| 414 | if (usbcf != NULL && (strcmp(usbcf, "ppc") == 0)) { |
| 415 | /* |
| 416 | * If environment variable "usbcf" is defined and set to "ppc", |
| 417 | * then connect the CompactFlash controller to the PowerPC USB |
| 418 | * port. |
| 419 | */ |
| 420 | printf("Attaching CompactFalsh controller to PPC USB\n"); |
| 421 | out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02, |
| 422 | in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02) | 0x10); |
| 423 | } else { |
| 424 | if (usbcf != NULL && (strcmp(usbcf, "pci") != 0)) |
| 425 | printf("Warning: \"korat_usbcf\" is not set to a legal " |
| 426 | "value (\"ppc\" or \"pci\")\n"); |
| 427 | |
| 428 | printf("Attaching CompactFalsh controller to PCI USB\n"); |
| 429 | } |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 430 | if (act == NULL || strcmp(act, "hostdev") == 0) { |
| 431 | /* SDR Setting */ |
| 432 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 433 | mfsdr(SDR0_USB2D0CR, usb2d0cr); |
| 434 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 435 | mfsdr(SDR0_USB2H0CR, usb2h0cr); |
| 436 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 437 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 438 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 439 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK; |
| 440 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; |
| 441 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 442 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; |
| 443 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 444 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; |
| 445 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 446 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 447 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 448 | /* |
| 449 | * An 8-bit/60MHz interface is the only possible alternative |
| 450 | * when connecting the Device to the PHY |
| 451 | */ |
| 452 | usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK; |
| 453 | usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 454 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 455 | /* |
| 456 | * To enable the USB 2.0 Device function |
| 457 | * through the UTMI interface |
| 458 | */ |
| 459 | usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK; |
| 460 | usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 461 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 462 | sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK; |
| 463 | sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 464 | |
| 465 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 466 | mtsdr(SDR0_USB2D0CR, usb2d0cr); |
| 467 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 468 | mtsdr(SDR0_USB2H0CR, usb2h0cr); |
| 469 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 470 | /* clear resets */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 471 | udelay(1000); |
| 472 | mtsdr(SDR0_SRST1, 0x00000000); |
| 473 | udelay(1000); |
| 474 | mtsdr(SDR0_SRST0, 0x00000000); |
| 475 | |
| 476 | printf("USB: Host(int phy) Device(ext phy)\n"); |
| 477 | |
| 478 | } else if (strcmp(act, "dev") == 0) { |
| 479 | /*-------------------PATCH-------------------------------*/ |
| 480 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 481 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 482 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 483 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 484 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 485 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; |
| 486 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 487 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; |
| 488 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 489 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 490 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 491 | |
| 492 | udelay(1000); |
| 493 | mtsdr(SDR0_SRST1, 0x672c6000); |
| 494 | |
| 495 | udelay(1000); |
| 496 | mtsdr(SDR0_SRST0, 0x00000080); |
| 497 | |
| 498 | udelay(1000); |
| 499 | mtsdr(SDR0_SRST1, 0x60206000); |
| 500 | |
| 501 | *(unsigned int *)(0xe0000350) = 0x00000001; |
| 502 | |
| 503 | udelay(1000); |
| 504 | mtsdr(SDR0_SRST1, 0x60306000); |
| 505 | /*-------------------PATCH-------------------------------*/ |
| 506 | |
| 507 | /* SDR Setting */ |
| 508 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 509 | mfsdr(SDR0_USB2H0CR, usb2h0cr); |
| 510 | mfsdr(SDR0_USB2D0CR, usb2d0cr); |
| 511 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 512 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 513 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 514 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; |
| 515 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK; |
| 516 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ; |
| 517 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 518 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; |
| 519 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 520 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV; |
| 521 | usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 522 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 523 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 524 | usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK; |
| 525 | usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 526 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 527 | usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK; |
| 528 | usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 529 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 530 | sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK; |
| 531 | sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 532 | |
| 533 | mtsdr(SDR0_USB2H0CR, usb2h0cr); |
| 534 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 535 | mtsdr(SDR0_USB2D0CR, usb2d0cr); |
| 536 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 537 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 538 | /* clear resets */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 539 | udelay(1000); |
| 540 | mtsdr(SDR0_SRST1, 0x00000000); |
| 541 | udelay(1000); |
| 542 | mtsdr(SDR0_SRST0, 0x00000000); |
| 543 | |
| 544 | printf("USB: Device(int phy)\n"); |
| 545 | } |
| 546 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 547 | mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 548 | reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0); |
| 549 | mtsdr(SDR0_SRST1, reg); |
| 550 | |
| 551 | /* |
| 552 | * Clear PLB4A0_ACR[WRP] |
| 553 | * This fix will make the MAL burst disabling patch for the Linux |
| 554 | * EMAC driver obsolete. |
| 555 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 556 | reg = mfdcr(PLB4_ACR) & ~PLB4_ACR_WRP; |
| 557 | mtdcr(PLB4_ACR, reg); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 558 | |
| 559 | set_serial_number(); |
| 560 | set_mac_addresses(); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 561 | gpio_write_bit(CONFIG_SYS_GPIO_ATMEGA_RESET_, 1); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 562 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | int checkboard(void) |
| 567 | { |
| 568 | char const *const s = getenv("serial#"); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 569 | u8 const rev = in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 570 | |
| 571 | printf("Board: Korat, Rev. %X", rev); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 572 | if (s) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 573 | printf(", serial# %s", s); |
| 574 | |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 575 | printf(".\n Ethernet PHY 0: "); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 576 | if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL)) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 577 | printf("fiber"); |
| 578 | else |
| 579 | printf("copper"); |
| 580 | |
| 581 | printf(", PHY 1: "); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 582 | if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY1_FIBER_SEL)) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 583 | printf("fiber"); |
| 584 | else |
| 585 | printf("copper"); |
| 586 | |
| 587 | printf(".\n"); |
Larry Johnson | 6433fa2 | 2008-03-17 11:10:35 -0500 | [diff] [blame] | 588 | #if defined(CONFIG_KORAT_PERMANENT) |
| 589 | printf(" Executing permanent copy of U-Boot.\n"); |
| 590 | #endif |
| 591 | return 0; |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 594 | #if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP) |
| 595 | /* |
| 596 | * Assign interrupts to PCI devices. |
| 597 | */ |
| 598 | void korat_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 599 | { |
Stefan Roese | 6bd9138 | 2008-07-11 11:40:13 +0200 | [diff] [blame] | 600 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2); |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 601 | } |
| 602 | #endif |
| 603 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 604 | /* |
| 605 | * pci_pre_init |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 606 | * |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 607 | * This routine is called just prior to registering the hose and gives |
| 608 | * the board the opportunity to check things. Returning a value of zero |
| 609 | * indicates that things are bad & PCI initialization should be aborted. |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 610 | * |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 611 | * Different boards may wish to customize the pci controller structure |
| 612 | * (add regions, override default access routines, etc) or perform |
| 613 | * certain pre-initialization actions. |
| 614 | */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 615 | #if defined(CONFIG_PCI) |
| 616 | int pci_pre_init(struct pci_controller *hose) |
| 617 | { |
| 618 | unsigned long addr; |
| 619 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 620 | /* |
| 621 | * Set priority for all PLB3 devices to 0. |
| 622 | * Set PLB3 arbiter to fair mode. |
| 623 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 624 | mfsdr(SD0_AMP1, addr); |
| 625 | mtsdr(SD0_AMP1, (addr & 0x000000FF) | 0x0000FF00); |
| 626 | addr = mfdcr(PLB3_ACR); |
| 627 | mtdcr(PLB3_ACR, addr | 0x80000000); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 628 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 629 | /* |
| 630 | * Set priority for all PLB4 devices to 0. |
| 631 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 632 | mfsdr(SD0_AMP0, addr); |
| 633 | mtsdr(SD0_AMP0, (addr & 0x000000FF) | 0x0000FF00); |
| 634 | addr = mfdcr(PLB4_ACR) | 0xa0000000; /* Was 0x8---- */ |
| 635 | mtdcr(PLB4_ACR, addr); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 636 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 637 | /* |
| 638 | * Set Nebula PLB4 arbiter to fair mode. |
| 639 | */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 640 | /* Segment0 */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 641 | addr = (mfdcr(PLB0_ACR) & ~PLB0_ACR_PPM_MASK) | PLB0_ACR_PPM_FAIR; |
| 642 | addr = (addr & ~PLB0_ACR_HBU_MASK) | PLB0_ACR_HBU_ENABLED; |
| 643 | addr = (addr & ~PLB0_ACR_RDP_MASK) | PLB0_ACR_RDP_4DEEP; |
| 644 | addr = (addr & ~PLB0_ACR_WRP_MASK) | PLB0_ACR_WRP_2DEEP; |
| 645 | mtdcr(PLB0_ACR, addr); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 646 | |
| 647 | /* Segment1 */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 648 | addr = (mfdcr(PLB1_ACR) & ~PLB1_ACR_PPM_MASK) | PLB1_ACR_PPM_FAIR; |
| 649 | addr = (addr & ~PLB1_ACR_HBU_MASK) | PLB1_ACR_HBU_ENABLED; |
| 650 | addr = (addr & ~PLB1_ACR_RDP_MASK) | PLB1_ACR_RDP_4DEEP; |
| 651 | addr = (addr & ~PLB1_ACR_WRP_MASK) | PLB1_ACR_WRP_2DEEP; |
| 652 | mtdcr(PLB1_ACR, addr); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 653 | |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 654 | #if defined(CONFIG_PCI_PNP) |
| 655 | hose->fixup_irq = korat_pci_fixup_irq; |
| 656 | #endif |
| 657 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 658 | return 1; |
| 659 | } |
| 660 | #endif /* defined(CONFIG_PCI) */ |
| 661 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 662 | /* |
| 663 | * pci_target_init |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 664 | * |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 665 | * The bootstrap configuration provides default settings for the pci |
| 666 | * inbound map (PIM). But the bootstrap config choices are limited and |
| 667 | * may not be sufficient for a given board. |
| 668 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 669 | #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 670 | void pci_target_init(struct pci_controller *hose) |
| 671 | { |
Stefan Roese | 1095493 | 2009-11-12 12:00:49 +0100 | [diff] [blame^] | 672 | /* First do 440EP(x) common setup */ |
| 673 | __pci_target_init(hose); |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 674 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 675 | /* |
| 676 | * Set up Configuration registers for on-board NEC uPD720101 USB |
| 677 | * controller. |
| 678 | */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 679 | pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020); |
| 680 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 681 | #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 682 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 683 | #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 684 | void pci_master_init(struct pci_controller *hose) |
| 685 | { |
| 686 | unsigned short temp_short; |
| 687 | |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 688 | /* |
| 689 | * Write the PowerPC440 EP PCI Configuration regs. |
| 690 | * Enable PowerPC440 EP to be a master on the PCI bus (PMM). |
| 691 | * Enable PowerPC440 EP to act as a PCI memory target (PTM). |
| 692 | */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 693 | pci_read_config_word(0, PCI_COMMAND, &temp_short); |
| 694 | pci_write_config_word(0, PCI_COMMAND, |
| 695 | temp_short | PCI_COMMAND_MASTER | |
| 696 | PCI_COMMAND_MEMORY); |
| 697 | } |
| 698 | #endif |
| 699 | |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 700 | #if defined(CONFIG_POST) |
| 701 | /* |
| 702 | * Returns 1 if keys pressed to start the power-on long-running tests |
| 703 | * Called from board_init_f(). |
| 704 | */ |
| 705 | int post_hotkeys_pressed(void) |
| 706 | { |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 707 | return 0; /* No hotkeys supported */ |
Larry Johnson | c591dff | 2007-12-27 11:28:51 -0500 | [diff] [blame] | 708 | } |
Larry Johnson | 3259eea | 2008-01-17 08:50:09 -0500 | [diff] [blame] | 709 | #endif /* CONFIG_POST */ |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 710 | |
| 711 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 712 | void ft_board_setup(void *blob, bd_t *bd) |
| 713 | { |
| 714 | u32 val[4]; |
| 715 | int rc; |
| 716 | |
| 717 | ft_cpu_setup(blob, bd); |
| 718 | |
| 719 | /* Fixup NOR mapping */ |
| 720 | val[0] = 1; /* chip select number */ |
| 721 | val[1] = 0; /* always 0 */ |
| 722 | val[2] = gd->bd->bi_flashstart; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 723 | val[3] = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE; |
Larry Johnson | 47ce4a2 | 2008-06-14 16:53:02 -0400 | [diff] [blame] | 724 | rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges", |
| 725 | val, sizeof(val), 1); |
| 726 | if (rc) |
| 727 | printf("Unable to update property NOR mapping, err=%s\n", |
| 728 | fdt_strerror(rc)); |
| 729 | } |
| 730 | #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */ |