blob: d975220804916c9f35c734b9b4db212e36389f0a [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/io.h>
7#include <linux/ioport.h>
Florian Fainelli2fea6f32007-02-12 23:16:27 +00008#include <linux/leds.h>
Yoichi Yuasa4276fd72007-09-27 17:51:17 +09009#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/types.h>
Florian Fainelli2fea6f32007-02-12 23:16:27 +000012
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090013#define LED_FRONT_LEFT 0x01
14#define LED_FRONT_RIGHT 0x02
15
16static void __iomem *led_port;
17static u8 led_value;
18
19static void qube_front_led_set(struct led_classdev *led_cdev,
Németh Márton4d404fd2008-03-09 20:59:57 +000020 enum led_brightness brightness)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000021{
22 if (brightness)
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090023 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000024 else
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090025 led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
26 writeb(led_value, led_port);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000027}
28
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090029static struct led_classdev qube_front_led = {
Olaf Heringdb3f5202009-09-07 14:37:27 +010030 .name = "qube::front",
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090031 .brightness = LED_FULL,
32 .brightness_set = qube_front_led_set,
Florian Fainelli51de0362009-11-26 19:41:02 +010033 .default_trigger = "default-on",
Florian Fainelli2fea6f32007-02-12 23:16:27 +000034};
35
Bill Pemberton98ea1ea2012-11-19 13:23:02 -050036static int cobalt_qube_led_probe(struct platform_device *pdev)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000037{
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090038 struct resource *res;
39 int retval;
40
41 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
42 if (!res)
43 return -EBUSY;
44
Jingoo Hanf87ef102012-10-23 05:21:27 -070045 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090046 if (!led_port)
47 return -ENOMEM;
48
49 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
50 writeb(led_value, led_port);
51
52 retval = led_classdev_register(&pdev->dev, &qube_front_led);
53 if (retval)
Jingoo Hanf87ef102012-10-23 05:21:27 -070054 goto err_null;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090055
56 return 0;
57
Jingoo Hanf87ef102012-10-23 05:21:27 -070058err_null:
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090059 led_port = NULL;
60
61 return retval;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000062}
63
Bill Pemberton678e8a62012-11-19 13:26:00 -050064static int cobalt_qube_led_remove(struct platform_device *pdev)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000065{
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090066 led_classdev_unregister(&qube_front_led);
67
Jingoo Hanf87ef102012-10-23 05:21:27 -070068 if (led_port)
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090069 led_port = NULL;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090070
71 return 0;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000072}
73
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090074static struct platform_driver cobalt_qube_led_driver = {
75 .probe = cobalt_qube_led_probe,
Bill Pembertondf07cf82012-11-19 13:20:20 -050076 .remove = cobalt_qube_led_remove,
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090077 .driver = {
78 .name = "cobalt-qube-leds",
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090079 },
80};
81
Axel Lin892a8842012-01-10 15:09:24 -080082module_platform_driver(cobalt_qube_led_driver);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000083
84MODULE_LICENSE("GPL");
85MODULE_DESCRIPTION("Front LED support for Cobalt Server");
86MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
Axel Lin892a8842012-01-10 15:09:24 -080087MODULE_ALIAS("platform:cobalt-qube-leds");