Pull novell-bugzilla-156426 into release branch
[linux-2.6] / arch / arm / mach-footbridge / netwinder-leds.c
1 /*
2  *  linux/arch/arm/mach-footbridge/netwinder-leds.c
3  *
4  *  Copyright (C) 1998-1999 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * NetWinder LED control routines.
11  *
12  * The Netwinder uses the leds as follows:
13  *  - Green - toggles state every 50 timer interrupts
14  *  - Red   - On if the system is not idle
15  *
16  * Changelog:
17  *   02-05-1999 RMK     Various cleanups
18  */
19 #include <linux/config.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/spinlock.h>
24
25 #include <asm/hardware.h>
26 #include <asm/leds.h>
27 #include <asm/mach-types.h>
28 #include <asm/system.h>
29
30 #define LED_STATE_ENABLED       1
31 #define LED_STATE_CLAIMED       2
32 static char led_state;
33 static char hw_led_state;
34
35 static DEFINE_SPINLOCK(leds_lock);
36 extern spinlock_t gpio_lock;
37
38 static void netwinder_leds_event(led_event_t evt)
39 {
40         unsigned long flags;
41
42         spin_lock_irqsave(&leds_lock, flags);
43
44         switch (evt) {
45         case led_start:
46                 led_state |= LED_STATE_ENABLED;
47                 hw_led_state = GPIO_GREEN_LED;
48                 break;
49
50         case led_stop:
51                 led_state &= ~LED_STATE_ENABLED;
52                 break;
53
54         case led_claim:
55                 led_state |= LED_STATE_CLAIMED;
56                 hw_led_state = 0;
57                 break;
58
59         case led_release:
60                 led_state &= ~LED_STATE_CLAIMED;
61                 hw_led_state = 0;
62                 break;
63
64 #ifdef CONFIG_LEDS_TIMER
65         case led_timer:
66                 if (!(led_state & LED_STATE_CLAIMED))
67                         hw_led_state ^= GPIO_GREEN_LED;
68                 break;
69 #endif
70
71 #ifdef CONFIG_LEDS_CPU
72         case led_idle_start:
73                 if (!(led_state & LED_STATE_CLAIMED))
74                         hw_led_state &= ~GPIO_RED_LED;
75                 break;
76
77         case led_idle_end:
78                 if (!(led_state & LED_STATE_CLAIMED))
79                         hw_led_state |= GPIO_RED_LED;
80                 break;
81 #endif
82
83         case led_halted:
84                 if (!(led_state & LED_STATE_CLAIMED))
85                         hw_led_state |= GPIO_RED_LED;
86                 break;
87
88         case led_green_on:
89                 if (led_state & LED_STATE_CLAIMED)
90                         hw_led_state |= GPIO_GREEN_LED;
91                 break;
92
93         case led_green_off:
94                 if (led_state & LED_STATE_CLAIMED)
95                         hw_led_state &= ~GPIO_GREEN_LED;
96                 break;
97
98         case led_amber_on:
99                 if (led_state & LED_STATE_CLAIMED)
100                         hw_led_state |= GPIO_GREEN_LED | GPIO_RED_LED;
101                 break;
102
103         case led_amber_off:
104                 if (led_state & LED_STATE_CLAIMED)
105                         hw_led_state &= ~(GPIO_GREEN_LED | GPIO_RED_LED);
106                 break;
107
108         case led_red_on:
109                 if (led_state & LED_STATE_CLAIMED)
110                         hw_led_state |= GPIO_RED_LED;
111                 break;
112
113         case led_red_off:
114                 if (led_state & LED_STATE_CLAIMED)
115                         hw_led_state &= ~GPIO_RED_LED;
116                 break;
117
118         default:
119                 break;
120         }
121
122         spin_unlock_irqrestore(&leds_lock, flags);
123
124         if  (led_state & LED_STATE_ENABLED) {
125                 spin_lock_irqsave(&gpio_lock, flags);
126                 gpio_modify_op(GPIO_RED_LED | GPIO_GREEN_LED, hw_led_state);
127                 spin_unlock_irqrestore(&gpio_lock, flags);
128         }
129 }
130
131 static int __init leds_init(void)
132 {
133         if (machine_is_netwinder())
134                 leds_event = netwinder_leds_event;
135
136         leds_event(led_start);
137
138         return 0;
139 }
140
141 __initcall(leds_init);