2015-07-03 13:11:30

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 0/7] Remove work queues from LED class drivers

This is a third version of the RFC aiming at removing work queues
from LED class drivers, as well as getting rid of complimentary
functionalities introduced along with addition of LED flash class
extension.


======================
Changes from version 2
======================

- split changes to several incremental patches
- removed SET_BRIGHTNESS_SYNC and SET_BRIGHTNESS_ASYNC flags
- fixed led_set_brightness_async function instead of renaming it

======================
Changes from version 1
======================

V2 includes also patches for one LED class driver
and two LED flash class drivers, that show how the
drivers will benefit from the optimization being
introduced in the first patch of this patch set.

I was able to test only the LED Flash class drivers.

Original message from the patch 483a3122 ("leds: Use set_brightness_work for
brightness_set ops that can sleep") that was sent previously as a single one:

Hi All,

Since this patch will affect all the LED subsystem drivers
I'd like it was tested by as many developers as possible
to make sure that I haven't missed something.

For the drivers which can sleep in their brightness_set ops
(e.g. use mutex or gpio "cansleep" API) you only need to
remove the work queues and move the code executed currently
in the work queue task to the brightness_set op, as now
LED core does the job.

For drivers that are capable of setting brightness with use
of MMIO you need to set the LED_BRIGHTNESS_FAST flag, so
that LED core would know that it doesn't have to employ
work queue.

After the patch is positively verified I will create relevant
patches for every LED class driver.

This patch is based on linux-next_20150622.

I am looking forward to your cooperation.

Best Regards,
Jacek Anaszewski

Jacek Anaszewski (7):
leds: Add led_set_brightness_sync to the public LED subsystem API
leds: Improve asynchronous path of setting brightness
leds: Add an internal led_set_brightness_nosleep function
leds: Improve setting brightness in a non sleeping way
leds: Drivers shouldn't enforce SYNC/ASYNC brightness setting
media: flash: use led_set_brightness_sync for torch brightness
leds: pwm: remove work queue

drivers/leds/led-class-flash.c | 7 ---
drivers/leds/led-class.c | 20 +++++----
drivers/leds/led-core.c | 42 +++++++++---------
drivers/leds/leds-aat1290.c | 50 ++++++---------------
drivers/leds/leds-ktd2692.c | 41 +++---------------
drivers/leds/leds-max77693.c | 55 +++---------------------
drivers/leds/leds-pwm.c | 24 ++---------
drivers/leds/leds.h | 34 ++++++++-------
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 | 36 +++++++++++-----
16 files changed, 124 insertions(+), 225 deletions(-)

--
1.7.9.5


2015-07-03 13:12:25

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 1/7] leds: Add led_set_brightness_sync to the public LED subsystem API

led_set_brightness_sync function was visible only internally to the
LED subsystem. It is now being made publicly available since it has
become apparent that this is a caller who should decide whether
brightness is to be set in a synchronous or an asynchronous way.
The function is modified to use brightness_set op as the second
option if brightness_set_sync is not implemented. Eventually all
LED subsystem drivers will be modfified to set brightness only in
a synchronous way with use of brightness_set op and brightness_set_sync
op will be removed. LED core will take care of calling brightness_set
op asynchronously if needed.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/leds.h | 13 -------------
include/linux/leds.h | 29 +++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index bc89d7a..1c026c9 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -26,19 +26,6 @@ static inline void led_set_brightness_async(struct led_classdev *led_cdev,
led_cdev->brightness_set(led_cdev, value);
}

