[PATCH 3/3] wifi: ath10k: add DT support for LED definition

From: Christian Marangi
Date: Fri Jun 16 2023 - 17:02:26 EST


If supported, the LED definition for the ath10k wifi card is all
hardcoded with static names, triggers and default-state.

Add DT support for the supported LED to permit custom names, define a
default state and a default trigger.

To identify these special LED, devname_mandatory is set to true and each
LED is prefixed with ath10k- and the wireless phy name.

The non-DT implementation is still supported and DT definition is not
mandatory.

Signed-off-by: Christian Marangi <ansuelsmth@xxxxxxxxx>
---
drivers/net/wireless/ath/ath10k/leds.c | 38 +++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath10k/leds.c b/drivers/net/wireless/ath/ath10k/leds.c
index b3b3025b4a38..f2f31eb26b8e 100644
--- a/drivers/net/wireless/ath/ath10k/leds.c
+++ b/drivers/net/wireless/ath/ath10k/leds.c
@@ -54,8 +54,39 @@ int ath10k_leds_start(struct ath10k *ar)
return 0;
}

+static int ath10k_leds_of_init(struct ath10k *ar, struct led_init_data *init_data)
+{
+ struct fwnode_handle *led = NULL;
+ enum led_default_state state;
+
+ led = device_get_named_child_node(ar->dev, "led");
+ if (!led)
+ return -ENOENT;
+
+ /* LED will be init on ath10k core start. */
+ state = led_init_default_state_get(led);
+ switch (state) {
+ case LEDS_DEFSTATE_ON:
+ ar->leds.cdev.brightness = 1;
+ break;
+ /* KEEP will start the LED to OFF by default */
+ case LEDS_DEFSTATE_KEEP:
+ default:
+ ar->leds.cdev.brightness = 0;
+ }
+
+ init_data->default_label = "wifi";
+ init_data->fwnode = led;
+ init_data->devname_mandatory = true;
+ init_data->devicename = ar->leds.label;
+
+ return 0;
+}
+
int ath10k_leds_register(struct ath10k *ar)
{
+ struct led_init_data *init_data_ptr = NULL;
+ struct led_init_data init_data = { };
int ret;

if (ar->hw_params.led_pin == 0)
@@ -74,7 +105,12 @@ int ath10k_leds_register(struct ath10k *ar)
ar->leds.cdev.brightness = 0;
ar->leds.cdev.brightness_set_blocking = ath10k_leds_set_brightness_blocking;

- ret = led_classdev_register(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev);
+ /* Support DT defined led. init_data_ptr is NULL if DT is not supported. */
+ if (!ath10k_leds_of_init(ar, &init_data))
+ init_data_ptr = &init_data;
+
+ ret = led_classdev_register_ext(wiphy_dev(ar->hw->wiphy), &ar->leds.cdev,
+ init_data_ptr);
if (ret)
return ret;

--
2.40.1


--ISiK3ICplRRKwxPi--