Skip to contentSkip to conversation

add support for Cadence's XSPI controller

PATCH Superseded Parshuram Thombare 4 participants 20 messages Sep 1, 2021 – Sep 8, 2021

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover add support for Cadence's XSPI controller

This patch series adds support for Cadence's XSPI controller. It supports 3 work modes.
1. ACMD (auto command) work mode
ACMD name is because it uses auto command engine in the controller. It further has 2 modes PIO and CDMA (command DMA).
The CDMA work mode is dedicated for high-performance application where very low software overhead is required. In this mode the Command Engine is programmed by the series of linked descriptors stored in system memory. These descriptors provide commands to execute and store status information for finished commands.
The PIO mode work mode is dedicated for single operation where constructing a linked list of descriptors would require too much effort.
2. STIG (Software Triggered Instruction Generator) work mode
In STIG mode, controller sends low-level instructions to memory. Each instruction is 128-bit width. There is special instruction DataSequence which carries information about data phase. Driver uses Slave DMA interface to transfer data as only this interface can be used in STIG work mode.
3. Direct work mode
This work mode allows sending data without invoking any command through the slave interface.
Currently ACMD PIO mode is used for NOR flash read, program, erase operations, all other operations are handled in STIG work mode.

Changes since v2:
1. Removed extra lock around exec_op.
2. Removed PHY parameters setting from the driver, those will be handled by bootstrap pins available in the controller.

Changes since v1:
1. Use ACMD PIO work mode for NOR read, program and erase operations, for everything else use STIG(Software Triggered Instruction Generator) work mode.
2. Changes suggested by Lukas.

Parshuram Thombare (2):
spi: cadence: add dt-bindings documentation for Cadence XSPI
controller
spi: cadence: add support for Cadence XSPI controller

 .../devicetree/bindings/spi/cdns,xspi.yaml         |  66 ++
 drivers/spi/Kconfig                                |  11 +
 drivers/spi/Makefile                               |   1 +
 drivers/spi/spi-cadence-xspi.c                     | 837 +++++++++++++++++++++
 4 files changed, 915 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/cdns,xspi.yaml
 create mode 100644 drivers/spi/spi-cadence-xspi.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/2 spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Add DT binding for Cadence's XSPI controller driver.

---
 .../devicetree/bindings/spi/cdns,xspi.yaml         | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/cdns,xspi.yaml
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +66 -0
new file mode 100644
index 0000000..e52d6fa
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2020-21 Cadence
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/spi/cdns,xspi.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Cadence XSPI Controller
+
+maintainers:
+  - Parshuram Thombare <[email protected]>
+
+description: |
+  The XSPI controller allows SPI protocol communication in
+  single, dual, quad or octal wire transmission modes for
+  read/write access to slaves such as SPI-NOR flash.
+
+properties:
+  compatible:
+    const: cdns,xspi-nor
+
+  reg:
+    items:
+      - description: address and length of the controller register set
+      - description: address and length of the Slave DMA data port
+      - description: address and length of the auxiliary registers
+
+  reg-names:
+    items:
+      - const: xspi-iobase
+      - const: xspi-sdmabase
+      - const: xspi-auxbase
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    xspi: spi@a0010000 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "cdns,xspi-nor";
+        reg = <0x0 0xa0010000 0x0 0x10000>,
+              <0x0 0xb0000000 0x0 0x10000>,
+              <0x0 0xa0020000 0x0 0x10000>;
+        reg-names = "xspi-iobase", "xspi-sdmabase", "xspi-auxbase";
+        interrupts = <0 90 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-parent = <&gic>;
+        mt35xu512@0 {
+            compatible = "spi-nor", "micron,mt35xu512";
+            spi-max-frequency = <75000000>;
+            reg = <0>;
+        };
+        mt35xu512@1 {
+            compatible = "spi-nor", "micron,mt35xu512";
+            spi-max-frequency = <75000000>;
+            reg = <1>;
+        };
+    };
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Quoted 10 lines · Parshuram Thombare

Add DT binding for Cadence's XSPI controller driver.

---
 .../devicetree/bindings/spi/cdns,xspi.yaml         | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/cdns,xspi.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/spi/cdns,xspi.yaml: 'additionalProperties' is a required property
hint: A schema without a "$ref" to another schema must define all properties and use "additionalProperties"
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/spi/cdns,xspi.yaml: ignoring, error in schema:
warning: no schema found in file: ./Documentation/devicetree/bindings/spi/cdns,xspi.yaml /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml: example-0: spi@a0010000:reg:0: [0, 2684420096, 0, 65536] is too long
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml: example-0: spi@a0010000:reg:1: [0, 2952790016, 0, 65536] is too long
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml: example-0: spi@a0010000:reg:2: [0, 2684485632, 0, 65536] is too long
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml:0:0: /example-0/spi@a0010000: failed to match any schema with compatible: ['cdns,xspi-nor'] Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml:0:0: /example-0/spi@a0010000/mt35xu512@0: failed to match any schema with compatible: ['spi-nor', 'micron,mt35xu512'] Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml:0:0: /example-0/spi@a0010000/mt35xu512@0: failed to match any schema with compatible: ['spi-nor', 'micron,mt35xu512'] Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml:0:0: /example-0/spi@a0010000/mt35xu512@1: failed to match any schema with compatible: ['spi-nor', 'micron,mt35xu512'] Documentation/devicetree/bindings/spi/cdns,xspi.example.dt.yaml:0:0: /example-0/spi@a0010000/mt35xu512@1: failed to match any schema with compatible: ['spi-nor', 'micron,mt35xu512']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1523137

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

#3 lore raw

RE: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Hi Rob,

Quoted 8 lines

See
https://urldefense.com/v3/__https://patchwork.ozlabs.org/patch/1523137__;!!E
HscmS1ygiU1lA!V71KMbkd1YPERLm96tbPDX_W05cj0TCcttcwVXU9H3lDADvSBnc 5GbQunqxwGIA$

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

Quoted 7 lines

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

Thanks for your reply. I will fix this issue in next version of patchset.

Regards,
Parshuram Thombare

#4 lore raw

Re: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

In reply to Parshuram Thombare
Quoted 22 lines · Parshuram Thombare

Add DT binding for Cadence's XSPI controller driver.

---
 .../devicetree/bindings/spi/cdns,xspi.yaml         | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/cdns,xspi.yaml
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +6 -0
new file mode 100644
index 0000000..e52d6fa
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2020-21 Cadence
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/spi/cdns,xspi.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"

Documentation/devicetree/bindings/spi/cdns,xspi.yaml line 16

Quoted 10 lines
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +10 -0
+
+title: Cadence XSPI Controller
+
+maintainers:
+  - Parshuram Thombare <[email protected]>
+
+description: |
+  The XSPI controller allows SPI protocol communication in
+  single, dual, quad or octal wire transmission modes for
+  read/write access to slaves such as SPI-NOR flash.

This needs to be a "subclass" of the spi-controller.yaml binding.

allOf:
- $ref: spi-controller.yaml#

Quoted 30 lines
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +30 -0
+
+properties:
+  compatible:
+    const: cdns,xspi-nor
+
+  reg:
+    items:
+      - description: address and length of the controller register set
+      - description: address and length of the Slave DMA data port
+      - description: address and length of the auxiliary registers
+
+  reg-names:
+    items:
+      - const: xspi-iobase
+      - const: xspi-sdmabase
+      - const: xspi-auxbase
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    xspi: spi@a0010000 {

Documentation/devicetree/bindings/spi/cdns,xspi.yaml line 56

Quoted 10 lines
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +10 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        compatible = "cdns,xspi-nor";
+        reg = <0x0 0xa0010000 0x0 0x10000>,
+              <0x0 0xb0000000 0x0 0x10000>,
+              <0x0 0xa0020000 0x0 0x10000>;
+        reg-names = "xspi-iobase", "xspi-sdmabase", "xspi-auxbase";
+        interrupts = <0 90 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-parent = <&gic>;
+        mt35xu512@0 {

Node name should be flash@0.

Documentation/devicetree/bindings/spi/cdns,xspi.yaml line 57

Quoted 1 line
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +1 -0
+            compatible = "spi-nor", "micron,mt35xu512";

These compatibles are arbitrary and undocumented. You probably just need "jedec,spi-nor". If you need anything else, you need to justify why.

Please run dt_binding_check, it should point this out. See [0].

Documentation/devicetree/bindings/spi/cdns,xspi.yaml line 62

Quoted 5 lines
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +5 -0
+            spi-max-frequency = <75000000>;
+            reg = <0>;
+        };
+        mt35xu512@1 {
+            compatible = "spi-nor", "micron,mt35xu512";

Same as above.

Quoted 7 lines
Documentation/devicetree/bindings/spi/cdns,xspi.yaml new file +4 -0
+            spi-max-frequency = <75000000>;
+            reg = <1>;
+        };
+    };
Signature · 1 line
2.7.4

