]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/pcs440ep/pcs440ep.c
Merge git://www.denx.de/git/u-boot
[people/ms/u-boot.git] / board / pcs440ep / pcs440ep.c
1 /*
2 * (C) Copyright 2006
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 #include <common.h>
25 #include <ppc4xx.h>
26 #include <malloc.h>
27 #include <command.h>
28 #include <crc.h>
29 #include <asm/processor.h>
30 #include <spd_sdram.h>
31 #include <status_led.h>
32 #include <sha1.h>
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
37
38 unsigned char sha1_checksum[SHA1_SUM_LEN];
39
40 /* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
41 unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
42 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
43
44 static void set_leds (int val)
45 {
46 out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
47 }
48
49 #define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
50
51 void __led_init (led_id_t mask, int state)
52 {
53 int val = GET_LEDS;
54
55 if (state == STATUS_LED_ON)
56 val |= mask;
57 else
58 val &= ~mask;
59 set_leds (val);
60 }
61
62 void __led_set (led_id_t mask, int state)
63 {
64 int val = GET_LEDS;
65
66 if (state == STATUS_LED_ON)
67 val |= mask;
68 else if (state == STATUS_LED_OFF)
69 val &= ~mask;
70 set_leds (val);
71 }
72
73 void __led_toggle (led_id_t mask)
74 {
75 int val = GET_LEDS;
76
77 val ^= mask;
78 set_leds (val);
79 }
80
81 static void status_led_blink (void)
82 {
83 int i;
84 int val = GET_LEDS;
85
86 /* set all LED which are on, to state BLINKING */
87 for (i = 0; i < 4; i++) {
88 if (val & 0x08) status_led_set (i, STATUS_LED_BLINKING);
89 val = val << 1;
90 }
91 }
92
93 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
94 void show_boot_progress (int val)
95 {
96 /* find all valid Codes for val in README */
97 if (val == -30) return;
98 if (val < 0) {
99 /* smthing goes wrong */
100 status_led_blink ();
101 return;
102 }
103 switch (val) {
104 case 1:
105 /* validating Image */
106 status_led_set (0, STATUS_LED_OFF);
107 status_led_set (1, STATUS_LED_ON);
108 status_led_set (2, STATUS_LED_ON);
109 break;
110 case 15:
111 /* booting */
112 status_led_set (0, STATUS_LED_ON);
113 status_led_set (1, STATUS_LED_ON);
114 status_led_set (2, STATUS_LED_ON);
115 break;
116 case 64:
117 /* starting Ethernet configuration */
118 status_led_set (0, STATUS_LED_OFF);
119 status_led_set (1, STATUS_LED_OFF);
120 status_led_set (2, STATUS_LED_ON);
121 break;
122 case 80:
123 /* loading Image */
124 status_led_set (0, STATUS_LED_ON);
125 status_led_set (1, STATUS_LED_OFF);
126 status_led_set (2, STATUS_LED_ON);
127 break;
128 }
129 }
130 #endif
131
132 int board_early_init_f(void)
133 {
134 register uint reg;
135
136 set_leds(0); /* display boot info counter */
137
138 /*--------------------------------------------------------------------
139 * Setup the external bus controller/chip selects
140 *-------------------------------------------------------------------*/
141 mtdcr(ebccfga, xbcfg);
142 reg = mfdcr(ebccfgd);
143 mtdcr(ebccfgd, reg | 0x04000000); /* Set ATC */
144
145 /*--------------------------------------------------------------------
146 * GPIO's are alreay setup in cpu/ppc4xx/cpu_init.c
147 * via define from board config file.
148 *-------------------------------------------------------------------*/
149
150 /*--------------------------------------------------------------------
151 * Setup the interrupt controller polarities, triggers, etc.
152 *-------------------------------------------------------------------*/
153 mtdcr(uic0sr, 0xffffffff); /* clear all */
154 mtdcr(uic0er, 0x00000000); /* disable all */
155 mtdcr(uic0cr, 0x00000001); /* UIC1 crit is critical */
156 mtdcr(uic0pr, 0xfffffe1f); /* per ref-board manual */
157 mtdcr(uic0tr, 0x01c00000); /* per ref-board manual */
158 mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
159 mtdcr(uic0sr, 0xffffffff); /* clear all */
160
161 mtdcr(uic1sr, 0xffffffff); /* clear all */
162 mtdcr(uic1er, 0x00000000); /* disable all */
163 mtdcr(uic1cr, 0x00000000); /* all non-critical */
164 mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
165 mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
166 mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
167 mtdcr(uic1sr, 0xffffffff); /* clear all */
168
169 /*--------------------------------------------------------------------
170 * Setup other serial configuration
171 *-------------------------------------------------------------------*/
172 mfsdr(sdr_pci0, reg);
173 mtsdr(sdr_pci0, 0x80000000 | reg); /* PCI arbiter enabled */
174 mtsdr(sdr_pfc0, 0x00000100); /* Pin function: enable GPIO49-63 */
175 mtsdr(sdr_pfc1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
176
177 return 0;
178 }
179
180 #define EEPROM_LEN 256
181 void load_sernum_ethaddr (void)
182 {
183 int ret;
184 char buf[EEPROM_LEN];
185 char mac[32];
186 char *use_eeprom;
187 u16 checksumcrc16 = 0;
188
189 /* read the MACs from EEprom */
190 status_led_set (0, STATUS_LED_ON);
191 status_led_set (1, STATUS_LED_ON);
192 ret = eeprom_read (CFG_I2C_EEPROM_ADDR, 0, (uchar *)buf, EEPROM_LEN);
193 if (ret == 0) {
194 checksumcrc16 = cyg_crc16 ((uchar *)buf, EEPROM_LEN - 2);
195 /* check, if the EEprom is programmed:
196 * - The Prefix(Byte 0,1,2) is equal to "ATR"
197 * - The checksum, stored in the last 2 Bytes, is correct
198 */
199 if ((strncmp (buf,"ATR",3) != 0) ||
200 ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
201 ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
202 /* EEprom is not programmed */
203 printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
204 } else {
205 /* get the MACs */
206 sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
207 buf[3],
208 buf[4],
209 buf[5],
210 buf[6],
211 buf[7],
212 buf[8]);
213 setenv ("ethaddr", (char *) mac);
214 sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
215 buf[9],
216 buf[10],
217 buf[11],
218 buf[12],
219 buf[13],
220 buf[14]);
221 setenv ("eth1addr", (char *) mac);
222 return;
223 }
224 }
225
226 /* some error reading the EEprom */
227 if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
228 /* dont use bootcmd */
229 setenv("bootdelay", "-1");
230 return;
231 }
232 /* == default ? use standard */
233 if (strncmp (use_eeprom, "default", 7) == 0) {
234 return;
235 }
236 /* Env doesnt exist -> hang */
237 status_led_blink ();
238 hang ();
239 return;
240 }
241
242 #ifdef CONFIG_PREBOOT
243
244 static uchar kbd_magic_prefix[] = "key_magic";
245 static uchar kbd_command_prefix[] = "key_cmd";
246
247 struct kbd_data_t {
248 char s1;
249 char s2;
250 };
251
252 struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
253 {
254 char *val;
255 unsigned long tmp;
256
257 /* use the DIPs for some bootoptions */
258 val = getenv (ENV_NAME_DIP);
259 tmp = simple_strtoul (val, NULL, 16);
260
261 kbd_data->s2 = (tmp & 0x0f);
262 kbd_data->s1 = (tmp & 0xf0) >> 4;
263 return kbd_data;
264 }
265
266 static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
267 {
268 char s1 = str[0];
269
270 if (s1 >= '0' && s1 <= '9')
271 s1 -= '0';
272 else if (s1 >= 'a' && s1 <= 'f')
273 s1 = s1 - 'a' + 10;
274 else if (s1 >= 'A' && s1 <= 'F')
275 s1 = s1 - 'A' + 10;
276 else
277 return -1;
278
279 if (s1 != kbd_data->s1) return -1;
280
281 s1 = str[1];
282 if (s1 >= '0' && s1 <= '9')
283 s1 -= '0';
284 else if (s1 >= 'a' && s1 <= 'f')
285 s1 = s1 - 'a' + 10;
286 else if (s1 >= 'A' && s1 <= 'F')
287 s1 = s1 - 'A' + 10;
288 else
289 return -1;
290
291 if (s1 != kbd_data->s2) return -1;
292 return 0;
293 }
294
295 static char *key_match (const struct kbd_data_t *kbd_data)
296 {
297 char magic[sizeof (kbd_magic_prefix) + 1];
298 char *suffix;
299 char *kbd_magic_keys;
300
301 /*
302 * The following string defines the characters that can be appended
303 * to "key_magic" to form the names of environment variables that
304 * hold "magic" key codes, i. e. such key codes that can cause
305 * pre-boot actions. If the string is empty (""), then only
306 * "key_magic" is checked (old behaviour); the string "125" causes
307 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
308 */
309 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
310 kbd_magic_keys = "";
311
312 /* loop over all magic keys;
313 * use '\0' suffix in case of empty string
314 */
315 for (suffix = kbd_magic_keys; *suffix ||
316 suffix == kbd_magic_keys; ++suffix) {
317 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
318 if (compare_magic (kbd_data, getenv (magic)) == 0) {
319 char cmd_name[sizeof (kbd_command_prefix) + 1];
320 char *cmd;
321
322 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
323 cmd = getenv (cmd_name);
324
325 return (cmd);
326 }
327 }
328 return (NULL);
329 }
330
331 #endif /* CONFIG_PREBOOT */
332
333 static int pcs440ep_readinputs (void)
334 {
335 int i;
336 char value[20];
337
338 /* read the inputs and set the Envvars */
339 /* Revision Level Bit 26 - 29 */
340 i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
341 i = swapbits[i];
342 sprintf (value, "%02x", i);
343 setenv (ENV_NAME_REVLEV, value);
344 /* Solder Switch Bit 30 - 33 */
345 i = (in32 (GPIO0_IR) & 0x00000003) << 2;
346 i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
347 i = swapbits[i];
348 sprintf (value, "%02x", i);
349 setenv (ENV_NAME_SOLDER, value);
350 /* DIP Switch Bit 49 - 56 */
351 i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
352 i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
353 sprintf (value, "%02x", i);
354 setenv (ENV_NAME_DIP, value);
355 return 0;
356 }
357
358
359 #if defined(CONFIG_SHA1_CHECK_UB_IMG)
360 /*************************************************************************
361 * calculate a SHA1 sum for the U-Boot image in Flash.
362 *
363 ************************************************************************/
364 static int pcs440ep_sha1 (int docheck)
365 {
366 unsigned char *data;
367 unsigned char *ptroff;
368 unsigned char output[20];
369 unsigned char org[20];
370 int i, len = CONFIG_SHA1_LEN;
371
372 memcpy ((char *)CFG_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
373 data = (unsigned char *)CFG_LOAD_ADDR;
374 ptroff = &data[len + SHA1_SUM_POS];
375
376 for (i = 0; i < SHA1_SUM_LEN; i++) {
377 org[i] = ptroff[i];
378 ptroff[i] = 0;
379 }
380
381 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
382
383 if (docheck == 2) {
384 for (i = 0; i < 20 ; i++) {
385 printf("%02X ", output[i]);
386 }
387 printf("\n");
388 }
389 if (docheck == 1) {
390 for (i = 0; i < 20 ; i++) {
391 if (org[i] != output[i]) return 1;
392 }
393 }
394 return 0;
395 }
396
397 /*************************************************************************
398 * do some checks after the SHA1 checksum from the U-Boot Image was
399 * calculated.
400 *
401 ************************************************************************/
402 static void pcs440ep_checksha1 (void)
403 {
404 int ret;
405 char *cs_test;
406
407 ret = pcs440ep_sha1 (1);
408 if (ret == 0) return;
409
410 if ((cs_test = getenv ("cs_test")) == NULL) {
411 /* Env doesnt exist -> hang */
412 status_led_blink ();
413 hang ();
414 }
415
416 if (strncmp (cs_test, "off", 3) == 0) {
417 printf ("SHA1 U-Boot sum NOT ok!\n");
418 setenv ("bootdelay", "-1");
419 }
420 }
421 #else
422 static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
423 #endif
424
425 int misc_init_r (void)
426 {
427 uint pbcr;
428 int size_val = 0;
429
430 /* Re-do sizing to get full correct info */
431 mtdcr(ebccfga, pb0cr);
432 pbcr = mfdcr(ebccfgd);
433 switch (gd->bd->bi_flashsize) {
434 case 1 << 20:
435 size_val = 0;
436 break;
437 case 2 << 20:
438 size_val = 1;
439 break;
440 case 4 << 20:
441 size_val = 2;
442 break;
443 case 8 << 20:
444 size_val = 3;
445 break;
446 case 16 << 20:
447 size_val = 4;
448 break;
449 case 32 << 20:
450 size_val = 5;
451 break;
452 case 64 << 20:
453 size_val = 6;
454 break;
455 case 128 << 20:
456 size_val = 7;
457 break;
458 }
459 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
460 mtdcr(ebccfga, pb0cr);
461 mtdcr(ebccfgd, pbcr);
462
463 /* adjust flash start and offset */
464 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
465 gd->bd->bi_flashoffset = 0;
466
467 /* Monitor protection ON by default */
468 (void)flash_protect(FLAG_PROTECT_SET,
469 -CFG_MONITOR_LEN,
470 0xffffffff,
471 &flash_info[1]);
472
473 /* Env protection ON by default */
474 (void)flash_protect(FLAG_PROTECT_SET,
475 CFG_ENV_ADDR_REDUND,
476 CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
477 &flash_info[1]);
478
479 pcs440ep_readinputs ();
480 pcs440ep_checksha1 ();
481 #ifdef CONFIG_PREBOOT
482 {
483 struct kbd_data_t kbd_data;
484 /* Decode keys */
485 char *str = strdup (key_match (get_keys (&kbd_data)));
486 /* Set or delete definition */
487 setenv ("preboot", str);
488 free (str);
489 }
490 #endif /* CONFIG_PREBOOT */
491 return 0;
492 }
493
494 int checkboard(void)
495 {
496 char *s = getenv("serial#");
497
498 printf("Board: PCS440EP");
499 if (s != NULL) {
500 puts(", serial# ");
501 puts(s);
502 }
503 putc('\n');
504
505 return (0);
506 }
507
508 void spd_ddr_init_hang (void)
509 {
510 status_led_set (0, STATUS_LED_OFF);
511 status_led_set (1, STATUS_LED_ON);
512 /* we cannot use hang() because we are still running from
513 Flash, and so the status_led driver is not initialized */
514 puts ("### ERROR ### Please RESET the board ###\n");
515 for (;;) {
516 __led_toggle (4);
517 udelay (100000);
518 }
519 }
520
521 long int initdram (int board_type)
522 {
523 long dram_size = 0;
524
525 status_led_set (0, STATUS_LED_ON);
526 status_led_set (1, STATUS_LED_OFF);
527 dram_size = spd_sdram();
528 status_led_set (0, STATUS_LED_OFF);
529 status_led_set (1, STATUS_LED_ON);
530 if (dram_size == 0) {
531 hang();
532 }
533
534 return dram_size;
535 }
536
537 #if defined(CFG_DRAM_TEST)
538 int testdram(void)
539 {
540 unsigned long *mem = (unsigned long *)0;
541 const unsigned long kend = (1024 / sizeof(unsigned long));
542 unsigned long k, n;
543
544 mtmsr(0);
545
546 for (k = 0; k < CFG_KBYTES_SDRAM;
547 ++k, mem += (1024 / sizeof(unsigned long))) {
548 if ((k & 1023) == 0) {
549 printf("%3d MB\r", k / 1024);
550 }
551
552 memset(mem, 0xaaaaaaaa, 1024);
553 for (n = 0; n < kend; ++n) {
554 if (mem[n] != 0xaaaaaaaa) {
555 printf("SDRAM test fails at: %08x\n",
556 (uint) & mem[n]);
557 return 1;
558 }
559 }
560
561 memset(mem, 0x55555555, 1024);
562 for (n = 0; n < kend; ++n) {
563 if (mem[n] != 0x55555555) {
564 printf("SDRAM test fails at: %08x\n",
565 (uint) & mem[n]);
566 return 1;
567 }
568 }
569 }
570 printf("SDRAM test passes\n");
571 return 0;
572 }
573 #endif
574
575 /*************************************************************************
576 * pci_pre_init
577 *
578 * This routine is called just prior to registering the hose and gives
579 * the board the opportunity to check things. Returning a value of zero
580 * indicates that things are bad & PCI initialization should be aborted.
581 *
582 * Different boards may wish to customize the pci controller structure
583 * (add regions, override default access routines, etc) or perform
584 * certain pre-initialization actions.
585 *
586 ************************************************************************/
587 #if defined(CONFIG_PCI)
588 int pci_pre_init(struct pci_controller *hose)
589 {
590 unsigned long addr;
591
592 /*-------------------------------------------------------------------------+
593 | Set priority for all PLB3 devices to 0.
594 | Set PLB3 arbiter to fair mode.
595 +-------------------------------------------------------------------------*/
596 mfsdr(sdr_amp1, addr);
597 mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
598 addr = mfdcr(plb3_acr);
599 mtdcr(plb3_acr, addr | 0x80000000);
600
601 /*-------------------------------------------------------------------------+
602 | Set priority for all PLB4 devices to 0.
603 +-------------------------------------------------------------------------*/
604 mfsdr(sdr_amp0, addr);
605 mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
606 addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
607 mtdcr(plb4_acr, addr);
608
609 /*-------------------------------------------------------------------------+
610 | Set Nebula PLB4 arbiter to fair mode.
611 +-------------------------------------------------------------------------*/
612 /* Segment0 */
613 addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
614 addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
615 addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
616 addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
617 mtdcr(plb0_acr, addr);
618
619 /* Segment1 */
620 addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
621 addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
622 addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
623 addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
624 mtdcr(plb1_acr, addr);
625
626 return 1;
627 }
628 #endif /* defined(CONFIG_PCI) */
629
630 /*************************************************************************
631 * pci_target_init
632 *
633 * The bootstrap configuration provides default settings for the pci
634 * inbound map (PIM). But the bootstrap config choices are limited and
635 * may not be sufficient for a given board.
636 *
637 ************************************************************************/
638 #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
639 void pci_target_init(struct pci_controller *hose)
640 {
641 /*--------------------------------------------------------------------------+
642 * Set up Direct MMIO registers
643 *--------------------------------------------------------------------------*/
644 /*--------------------------------------------------------------------------+
645 | PowerPC440 EP PCI Master configuration.
646 | Map one 1Gig range of PLB/processor addresses to PCI memory space.
647 | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
648 | Use byte reversed out routines to handle endianess.
649 | Make this region non-prefetchable.
650 +--------------------------------------------------------------------------*/
651 out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
652 out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
653 out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
654 out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
655 out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
656
657 out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
658 out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
659 out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
660 out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
661 out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
662
663 out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
664 out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
665 out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
666 out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
667
668 /*--------------------------------------------------------------------------+
669 * Set up Configuration registers
670 *--------------------------------------------------------------------------*/
671
672 /* Program the board's subsystem id/vendor id */
673 pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
674 CFG_PCI_SUBSYS_VENDORID);
675 pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
676
677 /* Configure command register as bus master */
678 pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
679
680 /* 240nS PCI clock */
681 pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
682
683 /* No error reporting */
684 pci_write_config_word(0, PCI_ERREN, 0);
685
686 pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
687
688 }
689 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
690
691 /*************************************************************************
692 * pci_master_init
693 *
694 ************************************************************************/
695 #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
696 void pci_master_init(struct pci_controller *hose)
697 {
698 unsigned short temp_short;
699
700 /*--------------------------------------------------------------------------+
701 | Write the PowerPC440 EP PCI Configuration regs.
702 | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
703 | Enable PowerPC440 EP to act as a PCI memory target (PTM).
704 +--------------------------------------------------------------------------*/
705 pci_read_config_word(0, PCI_COMMAND, &temp_short);
706 pci_write_config_word(0, PCI_COMMAND,
707 temp_short | PCI_COMMAND_MASTER |
708 PCI_COMMAND_MEMORY);
709 }
710 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
711
712 /*************************************************************************
713 * is_pci_host
714 *
715 * This routine is called to determine if a pci scan should be
716 * performed. With various hardware environments (especially cPCI and
717 * PPMC) it's insufficient to depend on the state of the arbiter enable
718 * bit in the strap register, or generic host/adapter assumptions.
719 *
720 * Rather than hard-code a bad assumption in the general 440 code, the
721 * 440 pci code requires the board to decide at runtime.
722 *
723 * Return 0 for adapter mode, non-zero for host (monarch) mode.
724 *
725 *
726 ************************************************************************/
727 #if defined(CONFIG_PCI)
728 int is_pci_host(struct pci_controller *hose)
729 {
730 /* PCS440EP is always configured as host. */
731 return (1);
732 }
733 #endif /* defined(CONFIG_PCI) */
734
735 /*************************************************************************
736 * hw_watchdog_reset
737 *
738 * This routine is called to reset (keep alive) the watchdog timer
739 *
740 ************************************************************************/
741 #if defined(CONFIG_HW_WATCHDOG)
742 void hw_watchdog_reset(void)
743 {
744
745 }
746 #endif
747
748 /*************************************************************************
749 * "led" Commando for the U-Boot shell
750 *
751 ************************************************************************/
752 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
753 {
754 int rcode = 0;
755 ulong pattern = 0;
756
757 pattern = simple_strtoul (argv[1], NULL, 10);
758 if (pattern > 200) {
759 status_led_blink ();
760 hang ();
761 return rcode;
762 }
763 if (pattern > 100) {
764 status_led_blink ();
765 return rcode;
766 }
767 pattern &= 0x0f;
768 set_leds (pattern);
769 return rcode;
770 }
771
772 U_BOOT_CMD(
773 led, 2, 1, do_led,
774 "led - set the led\n",
775 NULL
776 );
777
778 #if defined(CONFIG_SHA1_CHECK_UB_IMG)
779 /*************************************************************************
780 * "sha1" Commando for the U-Boot shell
781 *
782 ************************************************************************/
783 int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
784 {
785 int rcode = -1;
786
787 if (argc < 2) {
788 usage:
789 printf ("Usage:\n%s\n", cmdtp->usage);
790 return 1;
791 }
792
793 if (argc >= 3) {
794 unsigned char *data;
795 unsigned char output[20];
796 int len;
797 int i;
798
799 data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
800 len = simple_strtoul (argv[2], NULL, 16);
801 sha1_csum (data, len, (unsigned char *)output);
802 printf ("U-Boot sum:\n");
803 for (i = 0; i < 20 ; i++) {
804 printf ("%02X ", output[i]);
805 }
806 printf ("\n");
807 if (argc == 4) {
808 data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
809 memcpy (data, output, 20);
810 }
811 return 0;
812 }
813 if (argc == 2) {
814 char *ptr = argv[1];
815 if (*ptr != '-') goto usage;
816 ptr++;
817 if ((*ptr == 'c') || (*ptr == 'C')) {
818 rcode = pcs440ep_sha1 (1);
819 printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
820 } else if ((*ptr == 'p') || (*ptr == 'P')) {
821 rcode = pcs440ep_sha1 (2);
822 } else {
823 rcode = pcs440ep_sha1 (0);
824 }
825 return rcode;
826 }
827 return rcode;
828 }
829
830 U_BOOT_CMD(
831 sha1, 4, 1, do_sha1,
832 "sha1 - calculate the SHA1 Sum\n",
833 "address len [addr] calculate the SHA1 sum [save at addr]\n"
834 " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
835 " -c check the U-Boot image in flash\n"
836 );
837 #endif
838
839 #ifdef CONFIG_IDE_PREINIT
840 int ide_preinit (void)
841 {
842 /* Set True IDE Mode */
843 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
844 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
845 out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
846 udelay (100000);
847 return 0;
848 }
849 #endif
850
851 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
852 void ide_set_reset (int idereset)
853 {
854 debug ("ide_reset(%d)\n", idereset);
855 if (idereset == 0) {
856 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
857 } else {
858 out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
859 }
860 udelay (10000);
861 }
862 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */