From: Selvamani Rajagopal Generic helper function to modify loopback bit of the PHY without modifying any other bit. This will help the PHYs that may have fixed speed, like 10Base-T1S or PHYs that don't need any other settings to set them in loopback mode. Signed-off-by: Selvamani Rajagopal --- changes in v7 - No change changes in v6 - No change changes in v5 - No change changes in v4 - Created a new genphy API to set the loopback. No other PHY registers touched. --- drivers/net/phy/dp83867.c | 11 +---------- drivers/net/phy/phy_device.c | 20 ++++++++++++++++++++ include/linux/phy.h | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 88255e92b4cd..01ea2e8dd253 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -991,15 +991,6 @@ static void dp83867_link_change_notify(struct phy_device *phydev) } } -static int dp83867_loopback(struct phy_device *phydev, bool enable, int speed) -{ - if (enable && speed) - return -EOPNOTSUPP; - - return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, - enable ? BMCR_LOOPBACK : 0); -} - static int dp83867_led_brightness_set(struct phy_device *phydev, u8 index, enum led_brightness brightness) @@ -1204,7 +1195,7 @@ static struct phy_driver dp83867_driver[] = { .resume = dp83867_resume, .link_change_notify = dp83867_link_change_notify, - .set_loopback = dp83867_loopback, + .set_loopback = genphy_loopback_fixed_speed, .led_brightness_set = dp83867_led_brightness_set, .led_hw_is_supported = dp83867_led_hw_is_supported, diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b82b99d08132..11fd204eea16 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2842,6 +2842,26 @@ int genphy_phy_write_mmd(struct phy_device *phydev, int devnum, } EXPORT_SYMBOL(genphy_phy_write_mmd); +/** + * genphy_loopback_fixed_speed - Helper to modify the PHY loopback mode + * without affecting any other settings. + * @phydev: The phy_device struct + * @enable: Flag to enable or disable the PHY level loopback. + * @speed: Speed setting. Not expected to be set. Error if it is set. + * + * Returns: 0 if successful, negative error code on failure. + */ +int genphy_loopback_fixed_speed(struct phy_device *phydev, bool enable, + int speed) +{ + if (enable && speed) + return -EOPNOTSUPP; + + return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, + enable ? BMCR_LOOPBACK : 0); +} +EXPORT_SYMBOL(genphy_loopback_fixed_speed); + int genphy_suspend(struct phy_device *phydev) { return phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN); diff --git a/include/linux/phy.h b/include/linux/phy.h index 8266dd4a8dbe..61bcd71a3143 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2301,6 +2301,8 @@ int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad, u16 regnum); int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum, u16 regnum, u16 val); +int genphy_loopback_fixed_speed(struct phy_device *phydev, bool enable, + int speed); int genphy_phy_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, u16 val); int genphy_phy_read_mmd(struct phy_device *phydev, int devnum, -- 2.43.0