linux-rockchip.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Michael Riesch <michael.riesch@wolfvision.net>
To: linux-rockchip@lists.infradead.org
Cc: Heiko Stuebner <heiko@sntech.de>,
	ivan@ivan.computer, punitagrawal@gmail.com,
	Michael Riesch <michael.riesch@wolfvision.net>
Subject: [RFC PATCH 1/3] net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and remove
Date: Wed, 15 Sep 2021 19:02:53 +0200	[thread overview]
Message-ID: <20210915170255.30561-2-michael.riesch@wolfvision.net> (raw)
In-Reply-To: <20210915170255.30561-1-michael.riesch@wolfvision.net>

Make the stmmac core responsible for suspend, resume and remove by
providing callbacks and using helper functions.

Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
---
 .../net/ethernet/stmicro/stmmac/dwmac-rk.c    | 69 +++++--------------
 1 file changed, 16 insertions(+), 53 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index ed817011a94a..0db8be543ee1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -40,7 +40,6 @@ struct rk_priv_data {
 	phy_interface_t phy_iface;
 	int id;
 	struct regulator *regulator;
-	bool suspended;
 	const struct rk_gmac_ops *ops;
 
 	bool clk_enabled;
@@ -1482,10 +1481,11 @@ static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv)
 	return 0;
 }
 
-static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
+static int rk_gmac_init(struct platform_device *pdev, void *priv)
 {
 	int ret;
-	struct device *dev = &bsp_priv->pdev->dev;
+	struct device *dev = &pdev->dev;
+	struct rk_priv_data *bsp_priv = priv;
 
 	ret = rk_gmac_check_ops(bsp_priv);
 	if (ret)
@@ -1534,13 +1534,15 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
 	return 0;
 }
 
-static void rk_gmac_powerdown(struct rk_priv_data *gmac)
+static void rk_gmac_exit(struct platform_device *pdev, void *priv)
 {
-	if (gmac->integrated_phy)
-		rk_gmac_integrated_phy_powerdown(gmac);
+	struct rk_priv_data *bsp_priv = priv;
 
-	phy_power_on(gmac, false);
-	gmac_clk_enable(gmac, false);
+	if (bsp_priv->integrated_phy)
+		rk_gmac_integrated_phy_powerdown(bsp_priv);
+
+	phy_power_on(bsp_priv, false);
+	gmac_clk_enable(bsp_priv, false);
 }
 
 static void rk_fix_speed(void *priv, unsigned int speed)
@@ -1591,6 +1593,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	 */
 	if (!plat_dat->has_gmac4)
 		plat_dat->has_gmac = true;
+	plat_dat->init = rk_gmac_init;
+	plat_dat->exit = rk_gmac_exit;
 	plat_dat->fix_mac_speed = rk_fix_speed;
 
 	plat_dat->bsp_priv = rk_gmac_setup(pdev, plat_dat, data);
@@ -1603,7 +1607,7 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_remove_config_dt;
 
-	ret = rk_gmac_powerup(plat_dat->bsp_priv);
+	ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
 	if (ret)
 		goto err_remove_config_dt;
 
@@ -1614,54 +1618,13 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	return 0;
 
 err_gmac_powerdown:
-	rk_gmac_powerdown(plat_dat->bsp_priv);
+	rk_gmac_exit(pdev, plat_dat->bsp_priv);
 err_remove_config_dt:
 	stmmac_remove_config_dt(pdev, plat_dat);
 
 	return ret;
 }
 
-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);
-
-	return ret;
-}
-
-#ifdef CONFIG_PM_SLEEP
-static int rk_gmac_suspend(struct device *dev)
-{
-	struct rk_priv_data *bsp_priv = get_stmmac_bsp_priv(dev);
-	int ret = stmmac_suspend(dev);
-
-	/* Keep the PHY up if we use Wake-on-Lan. */
-	if (!device_may_wakeup(dev)) {
-		rk_gmac_powerdown(bsp_priv);
-		bsp_priv->suspended = true;
-	}
-
-	return ret;
-}
-
-static int rk_gmac_resume(struct device *dev)
-{
-	struct rk_priv_data *bsp_priv = get_stmmac_bsp_priv(dev);
-
-	/* The PHY was up for Wake-on-Lan. */
-	if (bsp_priv->suspended) {
-		rk_gmac_powerup(bsp_priv);
-		bsp_priv->suspended = false;
-	}
-
-	return stmmac_resume(dev);
-}
-#endif /* CONFIG_PM_SLEEP */
-
-static SIMPLE_DEV_PM_OPS(rk_gmac_pm_ops, rk_gmac_suspend, rk_gmac_resume);
-
 static const struct of_device_id rk_gmac_dwmac_match[] = {
 	{ .compatible = "rockchip,px30-gmac",	.data = &px30_ops   },
 	{ .compatible = "rockchip,rk3128-gmac", .data = &rk3128_ops },
@@ -1680,10 +1643,10 @@ MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);
 
 static struct platform_driver rk_gmac_dwmac_driver = {
 	.probe  = rk_gmac_probe,
-	.remove = rk_gmac_remove,
+	.remove = stmmac_pltfr_remove,
 	.driver = {
 		.name           = "rk_gmac-dwmac",
-		.pm		= &rk_gmac_pm_ops,
+		.pm		= &stmmac_pltfr_pm_ops,
 		.of_match_table = rk_gmac_dwmac_match,
 	},
 };
-- 
2.17.1


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  reply	other threads:[~2021-09-15 17:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15 17:02 [RFC PATCH 0/3] net: stmmac: dwmac-rk: use stmmac helper functions and clean up Michael Riesch
2021-09-15 17:02 ` Michael Riesch [this message]
2021-09-21 14:23   ` [RFC PATCH 1/3] net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and remove Heiko Stuebner
2021-09-15 17:02 ` [RFC PATCH 2/3] net: stmmac: dwmac-rk: clean up includes Michael Riesch
2021-09-21 14:34   ` Heiko Stuebner
2021-09-15 17:02 ` [RFC PATCH 3/3] net: stmmac: dwmac-rk: use stmmac helper functions for clock management Michael Riesch
2021-09-15 23:29 ` [RFC PATCH 0/3] net: stmmac: dwmac-rk: use stmmac helper functions and clean up Punit Agrawal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210915170255.30561-2-michael.riesch@wolfvision.net \
    --to=michael.riesch@wolfvision.net \
    --cc=heiko@sntech.de \
    --cc=ivan@ivan.computer \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=punitagrawal@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).