2 * linux/arch/arm/plat-omap/debug-leds.c
4 * Copyright 2003 by Texas Instruments Incorporated
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/leds.h>
16 #include <mach/hardware.h>
18 #include <asm/system.h>
19 #include <asm/mach-types.h>
21 #include <mach/fpga.h>
22 #include <mach/gpio.h>
25 /* Many OMAP development platforms reuse the same "debug board"; these
26 * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
27 * debug board (all green), accessed through FPGA registers.
29 * The "surfer" expansion board and H2 sample board also have two-color
30 * green+red LEDs (in parallel), used here for timer and idle indicators
31 * in preference to the ones on the debug board, for a "Disco LED" effect.
33 * This driver exports either the original ARM LED API, the new generic
37 static spinlock_t lock;
38 static struct h2p2_dbg_fpga __iomem *fpga;
39 static u16 led_state, hw_led_state;
42 #ifdef CONFIG_LEDS_OMAP_DEBUG
43 #define new_led_api() 1
45 #define new_led_api() 0
49 /*-------------------------------------------------------------------------*/
51 /* original ARM debug LED API:
52 * - timer and idle leds (some boards use non-FPGA leds here);
53 * - up to 4 generic leds, easily accessed in-kernel (any context)
56 #define GPIO_LED_RED 3
57 #define GPIO_LED_GREEN OMAP_MPUIO(4)
59 #define LED_STATE_ENABLED 0x01
60 #define LED_STATE_CLAIMED 0x02
61 #define LED_TIMER_ON 0x04
63 #define GPIO_IDLE GPIO_LED_GREEN
64 #define GPIO_TIMER GPIO_LED_RED
66 static void h2p2_dbg_leds_event(led_event_t evt)
70 spin_lock_irqsave(&lock, flags);
72 if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
78 led_state |= LED_STATE_ENABLED;
83 /* all leds off during suspend or shutdown */
85 if (!(machine_is_omap_perseus2() || machine_is_omap_h4())) {
86 omap_set_gpio_dataout(GPIO_TIMER, 0);
87 omap_set_gpio_dataout(GPIO_IDLE, 0);
90 __raw_writew(~0, &fpga->leds);
91 led_state &= ~LED_STATE_ENABLED;
95 led_state |= LED_STATE_CLAIMED;
100 led_state &= ~LED_STATE_CLAIMED;
103 #ifdef CONFIG_LEDS_TIMER
105 led_state ^= LED_TIMER_ON;
107 if (machine_is_omap_perseus2() || machine_is_omap_h4())
108 hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER;
110 omap_set_gpio_dataout(GPIO_TIMER,
111 led_state & LED_TIMER_ON);
118 #ifdef CONFIG_LEDS_CPU
119 /* LED lit iff busy */
121 if (machine_is_omap_perseus2() || machine_is_omap_h4())
122 hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE;
124 omap_set_gpio_dataout(GPIO_IDLE, 1);
131 if (machine_is_omap_perseus2() || machine_is_omap_h4())
132 hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE;
134 omap_set_gpio_dataout(GPIO_IDLE, 0);
142 hw_led_state |= H2P2_DBG_FPGA_LED_GREEN;
145 hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN;
149 hw_led_state |= H2P2_DBG_FPGA_LED_AMBER;
152 hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER;
156 hw_led_state |= H2P2_DBG_FPGA_LED_RED;
159 hw_led_state &= ~H2P2_DBG_FPGA_LED_RED;
163 hw_led_state |= H2P2_DBG_FPGA_LED_BLUE;
166 hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE;
175 * Actually burn the LEDs
177 if (led_state & LED_STATE_ENABLED)
178 __raw_writew(~hw_led_state, &fpga->leds);
181 spin_unlock_irqrestore(&lock, flags);
184 /*-------------------------------------------------------------------------*/
187 * - with syfs access and generic triggering
188 * - not readily accessible to in-kernel drivers
192 struct led_classdev cdev;
196 static struct dbg_led dbg_leds[] = {
197 /* REVISIT at least H2 uses different timer & cpu leds... */
198 #ifndef CONFIG_LEDS_TIMER
199 { .mask = 1 << 0, .cdev.name = "d4:green",
200 .cdev.default_trigger = "heartbeat", },
202 #ifndef CONFIG_LEDS_CPU
203 { .mask = 1 << 1, .cdev.name = "d5:green", }, /* !idle */
205 { .mask = 1 << 2, .cdev.name = "d6:green", },
206 { .mask = 1 << 3, .cdev.name = "d7:green", },
208 { .mask = 1 << 4, .cdev.name = "d8:green", },
209 { .mask = 1 << 5, .cdev.name = "d9:green", },
210 { .mask = 1 << 6, .cdev.name = "d10:green", },
211 { .mask = 1 << 7, .cdev.name = "d11:green", },
213 { .mask = 1 << 8, .cdev.name = "d12:green", },
214 { .mask = 1 << 9, .cdev.name = "d13:green", },
215 { .mask = 1 << 10, .cdev.name = "d14:green", },
216 { .mask = 1 << 11, .cdev.name = "d15:green", },
219 { .mask = 1 << 12, .cdev.name = "d16:green", },
220 { .mask = 1 << 13, .cdev.name = "d17:green", },
221 { .mask = 1 << 14, .cdev.name = "d18:green", },
222 { .mask = 1 << 15, .cdev.name = "d19:green", },
227 fpga_led_set(struct led_classdev *cdev, enum led_brightness value)
229 struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
232 spin_lock_irqsave(&lock, flags);
233 if (value == LED_OFF)
234 hw_led_state &= ~led->mask;
236 hw_led_state |= led->mask;
237 __raw_writew(~hw_led_state, &fpga->leds);
238 spin_unlock_irqrestore(&lock, flags);
241 static void __init newled_init(struct device *dev)
247 for (i = 0, led = dbg_leds; i < ARRAY_SIZE(dbg_leds); i++, led++) {
248 led->cdev.brightness_set = fpga_led_set;
249 status = led_classdev_register(dev, &led->cdev);
257 /*-------------------------------------------------------------------------*/
259 static int /* __init */ fpga_probe(struct platform_device *pdev)
261 struct resource *iomem;
263 spin_lock_init(&lock);
265 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
269 fpga = ioremap(iomem->start, H2P2_DBG_FPGA_SIZE);
270 __raw_writew(~0, &fpga->leds);
273 leds_event = h2p2_dbg_leds_event;
274 leds_event(led_start);
278 newled_init(&pdev->dev);
284 static int fpga_suspend_late(struct platform_device *pdev, pm_message_t mesg)
286 __raw_writew(~0, &fpga->leds);
290 static int fpga_resume_early(struct platform_device *pdev)
292 __raw_writew(~hw_led_state, &fpga->leds);
297 static struct platform_driver led_driver = {
298 .driver.name = "omap_dbg_led",
300 .suspend_late = fpga_suspend_late,
301 .resume_early = fpga_resume_early,
304 static int __init fpga_init(void)
306 if (machine_is_omap_h4()
307 || machine_is_omap_h3()
308 || machine_is_omap_h2()
309 || machine_is_omap_perseus2()
311 return platform_driver_register(&led_driver);
314 fs_initcall(fpga_init);