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/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
14 #include <linux/leds.h>
16 #include <linux/module.h>
20 struct led_classdev cdev
;
27 * The device has three leds on the back panel (led_err, led_init and led_run)
28 * and can handle up to seven leds on the front panel.
31 static struct ot200_led leds
[] = {
84 static DEFINE_SPINLOCK(value_lock
);
87 * we need to store the current led states, as it is not
88 * possible to read the current led state via inb().
93 static void ot200_led_brightness_set(struct led_classdev
*led_cdev
,
94 enum led_brightness value
)
96 struct ot200_led
*led
= container_of(led_cdev
, struct ot200_led
, cdev
);
100 spin_lock_irqsave(&value_lock
, flags
);
102 if (led
->port
== 0x49)
104 else if (led
->port
== 0x5a)
109 if (value
== LED_OFF
)
114 outb(*val
, led
->port
);
115 spin_unlock_irqrestore(&value_lock
, flags
);
118 static int __devinit
ot200_led_probe(struct platform_device
*pdev
)
123 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++) {
125 leds
[i
].cdev
.name
= leds
[i
].name
;
126 leds
[i
].cdev
.brightness_set
= ot200_led_brightness_set
;
128 ret
= led_classdev_register(&pdev
->dev
, &leds
[i
].cdev
);
133 leds_front
= 0; /* turn off all front leds */
134 leds_back
= BIT(1); /* turn on init led */
135 outb(leds_front
, 0x49);
136 outb(leds_back
, 0x5a);
141 for (i
= i
- 1; i
>= 0; i
--)
142 led_classdev_unregister(&leds
[i
].cdev
);
147 static int __devexit
ot200_led_remove(struct platform_device
*pdev
)
151 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++)
152 led_classdev_unregister(&leds
[i
].cdev
);
157 static struct platform_driver ot200_led_driver
= {
158 .probe
= ot200_led_probe
,
159 .remove
= __devexit_p(ot200_led_remove
),
161 .name
= "leds-ot200",
162 .owner
= THIS_MODULE
,
166 module_platform_driver(ot200_led_driver
);
168 MODULE_AUTHOR("Sebastian A. Siewior <bigeasy@linutronix.de>");
169 MODULE_DESCRIPTION("ot200 LED driver");
170 MODULE_LICENSE("GPL");
171 MODULE_ALIAS("platform:leds-ot200");