blob: 8abcb66db01c2c587f7e85c91e296e324947027e [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 = {
Olaf Heringdb3f5202009-09-07 14:37:27 +010031 .name = "qube::front",
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090032 .brightness = LED_FULL,
33 .brightness_set = qube_front_led_set,
Florian Fainelli51de0362009-11-26 19:41:02 +010034 .default_trigger = "default-on",
Florian Fainelli2fea6f32007-02-12 23:16:27 +000035};
36
Bill Pemberton98ea1ea2012-11-19 13:23:02 -050037static int 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
Jingoo Hanf87ef102012-10-23 05:21:27 -070046 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090047 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)
Jingoo Hanf87ef102012-10-23 05:21:27 -070055 goto err_null;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090056
57 return 0;
58
Jingoo Hanf87ef102012-10-23 05:21:27 -070059err_null:
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090060 led_port = NULL;
61
62 return retval;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000063}
64
Bill Pemberton678e8a62012-11-19 13:26:00 -050065static int cobalt_qube_led_remove(struct platform_device *pdev)
Florian Fainelli2fea6f32007-02-12 23:16:27 +000066{
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090067 led_classdev_unregister(&qube_front_led);
68
Jingoo Hanf87ef102012-10-23 05:21:27 -070069 if (led_port)
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090070 led_port = NULL;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090071
72 return 0;
Florian Fainelli2fea6f32007-02-12 23:16:27 +000073}
74
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090075static struct platform_driver cobalt_qube_led_driver = {
76 .probe = cobalt_qube_led_probe,
Bill Pembertondf07cf82012-11-19 13:20:20 -050077 .remove = cobalt_qube_led_remove,
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090078 .driver = {
79 .name = "cobalt-qube-leds",
80 .owner = THIS_MODULE,
81 },
82};
83
Axel Lin892a8842012-01-10 15:09:24 -080084module_platform_driver(cobalt_qube_led_driver);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000085
86MODULE_LICENSE("GPL");
87MODULE_DESCRIPTION("Front LED support for Cobalt Server");
88MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
Axel Lin892a8842012-01-10 15:09:24 -080089MODULE_ALIAS("platform:cobalt-qube-leds");