Skip to contentSkip to conversation

ARM: dspi: Provide slave mode support for Vybryd vf610

PATCH Superseded Lukasz Majewski 3 participants 9 messages Sep 18, 2018 – Sep 26, 2018

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover ARM: dspi: Provide slave mode support for Vybryd vf610

This patch series provides support for DSPI slave mode operation. It tries to maximally reuse current DMA driver (including its limitations).

For testing the spidev_test program has been used. Test script for this patch can be found here:
https://github.com/lmajewski/tests-spi/blob/master/tests/spi/spi_tests.sh

Lukasz Majewski (3):
dt-bindings: spi: Provide bindings for fsl dspi working in slave mode
ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode)
ARM: dspi: Provide support for DSPI slave more operation (Vybryd

    vf610)
 .../devicetree/bindings/spi/spi-fsl-dspi.txt       |  8 ++++
 drivers/spi/spi-fsl-dspi.c                         | 54 ++++++++++++++++------
 2 files changed, 49 insertions(+), 13 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

This commit provides the description of new property: "fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion.

---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +8 -0
index 18eeafe359d8..b30af19a2bc5 100644
@@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
 - fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping the clock
   signal and deactivating chip select, at the end of a transfer.
 - bus-num : the slave chip chipselect signal number.
+- fsl,spi-slave-mode: if present, controller runs in slave mode.
 
 Example:
 
@@ -56,6 +57,13 @@ dspi0@4002c000 {
 		fsl,spi-cs-sck-delay = <100>;
 		fsl,spi-sck-cs-delay = <50>;
 	};
+
+	spidev3@1 {
+		compatible = "fsl,vf610-dspi";
+		spi-max-frequency = <30000000>;
+		reg = <1>;
+		fsl,spi-slave-mode;
+	};
 };
 
 
Signature · 1 line
2.11.0
#6 lore raw

PATCH 2/3 ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode)

In reply to Lukasz Majewski

The vf610 Vybryd can work in two DSPI modes - namely master and slave. Already we do support master mode.
This commit serves as a prerequisite to add support for slave mode. For slave mode we do need to preserve the MCR register value to change its "mode" bit (31) according to the supported state.

---
 drivers/spi/spi-fsl-dspi.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/spi/spi-fsl-dspi.c +9 -5
index 7cb3ab0a35a0..472385f0a842 100644
@@ -126,6 +126,7 @@
 #define DMA_COMPLETION_TIMEOUT	msecs_to_jiffies(3000)
 
 struct chip_data {
+	u32 mcr_val;
 	u32 ctar_val;
 	u16 void_write_data;
 };
