Devicetree
 help / color / mirror / Atom feed
From: Prakriti Sharma <Prakriti.Sharma@synopsys.com>
To: Mark Brown <broonie@kernel.org>, linux-spi@vger.kernel.org
Cc: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-kernel@vger.kernel.org,
	Siddhant Kumar <Siddhant.Kumar@synopsys.com>,
	Prakriti Sharma <Prakriti.Sharma@synopsys.com>
Subject: [PATCH 4/6] spi: dw-g2: Add SPI-NAND support
Date: Thu, 19 Nov 2026 15:35:11 +0530	[thread overview]
Message-ID: <20261119100513.433044-5-prakriti@synopsys.com> (raw)
In-Reply-To: <20261119100513.433044-1-prakriti@synopsys.com>

Handle SPI-NAND flash in the same spi-mem path as SPI-NOR.

NAND uses a 2-byte address and program-load writes land in the page
buffer, so short operations such as JEDEC ID and status reads take
the register path. A short delay after chip-select assertion, plus
barriers around that write, keeps the ID read ordered on this
integration.

Tested with a Winbond W25N01JW SPI-NAND flash.

Signed-off-by: Prakriti Sharma <prakriti@synopsys.com>
Signed-off-by: Siddhant Kumar <sidkumar@synopsys.com>
---
 drivers/spi/spi-dw-g2-core.c | 370 +++++++++++++++++++++++++----------
 drivers/spi/spi-dw-g2.h      |  20 +-
 2 files changed, 277 insertions(+), 113 deletions(-)

diff --git a/drivers/spi/spi-dw-g2-core.c b/drivers/spi/spi-dw-g2-core.c
index c640d6a19260..a94d4a7870df 100644
--- a/drivers/spi/spi-dw-g2-core.c
+++ b/drivers/spi/spi-dw-g2-core.c
@@ -262,9 +262,13 @@ static u32 dw_spi_g2_get_frf(const struct spi_mem_op *op)
  * dw_spi_g2_get_tt - Determine transfer type from operation bus widths
  * @op: SPI memory operation
  *
- * The transfer type (TT) field in SPI_CTRLR0 defines which phases use
- * multi-line mode. TT0 = standard (1-1-1), TT1 = data multi-line (1-1-x),
- * TT2 = addr+data multi-line (1-x-x). TT3 (x-x-x) is not supported.
+ * TRANS_TYPE in SPI_CTRLR0 / XIP_CTRL controls only the instruction and
+ * address phases.  Data always uses the enhanced mode set by SPI_FRF in
+ * CTRLR0 (or FRF in XIP_CTRL).
+ *
+ *   TT0 (0x0): instruction standard, address standard  (1-1-x)
+ *   TT1 (0x1): instruction standard, address enhanced  (1-x-x)
+ *   TT2 (0x2): instruction enhanced, address enhanced  (x-x-x)
  *
  * Return: Transfer type value (0-2), or -EOPNOTSUPP for unsupported patterns
  */
@@ -272,29 +276,37 @@ static int dw_spi_g2_get_tt(const struct spi_mem_op *op)
 {
 	bool cmd_m = (op->cmd.buswidth > 1);
 	bool addr_m = (op->addr.nbytes && op->addr.buswidth > 1);
-	bool data_m = (op->data.nbytes && op->data.buswidth > 1);
 
-	if (!cmd_m && !addr_m && !data_m)
-		return DW_SPI_G2_TRANS_TYPE_TT0;	/* 1-1-1 */
-	if (!cmd_m && !addr_m && data_m)
-		return DW_SPI_G2_TRANS_TYPE_TT1;	/* 1-1-x */
-	if (!cmd_m && addr_m && data_m)
-		return DW_SPI_G2_TRANS_TYPE_TT2;	/* 1-x-x */
+	if (!cmd_m && !addr_m)
+		return DW_SPI_G2_TRANS_TYPE_TT0;	/* 1-1-x */
+	if (!cmd_m && addr_m)
+		return DW_SPI_G2_TRANS_TYPE_TT1;	/* 1-x-x */
+	if (cmd_m && addr_m)
+		return DW_SPI_G2_TRANS_TYPE_TT2;	/* x-x-x */
 
 	return -EOPNOTSUPP;
 }
 
 /**
- * dw_spi_g2_is_reg_op - Check if operation is a register read/write
+ * dw_spi_g2_is_reg_op - Check if operation fits in TR (transmit-receive) mode
+ * @dws: Driver state (provides runtime fifo_len)
  * @op: SPI memory operation
  *
- * Register operations are single-byte commands with no address (e.g.,
- * RDSR, WRSR, RDID). Data must fit within the fixed-size stack buffer.
+ * Routes operations through TR mode when total transfer size (cmd + addr +
+ * dummy + data) fits within the FIFO. This avoids RO mode with SPI_CTRLR0
+ * (enhanced SPI framing) which some platforms don't fully support.
+ *
+ * Limit is min(fifo_len, compile-time buffer size) to stay within both
+ * the hardware FIFO and the stack-allocated buffers in reg_op().
  */
-static inline bool dw_spi_g2_is_reg_op(const struct spi_mem_op *op)
+static inline bool dw_spi_g2_is_reg_op(struct dw_spi_g2 *dws,
+				       const struct spi_mem_op *op)
 {
-	return !op->addr.nbytes && op->data.nbytes > 0 &&
-	       op->data.nbytes <= DW_SPI_G2_REG_OP_MAX_DATA;
+	u32 total = op->cmd.nbytes + op->addr.nbytes +
+		    op->dummy.nbytes + op->data.nbytes;
+	u32 limit = min_t(u32, dws->fifo_len, DW_SPI_G2_REG_OP_BUF_SIZE);
+
+	return op->data.nbytes > 0 && total <= limit;
 }
 
 /**
@@ -483,49 +495,132 @@ static void dw_spi_g2_reg_op_setup(struct dw_spi_g2 *dws,
 
 static int dw_spi_g2_reg_op(struct dw_spi_g2 *dws, const struct spi_mem_op *op)
 {
-	u8 tx_buf[DW_SPI_G2_REG_OP_MAX_DATA + 1];
-	u32 tx_len;
-	int ret;
-
-	/* Validate data length fits in stack buffer */
-	if (op->data.nbytes > DW_SPI_G2_REG_OP_MAX_DATA) {
-		dev_err(dws->dev, "reg_op data length %u exceeds max %u\n",
-			op->data.nbytes, DW_SPI_G2_REG_OP_MAX_DATA);
+	u8 tx_buf[DW_SPI_G2_REG_OP_BUF_SIZE];
+	u32 tx_len = 0;
+	u32 echo_bytes;
+	int ret = 0;
+	u32 i;
+
+	if (op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes +
+	    op->data.nbytes > sizeof(tx_buf)) {
+		dev_err(dws->dev, "reg_op transfer too large: cmd=%u addr=%u dummy=%u data=%u\n",
+			op->cmd.nbytes, op->addr.nbytes, op->dummy.nbytes,
+			op->data.nbytes);
 		return -EINVAL;
 	}
 
+	dev_dbg(dws->dev, "reg_op: cmd=0x%02x dir=%d data_len=%u\n",
+		op->cmd.opcode, op->data.dir, op->data.nbytes);
+
 	dw_spi_g2_reg_op_setup(dws, op);
 
-	dw_spi_g2_transfer_begin(dws);
+	/* Build complete TX buffer: [cmd] [addr] [dummy] [data/zeros] */
+	tx_buf[tx_len++] = op->cmd.opcode;
+
+	for (i = op->addr.nbytes; i > 0; i--)
+		tx_buf[tx_len++] = (op->addr.val >> ((i - 1) * 8)) & 0xFF;
 
 	if (op->data.dir == SPI_MEM_DATA_OUT) {
 		if (!op->data.buf.out) {
 			dev_err(dws->dev, "TX buffer is NULL\n");
 			return -EINVAL;
 		}
-		/* TX: [opcode] [data bytes] */
-		tx_buf[0] = op->cmd.opcode;
-		memcpy(&tx_buf[1], op->data.buf.out, op->data.nbytes);
-		tx_len = 1 + op->data.nbytes;
-		ret = dw_spi_g2_xfer_fifo(dws, tx_buf, tx_len, NULL, 0);
+		memcpy(&tx_buf[tx_len], op->data.buf.out, op->data.nbytes);
+		tx_len += op->data.nbytes;
 	} else {
 		if (!op->data.buf.in) {
 			dev_err(dws->dev, "RX buffer is NULL\n");
 			return -EINVAL;
 		}
-		/*
-		 * TR mode: each TX byte produces one RX byte.
-		 * Push opcode + nbytes dummy 0x00s, receive 1+nbytes,
-		 * discard first RX byte (echo of opcode phase).
-		 */
-		u8 rx_tmp[DW_SPI_G2_REG_OP_MAX_DATA + 1];
-
-		tx_buf[0] = op->cmd.opcode;
-		memset(&tx_buf[1], 0x00, op->data.nbytes);
-		tx_len = 1 + op->data.nbytes;
-		ret = dw_spi_g2_xfer_fifo(dws, tx_buf, tx_len, rx_tmp, tx_len);
-		if (!ret)
-			memcpy(op->data.buf.in, &rx_tmp[1], op->data.nbytes);
+		if (op->dummy.nbytes) {
+			memset(&tx_buf[tx_len], 0x00, op->dummy.nbytes);
+			tx_len += op->dummy.nbytes;
+		}
+		memset(&tx_buf[tx_len], 0x00, op->data.nbytes);
+		tx_len += op->data.nbytes;
+	}
+
+	echo_bytes = 1 + op->addr.nbytes + op->dummy.nbytes;
+
+	dev_dbg(dws->dev, "reg_op: tx_len=%u echo=%u\n", tx_len, echo_bytes);
+
+	dw_spi_g2_target_enable(dws, dws->cs);
+	dw_spi_g2_enable(dws, true);
+
+	/*
+	 * Write TX data to FIFO with TFNF polling.
+	 * Although tx_len is limited by dw_spi_g2_is_reg_op() to fifo_len,
+	 * we still poll TFNF for safety and to handle any hardware quirks.
+	 */
+	for (i = 0; i < tx_len; i++) {
+		u32 timeout = DW_SPI_G2_TIMEOUT_US;
+
+		/* Wait for TX FIFO to have space */
+		while (!(dw_spi_g2_readl(dws->regs, DW_SPI_G2_SR) & DW_SPI_G2_SR_TFNF)) {
+			if (--timeout == 0) {
+				dev_err(dws->dev, "reg_op: TX FIFO full timeout\n");
+				dw_spi_g2_transfer_end(dws);
+				dw_spi_g2_controller_reset(dws);
+				return -ETIMEDOUT;
+			}
+			udelay(1);
+		}
+
+		dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, tx_buf[i]);
+	}
+
+	/* Ensure all FIFO writes complete before CS assertion */
+	wmb();
+
+	dw_spi_g2_cs_assert(dws, dws->cs);
+
+	/*
+	 * CS settling delay for NAND flash:
+	 *
+	 * NAND flash requires a settling period after CS assertion before
+	 * data transactions can begin reliably. This is a hardware timing requirement.
+	 *
+	 * This is specific to NAND flash behavior where CS-to-valid-data timing
+	 * is more stringent than NOR flash. The delay applies to small
+	 * register operations (reg_op path) which are commonly used for:
+	 * - READID (0x9F)
+	 * - GET_FEATURE (0x0F)
+	 * - SET_FEATURE (0x1F)
+	 * - READ_STATUS (0x0F with feature address)
+	 *
+	 * Note: Only applies to NAND (detected via DT "spi-nand" compatible)
+	 * to avoid performance impact on NOR flash.
+	 */
+	if (dws->is_nand) {
+		/* Force a register read to ensure CS assertion propagates */
+		(void)dw_spi_g2_readl(dws->regs, DW_SPI_G2_SR);
+		usleep_range(10, 20);
+	}
+
+	dw_spi_g2_wait_idle(dws);
+
+	/* For TR mode reads, harvest RX FIFO after the burst completes */
+	if (op->data.dir == SPI_MEM_DATA_IN) {
+		u32 rxflr = dw_spi_g2_readl(dws->regs, DW_SPI_G2_RXFLR);
+		u32 rx_got = min_t(u32, rxflr, tx_len);
+
+		/* Ensure RXFLR read completes before reading RX FIFO */
+		rmb();
+
+		for (i = 0; i < rx_got; i++) {
+			u8 val = dw_spi_g2_readl(dws->regs,
+						 DW_SPI_G2_DR0) & 0xFF;
+			if (i >= echo_bytes &&
+			    (i - echo_bytes) < op->data.nbytes)
+				((u8 *)op->data.buf.in)[i - echo_bytes] = val;
+		}
+
+		if (rx_got < echo_bytes + op->data.nbytes) {
+			dev_err(dws->dev,
+				"reg_op RX short: got %u, need %u\n",
+				rx_got, echo_bytes + op->data.nbytes);
+			ret = -EIO;
+		}
 	}
 
 	dw_spi_g2_transfer_end(dws);
@@ -615,14 +710,17 @@ static int dw_spi_g2_indirect_read_setup(struct dw_spi_g2 *dws,
  * @dws: Driver state
  * @op: SPI memory operation
  *
- * Reads data from flash using RO (receive-only) mode.
+ * Reads data from flash using RO (receive-only) mode with enhanced SPI
+ * framing via SPI_CTRLR0.
  * Return: 0 on success, negative error code on failure
  */
 static int dw_spi_g2_indirect_read(struct dw_spi_g2 *dws,
 				   const struct spi_mem_op *op)
 {
-	u32 tx_entries;
+	struct spi_mem_op chunk_op;
 	u8 dummy_buf = 0;
+	u32 total, done = 0;
+	u32 tx_entries;
 	int ret;
 
 	if (!op->data.nbytes) {
@@ -635,35 +733,67 @@ static int dw_spi_g2_indirect_read(struct dw_spi_g2 *dws,
 		return -EINVAL;
 	}
 
-	ret = dw_spi_g2_indirect_read_setup(dws, op);
-	if (ret)
-		return ret;
+	total = op->data.nbytes;
+	dev_dbg(dws->dev, "indirect_read: cmd=0x%02x addr=0x%llx len=%u\n",
+		op->cmd.opcode, op->addr.val, total);
 
-	dw_spi_g2_target_enable(dws, dws->cs);
-	dw_spi_g2_enable(dws, true);
+	/*
+	 * Split into chunks no larger than dws->fifo_len so the RX FIFO
+	 * never overflows. Each iteration reprograms CTRLR1/NDF and
+	 * re-issues cmd+addr with the column advanced. A single
+	 * >fifo_len request leaves the controller idle (SR.BUSY=0,
+	 * RXFLR=0) after the first FIFO worth of data, causing an
+	 * RX timeout.
+	 */
+	chunk_op = *op;
+
+	while (done < total) {
+		u32 chunk = min_t(u32, total - done, dws->fifo_len);
+
+		chunk_op.addr.val = op->addr.val + done;
+		chunk_op.data.nbytes = chunk;
+		chunk_op.data.buf.in = (u8 *)op->data.buf.in + done;
 
-	tx_entries = 0;
+		ret = dw_spi_g2_indirect_read_setup(dws, &chunk_op);
+		if (ret)
+			return ret;
+
+		dw_spi_g2_target_enable(dws, dws->cs);
+		dw_spi_g2_enable(dws, true);
 
-	/* Write instruction */
-	dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, op->cmd.opcode);
-	tx_entries++;
+		tx_entries = 0;
 
-	/* Write address as a packed 32-bit value (one FIFO entry) */
-	if (op->addr.nbytes) {
-		dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, (u32)op->addr.val);
+		/* Write instruction to DR0 */
+		dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0,
+				 chunk_op.cmd.opcode);
 		tx_entries++;
-	}
 
-	/* Assert CS - controller begins: sends TX FIFO, then receives */
-	dw_spi_g2_cs_assert(dws, dws->cs);
+		/*
+		 * Write address as a single packed value.
+		 * In enhanced SPI framing (RO mode with SPI_CTRLR0), the
+		 * hardware extracts ADDR_L bits from this write.
+		 */
+		if (chunk_op.addr.nbytes) {
+			dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0,
+					 (u32)chunk_op.addr.val);
+			tx_entries++;
+		}
 
-	/* Receive data via polling */
-	ret = dw_spi_g2_xfer_fifo(dws, &dummy_buf, 0,
-				  op->data.buf.in, op->data.nbytes);
-	dw_spi_g2_transfer_end(dws);
-	dw_spi_g2_controller_reset(dws);
+		/* Assert CS - controller begins: sends TX FIFO, then receives */
+		dw_spi_g2_cs_assert(dws, dws->cs);
 
-	return ret;
+		/* Receive data via polling */
+		ret = dw_spi_g2_xfer_fifo(dws, &dummy_buf, 0,
+					  chunk_op.data.buf.in, chunk);
+		dw_spi_g2_transfer_end(dws);
+		dw_spi_g2_controller_reset(dws);
+		if (ret)
+			return ret;
+
+		done += chunk;
+	}
+
+	return 0;
 }
 
 /**
@@ -676,20 +806,26 @@ static int dw_spi_g2_indirect_read(struct dw_spi_g2 *dws,
  * @dws: Driver state
  * @op: SPI memory operation
  *
- * Sets up TMOD=TO (transmit-only), standard SPI mode.
+ * Sets up TMOD=TO (transmit-only)
  */
 static void dw_spi_g2_indirect_write_setup(struct dw_spi_g2 *dws,
 					   const struct spi_mem_op *op)
 {
 	u32 ctrlr0 = dw_spi_g2_build_ctrlr0(dws, DW_SPI_G2_CTRLR0_TMOD_TO,
 					    DW_SPI_G2_FRF_STANDARD);
+	u32 spictrlr0 = 0;
 
 	dw_spi_g2_controller_reset(dws);
 	dw_spi_g2_target_disable(dws, dws->cs);
 
+	if (op->cmd.dtr)
+		spictrlr0 |= DW_SPI_G2_SPI_CTRLR0_INST_DDR_EN_MASK;
+	if (op->addr.dtr || op->data.dtr)
+		spictrlr0 |= DW_SPI_G2_SPI_CTRLR0_DDR_EN_MASK;
+
 	dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR0(dws->cs), ctrlr0);
 	dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR1(dws->cs), 0);
-	dw_spi_g2_writel(dws->regs, DW_SPI_G2_SPI_CTRLR0(dws->cs), 0);
+	dw_spi_g2_writel(dws->regs, DW_SPI_G2_SPI_CTRLR0(dws->cs), spictrlr0);
 	dw_spi_g2_writel(dws->regs, DW_SPI_G2_TXFTLR, 0);
 	dw_spi_g2_writel(dws->regs, DW_SPI_G2_RXFTLR, 0);
 }
@@ -699,8 +835,12 @@ static void dw_spi_g2_indirect_write_setup(struct dw_spi_g2 *dws,
  * @dws: Driver state
  * @op: SPI memory operation
  *
- * Writes data to flash using TO (transmit-only) mode. The controller sends
- * instruction, address, and data bytes as a continuous stream.
+ * Writes data to flash using TMOD=TO (transmit-only).
+ * NOTE: CS is asserted before SSI enable for NAND compatibility in VDK.
+ * This non-standard sequence is required because:
+ * 1. Controller reset in setup clears FIFO (can't prefill while disabled)
+ * 2. Enabling SSI before CS causes 0x00 transmission from empty FIFO
+ * 3. NAND Program Load requires data immediately when CS asserts
  *
  * Return: 0 on success, negative error code on failure
  */
@@ -709,7 +849,7 @@ static int dw_spi_g2_indirect_write(struct dw_spi_g2 *dws,
 {
 	u32 tx_total = op->cmd.nbytes + op->addr.nbytes + op->data.nbytes;
 	u8 *tx_buf;
-	u32 prefill, pos;
+	int ret = 0;
 
 	if (!op->data.nbytes) {
 		dev_err(dws->dev, "Zero-length write not allowed\n");
@@ -721,52 +861,36 @@ static int dw_spi_g2_indirect_write(struct dw_spi_g2 *dws,
 		return -EINVAL;
 	}
 
+	dev_dbg(dws->dev, "indirect_write: cmd=0x%02x addr=0x%llx len=%u\n",
+		op->cmd.opcode, op->addr.val, op->data.nbytes);
+
 	dw_spi_g2_indirect_write_setup(dws, op);
 
-	/* Allocate and build TX buffer: [cmd][addr][data] */
 	tx_buf = kzalloc(tx_total, GFP_KERNEL);
 	if (!tx_buf)
 		return -ENOMEM;
 
 	dw_spi_g2_fill_tx_buf(tx_buf, op, true);
 
-	/*
-	 * Split enable sequence:
-	 * Enable SSI (without CS), pre-fill TX FIFO, then assert CS.
-	 * FIFO pointers are reset while SSIENR=0, so writes before
-	 * enabling would be discarded.
-	 */
 	dw_spi_g2_target_enable(dws, dws->cs);
-	dw_spi_g2_enable(dws, true);
-
-	/* Pre-fill FIFO to capacity or total size */
-	prefill = min_t(u32, tx_total, dws->fifo_len);
-	for (pos = 0; pos < prefill; pos++)
-		dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, tx_buf[pos]);
-
-	/* Assert CS - transfer starts */
 	dw_spi_g2_cs_assert(dws, dws->cs);
+	dw_spi_g2_enable(dws, true);
 
-	/* Refill FIFO with remaining bytes (if any) via polling */
-	if (pos < tx_total) {
-		int ret = dw_spi_g2_xfer_fifo(dws, &tx_buf[pos],
-					      tx_total - pos, NULL, 0);
-		if (ret) {
-			dw_spi_g2_transfer_end(dws);
-			dw_spi_g2_controller_reset(dws);
-			kfree(tx_buf);
-			return ret;
-		}
+	ret = dw_spi_g2_xfer_fifo(dws, tx_buf, tx_total, NULL, 0);
+	if (ret) {
+		dev_err(dws->dev,
+			"indirect_write: xfer_fifo failed: %d\n", ret);
+		dw_spi_g2_transfer_end(dws);
+		dw_spi_g2_controller_reset(dws);
+		kfree(tx_buf);
+		return ret;
 	}
 
-	/* Wait for transfer completion */
-	dw_spi_g2_wait_idle(dws);
-
 	dw_spi_g2_transfer_end(dws);
 	dw_spi_g2_controller_reset(dws);
 
 	kfree(tx_buf);
-	return 0;
+	return ret;
 }
 
 /*
@@ -778,9 +902,46 @@ static int dw_spi_g2_indirect_write(struct dw_spi_g2 *dws,
 static bool dw_spi_g2_supports_mem_ops(struct spi_mem *mem,
 				       const struct spi_mem_op *op)
 {
+	struct spi_device *spi = mem->spi;
+	struct dw_spi_g2 *dws = spi_controller_get_devdata(spi->controller);
+	bool op_is_dtr =
+		op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
+
+	/*
+	 * Detect NAND flash by checking device tree compatible string.
+	 * This is used for VDK timing workarounds.
+	 */
+	if (spi->dev.of_node) {
+		if (of_device_is_compatible(spi->dev.of_node, "spi-nand"))
+			dws->is_nand = true;
+	}
+
+	if (op_is_dtr) {
+		/*
+		 * DTR requires enhanced SPI modes (Dual/Quad/Octal).
+		 * Reject standard-width DTR since it has no practical use
+		 * and the hardware doesn't support it meaningfully.
+		 */
+		if (op->data.nbytes && op->data.buswidth == 1)
+			return false;
+
+		/*
+		 * In DTR mode all phases must agree on DTR — reject
+		 * mixed STR/DTR within a single operation.
+		 */
+		if (op->addr.nbytes && op->addr.dtr != op->cmd.dtr)
+			return false;
+		if (op->data.nbytes && op->data.dtr != op->cmd.dtr)
+			return false;
+	}
+
 	return spi_mem_default_supports_op(mem, op);
 }
 
+static const struct spi_controller_mem_caps dw_spi_g2_mem_caps = {
+	.dtr = true,
+};
+
 int dw_spi_g2_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op *op)
 {
 	if (op->data.dir == SPI_MEM_DATA_IN)
@@ -846,15 +1007,13 @@ static int dw_spi_g2_exec_mem_op(struct spi_mem *mem,
 	dws->cs = spi_get_chipselect(spi, 0);
 	dws->curr_spi = spi;
 
-	dev_dbg(dws->dev,
-		"exec_mem_op: cmd=0x%02x addr_len=%u data_len=%u dir=%d\n",
-		op->cmd.opcode, op->addr.nbytes, op->data.nbytes,
-		op->data.dir);
+	dev_dbg(dws->dev, "exec_op: cmd=0x%02x addr=0x%llx len=%u dir=%d\n",
+		op->cmd.opcode, op->addr.val, op->data.nbytes, op->data.dir);
 
 	if (op->data.dir == SPI_MEM_NO_DATA)
 		return dw_spi_g2_cmd_only(dws, op);
 
-	if (dw_spi_g2_is_reg_op(op))
+	if (dw_spi_g2_is_reg_op(dws, op))
 		return dw_spi_g2_reg_op(dws, op);
 
 	if (op->data.dir == SPI_MEM_DATA_IN)
@@ -943,6 +1102,7 @@ int dw_spi_g2_init(struct dw_spi_g2 *dws)
 
 	ctlr->setup = dw_spi_g2_setup;
 	ctlr->mem_ops = &dw_spi_g2_mem_ops;
+	ctlr->mem_caps = &dw_spi_g2_mem_caps;
 
 	dw_spi_g2_debugfs_init(dws);
 	init_completion(&dws->mem_done);
diff --git a/drivers/spi/spi-dw-g2.h b/drivers/spi/spi-dw-g2.h
index 1106be0af7b6..3091697238d7 100644
--- a/drivers/spi/spi-dw-g2.h
+++ b/drivers/spi/spi-dw-g2.h
@@ -186,13 +186,8 @@ static inline u32 dw_spi_g2_addr_len(unsigned int addr_nbytes)
 	return addr_nbytes ? addr_nbytes * 2U : 0U;
 }
 
-/*
- * Maximum chunk size for indirect reads.
- * 64KB allows efficient large transfers while staying well within typical
- * controller limits. The FIFO (256 bytes) drains continuously during
- * the transfer via polling.
- */
-#define DW_G2_MAX_CHUNK		256U
+/* Maximum data chunk per spi_mem_op. */
+#define DW_G2_MAX_CHUNK		(64 * 1024U)
 
 /* Timeout in microseconds for polling operations */
 #define DW_SPI_G2_TIMEOUT_US	200000U
@@ -222,7 +217,13 @@ static inline u32 dw_spi_g2_addr_len(unsigned int addr_nbytes)
  *   - etc.
  * Larger transfers use indirect read/write with FIFO (up to DW_G2_MAX_CHUNK).
  */
-#define DW_SPI_G2_REG_OP_MAX_DATA	15U
+/*
+ * Maximum total transfer size (cmd + addr + dummy + data) for reg_op
+ * (TR mode). Must fit within both the TX and RX FIFOs. Each FIFO has
+ * fifo_len entries (typically 256); we use a compile-time cap here and
+ * check against the runtime fifo_len in is_reg_op().
+ */
+ #define DW_SPI_G2_REG_OP_BUF_SIZE	256U
 
 struct dw_spi_g2_cfg {
 	u8 tmode;
@@ -259,6 +260,9 @@ struct dw_spi_g2 {
 	struct completion       mem_done;
 	int                     error;
 
+	/* Flash type detection for timing workarounds */
+	bool			is_nand;
+
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs;
 	struct debugfs_regset32 regset;
-- 
2.34.1


  parent reply	other threads:[~2026-11-19 10:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 10:05 [PATCH 0/6] spi: dw-g2: add Synopsys DWC SSI v2.02a controller support Prakriti Sharma
2026-11-19 10:05 ` [PATCH 1/6] dt-bindings: spi: Add Synopsys DWC SSI v2.02a binding Prakriti Sharma
2026-11-19 10:05 ` [PATCH 2/6] spi: dw-g2: Add Synopsys DWC SSI v2.02a driver Prakriti Sharma
2026-11-19 10:28   ` sashiko-bot
2026-11-19 10:05 ` [PATCH 3/6] spi: dw-g2: Add indirect read and write Prakriti Sharma
2026-11-19 10:27   ` sashiko-bot
2026-11-19 10:05 ` Prakriti Sharma [this message]
2026-11-19 10:25   ` [PATCH 4/6] spi: dw-g2: Add SPI-NAND support sashiko-bot
2026-11-19 10:05 ` [PATCH 5/6] dt-bindings: spi: Document DWC SSI XIP properties Prakriti Sharma
2026-11-19 10:14   ` sashiko-bot
2026-11-19 10:05 ` [PATCH 6/6] spi: dw-g2: Add XIP support Prakriti Sharma
2026-11-19 10:32   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119100513.433044-5-prakriti@synopsys.com \
    --to=prakriti.sharma@synopsys.com \
    --cc=Siddhant.Kumar@synopsys.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox