generic: add missing patch headers
[openwrt/openwrt.git] / target / linux / generic / hack-5.15 / 766-net-phy-mediatek-ge-add-LED-configuration-interface.patch
1 From cc225d163b5a4f7a0d1968298bf7927306646a47 Mon Sep 17 00:00:00 2001
2 From: David Bauer <mail@david-bauer.net>
3 Date: Fri, 28 Apr 2023 01:53:01 +0200
4 Subject: [PATCH] net: phy: mediatek-ge: add LED configuration interface
5
6 This adds a small hack similar to the one used for ar8xxx switches to
7 read a reg:value map for configuring the LED configuration registers.
8
9 This allows OpenWrt to write device-specific LED action as well as blink
10 configurations. It is unlikely to be accepted upstream, as upstream
11 plans on integrating their own framework for handling these LEDs.
12
13 Signed-off-by: David Bauer <mail@david-bauer.net>
14 ---
15 drivers/net/phy/mediatek-ge.c | 33 +++++++++++++++++++++++++++++++++
16 1 file changed, 33 insertions(+)
17
18 --- a/drivers/net/phy/mediatek-ge.c
19 +++ b/drivers/net/phy/mediatek-ge.c
20 @@ -1,4 +1,5 @@
21 // SPDX-License-Identifier: GPL-2.0+
22 +#include <linux/of.h>
23 #include <linux/bitfield.h>
24 #include <linux/module.h>
25 #include <linux/phy.h>
26 @@ -53,6 +54,36 @@ static int mt7530_phy_config_init(struct
27 return 0;
28 }
29
30 +static int mt7530_led_config_of(struct phy_device *phydev)
31 +{
32 + struct device_node *np = phydev->mdio.dev.of_node;
33 + const __be32 *paddr;
34 + int len;
35 + int i;
36 +
37 + paddr = of_get_property(np, "mediatek,led-config", &len);
38 + if (!paddr)
39 + return 0;
40 +
41 + if (len < (2 * sizeof(*paddr)))
42 + return -EINVAL;
43 +
44 + len /= sizeof(*paddr);
45 +
46 + phydev_warn(phydev, "Configure LED registers (num=%d)\n", len);
47 + for (i = 0; i < len - 1; i += 2) {
48 + u32 reg;
49 + u32 val;
50 +
51 + reg = be32_to_cpup(paddr + i);
52 + val = be32_to_cpup(paddr + i + 1);
53 +
54 + phy_write_mmd(phydev, MDIO_MMD_VEND2, reg, val);
55 + }
56 +
57 + return 0;
58 +}
59 +
60 static int mt7531_phy_config_init(struct phy_device *phydev)
61 {
62 mtk_gephy_config_init(phydev);
63 @@ -65,6 +96,9 @@ static int mt7531_phy_config_init(struct
64 phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x13, 0x404);
65 phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x14, 0x404);
66
67 + /* LED Config*/
68 + mt7530_led_config_of(phydev);
69 +
70 return 0;
71 }
72