]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
led: Add dts property to specify blinking of the led
authorMichael Polyntsov <michael.polyntsov@iopsys.eu>
Fri, 19 Jul 2024 09:12:13 +0000 (13:12 +0400)
committerTom Rini <trini@konsulko.com>
Tue, 30 Jul 2024 18:35:23 +0000 (12:35 -0600)
The standard property

    linux,default-trigger = "pattern";

used to get an effect. No blinking parameters can be set yet.

Signed-off-by: Michael Polyntsov <michael.polyntsov@iopsys.eu>
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/led/led-uclass.c

index e6312d1dc419ea2d04aa075b4f1f63ade9c029c5..199d68bc25a83f21544d40fd00cd874efebdfd78 100644 (file)
@@ -118,6 +118,14 @@ static int led_post_bind(struct udevice *dev)
        else
                return 0;
 
+       if (IS_ENABLED(CONFIG_LED_BLINK)) {
+               const char *trigger;
+
+               trigger = dev_read_string(dev, "linux,default-trigger");
+               if (trigger && !strncmp(trigger, "pattern", 7))
+                       uc_plat->default_state = LEDST_BLINK;
+       }
+
        /*
         * In case the LED has default-state DT property, trigger
         * probe() to configure its default state during startup.
@@ -130,12 +138,24 @@ static int led_post_bind(struct udevice *dev)
 static int led_post_probe(struct udevice *dev)
 {
        struct led_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+       int default_period_ms = 1000;
+       int ret = 0;
+
+       switch (uc_plat->default_state) {
+       case LEDST_ON:
+       case LEDST_OFF:
+               ret = led_set_state(dev, uc_plat->default_state);
+               break;
+       case LEDST_BLINK:
+               ret = led_set_period(dev, default_period_ms);
+               if (!ret)
+                       ret = led_set_state(dev, uc_plat->default_state);
+               break;
+       default:
+               break;
+       }
 
-       if (uc_plat->default_state == LEDST_ON ||
-           uc_plat->default_state == LEDST_OFF)
-               led_set_state(dev, uc_plat->default_state);
-
-       return 0;
+       return ret;
 }
 
 UCLASS_DRIVER(led) = {