leds-osk.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * linux/arch/arm/mach-omap1/leds-osk.c
  3. *
  4. * LED driver for OSK with optional Mistral QVGA board
  5. */
  6. #include <linux/gpio.h>
  7. #include <linux/init.h>
  8. #include <mach/hardware.h>
  9. #include <asm/leds.h>
  10. #include "leds.h"
  11. #define LED_STATE_ENABLED (1 << 0)
  12. #define LED_STATE_CLAIMED (1 << 1)
  13. static u8 led_state;
  14. #define TIMER_LED (1 << 3) /* Mistral board */
  15. #define IDLE_LED (1 << 4) /* Mistral board */
  16. static u8 hw_led_state;
  17. #ifdef CONFIG_OMAP_OSK_MISTRAL
  18. /* For now, all system indicators require the Mistral board, since that
  19. * LED can be manipulated without a task context. This LED is either red,
  20. * or green, but not both; it can't give the full "disco led" effect.
  21. */
  22. #define GPIO_LED_RED 3
  23. #define GPIO_LED_GREEN OMAP_MPUIO(4)
  24. static void mistral_setled(void)
  25. {
  26. int red = 0;
  27. int green = 0;
  28. if (hw_led_state & TIMER_LED)
  29. red = 1;
  30. else if (hw_led_state & IDLE_LED)
  31. green = 1;
  32. /* else both sides are disabled */
  33. gpio_set_value(GPIO_LED_GREEN, green);
  34. gpio_set_value(GPIO_LED_RED, red);
  35. }
  36. #endif
  37. void osk_leds_event(led_event_t evt)
  38. {
  39. unsigned long flags;
  40. u16 leds;
  41. local_irq_save(flags);
  42. if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
  43. goto done;
  44. leds = hw_led_state;
  45. switch (evt) {
  46. case led_start:
  47. led_state |= LED_STATE_ENABLED;
  48. hw_led_state = 0;
  49. leds = ~0;
  50. break;
  51. case led_halted:
  52. case led_stop:
  53. led_state &= ~LED_STATE_ENABLED;
  54. hw_led_state = 0;
  55. break;
  56. case led_claim:
  57. led_state |= LED_STATE_CLAIMED;
  58. hw_led_state = 0;
  59. leds = ~0;
  60. break;
  61. case led_release:
  62. led_state &= ~LED_STATE_CLAIMED;
  63. hw_led_state = 0;
  64. break;
  65. #ifdef CONFIG_OMAP_OSK_MISTRAL
  66. case led_timer:
  67. hw_led_state ^= TIMER_LED;
  68. mistral_setled();
  69. break;
  70. case led_idle_start: /* idle == off */
  71. hw_led_state &= ~IDLE_LED;
  72. mistral_setled();
  73. break;
  74. case led_idle_end:
  75. hw_led_state |= IDLE_LED;
  76. mistral_setled();
  77. break;
  78. #endif /* CONFIG_OMAP_OSK_MISTRAL */
  79. default:
  80. break;
  81. }
  82. leds ^= hw_led_state;
  83. done:
  84. local_irq_restore(flags);
  85. }