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 <asm/mach-types.h>
22 /* Many OMAP development platforms reuse the same "debug board"; these
23 * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
24 * debug board (all green), accessed through FPGA registers.
27 /* NOTE: most boards don't have a static mapping for the FPGA ... */
28 struct h2p2_dbg_fpga
{
44 /* plus also 4 rs232 ports ... */
47 static struct h2p2_dbg_fpga __iomem
*fpga
;
49 static u16 fpga_led_state
;
52 struct led_classdev cdev
;
60 { "dbg:d4", "heartbeat", },
61 { "dbg:d5", "cpu0", },
62 { "dbg:d6", "default-on", },
79 * The triggers lines up below will only be used if the
80 * LED triggers are compiled in.
82 static void dbg_led_set(struct led_classdev
*cdev
,
83 enum led_brightness b
)
85 struct dbg_led
*led
= container_of(cdev
, struct dbg_led
, cdev
);
88 reg
= readw_relaxed(&fpga
->leds
);
93 writew_relaxed(reg
, &fpga
->leds
);
96 static enum led_brightness
dbg_led_get(struct led_classdev
*cdev
)
98 struct dbg_led
*led
= container_of(cdev
, struct dbg_led
, cdev
);
101 reg
= readw_relaxed(&fpga
->leds
);
102 return (reg
& led
->mask
) ? LED_FULL
: LED_OFF
;
105 static int fpga_probe(struct platform_device
*pdev
)
107 struct resource
*iomem
;
110 iomem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
114 fpga
= ioremap(iomem
->start
, resource_size(iomem
));
115 writew_relaxed(0xff, &fpga
->leds
);
117 for (i
= 0; i
< ARRAY_SIZE(dbg_leds
); i
++) {
120 led
= kzalloc(sizeof(*led
), GFP_KERNEL
);
124 led
->cdev
.name
= dbg_leds
[i
].name
;
125 led
->cdev
.brightness_set
= dbg_led_set
;
126 led
->cdev
.brightness_get
= dbg_led_get
;
127 led
->cdev
.default_trigger
= dbg_leds
[i
].trigger
;
130 if (led_classdev_register(NULL
, &led
->cdev
) < 0) {
139 static int fpga_suspend_noirq(struct device
*dev
)
141 fpga_led_state
= readw_relaxed(&fpga
->leds
);
142 writew_relaxed(0xff, &fpga
->leds
);
147 static int fpga_resume_noirq(struct device
*dev
)
149 writew_relaxed(~fpga_led_state
, &fpga
->leds
);
153 static const struct dev_pm_ops fpga_dev_pm_ops
= {
154 .suspend_noirq
= fpga_suspend_noirq
,
155 .resume_noirq
= fpga_resume_noirq
,
158 static struct platform_driver led_driver
= {
159 .driver
.name
= "omap_dbg_led",
160 .driver
.pm
= &fpga_dev_pm_ops
,
164 static int __init
fpga_init(void)
166 if (machine_is_omap_h4()
167 || machine_is_omap_h3()
168 || machine_is_omap_h2()
169 || machine_is_omap_perseus2()
171 return platform_driver_register(&led_driver
);
174 fs_initcall(fpga_init
);