1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/plat-omap/debug-leds.c
5 * Copyright 2011 by Bryan Wu <bryan.wu@canonical.com>
6 * Copyright 2003 by Texas Instruments Incorporated
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/leds.h>
14 #include <linux/platform_data/gpio-omap.h>
15 #include <linux/slab.h>
17 #include <asm/mach-types.h>
19 /* Many OMAP development platforms reuse the same "debug board"; these
20 * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
21 * debug board (all green), accessed through FPGA registers.
24 /* NOTE: most boards don't have a static mapping for the FPGA ... */
25 struct h2p2_dbg_fpga
{
41 /* plus also 4 rs232 ports ... */
44 static struct h2p2_dbg_fpga __iomem
*fpga
;
46 static u16 fpga_led_state
;
49 struct led_classdev cdev
;
57 { "dbg:d4", "heartbeat", },
58 { "dbg:d5", "cpu0", },
59 { "dbg:d6", "default-on", },
76 * The triggers lines up below will only be used if the
77 * LED triggers are compiled in.
79 static void dbg_led_set(struct led_classdev
*cdev
,
80 enum led_brightness b
)
82 struct dbg_led
*led
= container_of(cdev
, struct dbg_led
, cdev
);
85 reg
= readw_relaxed(&fpga
->leds
);
90 writew_relaxed(reg
, &fpga
->leds
);
93 static enum led_brightness
dbg_led_get(struct led_classdev
*cdev
)
95 struct dbg_led
*led
= container_of(cdev
, struct dbg_led
, cdev
);
98 reg
= readw_relaxed(&fpga
->leds
);
99 return (reg
& led
->mask
) ? LED_FULL
: LED_OFF
;
102 static int fpga_probe(struct platform_device
*pdev
)
104 struct resource
*iomem
;
107 iomem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
111 fpga
= ioremap(iomem
->start
, resource_size(iomem
));
112 writew_relaxed(0xff, &fpga
->leds
);
114 for (i
= 0; i
< ARRAY_SIZE(dbg_leds
); i
++) {
117 led
= kzalloc(sizeof(*led
), GFP_KERNEL
);
121 led
->cdev
.name
= dbg_leds
[i
].name
;
122 led
->cdev
.brightness_set
= dbg_led_set
;
123 led
->cdev
.brightness_get
= dbg_led_get
;
124 led
->cdev
.default_trigger
= dbg_leds
[i
].trigger
;
127 if (led_classdev_register(NULL
, &led
->cdev
) < 0) {
136 static int fpga_suspend_noirq(struct device
*dev
)
138 fpga_led_state
= readw_relaxed(&fpga
->leds
);
139 writew_relaxed(0xff, &fpga
->leds
);
144 static int fpga_resume_noirq(struct device
*dev
)
146 writew_relaxed(~fpga_led_state
, &fpga
->leds
);
150 static const struct dev_pm_ops fpga_dev_pm_ops
= {
151 .suspend_noirq
= fpga_suspend_noirq
,
152 .resume_noirq
= fpga_resume_noirq
,
155 static struct platform_driver led_driver
= {
156 .driver
.name
= "omap_dbg_led",
157 .driver
.pm
= &fpga_dev_pm_ops
,
161 static int __init
fpga_init(void)
163 if (machine_is_omap_h4()
164 || machine_is_omap_h3()
165 || machine_is_omap_h2()
166 || machine_is_omap_perseus2()
168 return platform_driver_register(&led_driver
);
171 fs_initcall(fpga_init
);