gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / hack-6.1 / 765-mxl-gpy-control-LED-reg-from-DT.patch
1 From 94b90966095f3fa625897e8f53d215882f6e19b3 Mon Sep 17 00:00:00 2001
2 From: David Bauer <mail@david-bauer.net>
3 Date: Sat, 11 Mar 2023 17:00:01 +0100
4 Subject: [PATCH] mxl-gpy: control LED reg from DT
5
6 Add dynamic configuration for the LED control registers on MXL PHYs.
7
8 This patch has been tested with MaxLinear GPY211C. It is unlikely to be
9 accepted upstream, as upstream plans on integrating their own framework
10 for handling these LEDs.
11
12 For the time being, use this hack to configure PHY driven device-LEDs to
13 show the correct state.
14
15 A possible alternative might be to expose the LEDs using the kernel LED
16 framework and bind it to the netdevice. This might also be upstreamable,
17 although it is a considerable extra amount of work.
18
19 Signed-off-by: David Bauer <mail@david-bauer.net>
20 ---
21 drivers/net/phy/mxl-gpy.c | 37 ++++++++++++++++++++++++++++++++++++-
22 1 file changed, 36 insertions(+), 1 deletion(-)
23
24 --- a/drivers/net/phy/mxl-gpy.c
25 +++ b/drivers/net/phy/mxl-gpy.c
26 @@ -10,6 +10,7 @@
27 #include <linux/bitfield.h>
28 #include <linux/hwmon.h>
29 #include <linux/mutex.h>
30 +#include <linux/of.h>
31 #include <linux/phy.h>
32 #include <linux/polynomial.h>
33 #include <linux/netdevice.h>
34 @@ -33,6 +34,7 @@
35 #define PHY_MIISTAT 0x18 /* MII state */
36 #define PHY_IMASK 0x19 /* interrupt mask */
37 #define PHY_ISTAT 0x1A /* interrupt status */
38 +#define PHY_LED 0x1B /* LED control */
39 #define PHY_FWV 0x1E /* firmware version */
40
41 #define PHY_MIISTAT_SPD_MASK GENMASK(2, 0)
42 @@ -56,10 +58,15 @@
43 PHY_IMASK_ADSC | \
44 PHY_IMASK_ANC)
45
46 +#define PHY_LED_NUM_LEDS 4
47 +
48 #define PHY_FWV_REL_MASK BIT(15)
49 #define PHY_FWV_MAJOR_MASK GENMASK(11, 8)
50 #define PHY_FWV_MINOR_MASK GENMASK(7, 0)
51
52 +/* LED */
53 +#define VSPEC1_LED(x) (0x1 + x)
54 +
55 /* SGMII */
56 #define VSPEC1_SGMII_CTRL 0x08
57 #define VSPEC1_SGMII_CTRL_ANEN BIT(12) /* Aneg enable */
58 @@ -241,6 +248,35 @@ out:
59 return ret;
60 }
61
62 +static int gpy_led_write(struct phy_device *phydev)
63 +{
64 + struct device_node *node = phydev->mdio.dev.of_node;
65 + u32 led_regs[PHY_LED_NUM_LEDS];
66 + int i, ret;
67 + u16 val = 0xff00;
68 +
69 + if (!IS_ENABLED(CONFIG_OF_MDIO))
70 + return 0;
71 +
72 + if (of_property_read_u32_array(node, "mxl,led-config", led_regs, PHY_LED_NUM_LEDS))
73 + return 0;
74 +
75 + if (of_property_read_bool(node, "mxl,led-drive-vdd"))
76 + val &= 0x0fff;
77 +
78 + /* Enable LED function handling on all ports*/
79 + phy_write(phydev, PHY_LED, val);
80 +
81 + /* Write LED register values */
82 + for (i = 0; i < PHY_LED_NUM_LEDS; i++) {
83 + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_LED(i), (u16)led_regs[i]);
84 + if (ret < 0)
85 + return ret;
86 + }
87 +
88 + return 0;
89 +}
90 +
91 static int gpy_config_init(struct phy_device *phydev)
92 {
93 int ret;
94 @@ -252,7 +288,10 @@ static int gpy_config_init(struct phy_de
95
96 /* Clear all pending interrupts */
97 ret = phy_read(phydev, PHY_ISTAT);
98 - return ret < 0 ? ret : 0;
99 + if (ret < 0)
100 + return ret;
101 +
102 + return gpy_led_write(phydev);
103 }
104
105 static bool gpy_has_broken_mdint(struct phy_device *phydev)