linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32
@ 2021-02-05 11:08 Alain Volmat
  2021-02-05 11:08 ` [PATCH 1/8] spi: stm32: properly handle 0 byte transfer Alain Volmat
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

The serie provides a fix for the spi-stm32 driver, allowing to properly
handle 0 byte transfer (and thus being able to run spi-loopback-test).

In addition to that, important enhancements are implemented, among them,
supporting transfer larger that what the IP can setup in one go or
allowing to use the SPI bus without cs_gpio.

Alain Volmat (5):
  spi: stm32: properly handle 0 byte transfer
  spi: stm32: do not mandate cs_gpio
  spi: stm32h7: ensure message are smaller than max size
  spi: stm32: defer probe for reset
  spi: stm32: make spurious and overrun interrupts visible

Amelie Delaunay (2):
  spi: stm32: use bitfield macros
  spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC

Etienne Carriere (1):
  spi: stm32: driver uses reset controller only at init

 drivers/spi/spi-stm32.c | 116 +++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 62 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/8] spi: stm32: properly handle 0 byte transfer
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
@ 2021-02-05 11:08 ` Alain Volmat
  2021-02-05 13:29   ` Mark Brown
  2021-02-05 11:08 ` [PATCH 2/8] spi: stm32: do not mandate cs_gpio Alain Volmat
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

On 0 byte transfer request, return straight from the
xfer function after finalizing the transfer.

Fixes: dcbe0d84dfa5 ("spi: add driver for STM32 SPI controller")
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index db3e305d9ec4..137213633e6d 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1657,6 +1657,12 @@ static int stm32_spi_transfer_one(struct spi_master *master,
 	struct stm32_spi *spi = spi_master_get_devdata(master);
 	int ret;
 
+	/* Don't do anything on 0 bytes transfers */
+	if (transfer->len == 0) {
+		spi_finalize_current_transfer(master);
+		return 0;
+	}
+
 	spi->tx_buf = transfer->tx_buf;
 	spi->rx_buf = transfer->rx_buf;
 	spi->tx_len = spi->tx_buf ? transfer->len : 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/8] spi: stm32: do not mandate cs_gpio
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
  2021-02-05 11:08 ` [PATCH 1/8] spi: stm32: properly handle 0 byte transfer Alain Volmat
@ 2021-02-05 11:08 ` Alain Volmat
  2021-02-05 11:08 ` [PATCH 3/8] spi: stm32h7: ensure message are smaller than max size Alain Volmat
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

CS gpios is not mandatory, the driver should allow working
even when CS are not given.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 137213633e6d..8c6af3aa0dc3 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1946,12 +1946,6 @@ static int stm32_spi_probe(struct platform_device *pdev)
 		goto err_pm_disable;
 	}
 
-	if (!master->cs_gpiods) {
-		dev_err(&pdev->dev, "no CS gpios available\n");
-		ret = -EINVAL;
-		goto err_pm_disable;
-	}
-
 	dev_info(&pdev->dev, "driver initialized\n");
 
 	return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/8] spi: stm32h7: ensure message are smaller than max size
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
  2021-02-05 11:08 ` [PATCH 1/8] spi: stm32: properly handle 0 byte transfer Alain Volmat
  2021-02-05 11:08 ` [PATCH 2/8] spi: stm32: do not mandate cs_gpio Alain Volmat
@ 2021-02-05 11:08 ` Alain Volmat
  2021-02-05 11:08 ` [PATCH 4/8] spi: stm32: driver uses reset controller only at init Alain Volmat
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

Ensure that messages given to transfer_one handler can actually be
handled by it. For that purpose rely on the SPI framework
spi_split_transfers_maxsize function to split messages whenever necessary.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 8c6af3aa0dc3..417a2aa2b98d 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1013,6 +1013,20 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
 		!!(spi_dev->mode & SPI_LSB_FIRST),
 		!!(spi_dev->mode & SPI_CS_HIGH));
 
+	/* On STM32H7, messages should not exceed a maximum size setted
+	 * afterward via the set_number_of_data function. In order to
+	 * ensure that, split large messages into several messages
+	 */
+	if (spi->cfg->set_number_of_data) {
+		int ret;
+
+		ret = spi_split_transfers_maxsize(master, msg,
+						  STM32H7_SPI_TSIZE_MAX,
+						  GFP_KERNEL | GFP_DMA);
+		if (ret)
+			return ret;
+	}
+
 	spin_lock_irqsave(&spi->lock, flags);
 
 	/* CPOL, CPHA and LSB FIRST bits have common register */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/8] spi: stm32: driver uses reset controller only at init
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (2 preceding siblings ...)
  2021-02-05 11:08 ` [PATCH 3/8] spi: stm32h7: ensure message are smaller than max size Alain Volmat
