ARM: footbridge: convert to clockevents/clocksource
[linux-3.10.git] / arch / arm / mach-footbridge / ebsa285-leds.c
1 /*
2  *  linux/arch/arm/mach-footbridge/ebsa285-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  * EBSA-285 control routines.
10  *
11  * The EBSA-285 uses the leds as follows:
12  *  - Green - toggles state every 50 timer interrupts
13  *  - Amber - On if system is not idle
14  *  - Red   - currently unused
15  *
16  * Changelog:
17  *   02-05-1999 RMK     Various cleanups
18  */
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/spinlock.h>
23
24 #include <mach/hardware.h>
25 #include <asm/leds.h>
26 #include <asm/mach-types.h>
27 #include <asm/system.h>
28
29 #define LED_STATE_ENABLED       1
30 #define LED_STATE_CLAIMED       2
31 static char led_state;
32 static char hw_led_state;
33
34 static DEFINE_SPINLOCK(leds_lock);
35
36 static void ebsa285_leds_event(led_event_t evt)
37 {
38         unsigned long flags;
39
40         spin_lock_irqsave(&leds_lock, flags);
41
42         switch (evt) {
43         case led_start:
44                 hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN;
45 #ifndef CONFIG_LEDS_CPU
46                 hw_led_state |= XBUS_LED_AMBER;
47 #endif
48                 led_state |= LED_STATE_ENABLED;
49                 break;
50
51         case led_stop:
52                 led_state &= ~LED_STATE_ENABLED;
53                 break;
54
55         case led_claim:
56                 led_state |= LED_STATE_CLAIMED;
57                 hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
58                 break;
59
60         case led_release:
61                 led_state &= ~LED_STATE_CLAIMED;
62                 hw_led_state = XBUS_LED_RED | XBUS_LED_GREEN | XBUS_LED_AMBER;
63                 break;
64
65 #ifdef CONFIG_LEDS_TIMER
66         case led_timer:
67                 if (!(led_state & LED_STATE_CLAIMED))
68                         hw_led_state ^= XBUS_LED_GREEN;
69                 break;
70 #endif
71
72 #ifdef CONFIG_LEDS_CPU
73         case led_idle_start:
74                 if (!(led_state & LED_STATE_CLAIMED))
75                         hw_led_state |= XBUS_LED_AMBER;
76                 break;
77
78         case led_idle_end:
79                 if (!(led_state & LED_STATE_CLAIMED))
80                         hw_led_state &= ~XBUS_LED_AMBER;
81                 break;
82 #endif
83
84         case led_halted:
85                 if (!(led_state & LED_STATE_CLAIMED))
86                         hw_led_state &= ~XBUS_LED_RED;
87                 break;
88
89         case led_green_on:
90                 if (led_state & LED_STATE_CLAIMED)
91                         hw_led_state &= ~XBUS_LED_GREEN;
92                 break;
93
94         case led_green_off:
95                 if (led_state & LED_STATE_CLAIMED)
96                         hw_led_state |= XBUS_LED_GREEN;
97                 break;
98
99         case led_amber_on:
100                 if (led_state & LED_STATE_CLAIMED)
101                         hw_led_state &= ~XBUS_LED_AMBER;
102                 break;
103
104         case led_amber_off:
105                 if (led_state & LED_STATE_CLAIMED)
106                         hw_led_state |= XBUS_LED_AMBER;
107                 break;
108
109         case led_red_on:
110                 if (led_state & LED_STATE_CLAIMED)
111                         hw_led_state &= ~XBUS_LED_RED;
112                 break;
113
114         case led_red_off:
115                 if (led_state & LED_STATE_CLAIMED)
116                         hw_led_state |= XBUS_LED_RED;
117                 break;
118
119         default:
120                 break;
121         }
122
123         if  (led_state & LED_STATE_ENABLED)
124                 *XBUS_LEDS = hw_led_state;
125
126         spin_unlock_irqrestore(&leds_lock, flags);
127 }
128
129 static int __init leds_init(void)
130 {
131         if (machine_is_ebsa285())
132                 leds_event = ebsa285_leds_event;
133
134         leds_event(led_start);
135
136         return 0;
137 }
138
139 __initcall(leds_init);