2 * linux/arch/arm/mach-footbridge/netwinder-leds.c
4 * Copyright (C) 1998-1999 Russell King
6 * NetWinder LED control routines.
8 * The Netwinder uses the leds as follows:
9 * - Green - toggles state every 50 timer interrupts
10 * - Red - On if the system is not idle
13 * 02-05-1999 RMK Various cleanups
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/spinlock.h>
20 #include <asm/hardware.h>
22 #include <asm/mach-types.h>
23 #include <asm/system.h>
25 #define LED_STATE_ENABLED 1
26 #define LED_STATE_CLAIMED 2
27 static char led_state
;
28 static char hw_led_state
;
30 static spinlock_t leds_lock
= SPIN_LOCK_UNLOCKED
;
31 extern spinlock_t gpio_lock
;
33 static void netwinder_leds_event(led_event_t evt
)
37 spin_lock_irqsave(&leds_lock
, flags
);
41 led_state
|= LED_STATE_ENABLED
;
42 hw_led_state
= GPIO_GREEN_LED
;
46 led_state
&= ~LED_STATE_ENABLED
;
50 led_state
|= LED_STATE_CLAIMED
;
55 led_state
&= ~LED_STATE_CLAIMED
;
59 #ifdef CONFIG_LEDS_TIMER
61 if (!(led_state
& LED_STATE_CLAIMED
))
62 hw_led_state
^= GPIO_GREEN_LED
;
66 #ifdef CONFIG_LEDS_CPU
68 if (!(led_state
& LED_STATE_CLAIMED
))
69 hw_led_state
&= ~GPIO_RED_LED
;
73 if (!(led_state
& LED_STATE_CLAIMED
))
74 hw_led_state
|= GPIO_RED_LED
;
79 if (!(led_state
& LED_STATE_CLAIMED
))
80 hw_led_state
|= GPIO_RED_LED
;
84 if (led_state
& LED_STATE_CLAIMED
)
85 hw_led_state
|= GPIO_GREEN_LED
;
89 if (led_state
& LED_STATE_CLAIMED
)
90 hw_led_state
&= ~GPIO_GREEN_LED
;
94 if (led_state
& LED_STATE_CLAIMED
)
95 hw_led_state
|= GPIO_GREEN_LED
| GPIO_RED_LED
;
99 if (led_state
& LED_STATE_CLAIMED
)
100 hw_led_state
&= ~(GPIO_GREEN_LED
| GPIO_RED_LED
);
104 if (led_state
& LED_STATE_CLAIMED
)
105 hw_led_state
|= GPIO_RED_LED
;
109 if (led_state
& LED_STATE_CLAIMED
)
110 hw_led_state
&= ~GPIO_RED_LED
;
117 spin_unlock_irqrestore(&leds_lock
, flags
);
119 if (led_state
& LED_STATE_ENABLED
) {
120 spin_lock_irqsave(&gpio_lock
, flags
);
121 gpio_modify_op(GPIO_RED_LED
| GPIO_GREEN_LED
, hw_led_state
);
122 spin_unlock_irqrestore(&gpio_lock
, flags
);
126 static int __init
leds_init(void)
128 if (machine_is_netwinder())
129 leds_event
= netwinder_leds_event
;
131 leds_event(led_start
);
136 __initcall(leds_init
);