blob: 14520e11a6e0f9bbdafc1ec990416a60c347e69d [file] [log] [blame]
wdenk153d5112002-08-30 11:07:04 +00001/*
stroese0191b3c2004-09-16 12:34:51 +00002 * (C) Copyright 2001-2004
wdenk153d5112002-08-30 11:07:04 +00003 * 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 "ar405.h"
26#include <asm/processor.h>
Matthias Fuchsfaac7432009-02-20 10:19:18 +010027#include <asm/io.h>
wdenk153d5112002-08-30 11:07:04 +000028#include <command.h>
wdenk153d5112002-08-30 11:07:04 +000029
Wolfgang Denk6405a152006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenk57b2d802003-06-27 21:31:46 +000032/*cmd_boot.c*/
33extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
stroese0191b3c2004-09-16 12:34:51 +000034extern void lxt971_no_sleep(void);
wdenk153d5112002-08-30 11:07:04 +000035
36/* ------------------------------------------------------------------------- */
37
38#if 0
39#define FPGA_DEBUG
40#endif
41
42/* fpga configuration data - generated by bin2cc */
43const unsigned char fpgadata[] = {
44#include "fpgadata.c"
45};
46
stroese0191b3c2004-09-16 12:34:51 +000047const unsigned char fpgadata_xl30[] = {
48#include "fpgadata_xl30.c"
49};
50
wdenk153d5112002-08-30 11:07:04 +000051/*
52 * include common fpga code (for esd boards)
53 */
54#include "../common/fpga.c"
55
56
wdenkda55c6e2004-01-20 23:12:12 +000057int board_early_init_f (void)
wdenk153d5112002-08-30 11:07:04 +000058{
wdenk153d5112002-08-30 11:07:04 +000059 int index, len, i;
60 int status;
61
62#ifdef FPGA_DEBUG
63 /* set up serial port with default baudrate */
64 (void) get_clocks ();
65 gd->baudrate = CONFIG_BAUDRATE;
66 serial_init ();
67 console_init_f ();
68#endif
69
70 /*
71 * Boot onboard FPGA
72 */
stroese0191b3c2004-09-16 12:34:51 +000073 /* first try 40er image */
74 gd->board_type = 40;
wdenk153d5112002-08-30 11:07:04 +000075 status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata));
76 if (status != 0) {
stroese0191b3c2004-09-16 12:34:51 +000077 /* try xl30er image */
78 gd->board_type = 30;
79 status = fpga_boot ((unsigned char *) fpgadata_xl30, sizeof (fpgadata_xl30));
80 if (status != 0) {
81 /* booting FPGA failed */
wdenk153d5112002-08-30 11:07:04 +000082#ifndef FPGA_DEBUG
stroese0191b3c2004-09-16 12:34:51 +000083 /* set up serial port with default baudrate */
84 (void) get_clocks ();
85 gd->baudrate = CONFIG_BAUDRATE;
86 serial_init ();
87 console_init_f ();
wdenk153d5112002-08-30 11:07:04 +000088#endif
stroese0191b3c2004-09-16 12:34:51 +000089 printf ("\nFPGA: Booting failed ");
90 switch (status) {
91 case ERROR_FPGA_PRG_INIT_LOW:
92 printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
93 break;
94 case ERROR_FPGA_PRG_INIT_HIGH:
95 printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
96 break;
97 case ERROR_FPGA_PRG_DONE:
98 printf ("(Timeout: DONE not high after programming FPGA)\n ");
99 break;
100 }
wdenk153d5112002-08-30 11:07:04 +0000101
stroese0191b3c2004-09-16 12:34:51 +0000102 /* display infos on fpgaimage */
103 index = 15;
104 for (i = 0; i < 4; i++) {
105 len = fpgadata[index];
106 printf ("FPGA: %s\n", &(fpgadata[index + 1]));
107 index += len + 3;
108 }
109 putc ('\n');
110 /* delayed reboot */
111 for (i = 20; i > 0; i--) {
112 printf ("Rebooting in %2d seconds \r", i);
113 for (index = 0; index < 1000; index++)
114 udelay (1000);
115 }
116 putc ('\n');
117 do_reset (NULL, 0, 0, NULL);
wdenk153d5112002-08-30 11:07:04 +0000118 }
wdenk153d5112002-08-30 11:07:04 +0000119 }
120
121 /*
122 * IRQ 0-15 405GP internally generated; active high; level sensitive
123 * IRQ 16 405GP internally generated; active low; level sensitive
124 * IRQ 17-24 RESERVED
125 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
126 * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
127 * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
128 * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
129 * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
130 * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
131 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
132 */
133 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
134 mtdcr (uicer, 0x00000000); /* disable all ints */
135 mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
136 mtdcr (uicpr, 0xFFFFFF81); /* set int polarities */
137 mtdcr (uictr, 0x10000000); /* set int trigger levels */
138 mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
139 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
140
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100141 out_be16((void *)0xf03000ec, 0x0fff); /* enable interrupts in fpga */
wdenk153d5112002-08-30 11:07:04 +0000142
143 return 0;
144}
145
wdenk153d5112002-08-30 11:07:04 +0000146/*
147 * Check Board Identity:
148 */
wdenk153d5112002-08-30 11:07:04 +0000149int checkboard (void)
150{
151 int index;
152 int len;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200153 char str[64];
wdenk153d5112002-08-30 11:07:04 +0000154 int i = getenv_r ("serial#", str, sizeof (str));
stroese0191b3c2004-09-16 12:34:51 +0000155 const unsigned char *fpga;
wdenk153d5112002-08-30 11:07:04 +0000156
157 puts ("Board: ");
158
stroese0191b3c2004-09-16 12:34:51 +0000159 if (i == -1) {
160 puts ("### No HW ID - assuming AR405");
161 } else {
162 puts(str);
wdenk153d5112002-08-30 11:07:04 +0000163 }
164
wdenk153d5112002-08-30 11:07:04 +0000165 puts ("\nFPGA: ");
166
167 /* display infos on fpgaimage */
stroese0191b3c2004-09-16 12:34:51 +0000168 if (gd->board_type == 30) {
169 fpga = fpgadata_xl30;
170 } else {
171 fpga = fpgadata;
172 }
wdenk153d5112002-08-30 11:07:04 +0000173 index = 15;
174 for (i = 0; i < 4; i++) {
stroese0191b3c2004-09-16 12:34:51 +0000175 len = fpga[index];
176 printf ("%s ", &(fpga[index + 1]));
wdenk153d5112002-08-30 11:07:04 +0000177 index += len + 3;
178 }
179
180 putc ('\n');
181
stroese0191b3c2004-09-16 12:34:51 +0000182 /*
183 * Disable sleep mode in LXT971
184 */
185 lxt971_no_sleep();
186
wdenk153d5112002-08-30 11:07:04 +0000187 return 0;
188}
189
stroesed1065d22004-12-16 18:30:36 +0000190
191#if 1 /* test-only: some internal test routines... */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100192#define DIGEN ((void *)0xf03000b4) /* u8 */
193#define DIGOUT ((void *)0xf03000b0) /* u16 */
194#define DIGIN ((void *)0xf03000a0) /* u16 */
195
stroesed1065d22004-12-16 18:30:36 +0000196/*
197 * Some test routines
198 */
199int do_digtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
200{
stroesed1065d22004-12-16 18:30:36 +0000201 int i;
202 int k;
203 int start;
204 int end;
205
206 if (argc != 3) {
207 puts("Usage: digtest n_start n_end (digtest 0 7)\n");
208 return 0;
209 }
210
211 start = simple_strtol (argv[1], NULL, 10);
212 end = simple_strtol (argv[2], NULL, 10);
213
214 /*
215 * Enable digital outputs
216 */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100217 out_8(DIGEN, 0x08);
stroesed1065d22004-12-16 18:30:36 +0000218
219 printf("\nStarting digital In-/Out Test from I/O %d to %d (Cntrl-C to abort)...\n",
220 start, end);
221
222 /*
223 * Set outputs one by one
224 */
225 for (;;) {
226 for (i=start; i<=end; i++) {
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100227 out_be16(DIGOUT, 0x0001 << i);
stroesed1065d22004-12-16 18:30:36 +0000228 for (k=0; k<200; k++)
229 udelay(1000);
230
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100231 if (in_be16(DIGIN) != (0x0001 << i)) {
232 printf("ERROR: OUT=0x%04X, IN=0x%04X\n",
233 0x0001 << i, in_be16(DIGIN));
stroesed1065d22004-12-16 18:30:36 +0000234 return 0;
235 }
236
237 /* Abort if ctrl-c was pressed */
238 if (ctrlc()) {
239 puts("\nAbort\n");
240 return 0;
241 }
242 }
243 }
244
245 return 0;
246}
247U_BOOT_CMD(
248 digtest, 3, 1, do_digtest,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600249 "Test digital in-/output",
stroesed1065d22004-12-16 18:30:36 +0000250 NULL
251 );
252
253
254#define ERROR_DELTA 256
255
256struct io {
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100257 short val;
stroesed1065d22004-12-16 18:30:36 +0000258 short dummy;
259};
260
261int do_anatest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
262{
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100263 short val;
stroesed1065d22004-12-16 18:30:36 +0000264 int i;
265 int volt;
266 struct io *out;
267 struct io *in;
268
269 out = (struct io *)0xf0300090;
270 in = (struct io *)0xf0300000;
271
272 i = simple_strtol (argv[1], NULL, 10);
273
274 volt = 0;
275 printf("Setting Channel %d to %dV...\n", i, volt);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100276 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
stroesed1065d22004-12-16 18:30:36 +0000277 udelay(10000);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100278 val = in_be16((void *)&(in[i*2].val));
stroesed1065d22004-12-16 18:30:36 +0000279 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
280 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
281 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
282 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
283 ((volt * 0x7fff) / 40) + ERROR_DELTA);
284 return -1;
285 }
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100286 val = in_be16((void *)&(in[i*2+1].val));
stroesed1065d22004-12-16 18:30:36 +0000287 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
288 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
289 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
290 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
291 ((volt * 0x7fff) / 40) + ERROR_DELTA);
292 return -1;
293 }
294
295 volt = 5;
296 printf("Setting Channel %d to %dV...\n", i, volt);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100297 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
stroesed1065d22004-12-16 18:30:36 +0000298 udelay(10000);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100299 val = in_be16((void *)&(in[i*2].val));
stroesed1065d22004-12-16 18:30:36 +0000300 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
301 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
302 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
303 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
304 ((volt * 0x7fff) / 40) + ERROR_DELTA);
305 return -1;
306 }
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100307 val = in_be16((void *)&(in[i*2+1].val));
stroesed1065d22004-12-16 18:30:36 +0000308 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
309 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
310 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
311 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
312 ((volt * 0x7fff) / 40) + ERROR_DELTA);
313 return -1;
314 }
315
316 volt = 10;
317 printf("Setting Channel %d to %dV...\n", i, volt);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100318 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
stroesed1065d22004-12-16 18:30:36 +0000319 udelay(10000);
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100320 val = in_be16((void *)&(in[i*2].val));
stroesed1065d22004-12-16 18:30:36 +0000321 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
322 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
323 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
324 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
325 ((volt * 0x7fff) / 40) + ERROR_DELTA);
326 return -1;
327 }
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100328 val = in_be16((void *)&(in[i*2+1].val));
stroesed1065d22004-12-16 18:30:36 +0000329 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
330 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
331 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
332 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
333 ((volt * 0x7fff) / 40) + ERROR_DELTA);
334 return -1;
335 }
336
337 printf("Channel %d OK!\n", i);
338
339 return 0;
340}
341U_BOOT_CMD(
342 anatest, 2, 1, do_anatest,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600343 "Test analog in-/output",
stroesed1065d22004-12-16 18:30:36 +0000344 NULL
345 );
346
347
348int counter = 0;
349
350void cyclicInt(void *ptr)
351{
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100352 out_be16((void *)0xf03000e8, 0x0800); /* ack int */
stroesed1065d22004-12-16 18:30:36 +0000353 counter++;
354}
355
356
357int do_inctest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
358{
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100359 ulong *incin;
stroesed1065d22004-12-16 18:30:36 +0000360 int i;
361
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100362 incin = (ulong *)0xf0300040;
stroesed1065d22004-12-16 18:30:36 +0000363
364 /*
365 * Clear inc counter
366 */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100367 out_be32((void *)&incin[0], 0);
368 out_be32((void *)&incin[1], 0);
369 out_be32((void *)&incin[2], 0);
370 out_be32((void *)&incin[3], 0);
stroesed1065d22004-12-16 18:30:36 +0000371
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100372 incin = (ulong *)0xf0300050;
stroesed1065d22004-12-16 18:30:36 +0000373
374 /*
375 * Inc a little
376 */
377 for (i=0; i<10000; i++) {
378 switch (i & 0x03) {
379 case 0:
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100380 out_8(DIGEN, 0x02);
stroesed1065d22004-12-16 18:30:36 +0000381 break;
382 case 1:
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100383 out_8(DIGEN, 0x03);
stroesed1065d22004-12-16 18:30:36 +0000384 break;
385 case 2:
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100386 out_8(DIGEN, 0x01);
stroesed1065d22004-12-16 18:30:36 +0000387 break;
388 case 3:
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100389 out_8(DIGEN, 0x00);
stroesed1065d22004-12-16 18:30:36 +0000390 break;
391 }
392 udelay(10);
393 }
394
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100395 printf("Inc 0 = %d\n", in_be32((void *)&incin[0]));
396 printf("Inc 1 = %d\n", in_be32((void *)&incin[1]));
397 printf("Inc 2 = %d\n", in_be32((void *)&incin[2]));
398 printf("Inc 3 = %d\n", in_be32((void *)&incin[3]));
stroesed1065d22004-12-16 18:30:36 +0000399
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100400 out_be16((void *)0xf03000e0, 0x0c80-1); /* set counter */
401 out_be16((void *)0xf03000ec,
402 in_be16((void *)0xf03000ec) | 0x0800); /* enable int */
stroesed1065d22004-12-16 18:30:36 +0000403 irq_install_handler (30, (interrupt_handler_t *) cyclicInt, NULL);
404 printf("counter=%d\n", counter);
405
406 return 0;
407}
408U_BOOT_CMD(
409 inctest, 3, 1, do_inctest,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600410 "Test incremental encoder inputs",
stroesed1065d22004-12-16 18:30:36 +0000411 NULL
412 );
413#endif