include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / drivers / leds / leds-cobalt-raq.c
blobaac1c073fe7bb20b018553c7e5c89e0fe084a8cc
1 /*
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>
21 #include <linux/io.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>
27 #include <linux/export.h>
29 #define LED_WEB 0x04
30 #define LED_POWER_OFF 0x08
32 static void __iomem *led_port;
33 static u8 led_value;
34 static DEFINE_SPINLOCK(led_value_lock);
36 static void raq_web_led_set(struct led_classdev *led_cdev,
37 enum led_brightness brightness)
39 unsigned long flags;
41 spin_lock_irqsave(&led_value_lock, flags);
43 if (brightness)
44 led_value |= LED_WEB;
45 else
46 led_value &= ~LED_WEB;
47 writeb(led_value, led_port);
49 spin_unlock_irqrestore(&led_value_lock, flags);
52 static struct led_classdev raq_web_led = {
53 .name = "raq::web",
54 .brightness_set = raq_web_led_set,
57 static void raq_power_off_led_set(struct led_classdev *led_cdev,
58 enum led_brightness brightness)
60 unsigned long flags;
62 spin_lock_irqsave(&led_value_lock, flags);
64 if (brightness)
65 led_value |= LED_POWER_OFF;
66 else
67 led_value &= ~LED_POWER_OFF;
68 writeb(led_value, led_port);
70 spin_unlock_irqrestore(&led_value_lock, flags);
73 static struct led_classdev raq_power_off_led = {
74 .name = "raq::power-off",
75 .brightness_set = raq_power_off_led_set,
76 .default_trigger = "power-off",
79 static int __devinit cobalt_raq_led_probe(struct platform_device *pdev)
81 struct resource *res;
82 int retval;
84 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
85 if (!res)
86 return -EBUSY;
88 led_port = ioremap(res->start, resource_size(res));
89 if (!led_port)
90 return -ENOMEM;
92 retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
93 if (retval)
94 goto err_iounmap;
96 retval = led_classdev_register(&pdev->dev, &raq_web_led);
97 if (retval)
98 goto err_unregister;
100 return 0;
102 err_unregister:
103 led_classdev_unregister(&raq_power_off_led);
105 err_iounmap:
106 iounmap(led_port);
107 led_port = NULL;
109 return retval;
112 static int __devexit cobalt_raq_led_remove(struct platform_device *pdev)
114 led_classdev_unregister(&raq_power_off_led);
115 led_classdev_unregister(&raq_web_led);
117 if (led_port) {
118 iounmap(led_port);
119 led_port = NULL;
122 return 0;
125 static struct platform_driver cobalt_raq_led_driver = {
126 .probe = cobalt_raq_led_probe,
127 .remove = __devexit_p(cobalt_raq_led_remove),
128 .driver = {
129 .name = "cobalt-raq-leds",
130 .owner = THIS_MODULE,
134 static int __init cobalt_raq_led_init(void)
136 return platform_driver_register(&cobalt_raq_led_driver);
139 module_init(cobalt_raq_led_init);