xref: /linux/drivers/leds/leds-cobalt-qube.c (revision e58e871becec2d3b04ed91c0c16fe8deac9c9dfa)
1 /*
2  * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
3  *
4  * Control the Cobalt Qube/RaQ front LED
5  */
6 #include <linux/io.h>
7 #include <linux/ioport.h>
8 #include <linux/leds.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/types.h>
12 
13 #define LED_FRONT_LEFT	0x01
14 #define LED_FRONT_RIGHT	0x02
15 
16 static void __iomem *led_port;
17 static u8 led_value;
18 
19 static void qube_front_led_set(struct led_classdev *led_cdev,
20 			       enum led_brightness brightness)
21 {
22 	if (brightness)
23 		led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
24 	else
25 		led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
26 	writeb(led_value, led_port);
27 }
28 
29 static struct led_classdev qube_front_led = {
30 	.name			= "qube::front",
31 	.brightness		= LED_FULL,
32 	.brightness_set		= qube_front_led_set,
33 	.default_trigger	= "default-on",
34 };
35 
36 static int cobalt_qube_led_probe(struct platform_device *pdev)
37 {
38 	struct resource *res;
39 
40 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
41 	if (!res)
42 		return -EBUSY;
43 
44 	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
45 	if (!led_port)
46 		return -ENOMEM;
47 
48 	led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
49 	writeb(led_value, led_port);
50 
51 	return devm_led_classdev_register(&pdev->dev, &qube_front_led);
52 }
53 
54 static struct platform_driver cobalt_qube_led_driver = {
55 	.probe	= cobalt_qube_led_probe,
56 	.driver	= {
57 		.name	= "cobalt-qube-leds",
58 	},
59 };
60 
61 module_platform_driver(cobalt_qube_led_driver);
62 
63 MODULE_LICENSE("GPL");
64 MODULE_DESCRIPTION("Front LED support for Cobalt Server");
65 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
66 MODULE_ALIAS("platform:cobalt-qube-leds");
67