blob: 566f6f77793a62449d00a9b4dc32f2e7a130563a [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
stroesec2642d12004-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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
9#include <asm/processor.h>
10#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000011#include <malloc.h>
12#include <pci.h>
Stefan Roese3048bcb2007-10-03 15:01:02 +020013#include <asm/4xx_pci.h>
Matthias Fuchs0c2385c2008-11-24 15:11:09 +010014#include <asm/io.h>
wdenkc6097192002-11-03 00:24:07 +000015
stroesed69b1002003-03-25 14:41:35 +000016#include "pci405.h"
17
Wolfgang Denkd87080b2006-03-31 18:32:53 +020018DECLARE_GLOBAL_DATA_PTR;
stroesed69b1002003-03-25 14:41:35 +000019
stroesec2642d12004-12-16 18:38:22 +000020/* Prototypes */
stroesec2642d12004-12-16 18:38:22 +000021unsigned long fpga_done_state(void);
22unsigned long fpga_init_state(void);
23
wdenkc6097192002-11-03 00:24:07 +000024#if 0
25#define FPGA_DEBUG
26#endif
27
stroesec2642d12004-12-16 18:38:22 +000028/* predefine these here */
29#define FPGA_DONE_STATE (fpga_done_state())
30#define FPGA_INIT_STATE (fpga_init_state())
31
wdenkc6097192002-11-03 00:24:07 +000032/* fpga configuration data - generated by bin2cc */
33const unsigned char fpgadata[] =
34{
35#include "fpgadata.c"
36};
37
38/*
39 * include common fpga code (for esd boards)
40 */
41#include "../common/fpga.c"
42
Matthias Fuchs0c2385c2008-11-24 15:11:09 +010043#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)
wdenkc6097192002-11-03 00:24:07 +000045
Matthias Fuchs0c2385c2008-11-24 15:11:09 +010046#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)
stroesec2642d12004-12-16 18:38:22 +000048
49
50int board_revision(void)
51{
Stefan Roesed1c3b272009-09-09 16:25:29 +020052 unsigned long CPC0_CR0Reg;
stroesec2642d12004-12-16 18:38:22 +000053 unsigned long value;
54
55 /*
56 * Get version of PCI405 board from GPIO's
57 */
58
59 /*
60 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
61 */
Stefan Roesed1c3b272009-09-09 16:25:29 +020062 CPC0_CR0Reg = mfdcr(CPC0_CR0);
63 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
Matthias Fuchs0c2385c2008-11-24 15:11:09 +010064 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00100200);
65 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00100200);
stroesec2642d12004-12-16 18:38:22 +000066 udelay(1000); /* wait some time before reading input */
Matthias Fuchs0c2385c2008-11-24 15:11:09 +010067 value = in_be32((void*)GPIO0_IR) & 0x00100200; /* get config bits */
stroesec2642d12004-12-16 18:38:22 +000068
69 /*
70 * Restore GPIO settings
71 */
Stefan Roesed1c3b272009-09-09 16:25:29 +020072 mtdcr(CPC0_CR0, CPC0_CR0Reg);
stroesec2642d12004-12-16 18:38:22 +000073
74 switch (value) {
Stefan Roese5315dfa2005-08-12 16:56:56 +020075 case 0x00100200:
76 /* CS2==1 && IRQ5==1 -> version 1.0 and 1.1 */
stroesec2642d12004-12-16 18:38:22 +000077 return 1;
Stefan Roese5315dfa2005-08-12 16:56:56 +020078 case 0x00000200:
79 /* CS2==0 && IRQ5==1 -> version 1.2 */
stroesec2642d12004-12-16 18:38:22 +000080 return 2;
Stefan Roese5315dfa2005-08-12 16:56:56 +020081 case 0x00000000:
82 /* CS2==0 && IRQ5==0 -> version 1.3 */
83 return 3;
stroesec2642d12004-12-16 18:38:22 +000084#if 0 /* not yet manufactured ! */
85 case 0x00100000:
Stefan Roese5315dfa2005-08-12 16:56:56 +020086 /* CS2==1 && IRQ5==0 -> version 1.4 */
stroesec2642d12004-12-16 18:38:22 +000087 return 4;
88#endif
89 default:
90 /* should not be reached! */
91 return 0;
92 }
93}
94
95
96unsigned long fpga_done_state(void)
97{
stroesec2642d12004-12-16 18:38:22 +000098 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{
stroesec2642d12004-12-16 18:38:22 +0000108 if (gd->board_type < 2) {
109 return FPGA_INIT_STATE_V11;
110 } else {
111 return FPGA_INIT_STATE_V12;
112 }
113}
wdenkc6097192002-11-03 00:24:07 +0000114
115
wdenkc837dcb2004-01-20 23:12:12 +0000116int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +0000117{
Stefan Roesed1c3b272009-09-09 16:25:29 +0200118 unsigned long CPC0_CR0Reg;
wdenkc6097192002-11-03 00:24:07 +0000119
120 /*
stroesec2642d12004-12-16 18:38:22 +0000121 * First pull fpga-prg pin low, to disable fpga logic (on version 1.2 board)
122 */
Matthias Fuchs0c2385c2008-11-24 15:11:09 +0100123 out_be32((void*)GPIO0_ODR, 0x00000000); /* no open drain pins */
124 out_be32((void*)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */
125 out_be32((void*)GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */
126 out_be32((void*)GPIO0_OR, 0); /* pull prg low */
stroesec2642d12004-12-16 18:38:22 +0000127
128 /*
wdenkc6097192002-11-03 00:24:07 +0000129 * IRQ 0-15 405GP internally generated; active high; level sensitive
130 * IRQ 16 405GP internally generated; active low; level sensitive
131 * IRQ 17-24 RESERVED
132 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
133 * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
134 * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
135 * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
136 * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
137 * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
138 * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
139 */
Stefan Roese952e7762009-09-24 09:55:50 +0200140 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
141 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
142 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
143 mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
144 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
145 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
146 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +0000147
148 /*
149 * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
150 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200151 CPC0_CR0Reg = mfdcr(CPC0_CR0);
152 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00008000);
wdenkc6097192002-11-03 00:24:07 +0000153
stroese1545ad32003-05-23 11:33:57 +0000154 /*
stroesec2642d12004-12-16 18:38:22 +0000155 * Setup GPIO pins (CS6+CS7 as GPIO)
156 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200157 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
stroesec2642d12004-12-16 18:38:22 +0000158
159 /*
stroese1545ad32003-05-23 11:33:57 +0000160 * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
161 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200162 mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
stroese1545ad32003-05-23 11:33:57 +0000163
wdenkc6097192002-11-03 00:24:07 +0000164 return 0;
165}
166
wdenkc6097192002-11-03 00:24:07 +0000167int misc_init_r (void)
168{
169 unsigned char *dst;
170 ulong len = sizeof(fpgadata);
171 int status;
172 int index;
173 int i;
stroesed69b1002003-03-25 14:41:35 +0000174 unsigned int *ptr;
175 unsigned int *magic;
wdenkc6097192002-11-03 00:24:07 +0000176
177 /*
178 * On PCI-405 the environment is saved in eeprom!
179 * FPGA can be gzip compressed (malloc) and booted this late.
180 */
181
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200182 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
183 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
wdenkc6097192002-11-03 00:24:07 +0000184 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 /* display infos on fpgaimage */
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 /* delayed reboot */
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 /* display infos on fpgaimage */
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 /*
stroesed69b1002003-03-25 14:41:35 +0000233 * Reset FPGA via FPGA_DATA pin
wdenkc6097192002-11-03 00:24:07 +0000234 */
stroesed69b1002003-03-25 14:41:35 +0000235 SET_FPGA(FPGA_PRG | FPGA_CLK);
236 udelay(1000); /* wait 1ms */
237 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
238 udelay(1000); /* wait 1ms */
wdenkc6097192002-11-03 00:24:07 +0000239
stroesed69b1002003-03-25 14:41:35 +0000240 /*
241 * Check if magic for pci reconfig is written
242 */
243 magic = (unsigned int *)0x00000004;
244 if (*magic == PCI_RECONFIG_MAGIC) {
245 /*
246 * Rewrite pci config regs (only after soft-reset with magic set)
247 */
248 ptr = (unsigned int *)PCI_REGS_ADDR;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200249 if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
stroesed69b1002003-03-25 14:41:35 +0000250 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 }
Stefan Roese952e7762009-09-24 09:55:50 +0200256 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
stroese1545ad32003-05-23 11:33:57 +0000257
stroesed69b1002003-03-25 14:41:35 +0000258 *magic = 0; /* clear pci reconfig magic again */
259 }
wdenkc6097192002-11-03 00:24:07 +0000260
stroesec2642d12004-12-16 18:38:22 +0000261 /*
262 * Decrease PLB latency timeout and reduce priority of the PCI bridge master
263 */
264#define PCI0_BRDGOPT1 0x4a
265 pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
stroesec2642d12004-12-16 18:38:22 +0000266
stroesec2642d12004-12-16 18:38:22 +0000267 /*
268 * Enable fairness and high bus utilization
269 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200270 mtdcr(PLB0_ACR, 0x98000000);
stroesec2642d12004-12-16 18:38:22 +0000271
wdenkc6097192002-11-03 00:24:07 +0000272 free(dst);
273 return (0);
274}
275
276
277/*
278 * Check Board Identity:
279 */
wdenkc6097192002-11-03 00:24:07 +0000280int checkboard (void)
281{
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200282 char str[64];
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200283 int i = getenv_f("serial#", str, sizeof(str));
wdenkc6097192002-11-03 00:24:07 +0000284
285 puts ("Board: ");
286
287 if (i == -1) {
stroesed69b1002003-03-25 14:41:35 +0000288 puts ("### No HW ID - assuming PCI405");
wdenkc6097192002-11-03 00:24:07 +0000289 } else {
290 puts (str);
291 }
stroesec2642d12004-12-16 18:38:22 +0000292
293 gd->board_type = board_revision();
294 printf(" (Rev 1.%ld", gd->board_type);
295
296 if (gd->board_type >= 2) {
Stefan Roesed1c3b272009-09-09 16:25:29 +0200297 unsigned long CPC0_CR0Reg;
stroesec2642d12004-12-16 18:38:22 +0000298 unsigned long value;
299
300 /*
301 * Setup GPIO pins (Trace/GPIO1 to GPIO)
302 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200303 CPC0_CR0Reg = mfdcr(CPC0_CR0);
304 mtdcr(CPC0_CR0, CPC0_CR0Reg & ~0x08000000);
Matthias Fuchs0c2385c2008-11-24 15:11:09 +0100305 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x40000000);
306 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x40000000);
stroesec2642d12004-12-16 18:38:22 +0000307 udelay(1000); /* wait some time before reading input */
Matthias Fuchs0c2385c2008-11-24 15:11:09 +0100308 value = in_be32((void*)GPIO0_IR) & 0x40000000; /* get config bits */
stroesec2642d12004-12-16 18:38:22 +0000309 if (value) {
310 puts(", 33 MHz PCI");
311 } else {
Wolfgang Denk8ed44d92008-10-19 02:35:50 +0200312 puts(", 66 MHz PCI");
stroesec2642d12004-12-16 18:38:22 +0000313 }
314 }
315
316 puts(")\n");
wdenkc6097192002-11-03 00:24:07 +0000317
318 return 0;
319}
320
321/* ------------------------------------------------------------------------- */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100322#define UART1_MCR 0xef600404
Stefan Roese5315dfa2005-08-12 16:56:56 +0200323int wpeeprom(int wp)
324{
325 int wp_state = wp;
Stefan Roese5315dfa2005-08-12 16:56:56 +0200326
327 if (wp == 1) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100328 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) & ~0x02);
Stefan Roese5315dfa2005-08-12 16:56:56 +0200329 } else if (wp == 0) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100330 out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) | 0x02);
Stefan Roese5315dfa2005-08-12 16:56:56 +0200331 } else {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100332 if (in_8((void *)UART1_MCR) & 0x02) {
Stefan Roese5315dfa2005-08-12 16:56:56 +0200333 wp_state = 0;
334 } else {
335 wp_state = 1;
336 }
337 }
338 return wp_state;
339}
340
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200341int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese5315dfa2005-08-12 16:56:56 +0200342{
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,
Peter Tyser2fb26042009-01-27 18:03:12 -0600359 "Check/Enable/Disable I2C EEPROM write protection",
Stefan Roese5315dfa2005-08-12 16:56:56 +0200360 "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"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200365 " - disable I2C EEPROM write protection"
366);