1 From 7ae215ee7bb855f13c80565470fc7f67db4ba82f Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 25 Jan 2024 21:36:59 +0100
4 Subject: [PATCH 3/5] net: phy: add support for PHY LEDs polarity modes
6 Add support for PHY LEDs polarity modes. Some PHY require LED to be set
7 to active low to be turned ON. Adds support for this by declaring
8 active-low property in DT.
10 PHY driver needs to declare .led_polarity_set() to configure LED
11 polarity modes. Function will pass the index with the LED index and a
12 bitmap with all the required modes to set.
14 Current supported modes are:
15 - active-low with the flag PHY_LED_ACTIVE_LOW. LED is set to active-low
17 - inactive-high-impedance with the flag PHY_LED_INACTIVE_HIGH_IMPEDANCE.
18 LED is set to high impedance to turn it OFF.
20 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
21 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
22 Link: https://lore.kernel.org/r/20240125203702.4552-4-ansuelsmth@gmail.com
23 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
25 drivers/net/phy/phy_device.c | 16 ++++++++++++++++
26 include/linux/phy.h | 22 ++++++++++++++++++++++
27 2 files changed, 38 insertions(+)
29 --- a/drivers/net/phy/phy_device.c
30 +++ b/drivers/net/phy/phy_device.c
31 @@ -3140,6 +3140,7 @@ static int of_phy_led(struct phy_device
32 struct device *dev = &phydev->mdio.dev;
33 struct led_init_data init_data = {};
34 struct led_classdev *cdev;
35 + unsigned long modes = 0;
36 struct phy_led *phyled;
39 @@ -3157,6 +3158,21 @@ static int of_phy_led(struct phy_device
43 + if (of_property_read_bool(led, "active-low"))
44 + set_bit(PHY_LED_ACTIVE_LOW, &modes);
45 + if (of_property_read_bool(led, "inactive-high-impedance"))
46 + set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes);
49 + /* Return error if asked to set polarity modes but not supported */
50 + if (!phydev->drv->led_polarity_set)
53 + err = phydev->drv->led_polarity_set(phydev, index, modes);
58 phyled->index = index;
59 if (phydev->drv->led_brightness_set)
60 cdev->brightness_set_blocking = phy_led_set_brightness;
61 --- a/include/linux/phy.h
62 +++ b/include/linux/phy.h
63 @@ -791,6 +791,15 @@ struct phy_led {
65 #define to_phy_led(d) container_of(d, struct phy_led, led_cdev)
67 +/* Modes for PHY LED configuration */
69 + PHY_LED_ACTIVE_LOW = 0,
70 + PHY_LED_INACTIVE_HIGH_IMPEDANCE = 1,
73 + __PHY_LED_MODES_NUM,
77 * struct phy_driver - Driver structure for a particular PHY type
79 @@ -1059,6 +1068,19 @@ struct phy_driver {
80 int (*led_hw_control_get)(struct phy_device *dev, u8 index,
81 unsigned long *rules);
84 + * @led_polarity_set: Set the LED polarity modes
85 + * @dev: PHY device which has the LED
86 + * @index: Which LED of the PHY device
87 + * @modes: bitmap of LED polarity modes
89 + * Configure LED with all the required polarity modes in @modes
90 + * to make it correctly turn ON or OFF.
92 + * Returns 0, or an error code.
94 + int (*led_polarity_set)(struct phy_device *dev, int index,
95 + unsigned long modes);
97 #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
98 struct phy_driver, mdiodrv)