1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <common.h>
30#include <libfdt.h>
31#include <fdt_support.h>
32#include <asm/ppc440.h>
33#include <asm/processor.h>
34#include <asm/io.h>
35#include <asm/bitops.h>
36#include <command.h>
37#include <i2c.h>
38#ifdef CONFIG_RESET_PHY_R
39#include <miiphy.h>
40#endif
41#include <serial.h>
42#include <asm/4xx_pci.h>
43
44#include "fpga.h"
45#include "pmc440.h"
46
47DECLARE_GLOBAL_DATA_PTR;
48
49extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
50extern void __ft_board_setup(void *blob, bd_t *bd);
51
52ulong flash_get_size(ulong base, int banknum);
53int pci_is_66mhz(void);
54int is_monarch(void);
55int bootstrap_eeprom_read(unsigned dev_addr, unsigned offset,
56 uchar *buffer, unsigned cnt);
57
58struct serial_device *default_serial_console(void)
59{
60 uchar buf[4];
61 ulong delay;
62 int i;
63 ulong val;
64
65
66
67
68
69 mfsdr(SDR0_PINSTP, val);
70 if (((val & 0xf0000000) >> 29) != 7)
71 return &eserial2_device;
72
73 ulong scratchreg = in_be32((void*)GPIO0_ISR3L);
74 if (!(scratchreg & 0x80)) {
75
76 scratchreg = (scratchreg & 0xffffff00) | 0x80;
77
78 i = bootstrap_eeprom_read(CONFIG_SYS_I2C_BOOT_EEPROM_ADDR,
79 0x10, buf, 4);
80 if ((i != -1) && (buf[0] == 0x19) && (buf[1] == 0x75)) {
81 scratchreg |= buf[2];
82
83
84 for (delay=0; delay<(1000 * (ulong)buf[3]); delay++) {
85 udelay(1000);
86 }
87 } else
88 scratchreg |= 0x01;
89 out_be32((void*)GPIO0_ISR3L, scratchreg);
90 }
91
92 if (scratchreg & 0x01)
93 return &eserial2_device;
94 else
95 return &eserial1_device;
96}
97
98int board_early_init_f(void)
99{
100 u32 sdr0_cust0;
101 u32 sdr0_pfc1, sdr0_pfc2;
102 u32 reg;
103
104
105 mtdcr(EBC0_CFGADDR, EBC0_CFG);
106 mtdcr(EBC0_CFGDATA, 0xf8400000);
107
108
109
110
111
112 out_be32((void *)GPIO0_OR, 0x40000102);
113 out_be32((void *)GPIO0_TCR, 0x4c90011f);
114 out_be32((void *)GPIO0_OSRL, 0x28051400);
115 out_be32((void *)GPIO0_OSRH, 0x55005000);
116 out_be32((void *)GPIO0_TSRL, 0x08051400);
117 out_be32((void *)GPIO0_TSRH, 0x55005000);
118 out_be32((void *)GPIO0_ISR1L, 0x54000000);
119 out_be32((void *)GPIO0_ISR1H, 0x00000000);
120 out_be32((void *)GPIO0_ISR2L, 0x44000000);
121 out_be32((void *)GPIO0_ISR2H, 0x00000100);
122 out_be32((void *)GPIO0_ISR3L, 0x00000000);
123 out_be32((void *)GPIO0_ISR3H, 0x00000000);
124
125 out_be32((void *)GPIO1_OR, 0x80002408);
126 out_be32((void *)GPIO1_TCR, 0xd6003c08);
127 out_be32((void *)GPIO1_OSRL, 0x0a5a0000);
128 out_be32((void *)GPIO1_OSRH, 0x00000000);
129 out_be32((void *)GPIO1_TSRL, 0x00000000);
130 out_be32((void *)GPIO1_TSRH, 0x00000000);
131 out_be32((void *)GPIO1_ISR1L, 0x00005555);
132 out_be32((void *)GPIO1_ISR1H, 0x40000000);
133 out_be32((void *)GPIO1_ISR2L, 0x04010000);
134 out_be32((void *)GPIO1_ISR2H, 0x00000000);
135 out_be32((void *)GPIO1_ISR3L, 0x01400000);
136 out_be32((void *)GPIO1_ISR3H, 0x00000000);
137
138
139 mfcpr(CPR0_SPCID, reg);
140 if (pci_is_66mhz() && (reg != 0x02000000)) {
141 mtcpr(CPR0_SPCID, 0x02000000);
142
143 mfcpr(CPR0_ICFG, reg);
144 reg |= CPR0_ICFG_RLI_MASK;
145 mtcpr(CPR0_ICFG, reg);
146
147 mtspr(SPRN_DBCR0, 0x20000000);
148 }
149
150
151
152
153 mtdcr(UIC0SR, 0xffffffff);
154 mtdcr(UIC0ER, 0x00000000);
155 mtdcr(UIC0CR, 0x00000005);
156 mtdcr(UIC0PR, 0xfffff7ef);
157 mtdcr(UIC0TR, 0x00000000);
158 mtdcr(UIC0VR, 0x00000000);
159 mtdcr(UIC0SR, 0xffffffff);
160
161 mtdcr(UIC1SR, 0xffffffff);
162 mtdcr(UIC1ER, 0x00000000);
163 mtdcr(UIC1CR, 0x00000000);
164 mtdcr(UIC1PR, 0xffffc7f5);
165 mtdcr(UIC1TR, 0x00000000);
166 mtdcr(UIC1VR, 0x00000000);
167 mtdcr(UIC1SR, 0xffffffff);
168
169 mtdcr(UIC2SR, 0xffffffff);
170 mtdcr(UIC2ER, 0x00000000);
171 mtdcr(UIC2CR, 0x00000000);
172 mtdcr(UIC2PR, 0x27ffffff);
173 mtdcr(UIC2TR, 0x00000000);
174 mtdcr(UIC2VR, 0x00000000);
175 mtdcr(UIC2SR, 0xffffffff);
176
177
178 mfsdr(SDR0_PFC1, sdr0_pfc1);
179 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
180 SDR0_PFC1_SELECT_CONFIG_4;
181 mfsdr(SDR0_PFC2, sdr0_pfc2);
182 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
183 SDR0_PFC2_SELECT_CONFIG_4;
184
185
186 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL;
187
188 mtsdr(SDR0_PFC2, sdr0_pfc2);
189 mtsdr(SDR0_PFC1, sdr0_pfc1);
190
191
192 mfsdr(SDR0_CUST0, sdr0_cust0);
193 sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
194 SDR0_CUST0_NDFC_ENABLE |
195 SDR0_CUST0_NDFC_BW_8_BIT |
196 SDR0_CUST0_NDFC_ARE_MASK |
197 (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
198 mtsdr(SDR0_CUST0, sdr0_cust0);
199
200 return 0;
201}
202
203#if defined(CONFIG_MISC_INIT_F)
204int misc_init_f(void)
205{
206 struct pci_controller hose;
207 hose.first_busno = 0;
208 hose.last_busno = 0;
209 hose.region_count = 0;
210
211 if (getenv("pciearly") && (!is_monarch())) {
212 printf("PCI: early target init\n");
213 pci_setup_indirect(&hose, PCIL0_CFGADR, PCIL0_CFGDATA);
214 pci_target_init(&hose);
215 }
216 return 0;
217}
218#endif
219
220
221
222
223int misc_init_r(void)
224{
225 uint pbcr;
226 int size_val = 0;
227 u32 reg;
228 unsigned long usb2d0cr = 0;
229 unsigned long usb2phy0cr, usb2h0cr = 0;
230 unsigned long sdr0_pfc1;
231 unsigned long sdr0_srst0, sdr0_srst1;
232 char *act = getenv("usbact");
233
234
235
236
237
238
239
240
241 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
242 gd->bd->bi_flashoffset = 0;
243
244#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
245 mtdcr(EBC0_CFGADDR, PB2CR);
246#else
247 mtdcr(EBC0_CFGADDR, PB0CR);
248#endif
249 pbcr = mfdcr(EBC0_CFGDATA);
250 size_val = ffs(gd->bd->bi_flashsize) - 21;
251 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
252#if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
253 mtdcr(EBC0_CFGADDR, PB2CR);
254#else
255 mtdcr(EBC0_CFGADDR, PB0CR);
256#endif
257 mtdcr(EBC0_CFGDATA, pbcr);
258
259
260
261
262 flash_get_size(gd->bd->bi_flashstart, 0);
263
264#ifdef CONFIG_ENV_IS_IN_FLASH
265
266 (void)flash_protect(FLAG_PROTECT_SET,
267 -CONFIG_SYS_MONITOR_LEN,
268 0xffffffff,
269 &flash_info[0]);
270
271
272 (void)flash_protect(FLAG_PROTECT_SET,
273 CONFIG_ENV_ADDR_REDUND,
274 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
275 &flash_info[0]);
276#endif
277
278
279
280
281 if ((act == NULL || strcmp(act, "host") == 0) &&
282 !(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)){
283
284 mfsdr(SDR0_PFC1, sdr0_pfc1);
285 mfsdr(SDR0_USB2D0CR, usb2d0cr);
286 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
287 mfsdr(SDR0_USB2H0CR, usb2h0cr);
288
289 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
290 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
291 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
292 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
293 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
294 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
295 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
296 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
297 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
298 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
299
300
301
302
303
304 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
305 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
306
307 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
308 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
309
310 mtsdr(SDR0_PFC1, sdr0_pfc1);
311 mtsdr(SDR0_USB2D0CR, usb2d0cr);
312 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
313 mtsdr(SDR0_USB2H0CR, usb2h0cr);
314
315
316
317
318
319
320
321
322
323
324
325
326 mfsdr(SDR0_SRST1, sdr0_srst1);
327 sdr0_srst1 &= ~(SDR0_SRST1_OPBA1 | \
328 SDR0_SRST1_P4OPB0 | \
329 SDR0_SRST1_OPBA2 | \
330 SDR0_SRST1_PLB42OPB1 | \
331 SDR0_SRST1_OPB2PLB40);
332 mtsdr(SDR0_SRST1, sdr0_srst1);
333 udelay(1000);
334
335 mfsdr(SDR0_SRST1, sdr0_srst1);
336 sdr0_srst1 &= ~SDR0_SRST1_USB20PHY;
337 mtsdr(SDR0_SRST1, sdr0_srst1);
338 udelay(1000);
339
340 mfsdr(SDR0_SRST0, sdr0_srst0);
341 sdr0_srst0 &= ~SDR0_SRST0_USB2H;
342 mtsdr(SDR0_SRST0, sdr0_srst0);
343 udelay(4000);
344
345
346 mtsdr(SDR0_SRST1, 0x00000000);
347 mtsdr(SDR0_SRST0, 0x00000000);
348
349 if (!(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)) {
350
351 out_be32((void*)GPIO1_OR,
352 in_be32((void*)GPIO1_OR) & ~GPIO1_USB_PWR_N);
353 }
354
355 printf("USB: Host\n");
356
357 } else if ((strcmp(act, "dev") == 0) ||
358 (in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT)) {
359 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
360
361 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
362 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
363 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
364 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
365 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
366 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
367 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
368 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
369 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
370
371 udelay (1000);
372 mtsdr(SDR0_SRST1, 0x672c6000);
373
374 udelay (1000);
375 mtsdr(SDR0_SRST0, 0x00000080);
376
377 udelay (1000);
378 mtsdr(SDR0_SRST1, 0x60206000);
379
380 *(unsigned int *)(0xe0000350) = 0x00000001;
381
382 udelay (1000);
383 mtsdr(SDR0_SRST1, 0x60306000);
384
385
386 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
387 mfsdr(SDR0_USB2H0CR, usb2h0cr);
388 mfsdr(SDR0_USB2D0CR, usb2d0cr);
389 mfsdr(SDR0_PFC1, sdr0_pfc1);
390
391 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
392 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
393 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
394 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_8BIT_60MHZ;
395 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
396 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
397 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
398 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_DEV;
399 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
400 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_DEV;
401
402 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
403 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_8BIT_60MHZ;
404
405 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
406
407 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
408 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
409
410 mtsdr(SDR0_USB2H0CR, usb2h0cr);
411 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
412 mtsdr(SDR0_USB2D0CR, usb2d0cr);
413 mtsdr(SDR0_PFC1, sdr0_pfc1);
414
415
416 udelay(1000);
417 mtsdr(SDR0_SRST1, 0x00000000);
418 udelay(1000);
419 mtsdr(SDR0_SRST0, 0x00000000);
420
421 printf("USB: Device\n");
422 }
423
424
425
426
427
428
429 reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
430 mtdcr(PLB4A0_ACR, reg);
431
432#ifdef CONFIG_FPGA
433 pmc440_init_fpga();
434#endif
435
436
437 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_POST_N);
438
439 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~GPIO0_LED_RUN_N);
440 return 0;
441}
442
443int is_monarch(void)
444{
445 if (in_be32((void*)GPIO1_IR) & GPIO1_NONMONARCH)
446 return 0;
447
448 return 1;
449}
450
451int pci_is_66mhz(void)
452{
453 if (in_be32((void*)GPIO1_IR) & GPIO1_M66EN)
454 return 1;
455 return 0;
456}
457
458int board_revision(void)
459{
460 return (int)((in_be32((void*)GPIO1_IR) & GPIO1_HWID_MASK) >> 4);
461}
462
463int checkboard(void)
464{
465 puts("Board: esd GmbH - PMC440");
466
467 gd->board_type = board_revision();
468 printf(", Rev 1.%ld, ", gd->board_type);
469
470 if (!is_monarch()) {
471 puts("non-");
472 }
473
474 printf("monarch, PCI=%s MHz\n", pci_is_66mhz() ? "66" : "33");
475 return (0);
476}
477
478
479#if defined(CONFIG_PCI) && defined(CONFIG_PCI_PNP)
480
481
482
483void board_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
484{
485 unsigned char int_line[] = {IRQ_PCIC, IRQ_PCID, IRQ_PCIA, IRQ_PCIB};
486
487 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
488 int_line[PCI_DEV(dev) & 0x03]);
489}
490#endif
491
492
493
494
495
496
497
498
499#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_TARGET_INIT)
500void pci_target_init(struct pci_controller *hose)
501{
502 char *ptmla_str, *ptmms_str;
503
504
505
506
507
508
509
510
511
512
513
514
515 out32r(PCIL0_PMM0MA, 0x00000000);
516
517 out32r(PCIL0_PMM0LA, CONFIG_SYS_PCI_MEMBASE);
518 out32r(PCIL0_PMM0PCILA, CONFIG_SYS_PCI_MEMBASE);
519 out32r(PCIL0_PMM0PCIHA, 0x00000000);
520 out32r(PCIL0_PMM0MA, 0xc0000001);
521
522
523 if (!is_monarch()) {
524 ptmla_str = getenv("ptm1la");
525 ptmms_str = getenv("ptm1ms");
526 if(NULL != ptmla_str && NULL != ptmms_str ) {
527 out32r(PCIL0_PTM1MS,
528 simple_strtoul(ptmms_str, NULL, 16));
529 out32r(PCIL0_PTM1LA,
530 simple_strtoul(ptmla_str, NULL, 16));
531 } else {
532
533 out32r(PCIL0_PTM1MS, 0xfc000001);
534 out32r(PCIL0_PTM1LA, 0x0c000000);
535 }
536 } else {
537
538 out32r(PCIL0_PTM1MS, 0xf0000001);
539 out32r(PCIL0_PTM1LA, 0x00000000);
540 }
541
542 ptmla_str = getenv("ptm2la");
543 ptmms_str = getenv("ptm2ms");
544 if(NULL != ptmla_str && NULL != ptmms_str ) {
545 out32r(PCIL0_PTM2MS, simple_strtoul(ptmms_str, NULL, 16));
546 out32r(PCIL0_PTM2LA, simple_strtoul(ptmla_str, NULL, 16));
547 } else {
548
549 out32r(PCIL0_PTM2MS, 0xffc00001);
550 out32r(PCIL0_PTM2LA, 0xef000000);
551 }
552
553 if (is_monarch()) {
554
555 pci_hose_write_config_dword(hose, 0, PCI_BASE_ADDRESS_2, 0x40000008);
556 }
557
558
559
560
561
562
563 pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_VENDOR_ID,
564 CONFIG_SYS_PCI_SUBSYS_VENDORID);
565
566
567
568
569
570
571
572 pci_hose_write_config_word(hose, 0, PCI_LATENCY_TIMER, 1);
573
574
575 pci_hose_write_config_word(hose, 0, PCI_ERREN, 0);
576
577 if (!is_monarch()) {
578
579 pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_ID,
580 CONFIG_SYS_PCI_SUBSYS_ID_NONMONARCH);
581 pci_hose_write_config_word(hose, 0, PCI_CLASS_SUB_CODE,
582 CONFIG_SYS_PCI_CLASSCODE_NONMONARCH);
583
584
585 out_be32((void*)GPIO1_OR,
586 in_be32((void*)GPIO1_OR) | GPIO1_PPC_EREADY);
587 out_be32((void*)GPIO1_TCR,
588 in_be32((void*)GPIO1_TCR) | GPIO1_PPC_EREADY);
589 } else {
590
591 pci_hose_write_config_word(hose, 0, PCI_SUBSYSTEM_ID,
592 CONFIG_SYS_PCI_SUBSYS_ID_MONARCH);
593 pci_hose_write_config_word(hose, 0, PCI_CLASS_SUB_CODE,
594 CONFIG_SYS_PCI_CLASSCODE_MONARCH);
595 }
596
597
598 pci_hose_write_config_dword(hose, 0, PCI_BRDGOPT2, 0x00000101);
599}
600#endif
601
602
603
604
605#if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
606void pci_master_init(struct pci_controller *hose)
607{
608
609
610
611 if (is_monarch())
612 __pci_master_init(hose);
613}
614#endif
615
616static void wait_for_pci_ready(void)
617{
618 if (!(in_be32((void*)GPIO1_IR) & GPIO1_PPC_EREADY)) {
619 printf("PCI: Waiting for EREADY (CTRL-C to skip) ... ");
620 while (1) {
621 if (ctrlc()) {
622 puts("abort\n");
623 break;
624 }
625 if (in_be32((void*)GPIO1_IR) & GPIO1_PPC_EREADY) {
626 printf("done\n");
627 break;
628 }
629 }
630 }
631}
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646#if defined(CONFIG_PCI)
647int is_pci_host(struct pci_controller *hose)
648{
649 char *s = getenv("pciscan");
650 if (s == NULL)
651 if (is_monarch()) {
652 wait_for_pci_ready();
653 return 1;
654 } else
655 return 0;
656 else if (!strcmp(s, "yes"))
657 return 1;
658
659 return 0;
660}
661#endif
662
663#ifdef CONFIG_RESET_PHY_R
664void reset_phy(void)
665{
666 char *s;
667 unsigned short val_method, val_behavior;
668
669
670 if ((s = getenv("bd_type")) &&
671 ((!strcmp(s, "ngcc")) || (!strcmp(s, "candes")))) {
672 val_method = 0x0e0a;
673 val_behavior = 0x0cf2;
674 } else {
675
676 val_method = 0x0e10;
677 val_behavior = 0x0cf0;
678 }
679
680 if (miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x1f, 0x0001) == 0) {
681 miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x11, 0x0010);
682 miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x11, val_behavior);
683 miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x10, val_method);
684 miiphy_write("ppc_4xx_eth0", CONFIG_PHY_ADDR, 0x1f, 0x0000);
685 }
686
687 if (miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x1f, 0x0001) == 0) {
688 miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x11, 0x0010);
689 miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x11, val_behavior);
690 miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x10, val_method);
691 miiphy_write("ppc_4xx_eth1", CONFIG_PHY1_ADDR, 0x1f, 0x0000);
692 }
693}
694#endif
695
696#if defined(CONFIG_SYS_EEPROM_WREN)
697
698
699
700
701
702
703
704
705
706int eeprom_write_enable(unsigned dev_addr, int state)
707{
708 if ((CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) &&
709 (CONFIG_SYS_I2C_BOOT_EEPROM_ADDR != dev_addr)) {
710 return -1;
711 } else {
712 switch (state) {
713 case 1:
714
715 out_be32((void *)GPIO0_OR,
716 in_be32((void *)GPIO0_OR) & ~GPIO0_EP_EEP);
717 state = 0;
718 break;
719 case 0:
720
721 out_be32((void *)GPIO0_OR,
722 in_be32((void *)GPIO0_OR) | GPIO0_EP_EEP);
723 state = 0;
724 break;
725 default:
726
727 state = (0 == (in_be32((void *)GPIO0_OR)
728 & GPIO0_EP_EEP));
729 break;
730 }
731 }
732 return state;
733}
734#endif
735
736#define CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS 3
737int bootstrap_eeprom_write(unsigned dev_addr, unsigned offset,
738 uchar *buffer, unsigned cnt)
739{
740 unsigned end = offset + cnt;
741 unsigned blk_off;
742 int rcode = 0;
743
744#if defined(CONFIG_SYS_EEPROM_WREN)
745 eeprom_write_enable(dev_addr, 1);
746#endif
747
748
749
750
751
752
753 while (offset < end) {
754 unsigned alen, len;
755 unsigned maxlen;
756 uchar addr[2];
757
758 blk_off = offset & 0xFF;
759
760 addr[0] = offset >> 8;
761 addr[1] = blk_off;
762 alen = 2;
763 addr[0] |= dev_addr;
764
765 len = end - offset;
766
767#define BOOT_EEPROM_PAGE_SIZE (1 << CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
768#define BOOT_EEPROM_PAGE_OFFSET(x) ((x) & (BOOT_EEPROM_PAGE_SIZE - 1))
769
770 maxlen = BOOT_EEPROM_PAGE_SIZE -
771 BOOT_EEPROM_PAGE_OFFSET(blk_off);
772 if (maxlen > I2C_RXTX_LEN)
773 maxlen = I2C_RXTX_LEN;
774
775 if (len > maxlen)
776 len = maxlen;
777
778 if (i2c_write (addr[0], offset, alen-1, buffer, len) != 0)
779 rcode = 1;
780
781 buffer += len;
782 offset += len;
783
784#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
785 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
786#endif
787 }
788#if defined(CONFIG_SYS_EEPROM_WREN)
789 eeprom_write_enable(dev_addr, 0);
790#endif
791 return rcode;
792}
793
794int bootstrap_eeprom_read (unsigned dev_addr, unsigned offset,
795 uchar *buffer, unsigned cnt)
796{
797 unsigned end = offset + cnt;
798 unsigned blk_off;
799 int rcode = 0;
800
801
802
803
804
805
806 while (offset < end) {
807 unsigned alen, len;
808 unsigned maxlen;
809 uchar addr[2];
810
811 blk_off = offset & 0xFF;
812
813 addr[0] = offset >> 8;
814 addr[1] = blk_off;
815 alen = 2;
816
817 addr[0] |= dev_addr;
818
819 len = end - offset;
820
821 maxlen = 0x100 - blk_off;
822 if (maxlen > I2C_RXTX_LEN)
823 maxlen = I2C_RXTX_LEN;
824 if (len > maxlen)
825 len = maxlen;
826
827 if (i2c_read (addr[0], offset, alen-1, buffer, len) != 0)
828 rcode = 1;
829 buffer += len;
830 offset += len;
831 }
832
833 return rcode;
834}
835
836#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
837int usb_board_init(void)
838{
839 char *act = getenv("usbact");
840 int i;
841
842 if ((act == NULL || strcmp(act, "host") == 0) &&
843 !(in_be32((void*)GPIO0_IR) & GPIO0_USB_PRSNT))
844
845 out_be32((void*)GPIO1_OR,
846 in_be32((void*)GPIO1_OR) & ~GPIO1_USB_PWR_N);
847
848 for (i=0; i<1000; i++)
849 udelay(1000);
850
851 return 0;
852}
853
854int usb_board_stop(void)
855{
856
857 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_USB_PWR_N);
858 return 0;
859}
860
861int usb_board_init_fail(void)
862{
863 usb_board_stop();
864 return 0;
865}
866#endif
867
868#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
869void ft_board_setup(void *blob, bd_t *bd)
870{
871 int rc;
872
873 __ft_board_setup(blob, bd);
874
875
876
877
878 if (!is_monarch()) {
879 rc = fdt_find_and_setprop(blob, "/plb/pci@1ec000000", "status",
880 "disabled", sizeof("disabled"), 1);
881 if (rc) {
882 printf("Unable to update property status in PCI node, err=%s\n",
883 fdt_strerror(rc));
884 }
885 }
886}
887#endif
888