Multiple LED triggers might need to access default pattern so add a helper for that. Signed-off-by: Krzysztof Kozlowski <krzk@xxxxxxxxxx> --- drivers/leds/led-class.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/leds.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 3c7e3487b373..49eb64bffd4d 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -17,6 +17,7 @@ #include <linux/leds.h> #include <linux/list.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/timer.h> @@ -244,6 +245,47 @@ static int led_classdev_next_name(const char *init_name, char *name, } /** + * led_classdev_get_default_pattern - return default pattern + * + * @led_cdev: the led_classdev structure for this device + * @size: pointer for storing the number of elements in returned array, + * modified only if return != NULL + * + * Return: Allocated array of integers with default pattern from DeviceTree + * or NULL. Caller is responsible for kfree(). + */ +u32 *led_classdev_get_default_pattern(struct led_classdev *led_cdev, + unsigned int *size) +{ + struct device_node *np = dev_of_node(led_cdev->dev); + u32 *pattern; + int count; + + if (!np) + return NULL; + + count = of_property_count_u32_elems(np, "led-pattern"); + if (count < 0) + return NULL; + + pattern = kcalloc(count, sizeof(*pattern), GFP_KERNEL); + if (!pattern) + return NULL; + + if (of_property_read_u32_array(np, "led-pattern", pattern, count)) + goto err; + + *size = count; + + return pattern; + +err: + kfree(pattern); + return NULL; +} +EXPORT_SYMBOL_GPL(led_classdev_get_default_pattern); + +/** * of_led_classdev_register - register a new object of led_classdev class. * * @parent: parent of LED device diff --git a/include/linux/leds.h b/include/linux/leds.h index 5263f87e1d2c..70edf574ba81 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -129,6 +129,9 @@ struct led_classdev { struct mutex led_access; }; +extern u32 *led_classdev_get_default_pattern(struct led_classdev *led_cdev, + unsigned int *size); + extern int of_led_classdev_register(struct device *parent, struct device_node *np, struct led_classdev *led_cdev); -- 2.7.4