提交 0f85e849 编写于 作者: K Krzysztof Kozlowski 提交者: 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: NKrzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: NJacek Anaszewski <jacek.anaszewski@gmail.com>
上级 9c9ab51e
......@@ -15,6 +15,7 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/leds.h>
static ssize_t led_delay_on_show(struct device *dev,
......@@ -77,8 +78,41 @@ static struct attribute *timer_trig_attrs[] = {
};
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)
{
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_cdev->blink_delay_off);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册