x86, MCE, AMD: Disable error thresholding bank 4 on some models
[linux-2.6.git] / drivers / leds / leds-ot200.c
blobc4646825a620bb31940cd02e64d1ac753a08d0b0
1 /*
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.
8 */
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>
15 #include <linux/io.h>
16 #include <linux/module.h>
19 struct ot200_led {
20 struct led_classdev cdev;
21 const char *name;
22 unsigned long port;
23 u8 mask;
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[] = {
33 .name = "led_run",
34 .port = 0x5a,
35 .mask = BIT(0),
38 .name = "led_init",
39 .port = 0x5a,
40 .mask = BIT(1),
43 .name = "led_err",
44 .port = 0x5a,
45 .mask = BIT(2),
48 .name = "led_1",
49 .port = 0x49,
50 .mask = BIT(7),
53 .name = "led_2",
54 .port = 0x49,
55 .mask = BIT(6),
58 .name = "led_3",
59 .port = 0x49,
60 .mask = BIT(5),
63 .name = "led_4",
64 .port = 0x49,
65 .mask = BIT(4),
68 .name = "led_5",
69 .port = 0x49,
70 .mask = BIT(3),
73 .name = "led_6",
74 .port = 0x49,
75 .mask = BIT(2),
78 .name = "led_7",
79 .port = 0x49,
80 .mask = BIT(1),
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().
90 static u8 leds_back;
91 static u8 leds_front;
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);
97 u8 *val;
98 unsigned long flags;
100 spin_lock_irqsave(&value_lock, flags);
102 if (led->port == 0x49)
103 val = &leds_front;
104 else if (led->port == 0x5a)
105 val = &leds_back;
106 else
107 BUG();
109 if (value == LED_OFF)
110 *val &= ~led->mask;
111 else
112 *val |= led->mask;
114 outb(*val, led->port);
115 spin_unlock_irqrestore(&value_lock, flags);
118 static int __devinit ot200_led_probe(struct platform_device *pdev)
120 int i;
121 int ret;
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);
129 if (ret < 0)
130 goto err;
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);
138 return 0;
140 err:
141 for (i = i - 1; i >= 0; i--)
142 led_classdev_unregister(&leds[i].cdev);
144 return ret;
147 static int __devexit ot200_led_remove(struct platform_device *pdev)
149 int i;
151 for (i = 0; i < ARRAY_SIZE(leds); i++)
152 led_classdev_unregister(&leds[i].cdev);
154 return 0;
157 static struct platform_driver ot200_led_driver = {
158 .probe = ot200_led_probe,
159 .remove = __devexit_p(ot200_led_remove),
160 .driver = {
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");