net: phy: marvell: add support for PHY LEDs polarity modes
Subsystems (3)
PATCH v3 1/1 net: phy: marvell: add support for PHY LEDs polarity modes
Add the led_polarity_set callback for setting LED polarity. Implement this callback for the 88E1116R, 88E1318 and 88E1510 PHYs. This should also work on other Marvell PHYs, but I don't have access to the TRM or the hardware.
Keep the LED polarization settings and restore them after a hardware reset. This modification is actually only necessary on devices with a wired PHY reset line and a driver that resets the PHY during the link-up/link-down events. I found a single DTS file in OpenWRT (armada-385-fortinet-fg-5xe.dtsi) that matches this hardware configuration.
Tested on Adapteva Paralella board with Marvell 88E1318 PHY.
---
Changes in v3:
- Restore polarity settings after hardware reset
- Enable polarity control on 88E1116R
Changes in v2:
- add suppoer for PHY_LED_INACTIVE_HIGH_IMPEDANCE mode
--- drivers/net/phy/marvell.c | 65 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-)
drivers/net/phy/marvell.c +64 -1
@@ -146,6 +146,9 @@#define MII_88E1318S_PHY_LED_FUNC_ON (0x9)#define MII_88E1318S_PHY_LED_FUNC_HI_Z (0xa)#define MII_88E1318S_PHY_LED_FUNC_BLINK (0xb) +#define MII_88E1318S_PHY_LED_POL 0x11 +#define MII_88E1318S_PHY_LED_POL_ACT_HIGH (idx) BIT(2 * (idx)) +#define MII_88E1318S_PHY_LED_POL_HIGH_IMP (idx) BIT(2 * (idx) + 1)#define MII_88E1318S_PHY_LED_TCR 0x12#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
@@ -301,6 +304,8 @@#define NB_FIBER_STATS 1#define NB_STAT_MAX 3 +#define M88E1318S_MAX_LEDS 3 +MODULE_DESCRIPTION ("Marvell PHY driver" );MODULE_AUTHOR ("Andy Fleming" );MODULE_LICENSE ("GPL" );
@@ -352,6 +357,8 @@ struct marvell_priv {s8 pair;u8 vct_phase;bool wol_enabled; +u16 led_polarity_mask; +u16 led_polarity_val; };static int marvell_read_page (struct phy_device *phydev)
@@ -924,9 +931,22 @@ static void marvell_config_led(struct phy_device *phydev)static int marvell_config_init (struct phy_device *phydev) { +struct marvell_priv *priv = phydev->priv; +int err; +/* Set default LED */ marvell_config_led (phydev); +/* Restore the LED polarity settings after a reset. */ +if (priv->led_polarity_mask) { + err =phy_modify_paged (phydev,MII_MARVELL_LED_PAGE , +MII_88E1318S_PHY_LED_POL , + priv->led_polarity_mask, + priv->led_polarity_val); +if (err <0 ) +return err; + } +/* Set registers from marvell,reg-init DT property */ return marvell_of_reg_init (phydev); }
@@ -3625,7 +3645,7 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index, {int mode, reg; -if (index >2 ) +if (index >=M88E1318S_MAX_LEDS )return -EINVAL ; reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
@@ -3638,6 +3658,46 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,return marvell_get_led_rules (index, rules, mode); } +static int m88e1318_led_polarity_set (struct phy_device *phydev,int index, +unsigned long modes) +{ +struct marvell_priv *priv = phydev->priv; +u16 val =0 ; +u32 mode; +u16 mask; +int err; + +if (index <0 || index >=M88E1318S_MAX_LEDS ) +return -EINVAL ; + +for_each_set_bit (mode, &modes, __PHY_LED_MODES_NUM) { +switch (mode) { +case PHY_LED_ACTIVE_LOW : +break ; +case PHY_LED_ACTIVE_HIGH : + val |=MII_88E1318S_PHY_LED_POL_ACT_HIGH (index); +break ; +case PHY_LED_INACTIVE_HIGH_IMPEDANCE : + val |=MII_88E1318S_PHY_LED_POL_HIGH_IMP (index); +break ; +default : +return -EINVAL ; + } + } + + mask =MII_88E1318S_PHY_LED_POL_ACT_HIGH (index) | +MII_88E1318S_PHY_LED_POL_HIGH_IMP (index); + err =phy_modify_paged (phydev,MII_MARVELL_LED_PAGE , +MII_88E1318S_PHY_LED_POL , mask, val); +if (err <0 ) +return err; + + priv->led_polarity_mask |= mask; + priv->led_polarity_val |= val; + +return 0 ; +} +static int marvell_probe (struct phy_device *phydev) {struct marvell_priv *priv;
@@ -3886,6 +3946,7 @@ static struct phy_driver marvell_drivers[] = { .led_hw_is_supported = m88e1318_led_hw_is_supported, .led_hw_control_set = m88e1318_led_hw_control_set, .led_hw_control_get = m88e1318_led_hw_control_get, + .led_polarity_set = m88e1318_led_polarity_set, }, { .phy_id = MARVELL_PHY_ID_88E1145,
@@ -3971,6 +4032,7 @@ static struct phy_driver marvell_drivers[] = { .led_hw_is_supported = m88e1318_led_hw_is_supported, .led_hw_control_set = m88e1318_led_hw_control_set, .led_hw_control_get = m88e1318_led_hw_control_get, + .led_polarity_set = m88e1318_led_polarity_set, }, { .phy_id = MARVELL_PHY_ID_88E1510,
@@ -4005,6 +4067,7 @@ static struct phy_driver marvell_drivers[] = { .led_hw_is_supported = m88e1318_led_hw_is_supported, .led_hw_control_set = m88e1318_led_hw_control_set, .led_hw_control_get = m88e1318_led_hw_control_get, + .led_polarity_set = m88e1318_led_polarity_set, .attach_mii_port = m88e1510_attach_mii_port, }, {
Signature · 1 line
2.55.0
Andrew Lunn
maintainerQuoted 4 lines · Aleksander Jan Bajkowski
Add the
led_polarity_setcallback for setting LED polarity. Implement this callback for the 88E1116R, 88E1318 and 88E1510 PHYs. This should also work on other Marvell PHYs, but I don't have access to the TRM or the hardware.
Marvell have an SDK called DSDT, which covers their PHYs. It is GPL licensed, but not widely distributed. If you can find a copy, it will give you all the details for determining which PHYs this will work for. Just be warned, the code is horrible.
Quoted 5 lines
Keep the LED polarization settings and restore them after a hardware reset. This modification is actually only necessary on devices with a wired PHY reset line and a driver that resets the PHY during the link-up/link-down events. I found a single DTS file in OpenWRT (
armada-385-fortinet-fg-5xe.dtsi) that matches this hardware configuration.
Mainline does not really care about OpenWRT. However, why does armada-385-fortinet-fg-5xe.dtsi do this? Is it because of an errata in the PHY? Such an errata we might care about.
Quoted 4 lines
static int
marvell_config_init(struct phy_device *phydev){drivers/net/phy/marvell.c +2
-0+struct marvell_priv *priv = phydev->priv; +int err;
drivers/net/phy/marvell.c static void marvell_config_led(struct phy_device *phydev) · line 945
Quoted 10 lines
drivers/net/phy/marvell.c +7
-0+/* Set default LED */ marvell_config_led (phydev); +/* Restore the LED polarity settings after a reset. */ +if (priv->led_polarity_mask) { + err =phy_modify_paged (phydev,MII_MARVELL_LED_PAGE , +MII_88E1318S_PHY_LED_POL , + priv->led_polarity_mask, + priv->led_polarity_val);
This does not make much sense to me. If you have lost polarity, you have also likely lost the LED blinks modes. So you are only restoring part of the state?
And this is for a device which does not even exist in mainline.
I suggest KISS, throw this out.
Andrew