Path: blob/master/arch/arm/mach-footbridge/netwinder-leds.c
10817 views
/*1* linux/arch/arm/mach-footbridge/netwinder-leds.c2*3* Copyright (C) 1998-1999 Russell King4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*9* NetWinder LED control routines.10*11* The Netwinder uses the leds as follows:12* - Green - toggles state every 50 timer interrupts13* - Red - On if the system is not idle14*15* Changelog:16* 02-05-1999 RMK Various cleanups17*/18#include <linux/module.h>19#include <linux/kernel.h>20#include <linux/init.h>21#include <linux/spinlock.h>2223#include <mach/hardware.h>24#include <asm/leds.h>25#include <asm/mach-types.h>26#include <asm/system.h>2728#define LED_STATE_ENABLED 129#define LED_STATE_CLAIMED 230static char led_state;31static char hw_led_state;3233static DEFINE_SPINLOCK(leds_lock);3435static void netwinder_leds_event(led_event_t evt)36{37unsigned long flags;3839spin_lock_irqsave(&leds_lock, flags);4041switch (evt) {42case led_start:43led_state |= LED_STATE_ENABLED;44hw_led_state = GPIO_GREEN_LED;45break;4647case led_stop:48led_state &= ~LED_STATE_ENABLED;49break;5051case led_claim:52led_state |= LED_STATE_CLAIMED;53hw_led_state = 0;54break;5556case led_release:57led_state &= ~LED_STATE_CLAIMED;58hw_led_state = 0;59break;6061#ifdef CONFIG_LEDS_TIMER62case led_timer:63if (!(led_state & LED_STATE_CLAIMED))64hw_led_state ^= GPIO_GREEN_LED;65break;66#endif6768#ifdef CONFIG_LEDS_CPU69case led_idle_start:70if (!(led_state & LED_STATE_CLAIMED))71hw_led_state &= ~GPIO_RED_LED;72break;7374case led_idle_end:75if (!(led_state & LED_STATE_CLAIMED))76hw_led_state |= GPIO_RED_LED;77break;78#endif7980case led_halted:81if (!(led_state & LED_STATE_CLAIMED))82hw_led_state |= GPIO_RED_LED;83break;8485case led_green_on:86if (led_state & LED_STATE_CLAIMED)87hw_led_state |= GPIO_GREEN_LED;88break;8990case led_green_off:91if (led_state & LED_STATE_CLAIMED)92hw_led_state &= ~GPIO_GREEN_LED;93break;9495case led_amber_on:96if (led_state & LED_STATE_CLAIMED)97hw_led_state |= GPIO_GREEN_LED | GPIO_RED_LED;98break;99100case led_amber_off:101if (led_state & LED_STATE_CLAIMED)102hw_led_state &= ~(GPIO_GREEN_LED | GPIO_RED_LED);103break;104105case led_red_on:106if (led_state & LED_STATE_CLAIMED)107hw_led_state |= GPIO_RED_LED;108break;109110case led_red_off:111if (led_state & LED_STATE_CLAIMED)112hw_led_state &= ~GPIO_RED_LED;113break;114115default:116break;117}118119spin_unlock_irqrestore(&leds_lock, flags);120121if (led_state & LED_STATE_ENABLED) {122spin_lock_irqsave(&nw_gpio_lock, flags);123nw_gpio_modify_op(GPIO_RED_LED | GPIO_GREEN_LED, hw_led_state);124spin_unlock_irqrestore(&nw_gpio_lock, flags);125}126}127128static int __init leds_init(void)129{130if (machine_is_netwinder())131leds_event = netwinder_leds_event;132133leds_event(led_start);134135return 0;136}137138__initcall(leds_init);139140141