2 * Bachmann ot200 leds driver.
4 * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
5 * Christian Gmeiner <christian.gmeiner@gmail.com>
7 * License: GPL as published by the FSF.
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/slab.h>
13 #include <linux/leds.h>
15 #include <linux/module.h>
19 struct led_classdev cdev
;
26 * The device has three leds on the back panel (led_err, led_init and led_run)
27 * and can handle up to seven leds on the front panel.
30 static struct ot200_led leds
[] = {
83 static DEFINE_SPINLOCK(value_lock
);
86 * we need to store the current led states, as it is not
87 * possible to read the current led state via inb().
92 static void ot200_led_brightness_set(struct led_classdev
*led_cdev
,
93 enum led_brightness value
)
95 struct ot200_led
*led
= container_of(led_cdev
, struct ot200_led
, cdev
);
99 spin_lock_irqsave(&value_lock
, flags
);
101 if (led
->port
== 0x49)
103 else if (led
->port
== 0x5a)
108 if (value
== LED_OFF
)
113 outb(*val
, led
->port
);
114 spin_unlock_irqrestore(&value_lock
, flags
);
117 static int ot200_led_probe(struct platform_device
*pdev
)
122 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++) {
124 leds
[i
].cdev
.name
= leds
[i
].name
;
125 leds
[i
].cdev
.brightness_set
= ot200_led_brightness_set
;
127 ret
= led_classdev_register(&pdev
->dev
, &leds
[i
].cdev
);
132 leds_front
= 0; /* turn off all front leds */
133 leds_back
= BIT(1); /* turn on init led */
134 outb(leds_front
, 0x49);
135 outb(leds_back
, 0x5a);
140 for (i
= i
- 1; i
>= 0; i
--)
141 led_classdev_unregister(&leds
[i
].cdev
);
146 static int ot200_led_remove(struct platform_device
*pdev
)
150 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++)
151 led_classdev_unregister(&leds
[i
].cdev
);
156 static struct platform_driver ot200_led_driver
= {
157 .probe
= ot200_led_probe
,
158 .remove
= ot200_led_remove
,
160 .name
= "leds-ot200",
164 module_platform_driver(ot200_led_driver
);
166 MODULE_AUTHOR("Sebastian A. Siewior <bigeasy@linutronix.de>");
167 MODULE_DESCRIPTION("ot200 LED driver");
168 MODULE_LICENSE("GPL");
169 MODULE_ALIAS("platform:leds-ot200");