2 * linux/arch/arm/mach-footbridge/netwinder-leds.c
4 * Copyright (C) 1998-1999 Russell King
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.
10 * NetWinder LED control routines.
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
17 * 02-05-1999 RMK Various cleanups
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/spinlock.h>
24 #include <mach/hardware.h>
26 #include <asm/mach-types.h>
27 #include <asm/system.h>
29 #define LED_STATE_ENABLED 1
30 #define LED_STATE_CLAIMED 2
31 static char led_state
;
32 static char hw_led_state
;
34 static DEFINE_RAW_SPINLOCK(leds_lock
);
36 static void netwinder_leds_event(led_event_t evt
)
40 raw_spin_lock_irqsave(&leds_lock
, flags
);
44 led_state
|= LED_STATE_ENABLED
;
45 hw_led_state
= GPIO_GREEN_LED
;
49 led_state
&= ~LED_STATE_ENABLED
;
53 led_state
|= LED_STATE_CLAIMED
;
58 led_state
&= ~LED_STATE_CLAIMED
;
62 #ifdef CONFIG_LEDS_TIMER
64 if (!(led_state
& LED_STATE_CLAIMED
))
65 hw_led_state
^= GPIO_GREEN_LED
;
69 #ifdef CONFIG_LEDS_CPU
71 if (!(led_state
& LED_STATE_CLAIMED
))
72 hw_led_state
&= ~GPIO_RED_LED
;
76 if (!(led_state
& LED_STATE_CLAIMED
))
77 hw_led_state
|= GPIO_RED_LED
;
82 if (!(led_state
& LED_STATE_CLAIMED
))
83 hw_led_state
|= GPIO_RED_LED
;
87 if (led_state
& LED_STATE_CLAIMED
)
88 hw_led_state
|= GPIO_GREEN_LED
;
92 if (led_state
& LED_STATE_CLAIMED
)
93 hw_led_state
&= ~GPIO_GREEN_LED
;
97 if (led_state
& LED_STATE_CLAIMED
)
98 hw_led_state
|= GPIO_GREEN_LED
| GPIO_RED_LED
;
102 if (led_state
& LED_STATE_CLAIMED
)
103 hw_led_state
&= ~(GPIO_GREEN_LED
| GPIO_RED_LED
);
107 if (led_state
& LED_STATE_CLAIMED
)
108 hw_led_state
|= GPIO_RED_LED
;
112 if (led_state
& LED_STATE_CLAIMED
)
113 hw_led_state
&= ~GPIO_RED_LED
;
120 raw_spin_unlock_irqrestore(&leds_lock
, flags
);
122 if (led_state
& LED_STATE_ENABLED
) {
123 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
124 nw_gpio_modify_op(GPIO_RED_LED
| GPIO_GREEN_LED
, hw_led_state
);
125 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
129 static int __init
leds_init(void)
131 if (machine_is_netwinder())
132 leds_event
= netwinder_leds_event
;
134 leds_event(led_start
);
139 __initcall(leds_init
);