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