linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook
@ 2021-02-17  4:20 Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower Samuel Holland
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

These patches clean up some things I noticed while fixing suspend/resume
behavior. The first four are minor code improvements. The last one adds
a shutdown hook to minimize power consumption on boards without a PMIC.

Changes v1 to v2:
  - Note the assumption of exclusive reset controller access in patch 3

Samuel Holland (5):
  net: stmmac: dwmac-sun8i: Return void from PHY unpower
  net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check
  net: stmmac: dwmac-sun8i: Use reset_control_reset
  net: stmmac: dwmac-sun8i: Minor probe function cleanup
  net: stmmac: dwmac-sun8i: Add a shutdown callback

 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 33 ++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
@ 2021-02-17  4:20 ` Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 2/5] net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check Samuel Holland
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

This is a deinitialization function that always returned zero, and that
return value was always ignored. Have it return void instead.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index a5e0eff4a3874..8e505019adf85 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -820,15 +820,14 @@ static int sun8i_dwmac_power_internal_phy(struct stmmac_priv *priv)
 	return 0;
 }
 
-static int sun8i_dwmac_unpower_internal_phy(struct sunxi_priv_data *gmac)
+static void sun8i_dwmac_unpower_internal_phy(struct sunxi_priv_data *gmac)
 {
 	if (!gmac->internal_phy_powered)
-		return 0;
+		return;
 
 	clk_disable_unprepare(gmac->ephy_clk);
 	reset_control_assert(gmac->rst_ephy);
 	gmac->internal_phy_powered = false;
-	return 0;
 }
 
 /* MDIO multiplexing switch function
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 2/5] net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower Samuel Holland
@ 2021-02-17  4:20 ` Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 3/5] net: stmmac: dwmac-sun8i: Use reset_control_reset Samuel Holland
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

sun8i_dwmac_unpower_internal_phy already checks if the PHY is powered,
so there is no need to do it again here.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 8e505019adf85..3c3d0b99d3e8c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1018,10 +1018,8 @@ static void sun8i_dwmac_exit(struct platform_device *pdev, void *priv)
 {
 	struct sunxi_priv_data *gmac = priv;
 
-	if (gmac->variant->soc_has_internal_phy) {
-		if (gmac->internal_phy_powered)
-			sun8i_dwmac_unpower_internal_phy(gmac);
-	}
+	if (gmac->variant->soc_has_internal_phy)
+		sun8i_dwmac_unpower_internal_phy(gmac);
 
 	clk_disable_unprepare(gmac->tx_clk);
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 3/5] net: stmmac: dwmac-sun8i: Use reset_control_reset
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 2/5] net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check Samuel Holland
@ 2021-02-17  4:20 ` Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 4/5] net: stmmac: dwmac-sun8i: Minor probe function cleanup Samuel Holland
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

Use the appropriate function instead of reimplementing it,
and update the error message to match the code.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 3c3d0b99d3e8c..b61f442ed3033 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -805,12 +805,12 @@ static int sun8i_dwmac_power_internal_phy(struct stmmac_priv *priv)
 
 	/* Make sure the EPHY is properly reseted, as U-Boot may leave
 	 * it at deasserted state, and thus it may fail to reset EMAC.
+	 *
+	 * This assumes the driver has exclusive access to the EPHY reset.
 	 */
-	reset_control_assert(gmac->rst_ephy);
-
-	ret = reset_control_deassert(gmac->rst_ephy);
+	ret = reset_control_reset(gmac->rst_ephy);
 	if (ret) {
-		dev_err(priv->device, "Cannot deassert internal phy\n");
+		dev_err(priv->device, "Cannot reset internal PHY\n");
 		clk_disable_unprepare(gmac->ephy_clk);
 		return ret;
 	}
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 4/5] net: stmmac: dwmac-sun8i: Minor probe function cleanup
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
                   ` (2 preceding siblings ...)
  2021-02-17  4:20 ` [PATCH net-next v2 3/5] net: stmmac: dwmac-sun8i: Use reset_control_reset Samuel Holland
@ 2021-02-17  4:20 ` Samuel Holland
  2021-02-17  4:20 ` [PATCH net-next v2 5/5] net: stmmac: dwmac-sun8i: Add a shutdown callback Samuel Holland
  2021-02-17 21:50 ` [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

Adjust the spacing and use an explicit "return 0" in the success path
to make the function easier to parse.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index b61f442ed3033..a3d333b652836 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1229,6 +1229,7 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
 
 	ndev = dev_get_drvdata(&pdev->dev);
 	priv = netdev_priv(ndev);
+
 	/* The mux must be registered after parent MDIO
 	 * so after stmmac_dvr_probe()
 	 */
@@ -1247,7 +1248,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
 			goto dwmac_remove;
 	}
 
