diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/arm/mach-omap/leds-osk.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/arm/mach-omap/leds-osk.c')
-rw-r--r-- | arch/arm/mach-omap/leds-osk.c | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/arch/arm/mach-omap/leds-osk.c b/arch/arm/mach-omap/leds-osk.c new file mode 100644 index 000000000000..f5177f430793 --- /dev/null +++ b/arch/arm/mach-omap/leds-osk.c | |||
@@ -0,0 +1,198 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-omap/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 | |||
10 | #include <asm/hardware.h> | ||
11 | #include <asm/leds.h> | ||
12 | #include <asm/system.h> | ||
13 | |||
14 | #include <asm/arch/gpio.h> | ||
15 | #include <asm/arch/tps65010.h> | ||
16 | |||
17 | #include "leds.h" | ||
18 | |||
19 | |||
20 | #define LED_STATE_ENABLED (1 << 0) | ||
21 | #define LED_STATE_CLAIMED (1 << 1) | ||
22 | static u8 led_state; | ||
23 | |||
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; | ||
30 | |||
31 | |||
32 | /* TPS65010 leds are changed using i2c -- from a task context. | ||
33 | * Using one of these for the "idle" LED would be impractical... | ||
34 | */ | ||
35 | #define TPS_LEDS (GREEN_LED | RED_LED | AMBER_LED) | ||
36 | |||
37 | static u8 tps_leds_change; | ||
38 | |||
39 | static void tps_work(void *unused) | ||
40 | { | ||
41 | for (;;) { | ||
42 | u8 leds; | ||
43 | |||
44 | local_irq_disable(); | ||
45 | leds = tps_leds_change; | ||
46 | tps_leds_change = 0; | ||
47 | local_irq_enable(); | ||
48 | |||
49 | if (!leds) | ||
50 | break; | ||
51 | |||
52 | /* careful: the set_led() value is on/off/blink */ | ||
53 | if (leds & GREEN_LED) | ||
54 | tps65010_set_led(LED1, !!(hw_led_state & GREEN_LED)); | ||
55 | if (leds & AMBER_LED) | ||
56 | tps65010_set_led(LED2, !!(hw_led_state & AMBER_LED)); | ||
57 | |||
58 | /* the gpio led doesn't have that issue */ | ||
59 | if (leds & RED_LED) | ||
60 | tps65010_set_gpio_out_value(GPIO2, | ||
61 | !(hw_led_state & RED_LED)); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | static DECLARE_WORK(work, tps_work, NULL); | ||
66 | |||
67 | #ifdef CONFIG_FB_OMAP | ||
68 | |||
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. | ||
72 | */ | ||
73 | |||
74 | #define GPIO_LED_RED 3 | ||
75 | #define GPIO_LED_GREEN OMAP_MPUIO(4) | ||
76 | |||
77 | static void mistral_setled(void) | ||
78 | { | ||
79 | int red = 0; | ||
80 | int green = 0; | ||
81 | |||
82 | if (hw_led_state & TIMER_LED) | ||
83 | red = 1; | ||
84 | else if (hw_led_state & IDLE_LED) | ||
85 | green = 1; | ||
86 | // else both sides are disabled | ||
87 | |||
88 | omap_set_gpio_dataout(GPIO_LED_GREEN, green); | ||
89 | omap_set_gpio_dataout(GPIO_LED_RED, red); | ||
90 | } | ||
91 | |||
92 | #endif | ||
93 | |||
94 | void osk_leds_event(led_event_t evt) | ||
95 | { | ||
96 | unsigned long flags; | ||
97 | u16 leds; | ||
98 | |||
99 | local_irq_save(flags); | ||
100 | |||
101 | if (!(led_state & LED_STATE_ENABLED) && evt != led_start) | ||
102 | goto done; | ||
103 | |||
104 | leds = hw_led_state; | ||
105 | switch (evt) { | ||
106 | case led_start: | ||
107 | led_state |= LED_STATE_ENABLED; | ||
108 | hw_led_state = 0; | ||
109 | leds = ~0; | ||
110 | break; | ||
111 | |||
112 | case led_halted: | ||
113 | case led_stop: | ||
114 | led_state &= ~LED_STATE_ENABLED; | ||
115 | hw_led_state = 0; | ||
116 | // NOTE: work may still be pending!! | ||
117 | break; | ||
118 | |||
119 | case led_claim: | ||
120 | led_state |= LED_STATE_CLAIMED; | ||
121 | hw_led_state = 0; | ||
122 | leds = ~0; | ||
123 | break; | ||
124 | |||
125 | case led_release: | ||
126 | led_state &= ~LED_STATE_CLAIMED; | ||
127 | hw_led_state = 0; | ||
128 | break; | ||
129 | |||
130 | #ifdef CONFIG_FB_OMAP | ||
131 | |||
132 | #ifdef CONFIG_LEDS_TIMER | ||
133 | case led_timer: | ||
134 | hw_led_state ^= TIMER_LED; | ||
135 | mistral_setled(); | ||
136 | break; | ||
137 | #endif | ||
138 | |||
139 | #ifdef CONFIG_LEDS_CPU | ||
140 | case led_idle_start: | ||
141 | hw_led_state |= IDLE_LED; | ||
142 | mistral_setled(); | ||
143 | break; | ||
144 | |||
145 | case led_idle_end: | ||
146 | hw_led_state &= ~IDLE_LED; | ||
147 | mistral_setled(); | ||
148 | break; | ||
149 | #endif | ||
150 | |||
151 | #endif /* CONFIG_FB_OMAP */ | ||
152 | |||
153 | /* "green" == tps LED1 (leftmost, normally power-good) | ||
154 | * works only with DC adapter, not on battery power! | ||
155 | */ | ||
156 | case led_green_on: | ||
157 | if (led_state & LED_STATE_CLAIMED) | ||
158 | hw_led_state |= GREEN_LED; | ||
159 | break; | ||
160 | case led_green_off: | ||
161 | if (led_state & LED_STATE_CLAIMED) | ||
162 | hw_led_state &= ~GREEN_LED; | ||
163 | break; | ||
164 | |||
165 | /* "amber" == tps LED2 (middle) */ | ||
166 | case led_amber_on: | ||
167 | if (led_state & LED_STATE_CLAIMED) | ||
168 | hw_led_state |= AMBER_LED; | ||
169 | break; | ||
170 | case led_amber_off: | ||
171 | if (led_state & LED_STATE_CLAIMED) | ||
172 | hw_led_state &= ~AMBER_LED; | ||
173 | break; | ||
174 | |||
175 | /* "red" == LED on tps gpio3 (rightmost) */ | ||
176 | case led_red_on: | ||
177 | if (led_state & LED_STATE_CLAIMED) | ||
178 | hw_led_state |= RED_LED; | ||
179 | break; | ||
180 | case led_red_off: | ||
181 | if (led_state & LED_STATE_CLAIMED) | ||
182 | hw_led_state &= ~RED_LED; | ||
183 | break; | ||
184 | |||
185 | default: | ||
186 | break; | ||
187 | } | ||
188 | |||
189 | leds ^= hw_led_state; | ||
190 | leds &= TPS_LEDS; | ||
191 | if (leds && (led_state & LED_STATE_CLAIMED)) { | ||
192 | tps_leds_change |= leds; | ||
193 | schedule_work(&work); | ||
194 | } | ||
195 | |||
196 | done: | ||
197 | local_irq_restore(flags); | ||
198 | } | ||