Skip to contentSkip to conversation

Add Tegra Quad SPI driver

PATCH Superseded Sowjanya Komatineni 5 participants 20 messages Dec 17, 2020 – Dec 22, 2020

Subsystems (6)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sowjanya Komatineni

author maintainer
#0 lore raw

v4 cover Add Tegra Quad SPI driver

This series adds Tegra210, Tegra186, and Tegra194 Quad SPI driver and enables Quad SPI on Jetson Nano and Jetson Xavier NX.

QSPI controller is available on Tegra210, Tegra186 and Tegra194.

Tegra186 and Tegra194 has additional feature of combined sequence mode where command, address and data can all be transferred in a single transfer. Combined sequence mode is useful only when using DMA mode transfer.

This series does not have combined sequence mode feature as Tegra186/Tegra194 GPCDMA driver is not upstreamed yet.

This series includes
- dt-binding document
- QSPI driver for Tegra210/Tegra186/Tegra194
- Enables QSPI on Jetson Nano and Jetson Xavier NX.

Delta between patch versions:
[v4]: Updated dummy cycles implementation based on v3 feedback
- Added dummy_data bit field int spi_transfer to indicate corresponding transfer is dummy bytes transfer.
- Updated Tegra QSPI transfer_one_message to identify dummy transfer and to use HW supported dummy bytes transfer when dummy cycles are with in Tegra QSPI supported max HW dummy cycles otherwise fallsback to transfer dummy bytes from software.
- Updated dt-bindings based on v3 feedback.

[v3]: v2 has some mixed patches sent out accidentally.
v3 sends proper patches with fixes mentioned in v2.

[v2]: below v1 feedback
- Added SPI_MASTER_USES_HW_DUMMY_CYCLES flag for controllers supporting hardware dummy cycles and skips dummy bytes transfer from software for these controllers.
- Updated dt-binding doc with tx/rx tap delay properties.
- Added qspi_out clock to dt-binding doc which will be used later with ddr mode support.
- All other v1 feedback on some cleanup.

Sowjanya Komatineni (9):
dt-bindings: clock: tegra: Add clock ID TEGRA210_CLK_QSPI_PM
dt-bindings: spi: Add Tegra Quad SPI device tree binding
MAINTAINERS: Add Tegra Quad SPI driver section
spi: tegra210-quad: Add support for Tegra210 QSPI controller
spi: spi-mem: Mark dummy transfers by setting dummy_data bit
spi: tegra210-quad: Add support for hardware dummy cycles transfer
arm64: tegra: Enable QSPI on Jetson Nano
arm64: tegra: Add QSPI nodes on Tegra194
arm64: tegra: Enable QSPI on Jetson Xavier NX

 .../bindings/spi/nvidia,tegra210-quad.yaml         |  117 ++
 MAINTAINERS                                        |    8 +
 .../dts/nvidia/tegra194-p3509-0000+p3668-0000.dts  |   12 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi           |   28 +
 arch/arm64/boot/dts/nvidia/tegra210-p3450-0000.dts |   12 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           |    5 +-
 drivers/spi/Kconfig                                |    9 +
 drivers/spi/Makefile                               |    1 +
 drivers/spi/spi-mem.c                              |    1 +
 drivers/spi/spi-tegra210-quad.c                    | 1421 ++++++++++++++++++++
 include/dt-bindings/clock/tegra210-car.h           |    2 +-
 include/linux/spi/spi.h                            |    2 +
 12 files changed, 1615 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
 create mode 100644 drivers/spi/spi-tegra210-quad.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v4 1/9 dt-bindings: clock: tegra: Add clock ID TEGRA210_CLK_QSPI_PM

Tegra210 QSPI clock output has divider DIV2_SEL which will be enabled when using DDR interface mode.

This patch adds clock ID for this to dt-binding.

---
 include/dt-bindings/clock/tegra210-car.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/dt-bindings/clock/tegra210-car.h +1 -1
index ab8b8a7..9cfcc3b 100644
@@ -307,7 +307,7 @@
 #define TEGRA210_CLK_AUDIO4 275
 #define TEGRA210_CLK_SPDIF 276
 /* 277 */
-/* 278 */
+#define TEGRA210_CLK_QSPI_PM 278
 /* 279 */
 /* 280 */
 #define TEGRA210_CLK_SOR0_LVDS 281 /* deprecated */
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH v4 2/9 dt-bindings: spi: Add Tegra Quad SPI device tree binding

In reply to Sowjanya Komatineni

This patch adds YAML based device tree binding document for Tegra Quad SPI driver.

---
 .../bindings/spi/nvidia,tegra210-quad.yaml         | 117 +++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +117 -0