@ 2021-02-05 11:08 ` Alain Volmat
  2021-02-05 11:08 ` [PATCH 5/8] spi: stm32: defer probe for reset Alain Volmat
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

From: Etienne Carriere <etienne.carriere@st.com>

Remove reset controller device reference from the device private
structure since it is used only at probe time and can be discarded
once used to reset the SPI device.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 417a2aa2b98d..22bd3d1c8d69 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -268,7 +268,6 @@ struct stm32_spi_cfg {
  * @base: virtual memory area
  * @clk: hw kernel clock feeding the SPI clock generator
  * @clk_rate: rate of the hw kernel clock feeding the SPI clock generator
- * @rst: SPI controller reset line
  * @lock: prevent I/O concurrent access
  * @irq: SPI controller interrupt line
  * @fifo_size: size of the embedded fifo in bytes
@@ -294,7 +293,6 @@ struct stm32_spi {
 	void __iomem *base;
 	struct clk *clk;
 	u32 clk_rate;
-	struct reset_control *rst;
 	spinlock_t lock; /* prevent I/O concurrent access */
 	int irq;
 	unsigned int fifo_size;
@@ -1831,6 +1829,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
 	struct spi_master *master;
 	struct stm32_spi *spi;
 	struct resource *res;
+	struct reset_control *rst;
 	int ret;
 
 	master = spi_alloc_master(&pdev->dev, sizeof(struct stm32_spi));
@@ -1892,11 +1891,11 @@ static int stm32_spi_probe(struct platform_device *pdev)
 		goto err_clk_disable;
 	}
 
-	spi->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-	if (!IS_ERR(spi->rst)) {
-		reset_control_assert(spi->rst);
+	rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (!IS_ERR(rst)) {
+		reset_control_assert(rst);
 		udelay(2);
-		reset_control_deassert(spi->rst);
+		reset_control_deassert(rst);
 	}
 
 	if (spi->cfg->has_fifo)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/8] spi: stm32: defer probe for reset
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (3 preceding siblings ...)
  2021-02-05 11:08 ` [PATCH 4/8] spi: stm32: driver uses reset controller only at init Alain Volmat
@ 2021-02-05 11:08 ` Alain Volmat
  2021-02-05 16:41   ` Mark Brown
  2021-02-05 11:09 ` [PATCH 6/8] spi: stm32: use bitfield macros Alain Volmat
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:08 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

Defer the probe operation when a reset controller device is expected
but have not yet been probed.

This change replaces use of devm_reset_control_get_exclusive() with
devm_reset_control_get_optional_exclusive() as reset controller is
optional which is now explicitly stated.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 22bd3d1c8d69..c40cea0640e6 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1891,8 +1891,14 @@ static int stm32_spi_probe(struct platform_device *pdev)
 		goto err_clk_disable;
 	}
 
-	rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-	if (!IS_ERR(rst)) {
+	rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
+	if (rst) {
+		if (IS_ERR(rst)) {
+			ret = dev_err_probe(&pdev->dev, PTR_ERR(rst),
+					    "failed to get reset\n");
+			goto err_clk_disable;
+		}
+
 		reset_control_assert(rst);
 		udelay(2);
 		reset_control_deassert(rst);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/8] spi: stm32: use bitfield macros
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (4 preceding siblings ...)
  2021-02-05 11:08 ` [PATCH 5/8] spi: stm32: defer probe for reset Alain Volmat
@ 2021-02-05 11:09 ` Alain Volmat
  2021-02-05 11:09 ` [PATCH 7/8] spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC Alain Volmat
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:09 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

From: Amelie Delaunay <amelie.delaunay@foss.st.com>

To avoid defining shift and mask separately and hand-coding the bit
manipulation, use the bitfield macros.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 54 ++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 36 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index c40cea0640e6..cacd5b4b6823 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -5,6 +5,7 @@
 // Copyright (C) 2017, STMicroelectronics - All Rights Reserved
 // Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics.
 
+#include <linux/bitfield.h>
 #include <linux/debugfs.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
@@ -94,27 +95,22 @@
 #define STM32H7_SPI_CR1_SSI		BIT(12)
 
 /* STM32H7_SPI_CR2 bit fields */
-#define STM32H7_SPI_CR2_TSIZE_SHIFT	0
 #define STM32H7_SPI_CR2_TSIZE		GENMASK(15, 0)
+#define STM32H7_SPI_TSIZE_MAX		GENMASK(15, 0)
 
 /* STM32H7_SPI_CFG1 bit fields */
-#define STM32H7_SPI_CFG1_DSIZE_SHIFT	0
 #define STM32H7_SPI_CFG1_DSIZE		GENMASK(4, 0)
-#define STM32H7_SPI_CFG1_FTHLV_SHIFT	5
 #define STM32H7_SPI_CFG1_FTHLV		GENMASK(8, 5)
 #define STM32H7_SPI_CFG1_RXDMAEN	BIT(14)
 #define STM32H7_SPI_CFG1_TXDMAEN	BIT(15)
-#define STM32H7_SPI_CFG1_MBR_SHIFT	28
 #define STM32H7_SPI_CFG1_MBR		GENMASK(30, 28)
+#define STM32H7_SPI_CFG1_MBR_SHIFT	28
 #define STM32H7_SPI_CFG1_MBR_MIN	0
 #define STM32H7_SPI_CFG1_MBR_MAX	(GENMASK(30, 28) >> 28)
 
 /* STM32H7_SPI_CFG2 bit fields */
-#define STM32H7_SPI_CFG2_MIDI_SHIFT	4
 #define STM32H7_SPI_CFG2_MIDI		GENMASK(7, 4)
-#define STM32H7_SPI_CFG2_COMM_SHIFT	17
 #define STM32H7_SPI_CFG2_COMM		GENMASK(18, 17)
-#define STM32H7_SPI_CFG2_SP_SHIFT	19
 #define STM32H7_SPI_CFG2_SP		GENMASK(21, 19)
 #define STM32H7_SPI_CFG2_MASTER		BIT(22)
 #define STM32H7_SPI_CFG2_LSBFRST	BIT(23)
@@ -140,7 +136,6 @@
 #define STM32H7_SPI_SR_OVR		BIT(6)
 #define STM32H7_SPI_SR_MODF		BIT(9)
 #define STM32H7_SPI_SR_SUSP		BIT(11)
-#define STM32H7_SPI_SR_RXPLVL_SHIFT	13
 #define STM32H7_SPI_SR_RXPLVL		GENMASK(14, 13)
 #define STM32H7_SPI_SR_RXWNE		BIT(15)
 
@@ -415,9 +410,7 @@ static int stm32h7_spi_get_bpw_mask(struct stm32_spi *spi)
 	stm32_spi_set_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_DSIZE);
 
 	cfg1 = readl_relaxed(spi->base + STM32H7_SPI_CFG1);
-	max_bpw = (cfg1 & STM32H7_SPI_CFG1_DSIZE) >>
-		  STM32H7_SPI_CFG1_DSIZE_SHIFT;
-	max_bpw += 1;
+	max_bpw = FIELD_GET(STM32H7_SPI_CFG1_DSIZE, cfg1) + 1;
 
 	spin_unlock_irqrestore(&spi->lock, flags);
 
@@ -585,8 +578,7 @@ static void stm32f4_spi_read_rx(struct stm32_spi *spi)
 static void stm32h7_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
 {
 	u32 sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
-	u32 rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
-		     STM32H7_SPI_SR_RXPLVL_SHIFT;
+	u32 rxplvl = FIELD_GET(STM32H7_SPI_SR_RXPLVL, sr);
 
 	while ((spi->rx_len > 0) &&
 	       ((sr & STM32H7_SPI_SR_RXP) ||
@@ -613,8 +605,7 @@ static void stm32h7_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
 		}
 
 		sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
-		rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
-			 STM32H7_SPI_SR_RXPLVL_SHIFT;
+		rxplvl = FIELD_GET(STM32H7_SPI_SR_RXPLVL, sr);
 	}
 
 	dev_dbg(spi->dev, "%s%s: %d bytes left\n", __func__,
@@ -1397,15 +1388,13 @@ static void stm32h7_spi_set_bpw(struct stm32_spi *spi)
 	bpw = spi->cur_bpw - 1;
 
 	cfg1_clrb |= STM32H7_SPI_CFG1_DSIZE;
-	cfg1_setb |= (bpw << STM32H7_SPI_CFG1_DSIZE_SHIFT) &
-		     STM32H7_SPI_CFG1_DSIZE;
+	cfg1_setb |= FIELD_PREP(STM32H7_SPI_CFG1_DSIZE, bpw);
 
 	spi->cur_fthlv = stm32h7_spi_prepare_fthlv(spi, spi->cur_xferlen);
 	fthlv = spi->cur_fthlv - 1;
 
 	cfg1_clrb |= STM32H7_SPI_CFG1_FTHLV;
-	cfg1_setb |= (fthlv << STM32H7_SPI_CFG1_FTHLV_SHIFT) &
-		     STM32H7_SPI_CFG1_FTHLV;
+	cfg1_setb |= FIELD_PREP(STM32H7_SPI_CFG1_FTHLV, fthlv);
 
 	writel_relaxed(
 		(readl_relaxed(spi->base + STM32H7_SPI_CFG1) &
@@ -1423,8 +1412,7 @@ static void stm32_spi_set_mbr(struct stm32_spi *spi, u32 mbrdiv)
 	u32 clrb = 0, setb = 0;
 
 	clrb |= spi->cfg->regs->br.mask;
-	setb |= ((u32)mbrdiv << spi->cfg->regs->br.shift) &
-		spi->cfg->regs->br.mask;
+	setb |= (mbrdiv << spi->cfg->regs->br.shift) & spi->cfg->regs->br.mask;
 
 	writel_relaxed((readl_relaxed(spi->base + spi->cfg->regs->br.reg) &
 			~clrb) | setb,
@@ -1515,8 +1503,7 @@ static int stm32h7_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
 	}
 
 	cfg2_clrb |= STM32H7_SPI_CFG2_COMM;
-	cfg2_setb |= (mode << STM32H7_SPI_CFG2_COMM_SHIFT) &
-		     STM32H7_SPI_CFG2_COMM;
+	cfg2_setb |= FIELD_PREP(STM32H7_SPI_CFG2_COMM, mode);
 
 	writel_relaxed(
 		(readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
@@ -1539,14 +1526,15 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
 	cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
 	if ((len > 1) && (spi->cur_midi > 0)) {
 		u32 sck_period_ns = DIV_ROUND_UP(SPI_1HZ_NS, spi->cur_speed);
-		u32 midi = min((u32)DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
-			       (u32)STM32H7_SPI_CFG2_MIDI >>
-			       STM32H7_SPI_CFG2_MIDI_SHIFT);
+		u32 midi = min_t(u32,
+				 DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
+				 FIELD_GET(STM32H7_SPI_CFG2_MIDI,
+				 STM32H7_SPI_CFG2_MIDI));
+
 
 		dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n",
 			sck_period_ns, midi, midi * sck_period_ns);
-		cfg2_setb |= (midi << STM32H7_SPI_CFG2_MIDI_SHIFT) &
-			     STM32H7_SPI_CFG2_MIDI;
+		cfg2_setb |= FIELD_PREP(STM32H7_SPI_CFG2_MIDI, midi);
 	}
 
 	writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
@@ -1561,14 +1549,8 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
  */
 static int stm32h7_spi_number_of_data(struct stm32_spi *spi, u32 nb_words)
 {
-	u32 cr2_clrb = 0, cr2_setb = 0;
-
-	if (nb_words <= (STM32H7_SPI_CR2_TSIZE >>
-			 STM32H7_SPI_CR2_TSIZE_SHIFT)) {
-		cr2_clrb |= STM32H7_SPI_CR2_TSIZE;
-		cr2_setb = nb_words << STM32H7_SPI_CR2_TSIZE_SHIFT;
-		writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CR2) &
-				~cr2_clrb) | cr2_setb,
+	if (nb_words <= STM32H7_SPI_TSIZE_MAX) {
+		writel_relaxed(FIELD_PREP(STM32H7_SPI_CR2_TSIZE, nb_words),
 			       spi->base + STM32H7_SPI_CR2);
 	} else {
 		return -EMSGSIZE;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/8] spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (5 preceding siblings ...)
  2021-02-05 11:09 ` [PATCH 6/8] spi: stm32: use bitfield macros Alain Volmat
@ 2021-02-05 11:09 ` Alain Volmat
  2021-02-05 11:09 ` [PATCH 8/8] spi: stm32: make spurious and overrun interrupts visible Alain Volmat
  2021-02-05 20:16 ` (subset) [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Mark Brown
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:09 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

From: Amelie Delaunay <amelie.delaunay@foss.st.com>

Replace SPI_1HZ_NS private constant with NSEC_PER_SEC, which is easier
to read and understand.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index cacd5b4b6823..7692e2778df5 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -162,8 +162,6 @@
 #define SPI_3WIRE_TX		3
 #define SPI_3WIRE_RX		4
 
-#define SPI_1HZ_NS		1000000000
-
 /*
  * use PIO for small transfers, avoiding DMA setup/teardown overhead for drivers
  * without fifo buffers.
@@ -1525,7 +1523,7 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
 
 	cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
 	if ((len > 1) && (spi->cur_midi > 0)) {
-		u32 sck_period_ns = DIV_ROUND_UP(SPI_1HZ_NS, spi->cur_speed);
+		u32 sck_period_ns = DIV_ROUND_UP(NSEC_PER_SEC, spi->cur_speed);
 		u32 midi = min_t(u32,
 				 DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
 				 FIELD_GET(STM32H7_SPI_CFG2_MIDI,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/8] spi: stm32: make spurious and overrun interrupts visible
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (6 preceding siblings ...)
  2021-02-05 11:09 ` [PATCH 7/8] spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC Alain Volmat
@ 2021-02-05 11:09 ` Alain Volmat
  2021-02-05 20:16 ` (subset) [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Mark Brown
  8 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 11:09 UTC (permalink / raw)
  To: broonie, amelie.delaunay
  Cc: mcoquelin.stm32, alexandre.torgue, linux-spi, linux-stm32,
	linux-arm-kernel, linux-kernel, fabrice.gasnier, alain.volmat

We do not expect to receive spurious interrupts so rise a warning
if it happens.

RX overrun is an error condition that signals a corrupted RX
stream both in dma and in irq modes. Report the error and
abort the transfer in either cases.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/spi/spi-stm32.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 7692e2778df5..e7699758c609 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -895,8 +895,8 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
 		mask |= STM32H7_SPI_SR_RXP;
 
 	if (!(sr & mask)) {
-		dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
-			sr, ier);
+		dev_warn(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
+			 sr, ier);
 		spin_unlock_irqrestore(&spi->lock, flags);
 		return IRQ_NONE;
 	}
@@ -923,15 +923,8 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
 	}
 
 	if (sr & STM32H7_SPI_SR_OVR) {
-		dev_warn(spi->dev, "Overrun: received value discarded\n");
-		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
-			stm32h7_spi_read_rxfifo(spi, false);
-		/*
-		 * If overrun is detected while using DMA, it means that
-		 * something went wrong, so stop the current transfer
-		 */
-		if (spi->cur_usedma)
-			end = true;
+		dev_err(spi->dev, "Overrun: RX data lost\n");
+		end = true;
 	}
 
 	if (sr & STM32H7_SPI_SR_EOT) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/8] spi: stm32: properly handle 0 byte transfer
  2021-02-05 11:08 ` [PATCH 1/8] spi: stm32: properly handle 0 byte transfer Alain Volmat
@ 2021-02-05 13:29   ` Mark Brown
  0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2021-02-05 13:29 UTC (permalink / raw)
  To: Alain Volmat
  Cc: amelie.delaunay, mcoquelin.stm32, alexandre.torgue, linux-spi,
	linux-stm32, linux-arm-kernel, linux-kernel, fabrice.gasnier

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

