Skip to contentSkip to conversation

RFC for Zynq QSPI

RFC PATCH In review Naga Sureshkumar Relli 6 participants 15 messages Mar 23, 2018 – Jun 26, 2019 2 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover RFC for Zynq QSPI

Xilinx Zynq uses a QSPI controller that is based on the Cadence SPI IP. This controller implements all the functionality required to support Quad SPI NOR flash devices.
This driver along with the MTD layer is used to support flash devices.

This series is for the following purposes:
- RFC of the Quad SPI driver.
- We currently use a custom MTD layer and would like to get inputs on dual stacked/dual parallel handling (described below).

The flash device(s) can be connected in the three configurations:
1. Single - One flash device with 1 CS, 1 Clock and 4 IO lines.
2. Dual Parallel - Two flash devices connected with common CS and separate IO lines (resulting in 8 IO lines).
In this configuration, the controller
a) Duplicates commands, address etc. sent on both sets of 4 IO lines.
b) Stripes data both transmitted and received i.e.
4 bits of data is sent to the first flash and the other 4 bits to the second flash. Similarly read data is also consolidated.
Due to this, TX and RX data handling in the driver need special handling for parallel mode.
3. Dual Stacked - Two flash devices connected with separate CS and 4 common IO lines. This is largely similar to single, except for the slave selection logic.
The above configuration is conveyed to the QSPI driver through a devicetree property.

The QSPI driver differs from the existing Cadence SPI driver in the following respects majorly:
1. TX and RX handling: Different TX registers are used to write into the TX FIFO. TXD0, TXD1, TXD2 and TXD3 are used write 4, 1, 2 and 3 bytes respectively. Depending on the TXD register used, the received bytes also need to be handled separately.
2. Depending on the configuration in which flash devices are connected (single, parallel or stacked), QSPI controller configuration registers need to be modified.
3. There is no support for extended slave select in QSPI, as opposed to SPI. In case of stacked configuration, the slave select field remains the same and a different configuration bit is used to select between the two flash devices.
4. Handling of dual parallel configuration.

MTD layer:
The Xilinx Zynq MTD layer by far makes use of the mainline version with some differences. The primary flash families supported are Spansion, Winbond and Micron.
- Probe:
- In dual configurations, both flash devices are recognized as one continuous memory. (ID is read only from one flash and it is a pre-stated assumption that both flash devices have the same flash make and size.)
- Addressing:
a) In dual stacked mode, the address passed to the MTD layer can be between 0x0 to 2*(one flash size). Hence the MTD layer has to recognize whether the address belongs to the first flash or the second flash subtract the offset and indicate the same to the QSPI driver.
b) In dual stacked mode too the address can range between
0 to 2*(one flash size). But, when an 8 bit word is written, 4 bits are written to the first and 4 bits are written to the second flash. Hence the address sent is always halved and checks are in place for even address and even length.
- 4 byte addressing is not supported and hence bank selection logic is used along with the addressing system described above.
- Flash register read/writes, for example, lock/unlock, quad enable etc. are handled differently in dual stacked and parallel modes.

This is tested with current master branch of Linux.
To make Zynq QSPI work, we need to tweak spi-nor.c.
I agree that changing the spi-nor layer apis, doesn't look good but i didn't find a way to do the same.
So please suggest a way to handle Zynq QSPI controller in dual parallel and stacked modes.
we can move the spi/spi-zynq-qspi.c to spi-nor/ but even in that case also changes are needed in spi-nor.c.
What ever the changes we do to make Zynq QSPI work, will applicable for Xilinx ZynqMP SOC QSPI controller(spi-zynqmp-qspi.c) as well.
I am happy to do the changes suggested, so that we will have a solution for Xilinx Zynq and ZynqMP SOC QSPI controllers.

Naga Sureshkumar Relli (5):
spi: Add support for Zynq qspi controller
mtd: spi-nor: Add support for Zynq QSPI controller
mtd: spi-nor: Add Dual Parallel and Stacked support for Zynq QSPI
spi: Add PM Support for Zynq QSPI controller
devicetree: Add devicetree bindings documentation for Zynq QSPI

 .../devicetree/bindings/spi/spi-zynq-qspi.txt      |  26 +
 drivers/mtd/spi-nor/spi-nor.c                      | 425 ++++++++++-
 drivers/spi/Kconfig                                |  15 +
 drivers/spi/Makefile                               |   1 +
 drivers/spi/spi-zynq-qspi.c                        | 827 +++++++++++++++++++++
 include/linux/mtd/spi-nor.h                        |  15 +-
 include/linux/spi/spi.h                            |   5 +-
 7 files changed, 1276 insertions(+), 38 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt
 create mode 100644 drivers/spi/spi-zynq-qspi.c
Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH 3/5 mtd: spi-nor: Add Dual Parallel and Stacked support for Zynq QSPI

This patch adds Xilinx Zynq QSPI dual parallel and stacked support.

---
 drivers/mtd/spi-nor/spi-nor.c | 241 ++++++++++++++++++++++++++++++++++++++----
 include/linux/mtd/spi-nor.h   |   2 +
 2 files changed, 220 insertions(+), 23 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +218 -23
index 7698a92..03aa8c9 100644
@@ -106,15 +106,24 @@ static const struct flash_info *spi_nor_match_id(const char *name);
 static int read_sr(struct spi_nor *nor)
 {
 	int ret;
-	u8 val;
+	u8 val[2];
 
-	ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val, 1);
-	if (ret < 0) {
-		pr_err("error %d reading SR\n", (int) ret);
-		return ret;
+	if (nor->isparallel) {
+		ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val[0], 2);
+		if (ret < 0) {
+			pr_err("error %d reading SR\n", (int) ret);
+			return ret;
+		}
+		val[0] |= val[1];
+	} else {
+		ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val[0], 1);
+		if (ret < 0) {
+			pr_err("error %d reading SR\n", (int) ret);
+			return ret;
+		}
 	}
 
-	return val;
+	return val[0];
 }
 
 /*
@@ -125,15 +134,24 @@ static int read_sr(struct spi_nor *nor)
 static int read_fsr(struct spi_nor *nor)
 {
 	int ret;
-	u8 val;
+	u8 val[2];
 
-	ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val, 1);
-	if (ret < 0) {
-		pr_err("error %d reading FSR\n", ret);
-		return ret;
+	if (nor->isparallel) {
+		ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val[0], 2);
+		if (ret < 0) {
+			pr_err("error %d reading FSR\n", ret);
+			return ret;
+		}
+		val[0] &= val[1];
+	} else {
+		ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val[0], 1);
+		if (ret < 0) {
+			pr_err("error %d reading FSR\n", ret);
+			return ret;
+		}
 	}
 
-	return val;
+	return val[0];
 }
 
 /*
@@ -451,7 +469,10 @@ static int write_ear(struct spi_nor *nor, u32 addr)
 	addr = addr % (u32) mtd->size;
 	ear = addr >> 24;
 
-	if (ear == nor->curbank)
+	if ((!nor->isstacked) && (ear == nor->curbank))
+		return 0;
+
+	if (nor->isstacked && (mtd->size <= 0x2000000))
 		return 0;
 
 	if (nor->jedec_id == CFI_MFR_AMD)
@@ -480,9 +501,21 @@ static int erase_chip(struct spi_nor *nor)
 	u32 ret;
 	dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd.size >> 10));
 
+	if (nor->isstacked)
+		nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
 	ret = nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0);
 	if (ret)
 		return ret;
+	if (nor->isstacked) {
+		/* Wait until previous write command finished */
+		ret = spi_nor_wait_till_ready(nor);
+		if (ret)
+			return ret;
+
+		nor->spi->master->flags |= SPI_MASTER_U_PAGE;
+
+		ret = nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0);
+	}
 
 	return ret;
 }
@@ -619,6 +652,20 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 			write_enable(nor);
 			offset = addr;
 
+			if (nor->isparallel == 1)
+				offset /= 2;
+
+			if (nor->isstacked == 1) {
+				if (offset >= (mtd->size / 2)) {
+					offset = offset - (mtd->size / 2);
+					nor->spi->master->flags |=
+						SPI_MASTER_U_PAGE;
+				} else {
+					nor->spi->master->flags &=
+						~SPI_MASTER_U_PAGE;
+				}
+			}
+
 			if (nor->addr_width == 3) {
 				/* Update Extended Address Register */
 				ret = write_ear(nor, offset);
@@ -949,6 +996,16 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	ret = spi_nor_lock_and_prep(nor, SPI_NOR_OPS_LOCK);
 	if (ret)
 		return ret;
+	if (nor->isparallel == 1)
+		ofs = ofs >> nor->shift;
+
+	if (nor->isstacked == 1) {
+		if (ofs >= (mtd->size / 2)) {
+			ofs = ofs - (mtd->size / 2);
+			nor->spi->master->flags |= SPI_MASTER_U_PAGE;
+		} else
+			nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
+	}
 
 	ret = nor->flash_lock(nor, ofs, len);
 
@@ -964,6 +1021,16 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	ret = spi_nor_lock_and_prep(nor, SPI_NOR_OPS_UNLOCK);
 	if (ret)
 		return ret;
+	if (nor->isparallel == 1)
+		ofs = ofs >> nor->shift;
+
+	if (nor->isstacked == 1) {
+		if (ofs >= (mtd->size / 2)) {
+			ofs = ofs - (mtd->size / 2);
+			nor->spi->master->flags |= SPI_MASTER_U_PAGE;
+		} else
+			nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
+	}
 
 	ret = nor->flash_unlock(nor, ofs, len);
 
@@ -1355,6 +1422,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	int ret;
 	u32 offset = from;
+	u32 stack_shift = 0;
 	u32 read_len = 0;
 	u32 rem_bank_len = 0;
 	u8 bank;
@@ -1375,8 +1443,25 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 							(bank + 1)) - from;
 		}
 		offset = from;
+		if (nor->isparallel == 1)
+			offset /= 2;
+
+		if (nor->isstacked == 1) {
+			stack_shift = 1;
+			if (offset >= (mtd->size / 2)) {
+				offset = offset - (mtd->size / 2);
+				nor->spi->master->flags |= SPI_MASTER_U_PAGE;
+			} else {
+				nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
+			}
+		}
 
 		/* Die cross over issue is not handled */
+		if (nor->addr_width == 4) {
+			rem_bank_len = (mtd->size >> stack_shift) -
+					(offset << nor->shift);
+		}
+
 		if (nor->addr_width == 3)
 			write_ear(nor, offset);
 		if (len < rem_bank_len)
@@ -1390,9 +1475,9 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 			goto read_err;
 
 		if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT)
-			addr = spi_nor_s3an_addr_convert(nor, addr);
+			addr = spi_nor_s3an_addr_convert(nor, offset);
 
-		ret = nor->read(nor, addr, len, buf);
+		ret = nor->read(nor, offset, len, buf);
 		if (ret == 0) {
 			/* We shouldn't see 0-length reads */
 			ret = -EIO;
@@ -1504,6 +1589,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	size_t page_offset, page_remain, i;
 	ssize_t ret;
+	u32 offset, stack_shift = 0;
 	u8 bank = 0;
 	u32 rem_bank_len = 0;
 #define OFFSET_16_MB 0x1000000
@@ -1517,7 +1603,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	for (i = 0; i < len; ) {
 		ssize_t written;
 		loff_t addr = to + i;
-
+		offset = (to + i);
 		if (nor->addr_width == 3) {
 			bank = (u32)to / (OFFSET_16_MB << nor->shift);
 			rem_bank_len = ((OFFSET_16_MB << nor->shift) *
@@ -1535,26 +1621,53 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		 * modulus (do_div()) or not.
 		 */
 		if (hweight32(nor->page_size) == 1) {
-			page_offset = addr & (nor->page_size - 1);
+			page_offset = offset & (nor->page_size - 1);
 		} else {
-			uint64_t aux = addr;
+			uint64_t aux = offset;
 
 			page_offset = do_div(aux, nor->page_size);
 		}
+		if (nor->isparallel == 1)
+			offset /= 2;
+
+		if (nor->isstacked == 1) {
+			stack_shift = 1;
+			if (offset >= (mtd->size / 2)) {
+				offset = offset - (mtd->size / 2);
+				nor->spi->master->flags |= SPI_MASTER_U_PAGE;
+			} else {
+				nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
+			}
+		}
 		/* Die cross over issue is not handled */
+		if (nor->addr_width == 4)
+			rem_bank_len = (mtd->size >> stack_shift) - offset;
 		if (nor->addr_width == 3)
-			write_ear(nor, addr);
-		else {
-			/* the size of data remaining on the first page */
+			write_ear(nor, offset);
+		if (nor->isstacked == 1) {
+			if (len <= rem_bank_len) {
+				page_remain = min_t(size_t,
+					 nor->page_size - page_offset, len - i);
+			} else {
+				/*
+				 * the size of data remaining
+				 * on the first page
+				 */
+				page_remain = rem_bank_len;
+			}
+		} else {
 			page_remain = min_t(size_t,
-				    nor->page_size - page_offset, len - i);
+					 nor->page_size - page_offset, len - i);
 		}
+		ret = spi_nor_wait_till_ready(nor);
+		if (ret)
+			goto write_err;
 
 		if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT)
 			addr = spi_nor_s3an_addr_convert(nor, addr);
 
 		write_enable(nor);
-		ret = nor->write(nor, addr, page_remain, buf + i);
+		ret = nor->write(nor, offset, page_remain, buf + i);
 		if (ret < 0)
 			goto write_err;
 		written = ret;
@@ -2897,6 +3010,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	struct device_node *np_spi;
 	int ret;
 	int i;
+	u32 is_dual;
 
 	ret = spi_nor_check(nor);
 	if (ret)
@@ -2965,6 +3079,69 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	mtd->_read = spi_nor_read;
 	mtd->_resume = spi_nor_resume;
 
+#ifdef CONFIG_OF
+	np_spi = of_get_next_parent(np);
+	if ((of_property_match_string(np_spi, "compatible",
+		    "xlnx,zynq-qspi-1.0") >= 0) ||
+			(of_property_match_string(np_spi, "compatible",
+					"xlnx,zynqmp-qspi-1.0") >= 0)) {
+		if (of_property_read_u32(np_spi, "is-dual",
+					 &is_dual) < 0) {
+			/* Default to single if prop not defined */
+			nor->shift = 0;
+			nor->isstacked = 0;
+			nor->isparallel = 0;
+		} else {
+			if (is_dual == 1) {
+				/* dual parallel */
+				nor->shift = 1;
+				info->sector_size <<= nor->shift;
+				info->page_size <<= nor->shift;
+				mtd->size <<= nor->shift;
+				nor->isparallel = 1;
+				nor->isstacked = 0;
+			} else {
+#ifdef CONFIG_SPI_ZYNQ_QSPI_DUAL_STACKED
+				/* dual stacked */
+				nor->shift = 0;
+				mtd->size <<= 1;
+				info->n_sectors <<= 1;
+				nor->isstacked = 1;
+				nor->isparallel = 0;
+#else
+				u32 is_stacked;
+
+				if (of_property_read_u32(np_spi,
+						"is-stacked",
+						&is_stacked) < 0) {
+					is_stacked = 0;
+				}
+				if (is_stacked) {
+					/* dual stacked */
+					nor->shift = 0;
+					mtd->size <<= 1;
+					info->n_sectors <<= 1;
+					nor->isstacked = 1;
+					nor->isparallel = 0;
+				} else {
+					/* single */
+					nor->shift = 0;
+					nor->isstacked = 0;
+					nor->isparallel = 0;
+				}
+#endif
+			}
+		}
+	}
+
+#else
+	/* Default to single */
+	nor->shift = 0;
+	nor->isstacked = 0;
+	nor->isparallel = 0;
+#endif
+
+
 	/* NOR protection support for STmicro/Micron chips and similar */
 	if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
 			info->flags & SPI_NOR_HAS_LOCK) {
@@ -3063,6 +3240,24 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 			if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
 			    info->flags & SPI_NOR_4B_OPCODES)
 				spi_nor_set_4byte_opcodes(nor, info);
+			else {
+				np_spi = of_get_next_parent(np);
+				if (of_property_match_string(np_spi,
+						"compatible",
+						"xlnx,xps-spi-2.00.a") >= 0) {
+					nor->addr_width = 3;
+					set_4byte(nor, info, 0);
+				} else {
+					set_4byte(nor, info, 1);
+					if (nor->isstacked) {
+						nor->spi->master->flags |=
+							SPI_MASTER_U_PAGE;
+						set_4byte(nor, info, 1);
+						nor->spi->master->flags &=
+							~SPI_MASTER_U_PAGE;
+					}
+				}
+			}
 #ifdef CONFIG_OF
 		}
 #endif
include/linux/mtd/spi-nor.h +2 -0
index 64232b1..bdf6433 100644
@@ -303,6 +303,8 @@ struct spi_nor {
 	enum spi_nor_protocol	reg_proto;
 	bool			sst_write_second;
 	bool			shift;
+	bool			isparallel;
+	bool			isstacked;
 	u8			flags;
 	u8			cmd_buf[SPI_NOR_MAX_CMD_SIZE];
 
Signature · 1 line
2.7.4
#4 lore raw

RFC PATCH 4/5 spi: Add PM Support for Zynq QSPI controller

In reply to Naga Sureshkumar Relli

This patch adds PM Support for Xilinx Zynq QSPI Controller driver.

---
 drivers/spi/spi-zynq-qspi.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
drivers/spi/spi-zynq-qspi.c +58 -0
index 7a772ca..9f87ee1 100644
@@ -604,6 +604,64 @@ static int zynq_qspi_start_transfer(struct spi_master *master,
 }
 
 /**
+ * zynq_qspi_suspend - Suspend method for the QSPI driver
+ * @_dev:	Address of the platform_device structure
+ *
+ * This function stops the QSPI driver queue and disables the QSPI controller
+ *
+ * Return:	Always 0
+ */
+static int __maybe_unused zynq_qspi_suspend(struct device *_dev)
+{
+	struct platform_device *pdev = container_of(_dev,
+			struct platform_device, dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	spi_master_suspend(master);
+
+	zynq_unprepare_transfer_hardware(master);
+
+	return 0;
+}
+
+/**
+ * zynq_qspi_resume - Resume method for the QSPI driver
+ * @dev:	Address of the platform_device structure
+ *
+ * The function starts the QSPI driver queue and initializes the QSPI controller
+ *
+ * Return:	0 on success and error value on error
+ */
+static int __maybe_unused zynq_qspi_resume(struct device *dev)
+{
+	struct platform_device *pdev = container_of(dev,
+			struct platform_device, dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+	struct zynq_qspi *xqspi = spi_master_get_devdata(master);
+	int ret = 0;
+
+	ret = clk_enable(xqspi->pclk);
+	if (ret) {
+		dev_err(dev, "Cannot enable APB clock.\n");
+		return ret;
+	}
+
+	ret = clk_enable(xqspi->refclk);
+	if (ret) {
+		dev_err(dev, "Cannot enable device clock.\n");
+		clk_disable(xqspi->pclk);
+		return ret;
+	}
+
+	spi_master_resume(master);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(zynq_qspi_dev_pm_ops, zynq_qspi_suspend,
+zynq_qspi_resume);
+
+/**
  * zynq_qspi_probe - Probe method for the QSPI driver
  * @pdev:	Pointer to the platform_device structure
  *
Signature · 1 line
2.7.4
#5 lore raw

RFC PATCH 5/5 devicetree: Add devicetree bindings documentation for

In reply to Naga Sureshkumar Relli

Add bindings documentation for Zynq QSPI driver.

---
 .../devicetree/bindings/spi/spi-zynq-qspi.txt      | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt new file +28 -0
new file mode 100644
index 0000000..fe3b8e9
@@ -0,0 +1,28 @@
+Xilinx Zynq QSPI controller Device Tree Bindings
+-------------------------------------------------
+
+Required properties:
+- compatible		: Should be "xlnx,zynq-qspi-1.0".
+- reg			: Physical base address and size of QSPI registers map.
+- interrupts		: Property with a value describing the interrupt
+			  number.
+- interrupt-parent	: Must be core interrupt controller
+- clock-names		: List of input clock names - "ref_clk", "pclk"
+			  (See clock bindings for details).
+- clocks		: Clock phandles (see clock bindings for details).
+
+Optional properties:
+- num-cs		: Number of chip selects used.
+- is-dual		: QSPI operating in Dual parallel.
+- is-satcked		: QSPI operating in Stacked mode.
+
+Example:
+	qspi@e000d000 {
+		compatible = "xlnx,zynq-qspi-1.0";
+		clock-names = "ref_clk", "pclk";
+		clocks = <&clkc 10>, <&clkc 43>;
+		interrupt-parent = <&intc>;
+		interrupts = <0 19 4>;
+		num-cs = <1>;
+		reg = <0xe000d000 0x1000>;
+	} ;
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH 1/5 spi: Add support for Zynq qspi controller

In reply to Naga Sureshkumar Relli

This patch adds support for QSPI controller driver used by Xilinx Zynq SOC.

---
 drivers/spi/Kconfig         |  15 +
 drivers/spi/Makefile        |   1 +
 drivers/spi/spi-zynq-qspi.c | 769 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 785 insertions(+)
 create mode 100644 drivers/spi/spi-zynq-qspi.c
drivers/spi/Kconfig +15 -0
index 6037839..75b8f13 100644
@@ -762,6 +762,21 @@ config SPI_ZYNQMP_GQSPI
 	help
 	  Enables Xilinx GQSPI controller driver for Zynq UltraScale+ MPSoC.
 
+config SPI_ZYNQ_QSPI
+	tristate "Xilinx Zynq QSPI controller"
+	depends on ARCH_ZYNQ
+	depends on SPI_MASTER
+	help
+	 This selects the Xilinx ZYNQ Quad SPI controller master driver.
+
+config SPI_ZYNQ_QSPI_DUAL_STACKED
+	bool "Xilinx Zynq QSPI Dual stacked configuration"
+	depends on SPI_ZYNQ_QSPI
+	help
+	 This selects the Xilinx ZYNQ Quad SPI controller in dual stacked mode.
+	 Enable this option if your hw design is using dual stacked
+	 configuration.
+
 #
 # Add new SPI master controllers in alphabetical order above this line
 #
drivers/spi/Makefile +1 -0
index 34c5f28..b49cff6 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_SPI_XILINX)		+= spi-xilinx.o
 obj-$(CONFIG_SPI_XLP)			+= spi-xlp.o
 obj-$(CONFIG_SPI_XTENSA_XTFPGA)		+= spi-xtensa-xtfpga.o
 obj-$(CONFIG_SPI_ZYNQMP_GQSPI)		+= spi-zynqmp-gqspi.o
+obj-$(CONFIG_SPI_ZYNQ_QSPI)		+= spi-zynq-qspi.o
 
 # SPI slave protocol handlers
 obj-$(CONFIG_SPI_SLAVE_TIME)		+= spi-slave-time.o
drivers/spi/spi-zynq-qspi.c new file +769 -0

769 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

RFC PATCH 2/5 mtd: spi-nor: Add support for Zynq QSPI controller

In reply to Naga Sureshkumar Relli

This patch adds necessary changes required to support Zynq QSPI Controller driver.

---
 drivers/mtd/spi-nor/spi-nor.c | 194 ++++++++++++++++++++++++++++++++++++++----
 include/linux/mtd/spi-nor.h   |  13 ++-
 include/linux/spi/spi.h       |   5 +-
 3 files changed, 192 insertions(+), 20 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +177 -17
index d445a4d..7698a92 100644
@@ -23,6 +23,7 @@
 #include <linux/of_platform.h>
 #include <linux/spi/flash.h>
 #include <linux/mtd/spi-nor.h>
+#include <linux/spi/spi.h>
 
 /* Define max times to check status register before we give up. */
 
@@ -292,6 +293,35 @@ static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info,
 	}
 }
 
+/**
+ * read_ear - Get the extended/bank address register value
+ * @nor:	Pointer to the flash control structure
+ *
+ * This routine reads the Extended/bank address register value
+ *
+ * Return:	Negative if error occurred.
+ */
+static int read_ear(struct spi_nor *nor, struct flash_info *info)
+{
+	int ret;
+	u8 val;
+	u8 code;
+
+	/* This is actually Spansion */
+	if (JEDEC_MFR(info) == CFI_MFR_AMD)
+		code = SPINOR_OP_BRRD;
+	/* This is actually Micron */
+	else if (JEDEC_MFR(info) == CFI_MFR_ST)
+		code = SPINOR_OP_RDEAR;
+	else
+		return -EINVAL;
+
+	ret = nor->read_reg(nor, code, &val, 1);
+	if (ret < 0)
+		return ret;
+
+	return val;
+}
 static int s3an_sr_ready(struct spi_nor *nor)
 {
 	int ret;
@@ -401,15 +431,60 @@ static int spi_nor_wait_till_ready(struct spi_nor *nor)
 }
 
 /*
+ * Update Extended Address/bank selection Register.
+ * Call with flash->lock locked.
+ */
+static int write_ear(struct spi_nor *nor, u32 addr)
+{
+	u8 code;
+	u8 ear;
+	int ret;
+	struct mtd_info *mtd = &nor->mtd;
+
+	/* Wait until finished previous write command. */
+	if (spi_nor_wait_till_ready(nor))
+		return 1;
+
+	if (mtd->size <= (0x1000000) << nor->shift)
+		return 0;
+
+	addr = addr % (u32) mtd->size;
+	ear = addr >> 24;
+
+	if (ear == nor->curbank)
+		return 0;
+
+	if (nor->jedec_id == CFI_MFR_AMD)
+		code = SPINOR_OP_BRWR;
+	if (nor->jedec_id == CFI_MFR_ST) {
+		write_enable(nor);
+		code = SPINOR_OP_WREAR;
+	}
+	nor->cmd_buf[0] = ear;
+
+	ret = nor->write_reg(nor, code, nor->cmd_buf, 1);
+	if (ret < 0)
+		return ret;
+
+	nor->curbank = ear;
+
+	return 0;
+}
+/*
  * Erase the whole flash memory
  *
  * Returns 0 if successful, non-zero otherwise.
  */
 static int erase_chip(struct spi_nor *nor)
 {
+	u32 ret;
 	dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd.size >> 10));
 
-	return nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0);
+	ret = nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0);
+	if (ret)
+		return ret;
+
+	return ret;
 }
 
 static int spi_nor_lock_and_prep(struct spi_nor *nor, enum spi_nor_ops ops)
