diff mbox series

[7/8] tty: st-asc: Use devm_clk_get_enabled() helpers

Message ID 20240822033924.32397-8-liulei.rjpt@vivo.com (mailing list archive)
State New, archived
Headers show
Series tty serial drivers use devm_clk_get_enabled() helpers | expand

Commit Message

Lei Liu Aug. 22, 2024, 3:39 a.m. UTC
The devm_clk_get_enabled() helpers:
    - call devm_clk_get()
    - call clk_prepare_enable() and register what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids calls to clk_disable_unprepare().

Signed-off-by: Lei Liu <liulei.rjpt@vivo.com>
---
 drivers/tty/serial/st-asc.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko Aug. 22, 2024, 1:21 p.m. UTC | #1
On Thu, Aug 22, 2024 at 11:39:11AM +0800, Lei Liu wrote:
> The devm_clk_get_enabled() helpers:
>     - call devm_clk_get()
>     - call clk_prepare_enable() and register what is needed in order to
>      call clk_disable_unprepare() when needed, as a managed resource.
> 
> This simplifies the code and avoids calls to clk_disable_unprepare().

...

Same caveat as in another patch comment.

> -	ascport->clk = devm_clk_get(&pdev->dev, NULL);
> +	ascport->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  
>  	if (WARN_ON(IS_ERR(ascport->clk)))
>  		return -EINVAL;
> -	/* ensure that clk rate is correct by enabling the clk */
> -	ret = clk_prepare_enable(ascport->clk);
> -	if (ret)
> -		return ret;
> +
>  	ascport->port.uartclk = clk_get_rate(ascport->clk);

>  	WARN_ON(ascport->port.uartclk == 0);

Btw, not related to this series, you may try to get rid of these 0 checks as
the serial core has this and it will fail anyway. Perhaps you want to expand
serial core to issue an error message (if it's not done yet).

> -	clk_disable_unprepare(ascport->clk);
diff mbox series

Patch

diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c
index f91753a40a69..df666766d50e 100644
--- a/drivers/tty/serial/st-asc.c
+++ b/drivers/tty/serial/st-asc.c
@@ -706,17 +706,13 @@  static int asc_init_port(struct asc_port *ascport,
 
 	spin_lock_init(&port->lock);
 
-	ascport->clk = devm_clk_get(&pdev->dev, NULL);
+	ascport->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 
 	if (WARN_ON(IS_ERR(ascport->clk)))
 		return -EINVAL;
-	/* ensure that clk rate is correct by enabling the clk */
-	ret = clk_prepare_enable(ascport->clk);
-	if (ret)
-		return ret;
+
 	ascport->port.uartclk = clk_get_rate(ascport->clk);
 	WARN_ON(ascport->port.uartclk == 0);
-	clk_disable_unprepare(ascport->clk);
 
 	ascport->pinctrl = devm_pinctrl_get(&pdev->dev);
 	if (IS_ERR(ascport->pinctrl)) {