-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_sync(led_cdev,
- led_cdev->brightness);
- return ret;
-}
-
static inline int led_get_brightness(struct led_classdev *led_cdev)
{
return led_cdev->brightness;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index b122eea..9b62a3c 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -160,6 +160,35 @@ 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 register,
+ * and it can sleep.
+ */
+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)
+ return 0;
+
+ if (led_cdev->brightness_set_sync)
+ ret = led_cdev->brightness_set_sync(led_cdev,
+ led_cdev->brightness);
+ else
+ led_cdev->brightness_set(led_cdev, led_cdev->brightness);
+
+ return 0;
+}
+
/**
* led_update_brightness - update LED brightness
* @led_cdev: the LED to query
--
1.7.9.5

2015-07-03 13:13:30

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 2/7] leds: Improve asynchronous path of setting brightness

led_set_brightness_async function didn't set the brightness in an
asynchronous way in all cases. It was mistakenly assuming that all
LED subsystem drivers use work queue in their brightness_set op,
whereas only half of them does that. Modify the function to assure
setting brightness asynchronously in all cases by using existing
set_brightness_delayed work queue.

The work queue is now made using led_set_brightness_sync for setting
brightness. This modification changes the initial purpose of the work
queue, which was used for setting brightness only if blink timer was
active. In order to keep this functionality a LED_BLINK_DISABLE flag
is being introduced, as well as a new 'new_brightness_value' field
is being added to the struct led_classdev. All these improvements
entail changes in the led_brightness_set function.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/led-class.c | 14 +++++++++-----
drivers/leds/led-core.c | 20 ++++++++++++++++----
drivers/leds/leds.h | 9 +++------
include/linux/leds.h | 2 ++
4 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index beabfbc..b8decf7 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -121,10 +121,10 @@ 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) {
+ if (led_cdev->new_brightness_value) {
led_cdev->blink_brightness =
- led_cdev->delayed_set_value;
- led_cdev->delayed_set_value = 0;
+ led_cdev->new_brightness_value;
+ led_cdev->new_brightness_value = 0;
}
brightness = led_cdev->blink_brightness;
delay = led_cdev->blink_delay_on;
@@ -161,9 +161,13 @@ 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_stop_software_blink(led_cdev);
+ led_cdev->flags &= ~LED_BLINK_DISABLE;
+ return;
+ }

- led_set_brightness_async(led_cdev, led_cdev->delayed_set_value);
+ led_set_brightness_sync(led_cdev, led_cdev->delayed_set_value);
}

/**
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 549de7e..16fe995 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -119,11 +119,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)
- schedule_work(&led_cdev->set_brightness_work);
+ led_cdev->new_brightness_value = brightness;
+
+ /* New brightness will be set on next timer tick. */
+ if (brightness != LED_OFF)
+ return;
+ /*
+ * If need to disable soft blinking delegate this to the
+ * work queue task to avoid problems in case we are
+ * called from hard irq context.
+ */
+ led_cdev->flags |= LED_BLINK_DISABLE;
+ led_set_brightness_async(led_cdev, brightness);
return;
}

diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index 1c026c9..ca38f6a 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -17,13 +17,10 @@
#include <linux/leds.h>

static inline void led_set_brightness_async(struct led_classdev *led_cdev,
- enum led_brightness value)
+ 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);
+ led_cdev->delayed_set_value = value;
+ schedule_work(&led_cdev->set_brightness_work);
}

static inline int led_get_brightness(struct led_classdev *led_cdev)
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 9b62a3c..bf4a938 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -48,6 +48,7 @@ struct led_classdev {
#define SET_BRIGHTNESS_ASYNC (1 << 21)
#define SET_BRIGHTNESS_SYNC (1 << 22)
#define LED_DEV_CAP_FLASH (1 << 23)
+#define LED_BLINK_DISABLE (1 << 24)

/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
@@ -87,6 +88,7 @@ struct led_classdev {

struct work_struct set_brightness_work;
int delayed_set_value;
+ int new_brightness_value;

#ifdef CONFIG_LEDS_TRIGGERS
/* Protects the trigger data below */
--
1.7.9.5

2015-07-03 13:14:27

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 3/7] leds: Add an internal led_set_brightness_nosleep function

This patch adds led_set_brightness_nosleep function as well
as LED_BRIGHTNESS_FAST flag. The flag, when set by a driver
means that its brightness_set op is guaranteed not to sleep.
Basing on this information the function decides whether
brightness should be set in an asynchronous or synchronous
way.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/leds.h | 18 ++++++++++++++++++
include/linux/leds.h | 1 +
2 files changed, 19 insertions(+)

diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index ca38f6a..6c56142 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -2,8 +2,10 @@
* LED Core
*
* Copyright 2005 Openedhand Ltd.
+ * Copyright 2014, 2015 Samsung Electronics Co., Ltd.
*
* Author: Richard Purdie <[email protected]>
+ * Author: Jacek Anaszewski <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -23,6 +25,22 @@ static inline void led_set_brightness_async(struct led_classdev *led_cdev,
schedule_work(&led_cdev->set_brightness_work);
}

+static inline void led_set_brightness_nosleep(struct led_classdev *led_cdev,
+ enum led_brightness value)
+{
+ if (led_cdev->flags & LED_BRIGHTNESS_FAST) {
+ led_set_brightness_sync(led_cdev, value);
+ return;
+ }
+
+ /*
+ * Delegate setting brightness to a work queue task only for slow
+ * LEDs as the FAST ones are guaranteed not to sleep while setting
+ * brightness.
+ */
+ led_set_brightness_async(led_cdev, value);
+}
+
static inline int led_get_brightness(struct led_classdev *led_cdev)
{
return led_cdev->brightness;
diff --git a/include/linux/leds.h b/include/linux/leds.h
index bf4a938..a982626 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -49,6 +49,7 @@ struct led_classdev {
#define SET_BRIGHTNESS_SYNC (1 << 22)
#define LED_DEV_CAP_FLASH (1 << 23)
#define LED_BLINK_DISABLE (1 << 24)
+#define LED_BRIGHTNESS_FAST (1 << 25)

/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
--
1.7.9.5

2015-07-03 13:15:19

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 4/7] leds: Improve setting brightness in a non sleeping way

This patch 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
fast drivers.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/led-class.c | 4 ++--
drivers/leds/led-core.c | 5 +++--
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, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index b8decf7..964750a 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -109,7 +109,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;
}

@@ -137,7 +137,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 +
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 16fe995..428f04c 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -42,13 +42,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;
}

diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c
index 59eca17..1ca1f16 100644
--- a/drivers/leds/trigger/ledtrig-backlight.c
+++ b/drivers/leds/trigger/ledtrig-backlight.c
@@ -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;
}
diff --git a/drivers/leds/trigger/ledtrig-default-on.c b/drivers/leds/trigger/ledtrig-default-on.c
index 6f38f88..ff455cb 100644
--- a/drivers/leds/trigger/ledtrig-default-on.c
+++ b/drivers/leds/trigger/ledtrig-default-on.c
@@ -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 = {
diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c
index 4cc7040..51288a4 100644
--- a/drivers/leds/trigger/ledtrig-gpio.c
+++ b/drivers/leds/trigger/ledtrig-gpio.c
@@ -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);
}
}

diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c
index fea6871..3dc6f0c 100644
--- a/drivers/leds/trigger/ledtrig-heartbeat.c
+++ b/drivers/leds/trigger/ledtrig-heartbeat.c
@@ -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);
}

diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c
index fbd02cd..6729317 100644
--- a/drivers/leds/trigger/ledtrig-oneshot.c
+++ b/drivers/leds/trigger/ledtrig-oneshot.c
@@ -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;
}
diff --git a/drivers/leds/trigger/ledtrig-transient.c b/drivers/leds/trigger/ledtrig-transient.c
index 3c34de4..1dddd8f 100644
--- a/drivers/leds/trigger/ledtrig-transient.c
+++ b/drivers/leds/trigger/ledtrig-transient.c
@@ -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);
--
1.7.9.5

2015-07-03 13:15:01

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 5/7] leds: 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 rather then
choosing between sync and async op basing on the flags defined by the
driver. Caller can use led_set_brightness_sync API to make sure that
brightness_set op will be called synchronously.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/led-class-flash.c | 7 -----
drivers/leds/led-class.c | 2 --
drivers/leds/led-core.c | 17 ++-----------
drivers/leds/leds-aat1290.c | 50 +++++++++---------------------------
drivers/leds/leds-ktd2692.c | 41 ++++--------------------------
drivers/leds/leds-max77693.c | 55 +++++-----------------------------------
include/linux/leds.h | 30 +++++-----------------
7 files changed, 33 insertions(+), 169 deletions(-)

diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c
index 3b25734..68c3f36 100644
--- a/drivers/leds/led-class-flash.c
+++ b/drivers/leds/led-class-flash.c
@@ -298,9 +298,6 @@ 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)
- return -EINVAL;
-
ops = fled_cdev->ops;
if (!ops || !ops->strobe_set)
return -EINVAL;
@@ -316,10 +313,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);
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 964750a..d8d7a76 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -280,8 +280,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);

INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 428f04c..5f869fa 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -118,8 +118,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.
@@ -137,20 +135,9 @@ void led_set_brightness(struct led_classdev *led_cdev,
*/
led_cdev->flags |= LED_BLINK_DISABLE;
led_set_brightness_async(led_cdev, brightness);
- return;
+ } else {
+ led_set_brightness_nosleep(led_cdev, brightness);
}
-
- if (led_cdev->flags & SET_BRIGHTNESS_ASYNC) {
- led_set_brightness_async(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);
}
EXPORT_SYMBOL(led_set_brightness);

diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
index 1ac525b..318bcf0 100644
--- a/drivers/leds/leds-aat1290.c
+++ b/drivers/leds/leds-aat1290.c
@@ -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 void 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) {
@@ -160,37 +168,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;
-}
-
static int aat1290_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
bool state)

@@ -510,10 +487,8 @@ 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->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 +523,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);

diff --git a/drivers/leds/leds-ktd2692.c b/drivers/leds/leds-ktd2692.c
index 2ae8c4d..1e92656 100644
--- a/drivers/leds/leds-ktd2692.c
+++ b/drivers/leds/leds-ktd2692.c
@@ -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 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);
+
mutex_lock(&led->lock);

if (brightness == LED_OFF) {
@@ -176,35 +177,6 @@ static void ktd2692_brightness_set(struct ktd2692_context *led,
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;
-}
-
static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
bool state)
{
@@ -382,11 +354,9 @@ 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->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 +378,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);
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
index b8b0eec..797ab5b 100644
--- a/drivers/leds/leds-max77693.c
+++ b/drivers/leds/leds-max77693.c
@@ -19,7 +19,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
@@ -61,8 +60,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;

@@ -462,10 +459,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 void 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);

@@ -493,43 +494,6 @@ 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);
}

static int max77693_led_flash_brightness_set(
@@ -931,15 +895,12 @@ 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->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);

@@ -1061,13 +1022,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);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index a982626..efe564b 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -45,22 +45,14 @@ struct led_classdev {
#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_DISABLE (1 << 24)
-#define LED_BRIGHTNESS_FAST (1 << 25)
+#define LED_DEV_CAP_FLASH (1 << 21)
+#define LED_BLINK_DISABLE (1 << 22)
+#define LED_BRIGHTNESS_FAST (1 << 23)

/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
void (*brightness_set)(struct led_classdev *led_cdev,
enum led_brightness brightness);
- /*
- * 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);
/* Get LED brightness level */
enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);

@@ -159,7 +151,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);
@@ -173,23 +165,15 @@ extern void led_set_brightness(struct led_classdev *led_cdev,
* the caller for the time required for accessing device register,
* and it can sleep.
*/
-static inline int led_set_brightness_sync(struct led_classdev *led_cdev,
+static inline void 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)
- return 0;
-
- if (led_cdev->brightness_set_sync)
- ret = led_cdev->brightness_set_sync(led_cdev,
- led_cdev->brightness);
- else
- led_cdev->brightness_set(led_cdev, led_cdev->brightness);
+ return;

- return 0;
+ led_cdev->brightness_set(led_cdev, led_cdev->brightness);
}

