blob: 045c239c7328e174a4193ca8ded54e99acd3c3e6 [file] [log] [blame]
Thomas Gleixner16216332019-05-19 15:51:31 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +09002/*
3 * LEDs driver for the Cobalt Raq series.
4 *
Yoichi Yuasaada8e952009-07-03 00:39:38 +09005 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +09006 */
7#include <linux/init.h>
8#include <linux/io.h>
9#include <linux/ioport.h>
10#include <linux/leds.h>
11#include <linux/platform_device.h>
12#include <linux/spinlock.h>
13#include <linux/types.h>
Paul Gortmakerd131c492011-07-10 12:24:44 -040014#include <linux/export.h>
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090015
16#define LED_WEB 0x04
17#define LED_POWER_OFF 0x08
18
19static void __iomem *led_port;
20static u8 led_value;
21static DEFINE_SPINLOCK(led_value_lock);
22
23static void raq_web_led_set(struct led_classdev *led_cdev,
Németh Márton4d404fd2008-03-09 20:59:57 +000024 enum led_brightness brightness)
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090025{
26 unsigned long flags;
27
28 spin_lock_irqsave(&led_value_lock, flags);
29
30 if (brightness)
31 led_value |= LED_WEB;
32 else
33 led_value &= ~LED_WEB;
34 writeb(led_value, led_port);
35
36 spin_unlock_irqrestore(&led_value_lock, flags);
37}
38
39static struct led_classdev raq_web_led = {
Olaf Heringdb3f5202009-09-07 14:37:27 +010040 .name = "raq::web",
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090041 .brightness_set = raq_web_led_set,
42};
43
44static void raq_power_off_led_set(struct led_classdev *led_cdev,
Németh Márton4d404fd2008-03-09 20:59:57 +000045 enum led_brightness brightness)
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090046{
47 unsigned long flags;
48
49 spin_lock_irqsave(&led_value_lock, flags);
50
51 if (brightness)
52 led_value |= LED_POWER_OFF;
53 else
54 led_value &= ~LED_POWER_OFF;
55 writeb(led_value, led_port);
56
57 spin_unlock_irqrestore(&led_value_lock, flags);
58}
59
60static struct led_classdev raq_power_off_led = {
Olaf Heringdb3f5202009-09-07 14:37:27 +010061 .name = "raq::power-off",
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090062 .brightness_set = raq_power_off_led_set,
63 .default_trigger = "power-off",
64};
65
Bill Pemberton98ea1ea2012-11-19 13:23:02 -050066static int cobalt_raq_led_probe(struct platform_device *pdev)
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090067{
68 struct resource *res;
69 int retval;
70
71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
72 if (!res)
73 return -EBUSY;
74
Jingoo Han50e51942012-10-23 05:20:50 -070075 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090076 if (!led_port)
77 return -ENOMEM;
78
79 retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
80 if (retval)
Jingoo Han50e51942012-10-23 05:20:50 -070081 goto err_null;
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090082
83 retval = led_classdev_register(&pdev->dev, &raq_web_led);
84 if (retval)
85 goto err_unregister;
86
87 return 0;
88
89err_unregister:
90 led_classdev_unregister(&raq_power_off_led);
91
Jingoo Han50e51942012-10-23 05:20:50 -070092err_null:
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090093 led_port = NULL;
94
95 return retval;
96}
97
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +090098static struct platform_driver cobalt_raq_led_driver = {
99 .probe = cobalt_raq_led_probe,
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +0900100 .driver = {
101 .name = "cobalt-raq-leds",
Yoichi Yuasa97da7aa2007-09-27 17:51:05 +0900102 },
103};
104
Geliang Tangcee01222016-11-23 22:50:05 +0800105builtin_platform_driver(cobalt_raq_led_driver);