mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] led: gpio: Add trigger support
@ 2013-07-10 12:11 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2013-07-10 12:11 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/devicetree/bindings/leds/common.txt |  8 ++++++
 drivers/led/led-gpio.c                            | 33 +++++++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/common.txt

diff --git a/Documentation/devicetree/bindings/leds/common.txt b/Documentation/devicetree/bindings/leds/common.txt
new file mode 100644
index 0000000..db264b3
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/common.txt
@@ -0,0 +1,8 @@
+Common leds properties.
+
+- linux,default-trigger barebox,default-trigger:  This parameter, if present, is a
+    string defining the trigger assigned to the LED.  Current triggers are:
+     "heartbeat" - LED flashes at a constant rate
+     "panic" - LED turns on when barebox panics
+     "net" - LED indicates network activity
+
diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c
index 54f9264..69db70f 100644
--- a/drivers/led/led-gpio.c
+++ b/drivers/led/led-gpio.c
@@ -199,6 +199,38 @@ void led_gpio_rgb_unregister(struct gpio_led *led)
 
 #ifdef CONFIG_LED_GPIO_OF
 
+struct led_trg {
+	const char *str;
+	enum led_trigger trg;
+};
+
+static struct led_trg triggers[] = {
+	{ .str = "heartbeat", LED_TRIGGER_HEARTBEAT, },
+	{ .str = "panic", LED_TRIGGER_PANIC, },
+	{ .str = "net", LED_TRIGGER_NET_TXRX, },
+};
+
+static void led_of_parse_trigger(struct led *led, struct device_node *np)
+{
+	const char *trigger;
+	int i;
+
+	trigger = of_get_property(np, "linux,default-trigger", NULL);
+	if (!trigger)
+		trigger = of_get_property(np, "barebox,default-trigger", NULL);
+
+	if (!trigger)
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(triggers); i++) {
+		struct led_trg *trg = &triggers[i];
+		if (!strcmp(trg->str, trigger)) {
+			led_set_trigger(trg->trg, led);
+			return;
+		}
+	}
+}
+
 static int led_gpio_of_probe(struct device_d *dev)
 {
 	struct device_node *child;
@@ -220,6 +252,7 @@ static int led_gpio_of_probe(struct device_d *dev)
 		dev_dbg(dev, "register led %s on gpio%d, active_low = %d\n",
 			gled->led.name, gled->gpio, gled->active_low);
 
+		led_of_parse_trigger(&gled->led, child);
 		led_gpio_register(gled);
 	}
 
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-07-10 12:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10 12:11 [PATCH] led: gpio: Add trigger support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox