leds-osk.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * linux/arch/arm/mach-omap1/leds-osk.c
  3. *
  4. * LED driver for OSK, and optionally Mistral QVGA, boards
  5. */
  6. #include <linux/config.h>
  7. #include <linux/init.h>
  8. #include <linux/workqueue.h>
  9. #include <asm/hardware.h>
  10. #include <asm/leds.h>
  11. #include <asm/system.h>
  12. #include <asm/arch/gpio.h>
  13. #include <asm/arch/tps65010.h>
  14. #include "leds.h"
  15. #define LED_STATE_ENABLED (1 << 0)
  16. #define LED_STATE_CLAIMED (1 << 1)
  17. static u8 led_state;
  18. #define GREEN_LED (1 << 0) /* TPS65010 LED1 */
  19. #define AMBER_LED (1 << 1) /* TPS65010 LED2 */
  20. #define RED_LED (1 << 2) /* TPS65010 GPIO2 */
  21. #define TIMER_LED (1 << 3) /* Mistral board */
  22. #define IDLE_LED (1 << 4) /* Mistral board */
  23. static u8 hw_led_state;
  24. /* TPS65010 leds are changed using i2c -- from a task context.
  25. * Using one of these for the "idle" LED would be impractical...
  26. */
  27. #define TPS_LEDS (GREEN_LED | RED_LED | AMBER_LED)
  28. static u8 tps_leds_change;
  29. static void tps_work(void *unused)
  30. {
  31. for (;;) {
  32. u8 leds;
  33. local_irq_disable();
  34. leds = tps_leds_change;
  35. tps_leds_change = 0;
  36. local_irq_enable();
  37. if (!leds)
  38. break;
  39. /* careful: the set_led() value is on/off/blink */
  40. if (leds & GREEN_LED)
  41. tps65010_set_led(LED1, !!(hw_led_state & GREEN_LED));
  42. if (leds & AMBER_LED)
  43. tps65010_set_led(LED2, !!(hw_led_state & AMBER_LED));
  44. /* the gpio led doesn't have that issue */
  45. if (leds & RED_LED)
  46. tps65010_set_gpio_out_value(GPIO2,
  47. !(hw_led_state & RED_LED));
  48. }
  49. }
  50. static DECLARE_WORK(work, tps_work, NULL);
  51. #ifdef CONFIG_OMAP_OSK_MISTRAL
  52. /* For now, all system indicators require the Mistral board, since that
  53. * LED can be manipulated without a task context. This LED is either red,
  54. * or green, but not both; it can't give the full "disco led" effect.
  55. */
  56. #define GPIO_LED_RED 3
  57. #define GPIO_LED_GREEN OMAP_MPUIO(4)
  58. static void mistral_setled(void)
  59. {
  60. int red = 0;
  61. int green = 0;
  62. if (hw_led_state & TIMER_LED)
  63. red = 1;
  64. else if (hw_led_state & IDLE_LED)
  65. green = 1;
  66. // else both sides are disabled
  67. omap_set_gpio_dataout(GPIO_LED_GREEN, green);
  68. omap_set_gpio_dataout(GPIO_LED_RED, red);
  69. }
  70. #endif
  71. void osk_leds_event(led_event_t evt)
  72. {
  73. unsigned long flags;
  74. u16 leds;
  75. local_irq_save(flags);
  76. if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
  77. goto done;
  78. leds = hw_led_state;
  79. switch (evt) {
  80. case led_start:
  81. led_state |= LED_STATE_ENABLED;
  82. hw_led_state = 0;
  83. leds = ~0;
  84. break;
  85. case led_halted:
  86. case led_stop:
  87. led_state &= ~LED_STATE_ENABLED;
  88. hw_led_state = 0;
  89. // NOTE: work may still be pending!!
  90. break;
  91. case led_claim:
  92. led_state |= LED_STATE_CLAIMED;
  93. hw_led_state = 0;
  94. leds = ~0;
  95. break;
  96. case led_release:
  97. led_state &= ~LED_STATE_CLAIMED;
  98. hw_led_state = 0;
  99. break;
  100. #ifdef CONFIG_OMAP_OSK_MISTRAL
  101. case led_timer:
  102. hw_led_state ^= TIMER_LED;
  103. mistral_setled();
  104. break;
  105. case led_idle_start:
  106. hw_led_state |= IDLE_LED;
  107. mistral_setled();
  108. break;
  109. case led_idle_end:
  110. hw_led_state &= ~IDLE_LED;
  111. mistral_setled();
  112. break;
  113. #endif /* CONFIG_OMAP_OSK_MISTRAL */
  114. /* "green" == tps LED1 (leftmost, normally power-good)
  115. * works only with DC adapter, not on battery power!
  116. */
  117. case led_green_on:
  118. if (led_state & LED_STATE_CLAIMED)
  119. hw_led_state |= GREEN_LED;
  120. break;
  121. case led_green_off:
  122. if (led_state & LED_STATE_CLAIMED)
  123. hw_led_state &= ~GREEN_LED;
  124. break;
  125. /* "amber" == tps LED2 (middle) */
  126. case led_amber_on:
  127. if (led_state & LED_STATE_CLAIMED)
  128. hw_led_state |= AMBER_LED;
  129. break;
  130. case led_amber_off:
  131. if (led_state & LED_STATE_CLAIMED)
  132. hw_led_state &= ~AMBER_LED;
  133. break;
  134. /* "red" == LED on tps gpio3 (rightmost) */
  135. case led_red_on:
  136. if (led_state & LED_STATE_CLAIMED)
  137. hw_led_state |= RED_LED;
  138. break;
  139. case led_red_off:
  140. if (led_state & LED_STATE_CLAIMED)
  141. hw_led_state &= ~RED_LED;
  142. break;
  143. default:
  144. break;
  145. }
  146. leds ^= hw_led_state;
  147. leds &= TPS_LEDS;
  148. if (leds && (led_state & LED_STATE_CLAIMED)) {
  149. tps_leds_change |= leds;
  150. schedule_work(&work);
  151. }
  152. done:
  153. local_irq_restore(flags);
  154. }