linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/9] STM32 SPI various fixes
@ 2017-06-27 15:45 Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patchset answers to the reviews done after STM32 SPI driver introduction.

Amelie Delaunay (9):
  dt-bindings: spi: stm32: use SoC specific compatible
  spi: stm32: fix compatible to fit with new bindings
  dt-bindings: spi: stm32: fix example with st,spi-midi-ns property
  spi: stm32: replace st,spi-midi with st,spi-midi-ns to fit bindings
  spi: stm32: use normal conditional statements instead of ternary
    operator
  spi: stm32: add runtime PM support
  spi: stm32: enhance DMA error management
  spi: stm32: fix potential dereference null return value
  spi: spidev: add Aardvark to device tree compatibility list

 .../devicetree/bindings/spi/spi-stm32.txt          |  11 +-
 drivers/spi/spi-stm32.c                            | 130 +++++++++++++++------
 drivers/spi/spidev.c                               |   1 +
 3 files changed, 99 insertions(+), 43 deletions(-)

-- 
1.9.1

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

* [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-28 18:51   ` Mark Brown
  2017-06-27 15:45 ` [PATCHv2 2/9] spi: stm32: fix compatible to fit with new bindings Amelie Delaunay
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch replaces st,stm32-spi compatible with st,stm32h7-spi SoC
specific compatible and updates the example accondingly.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Acked-by: Rob Herring <robh@kernel.org>
---
 Documentation/devicetree/bindings/spi/spi-stm32.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-stm32.txt b/Documentation/devicetree/bindings/spi/spi-stm32.txt
index 3958bf6..415378b 100644
--- a/Documentation/devicetree/bindings/spi/spi-stm32.txt
+++ b/Documentation/devicetree/bindings/spi/spi-stm32.txt
@@ -7,7 +7,7 @@ from 4 to 32-bit data size. Although it can be configured as master or slave,
 only master is supported by the driver.
 
 Required properties:
-- compatible: Must be "st,stm32-spi".
+- compatible: Must be "st,stm32h7-spi".
 - reg: Offset and length of the device's register set.
 - interrupts: Must contain the interrupt id.
 - clocks: Must contain an entry for spiclk (which feeds the internal clock
@@ -38,7 +38,7 @@ Example:
 	spi2: spi@40003800 {
 		#address-cells = <1>;
 		#size-cells = <0>;
-		compatible = "st,stm32-spi";
+		compatible = "st,stm32h7-spi";
 		reg = <0x40003800 0x400>;
 		interrupts = <36>;
 		clocks = <&rcc SPI2_CK>;
-- 
1.9.1

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

* [PATCHv2 2/9] spi: stm32: fix compatible to fit with new bindings
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 3/9] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch updates of_device_id compatible string to fit with new
bindings.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 82a6616f..ca38c24 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -1038,7 +1038,7 @@ static int stm32_spi_config(struct stm32_spi *spi)
 }
 
 static const struct of_device_id stm32_spi_of_match[] = {
-	{ .compatible = "st,stm32-spi", },
+	{ .compatible = "st,stm32h7-spi", },
 	{},
 };
 MODULE_DEVICE_TABLE(of, stm32_spi_of_match);
-- 
1.9.1

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

* [PATCHv2 3/9] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 2/9] spi: stm32: fix compatible to fit with new bindings Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-28 19:25   ` Applied "spi: stm32: fix example with st, spi-midi-ns property" to the spi tree Mark Brown
  2017-06-27 15:45 ` [PATCHv2 4/9] spi: stm32: replace st,spi-midi with st,spi-midi-ns to fit bindings Amelie Delaunay
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch aligns example with the optional property description,
removes status and replace spidev unvalid compatible with
Aarvark SPI Host Adapter one.

In slave mode, Aardvark SPI Host Adapter requires 4ms delay
between the end of byte n and the start of byte n+1, hence the
use of the optional property st,spi-midi-ns.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 Documentation/devicetree/bindings/spi/spi-stm32.txt | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-stm32.txt b/Documentation/devicetree/bindings/spi/spi-stm32.txt
index 415378b..1b3fa2c1 100644
--- a/Documentation/devicetree/bindings/spi/spi-stm32.txt
+++ b/Documentation/devicetree/bindings/spi/spi-stm32.txt
@@ -48,13 +48,12 @@ Example:
 		dma-names = "rx", "tx";
 		pinctrl-0 = <&spi2_pins_b>;
 		pinctrl-names = "default";
