Patch by Andrea Marson, 11 Jun 2004:
[platform/kernel/u-boot.git] / board / dave / PPChameleonEVB / PPChameleonEVB.c
1 /*
2  * (C) Copyright 2003
3  * DAVE Srl
4  * http://www.dave-tech.it
5  * http://www.wawnet.biz
6  * mailto:info@wawnet.biz
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 #include <common.h>
28 #include <asm/processor.h>
29 #include <command.h>
30 #include <malloc.h>
31
32
33 /* ------------------------------------------------------------------------- */
34
35
36
37 /* Prototypes */
38 int gunzip(void *, int, unsigned char *, int *);
39
40
41 int board_early_init_f (void)
42 {
43         out32(GPIO0_OR, CFG_NAND0_CE);                 /* set initial outputs     */
44         out32(GPIO0_OR, CFG_NAND1_CE);                 /* set initial outputs     */
45
46         /*
47          * IRQ 0-15  405GP internally generated; active high; level sensitive
48          * IRQ 16    405GP internally generated; active low; level sensitive
49          * IRQ 17-24 RESERVED
50          * IRQ 25 (EXT IRQ 0)
51          * IRQ 26 (EXT IRQ 1)
52          * IRQ 27 (EXT IRQ 2)
53          * IRQ 28 (EXT IRQ 3)
54          * IRQ 29 (EXT IRQ 4)
55          * IRQ 30 (EXT IRQ 5)
56          * IRQ 31 (EXT IRQ 6)
57          */
58         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
59         mtdcr(uicer, 0x00000000);       /* disable all ints */
60         mtdcr(uiccr, 0x00000000);       /* set all to be non-critical*/
61         mtdcr(uicpr, 0xFFFFFF80);       /* set int polarities */
62         mtdcr(uictr, 0x10000000);       /* set int trigger levels */
63         mtdcr(uicvcr, 0x00000001);      /* set vect base=0,INT0 highest priority*/
64         mtdcr(uicsr, 0xFFFFFFFF);       /* clear all ints */
65
66         /*
67          * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
68          */
69 #if 1 /* test-only */
70         mtebc (epcr, 0xa8400000); /* ebc always driven */
71 #else
72         mtebc (epcr, 0x28400000); /* ebc in high-z */
73 #endif
74
75         return 0;
76 }
77
78
79 /* ------------------------------------------------------------------------- */
80
81 int misc_init_f (void)
82 {
83         return 0;  /* dummy implementation */
84 }
85
86 extern flash_info_t flash_info[];       /* info for FLASH chips */
87
88 int misc_init_r (void)
89 {
90         DECLARE_GLOBAL_DATA_PTR;
91
92         /* adjust flash start and size as well as the offset */
93         gd->bd->bi_flashstart = 0 - flash_info[0].size;
94         gd->bd->bi_flashoffset= flash_info[0].size - CFG_MONITOR_LEN;
95 #if 0
96         volatile unsigned short *fpga_mode =
97                 (unsigned short *)((ulong)CFG_FPGA_BASE_ADDR + CFG_FPGA_CTRL);
98         volatile unsigned char *duart0_mcr =
99                 (unsigned char *)((ulong)DUART0_BA + 4);
100         volatile unsigned char *duart1_mcr =
101                 (unsigned char *)((ulong)DUART1_BA + 4);
102
103         bd_t *bd = gd->bd;
104         char *  tmp;                    /* Temporary char pointer      */
105         unsigned char *dst;
106         ulong len = sizeof(fpgadata);
107         int status;
108         int index;
109         int i;
110         unsigned long cntrl0Reg;
111
112         dst = malloc(CFG_FPGA_MAX_SIZE);
113         if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
114                 printf ("GUNZIP ERROR - must RESET board to recover\n");
115                 do_reset (NULL, 0, 0, NULL);
116         }
117
118         status = fpga_boot(dst, len);
119         if (status != 0) {
120                 printf("\nFPGA: Booting failed ");
121                 switch (status) {
122                 case ERROR_FPGA_PRG_INIT_LOW:
123                         printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
124                         break;
125                 case ERROR_FPGA_PRG_INIT_HIGH:
126                         printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
127                         break;
128                 case ERROR_FPGA_PRG_DONE:
129                         printf("(Timeout: DONE not high after programming FPGA)\n ");
130                         break;
131                 }
132
133                 /* display infos on fpgaimage */
134                 index = 15;
135                 for (i=0; i<4; i++) {
136                         len = dst[index];
137                         printf("FPGA: %s\n", &(dst[index+1]));
138                         index += len+3;
139                 }
140                 putc ('\n');
141                 /* delayed reboot */
142                 for (i=20; i>0; i--) {
143                         printf("Rebooting in %2d seconds \r",i);
144                         for (index=0;index<1000;index++)
145                                 udelay(1000);
146                 }
147                 putc ('\n');
148                 do_reset(NULL, 0, 0, NULL);
149         }
150
151         puts("FPGA:  ");
152
153         /* display infos on fpgaimage */
154         index = 15;
155         for (i=0; i<4; i++) {
156                 len = dst[index];
157                 printf("%s ", &(dst[index+1]));
158                 index += len+3;
159         }
160         putc ('\n');
161
162         free(dst);
163
164         /*
165          * Reset FPGA via FPGA_DATA pin
166          */
167         SET_FPGA(FPGA_PRG | FPGA_CLK);
168         udelay(1000); /* wait 1ms */
169         SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
170         udelay(1000); /* wait 1ms */
171
172 #endif
173
174 #if 0
175         /*
176          * Enable power on PS/2 interface
177          */
178         *fpga_mode |= CFG_FPGA_CTRL_PS2_RESET;
179
180         /*
181          * Enable interrupts in exar duart mcr[3]
182          */
183         *duart0_mcr = 0x08;
184         *duart1_mcr = 0x08;
185 #endif
186         return (0);
187 }
188
189
190 /*
191  * Check Board Identity:
192  */
193
194 int checkboard (void)
195 {
196         unsigned char str[64];
197         int i = getenv_r ("serial#", str, sizeof(str));
198
199         puts ("Board: ");
200
201         if (i == -1) {
202                 puts ("### No HW ID - assuming PPChameleonEVB");
203         } else {
204                 puts(str);
205         }
206
207         putc ('\n');
208
209         return 0;
210 }
211
212 /* ------------------------------------------------------------------------- */
213
214 long int initdram (int board_type)
215 {
216         unsigned long val;
217
218         mtdcr(memcfga, mem_mb0cf);
219         val = mfdcr(memcfgd);
220
221 #if 0 /* test-only */
222         for (;;) {
223                 NAND_DISABLE_CE(1);
224                 udelay(100);
225                 NAND_ENABLE_CE(1);
226                 udelay(100);
227         }
228 #endif
229 #if 0
230         printf("\nmb0cf=%x\n", val); /* test-only */
231         printf("strap=%x\n", mfdcr(strap)); /* test-only */
232 #endif
233
234         return (4*1024*1024 << ((val & 0x000e0000) >> 17));
235 }
236
237 /* ------------------------------------------------------------------------- */
238
239 int testdram (void)
240 {
241         /* TODO: XXX XXX XXX */
242         printf ("test: 16 MB - ok\n");
243
244         return (0);
245 }
246
247 /* ------------------------------------------------------------------------- */
248
249 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
250 extern ulong
251 nand_probe(ulong physadr);
252
253 void
254 nand_init(void)
255 {
256         ulong totlen = 0;
257
258 /*
259         The HI model is equipped with a large block NAND chip not supported yet
260         by U-Boot
261     (CONFIG_PPCHAMELEON_MODULE_MODEL == CONFIG_PPCHAMELEON_MODULE_HI)
262 */
263
264 #if (CONFIG_PPCHAMELEON_MODULE_MODEL == CONFIG_PPCHAMELEON_MODULE_ME)
265         debug ("Probing at 0x%.8x\n", CFG_NAND0_BASE);
266         totlen += nand_probe (CFG_NAND0_BASE);
267 #endif  /* CONFIG_PPCHAMELEON_MODULE_ME, CONFIG_PPCHAMELEON_MODULE_HI */
268
269         debug ("Probing at 0x%.8x\n", CFG_NAND1_BASE);
270         totlen += nand_probe (CFG_NAND1_BASE);
271
272         printf ("%4lu MB\n", totlen >>20);
273 }
274 #endif
275
276 #ifdef CONFIG_CFB_CONSOLE
277 # ifdef CONFIG_CONSOLE_EXTRA_INFO
278 # include <video_fb.h>
279 extern GraphicDevice smi;
280
281 void video_get_info_str (int line_number, char *info)
282 {
283         uint pvr = get_pvr ();
284
285         /* init video info strings for graphic console */
286         switch (line_number) {
287         case 1:
288                 switch (pvr) {
289                 case PVR_405EP_RB:
290                         sprintf (info, " IBM PowerPC 405EP Rev. B");
291                         break;
292                 default:
293                         sprintf (info, " IBM PowerPC 405EP Rev. <unknown>");
294                         break;
295                 }
296                 return;
297         case 2:
298                 sprintf (info, " DAVE Srl PPChameleonEVB - www.dave-tech.it");
299                 return;
300         case 3:
301                 sprintf (info, " %s", smi.modeIdent);
302                 return;
303         }
304
305         /* no more info lines */
306         *info = 0;
307         return;
308 }
309 # endif /* CONFIG_CONSOLE_EXTRA_INFO */
310 #endif  /* CONFIG_CFB_CONSOLE */