From d09499e9c8a99763bf9afa92c06601070523dc3e Mon Sep 17 00:00:00 2001 From: Anil Veshala Veshala Date: Wed, 16 Feb 2022 22:06:53 -0800 Subject: [PATCH] spi: spi-msm-geni: Put device to suspend if PM status is active This change is to keep the device to autosuspend only if runtime PM status is not suspended. SPI driver resumes only if runtime PM is active, if framework calls unprepare_message/unprepare_hardware and if we try to keep driver to autosuspend, it may result into negative usage count. Also ensure for the PM calls, runtime is always enabled and if not, do not call PM. Change-Id: I701cbfbefb3a05ecbb99bf490e2b41b73fbaa897 Signed-off-by: Anil Veshala Veshala --- drivers/spi/spi-geni-qcom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c index 15bb3f735701..6b2fcc8ce50f 100644 --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -844,7 +844,8 @@ static int spi_geni_unprepare_message(struct spi_master *spi_mas, GENI_SE_ERR(mas->ipc, false, NULL, "suspend usage count mismatch:%d", count); - } else { + } else if (!pm_runtime_status_suspended(mas->dev) && + pm_runtime_enabled(mas->dev)) { pm_runtime_mark_last_busy(mas->dev); pm_runtime_put_autosuspend(mas->dev); } @@ -1099,7 +1100,8 @@ static int spi_geni_unprepare_transfer_hardware(struct spi_master *spi) if (count < 0) GENI_SE_ERR(mas->ipc, false, NULL, "suspend usage count mismatch:%d", count); - } else { + } else if (!pm_runtime_status_suspended(mas->dev) && + pm_runtime_enabled(mas->dev)) { pm_runtime_mark_last_busy(mas->dev); pm_runtime_put_autosuspend(mas->dev); }