/**
--
1.7.9.5

2015-07-03 13:15:58

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 6/7] media: flash: use led_set_brightness_sync for torch brightness

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.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/media/v4l2-core/v4l2-flash-led-class.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index 4e19dac..b3b082e 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -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);
--
1.7.9.5

2015-07-03 13:16:28

by Jacek Anaszewski

[permalink] [raw]
Subject: [PATCH/RFC v3 7/7] leds: pwm: remove work queue

Drivers no longer need to use work queues on their own if they can
sleep in their brightness_set ops. Adjust the driver accordingly.

Signed-off-by: Jacek Anaszewski <[email protected]>
---
drivers/leds/leds-pwm.c | 24 ++++--------------------
1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index 1d07e3e..0068297 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -22,12 +22,10 @@
#include <linux/pwm.h>
#include <linux/leds_pwm.h>
#include <linux/slab.h>
-#include <linux/workqueue.h>

struct led_pwm_data {
struct led_classdev cdev;
struct pwm_device *pwm;
- struct work_struct work;
unsigned int active_low;
unsigned int period;
int duty;
@@ -51,14 +49,6 @@ static void __led_pwm_set(struct led_pwm_data *led_dat)
pwm_enable(led_dat->pwm);
}

-static void led_pwm_work(struct work_struct *work)
-{
- struct led_pwm_data *led_dat =
- container_of(work, struct led_pwm_data, work);
-
- __led_pwm_set(led_dat);
-}
-
static void led_pwm_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
@@ -75,10 +65,7 @@ static void led_pwm_set(struct led_classdev *led_cdev,

led_dat->duty = duty;

- if (led_dat->can_sleep)
- schedule_work(&led_dat->work);
- else
- __led_pwm_set(led_dat);
+ __led_pwm_set(led_dat);
}

static inline size_t sizeof_pwm_leds_priv(int num_leds)
@@ -89,11 +76,8 @@ static inline size_t sizeof_pwm_leds_priv(int num_leds)

static void led_pwm_cleanup(struct led_pwm_priv *priv)
{
- while (priv->num_leds--) {
+ while (priv->num_leds--)
led_classdev_unregister(&priv->leds[priv->num_leds].cdev);
- if (priv->leds[priv->num_leds].can_sleep)
- cancel_work_sync(&priv->leds[priv->num_leds].work);
- }
}

static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
@@ -122,8 +106,8 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
}

led_data->can_sleep = pwm_can_sleep(led_data->pwm);
- if (led_data->can_sleep)
- INIT_WORK(&led_data->work, led_pwm_work);
+ if (!led_data->can_sleep)
+ led_data->cdev.flags |= LED_BRIGHTNESS_FAST;

led_data->period = pwm_get_period(led_data->pwm);
if (!led_data->period && (led->pwm_period_ns > 0))
--
1.7.9.5

2015-07-05 12:33:37

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH/RFC v3 7/7] leds: pwm: remove work queue

On Fri 2015-07-03 15:10:52, Jacek Anaszewski wrote:
> Drivers no longer need to use work queues on their own if they can
> sleep in their brightness_set ops. Adjust the driver accordingly.
>
> Signed-off-by: Jacek Anaszewski <[email protected]>

Acked-by: Pavel Machek <[email protected]>

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2015-07-05 12:34:57

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH/RFC v3 1/7] leds: Add led_set_brightness_sync to the public LED subsystem API

Hi!

> 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 register,
> + * and it can sleep.
> + */
> +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)
> + return 0;
> +
> + if (led_cdev->brightness_set_sync)
> + ret = led_cdev->brightness_set_sync(led_cdev,
> + led_cdev->brightness);
> + else
> + led_cdev->brightness_set(led_cdev, led_cdev->brightness);
> +
> + return 0;
> +}

return ret, AFAICT?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2015-07-06 06:31:27

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH/RFC v3 1/7] leds: Add led_set_brightness_sync to the public LED subsystem API

On 07/05/2015 02:34 PM, Pavel Machek wrote:
> Hi!
>
>> 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 register,
>> + * and it can sleep.
>> + */
>> +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)
>> + return 0;
>> +
>> + if (led_cdev->brightness_set_sync)
>> + ret = led_cdev->brightness_set_sync(led_cdev,
>> + led_cdev->brightness);
>> + else
>> + led_cdev->brightness_set(led_cdev, led_cdev->brightness);
>> +
>> + return 0;
>> +}
>
> return ret, AFAICT?

Right, thanks.

--
Best Regards,
Jacek Anaszewski

2015-07-14 14:10:36

by Simon Guinot

[permalink] [raw]
Subject: Re: [PATCH/RFC v3 0/7] Remove work queues from LED class drivers