new file mode 100644
index 0000000..35a8045
@@ -0,0 +1,117 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/spi/nvidia,tegra210-quad.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Tegra Quad SPI Controller
+
+maintainers:
+  - Thierry Reding <[email protected]>
+  - Jonathan Hunter <[email protected]>
+
+allOf:
+  - $ref: "spi-controller.yaml#"
+
+properties:
+  compatible:
+    enum:
+      - nvidia,tegra210-qspi
+      - nvidia,tegra186-qspi
+      - nvidia,tegra194-qspi
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: qspi
+      - const: qspi_out
+
+  clocks:
+    maxItems: 2
+
+  resets:
+    maxItems: 1
+
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    items:
+      - const: rx
+      - const: tx
+
+patternProperties:
+  "@[0-9a-f]+":
+    type: object
+
+    properties:
+      spi-rx-bus-width:
+        enum: [1, 2, 4]
+
+      spi-tx-bus-width:
+        enum: [1, 2, 4]
+
+      nvidia,tx-clk-tap-delay:
+        description:
+          Delays the clock going out to device with this tap value.
+          Tap value varies based on platform design trace lengths from Tegra
+          QSPI to corresponding slave device.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        minimum: 0
+        maximum: 31
+
+      nvidia,rx-clk-tap-delay:
+        description:
+          Delays the clock coming in from the device with this tap value.
+          Tap value varies based on platform design trace lengths from Tegra
+          QSPI to corresponding slave device.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        minimum: 0
+        maximum: 255
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/tegra210-car.h>
+    #include <dt-bindings/reset/tegra210-car.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    spi@70410000 {
+            compatible = "nvidia,tegra210-qspi";
+            reg = <0x70410000 0x1000>;
+            interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            clocks = <&tegra_car TEGRA210_CLK_QSPI>,
+                     <&tegra_car TEGRA210_CLK_QSPI_PM>;
+            clock-names = "qspi", "qspi_out";
+            resets = <&tegra_car 211>;
+            dmas = <&apbdma 5>, <&apbdma 5>;
+            dma-names = "rx", "tx";
+
+            flash@0 {
+                    compatible = "spi-nor";
+                    reg = <0>;
+                    spi-max-frequency = <104000000>;
+                    spi-tx-bus-width = <2>;
+                    spi-rx-bus-width = <2>;
+                    nvidia,tx-clk-tap-delay = <0>;
+                    nvidia,rx-clk-tap-delay = <0>;
+            };
+    };
Signature · 1 line
2.7.4
maintainer Reviewed-by on v4 2/9
#3 lore raw

Re: [PATCH v4 2/9] dt-bindings: spi: Add Tegra Quad SPI device tree binding

Quoted 9 lines · Sowjanya Komatineni

This patch adds YAML based device tree binding document for Tegra Quad SPI driver.

---
 .../bindings/spi/nvidia,tegra210-quad.yaml         | 117 +++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
author maintainer
#4 lore raw

PATCH v4 3/9 MAINTAINERS: Add Tegra Quad SPI driver section

In reply to Sowjanya Komatineni

Add maintainers and mailing list entries to Tegra Quad SPI driver section.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 5b20bab..19db61f 100644
@@ -17447,6 +17447,14 @@ M:	Laxman Dewangan <[email protected]>
 S:	Supported
 F:	drivers/spi/spi-tegra*
 
+TEGRA QUAD SPI DRIVER
+M:	Thierry Reding <[email protected]>
+M:	Jonathan Hunter <[email protected]>
+M:	Sowjanya Komatineni <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/spi/spi-tegra210-quad.c
+
 TEGRA VIDEO DRIVER
 M:	Thierry Reding <[email protected]>
 M:	Jonathan Hunter <[email protected]>
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH v4 4/9 spi: tegra210-quad: Add support for Tegra210 QSPI controller

In reply to Sowjanya Komatineni

Tegra SoC has a Quad SPI controller starting from Tegra210.

This patch adds support for Tegra210 QSPI controller.

---
 drivers/spi/Kconfig             |    9 +
 drivers/spi/Makefile            |    1 +
 drivers/spi/spi-tegra210-quad.c | 1382 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 1392 insertions(+)
 create mode 100644 drivers/spi/spi-tegra210-quad.c
drivers/spi/Kconfig +9 -0
index aadaea0..f56f20e 100644
@@ -843,6 +843,15 @@ config SPI_MXS
 	help
 	  SPI driver for Freescale MXS devices.
 
+config SPI_TEGRA210_QUAD
+	tristate "NVIDIA Tegra QSPI Controller"
+	depends on ARCH_TEGRA || COMPILE_TEST
+	depends on RESET_CONTROLLER
+	help
+	  QSPI driver for NVIDIA Tegra QSPI Controller interface. This
+	  controller is different from the SPI controller and is available
+	  on Tegra SoCs starting from Tegra210.
+
 config SPI_TEGRA114
 	tristate "NVIDIA Tegra114 SPI Controller"
 	depends on (ARCH_TEGRA && TEGRA20_APB_DMA) || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 6fea582..c822c5e 100644
@@ -115,6 +115,7 @@ obj-$(CONFIG_SPI_ST_SSC4)		+= spi-st-ssc4.o
 obj-$(CONFIG_SPI_SUN4I)			+= spi-sun4i.o
 obj-$(CONFIG_SPI_SUN6I)			+= spi-sun6i.o
 obj-$(CONFIG_SPI_SYNQUACER)		+= spi-synquacer.o
