linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 5/6] i2c: imx: Simplify using devm_clk_get_enableded()
       [not found] <20210330181755.204339-1-u.kleine-koenig@pengutronix.de>
@ 2021-03-30 18:17 ` Uwe Kleine-König
  2021-04-06  6:43   ` Uwe Kleine-König
  2021-04-06  6:46   ` [PATCH v4.1 " Uwe Kleine-König
  0 siblings, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2021-03-30 18:17 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Oleksij Rempel, Shawn Guo, Sascha Hauer
  Cc: linux-clk, kernel, Fabio Estevam, NXP Linux Team, linux-i2c,
	linux-arm-kernel

devm_clk_get_enabled() returns the clk already (prepared and) enabled
and the automatically called cleanup cares for disabling (and
unpreparing). So simplify .probe() and .remove() accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index b80fdc1f0092..aa156ecc616d 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1405,16 +1405,10 @@ static int i2c_imx_probe(struct platform_device *pdev)
 	ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev));
 
 	/* Get I2C clock */
-	i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
+	i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(i2c_imx->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk),
-				     "can't get I2C clock\n");
-
-	ret = clk_prepare_enable(i2c_imx->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "can't enable I2C clock, ret=%d\n", ret);
-		return ret;
-	}
+				     "can't get prepared I2C clock\n");
 
 	/* Init queue */
 	init_waitqueue_head(&i2c_imx->queue);
@@ -1517,7 +1511,6 @@ static int i2c_imx_remove(struct platform_device *pdev)
 	irq = platform_get_irq(pdev, 0);
 	if (irq >= 0)
 		free_irq(irq, i2c_imx);
-	clk_disable_unprepare(i2c_imx->clk);
 
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 5/6] i2c: imx: Simplify using devm_clk_get_enableded()
  2021-03-30 18:17 ` [PATCH v4 5/6] i2c: imx: Simplify using devm_clk_get_enableded() Uwe Kleine-König
@ 2021-04-06  6:43   ` Uwe Kleine-König
  2021-04-06  6:46   ` [PATCH v4.1 " Uwe Kleine-König
  1 sibling, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2021-04-06  6:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Oleksij Rempel, Shawn Guo, Sascha Hauer
  Cc: linux-i2c, kernel, Fabio Estevam, linux-clk, linux-arm-kernel,
	NXP Linux Team

[-- Attachment #1: Type: text/plain, Size: 2220 bytes --]

On Tue, Mar 30, 2021 at 08:17:54PM +0200, Uwe Kleine-König wrote:
> devm_clk_get_enabled() returns the clk already (prepared and) enabled
> and the automatically called cleanup cares for disabling (and
> unpreparing). So simplify .probe() and .remove() accordingly.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/i2c/busses/i2c-imx.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index b80fdc1f0092..aa156ecc616d 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1405,16 +1405,10 @@ static int i2c_imx_probe(struct platform_device *pdev)
>  	ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev));
>  
>  	/* Get I2C clock */
> -	i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
> +	i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(i2c_imx->clk))
>  		return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk),
> -				     "can't get I2C clock\n");
> -
> -	ret = clk_prepare_enable(i2c_imx->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "can't enable I2C clock, ret=%d\n", ret);
> -		return ret;
> -	}
> +				     "can't get prepared I2C clock\n");
>  
>  	/* Init queue */
>  	init_waitqueue_head(&i2c_imx->queue);
> @@ -1517,7 +1511,6 @@ static int i2c_imx_remove(struct platform_device *pdev)
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq >= 0)
>  		free_irq(irq, i2c_imx);
> -	clk_disable_unprepare(i2c_imx->clk);
>  
>  	pm_runtime_put_noidle(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);

Note this patch is wrong again, the following hunk is missing:

@@ -1481,7 +1481,6 @@ static int i2c_imx_probe(struct platform_device *pdev)
        pm_runtime_disable(&pdev->dev);
        pm_runtime_set_suspended(&pdev->dev);
        pm_runtime_dont_use_autosuspend(&pdev->dev);
-       clk_disable_unprepare(i2c_imx->clk);
        return ret;
 }

Will resend a fixed patch.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4.1 5/6] i2c: imx: Simplify using devm_clk_get_enableded()
  2021-03-30 18:17 ` [PATCH v4 5/6] i2c: imx: Simplify using devm_clk_get_enableded() Uwe Kleine-König
  2021-04-06  6:43   ` Uwe Kleine-König
