Commit 822c91e7 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Lee Jones

leds: trigger: Store brightness set by led_trigger_event()

If a simple trigger is assigned to a LED, then the LED may be off until
the next led_trigger_event() call. This may be an issue for simple
triggers with rare led_trigger_event() calls, e.g. power supply
charging indicators (drivers/power/supply/power_supply_leds.c).
Therefore persist the brightness value of the last led_trigger_event()
call and use this value if the trigger is assigned to a LED.
In addition add a getter for the trigger brightness value.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/b1358b25-3f30-458d-8240-5705ae007a8a@gmail.comSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 4cece764
...@@ -194,11 +194,11 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) ...@@ -194,11 +194,11 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
spin_unlock(&trig->leddev_list_lock); spin_unlock(&trig->leddev_list_lock);
led_cdev->trigger = trig; led_cdev->trigger = trig;
ret = 0;
if (trig->activate) if (trig->activate)
ret = trig->activate(led_cdev); ret = trig->activate(led_cdev);
else else
ret = 0; led_set_brightness(led_cdev, trig->brightness);
if (ret) if (ret)
goto err_activate; goto err_activate;
...@@ -387,6 +387,8 @@ void led_trigger_event(struct led_trigger *trig, ...@@ -387,6 +387,8 @@ void led_trigger_event(struct led_trigger *trig,
if (!trig) if (!trig)
return; return;
trig->brightness = brightness;
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(led_cdev, &trig->led_cdevs, trig_list) list_for_each_entry_rcu(led_cdev, &trig->led_cdevs, trig_list)
led_set_brightness(led_cdev, brightness); led_set_brightness(led_cdev, brightness);
......
...@@ -455,6 +455,9 @@ struct led_trigger { ...@@ -455,6 +455,9 @@ struct led_trigger {
int (*activate)(struct led_classdev *led_cdev); int (*activate)(struct led_classdev *led_cdev);
void (*deactivate)(struct led_classdev *led_cdev); void (*deactivate)(struct led_classdev *led_cdev);
/* Brightness set by led_trigger_event */
enum led_brightness brightness;
/* LED-private triggers have this set */ /* LED-private triggers have this set */
struct led_hw_trigger_type *trigger_type; struct led_hw_trigger_type *trigger_type;
...@@ -508,6 +511,12 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) ...@@ -508,6 +511,12 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
return led_cdev->trigger_data; return led_cdev->trigger_data;
} }
static inline enum led_brightness
led_trigger_get_brightness(const struct led_trigger *trigger)
{
return trigger ? trigger->brightness : LED_OFF;
}
#define module_led_trigger(__led_trigger) \ #define module_led_trigger(__led_trigger) \
module_driver(__led_trigger, led_trigger_register, \ module_driver(__led_trigger, led_trigger_register, \
led_trigger_unregister) led_trigger_unregister)
...@@ -544,6 +553,12 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) ...@@ -544,6 +553,12 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
return NULL; return NULL;
} }
static inline enum led_brightness
led_trigger_get_brightness(const struct led_trigger *trigger)
{
return LED_OFF;
}
#endif /* CONFIG_LEDS_TRIGGERS */ #endif /* CONFIG_LEDS_TRIGGERS */
/* Trigger specific enum */ /* Trigger specific enum */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment