Skip to contentSkip to conversation

mtd: spi-nor: Bindings for Cadence Quad SPI Flash Controller driver.

PATCH Superseded Marek Vasut 9 participants 40 messages Jan 11, 2016 – May 25, 2016 28 messages not in the archive

Subsystems (3)

v8 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/2 mtd: spi-nor: Bindings for Cadence Quad SPI Flash Controller driver.

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
---
 .../devicetree/bindings/mtd/cadence-quadspi.txt    | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/cadence-quadspi.txt

V2: Add cdns prefix to driver-specific bindings.
V3: Use existing property "is-decoded-cs" instead of creating a
duplicate, "ext-decoder". Timing parameters are in nanoseconds, not master reference clocks. Remove bus-num completely.
V4: Add new properties fifo-width and trigger-address
V7: - Prefix all of the Cadence-specific properties with cdns prefix,
those are in particular "cdns,is-decoded-cs", "cdns,fifo-depth", "cdns,fifo-width", "cdns,trigger-address".
- Drop bogus properties which were not used and were incorrect.
V8: Align lines to 80 chars.

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +56 -0
new file mode 100644
index 0000000..f248056
@@ -0,0 +1,56 @@
+* Cadence Quad SPI controller
+
+Required properties:
+- compatible : Should be "cdns,qspi-nor".
+- reg : Contains two entries, each of which is a tuple consisting of a
+	physical address and length. The first entry is the address and
+	length of the controller register set. The second entry is the
+	address and length of the QSPI Controller data area.
+- interrupts : Unit interrupt specifier for the controller interrupt.
+- clocks : phandle to the Quad SPI clock.
+- cdns,fifo-depth : Size of the data FIFO in words.
+- cdns,fifo-width : Bus width of the data FIFO in bytes.
+- cdns,trigger-address : 32-bit indirect AHB trigger address.
+
+Optional properties:
+- cdns,is-decoded-cs : Flag to indicate whether decoder is used or not.
+
+Optional subnodes:
+Subnodes of the Cadence Quad SPI controller are spi slave nodes with additional
+custom properties:
+- cdns,read-delay : Delay for read capture logic, in clock cycles
+- cdns,tshsl-ns : Delay in nanoseconds for the length that the master
+                  mode chip select outputs are de-asserted between
+		  transactions.
+- cdns,tsd2d-ns : Delay in nanoseconds between one chip select being
+                  de-activated and the activation of another.
+- cdns,tchsh-ns : Delay in nanoseconds between last bit of current
+                  transaction and deasserting the device chip select
+		  (qspi_n_ss_out).
+- cdns,tslch-ns : Delay in nanoseconds between setting qspi_n_ss_out low
+                  and first bit transfer.
+
+Example:
+
+	qspi: spi@ff705000 {
+		compatible = "cdns,qspi-nor";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0xff705000 0x1000>,
+		      <0xffa00000 0x1000>;
+		interrupts = <0 151 4>;
+		clocks = <&qspi_clk>;
+		cdns,is-decoded-cs;
+		cdns,fifo-depth = <128>;
+		cdns,fifo-width = <4>;
+		cdns,trigger-address = <0x00000000>;
+
+		flash0: n25q00@0 {
+			...
+			cdns,read-delay = <4>;
+			cdns,tshsl-ns = <50>;
+			cdns,tsd2d-ns = <50>;
+			cdns,tchsh-ns = <4>;
+			cdns,tslch-ns = <4>;
+		};
+	};
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1452486886-8049-1-git-send-email-marex-ynQEQJNshbs@public.gmane.org

#2 lore raw

PATCH v10 2/2 mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
---
 drivers/mtd/spi-nor/Kconfig           |   11 +
 drivers/mtd/spi-nor/Makefile          |    1 +
 drivers/mtd/spi-nor/cadence-quadspi.c | 1280 +++++++++++++++++++++++++++++++++
 3 files changed, 1292 insertions(+)
 create mode 100644 drivers/mtd/spi-nor/cadence-quadspi.c

V2: use NULL instead of modalias in spi_nor_scan call
V3: Use existing property is-decoded-cs instead of creating duplicate.
V4: Support Micron quad mode by snooping command stream for EVCR command
and subsequently configuring Cadence controller for quad mode.
V5: Clean up sparse and smatch complaints. Remove snooping of Micron
quad mode. Add comment on XIP mode bit and dummy clock cycles. Set up SRAM partition at 1:1 during init.
V6: Remove dts patch that was included by mistake. Incorporate Vikas's
comments regarding fifo width, SRAM partition setting, and trigger address. Trigger address was added as an unsigned int, as it is not an IO resource per se, and does not need to be mapped. Also add Marek Vasut's workaround for picking up OF properties on subnodes.
V7: - Perform coding-style cleanup and type fixes. Remove ugly QSPI_*()
macros and replace them with functions. Get rid of unused variables.
- Implement support for nor->set_protocol() to handle Quad-command, this patch now depends on the following patch:
mtd: spi-nor: notify (Q)SPI controller about protocol change
- Replace that cqspi_fifo_read() disaster with plain old readsl() and cqspi_fifo_write() tentacle horror with pretty writesl().
- Remove CQSPI_SUPPORT_XIP_CHIPS, which is broken.
- Get rid of cqspi_find_chipselect() mess, instead just place the struct cqspi_st and chipselect number into struct cqspi_flash_pdata and set nor->priv to the struct cqspi_flash_pdata of that particular chip.
- Replace the odd math in calculate_ticks_for_ns() with DIV_ROUND_UP().
- Make variables const where applicable.
V8: - Implement a function to wait for bit being set/unset for a given
period of time and use it to replace the ad-hoc bits of code.
- Configure the write underflow watermark to be 1/8 if FIFO size.
- Extract out the SPI NOR flash probing code into separate function to clearly mark what will soon be considered a boilerplate code.
- Repair the handling of mode bits, which caused instability in V7.
- Clean up the interrupt handling
- Fix Kconfig help text and make the patch depend on OF and COMPILE_TEST.
V9: - Rename CQSPI_REG_IRQ_IND_RD_OVERFLOW to CQSPI_REG_IRQ_IND_SRAM_FULL
- Merge cqspi_controller_disable() into cqspi_controller_enable() and make the mode selectable via parameter.
V10: - Update against Cyrille's new patchset and changes to linux-mtd.
- Repair problem with multiple QSPI NOR devices having the same mtd->name, they are now named devname.cs , where cs is the chipselect ID.

drivers/mtd/spi-nor/Kconfig +11 -0
index 43bafde..7e29050 100644
@@ -50,4 +50,15 @@ config SPI_NXP_SPIFI
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
+config SPI_CADENCE_QUADSPI
+	tristate "Cadence Quad SPI controller"
+	depends on OF && (ARCH_SOCFPGA || COMPILE_TEST)
+	help
+	  Enable support for the Cadence Quad SPI Flash controller.
+
+	  Cadence QSPI is a specialized controller for connecting an SPI
+	  Flash over 1/2/4-bit wide bus. Enable this option if you have a
+	  device with a Cadence QSPI controller and want to access the
+	  Flash as an MTD device.
+
 endif # MTD_SPI_NOR
drivers/mtd/spi-nor/Makefile +1 -0
index 5d80c9d..8ced75e 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_MTD_SPI_NOR)	+= spi-nor.o
+obj-$(CONFIG_SPI_CADENCE_QUADSPI)	+= cadence-quadspi.o
 obj-$(CONFIG_SPI_FSL_QUADSPI)	+= fsl-quadspi.o
 obj-$(CONFIG_SPI_NXP_SPIFI)	+= nxp-spifi.o
 obj-$(CONFIG_SPI_ATMEL_QUADSPI)	+= atmel-quadspi.o
drivers/mtd/spi-nor/cadence-quadspi.c new file +1280 -0

1,280 lines not on this page · raw message

Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 69 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
---
 drivers/mtd/spi-nor/Kconfig           |   11 +
 drivers/mtd/spi-nor/Makefile          |    1 +
 drivers/mtd/spi-nor/cadence-quadspi.c | 1280 +++++++++++++++++++++++++++++++++
 3 files changed, 1292 insertions(+)
 create mode 100644 drivers/mtd/spi-nor/cadence-quadspi.c

V2: use NULL instead of modalias in spi_nor_scan call
V3: Use existing property is-decoded-cs instead of creating duplicate.
V4: Support Micron quad mode by snooping command stream for EVCR command
and subsequently configuring Cadence controller for quad mode.
V5: Clean up sparse and smatch complaints. Remove snooping of Micron
quad mode. Add comment on XIP mode bit and dummy clock cycles. Set up SRAM partition at 1:1 during init.
V6: Remove dts patch that was included by mistake. Incorporate Vikas's
comments regarding fifo width, SRAM partition setting, and trigger address. Trigger address was added as an unsigned int, as it is not an IO resource per se, and does not need to be mapped. Also add Marek Vasut's workaround for picking up OF properties on subnodes.
V7: - Perform coding-style cleanup and type fixes. Remove ugly QSPI_*()
macros and replace them with functions. Get rid of unused variables.
- Implement support for nor->set_protocol() to handle Quad-command, this patch now depends on the following patch:
mtd: spi-nor: notify (Q)SPI controller about protocol change
- Replace that cqspi_fifo_read() disaster with plain old readsl() and cqspi_fifo_write() tentacle horror with pretty writesl().
- Remove CQSPI_SUPPORT_XIP_CHIPS, which is broken.
- Get rid of cqspi_find_chipselect() mess, instead just place the struct cqspi_st and chipselect number into struct cqspi_flash_pdata and set nor->priv to the struct cqspi_flash_pdata of that particular chip.
- Replace the odd math in calculate_ticks_for_ns() with DIV_ROUND_UP().
- Make variables const where applicable.
V8: - Implement a function to wait for bit being set/unset for a given
period of time and use it to replace the ad-hoc bits of code.
- Configure the write underflow watermark to be 1/8 if FIFO size.
- Extract out the SPI NOR flash probing code into separate function to clearly mark what will soon be considered a boilerplate code.
- Repair the handling of mode bits, which caused instability in V7.
- Clean up the interrupt handling
- Fix Kconfig help text and make the patch depend on OF and COMPILE_TEST.
V9: - Rename CQSPI_REG_IRQ_IND_RD_OVERFLOW to CQSPI_REG_IRQ_IND_SRAM_FULL
- Merge cqspi_controller_disable() into cqspi_controller_enable() and make the mode selectable via parameter.
V10: - Update against Cyrille's new patchset and changes to linux-mtd.
- Repair problem with multiple QSPI NOR devices having the same mtd->name, they are now named devname.cs , where cs is the chipselect ID.

drivers/mtd/spi-nor/Kconfig +0 -0
index 43bafde..7e29050 100644

drivers/mtd/spi-nor/Kconfig config SPI_NXP_SPIFI · line 55

Quoted 6 lines
drivers/mtd/spi-nor/Kconfig +3 -0
@@ -50,4 +50,15 @@ config SPI_NXP_SPIFI
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
+config SPI_CADENCE_QUADSPI
+	tristate "Cadence Quad SPI controller"
+	depends on OF && (ARCH_SOCFPGA || COMPILE_TEST)

I think you can remove the ARCH_SOCFPGA dependency as this driver is used on a TI EVM as well.

Dinh

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): 5693D3B4.2090304-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#5 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 103 lines · Dinh Nguyen
Quoted 102 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>

---

 drivers/mtd/spi-nor/Kconfig           |   11 +
 drivers/mtd/spi-nor/Makefile          |    1 +
 drivers/mtd/spi-nor/cadence-quadspi.c | 1280
 +++++++++++++++++++++++++++++++++ 3 files changed, 1292 insertions(+)
 create mode 100644 drivers/mtd/spi-nor/cadence-quadspi.c

