led.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2010 Texas Instruments, Inc.
  3. * Jason Kridner <jkridner@beagleboard.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <status_led.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/gpio.h>
  13. /* GPIO pins for the LEDs */
  14. #define BEAGLE_LED_USR0 150
  15. #define BEAGLE_LED_USR1 149
  16. #ifdef STATUS_LED_GREEN
  17. void green_led_off(void)
  18. {
  19. __led_set (STATUS_LED_GREEN, 0);
  20. }
  21. void green_led_on(void)
  22. {
  23. __led_set (STATUS_LED_GREEN, 1);
  24. }
  25. #endif
  26. static int get_led_gpio(led_id_t mask)
  27. {
  28. #ifdef STATUS_LED_BIT
  29. if (STATUS_LED_BIT & mask)
  30. return BEAGLE_LED_USR0;
  31. #endif
  32. #ifdef STATUS_LED_BIT1
  33. if (STATUS_LED_BIT1 & mask)
  34. return BEAGLE_LED_USR1;
  35. #endif
  36. return 0;
  37. }
  38. void __led_init (led_id_t mask, int state)
  39. {
  40. int toggle_gpio;
  41. toggle_gpio = get_led_gpio(mask);
  42. if (toggle_gpio && !gpio_request(toggle_gpio, "led"))
  43. __led_set(mask, state);
  44. }
  45. void __led_toggle (led_id_t mask)
  46. {
  47. int state, toggle_gpio;
  48. toggle_gpio = get_led_gpio(mask);
  49. if (toggle_gpio) {
  50. state = gpio_get_value(toggle_gpio);
  51. gpio_direction_output(toggle_gpio, !state);
  52. }
  53. }
  54. void __led_set (led_id_t mask, int state)
  55. {
  56. int toggle_gpio;
  57. toggle_gpio = get_led_gpio(mask);
  58. if (toggle_gpio)
  59. gpio_direction_output(toggle_gpio, state);
  60. }