Commit 0f85e849 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Jacek Anaszewski

leds: trigger: timer: Add initialization from Device Tree

Allow initialization of delays used in timer 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: default avatarKrzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: default avatarJacek Anaszewski <jacek.anaszewski@gmail.com>
parent 9c9ab51e
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/leds.h> #include <linux/leds.h>
static ssize_t led_delay_on_show(struct device *dev, static ssize_t led_delay_on_show(struct device *dev,
...@@ -77,8 +78,41 @@ static struct attribute *timer_trig_attrs[] = { ...@@ -77,8 +78,41 @@ static struct attribute *timer_trig_attrs[] = {
}; };
ATTRIBUTE_GROUPS(timer_trig); ATTRIBUTE_GROUPS(timer_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)
return;
if (size != 2) {
dev_warn(led_cdev->dev,
"Expected 2 but got %u values for delays pattern\n",
size);
goto out;
}
led_cdev->blink_delay_on = pattern[0];
led_cdev->blink_delay_off = pattern[1];
/* led_blink_set() called by caller */
out:
kfree(pattern);
}
static int timer_trig_activate(struct led_classdev *led_cdev) static int timer_trig_activate(struct led_classdev *led_cdev)
{ {
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;
}
led_blink_set(led_cdev, &led_cdev->blink_delay_on, led_blink_set(led_cdev, &led_cdev->blink_delay_on,
&led_cdev->blink_delay_off); &led_cdev->blink_delay_off);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment