blob: 754383dde807c4050908ae4ea7fa0d438a27b101 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Tony Lindgren7c38cf02005-09-08 23:07:38 +01002 * linux/arch/arm/mach-omap1/leds-osk.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Brownelld94577d2008-02-28 22:09:15 -08004 * LED driver for OSK with optional Mistral QVGA board
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8#include <asm/hardware.h>
9#include <asm/leds.h>
10#include <asm/system.h>
11
12#include <asm/arch/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "leds.h"
15
16
17#define LED_STATE_ENABLED (1 << 0)
18#define LED_STATE_CLAIMED (1 << 1)
19static u8 led_state;
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define TIMER_LED (1 << 3) /* Mistral board */
22#define IDLE_LED (1 << 4) /* Mistral board */
23static u8 hw_led_state;
24
25
Tony Lindgren7c38cf02005-09-08 23:07:38 +010026#ifdef CONFIG_OMAP_OSK_MISTRAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* For now, all system indicators require the Mistral board, since that
29 * LED can be manipulated without a task context. This LED is either red,
30 * or green, but not both; it can't give the full "disco led" effect.
31 */
32
33#define GPIO_LED_RED 3
34#define GPIO_LED_GREEN OMAP_MPUIO(4)
35
36static void mistral_setled(void)
37{
38 int red = 0;
39 int green = 0;
40
41 if (hw_led_state & TIMER_LED)
42 red = 1;
43 else if (hw_led_state & IDLE_LED)
44 green = 1;
David Cohen6e2d4102007-12-13 22:27:15 -040045 /* else both sides are disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 omap_set_gpio_dataout(GPIO_LED_GREEN, green);
48 omap_set_gpio_dataout(GPIO_LED_RED, red);
49}
50
51#endif
52
53void osk_leds_event(led_event_t evt)
54{
55 unsigned long flags;
56 u16 leds;
57
58 local_irq_save(flags);
59
60 if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
61 goto done;
62
63 leds = hw_led_state;
64 switch (evt) {
65 case led_start:
66 led_state |= LED_STATE_ENABLED;
67 hw_led_state = 0;
68 leds = ~0;
69 break;
70
71 case led_halted:
72 case led_stop:
73 led_state &= ~LED_STATE_ENABLED;
74 hw_led_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 break;
76
77 case led_claim:
78 led_state |= LED_STATE_CLAIMED;
79 hw_led_state = 0;
80 leds = ~0;
81 break;
82
83 case led_release:
84 led_state &= ~LED_STATE_CLAIMED;
85 hw_led_state = 0;
86 break;
87
Tony Lindgren7c38cf02005-09-08 23:07:38 +010088#ifdef CONFIG_OMAP_OSK_MISTRAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 case led_timer:
91 hw_led_state ^= TIMER_LED;
92 mistral_setled();
93 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
David Brownelleebdf7d72007-04-02 12:48:10 -070095 case led_idle_start: /* idle == off */
96 hw_led_state &= ~IDLE_LED;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 mistral_setled();
98 break;
99
100 case led_idle_end:
David Brownelleebdf7d72007-04-02 12:48:10 -0700101 hw_led_state |= IDLE_LED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 mistral_setled();
103 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100105#endif /* CONFIG_OMAP_OSK_MISTRAL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 default:
108 break;
109 }
110
111 leds ^= hw_led_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113done:
114 local_irq_restore(flags);
115}