@ 2021-04-06  6:46   ` Uwe Kleine-König
  2021-04-06  7:12     ` Oleksij Rempel
  2021-04-06 20:29     ` Wolfram Sang
  1 sibling, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2021-04-06  6:46 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Oleksij Rempel, Shawn Guo, Sascha Hauer
  Cc: linux-i2c, kernel, Fabio Estevam, linux-clk, linux-arm-kernel,
	NXP Linux Team, Uwe Kleine-König

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

devm_clk_get_enabled() returns the clk already (prepared and) enabled
and the automatically called cleanup cares for disabling (and
unpreparing). So simplify .probe() and .remove() accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index b80fdc1f0092..d6594358cf83 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1405,16 +1405,10 @@ static int i2c_imx_probe(struct platform_device *pdev)
 	ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev));
 
 	/* Get I2C clock */
-	i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
+	i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(i2c_imx->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk),
-				     "can't get I2C clock\n");
-
-	ret = clk_prepare_enable(i2c_imx->clk);
-	if (ret) {
-		dev_err(&pdev->dev, "can't enable I2C clock, ret=%d\n", ret);
-		return ret;
-	}
+				     "can't get prepared I2C clock\n");
 
 	/* Init queue */
 	init_waitqueue_head(&i2c_imx->queue);
@@ -1487,7 +1481,6 @@ static int i2c_imx_probe(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
-	clk_disable_unprepare(i2c_imx->clk);
 	return ret;
 }
 
@@ -1517,7 +1510,6 @@ static int i2c_imx_remove(struct platform_device *pdev)
 	irq = platform_get_irq(pdev, 0);
 	if (irq >= 0)
 		free_irq(irq, i2c_imx);
-	clk_disable_unprepare(i2c_imx->clk);
 
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4.1 5/6] i2c: imx: Simplify using devm_clk_get_enableded()
  2021-04-06  6:46   ` [PATCH v4.1 " Uwe Kleine-König
@ 2021-04-06  7:12     ` Oleksij Rempel
  2021-04-06 20:29     ` Wolfram Sang
  1 sibling, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2021-04-06  7:12 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Michael Turquette, Stephen Boyd, Oleksij Rempel, Shawn Guo,
	Sascha Hauer, NXP Linux Team, kernel, Uwe Kleine-König,
	Fabio Estevam, linux-clk, linux-arm-kernel, linux-i2c

On Tue, Apr 06, 2021 at 08:46:18AM +0200, Uwe Kleine-König wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> devm_clk_get_enabled() returns the clk already (prepared and) enabled
> and the automatically called cleanup cares for disabling (and
> unpreparing). So simplify .probe() and .remove() accordingly.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Enthusiastically Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

I hope devm_clk_get_enabled() will go mainline, it reduces dramatically
code and makes my life a lot better ;)

> ---
>  drivers/i2c/busses/i2c-imx.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index b80fdc1f0092..d6594358cf83 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1405,16 +1405,10 @@ static int i2c_imx_probe(struct platform_device *pdev)
>  	ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev));
>  
>  	/* Get I2C clock */
> -	i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
> +	i2c_imx->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(i2c_imx->clk))
>  		return dev_err_probe(&pdev->dev, PTR_ERR(i2c_imx->clk),
> -				     "can't get I2C clock\n");
> -
> -	ret = clk_prepare_enable(i2c_imx->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "can't enable I2C clock, ret=%d\n", ret);
> -		return ret;
> -	}
> +				     "can't get prepared I2C clock\n");
>  
>  	/* Init queue */
>  	init_waitqueue_head(&i2c_imx->queue);
> @@ -1487,7 +1481,6 @@ static int i2c_imx_probe(struct platform_device *pdev)
>  	pm_runtime_disable(&pdev->dev);
>  	pm_runtime_set_suspended(&pdev->dev);
>  	pm_runtime_dont_use_autosuspend(&pdev->dev);
> -	clk_disable_unprepare(i2c_imx->clk);
>  	return ret;
>  }
>  
> @@ -1517,7 +1510,6 @@ static int i2c_imx_remove(struct platform_device *pdev)
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq >= 0)
>  		free_irq(irq, i2c_imx);
> -	clk_disable_unprepare(i2c_imx->clk);
>  
>  	pm_runtime_put_noidle(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4.1 5/6] i2c: imx: Simplify using devm_clk_get_enableded()
  2021-04-06  6:46   ` [PATCH v4.1 " Uwe Kleine-König
  2021-04-06  7:12     ` Oleksij Rempel
@ 2021-04-06 20:29     ` Wolfram Sang
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2021-04-06 20:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Michael Turquette, Stephen Boyd, Oleksij Rempel, Shawn Guo,
	Sascha Hauer, linux-i2c, kernel, Fabio Estevam, linux-clk,
	linux-arm-kernel, NXP Linux Team, Uwe Kleine-König

[-- Attachment #1: Type: text/plain, Size: 523 bytes --]

On Tue, Apr 06, 2021 at 08:46:18AM +0200, Uwe Kleine-König wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> devm_clk_get_enabled() returns the clk already (prepared and) enabled
> and the automatically called cleanup cares for disabling (and
> unpreparing). So simplify .probe() and .remove() accordingly.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

So, this will go in with the rest of this series?

In that case:

Acked-by: Wolfram Sang <wsa@kernel.org>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-06 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210330181755.204339-1-u.kleine-koenig@pengutronix.de>
2021-03-30 18:17 ` [PATCH v4 5/6] i2c: imx: Simplify using devm_clk_get_enableded() Uwe Kleine-König
2021-04-06  6:43   ` Uwe Kleine-König
2021-04-06  6:46   ` [PATCH v4.1 " Uwe Kleine-König
2021-04-06  7:12     ` Oleksij Rempel
2021-04-06 20:29     ` Wolfram Sang

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).