wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 2 | * (C) Copyright 2001-2003 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 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 <asm/processor.h> |
| 26 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 27 | #include <malloc.h> |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 28 | #include <net.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame^] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 32 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /*cmd_boot.c*/ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | #if 0 |
| 34 | #define FPGA_DEBUG |
| 35 | #endif |
| 36 | |
| 37 | /* fpga configuration data - generated by bin2cc */ |
| 38 | const unsigned char fpgadata[] = |
| 39 | { |
| 40 | #ifdef CONFIG_CPCI405_VER2 |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 41 | # ifdef CONFIG_CPCI405AB |
| 42 | # include "fpgadata_cpci405ab.c" |
| 43 | # else |
| 44 | # include "fpgadata_cpci4052.c" |
| 45 | # endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 46 | #else |
| 47 | # include "fpgadata_cpci405.c" |
| 48 | #endif |
| 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * include common fpga code (for esd boards) |
| 53 | */ |
| 54 | #include "../common/fpga.c" |
| 55 | |
| 56 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 57 | #include "../common/auto_update.h" |
| 58 | |
| 59 | #ifdef CONFIG_CPCI405AB |
| 60 | au_image_t au_image[] = { |
| 61 | {"cpci405ab/preinst.img", 0, -1, AU_SCRIPT}, |
| 62 | {"cpci405ab/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 63 | {"cpci405ab/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR}, |
| 64 | {"cpci405ab/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE}, |
| 65 | {"cpci405ab/postinst.img", 0, 0, AU_SCRIPT}, |
| 66 | }; |
| 67 | #else |
| 68 | #ifdef CONFIG_CPCI405_VER2 |
| 69 | au_image_t au_image[] = { |
| 70 | {"cpci4052/preinst.img", 0, -1, AU_SCRIPT}, |
| 71 | {"cpci4052/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 72 | {"cpci4052/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR}, |
| 73 | {"cpci4052/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE}, |
| 74 | {"cpci4052/postinst.img", 0, 0, AU_SCRIPT}, |
| 75 | }; |
| 76 | #else |
| 77 | au_image_t au_image[] = { |
| 78 | {"cpci405/preinst.img", 0, -1, AU_SCRIPT}, |
| 79 | {"cpci405/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 80 | {"cpci405/pImage.initrd", 0xffcc0000, 0x00310000, AU_NOR}, |
| 81 | {"cpci405/u-boot.img", 0xfffd0000, 0x00030000, AU_FIRMWARE}, |
| 82 | {"cpci405/postinst.img", 0, 0, AU_SCRIPT}, |
| 83 | }; |
| 84 | #endif |
| 85 | #endif |
| 86 | |
| 87 | int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0])); |
| 88 | |
| 89 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | /* Prototypes */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 91 | int cpci405_version(void); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 92 | int gunzip(void *, int, unsigned char *, unsigned long *); |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 93 | void lxt971_no_sleep(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | |
| 95 | |
wdenk | da55c6e | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 96 | int board_early_init_f (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | { |
| 98 | #ifndef CONFIG_CPCI405_VER2 |
| 99 | int index, len, i; |
| 100 | int status; |
| 101 | #endif |
| 102 | |
| 103 | #ifdef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | /* set up serial port with default baudrate */ |
| 105 | (void) get_clocks (); |
| 106 | gd->baudrate = CONFIG_BAUDRATE; |
| 107 | serial_init (); |
| 108 | console_init_f(); |
| 109 | #endif |
| 110 | |
| 111 | /* |
| 112 | * First pull fpga-prg pin low, to disable fpga logic (on version 2 board) |
| 113 | */ |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 114 | out32(GPIO0_ODR, 0x00000000); /* no open drain pins */ |
| 115 | out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */ |
| 116 | out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */ |
| 117 | out32(GPIO0_OR, 0); /* pull prg low */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * Boot onboard FPGA |
| 121 | */ |
| 122 | #ifndef CONFIG_CPCI405_VER2 |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 123 | if (cpci405_version() == 1) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata)); |
| 125 | if (status != 0) { |
| 126 | /* booting FPGA failed */ |
| 127 | #ifndef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | /* set up serial port with default baudrate */ |
| 129 | (void) get_clocks (); |
| 130 | gd->baudrate = CONFIG_BAUDRATE; |
| 131 | serial_init (); |
| 132 | console_init_f(); |
| 133 | #endif |
| 134 | printf("\nFPGA: Booting failed "); |
| 135 | switch (status) { |
| 136 | case ERROR_FPGA_PRG_INIT_LOW: |
| 137 | printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); |
| 138 | break; |
| 139 | case ERROR_FPGA_PRG_INIT_HIGH: |
| 140 | printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); |
| 141 | break; |
| 142 | case ERROR_FPGA_PRG_DONE: |
| 143 | printf("(Timeout: DONE not high after programming FPGA)\n "); |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | /* display infos on fpgaimage */ |
| 148 | index = 15; |
| 149 | for (i=0; i<4; i++) { |
| 150 | len = fpgadata[index]; |
| 151 | printf("FPGA: %s\n", &(fpgadata[index+1])); |
| 152 | index += len+3; |
| 153 | } |
| 154 | putc ('\n'); |
| 155 | /* delayed reboot */ |
| 156 | for (i=20; i>0; i--) { |
| 157 | printf("Rebooting in %2d seconds \r",i); |
| 158 | for (index=0;index<1000;index++) |
| 159 | udelay(1000); |
| 160 | } |
| 161 | putc ('\n'); |
| 162 | do_reset(NULL, 0, 0, NULL); |
| 163 | } |
| 164 | } |
| 165 | #endif /* !CONFIG_CPCI405_VER2 */ |
| 166 | |
| 167 | /* |
| 168 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 169 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 170 | * IRQ 17-24 RESERVED |
| 171 | * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive |
| 172 | * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive |
| 173 | * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive |
| 174 | * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive |
| 175 | * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 176 | * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive |
| 177 | * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive |
| 178 | */ |
| 179 | mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 180 | mtdcr(uicer, 0x00000000); /* disable all ints */ |
| 181 | mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 182 | if (cpci405_version() == 3) { |
| 183 | mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */ |
| 184 | } else { |
| 185 | mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */ |
| 186 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 187 | mtdcr(uictr, 0x10000000); /* set int trigger levels */ |
| 188 | mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/ |
| 189 | mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | /* ------------------------------------------------------------------------- */ |
| 196 | |
| 197 | int ctermm2(void) |
| 198 | { |
| 199 | #ifdef CONFIG_CPCI405_VER2 |
| 200 | return 0; /* no, board is cpci405 */ |
| 201 | #else |
| 202 | if ((*(unsigned char *)0xf0000400 == 0x00) && |
| 203 | (*(unsigned char *)0xf0000401 == 0x01)) |
| 204 | return 0; /* no, board is cpci405 */ |
| 205 | else |
| 206 | return -1; /* yes, board is cterm-m2 */ |
| 207 | #endif |
| 208 | } |
| 209 | |
| 210 | |
| 211 | int cpci405_host(void) |
| 212 | { |
| 213 | if (mfdcr(strap) & PSR_PCI_ARBIT_EN) |
| 214 | return -1; /* yes, board is cpci405 host */ |
| 215 | else |
| 216 | return 0; /* no, board is cpci405 adapter */ |
| 217 | } |
| 218 | |
| 219 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 220 | int cpci405_version(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 221 | { |
| 222 | unsigned long cntrl0Reg; |
| 223 | unsigned long value; |
| 224 | |
| 225 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 226 | * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 227 | */ |
| 228 | cntrl0Reg = mfdcr(cntrl0); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 229 | mtdcr(cntrl0, cntrl0Reg | 0x03000000); |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 230 | out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00180000); |
| 231 | out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00180000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 232 | udelay(1000); /* wait some time before reading input */ |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 233 | value = in32(GPIO0_IR) & 0x00180000; /* get config bits */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 234 | |
| 235 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 236 | * Restore GPIO settings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | */ |
| 238 | mtdcr(cntrl0, cntrl0Reg); |
| 239 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 240 | switch (value) { |
| 241 | case 0x00180000: |
| 242 | /* CS2==1 && CS3==1 -> version 1 */ |
| 243 | return 1; |
| 244 | case 0x00080000: |
| 245 | /* CS2==0 && CS3==1 -> version 2 */ |
| 246 | return 2; |
| 247 | case 0x00100000: |
| 248 | /* CS2==1 && CS3==0 -> version 3 */ |
| 249 | return 3; |
| 250 | case 0x00000000: |
| 251 | /* CS2==0 && CS3==0 -> version 4 */ |
| 252 | return 4; |
| 253 | default: |
| 254 | /* should not be reached! */ |
| 255 | return 2; |
| 256 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | int misc_init_f (void) |
| 261 | { |
| 262 | return 0; /* dummy implementation */ |
| 263 | } |
| 264 | |
| 265 | |
| 266 | int misc_init_r (void) |
| 267 | { |
stroese | 67cb27d | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 268 | unsigned long cntrl0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 270 | /* adjust flash start and offset */ |
| 271 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 272 | gd->bd->bi_flashoffset = 0; |
| 273 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 274 | #ifdef CONFIG_CPCI405_VER2 |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 275 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 276 | unsigned char *dst; |
| 277 | ulong len = sizeof(fpgadata); |
| 278 | int status; |
| 279 | int index; |
| 280 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * On CPCI-405 version 2 the environment is saved in eeprom! |
| 284 | * FPGA can be gzip compressed (malloc) and booted this late. |
| 285 | */ |
| 286 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 287 | if (cpci405_version() >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 288 | /* |
| 289 | * Setup GPIO pins (CS6+CS7 as GPIO) |
| 290 | */ |
| 291 | cntrl0Reg = mfdcr(cntrl0); |
| 292 | mtdcr(cntrl0, cntrl0Reg | 0x00300000); |
| 293 | |
| 294 | dst = malloc(CFG_FPGA_MAX_SIZE); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 295 | if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 296 | printf ("GUNZIP ERROR - must RESET board to recover\n"); |
| 297 | do_reset (NULL, 0, 0, NULL); |
| 298 | } |
| 299 | |
| 300 | status = fpga_boot(dst, len); |
| 301 | if (status != 0) { |
| 302 | printf("\nFPGA: Booting failed "); |
| 303 | switch (status) { |
| 304 | case ERROR_FPGA_PRG_INIT_LOW: |
| 305 | printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); |
| 306 | break; |
| 307 | case ERROR_FPGA_PRG_INIT_HIGH: |
| 308 | printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); |
| 309 | break; |
| 310 | case ERROR_FPGA_PRG_DONE: |
| 311 | printf("(Timeout: DONE not high after programming FPGA)\n "); |
| 312 | break; |
| 313 | } |
| 314 | |
| 315 | /* display infos on fpgaimage */ |
| 316 | index = 15; |
| 317 | for (i=0; i<4; i++) { |
| 318 | len = dst[index]; |
| 319 | printf("FPGA: %s\n", &(dst[index+1])); |
| 320 | index += len+3; |
| 321 | } |
| 322 | putc ('\n'); |
| 323 | /* delayed reboot */ |
| 324 | for (i=20; i>0; i--) { |
| 325 | printf("Rebooting in %2d seconds \r",i); |
| 326 | for (index=0;index<1000;index++) |
| 327 | udelay(1000); |
| 328 | } |
| 329 | putc ('\n'); |
| 330 | do_reset(NULL, 0, 0, NULL); |
| 331 | } |
| 332 | |
| 333 | /* restore gpio/cs settings */ |
| 334 | mtdcr(cntrl0, cntrl0Reg); |
| 335 | |
| 336 | puts("FPGA: "); |
| 337 | |
| 338 | /* display infos on fpgaimage */ |
| 339 | index = 15; |
| 340 | for (i=0; i<4; i++) { |
| 341 | len = dst[index]; |
| 342 | printf("%s ", &(dst[index+1])); |
| 343 | index += len+3; |
| 344 | } |
| 345 | putc ('\n'); |
| 346 | |
| 347 | free(dst); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 348 | |
| 349 | /* |
| 350 | * Reset FPGA via FPGA_DATA pin |
| 351 | */ |
| 352 | SET_FPGA(FPGA_PRG | FPGA_CLK); |
| 353 | udelay(1000); /* wait 1ms */ |
| 354 | SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); |
| 355 | udelay(1000); /* wait 1ms */ |
| 356 | |
| 357 | if (cpci405_version() == 3) { |
| 358 | volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR; |
| 359 | volatile unsigned char *leds = (unsigned char *)CFG_LED_ADDR; |
| 360 | |
| 361 | /* |
| 362 | * Enable outputs in fpga on version 3 board |
| 363 | */ |
| 364 | *fpga_mode |= CFG_FPGA_MODE_ENABLE_OUTPUT; |
| 365 | |
| 366 | /* |
| 367 | * Set outputs to 0 |
| 368 | */ |
| 369 | *leds = 0x00; |
| 370 | |
| 371 | /* |
| 372 | * Reset external DUART |
| 373 | */ |
| 374 | *fpga_mode |= CFG_FPGA_MODE_DUART_RESET; |
| 375 | udelay(100); |
| 376 | *fpga_mode &= ~(CFG_FPGA_MODE_DUART_RESET); |
| 377 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | } |
| 379 | else { |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 380 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 381 | puts("*** CPCI-405 Version 1.x detected!\n"); |
| 382 | puts("*** Please use correct U-Boot version (CPCI405 instead of CPCI4052)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 383 | } |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 384 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 385 | |
| 386 | #else /* CONFIG_CPCI405_VER2 */ |
| 387 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 388 | #if 0 /* test-only: code-plug now not relavant for ip-address any more */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 389 | /* |
| 390 | * Generate last byte of ip-addr from code-plug @ 0xf0000400 |
| 391 | */ |
| 392 | if (ctermm2()) { |
| 393 | char str[32]; |
| 394 | unsigned char ipbyte = *(unsigned char *)0xf0000400; |
| 395 | |
| 396 | /* |
| 397 | * Only overwrite ip-addr with allowed values |
| 398 | */ |
| 399 | if ((ipbyte != 0x00) && (ipbyte != 0xff)) { |
| 400 | bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte; |
| 401 | sprintf(str, "%ld.%ld.%ld.%ld", |
| 402 | (bd->bi_ip_addr & 0xff000000) >> 24, |
| 403 | (bd->bi_ip_addr & 0x00ff0000) >> 16, |
| 404 | (bd->bi_ip_addr & 0x0000ff00) >> 8, |
| 405 | (bd->bi_ip_addr & 0x000000ff)); |
| 406 | setenv("ipaddr", str); |
| 407 | } |
| 408 | } |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 409 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 410 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 411 | if (cpci405_version() >= 2) { |
| 412 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 413 | puts("*** CPCI-405 Board Version 2.x detected!\n"); |
| 414 | puts("*** Please use correct U-Boot version (CPCI4052 instead of CPCI405)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | #endif /* CONFIG_CPCI405_VER2 */ |
| 418 | |
| 419 | /* |
stroese | 67cb27d | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 420 | * Select cts (and not dsr) on uart1 |
| 421 | */ |
| 422 | cntrl0Reg = mfdcr(cntrl0); |
| 423 | mtdcr(cntrl0, cntrl0Reg | 0x00001000); |
| 424 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 425 | return (0); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | /* |
| 430 | * Check Board Identity: |
| 431 | */ |
| 432 | |
| 433 | int checkboard (void) |
| 434 | { |
| 435 | #ifndef CONFIG_CPCI405_VER2 |
| 436 | int index; |
| 437 | int len; |
| 438 | #endif |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 439 | char str[64]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 440 | int i = getenv_r ("serial#", str, sizeof(str)); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 441 | unsigned short ver; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 442 | |
| 443 | puts ("Board: "); |
| 444 | |
| 445 | if (i == -1) { |
| 446 | puts ("### No HW ID - assuming CPCI405"); |
| 447 | } else { |
| 448 | puts(str); |
| 449 | } |
| 450 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 451 | ver = cpci405_version(); |
| 452 | printf(" (Ver %d.x, ", ver); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 453 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 454 | #if 0 /* test-only */ |
| 455 | if (ver >= 2) { |
| 456 | volatile u16 *fpga_status = (u16 *)CFG_FPGA_BASE_ADDR + 1; |
| 457 | |
| 458 | if (*fpga_status & CFG_FPGA_STATUS_FLASH) { |
| 459 | puts ("FLASH Bank B, "); |
| 460 | } else { |
| 461 | puts ("FLASH Bank A, "); |
| 462 | } |
| 463 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 464 | #endif |
| 465 | |
| 466 | if (ctermm2()) { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 467 | char str[4]; |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 468 | |
| 469 | /* |
| 470 | * Read board-id and save in env-variable |
| 471 | */ |
| 472 | sprintf(str, "%d", *(unsigned char *)0xf0000400); |
| 473 | setenv("boardid", str); |
| 474 | printf("CTERM-M2 - Id=%s)", str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 475 | } else { |
| 476 | if (cpci405_host()) { |
| 477 | puts ("PCI Host Version)"); |
| 478 | } else { |
| 479 | puts ("PCI Adapter Version)"); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | #ifndef CONFIG_CPCI405_VER2 |
| 484 | puts ("\nFPGA: "); |
| 485 | |
| 486 | /* display infos on fpgaimage */ |
| 487 | index = 15; |
| 488 | for (i=0; i<4; i++) { |
| 489 | len = fpgadata[index]; |
| 490 | printf("%s ", &(fpgadata[index+1])); |
| 491 | index += len+3; |
| 492 | } |
| 493 | #endif |
| 494 | |
| 495 | putc ('\n'); |
| 496 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 497 | /* |
| 498 | * Disable sleep mode in LXT971 |
| 499 | */ |
| 500 | lxt971_no_sleep(); |
| 501 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | /* ------------------------------------------------------------------------- */ |
| 506 | |
| 507 | long int initdram (int board_type) |
| 508 | { |
| 509 | unsigned long val; |
| 510 | |
| 511 | mtdcr(memcfga, mem_mb0cf); |
| 512 | val = mfdcr(memcfgd); |
| 513 | |
| 514 | #if 0 |
| 515 | printf("\nmb0cf=%x\n", val); /* test-only */ |
| 516 | printf("strap=%x\n", mfdcr(strap)); /* test-only */ |
| 517 | #endif |
| 518 | |
| 519 | return (4*1024*1024 << ((val & 0x000e0000) >> 17)); |
| 520 | } |
| 521 | |
| 522 | /* ------------------------------------------------------------------------- */ |
| 523 | |
| 524 | int testdram (void) |
| 525 | { |
| 526 | /* TODO: XXX XXX XXX */ |
| 527 | printf ("test: 16 MB - ok\n"); |
| 528 | |
| 529 | return (0); |
| 530 | } |
| 531 | |
| 532 | /* ------------------------------------------------------------------------- */ |
| 533 | |
| 534 | #ifdef CONFIG_CPCI405_VER2 |
| 535 | #ifdef CONFIG_IDE_RESET |
| 536 | |
| 537 | void ide_set_reset(int on) |
| 538 | { |
| 539 | volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR; |
| 540 | |
| 541 | /* |
| 542 | * Assert or deassert CompactFlash Reset Pin |
| 543 | */ |
| 544 | if (on) { /* assert RESET */ |
| 545 | *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET); |
| 546 | } else { /* release RESET */ |
| 547 | *fpga_mode |= CFG_FPGA_MODE_CF_RESET; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | #endif /* CONFIG_IDE_RESET */ |
| 552 | #endif /* CONFIG_CPCI405_VER2 */ |
| 553 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 554 | |
| 555 | #ifdef CONFIG_CPCI405AB |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 556 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 557 | #define ONE_WIRE_CLEAR (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \ |
wdenk | 07d7e6b | 2004-12-16 21:44:03 +0000 | [diff] [blame] | 558 | |= CFG_FPGA_MODE_1WIRE_DIR) |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 559 | #define ONE_WIRE_SET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_MODE) \ |
wdenk | 07d7e6b | 2004-12-16 21:44:03 +0000 | [diff] [blame] | 560 | &= ~CFG_FPGA_MODE_1WIRE_DIR) |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 561 | #define ONE_WIRE_GET (*(volatile unsigned short *)(CFG_FPGA_BASE_ADDR + CFG_FPGA_STATUS) \ |
wdenk | 07d7e6b | 2004-12-16 21:44:03 +0000 | [diff] [blame] | 562 | & CFG_FPGA_MODE_1WIRE) |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 563 | |
| 564 | /* |
| 565 | * Generate a 1-wire reset, return 1 if no presence detect was found, |
| 566 | * return 0 otherwise. |
| 567 | * (NOTE: Does not handle alarm presence from DS2404/DS1994) |
| 568 | */ |
| 569 | int OWTouchReset(void) |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 570 | { |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 571 | int result; |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 572 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 573 | ONE_WIRE_CLEAR; |
| 574 | udelay(480); |
| 575 | ONE_WIRE_SET; |
| 576 | udelay(70); |
| 577 | |
| 578 | result = ONE_WIRE_GET; |
| 579 | |
| 580 | udelay(410); |
| 581 | return result; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | /* |
| 586 | * Send 1 a 1-wire write bit. |
| 587 | * Provide 10us recovery time. |
| 588 | */ |
| 589 | void OWWriteBit(int bit) |
| 590 | { |
| 591 | if (bit) { |
| 592 | /* |
| 593 | * write '1' bit |
| 594 | */ |
| 595 | ONE_WIRE_CLEAR; |
| 596 | udelay(6); |
| 597 | ONE_WIRE_SET; |
| 598 | udelay(64); |
| 599 | } else { |
| 600 | /* |
| 601 | * write '0' bit |
| 602 | */ |
| 603 | ONE_WIRE_CLEAR; |
| 604 | udelay(60); |
| 605 | ONE_WIRE_SET; |
| 606 | udelay(10); |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 607 | } |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | /* |
| 612 | * Read a bit from the 1-wire bus and return it. |
| 613 | * Provide 10us recovery time. |
| 614 | */ |
| 615 | int OWReadBit(void) |
| 616 | { |
| 617 | int result; |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 618 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 619 | ONE_WIRE_CLEAR; |
| 620 | udelay(6); |
| 621 | ONE_WIRE_SET; |
| 622 | udelay(9); |
| 623 | |
| 624 | result = ONE_WIRE_GET; |
| 625 | |
| 626 | udelay(55); |
| 627 | return result; |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 631 | void OWWriteByte(int data) |
| 632 | { |
| 633 | int loop; |
| 634 | |
| 635 | for (loop=0; loop<8; loop++) { |
| 636 | OWWriteBit(data & 0x01); |
| 637 | data >>= 1; |
| 638 | } |
| 639 | } |
| 640 | |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 641 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 642 | int OWReadByte(void) |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 643 | { |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 644 | int loop, result = 0; |
| 645 | |
| 646 | for (loop=0; loop<8; loop++) { |
| 647 | result >>= 1; |
| 648 | if (OWReadBit()) { |
| 649 | result |= 0x80; |
| 650 | } |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 651 | } |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 652 | |
| 653 | return result; |
stroese | d253d4b | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 654 | } |
| 655 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 656 | |
| 657 | int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 658 | { |
| 659 | volatile unsigned short val; |
| 660 | int result; |
| 661 | int i; |
| 662 | unsigned char ow_id[6]; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 663 | char str[32]; |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 664 | unsigned char ow_crc; |
| 665 | |
| 666 | /* |
| 667 | * Clear 1-wire bit (open drain with pull-up) |
| 668 | */ |
| 669 | val = *(volatile unsigned short *)0xf0400000; |
| 670 | val &= ~0x1000; /* clear 1-wire bit */ |
| 671 | *(volatile unsigned short *)0xf0400000 = val; |
| 672 | |
| 673 | result = OWTouchReset(); |
| 674 | if (result != 0) { |
| 675 | puts("No 1-wire device detected!\n"); |
| 676 | } |
| 677 | |
| 678 | OWWriteByte(0x33); /* send read rom command */ |
| 679 | OWReadByte(); /* skip family code ( == 0x01) */ |
| 680 | for (i=0; i<6; i++) { |
| 681 | ow_id[i] = OWReadByte(); |
| 682 | } |
| 683 | ow_crc = OWReadByte(); /* read crc */ |
| 684 | |
| 685 | sprintf(str, "%08X%04X", *(unsigned int *)&ow_id[0], *(unsigned short *)&ow_id[4]); |
| 686 | printf("Setting environment variable 'ow_id' to %s\n", str); |
| 687 | setenv("ow_id", str); |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | U_BOOT_CMD( |
| 692 | onewire, 1, 1, do_onewire, |
| 693 | "onewire - Read 1-write ID\n", |
| 694 | NULL |
| 695 | ); |
| 696 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 697 | |
| 698 | #define CFG_I2C_EEPROM_ADDR_2 0x51 /* EEPROM CAT28WC32 */ |
| 699 | #define CFG_ENV_SIZE_2 0x800 /* 2048 bytes may be used for env vars*/ |
| 700 | |
| 701 | /* |
| 702 | * Write backplane ip-address... |
| 703 | */ |
| 704 | int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 705 | { |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 706 | bd_t *bd = gd->bd; |
| 707 | char *buf; |
| 708 | ulong crc; |
| 709 | char str[32]; |
| 710 | char *ptr; |
| 711 | IPaddr_t ipaddr; |
| 712 | |
| 713 | buf = malloc(CFG_ENV_SIZE_2); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 714 | if (eeprom_read(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) { |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 715 | puts("\nError reading backplane EEPROM!\n"); |
| 716 | } else { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 717 | crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4); |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 718 | if (crc != *(ulong *)buf) { |
| 719 | printf("ERROR: crc mismatch %08lx %08lx\n", crc, *(ulong *)buf); |
| 720 | return -1; |
| 721 | } |
| 722 | |
| 723 | /* |
| 724 | * Find bp_ip |
| 725 | */ |
| 726 | ptr = strstr(buf+4, "bp_ip="); |
| 727 | if (ptr == NULL) { |
| 728 | printf("ERROR: bp_ip not found!\n"); |
| 729 | return -1; |
| 730 | } |
| 731 | ptr += 6; |
| 732 | ipaddr = string_to_ip(ptr); |
| 733 | |
| 734 | /* |
| 735 | * Update whole ip-addr |
| 736 | */ |
| 737 | bd->bi_ip_addr = ipaddr; |
| 738 | sprintf(str, "%ld.%ld.%ld.%ld", |
| 739 | (bd->bi_ip_addr & 0xff000000) >> 24, |
| 740 | (bd->bi_ip_addr & 0x00ff0000) >> 16, |
| 741 | (bd->bi_ip_addr & 0x0000ff00) >> 8, |
| 742 | (bd->bi_ip_addr & 0x000000ff)); |
| 743 | setenv("ipaddr", str); |
| 744 | printf("Updated ip_addr from bp_eeprom to %s!\n", str); |
| 745 | } |
| 746 | |
| 747 | free(buf); |
| 748 | |
| 749 | return 0; |
| 750 | } |
| 751 | U_BOOT_CMD( |
| 752 | getbpip, 1, 1, do_get_bpip, |
| 753 | "getbpip - Update IP-Address with Backplane IP-Address\n", |
| 754 | NULL |
| 755 | ); |
| 756 | |
| 757 | /* |
| 758 | * Set and print backplane ip... |
| 759 | */ |
| 760 | int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 761 | { |
| 762 | char *buf; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 763 | char str[32]; |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 764 | ulong crc; |
| 765 | |
| 766 | if (argc < 2) { |
| 767 | puts("ERROR!\n"); |
| 768 | return -1; |
| 769 | } |
| 770 | |
| 771 | printf("Setting bp_ip to %s\n", argv[1]); |
| 772 | buf = malloc(CFG_ENV_SIZE_2); |
| 773 | memset(buf, 0, CFG_ENV_SIZE_2); |
| 774 | sprintf(str, "bp_ip=%s", argv[1]); |
| 775 | strcpy(buf+4, str); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 776 | crc = crc32(0, (uchar *)(buf+4), CFG_ENV_SIZE_2-4); |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 777 | *(ulong *)buf = crc; |
| 778 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 779 | if (eeprom_write(CFG_I2C_EEPROM_ADDR_2, 0, (uchar *)buf, CFG_ENV_SIZE_2)) { |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 780 | puts("\nError writing backplane EEPROM!\n"); |
| 781 | } |
| 782 | |
| 783 | free(buf); |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | U_BOOT_CMD( |
| 788 | setbpip, 2, 1, do_set_bpip, |
| 789 | "setbpip - Write Backplane IP-Address\n", |
| 790 | NULL |
| 791 | ); |
| 792 | |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 793 | #endif /* CONFIG_CPCI405AB */ |