diff options
author | Krzysztof Kozlowski <krzk@kernel.org> | 2019-01-09 17:44:48 +0300 |
---|---|---|
committer | Jacek Anaszewski <jacek.anaszewski@gmail.com> | 2019-01-17 00:09:18 +0300 |
commit | 9c9ab51e86bf1f3a24eb3477cbe5d4fb09d386a5 (patch) | |
tree | 918749372696a037f35b1fa07fb710a5ecb608ef /drivers/leds/trigger | |
parent | aa6fd10481bdb1af2d4a4b5975e23674e989cd81 (diff) | |
download | linux-9c9ab51e86bf1f3a24eb3477cbe5d4fb09d386a5.tar.xz |
leds: trigger: oneshot: Add initialization from Device Tree
Allow initialization of delays used in oneshot trigger from Device
Tree property.
This is especially useful for embedded systems where the trigger might
be used early, before bringing up user-space.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Diffstat (limited to 'drivers/leds/trigger')
-rw-r--r-- | drivers/leds/trigger/ledtrig-oneshot.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c index 95c9be4b6e7e..8808f0ad7339 100644 --- a/drivers/leds/trigger/ledtrig-oneshot.c +++ b/drivers/leds/trigger/ledtrig-oneshot.c @@ -130,6 +130,34 @@ static struct attribute *oneshot_trig_attrs[] = { }; ATTRIBUTE_GROUPS(oneshot_trig); +static void pattern_init(struct led_classdev *led_cdev) +{ + u32 *pattern; + unsigned int size = 0; + + pattern = led_get_default_pattern(led_cdev, &size); + if (!pattern) + goto out_default; + + if (size != 2) { + dev_warn(led_cdev->dev, + "Expected 2 but got %u values for delays pattern\n", + size); + goto out_default; + } + + led_cdev->blink_delay_on = pattern[0]; + led_cdev->blink_delay_off = pattern[1]; + kfree(pattern); + + return; + +out_default: + kfree(pattern); + led_cdev->blink_delay_on = DEFAULT_DELAY; + led_cdev->blink_delay_off = DEFAULT_DELAY; +} + static int oneshot_trig_activate(struct led_classdev *led_cdev) { struct oneshot_trig_data *oneshot_data; @@ -140,8 +168,14 @@ static int oneshot_trig_activate(struct led_classdev *led_cdev) led_set_trigger_data(led_cdev, oneshot_data); - led_cdev->blink_delay_on = DEFAULT_DELAY; - led_cdev->blink_delay_off = DEFAULT_DELAY; + if (led_cdev->flags & LED_INIT_DEFAULT_TRIGGER) { + pattern_init(led_cdev); + /* + * Mark as initialized even on pattern_init() error because + * any consecutive call to it would produce the same error. + */ + led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER; + } return 0; } |