blob: c1bac6a1b87e30fa5a9d063fbe48a6c277b4c8e2 [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>
Matthias Fuchs9b985c32008-11-24 15:11:09 +010030#include <asm/io.h>
wdenkc6097192002-11-03 00:24:07 +000031
stroese65f36a72003-03-25 14:41:35 +000032#include "pci405.h"
33
Wolfgang Denk6405a152006-03-31 18:32:53 +020034DECLARE_GLOBAL_DATA_PTR;
stroese65f36a72003-03-25 14:41:35 +000035
stroesea530a9a2004-12-16 18:38:22 +000036/* Prototypes */
stroesea530a9a2004-12-16 18:38:22 +000037unsigned long fpga_done_state(void);
38unsigned long fpga_init_state(void);
39
wdenkc6097192002-11-03 00:24:07 +000040#if 0
41#define FPGA_DEBUG
42#endif
43
stroesea530a9a2004-12-16 18:38:22 +000044/* predefine these here */
45#define FPGA_DONE_STATE (fpga_done_state())
46#define FPGA_INIT_STATE (fpga_init_state())
47
wdenkc6097192002-11-03 00:24:07 +000048/* fpga configuration data - generated by bin2cc */
49const unsigned char fpgadata[] =
50{
51#include "fpgadata.c"
52};
53
54/*
55 * include common fpga code (for esd boards)
56 */
57#include "../common/fpga.c"
58
Matthias Fuchs9b985c32008-11-24 15:11:09 +010059#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)
wdenkc6097192002-11-03 00:24:07 +000061
Matthias Fuchs9b985c32008-11-24 15:11:09 +010062#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)
stroesea530a9a2004-12-16 18:38:22 +000064
65
66int board_revision(void)
67{
Stefan Roese918010a2009-09-09 16:25:29 +020068 unsigned long CPC0_CR0Reg;
stroesea530a9a2004-12-16 18:38:22 +000069 unsigned long value;
70
71 /*
72 * Get version of PCI405 board from GPIO's
73 */
74
75 /*
76 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
77 */
Stefan Roese918010a2009-09-09 16:25:29 +020078 CPC0_CR0Reg = mfdcr(CPC0_CR0);
79 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
Matthias Fuchs9b985c32008-11-24 15:11:09 +010080 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00100200);
81 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00100200);
stroesea530a9a2004-12-16 18:38:22 +000082 udelay(1000); /* wait some time before reading input */
Matthias Fuchs9b985c32008-11-24 15:11:09 +010083 value = in_be32((void*)GPIO0_IR) & 0x00100200; /* get config bits */
stroesea530a9a2004-12-16 18:38:22 +000084
85 /*
86 * Restore GPIO settings
87 */
Stefan Roese918010a2009-09-09 16:25:29 +020088 mtdcr(CPC0_CR0, CPC0_CR0Reg);
stroesea530a9a2004-12-16 18:38:22 +000089
90 switch (value) {
Stefan Roese1e8519f2005-08-12 16:56:56 +020091 case 0x00100200:
92 /* CS2==1 && IRQ5==1 -> version 1.0 and 1.1 */
stroesea530a9a2004-12-16 18:38:22 +000093 return 1;
Stefan Roese1e8519f2005-08-12 16:56:56 +020094 case 0x00000200:
95 /* CS2==0 && IRQ5==1 -> version 1.2 */
stroesea530a9a2004-12-16 18:38:22 +000096 return 2;
Stefan Roese1e8519f2005-08-12 16:56:56 +020097 case 0x00000000:
98 /* CS2==0 && IRQ5==0 -> version 1.3 */
99 return 3;
stroesea530a9a2004-12-16 18:38:22 +0000100#if 0 /* not yet manufactured ! */
101 case 0x00100000:
Stefan Roese1e8519f2005-08-12 16:56:56 +0200102 /* CS2==1 && IRQ5==0 -> version 1.4 */
stroesea530a9a2004-12-16 18:38:22 +0000103 return 4;
104#endif
105 default:
106 /* should not be reached! */
107 return 0;
108 }
109}
110
111
112unsigned long fpga_done_state(void)
113{
stroesea530a9a2004-12-16 18:38:22 +0000114 if (gd->board_type < 2) {
115 return FPGA_DONE_STATE_V11;
116 } else {
117 return FPGA_DONE_STATE_V12;
118 }
119}
wdenkc6097192002-11-03 00:24:07 +0000120
121
stroesea530a9a2004-12-16 18:38:22 +0000122unsigned long fpga_init_state(void)
123{
stroesea530a9a2004-12-16 18:38:22 +0000124 if (gd->board_type < 2) {
125 return FPGA_INIT_STATE_V11;
126 } else {
127 return FPGA_INIT_STATE_V12;
128 }
129}
130
131
wdenkda55c6e2004-01-20 23:12:12 +0000132int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +0000133{
Stefan Roese918010a2009-09-09 16:25:29 +0200134 unsigned long CPC0_CR0Reg;
wdenkc6097192002-11-03 00:24:07 +0000135
136 /*
stroesea530a9a2004-12-16 18:38:22 +0000137 * First pull fpga-prg pin low, to disable fpga logic (on version 1.2 board)
138 */
Matthias Fuchs9b985c32008-11-24 15:11:09 +0100139 out_be32((void*)GPIO0_ODR, 0x00000000); /* no open drain pins */
140 out_be32((void*)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */
141 out_be32((void*)GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */
142 out_be32((void*)GPIO0_OR, 0); /* pull prg low */
stroesea530a9a2004-12-16 18:38:22 +0000143
144 /*
wdenkc6097192002-11-03 00:24:07 +0000145 * IRQ 0-15 405GP internally generated; active high; level sensitive
146 * IRQ 16 405GP internally generated; active low; level sensitive
147 * IRQ 17-24 RESERVED
148 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
149 * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
150 * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
151 * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
152 * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
153 * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
154 * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
155 */
Stefan Roese707fd362009-09-24 09:55:50 +0200156 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
157 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
158 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
159 mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
160 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
161 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
162 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +0000163
164 /*
165 * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
166 */
Stefan Roese918010a2009-09-09 16:25:29 +0200167 CPC0_CR0Reg = mfdcr(CPC0_CR0);
168 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00008000);
wdenkc6097192002-11-03 00:24:07 +0000169
stroese6bbfa9f2003-05-23 11:33:57 +0000170 /*
stroesea530a9a2004-12-16 18:38:22 +0000171 * Setup GPIO pins (CS6+CS7 as GPIO)
172 */
Stefan Roese918010a2009-09-09 16:25:29 +0200173 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
stroesea530a9a2004-12-16 18:38:22 +0000174
175 /*
stroese6bbfa9f2003-05-23 11:33:57 +0000176 * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
177 */
Stefan Roese918010a2009-09-09 16:25:29 +0200178 mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
stroese6bbfa9f2003-05-23 11:33:57 +0000179
wdenkc6097192002-11-03 00:24:07 +0000180 return 0;
181}
182
wdenkc6097192002-11-03 00:24:07 +0000183int misc_init_r (void)
184{
185 unsigned char *dst;
186 ulong len = sizeof(fpgadata);
187 int status;
188 int index;
189 int i;
stroese65f36a72003-03-25 14:41:35 +0000190 unsigned int *ptr;
191 unsigned int *magic;
wdenkc6097192002-11-03 00:24:07 +0000192
193 /*
194 * On PCI-405 the environment is saved in eeprom!
195 * FPGA can be gzip compressed (malloc) and booted this late.
196 */
197
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200198 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
199 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
wdenkc6097192002-11-03 00:24:07 +0000200 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 /* display infos on fpgaimage */
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 /* delayed reboot */
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 /* display infos on fpgaimage */
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 /*
stroese65f36a72003-03-25 14:41:35 +0000249 * Reset FPGA via FPGA_DATA pin
wdenkc6097192002-11-03 00:24:07 +0000250 */
stroese65f36a72003-03-25 14:41:35 +0000251 SET_FPGA(FPGA_PRG | FPGA_CLK);
252 udelay(1000); /* wait 1ms */
253 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
254 udelay(1000); /* wait 1ms */
wdenkc6097192002-11-03 00:24:07 +0000255
stroese65f36a72003-03-25 14:41:35 +0000256 /*
257 * Check if magic for pci reconfig is written
258 */
259 magic = (unsigned int *)0x00000004;
260 if (*magic == PCI_RECONFIG_MAGIC) {
261 /*
262 * Rewrite pci config regs (only after soft-reset with magic set)
263 */
264 ptr = (unsigned int *)PCI_REGS_ADDR;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200265 if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
stroese65f36a72003-03-25 14:41:35 +0000266 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 }
Stefan Roese707fd362009-09-24 09:55:50 +0200272 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
stroese6bbfa9f2003-05-23 11:33:57 +0000273
stroese65f36a72003-03-25 14:41:35 +0000274 *magic = 0; /* clear pci reconfig magic again */
275 }
wdenkc6097192002-11-03 00:24:07 +0000276
stroesea530a9a2004-12-16 18:38:22 +0000277 /*
278 * Decrease PLB latency timeout and reduce priority of the PCI bridge master
279 */
280#define PCI0_BRDGOPT1 0x4a
281 pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
stroesea530a9a2004-12-16 18:38:22 +0000282
stroesea530a9a2004-12-16 18:38:22 +0000283 /*
284 * Enable fairness and high bus utilization
285 */
Stefan Roese918010a2009-09-09 16:25:29 +0200286 mtdcr(PLB0_ACR, 0x98000000);
stroesea530a9a2004-12-16 18:38:22 +0000287
wdenkc6097192002-11-03 00:24:07 +0000288 free(dst);
289 return (0);
290}
291
292
293/*
294 * Check Board Identity:
295 */
wdenkc6097192002-11-03 00:24:07 +0000296int checkboard (void)
297{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200298 char str[64];
Wolfgang Denk76af2782010-07-24 21:55:43 +0200299 int i = getenv_f("serial#", str, sizeof(str));
wdenkc6097192002-11-03 00:24:07 +0000300
301 puts ("Board: ");
302
303 if (i == -1) {
stroese65f36a72003-03-25 14:41:35 +0000304 puts ("### No HW ID - assuming PCI405");
wdenkc6097192002-11-03 00:24:07 +0000305 } else {
306 puts (str);
307 }
stroesea530a9a2004-12-16 18:38:22 +0000308
309 gd->board_type = board_revision();
310 printf(" (Rev 1.%ld", gd->board_type);
311
312 if (gd->board_type >= 2) {
Stefan Roese918010a2009-09-09 16:25:29 +0200313 unsigned long CPC0_CR0Reg;
stroesea530a9a2004-12-16 18:38:22 +0000314 unsigned long value;
315
316 /*
317 * Setup GPIO pins (Trace/GPIO1 to GPIO)
318 */
Stefan Roese918010a2009-09-09 16:25:29 +0200319 CPC0_CR0Reg = mfdcr(CPC0_CR0);
320 mtdcr(CPC0_CR0, CPC0_CR0Reg & ~0x08000000);
Matthias Fuchs9b985c32008-11-24 15:11:09 +0100321 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x40000000);
322 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x40000000);
stroesea530a9a2004-12-16 18:38:22 +0000323 udelay(1000); /* wait some time before reading input */
Matthias Fuchs9b985c32008-11-24 15:11:09 +0100324 value = in_be32((void*)GPIO0_IR) & 0x40000000; /* get config bits */
stroesea530a9a2004-12-16 18:38:22 +0000325 if (value) {
326 puts(", 33 MHz PCI");
327 } else {
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200328 puts(", 66 MHz PCI");
stroesea530a9a2004-12-16 18:38:22 +0000329 }
330 }
331
332 puts(")\n");
wdenkc6097192002-11-03 00:24:07 +0000333
334 return 0;
335}
336
337/* ------------------------------------------------------------------------- */
Matthias Fuchs5dde4e22009-02-20 10:19:19 +0100338#define UART1_MCR 0xef600404
Stefan Roese1e8519f2005-08-12 16:56:56 +0200339int wpeeprom(int wp)
340{
341 int wp_state = wp;
Stefan Roese1e8519f2005-08-12 16:56:56 +0200342
343 if (wp == 1) {
Matthias Fuchs5dde4e22009-02-20 10:19:19 +0100344 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) & ~0x02);
Stefan Roese1e8519f2005-08-12 16:56:56 +0200345 } else if (wp == 0) {
Matthias Fuchs5dde4e22009-02-20 10:19:19 +0100346 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) | 0x02);
Stefan Roese1e8519f2005-08-12 16:56:56 +0200347 } else {
Matthias Fuchs5dde4e22009-02-20 10:19:19 +0100348 if (in_8((void *)UART1_MCR) & 0x02) {
Stefan Roese1e8519f2005-08-12 16:56:56 +0200349 wp_state = 0;
350 } else {
351 wp_state = 1;
352 }
353 }
354 return wp_state;
355}
356
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200357int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese1e8519f2005-08-12 16:56:56 +0200358{
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,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600375 "Check/Enable/Disable I2C EEPROM write protection",
Stefan Roese1e8519f2005-08-12 16:56:56 +0200376 "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"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200381 " - disable I2C EEPROM write protection"
382);