Local Bus Timeout increased.
[platform/kernel/u-boot.git] / board / esd / pci405 / pci405.c
1 /*
2  * (C) Copyright 2001
3  * 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>
27 #include <cmd_boot.h>
28 #include <malloc.h>
29 #include <pci.h>
30 #include <405gp_pci.h>
31
32 #include "pci405.h"
33
34
35 /* ------------------------------------------------------------------------- */
36
37 #if 0
38 #define FPGA_DEBUG
39 #endif
40
41 /* fpga configuration data - generated by bin2cc */
42 const unsigned char fpgadata[] =
43 {
44 #include "fpgadata.c"
45 };
46
47 /*
48  * include common fpga code (for esd boards)
49  */
50 #include "../common/fpga.c"
51
52
53 /* Prototypes */
54 int gunzip(void *, int, unsigned char *, int *);
55
56
57 int board_pre_init (void)
58 {
59         unsigned long cntrl0Reg;
60
61         /*
62          * IRQ 0-15  405GP internally generated; active high; level sensitive
63          * IRQ 16    405GP internally generated; active low; level sensitive
64          * IRQ 17-24 RESERVED
65          * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
66          * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
67          * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
68          * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
69          * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
70          * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
71          * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
72          */
73         mtdcr(uicsr, 0xFFFFFFFF);        /* clear all ints */
74         mtdcr(uicer, 0x00000000);        /* disable all ints */
75         mtdcr(uiccr, 0x00000000);        /* set all to be non-critical*/
76         mtdcr(uicpr, 0xFFFFFF80);        /* set int polarities */
77         mtdcr(uictr, 0x10000000);        /* set int trigger levels */
78         mtdcr(uicvcr, 0x00000001);       /* set vect base=0,INT0 highest priority*/
79         mtdcr(uicsr, 0xFFFFFFFF);        /* clear all ints */
80
81         /*
82          * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
83          */
84         cntrl0Reg = mfdcr(cntrl0);
85         mtdcr(cntrl0, cntrl0Reg | 0x00008000);
86
87         /*
88          * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
89          */
90         mtebc (epcr, 0xa8400000); /* ebc always driven */
91
92         return 0;
93 }
94
95
96 /* ------------------------------------------------------------------------- */
97
98 int misc_init_f (void)
99 {
100         return 0;  /* dummy implementation */
101 }
102
103
104 int misc_init_r (void)
105 {
106         unsigned char *dst;
107         ulong len = sizeof(fpgadata);
108         int status;
109         int index;
110         int i;
111         unsigned int *ptr;
112         unsigned int *magic;
113
114         /*
115          * On PCI-405 the environment is saved in eeprom!
116          * FPGA can be gzip compressed (malloc) and booted this late.
117          */
118
119         dst = malloc(CFG_FPGA_MAX_SIZE);
120         if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
121                 printf ("GUNZIP ERROR - must RESET board to recover\n");
122                 do_reset (NULL, 0, 0, NULL);
123         }
124
125         status = fpga_boot(dst, len);
126         if (status != 0) {
127                 printf("\nFPGA: Booting failed ");
128                 switch (status) {
129                 case ERROR_FPGA_PRG_INIT_LOW:
130                         printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
131                         break;
132                 case ERROR_FPGA_PRG_INIT_HIGH:
133                         printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
134                         break;
135                 case ERROR_FPGA_PRG_DONE:
136                         printf("(Timeout: DONE not high after programming FPGA)\n ");
137                         break;
138                 }
139
140                 /* display infos on fpgaimage */
141                 index = 15;
142                 for (i=0; i<4; i++) {
143                         len = dst[index];
144                         printf("FPGA: %s\n", &(dst[index+1]));
145                         index += len+3;
146                 }
147                 putc ('\n');
148                 /* delayed reboot */
149                 for (i=20; i>0; i--) {
150                         printf("Rebooting in %2d seconds \r",i);
151                         for (index=0;index<1000;index++)
152                                 udelay(1000);
153                 }
154                 putc ('\n');
155                 do_reset(NULL, 0, 0, NULL);
156         }
157
158         puts("FPGA:  ");
159
160         /* display infos on fpgaimage */
161         index = 15;
162         for (i=0; i<4; i++) {
163                 len = dst[index];
164                 printf("%s ", &(dst[index+1]));
165                 index += len+3;
166         }
167         putc ('\n');
168
169         /*
170          * Reset FPGA via FPGA_DATA pin
171          */
172         SET_FPGA(FPGA_PRG | FPGA_CLK);
173         udelay(1000); /* wait 1ms */
174         SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
175         udelay(1000); /* wait 1ms */
176
177         /*
178          * Check if magic for pci reconfig is written
179          */
180         magic = (unsigned int *)0x00000004;
181         if (*magic == PCI_RECONFIG_MAGIC) {
182                 /*
183                  * Rewrite pci config regs (only after soft-reset with magic set)
184                  */
185                 ptr = (unsigned int *)PCI_REGS_ADDR;
186                 if (crc32(0, (char *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
187                         puts("Restoring PCI Configurations Regs!\n");
188                         ptr = (unsigned int *)PCI_REGS_ADDR + 1;
189                         for (i=0; i<0x40; i+=4) {
190                                 pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
191                         }
192                 }
193                 mtdcr(uicsr, 0xFFFFFFFF);        /* clear all ints */
194
195                 *magic = 0;      /* clear pci reconfig magic again */
196         }
197
198         free(dst);
199         return (0);
200 }
201
202
203 /*
204  * Check Board Identity:
205  */
206
207 int checkboard (void)
208 {
209         unsigned char str[64];
210         int i = getenv_r ("serial#", str, sizeof(str));
211
212         puts ("Board: ");
213
214         if (i == -1) {
215                 puts ("### No HW ID - assuming PCI405");
216         } else {
217                 puts (str);
218         }
219         putc ('\n');
220
221         return 0;
222 }
223
224 /* ------------------------------------------------------------------------- */
225
226 long int initdram (int board_type)
227 {
228         unsigned long val;
229
230         mtdcr(memcfga, mem_mb0cf);
231         val = mfdcr(memcfgd);
232
233 #if 0
234         printf("\nmb0cf=%x\n", val); /* test-only */
235         printf("strap=%x\n", mfdcr(strap)); /* test-only */
236 #endif
237
238 #if 0 /* test-only: all PCI405 version must report 16mb */
239         return (4*1024*1024 << ((val & 0x000e0000) >> 17));
240 #else
241         return (16*1024*1024);
242 #endif
243 }
244
245 /* ------------------------------------------------------------------------- */
246
247 int testdram (void)
248 {
249         /* TODO: XXX XXX XXX */
250         printf ("test: 16 MB - ok\n");
251
252         return (0);
253 }
254
255 /* ------------------------------------------------------------------------- */