int misc_init_r (void) { DECLARE_GLOBAL_DATA_PTR; bd_t *bd = gd->bd; char * tmp; /* Temporary char pointer */ unsigned long cntrl0Reg; #ifdef CONFIG_CPCI405_VER2 unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; /* * On CPCI-405 version 2 the environment is saved in eeprom! * FPGA can be gzip compressed (malloc) and booted this late. */ if (cpci405_version() >= 2) { /* * Setup GPIO pins (CS6+CS7 as GPIO) */ cntrl0Reg = mfdcr(cntrl0); mtdcr(cntrl0, cntrl0Reg | 0x00300000); dst = malloc(CFG_FPGA_MAX_SIZE); if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) { printf ("GUNZIP ERROR - must RESET board to recover\n"); do_reset (NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high after programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len+3; } putc ('\n'); /* delayed reboot */ for (i=20; i>0; i--) { printf("Rebooting in %2d seconds \r",i); for (index=0;index<1000;index++) udelay(1000); } putc ('\n'); do_reset(NULL, 0, 0, NULL); } /* restore gpio/cs settings */ mtdcr(cntrl0, cntrl0Reg); puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("%s ", &(dst[index+1])); index += len+3; } putc ('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ if (cpci405_version() == 3) { volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR; volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR; /* * Enable outputs in fpga on version 3 board */ *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT; /* * Set outputs to 0 */ *leds = 0x00; /* * Reset external DUART */ *fpga_mode |= CFG_FPGA_MODE_DUART_RESET; udelay(100); *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET); } } else { puts("\n*** U-Boot Version does not match Board Version!\n"); puts("*** CPCI-405 Version 1.x detected!\n"); puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n"); } #else /* CONFIG_CPCI405_VER2 */ /* * Generate last byte of ip-addr from code-plug @ 0xf0000400 */ if (ctermm2()) { char str[32]; unsigned char ipbyte = *(unsigned char *)0xf0000400; /* * Only overwrite ip-addr with allowed values */ if ((ipbyte != 0x00) && (ipbyte != 0xff)) { bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte; sprintf(str, "%ld.%ld.%ld.%ld", (bd->bi_ip_addr & 0xff000000) >> 24, (bd->bi_ip_addr & 0x00ff0000) >> 16, (bd->bi_ip_addr & 0x0000ff00) >> 8, (bd->bi_ip_addr & 0x000000ff)); setenv("ipaddr", str); } }
int fpga_boot (unsigned char *fpgadata, int size) { volatile immap_t *immr = (immap_t *) CFG_IMMR; int i, index, len; int count; #ifdef CFG_FPGA_SPARTAN2 int j; unsigned char data; #else unsigned char b; int bit; #endif debug ("fpga_boot: fpgadata = %p, size = %d\n", fpgadata, size); /* display infos on fpgaimage */ printf ("FPGA:"); index = 15; for (i = 0; i < 4; i++) { len = fpgadata[index]; printf (" %s", &(fpgadata[index + 1])); index += len + 3; } printf ("\n"); index = 0; #ifdef CFG_FPGA_SPARTAN2 /* search for preamble 0xFFFFFFFF */ while (1) { if ((fpgadata[index] == 0xff) && (fpgadata[index + 1] == 0xff) && (fpgadata[index + 2] == 0xff) && (fpgadata[index + 3] == 0xff)) break; /* preamble found */ else index++; } #else /* search for preamble 0xFF2X */ for (index = 0; index < size - 1; index++) { if ((fpgadata[index] == 0xff) && ((fpgadata[index + 1] & 0xf0) == 0x30)) break; } index += 2; #endif debug ("FPGA: configdata starts at position 0x%x\n", index); debug ("FPGA: length of fpga-data %d\n", size - index); /* * Setup port pins for fpga programming */ immr->im_ioport.iop_pddir = FPGA_INIT_PDDIR; debug ("%s, ", ((GET_FPGA & FPGA_DONE) == 0) ? "NOT DONE" : "DONE"); debug ("%s\n", ((GET_FPGA & FPGA_INIT) == 0) ? "NOT INIT" : "INIT"); /* * Init fpga by asserting and deasserting PROGRAM* */ SET_FPGA (FPGA_CLK | FPGA_DATA); /* Wait for FPGA init line low */ count = 0; while (GET_FPGA & FPGA_INIT) { udelay (1000); /* wait 1ms */ /* Check for timeout - 100us max, so use 3ms */ if (count++ > 3) { debug ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_LOW; } } debug ("%s, ", ((GET_FPGA & FPGA_DONE) == 0) ? "NOT DONE" : "DONE"); debug ("%s\n", ((GET_FPGA & FPGA_INIT) == 0) ? "NOT INIT" : "INIT"); /* deassert PROGRAM* */ SET_FPGA (FPGA_PRG | FPGA_CLK | FPGA_DATA); /* Wait for FPGA end of init period . */ count = 0; while (!(GET_FPGA & FPGA_INIT)) { udelay (1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { debug ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_HIGH; } } debug ("%s, ", ((GET_FPGA & FPGA_DONE) == 0) ? "NOT DONE" : "DONE"); debug ("%s\n", ((GET_FPGA & FPGA_INIT) == 0) ? "NOT INIT" : "INIT"); debug ("write configuration data into fpga\n"); /* write configuration-data into fpga... */ #ifdef CFG_FPGA_SPARTAN2 /* * Load uncompressed image into fpga */ for (i = index; i < size; i++) { #ifdef CFG_FPGA_PROG_FEEDBACK if ((i % 1024) == 0) printf ("%6d out of %6d\r", i, size); /* let them know we are alive */ #endif data = fpgadata[i]; for (j = 0; j < 8; j++) { if ((data & 0x80) == 0x80) { FPGA_WRITE_1; } else { FPGA_WRITE_0; } data <<= 1; } } /* add some 0xff to the end of the file */ for (i = 0; i < 8; i++) { data = 0xff; for (j = 0; j < 8; j++) { if ((data & 0x80) == 0x80) { FPGA_WRITE_1; } else { FPGA_WRITE_0; } data <<= 1; } } #else /* send 0xff 0x20 */ FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_1; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; /* ** Bit_DeCompression ** Code 1 .. maxOnes : n '1's followed by '0' ** maxOnes + 1 .. maxOnes + 1 : n - 1 '1's no '0' ** maxOnes + 2 .. 254 : n - (maxOnes + 2) '0's followed by '1' ** 255 : '1' */ for (i = index; i < size; i++) { b = fpgadata[i]; if ((b >= 1) && (b <= MAX_ONES)) { for (bit = 0; bit < b; bit++) { FPGA_WRITE_1; } FPGA_WRITE_0; } else if (b == (MAX_ONES + 1)) { for (bit = 1; bit < b; bit++) { FPGA_WRITE_1; } } else if ((b >= (MAX_ONES + 2)) && (b <= 254)) { for (bit = 0; bit < (b - (MAX_ONES + 2)); bit++) { FPGA_WRITE_0; } FPGA_WRITE_1; } else if (b == 255) { FPGA_WRITE_1; } } #endif debug ("\n\n"); debug ("%s, ", ((GET_FPGA & FPGA_DONE) == 0) ? "NOT DONE" : "DONE"); debug ("%s\n", ((GET_FPGA & FPGA_INIT) == 0) ? "NOT INIT" : "INIT"); /* * Check if fpga's DONE signal - correctly booted ? */ /* Wait for FPGA end of programming period . */ count = 0; while (!(GET_FPGA & FPGA_DONE)) { udelay (1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { debug ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_DONE; } } debug ("FPGA: Booting successful!\n"); return 0; }
int misc_init_r (void) { volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4); volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4); volatile unsigned char *duart2_mcr = (unsigned char *)((ulong)DUART2_BA + 4); volatile unsigned char *duart3_mcr = (unsigned char *)((ulong)DUART3_BA + 4); unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf ("GUNZIP ERROR - must RESET board to recover\n"); do_reset (NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high after programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len+3; } putc ('\n'); /* delayed reboot */ for (i=20; i>0; i--) { printf("Rebooting in %2d seconds \r",i); for (index=0;index<1000;index++) udelay(1000); } putc ('\n'); do_reset(NULL, 0, 0, NULL); } puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("%s ", &(dst[index+1])); index += len+3; } putc ('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ /* * Reset external DUARTs */ out32(GPIO0_OR, in32(GPIO0_OR) | CONFIG_SYS_DUART_RST); /* set reset to high */ udelay(10); /* wait 10us */ out32(GPIO0_OR, in32(GPIO0_OR) & ~CONFIG_SYS_DUART_RST); /* set reset to low */ udelay(1000); /* wait 1ms */ /* * Enable interrupts in exar duart mcr[3] */ *duart0_mcr = 0x08; *duart1_mcr = 0x08; *duart2_mcr = 0x08; *duart3_mcr = 0x08; return (0); }
int misc_init_r(void) { u16 *fpga_mode = (u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL); u16 *fpga_ctrl2 =(u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL2); u8 *duart0_mcr = (u8 *)(DUART0_BA + 4); u8 *duart1_mcr = (u8 *)(DUART1_BA + 4); unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; unsigned long CPC0_CR0Reg; char *str; uchar *logo_addr; ulong logo_size; ushort minb, maxb; int result; /* * Setup GPIO pins (CS6+CS7 as GPIO) */ CPC0_CR0Reg = mfdcr(CPC0_CR0); mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000); dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf("GUNZIP ERROR - must RESET board to recover\n"); do_reset(NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: " "INIT not low after asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: " "INIT not high after deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: " "DONE not high after programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i = 0; i < 4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len + 3; } putc('\n'); /* delayed reboot */ for (i = 20; i > 0; i--) { printf("Rebooting in %2d seconds \r",i); for (index = 0; index < 1000; index++) udelay(1000); } putc('\n'); do_reset(NULL, 0, 0, NULL); } /* restore gpio/cs settings */ mtdcr(CPC0_CR0, CPC0_CR0Reg); puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i = 0; i < 4; i++) { len = dst[index]; printf("%s ", &(dst[index + 1])); index += len + 3; } putc('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ /* * Write board revision in FPGA */ out_be16(fpga_ctrl2, (in_be16(fpga_ctrl2) & 0xfff0) | (gd->board_type & 0x000f)); /* * Enable power on PS/2 interface (with reset) */ out_be16(fpga_mode, in_be16(fpga_mode) | CONFIG_SYS_FPGA_CTRL_PS2_RESET); for (i=0;i<100;i++) udelay(1000); udelay(1000); out_be16(fpga_mode, in_be16(fpga_mode) & ~CONFIG_SYS_FPGA_CTRL_PS2_RESET); /* * Enable interrupts in exar duart mcr[3] */ out_8(duart0_mcr, 0x08); out_8(duart1_mcr, 0x08); /* * Init lcd interface and display logo */ str = getenv("splashimage"); if (str) { logo_addr = (uchar *)simple_strtoul(str, NULL, 16); logo_size = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; } else { logo_addr = logo_bmp; logo_size = sizeof(logo_bmp); } if (gd->board_type >= 6) { result = lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM, regs_13505_640_480_16bpp, sizeof(regs_13505_640_480_16bpp) / sizeof(regs_13505_640_480_16bpp[0]), logo_addr, logo_size); if (result && str) { /* retry with internal image */ logo_addr = logo_bmp; logo_size = sizeof(logo_bmp); lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM, regs_13505_640_480_16bpp, sizeof(regs_13505_640_480_16bpp) / sizeof(regs_13505_640_480_16bpp[0]), logo_addr, logo_size); } } else { result = lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM, regs_13806_640_480_16bpp, sizeof(regs_13806_640_480_16bpp) / sizeof(regs_13806_640_480_16bpp[0]), logo_addr, logo_size); if (result && str) { /* retry with internal image */ logo_addr = logo_bmp; logo_size = sizeof(logo_bmp); lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM, regs_13806_640_480_16bpp, sizeof(regs_13806_640_480_16bpp) / sizeof(regs_13806_640_480_16bpp[0]), logo_addr, logo_size); } } /* * Reset microcontroller and setup backlight PWM controller */ out_be16(fpga_mode, in_be16(fpga_mode) | 0x0014); for (i=0;i<10;i++) udelay(1000); out_be16(fpga_mode, in_be16(fpga_mode) | 0x001c); minb = 0; maxb = 0xff; str = getenv("lcdbl"); if (str) { minb = (ushort)simple_strtoul(str, &str, 16) & 0x00ff; if (str && (*str=',')) { str++; maxb = (ushort)simple_strtoul(str, NULL, 16) & 0x00ff; } else minb = 0; out_be16((u16 *)(FUJI_BASE + LCDBL_PWMMIN), minb); out_be16((u16 *)(FUJI_BASE + LCDBL_PWMMAX), maxb); printf("LCDBL: min=0x%02x, max=0x%02x\n", minb, maxb); } out_be16((u16 *)(FUJI_BASE + LCDBL_PWM), 0xff); /* * fix environment for field updated units */ if (getenv("altbootcmd") == NULL) { setenv("usb_load", CONFIG_SYS_USB_LOAD_COMMAND); setenv("usbargs", CONFIG_SYS_USB_ARGS); setenv("bootcmd", CONFIG_BOOTCOMMAND); setenv("usb_self", CONFIG_SYS_USB_SELF_COMMAND); setenv("bootlimit", CONFIG_SYS_BOOTLIMIT); setenv("altbootcmd", CONFIG_SYS_ALT_BOOTCOMMAND); saveenv(); } return (0); }
int misc_init_r (void) { /* adjust flash start and size as well as the offset */ gd->bd->bi_flashstart = 0 - flash_info[0].size; gd->bd->bi_flashoffset= flash_info[0].size - CONFIG_SYS_MONITOR_LEN; #if 0 volatile unsigned short *fpga_mode = (unsigned short *)((ulong)CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL); volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4); volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4); bd_t *bd = gd->bd; char * tmp; /* Temporary char pointer */ unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; unsigned long CPC0_CR0Reg; dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf ("GUNZIP ERROR - must RESET board to recover\n"); do_reset (NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high after programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len+3; } putc ('\n'); /* delayed reboot */ for (i=20; i>0; i--) { printf("Rebooting in %2d seconds \r",i); for (index=0;index<1000;index++) udelay(1000); } putc ('\n'); do_reset(NULL, 0, 0, NULL); } puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("%s ", &(dst[index+1])); index += len+3; } putc ('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ #endif #if 0 /* * Enable power on PS/2 interface */ *fpga_mode |= CONFIG_SYS_FPGA_CTRL_PS2_RESET; /* * Enable interrupts in exar duart mcr[3] */ *duart0_mcr = 0x08; *duart1_mcr = 0x08; #endif return (0); }
static int fpga_boot(unsigned char *fpgadata, int size) { int i,index,len; int count; int j; /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = fpgadata[index]; DBG("FPGA: %s\n", &(fpgadata[index+1])); index += len+3; } /* search for preamble 0xFFFFFFFF */ while (1) { if ((fpgadata[index] == 0xff) && (fpgadata[index+1] == 0xff) && (fpgadata[index+2] == 0xff) && (fpgadata[index+3] == 0xff)) break; /* preamble found */ else index++; } DBG("FPGA: configdata starts at position 0x%x\n",index); DBG("FPGA: length of fpga-data %d\n", size-index); /* * Setup port pins for fpga programming */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); /* set pins to high */ DBG("%s, ",(FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE" ); DBG("%s\n",(FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT" ); /* * Init fpga by asserting and deasserting PROGRAM* */ SET_FPGA(0 | FPGA_CLK | FPGA_DATA); /* set prog active */ /* Wait for FPGA init line low */ count = 0; while (FPGA_INIT_STATE) { udelay(1000); /* wait 1ms */ /* Check for timeout - 100us max, so use 3ms */ if (count++ > 3) { DBG("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_LOW; } } DBG("%s, ",(FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE" ); DBG("%s\n",(FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT" ); /* deassert PROGRAM* */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); /* set prog inactive */ /* Wait for FPGA end of init period . */ count = 0; while (!(FPGA_INIT_STATE)) { udelay(1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { DBG("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_HIGH; } } DBG("%s, ",(FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE" ); DBG("%s\n",(FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT" ); DBG("write configuration data into fpga\n"); /* write configuration-data into fpga... */ /* * Load uncompressed image into fpga */ for (i=index; i<size; i++) { for (j=0; j<8; j++) { if ((fpgadata[i] & 0x80) == 0x80) { FPGA_WRITE_1; } else { FPGA_WRITE_0; } fpgadata[i] <<= 1; } } DBG("%s, ",(FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE" ); DBG("%s\n",(FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT" ); /* * Check if fpga's DONE signal - correctly booted ? */ /* Wait for FPGA end of programming period . */ count = 0; while (!(FPGA_DONE_STATE)) { udelay(1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { DBG("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_DONE; } } DBG("FPGA: Booting successful!\n"); return 0; }
static int fpga_boot (const unsigned char *fpgadata, int size) { int i, index, len; int count; unsigned char b; #ifdef CONFIG_SYS_FPGA_SPARTAN2 int j; #else int bit; #endif /* display infos on fpgaimage */ index = 15; for (i = 0; i < 4; i++) { len = fpgadata[index]; DBG ("FPGA: %s\n", &(fpgadata[index + 1])); index += len + 3; } #ifdef CONFIG_SYS_FPGA_SPARTAN2 /* search for preamble 0xFFFFFFFF */ while (1) { if ((fpgadata[index] == 0xff) && (fpgadata[index + 1] == 0xff) && (fpgadata[index + 2] == 0xff) && (fpgadata[index + 3] == 0xff)) break; /* preamble found */ else index++; } #else /* search for preamble 0xFF2X */ for (index = 0; index < size - 1; index++) { if ((fpgadata[index] == 0xff) && ((fpgadata[index + 1] & 0xf0) == 0x30)) break; } index += 2; #endif DBG ("FPGA: configdata starts at position 0x%x\n", index); DBG ("FPGA: length of fpga-data %d\n", size - index); /* * Setup port pins for fpga programming */ #ifndef CONFIG_M5249 out_be32 ((void *)GPIO0_ODR, 0x00000000); /* no open drain pins */ /* setup for output */ out_be32 ((void *)GPIO0_TCR, in_be32 ((void *)GPIO0_TCR) | FPGA_PRG | FPGA_CLK | FPGA_DATA); #endif SET_FPGA (FPGA_PRG_HIGH | FPGA_CLK_HIGH | FPGA_DATA_HIGH); /* set pins to high */ DBG ("%s, ", (FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE"); DBG ("%s\n", (FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT"); /* * Init fpga by asserting and deasserting PROGRAM* */ SET_FPGA (FPGA_PRG_LOW | FPGA_CLK_HIGH | FPGA_DATA_HIGH); /* set prog active */ /* Wait for FPGA init line low */ count = 0; while (FPGA_INIT_STATE) { udelay (1000); /* wait 1ms */ /* Check for timeout - 100us max, so use 3ms */ if (count++ > 3) { DBG ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_LOW; } } DBG ("%s, ", (FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE"); DBG ("%s\n", (FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT"); /* deassert PROGRAM* */ SET_FPGA (FPGA_PRG_HIGH | FPGA_CLK_HIGH | FPGA_DATA_HIGH); /* set prog inactive */ /* Wait for FPGA end of init period . */ count = 0; while (!(FPGA_INIT_STATE)) { udelay (1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { DBG ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_INIT_HIGH; } } DBG ("%s, ", (FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE"); DBG ("%s\n", (FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT"); DBG ("write configuration data into fpga\n"); /* write configuration-data into fpga... */ #ifdef CONFIG_SYS_FPGA_SPARTAN2 /* * Load uncompressed image into fpga */ for (i = index; i < size; i++) { b = fpgadata[i]; for (j = 0; j < 8; j++) { if ((b & 0x80) == 0x80) { FPGA_WRITE_1; } else { FPGA_WRITE_0; } b <<= 1; } } #else /* send 0xff 0x20 */ FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_1; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_1; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; FPGA_WRITE_0; /* ** Bit_DeCompression ** Code 1 .. maxOnes : n '1's followed by '0' ** maxOnes + 1 .. maxOnes + 1 : n - 1 '1's no '0' ** maxOnes + 2 .. 254 : n - (maxOnes + 2) '0's followed by '1' ** 255 : '1' */ for (i = index; i < size; i++) { b = fpgadata[i]; if ((b >= 1) && (b <= MAX_ONES)) { for (bit = 0; bit < b; bit++) { FPGA_WRITE_1; } FPGA_WRITE_0; } else if (b == (MAX_ONES + 1)) { for (bit = 1; bit < b; bit++) { FPGA_WRITE_1; } } else if ((b >= (MAX_ONES + 2)) && (b <= 254)) { for (bit = 0; bit < (b - (MAX_ONES + 2)); bit++) { FPGA_WRITE_0; } FPGA_WRITE_1; } else if (b == 255) { FPGA_WRITE_1; } } #endif DBG ("%s, ", (FPGA_DONE_STATE == 0) ? "NOT DONE" : "DONE"); DBG ("%s\n", (FPGA_INIT_STATE == 0) ? "NOT INIT" : "INIT"); /* * Check if fpga's DONE signal - correctly booted ? */ /* Wait for FPGA end of programming period . */ count = 0; while (!(FPGA_DONE_STATE)) { udelay (1000); /* wait 1ms */ /* Check for timeout */ if (count++ > 3) { DBG ("FPGA: Booting failed!\n"); return ERROR_FPGA_PRG_DONE; } } DBG ("FPGA: Booting successful!\n"); return 0; }
int misc_init_r(void) { unsigned char *dst; unsigned char fctr; ulong len = sizeof(fpgadata); int status; int index; int i; /* adjust flash start and offset */ gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; gd->bd->bi_flashoffset = 0; dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf("GUNZIP ERROR - must RESET board to recover\n"); do_reset(NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low " "after asserting PROGRAM*)\n"); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high " "after deasserting PROGRAM*)\n"); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high " "after programming FPGA)\n"); break; } /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len+3; } putc ('\n'); /* delayed reboot */ for (i=20; i>0; i--) { printf("Rebooting in %2d seconds \r",i); for (index=0;index<1000;index++) udelay(1000); } putc('\n'); do_reset(NULL, 0, 0, NULL); } puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("%s ", &(dst[index+1])); index += len+3; } putc('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ /* * Reset external DUARTs */ out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_DUART_RST); udelay(10); out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_DUART_RST); udelay(1000); /* * Set NAND-FLASH GPIO signals to default */ out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE)); out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_NAND_CE); /* * Setup EEPROM write protection */ out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_EEPROM_WP); out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CONFIG_SYS_EEPROM_WP); /* * Enable interrupts in exar duart mcr[3] */ out_8((void *)DUART0_BA + 4, 0x08); out_8((void *)DUART1_BA + 4, 0x08); /* * Enable auto RS485 mode in 2nd external uart */ out_8((void *)DUART1_BA + 3, 0xbf); /* write LCR */ fctr = in_8((void *)DUART1_BA + 1); /* read FCTR */ fctr |= 0x08; /* enable RS485 mode */ out_8((void *)DUART1_BA + 1, fctr); /* write FCTR */ out_8((void *)DUART1_BA + 3, 0); /* write LCR */ /* * Init magnetic couplers */ if (!getenv("noinitcoupler")) { init_coupler(CAN0_BA); init_coupler(CAN1_BA); } return 0; }
int misc_init_r (void) { unsigned long CPC0_CR0Reg; /* adjust flash start and offset */ gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; gd->bd->bi_flashoffset = 0; #if defined(CONFIG_CPCI405_VER2) { unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; /* * On CPCI-405 version 2 the environment is saved in eeprom! * FPGA can be gzip compressed (malloc) and booted this late. */ if (cpci405_version() >= 2) { /* * Setup GPIO pins (CS6+CS7 as GPIO) */ CPC0_CR0Reg = mfdcr(CPC0_CR0); mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000); dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf("GUNZIP ERROR - must RESET board to recover\n"); do_reset(NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low after " "asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high after " "deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high after " "programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i = 0; i < 4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index + 1])); index += len + 3; } putc('\n'); /* delayed reboot */ for (i = 20; i > 0; i--) { printf("Rebooting in %2d seconds \r", i); for (index = 0; index < 1000; index++) udelay(1000); } putc('\n'); do_reset(NULL, 0, 0, NULL); } /* restore gpio/cs settings */ mtdcr(CPC0_CR0, CPC0_CR0Reg); puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i = 0; i < 4; i++) { len = dst[index]; printf("%s ", &(dst[index + 1])); index += len + 3; } putc('\n'); free(dst); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ #if defined(CONFIG_CPCI405_6U) #error HIER GETH ES WEITER MIT IO ACCESSORS if (cpci405_version() == 3) { /* * Enable outputs in fpga on version 3 board */ out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT); /* * Set outputs to 0 */ out_8((void*)CONFIG_SYS_LED_ADDR, 0x00); /* * Reset external DUART */ out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | CONFIG_SYS_FPGA_MODE_DUART_RESET); udelay(100); out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & ~CONFIG_SYS_FPGA_MODE_DUART_RESET); } #endif } else { puts("\n*** U-Boot Version does not match Board Version!\n"); puts("*** CPCI-405 Version 1.x detected!\n"); puts("*** Please use correct U-Boot version " "(CPCI405 instead of CPCI4052)!\n\n"); } } #else /* CONFIG_CPCI405_VER2 */ if (cpci405_version() >= 2) { puts("\n*** U-Boot Version does not match Board Version!\n"); puts("*** CPCI-405 Board Version 2.x detected!\n"); puts("*** Please use correct U-Boot version " "(CPCI4052 instead of CPCI405)!\n\n"); } #endif /* CONFIG_CPCI405_VER2 */ /* * Select cts (and not dsr) on uart1 */ CPC0_CR0Reg = mfdcr(CPC0_CR0); mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000); return 0; }
int misc_init_r (void) { unsigned char *dst; ulong len = sizeof(fpgadata); int status; int index; int i; unsigned int *ptr; unsigned int *magic; /* * On PCI-405 the environment is saved in eeprom! * FPGA can be gzip compressed (malloc) and booted this late. */ dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { printf ("GUNZIP ERROR - must RESET board to recover\n"); do_reset (NULL, 0, 0, NULL); } status = fpga_boot(dst, len); if (status != 0) { printf("\nFPGA: Booting failed "); switch (status) { case ERROR_FPGA_PRG_INIT_LOW: printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_INIT_HIGH: printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); break; case ERROR_FPGA_PRG_DONE: printf("(Timeout: DONE not high after programming FPGA)\n "); break; } /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("FPGA: %s\n", &(dst[index+1])); index += len+3; } putc ('\n'); /* delayed reboot */ for (i=20; i>0; i--) { printf("Rebooting in %2d seconds \r",i); for (index=0; index<1000; index++) udelay(1000); } putc ('\n'); do_reset(NULL, 0, 0, NULL); } puts("FPGA: "); /* display infos on fpgaimage */ index = 15; for (i=0; i<4; i++) { len = dst[index]; printf("%s ", &(dst[index+1])); index += len+3; } putc ('\n'); /* * Reset FPGA via FPGA_DATA pin */ SET_FPGA(FPGA_PRG | FPGA_CLK); udelay(1000); /* wait 1ms */ SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); udelay(1000); /* wait 1ms */ /* * Check if magic for pci reconfig is written */ magic = (unsigned int *)0x00000004; if (*magic == PCI_RECONFIG_MAGIC) { /* * Rewrite pci config regs (only after soft-reset with magic set) */ ptr = (unsigned int *)PCI_REGS_ADDR; if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) { puts("Restoring PCI Configurations Regs!\n"); ptr = (unsigned int *)PCI_REGS_ADDR + 1; for (i=0; i<0x40; i+=4) { pci_write_config_dword(PCIDEVID_405GP, i, *ptr++); } } mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ *magic = 0; /* clear pci reconfig magic again */ } /* * Decrease PLB latency timeout and reduce priority of the PCI bridge master */ #define PCI0_BRDGOPT1 0x4a pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20); #define PLB0_ACR 0x87 /* * Enable fairness and high bus utilization */ mtdcr(PLB0_ACR, 0x98000000); free(dst); return (0); }