From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CDC4EB64DD for ; Thu, 20 Jul 2023 07:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbjGTHYG (ORCPT ); Thu, 20 Jul 2023 03:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbjGTHYB (ORCPT ); Thu, 20 Jul 2023 03:24:01 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249E22118 for ; Thu, 20 Jul 2023 00:24:00 -0700 (PDT) Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1qMO0I-00086j-7R; Thu, 20 Jul 2023 09:23:14 +0200 From: Marco Felsch To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, mcoquelin.stm32@gmail.com Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next v3 2/2] net: stmmac: add support for phy-supply Date: Thu, 20 Jul 2023 09:23:04 +0200 Message-Id: <20230720072304.3358701-2-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720072304.3358701-1-m.felsch@pengutronix.de> References: <20230720072304.3358701-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add generic phy-supply handling support to control the phy regulator to avoid handling it within the glue code. Use the generic stmmac_platform code to register a possible phy-supply and the stmmac_main code to handle the power on/off. Signed-off-by: Marco Felsch --- Changelog v3: - rebased onto net-next/main - fixed changelog style v2: - adapt stmmac_phy_power - move power-on/off into stmmac_main to handle WOL - adapt commit message .../net/ethernet/stmicro/stmmac/stmmac_main.c | 58 ++++++++++++++++++- .../ethernet/stmicro/stmmac/stmmac_platform.c | 10 ++++ include/linux/stmmac.h | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index e7ca52f0d2f2d..6ffb03abddfd9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef CONFIG_DEBUG_FS #include #include @@ -1128,6 +1129,55 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv) } } +/** + * stmmac_phy_power - PHY regulator on/off + * @priv: driver private structure + * @enable: turn on the regulator if true else turn it off + * Enable or disable the regulator powering the PHY. + */ +static int stmmac_phy_power(struct stmmac_priv *priv, bool enable) +{ + struct regulator *regulator = priv->plat->phy_regulator; + struct device *dev = priv->device; + + if (!regulator) + return 0; + + if (enable) { + int ret; + + ret = regulator_enable(regulator); + if (ret) + dev_err(dev, "Fail to enable regulator\n"); + + return ret; + } + + regulator_disable(regulator); + + return 0; +} + +/** + * stmmac_phy_power_on - PHY regulator on + * @priv: driver private structure + * Enable the PHY regulator + */ +static int stmmac_phy_power_on(struct stmmac_priv *priv) +{ + return stmmac_phy_power(priv, true); +} + +/** + * stmmac_phy_power_off - PHY regulator off + * @priv: driver private structure + * Disable the PHY regulator + */ +static void stmmac_phy_power_off(struct stmmac_priv *priv) +{ + stmmac_phy_power(priv, false); +} + /** * stmmac_init_phy - PHY initialization * @dev: net device structure @@ -1253,7 +1303,8 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) return PTR_ERR(phylink); priv->phylink = phylink; - return 0; + + return stmmac_phy_power_on(priv); } static void stmmac_display_rx_rings(struct stmmac_priv *priv, @@ -7588,6 +7639,7 @@ void stmmac_dvr_remove(struct device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); + stmmac_phy_power_off(priv); destroy_workqueue(priv->wq); mutex_destroy(&priv->lock); bitmap_free(priv->af_xdp_zc_qps); @@ -7651,6 +7703,8 @@ int stmmac_suspend(struct device *dev) if (device_may_wakeup(priv->device)) phylink_speed_down(priv->phylink, false); phylink_suspend(priv->phylink, false); + if (!priv->plat->use_phy_wol) + stmmac_phy_power_off(priv); } rtnl_unlock(); @@ -7733,6 +7787,8 @@ int stmmac_resume(struct device *dev) priv->irq_wake = 0; } else { pinctrl_pm_select_default_state(priv->device); + if (!priv->plat->use_phy_wol) + stmmac_phy_power_on(priv); /* reset the phy so that it's ready */ if (priv->mii) stmmac_mdio_reset(priv->mii); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 23d53ea04b24d..18988da4614cd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -424,6 +425,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) if (plat->interface < 0) plat->interface = plat->phy_interface; + /* Optional regulator for PHY */ + plat->phy_regulator = devm_regulator_get_optional(&pdev->dev, "phy"); + if (IS_ERR(plat->phy_regulator)) { + if (PTR_ERR(plat->phy_regulator) == -EPROBE_DEFER) + return ERR_CAST(plat->phy_regulator); + dev_info(&pdev->dev, "No regulator found\n"); + plat->phy_regulator = NULL; + } + /* Some wrapper drivers still rely on phy_node. Let's save it while * they are not converted to phylink. */ plat->phy_node = of_parse_phandle(np, "phy-handle", 0); diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index ef67dba775d04..b5d2d75de2759 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -222,6 +222,7 @@ struct plat_stmmacenet_data { int phy_addr; int interface; phy_interface_t phy_interface; + struct regulator *phy_regulator; struct stmmac_mdio_bus_data *mdio_bus_data; struct device_node *phy_node; struct device_node *phylink_node; -- 2.39.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46507EB64DA for ; Thu, 20 Jul 2023 07:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VnwTL4zFfJ36JkYg+29XMQ9HmD2NtA/oh5DYrCcE10o=; b=H51H4n2SbFKNor Rq35ZbfQgaDcNDhkhUB4a0YqRoczfdFgoCNv8wKtcg7VKDOWSYWMJbgwo9jfyn+s+5MR2+kZIfkmu UUgAmMTBWq4qAA/d/oMA2jgWrsTp/zSwwjPOBvHczemqu9GHiwYjOVks8kHNuLJFOOPOoyc09hAfn zdW+6FxUib2wc9clqY3D/iwR9IKUiaO43NGz2bBNZmP9lMUXK4DSeLQw6hbkIRyNK3/fJuTZejlak EzJGNvSPrrG+oZuFSgepIT5W2z+JUEaUBHUSzGEs+K1+tRlKiU0eiwDmf4VdRVnhwN21OHD9CTfxt JJjek+MfZx5y8zKYrckQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qMO1D-00A770-15; Thu, 20 Jul 2023 07:24:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMO1B-00A766-32 for linux-arm-kernel@bombadil.infradead.org; Thu, 20 Jul 2023 07:24:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=mz9u+NWYxe0OCFTFWAwWSdtLw8Xp2L+1x4TVOWKmwp0=; b=EKZyjt/wMdOltZIa+uoaJS+Avv 79vWMaeReYupU8CgBos7tVaXtNVjlZcTzKr+Eh1Gv1+RBZ/zEe2qbVNFJiknjrq+3j2cot/05Gix4 qT4rZyOYK1htZeomhZulr34MleyFd6U3J4/UZ0V40XZOzSP/LI8000ytxj2o+FghkgMqvgfH3Ccfq lPzthgnRzUx8mjQ8Xu8/GGPhNGxTvwxO2iqFvwmZsIFsrmIeIXk+7EP3OTQnmG6VYLvn4DGd3Dl72 nZrAtY9LgAHQtgi3z5bfH0etOr68FhFv24Vailp7wNezZsBVmRXy+lD6foWHxToGXeR8eeSPbRY0k yaIZ+umA==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qMO14-00FNSr-0G for linux-arm-kernel@lists.infradead.org; Thu, 20 Jul 2023 07:24:06 +0000 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1qMO0I-00086j-7R; Thu, 20 Jul 2023 09:23:14 +0200 From: Marco Felsch To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, mcoquelin.stm32@gmail.com Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next v3 2/2] net: stmmac: add support for phy-supply Date: Thu, 20 Jul 2023 09:23:04 +0200 Message-Id: <20230720072304.3358701-2-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230720072304.3358701-1-m.felsch@pengutronix.de> References: <20230720072304.3358701-1-m.felsch@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230720_082404_599506_431FFC52 X-CRM114-Status: GOOD ( 21.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add generic phy-supply handling support to control the phy regulator to avoid handling it within the glue code. Use the generic stmmac_platform code to register a possible phy-supply and the stmmac_main code to handle the power on/off. Signed-off-by: Marco Felsch --- Changelog v3: - rebased onto net-next/main - fixed changelog style v2: - adapt stmmac_phy_power - move power-on/off into stmmac_main to handle WOL - adapt commit message .../net/ethernet/stmicro/stmmac/stmmac_main.c | 58 ++++++++++++++++++- .../ethernet/stmicro/stmmac/stmmac_platform.c | 10 ++++ include/linux/stmmac.h | 1 + 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index e7ca52f0d2f2d..6ffb03abddfd9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef CONFIG_DEBUG_FS #include #include @@ -1128,6 +1129,55 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv) } } +/** + * stmmac_phy_power - PHY regulator on/off + * @priv: driver private structure + * @enable: turn on the regulator if true else turn it off + * Enable or disable the regulator powering the PHY. + */ +static int stmmac_phy_power(struct stmmac_priv *priv, bool enable) +{ + struct regulator *regulator = priv->plat->phy_regulator; + struct device *dev = priv->device; + + if (!regulator) + return 0; + + if (enable) { + int ret; + + ret = regulator_enable(regulator); + if (ret) + dev_err(dev, "Fail to enable regulator\n"); + + return ret; + } + + regulator_disable(regulator); + + return 0; +} + +/** + * stmmac_phy_power_on - PHY regulator on + * @priv: driver private structure + * Enable the PHY regulator + */ +static int stmmac_phy_power_on(struct stmmac_priv *priv) +{ + return stmmac_phy_power(priv, true); +} + +/** + * stmmac_phy_power_off - PHY regulator off + * @priv: driver private structure + * Disable the PHY regulator + */ +static void stmmac_phy_power_off(struct stmmac_priv *priv) +{ + stmmac_phy_power(priv, false); +} + /** * stmmac_init_phy - PHY initialization * @dev: net device structure @@ -1253,7 +1303,8 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) return PTR_ERR(phylink); priv->phylink = phylink; - return 0; + + return stmmac_phy_power_on(priv); } static void stmmac_display_rx_rings(struct stmmac_priv *priv, @@ -7588,6 +7639,7 @@ void stmmac_dvr_remove(struct device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); + stmmac_phy_power_off(priv); destroy_workqueue(priv->wq); mutex_destroy(&priv->lock); bitmap_free(priv->af_xdp_zc_qps); @@ -7651,6 +7703,8 @@ int stmmac_suspend(struct device *dev) if (device_may_wakeup(priv->device)) phylink_speed_down(priv->phylink, false); phylink_suspend(priv->phylink, false); + if (!priv->plat->use_phy_wol) + stmmac_phy_power_off(priv); } rtnl_unlock(); @@ -7733,6 +7787,8 @@ int stmmac_resume(struct device *dev) priv->irq_wake = 0; } else { pinctrl_pm_select_default_state(priv->device); + if (!priv->plat->use_phy_wol) + stmmac_phy_power_on(priv); /* reset the phy so that it's ready */ if (priv->mii) stmmac_mdio_reset(priv->mii); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 23d53ea04b24d..18988da4614cd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -424,6 +425,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) if (plat->interface < 0) plat->interface = plat->phy_interface; + /* Optional regulator for PHY */ + plat->phy_regulator = devm_regulator_get_optional(&pdev->dev, "phy"); + if (IS_ERR(plat->phy_regulator)) { + if (PTR_ERR(plat->phy_regulator) == -EPROBE_DEFER) + return ERR_CAST(plat->phy_regulator); + dev_info(&pdev->dev, "No regulator found\n"); + plat->phy_regulator = NULL; + } + /* Some wrapper drivers still rely on phy_node. Let's save it while * they are not converted to phylink. */ plat->phy_node = of_parse_phandle(np, "phy-handle", 0); diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index ef67dba775d04..b5d2d75de2759 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -222,6 +222,7 @@ struct plat_stmmacenet_data { int phy_addr; int interface; phy_interface_t phy_interface; + struct regulator *phy_regulator; struct stmmac_mdio_bus_data *mdio_bus_data; struct device_node *phy_node; struct device_node *phylink_node; -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel