Add "pcidelay" environment variable (in ms, enabled via CONFIG_PCI_BOOTDELAY).
[oweals/u-boot.git] / board / pn62 / cmd_pn62.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
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 <malloc.h>
26 #include <net.h>
27 #include <asm/io.h>
28 #include <pci.h>
29 #include <cmd_autoscript.h>
30 #include <cmd_bsp.h>
31
32 #include "pn62.h"
33
34 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
35
36 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
37
38 /*
39  * Command led: controls the various LEDs 0..11 on the PN62 card.
40  */
41 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
42 {
43     unsigned int number, function;
44
45     if (argc != 3) {
46         printf ("Usage:\n%s\n", cmdtp->usage);
47         return 1;
48     }
49     number = simple_strtoul(argv[1], NULL, 10);
50     if (number > PN62_LED_MAX)
51         return 1;
52     function = simple_strtoul(argv[2], NULL, 16);
53     set_led (number, function);
54     return 0;
55 }
56
57 /*
58  * Command loadpci: loads a image over PCI.
59  */
60 #define CMD_MOVE_WINDOW 0x1
61 #define CMD_BOOT_IMAGE  0x2
62
63 int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
64 {
65     char *s;
66     ulong addr = 0, count = 0;
67     u32 off;
68     int cmd, rcode = 0;
69
70     /* pre-set load_addr */
71     if ((s = getenv("loadaddr")) != NULL) {
72         addr = simple_strtoul(s, NULL, 16);
73     }
74
75     switch (argc) {
76     case 1:
77         break;
78     case 2:
79         addr = simple_strtoul(argv[1], NULL, 16);
80         break;
81     default:
82        printf ("Usage:\n%s\n", cmdtp->usage);
83         return 1;
84     }
85
86     printf ("## Ready for image download ...\n");
87
88     show_startup_phase(12);
89
90     while (1) {
91         /* Alive indicator */
92         i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
93
94         /* Toggle status LEDs */
95         cmd = (count / 200) % 4; /* downscale */
96         set_led(4, cmd == 0 ? LED_1 : LED_0);
97         set_led(5, cmd == 1 ? LED_1 : LED_0);
98         set_led(6, cmd == 2 ? LED_1 : LED_0);
99         set_led(7, cmd == 3 ? LED_1 : LED_0);
100         udelay(1000);
101         count++;
102
103         cmd = i2155x_read_scrapad(BOOT_CMD);
104
105         if (cmd == BOOT_CMD_MOVE) {
106             off = i2155x_read_scrapad(BOOT_DATA);
107             off += addr;
108             i2155x_set_bar_base(3, off);
109             printf ("## BAR3 Addr moved = 0x%08x\n", off);
110             i2155x_write_scrapad(BOOT_CMD, ~cmd);
111             show_startup_phase(13);
112         }
113         else if (cmd == BOOT_CMD_BOOT) {
114             set_led(4, LED_1);
115             set_led(5, LED_1);
116             set_led(6, LED_1);
117             set_led(7, LED_1);
118
119             i2155x_write_scrapad(BOOT_CMD, ~cmd);
120             show_startup_phase(14);
121             break;
122         }
123
124         /* Abort if ctrl-c was pressed */
125         if (ctrlc()) {
126             printf("\nAbort\n");
127             return 0;
128         }
129
130     }
131
132     /* Repoint to the default shared memory */
133     i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
134
135     load_addr = addr;
136     printf ("## Start Addr      = 0x%08lx\n", addr);
137
138     show_startup_phase(15);
139
140     /* Loading ok, check if we should attempt an auto-start */
141     if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
142         char *local_args[2];
143         local_args[0] = argv[0];
144         local_args[1] = NULL;
145
146         printf ("Automatic boot of image at addr 0x%08lX ...\n",
147                 load_addr);
148         rcode = do_bootm (cmdtp, 0, 1, local_args);
149     }
150
151 #ifdef CONFIG_AUTOSCRIPT
152     if (load_addr) {
153         char *s;
154
155         if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
156             printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
157             rcode = autoscript (bd, load_addr);
158         }
159     }
160 #endif
161     return rcode;
162 }
163
164 #endif