led.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2010 Texas Instruments, Inc.
  3. * Jason Kridner <jkridner@beagleboard.org>
  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. /* GPIO pins for the LEDs */
  28. #define BEAGLE_LED_USR0 149
  29. #define BEAGLE_LED_USR1 150
  30. #ifdef STATUS_LED_GREEN
  31. void green_LED_off (void)
  32. {
  33. __led_set (STATUS_LED_GREEN, 0);
  34. }
  35. void green_LED_on (void)
  36. {
  37. __led_set (STATUS_LED_GREEN, 1);
  38. }
  39. #endif
  40. void __led_init (led_id_t mask, int state)
  41. {
  42. __led_set (mask, state);
  43. }
  44. void __led_toggle (led_id_t mask)
  45. {
  46. #ifdef STATUS_LED_BIT
  47. if (STATUS_LED_BIT & mask) {
  48. if (STATUS_LED_ON == saved_state[0])
  49. __led_set(STATUS_LED_BIT, 0);
  50. else
  51. __led_set(STATUS_LED_BIT, 1);
  52. }
  53. #endif
  54. #ifdef STATUS_LED_BIT1
  55. if (STATUS_LED_BIT1 & mask) {
  56. if (STATUS_LED_ON == saved_state[1])
  57. __led_set(STATUS_LED_BIT1, 0);
  58. else
  59. __led_set(STATUS_LED_BIT1, 1);
  60. }
  61. #endif
  62. }
  63. void __led_set (led_id_t mask, int state)
  64. {
  65. #ifdef STATUS_LED_BIT
  66. if (STATUS_LED_BIT & mask) {
  67. if (!omap_request_gpio(BEAGLE_LED_USR0)) {
  68. omap_set_gpio_direction(BEAGLE_LED_USR0, 0);
  69. omap_set_gpio_dataout(BEAGLE_LED_USR0, state);
  70. }
  71. saved_state[0] = state;
  72. }
  73. #endif
  74. #ifdef STATUS_LED_BIT1
  75. if (STATUS_LED_BIT1 & mask) {
  76. if (!omap_request_gpio(BEAGLE_LED_USR1)) {
  77. omap_set_gpio_direction(BEAGLE_LED_USR1, 0);
  78. omap_set_gpio_dataout(BEAGLE_LED_USR1, state);
  79. }
  80. saved_state[1] = state;
  81. }
  82. #endif
  83. }