LED class heartbeat trigger allowed only for blinking with max_brightness
value. This patch adds more flexibility by exploiting part of LED core
software blink infrastructure.
Signed-off-by: Jacek Anaszewski <[email protected]>
Cc: Pavel Machek <[email protected]>
---
drivers/leds/trigger/ledtrig-heartbeat.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c
index c9f3862..9cc3e97 100644
--- a/drivers/leds/trigger/ledtrig-heartbeat.c
+++ b/drivers/leds/trigger/ledtrig-heartbeat.c
@@ -59,26 +59,26 @@ static void led_heartbeat_function(unsigned long data)
delay = msecs_to_jiffies(70);
heartbeat_data->phase++;
if (!heartbeat_data->invert)
- brightness = led_cdev->max_brightness;
+ brightness = led_cdev->blink_brightness;
break;
case 1:
delay = heartbeat_data->period / 4 - msecs_to_jiffies(70);
heartbeat_data->phase++;
if (heartbeat_data->invert)
- brightness = led_cdev->max_brightness;
+ brightness = led_cdev->blink_brightness;
break;
case 2:
delay = msecs_to_jiffies(70);
heartbeat_data->phase++;
if (!heartbeat_data->invert)
- brightness = led_cdev->max_brightness;
+ brightness = led_cdev->blink_brightness;
break;
default:
delay = heartbeat_data->period - heartbeat_data->period / 4 -
msecs_to_jiffies(70);
heartbeat_data->phase = 0;
if (heartbeat_data->invert)
- brightness = led_cdev->max_brightness;
+ brightness = led_cdev->blink_brightness;
break;
}
@@ -133,7 +133,10 @@ static void heartbeat_trig_activate(struct led_classdev *led_cdev)
setup_timer(&heartbeat_data->timer,
led_heartbeat_function, (unsigned long) led_cdev);
heartbeat_data->phase = 0;
+ if (!led_cdev->blink_brightness)
+ led_cdev->blink_brightness = led_cdev->max_brightness;
led_heartbeat_function(heartbeat_data->timer.data);
+ led_cdev->flags |= LED_BLINK_SW;
led_cdev->activated = true;
}
@@ -145,6 +148,7 @@ static void heartbeat_trig_deactivate(struct led_classdev *led_cdev)
del_timer_sync(&heartbeat_data->timer);
device_remove_file(led_cdev->dev, &dev_attr_invert);
kfree(heartbeat_data);
+ led_cdev->flags &= ~LED_BLINK_SW;
led_cdev->activated = false;
}
}
--
1.9.1
delayed_set_value property was introduced in the commit
d23a22a74fde ("leds: delay led_set_brightness if stopping soft-blink").
Its aim was to allow calling led_set_brightness() from hard irq context
when soft blinking is enabled. Later LED core refactoring preserved
the property, although in an ineffective way. That bug was harmless
because in the new approach brightness setting is deferred until the
next timer tick when software blinking is enabled.
Since LED brightness is assigned immediately in
led_set_brightness_nosleep() or through struct led_classdev's
blink_brightness while soft blinking is enabled, then
delayed_set_value is no longer required.
Signed-off-by: Jacek Anaszewski <[email protected]>
Cc: Fabio Baltieri <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: Andrew Lunn <[email protected]>
---
drivers/leds/led-core.c | 8 ++++----
include/linux/leds.h | 1 -
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 3bce448..2d0c75a 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -107,15 +107,15 @@ static void set_brightness_delayed(struct work_struct *ws)
int ret = 0;
if (led_cdev->flags & LED_BLINK_DISABLE) {
- led_cdev->delayed_set_value = LED_OFF;
+ led_cdev->brightness = LED_OFF;
led_stop_software_blink(led_cdev);
led_cdev->flags &= ~LED_BLINK_DISABLE;
}
- ret = __led_set_brightness(led_cdev, led_cdev->delayed_set_value);
+ ret = __led_set_brightness(led_cdev, led_cdev->brightness);
if (ret == -ENOTSUPP)
ret = __led_set_brightness_blocking(led_cdev,
- led_cdev->delayed_set_value);
+ led_cdev->brightness);
if (ret < 0 &&
/* LED HW might have been unplugged, therefore don't warn */
!(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) &&
@@ -260,7 +260,7 @@ void led_set_brightness_nopm(struct led_classdev *led_cdev,
return;
/* If brightness setting can sleep, delegate it to a work queue task */
- led_cdev->delayed_set_value = value;
+ led_cdev->brightness = value;
schedule_work(&led_cdev->set_brightness_work);
}
EXPORT_SYMBOL_GPL(led_set_brightness_nopm);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index ddfcb2d..52993de 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -92,7 +92,6 @@ struct led_classdev {
void (*flash_resume)(struct led_classdev *led_cdev);
struct work_struct set_brightness_work;
- int delayed_set_value;
#ifdef CONFIG_LEDS_TRIGGERS
/* Protects the trigger data below */
--
1.9.1
On Wed 2016-10-05 12:03:31, Jacek Anaszewski wrote:
> LED class heartbeat trigger allowed only for blinking with max_brightness
> value. This patch adds more flexibility by exploiting part of LED core
> software blink infrastructure.
>
> Signed-off-by: Jacek Anaszewski <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Thanks!
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Withdrawing this patch as it breaks restoring brightness
on resume.
Thanks,
Jacek Anaszewski
On 10/05/2016 12:03 PM, Jacek Anaszewski wrote:
> delayed_set_value property was introduced in the commit
> d23a22a74fde ("leds: delay led_set_brightness if stopping soft-blink").
> Its aim was to allow calling led_set_brightness() from hard irq context
> when soft blinking is enabled. Later LED core refactoring preserved
> the property, although in an ineffective way. That bug was harmless
> because in the new approach brightness setting is deferred until the
> next timer tick when software blinking is enabled.
>
> Since LED brightness is assigned immediately in
> led_set_brightness_nosleep() or through struct led_classdev's
> blink_brightness while soft blinking is enabled, then
> delayed_set_value is no longer required.
>
> Signed-off-by: Jacek Anaszewski <[email protected]>
> Cc: Fabio Baltieri <[email protected]>
> Cc: Sakari Ailus <[email protected]>
> Cc: Pavel Machek <[email protected]>
> Cc: Andrew Lunn <[email protected]>
> ---
> drivers/leds/led-core.c | 8 ++++----
> include/linux/leds.h | 1 -
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
> index 3bce448..2d0c75a 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -107,15 +107,15 @@ static void set_brightness_delayed(struct work_struct *ws)
> int ret = 0;
>
> if (led_cdev->flags & LED_BLINK_DISABLE) {
> - led_cdev->delayed_set_value = LED_OFF;
> + led_cdev->brightness = LED_OFF;
> led_stop_software_blink(led_cdev);
> led_cdev->flags &= ~LED_BLINK_DISABLE;
> }
>
> - ret = __led_set_brightness(led_cdev, led_cdev->delayed_set_value);
> + ret = __led_set_brightness(led_cdev, led_cdev->brightness);
> if (ret == -ENOTSUPP)
> ret = __led_set_brightness_blocking(led_cdev,
> - led_cdev->delayed_set_value);
> + led_cdev->brightness);
> if (ret < 0 &&
> /* LED HW might have been unplugged, therefore don't warn */
> !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) &&
> @@ -260,7 +260,7 @@ void led_set_brightness_nopm(struct led_classdev *led_cdev,
> return;
>
> /* If brightness setting can sleep, delegate it to a work queue task */
> - led_cdev->delayed_set_value = value;
> + led_cdev->brightness = value;
> schedule_work(&led_cdev->set_brightness_work);
> }
> EXPORT_SYMBOL_GPL(led_set_brightness_nopm);
> diff --git a/include/linux/leds.h b/include/linux/leds.h
> index ddfcb2d..52993de 100644
> --- a/include/linux/leds.h
> +++ b/include/linux/leds.h
> @@ -92,7 +92,6 @@ struct led_classdev {
> void (*flash_resume)(struct led_classdev *led_cdev);
>
> struct work_struct set_brightness_work;
> - int delayed_set_value;
>
> #ifdef CONFIG_LEDS_TRIGGERS
> /* Protects the trigger data below */
>