wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004, Li-Pro.Net <www.li-pro.net> |
| 3 | * Stephan Linz <linz@li-pro.net> |
| 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 |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 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 <command.h> |
| 26 | #include <status_led.h> |
| 27 | |
| 28 | #if defined(CONFIG_STATUS_LED) |
| 29 | |
| 30 | /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 31 | * !!!!! Q u i c k & D i r t y H a c k !!!!! |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 32 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 33 | * !!!!! !!!!! |
| 34 | * !!!!! Next type definition was coming from original !!!!! |
Marcel Ziswiler | 7817cb2 | 2007-12-30 03:30:46 +0100 | [diff] [blame] | 35 | * !!!!! status LED driver drivers/misc/status_led.c !!!!! |
| 36 | * !!!!! and should be exported for using it here. !!!!! |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 37 | * !!!!! !!!!! |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 38 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
| 39 | |
| 40 | typedef struct { |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 41 | led_id_t mask; |
| 42 | int state; |
| 43 | int period; |
| 44 | int cnt; |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 45 | } led_dev_t; |
| 46 | |
| 47 | extern led_dev_t led_dev[]; |
| 48 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 49 | #if defined(CONFIG_CMD_BSP) |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 50 | int do_sled (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 51 | { |
| 52 | int led_id = 0; |
| 53 | |
| 54 | if (argc > 1) { |
| 55 | #ifdef STATUS_LED_BOOT |
| 56 | if (!strcmp (argv[1], "boot")) { |
| 57 | led_id = STATUS_LED_BOOT + 1; |
| 58 | } |
| 59 | #endif |
| 60 | #ifdef STATUS_LED_RED |
| 61 | if (!strcmp (argv[1], "red")) { |
| 62 | led_id = STATUS_LED_RED + 1; |
| 63 | } |
| 64 | #endif |
| 65 | #ifdef STATUS_LED_YELLOW |
| 66 | if (!strcmp (argv[1], "yellow")) { |
| 67 | led_id = STATUS_LED_YELLOW + 1; |
| 68 | } |
| 69 | #endif |
| 70 | #ifdef STATUS_LED_GREEN |
| 71 | if (!strcmp (argv[1], "green")) { |
| 72 | led_id = STATUS_LED_GREEN + 1; |
| 73 | } |
| 74 | #endif |
| 75 | } |
| 76 | |
| 77 | switch (argc) { |
| 78 | case 1: |
| 79 | #if (STATUS_LED_BITS > 3) |
| 80 | for (; led_id < 4; led_id++) |
| 81 | #elif (STATUS_LED_BITS > 2) |
| 82 | for (; led_id < 3; led_id++) |
| 83 | #elif (STATUS_LED_BITS > 1) |
| 84 | for (; led_id < 2; led_id++) |
| 85 | #elif (STATUS_LED_BITS > 0) |
| 86 | for (; led_id < 1; led_id++) |
| 87 | #else |
| 88 | #error "*** STATUS_LED_BITS not correct defined ***" |
| 89 | #endif |
| 90 | { |
| 91 | printf ("Status LED '%s' is %s\n", |
| 92 | led_id == STATUS_LED_BOOT ? "boot" |
| 93 | : led_id == STATUS_LED_RED ? "red" |
| 94 | : led_id == STATUS_LED_YELLOW ? "yellow" |
| 95 | : led_id == |
| 96 | STATUS_LED_GREEN ? "green" : "unknown", |
| 97 | led_dev[led_id].state == |
| 98 | STATUS_LED_ON ? "on" : led_dev[led_id]. |
| 99 | state == |
| 100 | STATUS_LED_OFF ? "off" : led_dev[led_id]. |
| 101 | state == |
| 102 | STATUS_LED_BLINKING ? "blinking" : "unknown"); |
| 103 | } |
| 104 | return 0; |
| 105 | case 2: |
| 106 | if (led_id) { |
| 107 | printf ("Status LED '%s' is %s\n", argv[1], |
| 108 | led_dev[led_id - 1].state == |
| 109 | STATUS_LED_ON ? "on" : led_dev[led_id - |
| 110 | 1].state == |
| 111 | STATUS_LED_OFF ? "off" : led_dev[led_id - |
| 112 | 1].state == |
| 113 | STATUS_LED_BLINKING ? "blinking" : "unknown"); |
| 114 | return 0; |
| 115 | } else |
| 116 | break; |
| 117 | case 3: |
| 118 | if (led_id) { |
| 119 | if (!strcmp (argv[2], "on")) { |
| 120 | status_led_set (led_id - 1, STATUS_LED_ON); |
| 121 | return 0; |
| 122 | } else if (!strcmp (argv[2], "off")) { |
| 123 | status_led_set (led_id - 1, STATUS_LED_OFF); |
| 124 | return 0; |
| 125 | } else if (!strcmp (argv[2], "blink")) { |
| 126 | status_led_set (led_id - 1, |
| 127 | STATUS_LED_BLINKING); |
| 128 | return 0; |
| 129 | } else |
| 130 | break; |
| 131 | } else |
| 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
Peter Tyser | 62c3ae7 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 136 | cmd_usage(cmdtp); |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | #ifdef STATUS_LED_BOOT |
| 141 | #ifdef STATUS_LED_RED |
| 142 | #ifdef STATUS_LED_YELLOW |
| 143 | #ifdef STATUS_LED_GREEN |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 144 | #define __NAME_STR " - name: boot|red|yellow|green\n" |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 145 | #else |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 146 | #define __NAME_STR " - name: boot|red|yellow\n" |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 147 | #endif |
| 148 | #else |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 149 | #define __NAME_STR " - name: boot|red\n" |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 150 | #endif |
| 151 | #else |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 152 | #define __NAME_STR " - name: boot\n" |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 153 | #endif |
| 154 | #else |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 155 | #define __NAME_STR " - name: (no such defined)\n" |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
| 158 | U_BOOT_CMD (sled, 3, 0, do_sled, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 159 | "check and set status led", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 160 | "sled [name [state]]\n" __NAME_STR " - state: on|off|blink"); |
Jon Loeliger | d39b574 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 161 | #endif |
wdenk | aaf224a | 2004-03-14 15:20:55 +0000 | [diff] [blame] | 162 | #endif /* CONFIG_STATUS_LED */ |