Message ID | 20240822033924.32397-2-liulei.rjpt@vivo.com |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | tty serial drivers use devm_clk_get_enabled() helpers | expand |
Hi Lei Liu, Le jeudi 22 août 2024 à 11:39 +0800, Lei Liu a écrit : > 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/8250/8250_ingenic.c | 26 +++--------------------- > -- > 1 file changed, 3 insertions(+), 23 deletions(-) > > diff --git a/drivers/tty/serial/8250/8250_ingenic.c > b/drivers/tty/serial/8250/8250_ingenic.c > index a2783e38a2e3..5f8787309064 100644 > --- a/drivers/tty/serial/8250/8250_ingenic.c > +++ b/drivers/tty/serial/8250/8250_ingenic.c > @@ -274,44 +274,26 @@ static int ingenic_uart_probe(struct > platform_device *pdev) > if (!uart.port.membase) > return -ENOMEM; > > - data->clk_module = devm_clk_get(&pdev->dev, "module"); > + data->clk_module = devm_clk_get_enabled(&pdev->dev, > "module"); > if (IS_ERR(data->clk_module)) > return dev_err_probe(&pdev->dev, PTR_ERR(data- > >clk_module), > "unable to get module > clock\n"); > > - data->clk_baud = devm_clk_get(&pdev->dev, "baud"); > + data->clk_baud = devm_clk_get_enabled(&pdev->dev, "baud"); > if (IS_ERR(data->clk_baud)) > return dev_err_probe(&pdev->dev, PTR_ERR(data- > >clk_baud), > "unable to get baud clock\n"); > > - err = clk_prepare_enable(data->clk_module); > - if (err) { > - dev_err(&pdev->dev, "could not enable module clock: > %d\n", err); > - goto out; > - } > - > - err = clk_prepare_enable(data->clk_baud); > - if (err) { > - dev_err(&pdev->dev, "could not enable baud clock: > %d\n", err); > - goto out_disable_moduleclk; > - } > uart.port.uartclk = clk_get_rate(data->clk_baud); > > data->line = serial8250_register_8250_port(&uart); > if (data->line < 0) { > err = data->line; > - goto out_disable_baudclk; > + return err; Not really worth a V2, but if you make a V2, please "return data- >line;" directly. Acked-by: Paul Cercueil <paul@crapouillou.net> Cheers, -Paul > } > > platform_set_drvdata(pdev, data); > return 0; > - > -out_disable_baudclk: > - clk_disable_unprepare(data->clk_baud); > -out_disable_moduleclk: > - clk_disable_unprepare(data->clk_module); > -out: > - return err; > } > > static void ingenic_uart_remove(struct platform_device *pdev) > @@ -319,8 +301,6 @@ static void ingenic_uart_remove(struct > platform_device *pdev) > struct ingenic_uart_data *data = platform_get_drvdata(pdev); > > serial8250_unregister_port(data->line); > - clk_disable_unprepare(data->clk_module); > - clk_disable_unprepare(data->clk_baud); > } > > static const struct ingenic_uart_config jz4740_uart_config = {
On Thu, Aug 22, 2024 at 11:39:05AM +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(). ... > data->line = serial8250_register_8250_port(&uart); > if (data->line < 0) { > err = data->line; > - goto out_disable_baudclk; > + return err; > } data->line = serial8250_register_8250_port(&uart); if (data->line < 0) return data->line;
On Thu, Aug 22, 2024 at 11:40:46AM +0200, Paul Cercueil wrote: > Le jeudi 22 août 2024 à 11:39 +0800, Lei Liu a écrit : ... > Not really worth a V2, but if you make a V2, please "return data- > >line;" directly. > Acked-by: Paul Cercueil <paul@crapouillou.net> Despite of this, the series has other small issues that needs to be addressed, so I would wait for v2.
diff --git a/drivers/tty/serial/8250/8250_ingenic.c b/drivers/tty/serial/8250/8250_ingenic.c index a2783e38a2e3..5f8787309064 100644 --- a/drivers/tty/serial/8250/8250_ingenic.c +++ b/drivers/tty/serial/8250/8250_ingenic.c @@ -274,44 +274,26 @@ static int ingenic_uart_probe(struct platform_device *pdev) if (!uart.port.membase) return -ENOMEM; - data->clk_module = devm_clk_get(&pdev->dev, "module"); + data->clk_module = devm_clk_get_enabled(&pdev->dev, "module"); if (IS_ERR(data->clk_module)) return dev_err_probe(&pdev->dev, PTR_ERR(data->clk_module), "unable to get module clock\n"); - data->clk_baud = devm_clk_get(&pdev->dev, "baud"); + data->clk_baud = devm_clk_get_enabled(&pdev->dev, "baud"); if (IS_ERR(data->clk_baud)) return dev_err_probe(&pdev->dev, PTR_ERR(data->clk_baud), "unable to get baud clock\n"); - err = clk_prepare_enable(data->clk_module); - if (err) { - dev_err(&pdev->dev, "could not enable module clock: %d\n", err); - goto out; - } - - err = clk_prepare_enable(data->clk_baud); - if (err) { - dev_err(&pdev->dev, "could not enable baud clock: %d\n", err); - goto out_disable_moduleclk; - } uart.port.uartclk = clk_get_rate(data->clk_baud); data->line = serial8250_register_8250_port(&uart); if (data->line < 0) { err = data->line; - goto out_disable_baudclk; + return err; } platform_set_drvdata(pdev, data); return 0; - -out_disable_baudclk: - clk_disable_unprepare(data->clk_baud); -out_disable_moduleclk: - clk_disable_unprepare(data->clk_module); -out: - return err; } static void ingenic_uart_remove(struct platform_device *pdev) @@ -319,8 +301,6 @@ static void ingenic_uart_remove(struct platform_device *pdev) struct ingenic_uart_data *data = platform_get_drvdata(pdev); serial8250_unregister_port(data->line); - clk_disable_unprepare(data->clk_module); - clk_disable_unprepare(data->clk_baud); } static const struct ingenic_uart_config jz4740_uart_config = {
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/8250/8250_ingenic.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-)