diff options
author | Jacek Anaszewski <j.anaszewski@samsung.com> | 2015-10-07 11:10:41 +0200 |
---|---|---|
committer | Jacek Anaszewski <j.anaszewski@samsung.com> | 2016-01-04 09:57:30 +0100 |
commit | 81fe8e5b73e3f4de578ac7f53c1d956d4f58b8d4 (patch) | |
tree | ff084840f52a554f7a902c7e1ffe54416e4c452f /drivers/leds/led-core.c | |
parent | 437a4240f26461610cc0d90950b1c88348d9babe (diff) | |
download | lwn-81fe8e5b73e3f4de578ac7f53c1d956d4f58b8d4.tar.gz lwn-81fe8e5b73e3f4de578ac7f53c1d956d4f58b8d4.zip |
leds: core: Add led_set_brightness_nosleep{nopm} functions
This patch adds led_set_brightness_nosleep() and led_set_brightness_nopm()
functions, that guarantee setting LED brightness in a non-blocking way.
The latter is used from pm_ops context and doesn't modify the brightness
cached in the struct led_classdev. Its execution always ends up with
a call to brightness setting op - either directly or through
a set_brightness_work, regardless of LED_SUSPENDED flag state.
The patch 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.
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Diffstat (limited to 'drivers/leds/led-core.c')
-rw-r--r-- | drivers/leds/led-core.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 7cf59243e0ef..3d168592db65 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -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,33 @@ void led_set_brightness(struct led_classdev *led_cdev, } EXPORT_SYMBOL_GPL(led_set_brightness); +void led_set_brightness_nopm(struct led_classdev *led_cdev, + enum led_brightness value) +{ + /* Use brightness_set op if available, it is guaranteed not to sleep */ + if (led_cdev->brightness_set) { + led_cdev->brightness_set(led_cdev, value); + return; + } + + /* If brightness setting can sleep, delegate it to a work queue task */ + led_cdev->delayed_set_value = value; + schedule_work(&led_cdev->set_brightness_work); +} +EXPORT_SYMBOL_GPL(led_set_brightness_nopm); + +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; + + led_set_brightness_nopm(led_cdev, led_cdev->brightness); +} +EXPORT_SYMBOL_GPL(led_set_brightness_nosleep); + int led_update_brightness(struct led_classdev *led_cdev) { int ret = 0; |