blob: 8328ba326dbd3ca2a9ea7960627ba4f57e0b5836 [file] [log] [blame]
Larry Johnson667a3d42007-12-27 11:28:51 -05001/*
Larry Johnsona47dc142009-01-28 15:30:02 -05002 * (C) Copyright 2007-2009
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 *
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 Johnsonfc391002008-06-14 16:53:02 -040029#include <fdt_support.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050030#include <i2c.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040031#include <libfdt.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050032#include <ppc440.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040033#include <asm/bitops.h>
Larry Johnsone17c6f72008-01-17 08:50:09 -050034#include <asm/gpio.h>
Larry Johnsone17c6f72008-01-17 08:50:09 -050035#include <asm/io.h>
Stefan Roese4e36fa02008-07-11 11:40:13 +020036#include <asm/ppc4xx-uic.h>
Larry Johnsonfc391002008-06-14 16:53:02 -040037#include <asm/processor.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050038
39DECLARE_GLOBAL_DATA_PTR;
40
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Larry Johnson667a3d42007-12-27 11:28:51 -050042
43ulong flash_get_size(ulong base, int banknum);
44
Larry Johnson67682672008-03-17 11:10:35 -050045#if defined(CONFIG_KORAT_PERMANENT)
46void korat_buzzer(int const on)
47{
48 if (on) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
50 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) | 0x80);
Larry Johnson67682672008-03-17 11:10:35 -050051 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05,
53 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x05) & ~0x80);
Larry Johnson67682672008-03-17 11:10:35 -050054 }
55}
56#endif
57
Larry Johnson667a3d42007-12-27 11:28:51 -050058int board_early_init_f(void)
59{
Larry Johnson67682672008-03-17 11:10:35 -050060 uint32_t sdr0_pfc1, sdr0_pfc2;
61 uint32_t reg;
Larry Johnson667a3d42007-12-27 11:28:51 -050062 int eth;
63
Larry Johnson67682672008-03-17 11:10:35 -050064#if defined(CONFIG_KORAT_PERMANENT)
65 unsigned mscount;
66
67 extern void korat_branch_absolute(uint32_t addr);
68
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069 for (mscount = 0; mscount < CONFIG_SYS_KORAT_MAN_RESET_MS; ++mscount) {
Larry Johnson67682672008-03-17 11:10:35 -050070 udelay(1000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 if (gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_)) {
Larry Johnson67682672008-03-17 11:10:35 -050072 /* This call does not return. */
73 korat_branch_absolute(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074 CONFIG_SYS_FLASH1_TOP - 2 * CONFIG_ENV_SECT_SIZE - 4);
Larry Johnson67682672008-03-17 11:10:35 -050075 }
76 }
77 korat_buzzer(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 while (!gpio_read_in_bit(CONFIG_SYS_GPIO_RESET_PRESSED_))
Larry Johnson67682672008-03-17 11:10:35 -050079 udelay(1000);
80
81 korat_buzzer(0);
82#endif
83
Larry Johnson667a3d42007-12-27 11:28:51 -050084 mtdcr(ebccfga, xbcfg);
85 mtdcr(ebccfgd, 0xb8400000);
86
Larry Johnsone17c6f72008-01-17 08:50:09 -050087 /*
Larry Johnson667a3d42007-12-27 11:28:51 -050088 * Setup the interrupt controller polarities, triggers, etc.
Larry Johnsone17c6f72008-01-17 08:50:09 -050089 */
Larry Johnson667a3d42007-12-27 11:28:51 -050090 mtdcr(uic0sr, 0xffffffff); /* clear all */
91 mtdcr(uic0er, 0x00000000); /* disable all */
92 mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
93 mtdcr(uic0pr, 0xfffff7ff); /* per ref-board manual */
94 mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
95 mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
96 mtdcr(uic0sr, 0xffffffff); /* clear all */
97
98 mtdcr(uic1sr, 0xffffffff); /* clear all */
99 mtdcr(uic1er, 0x00000000); /* disable all */
100 mtdcr(uic1cr, 0x00000000); /* all non-critical */
101 mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */
102 mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
103 mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
104 mtdcr(uic1sr, 0xffffffff); /* clear all */
105
106 mtdcr(uic2sr, 0xffffffff); /* clear all */
107 mtdcr(uic2er, 0x00000000); /* disable all */
108 mtdcr(uic2cr, 0x00000000); /* all non-critical */
109 mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
110 mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
111 mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
112 mtdcr(uic2sr, 0xffffffff); /* clear all */
113
Larry Johnson67682672008-03-17 11:10:35 -0500114 /*
115 * Take sim card reader and CF controller out of reset. Also enable PHY
116 * auto-detect until board-specific PHY resets are available.
117 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02, 0xC0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500119
120 /* Configure the two Ethernet PHYs. For each PHY, configure for fiber
121 * if the SFP module is present, and for copper if it is not present.
122 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500123 for (eth = 0; eth < 2; ++eth) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200124 if (gpio_read_in_bit(CONFIG_SYS_GPIO_SFP0_PRESENT_ + eth)) {
Larry Johnson667a3d42007-12-27 11:28:51 -0500125 /* SFP module not present: configure PHY for copper. */
126 /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
128 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) |
Larry Johnson667a3d42007-12-27 11:28:51 -0500129 0x06 << (4 * eth));
130 } else {
131 /* SFP module present: configure PHY for fiber and
132 enable output */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL + eth, 1);
134 gpio_write_bit(CONFIG_SYS_GPIO_SFP0_TX_EN_ + eth, 0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500135 }
136 }
137 /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_EN, 1);
139 gpio_write_bit(CONFIG_SYS_GPIO_PHY1_EN, 1);
Larry Johnson667a3d42007-12-27 11:28:51 -0500140
Larry Johnson67682672008-03-17 11:10:35 -0500141 /* Wait 1 ms, then enable Fiber signal detect to PHYs. */
142 udelay(1000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03,
144 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x03) | 0x88);
Larry Johnson67682672008-03-17 11:10:35 -0500145
146 /* select Ethernet (and optionally IIC1) pins */
Larry Johnson667a3d42007-12-27 11:28:51 -0500147 mfsdr(SDR0_PFC1, sdr0_pfc1);
148 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500149 SDR0_PFC1_SELECT_CONFIG_4;
Larry Johnson67682672008-03-17 11:10:35 -0500150#ifdef CONFIG_I2C_MULTI_BUS
151 sdr0_pfc1 |= ((sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL);
152#endif
Larry Johnson667a3d42007-12-27 11:28:51 -0500153 mfsdr(SDR0_PFC2, sdr0_pfc2);
154 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500155 SDR0_PFC2_SELECT_CONFIG_4;
Larry Johnson667a3d42007-12-27 11:28:51 -0500156 mtsdr(SDR0_PFC2, sdr0_pfc2);
157 mtsdr(SDR0_PFC1, sdr0_pfc1);
158
159 /* PCI arbiter enabled */
160 mfsdr(sdr_pci0, reg);
161 mtsdr(sdr_pci0, 0x80000000 | reg);
162
163 return 0;
164}
165
Larry Johnson67682672008-03-17 11:10:35 -0500166/*
167 * The boot flash on CS0 normally has its write-enable pin disabled, and so will
168 * not respond to CFI commands. This routine therefore fills in the flash
169 * information for the boot flash. (The flash at CS1 operates normally.)
170 */
171ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
172{
173 uint32_t addr;
174 int i;
175
176 if (1 != banknum)
177 return 0;
178
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200179 info->size = CONFIG_SYS_FLASH0_SIZE;
180 info->sector_count = CONFIG_SYS_FLASH0_SIZE / 0x20000;
Larry Johnson67682672008-03-17 11:10:35 -0500181 info->flash_id = 0x01000000;
182 info->portwidth = 2;
183 info->chipwidth = 2;
184 info->buffer_size = 32;
185 info->erase_blk_tout = 16384;
186 info->write_tout = 2;
187 info->buffer_write_tout = 5;
188 info->vendor = 2;
189 info->cmd_reset = 0x00F0;
190 info->interface = 2;
191 info->legacy_unlock = 0;
192 info->manufacturer_id = 1;
193 info->device_id = 0x007E;
194
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200195#if CONFIG_SYS_FLASH0_SIZE == 0x01000000
Larry Johnson67682672008-03-17 11:10:35 -0500196 info->device_id2 = 0x2101;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200197#elif CONFIG_SYS_FLASH0_SIZE == 0x04000000
Larry Johnson67682672008-03-17 11:10:35 -0500198 info->device_id2 = 0x2301;
199#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200200#error Unable to set device_id2 for current CONFIG_SYS_FLASH0_SIZE
Larry Johnson67682672008-03-17 11:10:35 -0500201#endif
202
203 info->ext_addr = 0x0040;
204 info->cfi_version = 0x3133;
205 info->cfi_offset = 0x0055;
206 info->addr_unlock1 = 0x00000555;
207 info->addr_unlock2 = 0x000002AA;
208 info->name = "CFI conformant";
209 for (i = 0, addr = -info->size;
210 i < info->sector_count;
211 ++i, addr += 0x20000) {
212 info->start[i] = addr;
213 info->protect[i] = 0x00;
214 }
215 return 1;
216}
217
Larry Johnson667a3d42007-12-27 11:28:51 -0500218static int man_data_read(unsigned int addr)
219{
220 /*
221 * Read an octet of data from address "addr" in the manufacturer's
222 * information serial EEPROM, or -1 on error.
223 */
224 u8 data[2];
225
226 if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) ||
227 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) {
228 debug("man_data_read(0x%02X) failed\n", addr);
229 return -1;
230 }
231 debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]);
232 return data[0];
233}
234
235static unsigned int man_data_field_addr(unsigned int const field)
236{
237 /*
238 * The manufacturer's information serial EEPROM contains a sequence of
239 * zero-delimited fields. Return the starting address of field "field",
240 * or 0 on error.
241 */
242 unsigned addr, i;
243
244 if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1))
245 /* Only format "A" is currently supported */
246 return 0;
247
248 for (addr = 2, i = 1; i < field && addr < 256; ++addr) {
249 if ('\0' == man_data_read(addr))
250 ++i;
251 }
252 return (addr < 256) ? addr : 0;
253}
254
255static char *man_data_read_field(char s[], unsigned const field,
256 unsigned const length)
257{
258 /*
259 * Place the null-terminated contents of field "field" of length
260 * "length" from the manufacturer's information serial EEPROM into
261 * string "s[length + 1]" and return a pointer to s, or return 0 on
262 * error. In either case the original contents of s[] is not preserved.
263 */
264 unsigned addr, i;
265
266 addr = man_data_field_addr(field);
267 if (0 == addr || addr + length >= 255)
268 return 0;
269
270 for (i = 0; i < length; ++i) {
271 int const c = man_data_read(addr++);
272
273 if (c <= 0)
274 return 0;
275
276 s[i] = (char)c;
277 }
278 if (0 != man_data_read(addr))
279 return 0;
280
281 s[i] = '\0';
282 return s;
283}
284
285static void set_serial_number(void)
286{
287 /*
288 * If the environmental variable "serial#" is not set, try to set it
289 * from the manufacturer's information serial EEPROM.
290 */
Larry Johnson67682672008-03-17 11:10:35 -0500291 char s[MAN_INFO_LENGTH + MAN_MAC_ADDR_LENGTH + 2];
292
293 if (getenv("serial#"))
294 return;
295
296 if (!man_data_read_field(s, MAN_INFO_FIELD, MAN_INFO_LENGTH))
297 return;
Larry Johnson667a3d42007-12-27 11:28:51 -0500298
Larry Johnson67682672008-03-17 11:10:35 -0500299 s[MAN_INFO_LENGTH] = '-';
300 if (!man_data_read_field(s + MAN_INFO_LENGTH + 1, MAN_MAC_ADDR_FIELD,
301 MAN_MAC_ADDR_LENGTH))
302 return;
303
304 setenv("serial#", s);
Larry Johnson667a3d42007-12-27 11:28:51 -0500305}
306
307static void set_mac_addresses(void)
308{
309 /*
310 * If the environmental variables "ethaddr" and/or "eth1addr" are not
311 * set, try to set them from the manufacturer's information serial
312 * EEPROM.
313 */
Larry Johnson67682672008-03-17 11:10:35 -0500314
315#if MAN_MAC_ADDR_LENGTH % 2 != 0
316#error MAN_MAC_ADDR_LENGTH must be an even number
317#endif
318
319 char s[(3 * MAN_MAC_ADDR_LENGTH) / 2];
320 char *src;
321 char *dst;
Larry Johnson667a3d42007-12-27 11:28:51 -0500322
323 if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
324 return;
325
Larry Johnson67682672008-03-17 11:10:35 -0500326 if (0 == man_data_read_field(s + (MAN_MAC_ADDR_LENGTH / 2) - 1,
327 MAN_MAC_ADDR_FIELD, MAN_MAC_ADDR_LENGTH))
Larry Johnson667a3d42007-12-27 11:28:51 -0500328 return;
329
Larry Johnson67682672008-03-17 11:10:35 -0500330 for (src = s + (MAN_MAC_ADDR_LENGTH / 2) - 1, dst = s; src != dst;) {
331 *dst++ = *src++;
332 *dst++ = *src++;
333 *dst++ = ':';
334 }
Larry Johnson667a3d42007-12-27 11:28:51 -0500335 if (0 == getenv("ethaddr"))
336 setenv("ethaddr", s);
337
338 if (0 == getenv("eth1addr")) {
Larry Johnson67682672008-03-17 11:10:35 -0500339 ++s[((3 * MAN_MAC_ADDR_LENGTH) / 2) - 2];
Larry Johnson667a3d42007-12-27 11:28:51 -0500340 setenv("eth1addr", s);
341 }
342}
343
Larry Johnson667a3d42007-12-27 11:28:51 -0500344int misc_init_r(void)
345{
Larry Johnson67682672008-03-17 11:10:35 -0500346 uint32_t pbcr;
347 int size_val;
348 uint32_t reg;
Larry Johnson667a3d42007-12-27 11:28:51 -0500349 unsigned long usb2d0cr = 0;
350 unsigned long usb2phy0cr, usb2h0cr = 0;
351 unsigned long sdr0_pfc1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200352 uint32_t const flash1_size = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
Larry Johnson67682672008-03-17 11:10:35 -0500353 char const *const act = getenv("usbact");
Larry Johnsona47dc142009-01-28 15:30:02 -0500354 char const *const usbcf = getenv("korat_usbcf");
Larry Johnson667a3d42007-12-27 11:28:51 -0500355
Larry Johnson67682672008-03-17 11:10:35 -0500356 /*
357 * Re-do FLASH1 sizing and adjust flash start and offset.
358 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200359 gd->bd->bi_flashstart = CONFIG_SYS_FLASH1_TOP - flash1_size;
Larry Johnson667a3d42007-12-27 11:28:51 -0500360 gd->bd->bi_flashoffset = 0;
361
Larry Johnson67682672008-03-17 11:10:35 -0500362 mtdcr(ebccfga, pb1cr);
Larry Johnson667a3d42007-12-27 11:28:51 -0500363 pbcr = mfdcr(ebccfgd);
Larry Johnson67682672008-03-17 11:10:35 -0500364 size_val = ffs(flash1_size) - 21;
Larry Johnson667a3d42007-12-27 11:28:51 -0500365 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Larry Johnson67682672008-03-17 11:10:35 -0500366 mtdcr(ebccfga, pb1cr);
Larry Johnson667a3d42007-12-27 11:28:51 -0500367 mtdcr(ebccfgd, pbcr);
368
369 /*
370 * Re-check to get correct base address
371 */
372 flash_get_size(gd->bd->bi_flashstart, 0);
373
Larry Johnson67682672008-03-17 11:10:35 -0500374 /*
375 * Re-do FLASH1 sizing and adjust flash offset to reserve space for
376 * environment
377 */
378 gd->bd->bi_flashoffset =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200379 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - CONFIG_SYS_FLASH1_ADDR;
Larry Johnson67682672008-03-17 11:10:35 -0500380
381 mtdcr(ebccfga, pb1cr);
382 pbcr = mfdcr(ebccfgd);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200383 size_val = ffs(gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE) - 21;
Larry Johnson67682672008-03-17 11:10:35 -0500384 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
385 mtdcr(ebccfga, pb1cr);
386 mtdcr(ebccfgd, pbcr);
Larry Johnson667a3d42007-12-27 11:28:51 -0500387
Larry Johnson67682672008-03-17 11:10:35 -0500388 /* Monitor protection ON by default */
389#if defined(CONFIG_KORAT_PERMANENT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200390 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
391 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500392 flash_info + 1);
393#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200394 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
395 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500396 flash_info);
397#endif
Larry Johnson667a3d42007-12-27 11:28:51 -0500398 /* Env protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200399 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
400 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500401 flash_info);
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200402 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
403 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Larry Johnson67682672008-03-17 11:10:35 -0500404 flash_info);
Larry Johnson667a3d42007-12-27 11:28:51 -0500405
406 /*
407 * USB suff...
408 */
Larry Johnsona47dc142009-01-28 15:30:02 -0500409 /*
410 * Select the USB controller on the 440EPx ("ppc") or on the PCI bus
411 * ("pci") for the CompactFlash.
412 */
413 if (usbcf != NULL && (strcmp(usbcf, "ppc") == 0)) {
414 /*
415 * If environment variable "usbcf" is defined and set to "ppc",
416 * then connect the CompactFlash controller to the PowerPC USB
417 * port.
418 */
419 printf("Attaching CompactFalsh controller to PPC USB\n");
420 out_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02,
421 in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0x02) | 0x10);
422 } else {
423 if (usbcf != NULL && (strcmp(usbcf, "pci") != 0))
424 printf("Warning: \"korat_usbcf\" is not set to a legal "
425 "value (\"ppc\" or \"pci\")\n");
426
427 printf("Attaching CompactFalsh controller to PCI USB\n");
428 }
Larry Johnson667a3d42007-12-27 11:28:51 -0500429 if (act == NULL || strcmp(act, "hostdev") == 0) {
430 /* SDR Setting */
431 mfsdr(SDR0_PFC1, sdr0_pfc1);
432 mfsdr(SDR0_USB2D0CR, usb2d0cr);
433 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
434 mfsdr(SDR0_USB2H0CR, usb2h0cr);
435
Larry Johnsone17c6f72008-01-17 08:50:09 -0500436 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
437 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
438 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
439 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
440 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
441 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
442 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
443 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
444 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
445 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Larry Johnson667a3d42007-12-27 11:28:51 -0500446
Larry Johnsone17c6f72008-01-17 08:50:09 -0500447 /*
448 * An 8-bit/60MHz interface is the only possible alternative
449 * when connecting the Device to the PHY
450 */
451 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
452 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
Larry Johnson667a3d42007-12-27 11:28:51 -0500453
Larry Johnsone17c6f72008-01-17 08:50:09 -0500454 /*
455 * To enable the USB 2.0 Device function
456 * through the UTMI interface
457 */
458 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
459 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
Larry Johnson667a3d42007-12-27 11:28:51 -0500460
Larry Johnsone17c6f72008-01-17 08:50:09 -0500461 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
462 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500463
464 mtsdr(SDR0_PFC1, sdr0_pfc1);
465 mtsdr(SDR0_USB2D0CR, usb2d0cr);
466 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
467 mtsdr(SDR0_USB2H0CR, usb2h0cr);
468
Larry Johnsone17c6f72008-01-17 08:50:09 -0500469 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500470 udelay(1000);
471 mtsdr(SDR0_SRST1, 0x00000000);
472 udelay(1000);
473 mtsdr(SDR0_SRST0, 0x00000000);
474
475 printf("USB: Host(int phy) Device(ext phy)\n");
476
477 } else if (strcmp(act, "dev") == 0) {
478 /*-------------------PATCH-------------------------------*/
479 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
480
Larry Johnsone17c6f72008-01-17 08:50:09 -0500481 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
482 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
483 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
484 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
485 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
486 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
487 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
488 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Larry Johnson667a3d42007-12-27 11:28:51 -0500489 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
490
491 udelay(1000);
492 mtsdr(SDR0_SRST1, 0x672c6000);
493
494 udelay(1000);
495 mtsdr(SDR0_SRST0, 0x00000080);
496
497 udelay(1000);
498 mtsdr(SDR0_SRST1, 0x60206000);
499
500 *(unsigned int *)(0xe0000350) = 0x00000001;
501
502 udelay(1000);
503 mtsdr(SDR0_SRST1, 0x60306000);
504 /*-------------------PATCH-------------------------------*/
505
506 /* SDR Setting */
507 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
508 mfsdr(SDR0_USB2H0CR, usb2h0cr);
509 mfsdr(SDR0_USB2D0CR, usb2d0cr);
510 mfsdr(SDR0_PFC1, sdr0_pfc1);
511
Larry Johnsone17c6f72008-01-17 08:50:09 -0500512 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
513 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
514 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
515 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
516 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
517 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
518 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
519 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
520 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
521 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
Larry Johnson667a3d42007-12-27 11:28:51 -0500522
Larry Johnsone17c6f72008-01-17 08:50:09 -0500523 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
524 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
Larry Johnson667a3d42007-12-27 11:28:51 -0500525
Larry Johnsone17c6f72008-01-17 08:50:09 -0500526 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
527 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
Larry Johnson667a3d42007-12-27 11:28:51 -0500528
Larry Johnsone17c6f72008-01-17 08:50:09 -0500529 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
530 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500531
532 mtsdr(SDR0_USB2H0CR, usb2h0cr);
533 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
534 mtsdr(SDR0_USB2D0CR, usb2d0cr);
535 mtsdr(SDR0_PFC1, sdr0_pfc1);
536
Larry Johnsone17c6f72008-01-17 08:50:09 -0500537 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500538 udelay(1000);
539 mtsdr(SDR0_SRST1, 0x00000000);
540 udelay(1000);
541 mtsdr(SDR0_SRST0, 0x00000000);
542
543 printf("USB: Device(int phy)\n");
544 }
545
Larry Johnsone17c6f72008-01-17 08:50:09 -0500546 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
Larry Johnson667a3d42007-12-27 11:28:51 -0500547 reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
548 mtsdr(SDR0_SRST1, reg);
549
550 /*
551 * Clear PLB4A0_ACR[WRP]
552 * This fix will make the MAL burst disabling patch for the Linux
553 * EMAC driver obsolete.
554 */
555 reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
556 mtdcr(plb4_acr, reg);
557
558 set_serial_number();
559 set_mac_addresses();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200560 gpio_write_bit(CONFIG_SYS_GPIO_ATMEGA_RESET_, 1);
Larry Johnson67682672008-03-17 11:10:35 -0500561
Larry Johnson667a3d42007-12-27 11:28:51 -0500562 return 0;
563}
564
565int checkboard(void)
566{
567 char const *const s = getenv("serial#");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200568 u8 const rev = in_8((u8 *) CONFIG_SYS_CPLD_BASE + 0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500569
570 printf("Board: Korat, Rev. %X", rev);
Larry Johnson67682672008-03-17 11:10:35 -0500571 if (s)
Larry Johnson667a3d42007-12-27 11:28:51 -0500572 printf(", serial# %s", s);
573
Larry Johnson67682672008-03-17 11:10:35 -0500574 printf(".\n Ethernet PHY 0: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200575 if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY0_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500576 printf("fiber");
577 else
578 printf("copper");
579
580 printf(", PHY 1: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200581 if (gpio_read_out_bit(CONFIG_SYS_GPIO_PHY1_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500582 printf("fiber");
583 else
584 printf("copper");
585
586 printf(".\n");
Larry Johnson67682672008-03-17 11:10:35 -0500587#if defined(CONFIG_KORAT_PERMANENT)
588 printf(" Executing permanent copy of U-Boot.\n");
589#endif
590 return 0;
Larry Johnson667a3d42007-12-27 11:28:51 -0500591}
592
Larry Johnsonfc391002008-06-14 16:53:02 -0400593#if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
594/*
595 * Assign interrupts to PCI devices.
596 */
597void korat_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
598{
Stefan Roese4e36fa02008-07-11 11:40:13 +0200599 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, VECNUM_EIRQ2);
Larry Johnsonfc391002008-06-14 16:53:02 -0400600}
601#endif
602
Larry Johnsone17c6f72008-01-17 08:50:09 -0500603/*
604 * pci_pre_init
Larry Johnson667a3d42007-12-27 11:28:51 -0500605 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500606 * This routine is called just prior to registering the hose and gives
607 * the board the opportunity to check things. Returning a value of zero
608 * indicates that things are bad & PCI initialization should be aborted.
Larry Johnson667a3d42007-12-27 11:28:51 -0500609 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500610 * Different boards may wish to customize the pci controller structure
611 * (add regions, override default access routines, etc) or perform
612 * certain pre-initialization actions.
613 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500614#if defined(CONFIG_PCI)
615int pci_pre_init(struct pci_controller *hose)
616{
617 unsigned long addr;
618
Larry Johnsone17c6f72008-01-17 08:50:09 -0500619 /*
620 * Set priority for all PLB3 devices to 0.
621 * Set PLB3 arbiter to fair mode.
622 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500623 mfsdr(sdr_amp1, addr);
624 mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
625 addr = mfdcr(plb3_acr);
626 mtdcr(plb3_acr, addr | 0x80000000);
627
Larry Johnsone17c6f72008-01-17 08:50:09 -0500628 /*
629 * Set priority for all PLB4 devices to 0.
630 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500631 mfsdr(sdr_amp0, addr);
632 mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
633 addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
634 mtdcr(plb4_acr, addr);
635
Larry Johnsone17c6f72008-01-17 08:50:09 -0500636 /*
637 * Set Nebula PLB4 arbiter to fair mode.
638 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500639 /* Segment0 */
640 addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
641 addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
642 addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
643 addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
644 mtdcr(plb0_acr, addr);
645
646 /* Segment1 */
647 addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
648 addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
649 addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
650 addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
651 mtdcr(plb1_acr, addr);
652
Larry Johnsonfc391002008-06-14 16:53:02 -0400653#if defined(CONFIG_PCI_PNP)
654 hose->fixup_irq = korat_pci_fixup_irq;
655#endif
656
Larry Johnson667a3d42007-12-27 11:28:51 -0500657 return 1;
658}
659#endif /* defined(CONFIG_PCI) */
660
Larry Johnsone17c6f72008-01-17 08:50:09 -0500661/*
662 * pci_target_init
Larry Johnson667a3d42007-12-27 11:28:51 -0500663 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500664 * The bootstrap configuration provides default settings for the pci
665 * inbound map (PIM). But the bootstrap config choices are limited and
666 * may not be sufficient for a given board.
667 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200668#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
Larry Johnson667a3d42007-12-27 11:28:51 -0500669void pci_target_init(struct pci_controller *hose)
670{
Larry Johnsone17c6f72008-01-17 08:50:09 -0500671 /*
Larry Johnson667a3d42007-12-27 11:28:51 -0500672 * Set up Direct MMIO registers
Larry Johnsone17c6f72008-01-17 08:50:09 -0500673 */
674 /*
675 * PowerPC440EPX PCI Master configuration.
676 * Map one 1Gig range of PLB/processor addresses to PCI memory space.
Larry Johnson67682672008-03-17 11:10:35 -0500677 * PLB address 0x80000000-0xBFFFFFFF
678 * ==> PCI address 0x80000000-0xBFFFFFFF
Larry Johnsone17c6f72008-01-17 08:50:09 -0500679 * Use byte reversed out routines to handle endianess.
680 * Make this region non-prefetchable.
681 */
682 out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
683 /* - disabled b4 setting */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200684 out32r(PCIX0_PMM0LA, CONFIG_SYS_PCI_MEMBASE); /* PMM0 Local Address */
Larry Johnson67682672008-03-17 11:10:35 -0500685 out32r(PCIX0_PMM0PCILA,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200686 CONFIG_SYS_PCI_MEMBASE); /* PMM0 PCI Low Address */
Larry Johnson667a3d42007-12-27 11:28:51 -0500687 out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500688 out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
689 /* and enable region */
Larry Johnson667a3d42007-12-27 11:28:51 -0500690
Larry Johnsone17c6f72008-01-17 08:50:09 -0500691 out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
692 /* - disabled b4 setting */
Larry Johnson67682672008-03-17 11:10:35 -0500693 out32r(PCIX0_PMM1LA,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200694 CONFIG_SYS_PCI_MEMBASE + 0x20000000); /* PMM0 Local Address */
Larry Johnson67682672008-03-17 11:10:35 -0500695 out32r(PCIX0_PMM1PCILA,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200696 CONFIG_SYS_PCI_MEMBASE + 0x20000000); /* PMM0 PCI Low Address */
Larry Johnson667a3d42007-12-27 11:28:51 -0500697 out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500698 out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
699 /* and enable region */
Larry Johnson667a3d42007-12-27 11:28:51 -0500700
701 out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500702 out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
703 out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
704 out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
Larry Johnson667a3d42007-12-27 11:28:51 -0500705
Larry Johnsone17c6f72008-01-17 08:50:09 -0500706 /*
Larry Johnson667a3d42007-12-27 11:28:51 -0500707 * Set up Configuration registers
Larry Johnsone17c6f72008-01-17 08:50:09 -0500708 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500709
710 /* Program the board's subsystem id/vendor id */
711 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200712 CONFIG_SYS_PCI_SUBSYS_VENDORID);
713 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CONFIG_SYS_PCI_SUBSYS_ID);
Larry Johnson667a3d42007-12-27 11:28:51 -0500714
715 /* Configure command register as bus master */
716 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
717
718 /* 240nS PCI clock */
719 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
720
721 /* No error reporting */
722 pci_write_config_word(0, PCI_ERREN, 0);
723
724 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
725
Larry Johnsone17c6f72008-01-17 08:50:09 -0500726 /*
727 * Set up Configuration registers for on-board NEC uPD720101 USB
728 * controller.
729 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500730 pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
731}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200732#endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT) */
Larry Johnson667a3d42007-12-27 11:28:51 -0500733
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200734#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
Larry Johnson667a3d42007-12-27 11:28:51 -0500735void pci_master_init(struct pci_controller *hose)
736{
737 unsigned short temp_short;
738
Larry Johnsone17c6f72008-01-17 08:50:09 -0500739 /*
740 * Write the PowerPC440 EP PCI Configuration regs.
741 * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
742 * Enable PowerPC440 EP to act as a PCI memory target (PTM).
743 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500744 pci_read_config_word(0, PCI_COMMAND, &temp_short);
745 pci_write_config_word(0, PCI_COMMAND,
746 temp_short | PCI_COMMAND_MASTER |
747 PCI_COMMAND_MEMORY);
748}
749#endif
750
Larry Johnsone17c6f72008-01-17 08:50:09 -0500751/*
752 * is_pci_host
Larry Johnson667a3d42007-12-27 11:28:51 -0500753 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500754 * This routine is called to determine if a pci scan should be
755 * performed. With various hardware environments (especially cPCI and
756 * PPMC) it's insufficient to depend on the state of the arbiter enable
757 * bit in the strap register, or generic host/adapter assumptions.
Larry Johnson667a3d42007-12-27 11:28:51 -0500758 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500759 * Rather than hard-code a bad assumption in the general 440 code, the
760 * 440 pci code requires the board to decide at runtime.
Larry Johnson667a3d42007-12-27 11:28:51 -0500761 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500762 * Return 0 for adapter mode, non-zero for host (monarch) mode.
763 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500764#if defined(CONFIG_PCI)
765int is_pci_host(struct pci_controller *hose)
766{
767 /* Korat is always configured as host. */
768 return (1);
769}
Larry Johnsone17c6f72008-01-17 08:50:09 -0500770#endif /* defined(CONFIG_PCI) */
Larry Johnson667a3d42007-12-27 11:28:51 -0500771
772#if defined(CONFIG_POST)
773/*
774 * Returns 1 if keys pressed to start the power-on long-running tests
775 * Called from board_init_f().
776 */
777int post_hotkeys_pressed(void)
778{
Larry Johnsone17c6f72008-01-17 08:50:09 -0500779 return 0; /* No hotkeys supported */
Larry Johnson667a3d42007-12-27 11:28:51 -0500780}
Larry Johnsone17c6f72008-01-17 08:50:09 -0500781#endif /* CONFIG_POST */
Larry Johnsonfc391002008-06-14 16:53:02 -0400782
783#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
784void ft_board_setup(void *blob, bd_t *bd)
785{
786 u32 val[4];
787 int rc;
788
789 ft_cpu_setup(blob, bd);
790
791 /* Fixup NOR mapping */
792 val[0] = 1; /* chip select number */
793 val[1] = 0; /* always 0 */
794 val[2] = gd->bd->bi_flashstart;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200795 val[3] = gd->bd->bi_flashsize - CONFIG_SYS_FLASH0_SIZE;
Larry Johnsonfc391002008-06-14 16:53:02 -0400796 rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
797 val, sizeof(val), 1);
798 if (rc)
799 printf("Unable to update property NOR mapping, err=%s\n",
800 fdt_strerror(rc));
801}
802#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */