Disintegrate asm/system.h for ARM
[linux-2.6.git] / arch / arm / mach-shark / leds.c
blob25609076921fc01970ba6319b414bec74168afac
1 /*
2 * arch/arm/mach-shark/leds.c
3 * by Alexander Schulz
5 * derived from:
6 * arch/arm/kernel/leds-footbridge.c
7 * Copyright (C) 1998-1999 Russell King
9 * DIGITAL Shark LED control routines.
11 * The leds use is as follows:
12 * - Green front - toggles state every 50 timer interrupts
13 * - Amber front - Unused, this is a dual color led (Amber/Green)
14 * - Amber back - On if system is not idle
16 * Changelog:
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/spinlock.h>
22 #include <linux/ioport.h>
23 #include <linux/io.h>
25 #include <asm/leds.h>
27 #define LED_STATE_ENABLED 1
28 #define LED_STATE_CLAIMED 2
30 #define SEQUOIA_LED_GREEN (1<<6)
31 #define SEQUOIA_LED_AMBER (1<<5)
32 #define SEQUOIA_LED_BACK (1<<7)
34 static char led_state;
35 static short hw_led_state;
36 static short saved_state;
38 static DEFINE_RAW_SPINLOCK(leds_lock);
40 short sequoia_read(int addr) {
41 outw(addr,0x24);
42 return inw(0x26);
45 void sequoia_write(short value,short addr) {
46 outw(addr,0x24);
47 outw(value,0x26);
50 static void sequoia_leds_event(led_event_t evt)
52 unsigned long flags;
54 raw_spin_lock_irqsave(&leds_lock, flags);
56 hw_led_state = sequoia_read(0x09);
58 switch (evt) {
59 case led_start:
60 hw_led_state |= SEQUOIA_LED_GREEN;
61 hw_led_state |= SEQUOIA_LED_AMBER;
62 #ifdef CONFIG_LEDS_CPU
63 hw_led_state |= SEQUOIA_LED_BACK;
64 #else
65 hw_led_state &= ~SEQUOIA_LED_BACK;
66 #endif
67 led_state |= LED_STATE_ENABLED;
68 break;
70 case led_stop:
71 hw_led_state &= ~SEQUOIA_LED_BACK;
72 hw_led_state |= SEQUOIA_LED_GREEN;
73 hw_led_state |= SEQUOIA_LED_AMBER;
74 led_state &= ~LED_STATE_ENABLED;
75 break;
77 case led_claim:
78 led_state |= LED_STATE_CLAIMED;
79 saved_state = hw_led_state;
80 hw_led_state &= ~SEQUOIA_LED_BACK;
81 hw_led_state |= SEQUOIA_LED_GREEN;
82 hw_led_state |= SEQUOIA_LED_AMBER;
83 break;
85 case led_release:
86 led_state &= ~LED_STATE_CLAIMED;
87 hw_led_state = saved_state;
88 break;
90 #ifdef CONFIG_LEDS_TIMER
91 case led_timer:
92 if (!(led_state & LED_STATE_CLAIMED))
93 hw_led_state ^= SEQUOIA_LED_GREEN;
94 break;
95 #endif
97 #ifdef CONFIG_LEDS_CPU
98 case led_idle_start:
99 if (!(led_state & LED_STATE_CLAIMED))
100 hw_led_state &= ~SEQUOIA_LED_BACK;
101 break;
103 case led_idle_end:
104 if (!(led_state & LED_STATE_CLAIMED))
105 hw_led_state |= SEQUOIA_LED_BACK;
106 break;
107 #endif
109 case led_green_on:
110 if (led_state & LED_STATE_CLAIMED)
111 hw_led_state &= ~SEQUOIA_LED_GREEN;
112 break;
114 case led_green_off:
115 if (led_state & LED_STATE_CLAIMED)
116 hw_led_state |= SEQUOIA_LED_GREEN;
117 break;
119 case led_amber_on:
120 if (led_state & LED_STATE_CLAIMED)
121 hw_led_state &= ~SEQUOIA_LED_AMBER;
122 break;
124 case led_amber_off:
125 if (led_state & LED_STATE_CLAIMED)
126 hw_led_state |= SEQUOIA_LED_AMBER;
127 break;
129 case led_red_on:
130 if (led_state & LED_STATE_CLAIMED)
131 hw_led_state |= SEQUOIA_LED_BACK;
132 break;
134 case led_red_off:
135 if (led_state & LED_STATE_CLAIMED)
136 hw_led_state &= ~SEQUOIA_LED_BACK;
137 break;
139 default:
140 break;
143 if (led_state & LED_STATE_ENABLED)
144 sequoia_write(hw_led_state,0x09);
146 raw_spin_unlock_irqrestore(&leds_lock, flags);
149 static int __init leds_init(void)
151 extern void (*leds_event)(led_event_t);
152 short temp;
154 leds_event = sequoia_leds_event;
156 /* Make LEDs independent of power-state */
157 request_region(0x24,4,"sequoia");
158 temp = sequoia_read(0x09);
159 temp |= 1<<10;
160 sequoia_write(temp,0x09);
161 leds_event(led_start);
162 return 0;
165 __initcall(leds_init);