@@ -490,7 +565,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	u32 addr, len;
+	u32 addr, len, offset;
 	uint32_t rem;
 	int ret;
 
@@ -540,9 +615,23 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	/* "sector"-at-a-time erase */
 	} else {
 		while (len) {
+
+			write_enable(nor);
+			offset = addr;
+
+			if (nor->addr_width == 3) {
+				/* Update Extended Address Register */
+				ret = write_ear(nor, offset);
+				if (ret)
+					goto erase_err;
+			}
+			ret = spi_nor_wait_till_ready(nor);
+			if (ret)
+				goto erase_err;
+
 			write_enable(nor);
 
-			ret = spi_nor_erase_sector(nor, addr);
+			ret = spi_nor_erase_sector(nor, offset);
 			if (ret)
 				goto erase_err;
 
@@ -1265,6 +1354,13 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	int ret;
+	u32 offset = from;
+	u32 read_len = 0;
+	u32 rem_bank_len = 0;
+	u8 bank;
+	loff_t addr = 0;
+
+#define OFFSET_16_MB 0x1000000
 
 	dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
 
@@ -1273,7 +1369,25 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 		return ret;
 
 	while (len) {
-		loff_t addr = from;
+		if (nor->addr_width == 3) {
+			bank = (u32)from / (OFFSET_16_MB << nor->shift);
+			rem_bank_len = ((OFFSET_16_MB << nor->shift) *
+							(bank + 1)) - from;
+		}
+		offset = from;
+
+		/* Die cross over issue is not handled */
+		if (nor->addr_width == 3)
+			write_ear(nor, offset);
+		if (len < rem_bank_len)
+			read_len = len;
+		else
+			read_len = rem_bank_len;
+
+		/* Wait till previous write/erase is done. */
+		ret = spi_nor_wait_till_ready(nor);
+		if (ret)
+			goto read_err;
 
 		if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT)
 			addr = spi_nor_s3an_addr_convert(nor, addr);
@@ -1390,6 +1504,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	size_t page_offset, page_remain, i;
 	ssize_t ret;
+	u8 bank = 0;
+	u32 rem_bank_len = 0;
+#define OFFSET_16_MB 0x1000000
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
@@ -1401,6 +1518,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		ssize_t written;
 		loff_t addr = to + i;
 
+		if (nor->addr_width == 3) {
+			bank = (u32)to / (OFFSET_16_MB << nor->shift);
+			rem_bank_len = ((OFFSET_16_MB << nor->shift) *
+							(bank + 1)) - to;
+		}
+
+		page_offset = ((to + i)) & (nor->page_size - 1);
+
 		/*
 		 * If page_size is a power of two, the offset can be quickly
 		 * calculated with an AND operation. On the other cases we
@@ -1416,9 +1541,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 			page_offset = do_div(aux, nor->page_size);
 		}
-		/* the size of data remaining on the first page */
-		page_remain = min_t(size_t,
+		/* Die cross over issue is not handled */
+		if (nor->addr_width == 3)
+			write_ear(nor, addr);
+		else {
+			/* the size of data remaining on the first page */
+			page_remain = min_t(size_t,
 				    nor->page_size - page_offset, len - i);
+		}
 
 		if (nor->flags & SNOR_F_S3AN_ADDR_DEFAULT)
 			addr = spi_nor_s3an_addr_convert(nor, addr);
@@ -2760,10 +2890,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 		 const struct spi_nor_hwcaps *hwcaps)
 {
 	struct spi_nor_flash_parameter params;
-	const struct flash_info *info = NULL;
+	struct flash_info *info = NULL;
 	struct device *dev = nor->dev;
 	struct mtd_info *mtd = &nor->mtd;
 	struct device_node *np = spi_nor_get_flash_node(nor);
+	struct device_node *np_spi;
 	int ret;
 	int i;
 
@@ -2777,10 +2908,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	nor->write_proto = SNOR_PROTO_1_1_1;
 
 	if (name)
-		info = spi_nor_match_id(name);
+		info = (struct flash_info *)spi_nor_match_id(name);
 	/* Try to auto-detect if chip name wasn't specified or not found */
 	if (!info)
-		info = spi_nor_read_id(nor);
+		info = (struct flash_info *)spi_nor_read_id(nor);
 	if (IS_ERR_OR_NULL(info))
 		return -ENOENT;
 
@@ -2804,7 +2935,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 			 */
 			dev_warn(dev, "found %s, expected %s\n",
 				 jinfo->name, info->name);
-			info = jinfo;
+			info = (struct flash_info *)jinfo;
 		}
 	}
 
@@ -2863,9 +2994,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (info->flags & USE_CLSR)
 		nor->flags |= SNOR_F_USE_CLSR;
 
-	if (info->flags & SPI_NOR_NO_ERASE)
-		mtd->flags |= MTD_NO_ERASE;
+#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
+	/* prefer "small sector" erase if possible */
+	if (info->flags & SECT_4K ||
+			info->flags & SECT_4K_PMC) {
+		mtd->erasesize = 4096 << nor->shift;
+	} else
+#endif
+		if (info->flags & SPI_NOR_NO_ERASE)
+			mtd->flags |= MTD_NO_ERASE;
 
+	nor->jedec_id = info->id[0];
 	mtd->dev.parent = dev;
 	nor->page_size = params.page_size;
 	mtd->writebufsize = nor->page_size;
@@ -2901,11 +3040,32 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	} else if (info->addr_width) {
 		nor->addr_width = info->addr_width;
 	} else if (mtd->size > 0x1000000) {
-		/* enable 4-byte addressing if the device exceeds 16MiB */
-		nor->addr_width = 4;
-		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
-		    info->flags & SPI_NOR_4B_OPCODES)
-			spi_nor_set_4byte_opcodes(nor, info);
+#ifdef CONFIG_OF
+		np_spi = of_get_next_parent(np);
+		if (of_property_match_string(np_spi, "compatible",
+					     "xlnx,zynq-qspi-1.0") >= 0) {
+			int status;
+
+			nor->addr_width = 3;
+			set_4byte(nor, info, 0);
+			status = read_ear(nor, info);
+			if (status < 0)
+				dev_warn(dev, "failed to read ear reg\n");
+			else
+				nor->curbank = status & EAR_SEGMENT_MASK;
+		} else {
+#endif
+			/*
+			 * enable 4-byte addressing
+			 * if the device exceeds 16MiB
+			 */
+			nor->addr_width = 4;
+			if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
+			    info->flags & SPI_NOR_4B_OPCODES)
+				spi_nor_set_4byte_opcodes(nor, info);
+#ifdef CONFIG_OF
+		}
+#endif
 	} else {
 		nor->addr_width = 3;
 	}