@@ -696,9 +697,9 @@ static int dspi_transfer_one_message(struct spi_master *master,
 		else
 			dspi->bytes_per_word = 4;
 
-		regmap_update_bits(dspi->regmap, SPI_MCR,
-				   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
-				   SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+		regmap_write(dspi->regmap, SPI_MCR, dspi->cur_chip->mcr_val |
+			     SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
 		regmap_write(dspi->regmap, SPI_CTAR(0),
 			     dspi->cur_chip->ctar_val |
 			     SPI_FRAME_BITS(transfer->bits_per_word));
@@ -767,6 +768,11 @@ static int dspi_setup(struct spi_device *spi)
 			return -ENOMEM;
 	}
 
+	chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS;
+
+	if (dspi->devtype_data->xspi_mode)
+		chip->mcr_val |= SPI_MCR_XSPI;
+
 	pdata = dev_get_platdata(&dspi->pdev->dev);
 
 	if (!pdata) {
@@ -964,8 +970,6 @@ static const struct regmap_config dspi_xspi_regmap_config[] = {
 
 static void dspi_init(struct fsl_dspi *dspi)
 {
-	regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS |
-		     (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0));
 	regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
 	if (dspi->devtype_data->xspi_mode)
 		regmap_write(dspi->regmap, SPI_CTARE(0),
Signature · 1 line
2.11.0
#7 lore raw

PATCH 3/3 ARM: dspi: Provide support for DSPI slave more operation (Vybryd vf610)

In reply to Lukasz Majewski

The NXP's Vybryd vf610 can work as a SPI slave device (the CS and clock signal are provided by master).

It is possible to specify a single device to work in that mode. As we do use DMA for transferring data, the RX channel must be prepared for incoming data.
Moreover, in slave mode we just set a subset of control fields in configuration registers (CTAR0, PUSHR).

---
 drivers/spi/spi-fsl-dspi.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
drivers/spi/spi-fsl-dspi.c +32 -8
index 472385f0a842..1d71f6fd2e0b 100644
@@ -209,6 +209,14 @@ struct fsl_dspi {
 	struct fsl_dspi_dma	*dma;
 };
 
+static inline bool dspi_slave_mode(struct fsl_dspi *dspi)
+{
+	if (!(dspi->cur_chip->mcr_val & SPI_MCR_MASTER))
+		return true;
+
+	return false;
+}
+
 static u32 dspi_pop_tx(struct fsl_dspi *dspi)
 {
 	u32 txdata = 0;
@@ -230,6 +238,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi)
 {
 	u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi);
 
+	if (dspi_slave_mode(dspi))
+		return data;
+
 	if (dspi->len > 0)
 		cmd |= SPI_PUSHR_CMD_CONT;
 	return cmd << 16 | data;
@@ -326,6 +337,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
 	dma_async_issue_pending(dma->chan_rx);
 	dma_async_issue_pending(dma->chan_tx);
 
+	if (dspi_slave_mode(dspi)) {
+		wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete);
+		return 0;
+	}
+
 	time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete,
 					DMA_COMPLETION_TIMEOUT);
 	if (time_left == 0) {
@@ -781,6 +797,10 @@ static int dspi_setup(struct spi_device *spi)
 
 		of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay",
 				&sck_cs_delay);
+
+		if (of_property_read_bool(spi->dev.of_node,
+					  "fsl,spi-slave-mode"))
+			chip->mcr_val &= ~SPI_MCR_MASTER;
 	} else {
 		cs_sck_delay = pdata->cs_sck_delay;
 		sck_cs_delay = pdata->sck_cs_delay;
@@ -798,14 +818,18 @@ static int dspi_setup(struct spi_device *spi)
 	ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate);
 
 	chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0)
-		| SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0)
-		| SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0)
-		| SPI_CTAR_PCSSCK(pcssck)
-		| SPI_CTAR_CSSCK(cssck)
-		| SPI_CTAR_PASC(pasc)
-		| SPI_CTAR_ASC(asc)
-		| SPI_CTAR_PBR(pbr)
-		| SPI_CTAR_BR(br);
+		| SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0);
+
+	if (chip->mcr_val & SPI_MCR_MASTER) {
+		chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode &
+						 SPI_LSB_FIRST ? 1 : 0)
+			| SPI_CTAR_PCSSCK(pcssck)
+			| SPI_CTAR_CSSCK(cssck)
+			| SPI_CTAR_PASC(pasc)
+			| SPI_CTAR_ASC(asc)
+			| SPI_CTAR_PBR(pbr)
+			| SPI_CTAR_BR(br);
+	}
 
 	spi_set_ctldata(spi, chip);
 
Signature · 1 line
2.11.0
#8 lore raw
In reply to Lukasz Majewski

Dear All,

By a mistake I've forgotten to add (to CC/TO) some developers who worked on this driver before (they were not generated from get_maintainers.py script).

I'm sending the notification now.

Quoted 12 lines

This patch series provides support for DSPI slave mode operation. It tries to maximally reuse current DMA driver (including its limitations).

For testing the spidev_test program has been used. Test script for this patch can be found here:
https://github.com/lmajewski/tests-spi/blob/master/tests/spi/spi_tests.sh

Lukasz Majewski (3):
dt-bindings: spi: Provide bindings for fsl dspi working in slave
mode ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode) ARM: dspi: Provide support for DSPI slave more operation (Vybryd

Quoted 7 lines
    vf610)
 .../devicetree/bindings/spi/spi-fsl-dspi.txt       |  8 ++++
 drivers/spi/spi-fsl-dspi.c                         | 54

++++++++++++++++------ 2 files changed, 49 insertions(+), 13 deletions(-)

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]

maintainer
#2 lore raw

Re: [PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

In reply to Lukasz Majewski
Quoted 16 lines · Lukasz Majewski

This commit provides the description of new property: "fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion.

---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +0 -0
index 18eeafe359d8..b30af19a2bc5 100644

Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt Optional SPI properties for slave nodes: · line 29

Quoted 4 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +1 -0
@@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
 - fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping the clock
   signal and deactivating chip select, at the end of a transfer.
 - bus-num : the slave chip chipselect signal number.
+- fsl,spi-slave-mode: if present, controller runs in slave mode.

There's a standard property for this.

Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt dspi0@4002c000 { · line 65

Quoted 13 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +6 -0
 Example:
 
@@ -56,6 +57,13 @@ dspi0@4002c000 {
 		fsl,spi-cs-sck-delay = <100>;
 		fsl,spi-sck-cs-delay = <50>;
 	};
+
+	spidev3@1 {
+		compatible = "fsl,vf610-dspi";
+		spi-max-frequency = <30000000>;
+		reg = <1>;
+		fsl,spi-slave-mode;

This doesn't look right for how slave mode is described.

Quoted 7 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +1 -0
+	};
 };
 
 
Signature · 1 line
2.11.0
#3 lore raw

Re: [PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

Hi Rob,

Quoted 14 lines · Lukasz Majewski
Quoted 13 lines

This commit provides the description of new property:
"fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion.

---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 13 lines
Quoted 11 lines
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt index 18eeafe359d8..b30af19a2bc5 100644 --- a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +++ b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt @@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
- fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping
the clock signal and deactivating chip select, at the end of a transfer.
- bus-num : the slave chip chipselect signal number.
+- fsl,spi-slave-mode: if present, controller runs in slave mode.

There's a standard property for this.

I've just realised that there is "spi-slave" property in the Documentation/devicetree/bindings/spi/spi-bus.txt

I will convert the code to use it.

Quoted 4 lines
Quoted 4 lines

Example:

Quoted 12 lines

Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt dspi0@4002c000 { · line 65

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +6 -0
@@ -56,6 +57,13 @@ dspi0@4002c000 {
 		fsl,spi-cs-sck-delay = <100>;
 		fsl,spi-sck-cs-delay = <50>;
 	};
+
+	spidev3@1 {
+		compatible = "fsl,vf610-dspi";
+		spi-max-frequency = <30000000>;
+		reg = <1>;
+		fsl,spi-slave-mode;  

This doesn't look right for how slave mode is described.

You mean that I shall replace fsl,spi-slave-mode; with "spi-slave" ?

Or is there any other issue with this code?

Thanks for your review,

Quoted 9 lines
Quoted 8 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +1 -0
+	};
 };
 
 
Signature · 1 line
2.11.0

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]

#4 lore raw

Re: [PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

Hi Lukasz,

Quoted 50 lines · Lukasz Majewski
Quoted 14 lines · Lukasz Majewski
Quoted 13 lines

This commit provides the description of new property:
"fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion.

---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 13 lines
Quoted 11 lines
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt index 18eeafe359d8..b30af19a2bc5 100644 --- a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +++ b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt @@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
- fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping
the clock signal and deactivating chip select, at the end of a transfer.
- bus-num : the slave chip chipselect signal number.
+- fsl,spi-slave-mode: if present, controller runs in slave mode.

There's a standard property for this.

I've just realised that there is "spi-slave" property in the Documentation/devicetree/bindings/spi/spi-bus.txt

I will convert the code to use it.

Quoted 4 lines
Quoted 4 lines

Example:

Quoted 12 lines

Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt dspi0@4002c000 { · line 65

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +6 -0
@@ -56,6 +57,13 @@ dspi0@4002c000 {
            fsl,spi-cs-sck-delay = <100>;
            fsl,spi-sck-cs-delay = <50>;
    };
+
+   spidev3@1 {
+           compatible = "fsl,vf610-dspi";
+           spi-max-frequency = <30000000>;
+           reg = <1>;
+           fsl,spi-slave-mode;

This doesn't look right for how slave mode is described.

Quoted 3 lines

You mean that I shall replace fsl,spi-slave-mode; with "spi-slave" ?

Or is there any other issue with this code?

According to Documentation/devicetree/bindings/spi/spi-bus.txt:
1. "spi-slave" should be a property of the controller node, not of the slave node,
2. the slave node should be called "slave", without unit address, and without "reg" property.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Re: [PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

Hi Geert,

Quoted 57 lines

Hi Lukasz,

Quoted 54 lines · Lukasz Majewski
Quoted 28 lines · Lukasz Majewski
Quoted 24 lines

This commit provides the description of new property:
"fsl,spi-slave-mode" which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master device a new "spidev" based node has been introduced to avoid confusion.

---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8

++++++++ 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt index 18eeafe359d8..b30af19a2bc5 100644 --- a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +++ b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt @@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
- fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping
the clock signal and deactivating chip select, at the end of a transfer.
- bus-num : the slave chip chipselect signal number.

Quoted 2 lines
+- fsl,spi-slave-mode: if present, controller runs in slave
mode.  
Quoted 1 line

There's a standard property for this.

I've just realised that there is "spi-slave" property in the Documentation/devicetree/bindings/spi/spi-bus.txt

I will convert the code to use it.

Quoted 4 lines
Quoted 4 lines

Example:

Quoted 12 lines

Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt dspi0@4002c000 { · line 65

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +6 -0
@@ -56,6 +57,13 @@ dspi0@4002c000 {
            fsl,spi-cs-sck-delay = <100>;
            fsl,spi-sck-cs-delay = <50>;
    };
+
+   spidev3@1 {
+           compatible = "fsl,vf610-dspi";
+           spi-max-frequency = <30000000>;
+           reg = <1>;
+           fsl,spi-slave-mode;  

This doesn't look right for how slave mode is described.

You mean that I shall replace fsl,spi-slave-mode; with "spi-slave" ?

Quoted 7 lines
Quoted 1 line

Or is there any other issue with this code?

According to Documentation/devicetree/bindings/spi/spi-bus.txt:
1. "spi-slave" should be a property of the controller node, not of
the slave node,
2. the slave node should be called "slave", without unit address,
and without "reg" property.

Thanks for clarification.

Quoted 5 lines

Gr{oetje,eeting}s,

Geert

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]