2 * linux/arch/arm/mach-omap/leds-osk.c
4 * LED driver for OSK, and optionally Mistral QVGA, boards
6 #include <linux/config.h>
7 #include <linux/init.h>
8 #include <linux/workqueue.h>
10 #include <asm/hardware.h>
12 #include <asm/system.h>
14 #include <asm/arch/gpio.h>
15 #include <asm/arch/tps65010.h>
20 #define LED_STATE_ENABLED (1 << 0)
21 #define LED_STATE_CLAIMED (1 << 1)
24 #define GREEN_LED (1 << 0) /* TPS65010 LED1 */
25 #define AMBER_LED (1 << 1) /* TPS65010 LED2 */
26 #define RED_LED (1 << 2) /* TPS65010 GPIO2 */
27 #define TIMER_LED (1 << 3) /* Mistral board */
28 #define IDLE_LED (1 << 4) /* Mistral board */
29 static u8 hw_led_state
;
32 /* TPS65010 leds are changed using i2c -- from a task context.
33 * Using one of these for the "idle" LED would be impractical...
35 #define TPS_LEDS (GREEN_LED | RED_LED | AMBER_LED)
37 static u8 tps_leds_change
;
39 static void tps_work(void *unused
)
45 leds
= tps_leds_change
;
52 /* careful: the set_led() value is on/off/blink */
54 tps65010_set_led(LED1
, !!(hw_led_state
& GREEN_LED
));
56 tps65010_set_led(LED2
, !!(hw_led_state
& AMBER_LED
));
58 /* the gpio led doesn't have that issue */
60 tps65010_set_gpio_out_value(GPIO2
,
61 !(hw_led_state
& RED_LED
));
65 static DECLARE_WORK(work
, tps_work
, NULL
);
69 /* For now, all system indicators require the Mistral board, since that
70 * LED can be manipulated without a task context. This LED is either red,
71 * or green, but not both; it can't give the full "disco led" effect.
74 #define GPIO_LED_RED 3
75 #define GPIO_LED_GREEN OMAP_MPUIO(4)
77 static void mistral_setled(void)
82 if (hw_led_state
& TIMER_LED
)
84 else if (hw_led_state
& IDLE_LED
)
86 // else both sides are disabled
88 omap_set_gpio_dataout(GPIO_LED_GREEN
, green
);
89 omap_set_gpio_dataout(GPIO_LED_RED
, red
);
94 void osk_leds_event(led_event_t evt
)
99 local_irq_save(flags
);
101 if (!(led_state
& LED_STATE_ENABLED
) && evt
!= led_start
)
107 led_state
|= LED_STATE_ENABLED
;
114 led_state
&= ~LED_STATE_ENABLED
;
116 // NOTE: work may still be pending!!
120 led_state
|= LED_STATE_CLAIMED
;
126 led_state
&= ~LED_STATE_CLAIMED
;
130 #ifdef CONFIG_FB_OMAP
132 #ifdef CONFIG_LEDS_TIMER
134 hw_led_state
^= TIMER_LED
;
139 #ifdef CONFIG_LEDS_CPU
141 hw_led_state
|= IDLE_LED
;
146 hw_led_state
&= ~IDLE_LED
;
151 #endif /* CONFIG_FB_OMAP */
153 /* "green" == tps LED1 (leftmost, normally power-good)
154 * works only with DC adapter, not on battery power!
157 if (led_state
& LED_STATE_CLAIMED
)
158 hw_led_state
|= GREEN_LED
;
161 if (led_state
& LED_STATE_CLAIMED
)
162 hw_led_state
&= ~GREEN_LED
;
165 /* "amber" == tps LED2 (middle) */
167 if (led_state
& LED_STATE_CLAIMED
)
168 hw_led_state
|= AMBER_LED
;
171 if (led_state
& LED_STATE_CLAIMED
)
172 hw_led_state
&= ~AMBER_LED
;
175 /* "red" == LED on tps gpio3 (rightmost) */
177 if (led_state
& LED_STATE_CLAIMED
)
178 hw_led_state
|= RED_LED
;
181 if (led_state
& LED_STATE_CLAIMED
)
182 hw_led_state
&= ~RED_LED
;
189 leds
^= hw_led_state
;
191 if (leds
&& (led_state
& LED_STATE_CLAIMED
)) {
192 tps_leds_change
|= leds
;
193 schedule_work(&work
);
197 local_irq_restore(flags
);