]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
kernel: ar8327: support LED device tree bindings
authorLech Perczak <lech.perczak@gmail.com>
Tue, 14 Sep 2021 21:39:41 +0000 (23:39 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Mon, 17 Mar 2025 15:40:46 +0000 (16:40 +0100)
The ar8216 switch driver supports exposing configuration of AR8327 and
AR8337 switch LEDs to the userspace, however it is only configurable
through platform data, causing the devices ported from ar71xx target to
lack the support.
Since there is still a long way to go until we can migrate the target to
qca8k, an interim solution is needed.
Extend ar8327_hw_config_of function to parse a "leds"
subnode, which will populate the missing platform data based on device
tree contents, and restore the existing support for the LEDs.
Standard bindings apply, mapping "reg" property to LED index, with
addition of "qca,led-mode" property, which selects HW (0) or SW (1)
mode, defaulting to HW mode.

Signed-off-by: Lech Perczak <lech.perczak@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/12487
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/generic/files/drivers/net/phy/ar8327.c
target/linux/generic/files/drivers/net/phy/ar8327.h
target/linux/generic/files/include/linux/ar8216_platform.h

index 83191cd5917f12feeaf8b7cc8e9b86dd1089947a..cf9c2dc3c1604564ef17a2a4b0851a6ad6991ce4 100644 (file)
@@ -392,8 +392,11 @@ static int
 ar8327_led_register(struct ar8327_led *aled)
 {
        int ret;
+       struct led_init_data init_data = {
+               .fwnode = aled->fwnode
+       };
 
-       ret = led_classdev_register(NULL, &aled->cdev);
+       ret = led_classdev_register_ext(NULL, &aled->cdev, &init_data);
        if (ret < 0)
                return ret;
 
@@ -447,6 +450,7 @@ ar8327_led_create(struct ar8xxx_priv *priv,
        aled->led_num = led_info->led_num;
        aled->active_low = led_info->active_low;
        aled->mode = led_info->mode;
+       aled->fwnode = led_info->fwnode;
 
        if (aled->mode == AR8327_LED_MODE_HW)
                aled->enable_hw_mode = true;
@@ -616,6 +620,7 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
        const __be32 *paddr;
        int len;
        int i;
+       struct device_node *leds, *child;
 
        paddr = of_get_property(np, "qca,ar8327-initvals", &len);
        if (!paddr || len < (2 * sizeof(*paddr)))
@@ -643,6 +648,39 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
                }
        }
 
+       leds = of_get_child_by_name(np, "leds");
+       if (!leds)
+               return 0;
+
+       data->leds = kvcalloc(of_get_child_count(leds), sizeof(void *),
+                            GFP_KERNEL);
+       if (!data->leds)
+               return -ENOMEM;
+
+       for_each_available_child_of_node(leds, child) {
+               u32 reg = 0, mode = 0;
+               struct ar8327_led_info info;
+               int ret;
+
+               ret = of_property_read_u32(child, "reg", &reg);
+               if (ret) {
+                       pr_err("ar8327: LED %s is missing reg node\n", child->name);
+                       continue;
+               }
+
+               of_property_read_u32(child, "qca,led-mode", &mode);
+
+               info = (struct ar8327_led_info) {
+                       .name = of_get_property(child, "label", NULL) ? : child->name,
+                       .fwnode = of_fwnode_handle(child),
+                       .active_low = of_property_read_bool(child, "active-low"),
+                       .led_num = (enum ar8327_led_num) reg,
+                       .mode = (enum ar8327_led_mode) mode
+               };
+               ar8327_led_create(priv, &info);
+       }
+
+       of_node_put(leds);
        return 0;
 }
 #else
index 088b28861855a8560119aeda1f24b87091b9e233..53a82d1f76a38a01a599b99ed4d53c46be255d40 100644 (file)
@@ -317,6 +317,7 @@ struct ar8327_led {
        struct work_struct led_work;
        bool enable_hw_mode;
        enum ar8327_led_pattern pattern;
+       struct fwnode_handle *fwnode;
 };
 
 struct ar8327_data {
index 24bc442a26d0ced7a5b686846dfc53f14f7ded37..fff05ffb5c1674bbbc39a0ec82e260614644a5b2 100644 (file)
@@ -106,6 +106,7 @@ struct ar8327_led_info {
        bool active_low;
        enum ar8327_led_num led_num;
        enum ar8327_led_mode mode;
+       struct fwnode_handle *fwnode;
 };
 
 #define AR8327_LED_INFO(_led, _mode, _name) {  \