summaryrefslogtreecommitdiffstats
path: root/drivers/led
diff options
context:
space:
mode:
authorSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>2013-07-02 20:30:47 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-07-09 20:00:19 +0200
commit34934c183b2880340c9ee8f7f36da5a77bffea46 (patch)
treea44d302e6896f6224698892e9db80e2073e72bee /drivers/led
parentcf31688b6a6981bf6e66ec8587d0ccf3dd72a594 (diff)
downloadbarebox-34934c183b2880340c9ee8f7f36da5a77bffea46.tar.gz
barebox-34934c183b2880340c9ee8f7f36da5a77bffea46.tar.xz
LED: add support for device tree parsing of gpio-leds
This adds a driver option to probe GPIO LEDs from device tree compatible with "gpio-leds" device tree nodes. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/led')
-rw-r--r--drivers/led/Kconfig4
-rw-r--r--drivers/led/led-gpio.c45
2 files changed, 49 insertions, 0 deletions
diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 8ca6ab8e44..3ead82e031 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -7,6 +7,10 @@ config LED_GPIO
bool "gpio LED support"
depends on GENERIC_GPIO
+config LED_GPIO_OF
+ bool "support parsing gpio LEDs from device tree"
+ depends on LED_GPIO && OFTREE
+
config LED_GPIO_RGB
bool "gpio rgb LED support"
depends on LED_GPIO
diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c
index 08dc9bad0d..54f9264d44 100644
--- a/drivers/led/led-gpio.c
+++ b/drivers/led/led-gpio.c
@@ -18,8 +18,10 @@
*
*/
#include <common.h>
+#include <init.h>
#include <led.h>
#include <gpio.h>
+#include <of_gpio.h>
static void led_gpio_set(struct led *led, unsigned int value)
{
@@ -194,3 +196,46 @@ void led_gpio_rgb_unregister(struct gpio_led *led)
led_unregister(&led->led);
}
#endif /* CONFIG_LED_GPIO_RGB */
+
+#ifdef CONFIG_LED_GPIO_OF
+
+static int led_gpio_of_probe(struct device_d *dev)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(dev->device_node, child) {
+ struct gpio_led *gled;
+ enum of_gpio_flags flags;
+ int gpio;
+
+ gpio = of_get_named_gpio_flags(child, "gpios", 0, &flags);
+ if (gpio < 0)
+ continue;
+
+ gled = xzalloc(sizeof(*gled));
+ gled->led.name = xstrdup(child->name);
+ gled->gpio = gpio;
+ gled->active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0;
+
+ dev_dbg(dev, "register led %s on gpio%d, active_low = %d\n",
+ gled->led.name, gled->gpio, gled->active_low);
+
+ led_gpio_register(gled);
+ }
+
+ return 0;
+}
+
+static struct of_device_id led_gpio_of_ids[] = {
+ { .compatible = "gpio-leds", },
+ { }
+};
+
+static struct driver_d led_gpio_of_driver = {
+ .name = "gpio-leds",
+ .probe = led_gpio_of_probe,
+ .of_compatible = DRV_OF_COMPAT(led_gpio_of_ids),
+};
+device_platform_driver(led_gpio_of_driver);
+
+#endif /* CONFIG LED_GPIO_OF */