+obj-$(CONFIG_SPI_TEGRA210_QUAD)		+= spi-tegra210-quad.o
 obj-$(CONFIG_SPI_TEGRA114)		+= spi-tegra114.o
 obj-$(CONFIG_SPI_TEGRA20_SFLASH)	+= spi-tegra20-sflash.o
 obj-$(CONFIG_SPI_TEGRA20_SLINK)		+= spi-tegra20-slink.o
drivers/spi/spi-tegra210-quad.c new file +1382 -0

1,382 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#6 lore raw

PATCH v4 5/9 spi: spi-mem: Mark dummy transfers by setting dummy_data bit

In reply to Sowjanya Komatineni

This patch marks dummy transfer by setting dummy_data bit to 1.

Controllers supporting dummy transfer by hardware use this bit field to skip software transfer of dummy bytes and use hardware dummy bytes transfer.

---
 drivers/spi/spi-mem.c   | 1 +
 include/linux/spi/spi.h | 2 ++
 2 files changed, 3 insertions(+)
drivers/spi/spi-mem.c +1 -0
index f3a3f19..c64371c 100644
@@ -354,6 +354,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
 		xfers[xferpos].len = op->dummy.nbytes;
 		xfers[xferpos].tx_nbits = op->dummy.buswidth;
+		xfers[xferpos].dummy_data = 1;
 		spi_message_add_tail(&xfers[xferpos], &msg);
 		xferpos++;
 		totalxferlen += op->dummy.nbytes;
