00bdcc54689ce6cb26960befe588a62949440b24
[openwrt/staging/pepe2k.git] /
1 From 4e901018432e38eab35d2a352661ce4727795be1 Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Mon, 17 Apr 2023 17:17:30 +0200
4 Subject: [PATCH 8/9] net: phy: phy_device: Call into the PHY driver to set LED
5 blinking
6
7 Linux LEDs can be requested to perform hardware accelerated
8 blinking. Pass this to the PHY driver, if it implements the op.
9
10 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
11 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
12 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/phy/phy_device.c | 18 ++++++++++++++++++
16 include/linux/phy.h | 12 ++++++++++++
17 2 files changed, 30 insertions(+)
18
19 --- a/drivers/net/phy/phy_device.c
20 +++ b/drivers/net/phy/phy_device.c
21 @@ -3052,6 +3052,22 @@ static int phy_led_set_brightness(struct
22 return err;
23 }
24
25 +static int phy_led_blink_set(struct led_classdev *led_cdev,
26 + unsigned long *delay_on,
27 + unsigned long *delay_off)
28 +{
29 + struct phy_led *phyled = to_phy_led(led_cdev);
30 + struct phy_device *phydev = phyled->phydev;
31 + int err;
32 +
33 + mutex_lock(&phydev->lock);
34 + err = phydev->drv->led_blink_set(phydev, phyled->index,
35 + delay_on, delay_off);
36 + mutex_unlock(&phydev->lock);
37 +
38 + return err;
39 +}
40 +
41 static int of_phy_led(struct phy_device *phydev,
42 struct device_node *led)
43 {
44 @@ -3074,6 +3090,8 @@ static int of_phy_led(struct phy_device
45
46 if (phydev->drv->led_brightness_set)
47 cdev->brightness_set_blocking = phy_led_set_brightness;
48 + if (phydev->drv->led_blink_set)
49 + cdev->blink_set = phy_led_blink_set;
50 cdev->max_brightness = 1;
51 init_data.devicename = dev_name(&phydev->mdio.dev);
52 init_data.fwnode = of_fwnode_handle(led);
53 --- a/include/linux/phy.h
54 +++ b/include/linux/phy.h
55 @@ -1014,6 +1014,18 @@ struct phy_driver {
56 */
57 int (*led_brightness_set)(struct phy_device *dev,
58 u8 index, enum led_brightness value);
59 +
60 + /**
61 + * @led_blink_set: Set a PHY LED brightness. Index indicates
62 + * which of the PHYs led should be configured to blink. Delays
63 + * are in milliseconds and if both are zero then a sensible
64 + * default should be chosen. The call should adjust the
65 + * timings in that case and if it can't match the values
66 + * specified exactly.
67 + */
68 + int (*led_blink_set)(struct phy_device *dev, u8 index,
69 + unsigned long *delay_on,
70 + unsigned long *delay_off);
71 };
72 #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
73 struct phy_driver, mdiodrv)