summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 */