blob: f740d595bef01f9b7458708eab5c074611d31282 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
stroesea530a9a2004-12-16 18:38:22 +00002 * (C) Copyright 2001-2004
wdenkc6097192002-11-03 00:24:07 +00003 * 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>
wdenkc6097192002-11-03 00:24:07 +000027#include <malloc.h>
28#include <pci.h>
Stefan Roeseca8725f2007-10-03 15:01:02 +020029#include <asm/4xx_pci.h>
wdenkc6097192002-11-03 00:24:07 +000030
stroese65f36a72003-03-25 14:41:35 +000031#include "pci405.h"
32
Wolfgang Denk6405a152006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
stroese65f36a72003-03-25 14:41:35 +000034
stroesea530a9a2004-12-16 18:38:22 +000035/* Prototypes */
36int gunzip(void *, int, unsigned char *, unsigned long *);
37int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);/*cmd_boot.c*/
38unsigned long fpga_done_state(void);
39unsigned long fpga_init_state(void);
40
wdenkc6097192002-11-03 00:24:07 +000041#if 0
42#define FPGA_DEBUG
43#endif
44
stroesea530a9a2004-12-16 18:38:22 +000045/* predefine these here */
46#define FPGA_DONE_STATE (fpga_done_state())
47#define FPGA_INIT_STATE (fpga_init_state())
48
wdenkc6097192002-11-03 00:24:07 +000049/* fpga configuration data - generated by bin2cc */
50const unsigned char fpgadata[] =
51{
52#include "fpgadata.c"
53};
54
55/*
56 * include common fpga code (for esd boards)
57 */
58#include "../common/fpga.c"
59
stroesea530a9a2004-12-16 18:38:22 +000060#define FPGA_DONE_STATE_V11 (in32(GPIO0_IR) & CFG_FPGA_DONE)
61#define FPGA_DONE_STATE_V12 (in32(GPIO0_IR) & CFG_FPGA_DONE_V12)
wdenkc6097192002-11-03 00:24:07 +000062
stroesea530a9a2004-12-16 18:38:22 +000063#define FPGA_INIT_STATE_V11 (in32(GPIO0_IR) & CFG_FPGA_INIT)
64#define FPGA_INIT_STATE_V12 (in32(GPIO0_IR) & CFG_FPGA_INIT_V12)
65
66
67int board_revision(void)
68{
69 unsigned long cntrl0Reg;
70 unsigned long value;
71
72 /*
73 * Get version of PCI405 board from GPIO's
74 */
75
76 /*
77 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
78 */
79 cntrl0Reg = mfdcr(cntrl0);
80 mtdcr(cntrl0, cntrl0Reg | 0x03000000);
Stefan Roese1e8519f2005-08-12 16:56:56 +020081 out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00100200);
82 out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00100200);
stroesea530a9a2004-12-16 18:38:22 +000083 udelay(1000); /* wait some time before reading input */
Stefan Roese1e8519f2005-08-12 16:56:56 +020084 value = in32(GPIO0_IR) & 0x00100200; /* get config bits */
stroesea530a9a2004-12-16 18:38:22 +000085
86 /*
87 * Restore GPIO settings
88 */
89 mtdcr(cntrl0, cntrl0Reg);
90
91 switch (value) {
Stefan Roese1e8519f2005-08-12 16:56:56 +020092 case 0x00100200:
93 /* CS2==1 && IRQ5==1 -> version 1.0 and 1.1 */
stroesea530a9a2004-12-16 18:38:22 +000094 return 1;
Stefan Roese1e8519f2005-08-12 16:56:56 +020095 case 0x00000200:
96 /* CS2==0 && IRQ5==1 -> version 1.2 */
stroesea530a9a2004-12-16 18:38:22 +000097 return 2;
Stefan Roese1e8519f2005-08-12 16:56:56 +020098 case 0x00000000:
99 /* CS2==0 && IRQ5==0 -> version 1.3 */
100 return 3;
stroesea530a9a2004-12-16 18:38:22 +0000101#if 0 /* not yet manufactured ! */
102 case 0x00100000:
Stefan Roese1e8519f2005-08-12 16:56:56 +0200103 /* CS2==1 && IRQ5==0 -> version 1.4 */
stroesea530a9a2004-12-16 18:38:22 +0000104 return 4;
105#endif
106 default:
107 /* should not be reached! */
108 return 0;
109 }
110}
111
112
113unsigned long fpga_done_state(void)
114{
stroesea530a9a2004-12-16 18:38:22 +0000115 if (gd->board_type < 2) {
116 return FPGA_DONE_STATE_V11;
117 } else {
118 return FPGA_DONE_STATE_V12;
119 }
120}
wdenkc6097192002-11-03 00:24:07 +0000121
122
stroesea530a9a2004-12-16 18:38:22 +0000123unsigned long fpga_init_state(void)
124{
stroesea530a9a2004-12-16 18:38:22 +0000125 if (gd->board_type < 2) {
126 return FPGA_INIT_STATE_V11;
127 } else {
128 return FPGA_INIT_STATE_V12;
129 }
130}
131
132
wdenkda55c6e2004-01-20 23:12:12 +0000133int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +0000134{
135 unsigned long cntrl0Reg;
136
137 /*
stroesea530a9a2004-12-16 18:38:22 +0000138 * First pull fpga-prg pin low, to disable fpga logic (on version 1.2 board)
139 */
140 out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
141 out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
142 out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
143 out32(GPIO0_OR, 0); /* pull prg low */
144
145 /*
wdenkc6097192002-11-03 00:24:07 +0000146 * IRQ 0-15 405GP internally generated; active high; level sensitive
147 * IRQ 16 405GP internally generated; active low; level sensitive
148 * IRQ 17-24 RESERVED
149 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
150 * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
151 * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
152 * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
153 * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
154 * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
155 * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
156 */
157 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
158 mtdcr(uicer, 0x00000000); /* disable all ints */
159 mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
160 mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
161 mtdcr(uictr, 0x10000000); /* set int trigger levels */
162 mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
163 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
164
165 /*
166 * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
167 */
168 cntrl0Reg = mfdcr(cntrl0);
169 mtdcr(cntrl0, cntrl0Reg | 0x00008000);
170
stroese6bbfa9f2003-05-23 11:33:57 +0000171 /*
stroesea530a9a2004-12-16 18:38:22 +0000172 * Setup GPIO pins (CS6+CS7 as GPIO)
173 */
174 mtdcr(cntrl0, cntrl0Reg | 0x00300000);
175
176 /*
stroese6bbfa9f2003-05-23 11:33:57 +0000177 * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
178 */
179 mtebc (epcr, 0xa8400000); /* ebc always driven */
180
wdenkc6097192002-11-03 00:24:07 +0000181 return 0;
182}
183
184
185/* ------------------------------------------------------------------------- */
186
187int misc_init_f (void)
188{
189 return 0; /* dummy implementation */
190}
191
192
193int misc_init_r (void)
194{
195 unsigned char *dst;
196 ulong len = sizeof(fpgadata);
197 int status;
198 int index;
199 int i;
stroese65f36a72003-03-25 14:41:35 +0000200 unsigned int *ptr;
201 unsigned int *magic;
wdenkc6097192002-11-03 00:24:07 +0000202
203 /*
204 * On PCI-405 the environment is saved in eeprom!
205 * FPGA can be gzip compressed (malloc) and booted this late.
206 */
207
208 dst = malloc(CFG_FPGA_MAX_SIZE);
wdenka0ebde52004-09-08 22:03:11 +0000209 if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
wdenkc6097192002-11-03 00:24:07 +0000210 printf ("GUNZIP ERROR - must RESET board to recover\n");
211 do_reset (NULL, 0, 0, NULL);
212 }
213
214 status = fpga_boot(dst, len);
215 if (status != 0) {
216 printf("\nFPGA: Booting failed ");
217 switch (status) {
218 case ERROR_FPGA_PRG_INIT_LOW:
219 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
220 break;
221 case ERROR_FPGA_PRG_INIT_HIGH:
222 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
223 break;
224 case ERROR_FPGA_PRG_DONE:
225 printf("(Timeout: DONE not high after programming FPGA)\n ");
226 break;
227 }
228
229 /* display infos on fpgaimage */
230 index = 15;
231 for (i=0; i<4; i++) {
232 len = dst[index];
233 printf("FPGA: %s\n", &(dst[index+1]));
234 index += len+3;
235 }
236 putc ('\n');
237 /* delayed reboot */
238 for (i=20; i>0; i--) {
239 printf("Rebooting in %2d seconds \r",i);
240 for (index=0;index<1000;index++)
241 udelay(1000);
242 }
243 putc ('\n');
244 do_reset(NULL, 0, 0, NULL);
245 }
246
247 puts("FPGA: ");
248
249 /* display infos on fpgaimage */
250 index = 15;
251 for (i=0; i<4; i++) {
252 len = dst[index];
253 printf("%s ", &(dst[index+1]));
254 index += len+3;
255 }
256 putc ('\n');
257
258 /*
stroese65f36a72003-03-25 14:41:35 +0000259 * Reset FPGA via FPGA_DATA pin
wdenkc6097192002-11-03 00:24:07 +0000260 */
stroese65f36a72003-03-25 14:41:35 +0000261 SET_FPGA(FPGA_PRG | FPGA_CLK);
262 udelay(1000); /* wait 1ms */
263 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
264 udelay(1000); /* wait 1ms */
wdenkc6097192002-11-03 00:24:07 +0000265
stroese65f36a72003-03-25 14:41:35 +0000266 /*
267 * Check if magic for pci reconfig is written
268 */
269 magic = (unsigned int *)0x00000004;
270 if (*magic == PCI_RECONFIG_MAGIC) {
271 /*
272 * Rewrite pci config regs (only after soft-reset with magic set)
273 */
274 ptr = (unsigned int *)PCI_REGS_ADDR;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200275 if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
stroese65f36a72003-03-25 14:41:35 +0000276 puts("Restoring PCI Configurations Regs!\n");
277 ptr = (unsigned int *)PCI_REGS_ADDR + 1;
278 for (i=0; i<0x40; i+=4) {
279 pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
280 }
281 }
282 mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
stroese6bbfa9f2003-05-23 11:33:57 +0000283
stroese65f36a72003-03-25 14:41:35 +0000284 *magic = 0; /* clear pci reconfig magic again */
285 }
wdenkc6097192002-11-03 00:24:07 +0000286
stroesea530a9a2004-12-16 18:38:22 +0000287#if 1 /* test-only */
288 /*
289 * Decrease PLB latency timeout and reduce priority of the PCI bridge master
290 */
291#define PCI0_BRDGOPT1 0x4a
292 pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
wdenk07d7e6b2004-12-16 21:44:03 +0000293/* pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f60); */
stroesea530a9a2004-12-16 18:38:22 +0000294
295#define plb0_acr 0x87
296 /*
297 * Enable fairness and high bus utilization
298 */
299 mtdcr(plb0_acr, 0x98000000);
300
301#if 0 /* test-only */
302 printf("CCR0=%08x\n", mfspr(ccr0)); /* test-only */
wdenk07d7e6b2004-12-16 21:44:03 +0000303/* mtspr(ccr0, (mfspr(ccr0) & 0xff8fffff) | 0x00100000); */
stroesea530a9a2004-12-16 18:38:22 +0000304 mtspr(ccr0, (mfspr(ccr0) & 0xff8fffff) | 0x00000000);
305#endif
wdenk54070ab2004-12-31 09:32:47 +0000306/* printf("CCR0=%08x\n", mfspr(ccr0)); */ /* test-only */
stroesea530a9a2004-12-16 18:38:22 +0000307#endif
308
wdenkc6097192002-11-03 00:24:07 +0000309 free(dst);
310 return (0);
311}
312
313
314/*
315 * Check Board Identity:
316 */
317
318int checkboard (void)
319{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200320 char str[64];
wdenkc6097192002-11-03 00:24:07 +0000321 int i = getenv_r ("serial#", str, sizeof(str));
322
323 puts ("Board: ");
324
325 if (i == -1) {
stroese65f36a72003-03-25 14:41:35 +0000326 puts ("### No HW ID - assuming PCI405");
wdenkc6097192002-11-03 00:24:07 +0000327 } else {
328 puts (str);
329 }
stroesea530a9a2004-12-16 18:38:22 +0000330
331 gd->board_type = board_revision();
332 printf(" (Rev 1.%ld", gd->board_type);
333
334 if (gd->board_type >= 2) {
335 unsigned long cntrl0Reg;
336 unsigned long value;
337
338 /*
339 * Setup GPIO pins (Trace/GPIO1 to GPIO)
340 */
341 cntrl0Reg = mfdcr(cntrl0);
342 mtdcr(cntrl0, cntrl0Reg & ~0x08000000);
343 out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x40000000);
344 out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x40000000);
345 udelay(1000); /* wait some time before reading input */
346 value = in32(GPIO0_IR) & 0x40000000; /* get config bits */
347 if (value) {
348 puts(", 33 MHz PCI");
349 } else {
350 puts(", 66 Mhz PCI");
351 }
352 }
353
354 puts(")\n");
wdenkc6097192002-11-03 00:24:07 +0000355
356 return 0;
357}
358
359/* ------------------------------------------------------------------------- */
360
Becky Brucebd99ae72008-06-09 16:03:40 -0500361phys_size_t initdram (int board_type)
wdenkc6097192002-11-03 00:24:07 +0000362{
363 unsigned long val;
364
365 mtdcr(memcfga, mem_mb0cf);
366 val = mfdcr(memcfgd);
367
368#if 0
369 printf("\nmb0cf=%x\n", val); /* test-only */
370 printf("strap=%x\n", mfdcr(strap)); /* test-only */
371#endif
372
stroese65f36a72003-03-25 14:41:35 +0000373#if 0 /* test-only: all PCI405 version must report 16mb */
wdenkc6097192002-11-03 00:24:07 +0000374 return (4*1024*1024 << ((val & 0x000e0000) >> 17));
stroese65f36a72003-03-25 14:41:35 +0000375#else
376 return (16*1024*1024);
377#endif
wdenkc6097192002-11-03 00:24:07 +0000378}
379
380/* ------------------------------------------------------------------------- */
381
382int testdram (void)
383{
384 /* TODO: XXX XXX XXX */
385 printf ("test: 16 MB - ok\n");
386
387 return (0);
388}
389
390/* ------------------------------------------------------------------------- */
Stefan Roese1e8519f2005-08-12 16:56:56 +0200391int wpeeprom(int wp)
392{
393 int wp_state = wp;
394 volatile unsigned char *uart1_mcr = (volatile unsigned char *)0xef600404;
395
396 if (wp == 1) {
397 *uart1_mcr &= ~0x02;
398 } else if (wp == 0) {
399 *uart1_mcr |= 0x02;
400 } else {
401 if (*uart1_mcr & 0x02) {
402 wp_state = 0;
403 } else {
404 wp_state = 1;
405 }
406 }
407 return wp_state;
408}
409
410int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
411{
412 int wp = -1;
413 if (argc >= 2) {
414 if (argv[1][0] == '1') {
415 wp = 1;
416 } else if (argv[1][0] == '0') {
417 wp = 0;
418 }
419 }
420
421 wp = wpeeprom(wp);
422 printf("EEPROM write protection %s\n", wp ? "ENABLED" : "DISABLED");
423 return 0;
424}
425
426U_BOOT_CMD(
427 wpeeprom, 2, 1, do_wpeeprom,
428 "wpeeprom - Check/Enable/Disable I2C EEPROM write protection\n",
429 "wpeeprom\n"
430 " - check I2C EEPROM write protection state\n"
431 "wpeeprom 1\n"
432 " - enable I2C EEPROM write protection\n"
433 "wpeeprom 0\n"
434 " - disable I2C EEPROM write protection\n"
435 );