1 From 460b0b648fab24f576c481424e0de5479ffb9786 Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Tue, 8 Aug 2023 23:04:35 +0200
4 Subject: [PATCH 3/4] net: phy: marvell: Add support for offloading LED
7 Add the code needed to indicate if a given blinking pattern can be
8 offloaded, to offload a pattern and to try to return the current
11 Reviewed-by: Simon Horman <simon.horman@corigine.com>
12 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
13 Tested-by: Daniel Golle <daniel@makrotopia.org>
14 Link: https://lore.kernel.org/r/20230808210436.838995-4-andrew@lunn.ch
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 drivers/net/phy/marvell.c | 281 ++++++++++++++++++++++++++++++++++++++
18 1 file changed, 281 insertions(+)
20 --- a/drivers/net/phy/marvell.c
21 +++ b/drivers/net/phy/marvell.c
22 @@ -2893,6 +2893,272 @@ static int m88e1318_led_blink_set(struct
23 MII_88E1318S_PHY_LED_FUNC, reg);
26 +struct marvell_led_rules {
28 + unsigned long rules;
31 +static const struct marvell_led_rules marvell_led0[] = {
34 + .rules = BIT(TRIGGER_NETDEV_LINK),
38 + .rules = (BIT(TRIGGER_NETDEV_LINK) |
39 + BIT(TRIGGER_NETDEV_RX) |
40 + BIT(TRIGGER_NETDEV_TX)),
44 + .rules = (BIT(TRIGGER_NETDEV_RX) |
45 + BIT(TRIGGER_NETDEV_TX)),
49 + .rules = (BIT(TRIGGER_NETDEV_RX) |
50 + BIT(TRIGGER_NETDEV_TX)),
54 + .rules = BIT(TRIGGER_NETDEV_TX),
58 + .rules = BIT(TRIGGER_NETDEV_LINK),
62 + .rules = BIT(TRIGGER_NETDEV_LINK_1000),
70 +static const struct marvell_led_rules marvell_led1[] = {
73 + .rules = (BIT(TRIGGER_NETDEV_LINK) |
74 + BIT(TRIGGER_NETDEV_RX) |
75 + BIT(TRIGGER_NETDEV_TX)),
79 + .rules = (BIT(TRIGGER_NETDEV_LINK) |
80 + BIT(TRIGGER_NETDEV_RX)),
84 + .rules = (BIT(TRIGGER_NETDEV_RX) |
85 + BIT(TRIGGER_NETDEV_TX)),
89 + .rules = (BIT(TRIGGER_NETDEV_RX) |
90 + BIT(TRIGGER_NETDEV_TX)),
94 + .rules = (BIT(TRIGGER_NETDEV_LINK_100) |
95 + BIT(TRIGGER_NETDEV_LINK_1000)),
99 + .rules = BIT(TRIGGER_NETDEV_LINK_100),
107 +static const struct marvell_led_rules marvell_led2[] = {
110 + .rules = BIT(TRIGGER_NETDEV_LINK),
114 + .rules = (BIT(TRIGGER_NETDEV_LINK) |
115 + BIT(TRIGGER_NETDEV_RX) |
116 + BIT(TRIGGER_NETDEV_TX)),
120 + .rules = (BIT(TRIGGER_NETDEV_RX) |
121 + BIT(TRIGGER_NETDEV_TX)),
125 + .rules = (BIT(TRIGGER_NETDEV_RX) |
126 + BIT(TRIGGER_NETDEV_TX)),
130 + .rules = BIT(TRIGGER_NETDEV_TX),
134 + .rules = (BIT(TRIGGER_NETDEV_LINK_10) |
135 + BIT(TRIGGER_NETDEV_LINK_1000)),
139 + .rules = BIT(TRIGGER_NETDEV_LINK_10),
147 +static int marvell_find_led_mode(unsigned long rules,
148 + const struct marvell_led_rules *marvell_rules,
154 + for (i = 0; i < count; i++) {
155 + if (marvell_rules[i].rules == rules) {
156 + *mode = marvell_rules[i].mode;
160 + return -EOPNOTSUPP;
163 +static int marvell_get_led_mode(u8 index, unsigned long rules, int *mode)
169 + ret = marvell_find_led_mode(rules, marvell_led0,
170 + ARRAY_SIZE(marvell_led0), mode);
173 + ret = marvell_find_led_mode(rules, marvell_led1,
174 + ARRAY_SIZE(marvell_led1), mode);
177 + ret = marvell_find_led_mode(rules, marvell_led2,
178 + ARRAY_SIZE(marvell_led2), mode);
187 +static int marvell_find_led_rules(unsigned long *rules,
188 + const struct marvell_led_rules *marvell_rules,
194 + for (i = 0; i < count; i++) {
195 + if (marvell_rules[i].mode == mode) {
196 + *rules = marvell_rules[i].rules;
200 + return -EOPNOTSUPP;
203 +static int marvell_get_led_rules(u8 index, unsigned long *rules, int mode)
209 + ret = marvell_find_led_rules(rules, marvell_led0,
210 + ARRAY_SIZE(marvell_led0), mode);
213 + ret = marvell_find_led_rules(rules, marvell_led1,
214 + ARRAY_SIZE(marvell_led1), mode);
217 + ret = marvell_find_led_rules(rules, marvell_led2,
218 + ARRAY_SIZE(marvell_led2), mode);
227 +static int m88e1318_led_hw_is_supported(struct phy_device *phydev, u8 index,
228 + unsigned long rules)
236 + ret = marvell_get_led_mode(index, rules, &mode);
245 +static int m88e1318_led_hw_control_set(struct phy_device *phydev, u8 index,
246 + unsigned long rules)
248 + int mode, ret, reg;
254 + ret = marvell_get_led_mode(index, rules, &mode);
263 + reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
264 + MII_88E1318S_PHY_LED_FUNC);
268 + reg &= ~(0xf << (4 * index));
269 + reg |= mode << (4 * index);
270 + return phy_write_paged(phydev, MII_MARVELL_LED_PAGE,
271 + MII_88E1318S_PHY_LED_FUNC, reg);
274 +static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,
275 + unsigned long *rules)
282 + reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
283 + MII_88E1318S_PHY_LED_FUNC);
287 + mode = (reg >> (4 * index)) & 0xf;
289 + return marvell_get_led_rules(index, rules, mode);
292 static int marvell_probe(struct phy_device *phydev)
294 struct marvell_priv *priv;
295 @@ -3144,6 +3410,9 @@ static struct phy_driver marvell_drivers
296 .get_stats = marvell_get_stats,
297 .led_brightness_set = m88e1318_led_brightness_set,
298 .led_blink_set = m88e1318_led_blink_set,
299 + .led_hw_is_supported = m88e1318_led_hw_is_supported,
300 + .led_hw_control_set = m88e1318_led_hw_control_set,
301 + .led_hw_control_get = m88e1318_led_hw_control_get,
304 .phy_id = MARVELL_PHY_ID_88E1145,
305 @@ -3252,6 +3521,9 @@ static struct phy_driver marvell_drivers
306 .cable_test_get_status = marvell_vct7_cable_test_get_status,
307 .led_brightness_set = m88e1318_led_brightness_set,
308 .led_blink_set = m88e1318_led_blink_set,
309 + .led_hw_is_supported = m88e1318_led_hw_is_supported,
310 + .led_hw_control_set = m88e1318_led_hw_control_set,
311 + .led_hw_control_get = m88e1318_led_hw_control_get,
314 .phy_id = MARVELL_PHY_ID_88E1540,
315 @@ -3280,6 +3552,9 @@ static struct phy_driver marvell_drivers
316 .cable_test_get_status = marvell_vct7_cable_test_get_status,
317 .led_brightness_set = m88e1318_led_brightness_set,
318 .led_blink_set = m88e1318_led_blink_set,
319 + .led_hw_is_supported = m88e1318_led_hw_is_supported,
320 + .led_hw_control_set = m88e1318_led_hw_control_set,
321 + .led_hw_control_get = m88e1318_led_hw_control_get,
324 .phy_id = MARVELL_PHY_ID_88E1545,
325 @@ -3308,6 +3583,9 @@ static struct phy_driver marvell_drivers
326 .cable_test_get_status = marvell_vct7_cable_test_get_status,
327 .led_brightness_set = m88e1318_led_brightness_set,
328 .led_blink_set = m88e1318_led_blink_set,
329 + .led_hw_is_supported = m88e1318_led_hw_is_supported,
330 + .led_hw_control_set = m88e1318_led_hw_control_set,
331 + .led_hw_control_get = m88e1318_led_hw_control_get,
334 .phy_id = MARVELL_PHY_ID_88E3016,
335 @@ -3451,6 +3729,9 @@ static struct phy_driver marvell_drivers
336 .set_tunable = m88e1540_set_tunable,
337 .led_brightness_set = m88e1318_led_brightness_set,
338 .led_blink_set = m88e1318_led_blink_set,
339 + .led_hw_is_supported = m88e1318_led_hw_is_supported,
340 + .led_hw_control_set = m88e1318_led_hw_control_set,
341 + .led_hw_control_get = m88e1318_led_hw_control_get,