diff mbox series

power: supply: leds: Fix blink to LED on transition

Message ID 20230413100941.115529-1-hdegoede@redhat.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series power: supply: leds: Fix blink to LED on transition | expand

Commit Message

Hans de Goede April 13, 2023, 10:09 a.m. UTC
When a battery's status changes from charging to full then
the charging-blink-full-solid trigger tries to change
the LED from blinking to solid/on.

As is documented in include/linux/leds.h to deactivate blinking /
to make the LED solid a LED_OFF must be send:

"""
         * Deactivate blinking again when the brightness is set to LED_OFF
         * via the brightness_set() callback.
"""

led_set_brighness() calls with a brightness value other then 0 / LED_OFF
merely change the brightness of the LED in its on state while it is
blinking.

So power_supply_update_bat_leds() must first send a LED_OFF event
before the LED_FULL to disable blinking.

Fixes: 6501f728c56f ("power_supply: Add new LED trigger charging-blink-solid-full")
Cc: Vasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/supply/power_supply_leds.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Vasily Khoruzhick April 13, 2023, 4:40 p.m. UTC | #1
On Thu, Apr 13, 2023 at 3:09 AM Hans de Goede <hdegoede@redhat.com> wrote:
>
> When a battery's status changes from charging to full then
> the charging-blink-full-solid trigger tries to change
> the LED from blinking to solid/on.
>
> As is documented in include/linux/leds.h to deactivate blinking /
> to make the LED solid a LED_OFF must be send:
>
> """
>          * Deactivate blinking again when the brightness is set to LED_OFF
>          * via the brightness_set() callback.
> """
>
> led_set_brighness() calls with a brightness value other then 0 / LED_OFF
> merely change the brightness of the LED in its on state while it is
> blinking.
>
> So power_supply_update_bat_leds() must first send a LED_OFF event
> before the LED_FULL to disable blinking.
>
> Fixes: 6501f728c56f ("power_supply: Add new LED trigger charging-blink-solid-full")

Wow, it's a commit from 2011 :)

> Cc: Vasily Khoruzhick <anarsoul@gmail.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>

> ---
>  drivers/power/supply/power_supply_leds.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/supply/power_supply_leds.c b/drivers/power/supply/power_supply_leds.c
> index e2f554e4e4e6..c7db29d5fcb8 100644
> --- a/drivers/power/supply/power_supply_leds.c
> +++ b/drivers/power/supply/power_supply_leds.c
> @@ -33,8 +33,9 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
>                 led_trigger_event(psy->charging_full_trig, LED_FULL);
>                 led_trigger_event(psy->charging_trig, LED_OFF);
>                 led_trigger_event(psy->full_trig, LED_FULL);
> -               led_trigger_event(psy->charging_blink_full_solid_trig,
> -                       LED_FULL);
> +               /* Going from blink to LED on requires a LED_OFF event to stop blink */
> +               led_trigger_event(psy->charging_blink_full_solid_trig, LED_OFF);
> +               led_trigger_event(psy->charging_blink_full_solid_trig, LED_FULL);
>                 break;
>         case POWER_SUPPLY_STATUS_CHARGING:
>                 led_trigger_event(psy->charging_full_trig, LED_FULL);
> --
> 2.39.1
>
Sebastian Reichel May 8, 2023, 1:14 p.m. UTC | #2
Hi,

On Thu, Apr 13, 2023 at 09:40:44AM -0700, Vasily Khoruzhick wrote:
> On Thu, Apr 13, 2023 at 3:09 AM Hans de Goede <hdegoede@redhat.com> wrote:
> >
> > When a battery's status changes from charging to full then
> > the charging-blink-full-solid trigger tries to change
> > the LED from blinking to solid/on.
> >
> > As is documented in include/linux/leds.h to deactivate blinking /
> > to make the LED solid a LED_OFF must be send:
> >
> > """
> >          * Deactivate blinking again when the brightness is set to LED_OFF
> >          * via the brightness_set() callback.
> > """
> >
> > led_set_brighness() calls with a brightness value other then 0 / LED_OFF
> > merely change the brightness of the LED in its on state while it is
> > blinking.
> >
> > So power_supply_update_bat_leds() must first send a LED_OFF event
> > before the LED_FULL to disable blinking.
> >
> > Fixes: 6501f728c56f ("power_supply: Add new LED trigger charging-blink-solid-full")
> 
> Wow, it's a commit from 2011 :)
> 
> > Cc: Vasily Khoruzhick <anarsoul@gmail.com>
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>

Thanks, queued to my fixes branch.

-- Sebastian

> > ---
> >  drivers/power/supply/power_supply_leds.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/power/supply/power_supply_leds.c b/drivers/power/supply/power_supply_leds.c
> > index e2f554e4e4e6..c7db29d5fcb8 100644
> > --- a/drivers/power/supply/power_supply_leds.c
> > +++ b/drivers/power/supply/power_supply_leds.c
> > @@ -33,8 +33,9 @@ static void power_supply_update_bat_leds(struct power_supply *psy)
> >                 led_trigger_event(psy->charging_full_trig, LED_FULL);
> >                 led_trigger_event(psy->charging_trig, LED_OFF);
> >                 led_trigger_event(psy->full_trig, LED_FULL);
> > -               led_trigger_event(psy->charging_blink_full_solid_trig,
> > -                       LED_FULL);
> > +               /* Going from blink to LED on requires a LED_OFF event to stop blink */
> > +               led_trigger_event(psy->charging_blink_full_solid_trig, LED_OFF);
> > +               led_trigger_event(psy->charging_blink_full_solid_trig, LED_FULL);
> >                 break;
> >         case POWER_SUPPLY_STATUS_CHARGING:
> >                 led_trigger_event(psy->charging_full_trig, LED_FULL);
> > --
> > 2.39.1
> >
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_leds.c b/drivers/power/supply/power_supply_leds.c
index e2f554e4e4e6..c7db29d5fcb8 100644
--- a/drivers/power/supply/power_supply_leds.c
+++ b/drivers/power/supply/power_supply_leds.c
@@ -33,8 +33,9 @@  static void power_supply_update_bat_leds(struct power_supply *psy)
 		led_trigger_event(psy->charging_full_trig, LED_FULL);
 		led_trigger_event(psy->charging_trig, LED_OFF);
 		led_trigger_event(psy->full_trig, LED_FULL);
-		led_trigger_event(psy->charging_blink_full_solid_trig,
-			LED_FULL);
+		/* Going from blink to LED on requires a LED_OFF event to stop blink */
+		led_trigger_event(psy->charging_blink_full_solid_trig, LED_OFF);
+		led_trigger_event(psy->charging_blink_full_solid_trig, LED_FULL);
 		break;
 	case POWER_SUPPLY_STATUS_CHARGING:
 		led_trigger_event(psy->charging_full_trig, LED_FULL);