Skip to contentSkip to conversation

Add Tegra Quad SPI driver

PATCH Superseded Sowjanya Komatineni 5 participants 20 messages Dec 11, 2020 – Dec 15, 2020

Subsystems (6)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sowjanya Komatineni

author maintainer
#0 lore raw

v3 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 with 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:
[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: Allow masters to transfer dummy cycles directly by
hardware
spi: tegra210-quad: Add support for hardware dummy cycles
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         |  130 ++
 MAINTAINERS                                        |    8 +
 .../dts/nvidia/tegra194-p3509-0000+p3668-0000.dts  |   12 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi           |   24 +
 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                              |   18 +-
 drivers/spi/spi-tegra210-quad.c                    | 1407 ++++++++++++++++++++
 include/dt-bindings/clock/tegra210-car.h           |    2 +-
 include/linux/spi/spi.h                            |    8 +
 12 files changed, 1626 insertions(+), 10 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 v3 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
maintainer Acked-by on v3 1/9
#2 lore raw

Re: [PATCH v3 1/9] dt-bindings: clock: tegra: Add clock ID TEGRA210_CLK_QSPI_PM

Quoted 10 lines · Sowjanya Komatineni

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(-)
author maintainer
#3 lore raw

PATCH v3 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         | 130 +++++++++++++++++++++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +130 -0
new file mode 100644
index 0000000..0b5fea6
@@ -0,0 +1,130 @@
+# 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]>
+
+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:
+      compatible:
+        description:
+          Compatible of the SPI device.
+
+      reg:
+        maxItems: 1
+
+      spi-max-frequency:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Maximum Quad SPI clocking speed of the device in Hz.
+
+      spi-rx-bus-width:
+        description:
+          Bus width to the Quad SPI bus used for read transfers.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [1, 2, 4]
+
+      spi-tx-bus-width:
+        description:
+          Bus width to the Quad SPI bus used for write transfers.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        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
+
+additionalProperties: true
+
+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>;
+            };
+    };
Signature · 1 line
2.7.4
maintainer
#4 lore raw

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

Quoted 16 lines · Sowjanya Komatineni

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

---
 .../bindings/spi/nvidia,tegra210-quad.yaml         | 130 +++++++++++++++++++++
 1 file changed, 130 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +1 -0
new file mode 100644
index 0000000..0b5fea6
@@ -0,0 +1,130 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)

Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml line 11

Quoted 10 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +10 -0
+%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#

Quoted 25 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +25 -0
+
+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
+

Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml line 46

Quoted 10 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +10 -0
+  dmas:
+    maxItems: 2
+
+  dma-names:
+    items:
+      - const: rx
+      - const: tx
+
+patternProperties:
+  "^.*@[0-9a-f]+":

You can drop '^.*'.

Quoted 16 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +16 -0
+    type: object
+
+    properties:
+      compatible:
+        description:
+          Compatible of the SPI device.
+
+      reg:
+        maxItems: 1
+
+      spi-max-frequency:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Maximum Quad SPI clocking speed of the device in Hz.
+
+      spi-rx-bus-width:

Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml line 72

Quoted 10 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +10 -0
+        description:
+          Bus width to the Quad SPI bus used for read transfers.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [1, 2, 4]
+
+      spi-tx-bus-width:
+        description:
+          Bus width to the Quad SPI bus used for write transfers.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [1, 2, 4]

All of the above 5 properties are covered by spi-controller.yaml. You only need additional constraints here. As 8-bit mode is not supported, you need:

spi-tx-bus-width:
enum: [1, 2, 4]

Quoted 8 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +8 -0
+
+      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

Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml line 90

Quoted 10 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +10 -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

Please include these properties in your example.

Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml line 103

Quoted 13 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +13 -0
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clock-names
+  - clocks
+  - resets
+
+additionalProperties: true

That's generally wrong unless it's a schema to be included by other schemas.

unevaluatedProperties: false

Quoted 30 lines
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml new file +27 -0
+
+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>;
+            };
+    };
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH v3 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
#6 lore raw

