diff mbox series

[09/11] leds: trigger: netdev: init mode if hw control already active

Message ID 20230427001541.18704-10-ansuelsmth@gmail.com
State New
Headers show
Series leds: introduce new LED hw control APIs | expand

Commit Message

Christian Marangi April 27, 2023, 12:15 a.m. UTC
On netdev trigger activation, hw control may be already active by
default. If this is the case, init the already active mode and set the
bool to hw_control bool to true to reflect the already set mode in the
trigger_data.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/trigger/ledtrig-netdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 61bc19fd0c7a..27df24e6d559 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -465,6 +465,13 @@  static int netdev_trig_activate(struct led_classdev *led_cdev)
 	atomic_set(&trigger_data->interval, msecs_to_jiffies(50));
 	trigger_data->last_activity = 0;
 
+	/* Check if hw control is active by default on the LED.
+	 * Init already enabled mode in hw control.
+	 */
+	if (led_trigger_can_hw_control(led_cdev) &&
+	    !led_cdev->hw_control_get(led_cdev, &trigger_data->mode))
+		trigger_data->hw_control = true;
+
 	led_set_trigger_data(led_cdev, trigger_data);
 
 	rc = register_netdevice_notifier(&trigger_data->notifier);