e20594c99a3eaaafec8af1a743b7be69aa34390c
[openwrt/staging/pepe2k.git] /
1 From 0316cc5629d15880dd3f097d221c55ca648bcd61 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Mon, 29 May 2023 18:32:40 +0200
4 Subject: [PATCH 10/13] leds: trigger: netdev: init mode if hw control already
5 active
6
7 On netdev trigger activation, hw control may be already active by
8 default. If this is the case and a device is actually provided by
9 hw_control_get_device(), init the already active mode and set the
10 bool to hw_control bool to true to reflect the already set mode in the
11 trigger_data.
12
13 Co-developed-by: Andrew Lunn <andrew@lunn.ch>
14 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18 drivers/leds/trigger/ledtrig-netdev.c | 17 +++++++++++++++++
19 1 file changed, 17 insertions(+)
20
21 --- a/drivers/leds/trigger/ledtrig-netdev.c
22 +++ b/drivers/leds/trigger/ledtrig-netdev.c
23 @@ -454,6 +454,8 @@ static void netdev_trig_work(struct work
24 static int netdev_trig_activate(struct led_classdev *led_cdev)
25 {
26 struct led_netdev_data *trigger_data;
27 + unsigned long mode;
28 + struct device *dev;
29 int rc;
30
31 trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL);
32 @@ -475,6 +477,21 @@ static int netdev_trig_activate(struct l
33 atomic_set(&trigger_data->interval, msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL));
34 trigger_data->last_activity = 0;
35
36 + /* Check if hw control is active by default on the LED.
37 + * Init already enabled mode in hw control.
38 + */
39 + if (supports_hw_control(led_cdev) &&
40 + !led_cdev->hw_control_get(led_cdev, &mode)) {
41 + dev = led_cdev->hw_control_get_device(led_cdev);
42 + if (dev) {
43 + const char *name = dev_name(dev);
44 +
45 + set_device_name(trigger_data, name, strlen(name));
46 + trigger_data->hw_control = true;
47 + trigger_data->mode = mode;
48 + }
49 + }
50 +
51 led_set_trigger_data(led_cdev, trigger_data);
52
53 rc = register_netdevice_notifier(&trigger_data->notifier);