Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Tony Lindgren | 7c38cf0 | 2005-09-08 23:07:38 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mach-omap1/leds-osk.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
David Brownell | d94577d | 2008-02-28 22:09:15 -0800 | [diff] [blame] | 4 | * LED driver for OSK with optional Mistral QVGA board |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | |
| 8 | #include <asm/hardware.h> |
| 9 | #include <asm/leds.h> |
| 10 | #include <asm/system.h> |
| 11 | |
| 12 | #include <asm/arch/gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "leds.h" |
| 15 | |
| 16 | |
| 17 | #define LED_STATE_ENABLED (1 << 0) |
| 18 | #define LED_STATE_CLAIMED (1 << 1) |
| 19 | static u8 led_state; |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define TIMER_LED (1 << 3) /* Mistral board */ |
| 22 | #define IDLE_LED (1 << 4) /* Mistral board */ |
| 23 | static u8 hw_led_state; |
| 24 | |
| 25 | |
Tony Lindgren | 7c38cf0 | 2005-09-08 23:07:38 +0100 | [diff] [blame] | 26 | #ifdef CONFIG_OMAP_OSK_MISTRAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 36 | static 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; |
David Cohen | 6e2d410 | 2007-12-13 22:27:15 -0400 | [diff] [blame] | 45 | /* else both sides are disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | omap_set_gpio_dataout(GPIO_LED_GREEN, green); |
| 48 | omap_set_gpio_dataout(GPIO_LED_RED, red); |
| 49 | } |
| 50 | |
| 51 | #endif |
| 52 | |
| 53 | void 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Tony Lindgren | 7c38cf0 | 2005-09-08 23:07:38 +0100 | [diff] [blame] | 88 | #ifdef CONFIG_OMAP_OSK_MISTRAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | case led_timer: |
| 91 | hw_led_state ^= TIMER_LED; |
| 92 | mistral_setled(); |
| 93 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
David Brownell | eebdf7d7 | 2007-04-02 12:48:10 -0700 | [diff] [blame] | 95 | case led_idle_start: /* idle == off */ |
| 96 | hw_led_state &= ~IDLE_LED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | mistral_setled(); |
| 98 | break; |
| 99 | |
| 100 | case led_idle_end: |
David Brownell | eebdf7d7 | 2007-04-02 12:48:10 -0700 | [diff] [blame] | 101 | hw_led_state |= IDLE_LED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | mistral_setled(); |
| 103 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Tony Lindgren | 7c38cf0 | 2005-09-08 23:07:38 +0100 | [diff] [blame] | 105 | #endif /* CONFIG_OMAP_OSK_MISTRAL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | default: |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | leds ^= hw_led_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | done: |
| 114 | local_irq_restore(flags); |
| 115 | } |