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/config.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/spinlock.h>
25 #include <asm/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/system.h>
30 #define LED_STATE_ENABLED 1
31 #define LED_STATE_CLAIMED 2
32 static char led_state;
33 static char hw_led_state;
35 static DEFINE_SPINLOCK(leds_lock);
36 extern spinlock_t gpio_lock;
38 static void netwinder_leds_event(led_event_t evt)
42 spin_lock_irqsave(&leds_lock, flags);
46 led_state |= LED_STATE_ENABLED;
47 hw_led_state = GPIO_GREEN_LED;
51 led_state &= ~LED_STATE_ENABLED;
55 led_state |= LED_STATE_CLAIMED;
60 led_state &= ~LED_STATE_CLAIMED;
64 #ifdef CONFIG_LEDS_TIMER
66 if (!(led_state & LED_STATE_CLAIMED))
67 hw_led_state ^= GPIO_GREEN_LED;
71 #ifdef CONFIG_LEDS_CPU
73 if (!(led_state & LED_STATE_CLAIMED))
74 hw_led_state &= ~GPIO_RED_LED;
78 if (!(led_state & LED_STATE_CLAIMED))
79 hw_led_state |= GPIO_RED_LED;
84 if (!(led_state & LED_STATE_CLAIMED))
85 hw_led_state |= GPIO_RED_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;
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_GREEN_LED | GPIO_RED_LED);
109 if (led_state & LED_STATE_CLAIMED)
110 hw_led_state |= GPIO_RED_LED;
114 if (led_state & LED_STATE_CLAIMED)
115 hw_led_state &= ~GPIO_RED_LED;
122 spin_unlock_irqrestore(&leds_lock, flags);
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);
131 static int __init leds_init(void)
133 if (machine_is_netwinder())
134 leds_event = netwinder_leds_event;
136 leds_event(led_start);
141 __initcall(leds_init);