Linux-2.6.12-rc2
[linux-2.6.git] / arch / arm / mach-omap / leds-h2p2-debug.c
1 /*
2  * linux/arch/arm/mach-omap/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 #include <linux/version.h>
17
18 #include <asm/io.h>
19 #include <asm/hardware.h>
20 #include <asm/leds.h>
21 #include <asm/system.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                 omap_set_gpio_dataout(GPIO_TIMER, 0);
68                 omap_set_gpio_dataout(GPIO_IDLE, 0);
69                 __raw_writew(~0, &fpga->leds);
70                 led_state &= ~LED_STATE_ENABLED;
71                 if (evt == led_halted) {
72                         iounmap(fpga);
73                         fpga = NULL;
74                 }
75                 goto done;
76
77         case led_claim:
78                 led_state |= LED_STATE_CLAIMED;
79                 hw_led_state = 0;
80                 break;
81
82         case led_release:
83                 led_state &= ~LED_STATE_CLAIMED;
84                 break;
85
86 #ifdef CONFIG_LEDS_TIMER
87         case led_timer:
88                 led_state ^= LED_TIMER_ON;
89                 omap_set_gpio_dataout(GPIO_TIMER, led_state & LED_TIMER_ON);
90                 goto done;
91 #endif
92
93 #ifdef CONFIG_LEDS_CPU
94         case led_idle_start:
95                 omap_set_gpio_dataout(GPIO_IDLE, 1);
96                 goto done;
97
98         case led_idle_end:
99                 omap_set_gpio_dataout(GPIO_IDLE, 0);
100                 goto done;
101 #endif
102
103         case led_green_on:
104                 hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
105                 break;
106         case led_green_off:
107                 hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
108                 break;
109
110         case led_amber_on:
111                 hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
112                 break;
113         case led_amber_off:
114                 hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
115                 break;
116
117         case led_red_on:
118                 hw_led_state |= H2P2_DBG_FPGA_LED_RED;
119                 break;
120         case led_red_off:
121                 hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
122                 break;
123
124         case led_blue_on:
125                 hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
126                 break;
127         case led_blue_off:
128                 hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
129                 break;
130
131         default:
132                 break;
133         }
134
135
136         /*
137          *  Actually burn the LEDs
138          */
139         if (led_state & LED_STATE_CLAIMED)
140                 __raw_writew(~hw_led_state, &fpga->leds);
141
142 done:
143         local_irq_restore(flags);
144 }