blob: f2f0325c3fa3e223bd68abe8152cf8e5ab733cc9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/*
* linux/arch/arm/kernel/leds-sa1100.c
*
* Copyright (C) 2000 John Dorsey <john+@cs.cmu.edu>
*
* Original (leds-footbridge.c) by Russell King
*
* Added Brutus LEDs support
* Nicolas Pitre, Mar 19, 2000
*
* Added LART LED support
* Erik Mouw (J.A.K.Mouw@its.tudelft.nl), April 21, 2000
*
*
* Assabet uses the LEDs as follows:
* - Green - toggles state every 50 timer interrupts
* - Red - on if system is not idle
*
* Brutus uses the LEDs as follows:
* - D3 (Green, GPIO9) - toggles state every 50 timer interrupts
* - D17 (Red, GPIO20) - on if system is not idle
* - D4 (Green, GPIO8) - misc function
*
* LART uses the LED as follows:
* - GPIO23 is the LED, on if system is not idle
* You can use both CONFIG_LEDS_CPU and CONFIG_LEDS_TIMER at the same
* time, but in that case the timer events will still dictate the
* pace of the LED.
*
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <asm/hardware.h>
#include <asm/leds.h>
#include <asm/system.h>
#define LED_STATE_ENABLED 1
#define LED_STATE_CLAIMED 2
static unsigned int led_state;
static unsigned int hw_led_state;
#ifdef CONFIG_SA1100_ASSABET
#define BCR_LED_MASK (BCR_LED_GREEN | BCR_LED_RED)
static void assabet_leds_event(led_event_t evt)
{
unsigned long flags;
save_flags_cli(flags);
switch (evt) {
case led_start:
hw_led_state = BCR_LED_RED | BCR_LED_GREEN;
led_state = LED_STATE_ENABLED;
break;
case led_stop:
led_state &= ~LED_STATE_ENABLED;
break;
case led_claim:
led_state |= LED_STATE_CLAIMED;
hw_led_state = BCR_LED_RED | BCR_LED_GREEN;
break;
case led_release:
led_state &= ~LED_STATE_CLAIMED;
hw_led_state = BCR_LED_RED | BCR_LED_GREEN;
break;
#ifdef CONFIG_LEDS_TIMER
case led_timer:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state ^= BCR_LED_GREEN;
break;
#endif
#ifdef CONFIG_LEDS_CPU
case led_idle_start:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= BCR_LED_RED;
break;
case led_idle_end:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~BCR_LED_RED;
break;
#endif
case led_green_on:
if (led_state & LED_STATE_CLAIMED)
hw_led_state &= ~BCR_LED_GREEN;
break;
case led_green_off:
if (led_state & LED_STATE_CLAIMED)
hw_led_state |= BCR_LED_GREEN;
break;
case led_amber_on:
break;
case led_amber_off:
break;
case led_red_on:
if (led_state & LED_STATE_CLAIMED)
hw_led_state &= ~BCR_LED_RED;
break;
case led_red_off:
if (led_state & LED_STATE_CLAIMED)
hw_led_state |= BCR_LED_RED;
break;
default:
break;
}
if (led_state & LED_STATE_ENABLED)
BCR = BCR_value = (BCR_value & ~BCR_LED_MASK) | hw_led_state;
restore_flags(flags);
}
#endif /* CONFIG_SA1100_ASSABET */
#ifdef CONFIG_SA1100_BRUTUS
#define LED_D3 GPIO_GPIO(9)
#define LED_D4 GPIO_GPIO(8)
#define LED_D17 GPIO_GPIO(20)
#define LED_MASK (LED_D3|LED_D4|LED_D17)
static void brutus_leds_event(led_event_t evt)
{
unsigned long flags;
save_flags_cli(flags);
switch (evt) {
case led_start:
hw_led_state = LED_MASK;
led_state = LED_STATE_ENABLED;
break;
case led_stop:
led_state &= ~LED_STATE_ENABLED;
break;
case led_claim:
led_state |= LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
case led_release:
led_state &= ~LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
#ifdef CONFIG_LEDS_TIMER
case led_timer:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state ^= LED_D3;
break;
#endif
#ifdef CONFIG_LEDS_CPU
case led_idle_start:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= LED_D17;
break;
case led_idle_end:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~LED_D17;
break;
#endif
case led_green_on:
hw_led_state &= ~LED_D4;
break;
case led_green_off:
hw_led_state |= LED_D4;
break;
case led_amber_on:
break;
case led_amber_off:
break;
case led_red_on:
if (led_state & LED_STATE_CLAIMED)
hw_led_state &= ~LED_D17;
break;
case led_red_off:
if (led_state & LED_STATE_CLAIMED)
hw_led_state |= LED_D17;
break;
default:
break;
}
if (led_state & LED_STATE_ENABLED) {
GPSR = hw_led_state;
GPCR = hw_led_state ^ LED_MASK;
}
restore_flags(flags);
}
#endif /* CONFIG_SA1100_BRUTUS */
#ifdef CONFIG_SA1100_LART
#define LED_23 GPIO_GPIO23
#define LED_MASK (LED_23)
static void lart_leds_event(led_event_t evt)
{
unsigned long flags;
save_flags_cli(flags);
switch(evt) {
case led_start:
hw_led_state = LED_MASK;
led_state = LED_STATE_ENABLED;
break;
case led_stop:
led_state &= ~LED_STATE_ENABLED;
break;
case led_claim:
led_state |= LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
case led_release:
led_state &= ~LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
#ifdef CONFIG_LEDS_TIMER
case led_timer:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state ^= LED_23;
break;
#endif
#ifdef CONFIG_LEDS_CPU
case led_idle_start:
/* The LART people like the LED to be off when the
system is idle... */
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~LED_23;
break;
case led_idle_end:
/* ... and on if the system is not idle */
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= LED_23;
break;
#endif
case led_red_on:
if (led_state & LED_STATE_CLAIMED)
hw_led_state &= ~LED_23;
break;
case led_red_off:
if (led_state & LED_STATE_CLAIMED)
hw_led_state |= LED_23;
break;
default:
break;
}
/* Now set the GPIO state, or nothing will happen at all */
if (led_state & LED_STATE_ENABLED) {
GPSR = hw_led_state;
GPCR = hw_led_state ^ LED_MASK;
}
restore_flags(flags);
}
#endif /* CONFIG_SA1100_LART */
static void dummy_leds_event(led_event_t evt)
{
}
void (*leds_event)(led_event_t) = dummy_leds_event;
EXPORT_SYMBOL(leds_event);
static int __init
sa1100_leds_init(void)
{
#ifdef CONFIG_SA1100_ASSABET
if (machine_is_assabet())
leds_event = assabet_leds_event;
#endif
#ifdef CONFIG_SA1100_BRUTUS
if (machine_is_brutus())
leds_event = brutus_leds_event;
#endif
#ifdef CONFIG_SA1100_LART
if (machine_is_lart())
leds_event = lart_leds_event;
#endif
leds_event(led_start);
return 0;
}
__initcall(sa1100_leds_init);
|