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;
33 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
34 extern void lxt971_no_sleep(void);
36 /* ------------------------------------------------------------------------- */
42 /* fpga configuration data - generated by bin2cc */
43 const unsigned char fpgadata[] = {
47 const unsigned char fpgadata_xl30[] = {
48 #include "fpgadata_xl30.c"
52 * include common fpga code (for esd boards)
54 #include "../common/fpga.c"
57 int board_early_init_f (void)
63 /* set up serial port with default baudrate */
65 gd->baudrate = CONFIG_BAUDRATE;
73 /* first try 40er image */
75 status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata));
77 /* try xl30er image */
79 status = fpga_boot ((unsigned char *) fpgadata_xl30, sizeof (fpgadata_xl30));
81 /* booting FPGA failed */
83 /* set up serial port with default baudrate */
85 gd->baudrate = CONFIG_BAUDRATE;
89 printf ("\nFPGA: Booting failed ");
91 case ERROR_FPGA_PRG_INIT_LOW:
92 printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
94 case ERROR_FPGA_PRG_INIT_HIGH:
95 printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
97 case ERROR_FPGA_PRG_DONE:
98 printf ("(Timeout: DONE not high after programming FPGA)\n ");
102 /* display infos on fpgaimage */
104 for (i = 0; i < 4; i++) {
105 len = fpgadata[index];
106 printf ("FPGA: %s\n", &(fpgadata[index + 1]));
111 for (i = 20; i > 0; i--) {
112 printf ("Rebooting in %2d seconds \r", i);
113 for (index = 0; index < 1000; index++)
117 do_reset (NULL, 0, 0, NULL);
122 * IRQ 0-15 405GP internally generated; active high; level sensitive
123 * IRQ 16 405GP internally generated; active low; level sensitive
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
133 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
134 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
135 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
136 mtdcr (UIC0PR, 0xFFFFFF81); /* set int polarities */
137 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
138 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */
139 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
141 out_be16((void *)0xf03000ec, 0x0fff); /* enable interrupts in fpga */
147 * Check Board Identity:
149 int checkboard (void)
154 int i = getenv_f("serial#", str, sizeof (str));
155 const unsigned char *fpga;
160 puts ("### No HW ID - assuming AR405");
167 /* display infos on fpgaimage */
168 if (gd->board_type == 30) {
169 fpga = fpgadata_xl30;
174 for (i = 0; i < 4; i++) {
176 printf ("%s ", &(fpga[index + 1]));
183 * Disable sleep mode in LXT971
191 #if 1 /* test-only: some internal test routines... */
192 #define DIGEN ((void *)0xf03000b4) /* u8 */
193 #define DIGOUT ((void *)0xf03000b0) /* u16 */
194 #define DIGIN ((void *)0xf03000a0) /* u16 */
199 int do_digtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
207 puts("Usage: digtest n_start n_end (digtest 0 7)\n");
211 start = simple_strtol (argv[1], NULL, 10);
212 end = simple_strtol (argv[2], NULL, 10);
215 * Enable digital outputs
219 printf("\nStarting digital In-/Out Test from I/O %d to %d (Cntrl-C to abort)...\n",
223 * Set outputs one by one
226 for (i=start; i<=end; i++) {
227 out_be16(DIGOUT, 0x0001 << i);
228 for (k=0; k<200; k++)
231 if (in_be16(DIGIN) != (0x0001 << i)) {
232 printf("ERROR: OUT=0x%04X, IN=0x%04X\n",
233 0x0001 << i, in_be16(DIGIN));
237 /* Abort if ctrl-c was pressed */
248 digtest, 3, 1, do_digtest,
249 "Test digital in-/output",
253 #define ERROR_DELTA 256
260 int do_anatest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
268 out = (struct io *)0xf0300090;
269 in = (struct io *)0xf0300000;
271 i = simple_strtol (argv[1], NULL, 10);
274 printf("Setting Channel %d to %dV...\n", i, volt);
275 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
277 val = in_be16((void *)&(in[i*2].val));
278 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
279 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
280 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
281 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
282 ((volt * 0x7fff) / 40) + ERROR_DELTA);
285 val = in_be16((void *)&(in[i*2+1].val));
286 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
287 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
288 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
289 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
290 ((volt * 0x7fff) / 40) + ERROR_DELTA);
295 printf("Setting Channel %d to %dV...\n", i, volt);
296 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
298 val = in_be16((void *)&(in[i*2].val));
299 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
300 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
301 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
302 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
303 ((volt * 0x7fff) / 40) + ERROR_DELTA);
306 val = in_be16((void *)&(in[i*2+1].val));
307 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
308 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
309 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
310 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
311 ((volt * 0x7fff) / 40) + ERROR_DELTA);
316 printf("Setting Channel %d to %dV...\n", i, volt);
317 out_be16((void *)&(out[i].val), (volt * 0x7fff) / 10);
319 val = in_be16((void *)&(in[i*2].val));
320 printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
321 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
322 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
323 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
324 ((volt * 0x7fff) / 40) + ERROR_DELTA);
327 val = in_be16((void *)&(in[i*2+1].val));
328 printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
329 if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
330 (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
331 printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
332 ((volt * 0x7fff) / 40) + ERROR_DELTA);
336 printf("Channel %d OK!\n", i);
341 anatest, 2, 1, do_anatest,
342 "Test analog in-/output",
349 void cyclicInt(void *ptr)
351 out_be16((void *)0xf03000e8, 0x0800); /* ack int */
356 int do_inctest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
361 incin = (ulong *)0xf0300040;
366 out_be32((void *)&incin[0], 0);
367 out_be32((void *)&incin[1], 0);
368 out_be32((void *)&incin[2], 0);
369 out_be32((void *)&incin[3], 0);
371 incin = (ulong *)0xf0300050;
376 for (i=0; i<10000; i++) {
394 printf("Inc 0 = %d\n", in_be32((void *)&incin[0]));
395 printf("Inc 1 = %d\n", in_be32((void *)&incin[1]));
396 printf("Inc 2 = %d\n", in_be32((void *)&incin[2]));
397 printf("Inc 3 = %d\n", in_be32((void *)&incin[3]));
399 out_be16((void *)0xf03000e0, 0x0c80-1); /* set counter */
400 out_be16((void *)0xf03000ec,
401 in_be16((void *)0xf03000ec) | 0x0800); /* enable int */
402 irq_install_handler (30, (interrupt_handler_t *) cyclicInt, NULL);
403 printf("counter=%d\n", counter);
408 inctest, 3, 1, do_inctest,
409 "Test incremental encoder inputs",