修改led-core.c 让led的delay_on和delay_off时间不会应为trigger配置改版而重置为1HZ
先列一下leds trigger的设置流程
echo none > trigger 的流程
led_trigger_set()
|
led_stop_software_blink()
echo timer > trigger 的流程
led_trigger_set()
|
ret = trig->activate(led_cdev);
|
timer_trig_activate()
|
led_blink_set()
|
led_blink_setup()
问题出在led_stop_software_blink()这个函数。当trigger设置为none时会调用到这里,这个函数会将delay_on/off都还原成0
void led_stop_software_blink(struct led_classdev *led_cdev) { del_timer_sync(&led_cdev->blink_timer); led_cdev->blink_delay_on = 0; led_cdev->blink_delay_off = 0; clear_bit(LED_BLINK_SW, &led_cdev->work_flags); }
当trigger设置为timer时会调用到这里,此时delay_on跟delay_off都为0,if (!*delay_on && !*delay_off) 判断成立,最终delay_on/off就被重置为1HZ
static void led_blink_setup(struct led_classdev *led_cdev, unsigned long *delay_on, unsigned long *delay_off) { if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) && led_cdev->blink_set && !led_cdev->blink_set(led_cdev, delay_on, delay_off)) return; /* blink with 1 Hz as default if nothing specified */ if (!*delay_on && !*delay_off) *delay_on = *delay_off = 500; led_set_software_blink(led_cdev, *delay_on, *delay_off); }
所以,解决方案就是将led_stop_software_blink()函数中delay_on/off设置为0的代码注释掉。