generic: 6.1: backport various qca8k fixes patch
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 801-v6.4-07-net-phy-marvell-Add-software-control-of-the-LEDs.patch
1 From 2d3960e58ef7c83fe1dbf952f056b9e906cb6df8 Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Mon, 17 Apr 2023 17:17:29 +0200
4 Subject: [PATCH 7/9] net: phy: marvell: Add software control of the LEDs
5
6 Add a brightness function, so the LEDs can be controlled from
7 software using the standard Linux LED infrastructure.
8
9 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
10 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14 drivers/net/phy/marvell.c | 45 ++++++++++++++++++++++++++++++++++-----
15 1 file changed, 40 insertions(+), 5 deletions(-)
16
17 --- a/drivers/net/phy/marvell.c
18 +++ b/drivers/net/phy/marvell.c
19 @@ -144,11 +144,13 @@
20 /* WOL Event Interrupt Enable */
21 #define MII_88E1318S_PHY_CSIER_WOL_EIE BIT(7)
22
23 -/* LED Timer Control Register */
24 -#define MII_88E1318S_PHY_LED_TCR 0x12
25 -#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
26 -#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
27 -#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
28 +#define MII_88E1318S_PHY_LED_FUNC 0x10
29 +#define MII_88E1318S_PHY_LED_FUNC_OFF (0x8)
30 +#define MII_88E1318S_PHY_LED_FUNC_ON (0x9)
31 +#define MII_88E1318S_PHY_LED_TCR 0x12
32 +#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
33 +#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
34 +#define MII_88E1318S_PHY_LED_TCR_INT_ACTIVE_LOW BIT(11)
35
36 /* Magic Packet MAC address registers */
37 #define MII_88E1318S_PHY_MAGIC_PACKET_WORD2 0x17
38 @@ -2832,6 +2834,34 @@ static int marvell_hwmon_probe(struct ph
39 }
40 #endif
41
42 +static int m88e1318_led_brightness_set(struct phy_device *phydev,
43 + u8 index, enum led_brightness value)
44 +{
45 + int reg;
46 +
47 + reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
48 + MII_88E1318S_PHY_LED_FUNC);
49 + if (reg < 0)
50 + return reg;
51 +
52 + switch (index) {
53 + case 0:
54 + case 1:
55 + case 2:
56 + reg &= ~(0xf << (4 * index));
57 + if (value == LED_OFF)
58 + reg |= MII_88E1318S_PHY_LED_FUNC_OFF << (4 * index);
59 + else
60 + reg |= MII_88E1318S_PHY_LED_FUNC_ON << (4 * index);
61 + break;
62 + default:
63 + return -EINVAL;
64 + }
65 +
66 + return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
67 + MII_88E1318S_PHY_LED_FUNC, reg);
68 +}
69 +
70 static int marvell_probe(struct phy_device *phydev)
71 {
72 struct marvell_priv *priv;
73 @@ -3081,6 +3111,7 @@ static struct phy_driver marvell_drivers
74 .get_sset_count = marvell_get_sset_count,
75 .get_strings = marvell_get_strings,
76 .get_stats = marvell_get_stats,
77 + .led_brightness_set = m88e1318_led_brightness_set,
78 },
79 {
80 .phy_id = MARVELL_PHY_ID_88E1145,
81 @@ -3187,6 +3218,7 @@ static struct phy_driver marvell_drivers
82 .cable_test_start = marvell_vct7_cable_test_start,
83 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
84 .cable_test_get_status = marvell_vct7_cable_test_get_status,
85 + .led_brightness_set = m88e1318_led_brightness_set,
86 },
87 {
88 .phy_id = MARVELL_PHY_ID_88E1540,
89 @@ -3213,6 +3245,7 @@ static struct phy_driver marvell_drivers
90 .cable_test_start = marvell_vct7_cable_test_start,
91 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
92 .cable_test_get_status = marvell_vct7_cable_test_get_status,
93 + .led_brightness_set = m88e1318_led_brightness_set,
94 },
95 {
96 .phy_id = MARVELL_PHY_ID_88E1545,
97 @@ -3239,6 +3272,7 @@ static struct phy_driver marvell_drivers
98 .cable_test_start = marvell_vct7_cable_test_start,
99 .cable_test_tdr_start = marvell_vct5_cable_test_tdr_start,
100 .cable_test_get_status = marvell_vct7_cable_test_get_status,
101 + .led_brightness_set = m88e1318_led_brightness_set,
102 },
103 {
104 .phy_id = MARVELL_PHY_ID_88E3016,
105 @@ -3380,6 +3414,7 @@ static struct phy_driver marvell_drivers
106 .get_stats = marvell_get_stats,
107 .get_tunable = m88e1540_get_tunable,
108 .set_tunable = m88e1540_set_tunable,
109 + .led_brightness_set = m88e1318_led_brightness_set,
110 },
111 };
112