[0] https://www.kernel.org/doc/html/latest/devicetree/bindings/writing-schema.html#testing

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#5 lore raw

RE: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Quoted 4 lines

This needs to be a "subclass" of the spi-controller.yaml binding.

allOf:
- $ref: spi-controller.yaml#

Isn't stating that validation need against spi-controller.yaml as well as this schema sufficient ? Can you please point an example how to make controller binding a "subclass" of spi-controller.yaml binding ?

Quoted 1 line

Node name should be flash@0.

I think spi-controller.yaml uses wildcard for the name of a device node, so anything in string@hexvalue: should work.

Quoted 4 lines
Quoted 1 line

+ compatible = "spi-nor", "micron,mt35xu512";

These compatibles are arbitrary and undocumented. You probably just need "jedec,spi-nor". If you need anything else, you need to justify why.

Although just "spi-nor" also works, I agree to use "jedec, spi-nor" and drop device name.

Regards,
Parshuram Thombare

#6 lore raw

Re: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Quoted 8 lines · Parshuram Raju Thombare
Quoted 4 lines

This needs to be a "subclass" of the spi-controller.yaml binding.

allOf:
- $ref: spi-controller.yaml#

Isn't stating that validation need against spi-controller.yaml as well as this schema sufficient ? Can you please point an example how to make controller binding a "subclass" of spi-controller.yaml binding ?

I just showed you. You need to add the below lines:

allOf:
- $ref: spi-controller.yaml#

See cdns,qspi-nor.yaml or nvidia,tegra210-quad.yaml or any of the multiple controller bindings we already have.

By "subclass" I did not mean a programming construct, I just meant it should logically be a subclass of the spi-controller.yaml binding, which can be done by the allOf.

Quoted 5 lines
Quoted 2 lines

Node name should be flash@0.

I think spi-controller.yaml uses wildcard for the name of a device node, so anything in string@hexvalue: should work.

Sure, but mtd.yaml (which the SPI NOR binding depends on) requires it.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

+ compatible = "spi-nor", "micron,mt35xu512";

These compatibles are arbitrary and undocumented. You probably just need "jedec,spi-nor". If you need anything else, you need to justify why.

Although just "spi-nor" also works, I agree to use "jedec, spi-nor" and drop device name.

Does it? I see "jedec,spi-nor" compatible documented, but not just "spi-nor". And I don't see "micron,mt35xu512" compatible documented anywhere either.

Anyway, please just use "jedec,spi-nor".

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#7 lore raw

RE: [PATCH v3 1/2] spi: cadence: add dt-bindings documentation for Cadence XSPI controller

Quoted 6 lines
Quoted 4 lines

Isn't stating that validation need against spi-controller.yaml as well as this schema sufficient ? Can you please point an example how to make controller binding a "subclass" of spi-controller.yaml binding ?

I just showed you. You need to add the below lines:

Oh, my bad. I already added that dependency in my local patches for next version, I thought you are suggesting something else.

Quoted 4 lines
Quoted 2 lines

I think spi-controller.yaml uses wildcard for the name of a device node, so anything in string@hexvalue: should work.

