74xx/7xx/86xx: Rename flush_data_cache to flush_dcache to match 85xx version
[platform/kernel/u-boot.git] / board / esd / ash405 / ash405.c
1 /*
2  * (C) Copyright 2001-2003
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 <asm/io.h>
27 #include <command.h>
28 #include <malloc.h>
29
30 /* ------------------------------------------------------------------------- */
31
32 #if 0
33 #define FPGA_DEBUG
34 #endif
35
36 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
37 extern void lxt971_no_sleep(void);
38
39 /* fpga configuration data - gzip compressed and generated by bin2c */
40 const unsigned char fpgadata[] =
41 {
42 #include "fpgadata.c"
43 };
44
45 /*
46  * include common fpga code (for esd boards)
47  */
48 #include "../common/fpga.c"
49
50
51 /* Prototypes */
52 int gunzip(void *, int, unsigned char *, unsigned long *);
53
54
55 int board_early_init_f (void)
56 {
57         /*
58          * IRQ 0-15  405GP internally generated; active high; level sensitive
59          * IRQ 16    405GP internally generated; active low; level sensitive
60          * IRQ 17-24 RESERVED
61          * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
62          * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
63          * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
64          * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
65          * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
66          * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
67          * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
68          */
69         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
70         mtdcr(uicer, 0x00000000);       /* disable all ints */
71         mtdcr(uiccr, 0x00000000);       /* set all to be non-critical*/
72         mtdcr(uicpr, 0xFFFFFF9F);       /* set int polarities */
73         mtdcr(uictr, 0x10000000);       /* set int trigger levels */
74         mtdcr(uicvcr, 0x00000001);      /* set vect base=0,INT0 highest priority*/
75         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
76
77         /*
78          * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
79          */
80         mtebc (epcr, 0xa8400000); /* ebc always driven */
81
82         return 0;
83 }
84
85 int misc_init_r (void)
86 {
87         volatile unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
88         volatile unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
89         volatile unsigned char *duart2_mcr = (unsigned char *)((ulong)DUART2_BA + 4);
90         volatile unsigned char *duart3_mcr = (unsigned char *)((ulong)DUART3_BA + 4);
91         unsigned char *dst;
92         ulong len = sizeof(fpgadata);
93         int status;
94         int index;
95         int i;
96
97         dst = malloc(CFG_FPGA_MAX_SIZE);
98         if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
99                 printf ("GUNZIP ERROR - must RESET board to recover\n");
100                 do_reset (NULL, 0, 0, NULL);
101         }
102
103         status = fpga_boot(dst, len);
104         if (status != 0) {
105                 printf("\nFPGA: Booting failed ");
106                 switch (status) {
107                 case ERROR_FPGA_PRG_INIT_LOW:
108                         printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
109                         break;
110                 case ERROR_FPGA_PRG_INIT_HIGH:
111                         printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
112                         break;
113                 case ERROR_FPGA_PRG_DONE:
114                         printf("(Timeout: DONE not high after programming FPGA)\n ");
115                         break;
116                 }
117
118                 /* display infos on fpgaimage */
119                 index = 15;
120                 for (i=0; i<4; i++) {
121                         len = dst[index];
122                         printf("FPGA: %s\n", &(dst[index+1]));
123                         index += len+3;
124                 }
125                 putc ('\n');
126                 /* delayed reboot */
127                 for (i=20; i>0; i--) {
128                         printf("Rebooting in %2d seconds \r",i);
129                         for (index=0;index<1000;index++)
130                                 udelay(1000);
131                 }
132                 putc ('\n');
133                 do_reset(NULL, 0, 0, NULL);
134         }
135
136         puts("FPGA:  ");
137
138         /* display infos on fpgaimage */
139         index = 15;
140         for (i=0; i<4; i++) {
141                 len = dst[index];
142                 printf("%s ", &(dst[index+1]));
143                 index += len+3;
144         }
145         putc ('\n');
146
147         free(dst);
148
149         /*
150          * Reset FPGA via FPGA_DATA pin
151          */
152         SET_FPGA(FPGA_PRG | FPGA_CLK);
153         udelay(1000); /* wait 1ms */
154         SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
155         udelay(1000); /* wait 1ms */
156
157         /*
158          * Reset external DUARTs
159          */
160         out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CFG_DUART_RST);
161         udelay(10); /* wait 10us */
162         out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CFG_DUART_RST);
163         udelay(1000); /* wait 1ms */
164
165         /*
166          * Enable interrupts in exar duart mcr[3]
167          */
168         *duart0_mcr = 0x08;
169         *duart1_mcr = 0x08;
170         *duart2_mcr = 0x08;
171         *duart3_mcr = 0x08;
172
173         return (0);
174 }
175
176
177 /*
178  * Check Board Identity:
179  */
180
181 int checkboard (void)
182 {
183         char str[64];
184         int i = getenv_r ("serial#", str, sizeof(str));
185
186         puts ("Board: ");
187
188         if (i == -1) {
189                 puts ("### No HW ID - assuming ASH405");
190         } else {
191                 puts(str);
192         }
193
194         putc ('\n');
195
196         return 0;
197 }
198
199 void reset_phy(void)
200 {
201 #ifdef CONFIG_LXT971_NO_SLEEP
202         /*
203          * Disable sleep mode in LXT971
204          */
205         lxt971_no_sleep();
206 #endif
207 }