led.c 1.3 KB

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