WIP FPC-III support
[linux/fpc-iii.git] / drivers / leds / leds-cobalt-raq.c
blob045c239c7328e174a4193ca8ded54e99acd3c3e6
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * LEDs driver for the Cobalt Raq series.
5 * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
6 */
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>
14 #include <linux/export.h>
16 #define LED_WEB 0x04
17 #define LED_POWER_OFF 0x08
19 static void __iomem *led_port;
20 static u8 led_value;
21 static DEFINE_SPINLOCK(led_value_lock);
23 static void raq_web_led_set(struct led_classdev *led_cdev,
24 enum led_brightness brightness)
26 unsigned long flags;
28 spin_lock_irqsave(&led_value_lock, flags);
30 if (brightness)
31 led_value |= LED_WEB;
32 else
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 = {
40 .name = "raq::web",
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)
47 unsigned long flags;
49 spin_lock_irqsave(&led_value_lock, flags);
51 if (brightness)
52 led_value |= LED_POWER_OFF;
53 else
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)
68 struct resource *res;
69 int retval;
71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
72 if (!res)
73 return -EBUSY;
75 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
76 if (!led_port)
77 return -ENOMEM;
79 retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
80 if (retval)
81 goto err_null;
83 retval = led_classdev_register(&pdev->dev, &raq_web_led);
84 if (retval)
85 goto err_unregister;
87 return 0;
89 err_unregister:
90 led_classdev_unregister(&raq_power_off_led);
92 err_null:
93 led_port = NULL;
95 return retval;
98 static struct platform_driver cobalt_raq_led_driver = {
99 .probe = cobalt_raq_led_probe,
100 .driver = {
101 .name = "cobalt-raq-leds",
105 builtin_platform_driver(cobalt_raq_led_driver);