Sure, but mtd.yaml (which the SPI NOR binding depends on) requires it.

Ok, using "jedec,spi-nor" creates dependency on spi-nor schema, otherwise I was not seeing any issue in " make dt_binding_check" with just "spi-nor".

This will be taken care in next version of patch set.

Regards,
Parshuram Thombare

#8 lore raw

PATCH v3 2/2 spi: cadence: add support for Cadence XSPI controller

In reply to Parshuram Thombare

This patch adds driver for Cadence's XSPI controller.
It supports 3 work modes.
1. ACMD (auto command) work mode
ACMD name is because it uses auto command engine in the controller. It further has 2 modes PIO and CDMA (command DMA).
The CDMA work mode is dedicated for high-performance application where very low software overhead is required. In this mode the Command Engine is programmed by the series of linked descriptors stored in system memory. These descriptors provide commands to execute and store status information for finished commands.
The PIO mode work mode is dedicated for single operation where constructing a linked list of descriptors would require too much effort.
2. STIG (Software Triggered Instruction Generator) work mode
In STIG mode, controller sends low-level instructions to memory. Each instruction is 128-bit width. There is special instruction DataSequence which carries information about data phase. Driver uses Slave DMA interface to transfer data as only this interface can be used in STIG work mode.
3. Direct work mode
This work mode allows sending data without invoking any command through the slave interface.
Currently ACMD PIO mode is used for NOR flash read, program, erase operations, all other operations are handled in STIG work mode.

---
 drivers/spi/Kconfig            |  11 +
 drivers/spi/Makefile           |   1 +
 drivers/spi/spi-cadence-xspi.c | 837 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 849 insertions(+)
 create mode 100644 drivers/spi/spi-cadence-xspi.c
drivers/spi/Kconfig +11 -0
index e71a4c5..874f7aa 100644
@@ -228,6 +228,17 @@ config SPI_CADENCE_QUADSPI
 	  device with a Cadence QSPI controller and want to access the
 	  Flash as an MTD device.
 
+config SPI_CADENCE_XSPI
+	tristate "Cadence XSPI controller"
+	depends on (OF || COMPILE_TEST) && HAS_IOMEM
+	help
+	  Enable support for the Cadence XSPI Flash controller.
+
+	  Cadence XSPI is a specialized controller for connecting an SPI
+	  Flash over upto 8bit wide bus. Enable this option if you have a
+	  device with a Cadence XSPI controller and want to access the
+	  Flash as an MTD device.
+
 config SPI_CLPS711X
 	tristate "CLPS711X host SPI controller"
 	depends on ARCH_CLPS711X || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 13e54c4..93229a8 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_SPI_AR934X)		+= spi-ar934x.o
 obj-$(CONFIG_SPI_ARMADA_3700)		+= spi-armada-3700.o
 obj-$(CONFIG_SPI_ATMEL)			+= spi-atmel.o
 obj-$(CONFIG_SPI_ATMEL_QUADSPI)		+= atmel-quadspi.o
+obj-$(CONFIG_SPI_CADENCE_XSPI)		+= spi-cadence-xspi.o
 obj-$(CONFIG_SPI_AT91_USART)		+= spi-at91-usart.o
 obj-$(CONFIG_SPI_ATH79)			+= spi-ath79.o
 obj-$(CONFIG_SPI_AU1550)		+= spi-au1550.o
drivers/spi/spi-cadence-xspi.c new file +837 -0

837 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#9 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

drivers/spi/spi-cadence-xspi.c line 3

Quoted 5 lines · Parshuram Thombare

+++ b/drivers/spi/spi-cadence-xspi.c

drivers/spi/spi-cadence-xspi.c new file +3 -0
@@ -0,0 +1,837 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Cadence XSPI flash controller driver

Please make the entire comment a C++ so things look more intentional.

drivers/spi/spi-cadence-xspi.c line 638

Quoted 11 lines
drivers/spi/spi-cadence-xspi.c new file +11 -0
+static int cdns_xspi_setup(struct spi_device *spi_dev)
+{
+	if (spi_dev->chip_select > spi_dev->master->num_chipselect) {
+		dev_err(&spi_dev->dev,
+			"%d chip-select is out of range\n",
+			spi_dev->chip_select);
+		return -EINVAL;
+	}
+
+	return 0;
+}

The core already validates this, are you seeing it happen? If so we should fix the core and either way just remove setup() entirely.

Quoted 9 lines
drivers/spi/spi-cadence-xspi.c new file +9 -0
+	if (irq_status) {
+		writel(irq_status,
+		       cdns_xspi->iobase + CDNS_XSPI_INTR_STATUS_REG);
+
+		if (irq_status & CDNS_XSPI_SDMA_ERROR) {
+			dev_err(cdns_xspi->dev,
+				"Slave DMA transaction error\n");
+			cdns_xspi->sdma_error = true;
+			complete(&cdns_xspi->sdma_complete);

drivers/spi/spi-cadence-xspi.c line 665

Quoted 10 lines
drivers/spi/spi-cadence-xspi.c new file +10 -0
+		}
+
+		if (irq_status & CDNS_XSPI_SDMA_TRIGGER)
+			complete(&cdns_xspi->sdma_complete);
+
+		if (irq_status & CDNS_XSPI_STIG_DONE)
+			complete(&cdns_xspi->cmd_complete);
+
+		result = IRQ_HANDLED;
+	}

