blob: c3710ab48111e0417f4cf256de1b9f4b3f3d7cbc [file] [log] [blame]
stroese44a99e02003-05-23 11:27:18 +00001/*
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>
Matthias Fuchsc8452fa2007-07-09 10:10:06 +020026#include <asm/io.h>
stroese44a99e02003-05-23 11:27:18 +000027#include <command.h>
stroese44a99e02003-05-23 11:27:18 +000028#include <malloc.h>
29
30/* ------------------------------------------------------------------------- */
31
32#if 0
33#define FPGA_DEBUG
34#endif
35
wdenk57b2d802003-06-27 21:31:46 +000036extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Matthias Fuchsc8452fa2007-07-09 10:10:06 +020037extern void lxt971_no_sleep(void);
wdenk57b2d802003-06-27 21:31:46 +000038
stroese44a99e02003-05-23 11:27:18 +000039/* fpga configuration data - gzip compressed and generated by bin2c */
40const 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 */
wdenka0ebde52004-09-08 22:03:11 +000052int gunzip(void *, int, unsigned char *, unsigned long *);
stroese44a99e02003-05-23 11:27:18 +000053
54
wdenkda55c6e2004-01-20 23:12:12 +000055int board_early_init_f (void)
stroese44a99e02003-05-23 11:27:18 +000056{
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*/
stroese4fcb5df2003-07-11 08:20:33 +000072 mtdcr(uicpr, 0xFFFFFF9F); /* set int polarities */
stroese44a99e02003-05-23 11:27:18 +000073 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
stroese44a99e02003-05-23 11:27:18 +000085int 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);
wdenka0ebde52004-09-08 22:03:11 +000098 if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
stroese44a99e02003-05-23 11:27:18 +000099 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 */
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200160 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CFG_DUART_RST);
stroese44a99e02003-05-23 11:27:18 +0000161 udelay(10); /* wait 10us */
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200162 out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CFG_DUART_RST);
stroese44a99e02003-05-23 11:27:18 +0000163 udelay(1000); /* wait 1ms */
164
165 /*
stroese44a99e02003-05-23 11:27:18 +0000166 * 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
181int checkboard (void)
182{
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200183 char str[64];
stroese44a99e02003-05-23 11:27:18 +0000184 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
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200199void reset_phy(void)
stroese44a99e02003-05-23 11:27:18 +0000200{
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200201#ifdef CONFIG_LXT971_NO_SLEEP
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200202 /*
203 * Disable sleep mode in LXT971
204 */
205 lxt971_no_sleep();
stroese44a99e02003-05-23 11:27:18 +0000206#endif
Matthias Fuchsc8452fa2007-07-09 10:10:06 +0200207}