Add the "st,phy-wol" to indicate the MAC to use the wakeup capability of the PHY instead of the MAC. Signed-off-by: Gatien Chevallier --- Documentation/devicetree/bindings/net/stm32-dwmac.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/stm32-dwmac.yaml b/Documentation/devicetree/bindings/net/stm32-dwmac.yaml index 987254900d0da7aab81237f20b1540ad8a17bd21..985bd4c320b3e07fd1cd0aa398d6cce0b55a4e4d 100644 --- a/Documentation/devicetree/bindings/net/stm32-dwmac.yaml +++ b/Documentation/devicetree/bindings/net/stm32-dwmac.yaml @@ -121,6 +121,12 @@ properties: minItems: 1 maxItems: 2 + st,phy-wol: + description: + set this property to use the wakeup capability from the PHY, if supported, instead of the + MAC. + type: boolean + required: - compatible - clocks -- 2.35.3 If the "st,phy-wol" property is present in the device tree node, set the STMMAC_FLAG_USE_PHY_WOL flag to use the WoL capability of the PHY. Signed-off-by: Gatien Chevallier --- drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c index 77a04c4579c9dbae886a0b387f69610a932b7b9e..6f197789cc2e8018d6959158b795e4bca46869c5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c @@ -106,6 +106,7 @@ struct stm32_dwmac { u32 speed; const struct stm32_ops *ops; struct device *dev; + bool phy_wol; }; struct stm32_ops { @@ -433,6 +434,8 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, } } + dwmac->phy_wol = of_property_read_bool(np, "st,phy-wol"); + return err; } @@ -557,6 +560,8 @@ static int stm32_dwmac_probe(struct platform_device *pdev) plat_dat->bsp_priv = dwmac; plat_dat->suspend = stm32_dwmac_suspend; plat_dat->resume = stm32_dwmac_resume; + if (dwmac->phy_wol) + plat_dat->flags |= STMMAC_FLAG_USE_PHY_WOL; ret = stm32_dwmac_init(plat_dat); if (ret) -- 2.35.3 Add suspend()/resume() callbacks that do not shut down the PHY if the WoL is supported and handle the WoL status flags. If the WoL is supported by the PHY, indicate that the PHY device can be a source of wake up for the platform. When setting the WoL configuration, enable this capability. The suspend() callback now handle WoL event flags that would prevent a system to wake up from a WoL event when in low-power mode. Because the WoL prevents a call to the suspend() callback, add the PHY_ALWAYS_CALL_SUSPEND flag to the LAN8742 PHYs. Fixes: 8b305ee2a91c ("net: phy: smsc: add WoL support to LAN8740/LAN8742 PHYs") Signed-off-by: Gatien Chevallier --- drivers/net/phy/smsc.c | 66 +++++++++++++++++++++++++++++++++++++++++++++---- include/linux/smscphy.h | 2 ++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c index 48487149c22528631be5aca98ff4980f55b495d9..818cb21b833a530c7fa2384f605bbb2e93c5eb5f 100644 --- a/drivers/net/phy/smsc.c +++ b/drivers/net/phy/smsc.c @@ -537,14 +537,67 @@ static int lan874x_set_wol(struct phy_device *phydev, } } - rc = phy_write_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR, - val_wucsr); + /* Enable wakeup on PHY device if at least one WoL feature is configured */ + device_set_wakeup_enable(&phydev->mdio.dev, !!(val_wucsr & MII_LAN874X_PHY_WOL_MASK)); + + rc = phy_write_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR, val_wucsr); if (rc < 0) return rc; return 0; } +static int smsc_phy_suspend(struct phy_device *phydev) +{ + int rc; + + if (!device_may_wakeup(&phydev->mdio.dev)) + return 0; + + if (!phydev->wol_enabled) + return genphy_suspend(phydev); + + /* Handle pending WoL events */ + rc = phy_read_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR); + if (rc < 0) { + phy_error(phydev); + return -EINVAL; + } + + if (!(rc & MII_LAN874X_PHY_WOL_STATUS_MASK)) + return 0; + + rc = phy_write_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR, + rc | MII_LAN874X_PHY_WOL_STATUS_MASK); + if (rc < 0) { + phy_error(phydev); + return -EINVAL; + } + + return 0; +} + +static int smsc_phy_resume(struct phy_device *phydev) +{ + int rc; + + if (!phydev->wol_enabled) + return genphy_resume(phydev); + + rc = phy_read_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR); + if (rc < 0) + return rc; + + if (!(rc & MII_LAN874X_PHY_WOL_STATUS_MASK)) + return 0; + + phydev_dbg(phydev, "Woke up from LAN event.\n"); + rc = phy_write_mmd(phydev, MDIO_MMD_PCS, MII_LAN874X_PHY_MMD_WOL_WUCSR, + rc | MII_LAN874X_PHY_WOL_STATUS_MASK); + + return rc; +} + static int smsc_get_sset_count(struct phy_device *phydev) { return ARRAY_SIZE(smsc_hw_stats); @@ -673,6 +726,9 @@ int smsc_phy_probe(struct phy_device *phydev) phydev->priv = priv; + if (phydev->drv->set_wol) + device_set_wakeup_capable(&phydev->mdio.dev, true); + /* Make clk optional to keep DTB backward compatibility. */ refclk = devm_clk_get_optional_enabled_with_rate(dev, NULL, 50 * 1000 * 1000); @@ -851,7 +907,7 @@ static struct phy_driver smsc_phy_driver[] = { .name = "Microchip LAN8742", /* PHY_BASIC_FEATURES */ - .flags = PHY_RST_AFTER_CLK_EN, + .flags = PHY_RST_AFTER_CLK_EN | PHY_ALWAYS_CALL_SUSPEND, .probe = smsc_phy_probe, @@ -876,8 +932,8 @@ static struct phy_driver smsc_phy_driver[] = { .set_wol = lan874x_set_wol, .get_wol = lan874x_get_wol, - .suspend = genphy_suspend, - .resume = genphy_resume, + .suspend = smsc_phy_suspend, + .resume = smsc_phy_resume, } }; module_phy_driver(smsc_phy_driver); diff --git a/include/linux/smscphy.h b/include/linux/smscphy.h index 1a6a851d2cf80d225bada7adeb79969e625964bd..cdf266960032609241afc8316da23f1c4834bfee 100644 --- a/include/linux/smscphy.h +++ b/include/linux/smscphy.h @@ -65,6 +65,8 @@ int smsc_phy_probe(struct phy_device *phydev); #define MII_LAN874X_PHY_WOL_WUEN BIT(2) #define MII_LAN874X_PHY_WOL_MPEN BIT(1) #define MII_LAN874X_PHY_WOL_BCSTEN BIT(0) +#define MII_LAN874X_PHY_WOL_MASK GENMASK(4, 0) +#define MII_LAN874X_PHY_WOL_STATUS_MASK GENMASK(7, 4) #define MII_LAN874X_PHY_WOL_FILTER_EN BIT(15) #define MII_LAN874X_PHY_WOL_FILTER_MCASTTEN BIT(9) -- 2.35.3 On this board, the ETH1 supports WoL from PHY. Add the "st,phy-wol" property to support it. Signed-off-by: Gatien Chevallier --- arch/arm/boot/dts/st/stm32mp135f-dk.dts | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/boot/dts/st/stm32mp135f-dk.dts b/arch/arm/boot/dts/st/stm32mp135f-dk.dts index 9764a6bfa5b428c8524a5902c10b7807dda46b3d..d746424b039013759bfbcce5193a701ff775e715 100644 --- a/arch/arm/boot/dts/st/stm32mp135f-dk.dts +++ b/arch/arm/boot/dts/st/stm32mp135f-dk.dts @@ -193,6 +193,7 @@ ðernet1 { pinctrl-names = "default", "sleep"; phy-mode = "rmii"; phy-handle = <&phy0_eth1>; + st,phy-wol; mdio { #address-cells = <1>; -- 2.35.3