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