[PATCH v5 01/17] spi: axiado: Simplify clock management with devm_clk_get_enabled()
Pei Xiao <[email protected]>
| Newsgroups | org.ozlabs.lists.openbmc,dev.linux.lists.imx,org.infradead.lists.linux-arm-kernel,org.infradead.lists.linux-mediatek,org.infradead.lists.linux-riscv,org.infradead.lists.linux-rockchip,org.kernel.vger.linux-kernel,org.kernel.vger.linux-spi |
|---|---|
| Message-ID | <52f7e0ebd2f0ece71929384444e1ae87506e5e2d.1773885292.git.xiaopei01@kylinos.cn> |
Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for both the "pclk" and "ref" clocks. This reduces boilerplate code and error handling, as the managed API automatically disables the clocks when the device is removed or if probe fails. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error paths and the remove callback. Rename the error label from 'clk_dis_all' to 'err_disable_pm_runtime' to reflect that only PM runtime cleanup remains. Signed-off-by: Pei Xiao <[email protected]> --- drivers/spi/spi-axiado.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/drivers/spi/spi-axiado.c b/drivers/spi/spi-axiado.c index dc55c55ae63c..d7918ea7c586 100644 --- a/drivers/spi/spi-axiado.c +++ b/drivers/spi/spi-axiado.c @@ -768,25 +768,15 @@ static int ax_spi_probe(struct platform_device *pdev) if (IS_ERR(xspi->regs)) return PTR_ERR(xspi->regs); - xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); + xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk"); if (IS_ERR(xspi->pclk)) return dev_err_probe(&pdev->dev, PTR_ERR(xspi->pclk), - "pclk clock not found.\n"); + "Unable to enable APB clock.\n"); - xspi->ref_clk = devm_clk_get(&pdev->dev, "ref"); + xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref"); if (IS_ERR(xspi->ref_clk)) return dev_err_probe(&pdev->dev, PTR_ERR(xspi->ref_clk), - "ref clock not found.\n"); - - ret = clk_prepare_enable(xspi->pclk); - if (ret) - return dev_err_probe(&pdev->dev, ret, "Unable to enable APB clock.\n"); - - ret = clk_prepare_enable(xspi->ref_clk); - if (ret) { - dev_err(&pdev->dev, "Unable to enable device clock.\n"); - goto clk_dis_apb; - } + "Unable to enable device clock.\n"); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); @@ -815,7 +805,7 @@ static int ax_spi_probe(struct platform_device *pdev) irq = platform_get_irq(pdev, 0); if (irq <= 0) { ret = -ENXIO; - goto clk_dis_all; + goto err_disable_pm_runtime; } ret = devm_request_irq(&pdev->dev, irq, ax_spi_irq, @@ -823,7 +813,7 @@ static int ax_spi_probe(struct platform_device *pdev) if (ret != 0) { ret = -ENXIO; dev_err(&pdev->dev, "request_irq failed\n"); - goto clk_dis_all; + goto err_disable_pm_runtime; } ctlr->use_gpio_descriptors = true; @@ -849,17 +839,14 @@ static int ax_spi_probe(struct platform_device *pdev) ret = spi_register_controller(ctlr); if (ret) { dev_err(&pdev->dev, "spi_register_controller failed\n"); - goto clk_dis_all; + goto err_disable_pm_runtime; } return ret; -clk_dis_all: +err_disable_pm_runtime: pm_runtime_set_suspended(&pdev->dev); pm_runtime_disable(&pdev->dev); - clk_disable_unprepare(xspi->ref_clk); -clk_dis_apb: - clk_disable_unprepare(xspi->pclk); return ret; } @@ -875,15 +862,12 @@ static int ax_spi_probe(struct platform_device *pdev) static void ax_spi_remove(struct platform_device *pdev) { struct spi_controller *ctlr = platform_get_drvdata(pdev); - struct ax_spi *xspi = spi_controller_get_devdata(ctlr); spi_unregister_controller(ctlr); pm_runtime_set_suspended(&pdev->dev); pm_runtime_disable(&pdev->dev); - clk_disable_unprepare(xspi->ref_clk); - clk_disable_unprepare(xspi->pclk); } /** -- 2.25.1