diff mbox series

[v4,5/6] i2c: imx: Simplify using devm_clk_get_enableded()

Message ID 20210330181755.204339-6-u.kleine-koenig@pengutronix.de
State New
Headers show
Series None | expand

Commit Message

Uwe Kleine-König March 30, 2021, 6:17 p.m. UTC
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(-)

Comments

Uwe Kleine-König April 6, 2021, 6:43 a.m. UTC | #1
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/ |
Oleksij Rempel April 6, 2021, 7:12 a.m. UTC | #2
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 |
Wolfram Sang April 6, 2021, 8:29 p.m. UTC | #3
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>
diff mbox series

Patch

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