From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com ([74.125.82.65]:54852 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991AbeCPVZr (ORCPT ); Fri, 16 Mar 2018 17:25:47 -0400 Received: by mail-wm0-f65.google.com with SMTP id h76so5538060wme.4 for ; Fri, 16 Mar 2018 14:25:46 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH RFC v2 3/7] net: phy: resume PHY only if needed in mdio_bus_phy_suspend To: Florian Fainelli , Andrew Lunn , Geert Uytterhoeven Cc: "netdev@vger.kernel.org" References: <6618f53c-778a-cb12-deb4-c618a728b43e@gmail.com> Message-ID: <1e350c73-291a-210a-7d34-92cb3af3850d@gmail.com> Date: Fri, 16 Mar 2018 22:15:05 +0100 MIME-Version: 1.0 In-Reply-To: <6618f53c-778a-cb12-deb4-c618a728b43e@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org List-ID: Currently the PHY is unconditionally resumed in mdio_bus_phy_suspend(). In cases where the PHY was sleepinh before suspending or if somebody else takes care of resuming later, this is not needed and wastes energy. Also start the state machine only if it's used by the driver (indicated by the adjust_link callback being defined). Signed-off-by: Heiner Kallweit --- v2: - rename variable in mdio_bus_phy_needs_start --- drivers/net/phy/phy_device.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 85ebb969..c934725b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -124,6 +124,18 @@ static bool phy_may_suspend(struct phy_device *phydev) } #ifdef CONFIG_PM + +static bool mdio_bus_phy_needs_start(struct phy_device *phydev) +{ + bool needs_start; + + mutex_lock(&phydev->lock); + needs_start = phydev->state == PHY_UP && phydev->adjust_link; + mutex_unlock(&phydev->lock); + + return needs_start; +} + static int mdio_bus_phy_suspend(struct device *dev) { struct phy_device *phydev = to_phy_device(dev); @@ -142,16 +154,17 @@ static int mdio_bus_phy_suspend(struct device *dev) static int mdio_bus_phy_resume(struct device *dev) { struct phy_device *phydev = to_phy_device(dev); - int ret; + int ret = 0; - ret = phy_resume(phydev); - if (ret < 0) - return ret; + if (!phydev->attached_dev) + return 0; - if (phydev->attached_dev && phydev->adjust_link) - phy_start_machine(phydev); + if (mdio_bus_phy_needs_start(phydev)) + phy_start(phydev); + else if (!phydev->adjust_link) + ret = phy_resume(phydev); - return 0; + return ret; } static int mdio_bus_phy_restore(struct device *dev) @@ -171,7 +184,8 @@ static int mdio_bus_phy_restore(struct device *dev) phydev->link = 0; phydev->state = PHY_UP; - phy_start_machine(phydev); + if (mdio_bus_phy_needs_start(phydev)) + phy_start(phydev); return 0; } -- 2.16.2