On Fri, Jul 03, 2015 at 03:10:45PM +0200, Jacek Anaszewski wrote:
> This is a third version of the RFC aiming at removing work queues
> from LED class drivers, as well as getting rid of complimentary
> functionalities introduced along with addition of LED flash class
> extension.
>
>
> ======================
> Changes from version 2
> ======================
>
> - split changes to several incremental patches
> - removed SET_BRIGHTNESS_SYNC and SET_BRIGHTNESS_ASYNC flags
> - fixed led_set_brightness_async function instead of renaming it
>
> ======================
> Changes from version 1
> ======================
>
> V2 includes also patches for one LED class driver
> and two LED flash class drivers, that show how the
> drivers will benefit from the optimization being
> introduced in the first patch of this patch set.
>
> I was able to test only the LED Flash class drivers.
>
> Original message from the patch 483a3122 ("leds: Use set_brightness_work for
> brightness_set ops that can sleep") that was sent previously as a single one:
>
> Hi All,
>
> Since this patch will affect all the LED subsystem drivers
> I'd like it was tested by as many developers as possible
> to make sure that I haven't missed something.
>
> For the drivers which can sleep in their brightness_set ops
> (e.g. use mutex or gpio "cansleep" API) you only need to
> remove the work queues and move the code executed currently
> in the work queue task to the brightness_set op, as now
> LED core does the job.
>
> For drivers that are capable of setting brightness with use
> of MMIO you need to set the LED_BRIGHTNESS_FAST flag, so
> that LED core would know that it doesn't have to employ
> work queue.
>
> After the patch is positively verified I will create relevant
> patches for every LED class driver.
>
> This patch is based on linux-next_20150622.
>
> I am looking forward to your cooperation.
>
> Best Regards,
> Jacek Anaszewski
>
> Jacek Anaszewski (7):
> leds: Add led_set_brightness_sync to the public LED subsystem API
> leds: Improve asynchronous path of setting brightness
> leds: Add an internal led_set_brightness_nosleep function
> leds: Improve setting brightness in a non sleeping way
> leds: Drivers shouldn't enforce SYNC/ASYNC brightness setting
> media: flash: use led_set_brightness_sync for torch brightness
> leds: pwm: remove work queue
>
> drivers/leds/led-class-flash.c | 7 ---
> drivers/leds/led-class.c | 20 +++++----
> drivers/leds/led-core.c | 42 +++++++++---------
> drivers/leds/leds-aat1290.c | 50 ++++++---------------
> drivers/leds/leds-ktd2692.c | 41 +++---------------
> drivers/leds/leds-max77693.c | 55 +++---------------------
> drivers/leds/leds-pwm.c | 24 ++---------
> drivers/leds/leds.h | 34 ++++++++-------
> 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 | 36 +++++++++++-----
> 16 files changed, 124 insertions(+), 225 deletions(-)

Hi Jacek,

I have successfully tested this patch set with both the leds-ns2 and
leds-netxbig drivers and with either sleeping and non-sleeping GPIOs
LEDs.

Tested-by: Simon Guinot <[email protected]>

Note that you may want to get rid of the comment
"Must not sleep, use a workqueue if needed" above the member
brightness_set in struct led_classdev.

Regards,

Simon


Attachments:
(No filename) (3.81 kB)
signature.asc (181.00 B)
Digital signature
Download all attachments

2015-07-14 14:23:57

by Jacek Anaszewski

[permalink] [raw]
Subject: Re: [PATCH/RFC v3 0/7] Remove work queues from LED class drivers

Hi Simon,

On 07/14/2015 04:10 PM, Simon Guinot wrote:
[...]

files changed, 124 insertions(+), 225 deletions(-)
>
> Hi Jacek,
>
> I have successfully tested this patch set with both the leds-ns2 and
> leds-netxbig drivers and with either sleeping and non-sleeping GPIOs
> LEDs.
>
> Tested-by: Simon Guinot <[email protected]>

Thanks for the feedback.

> Note that you may want to get rid of the comment
> "Must not sleep, use a workqueue if needed" above the member
> brightness_set in struct led_classdev.

Right, thanks.

--
Best Regards,
Jacek Anaszewski