include/linux/mtd/spi-nor.h +12 -1
index de36969..64232b1 100644
@@ -62,6 +62,9 @@
 #define SPINOR_OP_RDCR		0x35	/* Read configuration register */
 #define SPINOR_OP_RDFSR		0x70	/* Read flag status register */
 #define SPINOR_OP_CLFSR		0x50	/* Clear flag status register */
+#define SPINOR_OP_WREAR		0xc5	/* Write Extended Address Register */
+#define SPINOR_OP_RDEAR		0xc8	/* Read Extended Address Register */
+
 
 /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
 #define SPINOR_OP_READ_4B	0x13	/* Read data bytes (low frequency) */
@@ -106,6 +109,7 @@
 
 /* Used for Spansion flashes only. */
 #define SPINOR_OP_BRWR		0x17	/* Bank register write */
+#define	SPINOR_OP_BRRD		0x16	/* Bank register read */
 #define SPINOR_OP_CLSR		0x30	/* Clear status register 1 */
 
 /* Used for Micron flashes only. */
@@ -139,6 +143,7 @@
 /* Configuration Register bits. */
 #define CR_QUAD_EN_SPAN		BIT(1)	/* Spansion Quad I/O */
 
+#define EAR_SEGMENT_MASK	0x7 /* 128 Mb segment mask */
 /* Status Register 2 bits. */
 #define SR2_QUAD_EN_BIT7	BIT(7)
 