V2: use NULL instead of modalias in spi_nor_scan call
V3: Use existing property is-decoded-cs instead of creating duplicate.
V4: Support Micron quad mode by snooping command stream for EVCR command

and subsequently configuring Cadence controller for quad mode.

V5: Clean up sparse and smatch complaints. Remove snooping of Micron

quad mode. Add comment on XIP mode bit and dummy clock cycles. Set up SRAM partition at 1:1 during init.

V6: Remove dts patch that was included by mistake. Incorporate Vikas's

comments regarding fifo width, SRAM partition setting, and trigger address. Trigger address was added as an unsigned int, as it is not an IO resource per se, and does not need to be mapped. Also add Marek Vasut's workaround for picking up OF properties on subnodes.

V7: - Perform coding-style cleanup and type fixes. Remove ugly QSPI_*()

macros and replace them with functions. Get rid of unused variables.

- Implement support for nor->set_protocol() to handle Quad-command,

this patch now depends on the following patch:
mtd: spi-nor: notify (Q)SPI controller about protocol change

- Replace that cqspi_fifo_read() disaster with plain old readsl()

and cqspi_fifo_write() tentacle horror with pretty writesl().

- Remove CQSPI_SUPPORT_XIP_CHIPS, which is broken.
- Get rid of cqspi_find_chipselect() mess, instead just place the

struct cqspi_st and chipselect number into struct cqspi_flash_pdata and set nor->priv to the struct cqspi_flash_pdata of that particular chip.

- Replace the odd math in calculate_ticks_for_ns() with DIV_ROUND_UP(). - Make variables const where applicable.

V8: - Implement a function to wait for bit being set/unset for a given

period of time and use it to replace the ad-hoc bits of code.

- Configure the write underflow watermark to be 1/8 if FIFO size.
- Extract out the SPI NOR flash probing code into separate function

to clearly mark what will soon be considered a boilerplate code.

- Repair the handling of mode bits, which caused instability in V7.
- Clean up the interrupt handling
- Fix Kconfig help text and make the patch depend on OF and COMPILE_TEST.

V9: - Rename CQSPI_REG_IRQ_IND_RD_OVERFLOW to CQSPI_REG_IRQ_IND_SRAM_FULL

- Merge cqspi_controller_disable() into cqspi_controller_enable() and

make the mode selectable via parameter.

V10: - Update against Cyrille's new patchset and changes to linux-mtd.

- Repair problem with multiple QSPI NOR devices having the same mtd->name,

they are now named devname.cs , where cs is the chipselect ID.

drivers/mtd/spi-nor/Kconfig +0 -0
index 43bafde..7e29050 100644
@@ -50,4 +50,15 @@ config SPI_NXP_SPIFI
 
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
Quoted 6 lines

drivers/mtd/spi-nor/Kconfig config SPI_NXP_SPIFI · line 55

Quoted 3 lines
drivers/mtd/spi-nor/Kconfig +3 -0
+config SPI_CADENCE_QUADSPI
+	tristate "Cadence Quad SPI controller"
+	depends on OF && (ARCH_SOCFPGA || COMPILE_TEST)

I think you can remove the ARCH_SOCFPGA dependency as this driver is used on a TI EVM as well.

Yeah, that's a good point, thanks!

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

In reply to a message not in the archive
Quoted 7 lines · Dinh Nguyen
Quoted 6 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

[...]

Quoted 8 lines
Quoted 8 lines
drivers/mtd/spi-nor/Kconfig +0 -0
index 43bafde..7e29050 100644
@@ -50,4 +50,15 @@ config SPI_NXP_SPIFI
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
Quoted 6 lines

drivers/mtd/spi-nor/Kconfig config SPI_NXP_SPIFI · line 55

Quoted 3 lines
drivers/mtd/spi-nor/Kconfig +3 -0
+config SPI_CADENCE_QUADSPI
+	tristate "Cadence Quad SPI controller"
+	depends on OF && (ARCH_SOCFPGA || COMPILE_TEST)

I think you can remove the ARCH_SOCFPGA dependency as this driver is used on a TI EVM as well.

I think above usage is correct. This will enable SPI_CADENCE_QUADSPI to be selected when ARCH_SOCFPGA=y without having to enable COMPILE_TEST. AFAIK, COMPILE_TEST is used usually to build test the driver w/o having to enable ARCH specific configs (usually by maintainers). For TI EVM, I would patch this file to add my architecture later(i.e along with DT patch to my board).

Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 26 lines · Vignesh R
Quoted 6 lines · Dinh Nguyen
Quoted 5 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

[...]

Quoted 9 lines
Quoted 9 lines
drivers/mtd/spi-nor/Kconfig +0 -0
index 43bafde..7e29050 100644
@@ -50,4 +50,15 @@ config SPI_NXP_SPIFI
 
 	  Flash. Enable this option if you have a device with a SPIFI
 	  controller and want to access the Flash as a mtd device.
 
Quoted 6 lines

drivers/mtd/spi-nor/Kconfig config SPI_NXP_SPIFI · line 55

Quoted 3 lines
drivers/mtd/spi-nor/Kconfig +3 -0
+config SPI_CADENCE_QUADSPI
+	tristate "Cadence Quad SPI controller"
+	depends on OF && (ARCH_SOCFPGA || COMPILE_TEST)

I think you can remove the ARCH_SOCFPGA dependency as this driver is used on a TI EVM as well.

Quoted 6 lines

I think above usage is correct. This will enable SPI_CADENCE_QUADSPI to be selected when ARCH_SOCFPGA=y without having to enable COMPILE_TEST. AFAIK, COMPILE_TEST is used usually to build test the driver w/o having to enable ARCH specific configs (usually by maintainers). For TI EVM, I would patch this file to add my architecture later(i.e along with DT patch to my board).

I changed this to OF && (ARM || COMPILE_TEST) , so that should be enough.

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1452486886-8049-2-git-send-email-marex-ynQEQJNshbs@public.gmane.org

#10 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Hi Marek,

I encountered a issue with this driver while testing.

Quoted 16 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

drivers/mtd/spi-nor/cadence-quadspi.c new file +9 -0
+static void cqspi_switch_cs(struct spi_nor *nor)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	void __iomem *iobase = cqspi->iobase;
+	unsigned int reg;
+
+	cqspi_controller_enable(cqspi, 0);
+

drivers/mtd/spi-nor/cadence-quadspi.c line 913

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+	/* configure page size and block size. */
+	reg = readl(iobase + CQSPI_REG_SIZE);
+	reg &= ~(CQSPI_REG_SIZE_PAGE_MASK << CQSPI_REG_SIZE_PAGE_LSB);
+	reg &= ~(CQSPI_REG_SIZE_BLOCK_MASK << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
+	reg |= (nor->page_size << CQSPI_REG_SIZE_PAGE_LSB);
+	reg |= (ilog2(nor->mtd.erasesize) << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg |= (nor->addr_width - 1);
+	writel(reg, iobase + CQSPI_REG_SIZE);
+

Page size and block size are configured here...

Quoted 6 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +6 -0
+	/* configure the chip select */
+	cqspi_chipselect(nor);
+
+	cqspi_controller_enable(cqspi, 1);
+}
+

drivers/mtd/spi-nor/cadence-quadspi.c line 929

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	const unsigned int sclk = f_pdata->clk_rate;
+
+	/* Switch chip select. */
+	if (cqspi->current_cs != f_pdata->cs) {
+		cqspi->current_cs = f_pdata->cs;
+		cqspi_switch_cs(nor);

cqspi_switch_cs(nor) is called from cqspi_prep(). And is called only once for a given slave (assuming only one slave on the QSPI bus)

Quoted 14 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +14 -0
+	}
+
+	/* Setup baudrate divisor and delays */
+	if (cqspi->sclk != sclk) {
+		cqspi->sclk = sclk;
+		cqspi_controller_enable(cqspi, 0);
+		cqspi_config_baudrate_div(cqspi, sclk);
+		cqspi_delay(nor, sclk);
+		cqspi_readdata_capture(cqspi, 1, f_pdata->read_delay);
+		cqspi_controller_enable(cqspi, 1);
+	}
+
+	return 0;
+}

drivers/mtd/spi-nor/cadence-quadspi.c line 953

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+
+static int cqspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
+{
+	int ret;
+
+	ret = cqspi_set_protocol(nor, nor->reg_proto);
+	if (ret)
+		return ret;
+
+	cqspi_prep(nor, SPI_NOR_OPS_READ);

cqspi_read_reg() is first called to read JEDEC ID, this calls cqspi_prep() for first time. But nor->page_size, nor->mtd.erasesize are not yet populated. Therefore cqspi_switch_cs() will not populate CQSPI_REG_SIZE with correct values.
I think its better to configure this register each time during read/write ops.

Regards
Vignesh

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Quoted 85 lines · Marek Vasut
Quoted 16 lines

From: Graham Moore <[email protected]>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

(quoted diff) +9 -0
+static void cqspi_switch_cs(struct spi_nor *nor)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	void __iomem *iobase = cqspi->iobase;
+	unsigned int reg;
+
+	cqspi_controller_enable(cqspi, 0);
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	/* configure page size and block size. */
+	reg = readl(iobase + CQSPI_REG_SIZE);
+	reg &= ~(CQSPI_REG_SIZE_PAGE_MASK << CQSPI_REG_SIZE_PAGE_LSB);
+	reg &= ~(CQSPI_REG_SIZE_BLOCK_MASK << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
+	reg |= (nor->page_size << CQSPI_REG_SIZE_PAGE_LSB);
+	reg |= (ilog2(nor->mtd.erasesize) << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg |= (nor->addr_width - 1);
+	writel(reg, iobase + CQSPI_REG_SIZE);
+

Page size and block size are configured here...

Quoted 6 lines
(quoted diff) +6 -0
+	/* configure the chip select */
+	cqspi_chipselect(nor);
+
+	cqspi_controller_enable(cqspi, 1);
+}
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	const unsigned int sclk = f_pdata->clk_rate;
+
+	/* Switch chip select. */
+	if (cqspi->current_cs != f_pdata->cs) {
+		cqspi->current_cs = f_pdata->cs;
+		cqspi_switch_cs(nor);

cqspi_switch_cs(nor) is called from cqspi_prep(). And is called only once for a given slave (assuming only one slave on the QSPI bus)

Quoted 14 lines
(quoted diff) +14 -0
+	}
+
+	/* Setup baudrate divisor and delays */
+	if (cqspi->sclk != sclk) {
+		cqspi->sclk = sclk;
+		cqspi_controller_enable(cqspi, 0);
+		cqspi_config_baudrate_div(cqspi, sclk);
+		cqspi_delay(nor, sclk);
+		cqspi_readdata_capture(cqspi, 1, f_pdata->read_delay);
+		cqspi_controller_enable(cqspi, 1);
+	}
+
+	return 0;
+}

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+static int cqspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
+{
+	int ret;
+
+	ret = cqspi_set_protocol(nor, nor->reg_proto);
+	if (ret)
+		return ret;
+
+	cqspi_prep(nor, SPI_NOR_OPS_READ);

cqspi_read_reg() is first called to read JEDEC ID, this calls cqspi_prep() for first time. But nor->page_size, nor->mtd.erasesize are not yet populated. Therefore cqspi_switch_cs() will not populate CQSPI_REG_SIZE with correct values.
I think its better to configure this register each time during read/write ops.

Regards
Vignesh

Signature · 2 lines
Best regards,
Marek Vasut
Quoted 1 line

From 6a649c8263149b06d29a3acc91b63fb0c1728deb Mon Sep 17 00:00:00 2001

From: Marek Vasut <[email protected]>
Date: Wed, 23 Mar 2016 08:26:46 +0100
Subject: [PATCH 1/3] mtd: spi-nor: cqspi: Reinit completion during indirect
read and write

Reinit the completion structures when performing indirect I/O. This does not manifest as a bug, but is necessary to make the code fully correct.

---
 drivers/mtd/spi-nor/cadence-quadspi.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi-nor/cadence-quadspi.c +6 -0
index d9a7a67..a4d246c 100644
@@ -527,6 +527,9 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor,
 			remaining -= bytes_to_read;
 			bytes_to_read = cqspi_get_rd_sram_level(cqspi);
 		}
+
+		if (remaining > 0)
+			reinit_completion(&cqspi->transfer_complete);
 	}
 
 	/* Check indirect done status */
