blob: 10d0df63a8c5b8983c9db3e2718ce77420b2cd45 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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>
wdenk8bde7f72003-06-27 21:31:46 +000029#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000030#include "pn62.h"
31
Jon Loeliger3fe00102007-07-09 18:38:39 -050032#if defined(CONFIG_CMD_BSP)
wdenkc6097192002-11-03 00:24:07 +000033
34extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
35
36/*
37 * Command led: controls the various LEDs 0..11 on the PN62 card.
38 */
39int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
40{
41 unsigned int number, function;
42
43 if (argc != 3) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060044 cmd_usage(cmdtp);
wdenkc6097192002-11-03 00:24:07 +000045 return 1;
46 }
47 number = simple_strtoul(argv[1], NULL, 10);
48 if (number > PN62_LED_MAX)
49 return 1;
50 function = simple_strtoul(argv[2], NULL, 16);
51 set_led (number, function);
52 return 0;
53}
wdenk0d498392003-07-01 21:06:45 +000054U_BOOT_CMD(
55 led , 3, 1, do_led,
Peter Tyser2fb26042009-01-27 18:03:12 -060056 "set LED 0..11 on the PN62 board",
wdenk8bde7f72003-06-27 21:31:46 +000057 "i fun\n"
58 " - set 'i'th LED to function 'fun'\n"
59);
wdenkc6097192002-11-03 00:24:07 +000060
61/*
62 * Command loadpci: loads a image over PCI.
63 */
64#define CMD_MOVE_WINDOW 0x1
65#define CMD_BOOT_IMAGE 0x2
66
67int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
68{
69 char *s;
70 ulong addr = 0, count = 0;
71 u32 off;
72 int cmd, rcode = 0;
73
74 /* pre-set load_addr */
75 if ((s = getenv("loadaddr")) != NULL) {
76 addr = simple_strtoul(s, NULL, 16);
77 }
78
79 switch (argc) {
80 case 1:
81 break;
82 case 2:
83 addr = simple_strtoul(argv[1], NULL, 16);
84 break;
85 default:
Peter Tyser62c3ae72009-01-27 18:03:10 -060086 cmd_usage(cmdtp);
wdenkc6097192002-11-03 00:24:07 +000087 return 1;
88 }
89
90 printf ("## Ready for image download ...\n");
91
92 show_startup_phase(12);
93
94 while (1) {
95 /* Alive indicator */
96 i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
97
98 /* Toggle status LEDs */
99 cmd = (count / 200) % 4; /* downscale */
100 set_led(4, cmd == 0 ? LED_1 : LED_0);
101 set_led(5, cmd == 1 ? LED_1 : LED_0);
102 set_led(6, cmd == 2 ? LED_1 : LED_0);
103 set_led(7, cmd == 3 ? LED_1 : LED_0);
104 udelay(1000);
105 count++;
106
107 cmd = i2155x_read_scrapad(BOOT_CMD);
108
109 if (cmd == BOOT_CMD_MOVE) {
110 off = i2155x_read_scrapad(BOOT_DATA);
111 off += addr;
112 i2155x_set_bar_base(3, off);
113 printf ("## BAR3 Addr moved = 0x%08x\n", off);
114 i2155x_write_scrapad(BOOT_CMD, ~cmd);
115 show_startup_phase(13);
116 }
117 else if (cmd == BOOT_CMD_BOOT) {
118 set_led(4, LED_1);
119 set_led(5, LED_1);
120 set_led(6, LED_1);
121 set_led(7, LED_1);
122
123 i2155x_write_scrapad(BOOT_CMD, ~cmd);
124 show_startup_phase(14);
125 break;
126 }
127
128 /* Abort if ctrl-c was pressed */
129 if (ctrlc()) {
130 printf("\nAbort\n");
131 return 0;
132 }
133
134 }
135
136 /* Repoint to the default shared memory */
137 i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
138
139 load_addr = addr;
140 printf ("## Start Addr = 0x%08lx\n", addr);
141
142 show_startup_phase(15);
143
144 /* Loading ok, check if we should attempt an auto-start */
145 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
146 char *local_args[2];
147 local_args[0] = argv[0];
148 local_args[1] = NULL;
149
150 printf ("Automatic boot of image at addr 0x%08lX ...\n",
151 load_addr);
152 rcode = do_bootm (cmdtp, 0, 1, local_args);
153 }
154
155#ifdef CONFIG_AUTOSCRIPT
156 if (load_addr) {
157 char *s;
158
159 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
Marian Balakowicz424c4ab2008-03-12 10:33:00 +0100160 printf ("Running autoscript at addr 0x%08lX", load_addr);
161
162 s = getenv ("autoscript_uname");
163 if (s)
164 printf (":%s ...\n", s);
165 else
166 puts (" ...\n");
167
168 rcode = autoscript (load_addr, s);
wdenkc6097192002-11-03 00:24:07 +0000169 }
170 }
171#endif
172 return rcode;
173}
174
wdenk0d498392003-07-01 21:06:45 +0000175U_BOOT_CMD(
176 loadpci, 2, 1, do_loadpci,
Peter Tyser2fb26042009-01-27 18:03:12 -0600177 "load binary file over PCI",
wdenk8bde7f72003-06-27 21:31:46 +0000178 "[addr]\n"
179 " - load binary file over PCI to address 'addr'\n"
180);
181
wdenkc6097192002-11-03 00:24:07 +0000182#endif