blob: da09f4364979808421b2f482b68a32ea84ec898c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Tony Lindgren7c38cf02005-09-08 23:07:38 +01002 * linux/arch/arm/mach-omap1/leds-osk.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
David Brownelld94577d2008-02-28 22:09:15 -08004 * LED driver for OSK with optional Mistral QVGA board
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Russell King2f8163b2011-07-26 10:53:52 +01006#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Russell Kinga09e64f2008-08-05 16:14:15 +01009#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/leds.h>
11#include <asm/system.h>
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "leds.h"
14
15
16#define LED_STATE_ENABLED (1 << 0)
17#define LED_STATE_CLAIMED (1 << 1)
18static u8 led_state;
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define TIMER_LED (1 << 3) /* Mistral board */
21#define IDLE_LED (1 << 4) /* Mistral board */
22static u8 hw_led_state;
23
24
Tony Lindgren7c38cf02005-09-08 23:07:38 +010025#ifdef CONFIG_OMAP_OSK_MISTRAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/* For now, all system indicators require the Mistral board, since that
28 * LED can be manipulated without a task context. This LED is either red,
29 * or green, but not both; it can't give the full "disco led" effect.
30 */
31
32#define GPIO_LED_RED 3
33#define GPIO_LED_GREEN OMAP_MPUIO(4)
34
35static void mistral_setled(void)
36{
37 int red = 0;
38 int green = 0;
39
40 if (hw_led_state & TIMER_LED)
41 red = 1;
42 else if (hw_led_state & IDLE_LED)
43 green = 1;
David Cohen6e2d4102007-12-13 22:27:15 -040044 /* else both sides are disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
David Brownell0b84b5c2008-12-10 17:35:25 -080046 gpio_set_value(GPIO_LED_GREEN, green);
47 gpio_set_value(GPIO_LED_RED, red);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
50#endif
51
52void osk_leds_event(led_event_t evt)
53{
54 unsigned long flags;
55 u16 leds;
56
57 local_irq_save(flags);
58
59 if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
60 goto done;
61
62 leds = hw_led_state;
63 switch (evt) {
64 case led_start:
65 led_state |= LED_STATE_ENABLED;
66 hw_led_state = 0;
67 leds = ~0;
68 break;
69
70 case led_halted:
71 case led_stop:
72 led_state &= ~LED_STATE_ENABLED;
73 hw_led_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 break;
75
76 case led_claim:
77 led_state |= LED_STATE_CLAIMED;
78 hw_led_state = 0;
79 leds = ~0;
80 break;
81
82 case led_release:
83 led_state &= ~LED_STATE_CLAIMED;
84 hw_led_state = 0;
85 break;
86
Tony Lindgren7c38cf02005-09-08 23:07:38 +010087#ifdef CONFIG_OMAP_OSK_MISTRAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 case led_timer:
90 hw_led_state ^= TIMER_LED;
91 mistral_setled();
92 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
David Brownelleebdf7d72007-04-02 12:48:10 -070094 case led_idle_start: /* idle == off */
95 hw_led_state &= ~IDLE_LED;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 mistral_setled();
97 break;
98
99 case led_idle_end:
David Brownelleebdf7d72007-04-02 12:48:10 -0700100 hw_led_state |= IDLE_LED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 mistral_setled();
102 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100104#endif /* CONFIG_OMAP_OSK_MISTRAL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 default:
107 break;
108 }
109
110 leds ^= hw_led_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112done:
113 local_irq_restore(flags);
114}