We will just silently ignore any unknown interrupts here. It would be better to either only ack known interrupts (so genirq can notice if there's a problem with other interrupts) or at least log that we're seeing unexpected interrupts. The current code will cause trouble if this is deployed in a system with the interrupt line shared (which the driver claims to support), or if something goes wrong and the IP starts asserting some interrupt that isn't expected.

drivers/spi/spi-cadence-xspi.c line 732

Quoted 3 lines
drivers/spi/spi-cadence-xspi.c new file +3 -0
+	master->mode_bits = SPI_3WIRE | SPI_TX_DUAL  | SPI_TX_QUAD  |
+		SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL |
+		SPI_MODE_0  | SPI_MODE_3;

I don't see any handling of these in the code?

#10 lore raw

RE: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Hi Mark,

Thanks for your reply.

Quoted 1 line

Please make the entire comment a C++ so things look more intentional.

Sure

Quoted 2 lines

The core already validates this, are you seeing it happen? If so we should fix the core and either way just remove setup() entirely.

Oh, right. spi_add_device() seems to be already doing that check. I will remove it from the driver.

Quoted 7 lines

We will just silently ignore any unknown interrupts here. It would be better to either only ack known interrupts (so genirq can notice if there's a problem with other interrupts) or at least log that we're seeing unexpected interrupts. The current code will cause trouble if this is deployed in a system with the interrupt line shared (which the driver claims to support), or if something goes wrong and the IP starts asserting some interrupt that isn't expected.

Ok, I will modify this to return IRQ_HANDLED only for enabled interrupts.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	master->mode_bits = SPI_3WIRE | SPI_TX_DUAL  | SPI_TX_QUAD  |
+		SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL

|

drivers/spi/spi-cadence-xspi.c line 732

Quoted 1 line
drivers/spi/spi-cadence-xspi.c new file +1 -0
+		SPI_MODE_0  | SPI_MODE_3;

I don't see any handling of these in the code?

This is just to declare controller's capability, so that spi_setup() can modify spi->mode according to the capability of attached device.

Regards,
Parshuram Thombare

maintainer
#11 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 9 lines · Parshuram Raju Thombare
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	master->mode_bits = SPI_3WIRE | SPI_TX_DUAL  | SPI_TX_QUAD  |
+		SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL

|

drivers/spi/spi-cadence-xspi.c line 732

Quoted 1 line
drivers/spi/spi-cadence-xspi.c new file +1 -0
+		SPI_MODE_0  | SPI_MODE_3;

I don't see any handling of these in the code?

This is just to declare controller's capability, so that spi_setup() can modify spi->mode according to the capability of attached device.

In order for this to work I would expect there to be code in the driver which configures the controller into the specified mode.

#12 lore raw

RE: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 9 lines · Parshuram Raju Thombare
Quoted 7 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	master->mode_bits = SPI_3WIRE | SPI_TX_DUAL  | SPI_TX_QUAD  |
+		SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL

|

drivers/spi/spi-cadence-xspi.c line 732

Quoted 1 line
drivers/spi/spi-cadence-xspi.c new file +1 -0
+		SPI_MODE_0  | SPI_MODE_3;

I don't see any handling of these in the code?

Quoted 5 lines
Quoted 2 lines

This is just to declare controller's capability, so that spi_setup() can modify spi->mode according to the capability of attached device.

In order for this to work I would expect there to be code in the driver which configures the controller into the specified mode.

Oh, ok. That is done at power on reset by the controller in 2 ways.
1. Using device discovery module, controller try to auto detect the valid protocol mode by trying to read SFDP signature in various modes.
2. Particular protocol mode can be selected using bootstrap signals.

I think mode_bits need to include protocol mode which is auto detected or set using bootstrap signals. I will make that change in next version.

Regards,
Parshuram Thombare

maintainer
#13 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 7 lines · Parshuram Raju Thombare

Oh, ok. That is done at power on reset by the controller in 2 ways.
1. Using device discovery module, controller try to auto detect the valid protocol mode by trying to read SFDP signature in various modes.
2. Particular protocol mode can be selected using bootstrap signals.

I think mode_bits need to include protocol mode which is auto detected or set using bootstrap signals. I will make that change in next version.

Yes, that sounds better. I guess at least in the case of autodetection the mode can be overridden by software later, but that can always be added later if someone actually needs the feature.

#14 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

In reply to Parshuram Thombare

+ Tudor, Vignesh,

Quoted 16 lines · Parshuram Thombare

This patch adds driver for Cadence's XSPI controller.
It supports 3 work modes.
1. ACMD (auto command) work mode
ACMD name is because it uses auto command engine in the controller. It further has 2 modes PIO and CDMA (command DMA).
The CDMA work mode is dedicated for high-performance application where very low software overhead is required. In this mode the Command Engine is programmed by the series of linked descriptors stored in system memory. These descriptors provide commands to execute and store status information for finished commands.
The PIO mode work mode is dedicated for single operation where constructing a linked list of descriptors would require too much effort.
2. STIG (Software Triggered Instruction Generator) work mode In STIG mode, controller sends low-level instructions to memory. Each instruction is 128-bit width. There is special instruction

Quoted 8 lines

DataSequence which carries information about data phase. Driver uses Slave DMA interface to transfer data as only this interface can be used in STIG work mode.
3. Direct work mode
This work mode allows sending data without invoking any command through the slave interface.
Currently ACMD PIO mode is used for NOR flash read, program, erase operations, all other operations are handled in STIG work mode.

Thanks. The commit message is much nicer now!

Quoted 16 lines
---
 drivers/spi/Kconfig            |  11 +
 drivers/spi/Makefile           |   1 +
 drivers/spi/spi-cadence-xspi.c | 837 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 849 insertions(+)
 create mode 100644 drivers/spi/spi-cadence-xspi.c
drivers/spi/Kconfig +0 -0
index e71a4c5..874f7aa 100644

drivers/spi/Kconfig config SPI_CADENCE_QUADSPI · line 233

Quoted 6 lines
drivers/spi/Kconfig +3 -0
@@ -228,6 +228,17 @@ config SPI_CADENCE_QUADSPI
 	  device with a Cadence QSPI controller and want to access the
 	  Flash as an MTD device.
 
+config SPI_CADENCE_XSPI
+	tristate "Cadence XSPI controller"
+	depends on (OF || COMPILE_TEST) && HAS_IOMEM

Depends on SPI_MEM as well.

Quoted 41 lines
drivers/spi/Kconfig +8 -0
+	help
+	  Enable support for the Cadence XSPI Flash controller.
+
+	  Cadence XSPI is a specialized controller for connecting an SPI
+	  Flash over upto 8bit wide bus. Enable this option if you have a
+	  device with a Cadence XSPI controller and want to access the
+	  Flash as an MTD device.
+
 config SPI_CLPS711X
 	tristate "CLPS711X host SPI controller"
 	depends on ARCH_CLPS711X || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 13e54c4..93229a8 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_SPI_AR934X)		+= spi-ar934x.o
 obj-$(CONFIG_SPI_ARMADA_3700)		+= spi-armada-3700.o
 obj-$(CONFIG_SPI_ATMEL)			+= spi-atmel.o
 obj-$(CONFIG_SPI_ATMEL_QUADSPI)		+= atmel-quadspi.o
+obj-$(CONFIG_SPI_CADENCE_XSPI)		+= spi-cadence-xspi.o
 obj-$(CONFIG_SPI_AT91_USART)		+= spi-at91-usart.o
 obj-$(CONFIG_SPI_ATH79)			+= spi-ath79.o
 obj-$(CONFIG_SPI_AU1550)		+= spi-au1550.o
drivers/spi/spi-cadence-xspi.c new file +12 -0
new file mode 100644
index 0000000..c2b33e2
@@ -0,0 +1,837 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Cadence XSPI flash controller driver
+ *
+ * Copyright (C) 2020-21 Cadence
+ *
+ */
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>

drivers/spi/spi-cadence-xspi.c line 22

Quoted 10 lines
drivers/spi/spi-cadence-xspi.c new file +10 -0
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/spi/spi.h>
+#include <linux/mtd/spi-nor.h>

Umm, this seems wrong to me. SPI MEM based drivers should generally not need to know anything about the subsystem driving them. Why do you need to include this?

More on this below.

Quoted 4 lines
drivers/spi/spi-cadence-xspi.c new file +4 -0
+#include <linux/bitfield.h>
+#include <linux/limits.h>
+#include <linux/log2.h>
+

[...]

drivers/spi/spi-cadence-xspi.c line 594

Quoted 11 lines
drivers/spi/spi-cadence-xspi.c new file +11 -0
+static int cdns_xspi_mem_op(struct cdns_xspi_dev *cdns_xspi,
+			    struct spi_mem *mem,
+			    const struct spi_mem_op *op)
+{
+	struct spi_driver *spidrv = to_spi_driver(mem->spi->dev.driver);
+	enum spi_mem_data_dir dir = op->data.dir;
+
+	if (cdns_xspi->cur_cs != mem->spi->chip_select)
+		cdns_xspi->cur_cs = mem->spi->chip_select;
+
+	if (!strstr(spidrv->driver.name, "nor") ||

I commented on this last time around as well. This does not look right at all. A SPI MEM based driver should *not* need to know anything about the subsystem driving it. That is the entire point of the API.

The controller seems to be able to extract the read and write opcodes from the SFDP on its own since you don't pass in that information to cdns_xspi_nor_read(). It looks like it is tied very heavily to a NOR flash, and I am not sure if it can really be used with a NAND flash, or something else entirely.

Which makes me wonder how we should handle controllers like these. I don't think they fit in very well with the SPI MEM model, since they can't execute arbitrary SPI MEM commands very well. At the same time we are trying to get rid of mtd/spi-nor/controllers. Dunno...

Mark, Tudor, Vignesh, any ideas?

Quoted 33 lines
drivers/spi/spi-cadence-xspi.c new file +33 -0
+	    (!op->addr.buswidth && !op->addr.nbytes && !op->addr.val)) {
+		return cdns_xspi_send_stig_command(cdns_xspi, op,
+						   (dir != SPI_MEM_NO_DATA));
+	} else {
+		if (dir == SPI_MEM_DATA_IN)
+			return cdns_xspi_nor_read(cdns_xspi, op->addr.val,
+						  op->data.nbytes,
+						  op->data.buf.in);
+		else if (dir == SPI_MEM_DATA_OUT)
+			return cdns_xspi_nor_write(cdns_xspi, op->addr.val,
+						   op->data.nbytes,
+						   op->data.buf.out);
+		else
+			return cdns_xspi_nor_erase(cdns_xspi, op->addr.val);
+	}
+}
+
+static int cdns_xspi_mem_op_execute(struct spi_mem *mem,
+				    const struct spi_mem_op *op)
+{
+	struct cdns_xspi_dev *cdns_xspi =
+		spi_master_get_devdata(mem->spi->master);
+	int ret = 0;
+
+	ret = cdns_xspi_mem_op(cdns_xspi, mem, op);
+
+	return ret;
+}
+
+static const struct spi_controller_mem_ops cadence_xspi_mem_ops = {
+	.exec_op = cdns_xspi_mem_op_execute,
+};
+
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#15 lore raw

RE: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 1 line

Depends on SPI_MEM as well.

Ok

Quoted 10 lines

I commented on this last time around as well. This does not look right at all. A SPI MEM based driver should *not* need to know anything about the subsystem driving it. That is the entire point of the API.

The controller seems to be able to extract the read and write opcodes from the SFDP on its own since you don't pass in that information to cdns_xspi_nor_read(). It looks like it is tied very heavily to a NOR flash, and I am not sure if it can really be used with a NAND flash, or something else entirely.

Quoted 6 lines

Which makes me wonder how we should handle controllers like these. I don't think they fit in very well with the SPI MEM model, since they can't execute arbitrary SPI MEM commands very well. At the same time we are trying to get rid of mtd/spi-nor/controllers. Dunno...

Mark, Tudor, Vignesh, any ideas?

Ok, then for now I will drop ACMD PIO mode and use only STIG mode. In STIG mode driver configures bus width and clock edge mode for command, address and data for each operation.

Regards,
Parshuram Thombare

#16 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 19 lines · Parshuram Raju Thombare
Quoted 1 line

Depends on SPI_MEM as well.

Ok

Quoted 15 lines

I commented on this last time around as well. This does not look right at all. A SPI MEM based driver should *not* need to know anything about the subsystem driving it. That is the entire point of the API.

The controller seems to be able to extract the read and write opcodes from the SFDP on its own since you don't pass in that information to cdns_xspi_nor_read(). It looks like it is tied very heavily to a NOR flash, and I am not sure if it can really be used with a NAND flash, or something else entirely.

Which makes me wonder how we should handle controllers like these. I don't think they fit in very well with the SPI MEM model, since they can't execute arbitrary SPI MEM commands very well. At the same time we are trying to get rid of mtd/spi-nor/controllers. Dunno...

Quoted 5 lines
Quoted 1 line

Mark, Tudor, Vignesh, any ideas?

Ok, then for now I will drop ACMD PIO mode and use only STIG mode. In STIG mode driver configures bus width and clock edge mode for command, address and data for each operation.

But it would reduce performance by a lot, no? I think we should try to figure out how we can accomodate controllers like this before resorting to using the slower modes.

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.
#17 lore raw

RE: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 3 lines

But it would reduce performance by a lot, no? I think we should try to figure out how we can accomodate controllers like this before resorting to using the slower modes.[>]

I am not saying that functionality will be restricted to STIG mode. But we can merge base driver with STIG mode for now and add other functionalities/modes incrementally.

Regards,
Parshuram Thombare

maintainer
#18 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

In reply to Pratyush Yadav
Quoted 3 lines · Pratyush Yadav

But it would reduce performance by a lot, no? I think we should try to figure out how we can accomodate controllers like this before resorting to using the slower modes.

OTOH if it's going to be hard to figure out perhaps merging something slower that works while we do so would be good - lets people use their systems while things are figured out.

#19 lore raw

Re: [PATCH v3 2/2] spi: cadence: add support for Cadence XSPI controller

Quoted 9 lines · Mark Brown
Quoted 3 lines · Pratyush Yadav

But it would reduce performance by a lot, no? I think we should try to figure out how we can accomodate controllers like this before resorting to using the slower modes.

OTOH if it's going to be hard to figure out perhaps merging something slower that works while we do so would be good - lets people use their systems while things are figured out.

I would prefer to solve this problem rather than leaving it for later, but either way is fine.

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.