@@ -281,6 +286,7 @@ struct spi_nor {
 	struct mtd_info		mtd;
 	struct mutex		lock;
 	struct device		*dev;
+	struct spi_device       *spi;
 	const struct flash_info	*info;
 	u32			page_size;
 	u8			addr_width;
@@ -288,11 +294,16 @@ struct spi_nor {
 	u8			read_opcode;
 	u8			read_dummy;
 	u8			program_opcode;
+	u32			jedec_id;
+	u16			curbank;
+	u16			n_sectors;
+	u32			sector_size;
 	enum spi_nor_protocol	read_proto;
 	enum spi_nor_protocol	write_proto;
 	enum spi_nor_protocol	reg_proto;
 	bool			sst_write_second;
-	u32			flags;
+	bool			shift;
+	u8			flags;
 	u8			cmd_buf[SPI_NOR_MAX_CMD_SIZE];
 
 	int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
include/linux/spi/spi.h +3 -2
index bc6bb32..576dea1 100644
@@ -451,7 +451,8 @@ struct spi_controller {
 #define SPI_CONTROLLER_MUST_TX		BIT(4)	/* requires tx */
 
 #define SPI_MASTER_GPIO_SS		BIT(5)	/* GPIO CS must select slave */
-
+#define SPI_MASTER_QUAD_MODE		BIT(6)	/* support quad mode */
+#define SPI_MASTER_U_PAGE		BIT(9)	/* select upper flash */
 	/* flag indicating this is an SPI slave controller */
 	bool			slave;
 
@@ -797,7 +798,7 @@ struct spi_transfer {
 	u8		bits_per_word;
 	u16		delay_usecs;
 	u32		speed_hz;
-
+	u32		dummy;
 	struct list_head transfer_list;
 };
 
Signature · 1 line
2.7.4
#7 lore raw
In reply to Naga Sureshkumar Relli
Quoted 1 line · Naga Sureshkumar Relli

Xilinx Zynq uses a QSPI controller that is based on the Cadence SPI IP.

Don't we have a CQSPI driver already ? Why is this adding a new one ?

Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

Hi Marek,

Thanks for reviewing the patch.

Quoted 10 lines

-----Original Message-----
From: Marek Vasut [mailto:[email protected]]
Sent: Friday, March 23, 2018 6:22 PM
To: Naga Sureshkumar Relli <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Naga Sureshkumar Relli <[email protected]>
Subject: Re: [RFC PATCH 0/5] RFC for Zynq QSPI

Quoted 4 lines
Quoted 1 line · Naga Sureshkumar Relli

Xilinx Zynq uses a QSPI controller that is based on the Cadence SPI IP.

Don't we have a CQSPI driver already ? Why is this adding a new one ?

Zynq QSPI Controller is designed by using Cadence SPI IP core in order to add multi bit IO capability. The modified core is Zynq QSPI Controller core. Both are different.

Quoted 4 lines

--
Best regards,
Marek Vasut

Thanks,
Naga Sureshkumar Relli.

maintainer
#6 lore raw

Re: [RFC PATCH 5/5] devicetree: Add devicetree bindings documentation for

In reply to Naga Sureshkumar Relli

Hi Naga,

Quoted 14 lines · Naga Sureshkumar Relli

Add bindings documentation for Zynq QSPI driver.

---
 .../devicetree/bindings/spi/spi-zynq-qspi.txt      | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt new file +0 -0
new file mode 100644
index 0000000..fe3b8e9

Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt new file +5 -0
@@ -0,0 +1,28 @@
+Xilinx Zynq QSPI controller Device Tree Bindings
+-------------------------------------------------
+
+Required properties:
+- compatible		: Should be "xlnx,zynq-qspi-1.0".

What is this trailing "-1.0" for?

Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt line 17

Quoted 12 lines
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt new file +12 -0
+- reg			: Physical base address and size of QSPI registers map.
+- interrupts		: Property with a value describing the interrupt
+			  number.
+- interrupt-parent	: Must be core interrupt controller
+- clock-names		: List of input clock names - "ref_clk", "pclk"
+			  (See clock bindings for details).
+- clocks		: Clock phandles (see clock bindings for details).
+
+Optional properties:
+- num-cs		: Number of chip selects used.
+- is-dual		: QSPI operating in Dual parallel.
+- is-satcked		: QSPI operating in Stacked mode.

^ stacked

BTW, if you have both is-dual and is-stacked properties in the DT, do you really need a configuration option for that?

Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt line 28

Quoted 11 lines
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt new file +11 -0
+
+Example:
+	qspi@e000d000 {
+		compatible = "xlnx,zynq-qspi-1.0";
+		clock-names = "ref_clk", "pclk";
+		clocks = <&clkc 10>, <&clkc 43>;
+		interrupt-parent = <&intc>;
+		interrupts = <0 19 4>;
+		num-cs = <1>;
+		reg = <0xe000d000 0x1000>;
+	} ;

Thanks,
Miquèl

Signature · 3 lines
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#9 lore raw
In reply to Naga Sureshkumar Relli

Hi all,

Can some body propose an alternative to get the things done(Adding Zynq Dual parallel and stacked support)? Because to handle this we have changed the core functions. See my patches "[RFC PATCH 3/5] mtd: spi-nor: Add Dual Parallel and Stacked support for Zynq QSPI"
"[RFC PATCH 1/5] spi: Add support for Zynq qspi controller"

I will provide required inputs, if any.

Thanks,
Naga Sureshkumar Relli.

Quoted 103 lines

-----Original Message-----
From: Naga Sureshkumar Relli [mailto:[email protected]]
Sent: Friday, March 23, 2018 5:52 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Naga Sureshkumar Relli <[email protected]>
Subject: [RFC PATCH 0/5] RFC for Zynq QSPI

Xilinx Zynq uses a QSPI controller that is based on the Cadence SPI IP. This controller implements all the functionality required to support Quad SPI NOR flash devices.
This driver along with the MTD layer is used to support flash devices.

This series is for the following purposes:
- RFC of the Quad SPI driver.
- We currently use a custom MTD layer and would like to get inputs on dual stacked/dual parallel handling (described below).

The flash device(s) can be connected in the three configurations:
1. Single - One flash device with 1 CS, 1 Clock and 4 IO lines.
2. Dual Parallel - Two flash devices connected with common CS and separate IO lines (resulting in 8 IO lines).
In this configuration, the controller
a) Duplicates commands, address etc. sent on both sets of 4 IO lines.
b) Stripes data both transmitted and received i.e.
4 bits of data is sent to the first flash and the other 4 bits
to the second flash. Similarly read data is also consolidated.
Due to this, TX and RX data handling in the driver need special handling for parallel mode.
3. Dual Stacked - Two flash devices connected with separate CS and
4 common IO lines. This is largely similar to single, except for
the slave selection logic.
The above configuration is conveyed to the QSPI driver through a devicetree property.

The QSPI driver differs from the existing Cadence SPI driver in the following respects majorly:
1. TX and RX handling: Different TX registers are used to write into
the TX FIFO. TXD0, TXD1, TXD2 and TXD3 are used write 4, 1, 2 and 3
bytes respectively. Depending on the TXD register used, the received
bytes also need to be handled separately.
2. Depending on the configuration in which flash devices are connected
(single, parallel or stacked), QSPI controller configuration registers
need to be modified.
3. There is no support for extended slave select in QSPI, as opposed to
SPI. In case of stacked configuration, the slave select field remains
the same and a different configuration bit is used to select between
the two flash devices.
4. Handling of dual parallel configuration.

MTD layer:
The Xilinx Zynq MTD layer by far makes use of the mainline version with some differences. The primary flash families supported are Spansion, Winbond and Micron.
- Probe:
- In dual configurations, both flash devices are recognized as one continuous memory. (ID is read only from one flash and it is a pre-stated assumption that both flash devices have the same flash
make and size.)
- Addressing:
a) In dual stacked mode, the address passed to the MTD layer can be between 0x0 to 2*(one flash size). Hence the MTD layer has to recognize whether the address belongs to the first flash or the second flash subtract the offset and indicate the same to the QSPI driver.
b) In dual stacked mode too the address can range between
0 to 2*(one flash size). But, when an 8 bit word is written,
4 bits are written to the first and 4 bits are written to the
second flash. Hence the address sent is always halved and checks
are in place for even address and even length.
- 4 byte addressing is not supported and hence bank selection logic is used along with the addressing system described above.
- Flash register read/writes, for example, lock/unlock, quad enable etc. are handled differently in dual stacked and parallel modes.

This is tested with current master branch of Linux.
To make Zynq QSPI work, we need to tweak spi-nor.c.
I agree that changing the spi-nor layer apis, doesn't look good but i didn't find a way to do the same.
So please suggest a way to handle Zynq QSPI controller in dual parallel and stacked modes. we can move the spi/spi-zynq-qspi.c to spi-nor/ but even in that case also changes are needed in spi-nor.c.
What ever the changes we do to make Zynq QSPI work, will applicable for Xilinx ZynqMP SOC QSPI controller(spi-zynqmp-qspi.c) as well.
I am happy to do the changes suggested, so that we will have a solution for Xilinx Zynq and ZynqMP SOC QSPI controllers.

Naga Sureshkumar Relli (5):
spi: Add support for Zynq qspi controller
mtd: spi-nor: Add support for Zynq QSPI controller
mtd: spi-nor: Add Dual Parallel and Stacked support for Zynq QSPI
spi: Add PM Support for Zynq QSPI controller
devicetree: Add devicetree bindings documentation for Zynq QSPI

 .../devicetree/bindings/spi/spi-zynq-qspi.txt      |  26 +
 drivers/mtd/spi-nor/spi-nor.c                      | 425 ++++++++++-
 drivers/spi/Kconfig                                |  15 +
 drivers/spi/Makefile                               |   1 +
 drivers/spi/spi-zynq-qspi.c                        | 827 +++++++++++++++++++++
 include/linux/mtd/spi-nor.h                        |  15 +-
 include/linux/spi/spi.h                            |   5 +-
 7 files changed, 1276 insertions(+), 38 deletions(-)  create mode 100644
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt
 create mode 100644 drivers/spi/spi-zynq-qspi.c

--
2.7.4

#11 lore raw
In reply to a message not in the archive

Hi Naga,

Quoted 3 lines · On Mon, 17 Sep 2018 16:08:26 +0530 naga suresh kumar…

Hi all,

Can i write the Zynq QSPI driver under the new spi/mem framework?

Yes, you should.

Quoted 1 line

As i said, it needs tweaking the mtd->size and spi read/write addresses.

Can you elaborate a bit on why you think this is needed? Did you look at [1]? Maybe it will prevent us from exposing the flash size at the spi-mem level.

Quoted 2 lines

Can somebody share your thoughts on this(Adding Zynq QSPI Dual parallel and stacked)?

I always have a hard time with this naming. I guess stacked is when you have 2 chips sharing the same I/O bus, and parallel is when you have 2 chips with one taking all of the I/O and the other taking the other half. Is that correct?

If it is, then stacked mode should be easy to support (it's just a matter of patching the spi layer to allow passing several CS lines to a single device (in case of DT parsing, it means reg = <0 1> implies CS 0 and 1 are assigned to the same device. For the parallel, I don't have a solution yet.

Anyway, I'd suggest that you start with something simple (a spi-mem driver supporting ->exec_op() in Single/Dual/Quad mode), and build on top of that for the advanced features you're mentioning here.

Regards,

Boris

[1]http://lists.infradead.org/pipermail/linux-mtd/2018-June/081460.html

#12 lore raw
Quoted 17 lines · On Mon, 17 Sep 2018 17:05:22 +0200 Boris Brezillon…

Hi Naga,

Quoted 3 lines · On Mon, 17 Sep 2018 16:08:26 +0530 naga suresh kumar…

Hi all,

Can i write the Zynq QSPI driver under the new spi/mem framework?

Yes, you should.

Quoted 1 line

As i said, it needs tweaking the mtd->size and spi read/write addresses.

Can you elaborate a bit on why you think this is needed? Did you look at [1]? Maybe it will prevent us from exposing the flash size at the spi-mem level.

Quoted 6 lines
Quoted 2 lines

Can somebody share your thoughts on this(Adding Zynq QSPI Dual parallel and stacked)?

I always have a hard time with this naming. I guess stacked is when you have 2 chips sharing the same I/O bus, and parallel is when you have 2 chips with one taking all of the I/O and the other taking the other

^half of the I/O bus and the other one

Quoted 17 lines

half. Is that correct?

If it is, then stacked mode should be easy to support (it's just a matter of patching the spi layer to allow passing several CS lines to a single device (in case of DT parsing, it means reg = <0 1> implies CS 0 and 1 are assigned to the same device. For the parallel, I don't have a solution yet.

Anyway, I'd suggest that you start with something simple (a spi-mem driver supporting ->exec_op() in Single/Dual/Quad mode), and build on top of that for the advanced features you're mentioning here.

Regards,

Boris

[1]http://lists.infradead.org/pipermail/linux-mtd/2018-June/081460.html

#14 lore raw
In reply to a message not in the archive

Hi Naga,

Quoted 4 lines · On Tue, 18 Sep 2018 11:26:05 +0530 naga suresh kumar…

Hi,

Please see my reply inline by prefacing my name, currently i am facing issues with my outlook. the reply looks not good but please don't mind.

I do mind. Please find a way to fix that, 'cause I'm pretty sure others will soon complain about that too.

Quoted 37 lines
Quoted 37 lines
Quoted 1 line

As i said, it needs tweaking the mtd->size and spi read/write addresses.

Can you elaborate a bit on why you think this is needed? Did you look at [1]? Maybe it will prevent us from exposing the flash size at the spi-mem level.
[naga]: some example snippet below

spi_nor_read () {

   if (nor->isparallel == 1)

   {

      offset /= 2; //byte stripping will happen here

       nor->spi->master->flags |= SPI_DATA_STRIPE;

       //By setting this flag even bits of data word located in lower

memory and odd are in upper memory

   }

   if (nor->isstacked == 1) {
     stack_shift = 1;

     if (offset >= (mtd->size / 2)) {

     offset = offset - (mtd->size / 2);

     nor->spi->master->flags |= SPI_MASTER_U_PAGE;

     //We can access Upper memory or lower memory, by setting this flag in

controller.

  } else {
Quoted 7 lines
Quoted 7 lines
        nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
  }

}

same for spi_nor_write() also.

Let's put the stacked and parallel support on the side for now and focus on single die/chip support. Will find a clean way to handle that afterwards.

Quoted 3 lines
Quoted 3 lines

Also in both dual parallel and stacked mode mtd->size should be sum of both flash device sizes

Yes, but this information should stay at the spi-nor/mtd level.

Quoted 5 lines
Quoted 5 lines

also status register read will change, it needs status from both devices. like that some changes

will be needed in core.

Which is why this needs to be handled in spi-nor.c. The spi-nor core needs to know about the parallel/stack setup and handle it differently (read both status bytes, read both IDs, ...).

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

Can somebody share your thoughts on this(Adding Zynq QSPI Dual parallel

and

Quoted 1 line

stacked)?

I always have a hard time with this naming. I guess stacked is when you have 2 chips sharing the same I/O bus, and parallel is when you have 2 chips with one taking all of the I/O and the other taking the other half. Is that correct?
[naga]: Yes, you are correct, i have attached the diagrams for these mode.

Quoted 6 lines
Quoted 6 lines

In parallel mode, with the help of controller STRIPE feature, even bits of

data words are located in lower memory and odd bits are located in upper memory.

Data management will be taken care by controller in both modes

Ok. I need to think about it a bit more. In the meantime, I recommend that you submit a version of the driver that does not support parallel and stacked modes.

Regards,

Boris

#15 lore raw

Hi Boris,

Quoted 15 lines

-----Original Message-----
From: Boris Brezillon [mailto:[email protected]]
Sent: Tuesday, September 18, 2018 12:47 PM
To: naga suresh kumar <[email protected]>
Cc: Naga Sureshkumar Relli <[email protected]>; [email protected]; Marek Vašut <[email protected]>; David Woodhouse <[email protected]>; Brian Norris <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [RFC PATCH 0/5] RFC for Zynq QSPI

Hi Naga,

On Tue, 18 Sep 2018 11:26:05 +0530
naga suresh kumar <[email protected]> wrote:

Quoted 7 lines
Quoted 4 lines

Hi,

Please see my reply inline by prefacing my name, currently i am facing issues with my outlook. the reply looks not good but please don't mind.

I do mind. Please find a way to fix that, 'cause I'm pretty sure others will soon complain about that too.

Its working now.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 3 lines

As i said, it needs tweaking the mtd->size and spi read/write addresses.

Can you elaborate a bit on why you think this is needed? Did you look at [1]? Maybe it will prevent us from exposing the flash size at the spi-mem level.
[naga]: some example snippet below

spi_nor_read () {

   if (nor->isparallel == 1)

   {

      offset /= 2; //byte stripping will happen here

       nor->spi->master->flags |= SPI_DATA_STRIPE;

       //By setting this flag even bits of data word located in

lower memory and odd are in upper memory

   }

   if (nor->isstacked == 1) {
     stack_shift = 1;

     if (offset >= (mtd->size / 2)) {

     offset = offset - (mtd->size / 2);

     nor->spi->master->flags |= SPI_MASTER_U_PAGE;

     //We can access Upper memory or lower memory, by setting this

flag in controller.

  } else {
        nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
  }

}

same for spi_nor_write() also.

Let's put the stacked and parallel support on the side for now and focus on single die/chip support. Will find a clean way to handle that afterwards.

Ok

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Also in both dual parallel and stacked mode mtd->size should be sum of both flash device sizes

Yes, but this information should stay at the spi-nor/mtd level.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

also status register read will change, it needs status from both devices. like that some changes

will be needed in core.

Which is why this needs to be handled in spi-nor.c. The spi-nor core needs to know about the parallel/stack setup and handle it differently (read both status bytes, read both IDs, ...).

Ok

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines

Can somebody share your thoughts on this(Adding Zynq QSPI Dual parallel

and

Quoted 1 line

stacked)?

I always have a hard time with this naming. I guess stacked is when you have 2 chips sharing the same I/O bus, and parallel is when you have 2 chips with one taking all of the I/O and the other taking the other half. Is that correct?
[naga]: Yes, you are correct, i have attached the diagrams for these mode.

In parallel mode, with the help of controller STRIPE feature, even bits of

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

data words are located in lower memory and odd bits are located in upper memory.

Data management will be taken care by controller in both modes

Ok. I need to think about it a bit more. In the meantime, I recommend that you submit a version of the driver that does not support parallel and stacked modes.

Ok sure.

Thanks,
Naga Sureshkumar Relli.

Quoted 4 lines

Regards,

Boris

#16 lore raw
In reply to Boris Brezillon

Hi Boris,

Quoted 92 lines · Boris Brezillon

Hi Naga,

Quoted 4 lines · On Tue, 18 Sep 2018 11:26:05 +0530 naga suresh kumar…

Hi,

Please see my reply inline by prefacing my name, currently i am facing issues with my outlook. the reply looks not good but please don't mind.

I do mind. Please find a way to fix that, 'cause I'm pretty sure others will soon complain about that too.

Quoted 37 lines
Quoted 37 lines
Quoted 1 line

As i said, it needs tweaking the mtd->size and spi read/write addresses.

Can you elaborate a bit on why you think this is needed? Did you look at [1]? Maybe it will prevent us from exposing the flash size at the spi-mem level.
[naga]: some example snippet below

spi_nor_read () {

   if (nor->isparallel == 1)

   {

      offset /= 2; //byte stripping will happen here

       nor->spi->master->flags |= SPI_DATA_STRIPE;

       //By setting this flag even bits of data word located in lower

memory and odd are in upper memory

   }

   if (nor->isstacked == 1) {
     stack_shift = 1;

     if (offset >= (mtd->size / 2)) {

     offset = offset - (mtd->size / 2);

     nor->spi->master->flags |= SPI_MASTER_U_PAGE;

     //We can access Upper memory or lower memory, by setting this flag in

controller.

  } else {
Quoted 7 lines
Quoted 7 lines
        nor->spi->master->flags &= ~SPI_MASTER_U_PAGE;
  }

}

same for spi_nor_write() also.

Let's put the stacked and parallel support on the side for now and focus on single die/chip support. Will find a clean way to handle that afterwards.

Quoted 3 lines
Quoted 3 lines

Also in both dual parallel and stacked mode mtd->size should be sum of both flash device sizes

Yes, but this information should stay at the spi-nor/mtd level.

Quoted 5 lines
Quoted 5 lines

also status register read will change, it needs status from both devices. like that some changes

will be needed in core.

Which is why this needs to be handled in spi-nor.c. The spi-nor core needs to know about the parallel/stack setup and handle it differently (read both status bytes, read both IDs, ...).

Quoted 12 lines
Quoted 12 lines
Quoted 1 line

Can somebody share your thoughts on this(Adding Zynq QSPI Dual parallel

and

Quoted 1 line

stacked)?

I always have a hard time with this naming. I guess stacked is when you have 2 chips sharing the same I/O bus, and parallel is when you have 2 chips with one taking all of the I/O and the other taking the other half. Is that correct?
[naga]: Yes, you are correct, i have attached the diagrams for these mode.

In parallel mode, with the help of controller STRIPE feature, even bits of

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

data words are located in lower memory and odd bits are located in upper memory.

Data management will be taken care by controller in both modes

Ok. I need to think about it a bit more. In the meantime, I recommend that you submit a version of the driver that does not support parallel and stacked modes.

As you suggested previously, i have added the support for Zynq QSPI controller to support single chip.
Currently i am planning to add support for Parallel and Stacked for the same. Could you please provide your implementation thoughts on this Parallel and Stacked mode?

Quoted 1 line

From my side, i am thinking like below.

Will take two config entries CONFIG_SPI_XLNX_PARALLEL and CONFIG_SPI_XLNX_STACKED
and
#ifdef CONFIG_SPI_XILINX_PARALLEL
#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
------
.sector_size = (_sector_size) << 1, \
.n_sectors = (_n_sectors), \
.page_size = (256 << 1), \
.flags = (_flags | SPI_NOR_XLNX_PARALLEL),
#elif CONFIG_SPI_XILINX_STACKED

    #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
    -------

.sector_size = (_sector_size), \
.n_sectors = (_n_sectors << 1), \
.page_size = 256, \
.flags = (_flags | SPI_NOR_XLNX_STACKED),
#else
#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
------
.sector_size = (_sector_size), \
.n_sectors = (_n_sectors), \
.page_size = 256, \
.flags = (_flags),
#endif

Quoted 1 line

And in the spi_nor_scan()

if (info->flags & (SPI_NOR_XLNX_PARALLEL || SPI_NOR_XLNX_STACKED)) {
        mtd->size = (params.size << 1);
        if (info->flags & SPI_NOR_XLNX_PARALLEL) {
            nor->spi->controller->flags |= (SPI_CONTROLLER_BOTH_CS |
SPI_CONTROLLER_DATA_STRIPE);
            nor->flags |= SNOR_F_XLNX_PARALLEL;
        } else if (info->flags & SPI_NOR_XLNX_STACKED) {
            nor->flags |= SNOR_F_XLNX_STACKED;
       }
}

Based on these flags, will alter the address to write/read, in spi_nor_write() and spi_nor_read().
i will send an RFC patch with this update just to give show case this feature.

So could you please provide a way to implement the same?
i have also seen, that NXP flex controller is also supporting Parallel flash mode, but not sure how
they are handling the chip select and mtd->size, page_size etc... Sorry to bother you, but your suggestions helps a lot.

Thanks,
Naga Sureshkumar Relli

Quoted 3 lines

Regards,

Boris

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