This patch provides simple brightness control with given name. Once LED class device is registered with specific name, then the LED brightness can be controlled by other drivers or kernel area. What is the difference between LED trigger and led_set_brightness_simple() LED class device provides similar function, LED trigger. However, we need additional register/unregister functions before setting the brightness. On the other hand, no registration is required when this function is invoked. Just look up the LED device name and set the brightness. If LED device doesn't exist, it returns as -ENODEV. Signed-off-by: Milo(Woogyom) Kim <milo.kim@xxxxxx> --- drivers/leds/led-core.c | 19 +++++++++++++++++++ include/linux/leds.h | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index ce8921a..faacfe2 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -124,3 +124,22 @@ void led_set_brightness(struct led_classdev *led_cdev, __led_set_brightness(led_cdev, brightness); } EXPORT_SYMBOL(led_set_brightness); + +int led_set_brightness_simple(const char *name, + enum led_brightness brightness) +{ + struct led_classdev *led_cdev; + + down_read(&leds_list_lock); + list_for_each_entry(led_cdev, &leds_list, node) { + if (!strcmp(led_cdev->name, name)) { + led_set_brightness(led_cdev, brightness); + up_read(&leds_list_lock); + return 0; + } + } + up_read(&leds_list_lock); + + return -ENODEV; +} +EXPORT_SYMBOL_GPL(led_set_brightness_simple); diff --git a/include/linux/leds.h b/include/linux/leds.h index 6e53bb3..25f48db 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -139,6 +139,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev, extern void led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness); +/** + * led_set_brightness_simple + * @name: The name of LED to control + * @brightness: the brightness to set it to + * + * Find LED device with given name and set an LED's brightness. + * If the LED doesn't exist, then it returns as negative value. + */ +extern int led_set_brightness_simple(const char *name, + enum led_brightness brightness); /* * LED Triggers */ -- 1.7.9.5 Best Regards, Milo -- To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html