[PATCH v4 01/17] spi: axiado: Simplify clock management with devm_clk_get_enabled()
From: Pei Xiao <hidden>
Date: 2026-03-18 02:40:21
Also in:
imx, linux-mediatek, linux-riscv, linux-rockchip, linux-spi, lkml, openbmc
Subsystem:
axiado spi db driver, spi subsystem, the rest · Maintainers:
Vladimir Moravcevic, Tzu-Hao Wei, Swark Yang, Prasad Bolisetty, Mark Brown, Linus Torvalds
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 <redacted> --- drivers/spi/spi-axiado.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/drivers/spi/spi-axiado.c b/drivers/spi/spi-axiado.c
index dc55c55ae63c..b2d1011357f4 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; }
@@ -882,8 +869,6 @@ static void ax_spi_remove(struct platform_device *pdev) 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