2 * linux/arch/arm/mach-omap1/leds-osk.c
4 * LED driver for OSK, and optionally Mistral QVGA, boards
6 #include <linux/init.h>
7 #include <linux/workqueue.h>
9 #include <asm/hardware.h>
11 #include <asm/system.h>
13 #include <asm/arch/gpio.h>
14 #include <asm/arch/tps65010.h>
19 #define LED_STATE_ENABLED (1 << 0)
20 #define LED_STATE_CLAIMED (1 << 1)
23 #define GREEN_LED (1 << 0) /* TPS65010 LED1 */
24 #define AMBER_LED (1 << 1) /* TPS65010 LED2 */
25 #define RED_LED (1 << 2) /* TPS65010 GPIO2 */
26 #define TIMER_LED (1 << 3) /* Mistral board */
27 #define IDLE_LED (1 << 4) /* Mistral board */
28 static u8 hw_led_state
;
31 /* TPS65010 leds are changed using i2c -- from a task context.
32 * Using one of these for the "idle" LED would be impractical...
34 #define TPS_LEDS (GREEN_LED | RED_LED | AMBER_LED)
36 static u8 tps_leds_change
;
38 static void tps_work(struct work_struct
*unused
)
44 leds
= tps_leds_change
;
51 /* careful: the set_led() value is on/off/blink */
53 tps65010_set_led(LED1
, !!(hw_led_state
& GREEN_LED
));
55 tps65010_set_led(LED2
, !!(hw_led_state
& AMBER_LED
));
57 /* the gpio led doesn't have that issue */
59 tps65010_set_gpio_out_value(GPIO2
,
60 !(hw_led_state
& RED_LED
));
64 static DECLARE_WORK(work
, tps_work
);
66 #ifdef CONFIG_OMAP_OSK_MISTRAL
68 /* For now, all system indicators require the Mistral board, since that
69 * LED can be manipulated without a task context. This LED is either red,
70 * or green, but not both; it can't give the full "disco led" effect.
73 #define GPIO_LED_RED 3
74 #define GPIO_LED_GREEN OMAP_MPUIO(4)
76 static void mistral_setled(void)
81 if (hw_led_state
& TIMER_LED
)
83 else if (hw_led_state
& IDLE_LED
)
85 // else both sides are disabled
87 omap_set_gpio_dataout(GPIO_LED_GREEN
, green
);
88 omap_set_gpio_dataout(GPIO_LED_RED
, red
);
93 void osk_leds_event(led_event_t evt
)
98 local_irq_save(flags
);
100 if (!(led_state
& LED_STATE_ENABLED
) && evt
!= led_start
)
106 led_state
|= LED_STATE_ENABLED
;
113 led_state
&= ~LED_STATE_ENABLED
;
115 // NOTE: work may still be pending!!
119 led_state
|= LED_STATE_CLAIMED
;
125 led_state
&= ~LED_STATE_CLAIMED
;
129 #ifdef CONFIG_OMAP_OSK_MISTRAL
132 hw_led_state
^= TIMER_LED
;
137 hw_led_state
|= IDLE_LED
;
142 hw_led_state
&= ~IDLE_LED
;
146 #endif /* CONFIG_OMAP_OSK_MISTRAL */
148 /* "green" == tps LED1 (leftmost, normally power-good)
149 * works only with DC adapter, not on battery power!
152 if (led_state
& LED_STATE_CLAIMED
)
153 hw_led_state
|= GREEN_LED
;
156 if (led_state
& LED_STATE_CLAIMED
)
157 hw_led_state
&= ~GREEN_LED
;
160 /* "amber" == tps LED2 (middle) */
162 if (led_state
& LED_STATE_CLAIMED
)
163 hw_led_state
|= AMBER_LED
;
166 if (led_state
& LED_STATE_CLAIMED
)
167 hw_led_state
&= ~AMBER_LED
;
170 /* "red" == LED on tps gpio3 (rightmost) */
172 if (led_state
& LED_STATE_CLAIMED
)
173 hw_led_state
|= RED_LED
;
176 if (led_state
& LED_STATE_CLAIMED
)
177 hw_led_state
&= ~RED_LED
;
184 leds
^= hw_led_state
;
186 if (leds
&& (led_state
& LED_STATE_CLAIMED
)) {
187 tps_leds_change
|= leds
;
188 schedule_work(&work
);
192 local_irq_restore(flags
);