blob: a0326b40d680037f8a6faeb3244785ba71a00650 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
9#include <malloc.h>
10#include <net.h>
11#include <asm/io.h>
12#include <pci.h>
wdenk57b2d802003-06-27 21:31:46 +000013#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000014#include "pn62.h"
15
Jon Loeliger145318c2007-07-09 18:38:39 -050016#if defined(CONFIG_CMD_BSP)
wdenkc6097192002-11-03 00:24:07 +000017
wdenkc6097192002-11-03 00:24:07 +000018/*
19 * Command led: controls the various LEDs 0..11 on the PN62 card.
20 */
Wolfgang Denk3b683112010-07-17 01:06:04 +020021int do_led(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
wdenkc6097192002-11-03 00:24:07 +000022{
Wolfgang Denk3b683112010-07-17 01:06:04 +020023 unsigned int number, function;
wdenkc6097192002-11-03 00:24:07 +000024
Wolfgang Denk3b683112010-07-17 01:06:04 +020025 if (argc != 3)
26 return cmd_usage(cmdtp);
27
28 number = simple_strtoul(argv[1], NULL, 10);
29 if (number > PN62_LED_MAX)
30 return 1;
31
32 function = simple_strtoul(argv[2], NULL, 16);
33 set_led(number, function);
34 return 0;
wdenkc6097192002-11-03 00:24:07 +000035}
wdenkf287a242003-07-01 21:06:45 +000036U_BOOT_CMD(
37 led , 3, 1, do_led,
Peter Tyserdfb72b82009-01-27 18:03:12 -060038 "set LED 0..11 on the PN62 board",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020039 "i fun"
40 " - set 'i'th LED to function 'fun'"
wdenk57b2d802003-06-27 21:31:46 +000041);
wdenkc6097192002-11-03 00:24:07 +000042
43/*
44 * Command loadpci: loads a image over PCI.
45 */
46#define CMD_MOVE_WINDOW 0x1
47#define CMD_BOOT_IMAGE 0x2
48
Wolfgang Denk6262d0212010-06-28 22:00:46 +020049int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc6097192002-11-03 00:24:07 +000050{
51 char *s;
52 ulong addr = 0, count = 0;
53 u32 off;
54 int cmd, rcode = 0;
55
56 /* pre-set load_addr */
57 if ((s = getenv("loadaddr")) != NULL) {
58 addr = simple_strtoul(s, NULL, 16);
59 }
60
61 switch (argc) {
62 case 1:
63 break;
64 case 2:
65 addr = simple_strtoul(argv[1], NULL, 16);
66 break;
67 default:
Wolfgang Denke9e8bab2010-09-10 00:16:19 +020068 return cmd_usage(cmdtp);
wdenkc6097192002-11-03 00:24:07 +000069 }
70
71 printf ("## Ready for image download ...\n");
72
73 show_startup_phase(12);
74
75 while (1) {
76 /* Alive indicator */
77 i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
78
79 /* Toggle status LEDs */
80 cmd = (count / 200) % 4; /* downscale */
81 set_led(4, cmd == 0 ? LED_1 : LED_0);
82 set_led(5, cmd == 1 ? LED_1 : LED_0);
83 set_led(6, cmd == 2 ? LED_1 : LED_0);
84 set_led(7, cmd == 3 ? LED_1 : LED_0);
85 udelay(1000);
86 count++;
87
88 cmd = i2155x_read_scrapad(BOOT_CMD);
89
90 if (cmd == BOOT_CMD_MOVE) {
91 off = i2155x_read_scrapad(BOOT_DATA);
92 off += addr;
93 i2155x_set_bar_base(3, off);
94 printf ("## BAR3 Addr moved = 0x%08x\n", off);
95 i2155x_write_scrapad(BOOT_CMD, ~cmd);
96 show_startup_phase(13);
97 }
98 else if (cmd == BOOT_CMD_BOOT) {
99 set_led(4, LED_1);
100 set_led(5, LED_1);
101 set_led(6, LED_1);
102 set_led(7, LED_1);
103
104 i2155x_write_scrapad(BOOT_CMD, ~cmd);
105 show_startup_phase(14);
106 break;
107 }
108
109 /* Abort if ctrl-c was pressed */
110 if (ctrlc()) {
111 printf("\nAbort\n");
112 return 0;
113 }
114
115 }
116
117 /* Repoint to the default shared memory */
118 i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
119
120 load_addr = addr;
121 printf ("## Start Addr = 0x%08lx\n", addr);
122
123 show_startup_phase(15);
124
125 /* Loading ok, check if we should attempt an auto-start */
126 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
127 char *local_args[2];
128 local_args[0] = argv[0];
129 local_args[1] = NULL;
130
131 printf ("Automatic boot of image at addr 0x%08lX ...\n",
132 load_addr);
133 rcode = do_bootm (cmdtp, 0, 1, local_args);
134 }
135
wdenkc6097192002-11-03 00:24:07 +0000136 return rcode;
137}
138
wdenkf287a242003-07-01 21:06:45 +0000139U_BOOT_CMD(
140 loadpci, 2, 1, do_loadpci,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600141 "load binary file over PCI",
wdenk57b2d802003-06-27 21:31:46 +0000142 "[addr]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200143 " - load binary file over PCI to address 'addr'"
wdenk57b2d802003-06-27 21:31:46 +0000144);
145
wdenkc6097192002-11-03 00:24:07 +0000146#endif