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