diff mbox series

[v2,3/8] net: macb: add function to disable all macb clocks

Message ID 1607343333-26552-4-git-send-email-claudiu.beznea@microchip.com (mailing list archive)
State New, archived
Headers show
Series net: macb: add support for sama7g5 | expand

Commit Message

Claudiu Beznea Dec. 7, 2020, 12:15 p.m. UTC
Add function to disable all macb clocks.

Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Suggested-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/ethernet/cadence/macb_main.c | 62 ++++++++++++++++----------------
 1 file changed, 32 insertions(+), 30 deletions(-)

Comments

Andrew Lunn Dec. 8, 2020, 6:48 p.m. UTC | #1
Hi Claudiu

>  static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
>  			 struct clk **hclk, struct clk **tx_clk,
>  			 struct clk **rx_clk, struct clk **tsu_clk)
> @@ -3743,40 +3753,37 @@ static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
>  	err = clk_prepare_enable(*hclk);
>  	if (err) {
>  		dev_err(&pdev->dev, "failed to enable hclk (%d)\n", err);
> -		goto err_disable_pclk;
> +		hclk = NULL;
> +		tx_clk = NULL;
> +		rx_clk = NULL;
> +		goto err_disable_clks;
>  	}
>  
>  	err = clk_prepare_enable(*tx_clk);
>  	if (err) {
>  		dev_err(&pdev->dev, "failed to enable tx_clk (%d)\n", err);
> -		goto err_disable_hclk;
> +		tx_clk = NULL;
> +		rx_clk = NULL;
> +		goto err_disable_clks;
>  	}
>  
>  	err = clk_prepare_enable(*rx_clk);
>  	if (err) {
>  		dev_err(&pdev->dev, "failed to enable rx_clk (%d)\n", err);
> -		goto err_disable_txclk;
> +		rx_clk = NULL;
> +		goto err_disable_clks;
>  	}
>  
>  	err = clk_prepare_enable(*tsu_clk);
>  	if (err) {
>  		dev_err(&pdev->dev, "failed to enable tsu_clk (%d)\n", err);
> -		goto err_disable_rxclk;
> +		goto err_disable_clks;
>  	}
>  
>  	return 0;
>  
> -err_disable_rxclk:
> -	clk_disable_unprepare(*rx_clk);
> -
> -err_disable_txclk:
> -	clk_disable_unprepare(*tx_clk);
> -
> -err_disable_hclk:
> -	clk_disable_unprepare(*hclk);
> -
> -err_disable_pclk:
> -	clk_disable_unprepare(*pclk);
> +err_disable_clks:
> +	macb_clks_disable(*pclk, *hclk, *tx_clk, *rx_clk, NULL);

Personal taste, but i would of not changed this.