On Fri, Feb 05, 2021 at 12:08:55PM +0100, Alain Volmat wrote:
> On 0 byte transfer request, return straight from the
> xfer function after finalizing the transfer.

> +	if (transfer->len == 0) {
> +		spi_finalize_current_transfer(master);
> +		return 0;

The driver only needs to finalize the transfer if it returned a value
greater than 0, returning 0 indicates that the transfer is already done.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/8] spi: stm32: defer probe for reset
  2021-02-05 11:08 ` [PATCH 5/8] spi: stm32: defer probe for reset Alain Volmat
@ 2021-02-05 16:41   ` Mark Brown
  2021-02-05 17:23     ` Alain Volmat
  0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2021-02-05 16:41 UTC (permalink / raw)
  To: Alain Volmat
  Cc: amelie.delaunay, linux-kernel, alexandre.torgue, fabrice.gasnier,
	mcoquelin.stm32, linux-spi, linux-stm32, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

On Fri, Feb 05, 2021 at 12:08:59PM +0100, Alain Volmat wrote:
> Defer the probe operation when a reset controller device is expected
> but have not yet been probed.
> 
> This change replaces use of devm_reset_control_get_exclusive() with
> devm_reset_control_get_optional_exclusive() as reset controller is
> optional which is now explicitly stated.

This has trouble building an x86 allmodconfig build:

/mnt/kernel/drivers/spi/spi-stm32.c: In function 'stm32_spi_prepare_msg':
/mnt/kernel/drivers/spi/spi-stm32.c:1022:9: error: 'STM32H7_SPI_TSIZE_MAX' undeclared (first use in this function); did you mean 'STM32H7_SPI_CR1_MASRX'?
         STM32H7_SPI_TSIZE_MAX,
         ^~~~~~~~~~~~~~~~~~~~~
         STM32H7_SPI_CR1_MASRX
/mnt/kernel/drivers/spi/spi-stm32.c:1022:9: note: each undeclared identifier is reported only once for each function it appears in

This may be due to an earlier patch in the series, my script is working
back through the patch series.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/8] spi: stm32: defer probe for reset
  2021-02-05 16:41   ` Mark Brown
