linux/arch/arm/mach-omap1/leds-osk.c
<<
>>
Prefs
   1/*
   2 * linux/arch/arm/mach-omap1/leds-osk.c
   3 *
   4 * LED driver for OSK with optional Mistral QVGA board
   5 */
   6#include <linux/init.h>
   7
   8#include <mach/hardware.h>
   9#include <asm/leds.h>
  10#include <asm/system.h>
  11
  12#include <mach/gpio.h>
  13
  14#include "leds.h"
  15
  16
  17#define LED_STATE_ENABLED       (1 << 0)
  18#define LED_STATE_CLAIMED       (1 << 1)
  19static u8 led_state;
  20
  21#define TIMER_LED               (1 << 3)        /* Mistral board */
  22#define IDLE_LED                (1 << 4)        /* Mistral board */
  23static u8 hw_led_state;
  24
  25
  26#ifdef  CONFIG_OMAP_OSK_MISTRAL
  27
  28/* For now, all system indicators require the Mistral board, since that
  29 * LED can be manipulated without a task context.  This LED is either red,
  30 * or green, but not both; it can't give the full "disco led" effect.
  31 */
  32
  33#define GPIO_LED_RED            3
  34#define GPIO_LED_GREEN          OMAP_MPUIO(4)
  35
  36static void mistral_setled(void)
  37{
  38        int     red = 0;
  39        int     green = 0;
  40
  41        if (hw_led_state & TIMER_LED)
  42                red = 1;
  43        else if (hw_led_state & IDLE_LED)
  44                green = 1;
  45        /* else both sides are disabled */
  46
  47        gpio_set_value(GPIO_LED_GREEN, green);
  48        gpio_set_value(GPIO_LED_RED, red);
  49}
  50
  51#endif
  52
  53void osk_leds_event(led_event_t evt)
  54{
  55        unsigned long   flags;
  56        u16             leds;
  57
  58        local_irq_save(flags);
  59
  60        if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
  61                goto done;
  62
  63        leds = hw_led_state;
  64        switch (evt) {
  65        case led_start:
  66                led_state |= LED_STATE_ENABLED;
  67                hw_led_state = 0;
  68                leds = ~0;
  69                break;
  70
  71        case led_halted:
  72        case led_stop:
  73                led_state &= ~LED_STATE_ENABLED;
  74                hw_led_state = 0;
  75                break;
  76
  77        case led_claim:
  78                led_state |= LED_STATE_CLAIMED;
  79                hw_led_state = 0;
  80                leds = ~0;
  81                break;
  82
  83        case led_release:
  84                led_state &= ~LED_STATE_CLAIMED;
  85                hw_led_state = 0;
  86                break;
  87
  88#ifdef  CONFIG_OMAP_OSK_MISTRAL
  89
  90        case led_timer:
  91                hw_led_state ^= TIMER_LED;
  92                mistral_setled();
  93                break;
  94
  95        case led_idle_start:    /* idle == off */
  96                hw_led_state &= ~IDLE_LED;
  97                mistral_setled();
  98                break;
  99
 100        case led_idle_end:
 101                hw_led_state |= IDLE_LED;
 102                mistral_setled();
 103                break;
 104
 105#endif  /* CONFIG_OMAP_OSK_MISTRAL */
 106
 107        default:
 108                break;
 109        }
 110
 111        leds ^= hw_led_state;
 112
 113done:
 114        local_irq_restore(flags);
 115}
 116