>  
>  	return err;
>  }
> @@ -4755,11 +4762,7 @@ static int macb_probe(struct platform_device *pdev)
>  	free_netdev(dev);
>  
>  err_disable_clocks:
> -	clk_disable_unprepare(tx_clk);
> -	clk_disable_unprepare(hclk);
> -	clk_disable_unprepare(pclk);
> -	clk_disable_unprepare(rx_clk);
> -	clk_disable_unprepare(tsu_clk);
> +	macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk, bp->rx_clk, bp->tsu_clk);
>  	pm_runtime_disable(&pdev->dev);
>  	pm_runtime_set_suspended(&pdev->dev);
>  	pm_runtime_dont_use_autosuspend(&pdev->dev);
> @@ -4784,11 +4787,8 @@ static int macb_remove(struct platform_device *pdev)
>  		pm_runtime_disable(&pdev->dev);
>  		pm_runtime_dont_use_autosuspend(&pdev->dev);
>  		if (!pm_runtime_suspended(&pdev->dev)) {
> -			clk_disable_unprepare(bp->tx_clk);
> -			clk_disable_unprepare(bp->hclk);
> -			clk_disable_unprepare(bp->pclk);
> -			clk_disable_unprepare(bp->rx_clk);
> -			clk_disable_unprepare(bp->tsu_clk);
> +			macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk,
> +					  bp->rx_clk, bp->tsu_clk);
>  			pm_runtime_set_suspended(&pdev->dev);
>  		}
>  		phylink_destroy(bp->phylink);
> @@ -4966,14 +4966,16 @@ static int __maybe_unused macb_runtime_suspend(struct device *dev)
>  {
>  	struct net_device *netdev = dev_get_drvdata(dev);
>  	struct macb *bp = netdev_priv(netdev);
> +	struct clk *pclk = NULL, *hclk = NULL, *tx_clk = NULL, *rx_clk = NULL;
>  
>  	if (!(device_may_wakeup(dev))) {
> -		clk_disable_unprepare(bp->tx_clk);
> -		clk_disable_unprepare(bp->hclk);
> -		clk_disable_unprepare(bp->pclk);
> -		clk_disable_unprepare(bp->rx_clk);
> +		pclk = bp->pclk;
> +		hclk = bp->hclk;
> +		tx_clk = bp->tx_clk;
> +		rx_clk = bp->rx_clk;
>  	}
> -	clk_disable_unprepare(bp->tsu_clk);
> +
> +	macb_clks_disable(pclk, hclk, tx_clk, rx_clk, bp->tsu_clk);

Maybe

  	if (!(device_may_wakeup(dev)))
		macb_clks_disable(bp->pclk, bp->hclk, pb->tx_clk, bp->rx_clk, bp->tsu_clk);
	else
		macb_clks_disable(NULL, NULL, NULL, NULL, bp->tsu_clk);

is more readable?

   Andrew
Jakub Kicinski Dec. 9, 2020, 12:22 a.m. UTC | #2
On Tue, 8 Dec 2020 19:48:56 +0100 Andrew Lunn wrote:
> > -err_disable_rxclk:
> > -	clk_disable_unprepare(*rx_clk);
> > -
> > -err_disable_txclk:
> > -	clk_disable_unprepare(*tx_clk);
> > -
> > -err_disable_hclk:
> > -	clk_disable_unprepare(*hclk);
> > -
> > -err_disable_pclk:
> > -	clk_disable_unprepare(*pclk);
> > +err_disable_clks:
> > +	macb_clks_disable(*pclk, *hclk, *tx_clk, *rx_clk, NULL);  
> 
> Personal taste, but i would of not changed this.

+1 FWIW
Florian Fainelli Dec. 9, 2020, 12:29 a.m. UTC | #3
On 12/7/20 4:15 AM, Claudiu Beznea wrote:
> Add function to disable all macb clocks.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  drivers/net/ethernet/cadence/macb_main.c | 62 ++++++++++++++++----------------
>  1 file changed, 32 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index b23e986ac6dc..6b8e1109dfd3 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -3694,6 +3694,16 @@ static void macb_probe_queues(void __iomem *mem,
>  	*num_queues = hweight32(*queue_mask);
>  }
>  
> +static void macb_clks_disable(struct clk *pclk, struct clk *hclk, struct clk *tx_clk,
> +			      struct clk *rx_clk, struct clk *tsu_clk)
> +{
> +	clk_disable_unprepare(tx_clk);
> +	clk_disable_unprepare(hclk);
> +	clk_disable_unprepare(pclk);
> +	clk_disable_unprepare(rx_clk);
> +	clk_disable_unprepare(tsu_clk);

Looks like you should consider using the CLK bulk API:
clk_bulk_disable_unprepare() and friends.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index b23e986ac6dc..6b8e1109dfd3 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -3694,6 +3694,16 @@  static void macb_probe_queues(void __iomem *mem,
 	*num_queues = hweight32(*queue_mask);
 }
 
+static void macb_clks_disable(struct clk *pclk, struct clk *hclk, struct clk *tx_clk,
+			      struct clk *rx_clk, struct clk *tsu_clk)
+{
+	clk_disable_unprepare(tx_clk);
+	clk_disable_unprepare(hclk);
+	clk_disable_unprepare(pclk);
+	clk_disable_unprepare(rx_clk);
+	clk_disable_unprepare(tsu_clk);
+}
+
 static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
 			 struct clk **hclk, struct clk **tx_clk,
 			 struct clk **rx_clk, struct clk **tsu_clk)
@@ -3743,40 +3753,37 @@  static int macb_clk_init(struct platform_device *pdev, struct clk **pclk,
 	err = clk_prepare_enable(*hclk);
 	if (err) {
 		dev_err(&pdev->dev, "failed to enable hclk (%d)\n", err);
-		goto err_disable_pclk;
+		hclk = NULL;
+		tx_clk = NULL;
+		rx_clk = NULL;
+		goto err_disable_clks;
 	}
 
 	err = clk_prepare_enable(*tx_clk);
 	if (err) {
 		dev_err(&pdev->dev, "failed to enable tx_clk (%d)\n", err);
-		goto err_disable_hclk;
+		tx_clk = NULL;
+		rx_clk = NULL;
+		goto err_disable_clks;
 	}
 
 	err = clk_prepare_enable(*rx_clk);
 	if (err) {
 		dev_err(&pdev->dev, "failed to enable rx_clk (%d)\n", err);
-		goto err_disable_txclk;
+		rx_clk = NULL;
+		goto err_disable_clks;
 	}
 
 	err = clk_prepare_enable(*tsu_clk);
 	if (err) {
 		dev_err(&pdev->dev, "failed to enable tsu_clk (%d)\n", err);
-		goto err_disable_rxclk;
+		goto err_disable_clks;
 	}
 
 	return 0;
 
-err_disable_rxclk:
-	clk_disable_unprepare(*rx_clk);
-
-err_disable_txclk:
-	clk_disable_unprepare(*tx_clk);
-
-err_disable_hclk:
-	clk_disable_unprepare(*hclk);
-
-err_disable_pclk:
-	clk_disable_unprepare(*pclk);
+err_disable_clks:
+	macb_clks_disable(*pclk, *hclk, *tx_clk, *rx_clk, NULL);
 
 	return err;
 }
@@ -4755,11 +4762,7 @@  static int macb_probe(struct platform_device *pdev)
 	free_netdev(dev);
 
 err_disable_clocks:
-	clk_disable_unprepare(tx_clk);
-	clk_disable_unprepare(hclk);
-	clk_disable_unprepare(pclk);
-	clk_disable_unprepare(rx_clk);
-	clk_disable_unprepare(tsu_clk);
+	macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk, bp->rx_clk, bp->tsu_clk);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
@@ -4784,11 +4787,8 @@  static int macb_remove(struct platform_device *pdev)
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_dont_use_autosuspend(&pdev->dev);
 		if (!pm_runtime_suspended(&pdev->dev)) {
-			clk_disable_unprepare(bp->tx_clk);
-			clk_disable_unprepare(bp->hclk);
-			clk_disable_unprepare(bp->pclk);
-			clk_disable_unprepare(bp->rx_clk);
-			clk_disable_unprepare(bp->tsu_clk);
+			macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk,
+					  bp->rx_clk, bp->tsu_clk);
 			pm_runtime_set_suspended(&pdev->dev);
 		}
 		phylink_destroy(bp->phylink);
@@ -4966,14 +4966,16 @@  static int __maybe_unused macb_runtime_suspend(struct device *dev)
 {
 	struct net_device *netdev = dev_get_drvdata(dev);
 	struct macb *bp = netdev_priv(netdev);
+	struct clk *pclk = NULL, *hclk = NULL, *tx_clk = NULL, *rx_clk = NULL;
 
 	if (!(device_may_wakeup(dev))) {
-		clk_disable_unprepare(bp->tx_clk);
-		clk_disable_unprepare(bp->hclk);
-		clk_disable_unprepare(bp->pclk);
-		clk_disable_unprepare(bp->rx_clk);
+		pclk = bp->pclk;
+		hclk = bp->hclk;
+		tx_clk = bp->tx_clk;
+		rx_clk = bp->rx_clk;
 	}
-	clk_disable_unprepare(bp->tsu_clk);
+
+	macb_clks_disable(pclk, hclk, tx_clk, rx_clk, bp->tsu_clk);
 
 	return 0;
 }