Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-omap / leds-h2p2-debug.c
blob6e98290cca5ca3cc41b1f4bf3b0527618858e88a
1 /*
2 * linux/arch/arm/mach-omap/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/config.h>
13 #include <linux/init.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/sched.h>
16 #include <linux/version.h>
18 #include <asm/io.h>
19 #include <asm/hardware.h>
20 #include <asm/leds.h>
21 #include <asm/system.h>
23 #include <asm/arch/fpga.h>
24 #include <asm/arch/gpio.h>
26 #include "leds.h"
29 #define GPIO_LED_RED 3
30 #define GPIO_LED_GREEN OMAP_MPUIO(4)
33 #define LED_STATE_ENABLED 0x01
34 #define LED_STATE_CLAIMED 0x02
35 #define LED_TIMER_ON 0x04
37 #define GPIO_IDLE GPIO_LED_GREEN
38 #define GPIO_TIMER GPIO_LED_RED
41 void h2p2_dbg_leds_event(led_event_t evt)
43 unsigned long flags;
45 static struct h2p2_dbg_fpga __iomem *fpga;
46 static u16 led_state, hw_led_state;
48 local_irq_save(flags);
50 if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
51 goto done;
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);
62 break;
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;
75 goto done;
77 case led_claim:
78 led_state |= LED_STATE_CLAIMED;
79 hw_led_state = 0;
80 break;
82 case led_release:
83 led_state &= ~LED_STATE_CLAIMED;
84 break;
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
93 #ifdef CONFIG_LEDS_CPU
94 case led_idle_start:
95 omap_set_gpio_dataout(GPIO_IDLE, 1);
96 goto done;
98 case led_idle_end:
99 omap_set_gpio_dataout(GPIO_IDLE, 0);
100 goto done;
101 #endif
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;
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;
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;
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;
131 default:
132 break;
137 * Actually burn the LEDs
139 if (led_state & LED_STATE_CLAIMED)
140 __raw_writew(~hw_led_state, &fpga->leds);
142 done:
143 local_irq_restore(flags);