include/linux/spi/spi.h +2 -0
index aa09fdc..708f2f5 100644
@@ -827,6 +827,7 @@ extern void spi_res_release(struct spi_controller *ctlr,
  *      transfer. If 0 the default (from @spi_device) is used.
  * @bits_per_word: select a bits_per_word other than the device default
  *      for this transfer. If 0 the default (from @spi_device) is used.
+ * @dummy_data: indicates transfer is dummy bytes transfer.
  * @cs_change: affects chipselect after this transfer completes
  * @cs_change_delay: delay between cs deassert and assert when
  *      @cs_change is set and @spi_transfer is not the last in @spi_message
@@ -939,6 +940,7 @@ struct spi_transfer {
 	struct sg_table tx_sg;
 	struct sg_table rx_sg;
 
+	unsigned	dummy_data:1;
 	unsigned	cs_change:1;
 	unsigned	tx_nbits:3;
 	unsigned	rx_nbits:3;
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Hi Sowjanya,

Quoted 5 lines · Sowjanya Komatineni

This patch marks dummy transfer by setting dummy_data bit to 1.

Controllers supporting dummy transfer by hardware use this bit field to skip software transfer of dummy bytes and use hardware dummy bytes transfer.

What is the benefit you get from this change? You add complexity in spi-mem and the controller driver, so that must come with some benefits. Here I don't see any. The transfer will certainly take the same amount of time because the number or period of the dummy cycles has not changed. So why is this needed?

Quoted 41 lines
---
 drivers/spi/spi-mem.c   | 1 +
 include/linux/spi/spi.h | 2 ++
 2 files changed, 3 insertions(+)
drivers/spi/spi-mem.c +1 -0
index f3a3f19..c64371c 100644
@@ -354,6 +354,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
 		xfers[xferpos].len = op->dummy.nbytes;
 		xfers[xferpos].tx_nbits = op->dummy.buswidth;
+		xfers[xferpos].dummy_data = 1;
 		spi_message_add_tail(&xfers[xferpos], &msg);
 		xferpos++;
 		totalxferlen += op->dummy.nbytes;
include/linux/spi/spi.h +2 -0
index aa09fdc..708f2f5 100644
@@ -827,6 +827,7 @@ extern void spi_res_release(struct spi_controller *ctlr,
  *      transfer. If 0 the default (from @spi_device) is used.
  * @bits_per_word: select a bits_per_word other than the device default
  *      for this transfer. If 0 the default (from @spi_device) is used.
+ * @dummy_data: indicates transfer is dummy bytes transfer.
  * @cs_change: affects chipselect after this transfer completes
  * @cs_change_delay: delay between cs deassert and assert when
  *      @cs_change is set and @spi_transfer is not the last in @spi_message
@@ -939,6 +940,7 @@ struct spi_transfer {
 	struct sg_table tx_sg;
 	struct sg_table rx_sg;
 
+	unsigned	dummy_data:1;
 	unsigned	cs_change:1;
 	unsigned	tx_nbits:3;
 	unsigned	rx_nbits:3;
Signature · 1 line
2.7.4
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India
#8 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 9 lines · On Fri, 18 Dec 2020 14:51:08 +0530 Pratyush Yadav <[email protected]> wrote:

Hi Sowjanya,

Quoted 5 lines · Sowjanya Komatineni

This patch marks dummy transfer by setting dummy_data bit to 1.

Controllers supporting dummy transfer by hardware use this bit field to skip software transfer of dummy bytes and use hardware dummy bytes transfer.

Quoted 5 lines

What is the benefit you get from this change? You add complexity in spi-mem and the controller driver, so that must come with some benefits. Here I don't see any. The transfer will certainly take the same amount of time because the number or period of the dummy cycles has not changed. So why is this needed?

Well, you don't have to queue TX bytes if you use HW-based dummy cycles, but I agree, I'd expect the overhead to be negligible, especially since we're talking about emitting a few bytes, not hundreds. This being said, the complexity added to the core is reasonable IMHO, so if it really helps reducing the CPU overhead (we might need some numbers to prove that), I guess it's okay.

Quoted 43 lines
Quoted 42 lines
---
 drivers/spi/spi-mem.c   | 1 +
 include/linux/spi/spi.h | 2 ++
 2 files changed, 3 insertions(+)
drivers/spi/spi-mem.c +1 -0
index f3a3f19..c64371c 100644
@@ -354,6 +354,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
 		xfers[xferpos].len = op->dummy.nbytes;
 		xfers[xferpos].tx_nbits = op->dummy.buswidth;
+		xfers[xferpos].dummy_data = 1;
 		spi_message_add_tail(&xfers[xferpos], &msg);
 		xferpos++;
 		totalxferlen += op->dummy.nbytes;
include/linux/spi/spi.h +2 -0
index aa09fdc..708f2f5 100644
@@ -827,6 +827,7 @@ extern void spi_res_release(struct spi_controller *ctlr,
  *      transfer. If 0 the default (from @spi_device) is used.
  * @bits_per_word: select a bits_per_word other than the device default
  *      for this transfer. If 0 the default (from @spi_device) is used.
+ * @dummy_data: indicates transfer is dummy bytes transfer.
  * @cs_change: affects chipselect after this transfer completes
  * @cs_change_delay: delay between cs deassert and assert when
  *      @cs_change is set and @spi_transfer is not the last in @spi_message
@@ -939,6 +940,7 @@ struct spi_transfer {
 	struct sg_table tx_sg;
 	struct sg_table rx_sg;
 
+	unsigned	dummy_data:1;
 	unsigned	cs_change:1;
 	unsigned	tx_nbits:3;
 	unsigned	rx_nbits:3;
Signature · 1 line
2.7.4
author maintainer
#9 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 16 lines · Boris Brezillon
Quoted 5 lines · On Fri, 18 Dec 2020 14:51:08 +0530 Pratyush Yadav <[email protected]> wrote:

Hi Sowjanya,

Quoted 2 lines · Sowjanya Komatineni

This patch marks dummy transfer by setting dummy_data bit to 1.

Quoted 8 lines
Quoted 3 lines

Controllers supporting dummy transfer by hardware use this bit field to skip software transfer of dummy bytes and use hardware dummy bytes transfer.

What is the benefit you get from this change? You add complexity in spi-mem and the controller driver, so that must come with some benefits. Here I don't see any. The transfer will certainly take the same amount of time because the number or period of the dummy cycles has not changed. So why is this needed?

Quoted 6 lines

Well, you don't have to queue TX bytes if you use HW-based dummy cycles, but I agree, I'd expect the overhead to be negligible, especially since we're talking about emitting a few bytes, not hundreds. This being said, the complexity added to the core is reasonable IMHO, so if it really helps reducing the CPU overhead (we might need some numbers to prove that), I guess it's okay.

Hardware dummy cycles feature of Tegra QSPI is to save SW transfer cycle of dummy bytes by filling FIFO.

I don't have numbers as we always use hardware dummy cycles with Tegra QSPI.

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
---
  drivers/spi/spi-mem.c   | 1 +
  include/linux/spi/spi.h | 2 ++
  2 files changed, 3 insertions(+)
drivers/spi/spi-mem.c +1 -0
index f3a3f19..c64371c 100644
@@ -354,6 +354,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
  		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
  		xfers[xferpos].len = op->dummy.nbytes;
  		xfers[xferpos].tx_nbits = op->dummy.buswidth;
+		xfers[xferpos].dummy_data = 1;
  		spi_message_add_tail(&xfers[xferpos], &msg);
  		xferpos++;
  		totalxferlen += op->dummy.nbytes;
include/linux/spi/spi.h +2 -0
index aa09fdc..708f2f5 100644
@@ -827,6 +827,7 @@ extern void spi_res_release(struct spi_controller *ctlr,
   *      transfer. If 0 the default (from @spi_device) is used.
   * @bits_per_word: select a bits_per_word other than the device default
   *      for this transfer. If 0 the default (from @spi_device) is used.
+ * @dummy_data: indicates transfer is dummy bytes transfer.
   * @cs_change: affects chipselect after this transfer completes
   * @cs_change_delay: delay between cs deassert and assert when
   *      @cs_change is set and @spi_transfer is not the last in @spi_message
@@ -939,6 +940,7 @@ struct spi_transfer {
  	struct sg_table tx_sg;
  	struct sg_table rx_sg;
 
+	unsigned	dummy_data:1;
  	unsigned	cs_change:1;
  	unsigned	tx_nbits:3;
  	unsigned	rx_nbits:3;
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 25 lines · Sowjanya Komatineni
Quoted 16 lines · Boris Brezillon
Quoted 5 lines · On Fri, 18 Dec 2020 14:51:08 +0530 Pratyush Yadav <[email protected]> wrote:

Hi Sowjanya,

Quoted 2 lines · Sowjanya Komatineni

This patch marks dummy transfer by setting dummy_data bit to 1.

Quoted 8 lines
Quoted 3 lines

Controllers supporting dummy transfer by hardware use this bit field to skip software transfer of dummy bytes and use hardware dummy bytes transfer.

What is the benefit you get from this change? You add complexity in spi-mem and the controller driver, so that must come with some benefits. Here I don't see any. The transfer will certainly take the same amount of time because the number or period of the dummy cycles has not changed. So why is this needed?

Quoted 6 lines

Well, you don't have to queue TX bytes if you use HW-based dummy cycles, but I agree, I'd expect the overhead to be negligible, especially since we're talking about emitting a few bytes, not hundreds. This being said, the complexity added to the core is reasonable IMHO, so if it really helps reducing the CPU overhead (we might need some numbers to prove that), I guess it's okay.

Quoted 4 lines

Hardware dummy cycles feature of Tegra QSPI is to save SW transfer cycle of dummy bytes by filling FIFO.

I don't have numbers as we always use hardware dummy cycles with Tegra QSPI.

Most flashes use somewhere around 8-10 dummy cycles. Some of the faster ones working at 166 MHz or above use 20-25. From what I understand, the only time hardware transfer of dummy cycles will reduce CPU load significantly will be when multiple small transfers are made in quick succession. Unless you have such a usecase I don't know how much benefit you will get by it.

Anyway, if the SPI maintainers think this is worth it, I won't object.

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
---
  drivers/spi/spi-mem.c   | 1 +
  include/linux/spi/spi.h | 2 ++
  2 files changed, 3 insertions(+)
drivers/spi/spi-mem.c +1 -0
index f3a3f19..c64371c 100644
@@ -354,6 +354,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
  		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
  		xfers[xferpos].len = op->dummy.nbytes;
  		xfers[xferpos].tx_nbits = op->dummy.buswidth;
+		xfers[xferpos].dummy_data = 1;
  		spi_message_add_tail(&xfers[xferpos], &msg);
  		xferpos++;
  		totalxferlen += op->dummy.nbytes;
include/linux/spi/spi.h +2 -0
index aa09fdc..708f2f5 100644
@@ -827,6 +827,7 @@ extern void spi_res_release(struct spi_controller *ctlr,
   *      transfer. If 0 the default (from @spi_device) is used.
   * @bits_per_word: select a bits_per_word other than the device default
   *      for this transfer. If 0 the default (from @spi_device) is used.
+ * @dummy_data: indicates transfer is dummy bytes transfer.
   * @cs_change: affects chipselect after this transfer completes
   * @cs_change_delay: delay between cs deassert and assert when
   *      @cs_change is set and @spi_transfer is not the last in @spi_message
@@ -939,6 +940,7 @@ struct spi_transfer {
  	struct sg_table tx_sg;
  	struct sg_table rx_sg;
+	unsigned	dummy_data:1;
  	unsigned	cs_change:1;
  	unsigned	tx_nbits:3;
  	unsigned	rx_nbits:3;
Signature · 1 line
2.7.4
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India
maintainer
#11 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 1 line · Pratyush Yadav

Anyway, if the SPI maintainers think this is worth it, I won't object.

This gets kind of circular, for me it's a question of if there's some meaningful benefit from using the feature vs the cost to support it and from the sounds of it we don't have numbers on the benefits from using it at present.

maintainer
#12 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 8 lines · Mark Brown
Quoted 1 line · Pratyush Yadav

Anyway, if the SPI maintainers think this is worth it, I won't object.

This gets kind of circular, for me it's a question of if there's some meaningful benefit from using the feature vs the cost to support it and from the sounds of it we don't have numbers on the benefits from using it at present.

...although I do have to say looking at the implementation that the cost seems low, it's just a flag set on an existing transfer. The only issue is if we'd get more win from coalesing the entire transaction (or entire transmit) into a single transfer that could be DMAed and/or requires fewer trips through the stack which does make it seem like an unclear tradeoff from the point of view of client drivers

author maintainer
#13 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 7 lines · Mark Brown
Quoted 6 lines · Mark Brown
Quoted 1 line · Pratyush Yadav

Anyway, if the SPI maintainers think this is worth it, I won't object.

This gets kind of circular, for me it's a question of if there's some meaningful benefit from using the feature vs the cost to support it and from the sounds of it we don't have numbers on the benefits from using it at present.

Quoted 6 lines

...although I do have to say looking at the implementation that the cost seems low, it's just a flag set on an existing transfer. The only issue is if we'd get more win from coalesing the entire transaction (or entire transmit) into a single transfer that could be DMAed and/or requires fewer trips through the stack which does make it seem like an unclear tradeoff from the point of view of client drivers

Using HW dummy cycles save extra software cycle of transfer which involves transfer setup register writes, writing dummy bytes to TX FIFO, interrupt processing.

Implementation wise it just a single bit field added to spi_transfer and on Tegra controller driver programming dummy cycles with prior transfer and skipping sw dummy transfer which is actually not complex.

From quick check, I see HW dummy cycles transfer of 128KB shows 18 Mb/s while SW transfer of bytes shows 17.3 MB/s on average.

When back-to-back read commands are executed using HW dummy cycles will definitely save cycles.

maintainer
#14 lore raw

Re: [PATCH v4 5/9] spi: spi-mem: Mark dummy transfers by setting dummy_data bit

Quoted 2 lines · Sowjanya Komatineni

From quick check, I see HW dummy cycles transfer of 128KB shows 18 Mb/s while SW transfer of bytes shows 17.3 MB/s on average.

OK, it's not going to revolutionize the world or anything but that's definitely a speedup.

author maintainer
#15 lore raw

PATCH v4 6/9 spi: tegra210-quad: Add support for hardware dummy cycles transfer

In reply to Sowjanya Komatineni

Tegra Quad SPI controller hardware supports sending dummy bytes based on programmed dummy clock cycles after the actual transfer bytes.

This patch adds this support of hardware dummy bytes transfer and skips transfer of dummy bytes from the software.

For dummy cycles more than Tegra Quad SPI hardware maximum dummy cycles limit, driver transfers dummy bytes from the software.

---
 drivers/spi/spi-tegra210-quad.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra210-quad.c +40 -1
index e7bee8d..695a296 100644
@@ -117,6 +117,7 @@
 
 #define QSPI_MISC_REG                           0x194
 #define QSPI_NUM_DUMMY_CYCLE(x)			(((x) & 0xff) << 0)
+#define QSPI_DUMMY_CYCLES_MAX			0xff
 
 #define DATA_DIR_TX				BIT(0)
 #define DATA_DIR_RX				BIT(1)
@@ -170,6 +171,7 @@ struct tegra_qspi {
 	u32					def_command2_reg;
 	u32					spi_cs_timing1;
 	u32					spi_cs_timing2;
+	u8					dummy_cycles;
 
 	struct completion			xfer_completion;
 	struct spi_transfer			*curr_xfer;
@@ -856,6 +858,8 @@ static int tegra_qspi_start_transfer_one(struct spi_device *spi,
 
 	tqspi->command1_reg = command1;
 
+	tegra_qspi_writel(tqspi, QSPI_NUM_DUMMY_CYCLE(tqspi->dummy_cycles), QSPI_MISC_REG);
+
 	ret = tegra_qspi_flush_fifos(tqspi, false);
 	if (ret < 0)
 		return ret;
@@ -974,7 +978,8 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 {
 	struct tegra_qspi *tqspi = spi_master_get_devdata(master);
 	struct spi_device *spi = msg->spi;
-	struct spi_transfer *xfer;
+	struct spi_transfer *xfer, *next_xfer;
+	bool use_hw_dummy_cycles = false;
 	bool is_first_msg = true;
 	int ret;
 
@@ -984,8 +989,42 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	tqspi->rx_status = 0;
 
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+		u8 dummy_cycles = 0;
 		u32 cmd1;
 
+		/*
+		 * Skip dummy bytes transfer if they are transferred by the hardware along
+		 * with previous transfer.
+		 */
+		if (xfer->dummy_data && use_hw_dummy_cycles) {
+			msg->actual_length += xfer->len;
+			continue;
+		}
+
+		/*
+		 * Tegra QSPI hardware supports dummy bytes transfer after actual transfer
+		 * bytes based on programmed dummy clock cycles in the QSPI_MISC register.
+		 * So, check if the next transfer is dummy data transfer and program dummy
+		 * clock cycles along with the current transfer.
+		 */
+		if (!list_is_last(&xfer->transfer_list, &msg->transfers)) {
+			next_xfer = list_next_entry(xfer, transfer_list);
+			if (next_xfer && next_xfer->dummy_data) {
+				dummy_cycles = next_xfer->len * 8 / next_xfer->tx_nbits;
+				use_hw_dummy_cycles = true;
+				/*
+				 * Use software dummy bytes transfer if dummy cycles exceeds
+				 * Tegra QSPI hardware maximum dummy cycles limit.
+				 */
+				if (dummy_cycles > QSPI_DUMMY_CYCLES_MAX) {
+					use_hw_dummy_cycles = false;
+					dummy_cycles = 0;
+				}
+			}
+		}
+
+		tqspi->dummy_cycles = dummy_cycles;
+
 		reinit_completion(&tqspi->xfer_completion);
 
 		cmd1 = tegra_qspi_setup_transfer_one(spi, xfer, is_first_msg);
Signature · 1 line
2.7.4
#16 lore raw

Re: [PATCH v4 6/9] spi: tegra210-quad: Add support for hardware dummy cycles transfer

Quoted 44 lines · On Thu, 17 Dec 2020 12:28:44 -0800 Sowjanya Komatineni…

Tegra Quad SPI controller hardware supports sending dummy bytes based on programmed dummy clock cycles after the actual transfer bytes.

This patch adds this support of hardware dummy bytes transfer and skips transfer of dummy bytes from the software.

For dummy cycles more than Tegra Quad SPI hardware maximum dummy cycles limit, driver transfers dummy bytes from the software.

---
 drivers/spi/spi-tegra210-quad.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra210-quad.c +4 -0
index e7bee8d..695a296 100644
@@ -117,6 +117,7 @@
 
 #define QSPI_MISC_REG                           0x194
 #define QSPI_NUM_DUMMY_CYCLE(x)			(((x) & 0xff) << 0)
+#define QSPI_DUMMY_CYCLES_MAX			0xff
 
 #define DATA_DIR_TX				BIT(0)
 #define DATA_DIR_RX				BIT(1)
@@ -170,6 +171,7 @@ struct tegra_qspi {
 	u32					def_command2_reg;
 	u32					spi_cs_timing1;
 	u32					spi_cs_timing2;
+	u8					dummy_cycles;
 
 	struct completion			xfer_completion;
 	struct spi_transfer			*curr_xfer;
@@ -856,6 +858,8 @@ static int tegra_qspi_start_transfer_one(struct spi_device *spi,
 
 	tqspi->command1_reg = command1;
 
+	tegra_qspi_writel(tqspi, QSPI_NUM_DUMMY_CYCLE(tqspi->dummy_cycles), QSPI_MISC_REG);
+
 	ret = tegra_qspi_flush_fifos(tqspi, false);
 	if (ret < 0)
 		return ret;

drivers/spi/spi-tegra210-quad.c static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · line 981

Quoted 5 lines
drivers/spi/spi-tegra210-quad.c +1 -1
@@ -974,7 +978,8 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 {
 	struct tegra_qspi *tqspi = spi_master_get_devdata(master);
 	struct spi_device *spi = msg->spi;
-	struct spi_transfer *xfer;
+	struct spi_transfer *xfer, *next_xfer;

next_after should be declared where it's actually used.

drivers/spi/spi-tegra210-quad.c static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · line 982

Quoted 1 line
drivers/spi/spi-tegra210-quad.c +1 -0
+	bool use_hw_dummy_cycles = false;

I don't think you need this variable (see below).

drivers/spi/spi-tegra210-quad.c static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · line 992

Quoted 8 lines
drivers/spi/spi-tegra210-quad.c +1 -0
 	bool is_first_msg = true;
 	int ret;
 
@@ -984,8 +989,42 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	tqspi->rx_status = 0;
 
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+		u8 dummy_cycles = 0;

Should be declared where it's actually used, and you don't want it to be a u8 since you're checking that the result does not exceed 255 which will always be true with a u8.

Quoted 25 lines
drivers/spi/spi-tegra210-quad.c +23 -0
 		u32 cmd1;
 
+		/*
+		 * Skip dummy bytes transfer if they are transferred by the hardware along
+		 * with previous transfer.
+		 */
+		if (xfer->dummy_data && use_hw_dummy_cycles) {
+			msg->actual_length += xfer->len;
+			continue;
+		}
+
+		/*
+		 * Tegra QSPI hardware supports dummy bytes transfer after actual transfer
+		 * bytes based on programmed dummy clock cycles in the QSPI_MISC register.
+		 * So, check if the next transfer is dummy data transfer and program dummy
+		 * clock cycles along with the current transfer.
+		 */
+		if (!list_is_last(&xfer->transfer_list, &msg->transfers)) {
+			next_xfer = list_next_entry(xfer, transfer_list);
+			if (next_xfer && next_xfer->dummy_data) {
+				dummy_cycles = next_xfer->len * 8 / next_xfer->tx_nbits;
+				use_hw_dummy_cycles = true;
+				/*
+				 * Use software dummy bytes transfer if dummy cycles exceeds
+				 * Tegra QSPI hardware maximum dummy cycles limit.

drivers/spi/spi-tegra210-quad.c static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · line 1027

Quoted 10 lines
drivers/spi/spi-tegra210-quad.c +10 -0
+				 */
+				if (dummy_cycles > QSPI_DUMMY_CYCLES_MAX) {
+					use_hw_dummy_cycles = false;
+					dummy_cycles = 0;
+				}
+			}
+		}
+
+		tqspi->dummy_cycles = dummy_cycles;
+

This can be simplified:

		/*
		 * Skip dummy bytes transfer if they were issued with the
		 * previous transfer.
		 */
		if (tqspi->dummy_cycles) {
			WARN_ON(!xfer->dummy_data);
			tqspi->dummy_cycles = 0;
		}

		/*
		 * Tegra QSPI hardware supports dummy bytes transfer after actual
		 * transfer bytes based on programmed dummy clock cycles in the
		 * QSPI_MISC register. So, check if the next transfer is dummy
		 * data transfer and program dummy clock cycles along with the
		 * current transfer.
		 */
		if (!list_is_last(&xfer->transfer_list, &msg->transfers)) {
			struct spi_transfer *next_xfer;

			next_xfer = list_next_entry(xfer, transfer_list);
			if (next_xfer->dummy_data) {
				u32 dummy_cycles = next_xfer->len * 8 /
						   next_xfer->tx_nbits;
				if (dummy_cycles <= QSPI_DUMMY_CYCLES_MAX)
					tqspi->dummy_cycles = dummy_cycles;
			}
		}
Quoted 3 lines
drivers/spi/spi-tegra210-quad.c +0 -0
 		reinit_completion(&tqspi->xfer_completion);
 
 		cmd1 = tegra_qspi_setup_transfer_one(spi, xfer, is_first_msg);
author maintainer
#17 lore raw

PATCH v4 7/9 arm64: tegra: Enable QSPI on Jetson Nano

In reply to Sowjanya Komatineni

This patch enables QSPI on Jetson Nano.

---
 arch/arm64/boot/dts/nvidia/tegra210-p3450-0000.dts | 12 ++++++++++++
 arch/arm64/boot/dts/nvidia/tegra210.dtsi           |  5 +++--
 2 files changed, 15 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/nvidia/tegra210-p3450-0000.dts +12 -0
index 6a877de..a1b4603 100644
@@ -638,6 +638,18 @@
 		};
 	};
 
+	spi@70410000 {
+		status = "okay";
+
+		flash@0 {
+			compatible = "spi-nor";
+			reg = <0>;
+			spi-max-frequency = <104000000>;
+			spi-tx-bus-width = <2>;
+			spi-rx-bus-width = <2>;
+		};
+	};
+
 	clk32k_in: clock@0 {
 		compatible = "fixed-clock";
 		clock-frequency = <32768>;
arch/arm64/boot/dts/nvidia/tegra210.dtsi +3 -2
index 4fbf8c1..998fa81 100644
@@ -1536,8 +1536,9 @@
 		interrupts = <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
 		#address-cells = <1>;
 		#size-cells = <0>;
-		clocks = <&tegra_car TEGRA210_CLK_QSPI>;
-		clock-names = "qspi";
+		clocks = <&tegra_car TEGRA210_CLK_QSPI>,
+			 <&tegra_car TEGRA210_CLK_QSPI_PM>;
+		clock-names = "qspi", "qspi_out";
 		resets = <&tegra_car 211>;
 		reset-names = "qspi";
 		dmas = <&apbdma 5>, <&apbdma 5>;
Signature · 1 line
2.7.4
author maintainer
#18 lore raw

PATCH v4 8/9 arm64: tegra: Add QSPI nodes on Tegra194

In reply to Sowjanya Komatineni

Tegra194 has 2 QSPI controllers.

This patch adds DT node for these 2 QSPI controllers.

---
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194.dtsi +28 -0
index 25f36d6..852980f 100644
@@ -609,6 +609,34 @@
 			status = "disabled";
 		};
 
+		spi@3270000 {
+			compatible = "nvidia,tegra194-qspi";
+			reg = <0x3270000 0x1000>;
+			interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			clocks = <&bpmp TEGRA194_CLK_QSPI0>,
+				 <&bpmp TEGRA194_CLK_QSPI0_PM>;
+			clock-names = "qspi", "qspi_out";
+			resets = <&bpmp TEGRA194_RESET_QSPI0>;
+			reset-names = "qspi";
+			status = "disabled";
+		};
+
+		spi@3300000 {
+			compatible = "nvidia,tegra194-qspi";
+			reg = <0x3300000 0x1000>;
+			interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			clocks = <&bpmp TEGRA194_CLK_QSPI1>,
+				 <&bpmp TEGRA194_CLK_QSPI1_PM>;
+			clock-names = "qspi", "qspi_out";
+			resets = <&bpmp TEGRA194_RESET_QSPI1>;
+			reset-names = "qspi";
+			status = "disabled";
+		};
+
 		pwm1: pwm@3280000 {
 			compatible = "nvidia,tegra194-pwm",
 				     "nvidia,tegra186-pwm";
Signature · 1 line
2.7.4
author maintainer
#19 lore raw

PATCH v4 9/9 arm64: tegra: Enable QSPI on Jetson Xavier NX

In reply to Sowjanya Komatineni

This patch enables QSPI on Jetson Xavier NX.

---
 .../arm64/boot/dts/nvidia/tegra194-p3509-0000+p3668-0000.dts | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p3509-0000+p3668-0000.dts +12 -0
index 7f97b34..f1053e7 100644
@@ -100,6 +100,18 @@
 			phy-names = "usb2-1", "usb2-2", "usb3-2";
 		};
 
+		spi@3270000 {
+			status = "okay";
+
+			flash@0 {
+				compatible = "spi-nor";
+				reg = <0>;
+				spi-max-frequency = <102000000>;
+				spi-tx-bus-width = <4>;
+				spi-rx-bus-width = <4>;
+			};
+		};
+
 		pwm@32d0000 {
 			status = "okay";
 		};
Signature · 1 line
2.7.4