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>
32 DECLARE_GLOBAL_DATA_PTR;
34 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /*cmd_boot.c*/
39 /* fpga configuration data - generated by bin2cc */
40 const unsigned char fpgadata[] =
42 #ifdef CONFIG_CPCI405_VER2
43 # ifdef CONFIG_CPCI405AB
44 # include "fpgadata_cpci405ab.c"
46 # include "fpgadata_cpci4052.c"
49 # include "fpgadata_cpci405.c"
54 * include common fpga code (for esd boards)
56 #include "../common/fpga.c"
59 #include "../common/auto_update.h"
61 #ifdef CONFIG_CPCI405AB
62 au_image_t au_image[] = {
63 {"cpci405ab/preinst.img", 0, -1, AU_SCRIPT},
64 {"cpci405ab/pImage", 0xffc00000, 0x000c0000, AU_NOR},
65 {"cpci405ab/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
66 {"cpci405ab/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
67 {"cpci405ab/postinst.img", 0, 0, AU_SCRIPT},
70 #ifdef CONFIG_CPCI405_VER2
71 au_image_t au_image[] = {
72 {"cpci4052/preinst.img", 0, -1, AU_SCRIPT},
73 {"cpci4052/pImage", 0xffc00000, 0x000c0000, AU_NOR},
74 {"cpci4052/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR},
75 {"cpci4052/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE},
76 {"cpci4052/postinst.img", 0, 0, AU_SCRIPT},
79 au_image_t au_image[] = {
80 {"cpci405/preinst.img", 0, -1, AU_SCRIPT},
81 {"cpci405/pImage", 0xffc00000, 0x000c0000, AU_NOR},
82 {"cpci405/pImage.initrd", 0xffcc0000, 0x00310000, AU_NOR},
83 {"cpci405/u-boot.img", 0xfffd0000, 0x00030000, AU_FIRMWARE},
84 {"cpci405/postinst.img", 0, 0, AU_SCRIPT},
89 int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
93 int cpci405_version(void);
94 int gunzip(void *, int, unsigned char *, unsigned long *);
95 void lxt971_no_sleep(void);
98 int board_early_init_f (void)
100 #ifndef CONFIG_CPCI405_VER2
106 /* set up serial port with default baudrate */
107 (void) get_clocks ();
108 gd->baudrate = CONFIG_BAUDRATE;
114 * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
116 out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
117 out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
118 out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
119 out32(GPIO0_OR, 0); /* pull prg low */
124 #ifndef CONFIG_CPCI405_VER2
125 if (cpci405_version() == 1) {
126 status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
128 /* booting FPGA failed */
130 /* set up serial port with default baudrate */
131 (void) get_clocks ();
132 gd->baudrate = CONFIG_BAUDRATE;
136 printf("\nFPGA: Booting failed ");
138 case ERROR_FPGA_PRG_INIT_LOW:
139 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
141 case ERROR_FPGA_PRG_INIT_HIGH:
142 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
144 case ERROR_FPGA_PRG_DONE:
145 printf("(Timeout: DONE not high after programming FPGA)\n ");
149 /* display infos on fpgaimage */
151 for (i=0; i<4; i++) {
152 len = fpgadata[index];
153 printf("FPGA: %s\n", &(fpgadata[index+1]));
158 for (i=20; i>0; i--) {
159 printf("Rebooting in %2d seconds \r",i);
160 for (index=0;index<1000;index++)
164 do_reset(NULL, 0, 0, NULL);
167 #endif /* !CONFIG_CPCI405_VER2 */
170 * IRQ 0-15 405GP internally generated; active high; level sensitive
171 * IRQ 16 405GP internally generated; active low; level sensitive
173 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
174 * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive
175 * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
176 * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
177 * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
178 * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
179 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
181 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
182 mtdcr(uicer, 0x00000000); /* disable all ints */
183 mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
184 #ifdef CONFIG_CPCI405_6U
185 if (cpci405_version() == 3) {
186 mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */
188 mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
191 mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
193 mtdcr(uictr, 0x10000000); /* set int trigger levels */
194 mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
195 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
201 /* ------------------------------------------------------------------------- */
205 #ifdef CONFIG_CPCI405_VER2
206 return 0; /* no, board is cpci405 */
208 if ((*(unsigned char *)0xf0000400 == 0x00) &&
209 (*(unsigned char *)0xf0000401 == 0x01))
210 return 0; /* no, board is cpci405 */
212 return -1; /* yes, board is cterm-m2 */
217 int cpci405_host(void)
219 if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
220 return -1; /* yes, board is cpci405 host */
222 return 0; /* no, board is cpci405 adapter */
226 int cpci405_version(void)
228 unsigned long cntrl0Reg;
232 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
234 cntrl0Reg = mfdcr(cntrl0);
235 mtdcr(cntrl0, cntrl0Reg | 0x03000000);
236 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000);
237 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000);
238 udelay(1000); /* wait some time before reading input */
239 value = in_be32((void*)GPIO0_IR) & 0x00180000; /* get config bits */
242 * Restore GPIO settings
244 mtdcr(cntrl0, cntrl0Reg);
248 /* CS2==1 && CS3==1 -> version 1 */
251 /* CS2==0 && CS3==1 -> version 2 */
254 /* CS2==1 && CS3==0 -> version 3 or 6U board */
257 /* CS2==0 && CS3==0 -> version 4 */
260 /* should not be reached! */
266 int misc_init_f (void)
268 return 0; /* dummy implementation */
272 int misc_init_r (void)
274 unsigned long cntrl0Reg;
276 /* adjust flash start and offset */
277 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
278 gd->bd->bi_flashoffset = 0;
280 #ifdef CONFIG_CPCI405_VER2
283 ulong len = sizeof(fpgadata);
289 * On CPCI-405 version 2 the environment is saved in eeprom!
290 * FPGA can be gzip compressed (malloc) and booted this late.
292 if (cpci405_version() >= 2) {
294 * Setup GPIO pins (CS6+CS7 as GPIO)
296 cntrl0Reg = mfdcr(cntrl0);
297 mtdcr(cntrl0, cntrl0Reg | 0x00300000);
299 dst = malloc(CFG_FPGA_MAX_SIZE);
300 if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
301 printf ("GUNZIP ERROR - must RESET board to recover\n");
302 do_reset (NULL, 0, 0, NULL);
305 status = fpga_boot(dst, len);
307 printf("\nFPGA: Booting failed ");
309 case ERROR_FPGA_PRG_INIT_LOW:
310 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
312 case ERROR_FPGA_PRG_INIT_HIGH:
313 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
315 case ERROR_FPGA_PRG_DONE:
316 printf("(Timeout: DONE not high after programming FPGA)\n ");
320 /* display infos on fpgaimage */
322 for (i=0; i<4; i++) {
324 printf("FPGA: %s\n", &(dst[index+1]));
329 for (i=20; i>0; i--) {
330 printf("Rebooting in %2d seconds \r",i);
331 for (index=0;index<1000;index++)
335 do_reset(NULL, 0, 0, NULL);
338 /* restore gpio/cs settings */
339 mtdcr(cntrl0, cntrl0Reg);
343 /* display infos on fpgaimage */
345 for (i=0; i<4; i++) {
347 printf("%s ", &(dst[index+1]));
355 * Reset FPGA via FPGA_DATA pin
357 SET_FPGA(FPGA_PRG | FPGA_CLK);
358 udelay(1000); /* wait 1ms */
359 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
360 udelay(1000); /* wait 1ms */
362 #ifdef CONFIG_CPCI405_6U
363 if (cpci405_version() == 3) {
364 volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
365 volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR;
368 * Enable outputs in fpga on version 3 board
370 *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT;
378 * Reset external DUART
380 *fpga_mode |= CFG_FPGA_MODE_DUART_RESET;
382 *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET);
387 puts("\n*** U-Boot Version does not match Board Version!\n");
388 puts("*** CPCI-405 Version 1.x detected!\n");
389 puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n");
393 #else /* CONFIG_CPCI405_VER2 */
395 #if 0 /* test-only: code-plug now not relavant for ip-address any more */
397 * Generate last byte of ip-addr from code-plug @ 0xf0000400
401 unsigned char ipbyte = *(unsigned char *)0xf0000400;
404 * Only overwrite ip-addr with allowed values
406 if ((ipbyte != 0x00) && (ipbyte != 0xff)) {
407 bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte;
408 sprintf(str, "%ld.%ld.%ld.%ld",
409 (bd->bi_ip_addr & 0xff000000) >> 24,
410 (bd->bi_ip_addr & 0x00ff0000) >> 16,
411 (bd->bi_ip_addr & 0x0000ff00) >> 8,
412 (bd->bi_ip_addr & 0x000000ff));
413 setenv("ipaddr", str);
418 if (cpci405_version() >= 2) {
419 puts("\n*** U-Boot Version does not match Board Version!\n");
420 puts("*** CPCI-405 Board Version 2.x detected!\n");
421 puts("*** Please use correct U-Boot version (CPCI4052 instead of CPCI405)!\n\n");
424 #endif /* CONFIG_CPCI405_VER2 */
427 * Select cts (and not dsr) on uart1
429 cntrl0Reg = mfdcr(cntrl0);
430 mtdcr(cntrl0, cntrl0Reg | 0x00001000);
437 * Check Board Identity:
440 int checkboard (void)
442 #ifndef CONFIG_CPCI405_VER2
447 int i = getenv_r ("serial#", str, sizeof(str));
453 puts ("### No HW ID - assuming CPCI405");
458 ver = cpci405_version();
459 printf(" (Ver %d.x, ", ver);
461 #if 0 /* test-only */
463 volatile u16 *fpga_status = (u16 *)CFG_FPGA_BASE_ADDR + 1;
465 if (*fpga_status & CFG_FPGA_STATUS_FLASH) {
466 puts ("FLASH Bank B, ");
468 puts ("FLASH Bank A, ");
477 * Read board-id and save in env-variable
479 sprintf(str, "%d", *(unsigned char *)0xf0000400);
480 setenv("boardid", str);
481 printf("CTERM-M2 - Id=%s)", str);
483 if (cpci405_host()) {
484 puts ("PCI Host Version)");
486 puts ("PCI Adapter Version)");
490 #ifndef CONFIG_CPCI405_VER2
493 /* display infos on fpgaimage */
495 for (i=0; i<4; i++) {
496 len = fpgadata[index];
497 printf("%s ", &(fpgadata[index+1]));
506 /* ------------------------------------------------------------------------- */
508 long int initdram (int board_type)
512 mtdcr(memcfga, mem_mb0cf);
513 val = mfdcr(memcfgd);
515 return (4*1024*1024 << ((val & 0x000e0000) >> 17));
521 #ifdef CONFIG_LXT971_NO_SLEEP
524 * Disable sleep mode in LXT971
531 /* ------------------------------------------------------------------------- */
533 #ifdef CONFIG_CPCI405_VER2
534 #ifdef CONFIG_IDE_RESET
536 void ide_set_reset(int on)
538 volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
541 * Assert or deassert CompactFlash Reset Pin
543 if (on) { /* assert RESET */
544 *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET);
545 } else { /* release RESET */
546 *fpga_mode |= CFG_FPGA_MODE_CF_RESET;
550 #endif /* CONFIG_IDE_RESET */
551 #endif /* CONFIG_CPCI405_VER2 */
554 #if defined(CONFIG_PCI)
555 void cpci405_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
557 unsigned char int_line = 0xff;
560 * Write pci interrupt line register (cpci405 specific)
562 switch (PCI_DEV(dev) & 0x03) {
577 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
580 int pci_pre_init(struct pci_controller *hose)
582 hose->fixup_irq = cpci405_pci_fixup_irq;
585 #endif /* defined(CONFIG_PCI) */
589 #ifdef CONFIG_CPCI405AB
591 #define ONE_WIRE_CLEAR (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
592 |= CFG_FPGA_MODE_1WIRE_DIR)
593 #define ONE_WIRE_SET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \
594 &= ~CFG_FPGA_MODE_1WIRE_DIR)
595 #define ONE_WIRE_GET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_STATUS) \
596 & CFG_FPGA_MODE_1WIRE)
599 * Generate a 1-wire reset, return 1 if no presence detect was found,
600 * return 0 otherwise.
601 * (NOTE: Does not handle alarm presence from DS2404/DS1994)
603 int OWTouchReset(void)
612 result = ONE_WIRE_GET;
620 * Send 1 a 1-wire write bit.
621 * Provide 10us recovery time.
623 void OWWriteBit(int bit)
646 * Read a bit from the 1-wire bus and return it.
647 * Provide 10us recovery time.
658 result = ONE_WIRE_GET;
665 void OWWriteByte(int data)
669 for (loop=0; loop<8; loop++) {
670 OWWriteBit(data & 0x01);
678 int loop, result = 0;
680 for (loop=0; loop<8; loop++) {
691 int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
693 volatile unsigned short val;
696 unsigned char ow_id[6];
698 unsigned char ow_crc;
701 * Clear 1-wire bit (open drain with pull-up)
703 val = *(volatile unsigned short *)0xf0400000;
704 val &= ~0x1000; /* clear 1-wire bit */
705 *(volatile unsigned short *)0xf0400000 = val;
707 result = OWTouchReset();
709 puts("No 1-wire device detected!\n");
712 OWWriteByte(0x33); /* send read rom command */
713 OWReadByte(); /* skip family code ( == 0x01) */
714 for (i=0; i<6; i++) {
715 ow_id[i] = OWReadByte();
717 ow_crc = OWReadByte(); /* read crc */
719 sprintf(str, "%08X%04X", *(unsigned int *)&ow_id[0], *(unsigned short *)&ow_id[4]);
720 printf("Setting environment variable 'ow_id' to %s\n", str);
721 setenv("ow_id", str);
726 onewire, 1, 1, do_onewire,
727 "onewire - Read 1-write ID\n",
732 #define CFG_I2C_EEPROM_ADDR_2 0x51 /* EEPROM CAT28WC32 */
733 #define CFG_ENV_SIZE_2 0x800 /* 2048 bytes may be used for env vars*/
736 * Write backplane ip-address...
738 int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
747 buf = malloc(CFG_ENV_SIZE_2);
748 if (eeprom_read(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
749 puts("\nError reading backplane EEPROM!\n");
751 crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
752 if (crc != *(ulong *)buf) {
753 printf("ERROR: crc mismatch %08lx %08lx\n", crc, *(ulong *)buf);
760 ptr = strstr(buf+4, "bp_ip=");
762 printf("ERROR: bp_ip not found!\n");
766 ipaddr = string_to_ip(ptr);
769 * Update whole ip-addr
771 bd->bi_ip_addr = ipaddr;
772 sprintf(str, "%ld.%ld.%ld.%ld",
773 (bd->bi_ip_addr & 0xff000000) >> 24,
774 (bd->bi_ip_addr & 0x00ff0000) >> 16,
775 (bd->bi_ip_addr & 0x0000ff00) >> 8,
776 (bd->bi_ip_addr & 0x000000ff));
777 setenv("ipaddr", str);
778 printf("Updated ip_addr from bp_eeprom to %s!\n", str);
786 getbpip, 1, 1, do_get_bpip,
787 "getbpip - Update IP-Address with Backplane IP-Address\n",
792 * Set and print backplane ip...
794 int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
805 printf("Setting bp_ip to %s\n", argv[1]);
806 buf = malloc(CFG_ENV_SIZE_2);
807 memset(buf, 0, CFG_ENV_SIZE_2);
808 sprintf(str, "bp_ip=%s", argv[1]);
810 crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4);
813 if (eeprom_write(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) {
814 puts("\nError writing backplane EEPROM!\n");
822 setbpip, 2, 1, do_set_bpip,
823 "setbpip - Write Backplane IP-Address\n",
827 #endif /* CONFIG_CPCI405AB */