led.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2009 Wind River Systems, Inc.
  3. * Tom Rix <Tom.Rix@windriver.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <status_led.h>
  22. #include <asm/arch/cpu.h>
  23. #include <asm/io.h>
  24. #include <asm/arch/sys_proto.h>
  25. #include <asm/arch/gpio.h>
  26. static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
  27. /*
  28. * GPIO LEDs
  29. * 173 red
  30. * 154 blue
  31. * 61 blue2
  32. */
  33. #define ZOOM2_LED_RED 173
  34. #define ZOOM2_LED_BLUE 154
  35. #define ZOOM2_LED_BLUE2 61
  36. void red_LED_off (void)
  37. {
  38. /* red */
  39. if (!omap_request_gpio(ZOOM2_LED_RED)) {
  40. omap_set_gpio_direction(ZOOM2_LED_RED, 0);
  41. omap_set_gpio_dataout(ZOOM2_LED_RED, 0);
  42. }
  43. saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
  44. }
  45. void blue_LED_off (void)
  46. {
  47. /* blue */
  48. if (!omap_request_gpio(ZOOM2_LED_BLUE)) {
  49. omap_set_gpio_direction(ZOOM2_LED_BLUE, 0);
  50. omap_set_gpio_dataout(ZOOM2_LED_BLUE, 0);
  51. }
  52. /* blue 2 */
  53. if (!omap_request_gpio(ZOOM2_LED_BLUE2)) {
  54. omap_set_gpio_direction(ZOOM2_LED_BLUE2, 0);
  55. omap_set_gpio_dataout(ZOOM2_LED_BLUE2, 0);
  56. }
  57. saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
  58. }
  59. void red_LED_on (void)
  60. {
  61. blue_LED_off ();
  62. /* red */
  63. if (!omap_request_gpio(ZOOM2_LED_RED)) {
  64. omap_set_gpio_direction(ZOOM2_LED_RED, 0);
  65. omap_set_gpio_dataout(ZOOM2_LED_RED, 1);
  66. }
  67. saved_state[STATUS_LED_RED] = STATUS_LED_ON;
  68. }
  69. void blue_LED_on (void)
  70. {
  71. red_LED_off ();
  72. /* blue */
  73. if (!omap_request_gpio(ZOOM2_LED_BLUE)) {
  74. omap_set_gpio_direction(ZOOM2_LED_BLUE, 0);
  75. omap_set_gpio_dataout(ZOOM2_LED_BLUE, 1);
  76. }
  77. /* blue 2 */
  78. if (!omap_request_gpio(ZOOM2_LED_BLUE2)) {
  79. omap_set_gpio_direction(ZOOM2_LED_BLUE2, 0);
  80. omap_set_gpio_dataout(ZOOM2_LED_BLUE2, 1);
  81. }
  82. saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
  83. }
  84. void __led_init (led_id_t mask, int state)
  85. {
  86. __led_set (mask, state);
  87. }
  88. void __led_toggle (led_id_t mask)
  89. {
  90. if (STATUS_LED_BLUE == mask) {
  91. if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
  92. blue_LED_off ();
  93. else
  94. blue_LED_on ();
  95. } else if (STATUS_LED_RED == mask) {
  96. if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
  97. red_LED_off ();
  98. else
  99. red_LED_on ();
  100. }
  101. }
  102. void __led_set (led_id_t mask, int state)
  103. {
  104. if (STATUS_LED_BLUE == mask) {
  105. if (STATUS_LED_ON == state)
  106. blue_LED_on ();
  107. else
  108. blue_LED_off ();
  109. } else if (STATUS_LED_RED == mask) {
  110. if (STATUS_LED_ON == state)
  111. red_LED_on ();
  112. else
  113. red_LED_off ();
  114. }
  115. }