1 /* 2 * linux/arch/arm/mach-sa1100/leds-badge4.c 3 * 4 * Author: Christopher Hoover <ch@hpl.hp.com> 5 * Copyright (C) 2002 Hewlett-Packard Company 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 */ 12 13 #include <linux/init.h> 14 15 #include <mach/hardware.h> 16 #include <asm/leds.h> 17 18 #include "leds.h" 19 20 #define LED_STATE_ENABLED 1 21 #define LED_STATE_CLAIMED 2 22 23 static unsigned int led_state; 24 static unsigned int hw_led_state; 25 26 #define LED_RED GPIO_GPIO(7) 27 #define LED_GREEN GPIO_GPIO(9) 28 #define LED_MASK (LED_RED|LED_GREEN) 29 30 #define LED_IDLE LED_GREEN 31 #define LED_TIMER LED_RED 32 badge4_leds_event(led_event_t evt)33void badge4_leds_event(led_event_t evt) 34 { 35 unsigned long flags; 36 37 local_irq_save(flags); 38 39 switch (evt) { 40 case led_start: 41 GPDR |= LED_MASK; 42 hw_led_state = LED_MASK; 43 led_state = LED_STATE_ENABLED; 44 break; 45 46 case led_stop: 47 led_state &= ~LED_STATE_ENABLED; 48 break; 49 50 case led_claim: 51 led_state |= LED_STATE_CLAIMED; 52 hw_led_state = LED_MASK; 53 break; 54 55 case led_release: 56 led_state &= ~LED_STATE_CLAIMED; 57 hw_led_state = LED_MASK; 58 break; 59 60 #ifdef CONFIG_LEDS_TIMER 61 case led_timer: 62 if (!(led_state & LED_STATE_CLAIMED)) 63 hw_led_state ^= LED_TIMER; 64 break; 65 #endif 66 67 #ifdef CONFIG_LEDS_CPU 68 case led_idle_start: 69 /* LED off when system is idle */ 70 if (!(led_state & LED_STATE_CLAIMED)) 71 hw_led_state &= ~LED_IDLE; 72 break; 73 74 case led_idle_end: 75 if (!(led_state & LED_STATE_CLAIMED)) 76 hw_led_state |= LED_IDLE; 77 break; 78 #endif 79 80 case led_red_on: 81 if (!(led_state & LED_STATE_CLAIMED)) 82 hw_led_state &= ~LED_RED; 83 break; 84 85 case led_red_off: 86 if (!(led_state & LED_STATE_CLAIMED)) 87 hw_led_state |= LED_RED; 88 break; 89 90 case led_green_on: 91 if (!(led_state & LED_STATE_CLAIMED)) 92 hw_led_state &= ~LED_GREEN; 93 break; 94 95 case led_green_off: 96 if (!(led_state & LED_STATE_CLAIMED)) 97 hw_led_state |= LED_GREEN; 98 break; 99 100 default: 101 break; 102 } 103 104 if (led_state & LED_STATE_ENABLED) { 105 GPSR = hw_led_state; 106 GPCR = hw_led_state ^ LED_MASK; 107 } 108 109 local_irq_restore(flags); 110 } 111