blob: 9be195707b392d0c9dd8ca0da5f4633553342de0 [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 Fainelli51de036b2009-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;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090039
40 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
41 if (!res)
42 return -EBUSY;
43
Jingoo Hanf87ef102012-10-23 05:21:27 -070044 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090045 if (!led_port)
46 return -ENOMEM;
47
48 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
49 writeb(led_value, led_port);
50
Vaishali Thakkaraa4e2522015-09-04 12:12:01 +020051 return devm_led_classdev_register(&pdev->dev, &qube_front_led);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000052}
53
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090054static struct platform_driver cobalt_qube_led_driver = {
55 .probe = cobalt_qube_led_probe,
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090056 .driver = {
57 .name = "cobalt-qube-leds",
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090058 },
59};
60
Axel Lin892a8842012-01-10 15:09:24 -080061module_platform_driver(cobalt_qube_led_driver);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000062
63MODULE_LICENSE("GPL");
64MODULE_DESCRIPTION("Front LED support for Cobalt Server");
65MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
Axel Lin892a8842012-01-10 15:09:24 -080066MODULE_ALIAS("platform:cobalt-qube-leds");