@@ -616,6 +619,9 @@ static int cqspi_indirect_write_execute(struct spi_nor *nor,
 
 		txbuf += write_bytes;
 		remaining -= write_bytes;
+
+		if (remaining > 0)
+			reinit_completion(&cqspi->transfer_complete);
 	}
 
 	/* Check indirect done status */
Signature · 1 line
2.7.0
Quoted 1 line

From 30391427f34193d9229e70bf62794cbcb733b047 Mon Sep 17 00:00:00 2001

From: Marek Vasut <[email protected]>
Date: Wed, 23 Mar 2016 08:27:50 +0100
Subject: [PATCH 2/3] mtd: spi-nor: cqspi: Optimize the control reconfiguration

Always disable and re-enable the controller only once when switching the chipselect and bus speed instead of doing so twice.

---
 drivers/mtd/spi-nor/cadence-quadspi.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/mtd/spi-nor/cadence-quadspi.c +10 -8
index a4d246c..ee309cb 100644
@@ -905,8 +905,6 @@ static void cqspi_switch_cs(struct spi_nor *nor)
 	void __iomem *iobase = cqspi->iobase;
 	unsigned int reg;
 
-	cqspi_controller_enable(cqspi, 0);
-
 	/* configure page size and block size. */
 	reg = readl(iobase + CQSPI_REG_SIZE);
 	reg &= ~(CQSPI_REG_SIZE_PAGE_MASK << CQSPI_REG_SIZE_PAGE_LSB);
@@ -919,8 +917,6 @@ static void cqspi_switch_cs(struct spi_nor *nor)
 
 	/* configure the chip select */
 	cqspi_chipselect(nor);
-
-	cqspi_controller_enable(cqspi, 1);
 }
 
 static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
@@ -928,23 +924,29 @@ static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
 	struct cqspi_flash_pdata *f_pdata = nor->priv;
 	struct cqspi_st *cqspi = f_pdata->cqspi;
 	const unsigned int sclk = f_pdata->clk_rate;
+	const int switch_cs = (cqspi->current_cs != f_pdata->cs);
+	const int switch_ck = (cqspi->sclk != sclk);
+
+	if (switch_cs || switch_ck)
+		cqspi_controller_enable(cqspi, 0);
 
 	/* Switch chip select. */
-	if (cqspi->current_cs != f_pdata->cs) {
+	if (switch_cs) {
 		cqspi->current_cs = f_pdata->cs;
 		cqspi_switch_cs(nor);
 	}
 
 	/* Setup baudrate divisor and delays */
-	if (cqspi->sclk != sclk) {
+	if (switch_ck) {
 		cqspi->sclk = sclk;
-		cqspi_controller_enable(cqspi, 0);
 		cqspi_config_baudrate_div(cqspi, sclk);
 		cqspi_delay(nor, sclk);
 		cqspi_readdata_capture(cqspi, 1, f_pdata->read_delay);
-		cqspi_controller_enable(cqspi, 1);
 	}
 
+	if (switch_cs || switch_ck)
+		cqspi_controller_enable(cqspi, 1);
+
 	return 0;
 }
 
Signature · 1 line
2.7.0
Quoted 1 line

From e680fa497cf0e2f41fe1b56c7d6b868596d8e420 Mon Sep 17 00:00:00 2001

From: Marek Vasut <[email protected]>
Date: Wed, 23 Mar 2016 08:30:47 +0100
Subject: [PATCH 3/3] mtd: spi-nor: cqspi: Add bus lock

Lock the whole bus in .prepare callback and unlock the whole bus in the .unprepare callback. This is necessary to prevent a race condition when accessing two flashes, each of which has it's own instance of struct spi_nor, in parallel. The SPI NOR framework only locks the mutex in struct spi_nor and therefore the locking happens with per-flash granularity, which is not enough to prevent concurrent access to the SPI NOR controller registers.

---
 drivers/mtd/spi-nor/cadence-quadspi.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)
drivers/mtd/spi-nor/cadence-quadspi.c +29 -6
index ee309cb..b086609 100644
@@ -63,6 +63,7 @@ struct cqspi_st {
 	void __iomem		*iobase;
 	void __iomem		*ahb_base;
 	struct completion	transfer_complete;
+	struct mutex		bus_mutex;
 
 	int			current_cs;
 	unsigned long		master_ref_clk_hz;
@@ -919,7 +920,7 @@ static void cqspi_switch_cs(struct spi_nor *nor)
 	cqspi_chipselect(nor);
 }
 
-static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
+static int cqspi_prep_unlocked(struct spi_nor *nor, enum spi_nor_ops ops)
 {
 	struct cqspi_flash_pdata *f_pdata = nor->priv;
 	struct cqspi_st *cqspi = f_pdata->cqspi;
@@ -950,31 +951,51 @@ static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
 	return 0;
 }
 
+static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+
+	mutex_lock(&cqspi->bus_mutex);
+
+	return cqspi_prep_unlocked(nor, ops);
+}
+
+static void cqspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+
+	mutex_unlock(&cqspi->bus_mutex);
+}
+
 static int cqspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
 {
 	int ret;
 
 	ret = cqspi_set_protocol(nor, nor->reg_proto);
 	if (ret)
-		return ret;
+		goto exit;
 
-	cqspi_prep(nor, SPI_NOR_OPS_READ);
+	cqspi_prep_unlocked(nor, SPI_NOR_OPS_READ);
 
 	ret = cqspi_command_read(nor, &opcode, 1, buf, len);
+exit:
 	return ret;
 }
 
 static int cqspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
 {
-	int ret = 0;
+	int ret;
 
 	ret = cqspi_set_protocol(nor, nor->reg_proto);
 	if (ret)
-		return ret;
+		goto exit;
 
-	cqspi_prep(nor, SPI_NOR_OPS_WRITE);
+	cqspi_prep_unlocked(nor, SPI_NOR_OPS_WRITE);
 
 	ret = cqspi_command_write(nor, opcode, buf, len);
+exit:
 	return ret;
 }
 
@@ -1113,6 +1134,7 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi, struct device_node *np)
 		nor->write = cqspi_write;
 		nor->erase = cqspi_erase;
 		nor->prepare = cqspi_prep;
+		nor->unprepare = cqspi_unprep;
 
 		mtd->name = kasprintf(GFP_KERNEL, "%s.%d", dev_name(dev), cs);
 		if (!mtd->name) {
@@ -1154,6 +1176,7 @@ static int cqspi_probe(struct platform_device *pdev)
 	if (!cqspi)
 		return -ENOMEM;
 
+	mutex_init(&cqspi->bus_mutex);
 	cqspi->pdev = pdev;
 	platform_set_drvdata(pdev, cqspi);
 
Signature · 1 line
2.7.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 10 lines · Marek Vasut
Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Thanks for the patches.
But I am pretty sure that's not the problem at my end, because I have only one flash device on QSPI bus.

The problem is cqspi_switch_cs() is called only once ie when JEDEC ID is being read(during autodetect of chip), but at that instance, nor->page_size and nor->mtd.erasesize are not yet initialized (They are initialized only after JEDEC ID is looked up in the table and page_size and erasesize are known).
Therefore if nor->page_size is printed during cqspi_switch_cs() then its zero. But nor->page_size reports 256 when printed in cqspi_flash_setup() after spi_nor_scan(). Therefore CQSPI_REG_SIZE register has to be configured only after spi_nor struct is fully populated (i.e after spi_nor_scan() has recognized the slave after JEDEC ID read).

Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 10 lines · Vignesh R
Quoted 7 lines · Marek Vasut
Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Quoted 7 lines
Quoted 3 lines

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Thanks for the patches.
But I am pretty sure that's not the problem at my end, because I have only one flash device on QSPI bus.

OK, sorry for the delayed reply. I will go through the rest of the QSPI mail later, probably this week.

Quoted 12 lines

The problem is cqspi_switch_cs() is called only once ie when JEDEC ID is being read(during autodetect of chip), but at that instance, nor->page_size and nor->mtd.erasesize are not yet initialized (They are initialized only after JEDEC ID is looked up in the table and page_size and erasesize are known).
Therefore if nor->page_size is printed during cqspi_switch_cs() then its zero. But nor->page_size reports 256 when printed in cqspi_flash_setup() after spi_nor_scan(). Therefore CQSPI_REG_SIZE register has to be configured only after spi_nor struct is fully populated (i.e after spi_nor_scan() has recognized the slave after JEDEC ID read).

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

In reply to a message not in the archive
Quoted 18 lines · Vignesh R
Quoted 10 lines · Marek Vasut
Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Thanks for the patches.
But I am pretty sure that's not the problem at my end, because I have only one flash device on QSPI bus.

Quoted 10 lines

The problem is cqspi_switch_cs() is called only once ie when JEDEC ID is being read(during autodetect of chip), but at that instance, nor->page_size and nor->mtd.erasesize are not yet initialized (They are initialized only after JEDEC ID is looked up in the table and page_size and erasesize are known).
Therefore if nor->page_size is printed during cqspi_switch_cs() then its zero. But nor->page_size reports 256 when printed in cqspi_flash_setup() after spi_nor_scan(). Therefore CQSPI_REG_SIZE register has to be configured only after spi_nor struct is fully populated (i.e after spi_nor_scan() has recognized the slave after JEDEC ID read).

Got it and I have a patch for this. Nice find, thanks! It gave me 60% read performance boost on my machine :-)

I am now caching the page_size, erasesize, addr_width values, so I can avoid reconfiguring the controller if there is no need for it, but reconfigure it if there is a need. The patch is attached, but it's quite big, so I also pushed a git branch with this driver for your convenience (based on linux-next, expect rebases):

https://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=next/cadence-qspi

Signature · 2 lines
Best regards,
Marek Vasut
drivers/mtd/spi-nor/cadence-quadspi.c +164 -159
index 7e61fba..331e7d1 100644
@@ -66,6 +66,9 @@ struct cqspi_st {
 	struct mutex		bus_mutex;
 
 	int			current_cs;
+	int			current_page_size;
+	int			current_erase_size;
+	int			current_addr_width;
 	unsigned long		master_ref_clk_hz;
 	bool			is_decoded_cs;
 	u32			fifo_depth;
@@ -654,109 +657,60 @@ failwr:
 	return ret;
 }
 
