diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-01-15 07:58:30 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-01-15 07:58:30 +0100 |
commit | e1907bca0cf0237ad4cd7340dbadaf8f4bcd5bad (patch) | |
tree | f90ca08ed94aed60f3cdd258645c24510d335149 | |
parent | 67ee472f8fd8fee14444ca497c9e08429723cc8d (diff) | |
parent | 1e000e8e92182d21c2e9e59f73f022422843b646 (diff) | |
download | barebox-e1907bca0cf0237ad4cd7340dbadaf8f4bcd5bad.tar.gz |
Merge branch 'for-next/led'
-rw-r--r-- | Documentation/devicetree/bindings/leds/common.rst | 7 | ||||
-rw-r--r-- | drivers/led/core.c | 64 | ||||
-rw-r--r-- | drivers/led/led-triggers.c | 25 |
3 files changed, 47 insertions, 49 deletions
diff --git a/Documentation/devicetree/bindings/leds/common.rst b/Documentation/devicetree/bindings/leds/common.rst index 1f5ae42caf..911a55f4f6 100644 --- a/Documentation/devicetree/bindings/leds/common.rst +++ b/Documentation/devicetree/bindings/leds/common.rst @@ -6,7 +6,12 @@ Common leds properties * ``heartbeat`` - LED flashes at a constant rate * ``panic`` - LED turns on when barebox panics - * ``net`` - LED indicates network activity + * ``net`` - LED indicates network activity (tx and rx) + * ``net-rx`` - LED indicates network activity (rx only) + * ``net-tx`` - LED indicates network activity (tx only) * ``label``: The label for this LED. If omitted, the label is taken from the node name (excluding the unit address). + +* ``panic-indicator`` - This property specifies that the LED should be used as a + panic indicator. diff --git a/drivers/led/core.c b/drivers/led/core.c index 431966d067..e727148a24 100644 --- a/drivers/led/core.c +++ b/drivers/led/core.c @@ -256,37 +256,55 @@ void led_unregister(struct led *led) list_del(&led->list); } -struct led_trg { - const char *str; - enum led_trigger trg; +static char *trigger_names[] = { + [LED_TRIGGER_PANIC] = "panic", + [LED_TRIGGER_HEARTBEAT] = "heartbeat", + [LED_TRIGGER_NET_RX] = "net-rx", + [LED_TRIGGER_NET_TX] = "net-tx", + [LED_TRIGGER_NET_TXRX] = "net", + [LED_TRIGGER_DEFAULT_ON] = "default-on", }; -static struct led_trg triggers[] = { - { .str = "heartbeat", LED_TRIGGER_HEARTBEAT, }, - { .str = "panic", LED_TRIGGER_PANIC, }, - { .str = "net", LED_TRIGGER_NET_TXRX, }, - { .str = "default-on", LED_TRIGGER_DEFAULT_ON, }, -}; +const char *trigger_name(enum led_trigger trigger) +{ + return trigger_names[trigger]; +} + +enum led_trigger trigger_by_name(const char *name) +{ + int i; + + if (!name) + return LED_TRIGGER_MAX; + + for (i = 0; i < LED_TRIGGER_MAX; i++) + if (!strcmp(name, trigger_names[i])) + return i; + + return LED_TRIGGER_MAX; +} void led_of_parse_trigger(struct led *led, struct device_node *np) { + enum led_trigger trg = LED_TRIGGER_MAX; 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 (of_property_read_bool(np, "panic-indicator")) + trg = LED_TRIGGER_PANIC; + + if (trg == LED_TRIGGER_MAX) { + trigger = of_get_property(np, "linux,default-trigger", NULL); + trg = trigger_by_name(trigger); + } - if (!trigger) - return; + if (trg == LED_TRIGGER_MAX) { + trigger = of_get_property(np, "barebox,default-trigger", NULL); + trg = trigger_by_name(trigger); + } - for (i = 0; i < ARRAY_SIZE(triggers); i++) { - struct led_trg *trg = &triggers[i]; - if (!strcmp(trg->str, trigger)) { - /* disable LED before installing trigger */ - led_set(led, 0); - led_set_trigger(trg->trg, led); - return; - } + if (trg != LED_TRIGGER_MAX) { + /* disable LED before installing trigger */ + led_set(led, 0); + led_set_trigger(trg, led); } } diff --git a/drivers/led/led-triggers.c b/drivers/led/led-triggers.c index 76a1481e14..216c8639bc 100644 --- a/drivers/led/led-triggers.c +++ b/drivers/led/led-triggers.c @@ -143,31 +143,6 @@ int led_set_trigger(enum led_trigger trigger, struct led *led) return 0; } -static char *trigger_names[] = { - [LED_TRIGGER_PANIC] = "panic", - [LED_TRIGGER_HEARTBEAT] = "heartbeat", - [LED_TRIGGER_NET_RX] = "net-rx", - [LED_TRIGGER_NET_TX] = "net-tx", - [LED_TRIGGER_NET_TXRX] = "net", - [LED_TRIGGER_DEFAULT_ON] = "default-on", -}; - -const char *trigger_name(enum led_trigger trigger) -{ - return trigger_names[trigger]; -} - -enum led_trigger trigger_by_name(const char *name) -{ - int i; - - for (i = 0; i < LED_TRIGGER_MAX; i++) - if (!strcmp(name, trigger_names[i])) - return i; - - return LED_TRIGGER_MAX; -} - /** * led_triggers_show_info - Show information about all registered * triggers |