-		status = "okay";
 		cs-gpios = <&gpioa 11 0>;
 
-		spidev@0 {
-			compatible = "spidev";
+		aardvark@0 {
+			compatible = "totalphase,aardvark";
 			reg = <0>;
 			spi-max-frequency = <4000000>;
-			st,spi-midi = <4000>;
+			st,spi-midi-ns = <4000>;
 		};
 	};
-- 
1.9.1

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

* [PATCHv2 4/9] spi: stm32: replace st,spi-midi with st,spi-midi-ns to fit bindings
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (2 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 3/9] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 5/9] spi: stm32: use normal conditional statements instead of ternary operator Amelie Delaunay
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch fixes the optional dt property used to set master inter-data
idleness.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index ca38c24..0997d6d 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -582,7 +582,7 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
 
 	/* SPI slave device may need time between data frames */
 	spi->cur_midi = 0;
-	if (np && !of_property_read_u32(np, "st,spi-midi", &spi->cur_midi))
+	if (np && !of_property_read_u32(np, "st,spi-midi-ns", &spi->cur_midi))
 		dev_dbg(spi->dev, "%dns inter-data idleness\n", spi->cur_midi);
 
 	if (spi_dev->mode & SPI_CPOL)
-- 
1.9.1

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

* [PATCHv2 5/9] spi: stm32: use normal conditional statements instead of ternary operator
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (3 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 4/9] spi: stm32: replace st,spi-midi with st,spi-midi-ns to fit bindings Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 6/9] spi: stm32: add runtime PM support Amelie Delaunay
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch replace ternary operator use by normal condition statements
to ease code reading.
It also removes redundant !!.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 0997d6d..72efc63 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -267,7 +267,10 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz)
 		return -EINVAL;
 
 	/* Determine the first power of 2 greater than or equal to div */
-	mbrdiv = (div & (div - 1)) ? fls(div) : fls(div) - 1;
+	if (div & (div - 1))
+		mbrdiv = fls(div);
+	else
+		mbrdiv = fls(div) - 1;
 
 	spi->cur_speed = spi->clk_rate / (1 << mbrdiv);
 
@@ -285,9 +288,12 @@ static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi)
 	/* data packet should not exceed 1/2 of fifo space */
 	half_fifo = (spi->fifo_size / 2);
 
-	fthlv = (spi->cur_bpw <= 8) ? half_fifo :
-		(spi->cur_bpw <= 16) ? (half_fifo / 2) :
-		(half_fifo / 4);
+	if (spi->cur_bpw <= 8)
+		fthlv = half_fifo;
+	else if (spi->cur_bpw <= 16)
+		fthlv = half_fifo / 2;
+	else
+		fthlv = half_fifo / 4;
 
 	/* align packet size with data registers access */
 	if (spi->cur_bpw > 8)
@@ -462,9 +468,9 @@ static bool stm32_spi_can_dma(struct spi_master *master,
 	struct stm32_spi *spi = spi_master_get_devdata(master);
 
 	dev_dbg(spi->dev, "%s: %s\n", __func__,
-		(!!(transfer->len > spi->fifo_size)) ? "true" : "false");
+		(transfer->len > spi->fifo_size) ? "true" : "false");
 
-	return !!(transfer->len > spi->fifo_size);
+	return (transfer->len > spi->fifo_size);
 }
 
 /**
@@ -493,7 +499,8 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 	 * Full-Duplex, need to poll RXP event to know if there are remaining
 	 * data, before disabling SPI.
 	 */
-	mask |= ((spi->rx_buf && !spi->cur_usedma) ? SPI_SR_RXP : 0);
+	if (spi->rx_buf && !spi->cur_usedma)
+		mask |= SPI_SR_RXP;
 
 	if (!(sr & mask)) {
 		dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
@@ -656,12 +663,18 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
 	enum dma_slave_buswidth buswidth;
 	u32 maxburst;
 
-	buswidth = (spi->cur_bpw <= 8) ? DMA_SLAVE_BUSWIDTH_1_BYTE :
-		   (spi->cur_bpw <= 16) ? DMA_SLAVE_BUSWIDTH_2_BYTES :
-		   DMA_SLAVE_BUSWIDTH_4_BYTES;
+	if (spi->cur_bpw <= 8)
+		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
+	else if (spi->cur_bpw <= 16)
+		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
+	else
+		buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
 
 	/* Valid for DMA Half or Full Fifo threshold */
-	maxburst = (spi->cur_fthlv == 2) ? 1 : spi->cur_fthlv;
+	if (spi->cur_fthlv == 2)
+		maxburst = 1;
+	else
+		maxburst = spi->cur_fthlv;
 
 	memset(dma_conf, 0, sizeof(struct dma_slave_config));
 	dma_conf->direction = dir;
@@ -920,9 +933,12 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
 				~cfg2_clrb) | cfg2_setb,
 			       spi->base + STM32_SPI_CFG2);
 
