blob: ef22e1e94048f9f4dd4265b1ec6b5813246a4de3 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Florian Fainelli2fea6f32007-02-12 23:16:27 +00002/*
3 * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
4 *
5 * Control the Cobalt Qube/RaQ front LED
6 */
Yoichi Yuasa4276fd72007-09-27 17:51:17 +09007#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 Fainelli51de036b2009-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;
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090040
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
Vaishali Thakkaraa4e2522015-09-04 12:12:01 +020052 return devm_led_classdev_register(&pdev->dev, &qube_front_led);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000053}
54
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090055static struct platform_driver cobalt_qube_led_driver = {
56 .probe = cobalt_qube_led_probe,
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090057 .driver = {
58 .name = "cobalt-qube-leds",
Yoichi Yuasa4276fd72007-09-27 17:51:17 +090059 },
60};
61
Axel Lin892a8842012-01-10 15:09:24 -080062module_platform_driver(cobalt_qube_led_driver);
Florian Fainelli2fea6f32007-02-12 23:16:27 +000063
64MODULE_LICENSE("GPL");
65MODULE_DESCRIPTION("Front LED support for Cobalt Server");
66MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
Axel Lin892a8842012-01-10 15:09:24 -080067MODULE_ALIAS("platform:cobalt-qube-leds");