2 * (C) Copyright 2001-2004
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 #include <asm/processor.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 extern void lxt971_no_sleep(void);
34 /* ------------------------------------------------------------------------- */
40 /* fpga configuration data - generated by bin2cc */
41 const unsigned char fpgadata[] = {
45 const unsigned char fpgadata_xl30[] = {
46 #include "fpgadata_xl30.c"
50 * include common fpga code (for esd boards)
52 #include "../common/fpga.c"
55 int board_early_init_f (void)
61 /* set up serial port with default baudrate */
63 gd->baudrate = CONFIG_BAUDRATE;
71 /* first try 40er image */
73 status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata));
75 /* try xl30er image */
77 status = fpga_boot ((unsigned char *) fpgadata_xl30, sizeof (fpgadata_xl30));
79 /* booting FPGA failed */
81 /* set up serial port with default baudrate */
83 gd->baudrate = CONFIG_BAUDRATE;
87 printf ("\nFPGA: Booting failed ");
89 case ERROR_FPGA_PRG_INIT_LOW:
90 printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
92 case ERROR_FPGA_PRG_INIT_HIGH:
93 printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
95 case ERROR_FPGA_PRG_DONE:
96 printf ("(Timeout: DONE not high after programming FPGA)\n ");
100 /* display infos on fpgaimage */
102 for (i = 0; i < 4; i++) {
103 len = fpgadata[index];
104 printf ("FPGA: %s\n", &(fpgadata[index + 1]));
109 for (i = 20; i > 0; i--) {
110 printf ("Rebooting in %2d seconds \r", i);
111 for (index = 0; index < 1000; index++)
115 do_reset (NULL, 0, 0, NULL);
120 * IRQ 0-15 405GP internally generated; active high; level sensitive
121 * IRQ 16 405GP internally generated; active low; level sensitive
123 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
124 * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
125 * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
126 * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
127 * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
128 * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
129 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
131 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
132 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
133 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
134 mtdcr (UIC0PR, 0xFFFFFF81); /* set int polarities */
135 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
136 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */
137 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
139 out_be16((void *)0xf03000ec, 0x0fff); /* enable interrupts in fpga */
145 * Check Board Identity:
147 int checkboard (void)
152 int i = getenv_f("serial#", str, sizeof (str));
153 const unsigned char *fpga;
158 puts ("### No HW ID - assuming AR405");
165 /* display infos on fpgaimage */
166 if (gd->board_type == 30) {
167 fpga = fpgadata_xl30;
172 for (i = 0; i < 4; i++) {
174 printf ("%s ", &(fpga[index + 1]));
181 * Disable sleep mode in LXT971
189 #if 1 /* test-only: some internal test routines... */
190 #define DIGEN ((void *)0xf03000b4) /* u8 */
191 #define DIGOUT ((void *)0xf03000b0) /* u16 */
192 #define DIGIN ((void *)0xf03000a0) /* u16 */
197 int do_digtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
205 puts("Usage: digtest n_start n_end (digtest 0 7)\n");
209 start = simple_strtol (argv[1], NULL, 10);
210 end = simple_strtol (argv[2], NULL, 10);
213 * Enable digital outputs
217 printf("\nStarting digital In-/Out Test from I/O %d to %d (Cntrl-C to abort)...\n",
221 * Set outputs one by one
224 for (i=start; i<=end; i++) {
225 out_be16(DIGOUT, 0x0001 << i);
226 for (k=0; k<200; k++)
229 if (in_be16(DIGIN) != (0x0001 << i)) {
230 printf("ERROR: OUT=0x%04X, IN=0x%04X\n",
231 0x0001 << i, in_be16(DIGIN));
235 /* Abort if ctrl-c was pressed */
246 digtest, 3, 1, do_digtest,
247 "Test digital in-/output",
251 #define ERROR_DELTA 256
258 int do_anatest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
266 out = (struct io *)0xf0300090;
267 in = (struct io *)0xf0300000;
269 i = simple_strtol (argv[1], NULL, 10);
272 printf("Setting Channel %d to %dV...\n", i, volt);
273 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
275 val = in_be16((void *)&(in[i*2].val));
276 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
277 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
278 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
279 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
280 ((volt * 0x7fff) / 40) + ERROR_DELTA);
283 val = in_be16((void *)&(in[i*2+1].val));
284 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
285 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
286 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
287 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
288 ((volt * 0x7fff) / 40) + ERROR_DELTA);
293 printf("Setting Channel %d to %dV...\n", i, volt);
294 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
296 val = in_be16((void *)&(in[i*2].val));
297 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
298 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
299 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
300 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
301 ((volt * 0x7fff) / 40) + ERROR_DELTA);
304 val = in_be16((void *)&(in[i*2+1].val));
305 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
306 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
307 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
308 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
309 ((volt * 0x7fff) / 40) + ERROR_DELTA);
314 printf("Setting Channel %d to %dV...\n", i, volt);
315 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
317 val = in_be16((void *)&(in[i*2].val));
318 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
319 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
320 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
321 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
322 ((volt * 0x7fff) / 40) + ERROR_DELTA);
325 val = in_be16((void *)&(in[i*2+1].val));
326 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
327 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
328 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
329 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
330 ((volt * 0x7fff) / 40) + ERROR_DELTA);
334 printf("Channel %d OK!\n", i);
339 anatest, 2, 1, do_anatest,
340 "Test analog in-/output",
347 void cyclicInt(void *ptr)
349 out_be16((void *)0xf03000e8, 0x0800); /* ack int */
354 int do_inctest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
359 incin = (ulong *)0xf0300040;
364 out_be32((void *)&incin[0], 0);
365 out_be32((void *)&incin[1], 0);
366 out_be32((void *)&incin[2], 0);
367 out_be32((void *)&incin[3], 0);
369 incin = (ulong *)0xf0300050;
374 for (i=0; i<10000; i++) {
392 printf("Inc 0 = %d\n", in_be32((void *)&incin[0]));
393 printf("Inc 1 = %d\n", in_be32((void *)&incin[1]));
394 printf("Inc 2 = %d\n", in_be32((void *)&incin[2]));
395 printf("Inc 3 = %d\n", in_be32((void *)&incin[3]));
397 out_be16((void *)0xf03000e0, 0x0c80-1); /* set counter */
398 out_be16((void *)0xf03000ec,
399 in_be16((void *)0xf03000ec) | 0x0800); /* enable int */
400 irq_install_handler (30, (interrupt_handler_t *) cyclicInt, NULL);
401 printf("counter=%d\n", counter);
406 inctest, 3, 1, do_inctest,
407 "Test incremental encoder inputs",