-	nb_words = DIV_ROUND_UP(transfer->len * 8,
-				(spi->cur_bpw <= 8) ? 8 :
-				(spi->cur_bpw <= 16) ? 16 : 32);
+	if (spi->cur_bpw <= 8)
+		nb_words = transfer->len;
+	else if (spi->cur_bpw <= 16)
+		nb_words = DIV_ROUND_UP(transfer->len * 8, 16);
+	else
+		nb_words = DIV_ROUND_UP(transfer->len * 8, 32);
 	nb_words <<= SPI_CR2_TSIZE_SHIFT;
 
 	if (nb_words <= SPI_CR2_TSIZE) {
-- 
1.9.1

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

* [PATCHv2 6/9] spi: stm32: add runtime PM support
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (4 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 5/9] spi: stm32: use normal conditional statements instead of ternary operator Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 7/9] spi: stm32: enhance DMA error management Amelie Delaunay
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch reworks suspend and resume callbacks and add runtime_suspend
and runtime_resume callbacks.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 72efc63..209afda 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -27,6 +27,7 @@
 #include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
+#include <linux/pm_runtime.h>
 #include <linux/reset.h>
 #include <linux/spi/spi.h>
 
@@ -1164,6 +1165,9 @@ static int stm32_spi_probe(struct platform_device *pdev)
 	if (spi->dma_tx || spi->dma_rx)
 		master->can_dma = stm32_spi_can_dma;
 
