Merge head 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/shaggy/jfs-2.6
[linux-2.6] / arch / arm / mach-omap1 / 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
17 #include <asm/io.h>
18 #include <asm/hardware.h>
19 #include <asm/leds.h>
20 #include <asm/system.h>
21
22 #include <asm/arch/fpga.h>
23 #include <asm/arch/gpio.h>
24
25 #include "leds.h"
26
27
28 #define GPIO_LED_RED            3
29 #define GPIO_LED_GREEN          OMAP_MPUIO(4)
30
31
32 #define LED_STATE_ENABLED       0x01
33 #define LED_STATE_CLAIMED       0x02
34 #define LED_TIMER_ON            0x04
35
36 #define GPIO_IDLE               GPIO_LED_GREEN
37 #define GPIO_TIMER              GPIO_LED_RED
38
39
40 void h2p2_dbg_leds_event(led_event_t evt)
41 {
42         unsigned long flags;
43
44         static struct h2p2_dbg_fpga __iomem *fpga;
45         static u16 led_state, hw_led_state;
46
47         local_irq_save(flags);
48
49         if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
50                 goto done;
51
52         switch (evt) {
53         case led_start:
54                 if (!fpga)
55                         fpga = ioremap(H2P2_DBG_FPGA_START,
56                                                 H2P2_DBG_FPGA_SIZE);
57                 if (fpga) {
58                         led_state |= LED_STATE_ENABLED;
59                         __raw_writew(~0, &fpga->leds);
60                 }
61                 break;
62
63         case led_stop:
64         case led_halted:
65                 /* all leds off during suspend or shutdown */
66                 omap_set_gpio_dataout(GPIO_TIMER, 0);
67                 omap_set_gpio_dataout(GPIO_IDLE, 0);
68                 __raw_writew(~0, &fpga->leds);
69                 led_state &= ~LED_STATE_ENABLED;
70                 if (evt == led_halted) {
71                         iounmap(fpga);
72                         fpga = NULL;
73                 }
74                 goto done;
75
76         case led_claim:
77                 led_state |= LED_STATE_CLAIMED;
78                 hw_led_state = 0;
79                 break;
80
81         case led_release:
82                 led_state &= ~LED_STATE_CLAIMED;
83                 break;
84
85 #ifdef CONFIG_LEDS_TIMER
86         case led_timer:
87                 led_state ^= LED_TIMER_ON;
88                 omap_set_gpio_dataout(GPIO_TIMER, led_state & LED_TIMER_ON);
89                 goto done;
90 #endif
91
92 #ifdef CONFIG_LEDS_CPU
93         case led_idle_start:
94                 omap_set_gpio_dataout(GPIO_IDLE, 1);
95                 goto done;
96
97         case led_idle_end:
98                 omap_set_gpio_dataout(GPIO_IDLE, 0);
99                 goto done;
100 #endif
101
102         case led_green_on:
103                 hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
104                 break;
105         case led_green_off:
106                 hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
107                 break;
108
109         case led_amber_on:
110                 hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
111                 break;
112         case led_amber_off:
113                 hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
114                 break;
115
116         case led_red_on:
117                 hw_led_state |= H2P2_DBG_FPGA_LED_RED;
118                 break;
119         case led_red_off:
120                 hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
121                 break;
122
123         case led_blue_on:
124                 hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
125                 break;
126         case led_blue_off:
127                 hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
128                 break;
129
130         default:
131                 break;
132         }
133
134
135         /*
136          *  Actually burn the LEDs
137          */
138         if (led_state & LED_STATE_CLAIMED)
139                 __raw_writew(~hw_led_state, &fpga->leds);
140
141 done:
142         local_irq_restore(flags);
143 }