led.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/gpio.h>
  26. /* GPIO pins for the LEDs */
  27. #define BEAGLE_LED_USR0 150
  28. #define BEAGLE_LED_USR1 149
  29. #ifdef STATUS_LED_GREEN
  30. void green_led_off(void)
  31. {
  32. __led_set (STATUS_LED_GREEN, 0);
  33. }
  34. void green_led_on(void)
  35. {
  36. __led_set (STATUS_LED_GREEN, 1);
  37. }
  38. #endif
  39. void __led_init (led_id_t mask, int state)
  40. {
  41. __led_set (mask, state);
  42. }
  43. void __led_toggle (led_id_t mask)
  44. {
  45. int state, toggle_gpio = 0;
  46. #ifdef STATUS_LED_BIT
  47. if (!toggle_gpio && STATUS_LED_BIT & mask)
  48. toggle_gpio = BEAGLE_LED_USR0;
  49. #endif
  50. #ifdef STATUS_LED_BIT1
  51. if (!toggle_gpio && STATUS_LED_BIT1 & mask)
  52. toggle_gpio = BEAGLE_LED_USR1;
  53. #endif
  54. if (toggle_gpio) {
  55. if (!gpio_request(toggle_gpio, "")) {
  56. gpio_direction_output(toggle_gpio, 0);
  57. state = gpio_get_value(toggle_gpio);
  58. gpio_set_value(toggle_gpio, !state);
  59. }
  60. }
  61. }
  62. void __led_set (led_id_t mask, int state)
  63. {
  64. #ifdef STATUS_LED_BIT
  65. if (STATUS_LED_BIT & mask) {
  66. if (!gpio_request(BEAGLE_LED_USR0, "")) {
  67. gpio_direction_output(BEAGLE_LED_USR0, 0);
  68. gpio_set_value(BEAGLE_LED_USR0, state);
  69. }
  70. }
  71. #endif
  72. #ifdef STATUS_LED_BIT1
  73. if (STATUS_LED_BIT1 & mask) {
  74. if (!gpio_request(BEAGLE_LED_USR1, "")) {
  75. gpio_direction_output(BEAGLE_LED_USR1, 0);
  76. gpio_set_value(BEAGLE_LED_USR1, state);
  77. }
  78. }
  79. #endif
  80. }