blob: 259b48e0be895b5b3c6ffcf50178b56c02a0b57f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/leds-cerf.c
3 *
4 * Author: ???
5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/init.h>
7
Russell Kinga09e64f2008-08-05 16:14:15 +01008#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/leds.h>
10#include <asm/system.h>
11
12#include "leds.h"
13
14
15#define LED_STATE_ENABLED 1
16#define LED_STATE_CLAIMED 2
17
18static unsigned int led_state;
19static unsigned int hw_led_state;
20
21#define LED_D0 GPIO_GPIO(0)
22#define LED_D1 GPIO_GPIO(1)
23#define LED_D2 GPIO_GPIO(2)
24#define LED_D3 GPIO_GPIO(3)
25#define LED_MASK (LED_D0|LED_D1|LED_D2|LED_D3)
26
27void cerf_leds_event(led_event_t evt)
28{
29 unsigned long flags;
30
31 local_irq_save(flags);
32
33 switch (evt) {
34 case led_start:
35 hw_led_state = LED_MASK;
36 led_state = LED_STATE_ENABLED;
37 break;
38
39 case led_stop:
40 led_state &= ~LED_STATE_ENABLED;
41 break;
42
43 case led_claim:
44 led_state |= LED_STATE_CLAIMED;
45 hw_led_state = LED_MASK;
46 break;
47 case led_release:
48 led_state &= ~LED_STATE_CLAIMED;
49 hw_led_state = LED_MASK;
50 break;
51
52#ifdef CONFIG_LEDS_TIMER
53 case led_timer:
54 if (!(led_state & LED_STATE_CLAIMED))
55 hw_led_state ^= LED_D0;
56 break;
57#endif
58
59#ifdef CONFIG_LEDS_CPU
60 case led_idle_start:
61 if (!(led_state & LED_STATE_CLAIMED))
62 hw_led_state &= ~LED_D1;
63 break;
64
65 case led_idle_end:
66 if (!(led_state & LED_STATE_CLAIMED))
67 hw_led_state |= LED_D1;
68 break;
69#endif
70 case led_green_on:
71 if (!(led_state & LED_STATE_CLAIMED))
72 hw_led_state &= ~LED_D2;
73 break;
74
75 case led_green_off:
76 if (!(led_state & LED_STATE_CLAIMED))
77 hw_led_state |= LED_D2;
78 break;
79
80 case led_amber_on:
81 if (!(led_state & LED_STATE_CLAIMED))
82 hw_led_state &= ~LED_D3;
83 break;
84
85 case led_amber_off:
86 if (!(led_state & LED_STATE_CLAIMED))
87 hw_led_state |= LED_D3;
88 break;
89
90 case led_red_on:
91 if (!(led_state & LED_STATE_CLAIMED))
92 hw_led_state &= ~LED_D1;
93 break;
94
95 case led_red_off:
96 if (!(led_state & LED_STATE_CLAIMED))
97 hw_led_state |= LED_D1;
98 break;
99
100 default:
101 break;
102 }
103
104 if (led_state & LED_STATE_ENABLED) {
105 GPSR = hw_led_state;
106 GPCR = hw_led_state ^ LED_MASK;
107 }
108
109 local_irq_restore(flags);
110}