修改leds-gpio.c 让GPIO LED在kernel启动时就开始闪烁

内容提要:

客户需要在开机时就闪烁LED,并要求越快越好

 

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 764c313..9276e99 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -194,6 +194,10 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
 
                fwnode_property_read_string(child, "linux,default-trigger",
                                            &led.default_trigger);
+               fwnode_property_read_u32(child, "blink-delay-on",
+                                           (unsigned int *)&led_dat->cdev.blink_delay_on);
+               fwnode_property_read_u32(child, "blink-delay-off",
+                                           (unsigned int *)&led_dat->cdev.blink_delay_off);
 
                if (!fwnode_property_read_string(child, "default-state",
                                                 &state)) {

 

设备树配置参考

        boot_led {
            label = "boot_led";
            gpios = <&tlmm 36 0>;
            default-state = "off";
            linux,default-trigger = "timer";
            blink-delay-on = <0>;
            blink-delay-off = <500>;
        };

        work_led {
            label = "work_led";
            gpios = <&tlmm 34 0>;
            default-state = "off";
            linux,default-trigger = "timer";
            blink-delay-on = <2000>;
            blink-delay-off = <1000>;
        };

 

总结。leds-gpio.c提供了在sysfs操作 blink_delay_on 和 blink_delay_off 的节点,但是默认情况下这两个属性在驱动中都初始化为0,导致驱动加载后无法开始闪烁,必须等kernel起来后,通过应用程序进行设置后才开始闪烁。通过在驱动中增加这两个方法,可以对这两个属性进行初始化配置,让闪烁在驱动加载完成后就进行。

 

posted @ 2023-02-22 11:13  PYPYN  阅读(95)  评论(0编辑  收藏  举报