blob: 059aa2924b1cb21ba9fa36c7c3f4b441989e18b1 [file] [log] [blame]
Florian Fainelli2fea6f32007-02-12 23:16:27 +00001/*
2 * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
3 *
4 * Control the Cobalt Qube/RaQ front LED
5 */
Yoichi Yuasa4276fd72007-09-27 17:51:17 +09006#include <linux/init.h>
7#include <linux/io.h>
8#include <linux/ioport.h>
Florian Fainelli2fea6f32007-02-12 23:16:27 +00009#include <linux/leds.h>
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090010#include <linux/module.h>
11#include <linux/platform_device.h>
12#include <linux/types.h>
Florian Fainelli2fea6f32007-02-12 23:16:27 +000013
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090014#define LED_FRONT_LEFT 0x01
15#define LED_FRONT_RIGHT 0x02
16
17static void __iomem *led_port;
18static u8 led_value;
19
20static void qube_front_led_set(struct led_classdev *led_cdev,
Németh Márton4d404fd2008-03-09 20:59:57 +000021 enum led_brightness brightness)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000022{
23 if (brightness)
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090024 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000025 else
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090026 led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
27 writeb(led_value, led_port);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000028}
29
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090030static struct led_classdev qube_front_led = {
31 .name = "qube-front",
32 .brightness = LED_FULL,
33 .brightness_set = qube_front_led_set,
34 .default_trigger = "ide-disk",
Florian Fainelli2fea6f32007-02-12 23:16:27 +000035};
36
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090037static int __devinit cobalt_qube_led_probe(struct platform_device *pdev)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000038{
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090039 struct resource *res;
40 int retval;
41
42 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
43 if (!res)
44 return -EBUSY;
45
46 led_port = ioremap(res->start, res->end - res->start + 1);
47 if (!led_port)
48 return -ENOMEM;
49
50 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
51 writeb(led_value, led_port);
52
53 retval = led_classdev_register(&pdev->dev, &qube_front_led);
54 if (retval)
55 goto err_iounmap;
56
57 return 0;
58
59err_iounmap:
60 iounmap(led_port);
61 led_port = NULL;
62
63 return retval;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000064}
65
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090066static int __devexit cobalt_qube_led_remove(struct platform_device *pdev)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000067{
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090068 led_classdev_unregister(&qube_front_led);
69
70 if (led_port) {
71 iounmap(led_port);
72 led_port = NULL;
73 }
74
75 return 0;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000076}
77
Kay Sievers3c4ded92008-04-15 14:34:30 -070078/* work with hotplug and coldplug */
79MODULE_ALIAS("platform:cobalt-qube-leds");
80
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090081static struct platform_driver cobalt_qube_led_driver = {
82 .probe = cobalt_qube_led_probe,
83 .remove = __devexit_p(cobalt_qube_led_remove),
84 .driver = {
85 .name = "cobalt-qube-leds",
86 .owner = THIS_MODULE,
87 },
88};
89
90static int __init cobalt_qube_led_init(void)
91{
92 return platform_driver_register(&cobalt_qube_led_driver);
93}
94
95static void __exit cobalt_qube_led_exit(void)
96{
97 platform_driver_unregister(&cobalt_qube_led_driver);
98}
99
100module_init(cobalt_qube_led_init);
101module_exit(cobalt_qube_led_exit);
Florian Fainelli2fea6f32007-02-12 23:16:27 +0000102
103MODULE_LICENSE("GPL");
104MODULE_DESCRIPTION("Front LED support for Cobalt Server");
105MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");