-	return ret;
+	return 0;
+
 dwmac_mux:
 	reset_control_put(gmac->rst_ephy);
 	clk_put(gmac->ephy_clk);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v2 5/5] net: stmmac: dwmac-sun8i: Add a shutdown callback
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
                   ` (3 preceding siblings ...)
  2021-02-17  4:20 ` [PATCH net-next v2 4/5] net: stmmac: dwmac-sun8i: Minor probe function cleanup Samuel Holland
@ 2021-02-17  4:20 ` Samuel Holland
  2021-02-17 21:50 ` [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Samuel Holland @ 2021-02-17  4:20 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S. Miller, Jakub Kicinski, Maxime Ripard, Chen-Yu Tsai,
	Jernej Skrabec, Corentin Labbe
  Cc: Ondrej Jirman, netdev, linux-arm-kernel, linux-kernel,
	linux-sunxi, Samuel Holland

The Ethernet MAC and PHY are usually major consumers of power on boards
which may not be able to fully power off (those with no PMIC). Powering
down the MAC and internal PHY saves power while these boards are "off".

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index a3d333b652836..6b75cf2603ffc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1284,6 +1284,15 @@ static int sun8i_dwmac_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void sun8i_dwmac_shutdown(struct platform_device *pdev)
+{
+	struct net_device *ndev = platform_get_drvdata(pdev);
+	struct stmmac_priv *priv = netdev_priv(ndev);
+	struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
+
+	sun8i_dwmac_exit(pdev, gmac);
+}
+
 static const struct of_device_id sun8i_dwmac_match[] = {
 	{ .compatible = "allwinner,sun8i-h3-emac",
 		.data = &emac_variant_h3 },
@@ -1304,6 +1313,7 @@ MODULE_DEVICE_TABLE(of, sun8i_dwmac_match);
 static struct platform_driver sun8i_dwmac_driver = {
 	.probe  = sun8i_dwmac_probe,
 	.remove = sun8i_dwmac_remove,
+	.shutdown = sun8i_dwmac_shutdown,
 	.driver = {
 		.name           = "dwmac-sun8i",
 		.pm		= &stmmac_pltfr_pm_ops,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook
  2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
                   ` (4 preceding siblings ...)
  2021-02-17  4:20 ` [PATCH net-next v2 5/5] net: stmmac: dwmac-sun8i: Add a shutdown callback Samuel Holland
@ 2021-02-17 21:50 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-17 21:50 UTC (permalink / raw)
  To: Samuel Holland
  Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, kuba, mripard,
	wens, jernej.skrabec, clabbe, megous, netdev, linux-arm-kernel,
	linux-kernel, linux-sunxi

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Tue, 16 Feb 2021 22:20:01 -0600 you wrote:
> These patches clean up some things I noticed while fixing suspend/resume
> behavior. The first four are minor code improvements. The last one adds
> a shutdown hook to minimize power consumption on boards without a PMIC.
> 
> Changes v1 to v2:
>   - Note the assumption of exclusive reset controller access in patch 3
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower
    https://git.kernel.org/netdev/net-next/c/557ef2dfb586
  - [net-next,v2,2/5] net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check
    https://git.kernel.org/netdev/net-next/c/afac1d34bfb4
  - [net-next,v2,3/5] net: stmmac: dwmac-sun8i: Use reset_control_reset
    https://git.kernel.org/netdev/net-next/c/1c22f54696be
  - [net-next,v2,4/5] net: stmmac: dwmac-sun8i: Minor probe function cleanup
    https://git.kernel.org/netdev/net-next/c/2743aa245038
  - [net-next,v2,5/5] net: stmmac: dwmac-sun8i: Add a shutdown callback
    https://git.kernel.org/netdev/net-next/c/96be41d74f2e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-17 21:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17  4:20 [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook Samuel Holland
2021-02-17  4:20 ` [PATCH net-next v2 1/5] net: stmmac: dwmac-sun8i: Return void from PHY unpower Samuel Holland
2021-02-17  4:20 ` [PATCH net-next v2 2/5] net: stmmac: dwmac-sun8i: Remove unnecessary PHY power check Samuel Holland
2021-02-17  4:20 ` [PATCH net-next v2 3/5] net: stmmac: dwmac-sun8i: Use reset_control_reset Samuel Holland
2021-02-17  4:20 ` [PATCH net-next v2 4/5] net: stmmac: dwmac-sun8i: Minor probe function cleanup Samuel Holland
2021-02-17  4:20 ` [PATCH net-next v2 5/5] net: stmmac: dwmac-sun8i: Add a shutdown callback Samuel Holland
2021-02-17 21:50 ` [PATCH net-next v2 0/5] dwmac-sun8i cleanup and shutdown hook patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).