Skip to contentSkip to conversation

spi: Add support for stacked/parallel memories

PATCH Applied Amit Kumar Mahapatra 13 participants 81 messages Nov 25, 2023 – Aug 19, 2024

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

v11 cover spi: Add support for stacked/parallel memories

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

The first nine patches
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
of the previous series got applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
for-next But the rest of the patches in the series did not get applied as failure was reported for spi driver with GPIO CS, so send the remaining patches in the series after rebasing it on top of for-next branch and fixing the issue.

CS GPIO is not tested on our hardware, but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/
---
BRANCH: for-next

Changes in v11:
- Rebased patch series on top of latest for-next branch.
- Added a new patch(1/10) to replace spi->chip_select with spi_get_chipselect() call in tps6594-spi.c.
- Added a new patch(2/10) to replace spi->chip_select with spi_get_chipseletc() call in cs35l56_hda_spi.c.
- In spi.c initialized unused CS[] to 0xff and spi->cs_index_mask to 0x01 in all flows.
- Updated spi_dev_check() to compare the CS of old spi device with the new spi device CS.
- Updated cover letter description to add information regarding GPIO CS testing and added Stefen's Tested-by tag in 3/10 patch.

Changes in v10:
- Rebased patch series on top of latest for-next branch and fixed merge conflicts.

Changes in v9:
- Updated 1/8 patch description to add an high-level overview of parallel(multi-cs) & stacked design.
- Initialized all unused CS to 0xFF.
- Moved CS check from spi_add_device() to __spi_add_device().
- Updated __spi_add_device() to check to make sure that multiple logical CS don't map to the same physical CS and same physical CS doesn't map to different logical CS.
- Updated 1/8, 5/8 & 7/8 to support arbitrary number of flash devices connected in parallel or stacked mode.
- Updated documentation for chip_select.
- Added a new spi-nor structure member nor->num_flash to keep track of the number of flashes connected.
- Added a new patch in the series 4/8 to move write_enable call just before spi_mem ops call in SPI-NOR.
- Added comments in SPI core & SPI-NOR.
- Rebased the patch series on top of the latest for-next branch.

Changes in v8:
- Updated __spi_add_device() and spi_set_cs() to fix spi driver failure with GPIO CS.
- Rebased the patch series on top of latest for-next branch and fixed merge conflicts.
- Updated cover letter description to add information regarding GPIO CS testing and request Stefan to provide his Tested-by tag for 1/7 patch.
- Updated 1/7 patch description.

Changes in v7:
- Updated spi_dev_check() to avoid failures for spi driver GPIO CS and moved the error message from __spi_add_device() to spi_dev_check().
- Resolved code indentation issue in spi_set_cs().
- In spi_set_cs() call spi_delay_exec( ) once if the controller supports multi cs with both the CS backed by GPIO.
- Updated __spi_validate()to add checks for both the GPIO CS.
- Replaced cs_index_mask bit mask with SPI_CS_CNT_MAX.
- Updated struct spi_controller to represent multi CS capability of the spi controller through a flag bit SPI_CONTROLLER_MULTI_CS instead of a boolen structure member "multi_cs_cap".
- Updated 1/7 patch description .

Changes in v6:
- Rebased on top of latest v6.3-rc1 and fixed merge conflicts in spi-mpc512x-psc.c, sfdp.c, spansion.c files and removed spi-omap-100k.c.
- Updated spi_dev_check( ) to reject new devices if any one of the chipselect is used by another device.

Changes in v5:
- Rebased the patches on top of v6.3-rc1 and fixed the merge conflicts.
- Fixed compilation warnings in spi-sh-msiof.c with shmobile_defconfig

Changes in v4:
- Fixed build error in spi-pl022.c file - reported by Mark.
- Fixed build error in spi-sn-f-ospi.c file.
- Added Reviewed-by: Serge Semin <[email protected]> tag.
- Added two more patches to replace spi->chip_select with API calls in mpc832x_rdb.c & cs35l41_hda_spi.c files.

Changes in v3:
- Rebased the patches on top of
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
- Added a patch to convert spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros into inline functions
- Added Reviewed-by & Acked-by tags

Changes in v2:
- Rebased the patches on top of v6.2-rc1
- Created separate patch to add get & set APIs for spi->chip_select & spi->cs_gpiod, and replaced all spi->chip_select and spi->cs_gpiod references with the API calls.
- Created separate patch to add get & set APIs for nor->params.
---
Amit Kumar Mahapatra (10):
mfd: tps6594: Use set/get APIs to access spi->chip_select
ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select
spi: Add multi-cs memories support in SPI core
mtd: spi-nor: Convert macros with inline functions
mtd: spi-nor: Add APIs to set/get nor->params
mtd: spi-nor: Move write enable inside specific write & erase APIs
mtd: spi-nor: Add stacked memories support in spi-nor
spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver
mtd: spi-nor: Add parallel memories support in spi-nor
spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver

 drivers/mfd/tps6594-spi.c        |   2 +-
 drivers/mtd/spi-nor/atmel.c      |  17 +-
 drivers/mtd/spi-nor/core.c       | 683 +++++++++++++++++++++++++------
 drivers/mtd/spi-nor/core.h       |   8 +
 drivers/mtd/spi-nor/debugfs.c    |   4 +-
 drivers/mtd/spi-nor/gigadevice.c |   4 +-
 drivers/mtd/spi-nor/issi.c       |  11 +-
 drivers/mtd/spi-nor/macronix.c   |  10 +-
 drivers/mtd/spi-nor/micron-st.c  |  35 +-
 drivers/mtd/spi-nor/otp.c        |  48 ++-
 drivers/mtd/spi-nor/sfdp.c       |  33 +-
 drivers/mtd/spi-nor/spansion.c   |  57 +--
 drivers/mtd/spi-nor/sst.c        |   7 +-
 drivers/mtd/spi-nor/swp.c        |  25 +-
 drivers/mtd/spi-nor/winbond.c    |   2 +-
 drivers/mtd/spi-nor/xilinx.c     |  18 +-
 drivers/spi/spi-zynqmp-gqspi.c   |  58 ++-
 drivers/spi/spi.c                | 259 ++++++++++--
 include/linux/mtd/spi-nor.h      |  21 +-
 include/linux/spi/spi.h          |  51 ++-
 sound/pci/hda/cs35l56_hda_spi.c  |   2 +-
 21 files changed, 1085 insertions(+), 270 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v11 1/10 mfd: tps6594: Use set/get APIs to access spi->chip_select

In preparation for adding multiple CS support for a device, set/get functions were introduces accessing spi->chip_select in 'commit 303feb3cc06a ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")'.
Replace spi->chip_select with spi_get_chipselect() API.

---
 drivers/mfd/tps6594-spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/tps6594-spi.c +1 -1
index f4b4f37f957f..24b72847e3f5 100644
@@ -98,7 +98,7 @@ static int tps6594_spi_probe(struct spi_device *spi)
 	spi_set_drvdata(spi, tps);
 
 	tps->dev = dev;
-	tps->reg = spi->chip_select;
+	tps->reg = spi_get_chipselect(spi, 0);
 	tps->irq = spi->irq;
 
 	tps->regmap = devm_regmap_init(dev, NULL, spi, &tps6594_spi_regmap_config);
Signature · 1 line
2.17.1
maintainer Applied
#2 lore raw

Re: (subset) [PATCH v11 01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

Quoted 8 lines · Amit Kumar Mahapatra

In preparation for adding multiple CS support for a device, set/get functions were introduces accessing spi->chip_select in 'commit 303feb3cc06a ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")'.
Replace spi->chip_select with spi_get_chipselect() API.

[...]

Applied, thanks!

[01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

        commit: dd636638446c87c95c5beddcd367d95ac6764c6c

--
Lee Jones [李琼斯]

maintainer
#3 lore raw

Re: (subset) [PATCH v11 01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

Quoted 11 lines · Lee Jones
Quoted 5 lines · Amit Kumar Mahapatra

In preparation for adding multiple CS support for a device, set/get functions were introduces accessing spi->chip_select in 'commit 303feb3cc06a ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")'.
Replace spi->chip_select with spi_get_chipselect() API.

Applied, thanks!

[01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

        commit: dd636638446c87c95c5beddcd367d95ac6764c6c

Is there a signed tag available for this - without this change the subsequent SPI changes introduce a build breakage.

maintainer
#4 lore raw

Re: (subset) [PATCH v11 01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

Quoted 8 lines · Mark Brown
Quoted 6 lines · Lee Jones
Quoted 5 lines · Amit Kumar Mahapatra

In preparation for adding multiple CS support for a device, set/get functions were introduces accessing spi->chip_select in 'commit 303feb3cc06a ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")'.
Replace spi->chip_select with spi_get_chipselect() API.

Quoted 7 lines
Quoted 4 lines

Applied, thanks!

[01/10] mfd: tps6594: Use set/get APIs to access spi->chip_select

        commit: dd636638446c87c95c5beddcd367d95ac6764c6c

Is there a signed tag available for this - without this change the subsequent SPI changes introduce a build breakage.

Not yet, but I can get around to making one.

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#5 lore raw

[GIT PULL] Immutable branch between MFD and SPI due for the v6.8 merge window

In reply to Mark Brown

Good afternoon Mark,

Quoted 2 lines

Is there a signed tag available for this - without this change the subsequent SPI changes introduce a build breakage.

The following changes since commit b85ea95d086471afb4ad062012a4d73cd328fa86:

Linux 6.7-rc1 (2023-11-12 16:19:07 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-spi-v6.8

for you to fetch changes up to 4ae08845db4c1f759b8382bc7527ab8249230e7f:

mfd: tps6594: Use spi_get_chipselect() API to access spi->chip_select (2023-12-07 13:36:29 +0000)

----------------------------------------------------------------
Immutable branch between MFD and SPI due for the v6.8 merge window

----------------------------------------------------------------
Amit Kumar Mahapatra (1):

      mfd: tps6594: Use spi_get_chipselect() API to access spi->chip_select
 drivers/mfd/tps6594-spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
Lee Jones [李琼斯]
maintainer
#6 lore raw

Re: [GIT PULL] Immutable branch between MFD and SPI due for the v6.8 merge window

Quoted 9 lines · Lee Jones

Good afternoon Mark,

Quoted 2 lines

Is there a signed tag available for this - without this change the subsequent SPI changes introduce a build breakage.

The following changes since commit b85ea95d086471afb4ad062012a4d73cd328fa86:

Linux 6.7-rc1 (2023-11-12 16:19:07 -0800)

Quoted 7 lines

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git ib-mfd-spi-v6.8

for you to fetch changes up to 4ae08845db4c1f759b8382bc7527ab8249230e7f:

mfd: tps6594: Use spi_get_chipselect() API to access spi->chip_select (2023-12-07 13:36:29 +0000)

Thanks!

#7 lore raw

PATCH v11 2/10 ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select

In reply to Amit Kumar Mahapatra

In preparation for adding multiple CS support for a device, set/get functions were introduces accessing spi->chip_select in 'commit 303feb3cc06a ("spi: Add APIs in spi core to set/get spi->chip_select and spi->cs_gpiod")'.
Replace spi->chip_select with spi_get_chipselect() API.

---
 sound/pci/hda/cs35l56_hda_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/hda/cs35l56_hda_spi.c +1 -1
index 756aec342eab..1c5cb3b1e2c3 100644
@@ -29,7 +29,7 @@ static int cs35l56_hda_spi_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	ret = cs35l56_hda_common_probe(cs35l56, spi->chip_select);
+	ret = cs35l56_hda_common_probe(cs35l56, spi_get_chipselect(spi, 0));
 	if (ret)
 		return ret;
 	ret = cs35l56_irq_request(&cs35l56->base, spi->irq);
Signature · 1 line
2.17.1
#8 lore raw

PATCH v11 3/10 spi: Add multi-cs memories support in SPI core

In reply to Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

One of these two mode is the parallel mode in which each byte of data is stored in both devices, the even bits in the lower flash & the odd bits in the upper flash. The byte split is automatically handled by the QSPI controller.

The other mode is the stacked mode in which both the flashes share the same SPI bus but each of the device contain half of the data. In this mode, the controller does not follow CS requests but instead internally wires the two CS levels with the value of the most significant address bit.

For supporting both these modes SPI core need to be updated for providing multiple CS for a single SPI device.

For adding multi CS support the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values.

spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n].

In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A SPI_CONTROLLER_MULTI_CS flag bit is added in the spi controller flags, through ctlr->flags the spi core will make sure that the controller is capable of handling multiple chip selects at once.

For supporting multiple CS via GPIO the cs_gpiod member of the spi_device structure is now an array that holds the gpio descriptor for each chipselect.

CS GPIO is not tested on our hardware, but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/

---
 drivers/spi/spi.c       | 259 +++++++++++++++++++++++++++++++++-------
 include/linux/spi/spi.h |  51 ++++++--
 2 files changed, 258 insertions(+), 52 deletions(-)
drivers/spi/spi.c +217 -42
index 8ead7acb99f3..45b6898cf0ee 100644
@@ -612,10 +612,21 @@ static int spi_dev_check(struct device *dev, void *data)
 {
 	struct spi_device *spi = to_spi_device(dev);
 	struct spi_device *new_spi = data;
-
-	if (spi->controller == new_spi->controller &&
-	    spi_get_chipselect(spi, 0) == spi_get_chipselect(new_spi, 0))
-		return -EBUSY;
+	int idx, nw_idx;
+	u8 cs, cs_nw;
+
+	if (spi->controller == new_spi->controller) {
+		for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+			cs = spi_get_chipselect(spi, idx);
+			for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX; nw_idx++) {
+				cs_nw = spi_get_chipselect(new_spi, nw_idx);
+				if (cs != 0xFF && cs_nw != 0xFF && cs == cs_nw) {
+					dev_err(dev, "chipselect %d already in use\n", cs_nw);
+					return -EBUSY;
+				}
+			}
+		}
+	}
 	return 0;
 }
 
@@ -629,13 +640,32 @@ static int __spi_add_device(struct spi_device *spi)
 {
 	struct spi_controller *ctlr = spi->controller;
 	struct device *dev = ctlr->dev.parent;
-	int status;
+	int status, idx, nw_idx;
+	u8 cs, nw_cs;
+
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+		/* Chipselects are numbered 0..max; validate. */
+		cs = spi_get_chipselect(spi, idx);
+		if (cs != 0xFF && cs >= ctlr->num_chipselect) {
+			dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx),
+				ctlr->num_chipselect);
+			return -EINVAL;
+		}
+	}
 
-	/* Chipselects are numbered 0..max; validate. */
-	if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) {
-		dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0),
-			ctlr->num_chipselect);
-		return -EINVAL;
+	/*
+	 * Make sure that multiple logical CS doesn't map to the same physical CS.
+	 * For example, spi->chip_select[0] != spi->chip_select[1] and so on.
+	 */
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+		cs = spi_get_chipselect(spi, idx);
+		for (nw_idx = idx + 1; nw_idx < SPI_CS_CNT_MAX; nw_idx++) {
+			nw_cs = spi_get_chipselect(spi, nw_idx);
+			if (cs != 0xFF && nw_cs != 0xFF && cs == nw_cs) {
+				dev_err(dev, "chipselect %d already in use\n", nw_cs);
+				return -EBUSY;
+			}
+		}
 	}
 
 	/* Set the bus ID string */
@@ -647,11 +677,8 @@ static int __spi_add_device(struct spi_device *spi)
 	 * its configuration.
 	 */
 	status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
-	if (status) {
-		dev_err(dev, "chipselect %d already in use\n",
-				spi_get_chipselect(spi, 0));
+	if (status)
 		return status;
-	}
 
 	/* Controller may unregister concurrently */
 	if (IS_ENABLED(CONFIG_SPI_DYNAMIC) &&
@@ -659,8 +686,15 @@ static int __spi_add_device(struct spi_device *spi)
 		return -ENODEV;
 	}
 
-	if (ctlr->cs_gpiods)
-		spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]);
+	if (ctlr->cs_gpiods) {
+		u8 cs;
+
+		for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+			cs = spi_get_chipselect(spi, idx);
+			if (cs != 0xFF)
+				spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
+		}
+	}
 
 	/*
 	 * Drivers may modify this initial i/o setup, but will
@@ -701,6 +735,9 @@ int spi_add_device(struct spi_device *spi)
 	struct spi_controller *ctlr = spi->controller;
 	int status;
 
+	/* Set the bus ID string */
+	spi_dev_set_name(spi);
+
 	mutex_lock(&ctlr->add_lock);
 	status = __spi_add_device(spi);
 	mutex_unlock(&ctlr->add_lock);
@@ -727,6 +764,7 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
 {
 	struct spi_device	*proxy;
 	int			status;
+	u8                      idx;
 
 	/*
 	 * NOTE:  caller did any chip->bus_num checks necessary.
@@ -742,6 +780,18 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
 
 	WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
 
+	/*
+	 * Zero(0) is a valid physical CS value and can be located at any
+	 * logical CS in the spi->chip_select[]. If all the physical CS
+	 * are initialized to 0 then It would be difficult to differentiate
+	 * between a valid physical CS 0 & an unused logical CS whose physical
+	 * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
+	 * Now all the unused logical CS will have 0xFF physical CS value & can be
+	 * ignore while performing physical CS validity checks.
+	 */
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		spi_set_chipselect(proxy, idx, 0xFF);
+
 	spi_set_chipselect(proxy, 0, chip->chip_select);
 	proxy->max_speed_hz = chip->max_speed_hz;
 	proxy->mode = chip->mode;
@@ -750,6 +800,15 @@ struct spi_device *spi_new_device(struct spi_controller *ctlr,
 	proxy->dev.platform_data = (void *) chip->platform_data;
 	proxy->controller_data = chip->controller_data;
 	proxy->controller_state = NULL;
+	/*
+	 * spi->chip_select[i] gives the corresponding physical CS for logical CS i
+	 * logical CS number is represented by setting the ith bit in spi->cs_index_mask
+	 * So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
+	 * spi->chip_select[0] will give the physical CS.
+	 * By default spi->chip_select[0] will hold the physical CS number so, set
+	 * spi->cs_index_mask as 0x01.
+	 */
+	proxy->cs_index_mask = 0x01;
 
 	if (chip->swnode) {
 		status = device_add_software_node(&proxy->dev, chip->swnode);
@@ -942,32 +1001,51 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
 }
 
 /*-------------------------------------------------------------------------*/
+static inline bool spi_is_last_cs(struct spi_device *spi)
+{
+	u8 idx;
+	bool last = false;
+
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+		if ((spi->cs_index_mask >> idx) & 0x01) {
+			if (spi->controller->last_cs[idx] == spi_get_chipselect(spi, idx))
+				last = true;
+		}
+	}
+	return last;
+}
+
 
 static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 {
 	bool activate = enable;
+	u8 idx;
 
 	/*
 	 * Avoid calling into the driver (or doing delays) if the chip select
 	 * isn't actually changing from the last time this was called.
 	 */
-	if (!force && ((enable && spi->controller->last_cs == spi_get_chipselect(spi, 0)) ||
-		       (!enable && spi->controller->last_cs != spi_get_chipselect(spi, 0))) &&
+	if (!force && ((enable && spi->controller->last_cs_index_mask == spi->cs_index_mask &&
+			spi_is_last_cs(spi)) ||
+		       (!enable && spi->controller->last_cs_index_mask == spi->cs_index_mask &&
+			!spi_is_last_cs(spi))) &&
 	    (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH)))
 		return;
 
 	trace_spi_set_cs(spi, activate);
 
-	spi->controller->last_cs = enable ? spi_get_chipselect(spi, 0) : -1;
+	spi->controller->last_cs_index_mask = spi->cs_index_mask;
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		spi->controller->last_cs[idx] = enable ? spi_get_chipselect(spi, 0) : -1;
 	spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;
 
-	if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) && !activate)
-		spi_delay_exec(&spi->cs_hold, NULL);
-
 	if (spi->mode & SPI_CS_HIGH)
 		enable = !enable;
 
-	if (spi_get_csgpiod(spi, 0)) {
+	if (spi_is_csgpiod(spi)) {
+		if (!spi->controller->set_cs_timing && !activate)
+			spi_delay_exec(&spi->cs_hold, NULL);
+
 		if (!(spi->mode & SPI_NO_CS)) {
 			/*
 			 * Historically ACPI has no means of the GPIO polarity and
@@ -979,26 +1057,38 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 			 * ambiguity. That's why we use enable, that takes SPI_CS_HIGH
 			 * into account.
 			 */
-			if (has_acpi_companion(&spi->dev))
-				gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), !enable);
-			else
-				/* Polarity handled by GPIO library */
-				gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), activate);
+			for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+				if (((spi->cs_index_mask >> idx) & 0x01) &&
+				    spi_get_csgpiod(spi, idx)) {
+					if (has_acpi_companion(&spi->dev))
+						gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
+									 !enable);
+					else
+						/* Polarity handled by GPIO library */
+						gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
+									 activate);
+
+					if (activate)
+						spi_delay_exec(&spi->cs_setup, NULL);
+					else
+						spi_delay_exec(&spi->cs_inactive, NULL);
+				}
+			}
 		}
 		/* Some SPI masters need both GPIO CS & slave_select */
 		if ((spi->controller->flags & SPI_CONTROLLER_GPIO_SS) &&
 		    spi->controller->set_cs)
 			spi->controller->set_cs(spi, !enable);
+
+		if (!spi->controller->set_cs_timing) {
+			if (activate)
+				spi_delay_exec(&spi->cs_setup, NULL);
+			else
+				spi_delay_exec(&spi->cs_inactive, NULL);
+		}
 	} else if (spi->controller->set_cs) {
 		spi->controller->set_cs(spi, !enable);
 	}
-
-	if (spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) {
-		if (activate)
-			spi_delay_exec(&spi->cs_setup, NULL);
-		else
-			spi_delay_exec(&spi->cs_inactive, NULL);
-	}
 }
 
 #ifdef CONFIG_HAS_DMA
@@ -2222,8 +2312,8 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,
 static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
 			   struct device_node *nc)
 {
-	u32 value;
-	int rc;
+	u32 value, cs[SPI_CS_CNT_MAX];
+	int rc, idx;
 
 	/* Mode (clock phase/polarity/etc.) */
 	if (of_property_read_bool(nc, "spi-cpha"))
@@ -2295,14 +2385,53 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
 		return 0;
 	}
 
+	if (ctlr->num_chipselect > SPI_CS_CNT_MAX) {
+		dev_err(&ctlr->dev, "No. of CS is more than max. no. of supported CS\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Zero(0) is a valid physical CS value and can be located at any
+	 * logical CS in the spi->chip_select[]. If all the physical CS
+	 * are initialized to 0 then It would be difficult to differentiate
+	 * between a valid physical CS 0 & an unused logical CS whose physical
+	 * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
+	 * Now all the unused logical CS will have 0xFF physical CS value & can be
+	 * ignore while performing physical CS validity checks.
+	 */
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		spi_set_chipselect(spi, idx, 0xFF);
+
 	/* Device address */
-	rc = of_property_read_u32(nc, "reg", &value);
-	if (rc) {
+	rc = of_property_read_variable_u32_array(nc, "reg", &cs[0], 1,
+						 SPI_CS_CNT_MAX);
+	if (rc < 0) {
 		dev_err(&ctlr->dev, "%pOF has no valid 'reg' property (%d)\n",
 			nc, rc);
 		return rc;
 	}
-	spi_set_chipselect(spi, 0, value);
+	if (rc > ctlr->num_chipselect) {
+		dev_err(&ctlr->dev, "%pOF has number of CS > ctlr->num_chipselect (%d)\n",
+			nc, rc);
+		return rc;
+	}
+	if ((of_property_read_bool(nc, "parallel-memories")) &&
+	    (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) {
+		dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n");
+		return -EINVAL;
+	}
+	for (idx = 0; idx < rc; idx++)
+		spi_set_chipselect(spi, idx, cs[idx]);
+
+	/*
+	 * spi->chip_select[i] gives the corresponding physical CS for logical CS i
+	 * logical CS number is represented by setting the ith bit in spi->cs_index_mask
+	 * So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
+	 * spi->chip_select[0] will give the physical CS.
+	 * By default spi->chip_select[0] will hold the physical CS number so, set
+	 * spi->cs_index_mask as 0x01.
+	 */
+	spi->cs_index_mask = 0x01;
 
 	/* Device speed */
 	if (!of_property_read_u32(nc, "spi-max-frequency", &value))
@@ -2408,6 +2537,7 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
 	struct spi_controller *ctlr = spi->controller;
 	struct spi_device *ancillary;
 	int rc = 0;
+	u8 idx;
 
 	/* Alloc an spi_device */
 	ancillary = spi_alloc_device(ctlr);
@@ -2418,12 +2548,33 @@ struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
 
 	strscpy(ancillary->modalias, "dummy", sizeof(ancillary->modalias));
 
+	/*
+	 * Zero(0) is a valid physical CS value and can be located at any
+	 * logical CS in the spi->chip_select[]. If all the physical CS
+	 * are initialized to 0 then It would be difficult to differentiate
+	 * between a valid physical CS 0 & an unused logical CS whose physical
+	 * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
+	 * Now all the unused logical CS will have 0xFF physical CS value & can be
+	 * ignore while performing physical CS validity checks.
+	 */
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		spi_set_chipselect(ancillary, idx, 0xFF);
+
 	/* Use provided chip-select for ancillary device */
 	spi_set_chipselect(ancillary, 0, chip_select);
 
 	/* Take over SPI mode/speed from SPI main device */
 	ancillary->max_speed_hz = spi->max_speed_hz;
 	ancillary->mode = spi->mode;
+	/*
+	 * spi->chip_select[i] gives the corresponding physical CS for logical CS i
+	 * logical CS number is represented by setting the ith bit in spi->cs_index_mask
+	 * So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
+	 * spi->chip_select[0] will give the physical CS.
+	 * By default spi->chip_select[0] will hold the physical CS number so, set
+	 * spi->cs_index_mask as 0x01.
+	 */
+	ancillary->cs_index_mask = 0x01;
 
 	WARN_ON(!mutex_is_locked(&ctlr->add_lock));
 
@@ -2626,6 +2777,7 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
 	struct acpi_spi_lookup lookup = {};
 	struct spi_device *spi;
 	int ret;
+	u8 idx;
 
 	if (!ctlr && index == -1)
 		return ERR_PTR(-EINVAL);
@@ -2661,12 +2813,33 @@ struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
 		return ERR_PTR(-ENOMEM);
 	}
 
+	/*
+	 * Zero(0) is a valid physical CS value and can be located at any
+	 * logical CS in the spi->chip_select[]. If all the physical CS
+	 * are initialized to 0 then It would be difficult to differentiate
+	 * between a valid physical CS 0 & an unused logical CS whose physical
+	 * CS can be 0. As a solution to this issue initialize all the CS to 0xFF.
+	 * Now all the unused logical CS will have 0xFF physical CS value & can be
+	 * ignore while performing physical CS validity checks.
+	 */
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		spi_set_chipselect(spi, idx, 0xFF);
+
 	ACPI_COMPANION_SET(&spi->dev, adev);
 	spi->max_speed_hz	= lookup.max_speed_hz;
 	spi->mode		|= lookup.mode;
 	spi->irq		= lookup.irq;
 	spi->bits_per_word	= lookup.bits_per_word;
 	spi_set_chipselect(spi, 0, lookup.chip_select);
+	/*
+	 * spi->chip_select[i] gives the corresponding physical CS for logical CS i
+	 * logical CS number is represented by setting the ith bit in spi->cs_index_mask
+	 * So, for example, if spi->cs_index_mask = 0x01 then logical CS number is 0 and
+	 * spi->chip_select[0] will give the physical CS.
+	 * By default spi->chip_select[0] will hold the physical CS number so, set
+	 * spi->cs_index_mask as 0x01.
+	 */
+	spi->cs_index_mask	= 0x01;
 
 	return spi;
 }
@@ -3100,6 +3273,7 @@ int spi_register_controller(struct spi_controller *ctlr)
 	struct boardinfo	*bi;
 	int			first_dynamic;
 	int			status;
+	int			idx;
 
 	if (!dev)
 		return -ENODEV;
@@ -3164,7 +3338,8 @@ int spi_register_controller(struct spi_controller *ctlr)
 	}
 
 	/* Setting last_cs to -1 means no chip selected */
-	ctlr->last_cs = -1;
+	for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+		ctlr->last_cs[idx] = -1;
 
 	status = device_add(&ctlr->dev);
 	if (status < 0)
@@ -3889,7 +4064,7 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
 	 * cs_change is set for each transfer.
 	 */
 	if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) ||
-					  spi_get_csgpiod(spi, 0))) {
+					  spi_is_csgpiod(spi))) {
 		size_t maxsize = BITS_TO_BYTES(spi->bits_per_word);
 		int ret;
 
include/linux/spi/spi.h +41 -10

129 lines not on this page · raw message

Signature · 1 line
2.17.1
#9 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Hi,

Quoted 33 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

One of these two mode is the parallel mode in which each byte of data is stored in both devices, the even bits in the lower flash & the odd bits in the upper flash. The byte split is automatically handled by the QSPI controller.

The other mode is the stacked mode in which both the flashes share the same SPI bus but each of the device contain half of the data. In this mode, the controller does not follow CS requests but instead internally wires the two CS levels with the value of the most significant address bit.

For supporting both these modes SPI core need to be updated for providing multiple CS for a single SPI device.

For adding multi CS support the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values.

spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n].

In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A SPI_CONTROLLER_MULTI_CS flag bit is added in the spi controller flags, through ctlr->flags the spi core will make sure that the controller is capable of handling multiple chip selects at once.

Quoted 7 lines

For supporting multiple CS via GPIO the cs_gpiod member of the spi_device structure is now an array that holds the gpio descriptor for each chipselect.

CS GPIO is not tested on our hardware, but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/

With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

[    3.006458] spi_master spi0: No. of CS is more than max. no. of supported CS
[    3.006775] spi_master spi0: Failed to create SPI device for /ahb/spi@1e620000/flash@0

The problem is no longer seen after reverting this patch.

Bisect log attached for reference.

Guenter

---
# bad: [70d201a40823acba23899342d62bc2644051ad2e] Merge tag 'f2fs-for-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
# good: [0dd3ee31125508cd67f7e7172247f05b7fd1753a] Linux 6.7
git bisect start 'HEAD' 'v6.7'
# bad: [de927f6c0b07d9e698416c5b287c521b07694cac] Merge tag 's390-6.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
git bisect bad de927f6c0b07d9e698416c5b287c521b07694cac
# bad: [35f11a3710cdcbbc5090d14017a6295454e0cc73] Merge tag 'mtd/for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
git bisect bad 35f11a3710cdcbbc5090d14017a6295454e0cc73
# good: [d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9] Merge tag 'slab-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab
git bisect good d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9
# good: [fb46e22a9e3863e08aef8815df9f17d0f4b9aede] Merge tag 'mm-stable-2024-01-08-15-31' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
git bisect good fb46e22a9e3863e08aef8815df9f17d0f4b9aede
# good: [063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac] Merge tag 'lsm-pr-20240105' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
git bisect good 063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac
# bad: [f6cd66231aa58599526584ff4df1bdde8d86eac8] spi: stm32: add st,stm32mp25-spi compatible supporting STM32MP25 soc
git bisect bad f6cd66231aa58599526584ff4df1bdde8d86eac8
# good: [18f78b5e609b19b56237f0dae47068d44b8b0ecd] spi: axi-spi-engine: improvements round 2
git bisect good 18f78b5e609b19b56237f0dae47068d44b8b0ecd
# bad: [9d93c8d97b4cdb5edddb4c5530881c90eecb7e44] spi: spi-ti-qspi: switch to use modern name
git bisect bad 9d93c8d97b4cdb5edddb4c5530881c90eecb7e44
# bad: [e6b7e64cb11966b26646a362677ca5a08481157e] spi: st-ssc4: switch to use modern name
git bisect bad e6b7e64cb11966b26646a362677ca5a08481157e
# bad: [c3aeaf2f0ec8af93189488bda3928a1ac7752388] spi: pxa2xx: Use inclusive language
git bisect bad c3aeaf2f0ec8af93189488bda3928a1ac7752388
# good: [f05e2f61fe88092e0d341ea27644a84e3386358d] ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select
git bisect good f05e2f61fe88092e0d341ea27644a84e3386358d
# bad: [88a50c1663ffa9f6b31705c6bf7a887a2c8d9434] spi: Add support for stacked/parallel memories
git bisect bad 88a50c1663ffa9f6b31705c6bf7a887a2c8d9434
# bad: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
git bisect bad 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

# first bad commit: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
maintainer
#10 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 4 lines · Guenter Roeck
Quoted 2 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

...

Quoted 3 lines

With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

Not sure what quanta-q711-bmc is - is almetto-bmc really palmetto-bmc (which has a mainline DT with a SPI flash)?

Quoted 41 lines
[    3.006458] spi_master spi0: No. of CS is more than max. no. of supported CS
[    3.006775] spi_master spi0: Failed to create SPI device for /ahb/spi@1e620000/flash@0

The problem is no longer seen after reverting this patch.

Bisect log attached for reference.

Guenter

---
# bad: [70d201a40823acba23899342d62bc2644051ad2e] Merge tag 'f2fs-for-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
# good: [0dd3ee31125508cd67f7e7172247f05b7fd1753a] Linux 6.7
git bisect start 'HEAD' 'v6.7'
# bad: [de927f6c0b07d9e698416c5b287c521b07694cac] Merge tag 's390-6.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
git bisect bad de927f6c0b07d9e698416c5b287c521b07694cac
# bad: [35f11a3710cdcbbc5090d14017a6295454e0cc73] Merge tag 'mtd/for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
git bisect bad 35f11a3710cdcbbc5090d14017a6295454e0cc73
# good: [d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9] Merge tag 'slab-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab
git bisect good d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9
# good: [fb46e22a9e3863e08aef8815df9f17d0f4b9aede] Merge tag 'mm-stable-2024-01-08-15-31' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
git bisect good fb46e22a9e3863e08aef8815df9f17d0f4b9aede
# good: [063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac] Merge tag 'lsm-pr-20240105' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
git bisect good 063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac
# bad: [f6cd66231aa58599526584ff4df1bdde8d86eac8] spi: stm32: add st,stm32mp25-spi compatible supporting STM32MP25 soc
git bisect bad f6cd66231aa58599526584ff4df1bdde8d86eac8
# good: [18f78b5e609b19b56237f0dae47068d44b8b0ecd] spi: axi-spi-engine: improvements round 2
git bisect good 18f78b5e609b19b56237f0dae47068d44b8b0ecd
# bad: [9d93c8d97b4cdb5edddb4c5530881c90eecb7e44] spi: spi-ti-qspi: switch to use modern name
git bisect bad 9d93c8d97b4cdb5edddb4c5530881c90eecb7e44
# bad: [e6b7e64cb11966b26646a362677ca5a08481157e] spi: st-ssc4: switch to use modern name
git bisect bad e6b7e64cb11966b26646a362677ca5a08481157e
# bad: [c3aeaf2f0ec8af93189488bda3928a1ac7752388] spi: pxa2xx: Use inclusive language
git bisect bad c3aeaf2f0ec8af93189488bda3928a1ac7752388
# good: [f05e2f61fe88092e0d341ea27644a84e3386358d] ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select
git bisect good f05e2f61fe88092e0d341ea27644a84e3386358d
# bad: [88a50c1663ffa9f6b31705c6bf7a887a2c8d9434] spi: Add support for stacked/parallel memories
git bisect bad 88a50c1663ffa9f6b31705c6bf7a887a2c8d9434
# bad: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
git bisect bad 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

# first bad commit: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
#11 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 6 lines · Mark Brown
Quoted 4 lines · Guenter Roeck
Quoted 2 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

Quoted 9 lines

...

Quoted 3 lines

With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

Not sure what quanta-q711-bmc is - is almetto-bmc really palmetto-bmc (which has a mainline DT with a SPI flash)?

Yes, sorry, it should have been palmetto-bmc.

quanta-q71l-bmc: See arch/arm/boot/dts/aspeed/aspeed-bmc-quanta-q71l.dts

(it is q71l, not q711)

Guenter

#12 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

In reply to Guenter Roeck
Quoted 44 lines · Guenter Roeck

Hi,

Quoted 33 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

One of these two mode is the parallel mode in which each byte of data is stored in both devices, the even bits in the lower flash & the odd bits in the upper flash. The byte split is automatically handled by the QSPI controller.

The other mode is the stacked mode in which both the flashes share the same SPI bus but each of the device contain half of the data. In this mode, the controller does not follow CS requests but instead internally wires the two CS levels with the value of the most significant address bit.

For supporting both these modes SPI core need to be updated for providing multiple CS for a single SPI device.

For adding multi CS support the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values.

spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n].

In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A SPI_CONTROLLER_MULTI_CS flag bit is added in the spi controller flags, through ctlr->flags the spi core will make sure that the controller is capable of handling multiple chip selects at once.

Quoted 7 lines

For supporting multiple CS via GPIO the cs_gpiod member of the spi_device structure is now an array that holds the gpio descriptor for each chipselect.

CS GPIO is not tested on our hardware, but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/

Quoted 9 lines

With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

[    3.006458] spi_master spi0: No. of CS is more than max. no. of supported CS
[    3.006775] spi_master spi0: Failed to create SPI device for /ahb/spi@1e620000/flash@0

The problem is no longer seen after reverting this patch.

FWIW, the problem is due to

+#define SPI_CS_CNT_MAX 4

in the offending patch, but apeed2400 FMC supports up to 5 SPI chip selects.

 static const struct aspeed_spi_data ast2400_fmc_data = {
        .max_cs        = 5,
	^^^^^^^^^^^^^^^^^^^
        .hastype       = true,

Limiting .max_cs to 4 or increasing SPI_CS_CNT_MAX to 5 fixes the problem, though of course I don't know if increasing SPI_CS_CNT_MAX has other side effects.

Guenter

Quoted 35 lines

Bisect log attached for reference.

Guenter

---
# bad: [70d201a40823acba23899342d62bc2644051ad2e] Merge tag 'f2fs-for-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
# good: [0dd3ee31125508cd67f7e7172247f05b7fd1753a] Linux 6.7
git bisect start 'HEAD' 'v6.7'
# bad: [de927f6c0b07d9e698416c5b287c521b07694cac] Merge tag 's390-6.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
git bisect bad de927f6c0b07d9e698416c5b287c521b07694cac
# bad: [35f11a3710cdcbbc5090d14017a6295454e0cc73] Merge tag 'mtd/for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
git bisect bad 35f11a3710cdcbbc5090d14017a6295454e0cc73
# good: [d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9] Merge tag 'slab-for-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab
git bisect good d30e51aa7b1f6fa7dd78d4598d1e4c047fcc3fb9
# good: [fb46e22a9e3863e08aef8815df9f17d0f4b9aede] Merge tag 'mm-stable-2024-01-08-15-31' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
git bisect good fb46e22a9e3863e08aef8815df9f17d0f4b9aede
# good: [063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac] Merge tag 'lsm-pr-20240105' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
git bisect good 063a7ce32ddc2c4f2404b0dfd29e60e3dbcdffac
# bad: [f6cd66231aa58599526584ff4df1bdde8d86eac8] spi: stm32: add st,stm32mp25-spi compatible supporting STM32MP25 soc
git bisect bad f6cd66231aa58599526584ff4df1bdde8d86eac8
# good: [18f78b5e609b19b56237f0dae47068d44b8b0ecd] spi: axi-spi-engine: improvements round 2
git bisect good 18f78b5e609b19b56237f0dae47068d44b8b0ecd
# bad: [9d93c8d97b4cdb5edddb4c5530881c90eecb7e44] spi: spi-ti-qspi: switch to use modern name
git bisect bad 9d93c8d97b4cdb5edddb4c5530881c90eecb7e44
# bad: [e6b7e64cb11966b26646a362677ca5a08481157e] spi: st-ssc4: switch to use modern name
git bisect bad e6b7e64cb11966b26646a362677ca5a08481157e
# bad: [c3aeaf2f0ec8af93189488bda3928a1ac7752388] spi: pxa2xx: Use inclusive language
git bisect bad c3aeaf2f0ec8af93189488bda3928a1ac7752388
# good: [f05e2f61fe88092e0d341ea27644a84e3386358d] ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select
git bisect good f05e2f61fe88092e0d341ea27644a84e3386358d
# bad: [88a50c1663ffa9f6b31705c6bf7a887a2c8d9434] spi: Add support for stacked/parallel memories
git bisect bad 88a50c1663ffa9f6b31705c6bf7a887a2c8d9434
# bad: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
git bisect bad 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

# first bad commit: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
maintainer
#13 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 6 lines · Guenter Roeck

FWIW, the problem is due to

+#define SPI_CS_CNT_MAX 4

in the offending patch, but apeed2400 FMC supports up to 5 SPI chip selects.

Quoted 8 lines
 static const struct aspeed_spi_data ast2400_fmc_data = {
        .max_cs        = 5,
	^^^^^^^^^^^^^^^^^^^
        .hastype       = true,

Limiting .max_cs to 4 or increasing SPI_CS_CNT_MAX to 5 fixes the problem, though of course I don't know if increasing SPI_CS_CNT_MAX has other side effects.

Yeah, I was coming to a similar conclusion myself - the limit is just too low. I can't see any problem with increasing it.

#14 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 13 lines · Mark Brown
Quoted 10 lines · Guenter Roeck

FWIW, the problem is due to

+#define SPI_CS_CNT_MAX 4

in the offending patch, but apeed2400 FMC supports up to 5 SPI chip selects.

  static const struct aspeed_spi_data ast2400_fmc_data = {
         .max_cs        = 5,
	^^^^^^^^^^^^^^^^^^^
         .hastype       = true,
Quoted 6 lines
Quoted 3 lines

Limiting .max_cs to 4 or increasing SPI_CS_CNT_MAX to 5 fixes the problem, though of course I don't know if increasing SPI_CS_CNT_MAX has other side effects.

Yeah, I was coming to a similar conclusion myself - the limit is just too low. I can't see any problem with increasing it.

It would cost a bit of memory and somewhat affect performance sine many of the newly introduced loops are bound by SPI_CS_CNT_MAX and not by num_chipselect.

It also might make sense to document the new limit somewhere. Prior to this commit it was not limited at all. Documentation/devicetree/bindings/spi/spi-davinci.txt lists 5 chip selects in its example for the use of cs-gpios. Documentation/devicetree/bindings/spi/spi-controller.yaml also does not list a limit.

Thanks,
Guenter

#15 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 22 lines
Quoted 11 lines
Quoted 10 lines

FWIW, the problem is due to

+#define SPI_CS_CNT_MAX 4

in the offending patch, but apeed2400 FMC supports up to 5 SPI chip selects.

  static const struct aspeed_spi_data ast2400_fmc_data = {
         .max_cs        = 5,
	^^^^^^^^^^^^^^^^^^^
         .hastype       = true,
Quoted 6 lines
Quoted 3 lines

Limiting .max_cs to 4 or increasing SPI_CS_CNT_MAX to 5 fixes the problem, though of course I don't know if increasing SPI_CS_CNT_MAX has other side effects.

Yeah, I was coming to a similar conclusion myself - the limit is just too low. I can't see any problem with increasing it.

It would cost a bit of memory and somewhat affect performance sine many of the newly introduced loops are bound by SPI_CS_CNT_MAX and not by num_chipselect.

Quoted 6 lines

It also might make sense to document the new limit somewhere. Prior to this commit it was not limited at all. Documentation/devicetree/bindings/spi/spi-davinci.txt lists 5 chip selects in its example for the use of cs-gpios. Documentation/devicetree/bindings/spi/spi-controller.yaml also does not list a limit.

Given that, that the rest of this series is under discussion (and esp. whether it is the correct way to do it) it might make sense to just revert the picked patches.

-michael

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

#16 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 29 lines · Michael Walle
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines

FWIW, the problem is due to

+#define SPI_CS_CNT_MAX 4

in the offending patch, but apeed2400 FMC supports up to 5 SPI chip selects.

  static const struct aspeed_spi_data ast2400_fmc_data = { .max_cs        = 5,
    ^^^^^^^^^^^^^^^^^^^
         .hastype       = true,

Quoted 6 lines
Quoted 3 lines

Limiting .max_cs to 4 or increasing SPI_CS_CNT_MAX to 5 fixes the problem, though of course I don't know if increasing SPI_CS_CNT_MAX has other side effects.

Yeah, I was coming to a similar conclusion myself - the limit is just too low.  I can't see any problem with increasing it.

It would cost a bit of memory and somewhat affect performance sine many of the newly introduced loops are bound by SPI_CS_CNT_MAX and not by num_chipselect.

Quoted 6 lines

It also might make sense to document the new limit somewhere. Prior to this commit it was not limited at all. Documentation/devicetree/bindings/spi/spi-davinci.txt lists 5 chip selects in its example for the use of cs-gpios. Documentation/devicetree/bindings/spi/spi-controller.yaml also does not list a limit.

Quoted 4 lines

Given that, that the rest of this series is under discussion (and esp. whether it is the correct way to do it) it might make sense to just revert the picked patches.

I can't really comment on that, but I found that there is another affected devicetree property: num-cs. Its range isn't limited in Documentation/devicetree/bindings/spi/spi-controller.yaml. Various dts/dtsi files use numbers as large as 8. The range is limited in some bindings files, but not all of them. Documentation/devicetree/bindings/spi/spi-lantiq-ssc.txt, for example, says

"num-cs: see spi-bus.txt, set to 8 if unset"

Various Broadcom dtsi files set it to 8.

So I guess 8 would be the absolute minimum to re-enable support for affected systems.

Guenter

maintainer
#17 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 2 lines · Guenter Roeck

So I guess 8 would be the absolute minimum to re-enable support for affected systems.

That's actually the number I went for, just waiting for CI to go through before I send it out.

maintainer
#18 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

In reply to Michael Walle
Quoted 5 lines · Michael Walle

Given that, that the rest of this series is under discussion (and esp. whether
it is the correct way to do it) it might make sense to just revert the picked
patches.

The API change in the patch is a pain out of tree due to the way it's easy to add new things that miss the helpers without it so I'd rather keep it in if possible. The underlying implementation does need some TLC though.

#19 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

In reply to Guenter Roeck
Quoted 14 lines · Guenter Roeck
Quoted 7 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

One of these two mode is the parallel mode in which each byte of data is stored in both devices, the even bits in the lower flash & the odd bits in the upper flash. The byte split is automatically handled by the QSPI controller.

[...]
With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

Quoted 6 lines
[    3.006458] spi_master spi0: No. of CS is more than max. no. of supported CS
[    3.006775] spi_master spi0: Failed to create SPI device for /ahb/spi@1e620000/flash@0

The problem is no longer seen after reverting this patch. [...]

# first bad commit: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core

Thanks for the report. To be sure the issue doesn't fall through the cracks unnoticed, I'm adding it to regzbot, the Linux kernel regression tracking bot:

#regzbot ^introduced 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9 #regzbot title spi: qemu emulations quanta-q71l-bmc and almetto-bmc fail to boot
#regzbot ignore-activity

This isn't a regression? This issue or a fix for it are already discussed somewhere else? It was fixed already? You want to clarify when the regression started to happen? Or point out I got the title or something else totally wrong? Then just reply and tell me -- ideally while also telling regzbot about it, as explained by the page listed in the footer of this mail.

Developers: When fixing the issue, remember to add 'Link:' tags pointing to the report (the parent of this mail). See page linked in footer for details.

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
That page also explains what to do if mails like this annoy you.

#20 lore raw

Re: [PATCH v11 03/10] spi: Add multi-cs memories support in SPI core

Quoted 22 lines · Linux regression tracking #adding (Thorsten Leemhuis)
Quoted 14 lines · Guenter Roeck
Quoted 7 lines · Amit Kumar Mahapatra

AMD-Xilinx GQSPI controller has two advanced mode that allows the controller to consider two flashes as one single device.

One of these two mode is the parallel mode in which each byte of data is stored in both devices, the even bits in the lower flash & the odd bits in the upper flash. The byte split is automatically handled by the QSPI controller.

[...]
With this patch in the mainline kernel, two of my qemu emulations (quanta-q71l-bmc and almetto-bmc) fail to instantiate the first SPI controller and thus fail to boot from SPI. The error message is

Quoted 6 lines
[    3.006458] spi_master spi0: No. of CS is more than max. no. of supported CS
[    3.006775] spi_master spi0: Failed to create SPI device for /ahb/spi@1e620000/flash@0

The problem is no longer seen after reverting this patch. [...]

# first bad commit: [4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b] spi: Add multi-cs memories support in SPI core
Quoted 8 lines

Thanks for the report. To be sure the issue doesn't fall through the cracks unnoticed, I'm adding it to regzbot, the Linux kernel regression tracking bot:

#regzbot ^introduced 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9 #regzbot title spi: qemu emulations quanta-q71l-bmc and almetto-bmc fail to boot
#regzbot ignore-activity

#regzbot fix: spi: Raise limit on number of chip selects #regzbot ignore-activity

Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
That page also explains what to do if mails like this annoy you.

#21 lore raw

PATCH v11 4/10 mtd: spi-nor: Convert macros with inline functions

In reply to Amit Kumar Mahapatra

In further patches the nor->params references in spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros will be replaced with spi_nor_get_params() API. To make the transition smoother, first converting the macros into static inline functions.

---
 drivers/mtd/spi-nor/otp.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/otp.c +21 -2
index 9a729aa3452d..23fe75ddc9cf 100644
@@ -11,8 +11,27 @@
 
 #include "core.h"
 
-#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len)
-#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions)
+/**
+ * spi_nor_otp_region_len() - get size of one OTP region in bytes
+ * @nor:        pointer to 'struct spi_nor'
+ *
+ * Return: size of one OTP region in bytes
+ */
+static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor)
+{
+	return nor->params->otp.org->len;
+}
+
+/**
+ * spi_nor_otp_n_regions() - get number of individual OTP regions
+ * @nor:        pointer to 'struct spi_nor'
+ *
+ * Return: number of individual OTP regions
+ */
+static inline unsigned int spi_nor_otp_n_regions(struct spi_nor *nor)
+{
+	return nor->params->otp.org->n_regions;
+}
 
 /**
  * spi_nor_otp_read_secr() - read security register
Signature · 1 line
2.17.1
#22 lore raw

PATCH v11 5/10 mtd: spi-nor: Add APIs to set/get nor->params

In reply to Amit Kumar Mahapatra

Supporting multi-cs in spi-nor would require the *params member of struct spi_nor to be an array. To make the transition smoother introduced spi_nor_get_params() & spi_nor_set_params() APIs to get & set nor->params, added a new local variable (struct spi_nor_flash_parameter *params) to hold the return value of the spi_nor_get_params() function call and replaced all nor->params references with the "params".
While adding multi-cs support in further patches the *params member of the spi_nor structure would be converted to arrays & the "idx" parameter of the APIs would be used as array index i.e., nor->params[idx].

---
 drivers/mtd/spi-nor/atmel.c      |  17 ++--
 drivers/mtd/spi-nor/core.c       | 136 ++++++++++++++++++++-----------
 drivers/mtd/spi-nor/debugfs.c    |   4 +-
 drivers/mtd/spi-nor/gigadevice.c |   4 +-
 drivers/mtd/spi-nor/issi.c       |  11 ++-
 drivers/mtd/spi-nor/macronix.c   |  10 ++-
 drivers/mtd/spi-nor/micron-st.c  |  30 ++++---
 drivers/mtd/spi-nor/otp.c        |  29 +++++--
 drivers/mtd/spi-nor/sfdp.c       |  33 ++++----
 drivers/mtd/spi-nor/spansion.c   |  57 +++++++------
 drivers/mtd/spi-nor/sst.c        |   7 +-
 drivers/mtd/spi-nor/swp.c        |  25 ++++--
 drivers/mtd/spi-nor/winbond.c    |   2 +-
 drivers/mtd/spi-nor/xilinx.c     |  18 ++--
 include/linux/mtd/spi-nor.h      |  10 +++
 15 files changed, 257 insertions(+), 136 deletions(-)
drivers/mtd/spi-nor/atmel.c +12 -5
index e13b8d2dd50a..b63cbe18162c 100644
@@ -23,10 +23,11 @@ static int at25fs_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 
 static int at25fs_nor_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 
 	/* We only support unlocking the whole flash array */
-	if (ofs || len != nor->params->size)
+	if (ofs || len != params->size)
 		return -EINVAL;
 
 	/* Write 0x00 to the status register to disable write protection */
@@ -50,7 +51,9 @@ static const struct spi_nor_locking_ops at25fs_nor_locking_ops = {
 
 static int at25fs_nor_late_init(struct spi_nor *nor)
 {
-	nor->params->locking_ops = &at25fs_nor_locking_ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->locking_ops = &at25fs_nor_locking_ops;
 
 	return 0;
 }
@@ -71,11 +74,12 @@ static const struct spi_nor_fixups at25fs_nor_fixups = {
 static int atmel_nor_set_global_protection(struct spi_nor *nor, loff_t ofs,
 					   uint64_t len, bool is_protect)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 	u8 sr;
 
 	/* We only support locking the whole flash array */
-	if (ofs || len != nor->params->size)
+	if (ofs || len != params->size)
 		return -EINVAL;
 
 	ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -133,9 +137,10 @@ static int atmel_nor_global_unprotect(struct spi_nor *nor, loff_t ofs,
 static int atmel_nor_is_global_protected(struct spi_nor *nor, loff_t ofs,
 					 uint64_t len)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 
-	if (ofs >= nor->params->size || (ofs + len) > nor->params->size)
+	if (ofs >= params->size || (ofs + len) > params->size)
 		return -EINVAL;
 
 	ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -153,7 +158,9 @@ static const struct spi_nor_locking_ops atmel_nor_global_protection_ops = {
 
 static int atmel_nor_global_protection_late_init(struct spi_nor *nor)
 {
-	nor->params->locking_ops = &atmel_nor_global_protection_ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->locking_ops = &atmel_nor_global_protection_ops;
 
 	return 0;
 }
drivers/mtd/spi-nor/core.c +88 -48

484 lines not on this page · raw message

drivers/mtd/spi-nor/debugfs.c +2 -2
index 6e163cb5b478..72a901b88ea9 100644
@@ -76,7 +76,7 @@ static void spi_nor_print_flags(struct seq_file *s, unsigned long flags,
 static int spi_nor_params_show(struct seq_file *s, void *data)
 {
 	struct spi_nor *nor = s->private;
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct spi_nor_erase_map *erase_map = &params->erase_map;
 	struct spi_nor_erase_region *region;
 	const struct flash_info *info = nor->info;
@@ -184,7 +184,7 @@ static void spi_nor_print_pp_cmd(struct seq_file *s,
 static int spi_nor_capabilities_show(struct seq_file *s, void *data)
 {
 	struct spi_nor *nor = s->private;
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	u32 hwcaps = params->hwcaps.mask;
 	int i, cmd;
 
drivers/mtd/spi-nor/gigadevice.c +3 -1
index ef1edd0add70..338ce989df22 100644
@@ -13,6 +13,8 @@ gd25q256_post_bfpt(struct spi_nor *nor,
 		   const struct sfdp_parameter_header *bfpt_header,
 		   const struct sfdp_bfpt *bfpt)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
 	/*
 	 * GD25Q256C supports the first version of JESD216 which does not define
 	 * the Quad Enable methods. Overwrite the default Quad Enable method.
@@ -24,7 +26,7 @@ gd25q256_post_bfpt(struct spi_nor *nor,
 	 */
 	if (bfpt_header->major == SFDP_JESD216_MAJOR &&
 	    bfpt_header->minor == SFDP_JESD216_MINOR)
-		nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
+		params->quad_enable = spi_nor_sr1_bit6_quad_enable;
 
 	return 0;
 }
drivers/mtd/spi-nor/issi.c +8 -3
index 18d9a00aa22e..ea148a3a5e1f 100644
@@ -13,6 +13,8 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor,
 			   const struct sfdp_parameter_header *bfpt_header,
 			   const struct sfdp_bfpt *bfpt)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
 	/*
 	 * IS25LP256 supports 4B opcodes, but the BFPT advertises
 	 * BFPT_DWORD1_ADDRESS_BYTES_3_ONLY.
@@ -20,7 +22,7 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor,
 	 */
 	if ((bfpt->dwords[SFDP_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) ==
 		BFPT_DWORD1_ADDRESS_BYTES_3_ONLY)
-		nor->params->addr_nbytes = 4;
+		params->addr_nbytes = 4;
 
 	return 0;
 }
@@ -31,7 +33,8 @@ static const struct spi_nor_fixups is25lp256_fixups = {
 
 static int pm25lv_nor_late_init(struct spi_nor *nor)
 {
-	struct spi_nor_erase_map *map = &nor->params->erase_map;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	struct spi_nor_erase_map *map = &params->erase_map;
 	int i;
 
 	/* The PM25LV series has a different 4k sector erase opcode */
@@ -131,7 +134,9 @@ static const struct flash_info issi_nor_parts[] = {
 
 static void issi_nor_default_init(struct spi_nor *nor)
 {
-	nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->quad_enable = spi_nor_sr1_bit6_quad_enable;
 }
 
 static const struct spi_nor_fixups issi_fixups = {
drivers/mtd/spi-nor/macronix.c +7 -3
index ea6be95e75a5..be1f273e3ce2 100644
@@ -187,13 +187,17 @@ static const struct flash_info macronix_nor_parts[] = {
 
 static void macronix_nor_default_init(struct spi_nor *nor)
 {
-	nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->quad_enable = spi_nor_sr1_bit6_quad_enable;
 }
 
 static int macronix_nor_late_init(struct spi_nor *nor)
 {
-	if (!nor->params->set_4byte_addr_mode)
-		nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	if (!params->set_4byte_addr_mode)
+		params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b;
 
 	return 0;
 }
drivers/mtd/spi-nor/micron-st.c +19 -11
index 8920547c12bf..813a5b1a269b 100644
@@ -49,10 +49,11 @@
 
 static int micron_st_nor_octal_dtr_en(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct spi_mem_op op;
 	u8 *buf = nor->bouncebuf;
 	int ret;
-	u8 addr_mode_nbytes = nor->params->addr_mode_nbytes;
+	u8 addr_mode_nbytes = params->addr_mode_nbytes;
 
 	/* Use 20 dummy cycles for memory array reads. */
 	*buf = 20;
@@ -128,27 +129,31 @@ static int micron_st_nor_set_octal_dtr(struct spi_nor *nor, bool enable)
 
 static void mt35xu512aba_default_init(struct spi_nor *nor)
 {
-	nor->params->set_octal_dtr = micron_st_nor_set_octal_dtr;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->set_octal_dtr = micron_st_nor_set_octal_dtr;
 }
 
 static int mt35xu512aba_post_sfdp_fixup(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
 	/* Set the Fast Read settings. */
-	nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
-	spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR],
+	params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
+	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_8_8_8_DTR],
 				  0, 20, SPINOR_OP_MT_DTR_RD,
 				  SNOR_PROTO_8_8_8_DTR);
 
 	nor->cmd_ext_type = SPI_NOR_EXT_REPEAT;
-	nor->params->rdsr_dummy = 8;
-	nor->params->rdsr_addr_nbytes = 0;
+	params->rdsr_dummy = 8;
+	params->rdsr_addr_nbytes = 0;
 
 	/*
 	 * The BFPT quad enable field is set to a reserved value so the quad
 	 * enable function is ignored by spi_nor_parse_bfpt(). Make sure we
 	 * disable it.
 	 */
-	nor->params->quad_enable = NULL;
+	params->quad_enable = NULL;
 
 	return 0;
 }
@@ -457,14 +462,15 @@ static const struct flash_info st_nor_parts[] = {
  */
 static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 
 	if (nor->spimem) {
 		struct spi_mem_op op = MICRON_ST_RDFSR_OP(fsr);
 
 		if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) {
-			op.addr.nbytes = nor->params->rdsr_addr_nbytes;
-			op.dummy.nbytes = nor->params->rdsr_dummy;
+			op.addr.nbytes = params->rdsr_addr_nbytes;
+			op.dummy.nbytes = params->rdsr_dummy;
 			/*
 			 * We don't want to read only one byte in DTR mode. So,
 			 * read 2 and then discard the second byte.
@@ -567,14 +573,16 @@ static int micron_st_nor_ready(struct spi_nor *nor)
 
 static void micron_st_nor_default_init(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
 	nor->flags |= SNOR_F_HAS_LOCK;
 	nor->flags &= ~SNOR_F_HAS_16BIT_SR;
-	nor->params->quad_enable = NULL;
+	params->quad_enable = NULL;
 }
 
 static int micron_st_nor_late_init(struct spi_nor *nor)
 {
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 
 	if (nor->info->mfr_flags & USE_FSR)
 		params->ready = micron_st_nor_ready;
drivers/mtd/spi-nor/otp.c +20 -9
index 23fe75ddc9cf..16a9a0375aeb 100644
@@ -19,7 +19,9 @@
  */
 static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor)
 {
-	return nor->params->otp.org->len;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	return params->otp.org->len;
 }
 
 /**
@@ -30,7 +32,9 @@ static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor)
  */
 static inline unsigned int spi_nor_otp_n_regions(struct spi_nor *nor)
 {
-	return nor->params->otp.org->n_regions;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	return params->otp.org->n_regions;
 }
 
 /**
@@ -241,7 +245,8 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region)
 
 static loff_t spi_nor_otp_region_start(const struct spi_nor *nor, unsigned int region)
 {
-	const struct spi_nor_otp_organization *org = nor->params->otp.org;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_organization *org = params->otp.org;
 
 	return org->base + region * org->offset;
 }
@@ -266,7 +271,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len,
 				size_t *retlen, struct otp_info *buf)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_ops *ops = params->otp.ops;
 	unsigned int n_regions = spi_nor_otp_n_regions(nor);
 	unsigned int i;
 	int ret, locked;
@@ -303,7 +309,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len,
 static int spi_nor_mtd_otp_range_is_locked(struct spi_nor *nor, loff_t ofs,
 					   size_t len)
 {
-	const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_ops *ops = params->otp.ops;
 	unsigned int region;
 	int locked;
 
@@ -328,7 +335,8 @@ static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs,
 				      const u8 *buf, bool is_write)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_ops *ops = params->otp.ops;
 	const size_t rlen = spi_nor_otp_region_len(nor);
 	loff_t rstart, rofs;
 	unsigned int region;
@@ -414,7 +422,8 @@ static int spi_nor_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len,
 static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_ops *ops = params->otp.ops;
 	const size_t rlen = spi_nor_otp_region_len(nor);
 	unsigned int region;
 	loff_t rstart;
@@ -467,7 +476,8 @@ static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len)
 static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	const struct spi_nor_otp_ops *ops = nor->params->otp.ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	const struct spi_nor_otp_ops *ops = params->otp.ops;
 	const size_t rlen = spi_nor_otp_region_len(nor);
 	unsigned int region;
 	int ret;
@@ -501,9 +511,10 @@ static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len)
 
 void spi_nor_set_mtd_otp_ops(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct mtd_info *mtd = &nor->mtd;
 
-	if (!nor->params->otp.ops)
+	if (!params->otp.ops)
 		return;
 
 	if (WARN_ON(!is_power_of_2(spi_nor_otp_region_len(nor))))
drivers/mtd/spi-nor/sfdp.c +19 -14
index b3b11dfed789..f7137c100569 100644
@@ -436,7 +436,7 @@ static void spi_nor_regions_sort_erase_types(struct spi_nor_erase_map *map)
 static int spi_nor_parse_bfpt(struct spi_nor *nor,
 			      const struct sfdp_parameter_header *bfpt_header)
 {
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct spi_nor_erase_map *map = &params->erase_map;
 	struct spi_nor_erase_type *erase_type = map->erase_type;
 	struct sfdp_bfpt bfpt;
@@ -661,6 +661,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
  */
 static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
 	switch (settings & SMPT_CMD_ADDRESS_LEN_MASK) {
 	case SMPT_CMD_ADDRESS_LEN_0:
 		return 0;
@@ -670,7 +672,7 @@ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings
 		return 4;
 	case SMPT_CMD_ADDRESS_LEN_USE_CURRENT:
 	default:
-		return nor->params->addr_mode_nbytes;
+		return params->addr_mode_nbytes;
 	}
 }
 
@@ -822,7 +824,8 @@ spi_nor_region_check_overlay(struct spi_nor_erase_region *region,
 static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
 					      const u32 *smpt)
 {
-	struct spi_nor_erase_map *map = &nor->params->erase_map;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	struct spi_nor_erase_map *map = &params->erase_map;
 	struct spi_nor_erase_type *erase = map->erase_type;
 	struct spi_nor_erase_region *region;
 	u64 offset;
@@ -910,6 +913,7 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
 static int spi_nor_parse_smpt(struct spi_nor *nor,
 			      const struct sfdp_parameter_header *smpt_header)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	const u32 *sector_map;
 	u32 *smpt;
 	size_t len;
@@ -940,7 +944,7 @@ static int spi_nor_parse_smpt(struct spi_nor *nor,
 	if (ret)
 		goto out;
 
-	spi_nor_regions_sort_erase_types(&nor->params->erase_map);
+	spi_nor_regions_sort_erase_types(&params->erase_map);
 	/* fall through */
 out:
 	kfree(smpt);
@@ -980,7 +984,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
 		{ 0u /* not used */,		BIT(11) },
 		{ 0u /* not used */,		BIT(12) },
 	};
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct spi_nor_pp_command *params_pp = params->page_programs;
 	struct spi_nor_erase_map *map = &params->erase_map;
 	struct spi_nor_erase_type *erase_type = map->erase_type;
@@ -1143,6 +1147,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
 static int spi_nor_parse_profile1(struct spi_nor *nor,
 				  const struct sfdp_parameter_header *profile1_header)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	u32 *dwords, addr;
 	size_t len;
 	int ret;
@@ -1165,14 +1170,14 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
 
 	 /* Set the Read Status Register dummy cycles and dummy address bytes. */
 	if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_DUMMY)
-		nor->params->rdsr_dummy = 8;
+		params->rdsr_dummy = 8;
 	else
-		nor->params->rdsr_dummy = 4;
+		params->rdsr_dummy = 4;
 
 	if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_ADDR_BYTES)
-		nor->params->rdsr_addr_nbytes = 4;
+		params->rdsr_addr_nbytes = 4;
 	else
-		nor->params->rdsr_addr_nbytes = 0;
+		params->rdsr_addr_nbytes = 0;
 
 	/*
 	 * We don't know what speed the controller is running at. Find the
@@ -1201,8 +1206,8 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
 	dummy = round_up(dummy, 2);
 
 	/* Update the fast read settings. */
-	nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
-	spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR],
+	params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
+	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_8_8_8_DTR],
 				  0, dummy, opcode,
 				  SNOR_PROTO_8_8_8_DTR);
 
@@ -1210,7 +1215,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
 	 * Page Program is "Required Command" in the xSPI Profile 1.0. Update
 	 * the params->hwcaps.mask here.
 	 */
-	nor->params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
+	params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
 
 out:
 	kfree(dwords);
@@ -1231,7 +1236,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
 static int spi_nor_parse_sccr(struct spi_nor *nor,
 			      const struct sfdp_parameter_header *sccr_header)
 {
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	u32 *dwords, addr;
 	size_t len;
 	int ret;
@@ -1282,7 +1287,7 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,
 static int spi_nor_parse_sccr_mc(struct spi_nor *nor,
 				 const struct sfdp_parameter_header *sccr_mc_header)
 {
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	u32 *dwords, addr;
 	u8 i, n_dice;
 	size_t len;
drivers/mtd/spi-nor/spansion.c +34 -23

224 lines not on this page · raw message

drivers/mtd/spi-nor/sst.c +5 -2
index 44d2a546bf17..8d6e50cfef62 100644
@@ -20,10 +20,11 @@ static int sst26vf_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 
 static int sst26vf_nor_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 
 	/* We only support unlocking the entire flash array. */
-	if (ofs != 0 || len != nor->params->size)
+	if (ofs != 0 || len != params->size)
 		return -EINVAL;
 
 	ret = spi_nor_read_cr(nor, nor->bouncebuf);
@@ -51,7 +52,9 @@ static const struct spi_nor_locking_ops sst26vf_nor_locking_ops = {
 
 static int sst26vf_nor_late_init(struct spi_nor *nor)
 {
-	nor->params->locking_ops = &sst26vf_nor_locking_ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->locking_ops = &sst26vf_nor_locking_ops;
 
 	return 0;
 }
drivers/mtd/spi-nor/swp.c +18 -7
index 585813310ee1..78febd6e1a00 100644
@@ -39,7 +39,8 @@ static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
 	 * the flash. For now, we need to have that ugly default.
 	 */
 	unsigned int sector_size = nor->info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE;
-	u64 n_sectors = div_u64(nor->params->size, sector_size);
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	u64 n_sectors = div_u64(params->size, sector_size);
 	u8 mask = spi_nor_get_sr_bp_mask(nor);
 
 	/* Reserved one for "protect none" and one for "protect all". */
@@ -350,11 +351,14 @@ static const struct spi_nor_locking_ops spi_nor_sr_locking_ops = {
 
 void spi_nor_init_default_locking_ops(struct spi_nor *nor)
 {
-	nor->params->locking_ops = &spi_nor_sr_locking_ops;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->locking_ops = &spi_nor_sr_locking_ops;
 }
 
 static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
+	struct spi_nor_flash_parameter *params;
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	int ret;
 
@@ -362,7 +366,8 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	if (ret)
 		return ret;
 
-	ret = nor->params->locking_ops->lock(nor, ofs, len);
+	params = spi_nor_get_params(nor, 0);
+	ret = params->locking_ops->lock(nor, ofs, len);
 
 	spi_nor_unlock_and_unprep(nor);
 	return ret;
@@ -370,6 +375,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
+	struct spi_nor_flash_parameter *params;
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	int ret;
 
@@ -377,7 +383,8 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	if (ret)
 		return ret;
 
-	ret = nor->params->locking_ops->unlock(nor, ofs, len);
+	params = spi_nor_get_params(nor, 0);
+	ret = params->locking_ops->unlock(nor, ofs, len);
 
 	spi_nor_unlock_and_unprep(nor);
 	return ret;
@@ -385,6 +392,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
+	struct spi_nor_flash_parameter *params;
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	int ret;
 
@@ -392,7 +400,8 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	if (ret)
 		return ret;
 
-	ret = nor->params->locking_ops->is_locked(nor, ofs, len);
+	params = spi_nor_get_params(nor, 0);
+	ret = params->locking_ops->is_locked(nor, ofs, len);
 
 	spi_nor_unlock_and_unprep(nor);
 	return ret;
@@ -412,6 +421,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  */
 void spi_nor_try_unlock_all(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	int ret;
 
 	if (!(nor->flags & SNOR_F_HAS_LOCK))
@@ -419,16 +429,17 @@ void spi_nor_try_unlock_all(struct spi_nor *nor)
 
 	dev_dbg(nor->dev, "Unprotecting entire flash array\n");
 
-	ret = spi_nor_unlock(&nor->mtd, 0, nor->params->size);
+	ret = spi_nor_unlock(&nor->mtd, 0, params->size);
 	if (ret)
 		dev_dbg(nor->dev, "Failed to unlock the entire flash memory array\n");
 }
 
 void spi_nor_set_mtd_locking_ops(struct spi_nor *nor)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct mtd_info *mtd = &nor->mtd;
 
-	if (!nor->params->locking_ops)
+	if (!params->locking_ops)
 		return;
 
 	mtd->_lock = spi_nor_lock;
drivers/mtd/spi-nor/winbond.c +1 -1
index 142fb27b2ea9..cdbec66aed91 100644
@@ -303,7 +303,7 @@ static const struct spi_nor_otp_ops winbond_nor_otp_ops = {
 
 static int winbond_nor_late_init(struct spi_nor *nor)
 {
-	struct spi_nor_flash_parameter *params = nor->params;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 
 	if (params->otp.org)
 		params->otp.ops = &winbond_nor_otp_ops;
drivers/mtd/spi-nor/xilinx.c +11 -7
index f99118c691b0..046dfba6b166 100644
@@ -50,7 +50,8 @@ static const struct flash_info xilinx_nor_parts[] = {
  */
 static u32 s3an_nor_convert_addr(struct spi_nor *nor, u32 addr)
 {
-	u32 page_size = nor->params->page_size;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	u32 page_size = params->page_size;
 	u32 offset, page;
 
 	offset = addr % page_size;
@@ -110,6 +111,7 @@ static int xilinx_nor_sr_ready(struct spi_nor *nor)
 static int xilinx_nor_setup(struct spi_nor *nor,
 			    const struct spi_nor_hwcaps *hwcaps)
 {
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	u32 page_size;
 	int ret;
 
@@ -135,14 +137,14 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 	 */
 	if (nor->bouncebuf[0] & XSR_PAGESIZE) {
 		/* Flash in Power of 2 mode */
-		page_size = (nor->params->page_size == 264) ? 256 : 512;
-		nor->params->page_size = page_size;
+		page_size = (params->page_size == 264) ? 256 : 512;
+		params->page_size = page_size;
 		nor->mtd.writebufsize = page_size;
-		nor->params->size = nor->info->size;
+		params->size = nor->info->size;
 		nor->mtd.erasesize = 8 * page_size;
 	} else {
 		/* Flash in Default addressing mode */
-		nor->params->convert_addr = s3an_nor_convert_addr;
+		params->convert_addr = s3an_nor_convert_addr;
 		nor->mtd.erasesize = nor->info->sector_size;
 	}
 
@@ -151,8 +153,10 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 
 static int xilinx_nor_late_init(struct spi_nor *nor)
 {
-	nor->params->setup = xilinx_nor_setup;
-	nor->params->ready = xilinx_nor_sr_ready;
+	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+	params->setup = xilinx_nor_setup;
+	params->ready = xilinx_nor_sr_ready;
 
 	return 0;
 }
include/linux/mtd/spi-nor.h +10 -0
index cdcfe0fd2e7d..59909e7d6f53 100644
@@ -433,6 +433,16 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
 	return mtd_get_of_node(&nor->mtd);
 }
 
+static inline struct spi_nor_flash_parameter *spi_nor_get_params(const struct spi_nor *nor, u8 idx)
+{
+	return nor->params;
+}
+
+static inline void spi_nor_set_params(struct spi_nor *nor, u8 idx,
+				      struct spi_nor_flash_parameter *params)
+{
+	nor->params = params;
+}
 /**
  * spi_nor_scan() - scan the SPI NOR
  * @nor:	the spi_nor structure
Signature · 1 line
2.17.1
#23 lore raw

PATCH v11 6/10 mtd: spi-nor: Move write enable inside specific write & erase APIs

In reply to Amit Kumar Mahapatra

In most of the register write operations the spi_nor_write_enable is called from within that API from where spi_mem APIs are called. Follwoing the same trend move the write enable API from spi_nor_write & spi_nor_erase APIs to the respective write & erase APIs.

---
 drivers/mtd/spi-nor/core.c | 40 ++++++++++++++------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)
drivers/mtd/spi-nor/core.c +15 -25
index 72c80d8b5858..93ae69b7ff83 100644
@@ -301,6 +301,12 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
 ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
 			   const u8 *buf)
 {
+	int ret;
+
+	ret = spi_nor_write_enable(nor);
+	if (ret)
+		return ret;
+
 	if (nor->spimem)
 		return spi_nor_spimem_write_data(nor, to, len, buf);
 
@@ -1074,6 +1080,10 @@ static int spi_nor_erase_chip(struct spi_nor *nor)
 
 	dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd.size >> 10));
 
+	ret = spi_nor_write_enable(nor);
+	if (ret)
+		return ret;
+
 	if (nor->spimem) {
 		struct spi_mem_op op = SPI_NOR_CHIP_ERASE_OP;
 
@@ -1481,10 +1491,14 @@ static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
  */
 int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 {
-	int i;
+	int i, ret;
 
 	addr = spi_nor_convert_addr(nor, addr);
 
+	ret = spi_nor_write_enable(nor);
+	if (ret)
+		return ret;
+
 	if (nor->spimem) {
 		struct spi_mem_op op =
 			SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode,
@@ -1777,12 +1791,6 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)
 			if (ret)
 				goto destroy_erase_cmd_list;
 
-			ret = spi_nor_write_enable(nor);
-			if (ret) {
-				spi_nor_unlock_device(nor);
-				goto destroy_erase_cmd_list;
-			}
-
 			ret = spi_nor_erase_sector(nor, addr);
 			spi_nor_unlock_device(nor);
 			if (ret)
@@ -1841,12 +1849,6 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		if (ret)
 			goto erase_err;
 
-		ret = spi_nor_write_enable(nor);
-		if (ret) {
-			spi_nor_unlock_device(nor);
-			goto erase_err;
-		}
-
 		ret = spi_nor_erase_chip(nor);
 		spi_nor_unlock_device(nor);
 		if (ret)
@@ -1877,12 +1879,6 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 			if (ret)
 				goto erase_err;
 
-			ret = spi_nor_write_enable(nor);
-			if (ret) {
-				spi_nor_unlock_device(nor);
-				goto erase_err;
-			}
-
 			ret = spi_nor_erase_sector(nor, addr);
 			spi_nor_unlock_device(nor);
 			if (ret)
@@ -2177,12 +2173,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		if (ret)
 			goto write_err;
 
-		ret = spi_nor_write_enable(nor);
-		if (ret) {
-			spi_nor_unlock_device(nor);
-			goto write_err;
-		}
-
 		ret = spi_nor_write_data(nor, addr, page_remain, buf + i);
 		spi_nor_unlock_device(nor);
 		if (ret < 0)
Signature · 1 line
2.17.1
#24 lore raw

PATCH v11 7/10 mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked configuration.

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +225 -47
index 93ae69b7ff83..e990be7c7eb6 100644
@@ -1821,13 +1821,18 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)
 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;
+	struct spi_nor_flash_parameter *params;
+	u32 addr, len, offset, cur_cs_num = 0;
 	uint32_t rem;
 	int ret;
+	u64 sz;
 
 	dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
 			(long long)instr->len);
 
+	params = spi_nor_get_params(nor, 0);
+	sz = params->size;
+
 	if (spi_nor_has_uniform_erase(nor)) {
 		div_u64_rem(instr->len, mtd->erasesize, &rem);
 		if (rem)
@@ -1849,23 +1854,27 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		if (ret)
 			goto erase_err;
 
-		ret = spi_nor_erase_chip(nor);
-		spi_nor_unlock_device(nor);
-		if (ret)
-			goto erase_err;
+		while (cur_cs_num < nor->num_flash) {
+			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+			ret = spi_nor_erase_chip(nor);
+			spi_nor_unlock_device(nor);
+			if (ret)
+				goto erase_err;
 
-		/*
-		 * Scale the timeout linearly with the size of the flash, with
-		 * a minimum calibrated to an old 2MB flash. We could try to
-		 * pull these from CFI/SFDP, but these values should be good
-		 * enough for now.
-		 */
-		timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
-			      CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
-			      (unsigned long)(mtd->size / SZ_2M));
-		ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
-		if (ret)
-			goto erase_err;
+			/*
+			 * Scale the timeout linearly with the size of the flash, with
+			 * a minimum calibrated to an old 2MB flash. We could try to
+			 * pull these from CFI/SFDP, but these values should be good
+			 * enough for now.
+			 */
+			timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
+				      CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
+				      (unsigned long)(params->size / SZ_2M));
+			ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
+			if (ret)
+				goto erase_err;
+			cur_cs_num++;
+		}
 
 	/* REVISIT in some cases we could speed up erasing large regions
 	 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
@@ -1874,12 +1883,26 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 
 	/* "sector"-at-a-time erase */
 	} else if (spi_nor_has_uniform_erase(nor)) {
+		/* Determine the flash from which the operation need to start */
+		while ((cur_cs_num < nor->num_flash) && (addr > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
+
 		while (len) {
 			ret = spi_nor_lock_device(nor);
 			if (ret)
 				goto erase_err;
 
-			ret = spi_nor_erase_sector(nor, addr);
+			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+			offset = addr;
+			if (nor->flags & SNOR_F_HAS_STACKED) {
+				params = spi_nor_get_params(nor, cur_cs_num);
+				offset -= (sz - params->size);
+			}
+
+			ret = spi_nor_erase_sector(nor, offset);
 			spi_nor_unlock_device(nor);
 			if (ret)
 				goto erase_err;
@@ -1890,13 +1913,45 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 
 			addr += mtd->erasesize;
 			len -= mtd->erasesize;
+
+			/*
+			 * Flash cross over condition in stacked mode.
+			 */
+			if ((nor->flags & SNOR_F_HAS_STACKED) && (addr > sz - 1)) {
+				cur_cs_num++;
+				params = spi_nor_get_params(nor, cur_cs_num);
+				sz += params->size;
+			}
 		}
 
 	/* erase multiple sectors */
 	} else {
-		ret = spi_nor_erase_multi_sectors(nor, addr, len);
-		if (ret)
-			goto erase_err;
+		u64 erase_len = 0;
+
+		/* Determine the flash from which the operation need to start */
+		while ((cur_cs_num < nor->num_flash) && (addr > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
+		/* perform multi sector erase onec per Flash*/
+		while (len) {
+			erase_len = (len > (sz - addr)) ? (sz - addr) : len;
+			offset = addr;
+			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+			if (nor->flags & SNOR_F_HAS_STACKED) {
+				params = spi_nor_get_params(nor, cur_cs_num);
+				offset -= (sz - params->size);
+			}
+			ret = spi_nor_erase_multi_sectors(nor, offset, erase_len);
+			if (ret)
+				goto erase_err;
+			len -= erase_len;
+			addr += erase_len;
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
 	}
 
 	ret = spi_nor_write_disable(nor);
@@ -2087,9 +2142,11 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 			size_t *retlen, u_char *buf)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
+	struct spi_nor_flash_parameter *params;
+	ssize_t ret, read_len, len_lock =  len;
 	loff_t from_lock = from;
-	size_t len_lock = len;
-	ssize_t ret;
+	u32 cur_cs_num = 0;
+	u64 sz;
 
 	dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
 
@@ -2097,9 +2154,23 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	if (ret)
 		return ret;
 
+	params = spi_nor_get_params(nor, 0);
+	sz = params->size;
+
+	/* Determine the flash from which the operation need to start */
+	while ((cur_cs_num < nor->num_flash) && (from > sz - 1)) {
+		cur_cs_num++;
+		params = spi_nor_get_params(nor, cur_cs_num);
+		sz += params->size;
+	}
 	while (len) {
 		loff_t addr = from;
 
+		nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+		read_len = (len > (sz - addr)) ? (sz - addr) : len;
+		params = spi_nor_get_params(nor, cur_cs_num);
+		addr -= (sz - params->size);
+
 		addr = spi_nor_convert_addr(nor, addr);
 
 		ret = spi_nor_read_data(nor, addr, len, buf);
@@ -2111,11 +2182,22 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 		if (ret < 0)
 			goto read_err;
 
-		WARN_ON(ret > len);
+		WARN_ON(ret > read_len);
 		*retlen += ret;
 		buf += ret;
 		from += ret;
 		len -= ret;
+
+		/*
+		 * Flash cross over condition in stacked mode.
+		 *
+		 */
+		if ((nor->flags & SNOR_F_HAS_STACKED) && (from > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
+
 	}
 	ret = 0;
 
@@ -2136,8 +2218,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);
 	struct spi_nor_flash_parameter *params;
 	size_t page_offset, page_remain, i;
+	u32 page_size, cur_cs_num = 0;
 	ssize_t ret;
-	u32 page_size;
+	u64 sz;
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
@@ -2147,6 +2230,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 	params = spi_nor_get_params(nor, 0);
 	page_size = params->page_size;
+	sz = params->size;
+
+	/* Determine the flash from which the operation need to start */
+	while ((cur_cs_num < nor->num_flash) && (to > sz - 1)) {
+		cur_cs_num++;
+		params = spi_nor_get_params(nor, cur_cs_num);
+		sz += params->size;
+	}
 
 	for (i = 0; i < len; ) {
 		ssize_t written;
@@ -2167,6 +2258,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* the size of data remaining on the first page */
 		page_remain = min_t(size_t, page_size - page_offset, len - i);
 
+		nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+		params = spi_nor_get_params(nor, cur_cs_num);
+		addr -= (sz - params->size);
+
 		addr = spi_nor_convert_addr(nor, addr);
 
 		ret = spi_nor_lock_device(nor);
@@ -2184,6 +2279,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 			goto write_err;
 		*retlen += written;
 		i += written;
+
+		/*
+		 * Flash cross over condition in stacked mode.
+		 */
+		if ((nor->flags & SNOR_F_HAS_STACKED) && ((to + i) > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
 	}
 
 write_err:
@@ -2297,8 +2401,6 @@ int spi_nor_hwcaps_pp2cmd(u32 hwcaps)
 static int spi_nor_spimem_check_op(struct spi_nor *nor,
 				   struct spi_mem_op *op)
 {
-	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
-
 	/*
 	 * First test with 4 address bytes. The opcode itself might
 	 * be a 3B addressing opcode but we don't care, because
@@ -2307,7 +2409,7 @@ static int spi_nor_spimem_check_op(struct spi_nor *nor,
 	 */
 	op->addr.nbytes = 4;
 	if (!spi_mem_supports_op(nor->spimem, op)) {
-		if (params->size > SZ_16M)
+		if (nor->mtd.size > SZ_16M)
 			return -EOPNOTSUPP;
 
 		/* If flash size <= 16MB, 3 address bytes are sufficient */
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor)
 static int spi_nor_late_init_params(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) {
@@ -2937,6 +3042,44 @@ static int spi_nor_late_init_params(struct spi_nor *nor)
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params->n_banks);
 
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same make.
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories", idx, &flash_size[idx]);
+		if (rc)
+			break;
+		idx++;
+		if (!(nor->flags & SNOR_F_HAS_STACKED))
+			nor->flags |= SNOR_F_HAS_STACKED;
+
+		nor->num_flash++;
+	}
+
+	/*
+	 * By default one flash device should be connected
+	 * so, nor->num_flash is 1.
+	 */
+	if (!nor->num_flash)
+		nor->num_flash = 1;
+
+	if (nor->flags & SNOR_F_HAS_STACKED) {
+		for (idx = 1; idx < nor->num_flash; idx++) {
+			params = spi_nor_get_params(nor, idx);
+			params = devm_kzalloc(nor->dev, sizeof(*params), GFP_KERNEL);
+			if (params) {
+				memcpy(params, spi_nor_get_params(nor, 0), sizeof(*params));
+				params->size = flash_size[idx];
+				spi_nor_set_params(nor, idx, params);
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -3145,16 +3288,28 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable)
  */
 static int spi_nor_quad_enable(struct spi_nor *nor)
 {
-	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+	struct spi_nor_flash_parameter *params;
+	int err, idx;
 
-	if (!params->quad_enable)
-		return 0;
+	for (idx = 0; idx < nor->num_flash; idx++) {
+		params = spi_nor_get_params(nor, idx);
+		if (!params->quad_enable)
+			return 0;
 
-	if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 ||
-	      spi_nor_get_protocol_width(nor->write_proto) == 4))
-		return 0;
+		if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 ||
+		      spi_nor_get_protocol_width(nor->write_proto) == 4))
+			return 0;
+		/*
+		 * Set the appropriate CS index before
+		 * issuing the command.
+		 */
+		nor->spimem->spi->cs_index_mask = 0x01 << idx;
 
-	return params->quad_enable(nor);
+		err = params->quad_enable(nor);
+		if (err)
+			return err;
+	}
+	return err;
 }
 
 /**
@@ -3186,7 +3341,7 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
 
 static int spi_nor_init(struct spi_nor *nor)
 {
-	int err;
+	int err, idx;
 
 	err = spi_nor_set_octal_dtr(nor, true);
 	if (err) {
@@ -3227,9 +3382,16 @@ static int spi_nor_init(struct spi_nor *nor)
 		 */
 		WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET,
 			  "enabling reset hack; may not recover from unexpected reboots\n");
-		err = spi_nor_set_4byte_addr_mode(nor, true);
-		if (err)
-			return err;
+		for (idx = 0; idx < nor->num_flash; idx++) {
+			/*
+			 * Select the appropriate CS index before
+			 * issuing the command.
+			 */
+			nor->spimem->spi->cs_index_mask = 0x01 << idx;
+			err = spi_nor_set_4byte_addr_mode(nor, true);
+			if (err)
+				return err;
+		}
 	}
 
 	return 0;
@@ -3344,18 +3506,28 @@ static void spi_nor_put_device(struct mtd_info *mtd)
 static void spi_nor_restore(struct spi_nor *nor)
 {
 	int ret;
+	int idx;
 
 	/* restore the addressing mode */
 	if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
 	    nor->flags & SNOR_F_BROKEN_RESET) {
-		ret = spi_nor_set_4byte_addr_mode(nor, false);
-		if (ret)
+		for (idx = 0; idx < nor->num_flash; idx++) {
 			/*
-			 * Do not stop the execution in the hope that the flash
-			 * will default to the 3-byte address mode after the
-			 * software reset.
+			 * Select the appropriate CS index before
+			 * issuing the command.
 			 */
-			dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret);
+			nor->spimem->spi->cs_index_mask = 1 << idx;
+			ret = spi_nor_set_4byte_addr_mode(nor, false);
+			if (ret)
+				/*
+				 * Do not stop the execution in the hope that the flash
+				 * will default to the 3-byte address mode after the
+				 * software reset.
+				 */
+				dev_err(nor->dev,
+					"Failed to exit 4-byte address mode, err = %d\n",
+					ret);
+		}
 	}
 
 	if (nor->flags & SNOR_F_SOFT_RESET)
@@ -3422,6 +3594,8 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
 	struct mtd_info *mtd = &nor->mtd;
 	struct device *dev = nor->dev;
+	u64 total_sz = 0;
+	int idx;
 
 	spi_nor_set_mtd_locking_ops(nor);
 	spi_nor_set_mtd_otp_ops(nor);
@@ -3440,7 +3614,11 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 		mtd->_erase = spi_nor_erase;
 	mtd->writesize = params->writesize;
 	mtd->writebufsize = params->page_size;
-	mtd->size = params->size;
+	for (idx = 0; idx < nor->num_flash; idx++) {
+		params = spi_nor_get_params(nor, idx);
+		total_sz += params->size;
+	}
+	mtd->size = total_sz;
 	mtd->_read = spi_nor_read;
 	/* Might be already set by some SST flashes. */
 	if (!mtd->_write)
drivers/mtd/spi-nor/core.h +4 -0
index 93cd2fc3606d..b2997eca7551 100644
@@ -18,6 +18,9 @@
 #define SPI_NOR_DEFAULT_N_BANKS 1
 #define SPI_NOR_DEFAULT_SECTOR_SIZE SZ_64K
 
+/* In single configuration enable CS0 */
+#define SPI_NOR_ENABLE_CS0     BIT(0)
+
 /* Standard SPI NOR flash operations. */
 #define SPI_NOR_READID_OP(naddr, ndummy, buf, len)			\
 	SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0),			\
@@ -140,6 +143,7 @@ enum spi_nor_option_flags {
 	SNOR_F_RWW		= BIT(14),
 	SNOR_F_ECC		= BIT(15),
 	SNOR_F_NO_WP		= BIT(16),
+	SNOR_F_HAS_STACKED      = BIT(17),
 };
 
 struct spi_nor_read_command {
include/linux/mtd/spi-nor.h +11 -4
index 59909e7d6f53..9d72b0bbab94 100644
@@ -127,6 +127,12 @@
 #define SR2_LB3			BIT(5)	/* Security Register Lock Bit 3 */
 #define SR2_QUAD_EN_BIT7	BIT(7)
 
+/*
+ * Maximum number of flashes that can be connected
+ * in stacked/parallel configuration
+ */
+#define	SNOR_FLASH_CNT_MAX	4
+
 /* Supported SPI protocols */
 #define SNOR_PROTO_INST_MASK	GENMASK(23, 16)
 #define SNOR_PROTO_INST_SHIFT	16
@@ -378,6 +384,7 @@ struct spi_nor_flash_parameter;
  *                      hooks, or dynamically when parsing the SFDP tables.
  * @dirmap:		pointers to struct spi_mem_dirmap_desc for reads/writes.
  * @priv:		pointer to the private data
+ * @num_flash		number of flashes connected in parallel or stacked mode
  */
 struct spi_nor {
 	struct mtd_info		mtd;
@@ -412,13 +419,13 @@ struct spi_nor {
 
 	const struct spi_nor_controller_ops *controller_ops;
 
-	struct spi_nor_flash_parameter *params;
+	struct spi_nor_flash_parameter *params[SNOR_FLASH_CNT_MAX];
 
 	struct {
 		struct spi_mem_dirmap_desc *rdesc;
 		struct spi_mem_dirmap_desc *wdesc;
 	} dirmap;
-
+	u32			num_flash;
 	void *priv;
 };
 
@@ -435,13 +442,13 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
 
 static inline struct spi_nor_flash_parameter *spi_nor_get_params(const struct spi_nor *nor, u8 idx)
 {
-	return nor->params;
+	return nor->params[idx];
 }
 
 static inline void spi_nor_set_params(struct spi_nor *nor, u8 idx,
 				      struct spi_nor_flash_parameter *params)
 {
-	nor->params = params;
+	nor->params[idx] = params;
 }
 /**
  * spi_nor_scan() - scan the SPI NOR
Signature · 1 line
2.17.1
#25 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 9 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked configuration.

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not, wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 20 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 16 lines
drivers/mtd/spi-nor/core.c +4 -1
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor)
 static int spi_nor_late_init_params(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) {
@@ -2937,6 +3042,44 @@ static int spi_nor_late_init_params(struct spi_nor *nor)
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params->n_banks);
 

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor) · line 3054

Quoted 10 lines
drivers/mtd/spi-nor/core.c +10 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same make.
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories", idx, &flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Cheers,
ta

#26 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 56 lines · Tudor Ambarus

Hi, Amit,

Quoted 9 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked configuration.

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not, wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 20 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 16 lines
drivers/mtd/spi-nor/core.c +4 -1
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor)
 static int spi_nor_late_init_params(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) {
@@ -2937,6 +3042,44 @@ static int spi_nor_late_init_params(struct spi_nor *nor)
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params->n_banks);
 
Quoted 10 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor) · line 3054

Quoted 10 lines
drivers/mtd/spi-nor/core.c +10 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same make.
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories", idx, &flash_size[idx]);

also, it's not clear to me why you read this property multiple times. Have you sent a device tree patch somewhere? It will help me understand what you're trying to achieve.

Quoted 7 lines

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Cheers,
ta

#27 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Tudor,

Quoted 94 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:14 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 7 lines · Tudor Ambarus

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

configuration.

Quoted 21 lines
Quoted 5 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not, wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 11 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

Signed-off-by Amit Kumar Mahapatra <amit.kumar-

[email protected]>

Quoted 13 lines
Quoted 10 lines
---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 13 lines

drivers/mtd/spi-nor/core.c

Quoted 11 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

Quoted 1 line
Quoted 4 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same

make.

Quoted 6 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 5 lines
Quoted 1 line
Quoted 1 line

+&flash_size[idx]);

also, it's not clear to me why you read this property multiple times. Have you sent a device tree patch somewhere? It will help me understand what you're trying to achieve.

Miquel submitted the device tree patch; here is the series.
https://lore.kernel.org/all/[email protected]/

Regards,
Amit

Quoted 8 lines
Quoted 8 lines

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Cheers,
ta

#28 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi!

Quoted 95 lines
Quoted 95 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:14 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 7 lines · Tudor Ambarus

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

configuration.

Quoted 21 lines
Quoted 5 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not, wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 11 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

Signed-off-by Amit Kumar Mahapatra <amit.kumar-

[email protected]>

Quoted 13 lines
Quoted 10 lines
---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 13 lines

drivers/mtd/spi-nor/core.c

Quoted 11 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

Quoted 1 line
Quoted 4 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same

make.

Quoted 6 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

+&flash_size[idx]);

also, it's not clear to me why you read this property multiple times. Have you sent a device tree patch somewhere? It will help me understand what you're trying to achieve.

Miquel submitted the device tree patch; here is the series.
https://lore.kernel.org/all/[email protected]/

oh, yes, I remember seeing this on the ml, but I couldn't allocate time to review it. Looking at:
https://lore.kernel.org/all/[email protected]/

Flash size is not necessary for SPI NORs, as it can be discovered via SFDP. And spi-max-frequency should have been specified for all flashes, as I expect it can differ. At least so that the controller chooses the minimum frequency from all the max (if it can't operate the stacks at different frequencies).

Cheers,
ta

#29 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Tudor Ambarus

Hello Tudor,

Quoted 25 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:00 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

Quoted 8 lines

configuration.

Quoted 5 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not,

No, according to the current implementation, in stacked mode, both flashes must be of the same make.

Quoted 2 lines

wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Yes, that is accurate. In alignment with our current stacked support use case we can have an array of flash sizes instead.
The primary purpose of having an array of params struct was to facilitate potential future extensions, allowing the addition of stacked support for different flashes

Quoted 55 lines
Quoted 22 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 13 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same

make.

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 5 lines
Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you anticipate that SPI-NOR should throw an error if the second or any subsequent flash within the stacked connection is different? Or would you prefer it to print a warning and operate in single mode (i.e., only the first flash)?

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#30 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi!

Quoted 38 lines
Quoted 26 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:00 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

Quoted 8 lines

configuration.

Quoted 5 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not,

No, according to the current implementation, in stacked mode, both flashes must be of the same make.

Quoted 9 lines
Quoted 2 lines

wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Yes, that is accurate. In alignment with our current stacked support use case we can have an array of flash sizes instead.
The primary purpose of having an array of params struct was to facilitate potential future extensions, allowing the addition of stacked support for different flashes

right. Don't do this change yet, let's decide on the overall architecture first.

Quoted 57 lines
Quoted 57 lines
Quoted 22 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 13 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
 
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of same

make.

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 1 line

+&flash_size[idx]);

Quoted 8 lines
Quoted 3 lines

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

I'm wondering whether we can add a layer on top of the flash type to handle the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Is the datasheet of the controller public?

Quoted 4 lines

anticipate that SPI-NOR should throw an error if the second or any subsequent flash within the stacked connection is different? Or would you prefer it to print a warning and operate in single mode (i.e., only the first flash)?

Both options are fine, but I haven't yet decided on the overall architecture.

Cheers,
ta

#31 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 22 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Monday, December 11, 2023 9:03 AM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 4 lines
Quoted 1 line · Amit Kumar

Hello Tudor,

Hi!

Hello Tudor,

Quoted 43 lines
Quoted 43 lines
Quoted 29 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:00 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

configuration.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not,

No, according to the current implementation, in stacked mode, both flashes must be of the same make.

Quoted 2 lines

wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 8 lines
Quoted 6 lines

Yes, that is accurate. In alignment with our current stacked support use case we can have an array of flash sizes instead.
The primary purpose of having an array of params struct was to facilitate potential future extensions, allowing the addition of stacked support for different flashes

right. Don't do this change yet, let's decide on the overall architecture first.

Sure.

Quoted 65 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

Quoted 1 line
Quoted 1 line
Quoted 1 line
Signed-off-by Amit Kumar Mahapatra <amit.kumar-

[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-----

--

Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 6 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi-nor/core.c

Quoted 5 lines
drivers/mtd/spi-nor/core.c +0 -0
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

Quoted 20 lines
Quoted 19 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +5 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of
+same

make.

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Quoted 7 lines
Quoted 5 lines

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

I'm wondering whether we can add a layer on top of the flash type to handle

When you mention "on top," are you referring to incorporating it into the MTD layer? Initially, Miquel had submitted this patch to address stacked/parallel handling in the MTD layer.
https://lore.kernel.org/linux-mtd/20200114191052.0a16d116@xps13/t/
However, the Device Tree bindings were initially not accepted. Following a series of discussions, the below bindings were eventually merged.
https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Is the datasheet of the controller public?

Yes, https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Quad-SPI-Controller

Quoted 7 lines
Quoted 5 lines

anticipate that SPI-NOR should throw an error if the second or any subsequent flash within the stacked connection is different? Or would you prefer it to print a warning and operate in single mode (i.e., only the first flash)?

Both options are fine, but I haven't yet decided on the overall architecture.

Ok.

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#32 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 22 lines · Amit Kumar
Quoted 22 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Monday, December 11, 2023 9:03 AM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 7 lines
Quoted 4 lines · Amit Kumar
Quoted 1 line

Hello Tudor,

Hi!

Hello Tudor,

Hi!

Quoted 124 lines
Quoted 43 lines
Quoted 43 lines
Quoted 29 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:00 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 4 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

configuration.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not,

No, according to the current implementation, in stacked mode, both flashes must be of the same make.

Quoted 2 lines

wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 8 lines
Quoted 6 lines

Yes, that is accurate. In alignment with our current stacked support use case we can have an array of flash sizes instead.
The primary purpose of having an array of params struct was to facilitate potential future extensions, allowing the addition of stacked support for different flashes

right. Don't do this change yet, let's decide on the overall architecture first.

Sure.

Quoted 71 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

Quoted 1 line
Quoted 1 line
Quoted 1 line
Signed-off-by Amit Kumar Mahapatra <amit.kumar-

[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
---
 drivers/mtd/spi-nor/core.c  | 272 +++++++++++++++++++++++++++++-----

--

Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
drivers/mtd/spi-nor/core.c +0 -0
index 93ae69b7ff83..e990be7c7eb6 100644

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 6 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi-nor/core.c

Quoted 5 lines
drivers/mtd/spi-nor/core.c +0 -0
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44 @@

static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

Quoted 25 lines
Quoted 14 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +5 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be of
+same

make.

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 6 lines
drivers/mtd/spi-nor/core.c +6 -0
+	 * Except the flash size all other properties are identical for all the
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be identical.
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-memories",

idx,

Quoted 5 lines
Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

Quoted 4 lines
Quoted 1 line

I'm wondering whether we can add a layer on top of the flash type to handle

When you mention "on top," are you referring to incorporating it into the MTD layer? Initially, Miquel had submitted this patch to address

I mean something above SPI MEM flashes, be it NOR, NANDs or whatever. Instead of treating the stacked flashes as a monolithic device and treat in SPI NOR some array of flashes, to have a layer above which probes the SPI MEM flash driver for each stacked flash. In your case SPI NOR would be probed twice, as you use 2 SPI NOR flashes.

Quoted 3 lines

stacked/parallel handling in the MTD layer.
https://lore.kernel.org/linux-mtd/20200114191052.0a16d116@xps13/t/
However, the Device Tree bindings were initially not accepted.

Okay, thanks for the pointer. I'll take a look.

Quoted 3 lines

Following a series of discussions, the below bindings were eventually merged.
https://lore.kernel.org/all/[email protected]/

I saw, thanks.

Quoted 9 lines
Quoted 6 lines

the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Is the datasheet of the controller public?

Yes, https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Quad-SPI-Controller

Wonderful, I'll take a look. I see two clocks there. Does this mean that the stacked flashes can be operated at different frequencies? Do you know if we can combine a SPI NOR with a SPI NAND in stacked configuration?

I need to study this a bit. I'll try to involve Michael and Pratyush too.

Cheers,
ta

#33 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 46 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Monday, December 11, 2023 3:05 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 23 lines · Amit Kumar
Quoted 23 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Monday, December 11, 2023 9:03 AM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

On 12/8/23 17:05, Mahapatra, Amit Kumar wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Hello Tudor,

Hi!

Hello Tudor,

Hi!

Hello Tudor,

Quoted 166 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Wednesday, December 6, 2023 8:00 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 94 lines
Quoted 36 lines
Quoted 36 lines
Quoted 22 lines

[email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD-
Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi, Amit,

Quoted 5 lines · Amit Kumar Mahapatra

Each flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked

configuration.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Do you plan to add support for different flashes in stacked mode? If not,

No, according to the current implementation, in stacked mode, both flashes must be of the same make.

Quoted 2 lines

wouldn't it be simpler to have just an array of flash sizes instead of duplicating the entire params struct?

Quoted 8 lines
Quoted 6 lines

Yes, that is accurate. In alignment with our current stacked support use case we can have an array of flash sizes instead.
The primary purpose of having an array of params struct was to facilitate potential future extensions, allowing the addition of stacked support for different flashes

right. Don't do this change yet, let's decide on the overall architecture first.

Sure.

Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].

Quoted 1 line
Quoted 1 line
Quoted 1 line
Signed-off-by Amit Kumar Mahapatra <amit.kumar-

[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
---
 drivers/mtd/spi-nor/core.c  | 272

+++++++++++++++++++++++++++++-----

--

Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi-nor/core.c index 93ae69b7ff83..e990be7c7eb6 100644

drivers/mtd/spi-nor/core.c +0 -0

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 6 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi-nor/core.c

Quoted 5 lines
drivers/mtd/spi-nor/core.c +0 -0
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44

@@ static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

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

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be

of

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+same

make.

drivers/mtd/spi-nor/core.c

Quoted 1 line
drivers/mtd/spi-nor/core.c +1 -0
+	 * Except the flash size all other properties are identical for all

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mtd/spi-nor/core.c

Quoted 2 lines
drivers/mtd/spi-nor/core.c +2 -0
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be

identical.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/mtd/spi-nor/core.c static int spi_nor_late_init_params(struct spi_nor *nor)

Quoted 3 lines
drivers/mtd/spi-nor/core.c +3 -0
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-

memories",

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

idx,

Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

Quoted 5 lines
Quoted 2 lines

I'm wondering whether we can add a layer on top of the flash type to handle

When you mention "on top," are you referring to incorporating it into the MTD layer? Initially, Miquel had submitted this patch to address

I mean something above SPI MEM flashes, be it NOR, NANDs or whatever. Instead of treating the stacked flashes as a monolithic device and treat in SPI NOR some array of flashes, to have a layer above which probes the SPI MEM flash driver for each stacked flash. In your case SPI NOR would be probed twice, as you use 2 SPI NOR flashes.

Quoted 3 lines

stacked/parallel handling in the MTD layer.
https://lore.kernel.org/linux-mtd/20200114191052.0a16d116@xps13/t/
However, the Device Tree bindings were initially not accepted.

Okay, thanks for the pointer. I'll take a look.

Quoted 4 lines

Following a series of discussions, the below bindings were eventually merged.
https://lore.kernel.org/all/20220126112608.955728-4-miquel.raynal@boot
lin.com/

I saw, thanks.

Quoted 7 lines
Quoted 6 lines

the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Is the datasheet of the controller public?

Quoted 7 lines
Quoted 4 lines

Yes,
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Quad-SPI-Control
ler

Wonderful, I'll take a look. I see two clocks there. Does this mean that the stacked flashes can be operated at different frequencies? Do you know if we

In stacked configuration, both flashes utilize a common clock (single clock line). In a parallel setup, the flashes share the same clock but have distinct clock lines. Please refer the diagrams in the sections below for reference.
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Interface-Diagrams

Quoted 1 line

can combine a SPI NOR with a SPI NAND in stacked configuration?

No, Xilinx/AMD QSPI controllers doesn't support this configuration.

Regards,
Amit

Quoted 5 lines

I need to study this a bit. I'll try to involve Michael and Pratyush too.

Cheers,
ta

#34 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

On 12/11/23 13:37, Mahapatra, Amit Kumar wrote:

Hi!

cut

Quoted 74 lines
Quoted 74 lines
Quoted 33 lines
Quoted 33 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
 drivers/mtd/spi-nor/core.c  | 272

+++++++++++++++++++++++++++++-----

--

Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi-nor/core.c index 93ae69b7ff83..e990be7c7eb6 100644

drivers/mtd/spi-nor/core.c +0 -0

cut

Quoted 4 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void spi_nor_init_fixup_flags(struct

spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor *nor) {
struct spi_nor_flash_parameter *params = spi_nor_get_params(nor,

0);

Quoted 6 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi-nor/core.c

Quoted 5 lines
drivers/mtd/spi-nor/core.c +0 -0
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6 +3042,44

@@ static int spi_nor_late_init_params(struct spi_nor *nor)

drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size, params-

n_banks);

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

drivers/mtd/spi-nor/core.c

Quoted 4 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be

of

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+same

make.

drivers/mtd/spi-nor/core.c

Quoted 1 line
drivers/mtd/spi-nor/core.c +1 -0
+	 * Except the flash size all other properties are identical for all

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mtd/spi-nor/core.c

Quoted 2 lines
drivers/mtd/spi-nor/core.c +2 -0
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be

identical.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/mtd/spi-nor/core.c

Quoted 3 lines
drivers/mtd/spi-nor/core.c +3 -0
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-

memories",

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

idx,

Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

Quoted 5 lines
Quoted 2 lines

I'm wondering whether we can add a layer on top of the flash type to handle

When you mention "on top," are you referring to incorporating it into the MTD layer? Initially, Miquel had submitted this patch to address

I mean something above SPI MEM flashes, be it NOR, NANDs or whatever. Instead of treating the stacked flashes as a monolithic device and treat in SPI NOR some array of flashes, to have a layer above which probes the SPI MEM flash driver for each stacked flash. In your case SPI NOR would be probed twice, as you use 2 SPI NOR flashes.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

stacked/parallel handling in the MTD layer.
https://lore.kernel.org/linux-mtd/20200114191052.0a16d116@xps13/t/
However, the Device Tree bindings were initially not accepted.

Okay, thanks for the pointer. I'll take a look.

haven't yet read the thread from above, but I skimmed over the AMD controller datasheet.

Quoted 20 lines
Quoted 20 lines
Quoted 5 lines

Following a series of discussions, the below bindings were eventually merged.
https://lore.kernel.org/all/20220126112608.955728-4-miquel.raynal@boot
lin.com/

I saw, thanks.

Quoted 11 lines
Quoted 6 lines

the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Is the datasheet of the controller public?

Yes,
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Quad-SPI-Control
ler

Quoted 8 lines
Quoted 2 lines

Wonderful, I'll take a look. I see two clocks there. Does this mean that the stacked flashes can be operated at different frequencies? Do you know if we

In stacked configuration, both flashes utilize a common clock (single clock line). In a parallel setup, the flashes share the same clock but have distinct clock lines. Please refer the diagrams in the sections below for reference.
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Interface-Diagrams

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

Quoted 4 lines
Quoted 1 line

can combine a SPI NOR with a SPI NAND in stacked configuration?

No, Xilinx/AMD QSPI controllers doesn't support this configuration.

2 SPI NANDs shall work with the AMD controller, right?

I skimmed over the QSPI controller datasheet and wondered why one would get complicated with 2 Quad Flashes when we have Octal. But then I saw that the same SoC can configure an Octal controller (the Octal and Quad controllers seems mutual exclusive) and that the Octal one can operate 2 octal flashes in stacked mode :).

Cheers,
ta

#35 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Tudor,

Quoted 148 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Tuesday, December 12, 2023 8:33 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

On 12/11/23 13:37, Mahapatra, Amit Kumar wrote:

Hi!

cut

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
 drivers/mtd/spi-nor/core.c  | 272

+++++++++++++++++++++++++++++-----

--

Quoted 25 lines
Quoted 25 lines
Quoted 9 lines
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  15 +-
 3 files changed, 240 insertions(+), 51 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi-nor/core.c index 93ae69b7ff83..e990be7c7eb6 100644

drivers/mtd/spi-nor/core.c +0 -0

cut

Quoted 6 lines
drivers/mtd/spi-nor/core.c +0 -0
@@ -2905,7 +3007,10 @@ static void

spi_nor_init_fixup_flags(struct spi_nor *nor) static int spi_nor_late_init_params(struct spi_nor
*nor) {
struct spi_nor_flash_parameter *params =
spi_nor_get_params(nor,

0);

Quoted 6 lines
drivers/mtd/spi-nor/core.c +4 -1
-	int ret;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	u64 flash_size[SNOR_FLASH_CNT_MAX];
+	u32 idx = 0;
+	int rc, ret;
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/mtd/spi-nor/core.c

Quoted 3 lines
drivers/mtd/spi-nor/core.c +1 -0
 	if (nor->manufacturer && nor->manufacturer->fixups &&
 	    nor->manufacturer->fixups->late_init) { @@ -2937,6
+3042,44 @@ static int spi_nor_late_init_params(struct spi_nor

*nor)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mtd/spi-nor/core.c

Quoted 2 lines
drivers/mtd/spi-nor/core.c +0 -0
 	if (params->n_banks > 1)
 		params->bank_size = div64_u64(params->size,

params-

Quoted 45 lines
Quoted 45 lines
Quoted 6 lines
Quoted 6 lines

n_banks);

Quoted 5 lines
Quoted 5 lines

drivers/mtd/spi-nor/core.c

Quoted 5 lines
drivers/mtd/spi-nor/core.c +4 -0
+	nor->num_flash = 0;
+
+	/*
+	 * The flashes that are connected in stacked mode should be

of

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

+same

make.

drivers/mtd/spi-nor/core.c

Quoted 2 lines
drivers/mtd/spi-nor/core.c +2 -0
+	 * Except the flash size all other properties are identical
+for all

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mtd/spi-nor/core.c

Quoted 2 lines
drivers/mtd/spi-nor/core.c +2 -0
+	 * flashes connected in stacked mode.
+	 * The flashes that are connected in parallel mode should be

identical.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/mtd/spi-nor/core.c

Quoted 3 lines
drivers/mtd/spi-nor/core.c +3 -0
+	 */
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "stacked-

memories",

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

idx,

Quoted 1 line

+&flash_size[idx]);

This is a little late in my opinion, as we don't have any sanity check on the flashes that are stacked on top of the first. We shall at least read and compare the ID for all.

Alright, I will incorporate a sanity check for reading and comparing the ID of the stacked flash. Subsequently, I believe this stacked logic should be relocated to spi_nor_get_flash_info() where we identify the first flash. Please share your thoughts on this. Additionally, do you

Quoted 6 lines
Quoted 2 lines

I'm wondering whether we can add a layer on top of the flash type to handle

When you mention "on top," are you referring to incorporating it into the MTD layer? Initially, Miquel had submitted this patch to address

I mean something above SPI MEM flashes, be it NOR, NANDs or whatever. Instead of treating the stacked flashes as a monolithic device and treat in SPI NOR some array of flashes, to have a layer above which probes the SPI MEM flash driver for each stacked flash. In your case SPI NOR would be probed twice, as you use 2 SPI NOR flashes.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

stacked/parallel handling in the MTD layer.
https://lore.kernel.org/linux-mtd/20200114191052.0a16d116@xps13/t/
However, the Device Tree bindings were initially not accepted.

Okay, thanks for the pointer. I'll take a look.

haven't yet read the thread from above, but I skimmed over the AMD controller datasheet.

Quoted 26 lines
Quoted 22 lines
Quoted 6 lines

Following a series of discussions, the below bindings were eventually merged.
https://lore.kernel.org/all/20220126112608.955728-4-miquel.raynal@bo
ot
lin.com/

I saw, thanks.

Quoted 5 lines
Quoted 5 lines

the stacked/parallel modes. This way everything will become flash type independent. Would it be possible to stack 2 SPI NANDs? How about a SPI NOR and a SPI NAND?

Quoted 7 lines
Quoted 1 line

Is the datasheet of the controller public?

Yes,
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Quad-SPI-Contr
ol
ler

Quoted 3 lines

Wonderful, I'll take a look. I see two clocks there. Does this mean that the stacked flashes can be operated at different frequencies? Do you know if we

Quoted 6 lines

In stacked configuration, both flashes utilize a common clock (single clock line). In a parallel setup, the flashes share the same clock but have distinct clock lines. Please refer the diagrams in the sections below for reference.
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Inter
face-Diagrams

Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

can combine a SPI NOR with a SPI NAND in stacked configuration?

No, Xilinx/AMD QSPI controllers doesn't support this configuration.

2 SPI NANDs shall work with the AMD controller, right?

We never tested 2 SPI-NAND with AMD controller.

Quoted 6 lines

I skimmed over the QSPI controller datasheet and wondered why one would get complicated with 2 Quad Flashes when we have Octal. But then I saw that the same SoC can configure an Octal controller (the Octal and Quad controllers seems mutual exclusive) and that the Octal one can operate 2 octal flashes in stacked mode :).

Thats correct .

Please let me know how you want me to proceed on this.

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#36 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 3 lines · Amit Kumar
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

What I'm interested is if each flash is in its own package. Are they?

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

can combine a SPI NOR with a SPI NAND in stacked configuration?

No, Xilinx/AMD QSPI controllers doesn't support this configuration.

2 SPI NANDs shall work with the AMD controller, right?

We never tested 2 SPI-NAND with AMD controller.

I was asking because I think the stacked layer shall be SPI MEM generic, and not particular to SPI NOR.

Quoted 8 lines
Quoted 5 lines

I skimmed over the QSPI controller datasheet and wondered why one would get complicated with 2 Quad Flashes when we have Octal. But then I saw that the same SoC can configure an Octal controller (the Octal and Quad controllers seems mutual exclusive) and that the Octal one can operate 2 octal flashes in stacked mode 🙂.

Thats correct .

Please let me know how you want me to proceed on this.

I got you. Still need to allocate more time on this.

Cheers,
ta

#37 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Tudor,

Quoted 20 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 1:40 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 6 lines
Quoted 3 lines · Amit Kumar
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

N25Q00A, MX66U2G45G, IS25LP01G & W25H02JV are some of the QSPI flashes on which we tested. Additionally, we conducted tests on over 30 different QSPI flashes from four distinct vendors (Miron, Winbond, Macronix, and ISSI).

Quoted 1 line

What I'm interested is if each flash is in its own package. Are they?

I'm sorry, but I don't quite understand what you mean by "if each flash in its own package."

Quoted 10 lines
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

can combine a SPI NOR with a SPI NAND in stacked configuration?

No, Xilinx/AMD QSPI controllers doesn't support this configuration.

2 SPI NANDs shall work with the AMD controller, right?

We never tested 2 SPI-NAND with AMD controller.

I was asking because I think the stacked layer shall be SPI MEM generic, and not particular to SPI NOR.

Yes, I agree.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

I skimmed over the QSPI controller datasheet and wondered why one would get complicated with 2 Quad Flashes when we have Octal. But then I saw that the same SoC can configure an Octal controller (the Octal and Quad controllers seems mutual exclusive) and that the Octal one can operate 2 octal flashes in stacked mode 🙂.

Thats correct .

Please let me know how you want me to proceed on this.

I got you. Still need to allocate more time on this.

Sure.

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#38 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi,

Quoted 24 lines
Quoted 24 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 1:40 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 2 lines · Amit Kumar
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

N25Q00A, MX66U2G45G, IS25LP01G & W25H02JV are some of the QSPI flashes on which we tested. Additionally, we conducted tests on over 30 different QSPI flashes from four distinct vendors (Miron, Winbond, Macronix, and ISSI).

Great.

Quoted 5 lines
Quoted 1 line

What I'm interested is if each flash is in its own package. Are they?

I'm sorry, but I don't quite understand what you mean by "if each flash in its own package."

There are flashes that are stacked at the physical level. It's a single flash with multiple dies, that are all under a single physical package.

As I understand, your stacked flash model is at logical level. You have 2 flashes each in its own package. 2 different entities. Is my understanding correct?

Cheers,
ta

#39 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Tudor,

Quoted 62 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 4:03 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; alsa- [email protected]; [email protected]; linux- [email protected]; git (AMD-Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi,

Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 1:40 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 8 lines
Quoted 6 lines · Amit Kumar
Quoted 3 lines
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

N25Q00A, MX66U2G45G, IS25LP01G & W25H02JV are some of the QSPI

flashes

Quoted 2 lines

on which we tested. Additionally, we conducted tests on over 30 different QSPI flashes from four distinct vendors (Miron, Winbond,

Macronix, and ISSI).

Quoted 1 line

Great.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What I'm interested is if each flash is in its own package. Are they?

I'm sorry, but I don't quite understand what you mean by "if each flash in its own package."

There are flashes that are stacked at the physical level. It's a single flash with multiple dies, that are all under a single physical package.

Got it. The W25H02JV QSPI flash I mentioned earlier is a device with with four dies that are stacked at the physical level.

Quoted 4 lines

As I understand, your stacked flash model is at logical level. You have 2 flashes each in its own package. 2 different entities. Is my understanding correct?

Yes, that’s correct.

I'd like to contribute to your earlier point regarding the placement of the stacked layer. As you correctly highlighted, it should be in the spi-mem generic layer. For instance, when a read/write operation extends across multiple flashes (whether SPI-NOR or SPI-NAND), the stacked layer must handle the flash crossover. This requires setting the appropriate CS index in mem->spi->cs_index_mask to select the correct slave device and updating the data buffer, address & data length in spi_mem_op struct variable. Does this align with your understanding?

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#40 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 2 lines · Amit Kumar

Hello Tudor,

Hi!

Quoted 81 lines
Quoted 62 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 4:03 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; alsa- [email protected]; [email protected]; linux- [email protected]; git (AMD-Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi,

Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 1:40 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 8 lines
Quoted 6 lines · Amit Kumar
Quoted 3 lines
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

N25Q00A, MX66U2G45G, IS25LP01G & W25H02JV are some of the QSPI

flashes

Quoted 2 lines

on which we tested. Additionally, we conducted tests on over 30 different QSPI flashes from four distinct vendors (Miron, Winbond,

Macronix, and ISSI).

Quoted 1 line

Great.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What I'm interested is if each flash is in its own package. Are they?

I'm sorry, but I don't quite understand what you mean by "if each flash in its own package."

There are flashes that are stacked at the physical level. It's a single flash with multiple dies, that are all under a single physical package.

Got it. The W25H02JV QSPI flash I mentioned earlier is a device with with four dies that are stacked at the physical level.

Quoted 4 lines

As I understand, your stacked flash model is at logical level. You have 2 flashes each in its own package. 2 different entities. Is my understanding correct?

Yes, that’s correct.

Quoted 9 lines

I'd like to contribute to your earlier point regarding the placement of the stacked layer. As you correctly highlighted, it should be in the spi-mem generic layer. For instance, when a read/write operation extends across multiple flashes (whether SPI-NOR or SPI-NAND), the stacked layer must handle the flash crossover. This requires setting the appropriate CS index in mem->spi->cs_index_mask to select the correct slave device and updating the data buffer, address & data length in spi_mem_op struct variable. Does this align with your understanding?

This was the initial idea, yes, but we'll have to see how mtd concat fits in. Maybe the abstraction can be made at the mtd level, which I suspect mtd concat does. I have to read that driver, never opened it.

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-/media/client/global/documents/products/data-sheet/nor-flash/serial-nor/mt25t/generation-b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.
Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

I had a short chat with Michael and he highlighted that instead of the parallel mode, one would be better of with an octal device. I wonder whether the quad parallel is worth the effort. I see AMD can select either quad (single/stacked/parallel) or octal (single/stacked). Is the parallel mode considered obsolete for new IPs?

Cheers,
ta

#41 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Tudor,

Quoted 118 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Tuesday, December 19, 2023 1:56 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 2 lines · Amit Kumar

Hello Tudor,

Hi!

Quoted 26 lines
Quoted 26 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 4:03 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; alsa- [email protected]; [email protected]; linux- [email protected]; git (AMD-Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 1 line · Amit Kumar

Hello Tudor,

Hi,

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

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, December 15, 2023 1:40 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 50 lines
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines

[email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD-
Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 8 lines
Quoted 6 lines · Amit Kumar
Quoted 3 lines
Quoted 2 lines

Thanks! Can you share with us what flashes you used for testing in the stacked and parallel configurations?

I used SPI-NOR QSPI flashes for testing stacked and parallel.

I got that, I wanted the flash name or device ID.

N25Q00A, MX66U2G45G, IS25LP01G & W25H02JV are some of the QSPI

flashes

Quoted 2 lines

on which we tested. Additionally, we conducted tests on over 30 different QSPI flashes from four distinct vendors (Miron, Winbond,

Macronix, and ISSI).

Quoted 1 line

Great.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What I'm interested is if each flash is in its own package. Are they?

I'm sorry, but I don't quite understand what you mean by "if each flash in its own package."

There are flashes that are stacked at the physical level. It's a single flash with multiple dies, that are all under a single physical package.

Got it. The W25H02JV QSPI flash I mentioned earlier is a device with with four dies that are stacked at the physical level.

Quoted 5 lines

As I understand, your stacked flash model is at logical level. You have
2 flashes each in its own package. 2 different entities. Is my understanding correct?

Yes, that’s correct.

Quoted 8 lines

I'd like to contribute to your earlier point regarding the placement of the stacked layer. As you correctly highlighted, it should be in the spi-mem generic layer. For instance, when a read/write operation extends across multiple flashes (whether SPI-NOR or SPI-NAND), the stacked layer must handle the flash crossover. This requires setting the appropriate CS index in mem->spi->cs_index_mask to select the correct slave device and updating the data buffer, address & data length in spi_mem_op struct variable. Does this align with your

Quoted 6 lines

understanding?

Quoted 1 line

This was the initial idea, yes, but we'll have to see how mtd concat fits in. Maybe the abstraction can be made at the mtd level, which I suspect mtd concat does. I have to read that driver, never opened it.

I haven't explored the mtd concat driver either.

Quoted 9 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation- b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Quoted 5 lines

I had a short chat with Michael and he highlighted that instead of the parallel mode, one would be better of with an octal device. I wonder whether the quad parallel is worth the effort. I see AMD can select either quad (single/stacked/parallel) or octal (single/stacked). Is the parallel mode

Indeed, customers have the flexibility to choose between quad or octal options. However, some opt for a cost-effective strategy by selecting only Quad SPI in their chipset and boosting throughput through the parallel use of two flashes. To gauge the popularity of this configuration, I will consult with our marketing team for further insights. Given that parallel is a controller feature, it can be integrated into the driver file. At present, we can emphasis on implementing support for stacked mode, either through a new interface like mtd/spi-nor/stacked.c or by utilizing the mtd concat driver.

Quoted 1 line

considered obsolete for new IPs?

No, the parallel mode feature is still present in AMD's new IPs.

Regards,
Amit

Quoted 3 lines

Cheers,
ta

#42 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 6 lines · Amit Kumar
Quoted 6 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation- b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

Quoted 8 lines
Quoted 2 lines

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Amit, please help me to assess this. I assume Micron and Microchip is using the same concepts as AMD uses for the "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".

I was wrong, the AMD datasheet [1] was misleading [2], it described the IOs for both flashes as IO[3:0], but later on in the "Table QSPI Interface Signals" the second flash is described with IO[7:4].

The AMD's 8-bit Dual Flash Parallel Interface is using dedicated CS# and CLK# lines for each flash. As Micron does, isn't it?

Micron says [3] that:
"The device contains two quad I/O die, each able to operate independently for a total of eight I/Os. The memory map applies to each die. Each die has internal registers for status, configuration, and device protection that can be set and read independently from one other. Micron recommends that internal configuration settings for the two die be set identically."

it also says that:
"When using quad commands in XIO-SPI or when using QIO-SPI, DQ[3:0]/DQ[7:4] are I/O."

So I guess the upper layers just ask for a chunk of memory to be written and the controller handles the cs# lines automatically. How is the AMD controller working, do you have to drive the cs# lines manually, or you just set the parallel mode and the controller takes care of everything?

I assume this is how mchp is handling things, they seem to just set a bit the protocol into the QSPI_IFR.PROTTYP register field and that's all [4]. They even seem to write the registers of both flashes at the same time.

In what regards the AMD's "dual stack interface", AMD is sharing the clock and IO lines and uses dedicated CS# lines for the flashes, whereas Micron shares the CS# and CLK# lines with different IO lines.

Amit, please study the architectures used by mchp, micron and amd and let us know if they are the same or they differ, and if they differ what are the differences.

I added Conor from mchp in cc, I see Nicolas is already there, and Bean from micron.

Thanks,
ta

[1]
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Interface-Signals
[2]
https://docs.xilinx.com/viewer/attachment/dwmjhDJGICdJqD4swyVzcQ/fD8nv4ry78xM0_EF5kv4mA
[3]
https://media-www.micron.com/-/media/client/global/documents/products/data-sheet/nor-flash/serial-nor/mt25t/generation-b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500
[4]
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

#43 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 29 lines · Tudor Ambarus
Quoted 6 lines · Amit Kumar
Quoted 6 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation- b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

Quoted 8 lines
Quoted 2 lines

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Amit, please help me to assess this. I assume Micron and Microchip is using the same concepts as AMD uses for the "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".

I was wrong, the AMD datasheet [1] was misleading [2], it described the IOs for both flashes as IO[3:0], but later on in the "Table QSPI Interface Signals" the second flash is described with IO[7:4].

The AMD's 8-bit Dual Flash Parallel Interface is using dedicated CS# and CLK# lines for each flash. As Micron does, isn't it?

Quoted 7 lines

Micron says [3] that:
"The device contains two quad I/O die, each able to operate independently for a total of eight I/Os. The memory map applies to each die. Each die has internal registers for status, configuration, and device protection that can be set and read independently from one other. Micron recommends that internal configuration settings for the two die be set identically."

Amit,

I forgot to say my first conclusion about the quote from above. Even if the dies are in the same physical package, micron asks users to configure each die as it is a self-standing entity, IOW to configure each die as it is a flash on its own. To me it looks like 2 concatenated flashes at first look. Thus identical to how AMD controller works. Please clarify this.

Quoted 4 lines

it also says that:
"When using quad commands in XIO-SPI or when using QIO-SPI, DQ[3:0]/DQ[7:4] are I/O."

and this would be a parallel concatenation of two flashes.

Then it would be good if you let us now the similarities and differences between how amd and mchp controller work, I scrawled few ideas below.

thanks,
ta

Quoted 32 lines

So I guess the upper layers just ask for a chunk of memory to be written and the controller handles the cs# lines automatically. How is the AMD controller working, do you have to drive the cs# lines manually, or you just set the parallel mode and the controller takes care of everything?

I assume this is how mchp is handling things, they seem to just set a bit the protocol into the QSPI_IFR.PROTTYP register field and that's all [4]. They even seem to write the registers of both flashes at the same time.

In what regards the AMD's "dual stack interface", AMD is sharing the clock and IO lines and uses dedicated CS# lines for the flashes, whereas Micron shares the CS# and CLK# lines with different IO lines.

Amit, please study the architectures used by mchp, micron and amd and let us know if they are the same or they differ, and if they differ what are the differences.

I added Conor from mchp in cc, I see Nicolas is already there, and Bean from micron.

Thanks,
ta

[1]
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Interface-Signals
[2]
https://docs.xilinx.com/viewer/attachment/dwmjhDJGICdJqD4swyVzcQ/fD8nv4ry78xM0_EF5kv4mA
[3]
https://media-www.micron.com/-/media/client/global/documents/products/data-sheet/nor-flash/serial-nor/mt25t/generation-b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500
[4]
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

#44 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 54 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, February 9, 2024 9:44 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]; Conor Dooley <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 8 lines · Tudor Ambarus
Quoted 5 lines · Amit Kumar
Quoted 5 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation-

b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

Quoted 21 lines
Quoted 9 lines
Quoted 3 lines

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Amit, please help me to assess this. I assume Micron and Microchip is using the same concepts as AMD uses for the "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".

I was wrong, the AMD datasheet [1] was misleading [2], it described the IOs for both flashes as IO[3:0], but later on in the "Table QSPI Interface Signals" the second flash is described with IO[7:4].

The AMD's 8-bit Dual Flash Parallel Interface is using dedicated CS# and CLK# lines for each flash. As Micron does, isn't it?

Quoted 9 lines
Quoted 5 lines

Micron says [3] that:
"The device contains two quad I/O die, each able to operate independently for a total of eight I/Os. The memory map applies to each die. Each die has internal registers for status, configuration, and device protection that can be set and read independently from one

other.

Quoted 2 lines

Micron recommends that internal configuration settings for the two die be set identically."

Hello Tudor,

Quoted 8 lines

Amit,

I forgot to say my first conclusion about the quote from above. Even if the dies are in the same physical package, micron asks users to configure each die as it is a self-standing entity, IOW to configure each die as it is a flash on its own. To me it looks like 2 concatenated flashes at first look. Thus identical to how AMD controller works.
Please clarify this.

That’s correct, the Micron flash that you referred can communicate with the AMD QSPI controller in both parallel and stacked mode.

Quoted 7 lines
Quoted 5 lines

it also says that:
"When using quad commands in XIO-SPI or when using QIO-SPI, DQ[3:0]/DQ[7:4] are I/O."

and this would be a parallel concatenation of two flashes.

That's correct.

Regards,
Amit

Quoted 49 lines

Then it would be good if you let us now the similarities and differences between how amd and mchp controller work, I scrawled few ideas below.

thanks,
ta

Quoted 5 lines

So I guess the upper layers just ask for a chunk of memory to be written and the controller handles the cs# lines automatically. How is the AMD controller working, do you have to drive the cs# lines manually, or you just set the parallel mode and the controller takes care of

everything?

Quoted 4 lines

I assume this is how mchp is handling things, they seem to just set a bit the protocol into the QSPI_IFR.PROTTYP register field and that's all [4]. They even seem to write the registers of both flashes at the same

time.

Quoted 12 lines

In what regards the AMD's "dual stack interface", AMD is sharing the clock and IO lines and uses dedicated CS# lines for the flashes, whereas Micron shares the CS# and CLK# lines with different IO lines.

Amit, please study the architectures used by mchp, micron and amd and let us know if they are the same or they differ, and if they differ what are the differences.

I added Conor from mchp in cc, I see Nicolas is already there, and Bean from micron.

Quoted 8 lines

Thanks,
ta

[1]
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Inter
face-Signals
[2]

https://docs.xilinx.com/viewer/attachment/dwmjhDJGICdJqD4swyVzcQ/fD8nv

Quoted 3 lines

4ry78xM0_EF5kv4mA
[3]
https://media-www.micron.com/-

/media/client/global/documents/products/

Quoted 4 lines

data-sheet/nor-flash/serial-nor/mt25t/generation-b/mt25t_qljs_l_512_xb a_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500
[4]

https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/
Produ

Quoted 1 line

ctDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

#45 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 34 lines

-----Original Message-----
From: Mahapatra, Amit Kumar <[email protected]>
Sent: Wednesday, March 13, 2024 9:34 PM
To: Tudor Ambarus <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]; Conor Dooley <[email protected]>; [email protected]
Subject: RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 4 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, February 9, 2024 9:44 PM
To: Mahapatra, Amit Kumar <[email protected]>;

Quoted 8 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>;

Quoted 7 lines

linux-

Quoted 6 lines

[email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]; Conor Dooley <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Everyone,

I would like to propose another approach for handling stacked and parallel connection modes and would appreciate your thoughts on it. But before that, here is some background on what we are trying to achieve.

The AMD QSPI controller supports two advanced connection modes(Stacked and Dual Parallel) which allow the controller to treat two different flashes as one storage.

Stacked:
Flashes share the same SPI bus, but different CS line, controller asserts the CS of the flash to which it needs to communicate.

Dual Parallel:
Both the flashes have their separate SPI bus CS of both the flashes will be asserted/de-asserted at the same time. In this mode data will be split across both the flashes by enabling the STRIPE setting in the controller. If STRIPE is not enabled, then same data will be sent to both the devices.

For more information on the modes please feel free to go through the controller flash interface below
https://docs.amd.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Device-Interface

Mirochip QSPI controller also supports "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

DT binding changes were added through the following commits:
https://github.com/torvalds/linux/commit/f89504300e94524d5d5846ff8b728592ac72cec4
https://github.com/torvalds/linux/commit/eba5368503b4291db7819512600fa014ea17c5a8
https://github.com/torvalds/linux/commit/e2edd1b64f1c79e8abda365149ed62a2a9a494b4

SPI core changes were adds through the following commit:
https://github.com/torvalds/linux/commit/4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

This layer would perform the following tasks:
- During probing, store information from all the connected flashes, whether in stacked or parallel mode, and present it as a single device to the MTD layer.
- Register callbacks through this new layer instead of spi-nor/core.c and handle MTD device registration.
- In stacked mode, select the appropriate spi-nor flash based on the address provided by the MTD layer during flash operations.
- Manage flash crossover operations in stacked mode.
- Ensure both connected flashes are identical in parallel mode.
- Handle odd byte count requests from the MTD layer during flash operations in parallel mode.

For implementing this the current DT binding need to be updated as follows.

stacked-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each stacked flash will have its own flash node. This approach allows flashes of different makes and sizes to be stacked together, as each flash will be probed individually.
- The stacked-memories DT bindings will contain the phandles of the flash nodes connected in stacked mode.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    stacked-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };
                        

  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };

}
}

parallel-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each flash connected in parallel mode will have its own flash node. This allows us to verify that both flashes connected in parallel are identical, as each flash node will be probed separately.
- The parallel-memories DT bindings will contain the phandles of the flash nodes connected in parallel.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    parallel-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };
                        

  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };

}
}

Regards,
Amit

Quoted 128 lines
Quoted 35 lines · Tudor Ambarus
Quoted 9 lines · Amit Kumar
Quoted 6 lines
Quoted 6 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/seria l-
nor/mt25t/generation-

b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

Quoted 21 lines
Quoted 9 lines
Quoted 3 lines

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Amit, please help me to assess this. I assume Micron and Microchip is using the same concepts as AMD uses for the "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".

I was wrong, the AMD datasheet [1] was misleading [2], it described the IOs for both flashes as IO[3:0], but later on in the "Table QSPI Interface Signals" the second flash is described with IO[7:4].

The AMD's 8-bit Dual Flash Parallel Interface is using dedicated CS# and CLK# lines for each flash. As Micron does, isn't it?

Quoted 10 lines
Quoted 6 lines

Micron says [3] that:
"The device contains two quad I/O die, each able to operate independently for a total of eight I/Os. The memory map applies to each die. Each die has internal registers for status, configuration, and device protection that can be set and read independently from one

other.

Quoted 2 lines

Micron recommends that internal configuration settings for the two die be set identically."

Hello Tudor,

Quoted 7 lines

Amit,

I forgot to say my first conclusion about the quote from above. Even if the dies are in the same physical package, micron asks users to configure each die as it is a self-standing entity, IOW to configure each die as it is a flash on its own. To me it looks like 2 concatenated flashes at first look. Thus identical to how AMD controller

works.

Quoted 1 line

Please clarify this.

That’s correct, the Micron flash that you referred can communicate with the AMD QSPI controller in both parallel and stacked mode.

Quoted 7 lines
Quoted 5 lines

it also says that:
"When using quad commands in XIO-SPI or when using QIO-SPI, DQ[3:0]/DQ[7:4] are I/O."

and this would be a parallel concatenation of two flashes.

That's correct.

Regards,
Amit

Quoted 3 lines

Then it would be good if you let us now the similarities and differences between how amd and mchp controller work, I scrawled few

ideas below.

Quoted 9 lines

thanks,
ta

Quoted 6 lines

So I guess the upper layers just ask for a chunk of memory to be written and the controller handles the cs# lines automatically. How is the AMD controller working, do you have to drive the cs# lines manually, or you just set the parallel mode and the controller takes care of

Quoted 29 lines

everything?

Quoted 5 lines

I assume this is how mchp is handling things, they seem to just set a bit the protocol into the QSPI_IFR.PROTTYP register field and that's all [4]. They even seem to write the registers of both flashes at the same

time.

Quoted 21 lines

In what regards the AMD's "dual stack interface", AMD is sharing the clock and IO lines and uses dedicated CS# lines for the flashes, whereas Micron shares the CS# and CLK# lines with different IO lines.

Amit, please study the architectures used by mchp, micron and amd and let us know if they are the same or they differ, and if they differ what are the differences.

I added Conor from mchp in cc, I see Nicolas is already there, and Bean from micron.

Thanks,
ta

[1]
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Int
er
face-Signals
[2]

https://docs.xilinx.com/viewer/attachment/dwmjhDJGICdJqD4swyVzcQ/fD8nv

Quoted 10 lines
Quoted 3 lines

4ry78xM0_EF5kv4mA
[3]
https://media-www.micron.com/-

/media/client/global/documents/products/

Quoted 5 lines

data-sheet/nor-flash/serial-nor/mt25t/generation-b/mt25t_qljs_l_512_ xb
a_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500
[4]

https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/

Quoted 2 lines

Produ

Quoted 1 line

ctDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

#46 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi,

Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

Will AMD submit to maintain this layer? What happens if the maintainer will leave AMD? TBH, personally, I don't like to maintain such a niche feature.
I'd really like to see some use cases and performance reports for this, like actual boards (and no evaluation boards don't count). Why wouldn't someone just use an octal flash?

And as already mentioned there is also mtdcat, which seems to duplicate some features?

-michael

maintainer
#47 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Michael,

Quoted 7 lines · Michael Walle

Hi,

Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

Quoted 6 lines

Will AMD submit to maintain this layer? What happens if the maintainer will leave AMD? TBH, personally, I don't like to maintain such a niche feature.
I'd really like to see some use cases and performance reports for this, like actual boards (and no evaluation boards don't count). Why wouldn't someone just use an octal flash?

AMD/Xilinx is not creating products that's why we don't have data on actual boards but I don't really understand why evaluation boards don't count. A lot of customers are taking schematics from us and removing parts which they don't need and add their custom part.

But one product for parallel configuration which is publicly saying that it is using it is for example this SOM.
https://shop.trenz-electronic.de/en/TE0820-05-2AI21MA-MPSoC-Module-with-AMD-Zynq-UltraScale-ZU2CG-1I-2-GByte-DDR4-SDRAM-4-x-5-cm

I am not marketing guy to tell if there is any other which publicly saying we are using this feature but we can only develop/support/maintain support for these configurations on our evaluation boards because that's what we have access to and what we know how it is done.

Also performance numbers from us can be only provided against our evaluation boards.

Thanks,
Michal

#48 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Michal,

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

Will AMD submit to maintain this layer? What happens if the maintainer will leave AMD? TBH, personally, I don't like to maintain such a niche feature.
I'd really like to see some use cases and performance reports for this, like actual boards (and no evaluation boards don't count). Why wouldn't someone just use an octal flash?

Quoted 2 lines

AMD/Xilinx is not creating products that's why we don't have data on actual boards but I don't really understand why evaluation boards don't count.

Because on an eval board the vendor just puts everything possible on the board.

Quoted 8 lines

A lot of
customers are taking schematics from us and removing parts which they don't need and add their custom part.

But one product for parallel configuration which is publicly saying that it is using it is for example this SOM.
https://shop.trenz-electronic.de/en/TE0820-05-2AI21MA-MPSoC-Module-with-AMD-Zynq-UltraScale-ZU2CG-1I-2-GByte-DDR4-SDRAM-4-x-5-cm

Quoted 6 lines

I am not marketing guy to tell if there is any other which publicly saying we are using this feature but we can only develop/support/maintain support for these configurations on our evaluation boards because that's what we have access to and what we know how it is done.

Also performance numbers from us can be only provided against our evaluation boards.

Which is good enough.

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

-michael

maintainer
#49 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 33 lines · Michael Walle

Hi Michal,

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

Will AMD submit to maintain this layer? What happens if the maintainer will leave AMD? TBH, personally, I don't like to maintain such a niche feature.
I'd really like to see some use cases and performance reports for this, like actual boards (and no evaluation boards don't count). Why wouldn't someone just use an octal flash?

Quoted 2 lines

AMD/Xilinx is not creating products that's why we don't have data on actual boards but I don't really understand why evaluation boards don't count.

Because on an eval board the vendor just puts everything possible on the board.

Quoted 13 lines

A lot of
customers are taking schematics from us and removing parts which they don't need and add their custom part.

But one product for parallel configuration which is publicly saying that it is using it is for example this SOM.
https://shop.trenz-electronic.de/en/TE0820-05-2AI21MA-MPSoC-Module-with-AMD-Zynq-UltraScale-ZU2CG-1I-2-GByte-DDR4-SDRAM-4-x-5-cm

I am not marketing guy to tell if there is any other which publicly saying we are using this feature but we can only develop/support/maintain support for these configurations on our evaluation boards because that's what we have access to and what we know how it is done.

Quoted 8 lines
Quoted 1 line

Also performance numbers from us can be only provided against our evaluation boards.

Which is good enough.

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Quoted 5 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.
And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream support for it.

Thanks,
Michal

#50 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 8 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers. Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard. Is it any faster? Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why? I mean you've put that controller on your SoC, you must have some convincing arguments why a customer should use it.

Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

Quoted 4 lines

And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream support for it.

You still didn't answer my initial question. Will AMD support and maintain that code? I was pushing you towards putting that code into your own driver because then that's up to you what you are doing there.

So how do we move forward? I'd like to see as little as core changes possible to get your dual flash setup working. I'm fine with having a layer in spi-nor/ (not sure that's how it will work with mtdcat which looks like it's similar as your stacked flash) as long as it can be a module (selected by the driver).

-michael

maintainer
#51 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Quoted 5 lines · Michael Walle
Quoted 5 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

Quoted 8 lines
Quoted 3 lines

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

Quoted 2 lines

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Quoted 1 line

Is it any faster?

Amit: please provide numbers.

Quoted 2 lines

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add something more to it.

Quoted 3 lines

I mean you've put that controller on your SoC,
you must have some convincing arguments why a customer should use it.

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other. If you want to have bigger size and also be faster answer is parallel configuration.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it has be clear which way to go.

Quoted 9 lines
Quoted 4 lines

And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream support for it.

You still didn't answer my initial question. Will AMD support and maintain that code? I was pushing you towards putting that code into your own driver because then that's up to you what you are doing there.

Of course. We care about our code and about supporting our SOC and features which are related to it. It means yes, we will be regularly testing it and taking care about it.

Quoted 5 lines

So how do we move forward? I'd like to see as little as core changes possible to get your dual flash setup working. I'm fine with having a layer in spi-nor/ (not sure that's how it will work with mtdcat which looks like it's similar as your stacked flash) as long as it can be a module (selected by the driver).

ok.

Thanks,
Michal

#52 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Michael,

Quoted 24 lines
Quoted 8 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Is it any faster?

Quoted 8 lines

Amit: please provide numbers.

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add something more to it.

Just to add a comment as I work directly with our customers. The main reason this support is important is for our older SoCs, zynq and zynqmp.

Most of our customers are using QSPI flash as the first boot memory to get from the boot ROM to u-boot. They then typically use other memories, such as eMMC for the Linux kernel, OS and file system.

The issue we have on the zynq and zynqmp SoCs is that the boot ROM (code that cannot be changed) will not boot from an OSPI flash. It will only boot from a QSPI flash. This is what is forcing many of our customers down the QSPI path. Since many of these customers are interested in additional speed and memory size, they then end up using a parallel or stacked configuration because they cannot use an OSPI with zynq or zynqmp.

All of our newer SoCs can boot from OSPI. I agree with you that if someone could choose OSPI for performance, they would, so I do not expect parallel or stacked configurations with our newer SoCs.

I get why you see this configuration as a niche, but for us, it is a very large niche because zynq and zynqmp are two of our most successful SoC families.

Quoted 42 lines

I mean you've put that controller on your SoC,
you must have some convincing arguments why a customer should use it.

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other.
If you want to have bigger size and also be faster answer is parallel configuration.

Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it has be clear which way to go.

Quoted 4 lines

And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream support for it.

You still didn't answer my initial question. Will AMD support and maintain that code? I was pushing you towards putting that code into your own driver because then that's up to you what you are doing there.

Of course. We care about our code and about supporting our SOC and features which are related to it. It means yes, we will be regularly testing it and taking care about it.

Quoted 7 lines

So how do we move forward? I'd like to see as little as core changes possible to get your dual flash setup working. I'm fine with having a layer in spi-nor/ (not sure that's how it will work with mtdcat which looks like it's similar as your stacked flash) as long as it can be a module (selected by the driver).

ok.

Best regards,
Neal Frager
AMD

#53 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello,

Quoted 27 lines

-----Original Message-----
From: Frager, Neal <[email protected]>
Sent: Thursday, August 1, 2024 12:07 PM
To: Simek, Michal <[email protected]>; Michael Walle <[email protected]>; Mahapatra, Amit Kumar <amit.kumar- [email protected]>; Tudor Ambarus <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]; Conor Dooley <[email protected]>; [email protected]
Subject: RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Michael,

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

Quoted 22 lines
Quoted 3 lines
Quoted 3 lines

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real

products.

Quoted 17 lines

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Is it any faster?

Amit: please provide numbers.

Here are some QSPI performance numbers comparing a single flash mode and two flashes connected in parallel mode. I ran the test on a VCK190 Eval Board https://www.xilinx.com/products/boards-and-kits/vck190.html,
measuring the timing for mtd_debug erase, write, and read operations. The QSPI bus clock was set to 150MHz, and the data size was 32MB, comparing a single flash setup with a two-flash parallel mode setup.

Single Flash mode:

xilinx-vck190-20242:/home/petalinux# time mtd_debug erase /dev/mtd2 0x00 0x1e00000
Erased 31457280 bytes from address 0x00000000 in flash

real 0m54.713s
user 0m0.000s
sys 0m32.639s

xilinx-vck190-20242:/home/petalinux# time mtd_debug write /dev/mtd2 0x00 0x1e00000 test.bin
Copied 31457280 bytes from test.bin to address 0x00000000 in flash

real 0m30.187s
user 0m0.000s
sys 0m16.359s

xilinx-vck190-20242:/home/petalinux# time mtd_debug read /dev/mtd2 0x00 0x1e00000 test-read.bin
Copied 31457280 bytes from address 0x00000000 in flash to test-read.bin

real 0m0.472s
user 0m0.001s
sys 0m0.040s

Two flashes connected in parallel mode:

xilinx-vck190-20242:/home/petalinux# time mtd_debug erase /dev/mtd2 0x00 0x1e00000
Erased 31457280 bytes from address 0x00000000 in flash

real 0m27.727s
user 0m0.004s
sys 0m14.923s

xilinx-vck190-20242:/home/petalinux# time mtd_debug write /dev/mtd2 0x00 0x1e00000 test.bin
Copied 31457280 bytes from test.bin to address 0x00000000 in flash

real 0m16.538s
user 0m0.000s
sys 0m8.512s

xilinx-vck190-20242:/home/petalinux# time mtd_debug read /dev/mtd2 0x00 0x1e00000 test-read.bin
Copied 31457280 bytes from address 0x00000000 in flash to test-read.bin

real 0m0.263s
user 0m0.000s
sys 0m0.044s

Regards,
Amit

Quoted 84 lines
Quoted 6 lines

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add

something more to it.

Just to add a comment as I work directly with our customers. The main reason this support is important is for our older SoCs, zynq and zynqmp.

Most of our customers are using QSPI flash as the first boot memory to get from the boot ROM to u-boot. They then typically use other memories, such as eMMC for the Linux kernel, OS and file system.

The issue we have on the zynq and zynqmp SoCs is that the boot ROM (code that cannot be changed) will not boot from an OSPI flash. It will only boot from a QSPI flash. This is what is forcing many of our customers down the QSPI path.
Since many of these customers are interested in additional speed and memory size, they then end up using a parallel or stacked configuration because they cannot use an OSPI with zynq or zynqmp.

All of our newer SoCs can boot from OSPI. I agree with you that if someone could choose OSPI for performance, they would, so I do not expect parallel or stacked configurations with our newer SoCs.

I get why you see this configuration as a niche, but for us, it is a very large niche because zynq and zynqmp are two of our most successful SoC families.

Quoted 18 lines

I mean you've put that controller on your SoC, you must have some convincing arguments why a customer should use it.

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other. If you want to have bigger size and also be faster answer is parallel configuration.

Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

Quoted 6 lines

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it

has be clear which way to go.

Quoted 4 lines
Quoted 4 lines

And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream

support for it.

Quoted 11 lines

You still didn't answer my initial question. Will AMD support and maintain that code? I was pushing you towards putting that code into your own driver because then that's up to you what you are doing there.

Of course. We care about our code and about supporting our SOC and features which are related to it. It means yes, we will be regularly testing it and taking care about it.

Quoted 7 lines

So how do we move forward? I'd like to see as little as core changes possible to get your dual flash setup working. I'm fine with having a layer in spi-nor/ (not sure that's how it will work with mtdcat which looks like it's similar as your stacked flash) as long as it can be a module (selected by the driver).

ok.

Best regards,
Neal Frager
AMD

#54 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Frager, Neal

Hi,

Quoted 10 lines
Quoted 3 lines

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add something more to it.

Just to add a comment as I work directly with our customers. The main reason this support is important is for our older SoCs, zynq and zynqmp.

Most of our customers are using QSPI flash as the first boot memory to get from the boot ROM to u-boot. They then typically use other memories, such as eMMC for the Linux kernel, OS and file system.

Agreed and that's probably the most prominent use case for NOR flashes anyway.

Quoted 6 lines

The issue we have on the zynq and zynqmp SoCs is that the boot ROM (code that cannot be changed) will not boot from an OSPI flash. It will only boot from a QSPI flash. This is what is forcing many of our customers down the QSPI path. Since many of these customers are interested in additional speed and memory size, they then end up using a parallel or stacked configuration because they cannot use an OSPI with zynq or zynqmp.

Above you've said, the bootloader is stored on the NOR flash and the bulk storage is eMMC. So why do you need bigger NOR flashes (where even the biggest NOR flash isn't enough)?

I also don't understand "the boot ROM will just boot from QSPI". First, you cannot connect an octal flash anyway, because you only have an QSPI controller, right? Secondly, normally the bootrom will (at least) boot the first stage using normal (single line) SPI commands. Is that not the case for zynq and zynqmp?

Quoted 3 lines

All of our newer SoCs can boot from OSPI. I agree with you that if someone could choose OSPI for performance, they would, so I do not expect parallel or stacked configurations with our newer SoCs.

Ok, but then the argument with bigger flashes are void, because you are back to be bound to one OSPI flash.

Quoted 3 lines

I get why you see this configuration as a niche, but for us, it is a very large niche because zynq and zynqmp are two of our most successful SoC families.

Fair enough. But please find a way to support it without butchering the whole core.

-michael

#55 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Michal Simek

Hi,

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Quoted 6 lines
Quoted 4 lines

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

See below.

Quoted 21 lines
Quoted 2 lines

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Quoted 1 line

Is it any faster?

Amit: please provide numbers.

Quoted 2 lines

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add something more to it.

Quoted 3 lines

I mean you've put that controller on your SoC,
you must have some convincing arguments why a customer should use it.

Quoted 5 lines

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other.
If you want to have bigger size and also be faster answer is parallel configuration.

But who is using expensive NOR flash for bulk storage anyway? You're only mentioning parallel mode. Also the performance numbers were just about the parallel mode. What about stacked mode? Because there's a chance that parallel mode works without modification of the core (?).

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

Quoted 6 lines
Quoted 2 lines

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it has be clear which way to go.

Well, AMD could have side stepped all this if they had just integrated a normal OSPI flash controller, which would have the same requirements regarding the pins (if not even less) and it would have been *easy* to integrate it into the already available ecosystem. That was what my initial question was about. Why did you choose two QSPI ports instead of one OSPI port.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And Amit is trying to figure it out which way to go.
I don't want to predict where that code should be going or how it should look like because don't have spi-nor experience. But I hope we finally move forward on this topic to see the path how to upstream support for it.

Quoted 8 lines
Quoted 4 lines

You still didn't answer my initial question. Will AMD support and maintain that code? I was pushing you towards putting that code into your own driver because then that's up to you what you are doing there.

Of course. We care about our code and about supporting our SOC and features which are related to it. It means yes, we will be regularly testing it and taking care about it.

Great!

-michael

maintainer
#56 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi,

Quoted 41 lines · Michael Walle

Hi,

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple customers in real products.

Quoted 6 lines
Quoted 4 lines

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

See below.

Quoted 21 lines
Quoted 2 lines

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Quoted 1 line

Is it any faster?

Amit: please provide numbers.

Quoted 2 lines

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to add something more to it.

Quoted 3 lines

I mean you've put that controller on your SoC,
you must have some convincing arguments why a customer should use it.

Quoted 7 lines
Quoted 5 lines

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other.
If you want to have bigger size and also be faster answer is parallel configuration.

But who is using expensive NOR flash for bulk storage anyway?

I expect you understand that even if I know companies which does it I am not allow to share their names.

But customers don't need to have other free pins to connect for example emmc. That's why adding one more "expensive flash" can be for them only one option.

Also I bet that price for one more qspi flash is nothing compare to chip itself and other related expenses for low volume production.

Quoted 5 lines

You're
only mentioning parallel mode. Also the performance numbers were just about the parallel mode. What about stacked mode? Because there's a chance that parallel mode works without modification of the core (?).

I will let Amit to comment it.

Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

Quoted 6 lines
Quoted 2 lines

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it has be clear which way to go.

Quoted 6 lines

Well, AMD could have side stepped all this if they had just integrated a normal OSPI flash controller, which would have the same requirements regarding the pins (if not even less) and it would have been *easy* to integrate it into the already available ecosystem. That was what my initial question was about. Why did you choose two QSPI ports instead of one OSPI port.

Keep in your mind that ZynqMP is 9years old SoC. Zynq 12+ years with a lot of internal development happening before. Not sure if ospi even exists at that time. Also if any IP was available for the price which they were targeting. I don't think make sense to discuss OSPI in this context because that's not in these SoCs.
I have never worked with spi that's why don't know historical context to provide more details.

Thanks,
Michal

#57 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Michael,

Quoted 62 lines · Michael Walle
Quoted 10 lines

Hi,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

All I'm saying is that you shouldn't put burden on us (the SPI NOR maintainers) for what seems to me at least as a niche. Thus I was asking for performance numbers and users. Convince me that I'm wrong and that is worth our time.

No. It is not really just feature of our evaluation boards. Customers are using it. I was talking to one guy from field and he confirms me that these configurations are used by his multiple

customers in real products.

Quoted 26 lines
Quoted 7 lines
Quoted 5 lines

Which begs the question, do we really have to support every feature in the core (I'd like to hear Tudors and Pratyush opinion here). Honestly, this just looks like a concatenation of two QSPI controllers.

Based on my understanding for stacked yes. For parallel no.

See below.

Quoted 16 lines
Quoted 2 lines

Why didn't you just use a normal octal controller which is a protocol also backed by the JEDEC standard.

On newer SOC octal IP core is used.
Amit please comment.

Quoted 1 line

Is it any faster?

Amit: please provide numbers.

Quoted 2 lines

Do you get more capacity? Does anyone really use large SPI-NOR flashes? If so, why?

You get twice more capacity based on that configuration. I can't answer the second question because not working with field. But both of that configurations are used by customers. Adding Neal if he wants to

add something more to it.

Quoted 11 lines
Quoted 9 lines
Quoted 3 lines

I mean you've put that controller on your SoC, you must have some convincing arguments why a customer should use it.

I expect recommendation is to use single configuration but if you need bigger space for your application the only way to extend it is to use stacked configuration with two the same flashes next to each other. If you want to have bigger size and also be faster answer is parallel configuration.

But who is using expensive NOR flash for bulk storage anyway?

I expect you understand that even if I know companies which does it I am not allow to share their names.

But customers don't need to have other free pins to connect for example emmc.
That's why adding one more "expensive flash" can be for them only one option.

Also I bet that price for one more qspi flash is nothing compare to chip itself and other related expenses for low volume production.

Quoted 6 lines
Quoted 4 lines

You're
only mentioning parallel mode. Also the performance numbers were just about the parallel mode. What about stacked mode? Because there's a chance that parallel mode works without modification of the core (?).

I will let Amit to comment it.

The performance of the stacked configuration will be the same as that of the single mode. As Michal mentioned earlier, stacked mode is used for scenarios where the customer requires larger flash space while maintaining the same performance.

I want to provide some background on why I choose to handle stacked and parallel modes through an additional layer or file, such as /mtd/spi-nor/stacked.c, rather than mtd-concat. Initially, when Miquel began upstreaming stacked support by extending the mtd-concat driver, the DT binding was not accepted. He proposed a couple of DT bindings
[1] & [2] to support stacking through mtd-concat, but none were accepted. Additionally, after reviewing the MTD core code, he found that adding stacked support through mtd-concat could be complicated and involve many corner cases, which he mentioned in his RFC [3]. He then suggested concatenating the flashes instead of the mtd partitions, and eventually, the current DT bindings were added. This is why I propose handling the stacked and parallel configurations through an additional layer or file, as the mtd-concat approach was already discussed and rejected.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3]https://lore.kernel.org/all/[email protected]/

Regards,
Amit

Quoted 38 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not

sure).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the

kernel.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I am just saying that this is not any adhoc new feature but configuration which has been already discussed and some steps made. If DT binding is wrong it can be deprecated and use new one but for that it

has be clear which way to go.

Quoted 7 lines

Well, AMD could have side stepped all this if they had just integrated a normal OSPI flash controller, which would have the same requirements regarding the pins (if not even less) and it would have been *easy* to integrate it into the already available ecosystem.
That was what my initial question was about. Why did you choose two QSPI ports instead of one OSPI port.

Keep in your mind that ZynqMP is 9years old SoC. Zynq 12+ years with a lot of internal development happening before. Not sure if ospi even exists at that time. Also if any IP was available for the price which they were targeting. I don't think make sense to discuss OSPI in this context because that's not in these SoCs.
I have never worked with spi that's why don't know historical context to provide more details.

Thanks,
Michal

maintainer
#58 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Michael Walle

Hi Michael,

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I'm sorry I'm now catching up, can you point at the thread explaining what is wrong in the bindings? I didn't find where this was detailed. Or otherwise summarize quickly what needs to change?

Thanks!
Miquèl

#59 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi,

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

Quoted 6 lines
Quoted 2 lines

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

I'm sorry I'm now catching up, can you point at the thread explaining what is wrong in the bindings? I didn't find where this was detailed. Or otherwise summarize quickly what needs to change?

Somewhere in this mega thread Tudor had some remarks about the bindings. Amit also mentioned it here:

https://lore.kernel.org/r/IA0PR12MB769944254171C39FF4171B52DCB42@IA0PR12MB7699.namprd12.prod.outlook.com/

-michael

maintainer
#60 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Michael,

[email protected] wrote on Mon, 12 Aug 2024 09:37:06 +0200:

Quoted 13 lines

Hi,

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

The first round of patches were really invasive regarding the core code. So if there is a clean layering approach which can be enabled as a module and you are maintaining it I'm fine with that (even if the core code needs some changes then like hooks or so, not sure).

That discussion started with Miquel some years ago when he was trying to to solve description in DT which is merged for a while in the kernel.

What's your point here? From what I can tell the DT binding is wrong and needs to be reworked anyway.

Quoted 8 lines
Quoted 3 lines

I'm sorry I'm now catching up, can you point at the thread explaining what is wrong in the bindings? I didn't find where this was detailed. Or otherwise summarize quickly what needs to change?

Somewhere in this mega thread Tudor had some remarks about the bindings. Amit also mentioned it here:

https://lore.kernel.org/r/IA0PR12MB769944254171C39FF4171B52DCB42@IA0PR12MB7699.namprd12.prod.outlook.com/

Great. I jumped-in there. Thanks!

Miquèl

maintainer
#61 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Mahapatra, Amit Kumar

Hi,

Quoted 33 lines

Hello Everyone,

I would like to propose another approach for handling stacked and parallel connection modes and would appreciate your thoughts on it. But before that, here is some background on what we are trying to achieve.

The AMD QSPI controller supports two advanced connection modes(Stacked and Dual Parallel) which allow the controller to treat two different flashes as one storage.

Stacked:
Flashes share the same SPI bus, but different CS line, controller asserts the CS of the flash to which it needs to communicate.

Dual Parallel:
Both the flashes have their separate SPI bus CS of both the flashes will be asserted/de-asserted at the same time. In this mode data will be split across both the flashes by enabling the STRIPE setting in the controller. If STRIPE is not enabled, then same data will be sent to both the devices.

For more information on the modes please feel free to go through the controller flash interface below
https://docs.amd.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Device-Interface

Mirochip QSPI controller also supports "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet-DS60001765.pdf

DT binding changes were added through the following commits:
https://github.com/torvalds/linux/commit/f89504300e94524d5d5846ff8b728592ac72cec4
https://github.com/torvalds/linux/commit/eba5368503b4291db7819512600fa014ea17c5a8
https://github.com/torvalds/linux/commit/e2edd1b64f1c79e8abda365149ed62a2a9a494b4

Quoted 7 lines

SPI core changes were adds through the following commit:
https://github.com/torvalds/linux/commit/4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

For now I don't think you need a totally generic implementation. As long as there is only one controller supporting these modes, I'd say this is not super relevant.

Quoted 13 lines

This layer would perform the following tasks:
- During probing, store information from all the connected flashes, whether in stacked or parallel mode, and present it as a single device to the MTD layer.
- Register callbacks through this new layer instead of spi-nor/core.c and handle MTD device registration.
- In stacked mode, select the appropriate spi-nor flash based on the address provided by the MTD layer during flash operations.
- Manage flash crossover operations in stacked mode.
- Ensure both connected flashes are identical in parallel mode.
- Handle odd byte count requests from the MTD layer during flash operations in parallel mode.

Quoted 2 lines

For implementing this the current DT binding need to be updated as follows.

So you want to go back to step 1 and redefine bindings? Is that worth?

Quoted 6 lines

stacked-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each stacked flash will have its own flash node. This approach allows flashes of different makes and sizes to be stacked together, as each flash will be probed individually.

And how will you define partitions crossing device boundaries? I believe this constraint has been totally forgotten in this proposal. The whole idea of stacking two devices this way was to simplify the user's life with a single device exposed and the controller handling itself the CS changes. That is precisely what the current binding do. The final goal being to double your storage transparently. If your goal was to put two chips aside, then none of this was actually needed. If you don't care about that anymore, then all the energy put into discussing the bindings initially was useless and a controller property could also have made the trick.

Quoted 31 lines

- The stacked-memories DT bindings will contain the phandles of the flash nodes connected in stacked mode.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    stacked-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };
                        

  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };

}
}

Quoted 6 lines

parallel-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each flash connected in parallel mode will have its own flash node. This allows us to verify that both flashes connected in parallel are identical, as each flash node will be probed separately.

Well, you don't have to verify that. It's a basic hardware design constraint for using this mode.

Otherwise same comment as above, this description doesn't allow correct partitioning and that was one of the main constraints back when we discussed these needs.

Quoted 28 lines

- The parallel-memories DT bindings will contain the phandles of the flash nodes connected in parallel.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    parallel-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };
                        

  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 { 
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };
Quoted 2 lines

}
}

Thanks,
Miquèl

#62 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hiya,

Amit, the thread becomes unreadable, better start a new one describing what you plan to do.

Quoted 3 lines · Miquel Raynal

For now I don't think you need a totally generic implementation. As long as there is only one controller supporting these modes, I'd say this is not super relevant.

Miquel,

Microchip supports a twin quad mode too, and micron has some flashes with similar architecture, see:

https://lore.kernel.org/linux-mtd/[email protected]/T/#mbe999dde1d29371183aa53089ef6f0087d6902a7

We shall consider them from the beginning. I guess we need to read everything all over again.

#63 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Miquel Raynal

Hello Miquel,

Quoted 8 lines
Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

For now I don't think you need a totally generic implementation. As long as there is only one controller supporting these modes, I'd say this is not super relevant.

IMHO, there should be a general solution since this isn't limited to just one controller. Any controller can support stacked mode with multiple native-cs or multiple gpio-cs, or with a combination of a native-cs and a gpio-cs. For parallel configurations, there are other controllers from Microchip and some flash devices that operate similarly to AMD's parallel mode.

Quoted 14 lines
Quoted 14 lines

This layer would perform the following tasks:
- During probing, store information from all the connected flashes, whether in stacked or parallel mode, and present it as a single device to the MTD layer.
- Register callbacks through this new layer instead of spi-nor/core.c and handle MTD device registration.
- In stacked mode, select the appropriate spi-nor flash based on the address provided by the MTD layer during flash operations.
- Manage flash crossover operations in stacked mode.
- Ensure both connected flashes are identical in parallel mode.
- Handle odd byte count requests from the MTD layer during flash operations in parallel mode.

Quoted 4 lines
Quoted 2 lines

For implementing this the current DT binding need to be updated as follows.

So you want to go back to step 1 and redefine bindings? Is that worth?

The current bindings are effective if we only support identical flash devices or flashes of the same make but with different sizes connected in stacked mode. However, if we want to extend stacked support to include flashes of different makes in stacked mode, the current bindings may not be adequate. That's why I suggested updating the bindings to accommodate all possible scenario.

Quoted 10 lines
Quoted 7 lines

stacked-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each stacked flash will have its own flash node. This approach allows flashes of different makes and sizes to be stacked together, as each flash will be probed individually.

And how will you define partitions crossing device boundaries? I believe this constraint has been totally forgotten in this proposal.

According to the new binding proposal, one of the two flash nodes will have a partition that crosses the device boundary.

Quoted 3 lines

The whole idea of stacking two devices this way was to simplify the user's life with a single device exposed and the controller handling itself the CS changes. That is precisely what the current binding do.

That's true, but as I mentioned earlier, if we're not inclined to support stacked mode for flashes of different makes, then the current bindings are sufficient.

Quoted 43 lines

The final goal being to double your storage transparently. If your goal was to put two chips aside, then none of this was actually needed. If you don't care about that anymore, then all the energy put into discussing the bindings initially was useless and a controller property could also have made the trick.

Quoted 31 lines

- The stacked-memories DT bindings will contain the phandles of the flash nodes connected in stacked mode.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    stacked-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 {
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };


  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 {
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };

}
}

Quoted 6 lines

parallel-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each flash connected in parallel mode will have its own flash node. This allows us to verify that both flashes connected in parallel are identical, as each flash node will be probed separately.

Quoted 2 lines

Well, you don't have to verify that. It's a basic hardware design constraint for using this mode.

Agree

Regards,
Amit

Quoted 38 lines

Otherwise same comment as above, this description doesn't allow correct partitioning and that was one of the main constraints back when we discussed these needs.

Quoted 28 lines

- The parallel-memories DT bindings will contain the phandles of the flash nodes connected in parallel.

spi@0 {

  flash@0 {
    compatible = "jedec,spi-nor"
    reg = <0x00>;
    parallel-memories = <&flash@0 &flash@1>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 {
        label = "qspi-0";
        reg = <0x0 0xf00000>;
    };


  }
  flash@1 {
    compatible = "jedec,spi-nor"
              reg = <0x01>;
    spi-max-frequency = <50000000>;
    ...
              partition@0 {
        label = "qspi-1";
        reg = <0x0 0x800000>;
    };
Quoted 2 lines

}
}

Thanks,
Miquèl

maintainer
#64 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Amit,

[email protected] wrote on Wed, 14 Aug 2024 07:13:35 +0000:

Quoted 7 lines

Hello Miquel,

Quoted 5 lines
Quoted 4 lines

Based on the inputs/suggestions from Tudor, i am planning to add a new layer between the SPI-NOR and MTD layers to support stacked and parallel configurations. This new layer will be part of the spi-nor and located in mtd/spi-nor/

Quoted 8 lines
Quoted 3 lines

For now I don't think you need a totally generic implementation. As long as there is only one controller supporting these modes, I'd say this is not super relevant.

IMHO, there should be a general solution since this isn't limited to just one controller. Any controller can support stacked mode with multiple native-cs or multiple gpio-cs, or with a combination of a native-cs and a gpio-cs.

That's not what was initially discussed. The Xilinx use case was:
a controller is managing two devices "at the same time" transparently from the host. So the two flashes appear like a single one and thus, are described like a single one.

You don't need anything in the bindings nor in the core to manage two flashes connected to the same controller otherwise. The only use case the Xilinx model was bringing, was to consider the storage bigger from a host perspective and thus be able to store files across the device boundary natively.

Quoted 3 lines

For parallel configurations, there are other controllers from Microchip and some flash devices that operate similarly to AMD's parallel mode.

Yes, Tudor reminded me about these.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

This layer would perform the following tasks:
- During probing, store information from all the connected flashes, whether in stacked or parallel mode, and present it as a single device to the MTD layer.
- Register callbacks through this new layer instead of spi-nor/core.c and handle MTD device registration.
- In stacked mode, select the appropriate spi-nor flash based on the address provided by the MTD layer during flash operations.
- Manage flash crossover operations in stacked mode.
- Ensure both connected flashes are identical in parallel mode.
- Handle odd byte count requests from the MTD layer during flash operations in parallel mode.

For implementing this the current DT binding need to be updated as follows.

Quoted 6 lines
Quoted 1 line

So you want to go back to step 1 and redefine bindings? Is that worth?

The current bindings are effective if we only support identical flash devices or flashes of the same make but with different sizes connected in stacked mode. However, if we want to extend stacked support to include flashes of different makes in stacked mode,

The only actual feature the stacked mode brings is the ability to consider two devices like one. This is abstracted by hardware, this is a controller capability. The only way this can work is if the two storage devices are of the same kind and accept the same commands/init cycles.

If you consider two different devices, then there is no hardware abstraction anymore, the controller is no longer "smart" enough and you are back to the standard situation with two devices connected using their own independent CS, known by the host. In this case the "stacked-mode" bindings no longer apply. You need to describe the two chips independently in the DT, and your stacked feature in the controller can no longer be used.

You need other bindings to support this case because it is a different situation. For this case, there was a mtd-concat approach (which was never merged). But this is really something different than the stacked mode in your controller because there is no specific hardware feature involved, it's just pure software.

Quoted 12 lines

the current
bindings may not be adequate. That's why I suggested updating the bindings to accommodate all possible scenario.

Quoted 8 lines
Quoted 7 lines

stacked-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each stacked flash will have its own flash node. This approach allows flashes of different makes and sizes to be stacked together, as each flash will be probed individually.

Quoted 5 lines
Quoted 2 lines

And how will you define partitions crossing device boundaries? I believe this constraint has been totally forgotten in this proposal.

According to the new binding proposal, one of the two flash nodes will have a partition that crosses the device boundary.

From a bindings perspective, it feels very awkward and I doubt it will be accepted. From a code perspective, you're gonna need to butcher the core...

Quoted 7 lines
Quoted 3 lines

The whole idea of stacking two devices this way was to simplify the user's life with a single device exposed and the controller handling itself the CS changes. That is precisely what the current binding do.

That's true, but as I mentioned earlier, if we're not inclined to support stacked mode for flashes of different makes, then the current bindings are sufficient.

Thanks,
Miquèl

#65 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Miquel,

Quoted 2 lines

That's not what was initially discussed. The Xilinx use case was:
a controller is managing two devices "at the same time" transparently from

Yes, but in stacked mode, the controller communicates with one of the two connected flash devices at any given time, based on the address and data length. It doesn't assert both chip selects simultaneously.

Quoted 8 lines

the host. So the two flashes appear like a single one and thus, are described like a single one.

You don't need anything in the bindings nor in the core to manage two flashes connected to the same controller otherwise. The only use case the Xilinx model was bringing, was to consider the storage bigger from a host perspective and thus be able to store files across the device boundary natively.

When adding stacked support to the SPI core, Mark also asked us to support the GPIO chip select use case, so it is not only restricted to native cs.

Quoted 25 lines
Quoted 4 lines

For parallel configurations, there are other controllers from Microchip and some flash devices that operate similarly to AMD's parallel mode.

Yes, Tudor reminded me about these.

Quoted 18 lines
Quoted 17 lines
Quoted 13 lines

This layer would perform the following tasks:
- During probing, store information from all the connected flashes, whether in stacked or parallel mode, and present it as a single device to the MTD layer.
- Register callbacks through this new layer instead of spi-nor/core.c and handle MTD device registration.
- In stacked mode, select the appropriate spi-nor flash based on the address provided by the MTD layer during flash operations.
- Manage flash crossover operations in stacked mode.
- Ensure both connected flashes are identical in parallel mode.
- Handle odd byte count requests from the MTD layer during flash operations in parallel mode.

Quoted 2 lines

For implementing this the current DT binding need to be updated as follows.

So you want to go back to step 1 and redefine bindings? Is that worth?

Quoted 7 lines
Quoted 4 lines

The current bindings are effective if we only support identical flash devices or flashes of the same make but with different sizes connected in stacked mode. However, if we want to extend stacked support to include flashes of different makes in stacked mode,

The only actual feature the stacked mode brings is the ability to consider two devices like one. This is abstracted by hardware, this is a controller capability.

Stacked mode is a software abstraction rather than a controller feature or capability. At any given time, the controller communicates with one of the two connected flash devices, as determined by the requested address and data length. If an operation starts on one flash and ends on the other, the core needs to split it into two separate operations and adjust the data length accordingly.

Quoted 9 lines

The only way this can work is if the two storage devices are of the same kind and accept the same commands/init cycles.

If you consider two different devices, then there is no hardware abstraction anymore, the controller is no longer "smart" enough and you are back to the standard situation with two devices connected using their own independent CS, known by the host. In this case the "stacked-mode" bindings no longer apply. You need to describe the two chips independently in the DT, and your stacked feature in the controller can no longer be used.

As stated earlier stacked is not a controller feature but rather a software abstraction to assert the appropriate cs as per the requested address & data length.

Regards,
Amit

Quoted 39 lines

You need other bindings to support this case because it is a different situation. For this case, there was a mtd-concat approach (which was never merged). But this is really something different than the stacked mode in your controller because there is no specific hardware feature involved, it's just pure software.

Quoted 12 lines

the current
bindings may not be adequate. That's why I suggested updating the bindings to accommodate all possible scenario.

Quoted 8 lines
Quoted 7 lines

stacked-memories DT changes:
- Flash size information can be retrieved directly from the flash, so it has been removed from the DT binding.
- Each stacked flash will have its own flash node. This approach allows flashes of different makes and sizes to be stacked together, as each flash will be probed individually.

Quoted 5 lines
Quoted 2 lines

And how will you define partitions crossing device boundaries? I believe this constraint has been totally forgotten in this proposal.

According to the new binding proposal, one of the two flash nodes will have a partition that crosses the device boundary.

From a bindings perspective, it feels very awkward and I doubt it will be accepted. From a code perspective, you're gonna need to butcher the core...

Quoted 2 lines
Quoted 2 lines

The whole idea of stacking two devices this way was to simplify the user's life with a single device exposed and the controller handling itself

the CS changes.

Quoted 5 lines
Quoted 1 line

That is precisely what the current binding do.

That's true, but as I mentioned earlier, if we're not inclined to support stacked mode for flashes of different makes, then the current bindings are sufficient.

Thanks,
Miquèl

maintainer
#66 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hi Amit,

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

For implementing this the current DT binding need to be updated as follows.

So you want to go back to step 1 and redefine bindings? Is that worth?

Quoted 7 lines
Quoted 4 lines

The current bindings are effective if we only support identical flash devices or flashes of the same make but with different sizes connected in stacked mode. However, if we want to extend stacked support to include flashes of different makes in stacked mode,

The only actual feature the stacked mode brings is the ability to consider two devices like one. This is abstracted by hardware, this is a controller capability.

Quoted 6 lines

Stacked mode is a software abstraction rather than a controller feature or capability. At any given time, the controller communicates with one of the two connected flash devices, as determined by the requested address and data length. If an operation starts on one flash and ends on the other, the core needs to split it into two separate operations and adjust the data length accordingly.

I'm sorry, that was not my understanding, cf the initial RFC:

Subject: [RFC PATCH 0/3] Dual stacked/parallel memories bindings
Date: Fri, 12 Nov 2021 16:24:08 +0100

"[...] supporting specific SPI controller modes like Xilinx's where the controller can highly abstract the hardware and provide access to a single bigger device instead [...]"

Furthermore, I rapidly checked the Zynq7000 TRM, it suggests that the controller is capable of addressing the right memory itself based on the address, especially in linear mode?

https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Dual-SS-4-bit-Stacked-I/O

"The lower SPI flash memory should always be connected if the linear Quad-SPI memory subsystem is used, and the upper flash memory is optional. Total address space is 32 MB with a 25-bit address. In IO mode, the MSB of the address is defined by U_PAGE which is located at bit 28 of register 0xA0 . In Linear address mode, AXI address bit 24 determines the upper or lower memory page. All of the commands will be executed by the device selected by U_PAGE in I/O mode and address bit 24 in linear mode."

Anyway, you may decide to go down the "pure software" route, which is probably easier from an implementation perspective, but means you're gonna have to argue -again- in favor of the representation of a purely virtual device that is not hardware.

Cheers,
Miquèl

#67 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

Hello Miquel,

Quoted 28 lines

Hi Amit,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

For implementing this the current DT binding need to be updated as follows.

So you want to go back to step 1 and redefine bindings? Is that worth?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

The current bindings are effective if we only support identical flash devices or flashes of the same make but with different sizes connected in stacked mode. However, if we want to extend stacked support to include flashes of different makes in stacked mode,

The only actual feature the stacked mode brings is the ability to consider two devices like one. This is abstracted by hardware, this is a

controller capability.

Quoted 7 lines

Stacked mode is a software abstraction rather than a controller feature or capability. At any given time, the controller communicates with one of the two connected flash devices, as determined by the requested address and data length. If an operation starts on one flash and ends on the other, the core needs to split it into two separate operations and adjust the data length accordingly.

I'm sorry, that was not my understanding, cf the initial RFC:

Subject: [RFC PATCH 0/3] Dual stacked/parallel memories bindings
Date: Fri, 12 Nov 2021 16:24:08 +0100

Quoted 7 lines

"[...] supporting specific SPI controller modes like Xilinx's where the controller can highly abstract the hardware and provide access to a single bigger device instead [...]"

Furthermore, I rapidly checked the Zynq7000 TRM, it suggests that the controller is capable of addressing the right memory itself based on the address, especially in linear mode?

Yes, this is true only when operating in Linear Mode. In this mode, the Zynq 7000 can only perform read operations. Erase and write operations are possible only in I/O mode, so while operating in I/O mode the CS pins must be manually asserted by the driver according to the address and data length

Quoted 14 lines
	https://docs.amd.com/r/en-US/ug585-zynq-7000-SoC-TRM/Dual-SS-

4-bit-Stacked-I/O

"The lower SPI flash memory should always be connected if the linear Quad-SPI memory subsystem is used, and the upper flash memory is optional. Total address space is 32 MB with a 25-bit address. In IO mode, the MSB of the address is defined by U_PAGE which is located at bit 28 of register 0xA0 . In Linear address mode, AXI address bit 24 determines the upper or lower memory page. All of the commands will be executed by the device selected by U_PAGE in I/O mode and address bit 24 in linear mode."

Quoted 4 lines

Anyway, you may decide to go down the "pure software" route, which is probably easier from an implementation perspective, but means you're gonna have to argue -again- in favor of the representation of a purely virtual device that is not hardware.

Yes, that's correct, but I was planning to manage it through a new layer rather than using mtd-concat. As Tudor mentioned, I will start a new email thread outlining my proposal so we can resume the discussion on the patch moving forward.

Regards,
Amit

Quoted 3 lines

Cheers,
Miquèl

#68 lore raw

RE: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Tudor Ambarus

Hello Tudor,

Quoted 36 lines

-----Original Message-----
From: Tudor Ambarus <[email protected]>
Sent: Friday, February 9, 2024 4:36 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; git (AMD- Xilinx) <[email protected]>; [email protected]; Conor Dooley <[email protected]>; [email protected]
Subject: Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.

Quoted 5 lines · Amit Kumar
Quoted 5 lines

Something else to consider: I see that Micron has a twin quad mode:
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation-

b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500

Quoted 5 lines
Quoted 3 lines

The micron's "Separate Chip-Select and Clock Signals" resembles the AMD's dual parallel 8-bit.

Yes, I agree.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

Micron's "Shared Chip-Select and Clock Signals" differs from the AMD's stacked mode, as Micron uses DQ[3:0] and DQ[7:4], whereas AMD considers both as DQ[3:0].

Yes, correct.

Amit, please help me to assess this. I assume Micron and Microchip is using the same concepts as AMD uses for the "Dual Parallel 8-bit IO mode", but they call it "Twin Quad Mode".

That's accurate. It's the same concept.

Quoted 4 lines

I was wrong, the AMD datasheet [1] was misleading [2], it described the IOs for both flashes as IO[3:0], but later on in the "Table QSPI Interface Signals" the second flash is described with IO[7:4].

That’s correct.

Quoted 3 lines

The AMD's 8-bit Dual Flash Parallel Interface is using dedicated CS# and CLK# lines for each flash. As Micron does, isn't it?

Correct.

Quoted 9 lines

Micron says [3] that:
"The device contains two quad I/O die, each able to operate independently for a total of eight I/Os. The memory map applies to each die. Each die has internal registers for status, configuration, and device protection that can be set and read independently from one other.
Micron recommends that internal configuration settings for the two die be set identically."

Quoted 8 lines

it also says that:
"When using quad commands in XIO-SPI or when using QIO-SPI, DQ[3:0]/DQ[7:4] are I/O."

So I guess the upper layers just ask for a chunk of memory to be written and the controller handles the cs# lines automatically. How is the AMD controller working, do you have to drive the cs# lines manually, or you just set the parallel mode and the controller takes care of everything?

https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/Word-Format
In parallel mode, the driver sets both the CS_LOWER and CS_UPPER bits in the Cmd_FIFO_Data register(please refer the above link), and sets BUS_SEL to 2’b11 to utilize all 8 IO lines. The controller then manages the assertion and de-assertion of the CS# lines.

Quoted 4 lines

I assume this is how mchp is handling things, they seem to just set a bit the protocol into the QSPI_IFR.PROTTYP register field and that's all [4]. They even seem to write the registers of both flashes at the same time.

Yes, that's accurate, but the key distinction is that in Microchip, the QSPI controller has one CS# (referred to as QCS), whereas the AMD QSPI controller has 2 CS#(referred to as CS0 & CS1).

Regards,
Amit

Quoted 30 lines

In what regards the AMD's "dual stack interface", AMD is sharing the clock and IO lines and uses dedicated CS# lines for the flashes, whereas Micron shares the CS# and CLK# lines with different IO lines.

Amit, please study the architectures used by mchp, micron and amd and let us know if they are the same or they differ, and if they differ what are the differences.

I added Conor from mchp in cc, I see Nicolas is already there, and Bean from micron.

Thanks,
ta

[1]
https://docs.xilinx.com/r/en-US/am011-versal-acap-trm/QSPI-Flash-Interface-
Signals
[2]
https://docs.xilinx.com/viewer/attachment/dwmjhDJGICdJqD4swyVzcQ/fD8nv
4ry78xM0_EF5kv4mA
[3]
https://media-www.micron.com/-
/media/client/global/documents/products/data-sheet/nor-flash/serial- nor/mt25t/generation- b/mt25t_qljs_l_512_xba_0.pdf?rev=de70b770c5dc4da8b8ead06b57c03500
[4]
https://ww1.microchip.com/downloads/aemDocuments/documents/MPU32/
ProductDocuments/DataSheets/SAMA7G5-Series-Data-Sheet- DS60001765.pdf

#69 lore raw

Re: [PATCH v11 07/10] mtd: spi-nor: Add stacked memories support in spi-nor

In reply to Amit Kumar Mahapatra
Quoted 4 lines · Amit Kumar Mahapatra

The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.

Too much restrictions, isn't it? Have you thought about adding a layer on top of SPI NOR managing the stacked/parallel flashes?

#70 lore raw

PATCH v11 8/10 spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver

In reply to Amit Kumar Mahapatra

GQSPI supports two chip select CS0 & CS1. Update the driver to assert/de-assert the appropriate chip select as per the bits set in qspi->cs_index_mask.

---
 drivers/spi/spi-zynqmp-gqspi.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +13 -8
index 9a46b2478f4e..c5d12ddd4ab3 100644
@@ -154,6 +154,9 @@
 #define GQSPI_FREQ_100MHZ	100000000
 #define GQSPI_FREQ_150MHZ	150000000
 
+#define GQSPI_SELECT_LOWER_CS  BIT(0)
+#define GQSPI_SELECT_UPPER_CS  BIT(1)
+
 #define SPI_AUTOSUSPEND_TIMEOUT		3000
 enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA};
 
@@ -465,15 +468,17 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
 
 	genfifoentry |= GQSPI_GENFIFO_MODE_SPI;
 
+	if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
+		zynqmp_gqspi_selectslave(xqspi,
+					 GQSPI_SELECT_FLASH_CS_UPPER,
+					 GQSPI_SELECT_FLASH_BUS_LOWER);
+	} else if (qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) {
+		zynqmp_gqspi_selectslave(xqspi,
+					 GQSPI_SELECT_FLASH_CS_LOWER,
+					 GQSPI_SELECT_FLASH_BUS_LOWER);
+	}
+	genfifoentry |= xqspi->genfifobus;
 	if (!is_high) {
-		if (!spi_get_chipselect(qspi, 0)) {
-			xqspi->genfifobus = GQSPI_GENFIFO_BUS_LOWER;
-			xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER;
-		} else {
-			xqspi->genfifobus = GQSPI_GENFIFO_BUS_UPPER;
-			xqspi->genfifocs = GQSPI_GENFIFO_CS_UPPER;
-		}
-		genfifoentry |= xqspi->genfifobus;
 		genfifoentry |= xqspi->genfifocs;
 		genfifoentry |= GQSPI_GENFIFO_CS_SETUP;
 	} else {
Signature · 1 line
2.17.1
#71 lore raw

PATCH v11 9/10 mtd: spi-nor: Add parallel memories support in spi-nor

In reply to Amit Kumar Mahapatra

The current implementation assumes that a maximum of two flashes are connected in parallel mode. The QSPI controller splits the data evenly between both the flashes so, both the flashes that are connected in parallel mode should be identical.
During each operation SPI-NOR sets 0th bit for CS0 & 1st bit for CS1 in nor->spimem->spi->cs_index_mask. The QSPI driver will then assert/de-assert CS0 & CS1.
Write operation in parallel mode are performed in page size * 2 chunks as each write operation results in writing both the flashes. For doubling the address space each operation is performed at addr/2 flash offset, where addr is the address specified by the user.

---
 drivers/mtd/spi-nor/core.c      | 409 +++++++++++++++++++++++++-------
 drivers/mtd/spi-nor/core.h      |   4 +
 drivers/mtd/spi-nor/micron-st.c |   5 +
 3 files changed, 333 insertions(+), 85 deletions(-)
drivers/mtd/spi-nor/core.c +324 -85
index e990be7c7eb6..2e6cc45341ed 100644
@@ -470,17 +470,29 @@ int spi_nor_read_sr(struct spi_nor *nor, u8 *sr)
 			op.data.nbytes = 2;
 		}
 
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			op.data.nbytes = 2;
+
 		spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
 
 		ret = spi_mem_exec_op(nor->spimem, &op);
 	} else {
-		ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr,
-						      1);
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			ret = spi_nor_controller_ops_read_reg(nor,
+							      SPINOR_OP_RDSR,
+							      sr, 2);
+		else
+			ret = spi_nor_controller_ops_read_reg(nor,
+							      SPINOR_OP_RDSR,
+							      sr, 1);
 	}
 
 	if (ret)
 		dev_dbg(nor->dev, "error %d reading SR\n", ret);
 
+	if (nor->flags & SNOR_F_HAS_PARALLEL)
+		sr[0] |= sr[1];
+
 	return ret;
 }
 
@@ -1824,6 +1836,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	struct spi_nor_flash_parameter *params;
 	u32 addr, len, offset, cur_cs_num = 0;
 	uint32_t rem;
+	u32 n_flash = 1;
 	int ret;
 	u64 sz;
 
@@ -1833,6 +1846,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	params = spi_nor_get_params(nor, 0);
 	sz = params->size;
 
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
 	if (spi_nor_has_uniform_erase(nor)) {
 		div_u64_rem(instr->len, mtd->erasesize, &rem);
 		if (rem)
@@ -1854,53 +1870,82 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		if (ret)
 			goto erase_err;
 
-		while (cur_cs_num < nor->num_flash) {
-			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
+			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
 			ret = spi_nor_erase_chip(nor);
 			spi_nor_unlock_device(nor);
 			if (ret)
 				goto erase_err;
 
 			/*
-			 * Scale the timeout linearly with the size of the flash, with
-			 * a minimum calibrated to an old 2MB flash. We could try to
-			 * pull these from CFI/SFDP, but these values should be good
-			 * enough for now.
-			 */
+			* Scale the timeout linearly with the size of the flash, with
+			* a minimum calibrated to an old 2MB flash. We could try to
+			* pull these from CFI/SFDP, but these values should be good
+			* enough for now.
+			*/
 			timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
-				      CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
-				      (unsigned long)(params->size / SZ_2M));
+					CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
+					(unsigned long)(mtd->size / SZ_2M));
 			ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
 			if (ret)
 				goto erase_err;
-			cur_cs_num++;
-		}
 
+		} else {
+			while (cur_cs_num < n_flash) {
+				nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
+				ret = spi_nor_erase_chip(nor);
+				spi_nor_unlock_device(nor);
+				if (ret)
+					goto erase_err;
+
+				/*
+				 * Scale the timeout linearly with the size of the flash, with
+				 * a minimum calibrated to an old 2MB flash. We could try to
+				 * pull these from CFI/SFDP, but these values should be good
+				 * enough for now.
+				 */
+				timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
+					      CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
+						(unsigned long)(params->size / SZ_2M));
+				ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
+				if (ret)
+					goto erase_err;
+
+				cur_cs_num++;
+				params = spi_nor_get_params(nor, cur_cs_num);
+			}
+		}
 	/* REVISIT in some cases we could speed up erasing large regions
 	 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
 	 * to use "small sector erase", but that's not always optimal.
 	 */
-
 	/* "sector"-at-a-time erase */
 	} else if (spi_nor_has_uniform_erase(nor)) {
-		/* Determine the flash from which the operation need to start */
-		while ((cur_cs_num < nor->num_flash) && (addr > sz - 1)) {
-			cur_cs_num++;
-			params = spi_nor_get_params(nor, cur_cs_num);
-			sz += params->size;
+		if (!(nor->flags & SNOR_F_HAS_PARALLEL)) {
+			while ((cur_cs_num < n_flash) && (addr > sz - 1)) {
+				cur_cs_num++;
+				params = spi_nor_get_params(nor, cur_cs_num);
+				sz += params->size;
+			}
 		}
-
 		while (len) {
 			ret = spi_nor_lock_device(nor);
 			if (ret)
 				goto erase_err;
 
-			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
 			offset = addr;
 			if (nor->flags & SNOR_F_HAS_STACKED) {
 				params = spi_nor_get_params(nor, cur_cs_num);
 				offset -= (sz - params->size);
 			}
+			nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
+			if (nor->flags & SNOR_F_HAS_PARALLEL) {
+				u64 aux = offset;
+
+				ret = do_div(aux, n_flash);
+				offset = aux;
+				nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
+			}
 
 			ret = spi_nor_erase_sector(nor, offset);
 			spi_nor_unlock_device(nor);
@@ -1923,34 +1968,42 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 				sz += params->size;
 			}
 		}
-
 	/* erase multiple sectors */
 	} else {
-		u64 erase_len = 0;
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
+			u64 aux = offset;
 
-		/* Determine the flash from which the operation need to start */
-		while ((cur_cs_num < nor->num_flash) && (addr > sz - 1)) {
-			cur_cs_num++;
-			params = spi_nor_get_params(nor, cur_cs_num);
-			sz += params->size;
-		}
-		/* perform multi sector erase onec per Flash*/
-		while (len) {
-			erase_len = (len > (sz - addr)) ? (sz - addr) : len;
-			offset = addr;
-			nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
-			if (nor->flags & SNOR_F_HAS_STACKED) {
-				params = spi_nor_get_params(nor, cur_cs_num);
-				offset -= (sz - params->size);
-			}
-			ret = spi_nor_erase_multi_sectors(nor, offset, erase_len);
+			ret = do_div(aux, n_flash);
+			offset = aux;
+			ret = spi_nor_erase_multi_sectors(nor, addr, len);
 			if (ret)
 				goto erase_err;
-			len -= erase_len;
-			addr += erase_len;
-			cur_cs_num++;
-			params = spi_nor_get_params(nor, cur_cs_num);
-			sz += params->size;
+		} else {
+			u64 erase_len = 0;
+
+			/* Determine the flash from which the operation need to start */
+			while ((cur_cs_num < n_flash) && (addr > sz - 1)) {
+				cur_cs_num++;
+				params = spi_nor_get_params(nor, cur_cs_num);
+				sz += params->size;
+			}
+			/* perform multi sector erase onec per Flash*/
+			while (len) {
+				erase_len = (len > (sz - addr)) ? (sz - addr) : len;
+				offset = addr;
+				nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
+				if (nor->flags & SNOR_F_HAS_STACKED) {
+					params = spi_nor_get_params(nor, cur_cs_num);
+					offset -= (sz - params->size);
+				}
+				ret = spi_nor_erase_multi_sectors(nor, offset, erase_len);
+				if (ret)
+					goto erase_err;
+				len -= erase_len;
+				addr += erase_len;
+				params = spi_nor_get_params(nor, cur_cs_num);
+				sz += params->size;
+			}
 		}
 	}
 
@@ -2144,9 +2197,12 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	struct spi_nor_flash_parameter *params;
 	ssize_t ret, read_len, len_lock =  len;
+	bool is_ofst_odd = false;
 	loff_t from_lock = from;
 	u32 cur_cs_num = 0;
-	u64 sz;
+	u_char *readbuf;
+	u32 n_flash = 1;
+	u64 sz = 0;
 
 	dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
 
@@ -2157,23 +2213,54 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	params = spi_nor_get_params(nor, 0);
 	sz = params->size;
 
-	/* Determine the flash from which the operation need to start */
-	while ((cur_cs_num < nor->num_flash) && (from > sz - 1)) {
-		cur_cs_num++;
-		params = spi_nor_get_params(nor, cur_cs_num);
-		sz += params->size;
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
+	/*
+	 * When even number of flashes are connected in parallel and the
+	 * requested read length is odd then read (len + 1) from offset + 1
+	 * and ignore offset[0] data.
+	 */
+	if ((nor->flags & SNOR_F_HAS_PARALLEL) && (!(n_flash % 2)) && (from & 0x01)) {
+		from = (loff_t)(from - 1);
+		len = (size_t)(len + 1);
+		is_ofst_odd = true;
+		readbuf = kmalloc(len, GFP_KERNEL);
+		if (!readbuf)
+			return -ENOMEM;
+	} else {
+		readbuf = buf;
 	}
+
+	if (!(nor->flags & SNOR_F_HAS_PARALLEL)) {
+		/* Determine the flash from which the operation need to start */
+		while ((cur_cs_num < n_flash) && (from > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
+	}
+
 	while (len) {
 		loff_t addr = from;
 
-		nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
-		read_len = (len > (sz - addr)) ? (sz - addr) : len;
-		params = spi_nor_get_params(nor, cur_cs_num);
-		addr -= (sz - params->size);
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
+			u64 aux = addr;
+
+			ret = do_div(aux, n_flash);
+			addr = aux;
+			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
+			read_len = len;
+		} else {
+			nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
+			read_len = (len > (sz - addr)) ? (sz - addr) : len;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			addr -= (sz - params->size);
+		}
 
 		addr = spi_nor_convert_addr(nor, addr);
 
-		ret = spi_nor_read_data(nor, addr, len, buf);
+		ret = spi_nor_read_data(nor, addr, read_len, readbuf);
 		if (ret == 0) {
 			/* We shouldn't see 0-length reads */
 			ret = -EIO;
@@ -2183,8 +2270,20 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 			goto read_err;
 
 		WARN_ON(ret > read_len);
-		*retlen += ret;
+		if (is_ofst_odd) {
+			/*
+			 * Cannot read from odd offset in parallel mode.
+			 * So read len + 1 from offset + 1 from the flash
+			 * and copy len data from readbuf[1].
+			 */
+			memcpy(buf, (readbuf + 1), (len - 1));
+			*retlen += (ret - 1);
+		} else {
+			*retlen += ret;
+		}
 		buf += ret;
+		if (!is_ofst_odd)
+			readbuf += ret;
 		from += ret;
 		len -= ret;
 
@@ -2202,8 +2301,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	ret = 0;
 
 read_err:
-	spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock);
+	if (is_ofst_odd)
+		kfree(readbuf);
 
+	spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock);
 	return ret;
 }
 
@@ -2219,6 +2320,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct spi_nor_flash_parameter *params;
 	size_t page_offset, page_remain, i;
 	u32 page_size, cur_cs_num = 0;
+	u32 n_flash = 1;
 	ssize_t ret;
 	u64 sz;
 
@@ -2232,11 +2334,41 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	page_size = params->page_size;
 	sz = params->size;
 
-	/* Determine the flash from which the operation need to start */
-	while ((cur_cs_num < nor->num_flash) && (to > sz - 1)) {
-		cur_cs_num++;
-		params = spi_nor_get_params(nor, cur_cs_num);
-		sz += params->size;
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
+	if (nor->flags & SNOR_F_HAS_PARALLEL) {
+		/*
+		 * When even number of flashes are connected in parallel and the
+		 * requested write length is odd then first write 2 bytes.
+		 */
+		if ((!(n_flash % 2)) && (to & 0x01)) {
+			u8 two[2] = {0xff, buf[0]};
+			size_t written_len;
+
+			ret = spi_nor_write(mtd, to & ~1, 2, &written_len, two);
+			if (ret < 0)
+				return ret;
+			*retlen += 1; /* We've written only one actual byte */
+			++buf;
+			--len;
+			++to;
+		}
+		/*
+		 * Write operation are performed in page size chunks and in
+		 * parallel memories both the flashes are written simultaneously,
+		 * hence increase the page_size in multiple of the number of flash
+		 * connected in parallel.
+		 */
+		page_size *= n_flash;
+
+	} else {
+		/* Determine the flash from which the operation need to start */
+		while ((cur_cs_num < n_flash) && (to > sz - 1)) {
+			cur_cs_num++;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			sz += params->size;
+		}
 	}
 
 	for (i = 0; i < len; ) {
@@ -2258,9 +2390,17 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* the size of data remaining on the first page */
 		page_remain = min_t(size_t, page_size - page_offset, len - i);
 
-		nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
-		params = spi_nor_get_params(nor, cur_cs_num);
-		addr -= (sz - params->size);
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
+			u64 aux = addr;
+
+			ret = do_div(aux, n_flash);
+			addr = aux;
+			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
+		} else {
+			nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
+			params = spi_nor_get_params(nor, cur_cs_num);
+			addr -= (sz - params->size);
+		}
 
 		addr = spi_nor_convert_addr(nor, addr);
 
@@ -2701,7 +2841,15 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 		if (!erase)
 			return -EINVAL;
 		nor->erase_opcode = erase->opcode;
-		mtd->erasesize = erase->size;
+		/*
+		 * In parallel-memories the erase operation is
+		 * performed on both the flashes simultaneously
+		 * so, double the erasesize.
+		 */
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			mtd->erasesize = erase->size * 2;
+		else
+			mtd->erasesize = erase->size;
 		return 0;
 	}
 
@@ -2719,7 +2867,15 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 	if (!erase)
 		return -EINVAL;
 
-	mtd->erasesize = erase->size;
+	/*
+	 * In parallel-memories the erase operation is
+	 * performed on both the flashes simultaneously
+	 * so, double the erasesize.
+	 */
+	if (nor->flags & SNOR_F_HAS_PARALLEL)
+		mtd->erasesize = erase->size * 2;
+	else
+		mtd->erasesize = erase->size;
 	return 0;
 }
 
@@ -3060,6 +3216,17 @@ static int spi_nor_late_init_params(struct spi_nor *nor)
 
 		nor->num_flash++;
 	}
+	idx = 0;
+	while (idx < SNOR_FLASH_CNT_MAX) {
+		rc = of_property_read_u64_index(np, "parallel-memories", idx, &flash_size[idx]);
+		if (rc)
+			break;
+		idx++;
+		if (!(nor->flags & SNOR_F_HAS_PARALLEL))
+			nor->flags |= SNOR_F_HAS_PARALLEL;
+
+		nor->num_flash++;
+	}
 
 	/*
 	 * By default one flash device should be connected
@@ -3068,7 +3235,7 @@ static int spi_nor_late_init_params(struct spi_nor *nor)
 	if (!nor->num_flash)
 		nor->num_flash = 1;
 
-	if (nor->flags & SNOR_F_HAS_STACKED) {
+	if (nor->flags & (SNOR_F_HAS_STACKED | SNOR_F_HAS_PARALLEL)) {
 		for (idx = 1; idx < nor->num_flash; idx++) {
 			params = spi_nor_get_params(nor, idx);
 			params = devm_kzalloc(nor->dev, sizeof(*params), GFP_KERNEL);
@@ -3289,10 +3456,14 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable)
 static int spi_nor_quad_enable(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params;
+	u32 n_flash = 1;
 	int err, idx;
 
-	for (idx = 0; idx < nor->num_flash; idx++) {
-		params = spi_nor_get_params(nor, idx);
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
+	if (nor->flags & SNOR_F_HAS_PARALLEL) {
+		params = spi_nor_get_params(nor, 0);
 		if (!params->quad_enable)
 			return 0;
 
@@ -3300,14 +3471,32 @@ static int spi_nor_quad_enable(struct spi_nor *nor)
 		      spi_nor_get_protocol_width(nor->write_proto) == 4))
 			return 0;
 		/*
-		 * Set the appropriate CS index before
-		 * issuing the command.
+		 * In parallel mode both chip selects i.e., CS0 &
+		 * CS1 need to be asserted simulatneously.
 		 */
-		nor->spimem->spi->cs_index_mask = 0x01 << idx;
-
+		nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
 		err = params->quad_enable(nor);
 		if (err)
 			return err;
+	} else {
+		for (idx = 0; idx < n_flash; idx++) {
+			params = spi_nor_get_params(nor, idx);
+			if (!params->quad_enable)
+				return 0;
+
+			if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 ||
+			      spi_nor_get_protocol_width(nor->write_proto) == 4))
+				return 0;
+			/*
+			 * Set the appropriate CS index before
+			 * issuing the command.
+			 */
+			nor->spimem->spi->cs_index_mask = 1 << idx;
+
+			err = params->quad_enable(nor);
+			if (err)
+				return err;
+		}
 	}
 	return err;
 }
@@ -3341,8 +3530,12 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
 
 static int spi_nor_init(struct spi_nor *nor)
 {
+	u32 n_flash = 1;
 	int err, idx;
 
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
 	err = spi_nor_set_octal_dtr(nor, true);
 	if (err) {
 		dev_dbg(nor->dev, "octal mode not supported\n");
@@ -3382,15 +3575,26 @@ static int spi_nor_init(struct spi_nor *nor)
 		 */
 		WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET,
 			  "enabling reset hack; may not recover from unexpected reboots\n");
-		for (idx = 0; idx < nor->num_flash; idx++) {
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
 			/*
-			 * Select the appropriate CS index before
-			 * issuing the command.
+			 * In parallel mode both chip selects i.e., CS0 &
+			 * CS1 need to be asserted simulatneously.
 			 */
-			nor->spimem->spi->cs_index_mask = 0x01 << idx;
+			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
 			err = spi_nor_set_4byte_addr_mode(nor, true);
 			if (err)
 				return err;
+		} else {
+			for (idx = 0; idx < n_flash; idx++) {
+				/*
+				 * Select the appropriate CS index before
+				 * issuing the command.
+				 */
+				nor->spimem->spi->cs_index_mask = 1 << idx;
+				err = spi_nor_set_4byte_addr_mode(nor, true);
+				if (err)
+					return err;
+			}
 		}
 	}
 
@@ -3505,19 +3709,23 @@ static void spi_nor_put_device(struct mtd_info *mtd)
 
 static void spi_nor_restore(struct spi_nor *nor)
 {
+	u32 n_flash = 1;
 	int ret;
 	int idx;
 
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
 	/* restore the addressing mode */
 	if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
 	    nor->flags & SNOR_F_BROKEN_RESET) {
-		for (idx = 0; idx < nor->num_flash; idx++) {
+		if (nor->flags & SNOR_F_HAS_PARALLEL) {
 			/*
-			 * Select the appropriate CS index before
-			 * issuing the command.
+			 * In parallel mode both chip selects i.e., CS0 &
+			 * CS1 need to be asserted simulatneously.
 			 */
-			nor->spimem->spi->cs_index_mask = 1 << idx;
-			ret = spi_nor_set_4byte_addr_mode(nor, false);
+			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
+			spi_nor_set_4byte_addr_mode(nor, false);
 			if (ret)
 				/*
 				 * Do not stop the execution in the hope that the flash
@@ -3527,6 +3735,24 @@ static void spi_nor_restore(struct spi_nor *nor)
 				dev_err(nor->dev,
 					"Failed to exit 4-byte address mode, err = %d\n",
 					ret);
+		} else {
+			for (idx = 0; idx < n_flash; idx++) {
+				/*
+				 * Select the appropriate CS index before
+				 * issuing the command.
+				 */
+				nor->spimem->spi->cs_index_mask = 1 << idx;
+				ret = spi_nor_set_4byte_addr_mode(nor, false);
+				if (ret)
+					/*
+					 * Do not stop the execution in the hope that the
+					 * flash will default to the 3-byte address mode
+					 * after the software reset.
+					 */
+					dev_err(nor->dev,
+						"Failed to exit 4-byte address mode, err = %d\n",
+						ret);
+			}
 		}
 	}
 
@@ -3595,11 +3821,15 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	struct mtd_info *mtd = &nor->mtd;
 	struct device *dev = nor->dev;
 	u64 total_sz = 0;
+	u32 n_flash = 1;
 	int idx;
 
 	spi_nor_set_mtd_locking_ops(nor);
 	spi_nor_set_mtd_otp_ops(nor);
 
+	if (nor->num_flash)
+		n_flash = nor->num_flash;
+
 	mtd->dev.parent = dev;
 	if (!mtd->name)
 		mtd->name = dev_name(dev);
@@ -3613,8 +3843,17 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	else
 		mtd->_erase = spi_nor_erase;
 	mtd->writesize = params->writesize;
-	mtd->writebufsize = params->page_size;
-	for (idx = 0; idx < nor->num_flash; idx++) {
+	/*
+	 * In parallel-memories the write operation is
+	 * performed on both the flashes simultaneously
+	 * one page per flash, so double the writebufsize.
+	 */
+	if (nor->flags & SNOR_F_HAS_PARALLEL)
+		mtd->writebufsize = params->page_size << 1;
+	else
+		mtd->writebufsize = params->page_size;
+
+	for (idx = 0; idx < n_flash; idx++) {
 		params = spi_nor_get_params(nor, idx);
 		total_sz += params->size;
 	}
drivers/mtd/spi-nor/core.h +4 -0
index b2997eca7551..6c3009796013 100644
@@ -21,6 +21,9 @@
 /* In single configuration enable CS0 */
 #define SPI_NOR_ENABLE_CS0     BIT(0)
 
+/* In parallel configuration enable multiple CS */
+#define SPI_NOR_ENABLE_MULTI_CS	(BIT(0) | BIT(1))
+
 /* Standard SPI NOR flash operations. */
 #define SPI_NOR_READID_OP(naddr, ndummy, buf, len)			\
 	SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0),			\
@@ -144,6 +147,7 @@ enum spi_nor_option_flags {
 	SNOR_F_ECC		= BIT(15),
 	SNOR_F_NO_WP		= BIT(16),
 	SNOR_F_HAS_STACKED      = BIT(17),
+	SNOR_F_HAS_PARALLEL	= BIT(18),
 };
 
 struct spi_nor_read_command {
drivers/mtd/spi-nor/micron-st.c +5 -0
index 813a5b1a269b..577121ebd6e8 100644
@@ -478,6 +478,9 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr)
 			op.data.nbytes = 2;
 		}
 
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			op.data.nbytes = 2;
+
 		spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
 
 		ret = spi_mem_exec_op(nor->spimem, &op);
@@ -489,6 +492,8 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr)
 	if (ret)
 		dev_dbg(nor->dev, "error %d reading FSR\n", ret);
 
+	if (nor->flags & SNOR_F_HAS_PARALLEL)
+		fsr[0] &= fsr[1];
 	return ret;
 }
 
Signature · 1 line
2.17.1
#72 lore raw

Re: [PATCH v11 09/10] mtd: spi-nor: Add parallel memories support in spi-nor

kernel test robot noticed the following build warnings:

Hi Amit,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-linus]
[also build test WARNING on linus/master v6.7-rc2]
[cannot apply to mtd/spi-nor/next lee-mfd/for-mfd-fixes next-20231124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Amit-Kumar-Mahapatra/ALSA-hda-cs35l56-Use-set-get-APIs-to-access-spi-chip_select/20231125-182341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-linus
patch link:    https://lore.kernel.org/r/20231125092137.2948-10-amit.kumar-mahapatra%40amd.com
patch subject: [PATCH v11 09/10] mtd: spi-nor: Add parallel memories support in spi-nor
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20231126/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231126/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/mtd/spi-nor/core.c:1974:14: warning: variable 'offset' is uninitialized when used here [-Wuninitialized]

                           u64 aux = offset;
                                     ^~~~~~
   drivers/mtd/spi-nor/core.c:1837:23: note: initialize the variable 'offset' to silence this warning
           u32 addr, len, offset, cur_cs_num = 0;
                                ^
                                 = 0
>> drivers/mtd/spi-nor/core.c:3729:8: warning: variable 'ret' is uninitialized when used here [-Wuninitialized]
                           if (ret)
                               ^~~
   drivers/mtd/spi-nor/core.c:3713:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0

2 warnings generated.

vim +/ret +3729 drivers/mtd/spi-nor/core.c

3709
3710 static void spi_nor_restore(struct spi_nor *nor)
3711 {
3712 u32 n_flash = 1;
3713 int ret;
3714 int idx;
3715
3716 if (nor->num_flash)
3717 n_flash = nor->num_flash;
3718
3719 /* restore the addressing mode */
3720 if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) &&
3721 nor->flags & SNOR_F_BROKEN_RESET) {
3722 if (nor->flags & SNOR_F_HAS_PARALLEL) {
3723 /*
3724 * In parallel mode both chip selects i.e., CS0 &
3725 * CS1 need to be asserted simulatneously.
3726 */
3727 nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
3728 spi_nor_set_4byte_addr_mode(nor, false);

> 3729				if (ret)

3730 /*
3731 * Do not stop the execution in the hope that the flash
3732 * will default to the 3-byte address mode after the
3733 * software reset.
3734 */
3735 dev_err(nor->dev,
3736 "Failed to exit 4-byte address mode, err = %d\n",
3737 ret);
3738 } else {
3739 for (idx = 0; idx < n_flash; idx++) {
3740 /*
3741 * Select the appropriate CS index before
3742 * issuing the command.
3743 */
3744 nor->spimem->spi->cs_index_mask = 1 << idx;
3745 ret = spi_nor_set_4byte_addr_mode(nor, false);
3746 if (ret)
3747 /*
3748 * Do not stop the execution in the hope that the
3749 * flash will default to the 3-byte address mode
3750 * after the software reset.
3751 */
3752 dev_err(nor->dev,
3753 "Failed to exit 4-byte address mode, err = %d\n",
3754 ret);
3755 }
3756 }
3757 }
3758
3759 if (nor->flags & SNOR_F_SOFT_RESET)
3760 spi_nor_soft_reset(nor);
3761 }
3762

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#73 lore raw

Re: [PATCH v11 09/10] mtd: spi-nor: Add parallel memories support in spi-nor

In reply to Amit Kumar Mahapatra

Hi Amit,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Amit-Kumar-Mahapatra/ALSA-hda-cs35l56-Use-set-get-APIs-to-access-spi-chip_select/20231125-182341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-linus
patch link:    https://lore.kernel.org/r/20231125092137.2948-10-amit.kumar-mahapatra%40amd.com
patch subject: [PATCH v11 09/10] mtd: spi-nor: Add parallel memories support in spi-nor
config: powerpc64-randconfig-r071-20231127 (https://download.01.org/0day-ci/archive/20231202/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce: (https://download.01.org/0day-ci/archive/20231202/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/mtd/spi-nor/core.c:1974 spi_nor_erase() error: uninitialized symbol 'offset'. drivers/mtd/spi-nor/core.c:3729 spi_nor_restore() error: uninitialized symbol 'ret'.

vim +/offset +1974 drivers/mtd/spi-nor/core.c

b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1833  static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1834  {
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1835  	struct spi_nor *nor = mtd_to_spi_nor(mtd);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1836  	struct spi_nor_flash_parameter *params;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1837  	u32 addr, len, offset, cur_cs_num = 0;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1838  	uint32_t rem;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1839  	u32 n_flash = 1;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1840  	int ret;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1841  	u64 sz;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1842  
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1843  	dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1844  			(long long)instr->len);
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1845  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1846  	params = spi_nor_get_params(nor, 0);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1847  	sz = params->size;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1848  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1849  	if (nor->num_flash)
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1850  		n_flash = nor->num_flash;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1851  
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  1852  	if (spi_nor_has_uniform_erase(nor)) {
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1853  		div_u64_rem(instr->len, mtd->erasesize, &rem);
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1854  		if (rem)
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1855  			return -EINVAL;
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  1856  	}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1857  
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1858  	addr = instr->addr;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1859  	len = instr->len;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1860  
e96d4605b024495 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  1861  	ret = spi_nor_prep_and_lock_pe(nor, instr->addr, instr->len);
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1862  	if (ret)
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1863  		return ret;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1864  
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1865  	/* whole-chip erase? */
e99ca98f1d7190c drivers/mtd/spi-nor/spi-nor.c Ricardo Ribalda      2016-12-02  1866  	if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) {
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1867  		unsigned long timeout;
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1868  
74df43b3f626a35 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  1869  		ret = spi_nor_lock_device(nor);
bce679e5ae3a388 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-11-02  1870  		if (ret)
bce679e5ae3a388 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-11-02  1871  			goto erase_err;
05241aead9b98c2 drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-11-05  1872  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1873  		if (nor->flags & SNOR_F_HAS_PARALLEL) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1874  			nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1875  			ret = spi_nor_erase_chip(nor);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1876  			spi_nor_unlock_device(nor);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1877  			if (ret)
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1878  				goto erase_err;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1879  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1880  			/*
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1881  			* Scale the timeout linearly with the size of the flash, with
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1882  			* a minimum calibrated to an old 2MB flash. We could try to
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1883  			* pull these from CFI/SFDP, but these values should be good
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1884  			* enough for now.
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1885  			*/
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1886  			timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1887  					CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1888  					(unsigned long)(mtd->size / SZ_2M));
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1889  			ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1890  			if (ret)
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1891  				goto erase_err;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1892  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1893  		} else {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1894  			while (cur_cs_num < n_flash) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1895  				nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
7380f79c111cf90 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-10-29  1896  				ret = spi_nor_erase_chip(nor);
74df43b3f626a35 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  1897  				spi_nor_unlock_device(nor);
7380f79c111cf90 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-10-29  1898  				if (ret)
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1899  					goto erase_err;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1900  
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1901  				/*
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1902  				 * Scale the timeout linearly with the size of the flash, with
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1903  				 * a minimum calibrated to an old 2MB flash. We could try to
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1904  				 * pull these from CFI/SFDP, but these values should be good
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1905  				 * enough for now.
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1906  				 */
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1907  				timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1908  					      CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1909  						(unsigned long)(params->size / SZ_2M));
09b6a377687b885 drivers/mtd/spi-nor/spi-nor.c Furquan Shaikh       2015-09-18  1910  				ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
dfa9c0cba4ea20e drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-08-06  1911  				if (ret)
dfa9c0cba4ea20e drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-08-06  1912  					goto erase_err;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1913  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1914  				cur_cs_num++;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1915  				params = spi_nor_get_params(nor, cur_cs_num);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1916  			}
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1917  		}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1918  	/* REVISIT in some cases we could speed up erasing large regions
b02e7f3ef0beb72 drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-04-08  1919  	 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1920  	 * to use "small sector erase", but that's not always optimal.
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1921  	 */
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1922  	/* "sector"-at-a-time erase */
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  1923  	} else if (spi_nor_has_uniform_erase(nor)) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1924  		if (!(nor->flags & SNOR_F_HAS_PARALLEL)) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1925  			while ((cur_cs_num < n_flash) && (addr > sz - 1)) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1926  				cur_cs_num++;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1927  				params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1928  				sz += params->size;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1929  			}
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1930  		}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1931  		while (len) {
74df43b3f626a35 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  1932  			ret = spi_nor_lock_device(nor);
bce679e5ae3a388 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-11-02  1933  			if (ret)
bce679e5ae3a388 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-11-02  1934  				goto erase_err;
05241aead9b98c2 drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-11-05  1935  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1936  			offset = addr;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1937  			if (nor->flags & SNOR_F_HAS_STACKED) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1938  				params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1939  				offset -= (sz - params->size);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1940  			}
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1941  			nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1942  			if (nor->flags & SNOR_F_HAS_PARALLEL) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1943  				u64 aux = offset;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1944  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1945  				ret = do_div(aux, n_flash);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1946  				offset = aux;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1947  				nor->spimem->spi->cs_index_mask = SPI_NOR_ENABLE_MULTI_CS;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1948  			}
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1949  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1950  			ret = spi_nor_erase_sector(nor, offset);
74df43b3f626a35 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  1951  			spi_nor_unlock_device(nor);
c67cbb839da9cc2 drivers/mtd/spi-nor/spi-nor.c Brian Norris         2015-11-10  1952  			if (ret)
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1953  				goto erase_err;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1954  
dfa9c0cba4ea20e drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-08-06  1955  			ret = spi_nor_wait_till_ready(nor);
dfa9c0cba4ea20e drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-08-06  1956  			if (ret)
dfa9c0cba4ea20e drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-08-06  1957  				goto erase_err;
786a0a75d0f34a8 drivers/mtd/spi-nor/core.c    Tudor Ambarus        2021-03-06  1958  
786a0a75d0f34a8 drivers/mtd/spi-nor/core.c    Tudor Ambarus        2021-03-06  1959  			addr += mtd->erasesize;
786a0a75d0f34a8 drivers/mtd/spi-nor/core.c    Tudor Ambarus        2021-03-06  1960  			len -= mtd->erasesize;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1961  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1962  			/*
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1963  			 * Flash cross over condition in stacked mode.
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1964  			 */
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1965  			if ((nor->flags & SNOR_F_HAS_STACKED) && (addr > sz - 1)) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1966  				cur_cs_num++;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1967  				params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1968  				sz += params->size;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1969  			}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  1970  		}
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  1971  	/* erase multiple sectors */
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1972  	} else {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1973  		if (nor->flags & SNOR_F_HAS_PARALLEL) {
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25 @1974  			u64 aux = offset;
                                                                                                                  ^^^^^^

offset hasn't been initialized yet.

08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1975  
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1976  			ret = do_div(aux, n_flash);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1977  			offset = aux;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1978  			ret = spi_nor_erase_multi_sectors(nor, addr, len);
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1979  			if (ret)
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1980  				goto erase_err;
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  1981  		} else {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1982  			u64 erase_len = 0;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1983  
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1984  			/* Determine the flash from which the operation need to start */
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1985  			while ((cur_cs_num < n_flash) && (addr > sz - 1)) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1986  				cur_cs_num++;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1987  				params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1988  				sz += params->size;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1989  			}
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1990  			/* perform multi sector erase onec per Flash*/
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1991  			while (len) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1992  				erase_len = (len > (sz - addr)) ? (sz - addr) : len;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1993  				offset = addr;
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1994  				nor->spimem->spi->cs_index_mask = 1 << cur_cs_num;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1995  				if (nor->flags & SNOR_F_HAS_STACKED) {
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1996  					params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1997  					offset -= (sz - params->size);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1998  				}
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  1999  				ret = spi_nor_erase_multi_sectors(nor, offset, erase_len);
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  2000  				if (ret)
5390a8df769ec9b drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2018-09-11  2001  					goto erase_err;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2002  				len -= erase_len;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2003  				addr += erase_len;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2004  				params = spi_nor_get_params(nor, cur_cs_num);
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2005  				sz += params->size;
c5e6166349410fd drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2006  			}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  2007  		}
08b10484d5b83ce drivers/mtd/spi-nor/core.c    Amit Kumar Mahapatra 2023-11-25  2008  	}
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  2009  
bce679e5ae3a388 drivers/mtd/spi-nor/spi-nor.c Tudor Ambarus        2019-11-02  2010  	ret = spi_nor_write_disable(nor);
05241aead9b98c2 drivers/mtd/spi-nor/spi-nor.c Brian Norris         2014-11-05  2011  
d6af26944a02e6d drivers/mtd/spi-nor/spi-nor.c Heiner Kallweit      2015-11-17  2012  erase_err:
e96d4605b024495 drivers/mtd/spi-nor/core.c    Miquel Raynal        2023-03-28  2013  	spi_nor_unlock_and_unprep_pe(nor, instr->addr, instr->len);
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  2014  
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  2015  	return ret;
b199489d37b21c5 drivers/mtd/spi-nor/spi-nor.c Huang Shijie         2014-02-24  2016  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#74 lore raw

PATCH v11 10/10 spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver

In reply to Amit Kumar Mahapatra

During probe GQSPI driver sets SPI_CONTROLLER_MULTI_CS bit in ctlr->flags for notifying SPI core about multi CS capability of the controller. In parallel mode the controller can either split the data between both the flash or can send the same data to both the flashes, this is determined by the STRIPE bit. While sending commands to the flashes the GQSPI driver send the same command to both the flashes by resetting the STRIPE bit, but while writing/reading data to & from the flash the GQSPI driver splits the data evenly between both the flashes by setting the STRIPE bit.

---
 drivers/spi/spi-zynqmp-gqspi.c | 39 +++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/spi/spi-zynqmp-gqspi.c +38 -1
index c5d12ddd4ab3..61e91d59014b 100644
@@ -21,6 +21,7 @@
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 #include <linux/spi/spi-mem.h>
+#include <linux/mtd/spi-nor.h>
 
 /* Generic QSPI register offsets */
 #define GQSPI_CONFIG_OFST		0x00000100
@@ -190,6 +191,7 @@ struct qspi_platform_data {
  * @op_lock:		Operational lock
  * @speed_hz:          Current SPI bus clock speed in hz
  * @has_tapdelay:	Used for tapdelay register available in qspi
+ * @is_parallel:		Used for multi CS support
  */
 struct zynqmp_qspi {
 	struct spi_controller *ctlr;
@@ -212,8 +214,33 @@ struct zynqmp_qspi {
 	struct mutex op_lock;
 	u32 speed_hz;
 	bool has_tapdelay;
+	bool is_parallel;
 };
 
+/**
+ * zynqmp_gqspi_update_stripe - For GQSPI controller data stripe capabilities
+ * @op:	Pointer to mem ops
+ * Return:      Status of the data stripe
+ *
+ * Returns true if data stripe need to be enabled, else returns false
+ */
+bool zynqmp_gqspi_update_stripe(const struct spi_mem_op *op)
+{
+	if (op->cmd.opcode ==  SPINOR_OP_BE_4K ||
+	    op->cmd.opcode ==  SPINOR_OP_BE_32K ||
+	    op->cmd.opcode ==  SPINOR_OP_CHIP_ERASE ||
+	    op->cmd.opcode ==  SPINOR_OP_SE ||
+	    op->cmd.opcode ==  SPINOR_OP_BE_32K_4B ||
+	    op->cmd.opcode ==  SPINOR_OP_SE_4B ||
+	    op->cmd.opcode == SPINOR_OP_BE_4K_4B ||
+	    op->cmd.opcode ==  SPINOR_OP_WRSR ||
+	    op->cmd.opcode ==  SPINOR_OP_BRWR ||
+	    (op->cmd.opcode ==  SPINOR_OP_WRSR2 && !op->addr.nbytes))
+		return false;
+
+	return true;
+}
+
 /**
  * zynqmp_gqspi_read - For GQSPI controller read operation
  * @xqspi:	Pointer to the zynqmp_qspi structure
@@ -468,7 +495,14 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
 
 	genfifoentry |= GQSPI_GENFIFO_MODE_SPI;
 
-	if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
+	if ((qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) &&
+	    (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS)) {
+		zynqmp_gqspi_selectslave(xqspi,
+					 GQSPI_SELECT_FLASH_CS_BOTH,
+					 GQSPI_SELECT_FLASH_BUS_BOTH);
+		if (!xqspi->is_parallel)
+			xqspi->is_parallel = true;
+	} else if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
 		zynqmp_gqspi_selectslave(xqspi,
 					 GQSPI_SELECT_FLASH_CS_UPPER,
 					 GQSPI_SELECT_FLASH_BUS_LOWER);
@@ -1137,6 +1171,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
 	}
 
 	if (op->data.nbytes) {
+		if (xqspi->is_parallel && zynqmp_gqspi_update_stripe(op))
+			genfifoentry |= GQSPI_GENFIFO_STRIPE;
 		reinit_completion(&xqspi->data_completion);
 		if (op->data.dir == SPI_MEM_DATA_OUT) {
 			xqspi->txbuf = (u8 *)op->data.buf.out;
@@ -1332,6 +1368,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
 	ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
 	ctlr->dev.of_node = np;
 	ctlr->auto_runtime_pm = true;
+	ctlr->flags |= SPI_CONTROLLER_MULTI_CS;
 
 	ret = devm_spi_register_controller(&pdev->dev, ctlr);
 	if (ret) {
Signature · 1 line
2.17.1
#75 lore raw

Re: [PATCH v11 10/10] spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver

kernel test robot noticed the following build warnings:

Hi Amit,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-linus]
[also build test WARNING on linus/master v6.7-rc2]
[cannot apply to mtd/spi-nor/next lee-mfd/for-mfd-fixes next-20231124] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Amit-Kumar-Mahapatra/ALSA-hda-cs35l56-Use-set-get-APIs-to-access-spi-chip_select/20231125-182341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-linus
patch link:    https://lore.kernel.org/r/20231125092137.2948-11-amit.kumar-mahapatra%40amd.com
patch subject: [PATCH v11 10/10] spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver
config: x86_64-randconfig-121-20231127 (https://download.01.org/0day-ci/archive/20231127/[email protected]/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231127/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/spi/spi-zynqmp-gqspi.c:227:6: sparse: sparse: symbol 'zynqmp_gqspi_update_stripe' was not declared. Should it be static?

vim +/zynqmp_gqspi_update_stripe +227 drivers/spi/spi-zynqmp-gqspi.c

219
220 /**
221 * zynqmp_gqspi_update_stripe - For GQSPI controller data stripe capabilities
222 * @op: Pointer to mem ops
223 * Return: Status of the data stripe
224 *
225 * Returns true if data stripe need to be enabled, else returns false
226 */

 > 227	bool zynqmp_gqspi_update_stripe(const struct spi_mem_op *op)
   228	{
   229		if (op->cmd.opcode ==  SPINOR_OP_BE_4K ||
   230		    op->cmd.opcode ==  SPINOR_OP_BE_32K ||
   231		    op->cmd.opcode ==  SPINOR_OP_CHIP_ERASE ||
   232		    op->cmd.opcode ==  SPINOR_OP_SE ||
   233		    op->cmd.opcode ==  SPINOR_OP_BE_32K_4B ||
   234		    op->cmd.opcode ==  SPINOR_OP_SE_4B ||
   235		    op->cmd.opcode == SPINOR_OP_BE_4K_4B ||
   236		    op->cmd.opcode ==  SPINOR_OP_WRSR ||
   237		    op->cmd.opcode ==  SPINOR_OP_BRWR ||
   238		    (op->cmd.opcode ==  SPINOR_OP_WRSR2 && !op->addr.nbytes))

239 return false;
240
241 return true;
242 }
243

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#76 lore raw

Re: (subset) [PATCH v11 00/10] spi: Add support for stacked/parallel memories

In reply to Amit Kumar Mahapatra
Quoted 20 lines · Amit Kumar Mahapatra

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

The first nine patches
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
of the previous series got applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
for-next But the rest of the patches in the series did not get applied as failure was reported for spi driver with GPIO CS, so send the remaining patches in the series after rebasing it on top of for-next branch and fixing the issue.

Quoted 1 line

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[02/10] ALSA: hda/cs35l56: Use set/get APIs to access spi->chip_select

        commit: f05e2f61fe88092e0d341ea27644a84e3386358d
[03/10] spi: Add multi-cs memories support in SPI core
        commit: 4d8ff6b0991d5e86b17b235fc46ec62e9195cb9b

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#77 lore raw
In reply to Amit Kumar Mahapatra
Quoted 2 lines

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

Honestly, I'm not thrilled about how this is implemented in the core and what the restrictions are.
First, the pattern "if (n==1) then { old behavior } else { copy old code modify for n==2 }" is hard to maintain. There should be no copy and the old code shall be adapted to work for both n=1 and n>1.

But I agree with Tudor, some kind of abstraction (layer) would be nice.

Also, you hardcode n=2 everywhere. Please generalize that one.

Are you aware of any other controller supporting such a feature? I've seen you also need to modify the spi controller and intercept some commands. Can everything be moved there?

I'm not sure we are implementing controller specific things in the core. Hard to judge without seeing other controllers doing a similar thing. I'd like to avoid that.

If we had some kind of abstraction here, that might be easier to adapt in the future, but just putting everything into the core will make it really hard to maintain. So if everything related to stacked and parallel memory would be in drivers/mtd/spi-nor/stacked.c, we'd have at least everything in one place with a proper interface between that and the core.

-michael

#78 lore raw

Hello Michael,

Quoted 19 lines

-----Original Message-----
From: Michael Walle <[email protected]>
Sent: Tuesday, December 12, 2023 6:05 PM
To: Mahapatra, Amit Kumar <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; alsa- [email protected]; [email protected]; linux- [email protected]; git (AMD-Xilinx) <[email protected]>; [email protected]
Subject: Re: [PATCH v11 00/10] spi: Add support for stacked/parallel memories

Quoted 8 lines
Quoted 2 lines

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

Honestly, I'm not thrilled about how this is implemented in the core and what the restrictions are.
First, the pattern "if (n==1) then { old behavior } else { copy old code modify for n==2 }" is hard to maintain. There should be no copy and the old code shall be adapted to work for both n=1 and n>1.

Stacked mode serves as an extension of single device mode concerning data handling and CS line assertion. In both scenarios, the driver only asserts one CS line at any given time. The existing code has been expanded to determine the CS line to be asserted based on the requested address and data length. This modification accommodates both single (legacy) and stacked use cases.

In contrast, parallel mode differs from the legacy (single) mode in terms of data handling. In parallel mode, each byte of data is stored in both devices, with even bits in the lower flash and odd bits in the upper flash. During the transfer, multiple CS lines need to be asserted simultaneously. Consequently, special handling is necessary for parallel mode.

Quoted 2 lines

But I agree with Tudor, some kind of abstraction (layer) would be nice.

I agree too.

Quoted 4 lines

Also, you hardcode n=2 everywhere. Please generalize that one.

Are you aware of any other controller supporting such a feature? I've seen

Currently, I am familiar only with the AMD-Xilinx QSPI controllers that support parallel/stacked configurations and AMD-Xilinx OSPI controllers, which support stacked configuration. However, it's important to highlight certain aspects of these configurations. In parallel mode, each byte of data is stored in both flash devices, and the QSPI controller automatically handles the byte split and the simultaneous assertion/de-assertion of multiple CS lines. Hence, it can be stated that parallel operation is a controller feature, and other controllers wishing to operate flashes in parallel mode should be capable of data splitting and asserting multiple CS lines simultaneously. This characteristic might be specific to the AMD-Xilinx controller.

In contrast, in stacked mode, only one CS pin is asserted at any given time, determined by the memory address and the accessed data length. Stacked mode, unlike parallel mode, functions as a software abstraction. Once implemented, any SPI controller with multiple CS lines or with a combination of native-CS and GPIO-CS can operate two or more flashes in stacked mode.

Quoted 1 line

you also need to modify the spi controller and intercept some commands.

Command interception occurs exclusively in parallel mode, not in stacked mode. In parallel mode, data must be split during flash memory read/write operations. However, during Flash register read/write operations, there should be no data split, as the identical data needs to be written to (or read from) the register of both flashes. Consequently, the driver has to intercept the command before activating the data split feature of the controller.

Quoted 1 line

Can everything be moved there?

In stacked mode, determining which flash device needs to be asserted is based on the flash address and the length of the requested data. This information is handled by the spi-nor core. If the operation spans across multiple flashes, the command, address, dummy (if required), and residual data must be issued to multiple flashes. This process should be carried out in the spi-nor core layer( or before spi-mem) and not in the driver.

That is why >

Quoted 1 line

I'm not sure we are implementing controller specific things in the core. Hard

As explained earlier the parallel mode of operation can be controller specific, But the stacked mode is controller independent.

Quoted 8 lines

to judge without seeing other controllers doing a similar thing. I'd like to avoid that.

If we had some kind of abstraction here, that might be easier to adapt in the future, but just putting everything into the core will make it really hard to maintain. So if everything related to stacked and parallel memory would be in drivers/mtd/spi-nor/stacked.c, we'd have at least everything in one place with a proper interface between that and the core.

I agree.

Regards
Amit

Quoted 2 lines

-michael

#79 lore raw
In reply to Amit Kumar Mahapatra

----- Ursprüngliche Mail -----

Quoted 4 lines

Von: "Amit Kumar Mahapatra" <[email protected]>

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

I wish the series had a real cover letter which explains the big picture in more detail.

What I didn't really get so far, is it really necessary to support multiple chip selects within a single mtd?
You changes introduce hard to maintain changes into the spi-nor/mtd core code which alert me.
Why can't we have one mtd for each cs and, if needed, combine them later? We have drivers such as mtdconcat for reasons.

Thanks,
//richard

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

maintainer
#80 lore raw

Hi Richard,

[email protected] wrote on Mon, 18 Dec 2023 23:10:20 +0100 (CET):

Quoted 9 lines

----- Ursprüngliche Mail -----

Quoted 4 lines

Von: "Amit Kumar Mahapatra" <[email protected]>

This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.

I wish the series had a real cover letter which explains the big picture in more detail.

Quoted 6 lines

What I didn't really get so far, is it really necessary to support multiple chip selects within a single mtd?
You changes introduce hard to maintain changes into the spi-nor/mtd core code which alert me.
Why can't we have one mtd for each cs and, if needed, combine them later? We have drivers such as mtdconcat for reasons.

The Xilinx SPI controller is a bit convoluted, there are two ways to address the bits in a memory:
* Either your extend the memory range with the second chip "on top" of the first (which would typically be a mtd-concat use case)
* Or you use the two chips in parallel and you store the even bits in one device (let's say cs0) and the odd bits in the other (cs1). Extending mtd-concat for this might be another solution, I don't know how feasible it would be.

Maybe these bindings will help understanding the logic:
e2edd1b64f1c ("spi: dt-bindings: Describe stacked/parallel memories modes") eba5368503b4 ("spi: dt-bindings: Add an example with two stacked flashes")

However I agree the changes will likely be hard to maintain given the complexity brought with such a different controller.

Thanks,
Miquèl