]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - board/prodrive/pdnb3/pdnb3.c
fa320da2d483fad3bd6d3cb66adfcf195c701adb
[karo-tx-uboot.git] / board / prodrive / pdnb3 / pdnb3.c
1 /*
2  * (C) Copyright 2006
3  * Stefan Roese, DENX Software Engineering, sr@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <command.h>
10 #include <malloc.h>
11 #include <asm/arch/ixp425.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 /* predefine these here for FPGA programming (before including fpga.c) */
16 #define SET_FPGA(data)  *IXP425_GPIO_GPOUTR = (data)
17 #define FPGA_DONE_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_DONE)
18 #define FPGA_INIT_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_INIT)
19 #define OLD_VAL         old_val
20
21 static unsigned long old_val = 0;
22
23 /*
24  * include common fpga code (for prodrive boards)
25  */
26 #include "../common/fpga.c"
27
28 /*
29  * Miscelaneous platform dependent initialisations
30  */
31 int board_init(void)
32 {
33         /* adress of boot parameters */
34         gd->bd->bi_boot_params = 0x00000100;
35
36         GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET);
37         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_FPGA_RESET);
38
39         GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_SYS_RUNNING);
40         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_SYS_RUNNING);
41
42         /*
43          * Setup GPIO's for FPGA programming
44          */
45         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG);
46         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK);
47         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA);
48         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PRG);
49         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK);
50         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_DATA);
51         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_INIT);
52         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_DONE);
53
54         /*
55          * Setup GPIO's for interrupts
56          */
57         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTA);
58         GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTA);
59         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTB);
60         GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTB);
61         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTORE_INT);
62         GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTORE_INT);
63         GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTART_INT);
64         GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTART_INT);
65
66         /*
67          * Setup GPIO's for 33MHz clock output
68          */
69         *IXP425_GPIO_GPCLKR = 0x01FF0000;
70         GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK_33M);
71
72         /*
73          * Setup other chip select's
74          */
75         *IXP425_EXP_CS1 = CONFIG_SYS_EXP_CS1;
76
77         return 0;
78 }
79
80 /*
81  * Check Board Identity
82  */
83 int checkboard(void)
84 {
85         char buf[64];
86         int i = getenv_f("serial#", buf, sizeof(buf));
87
88         puts("Board: PDNB3");
89
90         if (i > 0) {
91                 puts(", serial# ");
92                 puts(buf);
93         }
94         putc('\n');
95
96         return (0);
97 }
98
99 int dram_init(void)
100 {
101         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
102         gd->bd->bi_dram[0].size  = PHYS_SDRAM_1_SIZE;
103
104         return (0);
105 }
106
107 int do_fpga_boot(unsigned char *fpgadata)
108 {
109         unsigned char *dst;
110         int status;
111         int index;
112         int i;
113         ulong len = CONFIG_SYS_MALLOC_LEN;
114
115         /*
116          * Setup GPIO's for FPGA programming
117          */
118         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG);
119         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK);
120         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA);
121
122         /*
123          * Save value so no readback is required upon programming
124          */
125         old_val = *IXP425_GPIO_GPOUTR;
126
127         /*
128          * First try to decompress fpga image (gzip compressed?)
129          */
130         dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
131         if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
132                 printf("Error: Image has to be gzipp'ed!\n");
133                 return -1;
134         }
135
136         status = fpga_boot(dst, len);
137         if (status != 0) {
138                 printf("\nFPGA: Booting failed ");
139                 switch (status) {
140                 case ERROR_FPGA_PRG_INIT_LOW:
141                         printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
142                         break;
143                 case ERROR_FPGA_PRG_INIT_HIGH:
144                         printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
145                         break;
146                 case ERROR_FPGA_PRG_DONE:
147                         printf("(Timeout: DONE not high after programming FPGA)\n ");
148                         break;
149                 }
150
151                 /* display infos on fpgaimage */
152                 index = 15;
153                 for (i=0; i<4; i++) {
154                         len = dst[index];
155                         printf("FPGA: %s\n", &(dst[index+1]));
156                         index += len+3;
157                 }
158                 putc ('\n');
159                 /* delayed reboot */
160                 for (i=5; i>0; i--) {
161                         printf("Rebooting in %2d seconds \r",i);
162                         for (index=0;index<1000;index++)
163                                 udelay(1000);
164                 }
165                 putc('\n');
166                 do_reset(NULL, 0, 0, NULL);
167         }
168
169         puts("FPGA:  ");
170
171         /* display infos on fpgaimage */
172         index = 15;
173         for (i=0; i<4; i++) {
174                 len = dst[index];
175                 printf("%s ", &(dst[index+1]));
176                 index += len+3;
177         }
178         putc('\n');
179
180         free(dst);
181
182         /*
183          * Reset FPGA
184          */
185         GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_FPGA_RESET);
186         udelay(10);
187         GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET);
188
189         return (0);
190 }
191
192 int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
193 {
194         ulong addr;
195
196         if (argc < 2)
197                 return cmd_usage(cmdtp);
198
199         addr = simple_strtoul(argv[1], NULL, 16);
200
201         return do_fpga_boot((unsigned char *)addr);
202 }
203
204 U_BOOT_CMD(
205         fpga,     2,     0,      do_fpga,
206         "boot FPGA",
207         "address size\n    - boot FPGA with gzipped image at <address>"
208 );
209
210 #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
211 extern struct pci_controller hose;
212 extern void pci_ixp_init(struct pci_controller * hose);
213
214 void pci_init_board(void)
215 {
216         extern void pci_ixp_init (struct pci_controller *hose);
217
218         pci_ixp_init(&hose);
219 }
220 #endif