wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <malloc.h> |
| 10 | #include <net.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <pci.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 13 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 14 | #include "pn62.h" |
| 15 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 16 | #if defined(CONFIG_CMD_BSP) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 17 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 18 | /* |
| 19 | * Command led: controls the various LEDs 0..11 on the PN62 card. |
| 20 | */ |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 21 | int do_led(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 22 | { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 23 | unsigned int number, function; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 25 | 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; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | } |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 36 | U_BOOT_CMD( |
| 37 | led , 3, 1, do_led, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 38 | "set LED 0..11 on the PN62 board", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 39 | "i fun" |
| 40 | " - set 'i'th LED to function 'fun'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | ); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Command loadpci: loads a image over PCI. |
| 45 | */ |
| 46 | #define CMD_MOVE_WINDOW 0x1 |
| 47 | #define CMD_BOOT_IMAGE 0x2 |
| 48 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 49 | int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 50 | { |
| 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 Denk | e9e8bab | 2010-09-10 00:16:19 +0200 | [diff] [blame] | 68 | return cmd_usage(cmdtp); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | } |
| 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 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | return rcode; |
| 137 | } |
| 138 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 139 | U_BOOT_CMD( |
| 140 | loadpci, 2, 1, do_loadpci, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 141 | "load binary file over PCI", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 142 | "[addr]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 143 | " - load binary file over PCI to address 'addr'" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 144 | ); |
| 145 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 146 | #endif |