-static int cqspi_set_protocol(struct spi_nor *nor, enum spi_nor_protocol proto)
+static void cqspi_chipselect(struct spi_nor *nor)
 {
 	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	void __iomem *reg_base = cqspi->iobase;
+	unsigned int chip_select = f_pdata->cs;
+	unsigned int reg;
 
-	switch (proto) {
-	case SNOR_PROTO_1_1_1:
-	case SNOR_PROTO_1_1_2:
-	case SNOR_PROTO_1_1_4:
-	case SNOR_PROTO_1_2_2:
-	case SNOR_PROTO_1_4_4:
-		f_pdata->inst_width = CQSPI_INST_TYPE_SINGLE;
-		break;
-	case SNOR_PROTO_2_2_2:
-		f_pdata->inst_width = CQSPI_INST_TYPE_DUAL;
-		break;
-	case SNOR_PROTO_4_4_4:
-		f_pdata->inst_width = CQSPI_INST_TYPE_QUAD;
-		break;
-	default:
-		return -EINVAL;
-	}
+	reg = readl(reg_base + CQSPI_REG_CONFIG);
+	if (cqspi->is_decoded_cs) {
+		reg |= CQSPI_REG_CONFIG_DECODE_MASK;
+	} else {
+		reg &= ~CQSPI_REG_CONFIG_DECODE_MASK;
 
-	switch (proto) {
-	case SNOR_PROTO_1_1_1:
-	case SNOR_PROTO_1_1_2:
-	case SNOR_PROTO_1_1_4:
-		f_pdata->addr_width = CQSPI_INST_TYPE_SINGLE;
-		break;
-	case SNOR_PROTO_1_2_2:
-	case SNOR_PROTO_2_2_2:
-		f_pdata->addr_width = CQSPI_INST_TYPE_DUAL;
-		break;
-	case SNOR_PROTO_1_4_4:
-	case SNOR_PROTO_4_4_4:
-		f_pdata->addr_width = CQSPI_INST_TYPE_QUAD;
-		break;
-	default:
-		return -EINVAL;
+		/* Convert CS if without decoder.
+		 * CS0 to 4b'1110
+		 * CS1 to 4b'1101
+		 * CS2 to 4b'1011
+		 * CS3 to 4b'0111
+		 */
+		chip_select = 0xF & ~(1 << chip_select);
 	}
 
-	return 0;
-}
-
-static void cqspi_write(struct spi_nor *nor, loff_t to,
-			size_t len, size_t *retlen, const u_char *buf)
-{
-	int ret;
-
-	ret = cqspi_set_protocol(nor, nor->write_proto);
-	if (ret)
-		return;
-
-	ret = cqspi_indirect_write_setup(nor, to);
-	if (ret)
-		return;
-
-	ret = cqspi_indirect_write_execute(nor, buf, len);
-	if (ret)
-		return;
-
-	*retlen += len;
-}
-
-static int cqspi_read(struct spi_nor *nor, loff_t from,
-		      size_t len, size_t *retlen, u_char *buf)
-{
-	int ret;
-
-	ret = cqspi_set_protocol(nor, nor->read_proto);
-	if (ret)
-		return ret;
-
-	ret = cqspi_indirect_read_setup(nor, from);
-	if (ret)
-		return ret;
-
-	ret = cqspi_indirect_read_execute(nor, buf, len);
-	if (ret)
-		return ret;
-
-	*retlen += len;
-	return ret;
+	reg &= ~(CQSPI_REG_CONFIG_CHIPSELECT_MASK
+		 << CQSPI_REG_CONFIG_CHIPSELECT_LSB);
+	reg |= (chip_select & CQSPI_REG_CONFIG_CHIPSELECT_MASK)
+	    << CQSPI_REG_CONFIG_CHIPSELECT_LSB;
+	writel(reg, reg_base + CQSPI_REG_CONFIG);
 }
 
-static int cqspi_erase(struct spi_nor *nor, loff_t offs)
+static void cqspi_configure_cs_and_sizes(struct spi_nor *nor)
 {
-	int ret;
-
-	ret = cqspi_set_protocol(nor, nor->erase_proto);
-	if (ret)
-		return ret;
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;
+	void __iomem *iobase = cqspi->iobase;
+	unsigned int reg;
 
-	/* Send write enable, then erase commands. */
-	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
-	if (ret)
-		return ret;
+	/* configure page size and block size. */
+	reg = readl(iobase + CQSPI_REG_SIZE);
+	reg &= ~(CQSPI_REG_SIZE_PAGE_MASK << CQSPI_REG_SIZE_PAGE_LSB);
+	reg &= ~(CQSPI_REG_SIZE_BLOCK_MASK << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
+	reg |= (nor->page_size << CQSPI_REG_SIZE_PAGE_LSB);
+	reg |= (ilog2(nor->mtd.erasesize) << CQSPI_REG_SIZE_BLOCK_LSB);
+	reg |= (nor->addr_width - 1);
+	writel(reg, iobase + CQSPI_REG_SIZE);
 
-	/* Set up command buffer. */
-	ret = cqspi_command_write_addr(nor, nor->erase_opcode, offs);
-	if (ret)
-		return ret;
+	/* configure the chip select */
+	cqspi_chipselect(nor);
 
-	return 0;
+	/* Store the new configuration of the controller */
+	cqspi->current_page_size = nor->page_size;
+	cqspi->current_erase_size = nor->mtd.erasesize;
+	cqspi->current_addr_width = nor->addr_width;
 }
 
 static unsigned int calculate_ticks_for_ns(const unsigned int ref_clk_hz,
@@ -854,36 +808,6 @@ static void cqspi_readdata_capture(struct cqspi_st *cqspi,
 	writel(reg, reg_base + CQSPI_REG_READCAPTURE);
 }
 
-static void cqspi_chipselect(struct spi_nor *nor)
-{
-	struct cqspi_flash_pdata *f_pdata = nor->priv;
-	struct cqspi_st *cqspi = f_pdata->cqspi;
-	void __iomem *reg_base = cqspi->iobase;
-	unsigned int chip_select = f_pdata->cs;
-	unsigned int reg;
-
-	reg = readl(reg_base + CQSPI_REG_CONFIG);
-	if (cqspi->is_decoded_cs) {
-		reg |= CQSPI_REG_CONFIG_DECODE_MASK;
-	} else {
-		reg &= ~CQSPI_REG_CONFIG_DECODE_MASK;
-
-		/* Convert CS if without decoder.
-		 * CS0 to 4b'1110
-		 * CS1 to 4b'1101
-		 * CS2 to 4b'1011
-		 * CS3 to 4b'0111
-		 */
-		chip_select = 0xF & ~(1 << chip_select);
-	}
-
-	reg &= ~(CQSPI_REG_CONFIG_CHIPSELECT_MASK
-		 << CQSPI_REG_CONFIG_CHIPSELECT_LSB);
-	reg |= (chip_select & CQSPI_REG_CONFIG_CHIPSELECT_MASK)
-	    << CQSPI_REG_CONFIG_CHIPSELECT_LSB;
-	writel(reg, reg_base + CQSPI_REG_CONFIG);
-}
-
 static void cqspi_controller_enable(struct cqspi_st *cqspi, bool enable)
 {
 	void __iomem *reg_base = cqspi->iobase;
@@ -899,34 +823,18 @@ static void cqspi_controller_enable(struct cqspi_st *cqspi, bool enable)
 	writel(reg, reg_base + CQSPI_REG_CONFIG);
 }
 
-static void cqspi_switch_cs(struct spi_nor *nor)
-{
-	struct cqspi_flash_pdata *f_pdata = nor->priv;
-	struct cqspi_st *cqspi = f_pdata->cqspi;
-	void __iomem *iobase = cqspi->iobase;
-	unsigned int reg;
-
-	/* configure page size and block size. */
-	reg = readl(iobase + CQSPI_REG_SIZE);
-	reg &= ~(CQSPI_REG_SIZE_PAGE_MASK << CQSPI_REG_SIZE_PAGE_LSB);
-	reg &= ~(CQSPI_REG_SIZE_BLOCK_MASK << CQSPI_REG_SIZE_BLOCK_LSB);
-	reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
-	reg |= (nor->page_size << CQSPI_REG_SIZE_PAGE_LSB);
-	reg |= (ilog2(nor->mtd.erasesize) << CQSPI_REG_SIZE_BLOCK_LSB);
-	reg |= (nor->addr_width - 1);
-	writel(reg, iobase + CQSPI_REG_SIZE);
-
-	/* configure the chip select */
-	cqspi_chipselect(nor);
-}
-
-static int cqspi_prep_unlocked(struct spi_nor *nor, enum spi_nor_ops ops)
+static void cqspi_configure(struct spi_nor *nor)
 {
 	struct cqspi_flash_pdata *f_pdata = nor->priv;
 	struct cqspi_st *cqspi = f_pdata->cqspi;
 	const unsigned int sclk = f_pdata->clk_rate;
-	const int switch_cs = (cqspi->current_cs != f_pdata->cs);
-	const int switch_ck = (cqspi->sclk != sclk);
+	int switch_cs = (cqspi->current_cs != f_pdata->cs);
+	int switch_ck = (cqspi->sclk != sclk);
+
+	if ((cqspi->current_page_size != nor->page_size) ||
+	    (cqspi->current_erase_size != nor->mtd.erasesize) ||
+	    (cqspi->current_addr_width != nor->addr_width))
+		switch_cs = 1;
 
 	if (switch_cs || switch_ck)
 		cqspi_controller_enable(cqspi, 0);
@@ -934,7 +842,7 @@ static int cqspi_prep_unlocked(struct spi_nor *nor, enum spi_nor_ops ops)
 	/* Switch chip select. */
 	if (switch_cs) {
 		cqspi->current_cs = f_pdata->cs;
-		cqspi_switch_cs(nor);
+		cqspi_configure_cs_and_sizes(nor);
 	}
 
 	/* Setup baudrate divisor and delays */
@@ -947,6 +855,111 @@ static int cqspi_prep_unlocked(struct spi_nor *nor, enum spi_nor_ops ops)
 
 	if (switch_cs || switch_ck)
 		cqspi_controller_enable(cqspi, 1);
+}
+
+static int cqspi_set_protocol(struct spi_nor *nor, enum spi_nor_protocol proto)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+
+	switch (proto) {
+	case SNOR_PROTO_1_1_1:
+	case SNOR_PROTO_1_1_2:
+	case SNOR_PROTO_1_1_4:
+	case SNOR_PROTO_1_2_2:
+	case SNOR_PROTO_1_4_4:
+		f_pdata->inst_width = CQSPI_INST_TYPE_SINGLE;
+		break;
+	case SNOR_PROTO_2_2_2:
+		f_pdata->inst_width = CQSPI_INST_TYPE_DUAL;
+		break;
+	case SNOR_PROTO_4_4_4:
+		f_pdata->inst_width = CQSPI_INST_TYPE_QUAD;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (proto) {
+	case SNOR_PROTO_1_1_1:
+	case SNOR_PROTO_1_1_2:
+	case SNOR_PROTO_1_1_4:
+		f_pdata->addr_width = CQSPI_INST_TYPE_SINGLE;
+		break;
+	case SNOR_PROTO_1_2_2:
+	case SNOR_PROTO_2_2_2:
+		f_pdata->addr_width = CQSPI_INST_TYPE_DUAL;
+		break;
+	case SNOR_PROTO_1_4_4:
+	case SNOR_PROTO_4_4_4:
+		f_pdata->addr_width = CQSPI_INST_TYPE_QUAD;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	cqspi_configure(nor);
+
+	return 0;
+}
+
+static void cqspi_write(struct spi_nor *nor, loff_t to,
+			size_t len, size_t *retlen, const u_char *buf)
+{
+	int ret;
+
+	ret = cqspi_set_protocol(nor, nor->write_proto);
+	if (ret)
+		return;
+
+	ret = cqspi_indirect_write_setup(nor, to);
+	if (ret)
+		return;
+
+	ret = cqspi_indirect_write_execute(nor, buf, len);
+	if (ret)
+		return;
+
+	*retlen += len;
+}
+
+static int cqspi_read(struct spi_nor *nor, loff_t from,
+		      size_t len, size_t *retlen, u_char *buf)
+{
+	int ret;
+
+	ret = cqspi_set_protocol(nor, nor->read_proto);
+	if (ret)
+		return ret;
+
+	ret = cqspi_indirect_read_setup(nor, from);
+	if (ret)
+		return ret;
+
+	ret = cqspi_indirect_read_execute(nor, buf, len);
+	if (ret)
+		return ret;
+
+	*retlen += len;
+	return ret;
+}
+
+static int cqspi_erase(struct spi_nor *nor, loff_t offs)
+{
+	int ret;
+
+	ret = cqspi_set_protocol(nor, nor->erase_proto);
+	if (ret)
+		return ret;
+
+	/* Send write enable, then erase commands. */
+	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0);
+	if (ret)
+		return ret;
+
+	/* Set up command buffer. */
+	ret = cqspi_command_write_addr(nor, nor->erase_opcode, offs);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -958,7 +971,7 @@ static int cqspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
 
 	mutex_lock(&cqspi->bus_mutex);
 
-	return cqspi_prep_unlocked(nor, ops);
+	return 0;
 }
 
 static void cqspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
@@ -974,13 +987,9 @@ static int cqspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
 	int ret;
 
 	ret = cqspi_set_protocol(nor, nor->reg_proto);
-	if (ret)
-		goto exit;
-
-	cqspi_prep_unlocked(nor, SPI_NOR_OPS_READ);
+	if (!ret)
+		ret = cqspi_command_read(nor, &opcode, 1, buf, len);
 
-	ret = cqspi_command_read(nor, &opcode, 1, buf, len);
-exit:
 	return ret;
 }
 
@@ -989,13 +998,9 @@ static int cqspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
 	int ret;
 
 	ret = cqspi_set_protocol(nor, nor->reg_proto);
-	if (ret)
-		goto exit;
-
-	cqspi_prep_unlocked(nor, SPI_NOR_OPS_WRITE);
+	if (!ret)
+		ret = cqspi_command_write(nor, opcode, buf, len);
 
-	ret = cqspi_command_write(nor, opcode, buf, len);
-exit:
 	return ret;
 }
 

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 30 lines · Marek Vasut
Quoted 18 lines · Vignesh R
Quoted 10 lines · Marek Vasut
Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Thanks for the patches.
But I am pretty sure that's not the problem at my end, because I have only one flash device on QSPI bus.

Quoted 10 lines

The problem is cqspi_switch_cs() is called only once ie when JEDEC ID is being read(during autodetect of chip), but at that instance, nor->page_size and nor->mtd.erasesize are not yet initialized (They are initialized only after JEDEC ID is looked up in the table and page_size and erasesize are known).
Therefore if nor->page_size is printed during cqspi_switch_cs() then its zero. But nor->page_size reports 256 when printed in cqspi_flash_setup() after spi_nor_scan(). Therefore CQSPI_REG_SIZE register has to be configured only after spi_nor struct is fully populated (i.e after spi_nor_scan() has recognized the slave after JEDEC ID read).

Quoted 3 lines

Got it and I have a patch for this. Nice find, thanks! It gave me 60% read performance boost on my machine :-)