@ 2021-02-05 17:23     ` Alain Volmat
  0 siblings, 0 replies; 13+ messages in thread
From: Alain Volmat @ 2021-02-05 17:23 UTC (permalink / raw)
  To: Mark Brown
  Cc: amelie.delaunay, linux-kernel, alexandre.torgue, fabrice.gasnier,
	mcoquelin.stm32, linux-spi, linux-stm32, linux-arm-kernel

Hi Mark,

sorry about that, I've just noticed the issue. This is probably due to
modification of patches ordering I did. STM32H7_SPI_TSIZE_MAX is introduced
in the PATCH 6/8 and this is the reason why PATCH 5/8 doesn't build properly.
I'll rework that to ensure that all patches compile properly.

Sorry again,
Alain

On Fri, Feb 05, 2021 at 04:41:54PM +0000, Mark Brown wrote:
> On Fri, Feb 05, 2021 at 12:08:59PM +0100, Alain Volmat wrote:
> > Defer the probe operation when a reset controller device is expected
> > but have not yet been probed.
> > 
> > This change replaces use of devm_reset_control_get_exclusive() with
> > devm_reset_control_get_optional_exclusive() as reset controller is
> > optional which is now explicitly stated.
> 
> This has trouble building an x86 allmodconfig build:
> 
> /mnt/kernel/drivers/spi/spi-stm32.c: In function 'stm32_spi_prepare_msg':
> /mnt/kernel/drivers/spi/spi-stm32.c:1022:9: error: 'STM32H7_SPI_TSIZE_MAX' undeclared (first use in this function); did you mean 'STM32H7_SPI_CR1_MASRX'?
>          STM32H7_SPI_TSIZE_MAX,
>          ^~~~~~~~~~~~~~~~~~~~~
>          STM32H7_SPI_CR1_MASRX
> /mnt/kernel/drivers/spi/spi-stm32.c:1022:9: note: each undeclared identifier is reported only once for each function it appears in
> 
> This may be due to an earlier patch in the series, my script is working
> back through the patch series.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: (subset) [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32
  2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
                   ` (7 preceding siblings ...)
  2021-02-05 11:09 ` [PATCH 8/8] spi: stm32: make spurious and overrun interrupts visible Alain Volmat
@ 2021-02-05 20:16 ` Mark Brown
  8 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2021-02-05 20:16 UTC (permalink / raw)
  To: amelie.delaunay, Alain Volmat
  Cc: mcoquelin.stm32, linux-stm32, linux-arm-kernel, linux-spi,
	fabrice.gasnier, linux-kernel, alexandre.torgue

