1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <common.h>
24#include <libfdt.h>
25#include <fdt_support.h>
26#include <asm/processor.h>
27#include <asm/io.h>
28#include <command.h>
29#include <malloc.h>
30#include <net.h>
31#include <pci.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35extern void __ft_board_setup(void *blob, bd_t *bd);
36
37#undef FPGA_DEBUG
38
39
40const unsigned char fpgadata[] =
41{
42#if defined(CONFIG_CPCI405_VER2)
43# if defined(CONFIG_CPCI405AB)
44# include "fpgadata_cpci405ab.c"
45# else
46# include "fpgadata_cpci4052.c"
47# endif
48#else
49# include "fpgadata_cpci405.c"
50#endif
51};
52
53
54
55
56#include "../common/fpga.c"
57#include "../common/auto_update.h"
58
59#if defined(CONFIG_CPCI405AB)
60au_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#if defined(CONFIG_CPCI405_VER2)
69au_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
77au_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
87int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
88
89
90int cpci405_version(void);
91void lxt971_no_sleep(void);
92
93int board_early_init_f(void)
94{
95#ifndef CONFIG_CPCI405_VER2
96 int index, len, i;
97 int status;
98#endif
99
100#ifdef FPGA_DEBUG
101
102 (void)get_clocks();
103 gd->baudrate = CONFIG_BAUDRATE;
104 serial_init();
105 console_init_f();
106#endif
107
108
109
110
111
112 out_be32((void *)GPIO0_ODR, 0x00000000);
113 out_be32((void *)GPIO0_TCR, CONFIG_SYS_FPGA_PRG);
114 out_be32((void *)GPIO0_OR, CONFIG_SYS_FPGA_PRG);
115 out_be32((void *)GPIO0_OR, 0);
116
117
118
119
120#ifndef CONFIG_CPCI405_VER2
121 if (cpci405_version() == 1) {
122 status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
123 if (status != 0) {
124
125#ifndef FPGA_DEBUG
126
127 (void)get_clocks();
128 gd->baudrate = CONFIG_BAUDRATE;
129 serial_init();
130 console_init_f();
131#endif
132 printf("\nFPGA: Booting failed ");
133 switch (status) {
134 case ERROR_FPGA_PRG_INIT_LOW:
135 printf("(Timeout: INIT not low after "
136 "asserting PROGRAM*)\n ");
137 break;
138 case ERROR_FPGA_PRG_INIT_HIGH:
139 printf("(Timeout: INIT not high after "
140 "deasserting PROGRAM*)\n ");
141 break;
142 case ERROR_FPGA_PRG_DONE:
143 printf("(Timeout: DONE not high after "
144 "programming FPGA)\n ");
145 break;
146 }
147
148
149 index = 15;
150 for (i = 0; i < 4; i++) {
151 len = fpgadata[index];
152 printf("FPGA: %s\n", &(fpgadata[index + 1]));
153 index += len + 3;
154 }
155 putc('\n');
156
157 for (i = 20; i > 0; i--) {
158 printf("Rebooting in %2d seconds \r",i);
159 for (index = 0; index < 1000; index++)
160 udelay(1000);
161 }
162 putc('\n');
163 do_reset(NULL, 0, 0, NULL);
164 }
165 }
166#endif
167
168
169
170
171
172
173
174
175
176
177
178
179
180 mtdcr(UIC0SR, 0xFFFFFFFF);
181 mtdcr(UIC0ER, 0x00000000);
182 mtdcr(UIC0CR, 0x00000000);
183#if defined(CONFIG_CPCI405_6U)
184 if (cpci405_version() == 3) {
185 mtdcr(UIC0PR, 0xFFFFFF99);
186 } else {
187 mtdcr(UIC0PR, 0xFFFFFF81);
188 }
189#else
190 mtdcr(UIC0PR, 0xFFFFFF81);
191#endif
192 mtdcr(UIC0TR, 0x10000000);
193 mtdcr(UIC0VCR, 0x00000001);
194
195 mtdcr(UIC0SR, 0xFFFFFFFF);
196
197 return 0;
198}
199
200int ctermm2(void)
201{
202#if defined(CONFIG_CPCI405_VER2)
203 return 0;
204#else
205 if ((in_8((void*)0xf0000400) == 0x00) &&
206 (in_8((void*)0xf0000401) == 0x01))
207 return 0;
208 else
209 return -1;
210#endif
211}
212
213int cpci405_host(void)
214{
215 if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN)
216 return -1;
217 else
218 return 0;
219}
220
221int cpci405_version(void)
222{
223 unsigned long CPC0_CR0Reg;
224 unsigned long value;
225
226
227
228
229 CPC0_CR0Reg = mfdcr(CPC0_CR0);
230 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
231 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000);
232 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000);
233 udelay(1000);
234 value = in_be32((void*)GPIO0_IR) & 0x00180000;
235
236
237
238
239 mtdcr(CPC0_CR0, CPC0_CR0Reg);
240
241 switch (value) {
242 case 0x00180000:
243
244 return 1;
245 case 0x00080000:
246
247 return 2;
248 case 0x00100000:
249
250 return 3;
251 case 0x00000000:
252
253 return 4;
254 default:
255
256 return 2;
257 }
258}
259
260int misc_init_r (void)
261{
262 unsigned long CPC0_CR0Reg;
263
264
265 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
266 gd->bd->bi_flashoffset = 0;
267
268#if defined(CONFIG_CPCI405_VER2)
269 {
270 unsigned char *dst;
271 ulong len = sizeof(fpgadata);
272 int status;
273 int index;
274 int i;
275
276
277
278
279
280 if (cpci405_version() >= 2) {
281
282
283
284 CPC0_CR0Reg = mfdcr(CPC0_CR0);
285 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
286
287 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
288 if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE,
289 (uchar *)fpgadata, &len) != 0) {
290 printf("GUNZIP ERROR - must RESET board to recover\n");
291 do_reset(NULL, 0, 0, NULL);
292 }
293
294 status = fpga_boot(dst, len);
295 if (status != 0) {
296 printf("\nFPGA: Booting failed ");
297 switch (status) {
298 case ERROR_FPGA_PRG_INIT_LOW:
299 printf("(Timeout: INIT not low after "
300 "asserting PROGRAM*)\n ");
301 break;
302 case ERROR_FPGA_PRG_INIT_HIGH:
303 printf("(Timeout: INIT not high after "
304 "deasserting PROGRAM*)\n ");
305 break;
306 case ERROR_FPGA_PRG_DONE:
307 printf("(Timeout: DONE not high after "
308 "programming FPGA)\n ");
309 break;
310 }
311
312
313 index = 15;
314 for (i = 0; i < 4; i++) {
315 len = dst[index];
316 printf("FPGA: %s\n", &(dst[index + 1]));
317 index += len + 3;
318 }
319 putc('\n');
320
321 for (i = 20; i > 0; i--) {
322 printf("Rebooting in %2d seconds \r", i);
323 for (index = 0; index < 1000; index++)
324 udelay(1000);
325 }
326 putc('\n');
327 do_reset(NULL, 0, 0, NULL);
328 }
329
330
331 mtdcr(CPC0_CR0, CPC0_CR0Reg);
332
333 puts("FPGA: ");
334
335
336 index = 15;
337 for (i = 0; i < 4; i++) {
338 len = dst[index];
339 printf("%s ", &(dst[index + 1]));
340 index += len + 3;
341 }
342 putc('\n');
343
344 free(dst);
345
346
347
348
349 SET_FPGA(FPGA_PRG | FPGA_CLK);
350 udelay(1000);
351 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
352 udelay(1000);
353
354#if defined(CONFIG_CPCI405_6U)
355#error HIER GETH ES WEITER MIT IO ACCESSORS
356 if (cpci405_version() == 3) {
357
358
359
360 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
361 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
362 CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT);
363
364
365
366
367 out_8((void*)CONFIG_SYS_LED_ADDR, 0x00);
368
369
370
371
372 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
373 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
374 CONFIG_SYS_FPGA_MODE_DUART_RESET);
375 udelay(100);
376 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
377 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) &
378 ~CONFIG_SYS_FPGA_MODE_DUART_RESET);
379 }
380#endif
381 }
382 else {
383 puts("\n*** U-Boot Version does not match Board Version!\n");
384 puts("*** CPCI-405 Version 1.x detected!\n");
385 puts("*** Please use correct U-Boot version "
386 "(CPCI405 instead of CPCI4052)!\n\n");
387 }
388 }
389#else
390 if (cpci405_version() >= 2) {
391 puts("\n*** U-Boot Version does not match Board Version!\n");
392 puts("*** CPCI-405 Board Version 2.x detected!\n");
393 puts("*** Please use correct U-Boot version "
394 "(CPCI4052 instead of CPCI405)!\n\n");
395 }
396#endif
397
398
399
400
401 CPC0_CR0Reg = mfdcr(CPC0_CR0);
402 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000);
403
404 return 0;
405}
406
407
408
409
410
411int checkboard(void)
412{
413#ifndef CONFIG_CPCI405_VER2
414 int index;
415 int len;
416#endif
417 char str[64];
418 int i = getenv_f("serial#", str, sizeof(str));
419 unsigned short ver;
420
421 puts("Board: ");
422
423 if (i == -1)
424 puts("### No HW ID - assuming CPCI405");
425 else
426 puts(str);
427
428 ver = cpci405_version();
429 printf(" (Ver %d.x, ", ver);
430
431 if (ctermm2()) {
432 char str[4];
433
434
435
436
437 sprintf(str, "%d", *(unsigned char *)0xf0000400);
438 setenv("boardid", str);
439 printf("CTERM-M2 - Id=%s)", str);
440 } else {
441 if (cpci405_host())
442 puts("PCI Host Version)");
443 else
444 puts("PCI Adapter Version)");
445 }
446
447#ifndef CONFIG_CPCI405_VER2
448 puts("\nFPGA: ");
449
450
451 index = 15;
452 for (i = 0; i < 4; i++) {
453 len = fpgadata[index];
454 printf("%s ", &(fpgadata[index + 1]));
455 index += len + 3;
456 }
457#endif
458
459 putc('\n');
460 return 0;
461}
462
463void reset_phy(void)
464{
465#if defined(CONFIG_LXT971_NO_SLEEP)
466
467
468
469
470 lxt971_no_sleep();
471#endif
472}
473
474#if defined(CONFIG_CPCI405_VER2) && defined (CONFIG_IDE_RESET)
475void ide_set_reset(int on)
476{
477
478
479
480 if (on) {
481 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
482 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) &
483 ~CONFIG_SYS_FPGA_MODE_CF_RESET);
484 } else {
485 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
486 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
487 CONFIG_SYS_FPGA_MODE_CF_RESET);
488 }
489}
490
491#endif
492
493#if defined(CONFIG_PCI)
494void cpci405_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
495{
496 unsigned char int_line = 0xff;
497
498
499
500
501 switch (PCI_DEV(dev) & 0x03) {
502 case 0:
503 int_line = 27 + 2;
504 break;
505 case 1:
506 int_line = 27 + 3;
507 break;
508 case 2:
509 int_line = 27 + 0;
510 break;
511 case 3:
512 int_line = 27 + 1;
513 break;
514 }
515
516 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
517}
518
519int pci_pre_init(struct pci_controller *hose)
520{
521 hose->fixup_irq = cpci405_pci_fixup_irq;
522 return 1;
523}
524#endif
525
526#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
527void ft_board_setup(void *blob, bd_t *bd)
528{
529 int rc;
530
531 __ft_board_setup(blob, bd);
532
533
534
535
536 if (!cpci405_host()) {
537 rc = fdt_find_and_setprop(blob, "/plb/pci@ec000000", "status",
538 "disabled", sizeof("disabled"), 1);
539 if (rc) {
540 printf("Unable to update property status in PCI node, "
541 "err=%s\n",
542 fdt_strerror(rc));
543 }
544 }
545}
546#endif
547
548#if defined(CONFIG_CPCI405AB)
549#define ONE_WIRE_CLEAR out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \
550 CONFIG_SYS_FPGA_MODE), \
551 in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \
552 CONFIG_SYS_FPGA_MODE)) | \
553 CONFIG_SYS_FPGA_MODE_1WIRE_DIR)
554
555#define ONE_WIRE_SET out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \
556 CONFIG_SYS_FPGA_MODE), \
557 in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \
558 CONFIG_SYS_FPGA_MODE)) & \
559 ~CONFIG_SYS_FPGA_MODE_1WIRE_DIR)
560
561#define ONE_WIRE_GET (in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \
562 CONFIG_SYS_FPGA_STATUS)) & \
563 CONFIG_SYS_FPGA_MODE_1WIRE)
564
565
566
567
568
569
570int OWTouchReset(void)
571{
572 int result;
573
574 ONE_WIRE_CLEAR;
575 udelay(480);
576 ONE_WIRE_SET;
577 udelay(70);
578
579 result = ONE_WIRE_GET;
580
581 udelay(410);
582 return result;
583}
584
585
586
587
588
589void OWWriteBit(int bit)
590{
591 if (bit) {
592
593
594
595 ONE_WIRE_CLEAR;
596 udelay(6);
597 ONE_WIRE_SET;
598 udelay(64);
599 } else {
600
601
602
603 ONE_WIRE_CLEAR;
604 udelay(60);
605 ONE_WIRE_SET;
606 udelay(10);
607 }
608}
609
610
611
612
613
614int OWReadBit(void)
615{
616 int result;
617
618 ONE_WIRE_CLEAR;
619 udelay(6);
620 ONE_WIRE_SET;
621 udelay(9);
622
623 result = ONE_WIRE_GET;
624
625 udelay(55);
626 return result;
627}
628
629void OWWriteByte(int data)
630{
631 int loop;
632
633 for (loop = 0; loop < 8; loop++) {
634 OWWriteBit(data & 0x01);
635 data >>= 1;
636 }
637}
638
639int OWReadByte(void)
640{
641 int loop, result = 0;
642
643 for (loop = 0; loop < 8; loop++) {
644 result >>= 1;
645 if (OWReadBit())
646 result |= 0x80;
647 }
648
649 return result;
650}
651
652int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
653{
654 unsigned short val;
655 int result;
656 int i;
657 unsigned char ow_id[6];
658 char str[32];
659
660
661
662
663 val = in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR +
664 CONFIG_SYS_FPGA_MODE));
665 val &= ~CONFIG_SYS_FPGA_MODE_1WIRE;
666 out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR +
667 CONFIG_SYS_FPGA_MODE), val);
668
669 result = OWTouchReset();
670 if (result != 0)
671 puts("No 1-wire device detected!\n");
672
673 OWWriteByte(0x33);
674 OWReadByte();
675 for (i = 0; i < 6; i++)
676 ow_id[i] = OWReadByte();
677 OWReadByte();
678
679 sprintf(str, "%02X%02X%02X%02X%02X%02X",
680 ow_id[0], ow_id[1], ow_id[2], ow_id[3], ow_id[4], ow_id[5]);
681 printf("Setting environment variable 'ow_id' to %s\n", str);
682 setenv("ow_id", str);
683
684 return 0;
685}
686U_BOOT_CMD(
687 onewire, 1, 1, do_onewire,
688 "Read 1-write ID",
689 ""
690);
691
692#define CONFIG_SYS_I2C_EEPROM_ADDR_2 0x51
693#define CONFIG_ENV_SIZE_2 0x800
694
695
696
697
698int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
699{
700 bd_t *bd = gd->bd;
701 char *buf;
702 ulong crc;
703 char str[32];
704 char *ptr;
705 IPaddr_t ipaddr;
706
707 buf = malloc(CONFIG_ENV_SIZE_2);
708 if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR_2, 0,
709 (uchar *)buf, CONFIG_ENV_SIZE_2))
710 puts("\nError reading backplane EEPROM!\n");
711 else {
712 crc = crc32(0, (uchar *)(buf+4), CONFIG_ENV_SIZE_2 - 4);
713 if (crc != *(ulong *)buf) {
714 printf("ERROR: crc mismatch %08lx %08lx\n",
715 crc, *(ulong *)buf);
716 return -1;
717 }
718
719
720
721
722 ptr = strstr(buf+4, "bp_ip=");
723 if (ptr == NULL) {
724 printf("ERROR: bp_ip not found!\n");
725 return -1;
726 }
727 ptr += 6;
728 ipaddr = string_to_ip(ptr);
729
730
731
732
733 bd->bi_ip_addr = ipaddr;
734 sprintf(str, "%ld.%ld.%ld.%ld",
735 (bd->bi_ip_addr & 0xff000000) >> 24,
736 (bd->bi_ip_addr & 0x00ff0000) >> 16,
737 (bd->bi_ip_addr & 0x0000ff00) >> 8,
738 (bd->bi_ip_addr & 0x000000ff));
739 setenv("ipaddr", str);
740 printf("Updated ip_addr from bp_eeprom to %s!\n", str);
741 }
742
743 free(buf);
744
745 return 0;
746}
747U_BOOT_CMD(
748 getbpip, 1, 1, do_get_bpip,
749 "Update IP-Address with Backplane IP-Address",
750 ""
751);
752
753
754
755
756int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
757{
758 char *buf;
759 char str[32];
760 ulong crc;
761
762 if (argc < 2) {
763 puts("ERROR!\n");
764 return -1;
765 }
766
767 printf("Setting bp_ip to %s\n", argv[1]);
768 buf = malloc(CONFIG_ENV_SIZE_2);
769 memset(buf, 0, CONFIG_ENV_SIZE_2);
770 sprintf(str, "bp_ip=%s", argv[1]);
771 strcpy(buf+4, str);
772 crc = crc32(0, (uchar *)(buf+4), CONFIG_ENV_SIZE_2 - 4);
773 *(ulong *)buf = crc;
774
775 if (eeprom_write(CONFIG_SYS_I2C_EEPROM_ADDR_2,
776 0, (uchar *)buf, CONFIG_ENV_SIZE_2))
777 puts("\nError writing backplane EEPROM!\n");
778
779 free(buf);
780
781 return 0;
782}
783U_BOOT_CMD(
784 setbpip, 2, 1, do_set_bpip,
785 "Write Backplane IP-Address",
786 ""
787);
788
789#endif
790