Ah, hope I will see similar improvement at my end :)

Quoted 8 lines

I am now caching the page_size, erasesize, addr_width values, so I can avoid reconfiguring the controller if there is no need for it, but reconfigure it if there is a need. The patch is attached, but it's quite big, so I also pushed a git branch with this driver for your convenience (based on linux-next, expect rebases):

https://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=next/cadence-qspi

Ok, I will test this on my board sometime soon, thanks.

Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#21 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 45 lines · Vignesh
Quoted 30 lines · Marek Vasut
Quoted 18 lines · Vignesh R
Quoted 10 lines · Marek Vasut
Quoted 1 line · Vignesh

Hi Marek,

Hi!

Quoted 1 line

I encountered a issue with this driver while testing.

Try with the attached patches, I am planning to use them for V11 submission. I think you're hitting the problem with missing buslock.

Thanks for the patches.
But I am pretty sure that's not the problem at my end, because I have only one flash device on QSPI bus.

Quoted 10 lines

The problem is cqspi_switch_cs() is called only once ie when JEDEC ID is being read(during autodetect of chip), but at that instance, nor->page_size and nor->mtd.erasesize are not yet initialized (They are initialized only after JEDEC ID is looked up in the table and page_size and erasesize are known).
Therefore if nor->page_size is printed during cqspi_switch_cs() then its zero. But nor->page_size reports 256 when printed in cqspi_flash_setup() after spi_nor_scan(). Therefore CQSPI_REG_SIZE register has to be configured only after spi_nor struct is fully populated (i.e after spi_nor_scan() has recognized the slave after JEDEC ID read).

Quoted 3 lines

Got it and I have a patch for this. Nice find, thanks! It gave me 60% read performance boost on my machine :-)

Ah, hope I will see similar improvement at my end :)

Quoted 6 lines

I am now caching the page_size, erasesize, addr_width values, so I can avoid reconfiguring the controller if there is no need for it, but reconfigure it if there is a need. The patch is attached, but it's quite big, so I also pushed a git branch with this driver for your convenience (based on linux-next, expect rebases):

Quoted 5 lines
Quoted 2 lines

https://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=next/cadence-qspi

Ok, I will test this on my board sometime soon, thanks.

Thanks! Let me know how it went :)

There are now new patches from Cyrille, so I will rebase the driver on top of those and push when ready.

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#22 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

In reply to a message not in the archive

T24gTW9uLCAyMDE2LTAxLTExIGF0IDA1OjM0ICswMTAwLCBNYXJlayBWYXN1dCB3cm90ZToNCj4g RnJvbTogR3JhaGFtIE1vb3JlIDxncm1vb3JlLXl6dlBJQ3VrMkFCTWNnNElISzBrRm9INk1jNE1C MFZ4QHB1YmxpYy5nbWFuZS5vcmc+DQo+IA0KPiBBZGQgc3VwcG9ydCBmb3IgdGhlIENhZGVuY2Ug UVNQSSBjb250cm9sbGVyLiBUaGlzIGNvbnRyb2xsZXIgaXMNCj4gcHJlc2VudCBpbiB0aGUgQWx0 ZXJhIFNvQ0ZQR0EgU29DcyBhbmQgdGhpcyBkcml2ZXIgaGFzIGJlZW4gdGVzdGVkDQo+IG9uIHRo ZSBDeWNsb25lIFYgU29DLg0KDQpJJ20gdHJ5aW5nIHRvIHVzZSB0aGlzIGRyaXZlciB0aGUgQWxh cmljIERldmtpdCBmb3IgQWx0ZXJhJ3MgQXJyaWExMA0KU29DLiAgSXQncyBub3Qgd29ya2luZyBz byBmYXIuICBJbiB0aGUgY291cnNlIG9mIHRyeWluZyB0byBkZWJ1ZyBpdCwNCkkndmUgZm91bmQg YSBmZXcgdGhpbmdzIHdpdGggdGhlIGRyaXZlciBpbiB0aGUgc29jZnBnYS00LjEtbHRzaSBicmFu Y2guDQpIb3dldmVyIG1vc3Qgb2YgdGhlbSBhcmUgaW4gY29kZSB0aGF0J3Mgbm90IHByZXNlbnQg aW4gdGhpcyBkcml2ZXIsDQp3aGljaCBp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b25lIHdpdGg6DQoNCiAgIC8qIFJlZ2lzdGVyIHByb2dyYW1tZWQgd2l0aCBkaXZpZGVyIG1p bnVzIDEgKi8NCiAgIGRpdiA9IERJVl9ST1VORF9VUChyZWZfY2xrX2h6LCBzX2Nsa19oeiAqIDIp IC0gMTsNCiAgIGlmIChkaXYgPiAxNSkNCiAgICAgICAgZGl2ID0gMTU7DQoNCg0KPiArDQo+ICsJ ZGl2ID0gKGRpdiAmIENRU1BJX1JFR19DT05GSUdfQkFVRF9NQVNLKSA8PCBDUVNQSV9SRUdfQ09O RklHX0JBVURfTFNCOw0KPiArCXJlZyB8PSBkaXY7DQo+ICsJd3JpdGVsKHJlZywgcmVnX2Jhc2Ug KyBDUVNQSV9SRUdfQ09ORklHKTsNCj4gK30NCj4gKw0KDQo=
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1463097635.9103.301.camel-dVGoCQn2UwS33l2LyG1otL1RWLrjA2wiZkel5v8DVj8@public.gmane.org

#24 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 10 lines · Trent Piepho
Quoted 5 lines · Marek Vasut

From: Graham Moore <grmoore-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

I'm trying to use this driver the Alaric Devkit for Altera's Arria10 SoC. It's not working so far. In the course of trying to debug it, I've found a few things with the driver in the socfpga-4.1-ltsi branch.

So are you trying to debug this driver or some other out-of-tree driver? btw. I pushed the latest version here:

https://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=next/cadence-qspi

Quoted 2 lines

However most of them are in code that's not present in this driver, which is the newest post of the code I could find to reply to.

I will check the rest later, thanks!

Quoted 149 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 220

Quoted 5 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +5 -0
+					 CQSPI_REG_IRQ_WATERMARK	| \
+					 CQSPI_REG_IRQ_UNDERFLOW)
+
+#define CQSPI_IRQ_STATUS_MASK		0x1FFFF
+

Perhaps a comment.
/* waits for all bits set in mask to be zero (clear==false) or one (clear==true) */

drivers/mtd/spi-nor/cadence-quadspi.c line 233

Quoted 13 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +13 -0
+static int cqspi_wait_for_bit(void __iomem *reg, const u32 mask, bool clear)
+{
+	unsigned long end = jiffies + msecs_to_jiffies(CQSPI_TIMEOUT_MS);
+	u32 val;
+
+	while (1) {
+		val = readl(reg);
+		if (clear)
+			val = ~val;
+		val &= mask;
+
+		if (val == mask)
+			return 0;

Somewhat simpler.

if ((readl(reg) & mask) == (clear ? 0 : mask))

        return 0;

drivers/mtd/spi-nor/cadence-quadspi.c line 236

Quoted 3 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +3 -0
+
+		if (time_after(jiffies, end))
+			return -ETIMEDOUT;

Note that there is a hypervisor/vm/long hardirq etc. bug that can happen without timeouts like this. What happens is after the check of the bits fails, there is a very long delay before this task runs again. This can be easy if one is running under virtualization. The the time_after call reports the timeout expired. But the last time it the bit was checked, before the long delay, was well before the timeout expired. The way to avoid this is to always be sure to check the condition once after the timeout expired. This is sure to give the full timeout.

drivers/mtd/spi-nor/cadence-quadspi.c line 760

Quoted 11 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+	}
+}
+
 
+
+static unsigned int calculate_ticks_for_ns(const unsigned int ref_clk_hz,
+					   const unsigned int ns_val)
+{
+	unsigned int ticks;
+
+	ticks = ref_clk_hz / 1000;	/* kHz */

This division doesn't round up.

drivers/mtd/spi-nor/cadence-quadspi.c line 761

Quoted 1 line
drivers/mtd/spi-nor/cadence-quadspi.c new file +1 -0
+	ticks = DIV_ROUND_UP(ticks * ns_val, 1000000);

But this one does.

drivers/mtd/spi-nor/cadence-quadspi.c line 769

Quoted 8 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +8 -0
+
+	return ticks;
+}
+
+static void cqspi_delay(struct spi_nor *nor, const unsigned int sclk_hz)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;

Isn't the sclk_hz parameter of this function already available here as cqspi->sclk?

