cmd_sled.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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
  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. #include <common.h>
  24. #include <command.h>
  25. #include <status_led.h>
  26. #if defined(CONFIG_STATUS_LED)
  27. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  28. * !!!!! Q u i c k & D i r t y H a c k !!!!!
  29. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  30. * !!!!! !!!!!
  31. * !!!!! Next type definition was coming from original !!!!!
  32. * !!!!! status LED driver drivers/status_led.c and !!!!!
  33. * !!!!! should exported for using here. !!!!!
  34. * !!!!! !!!!!
  35. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  36. typedef struct {
  37. led_id_t mask;
  38. int state;
  39. int period;
  40. int cnt;
  41. } led_dev_t;
  42. extern led_dev_t led_dev[];
  43. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  44. int do_sled (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  45. {
  46. int led_id = 0;
  47. if (argc > 1) {
  48. #ifdef STATUS_LED_BOOT
  49. if (!strcmp (argv[1], "boot")) {
  50. led_id = STATUS_LED_BOOT + 1;
  51. }
  52. #endif
  53. #ifdef STATUS_LED_RED
  54. if (!strcmp (argv[1], "red")) {
  55. led_id = STATUS_LED_RED + 1;
  56. }
  57. #endif
  58. #ifdef STATUS_LED_YELLOW
  59. if (!strcmp (argv[1], "yellow")) {
  60. led_id = STATUS_LED_YELLOW + 1;
  61. }
  62. #endif
  63. #ifdef STATUS_LED_GREEN
  64. if (!strcmp (argv[1], "green")) {
  65. led_id = STATUS_LED_GREEN + 1;
  66. }
  67. #endif
  68. }
  69. switch (argc) {
  70. case 1:
  71. #if (STATUS_LED_BITS > 3)
  72. for (; led_id < 4; led_id++)
  73. #elif (STATUS_LED_BITS > 2)
  74. for (; led_id < 3; led_id++)
  75. #elif (STATUS_LED_BITS > 1)
  76. for (; led_id < 2; led_id++)
  77. #elif (STATUS_LED_BITS > 0)
  78. for (; led_id < 1; led_id++)
  79. #else
  80. #error "*** STATUS_LED_BITS not correct defined ***"
  81. #endif
  82. {
  83. printf ("Status LED '%s' is %s\n",
  84. led_id == STATUS_LED_BOOT ? "boot"
  85. : led_id == STATUS_LED_RED ? "red"
  86. : led_id == STATUS_LED_YELLOW ? "yellow"
  87. : led_id ==
  88. STATUS_LED_GREEN ? "green" : "unknown",
  89. led_dev[led_id].state ==
  90. STATUS_LED_ON ? "on" : led_dev[led_id].
  91. state ==
  92. STATUS_LED_OFF ? "off" : led_dev[led_id].
  93. state ==
  94. STATUS_LED_BLINKING ? "blinking" : "unknown");
  95. }
  96. return 0;
  97. case 2:
  98. if (led_id) {
  99. printf ("Status LED '%s' is %s\n", argv[1],
  100. led_dev[led_id - 1].state ==
  101. STATUS_LED_ON ? "on" : led_dev[led_id -
  102. 1].state ==
  103. STATUS_LED_OFF ? "off" : led_dev[led_id -
  104. 1].state ==
  105. STATUS_LED_BLINKING ? "blinking" : "unknown");
  106. return 0;
  107. } else
  108. break;
  109. case 3:
  110. if (led_id) {
  111. if (!strcmp (argv[2], "on")) {
  112. status_led_set (led_id - 1, STATUS_LED_ON);
  113. return 0;
  114. } else if (!strcmp (argv[2], "off")) {
  115. status_led_set (led_id - 1, STATUS_LED_OFF);
  116. return 0;
  117. } else if (!strcmp (argv[2], "blink")) {
  118. status_led_set (led_id - 1,
  119. STATUS_LED_BLINKING);
  120. return 0;
  121. } else
  122. break;
  123. } else
  124. break;
  125. default:
  126. break;
  127. }
  128. printf ("Usage:\n%s\n", cmdtp->usage);
  129. return 1;
  130. }
  131. #ifdef STATUS_LED_BOOT
  132. #ifdef STATUS_LED_RED
  133. #ifdef STATUS_LED_YELLOW
  134. #ifdef STATUS_LED_GREEN
  135. #define __NAME_STR " - name: boot|red|yellow|green\n"
  136. #else
  137. #define __NAME_STR " - name: boot|red|yellow\n"
  138. #endif
  139. #else
  140. #define __NAME_STR " - name: boot|red\n"
  141. #endif
  142. #else
  143. #define __NAME_STR " - name: boot\n"
  144. #endif
  145. #else
  146. #define __NAME_STR " - name: (no such defined)\n"
  147. #endif
  148. U_BOOT_CMD (sled, 3, 0, do_sled,
  149. "sled - check and set status led\n",
  150. "sled [name [state]]\n" __NAME_STR " - state: on|off|blink\n");
  151. #endif /* CFG_CMD_BSP */
  152. #endif /* CONFIG_STATUS_LED */