+	pm_runtime_set_active(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret) {
 		dev_err(&pdev->dev, "spi master registration failed: %d\n",
@@ -1203,6 +1207,8 @@ static int stm32_spi_probe(struct platform_device *pdev)
 		dma_release_channel(spi->dma_tx);
 	if (spi->dma_rx)
 		dma_release_channel(spi->dma_rx);
+
+	pm_runtime_disable(&pdev->dev);
 err_clk_disable:
 	clk_disable_unprepare(spi->clk);
 err_master_put:
@@ -1225,23 +1231,42 @@ static int stm32_spi_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(spi->clk);
 
+	pm_runtime_disable(&pdev->dev);
+
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int stm32_spi_runtime_suspend(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct stm32_spi *spi = spi_master_get_devdata(master);
+
+	clk_disable_unprepare(spi->clk);
+
+	return 0;
+}
+
+static int stm32_spi_runtime_resume(struct device *dev)
+{
+	struct spi_master *master = dev_get_drvdata(dev);
+	struct stm32_spi *spi = spi_master_get_devdata(master);
+
+	return clk_prepare_enable(spi->clk);
+}
+#endif
+
 #ifdef CONFIG_PM_SLEEP
 static int stm32_spi_suspend(struct device *dev)
 {
 	struct spi_master *master = dev_get_drvdata(dev);
-	struct stm32_spi *spi = spi_master_get_devdata(master);
 	int ret;
 
 	ret = spi_master_suspend(master);
 	if (ret)
 		return ret;
 
-	clk_disable_unprepare(spi->clk);
-
-	return ret;
+	return pm_runtime_force_suspend(dev);
 }
 
 static int stm32_spi_resume(struct device *dev)
@@ -1250,9 +1275,10 @@ static int stm32_spi_resume(struct device *dev)
 	struct stm32_spi *spi = spi_master_get_devdata(master);
 	int ret;
 
-	ret = clk_prepare_enable(spi->clk);
+	ret = pm_runtime_force_resume(dev);
 	if (ret)
 		return ret;
+
 	ret = spi_master_resume(master);
 	if (ret)
 		clk_disable_unprepare(spi->clk);
@@ -1261,8 +1287,11 @@ static int stm32_spi_resume(struct device *dev)
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(stm32_spi_pm_ops,
-			 stm32_spi_suspend, stm32_spi_resume);
+static const struct dev_pm_ops stm32_spi_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(stm32_spi_suspend, stm32_spi_resume)
+	SET_RUNTIME_PM_OPS(stm32_spi_runtime_suspend,
+			   stm32_spi_runtime_resume, NULL)
+};
 
 static struct platform_driver stm32_spi_driver = {
 	.probe = stm32_spi_probe,
-- 
1.9.1

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

* [PATCHv2 7/9] spi: stm32: enhance DMA error management
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (5 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 6/9] spi: stm32: add runtime PM support Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-28 19:25   ` Applied "spi: stm32: enhance DMA error management" to the spi tree Mark Brown
  2017-06-27 15:45 ` [PATCHv2 8/9] spi: stm32: fix potential dereference null return value Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list Amelie Delaunay
  8 siblings, 1 reply; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch reworks DMA error management. In case the DMA callback is
called while EOT (End Of Transfer) flag is not set, that means that DMA
encountered an error. This error will result in an auto-suspend of SPI
flow, which could also result in an overrun. So, in DMA mode, SUSP and
OVR flags are a condition to stop the current transfer.

Moreover, stm32_spi_can_dma doesn't care about the state of dma channels.
During driver probe, master->can_dma is initialised if dma channel request
is successful. That's why we must use master->can_dma to know if dma
use is possible (dma channel are successfully requested and the transfer
size is greater than fifo size).

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 209afda..fdbc648 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -514,6 +514,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Communication suspended\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_spi_read_rxfifo(spi, false);
+		/*
+		 * If communication is suspended while using DMA, it means
+		 * that something went wrong, so stop the current transfer
+		 */
+		if (spi->cur_usedma)
+			end = true;
 	}
 
 	if (sr & SPI_SR_MODF) {
@@ -525,6 +531,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Overrun: received value discarded\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_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;
 	}
 
 	if (sr & SPI_SR_EOT) {
@@ -645,12 +657,10 @@ static void stm32_spi_dma_cb(void *data)
 
 	spin_unlock_irqrestore(&spi->lock, flags);
 
-	if (!(sr & SPI_SR_EOT)) {
-		dev_warn(spi->dev, "DMA callback (sr=0x%08x)\n", sr);
+	if (!(sr & SPI_SR_EOT))
+		dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr);
 
-		spi_finalize_current_transfer(spi->master);
-		stm32_spi_disable(spi);
-	}
+	/* Now wait for EOT, or SUSP or OVR in case of error */
 }
 
 /**
@@ -986,7 +996,8 @@ static int stm32_spi_transfer_one(struct spi_master *master,
 	spi->tx_len = spi->tx_buf ? transfer->len : 0;
 	spi->rx_len = spi->rx_buf ? transfer->len : 0;
 
-	spi->cur_usedma = stm32_spi_can_dma(master, spi_dev, transfer);
+	spi->cur_usedma = (master->can_dma &&
+			   stm32_spi_can_dma(master, spi_dev, transfer));
 
 	ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer);
 	if (ret) {
-- 
1.9.1

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

* [PATCHv2 8/9] spi: stm32: fix potential dereference null return value
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (6 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 7/9] spi: stm32: enhance DMA error management Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-27 15:45 ` [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list Amelie Delaunay
  8 siblings, 0 replies; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch fixes the usage of rx_dma_desc and tx_dma_desc pointers
returned by dmaengine_prep_slave_sg, which can be null.

Detected by CoverityScan, CID#1446587 ("Dereference null return value")

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spi-stm32.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index fdbc648..bee74e3 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -775,9 +775,6 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
 					xfer->rx_sg.nents,
 					rx_dma_conf.direction,
 					DMA_PREP_INTERRUPT);
-
-		rx_dma_desc->callback = stm32_spi_dma_cb;
-		rx_dma_desc->callback_param = spi;
 	}
 
 	tx_dma_desc = NULL;
@@ -790,11 +787,6 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
 					xfer->tx_sg.nents,
 					tx_dma_conf.direction,
 					DMA_PREP_INTERRUPT);
-
-		if (spi->cur_comm == SPI_SIMPLEX_TX) {
-			tx_dma_desc->callback = stm32_spi_dma_cb;
-			tx_dma_desc->callback_param = spi;
-		}
 	}
 
 	if ((spi->tx_buf && !tx_dma_desc) ||
@@ -802,6 +794,9 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
 		goto dma_desc_error;
 
 	if (rx_dma_desc) {
+		rx_dma_desc->callback = stm32_spi_dma_cb;
+		rx_dma_desc->callback_param = spi;
+
 		if (dma_submit_error(dmaengine_submit(rx_dma_desc))) {
 			dev_err(spi->dev, "Rx DMA submit failed\n");
 			goto dma_desc_error;
@@ -811,6 +806,11 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
 	}
 
 	if (tx_dma_desc) {
+		if (spi->cur_comm == SPI_SIMPLEX_TX) {
+			tx_dma_desc->callback = stm32_spi_dma_cb;
+			tx_dma_desc->callback_param = spi;
+		}
+
 		if (dma_submit_error(dmaengine_submit(tx_dma_desc))) {
 			dev_err(spi->dev, "Tx DMA submit failed\n");
 			goto dma_submit_error;
-- 
1.9.1

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

* [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list
  2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
                   ` (7 preceding siblings ...)
  2017-06-27 15:45 ` [PATCHv2 8/9] spi: stm32: fix potential dereference null return value Amelie Delaunay
@ 2017-06-27 15:45 ` Amelie Delaunay
  2017-06-28 18:54   ` Mark Brown
  8 siblings, 1 reply; 16+ messages in thread
From: Amelie Delaunay @ 2017-06-27 15:45 UTC (permalink / raw)
  To: Mark Brown, Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue
  Cc: linux-spi, devicetree, linux-arm-kernel, linux-kernel, Amelie Delaunay

This patch adds an entry for the TotalPhase Aardvark SPI Host Adapter,
which can operate as an SPI Slave.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/spi/spidev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 9a2a79a..8093885 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -698,6 +698,7 @@ static int spidev_release(struct inode *inode, struct file *filp)
 	{ .compatible = "lineartechnology,ltc2488" },
 	{ .compatible = "ge,achc" },
 	{ .compatible = "semtech,sx1301" },
+	{ .compatible = "totalphase,aardvark" },
 	{},
 };
 MODULE_DEVICE_TABLE(of, spidev_dt_ids);
-- 
1.9.1

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

* Re: [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible
  2017-06-27 15:45 ` [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
@ 2017-06-28 18:51   ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2017-06-28 18:51 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue,
	linux-spi, devicetree, linux-arm-kernel, linux-kernel

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

On Tue, Jun 27, 2017 at 05:45:13PM +0200, Amelie Delaunay wrote:
> This patch replaces st,stm32-spi compatible with st,stm32h7-spi SoC
> specific compatible and updates the example accondingly.

Please use subject lines matching the style for the subsystem.  This
makes it easier for people to identify relevant patches.

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

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

* Re: [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list
  2017-06-27 15:45 ` [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list Amelie Delaunay
@ 2017-06-28 18:54   ` Mark Brown
  2017-06-29 12:58     ` Amelie DELAUNAY
  0 siblings, 1 reply; 16+ messages in thread
From: Mark Brown @ 2017-06-28 18:54 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre Torgue,
	linux-spi, devicetree, linux-arm-kernel, linux-kernel

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

On Tue, Jun 27, 2017 at 05:45:21PM +0200, Amelie Delaunay wrote:
> This patch adds an entry for the TotalPhase Aardvark SPI Host Adapter,
> which can operate as an SPI Slave.

What does this device actually do and why is spidev a sensible fit for
it?

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

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

* Applied "spi: stm32: enhance DMA error management" to the spi tree
  2017-06-27 15:45 ` [PATCHv2 7/9] spi: stm32: enhance DMA error management Amelie Delaunay
@ 2017-06-28 19:25   ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2017-06-28 19:25 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Mark Brown, Mark Brown, Rob Herring, Mark Rutland,
	Maxime Coquelin, Alexandre Torgue, linux-spi, devicetree,
	linux-arm-kernel, linux-kernel, linux-spi

The patch

   spi: stm32: enhance DMA error management

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

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

>From c67ad368cf75d4999d5ef86543d082b4b35dd2d7 Mon Sep 17 00:00:00 2001
From: Amelie Delaunay <amelie.delaunay@st.com>
Date: Tue, 27 Jun 2017 17:45:19 +0200
Subject: [PATCH] spi: stm32: enhance DMA error management

This patch reworks DMA error management. In case the DMA callback is
called while EOT (End Of Transfer) flag is not set, that means that DMA
encountered an error. This error will result in an auto-suspend of SPI
flow, which could also result in an overrun. So, in DMA mode, SUSP and
OVR flags are a condition to stop the current transfer.

Moreover, stm32_spi_can_dma doesn't care about the state of dma channels.
During driver probe, master->can_dma is initialised if dma channel request
is successful. That's why we must use master->can_dma to know if dma
use is possible (dma channel are successfully requested and the transfer
size is greater than fifo size).

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spi-stm32.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 392c9453c2e6..8a6bff379b21 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -514,6 +514,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Communication suspended\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_spi_read_rxfifo(spi, false);
+		/*
+		 * If communication is suspended while using DMA, it means
+		 * that something went wrong, so stop the current transfer
+		 */
+		if (spi->cur_usedma)
+			end = true;
 	}
 
 	if (sr & SPI_SR_MODF) {
@@ -525,6 +531,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Overrun: received value discarded\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_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;
 	}
 
 	if (sr & SPI_SR_EOT) {
@@ -645,12 +657,10 @@ static void stm32_spi_dma_cb(void *data)
 
 	spin_unlock_irqrestore(&spi->lock, flags);
 
-	if (!(sr & SPI_SR_EOT)) {
-		dev_warn(spi->dev, "DMA callback (sr=0x%08x)\n", sr);
+	if (!(sr & SPI_SR_EOT))
+		dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr);
 
-		spi_finalize_current_transfer(spi->master);
-		stm32_spi_disable(spi);
-	}
+	/* Now wait for EOT, or SUSP or OVR in case of error */
 }
 
 /**
@@ -986,7 +996,8 @@ static int stm32_spi_transfer_one(struct spi_master *master,
 	spi->tx_len = spi->tx_buf ? transfer->len : 0;
 	spi->rx_len = spi->rx_buf ? transfer->len : 0;
 
-	spi->cur_usedma = stm32_spi_can_dma(master, spi_dev, transfer);
+	spi->cur_usedma = (master->can_dma &&
+			   stm32_spi_can_dma(master, spi_dev, transfer));
 
 	ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer);
 	if (ret) {
-- 
2.13.2

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

* Applied "spi: stm32: fix example with st, spi-midi-ns property" to the spi tree
  2017-06-27 15:45 ` [PATCHv2 3/9] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
@ 2017-06-28 19:25   ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2017-06-28 19:25 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Mark Brown, Mark Brown, Rob Herring, Mark Rutland,
	Maxime Coquelin, Alexandre Torgue, linux-spi, devicetree,
	linux-arm-kernel, linux-kernel, linux-spi

The patch

   spi: stm32: fix example with st, spi-midi-ns property

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

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

>From 5fd3d9433217908e1e8e1c2f841c3b28c75509d6 Mon Sep 17 00:00:00 2001
From: Amelie Delaunay <amelie.delaunay@st.com>
Date: Tue, 27 Jun 2017 17:45:15 +0200
Subject: [PATCH] spi: stm32: fix example with st, spi-midi-ns property

This patch aligns example with the optional property description,
removes status and replace spidev unvalid compatible with
Aarvark SPI Host Adapter one.

In slave mode, Aardvark SPI Host Adapter requires 4ms delay
between the end of byte n and the start of byte n+1, hence the
use of the optional property st,spi-midi-ns.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 Documentation/devicetree/bindings/spi/spi-stm32.txt | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-stm32.txt b/Documentation/devicetree/bindings/spi/spi-stm32.txt
index 415378bca480..1b3fa2c119d5 100644
--- a/Documentation/devicetree/bindings/spi/spi-stm32.txt
+++ b/Documentation/devicetree/bindings/spi/spi-stm32.txt
@@ -48,13 +48,12 @@ Example:
 		dma-names = "rx", "tx";
 		pinctrl-0 = <&spi2_pins_b>;
 		pinctrl-names = "default";
-		status = "okay";
 		cs-gpios = <&gpioa 11 0>;
 
-		spidev@0 {
-			compatible = "spidev";
+		aardvark@0 {
+			compatible = "totalphase,aardvark";
 			reg = <0>;
 			spi-max-frequency = <4000000>;
-			st,spi-midi = <4000>;
+			st,spi-midi-ns = <4000>;
 		};
 	};
-- 
2.13.2

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

* Re: [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list
  2017-06-28 18:54   ` Mark Brown
@ 2017-06-29 12:58     ` Amelie DELAUNAY
  2017-06-30 11:51       ` Mark Brown
  0 siblings, 1 reply; 16+ messages in thread
From: Amelie DELAUNAY @ 2017-06-29 12:58 UTC (permalink / raw)
  To: Mark Brown
  Cc: Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre TORGUE,
	linux-spi, devicetree, linux-arm-kernel, linux-kernel



On 06/28/2017 08:54 PM, Mark Brown wrote:
> On Tue, Jun 27, 2017 at 05:45:21PM +0200, Amelie Delaunay wrote:
>> This patch adds an entry for the TotalPhase Aardvark SPI Host Adapter,
>> which can operate as an SPI Slave.
> 
> What does this device actually do and why is spidev a sensible fit for
> it?
> 
This device is actually a debugging tool [1] which can work on SPI bus 
(and also I2C). Connected via USB on a PC, it can either acts as an SPI 
master or SPI slave and it can transmit/receive serial data using SPI 
protocol. Polarity, Phase, Bit Order, Frequency can be configured. So 
this tool is really useful during SPI driver development to 
troubleshoot. And that's why spidev driver totally fit for it when used 
as an SPI slave, for the reason described in spidev Documentation: 
"Developing simple protocols used to talk to" Aardvark "acting as SPI 
slaves, which you may need to change quite often".

[1] https://www.totalphase.com/products/aardvark-i2cspi/

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

* Re: [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list
  2017-06-29 12:58     ` Amelie DELAUNAY
@ 2017-06-30 11:51       ` Mark Brown
  0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2017-06-30 11:51 UTC (permalink / raw)
  To: Amelie DELAUNAY
  Cc: Rob Herring, Mark Rutland, Maxime Coquelin, Alexandre TORGUE,
	linux-spi, devicetree, linux-arm-kernel, linux-kernel

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

On Thu, Jun 29, 2017 at 02:58:43PM +0200, Amelie DELAUNAY wrote:
> On 06/28/2017 08:54 PM, Mark Brown wrote:

> > What does this device actually do and why is spidev a sensible fit for
> > it?

> This device is actually a debugging tool [1] which can work on SPI bus (and
> also I2C). Connected via USB on a PC, it can either acts as an SPI master or
> SPI slave and it can transmit/receive serial data using SPI protocol.
> Polarity, Phase, Bit Order, Frequency can be configured. So this tool is
> really useful during SPI driver development to troubleshoot. And that's why
> spidev driver totally fit for it when used as an SPI slave, for the reason
> described in spidev Documentation: "Developing simple protocols used to talk
> to" Aardvark "acting as SPI slaves, which you may need to change quite
> often".

This doesn't seem like something that should be in DT, it's a tool used
to implement or emulate other things and is no more specific than spidev
itself is.  Whatever it is implementing or emulating should be in DT
instead.

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

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

end of thread, other threads:[~2017-06-30 11:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27 15:45 [PATCHv2 0/9] STM32 SPI various fixes Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 1/9] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
2017-06-28 18:51   ` Mark Brown
2017-06-27 15:45 ` [PATCHv2 2/9] spi: stm32: fix compatible to fit with new bindings Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 3/9] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
2017-06-28 19:25   ` Applied "spi: stm32: fix example with st, spi-midi-ns property" to the spi tree Mark Brown
2017-06-27 15:45 ` [PATCHv2 4/9] spi: stm32: replace st,spi-midi with st,spi-midi-ns to fit bindings Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 5/9] spi: stm32: use normal conditional statements instead of ternary operator Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 6/9] spi: stm32: add runtime PM support Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 7/9] spi: stm32: enhance DMA error management Amelie Delaunay
2017-06-28 19:25   ` Applied "spi: stm32: enhance DMA error management" to the spi tree Mark Brown
2017-06-27 15:45 ` [PATCHv2 8/9] spi: stm32: fix potential dereference null return value Amelie Delaunay
2017-06-27 15:45 ` [PATCHv2 9/9] spi: spidev: add Aardvark to device tree compatibility list Amelie Delaunay
2017-06-28 18:54   ` Mark Brown
2017-06-29 12:58     ` Amelie DELAUNAY
2017-06-30 11:51       ` 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).