2021-10-08 10:28:39

by hmz007

[permalink] [raw]
Subject: [PATCH] net: stmmac: dwmac-rk: Add runtime PM support

Commit 2d26f6e39afb ("fix unbalanced pm_runtime_enable warnings")
also enables runtime PM, which affects rk3399 with power-domain.

After an off-on switch of power-domain, the GMAC doesn't work properly,
calling rk_gmac_powerup at runtime resume fixes this issue.

Fixes: 2d26f6e39afb ("net: stmmac: dwmac-rk: fix unbalanced pm_runtime_enable warnings")
Signed-off-by: hmz007 <[email protected]>
---
.../net/ethernet/stmicro/stmmac/dwmac-rk.c | 25 ++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index ed817011a94a..a9eb98691a66 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -21,6 +21,7 @@
#include <linux/delay.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
+#include <linux/pm_runtime.h>

#include "stmmac_platform.h"

@@ -1626,7 +1627,8 @@ static int rk_gmac_remove(struct platform_device *pdev)
struct rk_priv_data *bsp_priv = get_stmmac_bsp_priv(&pdev->dev);
int ret = stmmac_dvr_remove(&pdev->dev);

- rk_gmac_powerdown(bsp_priv);
+ if (!pm_runtime_status_suspended(&pdev->dev))
+ rk_gmac_powerdown(bsp_priv);

return ret;
}
@@ -1638,7 +1640,7 @@ static int rk_gmac_suspend(struct device *dev)
int ret = stmmac_suspend(dev);

/* Keep the PHY up if we use Wake-on-Lan. */
- if (!device_may_wakeup(dev)) {
+ if (pm_runtime_active(dev) && !device_may_wakeup(dev)) {
rk_gmac_powerdown(bsp_priv);
bsp_priv->suspended = true;
}
@@ -1660,7 +1662,24 @@ static int rk_gmac_resume(struct device *dev)
}
#endif /* CONFIG_PM_SLEEP */

-static SIMPLE_DEV_PM_OPS(rk_gmac_pm_ops, rk_gmac_suspend, rk_gmac_resume);
+#ifdef CONFIG_PM
+static int rk_gmac_runtime_suspend(struct device *dev)
+{
+ rk_gmac_powerdown(get_stmmac_bsp_priv(dev));
+ return 0;
+}
+
+static int rk_gmac_runtime_resume(struct device *dev)
+{
+ rk_gmac_powerup(get_stmmac_bsp_priv(dev));
+ return 0;
+}
+#endif
+
+static const struct dev_pm_ops __maybe_unused rk_gmac_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(rk_gmac_suspend, rk_gmac_resume)
+ SET_RUNTIME_PM_OPS(rk_gmac_runtime_suspend, rk_gmac_runtime_resume, NULL)
+};

static const struct of_device_id rk_gmac_dwmac_match[] = {
{ .compatible = "rockchip,px30-gmac", .data = &px30_ops },
--
2.33.0


2021-10-08 14:08:59

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: stmmac: dwmac-rk: Add runtime PM support

From: hmz007 <[email protected]>
Date: Fri, 8 Oct 2021 18:24:10 +0800

> Commit 2d26f6e39afb ("fix unbalanced pm_runtime_enable warnings")
> also enables runtime PM, which affects rk3399 with power-domain.
>
> After an off-on switch of power-domain, the GMAC doesn't work properly,
> calling rk_gmac_powerup at runtime resume fixes this issue.
>
> Fixes: 2d26f6e39afb ("net: stmmac: dwmac-rk: fix unbalanced pm_runtime_enable warnings")
> Signed-off-by: hmz007 <[email protected]>

This patch does not apply to any of the networking trees.