mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 09:13:38 +00:00
power: supply: leds: Add activate() callback to triggers
Add an activate() callback to the power-supply LED triggers so that the LED being activated will properly reflect the current power-supply state for power-supply devices which are already fully registered when the trigger gets activated. This fixes e.g. wrong LED state (1) when the LED gets registered after the power-supply device. 1) Until the psy driver has a reason to call power_supply_changed() which may take quite a while Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy@kernel.org> Link: https://lore.kernel.org/r/20240531134702.166145-4-hdegoede@redhat.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
6c951a84da
commit
8179b068d5
@ -27,6 +27,16 @@ struct power_supply_led_trigger {
|
||||
#define trigger_to_psy_trigger(trigger) \
|
||||
container_of(trigger, struct power_supply_led_trigger, trig)
|
||||
|
||||
static int power_supply_led_trigger_activate(struct led_classdev *led_cdev)
|
||||
{
|
||||
struct power_supply_led_trigger *psy_trig =
|
||||
trigger_to_psy_trigger(led_cdev->trigger);
|
||||
|
||||
/* Sync current power-supply state to LED being activated */
|
||||
power_supply_update_leds(psy_trig->psy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int power_supply_register_led_trigger(struct power_supply *psy,
|
||||
const char *name_template,
|
||||
struct led_trigger **tp, int *err)
|
||||
@ -46,6 +56,7 @@ static int power_supply_register_led_trigger(struct power_supply *psy,
|
||||
if (!psy_trig->trig.name)
|
||||
goto err_free_trigger;
|
||||
|
||||
psy_trig->trig.activate = power_supply_led_trigger_activate;
|
||||
psy_trig->psy = psy;
|
||||
|
||||
ret = led_trigger_register(&psy_trig->trig);
|
||||
|
Loading…
Reference in New Issue
Block a user