drivers/mtd/spi-nor/cadence-quadspi.c line 777

Quoted 8 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +8 -0
+	void __iomem *iobase = cqspi->iobase;
+	const unsigned int ref_clk_hz = cqspi->master_ref_clk_hz;
+	unsigned int tshsl, tchsh, tslch, tsd2d;
+	unsigned int reg;
+	unsigned int tsclk;
+
+	/* calculate the number of ref ticks for one sclk tick */
+	tsclk = (ref_clk_hz + sclk_hz - 1) / sclk_hz;

DIV_ROUND_UP(ref_clk_hz, sclk_hz);

Quoted 14 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +14 -0
+
+	tshsl = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tshsl_ns);
+	/* this particular value must be at least one sclk */
+	if (tshsl < tsclk)
+		tshsl = tsclk;
+
+	tchsh = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tchsh_ns);
+	tslch = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tslch_ns);
+	tsd2d = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tsd2d_ns);
+
+	reg = (tshsl & CQSPI_REG_DELAY_TSHSL_MASK)
+	       << CQSPI_REG_DELAY_TSHSL_LSB;
+	reg |= (tchsh & CQSPI_REG_DELAY_TCHSH_MASK)
+		<< CQSPI_REG_DELAY_TCHSH_LSB;

drivers/mtd/spi-nor/cadence-quadspi.c line 801

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+	reg |= (tslch & CQSPI_REG_DELAY_TSLCH_MASK)
+		<< CQSPI_REG_DELAY_TSLCH_LSB;
+	reg |= (tsd2d & CQSPI_REG_DELAY_TSD2D_MASK)
+		<< CQSPI_REG_DELAY_TSD2D_LSB;
+	writel(reg, iobase + CQSPI_REG_DELAY);
+}
+
+static void cqspi_config_baudrate_div(struct cqspi_st *cqspi,
+				      const unsigned int sclk_hz)
+{

sclk_hz is available as cqspi->sclk.

drivers/mtd/spi-nor/cadence-quadspi.c line 810

Quoted 9 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +9 -0
+	const unsigned int ref_clk_hz = cqspi->master_ref_clk_hz;
+	void __iomem *reg_base = cqspi->iobase;
+	unsigned int reg;
+	unsigned int div;
+
+	reg = readl(reg_base + CQSPI_REG_CONFIG);
+	reg &= ~(CQSPI_REG_CONFIG_BAUD_MASK << CQSPI_REG_CONFIG_BAUD_LSB);
+
+	div = ref_clk_hz / sclk_hz;

Should this round up too?

drivers/mtd/spi-nor/cadence-quadspi.c line 820

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+
+	/* Recalculate the baudrate divisor based on QSPI specification. */
+	if (div > 32)
+		div = 32;
+
+	/* Check if even number. */
+	if (div & 1)
+		div = (div / 2);
+	else
+		div = (div / 2) - 1;

Wouldn't this be the same as div = DIV_ROUND_UP(div, 2) - 1;

The entire div calculation could be done with:

   /* Register programmed with divider minus 1 */
   div = DIV_ROUND_UP(ref_clk_hz, s_clk_hz * 2) - 1;
   if (div > 15)
        div = 15;
Quoted 6 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +6 -0
+
+	div = (div & CQSPI_REG_CONFIG_BAUD_MASK) << CQSPI_REG_CONFIG_BAUD_LSB;
+	reg |= div;
+	writel(reg, reg_base + CQSPI_REG_CONFIG);
+}
+
Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#26 lore raw

Re: [PATCH V10 2/2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dCB2ZXJzaW9uIGhlcmU6DQo+IA0KPiBodHRwczovL2dpdC5rZXJu ZWwub3JnL2NnaXQvbGludXgva2VybmVsL2dpdC9tYXJleC9saW51eC0yLjYuZ2l0L2xvZy8/aD1u ZXh0L2NhZGVuY2UtcXNwaQ0KDQpJJ20gdHJ5aW5nIHRvIHVzZSB0aGUgb3V0IG9mIHRyZWUgZHJp dmVyIGZyb20gQWx0ZXJhJ3MgbGF0ZXN0IGtlcm5lbCwNCmZyb20gaGVyZToNCmh0dHBzOi8vZ2l0 aHViLmNvbS9hbHRlcmEtb3BlbnNvdXJjZS9saW51eC1zb2NmcGdhL3RyZWUvc29jZnBnYS00LjQN Cg0KQnV0IGl0J3Mgbm90IGEgdG90YWxseSBkaWZmZXJlbnQgZHJpdmVyLCBpdCdzIGp1c3QgYW4g b2xkZXIgdmVyc2lvbiBvZg0KdGhpcyBkcml2ZXIuICBJJ20gdGhpbmtpbmcgb2YgcG9ydGluZyBp biB0aGlzIHZlcnNpb24gc2luY2UgSSB0aGluayBpdCdzDQptdWNoIGltcHJvdmVkIChhZnRlciBW MTEgb25lIHdvdWxkIGhvcGUgc28pLiAgUmVhbGx5LCBBbHRlcmEgc2hvdWxkDQp1cGRhdGUgdGhl aXIgc3VwcG9ydGVkIGtlcm5lbCB3aXRoIHRoaXMgY29kZS4NCg0KQ29tbWVudHMgYWJvdXQgd2hh dCdzIG9uIHlvdXIgYnJhbmNoLg0KDQpDb21taXQgIkFSTTogc29jZnBnYTogQWRkIENhbmRlbmNl IFFTUEkgY29udHJvbGxlciBEVCBub2RlIiBvbmx5DQphZGRzIHRoZSBub2RlIGZvciBDeWNsb25l IDUuICBUaGlzIHNhbWUgRFQgbm9kZSBzaG91bGQgYWxzbyBiZSBhZGRlZCB0bw0KdGhlIHNvY2Zw Z2FfYXJyaWExMC5kdHNpIGZpbGUuDQoNCg==
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1463172208.9103.313.camel-dVGoCQn2UwS33l2LyG1otL1RWLrjA2wiZkel5v8DVj8@public.gmane.org

#28 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

Quoted 18 lines · Trent Piepho
Quoted 8 lines · Marek Vasut
Quoted 7 lines · Trent Piepho
Quoted 5 lines · Marek Vasut

From: Graham Moore <grmoore-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

Quoted 8 lines
Quoted 3 lines

I'm trying to use this driver the Alaric Devkit for Altera's Arria10 SoC. It's not working so far. In the course of trying to debug it, I've found a few things with the driver in the socfpga-4.1-ltsi branch.

So are you trying to debug this driver or some other out-of-tree driver? btw. I pushed the latest version here:

https://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=next/cadence-qspi

Quoted 8 lines

I'm trying to use the out of tree driver from Altera's latest kernel, from here:
https://github.com/altera-opensource/linux-socfpga/tree/socfpga-4.4

But it's not a totally different driver, it's just an older version of this driver. I'm thinking of porting in this version since I think it's much improved (after V11 one would hope so). Really, Altera should update their supported kernel with this code.

I'm quite sure they're doing their best and really, they _are_ better than most vendors.

Quoted 6 lines

Comments about what's on your branch.

Commit "ARM: socfpga: Add Candence QSPI controller DT node" only adds the node for Cyclone 5. This same DT node should also be added to the socfpga_arria10.dtsi file.

I don't have A10 devkit (yet), but feel free to send a patch once this hits mainline if you can test it on A10. I updated the commit message until then.

The latest stuff is pushed here:
http://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=korg/next/cadence-qspi-v12

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#29 lore raw

Re: [PATCH V10 2/2] mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller.

In reply to a message not in the archive
Quoted 39 lines · Trent Piepho
Quoted 5 lines · Marek Vasut

From: Graham Moore <grmoore-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org>

Add support for the Cadence QSPI controller. This controller is present in the Altera SoCFPGA SoCs and this driver has been tested on the Cyclone V SoC.

I'm trying to use this driver the Alaric Devkit for Altera's Arria10 SoC. It's not working so far. In the course of trying to debug it, I've found a few things with the driver in the socfpga-4.1-ltsi branch. However most of them are in code that's not present in this driver, which is the newest post of the code I could find to reply to.

drivers/mtd/spi-nor/cadence-quadspi.c line 220

Quoted 5 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +5 -0
+					 CQSPI_REG_IRQ_WATERMARK	| \
+					 CQSPI_REG_IRQ_UNDERFLOW)
+
+#define CQSPI_IRQ_STATUS_MASK		0x1FFFF
+

Perhaps a comment.
/* waits for all bits set in mask to be zero (clear==false) or one (clear==true) */

drivers/mtd/spi-nor/cadence-quadspi.c line 233

Quoted 13 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +13 -0
+static int cqspi_wait_for_bit(void __iomem *reg, const u32 mask, bool clear)
+{
+	unsigned long end = jiffies + msecs_to_jiffies(CQSPI_TIMEOUT_MS);
+	u32 val;
+
+	while (1) {
+		val = readl(reg);
+		if (clear)
+			val = ~val;
+		val &= mask;
+
+		if (val == mask)
+			return 0;

Somewhat simpler.

Quoted 2 lines

if ((readl(reg) & mask) == (clear ? 0 : mask))

        return 0;

This looks far more cryptic though, so I will skip this one.

Quoted 4 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 236

Quoted 3 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +3 -0
+
+		if (time_after(jiffies, end))
+			return -ETIMEDOUT;
Quoted 8 lines

Note that there is a hypervisor/vm/long hardirq etc. bug that can happen without timeouts like this. What happens is after the check of the bits fails, there is a very long delay before this task runs again. This can be easy if one is running under virtualization. The the time_after call reports the timeout expired. But the last time it the bit was checked, before the long delay, was well before the timeout expired. The way to avoid this is to always be sure to check the condition once after the timeout expired. This is sure to give the full timeout.

The CQSPI timeout is 500 mS, which is pretty generous considering the completion will happen in the first 10 mS tops. Do you think this is of concern here and it's worth complicating the code further ?

Quoted 16 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 760

Quoted 11 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+	}
+}
+
 
+
+static unsigned int calculate_ticks_for_ns(const unsigned int ref_clk_hz,
+					   const unsigned int ns_val)
+{
+	unsigned int ticks;
+
+	ticks = ref_clk_hz / 1000;	/* kHz */

This division doesn't round up.

drivers/mtd/spi-nor/cadence-quadspi.c line 761

Quoted 1 line
drivers/mtd/spi-nor/cadence-quadspi.c new file +1 -0
+	ticks = DIV_ROUND_UP(ticks * ns_val, 1000000);

But this one does.

Quoted 11 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 769

Quoted 8 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +8 -0
+
+	return ticks;
+}
+
+static void cqspi_delay(struct spi_nor *nor, const unsigned int sclk_hz)
+{
+	struct cqspi_flash_pdata *f_pdata = nor->priv;
+	struct cqspi_st *cqspi = f_pdata->cqspi;

Isn't the sclk_hz parameter of this function already available here as cqspi->sclk?

It is , good catch, thanks.

Quoted 10 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 777

Quoted 8 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +8 -0
+	void __iomem *iobase = cqspi->iobase;
+	const unsigned int ref_clk_hz = cqspi->master_ref_clk_hz;
+	unsigned int tshsl, tchsh, tslch, tsd2d;
+	unsigned int reg;
+	unsigned int tsclk;
+
+	/* calculate the number of ref ticks for one sclk tick */
+	tsclk = (ref_clk_hz + sclk_hz - 1) / sclk_hz;

DIV_ROUND_UP(ref_clk_hz, sclk_hz);

OK

Quoted 18 lines
Quoted 18 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +18 -0
+
+	tshsl = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tshsl_ns);
+	/* this particular value must be at least one sclk */
+	if (tshsl < tsclk)
+		tshsl = tsclk;
+
+	tchsh = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tchsh_ns);
+	tslch = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tslch_ns);
+	tsd2d = calculate_ticks_for_ns(ref_clk_hz, f_pdata->tsd2d_ns);
+
+	reg = (tshsl & CQSPI_REG_DELAY_TSHSL_MASK)
+	       << CQSPI_REG_DELAY_TSHSL_LSB;
+	reg |= (tchsh & CQSPI_REG_DELAY_TCHSH_MASK)
+		<< CQSPI_REG_DELAY_TCHSH_LSB;
+	reg |= (tslch & CQSPI_REG_DELAY_TSLCH_MASK)
+		<< CQSPI_REG_DELAY_TSLCH_LSB;
+	reg |= (tsd2d & CQSPI_REG_DELAY_TSD2D_MASK)
+		<< CQSPI_REG_DELAY_TSD2D_LSB;
Quoted 8 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 801