PATCH v3 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 | 1387 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 1397 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 +1387 -0

1,387 lines not on this page · raw message

Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH v3 4/9] spi: tegra210-quad: Add support for Tegra210 QSPI controller

Quoted 1 line · Sowjanya Komatineni

Tegra SoC has a Quad SPI controller starting from Tegra210.

The probe/remove hooks LGTM now. Just two tiny nits that caught my eye:

drivers/spi/spi-tegra210-quad.c line 1198

Quoted 5 lines
drivers/spi/spi-tegra210-quad.c new file +5 -0
+	master = devm_spi_alloc_master(&pdev->dev, sizeof(*tqspi));
+	if (!master) {
+		dev_err(&pdev->dev, "failed to allocate spi_master\n");
+		return -ENOMEM;
+	}

The memory allocater already emits an error message if it can't satisfy a request. Emitting an additional message here isn't really necessary.

Quoted 7 lines
drivers/spi/spi-tegra210-quad.c new file +7 -0
+exit_free_irq:
+	free_irq(qspi_irq, tqspi);
+exit_pm_disable:
+	pm_runtime_disable(&pdev->dev);
+	tegra_qspi_deinit_dma(tqspi);
+	return ret;
+}

drivers/spi/spi-tegra210-quad.c line 1309

Quoted 10 lines
drivers/spi/spi-tegra210-quad.c new file +10 -0
+
+static int tegra_qspi_remove(struct platform_device *pdev)
+{
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct tegra_qspi *tqspi = spi_master_get_devdata(master);
+
+	spi_unregister_master(master);
+	free_irq(tqspi->irq, tqspi);
+	tegra_qspi_deinit_dma(tqspi);
+	pm_runtime_disable(&pdev->dev);

The order of tegra_qspi_deinit_dma() and pm_runtime_disable() is reversed in the remove hook vis-a-vis the probe error path. It's nicer to use the same order as in the probe error path.

Thanks,

Lukas

author maintainer
#8 lore raw

PATCH v3 5/9 spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

In reply to Sowjanya Komatineni

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

For controller with this flag set, spi-mem driver will skip dummy bytes transfer in the spi message.

Controller drivers can get the number of dummy cycles from spi_message.

---
 drivers/spi/spi-mem.c   | 18 +++++++++++-------
 include/linux/spi/spi.h |  8 ++++++++
 2 files changed, 19 insertions(+), 7 deletions(-)
drivers/spi/spi-mem.c +11 -7
index f3a3f19..38a523b 100644
@@ -350,13 +350,17 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 	}
 
 	if (op->dummy.nbytes) {
-		memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
-		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
-		xfers[xferpos].len = op->dummy.nbytes;
-		xfers[xferpos].tx_nbits = op->dummy.buswidth;
-		spi_message_add_tail(&xfers[xferpos], &msg);
-		xferpos++;
-		totalxferlen += op->dummy.nbytes;
+		if (ctlr->flags & SPI_MASTER_USES_HW_DUMMY_CYCLES) {
+			msg.dummy_cycles = (op->dummy.nbytes * 8) / op->dummy.buswidth;
+		} else {
+			memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
+			xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
+			xfers[xferpos].len = op->dummy.nbytes;
+			xfers[xferpos].tx_nbits = op->dummy.buswidth;
+			spi_message_add_tail(&xfers[xferpos], &msg);
+			xferpos++;
+			totalxferlen += op->dummy.nbytes;
+		}
 	}
 
 	if (op->data.nbytes) {
include/linux/spi/spi.h +8 -0
index aa09fdc..2024149 100644
@@ -512,6 +512,8 @@ struct spi_controller {
 
 #define SPI_MASTER_GPIO_SS		BIT(5)	/* GPIO CS must select slave */
 
+#define SPI_MASTER_USES_HW_DUMMY_CYCLES	BIT(6)	/* HW dummy bytes transfer */
+
 	/* flag indicating this is an SPI slave controller */
 	bool			slave;
 
@@ -1022,6 +1024,12 @@ struct spi_message {
 	unsigned		actual_length;
 	int			status;
 
+	/*
+	 * dummy cycles in the message transfer. This is used by the controller
+	 * drivers supports transfer of dummy cycles directly by the hardware.
+	 */
+	u8			dummy_cycles;
+
 	/* for optional use by whatever driver currently owns the
 	 * spi_message ...  between calls to spi_async and then later
 	 * complete(), that's the spi_controller controller driver.
Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

Quoted 2 lines · On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni…

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

If we go for those core changes, we should at least add a ctrl->max_dummy_cycles field so the core can fallback to regular writes when the number of dummy cycles in the spi_mem_op exceeds what the controller can do.

Quoted 67 lines

For controller with this flag set, spi-mem driver will skip dummy bytes transfer in the spi message.

Controller drivers can get the number of dummy cycles from spi_message.

---
 drivers/spi/spi-mem.c   | 18 +++++++++++-------
 include/linux/spi/spi.h |  8 ++++++++
 2 files changed, 19 insertions(+), 7 deletions(-)
drivers/spi/spi-mem.c +11 -7
index f3a3f19..38a523b 100644
@@ -350,13 +350,17 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
 	}
 
 	if (op->dummy.nbytes) {
-		memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
-		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
-		xfers[xferpos].len = op->dummy.nbytes;
-		xfers[xferpos].tx_nbits = op->dummy.buswidth;
-		spi_message_add_tail(&xfers[xferpos], &msg);
-		xferpos++;
-		totalxferlen += op->dummy.nbytes;
+		if (ctlr->flags & SPI_MASTER_USES_HW_DUMMY_CYCLES) {
+			msg.dummy_cycles = (op->dummy.nbytes * 8) / op->dummy.buswidth;
+		} else {
+			memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
+			xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
+			xfers[xferpos].len = op->dummy.nbytes;
+			xfers[xferpos].tx_nbits = op->dummy.buswidth;
+			spi_message_add_tail(&xfers[xferpos], &msg);
+			xferpos++;
+			totalxferlen += op->dummy.nbytes;
+		}
 	}
 
 	if (op->data.nbytes) {
include/linux/spi/spi.h +8 -0
index aa09fdc..2024149 100644
@@ -512,6 +512,8 @@ struct spi_controller {
 
 #define SPI_MASTER_GPIO_SS		BIT(5)	/* GPIO CS must select slave */
 
+#define SPI_MASTER_USES_HW_DUMMY_CYCLES	BIT(6)	/* HW dummy bytes transfer */
+
 	/* flag indicating this is an SPI slave controller */
 	bool			slave;
 
@@ -1022,6 +1024,12 @@ struct spi_message {
 	unsigned		actual_length;
 	int			status;
 
+	/*
+	 * dummy cycles in the message transfer. This is used by the controller
+	 * drivers supports transfer of dummy cycles directly by the hardware.
+	 */
+	u8			dummy_cycles;
+
 	/* for optional use by whatever driver currently owns the
 	 * spi_message ...  between calls to spi_async and then later
 	 * complete(), that's the spi_controller controller driver.
author maintainer
#10 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

Quoted 9 lines · Boris Brezillon
Quoted 2 lines · On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni…

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

dummy cycles programming is SPI device specific.

Transfer of dummy bytes by SW or HW controller can be depending on features supported by controller.

Adding controller driver specific exec_op() Just for skipping dummy bytes transfer will have so much of redundant code pretty much what all spi_mem_exec_op does.

So in v1, I handled this in controller driver by skipping SW transfer of dummy bytes during dummy phase and programming dummy cycles in controller register to allow HW to transfer.

Based on v1 feedback discussion, added this flag SPI_MASTER_USES_HW_DUMMY_CYCLES which can be used by controllers supporting HW dummy bytes transfer and updated spi_mem_exec_op to skip SW dummy bytes.

This helps other controllers supporting HW transfer of dummy bytes as well just to set the flag and use dummy cycles directly.

Quoted 4 lines

If we go for those core changes, we should at least add a ctrl->max_dummy_cycles field so the core can fallback to regular writes when the number of dummy cycles in the spi_mem_op exceeds what the controller can do.

Yes makes sense. Will add this once we decide on keeping this flag to identify controllers supporting HW transfer of dummy bytes Vs SW transfer.

Quoted 66 lines
Quoted 66 lines

For controller with this flag set, spi-mem driver will skip dummy bytes transfer in the spi message.

Controller drivers can get the number of dummy cycles from spi_message.

---
  drivers/spi/spi-mem.c   | 18 +++++++++++-------
  include/linux/spi/spi.h |  8 ++++++++
  2 files changed, 19 insertions(+), 7 deletions(-)
drivers/spi/spi-mem.c +11 -7
index f3a3f19..38a523b 100644
@@ -350,13 +350,17 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
  	}
 
  	if (op->dummy.nbytes) {
-		memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
-		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
-		xfers[xferpos].len = op->dummy.nbytes;
-		xfers[xferpos].tx_nbits = op->dummy.buswidth;
-		spi_message_add_tail(&xfers[xferpos], &msg);
-		xferpos++;
-		totalxferlen += op->dummy.nbytes;
+		if (ctlr->flags & SPI_MASTER_USES_HW_DUMMY_CYCLES) {
+			msg.dummy_cycles = (op->dummy.nbytes * 8) / op->dummy.buswidth;
+		} else {
+			memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
+			xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
+			xfers[xferpos].len = op->dummy.nbytes;
+			xfers[xferpos].tx_nbits = op->dummy.buswidth;
+			spi_message_add_tail(&xfers[xferpos], &msg);
+			xferpos++;
+			totalxferlen += op->dummy.nbytes;
+		}
  	}
 
  	if (op->data.nbytes) {
include/linux/spi/spi.h +8 -0
index aa09fdc..2024149 100644
@@ -512,6 +512,8 @@ struct spi_controller {
 
  #define SPI_MASTER_GPIO_SS		BIT(5)	/* GPIO CS must select slave */
 
+#define SPI_MASTER_USES_HW_DUMMY_CYCLES	BIT(6)	/* HW dummy bytes transfer */
+
  	/* flag indicating this is an SPI slave controller */
  	bool			slave;
 
@@ -1022,6 +1024,12 @@ struct spi_message {
  	unsigned		actual_length;
  	int			status;
 
+	/*
+	 * dummy cycles in the message transfer. This is used by the controller
+	 * drivers supports transfer of dummy cycles directly by the hardware.
+	 */
+	u8			dummy_cycles;
+
  	/* for optional use by whatever driver currently owns the
  	 * spi_message ...  between calls to spi_async and then later
  	 * complete(), that's the spi_controller controller driver.
#11 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

Quoted 24 lines · On Sat, 12 Dec 2020 09:28:50 -0800 Sowjanya Komatineni…
Quoted 9 lines · Boris Brezillon
Quoted 2 lines · On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni…

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

dummy cycles programming is SPI device specific.

Transfer of dummy bytes by SW or HW controller can be depending on features supported by controller.

Adding controller driver specific exec_op() Just for skipping dummy bytes transfer will have so much of redundant code pretty much what all spi_mem_exec_op does.

So in v1, I handled this in controller driver by skipping SW transfer of dummy bytes during dummy phase and programming dummy cycles in controller register to allow HW to transfer.

Quoted 7 lines

Based on v1 feedback discussion, added this flag SPI_MASTER_USES_HW_DUMMY_CYCLES which can be used by controllers supporting HW dummy bytes transfer and updated spi_mem_exec_op to skip SW dummy bytes.

This helps other controllers supporting HW transfer of dummy bytes as well just to set the flag and use dummy cycles directly.

Except saying a spi_message has X dummy cycle is not precise enough. Where are those dummy cycles in the transfer sequence? spi-mem has well defined sequencing (cmd[+addr][+dummy][+data]) so we know exacly where dummy cycles are, but trying to retro-fit the dummy-cycle concept in the generic spi_message is confusing IMHO. If want to avoid code duplication, I'm pretty sure the driver can be reworked so the spi_transfer/exec_op() path can share most of the logic (that probably implies declaring a tegra_qspi_op).

Quoted 73 lines
Quoted 5 lines

If we go for those core changes, we should at least add a ctrl->max_dummy_cycles field so the core can fallback to regular writes when the number of dummy cycles in the spi_mem_op exceeds what the controller can do.

Yes makes sense. Will add this once we decide on keeping this flag to identify controllers supporting HW transfer of dummy bytes Vs SW transfer.

Quoted 66 lines
Quoted 66 lines

For controller with this flag set, spi-mem driver will skip dummy bytes transfer in the spi message.

Controller drivers can get the number of dummy cycles from spi_message.

---
  drivers/spi/spi-mem.c   | 18 +++++++++++-------
  include/linux/spi/spi.h |  8 ++++++++
  2 files changed, 19 insertions(+), 7 deletions(-)
drivers/spi/spi-mem.c +11 -7
index f3a3f19..38a523b 100644
@@ -350,13 +350,17 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
  	}
 
  	if (op->dummy.nbytes) {
-		memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
-		xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
-		xfers[xferpos].len = op->dummy.nbytes;
-		xfers[xferpos].tx_nbits = op->dummy.buswidth;
-		spi_message_add_tail(&xfers[xferpos], &msg);
-		xferpos++;
-		totalxferlen += op->dummy.nbytes;
+		if (ctlr->flags & SPI_MASTER_USES_HW_DUMMY_CYCLES) {
+			msg.dummy_cycles = (op->dummy.nbytes * 8) / op->dummy.buswidth;
+		} else {
+			memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
+			xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
+			xfers[xferpos].len = op->dummy.nbytes;
+			xfers[xferpos].tx_nbits = op->dummy.buswidth;
+			spi_message_add_tail(&xfers[xferpos], &msg);
+			xferpos++;
+			totalxferlen += op->dummy.nbytes;
+		}
  	}
 
  	if (op->data.nbytes) {
include/linux/spi/spi.h +8 -0
index aa09fdc..2024149 100644
@@ -512,6 +512,8 @@ struct spi_controller {
 
  #define SPI_MASTER_GPIO_SS		BIT(5)	/* GPIO CS must select slave */
 
+#define SPI_MASTER_USES_HW_DUMMY_CYCLES	BIT(6)	/* HW dummy bytes transfer */
+
  	/* flag indicating this is an SPI slave controller */
  	bool			slave;
 
@@ -1022,6 +1024,12 @@ struct spi_message {
  	unsigned		actual_length;
  	int			status;
 
+	/*
+	 * dummy cycles in the message transfer. This is used by the controller
+	 * drivers supports transfer of dummy cycles directly by the hardware.
+	 */
+	u8			dummy_cycles;
+
  	/* for optional use by whatever driver currently owns the
  	 * spi_message ...  between calls to spi_async and then later
  	 * complete(), that's the spi_controller controller driver.  
#12 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

Quoted 35 lines · On Sun, 13 Dec 2020 10:54:26 +0100 Boris Brezillon…
Quoted 24 lines · On Sat, 12 Dec 2020 09:28:50 -0800 Sowjanya Komatineni…
Quoted 9 lines · Boris Brezillon
Quoted 2 lines · On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni…

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

dummy cycles programming is SPI device specific.

Transfer of dummy bytes by SW or HW controller can be depending on features supported by controller.

Adding controller driver specific exec_op() Just for skipping dummy bytes transfer will have so much of redundant code pretty much what all spi_mem_exec_op does.

So in v1, I handled this in controller driver by skipping SW transfer of dummy bytes during dummy phase and programming dummy cycles in controller register to allow HW to transfer.

Quoted 7 lines

Based on v1 feedback discussion, added this flag SPI_MASTER_USES_HW_DUMMY_CYCLES which can be used by controllers supporting HW dummy bytes transfer and updated spi_mem_exec_op to skip SW dummy bytes.

This helps other controllers supporting HW transfer of dummy bytes as well just to set the flag and use dummy cycles directly.

Quoted 8 lines

Except saying a spi_message has X dummy cycle is not precise enough. Where are those dummy cycles in the transfer sequence? spi-mem has well defined sequencing (cmd[+addr][+dummy][+data]) so we know exacly where dummy cycles are, but trying to retro-fit the dummy-cycle concept in the generic spi_message is confusing IMHO. If want to avoid code duplication, I'm pretty sure the driver can be reworked so the spi_transfer/exec_op() path can share most of the logic (that probably implies declaring a tegra_qspi_op).

Something like that might also do the trick:

--->8---

drivers/spi/spi-mem.c +1 -0
index ef53290b7d24..8b0476f37fbb 100644
@@ -353,6 +353,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 +5 -0
index 99380c0825db..ecf7989318c5 100644
@@ -807,6 +807,10 @@ 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: set to 1 for a dummy transfer (a transfer whose data is
+ *      ignored). Controllers that are able to issue dummy cycles can ignore
+ *      tx_buf, for those that can't tx_buf will contain dummy bytes. The
+ *      number of  dummy cycles to issue is (len * tx_bits) / 8.
  * @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
@@ -919,6 +923,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;
author maintainer
#13 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

Quoted 76 lines · Boris Brezillon
Quoted 33 lines · On Sun, 13 Dec 2020 10:54:26 +0100 Boris Brezillon…
Quoted 23 lines · On Sat, 12 Dec 2020 09:28:50 -0800 Sowjanya Komatineni…
Quoted 9 lines · Boris Brezillon
Quoted 2 lines · On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni…

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

dummy cycles programming is SPI device specific.

Transfer of dummy bytes by SW or HW controller can be depending on features supported by controller.

Adding controller driver specific exec_op() Just for skipping dummy bytes transfer will have so much of redundant code pretty much what all spi_mem_exec_op does.

So in v1, I handled this in controller driver by skipping SW transfer of dummy bytes during dummy phase and programming dummy cycles in controller register to allow HW to transfer.

Quoted 7 lines

Based on v1 feedback discussion, added this flag SPI_MASTER_USES_HW_DUMMY_CYCLES which can be used by controllers supporting HW dummy bytes transfer and updated spi_mem_exec_op to skip SW dummy bytes.

This helps other controllers supporting HW transfer of dummy bytes as well just to set the flag and use dummy cycles directly.

Quoted 8 lines

Except saying a spi_message has X dummy cycle is not precise enough. Where are those dummy cycles in the transfer sequence? spi-mem has well defined sequencing (cmd[+addr][+dummy][+data]) so we know exacly where dummy cycles are, but trying to retro-fit the dummy-cycle concept in the generic spi_message is confusing IMHO. If want to avoid code duplication, I'm pretty sure the driver can be reworked so the spi_transfer/exec_op() path can share most of the logic (that probably implies declaring a tegra_qspi_op).

Something like that might also do the trick:

--->8---

drivers/spi/spi-mem.c +1 -0
index ef53290b7d24..8b0476f37fbb 100644
@@ -353,6 +353,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 +4 -0
index 99380c0825db..ecf7989318c5 100644
@@ -807,6 +807,10 @@ 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: set to 1 for a dummy transfer (a transfer whose data is
+ *      ignored). Controllers that are able to issue dummy cycles can ignore
+ *      tx_buf, for those that can't tx_buf will contain dummy bytes. The
+ *      number of  dummy cycles to issue is (len * tx_bits) / 8.
   * @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

include/linux/spi/spi.h struct spi_transfer { · line 929

Quoted 7 lines
include/linux/spi/spi.h +1 -0
@@ -919,6 +923,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;

Thanks Boris.

Sorry was thinking of spi flash device only as we only support quad spi flash on Tegra QSPI interface.

But to make it more generic where spi message preparation can happen from any client driver, agree order of transfers may vary.

Also having controller driver implement exec_op callback is also not useful considering cases where spi message transfers dont' go thru spi_mem.

Yes adding dummy_data field to indicate transfer is dummy bytes transfer helps for any types of message transfers.

Tegra QSPI controller dummy cycles need be programmed with transfer after which dummy cycles are needed.

So, will have v4 to add dummy_data to spi_transfer and will update controller driver to convert dummy bytes to dummy cycles and program dummy cycles with its previous transfer and skip dummy transfer buffer.

Thanks

Sowjanya

maintainer
#14 lore raw

Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware

In reply to Boris Brezillon
Quoted 9 lines · Boris Brezillon
Quoted 2 lines · Sowjanya Komatineni

This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers that support transfer of dummy cycles by the hardware directly.

Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one.

I *have* seen other high speed devices which had padding bits in the transfer (see regmap's pad_bits feature), I think that corresponds to flash dummy bits but haven't checked that the hardware support lines up. I'm not sure it's ever been seen as something that we particularly needed to speed up with hardware offload though.

Quoted 4 lines

If we go for those core changes, we should at least add a ctrl->max_dummy_cycles field so the core can fallback to regular writes when the number of dummy cycles in the spi_mem_op exceeds what the controller can do.

That seems sensible if there's a risk of controllers being too limited, which knowing hardware seems likely.

author maintainer
#15 lore raw

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

In reply to Sowjanya Komatineni

Tegra Quad SPI controller hardware supports sending dummy cycles after address bytes.

This patch adds this support.

---
 drivers/spi/spi-tegra210-quad.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra210-quad.c +21 -1
index 624f395..1d1b125 100644
@@ -124,6 +124,13 @@
 #define QSPI_DMA_TIMEOUT			(msecs_to_jiffies(1000))
 #define DEFAULT_QSPI_DMA_BUF_LEN		(64 * 1024)
 
+enum transfer_phase {
+	CMD_BYTE_XFER = 0,
+	ADDR_BYTES_XFER,
+	DATA_BYTES_XFER,
+	MAX_XFERS,
+};
+
 struct tegra_qspi_client_data {
 	int tx_clk_tap_delay;
 	int rx_clk_tap_delay;
@@ -857,6 +864,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;
@@ -977,7 +986,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	struct spi_device *spi = msg->spi;
 	struct spi_transfer *xfer;
 	bool is_first_msg = true;
-	int ret;
+	int ret, xfer_phase = 0;
 
 	msg->status = 0;
 	msg->actual_length = 0;
@@ -987,6 +996,15 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		u32 cmd1;
 
+		/*
+		 * Program dummy clock cycles in Tegra QSPI register only
+		 * during address transfer phase.
+		 */
+		if (xfer_phase == ADDR_BYTES_XFER)
+			tqspi->dummy_cycles = msg->dummy_cycles;
+		else
+			tqspi->dummy_cycles = 0;
+
 		reinit_completion(&tqspi->xfer_completion);
 
 		cmd1 = tegra_qspi_setup_transfer_one(spi, xfer, is_first_msg);
@@ -1018,6 +1036,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 		}
 
 		msg->actual_length += xfer->len;
+		xfer_phase++;
 
 complete_xfer:
 		if (ret < 0) {
@@ -1203,6 +1222,7 @@ static int tegra_qspi_probe(struct platform_device *pdev)
 	master->mode_bits = SPI_MODE_0 | SPI_MODE_3 | SPI_CS_HIGH |
 			    SPI_TX_DUAL | SPI_RX_DUAL | SPI_TX_QUAD | SPI_RX_QUAD;
 	master->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) | SPI_BPW_MASK(8);
+	master->flags = SPI_MASTER_USES_HW_DUMMY_CYCLES;
 	master->setup = tegra_qspi_setup;
 	master->cleanup = tegra_qspi_cleanup;
 	master->transfer_one_message = tegra_qspi_transfer_one_message;
Signature · 1 line
2.7.4
#16 lore raw

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

Quoted 48 lines · On Fri, 11 Dec 2020 13:16:00 -0800 Sowjanya Komatineni…

Tegra Quad SPI controller hardware supports sending dummy cycles after address bytes.

This patch adds this support.

---
 drivers/spi/spi-tegra210-quad.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/spi/spi-tegra210-quad.c +10 -1
index 624f395..1d1b125 100644
@@ -124,6 +124,13 @@
 #define QSPI_DMA_TIMEOUT			(msecs_to_jiffies(1000))
 #define DEFAULT_QSPI_DMA_BUF_LEN		(64 * 1024)
 
+enum transfer_phase {
+	CMD_BYTE_XFER = 0,
+	ADDR_BYTES_XFER,
+	DATA_BYTES_XFER,
+	MAX_XFERS,
+};
+
 struct tegra_qspi_client_data {
 	int tx_clk_tap_delay;
 	int rx_clk_tap_delay;
@@ -857,6 +864,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;
@@ -977,7 +986,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	struct spi_device *spi = msg->spi;
 	struct spi_transfer *xfer;
 	bool is_first_msg = true;
-	int ret;
+	int ret, xfer_phase = 0;
 
 	msg->status = 0;
 	msg->actual_length = 0;
@@ -987,6 +996,15 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {

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

Quoted 10 lines
drivers/spi/spi-tegra210-quad.c +8 -0
 		u32 cmd1;
 
+		/*
+		 * Program dummy clock cycles in Tegra QSPI register only
+		 * during address transfer phase.
+		 */
+		if (xfer_phase == ADDR_BYTES_XFER)
+			tqspi->dummy_cycles = msg->dummy_cycles;
+		else
+			tqspi->dummy_cycles = 0;

That's fragile. You're trying to guess the phase (which is clearly a spi-mem concept) from the position of the transfer in the list. What happens if a spi-mem operation has no address bytes but requires dummy cycles after the command? What happens if we patch spi_mem_exec_op() to merge the cmd and address bytes in a single transfer (that's an option I considered at some point when designing the framework before deciding it was not worth the extra complexity)?

Besides, I keep thinking the regular transfer path should not assume it's being passed spi-mem operations, if it is, that means you should overload the default exec_op(). The more I look at it the less I like this idea of adding a dummy_cycles field to spi_message. I'm pretty sure we can find other ways to avoid code duplication if that's your main concern.

Quoted 20 lines
drivers/spi/spi-tegra210-quad.c +3 -0
+
 		reinit_completion(&tqspi->xfer_completion);
 
 		cmd1 = tegra_qspi_setup_transfer_one(spi, xfer, is_first_msg);
@@ -1018,6 +1036,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi
 		}
 
 		msg->actual_length += xfer->len;
+		xfer_phase++;
 
 complete_xfer:
 		if (ret < 0) {
@@ -1203,6 +1222,7 @@ static int tegra_qspi_probe(struct platform_device *pdev)
 	master->mode_bits = SPI_MODE_0 | SPI_MODE_3 | SPI_CS_HIGH |
 			    SPI_TX_DUAL | SPI_RX_DUAL | SPI_TX_QUAD | SPI_RX_QUAD;
 	master->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) | SPI_BPW_MASK(8);
+	master->flags = SPI_MASTER_USES_HW_DUMMY_CYCLES;
 	master->setup = tegra_qspi_setup;
 	master->cleanup = tegra_qspi_cleanup;
 	master->transfer_one_message = tegra_qspi_transfer_one_message;
author maintainer
#17 lore raw

PATCH v3 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 v3 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 | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194.dtsi +24 -0
index 25f36d6..63ed788 100644
@@ -609,6 +609,30 @@
 			status = "disabled";
 		};
 
+		spi@3270000 {
+			compatible = "nvidia,tegra194-qspi";
+			reg = <0x3270000 0x1000>;
+			interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
+			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>;
+			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 v3 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