From f1e80c07416adacc9ba1d9c5a4635c27b571f0df Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Wed, 7 Oct 2015 11:10:39 +0200 Subject: leds: core: Add two new LED_BLINK_ flags This patch adds LED_BLINK_BRIGHTNESS_CHANGE flag to indicate that blink brightness has changed, and LED_BLINK_DISABLE flag to indicate that blinking deactivation has been requested. In order to use the flags led_timer_function and set_brightness_delayed callbacks as well as led_set_brightness() function are being modified. The main goal of these modifications is to prepare set_brightness_work for extension of the scope of its responsibilities. Signed-off-by: Jacek Anaszewski Acked-by: Pavel Machek Acked-by: Sakari Ailus --- include/linux/leds.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/linux/leds.h b/include/linux/leds.h index fa359c79c825..7b67450234a9 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -44,10 +44,12 @@ struct led_classdev { #define LED_BLINK_ONESHOT (1 << 17) #define LED_BLINK_ONESHOT_STOP (1 << 18) #define LED_BLINK_INVERT (1 << 19) -#define LED_SYSFS_DISABLE (1 << 20) -#define SET_BRIGHTNESS_ASYNC (1 << 21) -#define SET_BRIGHTNESS_SYNC (1 << 22) -#define LED_DEV_CAP_FLASH (1 << 23) +#define LED_BLINK_BRIGHTNESS_CHANGE (1 << 20) +#define LED_BLINK_DISABLE (1 << 21) +#define LED_SYSFS_DISABLE (1 << 22) +#define SET_BRIGHTNESS_ASYNC (1 << 23) +#define SET_BRIGHTNESS_SYNC (1 << 24) +#define LED_DEV_CAP_FLASH (1 << 25) /* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */ -- cgit v1.2.3 From 437a4240f26461610cc0d90950b1c88348d9babe Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Wed, 7 Oct 2015 11:10:40 +0200 Subject: leds: Rename brightness_set_sync op to brightness_set_blocking The initial purpose of brightness_set_sync op, introduced along with the LED flash class extension, was to add a means for setting torch LED brightness as soon as possible, which couldn't have been guaranteed by brightness_set op. This patch renames the op to brightness_set_blocking, which describes its purpose in a more generic way. It is beneficial in view of the prospective changes in the LED core, aiming at removing the need for using work queues in LED class drivers that can sleep or use delays while setting brightness. Signed-off-by: Jacek Anaszewski Acked-by: Andrew Lunn Acked-by: Pavel Machek Acked-by: Sakari Ailus --- include/linux/leds.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/linux/leds.h b/include/linux/leds.h index 7b67450234a9..403fa8690295 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -59,8 +59,8 @@ struct led_classdev { * Set LED brightness level immediately - it can block the caller for * the time required for accessing a LED device register. */ - int (*brightness_set_sync)(struct led_classdev *led_cdev, - enum led_brightness brightness); + int (*brightness_set_blocking)(struct led_classdev *led_cdev, + enum led_brightness brightness); /* Get LED brightness level */ enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); -- cgit v1.2.3 From 1afcadfcd184c3b52e38bae15c247a5fa4a0e054 Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Mon, 19 Oct 2015 09:04:01 +0200 Subject: leds: core: Use set_brightness_work for the blocking op This patch makes LED core capable of setting brightness for drivers that implement brightness_set_blocking op. It removes from LED class drivers responsibility for using work queues on their own. In order to achieve this set_brightness_delayed callback is being modified to directly call one of available ops for brightness setting. led_set_brightness_async() function didn't set brightness in an asynchronous way in all cases. It was mistakenly assuming that all LED subsystem drivers used work queue in their brightness_set op, whereas only half of them did that. Since it has no users now, it is being removed. Signed-off-by: Jacek Anaszewski Acked-by: Sakari Ailus --- include/linux/leds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/leds.h b/include/linux/leds.h index 403fa8690295..b35e0f5b8d6c 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -158,7 +158,7 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev, * * Set an LED's brightness, and, if necessary, cancel the * software blink timer that implements blinking when the - * hardware doesn't. + * hardware doesn't. This function is guaranteed not to sleep. */ extern void led_set_brightness(struct led_classdev *led_cdev, enum led_brightness brightness); -- cgit v1.2.3 From 13ae79bbe4c214047f51623304d83b46eb02897d Mon Sep 17 00:00:00 2001 From: Jacek Anaszewski Date: Wed, 7 Oct 2015 11:10:43 +0200 Subject: leds: core: Drivers shouldn't enforce SYNC/ASYNC brightness setting This patch removes SET_BRIGHTNESS_ASYNC and SET_BRIGHTNESS_SYNC flags. led_set_brightness() now calls led_set_brightness_nosleep() instead of choosing between sync and async op basing on the flags defined by the driver. From now on, if a user wants to make sure that brightness will be set synchronously, they have to use led_set_brightness_sync() API. It is now being made publicly available since it has become apparent that it is a caller who should decide whether brightness is to be set in a synchronous or an asynchronous way. Signed-off-by: Jacek Anaszewski Acked-by: Sakari Ailus --- include/linux/leds.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/linux/leds.h b/include/linux/leds.h index b35e0f5b8d6c..088f1da02bed 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -47,9 +47,7 @@ struct led_classdev { #define LED_BLINK_BRIGHTNESS_CHANGE (1 << 20) #define LED_BLINK_DISABLE (1 << 21) #define LED_SYSFS_DISABLE (1 << 22) -#define SET_BRIGHTNESS_ASYNC (1 << 23) -#define SET_BRIGHTNESS_SYNC (1 << 24) -#define LED_DEV_CAP_FLASH (1 << 25) +#define LED_DEV_CAP_FLASH (1 << 23) /* Set LED brightness level */ /* Must not sleep, use a workqueue if needed */ @@ -162,6 +160,21 @@ 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_sync - set LED brightness synchronously + * @led_cdev: the LED to set + * @brightness: the brightness to set it to + * + * Set an LED's brightness immediately. This function will block + * the caller for the time required for accessing device registers, + * and it can sleep. + * + * Returns: 0 on success or negative error value on failure + */ +extern int led_set_brightness_sync(struct led_classdev *led_cdev, + enum led_brightness value); + /** * led_update_brightness - update LED brightness * @led_cdev: the LED to query -- cgit v1.2.3 From 0dd756f7677a519a1d52a94e74d179e0af39e2ec Mon Sep 17 00:00:00 2001 From: Andrew Lunn Date: Thu, 20 Aug 2015 12:59:45 +0200 Subject: leds: wm8350: Remove work queue Now the core implements the work queue, remove it from the drivers, and switch to using brightness_set_blocking op. Signed-off-by: Andrew Lunn Signed-off-by: Jacek Anaszewski Acked-by: Antonio Ospite Reviewed-by: Mark Brown --- include/linux/mfd/wm8350/pmic.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/linux/mfd/wm8350/pmic.h b/include/linux/mfd/wm8350/pmic.h index 579b50ca2e02..7a09e7f1f984 100644 --- a/include/linux/mfd/wm8350/pmic.h +++ b/include/linux/mfd/wm8350/pmic.h @@ -715,7 +715,6 @@ struct wm8350_led_platform_data { struct wm8350_led { struct platform_device *pdev; - struct mutex mutex; struct work_struct work; spinlock_t value_lock; enum led_brightness value; -- cgit v1.2.3 From 9534cc31dda2bb129480ce2db92bf7bc1ef470ed Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Sat, 2 Jan 2016 01:36:41 +0100 Subject: leds: core: add managed version of led_trigger_register Complementing devm_led_classdev_register add a managed version of led_trigger_register. I omit a managed version of led_classdev_unregister as the equivalent devm_led_classdev_unregister isn't used in the kernel as of today. Signed-off-by: Heiner Kallweit Signed-off-by: Jacek Anaszewski --- include/linux/leds.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/leds.h b/include/linux/leds.h index 088f1da02bed..bc1476fda96e 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -246,6 +246,8 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr, /* Registration functions for complex triggers */ extern int led_trigger_register(struct led_trigger *trigger); extern void led_trigger_unregister(struct led_trigger *trigger); +extern int devm_led_trigger_register(struct device *dev, + struct led_trigger *trigger); extern void led_trigger_register_simple(const char *name, struct led_trigger **trigger); -- cgit v1.2.3