Quoted 6 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +6 -0
+	writel(reg, iobase + CQSPI_REG_DELAY);
+}
+
+static void cqspi_config_baudrate_div(struct cqspi_st *cqspi,
+				      const unsigned int sclk_hz)
+{

sclk_hz is available as cqspi->sclk.

OK

Quoted 25 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 810

Quoted 9 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +9 -0
+	const unsigned int ref_clk_hz = cqspi->master_ref_clk_hz;
+	void __iomem *reg_base = cqspi->iobase;
+	unsigned int reg;
+	unsigned int div;
+
+	reg = readl(reg_base + CQSPI_REG_CONFIG);
+	reg &= ~(CQSPI_REG_CONFIG_BAUD_MASK << CQSPI_REG_CONFIG_BAUD_LSB);
+
+	div = ref_clk_hz / sclk_hz;

Should this round up too?

drivers/mtd/spi-nor/cadence-quadspi.c line 820

Quoted 10 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +10 -0
+
+	/* Recalculate the baudrate divisor based on QSPI specification. */
+	if (div > 32)
+		div = 32;
+
+	/* Check if even number. */
+	if (div & 1)
+		div = (div / 2);
+	else
+		div = (div / 2) - 1;

Wouldn't this be the same as div = DIV_ROUND_UP(div, 2) - 1;

Quoted 4 lines

The entire div calculation could be done with:

   /* Register programmed with divider minus 1 */
   div = DIV_ROUND_UP(ref_clk_hz, s_clk_hz * 2) - 1;

Good point, thanks.

Quoted 2 lines
   if (div > 15)
        div = 15;

You can even drop this, CQSPI_REG_CONFIG_BAUD_MASK is 0xf.

Quoted 8 lines

drivers/mtd/spi-nor/cadence-quadspi.c line 826

Quoted 7 lines
drivers/mtd/spi-nor/cadence-quadspi.c new file +6 -0
+
+	div = (div & CQSPI_REG_CONFIG_BAUD_MASK) << CQSPI_REG_CONFIG_BAUD_LSB;
+	reg |= div;
+	writel(reg, reg_base + CQSPI_REG_CONFIG);
+}
+

I pushed V12 btw:

http://git.kernel.org/cgit/linux/kernel/git/marex/linux-2.6.git/log/?h=korg/next/cadence-qspi-v12

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Acked-by
#30 lore raw
In reply to a message not in the archive
Quoted 36 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
---
 .../devicetree/bindings/mtd/cadence-quadspi.txt    | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/cadence-quadspi.txt

V2: Add cdns prefix to driver-specific bindings.
V3: Use existing property "is-decoded-cs" instead of creating a
duplicate, "ext-decoder". Timing parameters are in nanoseconds, not master reference clocks. Remove bus-num completely.
V4: Add new properties fifo-width and trigger-address
V7: - Prefix all of the Cadence-specific properties with cdns prefix,
those are in particular "cdns,is-decoded-cs", "cdns,fifo-depth", "cdns,fifo-width", "cdns,trigger-address".
- Drop bogus properties which were not used and were incorrect.
V8: Align lines to 80 chars.

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +0 -0
new file mode 100644
index 0000000..f248056

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +4 -0
@@ -0,0 +1,56 @@
+* Cadence Quad SPI controller
+
+Required properties:
+- compatible : Should be "cdns,qspi-nor".

Fine, but I expect to see SOCs using this block add their own compatible strings. It wouldn't surprise me that we already have some using this block.

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#31 lore raw
Quoted 54 lines · Rob Herring
Quoted 44 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>

---

 .../devicetree/bindings/mtd/cadence-quadspi.txt    | 56
 ++++++++++++++++++++++ 1 file changed, 56 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt

V2: Add cdns prefix to driver-specific bindings.
V3: Use existing property "is-decoded-cs" instead of creating a

duplicate, "ext-decoder". Timing parameters are in nanoseconds, not master reference clocks. Remove bus-num completely.

V4: Add new properties fifo-width and trigger-address
V7: - Prefix all of the Cadence-specific properties with cdns prefix,

those are in particular "cdns,is-decoded-cs", "cdns,fifo-depth", "cdns,fifo-width", "cdns,trigger-address".

- Drop bogus properties which were not used and were incorrect.

V8: Align lines to 80 chars.

(quoted diff) +0 -0

b/Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file mode 100644
index 0000000..f248056

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +4 -0
@@ -0,0 +1,56 @@
+* Cadence Quad SPI controller
+
+Required properties:
+- compatible : Should be "cdns,qspi-nor".

Fine, but I expect to see SOCs using this block add their own compatible strings. It wouldn't surprise me that we already have some using this block.

Quoted 1 line

I finally got an Ack on this, I am so happy :-)

As for the SoCs, there is Altera SoCFPGA Gen 5 and Gen 10 which uses this. Then there is some TI SoC, but I don't know the model. Vignesh (on CC) would. Then there is some ST SoC, but I have no idea what that's all about, sorry.

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#33 lore raw
Quoted 22 lines · Marek Vasut
Quoted 13 lines · Rob Herring

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt line 4

Quoted 7 lines · Marek Vasut
Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +4 -0
@@ -0,0 +1,56 @@
+* Cadence Quad SPI controller
+
+Required properties:
+- compatible : Should be "cdns,qspi-nor".

Fine, but I expect to see SOCs using this block add their own compatible strings. It wouldn't surprise me that we already have some using this block.

Quoted 1 line

I finally got an Ack on this, I am so happy :-)

As for the SoCs, there is Altera SoCFPGA Gen 5 and Gen 10 which uses this. Then there is some TI SoC, but I don't know the model. Vignesh (on CC) would. Then there is some ST SoC, but I have no idea what that's all about, sorry.

Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition. So you can, today, have:

	foo@xxxx {
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#35 lore raw
Quoted 39 lines · Brian Norris
Quoted 23 lines · Marek Vasut
Quoted 13 lines · Rob Herring

Documentation/devicetree/bindings/mtd/cadence-quadspi.txt line 4

Quoted 7 lines · Marek Vasut
Documentation/devicetree/bindings/mtd/cadence-quadspi.txt new file +4 -0
@@ -0,0 +1,56 @@
+* Cadence Quad SPI controller
+
+Required properties:
+- compatible : Should be "cdns,qspi-nor".

Fine, but I expect to see SOCs using this block add their own compatible strings. It wouldn't surprise me that we already have some using this block.

Quoted 1 line

I finally got an Ack on this, I am so happy :-)

As for the SoCs, there is Altera SoCFPGA Gen 5 and Gen 10 which uses this. Then there is some TI SoC, but I don't know the model. Vignesh (on CC) would. Then there is some ST SoC, but I have no idea what that's all about, sorry.

Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition. So you can, today, have:

