Pull release into acpica branch
[pandora-kernel.git] / arch / arm / mach-omap1 / leds-h2p2-debug.c
1 /*
2  * linux/arch/arm/mach-omap1/leds-h2p2-debug.c
3  *
4  * Copyright 2003 by Texas Instruments Incorporated
5  *
6  * There are 16 LEDs on the debug board (all green); four may be used
7  * for logical 'green', 'amber', 'red', and 'blue' (after "claiming").
8  *
9  * The "surfer" expansion board and H2 sample board also have two-color
10  * green+red LEDs (in parallel), used here for timer and idle indicators.
11  */
12 #include <linux/config.h>
13 #include <linux/init.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/sched.h>
16
17 #include <asm/io.h>
18 #include <asm/hardware.h>
19 #include <asm/leds.h>
20 #include <asm/system.h>
21 #include <asm/mach-types.h>
22
23 #include <asm/arch/fpga.h>
24 #include <asm/arch/gpio.h>
25
26 #include "leds.h"
27
28
29 #define GPIO_LED_RED            3
30 #define GPIO_LED_GREEN          OMAP_MPUIO(4)
31
32
33 #define LED_STATE_ENABLED       0x01
34 #define LED_STATE_CLAIMED       0x02
35 #define LED_TIMER_ON            0x04
36
37 #define GPIO_IDLE               GPIO_LED_GREEN
38 #define GPIO_TIMER              GPIO_LED_RED
39
40
41 void h2p2_dbg_leds_event(led_event_t evt)
42 {
43         unsigned long flags;
44
45         static struct h2p2_dbg_fpga __iomem *fpga;
46         static u16 led_state, hw_led_state;
47
48         local_irq_save(flags);
49
50         if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
51                 goto done;
52
53         switch (evt) {
54         case led_start:
55                 if (!fpga)
56                         fpga = ioremap(H2P2_DBG_FPGA_START,
57                                                 H2P2_DBG_FPGA_SIZE);
58                 if (fpga) {
59                         led_state |= LED_STATE_ENABLED;
60                         __raw_writew(~0, &fpga->leds);
61                 }
62                 break;
63
64         case led_stop:
65         case led_halted:
66                 /* all leds off during suspend or shutdown */
67
68                 if (! machine_is_omap_perseus2()) {
69                         omap_set_gpio_dataout(GPIO_TIMER, 0);
70                         omap_set_gpio_dataout(GPIO_IDLE, 0);
71                 }
72
73                 __raw_writew(~0, &fpga->leds);
74                 led_state &= ~LED_STATE_ENABLED;
75                 if (evt == led_halted) {
76                         iounmap(fpga);
77                         fpga = NULL;
78                 }
79
80                 goto done;
81
82         case led_claim:
83                 led_state |= LED_STATE_CLAIMED;
84                 hw_led_state = 0;
85                 break;
86
87         case led_release:
88                 led_state &= ~LED_STATE_CLAIMED;
89                 break;
90
91 #ifdef CONFIG_LEDS_TIMER
92         case led_timer:
93                 led_state ^= LED_TIMER_ON;
94
95                 if (machine_is_omap_perseus2())
96                         hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER;
97                 else {
98                         omap_set_gpio_dataout(GPIO_TIMER, led_state & LED_TIMER_ON);
99                         goto done;
100                 }
101
102                 break;
103 #endif
104
105 #ifdef CONFIG_LEDS_CPU
106         case led_idle_start:
107                 if (machine_is_omap_perseus2())
108                         hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE;
109                 else {
110                         omap_set_gpio_dataout(GPIO_IDLE, 1);
111                         goto done;
112                 }
113
114                 break;
115
116         case led_idle_end:
117                 if (machine_is_omap_perseus2())
118                         hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE;
119                 else {
120                         omap_set_gpio_dataout(GPIO_IDLE, 0);
121                         goto done;
122                 }
123
124                 break;
125 #endif
126
127         case led_green_on:
128                 hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
129                 break;
130         case led_green_off:
131                 hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
132                 break;
133
134         case led_amber_on:
135                 hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
136                 break;
137         case led_amber_off:
138                 hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
139                 break;
140
141         case led_red_on:
142                 hw_led_state |= H2P2_DBG_FPGA_LED_RED;
143                 break;
144         case led_red_off:
145                 hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
146                 break;
147
148         case led_blue_on:
149                 hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
150                 break;
151         case led_blue_off:
152                 hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
153                 break;
154
155         default:
156                 break;
157         }
158
159
160         /*
161          *  Actually burn the LEDs
162          */
163         if (led_state & LED_STATE_ENABLED)
164                 __raw_writew(~hw_led_state, &fpga->leds);
165
166 done:
167         local_irq_restore(flags);
168 }