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: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
This commit is contained in:
Krzysztof Kozlowski 2019-01-09 15:44:49 +01:00 коммит произвёл Jacek Anaszewski
Родитель 9c9ab51e86
Коммит 0f85e8498a
1 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -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);