Skip to content

Commit f1e80c0

Browse files
committed
leds: core: Add two new LED_BLINK_ flags
This patch adds LED_BLINK_BRIGHTNESS_CHANGE flag to indicate that blink brightness has changed, and LED_BLINK_DISABLE flag to indicate that blinking deactivation has been requested. In order to use the flags led_timer_function and set_brightness_delayed callbacks as well as led_set_brightness() function are being modified. The main goal of these modifications is to prepare set_brightness_work for extension of the scope of its responsibilities. Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com> Acked-by: Pavel Machek <pavel@ucw.cz> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
1 parent 2806e2f commit f1e80c0

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎drivers/leds/led-core.c‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ static void led_timer_function(unsigned long data)
4444
brightness = led_get_brightness(led_cdev);
4545
if (!brightness) {
4646
/* Time to switch the LED on. */
47-
if (led_cdev->delayed_set_value) {
48-
led_cdev->blink_brightness =
49-
led_cdev->delayed_set_value;
50-
led_cdev->delayed_set_value = 0;
51-
}
5247
brightness = led_cdev->blink_brightness;
5348
delay = led_cdev->blink_delay_on;
5449
} else {
5550
/* Store the current brightness value to be able
5651
* to restore it when the delay_off period is over.
52+
* Do it only if there is no pending blink brightness
53+
* change, to avoid overwriting the new value.
5754
*/
58-
led_cdev->blink_brightness = brightness;
55+
if (!(led_cdev->flags & LED_BLINK_BRIGHTNESS_CHANGE))
56+
led_cdev->blink_brightness = brightness;
57+
else
58+
led_cdev->flags &= ~LED_BLINK_BRIGHTNESS_CHANGE;
5959
brightness = LED_OFF;
6060
delay = led_cdev->blink_delay_off;
6161
}
@@ -84,7 +84,11 @@ static void set_brightness_delayed(struct work_struct *ws)
8484
struct led_classdev *led_cdev =
8585
container_of(ws, struct led_classdev, set_brightness_work);
8686

87-
led_stop_software_blink(led_cdev);
87+
if (led_cdev->flags & LED_BLINK_DISABLE) {
88+
led_cdev->delayed_set_value = LED_OFF;
89+
led_stop_software_blink(led_cdev);
90+
led_cdev->flags &= ~LED_BLINK_DISABLE;
91+
}
8892

8993
led_set_brightness_async(led_cdev, led_cdev->delayed_set_value);
9094
}
@@ -192,11 +196,23 @@ void led_set_brightness(struct led_classdev *led_cdev,
192196
{
193197
int ret = 0;
194198

195-
/* delay brightness if soft-blink is active */
199+
/*
200+
* In case blinking is on delay brightness setting
201+
* until the next timer tick.
202+
*/
196203
if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) {
197-
led_cdev->delayed_set_value = brightness;
198-
if (brightness == LED_OFF)
204+
/*
205+
* If we need to disable soft blinking delegate this to the
206+
* work queue task to avoid problems in case we are called
207+
* from hard irq context.
208+
*/
209+
if (brightness == LED_OFF) {
210+
led_cdev->flags |= LED_BLINK_DISABLE;
199211
schedule_work(&led_cdev->set_brightness_work);
212+
} else {
213+
led_cdev->flags |= LED_BLINK_BRIGHTNESS_CHANGE;
214+
led_cdev->blink_brightness = brightness;
215+
}
200216
return;
201217
}
202218

‎include/linux/leds.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ struct led_classdev {
4444
#define LED_BLINK_ONESHOT (1 << 17)
4545
#define LED_BLINK_ONESHOT_STOP (1 << 18)
4646
#define LED_BLINK_INVERT (1 << 19)
47-
#define LED_SYSFS_DISABLE (1 << 20)
48-
#define SET_BRIGHTNESS_ASYNC (1 << 21)
49-
#define SET_BRIGHTNESS_SYNC (1 << 22)
50-
#define LED_DEV_CAP_FLASH (1 << 23)
47+
#define LED_BLINK_BRIGHTNESS_CHANGE (1 << 20)
48+
#define LED_BLINK_DISABLE (1 << 21)
49+
#define LED_SYSFS_DISABLE (1 << 22)
50+
#define SET_BRIGHTNESS_ASYNC (1 << 23)
51+
#define SET_BRIGHTNESS_SYNC (1 << 24)
52+
#define LED_DEV_CAP_FLASH (1 << 25)
5153

5254
/* Set LED brightness level */
5355
/* Must not sleep, use a workqueue if needed */

0 commit comments

Comments
 (0)