On Fri, 5 Feb 2021 12:08:54 +0100, Alain Volmat wrote:
> The serie provides a fix for the spi-stm32 driver, allowing to properly
> handle 0 byte transfer (and thus being able to run spi-loopback-test).
> 
> In addition to that, important enhancements are implemented, among them,
> supporting transfer larger that what the IP can setup in one go or
> allowing to use the SPI bus without cs_gpio.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[2/8] spi: stm32: do not mandate cs_gpio
      commit: 8f8d0e3e33e36ba63416cad64b9a9ad6b0129eed
[3/8] spi: stm32h7: ensure message are smaller than max size
      commit: 084de5232820c9e857ccc2282c3d94f33f92a381
[4/8] spi: stm32: driver uses reset controller only at init
      commit: 1c75cfd53e213044523141b464eb06813e39ecea
[5/8] spi: stm32: defer probe for reset
      commit: c63b95b76e69b679b9b95014552db099eb77a4fa
[6/8] spi: stm32: use bitfield macros
      commit: 5a380b833ad437123dca91bf900a696709d9b6ab
[7/8] spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC
      commit: e1e2093b16cb1cefe4dc483b00e73d1333260784
[8/8] spi: stm32: make spurious and overrun interrupts visible
      commit: c64e7efe46b7de21937ef4b3594d9b1fc74f07df

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-06  0:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 11:08 [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Alain Volmat
2021-02-05 11:08 ` [PATCH 1/8] spi: stm32: properly handle 0 byte transfer Alain Volmat
2021-02-05 13:29   ` Mark Brown
2021-02-05 11:08 ` [PATCH 2/8] spi: stm32: do not mandate cs_gpio Alain Volmat
2021-02-05 11:08 ` [PATCH 3/8] spi: stm32h7: ensure message are smaller than max size Alain Volmat
2021-02-05 11:08 ` [PATCH 4/8] spi: stm32: driver uses reset controller only at init Alain Volmat
2021-02-05 11:08 ` [PATCH 5/8] spi: stm32: defer probe for reset Alain Volmat
2021-02-05 16:41   ` Mark Brown
2021-02-05 17:23     ` Alain Volmat
2021-02-05 11:09 ` [PATCH 6/8] spi: stm32: use bitfield macros Alain Volmat
2021-02-05 11:09 ` [PATCH 7/8] spi: stm32h7: replace private SPI_1HZ_NS with NSEC_PER_SEC Alain Volmat
2021-02-05 11:09 ` [PATCH 8/8] spi: stm32: make spurious and overrun interrupts visible Alain Volmat
2021-02-05 20:16 ` (subset) [PATCH 0/8] spi: stm32: fix and enhancements for spi-stm32 Mark Brown

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).