diff mbox series

[08/15] i2c: busses: mt7621: Use devm_clk_get_enabled()

Message ID 20230611225702.891856-9-andi.shyti@kernel.org
State New
Headers show
Series i2c: busses: Use devm_clk_get_enabled() | expand

Commit Message

Andi Shyti June 11, 2023, 10:56 p.m. UTC
Replace the pair of functions, devm_clk_get() and
clk_prepare_enable(), with a single function
devm_clk_get_enabled().

Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Cc: Stefan Roese <sr@denx.de>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/i2c/busses/i2c-mt7621.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

Comments

Matthias Brugger June 12, 2023, 3:17 a.m. UTC | #1
On 12/06/2023 00:56, Andi Shyti wrote:
> Replace the pair of functions, devm_clk_get() and
> clk_prepare_enable(), with a single function
> devm_clk_get_enabled().
> 
> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> Cc: Stefan Roese <sr@denx.de>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/i2c/busses/i2c-mt7621.c | 20 ++++----------------
>   1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index f9c294e2bd3c5..104bb194e9906 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -282,16 +282,11 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   	if (IS_ERR(i2c->base))
>   		return PTR_ERR(i2c->base);
>   
> -	i2c->clk = devm_clk_get(&pdev->dev, NULL);
> +	i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>   	if (IS_ERR(i2c->clk)) {
> -		dev_err(&pdev->dev, "no clock defined\n");
> +		dev_err(&pdev->dev, "Failed to enable clock\n");
>   		return PTR_ERR(i2c->clk);
>   	}
> -	ret = clk_prepare_enable(i2c->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "Unable to enable clock\n");
> -		return ret;
> -	}
>   
>   	i2c->dev = &pdev->dev;
>   
> @@ -301,8 +296,7 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	if (i2c->bus_freq == 0) {
>   		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
> -		ret = -EINVAL;
> -		goto err_disable_clk;
> +		return -EINVAL;
>   	}
>   
>   	adap = &i2c->adap;
> @@ -320,23 +314,17 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	ret = i2c_add_adapter(adap);
>   	if (ret < 0)
> -		goto err_disable_clk;
> +		return ret;
>   
>   	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
>   
>   	return 0;
> -
> -err_disable_clk:
> -	clk_disable_unprepare(i2c->clk);
> -
> -	return ret;
>   }
>   
>   static void mtk_i2c_remove(struct platform_device *pdev)
>   {
>   	struct mtk_i2c *i2c = platform_get_drvdata(pdev);
>   
> -	clk_disable_unprepare(i2c->clk);
>   	i2c_del_adapter(&i2c->adap);
>   }
>
Stefan Roese June 12, 2023, 8:43 a.m. UTC | #2
On 6/12/23 00:56, Andi Shyti wrote:
> Replace the pair of functions, devm_clk_get() and
> clk_prepare_enable(), with a single function
> devm_clk_get_enabled().
> 
> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> Cc: Stefan Roese <sr@denx.de>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   drivers/i2c/busses/i2c-mt7621.c | 20 ++++----------------
>   1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index f9c294e2bd3c5..104bb194e9906 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -282,16 +282,11 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   	if (IS_ERR(i2c->base))
>   		return PTR_ERR(i2c->base);
>   
> -	i2c->clk = devm_clk_get(&pdev->dev, NULL);
> +	i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>   	if (IS_ERR(i2c->clk)) {
> -		dev_err(&pdev->dev, "no clock defined\n");
> +		dev_err(&pdev->dev, "Failed to enable clock\n");
>   		return PTR_ERR(i2c->clk);
>   	}
> -	ret = clk_prepare_enable(i2c->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "Unable to enable clock\n");
> -		return ret;
> -	}
>   
>   	i2c->dev = &pdev->dev;
>   
> @@ -301,8 +296,7 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	if (i2c->bus_freq == 0) {
>   		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
> -		ret = -EINVAL;
> -		goto err_disable_clk;
> +		return -EINVAL;
>   	}
>   
>   	adap = &i2c->adap;
> @@ -320,23 +314,17 @@ static int mtk_i2c_probe(struct platform_device *pdev)
>   
>   	ret = i2c_add_adapter(adap);
>   	if (ret < 0)
> -		goto err_disable_clk;
> +		return ret;
>   
>   	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
>   
>   	return 0;
> -
> -err_disable_clk:
> -	clk_disable_unprepare(i2c->clk);
> -
> -	return ret;
>   }
>   
>   static void mtk_i2c_remove(struct platform_device *pdev)
>   {
>   	struct mtk_i2c *i2c = platform_get_drvdata(pdev);
>   
> -	clk_disable_unprepare(i2c->clk);
>   	i2c_del_adapter(&i2c->adap);
>   }
>   

Viele Grüße,
Stefan Roese
Wolfram Sang June 23, 2023, 9:55 a.m. UTC | #3
On Mon, Jun 12, 2023 at 12:56:55AM +0200, Andi Shyti wrote:
> Replace the pair of functions, devm_clk_get() and
> clk_prepare_enable(), with a single function
> devm_clk_get_enabled().
> 
> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
> Cc: Stefan Roese <sr@denx.de>
> Cc: Matthias Brugger <matthias.bgg@gmail.com>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index f9c294e2bd3c5..104bb194e9906 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -282,16 +282,11 @@  static int mtk_i2c_probe(struct platform_device *pdev)
 	if (IS_ERR(i2c->base))
 		return PTR_ERR(i2c->base);
 
-	i2c->clk = devm_clk_get(&pdev->dev, NULL);
+	i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(i2c->clk)) {
-		dev_err(&pdev->dev, "no clock defined\n");
+		dev_err(&pdev->dev, "Failed to enable clock\n");
 		return PTR_ERR(i2c->clk);
 	}
-	ret = clk_prepare_enable(i2c->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable clock\n");
-		return ret;
-	}
 
 	i2c->dev = &pdev->dev;
 
@@ -301,8 +296,7 @@  static int mtk_i2c_probe(struct platform_device *pdev)
 
 	if (i2c->bus_freq == 0) {
 		dev_warn(i2c->dev, "clock-frequency 0 not supported\n");
-		ret = -EINVAL;
-		goto err_disable_clk;
+		return -EINVAL;
 	}
 
 	adap = &i2c->adap;
@@ -320,23 +314,17 @@  static int mtk_i2c_probe(struct platform_device *pdev)
 
 	ret = i2c_add_adapter(adap);
 	if (ret < 0)
-		goto err_disable_clk;
+		return ret;
 
 	dev_info(&pdev->dev, "clock %u kHz\n", i2c->bus_freq / 1000);
 
 	return 0;
-
-err_disable_clk:
-	clk_disable_unprepare(i2c->clk);
-
-	return ret;
 }
 
 static void mtk_i2c_remove(struct platform_device *pdev)
 {
 	struct mtk_i2c *i2c = platform_get_drvdata(pdev);
 
-	clk_disable_unprepare(i2c->clk);
 	i2c_del_adapter(&i2c->adap);
 }