LED core improvements
Subsystems (3)
PATCH v2 1/12 leds: core: Use EXPORT_SYMBOL_GPL consistently
In reply to Jacek AnaszewskiLED core has a mixture of EXPORT_SYMBOL and EXPORT_SYMBOL_GPL macros. This patch fixes this discrepancy and switches to using EXPORT_SYMBOL_GPL for each exported function.
--- drivers/leds/led-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/leds/led-core.c +4 -4
@@ -83,7 +83,7 @@ void led_blink_set(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set); +EXPORT_SYMBOL_GPL (led_blink_set); void led_blink_set_oneshot(struct led_classdev *led_cdev, unsigned long *delay_on,
@@ -104,7 +104,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set_oneshot); +EXPORT_SYMBOL_GPL (led_blink_set_oneshot);void led_stop_software_blink (struct led_classdev *led_cdev) {
@@ -139,7 +139,7 @@ void led_set_brightness(struct led_classdev *led_cdev,dev_dbg (led_cdev->dev,"Setting LED brightness failed (%d)\n" , ret); } -EXPORT_SYMBOL (led_set_brightness); +EXPORT_SYMBOL_GPL (led_set_brightness);int led_update_brightness (struct led_classdev *led_cdev) {
@@ -155,7 +155,7 @@ int led_update_brightness(struct led_classdev *led_cdev)return ret; } -EXPORT_SYMBOL (led_update_brightness); +EXPORT_SYMBOL_GPL (led_update_brightness);/* Caller must ensure led_cdev->led_access held */ void led_sysfs_disable (struct led_classdev *led_cdev)
Signature · 1 line
1.7.9.5
PATCH v2 2/12 leds: core: Move LED core callbacks out of led-class.c
In reply to Jacek AnaszewskiSince the API for controlling LED brightness and blinking is defined in the LED core, move the related timer and work callbacks to the led-core.c, and initialize them through a new led_core_init API.
--- drivers/leds/led-class.c | 69 +------------------------------------------ drivers/leds/led-core.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/leds/leds.h | 1 + 3 files changed, 75 insertions(+), 68 deletions(-)
drivers/leds/led-class.c +1 -68
@@ -102,70 +102,6 @@ static const struct attribute_group *led_groups[] = { NULL, }; -static void led_timer_function (unsigned long data) -{ -struct led_classdev *led_cdev = (void *)data; -unsigned long brightness; -unsigned long delay; - -if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { -led_set_brightness_async (led_cdev,LED_OFF ); -return ; - } - -if (led_cdev->flags &LED_BLINK_ONESHOT_STOP ) { - led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP ; -return ; - } - - brightness =led_get_brightness (led_cdev); -if (!brightness) { -/* Time to switch the LED on. */ -if (led_cdev->delayed_set_value) { - led_cdev->blink_brightness = - led_cdev->delayed_set_value; - led_cdev->delayed_set_value =0 ; - } - brightness = led_cdev->blink_brightness; - delay = led_cdev->blink_delay_on; - }else { -/* Store the current brightness value to be able -* to restore it when the delay_off period is over. -*/ - led_cdev->blink_brightness = brightness; - brightness =LED_OFF ; - delay = led_cdev->blink_delay_off; - } - -led_set_brightness_async (led_cdev, brightness); - -/* Return in next iteration if led is in one-shot mode and we are in -* the final blink state so that the led is toggled each delay_on + -* delay_off milliseconds in worst case. -*/ -if (led_cdev->flags &LED_BLINK_ONESHOT ) { -if (led_cdev->flags &LED_BLINK_INVERT ) { -if (brightness) - led_cdev->flags |=LED_BLINK_ONESHOT_STOP ; - }else { -if (!brightness) - led_cdev->flags |=LED_BLINK_ONESHOT_STOP ; - } - } - -mod_timer (&led_cdev->blink_timer, jiffies +msecs_to_jiffies (delay)); -} - -static void set_brightness_delayed (struct work_struct *ws) -{ -struct led_classdev *led_cdev = - container_of(ws, struct led_classdev, set_brightness_work); - -led_stop_software_blink (led_cdev); - -led_set_brightness_async (led_cdev, led_cdev->delayed_set_value); -} -/** * led_classdev_suspend - suspend an led_classdev. * @led_cdev: the led_classdev to suspend.
@@ -283,10 +219,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)led_update_brightness (led_cdev); -INIT_WORK (&led_cdev->set_brightness_work, set_brightness_delayed); - -setup_timer (&led_cdev->blink_timer, led_timer_function, - (unsigned long )led_cdev); +led_init_core (led_cdev);#ifdef CONFIG_LEDS_TRIGGERS led_trigger_set_default (led_cdev);
drivers/leds/led-core.c +73 -0
85 lines not on this page · raw message
drivers/leds/leds.h +1 -0
@@ -44,6 +44,7 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)return led_cdev->brightness; } +void led_init_core (struct led_classdev *led_cdev);void led_stop_software_blink (struct led_classdev *led_cdev);extern struct rw_semaphore leds_list_lock;
Signature · 1 line
1.7.9.5
PATCH v2 3/12 leds: core: Add two new LED_BLINK_ flags
In reply to Jacek AnaszewskiThis 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.
--- drivers/leds/led-core.c | 36 ++++++++++++++++++++++++++---------- include/linux/leds.h | 10 ++++++---- 2 files changed, 32 insertions(+), 14 deletions(-)
drivers/leds/led-core.c +26 -10
@@ -44,18 +44,18 @@ static void led_timer_function(unsigned long data) brightness =led_get_brightness (led_cdev);if (!brightness) {/* Time to switch the LED on. */ -if (led_cdev->delayed_set_value) { - led_cdev->blink_brightness = - led_cdev->delayed_set_value; - led_cdev->delayed_set_value =0 ; - } brightness = led_cdev->blink_brightness; delay = led_cdev->blink_delay_on; }else {/* Store the current brightness value to be able * to restore it when the delay_off period is over. +* Do it only if there is no pending blink brightness +* change, to avoid overwriting the new value. */ - led_cdev->blink_brightness = brightness; +if (!(led_cdev->flags &LED_BLINK_BRIGHTNESS_CHANGE )) + led_cdev->blink_brightness = brightness; +else + led_cdev->flags &= ~LED_BLINK_BRIGHTNESS_CHANGE ; brightness =LED_OFF ; delay = led_cdev->blink_delay_off; }
@@ -84,7 +84,11 @@ static void set_brightness_delayed(struct work_struct *ws)struct led_classdev *led_cdev = container_of(ws, struct led_classdev, set_brightness_work); -led_stop_software_blink (led_cdev); +if (led_cdev->flags &LED_BLINK_DISABLE ) { + led_cdev->delayed_set_value =LED_OFF ; +led_stop_software_blink (led_cdev); + led_cdev->flags &= ~LED_BLINK_DISABLE ; + }led_set_brightness_async (led_cdev, led_cdev->delayed_set_value); }
@@ -192,11 +196,23 @@ void led_set_brightness(struct led_classdev *led_cdev, {int ret =0 ; -/* delay brightness if soft-blink is active */ +/* +* In case blinking is on delay brightness setting +* until the next timer tick. +*/ if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { - led_cdev->delayed_set_value = brightness; -if (brightness ==LED_OFF ) +/* +* If we need to disable soft blinking delegate this to the +* work queue task to avoid problems in case we are called +* from hard irq context. +*/ +if (brightness ==LED_OFF ) { + led_cdev->flags |=LED_BLINK_DISABLE ;schedule_work (&led_cdev->set_brightness_work); + }else { + led_cdev->flags |=LED_BLINK_BRIGHTNESS_CHANGE ; + led_cdev->blink_brightness = brightness; + }return ; }
include/linux/leds.h +6 -4
@@ -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 */
Signature · 1 line
1.7.9.5
PATCH v2 4/12 leds: Rename brightness_set_sync op to brightness_set_blocking
In reply to Jacek AnaszewskiThe 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.
--- drivers/leds/led-class-flash.c | 2 +- drivers/leds/leds-aat1290.c | 2 +- drivers/leds/leds-ktd2692.c | 2 +- drivers/leds/leds-max77693.c | 2 +- drivers/leds/leds.h | 2 +- include/linux/leds.h | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-)
drivers/leds/led-class-flash.c +1 -1
@@ -298,7 +298,7 @@ int led_classdev_flash_register(struct device *parent, led_cdev = &fled_cdev->led_cdev;if (led_cdev->flags &LED_DEV_CAP_FLASH ) { -if (!led_cdev->brightness_set_sync) +if (!led_cdev->brightness_set_blocking)return -EINVAL ; ops = fled_cdev->ops;
drivers/leds/leds-aat1290.c +1 -1
@@ -510,7 +510,7 @@ static int aat1290_led_probe(struct platform_device *pdev)/* Initialize LED Flash class device */ led_cdev->brightness_set = aat1290_led_brightness_set; - led_cdev->brightness_set_sync = aat1290_led_brightness_set_sync; + led_cdev->brightness_set_blocking = aat1290_led_brightness_set_sync; led_cdev->max_brightness = led_cfg.max_brightness; led_cdev->flags |=LED_DEV_CAP_FLASH ;INIT_WORK (&led->work_brightness_set, aat1290_brightness_set_work);
drivers/leds/leds-ktd2692.c +1 -1
@@ -382,7 +382,7 @@ static int ktd2692_probe(struct platform_device *pdev) led_cdev->max_brightness = led_cfg.max_brightness; led_cdev->brightness_set = ktd2692_led_brightness_set; - led_cdev->brightness_set_sync = ktd2692_led_brightness_set_sync; + led_cdev->brightness_set_blocking = ktd2692_led_brightness_set_sync; led_cdev->flags |=LED_CORE_SUSPENDRESUME |LED_DEV_CAP_FLASH ;mutex_init (&led->lock);
drivers/leds/leds-max77693.c +1 -1
@@ -932,7 +932,7 @@ static void max77693_init_fled_cdev(struct max77693_sub_led *sub_led, led_cdev->name = led_cfg->label[fled_id]; led_cdev->brightness_set = max77693_led_brightness_set; - led_cdev->brightness_set_sync = max77693_led_brightness_set_sync; + led_cdev->brightness_set_blocking = max77693_led_brightness_set_sync; led_cdev->max_brightness = (led->iout_joint ? led_cfg->iout_torch_max[FLED1] + led_cfg->iout_torch_max[FLED2] :
drivers/leds/leds.h +1 -1
@@ -34,7 +34,7 @@ static inline int led_set_brightness_sync(struct led_classdev *led_cdev, led_cdev->brightness =min (value, led_cdev->max_brightness);if (!(led_cdev->flags &LED_SUSPENDED )) - ret = led_cdev->brightness_set_sync (led_cdev, + ret = led_cdev->brightness_set_blocking (led_cdev, led_cdev->brightness);return ret; }
include/linux/leds.h +2 -2
@@ -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);
Signature · 1 line
1.7.9.5
PATCH v2 7/12 leds: core: Drivers shouldn't enforce SYNC/ASYNC brightness setting
In reply to Jacek AnaszewskiThis patch removes SET_BRIGHTNESS_ASYNC and SET_BRIGHTNESS 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.
Quoted 1 line
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.
--- drivers/leds/led-class-flash.c | 4 ---- drivers/leds/led-class.c | 2 -- drivers/leds/led-core.c | 32 +++++++++++++++++++------------- drivers/leds/leds.h | 13 ------------- include/linux/leds.h | 19 ++++++++++++++++--- 5 files changed, 35 insertions(+), 35 deletions(-)
drivers/leds/led-class-flash.c +0 -4
@@ -316,10 +316,6 @@ int led_classdev_flash_register(struct device *parent,if (ret <0 )return ret; -/* Setting a torch brightness needs to have immediate effect */ - led_cdev->flags &= ~SET_BRIGHTNESS_ASYNC ; - led_cdev->flags |=SET_BRIGHTNESS_SYNC ; -return 0 ; }EXPORT_SYMBOL_GPL (led_classdev_flash_register);
drivers/leds/led-class.c +0 -2
@@ -215,8 +215,6 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)if (!led_cdev->max_brightness) led_cdev->max_brightness =LED_FULL ; - led_cdev->flags |=SET_BRIGHTNESS_ASYNC ; -led_update_brightness (led_cdev);led_init_core (led_cdev);
drivers/leds/led-core.c +19 -13
@@ -205,8 +205,6 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink);void led_set_brightness (struct led_classdev *led_cdev,enum led_brightness brightness) { -int ret =0 ; -/* * In case blinking is on delay brightness setting * until the next timer tick.
@@ -227,17 +225,7 @@ void led_set_brightness(struct led_classdev *led_cdev,return ; } -if (led_cdev->flags &SET_BRIGHTNESS_ASYNC ) { -led_set_brightness_nosleep (led_cdev, brightness); -return ; - }else if (led_cdev->flags &SET_BRIGHTNESS_SYNC ) - ret =led_set_brightness_sync (led_cdev, brightness); -else - ret = -EINVAL ; - -if (ret <0 ) -dev_dbg (led_cdev->dev,"Setting LED brightness failed (%d)\n" , - ret); +led_set_brightness_nosleep (led_cdev, brightness); }EXPORT_SYMBOL_GPL (led_set_brightness);
@@ -261,6 +249,24 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev, }EXPORT_SYMBOL_GPL (led_set_brightness_nosleep); +int led_set_brightness_sync (struct led_classdev *led_cdev, +enum led_brightness value) +{ +if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) +return -EBUSY ; + + led_cdev->brightness =min (value, led_cdev->max_brightness); + +if (led_cdev->flags &LED_SUSPENDED ) +return 0 ; + +if (led_cdev->brightness_set_blocking) +return led_cdev->brightness_set_blocking (led_cdev, + led_cdev->brightness); +return -ENOTSUPP ; +} +EXPORT_SYMBOL_GPL (led_set_brightness_sync); +int led_update_brightness (struct led_classdev *led_cdev) {int ret =0 ;
drivers/leds/leds.h +0 -13
@@ -16,19 +16,6 @@#include <linux/rwsem.h> #include <linux/leds.h> -static inline int led_set_brightness_sync (struct led_classdev *led_cdev, -enum led_brightness value) -{ -int ret =0 ; - - led_cdev->brightness =min (value, led_cdev->max_brightness); - -if (!(led_cdev->flags &LED_SUSPENDED )) - ret = led_cdev->brightness_set_blocking (led_cdev, - led_cdev->brightness); -return ret; -} -static inline int led_get_brightness (struct led_classdev *led_cdev) {return led_cdev->brightness;
include/linux/leds.h +16 -3
@@ -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
Signature · 1 line
1.7.9.5
PATCH v2 8/12 Documentation: leds: Add description of brightness setting API
In reply to Jacek AnaszewskiThis patch adds description of the LED subsystem API for setting an LED brightness.
--- Documentation/leds/leds-class.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/leds/leds-class.txt +13 -0
@@ -52,6 +52,19 @@ above leaves scope for further attributes should they be needed. If sections of the name don't apply, just leave that section blank. +Brightness setting API +====================== + +LED subsystem core exposes following API for setting brightness: + + - led_set_brightness : it is guaranteed not to sleep, passing LED_OFF stops + blinking, + - led_set_brightness_sync : for use cases when immediate effect is desired - + it can block the caller for the time required for accessing + device registers and can sleep, passing LED_OFF stops hardware + blinking, returns -EBUSY if software blink fallback is enabled. + + Hardware accelerated blink of LEDs ==================================
Signature · 1 line
1.7.9.5
PATCH v2 9/12 leds: max77693: Remove work queue
In reply to Jacek AnaszewskiNow the core implements the work queue, remove it from the drivers, and switch to using brightness_set_blocking op.
--- drivers/leds/leds-max77693.c | 57 +++++++----------------------------------- 1 file changed, 9 insertions(+), 48 deletions(-)
drivers/leds/leds-max77693.c +9 -48
@@ -20,7 +20,6 @@#include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/slab.h> -#include <linux/workqueue.h> #include <media/v4l2-flash-led-class.h> #define MODE_OFF 0
@@ -62,8 +61,6 @@ struct max77693_sub_led {int fled_id;/* corresponding LED Flash class device */ struct led_classdev_flash fled_cdev; -/* assures led-triggers compatibility */ -struct work_struct work_brightness_set;/* V4L2 Flash device */ struct v4l2_flash *v4l2_flash;
@@ -463,10 +460,14 @@ static int max77693_setup(struct max77693_led_device *led,return max77693_set_mode_reg (led,MODE_OFF ); } -static int __max77693_led_brightness_set (struct max77693_led_device *led, -int fled_id,enum led_brightness value) +/* LED subsystem callbacks */ +static int max77693_led_brightness_set (struct led_classdev *led_cdev, +enum led_brightness value) { -int ret; +struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); +struct max77693_sub_led *sub_led =flcdev_to_sub_led (fled_cdev); +struct max77693_led_device *led =sub_led_to_led (sub_led); +int fled_id = sub_led->fled_id, ret;mutex_lock (&led->lock);
@@ -494,43 +495,8 @@ static int __max77693_led_brightness_set(struct max77693_led_device *led, ret); unlock:mutex_unlock (&led->lock); -return ret; -} -static void max77693_led_brightness_set_work ( -struct work_struct *work) -{ -struct max77693_sub_led *sub_led = - container_of(work, struct max77693_sub_led, - work_brightness_set); -struct max77693_led_device *led =sub_led_to_led (sub_led); - -__max77693_led_brightness_set (led, sub_led->fled_id, - sub_led->torch_brightness); -} - -/* LED subsystem callbacks */ - -static int max77693_led_brightness_set_sync ( -struct led_classdev *led_cdev, -enum led_brightness value) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct max77693_sub_led *sub_led =flcdev_to_sub_led (fled_cdev); -struct max77693_led_device *led =sub_led_to_led (sub_led); - -return __max77693_led_brightness_set (led, sub_led->fled_id, value); -} - -static void max77693_led_brightness_set ( -struct led_classdev *led_cdev, -enum led_brightness value) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct max77693_sub_led *sub_led =flcdev_to_sub_led (fled_cdev); - - sub_led->torch_brightness = value; -schedule_work (&sub_led->work_brightness_set); +return ret; } static int max77693_led_flash_brightness_set(
@@ -931,16 +897,13 @@ static void max77693_init_fled_cdev(struct max77693_sub_led *sub_led, led_cdev->name = led_cfg->label[fled_id]; - led_cdev->brightness_set = max77693_led_brightness_set; - led_cdev->brightness_set_blocking = max77693_led_brightness_set_sync; + led_cdev->brightness_set_blocking = max77693_led_brightness_set; led_cdev->max_brightness = (led->iout_joint ? led_cfg->iout_torch_max[FLED1 ] + led_cfg->iout_torch_max[FLED2 ] : led_cfg->iout_torch_max[fled_id]) /TORCH_IOUT_STEP ; led_cdev->flags |=LED_DEV_CAP_FLASH ; -INIT_WORK (&sub_led->work_brightness_set, - max77693_led_brightness_set_work);max77693_init_flash_settings (sub_led, led_cfg);
@@ -1062,13 +1025,11 @@ static int max77693_led_remove(struct platform_device *pdev)if (led->iout_joint ||max77693_fled_used (led,FLED1 )) {v4l2_flash_release (sub_leds[FLED1 ].v4l2_flash);led_classdev_flash_unregister (&sub_leds[FLED1 ].fled_cdev); -cancel_work_sync (&sub_leds[FLED1 ].work_brightness_set); }if (!led->iout_joint &&max77693_fled_used (led,FLED2 )) {v4l2_flash_release (sub_leds[FLED2 ].v4l2_flash);led_classdev_flash_unregister (&sub_leds[FLED2 ].fled_cdev); -cancel_work_sync (&sub_leds[FLED2 ].work_brightness_set); }mutex_destroy (&led->lock);
Signature · 1 line
1.7.9.5
PATCH v2 10/12 leds: aat1290: Remove work queue
In reply to Jacek AnaszewskiNow the core implements the work queue, remove it from the drivers, and switch to using brightness_set_blocking op.
--- drivers/leds/leds-aat1290.c | 50 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-)
drivers/leds/leds-aat1290.c +13 -37
@@ -20,7 +20,6 @@#include <linux/pinctrl/consumer.h> #include <linux/platform_device.h> #include <linux/slab.h> -#include <linux/workqueue.h> #include <media/v4l2-flash-led-class.h> #define AAT1290_MOVIE_MODE_CURRENT_ADDR 17
@@ -82,8 +81,6 @@ struct aat1290_led {/* brightness cache */ unsigned int torch_brightness; -/* assures led-triggers compatibility */ -struct work_struct work_brightness_set; }; static struct aat1290_led *fled_cdev_to_led(
@@ -92,6 +89,12 @@ static struct aat1290_led *fled_cdev_to_led( return container_of(fled_cdev, struct aat1290_led, fled_cdev); } +static struct led_classdev_flash *led_cdev_to_fled_cdev ( +struct led_classdev *led_cdev) +{ + return container_of(led_cdev, struct led_classdev_flash, led_cdev); +} +static void aat1290_as2cwire_write (struct aat1290_led *led,int addr,int value) {int i;
@@ -134,9 +137,14 @@ static void aat1290_set_flash_safety_timer(struct aat1290_led *led, flash_tm_reg); } -static void aat1290_brightness_set (struct aat1290_led *led, +/* LED subsystem callbacks */ + +static int aat1290_led_brightness_set (struct led_classdev *led_cdev,enum led_brightness brightness) { +struct led_classdev_flash *fled_cdev =led_cdev_to_fled_cdev (led_cdev); +struct aat1290_led *led =fled_cdev_to_led (fled_cdev); +mutex_lock (&led->lock);if (brightness ==0 ) {
@@ -158,35 +166,6 @@ static void aat1290_brightness_set(struct aat1290_led *led, }mutex_unlock (&led->lock); -} - -/* LED subsystem callbacks */ - -static void aat1290_brightness_set_work (struct work_struct *work) -{ -struct aat1290_led *led = - container_of(work, struct aat1290_led, work_brightness_set); - -aat1290_brightness_set (led, led->torch_brightness); -} - -static void aat1290_led_brightness_set (struct led_classdev *led_cdev, -enum led_brightness brightness) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct aat1290_led *led =fled_cdev_to_led (fled_cdev); - - led->torch_brightness = brightness; -schedule_work (&led->work_brightness_set); -} - -static int aat1290_led_brightness_set_sync (struct led_classdev *led_cdev, -enum led_brightness brightness) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct aat1290_led *led =fled_cdev_to_led (fled_cdev); - -aat1290_brightness_set (led, brightness);return 0 ; }
@@ -509,11 +488,9 @@ static int aat1290_led_probe(struct platform_device *pdev)mutex_init (&led->lock);/* Initialize LED Flash class device */ - led_cdev->brightness_set = aat1290_led_brightness_set; - led_cdev->brightness_set_blocking = aat1290_led_brightness_set_sync; + led_cdev->brightness_set_blocking = aat1290_led_brightness_set; led_cdev->max_brightness = led_cfg.max_brightness; led_cdev->flags |=LED_DEV_CAP_FLASH ; -INIT_WORK (&led->work_brightness_set, aat1290_brightness_set_work);aat1290_init_flash_timeout (led, &led_cfg);
@@ -548,7 +525,6 @@ static int aat1290_led_remove(struct platform_device *pdev)v4l2_flash_release (led->v4l2_flash);led_classdev_flash_unregister (&led->fled_cdev); -cancel_work_sync (&led->work_brightness_set);mutex_destroy (&led->lock);
Signature · 1 line
1.7.9.5
PATCH v2 12/12 media: flash: use led_set_brightness_sync for torch brightness
In reply to Jacek AnaszewskiLED subsystem shifted responsibility for choosing between SYNC or ASYNC way of setting brightness from drivers to the caller. Adapt the wrapper to those changes.
--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-flash-led-class.c +4 -4
@@ -107,10 +107,10 @@ static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH )return ; -led_set_brightness (&v4l2_flash->fled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->fled_cdev->led_cdev, brightness); }else { -led_set_brightness (&v4l2_flash->iled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->iled_cdev->led_cdev, brightness); } }
@@ -206,11 +206,11 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)case V4L2_CID_FLASH_LED_MODE :switch (c->val) {case V4L2_FLASH_LED_MODE_NONE : -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );return led_set_flash_strobe (fled_cdev, false);case V4L2_FLASH_LED_MODE_FLASH :/* Turn the torch LED off */ -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );if (ctrls[STROBE_SOURCE ]) { external_strobe = (ctrls[STROBE_SOURCE ]->val ==V4L2_FLASH_STROBE_SOURCE_EXTERNAL );
Signature · 1 line
1.7.9.5
v2 cover LED core improvements
This is a second version of the patch set preparing the ground for removing work queues from LED class drivers. Andrew and Sakari - thanks for a review.
================
Changes from v1:
================
- removed useless use of else in led_set_brightness()
- switched to removing error code instead of emitting warning from led_set_brightness_sync() in case software blink fallback is enabled
- moved __led_set_brightness() contents to set_brightness_delayed()
- removed description of internal led_set_brightness_nosleep() from led-class.txt documentation, and modified description of led_set_brightness() and led_set_brightness_sync()
- renamed LED_BLINK_CHANGE flag to more meaningful LED_BLINK_BRIGHTNESS_CHANGE
- Fixed stylistic issues in a few comments
- Adopted old brightness_set_sync() op description to
a new brightness_set_blocking() op
- Fixed led_set_brightness_nosleep to avoid scheduling spurious set_brightness_work
- made LED core using EXPORT_SYMBOL_GPL consistently
- switched v4l2-flash-led-class wrapper to using led_set_brightness_sync API for setting torch brightness
- merged with patch set
"LED flash: Set brightness in a sync way on demand"
======================
Original cover letter:
======================
This patch set prepares the ground for removing work queues from LED class drivers, and is a follow up of the patch set [1]. LED core modifications have been reorganized to make them more clear and easier to review. The patch set is reduced in comparison to it its predecessor, to expose the modifications indispensable for the LED core to gain the capability of handling brightness_set_blocking ops, that is without work queues.
Thanks,
Jacek Anaszewski
[1] https://lkml.org/lkml/2015/8/20/426
Jacek Anaszewski (12):
leds: core: Use EXPORT_SYMBOL_GPL consistently
leds: core: Move LED core callbacks out of led-class.c
leds: core: Add two new LED_BLINK_ flags
leds: Rename brightness_set_sync op to brightness_set_blocking
leds: core: Add an internal led_set_brightness_nosleep function
leds: core: Use set_brightness_work for the blocking op
leds: core: Drivers shouldn't enforce SYNC/ASYNC brightness setting
Documentation: leds: Add description of brightness setting API
leds: max77693: Remove work queue
leds: aat1290: Remove work queue
leds: ktd2692: Remove work queue
media: flash: use led_set_brightness_sync for torch brightness
Documentation/leds/leds-class.txt | 13 ++ drivers/leds/led-class-flash.c | 6 +- drivers/leds/led-class.c | 71 +--------- drivers/leds/led-core.c | 166 +++++++++++++++++++++--- drivers/leds/leds-aat1290.c | 50 ++----- drivers/leds/leds-ktd2692.c | 41 +----- drivers/leds/leds-max77693.c | 57 ++------ drivers/leds/leds.h | 26 +--- drivers/leds/trigger/ledtrig-backlight.c | 8 +- drivers/leds/trigger/ledtrig-default-on.c | 2 +- drivers/leds/trigger/ledtrig-gpio.c | 6 +- drivers/leds/trigger/ledtrig-heartbeat.c | 4 +- drivers/leds/trigger/ledtrig-oneshot.c | 4 +- drivers/leds/trigger/ledtrig-transient.c | 8 +- drivers/media/v4l2-core/v4l2-flash-led-class.c | 8 +- include/linux/leds.h | 27 +++- 16 files changed, 233 insertions(+), 264 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 5/12 leds: core: Add an internal led_set_brightness_nosleep function
This patch adds led_set_brightness_nosleep function, which guarantees setting LED brightness in a non-blocking way. It also replaces led_set_brightness_async with led_set_brightness_nosleep in all places where the most vital was setting brightness in a non sleeping way but not necessarily asynchronously, which is not needed for non-blocking drivers.
--- drivers/leds/led-core.c | 31 ++++++++++++++++++++++++----- drivers/leds/leds.h | 2 ++ drivers/leds/trigger/ledtrig-backlight.c | 8 ++++---- drivers/leds/trigger/ledtrig-default-on.c | 2 +- drivers/leds/trigger/ledtrig-gpio.c | 6 +++--- drivers/leds/trigger/ledtrig-heartbeat.c | 4 ++-- drivers/leds/trigger/ledtrig-oneshot.c | 4 ++-- drivers/leds/trigger/ledtrig-transient.c | 8 ++++---- 8 files changed, 44 insertions(+), 21 deletions(-)
drivers/leds/led-core.c +26 -5
@@ -32,7 +32,7 @@ static void led_timer_function(unsigned long data)unsigned long delay;if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { -led_set_brightness_async (led_cdev,LED_OFF ); +led_set_brightness_nosleep (led_cdev,LED_OFF );return ; }
@@ -60,7 +60,7 @@ static void led_timer_function(unsigned long data) delay = led_cdev->blink_delay_off; } -led_set_brightness_async (led_cdev, brightness); +led_set_brightness_nosleep (led_cdev, brightness);/* Return in next iteration if led is in one-shot mode and we are in * the final blink state so that the led is toggled each delay_on +
@@ -110,13 +110,14 @@ static void led_set_software_blink(struct led_classdev *led_cdev,/* never on - just set to off */ if (!delay_on) { -led_set_brightness_async (led_cdev,LED_OFF ); +led_set_brightness_nosleep (led_cdev,LED_OFF );return ; }/* never off - just set to brightness */ if (!delay_off) { -led_set_brightness_async (led_cdev, led_cdev->blink_brightness); +led_set_brightness_nosleep (led_cdev, + led_cdev->blink_brightness);return ; }
@@ -217,7 +218,7 @@ void led_set_brightness(struct led_classdev *led_cdev, }if (led_cdev->flags &SET_BRIGHTNESS_ASYNC ) { -led_set_brightness_async (led_cdev, brightness); +led_set_brightness_nosleep (led_cdev, brightness);return ; }else if (led_cdev->flags &SET_BRIGHTNESS_SYNC ) ret =led_set_brightness_sync (led_cdev, brightness);
@@ -230,6 +231,26 @@ void led_set_brightness(struct led_classdev *led_cdev, }EXPORT_SYMBOL_GPL (led_set_brightness); +void led_set_brightness_nosleep (struct led_classdev *led_cdev, +enum led_brightness value) +{ + led_cdev->brightness =min (value, led_cdev->max_brightness); + +if (led_cdev->flags &LED_SUSPENDED ) +return ; + +/* Use brightness_set op if available, it is guaranteed not to sleep */ +if (led_cdev->brightness_set) { + led_cdev->brightness_set (led_cdev, led_cdev->brightness); +return ; + } + +/* If brightness setting can sleep, delegate it to a work queue task */ + led_cdev->delayed_set_value = led_cdev->brightness; +schedule_work (&led_cdev->set_brightness_work); +} +EXPORT_SYMBOL_GPL (led_set_brightness_nosleep); +int led_update_brightness (struct led_classdev *led_cdev) {int ret =0 ;
drivers/leds/leds.h +2 -0
@@ -46,6 +46,8 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)void led_init_core (struct led_classdev *led_cdev);void led_stop_software_blink (struct led_classdev *led_cdev); +void led_set_brightness_nosleep (struct led_classdev *led_cdev, +enum led_brightness value);extern struct rw_semaphore leds_list_lock;extern struct list_head leds_list;
drivers/leds/trigger/ledtrig-backlight.c +4 -4
@@ -51,9 +51,9 @@ static int fb_notifier_callback(struct notifier_block *p,if ((n->old_status ==UNBLANK ) ^ n->invert) { n->brightness = led->brightness; -led_set_brightness_async (led,LED_OFF ); +led_set_brightness_nosleep (led,LED_OFF ); }else { -led_set_brightness_async (led, n->brightness); +led_set_brightness_nosleep (led, n->brightness); } n->old_status = new_status;
@@ -89,9 +89,9 @@ static ssize_t bl_trig_invert_store(struct device *dev,/* After inverting, we need to update the LED. */ if ((n->old_status ==BLANK ) ^ n->invert) -led_set_brightness_async (led,LED_OFF ); +led_set_brightness_nosleep (led,LED_OFF );else -led_set_brightness_async (led, n->brightness); +led_set_brightness_nosleep (led, n->brightness);return num; }
drivers/leds/trigger/ledtrig-default-on.c +1 -1
@@ -19,7 +19,7 @@static void defon_trig_activate (struct led_classdev *led_cdev) { -led_set_brightness_async (led_cdev, led_cdev->max_brightness); +led_set_brightness_nosleep (led_cdev, led_cdev->max_brightness); }static struct led_trigger defon_led_trigger = {
drivers/leds/trigger/ledtrig-gpio.c +3 -3
@@ -54,12 +54,12 @@ static void gpio_trig_work(struct work_struct *work)if (tmp) {if (gpio_data->desired_brightness) -led_set_brightness_async (gpio_data->led, +led_set_brightness_nosleep (gpio_data->led, gpio_data->desired_brightness);else -led_set_brightness_async (gpio_data->led,LED_FULL ); +led_set_brightness_nosleep (gpio_data->led,LED_FULL ); }else { -led_set_brightness_async (gpio_data->led,LED_OFF ); +led_set_brightness_nosleep (gpio_data->led,LED_OFF ); } }
drivers/leds/trigger/ledtrig-heartbeat.c +2 -2
@@ -37,7 +37,7 @@ static void led_heartbeat_function(unsigned long data)unsigned long delay =0 ;if (unlikely (panic_heartbeats)) { -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_nosleep (led_cdev,LED_OFF );return ; }
@@ -74,7 +74,7 @@ static void led_heartbeat_function(unsigned long data)break ; } -led_set_brightness_async (led_cdev, brightness); +led_set_brightness_nosleep (led_cdev, brightness);mod_timer (&heartbeat_data->timer, jiffies + delay); }
drivers/leds/trigger/ledtrig-oneshot.c +2 -2
@@ -63,9 +63,9 @@ static ssize_t led_invert_store(struct device *dev, oneshot_data->invert = !!state;if (oneshot_data->invert) -led_set_brightness_async (led_cdev,LED_FULL ); +led_set_brightness_nosleep (led_cdev,LED_FULL );else -led_set_brightness_async (led_cdev,LED_OFF ); +led_set_brightness_nosleep (led_cdev,LED_OFF );return size; }
drivers/leds/trigger/ledtrig-transient.c +4 -4
@@ -41,7 +41,7 @@ static void transient_timer_function(unsigned long data)struct transient_trig_data *transient_data = led_cdev->trigger_data; transient_data->activate =0 ; -led_set_brightness_async (led_cdev, transient_data->restore_state); +led_set_brightness_nosleep (led_cdev, transient_data->restore_state); } static ssize_t transient_activate_show(struct device *dev,
@@ -72,7 +72,7 @@ static ssize_t transient_activate_store(struct device *dev,if (state ==0 && transient_data->activate ==1 ) {del_timer (&transient_data->timer); transient_data->activate = state; -led_set_brightness_async (led_cdev, +led_set_brightness_nosleep (led_cdev, transient_data->restore_state);return size; }
@@ -81,7 +81,7 @@ static ssize_t transient_activate_store(struct device *dev,if (state ==1 && transient_data->activate ==0 && transient_data->duration !=0 ) { transient_data->activate = state; -led_set_brightness_async (led_cdev, transient_data->state); +led_set_brightness_nosleep (led_cdev, transient_data->state); transient_data->restore_state = (transient_data->state ==LED_FULL ) ?LED_OFF :LED_FULL ; mod_timer(&transient_data->timer,
@@ -204,7 +204,7 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev)if (led_cdev->activated) {del_timer_sync (&transient_data->timer); -led_set_brightness_async (led_cdev, +led_set_brightness_nosleep (led_cdev, transient_data->restore_state);device_remove_file (led_cdev->dev, &dev_attr_activate);device_remove_file (led_cdev->dev, &dev_attr_duration);
Signature · 1 line
1.7.9.5
PATCH v2 6/12 leds: core: Use set_brightness_work for the blocking op
In reply to Jacek AnaszewskiThis 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.
--- drivers/leds/led-core.c | 12 +++++++++++- drivers/leds/leds.h | 10 ---------- include/linux/leds.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-)
drivers/leds/led-core.c +11 -1
@@ -83,6 +83,7 @@ static void set_brightness_delayed(struct work_struct *ws) {struct led_classdev *led_cdev = container_of(ws, struct led_classdev, set_brightness_work); +int ret =0 ;if (led_cdev->flags &LED_BLINK_DISABLE ) { led_cdev->delayed_set_value =LED_OFF ;
@@ -90,7 +91,16 @@ static void set_brightness_delayed(struct work_struct *ws) led_cdev->flags &= ~LED_BLINK_DISABLE ; } -led_set_brightness_async (led_cdev, led_cdev->delayed_set_value); +if (led_cdev->brightness_set) + led_cdev->brightness_set (led_cdev, led_cdev->brightness); +else if (led_cdev->brightness_set_blocking) + ret = led_cdev->brightness_set_blocking (led_cdev, + led_cdev->brightness); +else + ret = -ENOTSUPP ; +if (ret <0 ) +dev_err (led_cdev->dev, +"Setting an LED's brightness failed (%d)\n" , ret); } static void led_set_software_blink(struct led_classdev *led_cdev,
drivers/leds/leds.h +0 -10
@@ -16,16 +16,6 @@#include <linux/rwsem.h> #include <linux/leds.h> -static inline void led_set_brightness_async (struct led_classdev *led_cdev, -enum led_brightness value) -{ - value =min (value, led_cdev->max_brightness); - led_cdev->brightness = value; - -if (!(led_cdev->flags &LED_SUSPENDED )) - led_cdev->brightness_set (led_cdev, value); -} -static inline int led_set_brightness_sync (struct led_classdev *led_cdev,enum led_brightness value) {
include/linux/leds.h +1 -1
@@ -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);
Signature · 1 line
1.7.9.5
PATCH v2 11/12 leds: ktd2692: Remove work queue
In reply to Jacek AnaszewskiNow the core implements the work queue, remove it from the drivers, and switch to using brightness_set_blocking op.
--- drivers/leds/leds-ktd2692.c | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-)
drivers/leds/leds-ktd2692.c +6 -35
@@ -18,7 +18,6 @@#include <linux/of.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> -#include <linux/workqueue.h> /* Value related the movie mode */ #define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16
@@ -82,7 +81,6 @@ struct ktd2692_context {/* secures access to the device */ struct mutex lock;struct regulator *regulator; -struct work_struct work_brightness_set;struct gpio_desc *aux_gpio;struct gpio_desc *ctrl_gpio;
@@ -158,9 +156,12 @@ static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value)ktd2692_expresswire_end (led); } -static void ktd2692_brightness_set (struct ktd2692_context *led, -enum led_brightness brightness) +static int ktd2692_led_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) { +struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); +struct ktd2692_context *led =fled_cdev_to_led (fled_cdev); +mutex_lock (&led->lock);if (brightness ==LED_OFF ) {
@@ -174,33 +175,6 @@ static void ktd2692_brightness_set(struct ktd2692_context *led,ktd2692_expresswire_write (led, led->mode |KTD2692_REG_MODE_BASE );mutex_unlock (&led->lock); -} - -static void ktd2692_brightness_set_work (struct work_struct *work) -{ -struct ktd2692_context *led = - container_of(work, struct ktd2692_context, work_brightness_set); - -ktd2692_brightness_set (led, led->torch_brightness); -} - -static void ktd2692_led_brightness_set (struct led_classdev *led_cdev, -enum led_brightness brightness) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct ktd2692_context *led =fled_cdev_to_led (fled_cdev); - - led->torch_brightness = brightness; -schedule_work (&led->work_brightness_set); -} - -static int ktd2692_led_brightness_set_sync (struct led_classdev *led_cdev, -enum led_brightness brightness) -{ -struct led_classdev_flash *fled_cdev =lcdev_to_flcdev (led_cdev); -struct ktd2692_context *led =fled_cdev_to_led (fled_cdev); - -ktd2692_brightness_set (led, brightness);return 0 ; }
@@ -381,12 +355,10 @@ static int ktd2692_probe(struct platform_device *pdev) fled_cdev->ops = &flash_ops; led_cdev->max_brightness = led_cfg.max_brightness; - led_cdev->brightness_set = ktd2692_led_brightness_set; - led_cdev->brightness_set_blocking = ktd2692_led_brightness_set_sync; + led_cdev->brightness_set_blocking = ktd2692_led_brightness_set; led_cdev->flags |=LED_CORE_SUSPENDRESUME |LED_DEV_CAP_FLASH ;mutex_init (&led->lock); -INIT_WORK (&led->work_brightness_set, ktd2692_brightness_set_work);platform_set_drvdata (pdev, led);
@@ -408,7 +380,6 @@ static int ktd2692_remove(struct platform_device *pdev)int ret;led_classdev_flash_unregister (&led->fled_cdev); -cancel_work_sync (&led->work_brightness_set);if (led->regulator) { ret =regulator_disable (led->regulator);
Signature · 1 line
1.7.9.5
Re: [PATCH v2 01/12] leds: core: Use EXPORT_SYMBOL_GPL consistently
In reply to Jacek AnaszewskiThis patch isn't going to be applied since it can cause legal implications for existing users.
Quoted 50 lines · Jacek Anaszewski
LED core has a mixture of
EXPORT_SYMBOLandEXPORT_SYMBOL_GPLmacros. This patch fixes this discrepancy and switches to usingEXPORT_SYMBOL_GPLfor each exported function.Signed-off-by Jacek Anaszewski <[email protected]>--- drivers/leds/led-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/leds/led-core.c +4
-4@@ -83,7 +83,7 @@ void led_blink_set(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set); +EXPORT_SYMBOL_GPL (led_blink_set); void led_blink_set_oneshot(struct led_classdev *led_cdev, unsigned long *delay_on,@@ -104,7 +104,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set_oneshot); +EXPORT_SYMBOL_GPL (led_blink_set_oneshot);void led_stop_software_blink (struct led_classdev *led_cdev) {@@ -139,7 +139,7 @@ void led_set_brightness(struct led_classdev *led_cdev,dev_dbg (led_cdev->dev,"Setting LED brightness failed (%d)\n" , ret); } -EXPORT_SYMBOL (led_set_brightness); +EXPORT_SYMBOL_GPL (led_set_brightness);int led_update_brightness (struct led_classdev *led_cdev) {@@ -155,7 +155,7 @@ int led_update_brightness(struct led_classdev *led_cdev)return ret; } -EXPORT_SYMBOL (led_update_brightness); +EXPORT_SYMBOL_GPL (led_update_brightness);/* Caller must ensure led_cdev->led_access held */ void led_sysfs_disable (struct led_classdev *led_cdev)
Signature · 2 lines
Best Regards, Jacek Anaszewski
Re: [PATCH v2 12/12] media: flash: use led_set_brightness_sync for torch brightness
In reply to Jacek AnaszewskiQuoted 3 lines · Jacek Anaszewski
LED subsystem shifted responsibility for choosing between SYNC or ASYNC way of setting brightness from drivers to the caller. Adapt the wrapper to those changes.
Umm. Maybe right patch, but wrong position in the queue, no?
If I understand changelog correctly, LED flashes will be subtly broken before this patch is applied.
I guess this patch should be moved sooner so everything works at each position in bisect...?
Best regards,
Pavel
Quoted 39 lines
Signed-off-by Jacek Anaszewski <[email protected]>Cc Sakari Ailus <[email protected]>Cc Pavel Machek <[email protected]>--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/media/v4l2-core/v4l2-flash-led-class.c +4
-4@@ -107,10 +107,10 @@ static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH )return ; -led_set_brightness (&v4l2_flash->fled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->fled_cdev->led_cdev, brightness); }else { -led_set_brightness (&v4l2_flash->iled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->iled_cdev->led_cdev, brightness); } }@@ -206,11 +206,11 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)case V4L2_CID_FLASH_LED_MODE :switch (c->val) {case V4L2_FLASH_LED_MODE_NONE : -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );return led_set_flash_strobe (fled_cdev, false);case V4L2_FLASH_LED_MODE_FLASH :/* Turn the torch LED off */ -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );if (ctrls[STROBE_SOURCE ]) { external_strobe = (ctrls[STROBE_SOURCE ]->val ==V4L2_FLASH_STROBE_SOURCE_EXTERNAL );
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v2 12/12] media: flash: use led_set_brightness_sync for torch brightness
Hi Pavel,
Thanks for the review.
Quoted 5 lines · Pavel Machek
Quoted 3 lines · Jacek Anaszewski
LED subsystem shifted responsibility for choosing between SYNC or ASYNC way of setting brightness from drivers to the caller. Adapt the wrapper to those changes.
Quoted 7 lines
Umm. Maybe right patch, but wrong position in the queue, no?
If I understand changelog correctly, LED flashes will be subtly broken before this patch is applied.
I guess this patch should be moved sooner so everything works at each position in bisect...?
Moving it wouldn't improve anything. It would have to be merged with patch 7/12 [1]. However, as you mentioned, LED flashes before this patch will be broken only subtly, i.e. torch brightness will be set from a work queue task and not synchronously. It would be barely noticeable. Nonetheless, I can merge the patches in the next version of the patch set.
[1] https://lkml.org/lkml/2015/9/28/322
Quoted 43 lines
Best regards,
PavelQuoted 39 lines
Signed-off-by Jacek Anaszewski <[email protected]>Cc Sakari Ailus <[email protected]>Cc Pavel Machek <[email protected]>--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/media/v4l2-core/v4l2-flash-led-class.c +4
-4@@ -107,10 +107,10 @@ static void v4l2_flash_set_led_brightness(struct v4l2_flash *v4l2_flash,if (ctrls[LED_MODE ]->val !=V4L2_FLASH_LED_MODE_TORCH )return ; -led_set_brightness (&v4l2_flash->fled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->fled_cdev->led_cdev, brightness); }else { -led_set_brightness (&v4l2_flash->iled_cdev->led_cdev, +led_set_brightness_sync (&v4l2_flash->iled_cdev->led_cdev, brightness); } }@@ -206,11 +206,11 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)case V4L2_CID_FLASH_LED_MODE :switch (c->val) {case V4L2_FLASH_LED_MODE_NONE : -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );return led_set_flash_strobe (fled_cdev, false);case V4L2_FLASH_LED_MODE_FLASH :/* Turn the torch LED off */ -led_set_brightness (led_cdev,LED_OFF ); +led_set_brightness_sync (led_cdev,LED_OFF );if (ctrls[STROBE_SOURCE ]) { external_strobe = (ctrls[STROBE_SOURCE ]->val ==V4L2_FLASH_STROBE_SOURCE_EXTERNAL );
Signature · 2 lines
Best Regards, Jacek Anaszewski
Re: [PATCH v2 12/12] media: flash: use led_set_brightness_sync for torch brightness
Quoted 18 lines · Jacek Anaszewski
Hi Pavel,
Thanks for the review.
Quoted 5 lines · Pavel Machek
Quoted 3 lines · Jacek Anaszewski
LED subsystem shifted responsibility for choosing between SYNC or ASYNC way of setting brightness from drivers to the caller. Adapt the wrapper to those changes.
Quoted 7 lines
Umm. Maybe right patch, but wrong position in the queue, no?
If I understand changelog correctly, LED flashes will be subtly broken before this patch is applied.
I guess this patch should be moved sooner so everything works at each position in bisect...?
Quoted 6 lines
Moving it wouldn't improve anything. It would have to be merged with patch 7/12 [1]. However, as you mentioned, LED flashes before this patch will be broken only subtly, i.e. torch brightness will be set from a work queue task and not synchronously. It would be barely noticeable. Nonetheless, I can merge the patches in the next version of the patch set.
Ok, flash firing a tiny bit later is probably not huge problem. I guess it is best to leave the patches as is.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Jacek,
Quoted 19 lines · Jacek Anaszewski
This is a second version of the patch set preparing the ground for removing work queues from LED class drivers. Andrew and Sakari - thanks for a review.
================
Changes from v1:
================
- removed useless use of else inled_set_brightness()
- switched to removing error code instead of emitting warning fromled_set_brightness_sync()in case software blink fallback is enabled
- moved__led_set_brightness()contents toset_brightness_delayed()
- removed description of internalled_set_brightness_nosleep()from led-class.txt documentation, and modified description ofled_set_brightness()andled_set_brightness_sync()
- renamedLED_BLINK_CHANGEflag to more meaningfulLED_BLINK_BRIGHTNESS_CHANGE
- Fixed stylistic issues in a few comments
- Adopted oldbrightness_set_sync()op description to
Quoted 8 lines
a new
brightness_set_blocking()op
- Fixedled_set_brightness_nosleepto avoid scheduling spuriousset_brightness_work
- made LED core usingEXPORT_SYMBOL_GPLconsistently
- switched v4l2-flash-led-class wrapper to usingled_set_brightness_syncAPI for setting torch brightness
- merged with patch set
"LED flash: Set brightness in a sync way on demand"
Thanks for the update.
A few comments on no particular patch ---
- Synchronous brightness setting is only possible with drivers that implement blocking brigtness setting op. Should the work queue be removed from the rest of the drivers, this would be easy to fix.
- led_classdev_suspend() and led_classdev_resume() still unconditionally call ->brightness_set() which may now be NULL. This needs to be fixed.
Signature · 4 lines
Kind regards, Sakari Ailus [email protected]
Hi Sakari,
Quoted 31 lines · Sakari Ailus
Hi Jacek,
Quoted 19 lines · Jacek Anaszewski
This is a second version of the patch set preparing the ground for removing work queues from LED class drivers. Andrew and Sakari - thanks for a review.
================
Changes from v1:
================
- removed useless use of else inled_set_brightness()
- switched to removing error code instead of emitting warning fromled_set_brightness_sync()in case software blink fallback is enabled
- moved__led_set_brightness()contents toset_brightness_delayed()
- removed description of internalled_set_brightness_nosleep()from led-class.txt documentation, and modified description ofled_set_brightness()andled_set_brightness_sync()
- renamedLED_BLINK_CHANGEflag to more meaningfulLED_BLINK_BRIGHTNESS_CHANGE
- Fixed stylistic issues in a few comments
- Adopted oldbrightness_set_sync()op description toQuoted 8 lines
a new
brightness_set_blocking()op
- Fixedled_set_brightness_nosleepto avoid scheduling spuriousset_brightness_work
- made LED core usingEXPORT_SYMBOL_GPLconsistently
- switched v4l2-flash-led-class wrapper to usingled_set_brightness_syncAPI for setting torch brightness
- merged with patch set
"LED flash: Set brightness in a sync way on demand"
Quoted 7 lines
Thanks for the update.
A few comments on no particular patch ---
- Synchronous brightness setting is only possible with drivers that implement blocking brigtness setting op. Should the work queue be removed from the rest of the drivers, this would be easy to fix.
Work queues are removed from drivers in the patch set [1], and I plan on picking them after merging this series. Those changes replace brightness_set op initialization with brightness_set_blocking. What needs modifications to support led_set_brightness_sync API are drivers with non-blocking brightness_set op. The question is whether it should be accomplished by simply adding brightness_set_blocking op initialization, with the same function as in case of brightness_set op. Alternatively we could avoid removing SET_BRIGHTNESS_SYNC flag, and mark non-blocking drivers with it to inform the core that they set brightness synchronously.
Quoted 3 lines
-
led_classdev_suspend()andled_classdev_resume()still unconditionally call ->brightness_set() which may now be NULL. This needs to be fixed.
Right, I noticed that at some point but finally forgot to address. Will fix in the next version.
[1] https://lkml.org/lkml/2015/8/20/426
Signature · 2 lines
Best Regards, Jacek Anaszewski
Re: [PATCH v2 01/12] leds: core: Use EXPORT_SYMBOL_GPL consistently
In reply to Jacek AnaszewskiQuoted 3 lines · Jacek Anaszewski
This patch isn't going to be applied since it can cause legal implications for existing users.
Are there any? Best do this ASAP :-).
Pavel
Quoted 61 lines · Jacek Anaszewski
Quoted 50 lines
LED core has a mixture of
EXPORT_SYMBOLandEXPORT_SYMBOL_GPLmacros. This patch fixes this discrepancy and switches to usingEXPORT_SYMBOL_GPLfor each exported function.Signed-off-by Jacek Anaszewski <[email protected]>--- drivers/leds/led-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/leds/led-core.c +4
-4@@ -83,7 +83,7 @@ void led_blink_set(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set); +EXPORT_SYMBOL_GPL (led_blink_set); void led_blink_set_oneshot(struct led_classdev *led_cdev, unsigned long *delay_on,@@ -104,7 +104,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev,led_blink_setup (led_cdev, delay_on, delay_off); } -EXPORT_SYMBOL (led_blink_set_oneshot); +EXPORT_SYMBOL_GPL (led_blink_set_oneshot);void led_stop_software_blink (struct led_classdev *led_cdev) {@@ -139,7 +139,7 @@ void led_set_brightness(struct led_classdev *led_cdev,dev_dbg (led_cdev->dev,"Setting LED brightness failed (%d)\n" , ret); } -EXPORT_SYMBOL (led_set_brightness); +EXPORT_SYMBOL_GPL (led_set_brightness);int led_update_brightness (struct led_classdev *led_cdev) {@@ -155,7 +155,7 @@ int led_update_brightness(struct led_classdev *led_cdev)return ret; } -EXPORT_SYMBOL (led_update_brightness); +EXPORT_SYMBOL_GPL (led_update_brightness);/* Caller must ensure led_cdev->led_access held */ void led_sysfs_disable (struct led_classdev *led_cdev)Signature · 7 lines
Best Regards, Jacek Anaszewski -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v2 01/12] leds: core: Use EXPORT_SYMBOL_GPL consistently
Quoted 6 lines · Pavel Machek
Quoted 3 lines · Jacek Anaszewski
This patch isn't going to be applied since it can cause legal implications for existing users.
Are there any? Best do this ASAP :-).
Current non-GPL users of led_set_brightness would be affected if we changed this. I am not however certain if there are any, having in mind that led_classdev_register is exported with EXPORT_SYMBOL_GPL. Theoretically it is possible to use led_set_brightness without registering LED class device, but it would be partially broken then due to not initialized set_brightness_work.
I think that it would be safe to apply this patch.
I need acks, though :)
Signature · 2 lines
Best Regards, Jacek Anaszewski
Pavel Machek
Acked-byRe: [PATCH v2 01/12] leds: core: Use EXPORT_SYMBOL_GPL consistently
Quoted 11 lines · Jacek Anaszewski
Quoted 6 lines · Pavel Machek
Quoted 3 lines · Jacek Anaszewski
This patch isn't going to be applied since it can cause legal implications for existing users.
Are there any? Best do this ASAP :-).
Current non-GPL users of
led_set_brightnesswould be affected if we changed this. I am not however certain if there are any, having in mind
Actually, _GPL or not is just an annotation, it has little legal power.
Quoted 6 lines
that
led_classdev_registeris exported withEXPORT_SYMBOL_GPL. Theoretically it is possible to useled_set_brightnesswithout registering LED class device, but it would be partially broken then due to not initializedset_brightness_work.
I think that it would be safe to apply this patch.
I need acks, though :)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html