[PATCH v2 1/3] spi: nxp-fspi: use devm runtime PM enablement

Jiawen Liu <[email protected]>
Newsgroups dev.linux.lists.imx,org.kernel.vger.linux-kernel,org.kernel.vger.linux-spi
Message-ID <[email protected]>
nxp_fspi_probe() enables runtime PM and then gets the device active for
the initial register setup. If that get fails, the old open-coded
pm_runtime_get_sync() path needs manual cleanup of both the usage counter
and runtime PM enablement.

Follow the newer spi-nxp-xspi pattern instead: use
devm_pm_runtime_enable() for managed runtime PM disablement, and use
PM_RUNTIME_ACQUIRE_AUTOSUSPEND() for the initial active window. This keeps
the error path simple and avoids leaving runtime PM state behind when the
initial resume fails.

Signed-off-by: Jiawen Liu <[email protected]>
---
 drivers/spi/spi-nxp-fspi.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index 1e36ae084dd8..6be78712b534 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1275,7 +1275,6 @@ static void nxp_fspi_cleanup(void *data)
 	/* disable the hardware */
 	fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
 
-	pm_runtime_disable(f->dev);
 	pm_runtime_put_noidle(f->dev);
 	nxp_fspi_clk_disable_unprep(f);
 
@@ -1345,12 +1344,15 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return dev_err_probe(dev, irq, "Failed to get irq source");
 
-	pm_runtime_enable(dev);
 	pm_runtime_set_autosuspend_delay(dev, FSPI_RPM_TIMEOUT);
 	pm_runtime_use_autosuspend(dev);
+	ret = devm_pm_runtime_enable(dev);
+	if (ret)
+		return ret;
 
 	/* enable clock */
-	ret = pm_runtime_get_sync(f->dev);
+	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "Failed to enable clock");
 
@@ -1361,10 +1363,6 @@ static int nxp_fspi_probe(struct platform_device *pdev)
 
 	nxp_fspi_default_setup(f);
 
-	ret = pm_runtime_put_sync(dev);
-	if (ret < 0)
-		return dev_err_probe(dev, ret, "Failed to disable clock");
-
 	init_completion(&f->c);
 	ret = devm_request_irq(dev, irq,
 			nxp_fspi_irq_handler, 0, pdev->name, f);
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.