Skip to content

Commit 7cfe749

Browse files
Tony Makkieljanaszewski
authored andcommitted
leds: core: Fix brightness setting upon hardware blinking enabled
Commit 76931ed ("leds: fix brightness changing when software blinking is active") changed the semantics of led_set_brightness() which according to the documentation should disable blinking upon any brightness setting. Moreover it made it different for soft blink case, where it was possible to change blink brightness, and for hardware blink case, where setting any brightness greater than 0 was ignored. While the change itself is against the documentation claims, it was driven also by the fact that timer trigger remained active after turning blinking off. Fixing that would have required major refactoring in the led-core, led-class, and led-triggers because of cyclic dependencies. Finally, it has been decided that allowing for brightness change during blinking is beneficial as it can be accomplished without disturbing blink rhythm. The change in brightness setting semantics will not affect existing LED class drivers that implement blink_set op thanks to the LED_BLINK_SW flag introduced by this patch. The flag state will be from now on checked in led_set_brightness() which will allow to distinguish between software and hardware blink mode. In the latter case the control will be passed directly to the drivers which apply their semantics on brightness set, which is disable the blinking in case of most such drivers. New drivers will apply new semantics and just change the brightness while hardware blinking is on, if possible. The issue was smuggled by subsequent LED core improvements, which modified the code that originally introduced the problem. Fixes: f1e80c0 ("leds: core: Add two new LED_BLINK_ flags") Signed-off-by: Tony Makkiel <tony.makkiel@daqri.com> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
1 parent af8c34c commit 7cfe749

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎Documentation/leds/leds-class.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ blink_set() function (see <linux/leds.h>). To set an LED to blinking,
7474
however, it is better to use the API function led_blink_set(), as it
7575
will check and implement software fallback if necessary.
7676

77-
To turn off blinking again, use the API function led_brightness_set()
78-
as that will not just set the LED brightness but also stop any software
77+
To turn off blinking, use the API function led_brightness_set()
78+
with brightness value LED_OFF, which should stop any software
7979
timers that may have been required for blinking.
8080

8181
The blink_set() function should choose a user friendly blinking value

‎drivers/leds/led-core.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ static void led_timer_function(unsigned long data)
5353

5454
if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
5555
led_set_brightness_nosleep(led_cdev, LED_OFF);
56+
led_cdev->flags &= ~LED_BLINK_SW;
5657
return;
5758
}
5859

5960
if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) {
60-
led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP;
61+
led_cdev->flags &= ~(LED_BLINK_ONESHOT_STOP | LED_BLINK_SW);
6162
return;
6263
}
6364

@@ -151,6 +152,7 @@ static void led_set_software_blink(struct led_classdev *led_cdev,
151152
return;
152153
}
153154

155+
led_cdev->flags |= LED_BLINK_SW;
154156
mod_timer(&led_cdev->blink_timer, jiffies + 1);
155157
}
156158

@@ -219,17 +221,18 @@ void led_stop_software_blink(struct led_classdev *led_cdev)
219221
del_timer_sync(&led_cdev->blink_timer);
220222
led_cdev->blink_delay_on = 0;
221223
led_cdev->blink_delay_off = 0;
224+
led_cdev->flags &= ~LED_BLINK_SW;
222225
}
223226
EXPORT_SYMBOL_GPL(led_stop_software_blink);
224227

225228
void led_set_brightness(struct led_classdev *led_cdev,
226229
enum led_brightness brightness)
227230
{
228231
/*
229-
* In case blinking is on delay brightness setting
232+
* If software blink is active, delay brightness setting
230233
* until the next timer tick.
231234
*/
232-
if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) {
235+
if (led_cdev->flags & LED_BLINK_SW) {
233236
/*
234237
* If we need to disable soft blinking delegate this to the
235238
* work queue task to avoid problems in case we are called

‎include/linux/leds.h‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ struct led_classdev {
4242
#define LED_UNREGISTERING (1 << 1)
4343
/* Upper 16 bits reflect control information */
4444
#define LED_CORE_SUSPENDRESUME (1 << 16)
45-
#define LED_BLINK_ONESHOT (1 << 17)
46-
#define LED_BLINK_ONESHOT_STOP (1 << 18)
47-
#define LED_BLINK_INVERT (1 << 19)
48-
#define LED_BLINK_BRIGHTNESS_CHANGE (1 << 20)
49-
#define LED_BLINK_DISABLE (1 << 21)
50-
#define LED_SYSFS_DISABLE (1 << 22)
51-
#define LED_DEV_CAP_FLASH (1 << 23)
52-
#define LED_HW_PLUGGABLE (1 << 24)
53-
#define LED_PANIC_INDICATOR (1 << 25)
45+
#define LED_BLINK_SW (1 << 17)
46+
#define LED_BLINK_ONESHOT (1 << 18)
47+
#define LED_BLINK_ONESHOT_STOP (1 << 19)
48+
#define LED_BLINK_INVERT (1 << 20)
49+
#define LED_BLINK_BRIGHTNESS_CHANGE (1 << 21)
50+
#define LED_BLINK_DISABLE (1 << 22)
51+
#define LED_SYSFS_DISABLE (1 << 23)
52+
#define LED_DEV_CAP_FLASH (1 << 24)
53+
#define LED_HW_PLUGGABLE (1 << 25)
54+
#define LED_PANIC_INDICATOR (1 << 26)
5455

5556
/* Set LED brightness level
5657
* Must not sleep. Use brightness_set_blocking for drivers
@@ -72,8 +73,8 @@ struct led_classdev {
7273
* and if both are zero then a sensible default should be chosen.
7374
* The call should adjust the timings in that case and if it can't
7475
* match the values specified exactly.
75-
* Deactivate blinking again when the brightness is set to a fixed
76-
* value via the brightness_set() callback.
76+
* Deactivate blinking again when the brightness is set to LED_OFF
77+
* via the brightness_set() callback.
7778
*/
7879
int (*blink_set)(struct led_classdev *led_cdev,
7980
unsigned long *delay_on,

0 commit comments

Comments
 (0)