1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * LEDs driver for the Cobalt Raq series.
5 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
7 #include <linux/init.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>
14 #include <linux/export.h>
17 #define LED_POWER_OFF 0x08
19 static void __iomem *led_port;
21 static DEFINE_SPINLOCK(led_value_lock);
23 static void raq_web_led_set(struct led_classdev *led_cdev,
24 enum led_brightness brightness)
28 spin_lock_irqsave(&led_value_lock, flags);
33 led_value &= ~LED_WEB;
34 writeb(led_value, led_port);
36 spin_unlock_irqrestore(&led_value_lock, flags);
39 static struct led_classdev raq_web_led = {
41 .brightness_set = raq_web_led_set,
44 static void raq_power_off_led_set(struct led_classdev *led_cdev,
45 enum led_brightness brightness)
49 spin_lock_irqsave(&led_value_lock, flags);
52 led_value |= LED_POWER_OFF;
54 led_value &= ~LED_POWER_OFF;
55 writeb(led_value, led_port);
57 spin_unlock_irqrestore(&led_value_lock, flags);
60 static struct led_classdev raq_power_off_led = {
61 .name = "raq::power-off",
62 .brightness_set = raq_power_off_led_set,
63 .default_trigger = "power-off",
66 static int cobalt_raq_led_probe(struct platform_device *pdev)
71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
79 retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
83 retval = led_classdev_register(&pdev->dev, &raq_web_led);
90 led_classdev_unregister(&raq_power_off_led);
98 static struct platform_driver cobalt_raq_led_driver = {
99 .probe = cobalt_raq_led_probe,
101 .name = "cobalt-raq-leds",
105 builtin_platform_driver(cobalt_raq_led_driver);