2 * linux/arch/arm/plat-omap/debug-leds.c
4 * Copyright 2011 by Bryan Wu <bryan.wu@canonical.com>
5 * Copyright 2003 by Texas Instruments Incorporated
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/leds.h>
17 #include <linux/platform_data/gpio-omap.h>
18 #include <linux/slab.h>
20 #include <mach/hardware.h>
21 #include <asm/mach-types.h>
23 #include <plat/fpga.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.
30 static struct h2p2_dbg_fpga __iomem *fpga;
32 static u16 fpga_led_state;
35 struct led_classdev cdev;
43 { "dbg:d4", "heartbeat", },
44 { "dbg:d5", "cpu0", },
45 { "dbg:d6", "default-on", },
62 * The triggers lines up below will only be used if the
63 * LED triggers are compiled in.
65 static void dbg_led_set(struct led_classdev *cdev,
66 enum led_brightness b)
68 struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
71 reg = __raw_readw(&fpga->leds);
76 __raw_writew(reg, &fpga->leds);
79 static enum led_brightness dbg_led_get(struct led_classdev *cdev)
81 struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
84 reg = __raw_readw(&fpga->leds);
85 return (reg & led->mask) ? LED_FULL : LED_OFF;
88 static int fpga_probe(struct platform_device *pdev)
90 struct resource *iomem;
93 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 fpga = ioremap(iomem->start, H2P2_DBG_FPGA_SIZE);
98 __raw_writew(0xff, &fpga->leds);
100 for (i = 0; i < ARRAY_SIZE(dbg_leds); i++) {
103 led = kzalloc(sizeof(*led), GFP_KERNEL);
107 led->cdev.name = dbg_leds[i].name;
108 led->cdev.brightness_set = dbg_led_set;
109 led->cdev.brightness_get = dbg_led_get;
110 led->cdev.default_trigger = dbg_leds[i].trigger;
113 if (led_classdev_register(NULL, &led->cdev) < 0) {
122 static int fpga_suspend_noirq(struct device *dev)
124 fpga_led_state = __raw_readw(&fpga->leds);
125 __raw_writew(0xff, &fpga->leds);
130 static int fpga_resume_noirq(struct device *dev)
132 __raw_writew(~fpga_led_state, &fpga->leds);
136 static const struct dev_pm_ops fpga_dev_pm_ops = {
137 .suspend_noirq = fpga_suspend_noirq,
138 .resume_noirq = fpga_resume_noirq,
141 static struct platform_driver led_driver = {
142 .driver.name = "omap_dbg_led",
143 .driver.pm = &fpga_dev_pm_ops,
147 static int __init fpga_init(void)
149 if (machine_is_omap_h4()
150 || machine_is_omap_h3()
151 || machine_is_omap_h2()
152 || machine_is_omap_perseus2()
154 return platform_driver_register(&led_driver);
157 fs_initcall(fpga_init);