2 * (C) Copyright 2001-2003
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 #include <asm/processor.h>
30 /* ------------------------------------------------------------------------- */
31 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /*cmd_boot.c*/
36 /* fpga configuration data - generated by bin2cc */
37 const unsigned char fpgadata[] =
39 #ifdef CONFIG_CPCI405_VER2
40 # ifdef CONFIG_CPCI405AB
41 # include "fpgadata_cpci405ab.c"
43 # include "fpgadata_cpci4052.c"
46 # include "fpgadata_cpci405.c"
51 * include common fpga code (for esd boards)
53 #include "../common/fpga.c"
56 #include "../common/auto_update.h"
58 #ifdef CONFIG_CPCI405AB
59 au_image_t au_image[] = {
60 {"cpci405ab/preinst.img", 0, -1, AU_SCRIPT},
61 {"cpci405ab/pImage", 0xffc00000, 0x000c0000, AU_NOR},
62 {"cpci405ab/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
63 {"cpci405ab/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
64 {"cpci405ab/postinst.img", 0, 0, AU_SCRIPT},
67 #ifdef CONFIG_CPCI405_VER2
68 au_image_t au_image[] = {
69 {"cpci4052/preinst.img", 0, -1, AU_SCRIPT},
70 {"cpci4052/pImage", 0xffc00000, 0x000c0000, AU_NOR},
71 {"cpci4052/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
72 {"cpci4052/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
73 {"cpci4052/postinst.img", 0, 0, AU_SCRIPT},
76 au_image_t au_image[] = {
77 {"cpci405/preinst.img", 0, -1, AU_SCRIPT},
78 {"cpci405/pImage", 0xffc00000, 0x000c0000, AU_NOR},
79 {"cpci405/pImage.initrd", 0xffcc0000, 0x00310000, AU_NOR},
80 {"cpci405/u-boot.img", 0xfffd0000, 0x00030000, AU_FIRMWARE},
81 {"cpci405/postinst.img", 0, 0, AU_SCRIPT},
86 int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
90 int cpci405_version(void);
91 int gunzip(void *, int, unsigned char *, unsigned long *);
92 void lxt971_no_sleep(void);
95 int board_early_init_f (void)
97 #ifndef CONFIG_CPCI405_VER2
103 DECLARE_GLOBAL_DATA_PTR;
105 /* set up serial port with default baudrate */
106 (void) get_clocks ();
107 gd->baudrate = CONFIG_BAUDRATE;
113 * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
115 out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
116 out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
117 out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
118 out32(GPIO0_OR, 0); /* pull prg low */
123 #ifndef CONFIG_CPCI405_VER2
124 if (cpci405_version() == 1) {
125 status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
127 /* booting FPGA failed */
129 DECLARE_GLOBAL_DATA_PTR;
131 /* set up serial port with default baudrate */
132 (void) get_clocks ();
133 gd->baudrate = CONFIG_BAUDRATE;
137 printf("\nFPGA: Booting failed ");
139 case ERROR_FPGA_PRG_INIT_LOW:
140 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
142 case ERROR_FPGA_PRG_INIT_HIGH:
143 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
145 case ERROR_FPGA_PRG_DONE:
146 printf("(Timeout: DONE not high after programming FPGA)\n ");
150 /* display infos on fpgaimage */
152 for (i=0; i<4; i++) {
153 len = fpgadata[index];
154 printf("FPGA: %s\n", &(fpgadata[index+1]));
159 for (i=20; i>0; i--) {
160 printf("Rebooting in %2d seconds \r",i);
161 for (index=0;index<1000;index++)
165 do_reset(NULL, 0, 0, NULL);
168 #endif /* !CONFIG_CPCI405_VER2 */
171 * IRQ 0-15 405GP internally generated; active high; level sensitive
172 * IRQ 16 405GP internally generated; active low; level sensitive
174 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
175 * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive
176 * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
177 * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
178 * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
179 * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
180 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
182 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
183 mtdcr(uicer, 0x00000000); /* disable all ints */
184 mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
185 if (cpci405_version() == 3) {
186 mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
188 mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
190 mtdcr(uictr, 0x10000000); /* set int trigger levels */
191 mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
192 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
198 /* ------------------------------------------------------------------------- */
202 #ifdef CONFIG_CPCI405_VER2
203 return 0; /* no, board is cpci405 */
205 if ((*(unsigned char *)0xf0000400 == 0x00) &&
206 (*(unsigned char *)0xf0000401 == 0x01))
207 return 0; /* no, board is cpci405 */
209 return -1; /* yes, board is cterm-m2 */
214 int cpci405_host(void)
216 if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
217 return -1; /* yes, board is cpci405 host */
219 return 0; /* no, board is cpci405 adapter */
223 int cpci405_version(void)
225 unsigned long cntrl0Reg;
229 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
231 cntrl0Reg = mfdcr(cntrl0);
232 mtdcr(cntrl0, cntrl0Reg | 0x03000000);
233 out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00180000);
234 out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00180000);
235 udelay(1000); /* wait some time before reading input */
236 value = in32(GPIO0_IR) & 0x00180000; /* get config bits */
239 * Restore GPIO settings
241 mtdcr(cntrl0, cntrl0Reg);
245 /* CS2==1 && CS3==1 -> version 1 */
248 /* CS2==0 && CS3==1 -> version 2 */
251 /* CS2==1 && CS3==0 -> version 3 */
254 /* CS2==0 && CS3==0 -> version 4 */
257 /* should not be reached! */
263 int misc_init_f (void)
265 return 0; /* dummy implementation */
269 int misc_init_r (void)
271 DECLARE_GLOBAL_DATA_PTR;
272 unsigned long cntrl0Reg;
274 /* adjust flash start and offset */
275 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
276 gd->bd->bi_flashoffset = 0;
278 #ifdef CONFIG_CPCI405_VER2
281 ulong len = sizeof(fpgadata);
287 * On CPCI-405 version 2 the environment is saved in eeprom!
288 * FPGA can be gzip compressed (malloc) and booted this late.
291 if (cpci405_version() >= 2) {
293 * Setup GPIO pins (CS6+CS7 as GPIO)
295 cntrl0Reg = mfdcr(cntrl0);
296 mtdcr(cntrl0, cntrl0Reg | 0x00300000);
298 dst = malloc(CFG_FPGA_MAX_SIZE);
299 if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
300 printf ("GUNZIP ERROR - must RESET board to recover\n");
301 do_reset (NULL, 0, 0, NULL);
304 status = fpga_boot(dst, len);
306 printf("\nFPGA: Booting failed ");
308 case ERROR_FPGA_PRG_INIT_LOW:
309 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
311 case ERROR_FPGA_PRG_INIT_HIGH:
312 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
314 case ERROR_FPGA_PRG_DONE:
315 printf("(Timeout: DONE not high after programming FPGA)\n ");
319 /* display infos on fpgaimage */
321 for (i=0; i<4; i++) {
323 printf("FPGA: %s\n", &(dst[index+1]));
328 for (i=20; i>0; i--) {
329 printf("Rebooting in %2d seconds \r",i);
330 for (index=0;index<1000;index++)
334 do_reset(NULL, 0, 0, NULL);
337 /* restore gpio/cs settings */
338 mtdcr(cntrl0, cntrl0Reg);
342 /* display infos on fpgaimage */
344 for (i=0; i<4; i++) {
346 printf("%s ", &(dst[index+1]));
354 * Reset FPGA via FPGA_DATA pin
356 SET_FPGA(FPGA_PRG | FPGA_CLK);
357 udelay(1000); /* wait 1ms */
358 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
359 udelay(1000); /* wait 1ms */
361 if (cpci405_version() == 3) {
362 volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
363 volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR;
366 * Enable outputs in fpga on version 3 board
368 *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT;
376 * Reset external DUART
378 *fpga_mode |= CFG_FPGA_MODE_DUART_RESET;
380 *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET);
384 puts("\n*** U-Boot Version does not match Board Version!\n");
385 puts("*** CPCI-405 Version 1.x detected!\n");
386 puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n");
390 #else /* CONFIG_CPCI405_VER2 */
392 #if 0 /* test-only: code-plug now not relavant for ip-address any more */
394 * Generate last byte of ip-addr from code-plug @ 0xf0000400
398 unsigned char ipbyte = *(unsigned char *)0xf0000400;
401 * Only overwrite ip-addr with allowed values
403 if ((ipbyte != 0x00) && (ipbyte != 0xff)) {
404 bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte;
405 sprintf(str, "%ld.%ld.%ld.%ld",
406 (bd->bi_ip_addr & 0xff000000) >> 24,
407 (bd->bi_ip_addr & 0x00ff0000) >> 16,
408 (bd->bi_ip_addr & 0x0000ff00) >> 8,
409 (bd->bi_ip_addr & 0x000000ff));
410 setenv("ipaddr", str);
415 if (cpci405_version() >= 2) {
416 puts("\n*** U-Boot Version does not match Board Version!\n");
417 puts("*** CPCI-405 Board Version 2.x detected!\n");
418 puts("*** Please use correct U-Boot version (CPCI4052 instead of CPCI405)!\n\n");
421 #endif /* CONFIG_CPCI405_VER2 */
424 * Select cts (and not dsr) on uart1
426 cntrl0Reg = mfdcr(cntrl0);
427 mtdcr(cntrl0, cntrl0Reg | 0x00001000);
434 * Check Board Identity:
437 int checkboard (void)
439 #ifndef CONFIG_CPCI405_VER2
444 int i = getenv_r ("serial#", str, sizeof(str));
450 puts ("### No HW ID - assuming CPCI405");
455 ver = cpci405_version();
456 printf(" (Ver %d.x, ", ver);
458 #if 0 /* test-only */
460 volatile u16 *fpga_status = (u16 *)CFG_FPGA_BASE_ADDR + 1;
462 if (*fpga_status & CFG_FPGA_STATUS_FLASH) {
463 puts ("FLASH Bank B, ");
465 puts ("FLASH Bank A, ");
474 * Read board-id and save in env-variable
476 sprintf(str, "%d", *(unsigned char *)0xf0000400);
477 setenv("boardid", str);
478 printf("CTERM-M2 - Id=%s)", str);
480 if (cpci405_host()) {
481 puts ("PCI Host Version)");
483 puts ("PCI Adapter Version)");
487 #ifndef CONFIG_CPCI405_VER2
490 /* display infos on fpgaimage */
492 for (i=0; i<4; i++) {
493 len = fpgadata[index];
494 printf("%s ", &(fpgadata[index+1]));
502 * Disable sleep mode in LXT971
509 /* ------------------------------------------------------------------------- */
511 long int initdram (int board_type)
515 mtdcr(memcfga, mem_mb0cf);
516 val = mfdcr(memcfgd);
519 printf("\nmb0cf=%x\n", val); /* test-only */
520 printf("strap=%x\n", mfdcr(strap)); /* test-only */
523 return (4*1024*1024 << ((val & 0x000e0000) >> 17));
526 /* ------------------------------------------------------------------------- */
530 /* TODO: XXX XXX XXX */
531 printf ("test: 16 MB - ok\n");
536 /* ------------------------------------------------------------------------- */
538 #ifdef CONFIG_CPCI405_VER2
539 #ifdef CONFIG_IDE_RESET
541 void ide_set_reset(int on)
543 volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
546 * Assert or deassert CompactFlash Reset Pin
548 if (on) { /* assert RESET */
549 *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET);
550 } else { /* release RESET */
551 *fpga_mode |= CFG_FPGA_MODE_CF_RESET;
555 #endif /* CONFIG_IDE_RESET */
556 #endif /* CONFIG_CPCI405_VER2 */
559 #ifdef CONFIG_CPCI405AB
561 #define ONE_WIRE_CLEAR (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
562 |= CFG_FPGA_MODE_1WIRE_DIR)
563 #define ONE_WIRE_SET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
564 &= ~CFG_FPGA_MODE_1WIRE_DIR)
565 #define ONE_WIRE_GET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_STATUS) \
566 & CFG_FPGA_MODE_1WIRE)
569 * Generate a 1-wire reset, return 1 if no presence detect was found,
570 * return 0 otherwise.
571 * (NOTE: Does not handle alarm presence from DS2404/DS1994)
573 int OWTouchReset(void)
582 result = ONE_WIRE_GET;
590 * Send 1 a 1-wire write bit.
591 * Provide 10us recovery time.
593 void OWWriteBit(int bit)
616 * Read a bit from the 1-wire bus and return it.
617 * Provide 10us recovery time.
628 result = ONE_WIRE_GET;
635 void OWWriteByte(int data)
639 for (loop=0; loop<8; loop++) {
640 OWWriteBit(data & 0x01);
648 int loop, result = 0;
650 for (loop=0; loop<8; loop++) {
661 int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
663 volatile unsigned short val;
666 unsigned char ow_id[6];
668 unsigned char ow_crc;
671 * Clear 1-wire bit (open drain with pull-up)
673 val = *(volatile unsigned short *)0xf0400000;
674 val &= ~0x1000; /* clear 1-wire bit */
675 *(volatile unsigned short *)0xf0400000 = val;
677 result = OWTouchReset();
679 puts("No 1-wire device detected!\n");
682 OWWriteByte(0x33); /* send read rom command */
683 OWReadByte(); /* skip family code ( == 0x01) */
684 for (i=0; i<6; i++) {
685 ow_id[i] = OWReadByte();
687 ow_crc = OWReadByte(); /* read crc */
689 sprintf(str, "%08X%04X", *(unsigned int *)&ow_id[0], *(unsigned short *)&ow_id[4]);
690 printf("Setting environment variable 'ow_id' to %s\n", str);
691 setenv("ow_id", str);
696 onewire, 1, 1, do_onewire,
697 "onewire - Read 1-write ID\n",
702 #define CFG_I2C_EEPROM_ADDR_2 0x51 /* EEPROM CAT28WC32 */
703 #define CFG_ENV_SIZE_2 0x800 /* 2048 bytes may be used for env vars*/
706 * Write backplane ip-address...
708 int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
710 DECLARE_GLOBAL_DATA_PTR;
719 buf = malloc(CFG_ENV_SIZE_2);
720 if (eeprom_read(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
721 puts("\nError reading backplane EEPROM!\n");
723 crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
724 if (crc != *(ulong *)buf) {
725 printf("ERROR: crc mismatch %08lx %08lx\n", crc, *(ulong *)buf);
732 ptr = strstr(buf+4, "bp_ip=");
734 printf("ERROR: bp_ip not found!\n");
738 ipaddr = string_to_ip(ptr);
741 * Update whole ip-addr
743 bd->bi_ip_addr = ipaddr;
744 sprintf(str, "%ld.%ld.%ld.%ld",
745 (bd->bi_ip_addr & 0xff000000) >> 24,
746 (bd->bi_ip_addr & 0x00ff0000) >> 16,
747 (bd->bi_ip_addr & 0x0000ff00) >> 8,
748 (bd->bi_ip_addr & 0x000000ff));
749 setenv("ipaddr", str);
750 printf("Updated ip_addr from bp_eeprom to %s!\n", str);
758 getbpip, 1, 1, do_get_bpip,
759 "getbpip - Update IP-Address with Backplane IP-Address\n",
764 * Set and print backplane ip...
766 int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
777 printf("Setting bp_ip to %s\n", argv[1]);
778 buf = malloc(CFG_ENV_SIZE_2);
779 memset(buf, 0, CFG_ENV_SIZE_2);
780 sprintf(str, "bp_ip=%s", argv[1]);
782 crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
785 if (eeprom_write(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
786 puts("\nError writing backplane EEPROM!\n");
794 setbpip, 2, 1, do_set_bpip,
795 "setbpip - Write Backplane IP-Address\n",
799 #endif /* CONFIG_CPCI405AB */