]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/leds/leds-cobalt-qube.c
Linux 4.3
[mirror_ubuntu-jammy-kernel.git] / drivers / leds / leds-cobalt-qube.c
CommitLineData
2fea6f35
FF
1/*
2 * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
3 *
4 * Control the Cobalt Qube/RaQ front LED
5 */
4276fd73
YY
6#include <linux/io.h>
7#include <linux/ioport.h>
8#include <linux/leds.h>
2fea6f35 9#include <linux/module.h>
4276fd73 10#include <linux/platform_device.h>
2fea6f35 11#include <linux/types.h>
2fea6f35 12
4276fd73
YY
13#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,
4d404fd5 20 enum led_brightness brightness)
2fea6f35
FF
21{
22 if (brightness)
4276fd73 23 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
2fea6f35 24 else
4276fd73
YY
25 led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
26 writeb(led_value, led_port);
27}
28
29static struct led_classdev qube_front_led = {
db3f5207 30 .name = "qube::front",
4276fd73
YY
31 .brightness = LED_FULL,
32 .brightness_set = qube_front_led_set,
51de036b 33 .default_trigger = "default-on",
4276fd73
YY
34};
35
98ea1ea2 36static int cobalt_qube_led_probe(struct platform_device *pdev)
4276fd73
YY
37{
38 struct resource *res;
39 int retval;
40
41 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
42 if (!res)
43 return -EBUSY;
44
f87ef101 45 led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
4276fd73
YY
46 if (!led_port)
47 return -ENOMEM;
48
49 led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
50 writeb(led_value, led_port);
51
52 retval = led_classdev_register(&pdev->dev, &qube_front_led);
53 if (retval)
f87ef101 54 goto err_null;
4276fd73
YY
55
56 return 0;
57
f87ef101 58err_null:
4276fd73
YY
59 led_port = NULL;
60
61 return retval;
62}
63
678e8a6b 64static int cobalt_qube_led_remove(struct platform_device *pdev)
4276fd73
YY
65{
66 led_classdev_unregister(&qube_front_led);
67
f87ef101 68 if (led_port)
4276fd73 69 led_port = NULL;
4276fd73
YY
70
71 return 0;
2fea6f35
FF
72}
73
4276fd73
YY
74static struct platform_driver cobalt_qube_led_driver = {
75 .probe = cobalt_qube_led_probe,
df07cf81 76 .remove = cobalt_qube_led_remove,
4276fd73
YY
77 .driver = {
78 .name = "cobalt-qube-leds",
4276fd73 79 },
2fea6f35
FF
80};
81
892a8843 82module_platform_driver(cobalt_qube_led_driver);
2fea6f35
FF
83
84MODULE_LICENSE("GPL");
85MODULE_DESCRIPTION("Front LED support for Cobalt Server");
86MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
892a8843 87MODULE_ALIAS("platform:cobalt-qube-leds");