Commit 8e1f4561 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Jacek Anaszewski

leds: Add helper for getting default pattern from Device Tree

Multiple LED triggers might need to access default pattern so add a
helper for that.
Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarJacek Anaszewski <jacek.anaszewski@gmail.com>
parent 1dd70937
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/slab.h>
#include "leds.h" #include "leds.h"
DECLARE_RWSEM(leds_list_lock); DECLARE_RWSEM(leds_list_lock);
...@@ -310,6 +312,34 @@ int led_update_brightness(struct led_classdev *led_cdev) ...@@ -310,6 +312,34 @@ int led_update_brightness(struct led_classdev *led_cdev)
} }
EXPORT_SYMBOL_GPL(led_update_brightness); EXPORT_SYMBOL_GPL(led_update_brightness);
u32 *led_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)) {
kfree(pattern);
return NULL;
}
*size = count;
return pattern;
}
EXPORT_SYMBOL_GPL(led_get_default_pattern);
/* Caller must ensure led_cdev->led_access held */ /* Caller must ensure led_cdev->led_access held */
void led_sysfs_disable(struct led_classdev *led_cdev) void led_sysfs_disable(struct led_classdev *led_cdev)
{ {
......
...@@ -218,6 +218,19 @@ extern int led_set_brightness_sync(struct led_classdev *led_cdev, ...@@ -218,6 +218,19 @@ extern int led_set_brightness_sync(struct led_classdev *led_cdev,
*/ */
extern int led_update_brightness(struct led_classdev *led_cdev); extern int led_update_brightness(struct led_classdev *led_cdev);
/**
* led_get_default_pattern - return default pattern
*
* @led_cdev: the LED to get default pattern for
* @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 device tree
* or NULL. Caller is responsible for kfree().
*/
extern u32 *led_get_default_pattern(struct led_classdev *led_cdev,
unsigned int *size);
/** /**
* led_sysfs_disable - disable LED sysfs interface * led_sysfs_disable - disable LED sysfs interface
* @led_cdev: the LED to set * @led_cdev: the LED to set
......
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