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