linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chunyan Zhang <zhang.lyra@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang7@gmail.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Chunyan Zhang <chunyan.zhang@unisoc.com>,
	Bangzheng Liu <bangzheng.liu@unisoc.com>
Subject: [PATCH] spi: sprd: add runtime pm for transfer message
Date: Fri, 30 Oct 2020 15:24:44 +0800	[thread overview]
Message-ID: <20201030072444.22122-1-zhang.lyra@gmail.com> (raw)

From: Bangzheng Liu <bangzheng.liu@unisoc.com>

Before transfer one message, spi core would set chipselect, sprd spi
device should be resumed from runtime suspend, otherwise kernel would
crash once access spi registers. The sprd spi device can be suspended
until clearing chipselect which would be executed after transfer.

Fixes: e7d973a31c24 ("spi: sprd: Add SPI driver for Spreadtrum SC9860")
Signed-off-by: Bangzheng Liu <bangzheng.liu@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
 drivers/spi/spi-sprd.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c
index 635738f54c73..1733d10eb296 100644
--- a/drivers/spi/spi-sprd.c
+++ b/drivers/spi/spi-sprd.c
@@ -293,15 +293,25 @@ static void sprd_spi_chipselect(struct spi_device *sdev, bool cs)
 	struct spi_controller *sctlr = sdev->controller;
 	struct sprd_spi *ss = spi_controller_get_devdata(sctlr);
 	u32 val;
+	int ret;
 
-	val = readl_relaxed(ss->base + SPRD_SPI_CTL0);
 	/*  The SPI controller will pull down CS pin if cs is 0 */
 	if (!cs) {
-		val &= ~SPRD_SPI_CS0_VALID;
+		ret = pm_runtime_get_sync(ss->dev);
+		if (ret < 0) {
+			pm_runtime_put_noidle(ss->dev);
+			dev_err(ss->dev, "Failed to power device: %d\n", ret);
+			return;
+		}
+		val = readl_relaxed(ss->base + SPRD_SPI_CTL0);
+		val &= ~SPRD_SPI_CS0_VALID; /* set cs0 valid */
 		writel_relaxed(val, ss->base + SPRD_SPI_CTL0);
 	} else {
-		val |= SPRD_SPI_CSN_MASK;
+		val = readl_relaxed(ss->base + SPRD_SPI_CTL0);
+		val |= SPRD_SPI_CSN_MASK; /* set all cs invalid */
 		writel_relaxed(val, ss->base + SPRD_SPI_CTL0);
+		pm_runtime_mark_last_busy(ss->dev);
+		pm_runtime_put_autosuspend(ss->dev);
 	}
 }
 
-- 
2.20.1


             reply	other threads:[~2020-10-30  7:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30  7:24 Chunyan Zhang [this message]
2020-10-30 13:42 ` [PATCH] spi: sprd: add runtime pm for transfer message Mark Brown
2020-11-02  3:17   ` Chunyan Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201030072444.22122-1-zhang.lyra@gmail.com \
    --to=zhang.lyra@gmail.com \
    --cc=bangzheng.liu@unisoc.com \
    --cc=baolin.wang7@gmail.com \
    --cc=broonie@kernel.org \
    --cc=chunyan.zhang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).