Quoted 7 lines
	foo@xxxx {
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

Ah, got it, thanks!

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#37 lore raw
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 7 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition. So you can, today, have:

Quoted 7 lines
Quoted 7 lines
	foo@xxxx {
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

The support for TI SoC that has this IP is not in upstream yet. I will add TI-specific compatible later. It will be:

	foo@xxxx {
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...
};

Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#39 lore raw
Quoted 32 lines · Vignesh R
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition.

So you can, today, have:

	foo@xxxx {
Quoted 7 lines
Quoted 7 lines
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

Quoted 7 lines

The support for TI SoC that has this IP is not in upstream yet. I will add TI-specific compatible later. It will be:

	foo@xxxx {
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...
};

Do you expect any specifics which cannot be handled by the current bindings btw? In my socfpga case, the compatible strings will be probably:

"altr,socfpga-gen5-qspi"

Dinh, Graham, do you agree with this or should we use something else ?

Thanks!

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#41 lore raw
Quoted 41 lines · Marek Vasut
Quoted 32 lines · Vignesh R
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition.

So you can, today, have:

	foo@xxxx {
Quoted 7 lines
Quoted 7 lines
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

Quoted 7 lines

The support for TI SoC that has this IP is not in upstream yet. I will add TI-specific compatible later. It will be:

	foo@xxxx {
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...
};

Quoted 7 lines

Do you expect any specifics which cannot be handled by the current bindings btw? In my socfpga case, the compatible strings will be probably:

"altr,socfpga-gen5-qspi"

Dinh, Graham, do you agree with this or should we use something else ?

I agree.

Dinh

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 56B38488.2000502-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#43 lore raw
Quoted 50 lines · Dinh Nguyen
Quoted 49 lines · Marek Vasut
Quoted 35 lines · Vignesh R
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition.

So you can, today, have:

	foo@xxxx {
Quoted 7 lines
Quoted 7 lines
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

The support for TI SoC that has this IP is not in upstream yet. I will

Quoted 8 lines

add TI-specific compatible later. It will be:

	foo@xxxx {
	
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...

};

Do you expect any specifics which cannot be handled by the current bindings btw? In my socfpga case, the compatible strings will be probably:

Quoted 5 lines
Quoted 3 lines

"altr,socfpga-gen5-qspi"

Dinh, Graham, do you agree with this or should we use something else ?

I agree.

Thanks

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#44 lore raw
In reply to a message not in the archive
Quoted 36 lines · Marek Vasut
Quoted 35 lines · Vignesh R
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition.

So you can, today, have:

	foo@xxxx {
Quoted 7 lines
Quoted 7 lines
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

The support for TI SoC that has this IP is not in upstream yet. I will add TI-specific compatible later. It will be:

Quoted 8 lines
Quoted 4 lines
	foo@xxxx {
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...
};

Do you expect any specifics which cannot be handled by the current bindings btw? In my socfpga case, the compatible strings will be probably:

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#46 lore raw
Quoted 46 lines · Vignesh
Quoted 45 lines · Marek Vasut
Quoted 43 lines · Vignesh R
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Brian Norris
Quoted 2 lines · Marek Vasut
Quoted 1 line · Rob Herring

On Mon, Jan 11, 2016 at 05:34:45AM +0100, Marek Vasut wrote:

[...]

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines

All these SoCs should be capable of tweaking the block to fit their needs by just the DT properties. I believe they differ only in the FIFO depth and sometimes someone is greedy and uses 4:16 CS multiplexer, which is an external passive component, but that's all.

Would we need soc-specific compatible strings if this is the case?

It's nice when most things can be supported with a small set of DT properties, as you've done. But IUIC, I think it's usually good practice to define and use SoC-specific (or maybe SoC family) compatible strings in the docs and DTS files, in addition to the generic one, in case there are future quirks that need to be handled. Note that you don't actually have to use these in the driver yet, but it's good to have a definition.

So you can, today, have:

	foo@xxxx {
Quoted 7 lines
Quoted 7 lines
		compatible = "ti,baz-12345", "cdns,qspi-nor";
		...
	
	};

And we have the option to pick up "ti,baz-12345" in the Linux driver *if needed.*

The support for TI SoC that has this IP is not in upstream yet. I will

add TI-specific compatible later. It will be:

	foo@xxxx {
	
		compatible = "ti,k2g-qspi", "cdns,qspi-nor";

...

};

Quoted 8 lines
Quoted 4 lines

Do you expect any specifics which cannot be handled by the current bindings btw?

In my socfpga case, the compatible strings will be probably:

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.

Can't you somehow poll the hardware to check whether or not it's ready instead of adding some random delay ?

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#48 lore raw
Quoted 2 lines · Marek Vasut
Quoted 1 line · Vignesh

On 2/4/2016 4:55 PM, Marek Vasut wrote:

[...]

Quoted 7 lines
Quoted 4 lines

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.

Can't you somehow poll the hardware to check whether or not it's ready instead of adding some random delay ?

There is no dedicated register to poll as such.

According to TRM:
"Wait for couple of cycles of QSPI_REF_CLK(functional clock of QSPI @384MHz) until CQSPI_REG_INDIRECTWR[0] bit is internally synchronized by the QSPI module before writing to flash".

So, a few ns(~6ns @384MHz) delay is needed (or accessing a QSPI module register should be sufficient as it will take more than 2 clock cycles). I believe this delay is specific to TI K2G SoC and maybe needs to be tied to the binding.

Signature · 6 lines
Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#50 lore raw
Quoted 20 lines · Vignesh R
Quoted 2 lines · Marek Vasut
Quoted 1 line · Vignesh

On 2/4/2016 4:55 PM, Marek Vasut wrote:

[...]

Quoted 7 lines
Quoted 4 lines

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.

Can't you somehow poll the hardware to check whether or not it's ready instead of adding some random delay ?

There is no dedicated register to poll as such.

According to TRM:
"Wait for couple of cycles of QSPI_REF_CLK(functional clock of QSPI @384MHz) until CQSPI_REG_INDIRECTWR[0] bit is internally synchronized by the QSPI module before writing to flash".

Quoted 4 lines

So, a few ns(~6ns @384MHz) delay is needed (or accessing a QSPI module register should be sufficient as it will take more than 2 clock cycles). I believe this delay is specific to TI K2G SoC and maybe needs to be tied to the binding.

OK, got it. Dinh/Graham, can you check if this might be needed on SoCFPGA too please?

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#51 lore raw
Quoted 21 lines · Marek Vasut
Quoted 20 lines · Vignesh R
Quoted 2 lines · Marek Vasut
Quoted 1 line · Vignesh

On 2/4/2016 4:55 PM, Marek Vasut wrote:

[...]

Quoted 7 lines
Quoted 4 lines

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.

Can't you somehow poll the hardware to check whether or not it's ready instead of adding some random delay ?

There is no dedicated register to poll as such.

According to TRM:
"Wait for couple of cycles of QSPI_REF_CLK(functional clock of QSPI @384MHz) until CQSPI_REG_INDIRECTWR[0] bit is internally synchronized by the QSPI module before writing to flash".

Quoted 8 lines
Quoted 4 lines

So, a few ns(~6ns @384MHz) delay is needed (or accessing a QSPI module register should be sufficient as it will take more than 2 clock cycles). I believe this delay is specific to TI K2G SoC and maybe needs to be tied to the binding.

OK, got it. Dinh/Graham, can you check if this might be needed on SoCFPGA too please?

I don't see any such requirement in the data sheet. It's working without it. So I think it's not needed on SoCFPGA

-Graham

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): 56BB60F1.9070306-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#53 lore raw
Quoted 27 lines · Graham Moore
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Vignesh R
Quoted 2 lines · Marek Vasut
Quoted 1 line · Vignesh

On 2/4/2016 4:55 PM, Marek Vasut wrote:

[...]

Quoted 7 lines
Quoted 4 lines

Yeah, there is delay(of few ns) required between writing to INDIRECTWR_START bit and actually writing data to flash(i.e writesl() call). This is specific to TI K2G SoC and needs to be tied to the new binding.

Can't you somehow poll the hardware to check whether or not it's ready instead of adding some random delay ?

There is no dedicated register to poll as such.

According to TRM:
"Wait for couple of cycles of QSPI_REF_CLK(functional clock of QSPI @384MHz) until CQSPI_REG_INDIRECTWR[0] bit is internally synchronized by the QSPI module before writing to flash".

So, a few ns(~6ns @384MHz) delay is needed (or accessing a QSPI module register should be sufficient as it will take more than 2 clock cycles). I believe this delay is specific to TI K2G SoC and maybe needs to be tied to the binding.

Quoted 7 lines
Quoted 4 lines

OK, got it. Dinh/Graham, can you check if this might be needed on SoCFPGA too
please?

I don't see any such requirement in the data sheet. It's working without it. So I think it's not needed on SoCFPGA

All right, so we will just add a special property or compat string for the TI SoC. But we need to get this driver mainlined first :)

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#55 lore raw

On 02/10/2016 10:17 AM, Marek Vasut wrote:

[...]

Quoted 3 lines

All right, so we will just add a special property or compat string for the TI SoC. But we need to get this driver mainlined first :)

Hi Marek,

How's that mainlining going? You probably noticed this patch needed some refactoring for 4.4. In the course of testing, we realized this driver needs to enable its clock.

Do you have a 4.4 or later version in your tree? I'd like to add the clock enabling.

-Graham
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#57 lore raw
Quoted 9 lines · Graham Moore

On 02/10/2016 10:17 AM, Marek Vasut wrote:

[...]

Quoted 3 lines

All right, so we will just add a special property or compat string for the TI SoC. But we need to get this driver mainlined first :)

Hi Marek,

Hi Graham,

Quoted 6 lines

How's that mainlining going? You probably noticed this patch needed some refactoring for 4.4. In the course of testing, we realized this driver needs to enable its clock.

Do you have a 4.4 or later version in your tree? I'd like to add the clock enabling.

Still waiting for the patches from Cyrille to go in, so this patch is stuck. I just checked next and some of them made it, but there are more which didn't. I have a V10 of this patch , it is in the ML already [1], so try playing around with that.

I have linux 4.4 branch with all the necessary patches backported and/or applied if you'd be interested in that, but I do my development on linux-next .

What sort of clock patch are you missing ?

[1] https://patchwork.ozlabs.org/patch/565599/

Quoted 1 line

-Graham

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#58 lore raw
Quoted 25 lines · Marek Vasut
Quoted 9 lines · Graham Moore

On 02/10/2016 10:17 AM, Marek Vasut wrote:

[...]

Quoted 3 lines

All right, so we will just add a special property or compat string for the TI SoC. But we need to get this driver mainlined first :)

Hi Marek,

Hi Graham,

Quoted 6 lines

How's that mainlining going? You probably noticed this patch needed some refactoring for 4.4. In the course of testing, we realized this driver needs to enable its clock.

Do you have a 4.4 or later version in your tree? I'd like to add the clock enabling.

Still waiting for the patches from Cyrille to go in, so this patch is stuck. I just checked next and some of them made it, but there are more which didn't. I have a V10 of this patch , it is in the ML already [1], so try playing around with that.

Quoted 6 lines

I have linux 4.4 branch with all the necessary patches backported and/or applied if you'd be interested in that, but I do my development on linux-next .

What sort of clock patch are you missing ?

The clock needs to be enabled, after the devm_clk_get(). I've added a clk_prepare_enable() there, and also clk_disable_unprepare() in the remove function.

That ML patch won't apply to any tree I have, 4.4, 4.5, linux-next, etc.
Maybe I'll just wait until it's in linux-next.

-Graham

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): 56E70024.3080205-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#60 lore raw
Quoted 30 lines · Graham Moore
Quoted 29 lines · Marek Vasut
Quoted 9 lines · Graham Moore

On 02/10/2016 10:17 AM, Marek Vasut wrote:

[...]

Quoted 3 lines

All right, so we will just add a special property or compat string for the TI SoC. But we need to get this driver mainlined first :)

Hi Marek,

Hi Graham,

Quoted 6 lines

How's that mainlining going? You probably noticed this patch needed some refactoring for 4.4. In the course of testing, we realized this driver needs to enable its clock.

Do you have a 4.4 or later version in your tree? I'd like to add the clock enabling.

Still waiting for the patches from Cyrille to go in, so this patch is stuck. I just checked next and some of them made it, but there are more which didn't. I have a V10 of this patch , it is in the ML already [1], so try playing around with that.

I have linux 4.4 branch with all the necessary patches backported and/or applied if you'd be interested in that, but I do my development on linux-next .

Quoted 6 lines
Quoted 2 lines

What sort of clock patch are you missing ?

The clock needs to be enabled, after the devm_clk_get(). I've added a clk_prepare_enable() there, and also clk_disable_unprepare() in the remove function.

Yeah, please send me a patch and I will add it into the driver, add your SoB line and repost.

Quoted 2 lines

That ML patch won't apply to any tree I have, 4.4, 4.5, linux-next, etc.
Maybe I'll just wait until it's in linux-next.

I'll send you the backport to 4.4 off-list, so I don't bother people here.

Quoted 2 lines

-Graham

Signature · 6 lines
Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#61 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 14 lines · Marek Vasut

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
Quoted 1 line

---

I think you also need to CC the following people for proper review of these bindings:

Rob Herring <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Pawel Moll <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Mark Rutland <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Ian Campbell <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Kumar Gala <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)

Dinh

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): 5693D306.9070001-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#63 lore raw
Quoted 1 line · Dinh Nguyen

Hi Marek,

Hi!

Quoted 20 lines · Marek Vasut
Quoted 14 lines

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
Quoted 1 line

---

I think you also need to CC the following people for proper review of these bindings:

Quoted 10 lines

Rob Herring <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Pawel Moll <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Mark Rutland <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Ian Campbell <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Kumar Gala <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)

Isn't it enough to submit them to devicetree@vger ?

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#65 lore raw
Quoted 36 lines · Marek Vasut
Quoted 1 line · Dinh Nguyen

Hi Marek,

Hi!

Quoted 20 lines · Marek Vasut
Quoted 14 lines

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
Quoted 1 line

---

I think you also need to CC the following people for proper review of these bindings:

Quoted 10 lines

Rob Herring <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Pawel Moll <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Mark Rutland <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Ian Campbell <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Kumar Gala <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)

Quoted 2 lines

Isn't it enough to submit them to devicetree@vger ?

Not sure, but I always CC those names explicitly for DTS bindings since they are listed in the MAINTAINERS file.

Dinh

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 5693E079.3050301-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org

#67 lore raw
Quoted 37 lines · Dinh Nguyen
Quoted 36 lines · Marek Vasut
Quoted 1 line · Dinh Nguyen

Hi Marek,

Hi!

Quoted 30 lines · Marek Vasut
Quoted 14 lines

From: Graham Moore <[email protected]>

Add binding document for the Cadence QSPI controller.

Cc Alan Tull <[email protected]>
Cc Brian Norris <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Graham Moore <[email protected]>
Cc "R, Vignesh" <[email protected]>
Cc Yves Vandervennet <[email protected]>
Quoted 1 line

---

I think you also need to CC the following people for proper review of these bindings:

Rob Herring <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Pawel Moll <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Mark Rutland <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Ian Campbell <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)
Kumar Gala <[email protected]> (maintainer:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS)

Quoted 4 lines
Quoted 1 line

Isn't it enough to submit them to devicetree@vger ?

Not sure, but I always CC those names explicitly for DTS bindings since they are listed in the MAINTAINERS file.

OK, will do in the next revision (if needed). Thanks!

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html