block: move down direct IO plugging
[linux/fpc-iii.git] / arch / arm / mach-omap1 / leds-h2p2-debug.c
blobf6b14a14a95727c92dd697a7f7c63c9a8e4fda9a
1 /*
2 * linux/arch/arm/mach-omap1/leds-h2p2-debug.c
4 * Copyright 2003 by Texas Instruments Incorporated
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").
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.
12 #include <linux/gpio.h>
13 #include <linux/init.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/sched.h>
16 #include <linux/io.h>
18 #include <mach/hardware.h>
19 #include <asm/leds.h>
20 #include <asm/mach-types.h>
22 #include <plat/fpga.h>
24 #include "leds.h"
27 #define GPIO_LED_RED 3
28 #define GPIO_LED_GREEN OMAP_MPUIO(4)
31 #define LED_STATE_ENABLED 0x01
32 #define LED_STATE_CLAIMED 0x02
33 #define LED_TIMER_ON 0x04
35 #define GPIO_IDLE GPIO_LED_GREEN
36 #define GPIO_TIMER GPIO_LED_RED
39 void h2p2_dbg_leds_event(led_event_t evt)
41 unsigned long flags;
43 static struct h2p2_dbg_fpga __iomem *fpga;
44 static u16 led_state, hw_led_state;
46 local_irq_save(flags);
48 if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
49 goto done;
51 switch (evt) {
52 case led_start:
53 if (!fpga)
54 fpga = ioremap(H2P2_DBG_FPGA_START,
55 H2P2_DBG_FPGA_SIZE);
56 if (fpga) {
57 led_state |= LED_STATE_ENABLED;
58 __raw_writew(~0, &fpga->leds);
60 break;
62 case led_stop:
63 case led_halted:
64 /* all leds off during suspend or shutdown */
66 if (! machine_is_omap_perseus2()) {
67 gpio_set_value(GPIO_TIMER, 0);
68 gpio_set_value(GPIO_IDLE, 0);
71 __raw_writew(~0, &fpga->leds);
72 led_state &= ~LED_STATE_ENABLED;
73 if (evt == led_halted) {
74 iounmap(fpga);
75 fpga = NULL;
78 goto done;
80 case led_claim:
81 led_state |= LED_STATE_CLAIMED;
82 hw_led_state = 0;
83 break;
85 case led_release:
86 led_state &= ~LED_STATE_CLAIMED;
87 break;
89 #ifdef CONFIG_LEDS_TIMER
90 case led_timer:
91 led_state ^= LED_TIMER_ON;
93 if (machine_is_omap_perseus2())
94 hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER;
95 else {
96 gpio_set_value(GPIO_TIMER, led_state & LED_TIMER_ON);
97 goto done;
100 break;
101 #endif
103 #ifdef CONFIG_LEDS_CPU
104 case led_idle_start:
105 if (machine_is_omap_perseus2())
106 hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE;
107 else {
108 gpio_set_value(GPIO_IDLE, 1);
109 goto done;
112 break;
114 case led_idle_end:
115 if (machine_is_omap_perseus2())
116 hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE;
117 else {
118 gpio_set_value(GPIO_IDLE, 0);
119 goto done;
122 break;
123 #endif
125 case led_green_on:
126 hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
127 break;
128 case led_green_off:
129 hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
130 break;
132 case led_amber_on:
133 hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
134 break;
135 case led_amber_off:
136 hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
137 break;
139 case led_red_on:
140 hw_led_state |= H2P2_DBG_FPGA_LED_RED;
141 break;
142 case led_red_off:
143 hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
144 break;
146 case led_blue_on:
147 hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
148 break;
149 case led_blue_off:
150 hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
151 break;
153 default:
154 break;
159 * Actually burn the LEDs
161 if (led_state & LED_STATE_ENABLED)
162 __raw_writew(~hw_led_state, &fpga->leds);
164 done:
165 local_irq_restore(flags);