All of lore.kernel.org
 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 3/3] net: stmmac: dwmac-rk: use stmmac helper functions for clock management
Date: Wed, 15 Sep 2021 19:02:55 +0200	[thread overview]
Message-ID: <20210915170255.30561-4-michael.riesch@wolfvision.net> (raw)
In-Reply-To: <20210915170255.30561-1-michael.riesch@wolfvision.net>

Make the stmmac core responsible for the management of the stmmaceth
clock (directly) and the dwmac-rk specific clocks (via a the clks_config
callback function).

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

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 96ec7d73a74a..0a66c3b589b1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -42,7 +42,6 @@ struct rk_priv_data {
 	bool clock_input;
 	bool integrated_phy;
 
-	struct clk *clk_mac;
 	struct clk *gmac_clkin;
 	struct clk *mac_clk_rx;
 	struct clk *mac_clk_tx;
@@ -1217,11 +1216,6 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)
 		dev_err(dev, "cannot get clock %s\n",
 			"pclk_mac");
 
-	bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth");
-	if (IS_ERR(bsp_priv->clk_mac))
-		dev_err(dev, "cannot get clock %s\n",
-			"stmmaceth");
-
 	if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) {
 		bsp_priv->clk_mac_ref = devm_clk_get(dev, "clk_mac_ref");
 		if (IS_ERR(bsp_priv->clk_mac_ref))
@@ -1245,7 +1239,7 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)
 		dev_info(dev, "clock input from PHY\n");
 	} else {
 		if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII)
-			clk_set_rate(bsp_priv->clk_mac, 50000000);
+			clk_set_rate(plat->stmmac_clk, 50000000);
 	}
 
 	if (plat->phy_node && bsp_priv->integrated_phy) {
@@ -1261,8 +1255,9 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)
 	return 0;
 }
 
-static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
+static int rk_gmac_clks_config(void *priv, bool enable)
 {
+	struct rk_priv_data *bsp_priv = priv;
 	int phy_iface = bsp_priv->phy_iface;
 
 	if (enable) {
@@ -1296,10 +1291,6 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
 			if (!IS_ERR(bsp_priv->clk_mac_speed))
 				clk_prepare_enable(bsp_priv->clk_mac_speed);
 
-			/**
-			 * if (!IS_ERR(bsp_priv->clk_mac))
-			 *	clk_prepare_enable(bsp_priv->clk_mac);
-			 */
 			mdelay(5);
 			bsp_priv->clk_enabled = true;
 		}
@@ -1322,10 +1313,7 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)
 			clk_disable_unprepare(bsp_priv->mac_clk_tx);
 
 			clk_disable_unprepare(bsp_priv->clk_mac_speed);
-			/**
-			 * if (!IS_ERR(bsp_priv->clk_mac))
-			 *	clk_disable_unprepare(bsp_priv->clk_mac);
-			 */
+
 			bsp_priv->clk_enabled = false;
 		}
 	}
@@ -1487,10 +1475,6 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
 	if (ret)
 		return ret;
 
-	ret = gmac_clk_enable(bsp_priv, true);
-	if (ret)
-		return ret;
-
 	/*rmii or rgmii*/
 	switch (bsp_priv->phy_iface) {
 	case PHY_INTERFACE_MODE_RGMII:
@@ -1519,10 +1503,8 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)
 	}
 
 	ret = phy_power_on(bsp_priv, true);
-	if (ret) {
-		gmac_clk_enable(bsp_priv, false);
+	if (ret)
 		return ret;
-	}
 
 	if (bsp_priv->integrated_phy)
 		rk_gmac_integrated_phy_powerup(bsp_priv);
@@ -1538,7 +1520,6 @@ static void rk_gmac_exit(struct platform_device *pdev, void *priv)
 		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 +1572,7 @@ static int rk_gmac_probe(struct platform_device *pdev)
 		plat_dat->has_gmac = true;
 	plat_dat->init = rk_gmac_init;
 	plat_dat->exit = rk_gmac_exit;
+	plat_dat->clks_config = rk_gmac_clks_config;
 	plat_dat->fix_mac_speed = rk_fix_speed;
 
 	plat_dat->bsp_priv = rk_gmac_setup(pdev, plat_dat, data);
@@ -1603,10 +1585,14 @@ static int rk_gmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_remove_config_dt;
 
-	ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
+	ret = rk_gmac_clks_config(plat_dat->bsp_priv, true);
 	if (ret)
 		goto err_remove_config_dt;
 
+	ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
+	if (ret)
+		goto err_gmac_clks_off;
+
 	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 	if (ret)
 		goto err_gmac_powerdown;
@@ -1615,6 +1601,8 @@ static int rk_gmac_probe(struct platform_device *pdev)
 
 err_gmac_powerdown:
 	rk_gmac_exit(pdev, plat_dat->bsp_priv);
+err_gmac_clks_off:
+	rk_gmac_clks_config(plat_dat->bsp_priv, true);
 err_remove_config_dt:
 	stmmac_remove_config_dt(pdev, plat_dat);
 
-- 
2.17.1


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

  parent 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 ` [RFC PATCH 1/3] net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and remove Michael Riesch
2021-09-21 14:23   ` 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 ` Michael Riesch [this message]
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-4-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.