lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201030072444.22122-1-zhang.lyra@gmail.com>
Date:   Fri, 30 Oct 2020 15:24:44 +0800
From:   Chunyan Zhang <zhang.lyra@...il.com>
To:     Mark Brown <broonie@...nel.org>
Cc:     linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org,
        Orson Zhai <orsonzhai@...il.com>,
        Baolin Wang <baolin.wang7@...il.com>,
        Chunyan Zhang <zhang.lyra@...il.com>,
        Chunyan Zhang <chunyan.zhang@...soc.com>,
        Bangzheng Liu <bangzheng.liu@...soc.com>
Subject: [PATCH] spi: sprd: add runtime pm for transfer message

From: Bangzheng Liu <bangzheng.liu@...soc.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@...soc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@...soc.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