1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <asm/processor.h>
26#include <command.h>
27#include <malloc.h>
28#include <pci.h>
29#include <asm/4xx_pci.h>
30#include <asm/io.h>
31
32#include "pci405.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
36
37unsigned long fpga_done_state(void);
38unsigned long fpga_init_state(void);
39
40#if 0
41#define FPGA_DEBUG
42#endif
43
44
45#define FPGA_DONE_STATE (fpga_done_state())
46#define FPGA_INIT_STATE (fpga_init_state())
47
48
49const unsigned char fpgadata[] =
50{
51#include "fpgadata.c"
52};
53
54
55
56
57#include "../common/fpga.c"
58
59#define FPGA_DONE_STATE_V11 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_DONE)
60#define FPGA_DONE_STATE_V12 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_DONE_V12)
61
62#define FPGA_INIT_STATE_V11 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_INIT)
63#define FPGA_INIT_STATE_V12 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_INIT_V12)
64
65
66int board_revision(void)
67{
68 unsigned long CPC0_CR0Reg;
69 unsigned long value;
70
71
72
73
74
75
76
77
78 CPC0_CR0Reg = mfdcr(CPC0_CR0);
79 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
80 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00100200);
81 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00100200);
82 udelay(1000);
83 value = in_be32((void*)GPIO0_IR) & 0x00100200;
84
85
86
87
88 mtdcr(CPC0_CR0, CPC0_CR0Reg);
89
90 switch (value) {
91 case 0x00100200:
92
93 return 1;
94 case 0x00000200:
95
96 return 2;
97 case 0x00000000:
98
99 return 3;
100#if 0
101 case 0x00100000:
102
103 return 4;
104#endif
105 default:
106
107 return 0;
108 }
109}
110
111
112unsigned long fpga_done_state(void)
113{
114 if (gd->board_type < 2) {
115 return FPGA_DONE_STATE_V11;
116 } else {
117 return FPGA_DONE_STATE_V12;
118 }
119}
120
121
122unsigned long fpga_init_state(void)
123{
124 if (gd->board_type < 2) {
125 return FPGA_INIT_STATE_V11;
126 } else {
127 return FPGA_INIT_STATE_V12;
128 }
129}
130
131
132int board_early_init_f (void)
133{
134 unsigned long CPC0_CR0Reg;
135
136
137
138
139 out_be32((void*)GPIO0_ODR, 0x00000000);
140 out_be32((void*)GPIO0_TCR, CONFIG_SYS_FPGA_PRG);
141 out_be32((void*)GPIO0_OR, CONFIG_SYS_FPGA_PRG);
142 out_be32((void*)GPIO0_OR, 0);
143
144
145
146
147
148
149
150
151
152
153
154
155
156 mtdcr(UIC0SR, 0xFFFFFFFF);
157 mtdcr(UIC0ER, 0x00000000);
158 mtdcr(UIC0CR, 0x00000000);
159 mtdcr(UIC0PR, 0xFFFFFF80);
160 mtdcr(UIC0TR, 0x10000000);
161 mtdcr(UIC0VCR, 0x00000001);
162 mtdcr(UIC0SR, 0xFFFFFFFF);
163
164
165
166
167 CPC0_CR0Reg = mfdcr(CPC0_CR0);
168 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00008000);
169
170
171
172
173 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
174
175
176
177
178 mtebc (EBC0_CFG, 0xa8400000);
179
180 return 0;
181}
182
183int misc_init_r (void)
184{
185 unsigned char *dst;
186 ulong len = sizeof(fpgadata);
187 int status;
188 int index;
189 int i;
190 unsigned int *ptr;
191 unsigned int *magic;
192
193
194
195
196
197
198 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
199 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
200 printf ("GUNZIP ERROR - must RESET board to recover\n");
201 do_reset (NULL, 0, 0, NULL);
202 }
203
204 status = fpga_boot(dst, len);
205 if (status != 0) {
206 printf("\nFPGA: Booting failed ");
207 switch (status) {
208 case ERROR_FPGA_PRG_INIT_LOW:
209 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
210 break;
211 case ERROR_FPGA_PRG_INIT_HIGH:
212 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
213 break;
214 case ERROR_FPGA_PRG_DONE:
215 printf("(Timeout: DONE not high after programming FPGA)\n ");
216 break;
217 }
218
219
220 index = 15;
221 for (i=0; i<4; i++) {
222 len = dst[index];
223 printf("FPGA: %s\n", &(dst[index+1]));
224 index += len+3;
225 }
226 putc ('\n');
227
228 for (i=20; i>0; i--) {
229 printf("Rebooting in %2d seconds \r",i);
230 for (index=0;index<1000;index++)
231 udelay(1000);
232 }
233 putc ('\n');
234 do_reset(NULL, 0, 0, NULL);
235 }
236
237 puts("FPGA: ");
238
239
240 index = 15;
241 for (i=0; i<4; i++) {
242 len = dst[index];
243 printf("%s ", &(dst[index+1]));
244 index += len+3;
245 }
246 putc ('\n');
247
248
249
250
251 SET_FPGA(FPGA_PRG | FPGA_CLK);
252 udelay(1000);
253 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
254 udelay(1000);
255
256
257
258
259 magic = (unsigned int *)0x00000004;
260 if (*magic == PCI_RECONFIG_MAGIC) {
261
262
263
264 ptr = (unsigned int *)PCI_REGS_ADDR;
265 if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
266 puts("Restoring PCI Configurations Regs!\n");
267 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
268 for (i=0; i<0x40; i+=4) {
269 pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
270 }
271 }
272 mtdcr(UIC0SR, 0xFFFFFFFF);
273
274 *magic = 0;
275 }
276
277
278
279
280#define PCI0_BRDGOPT1 0x4a
281 pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
282
283
284
285
286 mtdcr(PLB0_ACR, 0x98000000);
287
288 free(dst);
289 return (0);
290}
291
292
293
294
295
296int checkboard (void)
297{
298 char str[64];
299 int i = getenv_f("serial#", str, sizeof(str));
300
301 puts ("Board: ");
302
303 if (i == -1) {
304 puts ("### No HW ID - assuming PCI405");
305 } else {
306 puts (str);
307 }
308
309 gd->board_type = board_revision();
310 printf(" (Rev 1.%ld", gd->board_type);
311
312 if (gd->board_type >= 2) {
313 unsigned long CPC0_CR0Reg;
314 unsigned long value;
315
316
317
318
319 CPC0_CR0Reg = mfdcr(CPC0_CR0);
320 mtdcr(CPC0_CR0, CPC0_CR0Reg & ~0x08000000);
321 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x40000000);
322 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x40000000);
323 udelay(1000);
324 value = in_be32((void*)GPIO0_IR) & 0x40000000;
325 if (value) {
326 puts(", 33 MHz PCI");
327 } else {
328 puts(", 66 MHz PCI");
329 }
330 }
331
332 puts(")\n");
333
334 return 0;
335}
336
337
338#define UART1_MCR 0xef600404
339int wpeeprom(int wp)
340{
341 int wp_state = wp;
342
343 if (wp == 1) {
344 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) & ~0x02);
345 } else if (wp == 0) {
346 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) | 0x02);
347 } else {
348 if (in_8((void *)UART1_MCR) & 0x02) {
349 wp_state = 0;
350 } else {
351 wp_state = 1;
352 }
353 }
354 return wp_state;
355}
356
357int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
358{
359 int wp = -1;
360 if (argc >= 2) {
361 if (argv[1][0] == '1') {
362 wp = 1;
363 } else if (argv[1][0] == '0') {
364 wp = 0;
365 }
366 }
367
368 wp = wpeeprom(wp);
369 printf("EEPROM write protection %s\n", wp ? "ENABLED" : "DISABLED");
370 return 0;
371}
372
373U_BOOT_CMD(
374 wpeeprom, 2, 1, do_wpeeprom,
375 "Check/Enable/Disable I2C EEPROM write protection",
376 "wpeeprom\n"
377 " - check I2C EEPROM write protection state\n"
378 "wpeeprom 1\n"
379 " - enable I2C EEPROM write protection\n"
380 "wpeeprom 0\n"
381 " - disable I2C EEPROM write protection"
382);
383