blob: 90fd0a753212d1b30dffa23ea839e322a38dc29c [file] [log] [blame]
Larry Johnson667a3d42007-12-27 11:28:51 -05001/*
Lawrence R. Johnson59890582008-01-03 15:02:02 -05002 * (C) Copyright 2007-2008
Larry Johnson667a3d42007-12-27 11:28:51 -05003 * Larry Johnson, lrj@acm.org
4 *
Larry Johnsone17c6f72008-01-17 08:50:09 -05005 * (C) Copyright 2006-2008
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 Johnsone17c6f72008-01-17 08:50:09 -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 Johnson667a3d42007-12-27 11:28:51 -050029#include <i2c.h>
30#include <ppc440.h>
Larry Johnsone17c6f72008-01-17 08:50:09 -050031#include <asm/gpio.h>
32#include <asm/processor.h>
33#include <asm/io.h>
34#include <asm/bitops.h>
Larry Johnson667a3d42007-12-27 11:28:51 -050035
36DECLARE_GLOBAL_DATA_PTR;
37
Larry Johnsone17c6f72008-01-17 08:50:09 -050038extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
Larry Johnson667a3d42007-12-27 11:28:51 -050039
40ulong flash_get_size(ulong base, int banknum);
41
42int board_early_init_f(void)
43{
44 u32 sdr0_pfc1, sdr0_pfc2;
Larry Johnson667a3d42007-12-27 11:28:51 -050045 u32 reg;
46 int eth;
47
48 mtdcr(ebccfga, xbcfg);
49 mtdcr(ebccfgd, 0xb8400000);
50
Larry Johnsone17c6f72008-01-17 08:50:09 -050051 /*
Larry Johnson667a3d42007-12-27 11:28:51 -050052 * Setup the interrupt controller polarities, triggers, etc.
Larry Johnsone17c6f72008-01-17 08:50:09 -050053 */
Larry Johnson667a3d42007-12-27 11:28:51 -050054 mtdcr(uic0sr, 0xffffffff); /* clear all */
55 mtdcr(uic0er, 0x00000000); /* disable all */
56 mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
57 mtdcr(uic0pr, 0xfffff7ff); /* per ref-board manual */
58 mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
59 mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
60 mtdcr(uic0sr, 0xffffffff); /* clear all */
61
62 mtdcr(uic1sr, 0xffffffff); /* clear all */
63 mtdcr(uic1er, 0x00000000); /* disable all */
64 mtdcr(uic1cr, 0x00000000); /* all non-critical */
65 mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */
66 mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
67 mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
68 mtdcr(uic1sr, 0xffffffff); /* clear all */
69
70 mtdcr(uic2sr, 0xffffffff); /* clear all */
71 mtdcr(uic2er, 0x00000000); /* disable all */
72 mtdcr(uic2cr, 0x00000000); /* all non-critical */
73 mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
74 mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
75 mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
76 mtdcr(uic2sr, 0xffffffff); /* clear all */
77
78 /* take sim card reader and CF controller out of reset */
79 out_8((u8 *) CFG_CPLD_BASE + 0x04, 0x80);
80
81 /* Configure the two Ethernet PHYs. For each PHY, configure for fiber
82 * if the SFP module is present, and for copper if it is not present.
83 */
Larry Johnson667a3d42007-12-27 11:28:51 -050084 for (eth = 0; eth < 2; ++eth) {
Lawrence R. Johnson59890582008-01-03 15:02:02 -050085 if (gpio_read_in_bit(CFG_GPIO_SFP0_PRESENT_ + eth)) {
Larry Johnson667a3d42007-12-27 11:28:51 -050086 /* SFP module not present: configure PHY for copper. */
87 /* Set PHY to autonegotate 10 MB, 100MB, or 1 GB */
88 out_8((u8 *) CFG_CPLD_BASE + 0x06,
89 in_8((u8 *) CFG_CPLD_BASE + 0x06) |
90 0x06 << (4 * eth));
91 } else {
92 /* SFP module present: configure PHY for fiber and
93 enable output */
Lawrence R. Johnson59890582008-01-03 15:02:02 -050094 gpio_write_bit(CFG_GPIO_PHY0_FIBER_SEL + eth, 1);
95 gpio_write_bit(CFG_GPIO_SFP0_TX_EN_ + eth, 0);
Larry Johnson667a3d42007-12-27 11:28:51 -050096 }
97 }
98 /* enable Ethernet: set GPIO45 and GPIO46 to 1 */
Lawrence R. Johnson59890582008-01-03 15:02:02 -050099 gpio_write_bit(CFG_GPIO_PHY0_EN, 1);
100 gpio_write_bit(CFG_GPIO_PHY1_EN, 1);
Larry Johnson667a3d42007-12-27 11:28:51 -0500101
102 /* select Ethernet pins */
103 mfsdr(SDR0_PFC1, sdr0_pfc1);
104 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500105 SDR0_PFC1_SELECT_CONFIG_4;
Larry Johnson667a3d42007-12-27 11:28:51 -0500106 mfsdr(SDR0_PFC2, sdr0_pfc2);
107 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
Larry Johnsone17c6f72008-01-17 08:50:09 -0500108 SDR0_PFC2_SELECT_CONFIG_4;
Larry Johnson667a3d42007-12-27 11:28:51 -0500109 mtsdr(SDR0_PFC2, sdr0_pfc2);
110 mtsdr(SDR0_PFC1, sdr0_pfc1);
111
112 /* PCI arbiter enabled */
113 mfsdr(sdr_pci0, reg);
114 mtsdr(sdr_pci0, 0x80000000 | reg);
115
116 return 0;
117}
118
119static int man_data_read(unsigned int addr)
120{
121 /*
122 * Read an octet of data from address "addr" in the manufacturer's
123 * information serial EEPROM, or -1 on error.
124 */
125 u8 data[2];
126
127 if (0 != i2c_probe(MAN_DATA_EEPROM_ADDR) ||
128 0 != i2c_read(MAN_DATA_EEPROM_ADDR, addr, 1, data, 1)) {
129 debug("man_data_read(0x%02X) failed\n", addr);
130 return -1;
131 }
132 debug("man_info_read(0x%02X) returned 0x%02X\n", addr, data[0]);
133 return data[0];
134}
135
136static unsigned int man_data_field_addr(unsigned int const field)
137{
138 /*
139 * The manufacturer's information serial EEPROM contains a sequence of
140 * zero-delimited fields. Return the starting address of field "field",
141 * or 0 on error.
142 */
143 unsigned addr, i;
144
145 if (0 == field || 'A' != man_data_read(0) || '\0' != man_data_read(1))
146 /* Only format "A" is currently supported */
147 return 0;
148
149 for (addr = 2, i = 1; i < field && addr < 256; ++addr) {
150 if ('\0' == man_data_read(addr))
151 ++i;
152 }
153 return (addr < 256) ? addr : 0;
154}
155
156static char *man_data_read_field(char s[], unsigned const field,
157 unsigned const length)
158{
159 /*
160 * Place the null-terminated contents of field "field" of length
161 * "length" from the manufacturer's information serial EEPROM into
162 * string "s[length + 1]" and return a pointer to s, or return 0 on
163 * error. In either case the original contents of s[] is not preserved.
164 */
165 unsigned addr, i;
166
167 addr = man_data_field_addr(field);
168 if (0 == addr || addr + length >= 255)
169 return 0;
170
171 for (i = 0; i < length; ++i) {
172 int const c = man_data_read(addr++);
173
174 if (c <= 0)
175 return 0;
176
177 s[i] = (char)c;
178 }
179 if (0 != man_data_read(addr))
180 return 0;
181
182 s[i] = '\0';
183 return s;
184}
185
186static void set_serial_number(void)
187{
188 /*
189 * If the environmental variable "serial#" is not set, try to set it
190 * from the manufacturer's information serial EEPROM.
191 */
192 char s[MAN_SERIAL_NO_LENGTH + 1];
193
194 if (0 == getenv("serial#") &&
195 0 != man_data_read_field(s, MAN_SERIAL_NO_FIELD,
196 MAN_SERIAL_NO_LENGTH))
197 setenv("serial#", s);
198}
199
200static void set_mac_addresses(void)
201{
202 /*
203 * If the environmental variables "ethaddr" and/or "eth1addr" are not
204 * set, try to set them from the manufacturer's information serial
205 * EEPROM.
206 */
207 char s[MAN_MAC_ADDR_LENGTH + 1];
208
209 if (0 != getenv("ethaddr") && 0 != getenv("eth1addr"))
210 return;
211
212 if (0 == man_data_read_field(s, MAN_MAC_ADDR_FIELD,
213 MAN_MAC_ADDR_LENGTH))
214 return;
215
216 if (0 == getenv("ethaddr"))
217 setenv("ethaddr", s);
218
219 if (0 == getenv("eth1addr")) {
220 ++s[MAN_MAC_ADDR_LENGTH - 1];
221 setenv("eth1addr", s);
222 }
223}
224
Larry Johnson667a3d42007-12-27 11:28:51 -0500225int misc_init_r(void)
226{
227 uint pbcr;
228 int size_val = 0;
229 u32 reg;
230 unsigned long usb2d0cr = 0;
231 unsigned long usb2phy0cr, usb2h0cr = 0;
232 unsigned long sdr0_pfc1;
233 char *act = getenv("usbact");
234
Larry Johnsone17c6f72008-01-17 08:50:09 -0500235 /* Re-do flash sizing to get full correct info */
Larry Johnson667a3d42007-12-27 11:28:51 -0500236
237 /* adjust flash start and offset */
238 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
239 gd->bd->bi_flashoffset = 0;
240
241 mtdcr(ebccfga, pb0cr);
242 pbcr = mfdcr(ebccfgd);
Larry Johnsone17c6f72008-01-17 08:50:09 -0500243 size_val = ffs(gd->bd->bi_flashsize) - 21;
Larry Johnson667a3d42007-12-27 11:28:51 -0500244 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
245 mtdcr(ebccfga, pb0cr);
246 mtdcr(ebccfgd, pbcr);
247
248 /*
249 * Re-check to get correct base address
250 */
251 flash_get_size(gd->bd->bi_flashstart, 0);
252
253 /* Monitor protection ON by default */
254 (void)flash_protect(FLAG_PROTECT_SET, -CFG_MONITOR_LEN, 0xffffffff,
255 &flash_info[0]);
256
257 /* Env protection ON by default */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500258 (void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR_REDUND,
Larry Johnson667a3d42007-12-27 11:28:51 -0500259 CFG_ENV_ADDR_REDUND + 2 * CFG_ENV_SECT_SIZE - 1,
260 &flash_info[0]);
261
262 /*
263 * USB suff...
264 */
265 if (act == NULL || strcmp(act, "hostdev") == 0) {
266 /* SDR Setting */
267 mfsdr(SDR0_PFC1, sdr0_pfc1);
268 mfsdr(SDR0_USB2D0CR, usb2d0cr);
269 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
270 mfsdr(SDR0_USB2H0CR, usb2h0cr);
271
Larry Johnsone17c6f72008-01-17 08:50:09 -0500272 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
273 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
274 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
275 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
276 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
277 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
278 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
279 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
280 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
281 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Larry Johnson667a3d42007-12-27 11:28:51 -0500282
Larry Johnsone17c6f72008-01-17 08:50:09 -0500283 /*
284 * An 8-bit/60MHz interface is the only possible alternative
285 * when connecting the Device to the PHY
286 */
287 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
288 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
Larry Johnson667a3d42007-12-27 11:28:51 -0500289
Larry Johnsone17c6f72008-01-17 08:50:09 -0500290 /*
291 * To enable the USB 2.0 Device function
292 * through the UTMI interface
293 */
294 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
295 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_USB2DEV_SELECTION;
Larry Johnson667a3d42007-12-27 11:28:51 -0500296
Larry Johnsone17c6f72008-01-17 08:50:09 -0500297 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
298 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_USB2D_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500299
300 mtsdr(SDR0_PFC1, sdr0_pfc1);
301 mtsdr(SDR0_USB2D0CR, usb2d0cr);
302 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
303 mtsdr(SDR0_USB2H0CR, usb2h0cr);
304
Larry Johnsone17c6f72008-01-17 08:50:09 -0500305 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500306 udelay(1000);
307 mtsdr(SDR0_SRST1, 0x00000000);
308 udelay(1000);
309 mtsdr(SDR0_SRST0, 0x00000000);
310
311 printf("USB: Host(int phy) Device(ext phy)\n");
312
313 } else if (strcmp(act, "dev") == 0) {
314 /*-------------------PATCH-------------------------------*/
315 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
316
Larry Johnsone17c6f72008-01-17 08:50:09 -0500317 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
318 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
319 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
320 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
321 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
322 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
323 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
324 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
Larry Johnson667a3d42007-12-27 11:28:51 -0500325 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
326
327 udelay(1000);
328 mtsdr(SDR0_SRST1, 0x672c6000);
329
330 udelay(1000);
331 mtsdr(SDR0_SRST0, 0x00000080);
332
333 udelay(1000);
334 mtsdr(SDR0_SRST1, 0x60206000);
335
336 *(unsigned int *)(0xe0000350) = 0x00000001;
337
338 udelay(1000);
339 mtsdr(SDR0_SRST1, 0x60306000);
340 /*-------------------PATCH-------------------------------*/
341
342 /* SDR Setting */
343 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
344 mfsdr(SDR0_USB2H0CR, usb2h0cr);
345 mfsdr(SDR0_USB2D0CR, usb2d0cr);
346 mfsdr(SDR0_PFC1, sdr0_pfc1);
347
Larry Johnsone17c6f72008-01-17 08:50:09 -0500348 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
349 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
350 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
351 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
352 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
353 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
354 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
355 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
356 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
357 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
Larry Johnson667a3d42007-12-27 11:28:51 -0500358
Larry Johnsone17c6f72008-01-17 08:50:09 -0500359 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
360 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
Larry Johnson667a3d42007-12-27 11:28:51 -0500361
Larry Johnsone17c6f72008-01-17 08:50:09 -0500362 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
363 usb2d0cr = usb2d0cr | SDR0_USB2D0CR_EBC_SELECTION;
Larry Johnson667a3d42007-12-27 11:28:51 -0500364
Larry Johnsone17c6f72008-01-17 08:50:09 -0500365 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
366 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
Larry Johnson667a3d42007-12-27 11:28:51 -0500367
368 mtsdr(SDR0_USB2H0CR, usb2h0cr);
369 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
370 mtsdr(SDR0_USB2D0CR, usb2d0cr);
371 mtsdr(SDR0_PFC1, sdr0_pfc1);
372
Larry Johnsone17c6f72008-01-17 08:50:09 -0500373 /* clear resets */
Larry Johnson667a3d42007-12-27 11:28:51 -0500374 udelay(1000);
375 mtsdr(SDR0_SRST1, 0x00000000);
376 udelay(1000);
377 mtsdr(SDR0_SRST0, 0x00000000);
378
379 printf("USB: Device(int phy)\n");
380 }
381
Larry Johnsone17c6f72008-01-17 08:50:09 -0500382 mfsdr(SDR0_SRST1, reg); /* enable security/kasumi engines */
Larry Johnson667a3d42007-12-27 11:28:51 -0500383 reg &= ~(SDR0_SRST1_CRYP0 | SDR0_SRST1_KASU0);
384 mtsdr(SDR0_SRST1, reg);
385
386 /*
387 * Clear PLB4A0_ACR[WRP]
388 * This fix will make the MAL burst disabling patch for the Linux
389 * EMAC driver obsolete.
390 */
391 reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
392 mtdcr(plb4_acr, reg);
393
394 set_serial_number();
395 set_mac_addresses();
396 return 0;
397}
398
399int checkboard(void)
400{
401 char const *const s = getenv("serial#");
402 u8 const rev = in_8((u8 *) CFG_CPLD_BASE + 0);
Larry Johnson667a3d42007-12-27 11:28:51 -0500403
404 printf("Board: Korat, Rev. %X", rev);
405 if (s != NULL)
406 printf(", serial# %s", s);
407
408 printf(", Ethernet PHY 0: ");
Lawrence R. Johnson59890582008-01-03 15:02:02 -0500409 if (gpio_read_out_bit(CFG_GPIO_PHY0_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500410 printf("fiber");
411 else
412 printf("copper");
413
414 printf(", PHY 1: ");
Lawrence R. Johnson59890582008-01-03 15:02:02 -0500415 if (gpio_read_out_bit(CFG_GPIO_PHY1_FIBER_SEL))
Larry Johnson667a3d42007-12-27 11:28:51 -0500416 printf("fiber");
417 else
418 printf("copper");
419
420 printf(".\n");
421 return (0);
422}
423
424#if defined(CFG_DRAM_TEST)
425int testdram(void)
426{
427 unsigned long *mem = (unsigned long *)0;
428 const unsigned long kend = (1024 / sizeof(unsigned long));
429 unsigned long k, n;
430
431 mtmsr(0);
432
433 /* TODO: find correct size of SDRAM */
434 for (k = 0; k < CFG_MBYTES_SDRAM;
435 ++k, mem += (1024 / sizeof(unsigned long))) {
436 if ((k & 1023) == 0)
437 printf("%3d MB\r", k / 1024);
438
439 memset(mem, 0xaaaaaaaa, 1024);
440 for (n = 0; n < kend; ++n) {
441 if (mem[n] != 0xaaaaaaaa) {
442 printf("SDRAM test fails at: %08x\n",
443 (uint) & mem[n]);
444 return 1;
445 }
446 }
447
448 memset(mem, 0x55555555, 1024);
449 for (n = 0; n < kend; ++n) {
450 if (mem[n] != 0x55555555) {
451 printf("SDRAM test fails at: %08x\n",
452 (uint) & mem[n]);
453 return 1;
454 }
455 }
456 }
457 printf("SDRAM test passes\n");
458 return 0;
459}
460#endif /* defined(CFG_DRAM_TEST) */
461
Larry Johnsone17c6f72008-01-17 08:50:09 -0500462/*
463 * pci_pre_init
Larry Johnson667a3d42007-12-27 11:28:51 -0500464 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500465 * This routine is called just prior to registering the hose and gives
466 * the board the opportunity to check things. Returning a value of zero
467 * indicates that things are bad & PCI initialization should be aborted.
Larry Johnson667a3d42007-12-27 11:28:51 -0500468 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500469 * Different boards may wish to customize the pci controller structure
470 * (add regions, override default access routines, etc) or perform
471 * certain pre-initialization actions.
472 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500473#if defined(CONFIG_PCI)
474int pci_pre_init(struct pci_controller *hose)
475{
476 unsigned long addr;
477
Larry Johnsone17c6f72008-01-17 08:50:09 -0500478 /*
479 * Set priority for all PLB3 devices to 0.
480 * Set PLB3 arbiter to fair mode.
481 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500482 mfsdr(sdr_amp1, addr);
483 mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
484 addr = mfdcr(plb3_acr);
485 mtdcr(plb3_acr, addr | 0x80000000);
486
Larry Johnsone17c6f72008-01-17 08:50:09 -0500487 /*
488 * Set priority for all PLB4 devices to 0.
489 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500490 mfsdr(sdr_amp0, addr);
491 mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
492 addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
493 mtdcr(plb4_acr, addr);
494
Larry Johnsone17c6f72008-01-17 08:50:09 -0500495 /*
496 * Set Nebula PLB4 arbiter to fair mode.
497 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500498 /* Segment0 */
499 addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
500 addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
501 addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
502 addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
503 mtdcr(plb0_acr, addr);
504
505 /* Segment1 */
506 addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
507 addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
508 addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
509 addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
510 mtdcr(plb1_acr, addr);
511
512 return 1;
513}
514#endif /* defined(CONFIG_PCI) */
515
Larry Johnsone17c6f72008-01-17 08:50:09 -0500516/*
517 * pci_target_init
Larry Johnson667a3d42007-12-27 11:28:51 -0500518 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500519 * The bootstrap configuration provides default settings for the pci
520 * inbound map (PIM). But the bootstrap config choices are limited and
521 * may not be sufficient for a given board.
522 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500523#if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
524void pci_target_init(struct pci_controller *hose)
525{
Larry Johnsone17c6f72008-01-17 08:50:09 -0500526 /*
Larry Johnson667a3d42007-12-27 11:28:51 -0500527 * Set up Direct MMIO registers
Larry Johnsone17c6f72008-01-17 08:50:09 -0500528 */
529 /*
530 * PowerPC440EPX PCI Master configuration.
531 * Map one 1Gig range of PLB/processor addresses to PCI memory space.
532 * PLB address 0xA0000000-0xDFFFFFFF
533 * ==> PCI address 0xA0000000-0xDFFFFFFF
534 * Use byte reversed out routines to handle endianess.
535 * Make this region non-prefetchable.
536 */
537 out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
538 /* - disabled b4 setting */
Larry Johnson667a3d42007-12-27 11:28:51 -0500539 out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500540 out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
Larry Johnson667a3d42007-12-27 11:28:51 -0500541 out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500542 out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
543 /* and enable region */
Larry Johnson667a3d42007-12-27 11:28:51 -0500544
Larry Johnsone17c6f72008-01-17 08:50:09 -0500545 out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
546 /* - disabled b4 setting */
547 out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
548 out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
Larry Johnson667a3d42007-12-27 11:28:51 -0500549 out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500550 out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
551 /* and enable region */
Larry Johnson667a3d42007-12-27 11:28:51 -0500552
553 out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
Larry Johnsone17c6f72008-01-17 08:50:09 -0500554 out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
555 out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
556 out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
Larry Johnson667a3d42007-12-27 11:28:51 -0500557
Larry Johnsone17c6f72008-01-17 08:50:09 -0500558 /*
Larry Johnson667a3d42007-12-27 11:28:51 -0500559 * Set up Configuration registers
Larry Johnsone17c6f72008-01-17 08:50:09 -0500560 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500561
562 /* Program the board's subsystem id/vendor id */
563 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
564 CFG_PCI_SUBSYS_VENDORID);
565 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
566
567 /* Configure command register as bus master */
568 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
569
570 /* 240nS PCI clock */
571 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
572
573 /* No error reporting */
574 pci_write_config_word(0, PCI_ERREN, 0);
575
576 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
577
Larry Johnsone17c6f72008-01-17 08:50:09 -0500578 /*
579 * Set up Configuration registers for on-board NEC uPD720101 USB
580 * controller.
581 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500582 pci_write_config_dword(PCI_BDF(0x0, 0xC, 0x0), 0xE4, 0x00000020);
583}
584#endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
585
Larry Johnson667a3d42007-12-27 11:28:51 -0500586#if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
587void pci_master_init(struct pci_controller *hose)
588{
589 unsigned short temp_short;
590
Larry Johnsone17c6f72008-01-17 08:50:09 -0500591 /*
592 * Write the PowerPC440 EP PCI Configuration regs.
593 * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
594 * Enable PowerPC440 EP to act as a PCI memory target (PTM).
595 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500596 pci_read_config_word(0, PCI_COMMAND, &temp_short);
597 pci_write_config_word(0, PCI_COMMAND,
598 temp_short | PCI_COMMAND_MASTER |
599 PCI_COMMAND_MEMORY);
600}
601#endif
602
Larry Johnsone17c6f72008-01-17 08:50:09 -0500603/*
604 * is_pci_host
Larry Johnson667a3d42007-12-27 11:28:51 -0500605 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500606 * This routine is called to determine if a pci scan should be
607 * performed. With various hardware environments (especially cPCI and
608 * PPMC) it's insufficient to depend on the state of the arbiter enable
609 * bit in the strap register, or generic host/adapter assumptions.
Larry Johnson667a3d42007-12-27 11:28:51 -0500610 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500611 * Rather than hard-code a bad assumption in the general 440 code, the
612 * 440 pci code requires the board to decide at runtime.
Larry Johnson667a3d42007-12-27 11:28:51 -0500613 *
Larry Johnsone17c6f72008-01-17 08:50:09 -0500614 * Return 0 for adapter mode, non-zero for host (monarch) mode.
615 */
Larry Johnson667a3d42007-12-27 11:28:51 -0500616#if defined(CONFIG_PCI)
617int is_pci_host(struct pci_controller *hose)
618{
619 /* Korat is always configured as host. */
620 return (1);
621}
Larry Johnsone17c6f72008-01-17 08:50:09 -0500622#endif /* defined(CONFIG_PCI) */
Larry Johnson667a3d42007-12-27 11:28:51 -0500623
624#if defined(CONFIG_POST)
625/*
626 * Returns 1 if keys pressed to start the power-on long-running tests
627 * Called from board_init_f().
628 */
629int post_hotkeys_pressed(void)
630{
Larry Johnsone17c6f72008-01-17 08:50:09 -0500631 return 0; /* No hotkeys supported */
Larry Johnson667a3d42007-12-27 11:28:51 -0500632}
Larry Johnsone17c6f72008-01-17 08:50:09 -0500633#endif /* CONFIG_POST */