2 * LEDs driver for the Cobalt Raq series.
4 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <linux/init.h>
22 #include <linux/ioport.h>
23 #include <linux/leds.h>
24 #include <linux/platform_device.h>
25 #include <linux/spinlock.h>
26 #include <linux/types.h>
29 #define LED_POWER_OFF 0x08
31 static void __iomem *led_port;
33 static DEFINE_SPINLOCK(led_value_lock);
35 static void raq_web_led_set(struct led_classdev *led_cdev,
36 enum led_brightness brightness)
40 spin_lock_irqsave(&led_value_lock, flags);
45 led_value &= ~LED_WEB;
46 writeb(led_value, led_port);
48 spin_unlock_irqrestore(&led_value_lock, flags);
51 static struct led_classdev raq_web_led = {
53 .brightness_set = raq_web_led_set,
56 static void raq_power_off_led_set(struct led_classdev *led_cdev,
57 enum led_brightness brightness)
61 spin_lock_irqsave(&led_value_lock, flags);
64 led_value |= LED_POWER_OFF;
66 led_value &= ~LED_POWER_OFF;
67 writeb(led_value, led_port);
69 spin_unlock_irqrestore(&led_value_lock, flags);
72 static struct led_classdev raq_power_off_led = {
73 .name = "raq-power-off",
74 .brightness_set = raq_power_off_led_set,
75 .default_trigger = "power-off",
78 static int __devinit cobalt_raq_led_probe(struct platform_device *pdev)
83 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
87 led_port = ioremap(res->start, res->end - res->start + 1);
91 retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
95 retval = led_classdev_register(&pdev->dev, &raq_web_led);
102 led_classdev_unregister(&raq_power_off_led);
111 static int __devexit cobalt_raq_led_remove(struct platform_device *pdev)
113 led_classdev_unregister(&raq_power_off_led);
114 led_classdev_unregister(&raq_web_led);
124 static struct platform_driver cobalt_raq_led_driver = {
125 .probe = cobalt_raq_led_probe,
126 .remove = __devexit_p(cobalt_raq_led_remove),
128 .name = "cobalt-raq-leds",
129 .owner = THIS_MODULE,
133 static int __init cobalt_raq_led_init(void)
135 return platform_driver_register(&cobalt_raq_led_driver);
138 module_init(cobalt_raq_led_init);