blob: d9ab2fd421651df92c7784424cb7dc0441835056 [file] [log] [blame]
Larry Johnson667a3d42007-12-27 11:28:51 -05001/*
Larry Johnsonabca6f02010-04-20 08:11:40 -04002 * (C) Copyright 2007-2010
Larry Johnson667a3d42007-12-27 11:28:51 -05003 * Larry Johnson, lrj@acm.org
4 *
Larry Johnson67682672008-03-17 11:10:35 -05005 * (C) Copyright 2006-2007
Larry Johnson667a3d42007-12-27 11:28:51 -05006 * 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 Johnson67682672008-03-17 11:10:35 -050010 * Alain Saurel, AMCC/IBM, alain.saurel@fr.ibm.com
Larry Johnson667a3d42007-12-27 11:28:51 -050011 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Larry Johnson667a3d42007-12-27 11:28:51 -050013 */
14
15#include <common.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040016#include <fdt_support.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050017#include <i2c.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040018#include <libfdt.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020019#include <asm/ppc440.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040020#include <asm/bitops.h>
Stefan Roesede21eab2010-09-16 14:30:37 +020021#include <asm/ppc4xx-gpio.h>
Larry Johnsone17c6f72008-01-17 08:50:09 -050022#include <asm/io.h>
Stefan Roese4e36fa02008-07-11 11:40:13 +020023#include <asm/ppc4xx-uic.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040024#include <asm/processor.h>
Stefan Roese8e538be2009-11-12 12:00:49 +010025#include <asm/4xx_pci.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050026
27DECLARE_GLOBAL_DATA_PTR;
28
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Larry Johnson667a3d42007-12-27 11:28:51 -050030
31ulong flash_get_size(ulong base, int banknum);
32
Larry Johnson67682672008-03-17 11:10:35 -050033#if defined(CONFIG_KORAT_PERMANENT)
34void korat_buzzer(int const on)
35{
36 if (on) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
38 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) | 0x80);
Larry Johnson67682672008-03-17 11:10:35 -050039 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
41 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) & ~0x80);
Larry Johnson67682672008-03-17 11:10:35 -050042 }
43}
44#endif
45
Larry Johnson667a3d42007-12-27 11:28:51 -050046int board_early_init_f(void)
47{
Larry Johnson67682672008-03-17 11:10:35 -050048 uint32_t sdr0_pfc1, sdr0_pfc2;
49 uint32_t reg;
Larry Johnson667a3d42007-12-27 11:28:51 -050050 int eth;
51
Larry Johnson67682672008-03-17 11:10:35 -050052#if defined(CONFIG_KORAT_PERMANENT)
53 unsigned mscount;
54
55 extern void korat_branch_absolute(uint32_t addr);
56
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 for (mscount = 0; mscount < CONFIG_SYS_KORAT_MAN_RESET_MS; ++mscount) {
Larry Johnson67682672008-03-17 11:10:35 -050058 udelay(1000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 if (gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) {
Larry Johnson67682672008-03-17 11:10:35 -050060 /* This call does not return. */
61 korat_branch_absolute(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020062 CONFIG_SYS_FLASH1_TOP - 2 * CONFIG_ENV_SECT_SIZE - 4);
Larry Johnson67682672008-03-17 11:10:35 -050063 }
64 }
65 korat_buzzer(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066 while (!gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_))
Larry Johnson67682672008-03-17 11:10:35 -050067 udelay(1000);
68
69 korat_buzzer(0);
70#endif
71
Stefan Roese918010a2009-09-09 16:25:29 +020072 mtdcr(EBC0_CFGADDR, EBC0_CFG);
73 mtdcr(EBC0_CFGDATA, 0xb8400000);
Larry Johnson667a3d42007-12-27 11:28:51 -050074
Larry Johnsone17c6f72008-01-17 08:50:09 -050075 /*
Larry Johnson667a3d42007-12-27 11:28:51 -050076 * Setup the interrupt controller polarities, triggers, etc.
Larry Johnsone17c6f72008-01-17 08:50:09 -050077 */
Stefan Roese707fd362009-09-24 09:55:50 +020078 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 */
Larry Johnson667a3d42007-12-27 11:28:51 -050085
Stefan Roese707fd362009-09-24 09:55:50 +020086 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 */
Larry Johnson667a3d42007-12-27 11:28:51 -050093
Stefan Roese707fd362009-09-24 09:55:50 +020094 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 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500101
Larry Johnson67682672008-03-17 11:10:35 -0500102 /*
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 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02, 0xC0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500107
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 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500111 for (eth = 0; eth < 2; ++eth) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 if (gpio_read_in_bit(CONFIG_SYS_GPIO_SFP0_PRESENT_ + eth)) {
Larry Johnson667a3d42007-12-27 11:28:51 -0500113 /* SFP module not present: configure PHY for copper. */
114 /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
116 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) |
Larry Johnson667a3d42007-12-27 11:28:51 -0500117 0x06 << (4 * eth));
118 } else {
119 /* SFP module present: configure PHY for fiber and
120 enable output */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL + eth, 1);
122 gpio_write_bit(CONFIG_SYS_GPIO_SFP0_TX_EN_ + eth, 0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500123 }
124 }
125 /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_EN, 1);
127 gpio_write_bit(CONFIG_SYS_GPIO_PHY1_EN, 1);
Larry Johnson667a3d42007-12-27 11:28:51 -0500128
Larry Johnson67682672008-03-17 11:10:35 -0500129 /* Wait 1 ms, then enable Fiber signal detect to PHYs. */
130 udelay(1000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
132 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) | 0x88);
Larry Johnson67682672008-03-17 11:10:35 -0500133
134 /* select Ethernet (and optionally IIC1) pins */
Larry Johnson667a3d42007-12-27 11:28:51 -0500135 mfsdr(SDR0_PFC1, sdr0_pfc1);
136 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500137 SDR0_PFC1_SELECT_CONFIG_4;
Larry Johnson67682672008-03-17 11:10:35 -0500138#ifdef CONFIG_I2C_MULTI_BUS
139 sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
140#endif
Larry Johnson667a3d42007-12-27 11:28:51 -0500141 mfsdr(SDR0_PFC2, sdr0_pfc2);
142 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500143 SDR0_PFC2_SELECT_CONFIG_4;
Larry Johnson667a3d42007-12-27 11:28:51 -0500144 mtsdr(SDR0_PFC2, sdr0_pfc2);
145 mtsdr(SDR0_PFC1, sdr0_pfc1);
146
147 /* PCI arbiter enabled */
Stefan Roese918010a2009-09-09 16:25:29 +0200148 mfsdr(SDR0_PCI0, reg);
149 mtsdr(SDR0_PCI0, 0x80000000 | reg);
Larry Johnson667a3d42007-12-27 11:28:51 -0500150
151 return 0;
152}
153
Larry Johnson67682672008-03-17 11:10:35 -0500154/*
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 */
159ulong 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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200167 info->size = CONFIG_SYS_FLASH0_SIZE;
168 info->sector_count = CONFIG_SYS_FLASH0_SIZE / 0x20000;
Larry Johnson67682672008-03-17 11:10:35 -0500169 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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200183#if CONFIG_SYS_FLASH0_SIZE == 0x01000000
Larry Johnson67682672008-03-17 11:10:35 -0500184 info->device_id2 = 0x2101;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200185#elif CONFIG_SYS_FLASH0_SIZE == 0x04000000
Larry Johnson67682672008-03-17 11:10:35 -0500186 info->device_id2 = 0x2301;
187#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200188#error Unable to set device_id2 for current CONFIG_SYS_FLASH0_SIZE
Larry Johnson67682672008-03-17 11:10:35 -0500189#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
Larry Johnson667a3d42007-12-27 11:28:51 -0500206static 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
223static 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
243static 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
273static 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 */
Larry Johnson67682672008-03-17 11:10:35 -0500279 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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500286
Larry Johnson67682672008-03-17 11:10:35 -0500287 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;
291
292 setenv("serial#", s);
Larry Johnson667a3d42007-12-27 11:28:51 -0500293}
294
295static 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 */
Larry Johnson67682672008-03-17 11:10:35 -0500302
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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500310
311 if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
312 return;
313
Larry Johnson67682672008-03-17 11:10:35 -0500314 if (0 == man_data_read_field(s + (MAN_MAC_ADDR_LENGTH / 2) - 1,
315 MAN_MAC_ADDR_FIELD, MAN_MAC_ADDR_LENGTH))
Larry Johnson667a3d42007-12-27 11:28:51 -0500316 return;
317
Larry Johnson67682672008-03-17 11:10:35 -0500318 for (src = s + (MAN_MAC_ADDR_LENGTH / 2) - 1, dst = s; src != dst;) {
319 *dst++ = *src++;
320 *dst++ = *src++;
321 *dst++ = ':';
322 }
Larry Johnson667a3d42007-12-27 11:28:51 -0500323 if (0 == getenv("ethaddr"))
324 setenv("ethaddr", s);
325
326 if (0 == getenv("eth1addr")) {
Larry Johnson67682672008-03-17 11:10:35 -0500327 ++s[((3 * MAN_MAC_ADDR_LENGTH) / 2) - 2];
Larry Johnson667a3d42007-12-27 11:28:51 -0500328 setenv("eth1addr", s);
329 }
330}
331
Larry Johnson667a3d42007-12-27 11:28:51 -0500332int misc_init_r(void)
333{
Larry Johnson67682672008-03-17 11:10:35 -0500334 uint32_t pbcr;
335 int size_val;
336 uint32_t reg;
Larry Johnson667a3d42007-12-27 11:28:51 -0500337 unsigned long usb2d0cr = 0;
338 unsigned long usb2phy0cr, usb2h0cr = 0;
339 unsigned long sdr0_pfc1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200340 uint32_t const flash1_size = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
Larry Johnson67682672008-03-17 11:10:35 -0500341 char const *const act = getenv("usbact");
Larry Johnsona47dc142009-01-28 15:30:02 -0500342 char const *const usbcf = getenv("korat_usbcf");
Larry Johnson667a3d42007-12-27 11:28:51 -0500343
Larry Johnson67682672008-03-17 11:10:35 -0500344 /*
345 * Re-do FLASH1 sizing and adjust flash start and offset.
346 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200347 gd->bd->bi_flashstart = CONFIG_SYS_FLASH1_TOP - flash1_size;
Larry Johnson667a3d42007-12-27 11:28:51 -0500348 gd->bd->bi_flashoffset = 0;
349
Stefan Roese918010a2009-09-09 16:25:29 +0200350 mtdcr(EBC0_CFGADDR, PB1CR);
351 pbcr = mfdcr(EBC0_CFGDATA);
Larry Johnson67682672008-03-17 11:10:35 -0500352 size_val = ffs(flash1_size) - 21;
Larry Johnson667a3d42007-12-27 11:28:51 -0500353 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roese918010a2009-09-09 16:25:29 +0200354 mtdcr(EBC0_CFGADDR, PB1CR);
355 mtdcr(EBC0_CFGDATA, pbcr);
Larry Johnson667a3d42007-12-27 11:28:51 -0500356
357 /*
358 * Re-check to get correct base address
359 */
360 flash_get_size(gd->bd->bi_flashstart, 0);
361
Larry Johnson67682672008-03-17 11:10:35 -0500362 /*
363 * Re-do FLASH1 sizing and adjust flash offset to reserve space for
364 * environment
365 */
366 gd->bd->bi_flashoffset =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200367 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - CONFIG_SYS_FLASH1_ADDR;
Larry Johnson67682672008-03-17 11:10:35 -0500368
Stefan Roese918010a2009-09-09 16:25:29 +0200369 mtdcr(EBC0_CFGADDR, PB1CR);
370 pbcr = mfdcr(EBC0_CFGDATA);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200371 size_val = ffs(gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE) - 21;
Larry Johnson67682672008-03-17 11:10:35 -0500372 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roese918010a2009-09-09 16:25:29 +0200373 mtdcr(EBC0_CFGADDR, PB1CR);
374 mtdcr(EBC0_CFGDATA, pbcr);
Larry Johnson667a3d42007-12-27 11:28:51 -0500375
Larry Johnson67682672008-03-17 11:10:35 -0500376 /* Monitor protection ON by default */
377#if defined(CONFIG_KORAT_PERMANENT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200378 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
379 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500380 flash_info + 1);
381#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200382 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
383 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500384 flash_info);
385#endif
Larry Johnson667a3d42007-12-27 11:28:51 -0500386 /* Env protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200387 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
388 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500389 flash_info);
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200390 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
391 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500392 flash_info);
Larry Johnson667a3d42007-12-27 11:28:51 -0500393
394 /*
395 * USB suff...
396 */
Larry Johnsona47dc142009-01-28 15:30:02 -0500397 /*
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 */
Larry Johnsonabca6f02010-04-20 08:11:40 -0400407 printf("Attaching CompactFlash controller to PPC USB\n");
Larry Johnsona47dc142009-01-28 15:30:02 -0500408 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
Larry Johnsonabca6f02010-04-20 08:11:40 -0400415 printf("Attaching CompactFlash controller to PCI USB\n");
Larry Johnsona47dc142009-01-28 15:30:02 -0500416 }
Larry Johnson667a3d42007-12-27 11:28:51 -0500417 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
Larry Johnsone17c6f72008-01-17 08:50:09 -0500424 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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500434
Larry Johnsone17c6f72008-01-17 08:50:09 -0500435 /*
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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500441
Larry Johnsone17c6f72008-01-17 08:50:09 -0500442 /*
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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500448
Larry Johnsone17c6f72008-01-17 08:50:09 -0500449 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
450 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500451
452 mtsdr(SDR0_PFC1, sdr0_pfc1);
453 mtsdr(SDR0_USB2D0CR, usb2d0cr);
454 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
455 mtsdr(SDR0_USB2H0CR, usb2h0cr);
456
Larry Johnsone17c6f72008-01-17 08:50:09 -0500457 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500458 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
Larry Johnsone17c6f72008-01-17 08:50:09 -0500469 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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500477 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
Larry Johnsone17c6f72008-01-17 08:50:09 -0500500 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;
Larry Johnson667a3d42007-12-27 11:28:51 -0500510
Larry Johnsone17c6f72008-01-17 08:50:09 -0500511 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
512 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
Larry Johnson667a3d42007-12-27 11:28:51 -0500513
Larry Johnsone17c6f72008-01-17 08:50:09 -0500514 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
515 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
Larry Johnson667a3d42007-12-27 11:28:51 -0500516
Larry Johnsone17c6f72008-01-17 08:50:09 -0500517 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
518 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500519
520 mtsdr(SDR0_USB2H0CR, usb2h0cr);
521 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
522 mtsdr(SDR0_USB2D0CR, usb2d0cr);
523 mtsdr(SDR0_PFC1, sdr0_pfc1);
524
Larry Johnsone17c6f72008-01-17 08:50:09 -0500525 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500526 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
Larry Johnsone17c6f72008-01-17 08:50:09 -0500534 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
Larry Johnson667a3d42007-12-27 11:28:51 -0500535 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 */
Stefan Roese95ca5fa2010-09-11 09:31:43 +0200543 reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
544 mtdcr(PLB4A0_ACR, reg);
Larry Johnson667a3d42007-12-27 11:28:51 -0500545
546 set_serial_number();
547 set_mac_addresses();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200548 gpio_write_bit(CONFIG_SYS_GPIO_ATMEGA_RESET_, 1);
Larry Johnson67682672008-03-17 11:10:35 -0500549
Larry Johnson667a3d42007-12-27 11:28:51 -0500550 return 0;
551}
552
553int checkboard(void)
554{
555 char const *const s = getenv("serial#");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200556 u8 const rev = in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500557
558 printf("Board: Korat, Rev. %X", rev);
Larry Johnson67682672008-03-17 11:10:35 -0500559 if (s)
Larry Johnson667a3d42007-12-27 11:28:51 -0500560 printf(", serial# %s", s);
561
Larry Johnson67682672008-03-17 11:10:35 -0500562 printf(".\n Ethernet PHY 0: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200563 if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500564 printf("fiber");
565 else
566 printf("copper");
567
568 printf(", PHY 1: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200569 if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY1_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500570 printf("fiber");
571 else
572 printf("copper");
573
574 printf(".\n");
Larry Johnson67682672008-03-17 11:10:35 -0500575#if defined(CONFIG_KORAT_PERMANENT)
576 printf(" Executing permanent copy of U-Boot.\n");
577#endif
578 return 0;
Larry Johnson667a3d42007-12-27 11:28:51 -0500579}
580
Larry Johnsonfc391002008-06-14 16:53:02 -0400581#if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
582/*
583 * Assign interrupts to PCI devices.
584 */
Stefan Roese5d8033e2009-11-12 16:41:09 +0100585void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
Larry Johnsonfc391002008-06-14 16:53:02 -0400586{
Stefan Roese4e36fa02008-07-11 11:40:13 +0200587 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
Larry Johnsonfc391002008-06-14 16:53:02 -0400588}
589#endif
590
Larry Johnsone17c6f72008-01-17 08:50:09 -0500591/*
Larry Johnsone17c6f72008-01-17 08:50:09 -0500592 * pci_target_init
Larry Johnson667a3d42007-12-27 11:28:51 -0500593 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500594 * 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 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200598#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
Larry Johnson667a3d42007-12-27 11:28:51 -0500599void pci_target_init(struct pci_controller *hose)
600{
Stefan Roese8e538be2009-11-12 12:00:49 +0100601 /* First do 440EP(x) common setup */
602 __pci_target_init(hose);
Larry Johnson667a3d42007-12-27 11:28:51 -0500603
Larry Johnsone17c6f72008-01-17 08:50:09 -0500604 /*
605 * Set up Configuration registers for on-board NEC uPD720101 USB
606 * controller.
607 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500608 pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
609}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200610#endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
Larry Johnson667a3d42007-12-27 11:28:51 -0500611
Larry Johnsonfc391002008-06-14 16:53:02 -0400612#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600613int ft_board_setup(void *blob, bd_t *bd)
Larry Johnsonfc391002008-06-14 16:53:02 -0400614{
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;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200624 val[3] = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
Larry Johnsonfc391002008-06-14 16:53:02 -0400625 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));
Simon Glass2aec3cc2014-10-23 18:58:47 -0600630
631 return 0;
Larry Johnsonfc391002008-06-14 16:53:02 -0400632}
633#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */