mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Mark Brown <broonie@kernel.org>,
	Liang Yang <liang.yang@amlogic.com>,
	 Feng Chen <feng.chen@amlogic.com>,
	Xianwei Zhao <xianwei.zhao@amlogic.com>,  Han Xu <han.xu@nxp.com>,
	Conor Dooley <conor.dooley@microchip.com>,
	 Valentina Fernandez <valentina.fernandezalanis@microchip.com>,
	 Daire McNamara <daire.mcnamara@microchip.com>,
	 Haibo Chen <haibo.chen@nxp.com>,
	Jyan Chou <jyanchou@realtek.com>,
	 Yu-Chun Lin <eleanor.lin@realtek.com>,
	 Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	 Alexandre Torgue <alexandre.torgue@foss.st.com>,
	 Pratyush Yadav <pratyush@kernel.org>,
	Michael Walle <mwalle@kernel.org>,
	 Takahiro Kuwano <takahiro.kuwano@infineon.com>,
	 Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Alvin Zhou <alvinzhou@mxic.com.tw>,
	 Cheng Ming Lin <chengminglin@mxic.com.tw>,
	linux-spi@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-amlogic@lists.infradead.org,  imx@lists.linux.dev,
	linux-riscv@lists.infradead.org,
	 linux-stm32@st-md-mailman.stormreply.com,
	 linux-arm-kernel@lists.infradead.org,
	linux-mtd@lists.infradead.org,
	 Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH RFC 07/16] spi: cadence-qspi: Consume dummy cycles directly
Date: Wed, 25 Nov 2026 18:51:21 +0100	[thread overview]
Message-ID: <20261125-macronix-upstreaming-spi-mem-cycles-v1-7-fd036402fd37@bootlin.com> (raw)
In-Reply-To: <20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com>

The spi-mem layer is now capable of providing the dummy phase in cycle
units rather than bytes, provided that drivers advertize the dummy_cycle
capability. Since this controller is consuming cycles and currently
converts bytes into cycles, flag it capable to consume cycles directly
and drop the extra conversions.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/spi/spi-cadence-quadspi.c | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 44d96b8cf8f0..1bf21cadd1da 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -410,20 +410,6 @@ static unsigned int cqspi_calc_rdreg(const struct spi_mem_op *op)
 	return rdreg;
 }
 
-static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op)
-{
-	unsigned int dummy_clk;
-
-	if (!op->dummy.nbytes)
-		return 0;
-
-	dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
-	if (op->cmd.dtr)
-		dummy_clk /= 2;
-
-	return dummy_clk;
-}
-
 static int cqspi_wait_idle(struct cqspi_st *cqspi)
 {
 	const unsigned int poll_idle_retry = 3;
@@ -549,7 +535,6 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
 	size_t n_rx = op->data.nbytes;
 	unsigned int rdreg;
 	unsigned int reg;
-	unsigned int dummy_clk;
 	size_t read_len;
 	int status;
 
@@ -574,12 +559,11 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
 	rdreg = cqspi_calc_rdreg(op);
 	writel(rdreg, reg_base + CQSPI_REG_RD_INSTR);
 
-	dummy_clk = cqspi_calc_dummy(op);
-	if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
+	if (op->dummy.ncycles > CQSPI_DUMMY_CLKS_MAX)
 		return -EOPNOTSUPP;
 
-	if (dummy_clk)
-		reg |= (dummy_clk & CQSPI_REG_CMDCTRL_DUMMY_MASK)
+	if (op->dummy.ncycles)
+		reg |= (op->dummy.ncycles & CQSPI_REG_CMDCTRL_DUMMY_MASK)
 		     << CQSPI_REG_CMDCTRL_DUMMY_LSB;
 
 	reg |= BIT(CQSPI_REG_CMDCTRL_RD_EN_LSB);
@@ -696,7 +680,6 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
 {
 	struct cqspi_st *cqspi = f_pdata->cqspi;
 	void __iomem *reg_base = cqspi->iobase;
-	unsigned int dummy_clk = 0;
 	unsigned int reg;
 	int ret;
 	u8 opcode;
@@ -714,13 +697,11 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
 	reg |= cqspi_calc_rdreg(op);
 
 	/* Setup dummy clock cycles */
-	dummy_clk = cqspi_calc_dummy(op);
-
-	if (dummy_clk > CQSPI_DUMMY_CLKS_MAX)
+	if (op->dummy.ncycles > CQSPI_DUMMY_CLKS_MAX)
 		return -EOPNOTSUPP;
 
-	if (dummy_clk)
-		reg |= (dummy_clk & CQSPI_REG_RD_INSTR_DUMMY_MASK)
+	if (op->dummy.ncycles)
+		reg |= (op->dummy.ncycles & CQSPI_REG_RD_INSTR_DUMMY_MASK)
 		       << CQSPI_REG_RD_INSTR_DUMMY_LSB;
 
 	writel(reg, reg_base + CQSPI_REG_RD_INSTR);
@@ -1528,7 +1509,7 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
 	 */
 	all_true = op->cmd.dtr &&
 		   (!op->addr.nbytes || op->addr.dtr) &&
-		   (!op->dummy.nbytes || op->dummy.dtr) &&
+		   (!op->dummy.ncycles || op->dummy.dtr) &&
 		   (!op->data.nbytes || op->data.dtr);
 
 	all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
@@ -1739,12 +1720,14 @@ static const struct spi_controller_mem_ops cqspi_mem_ops = {
 static const struct spi_controller_mem_caps cqspi_mem_caps = {
 	.dtr = true,
 	.per_op_freq = true,
+	.dummy_cycles = true,
 };
 
 static const struct spi_controller_mem_caps cqspi_am654_mem_caps = {
 	.dtr = true,
 	.per_op_freq = true,
 	.no_cs_assertion = true,
+	.dummy_cycles = true,
 };
 
 static int cqspi_setup_flash(struct cqspi_st *cqspi)

-- 
2.56.0


  parent reply	other threads:[~2026-11-25 17:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:51 ` Miquel Raynal [this message]
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 10/16] spi: nxp-xspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
2026-11-26 11:09 ` [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal

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=20261125-macronix-upstreaming-spi-mem-cycles-v1-7-fd036402fd37@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=alvinzhou@mxic.com.tw \
    --cc=broonie@kernel.org \
    --cc=chengminglin@mxic.com.tw \
    --cc=conor.dooley@microchip.com \
    --cc=daire.mcnamara@microchip.com \
    --cc=eleanor.lin@realtek.com \
    --cc=feng.chen@amlogic.com \
    --cc=haibo.chen@nxp.com \
    --cc=han.xu@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=jyanchou@realtek.com \
    --cc=liang.yang@amlogic.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=takahiro.kuwano@infineon.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=valentina.fernandezalanis@microchip.com \
    --cc=vigneshr@ti.com \
    --cc=xianwei.zhao@amlogic.com \
    /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

all inboxes | Powered by JetHome®