Commit 0969abaa authored by Quentin Schulz's avatar Quentin Schulz Committed by David S. Miller

net: phy: mscc: factorize function for getting LED mode from DT

Microsemi PHYs support different LED modes depending on the variant, so
let's factorize the code so we just have to give the supported modes
while the logic behind getting the mode remains identical.
Signed-off-by: default avatarQuentin Schulz <quentin.schulz@bootlin.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 11bfdabb
...@@ -104,8 +104,24 @@ enum rgmii_rx_clock_delay { ...@@ -104,8 +104,24 @@ enum rgmii_rx_clock_delay {
#define DOWNSHIFT_COUNT_MAX 5 #define DOWNSHIFT_COUNT_MAX 5
#define MAX_LEDS 4 #define MAX_LEDS 4
#define VSC85XX_SUPP_LED_MODES (BIT(VSC8531_LINK_ACTIVITY) | \
BIT(VSC8531_LINK_1000_ACTIVITY) | \
BIT(VSC8531_LINK_100_ACTIVITY) | \
BIT(VSC8531_LINK_10_ACTIVITY) | \
BIT(VSC8531_LINK_100_1000_ACTIVITY) | \
BIT(VSC8531_LINK_10_1000_ACTIVITY) | \
BIT(VSC8531_LINK_10_100_ACTIVITY) | \
BIT(VSC8531_DUPLEX_COLLISION) | \
BIT(VSC8531_COLLISION) | \
BIT(VSC8531_ACTIVITY) | \
BIT(VSC8531_AUTONEG_FAULT) | \
BIT(VSC8531_SERIAL_MODE) | \
BIT(VSC8531_FORCE_LED_OFF) | \
BIT(VSC8531_FORCE_LED_ON))
struct vsc8531_private { struct vsc8531_private {
int rate_magic; int rate_magic;
u16 supp_led_modes;
u8 leds_mode[MAX_LEDS]; u8 leds_mode[MAX_LEDS];
u8 nleds; u8 nleds;
}; };
...@@ -401,6 +417,7 @@ static int vsc85xx_dt_led_mode_get(struct phy_device *phydev, ...@@ -401,6 +417,7 @@ static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
char *led, char *led,
u8 default_mode) u8 default_mode)
{ {
struct vsc8531_private *priv = phydev->priv;
struct device *dev = &phydev->mdio.dev; struct device *dev = &phydev->mdio.dev;
struct device_node *of_node = dev->of_node; struct device_node *of_node = dev->of_node;
u8 led_mode; u8 led_mode;
...@@ -411,7 +428,7 @@ static int vsc85xx_dt_led_mode_get(struct phy_device *phydev, ...@@ -411,7 +428,7 @@ static int vsc85xx_dt_led_mode_get(struct phy_device *phydev,
led_mode = default_mode; led_mode = default_mode;
err = of_property_read_u8(of_node, led, &led_mode); err = of_property_read_u8(of_node, led, &led_mode);
if (!err && (led_mode > 15 || led_mode == 7 || led_mode == 11)) { if (!err && !(BIT(led_mode) & priv->supp_led_modes)) {
phydev_err(phydev, "DT %s invalid\n", led); phydev_err(phydev, "DT %s invalid\n", led);
return -EINVAL; return -EINVAL;
} }
...@@ -655,6 +672,7 @@ static int vsc85xx_probe(struct phy_device *phydev) ...@@ -655,6 +672,7 @@ static int vsc85xx_probe(struct phy_device *phydev)
vsc8531->rate_magic = rate_magic; vsc8531->rate_magic = rate_magic;
vsc8531->nleds = 2; vsc8531->nleds = 2;
vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES;
return vsc85xx_dt_led_modes_get(phydev, default_mode); return vsc85xx_dt_led_modes_get(phydev, default_mode);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment