[PATCH RFC v2 34/35] spi: zynqmp-gqspi: Consume dummy cycles directly
Miquel Raynal
miquel.raynal at bootlin.com
Fri Nov 27 06:22:56 PST 2026
The controller programs the dummy phase in clock cycles in the GEN_FIFO,
but the driver converts the legacy dummy byte count itself. Advertise the
dummy_cycles capability and use op->dummy.ncycles directly.
Store the dummy cycle count in a dedicated dummy_cycles field instead of
reusing bytes_to_transfer, which is reserved for byte-oriented transfers.
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
drivers/spi/spi-zynqmp-gqspi.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index 15e9d3ef8839..6289e33c2807 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -176,6 +176,8 @@ struct qspi_platform_data {
* @rxbuf: Pointer to the RX buffer
* @bytes_to_transfer: Number of bytes left to transfer
* @bytes_to_receive: Number of bytes left to receive
+ * @dummy_cycles: Number of dummy cycles to insert
+ * @dummy_phase: Whether the dummy phase is currently executing
* @genfifocs: Used for chip select
* @genfifobus: Used to select the upper or lower bus
* @dma_rx_bytes: Remaining bytes to receive by DMA mode
@@ -198,6 +200,8 @@ struct zynqmp_qspi {
void *rxbuf;
int bytes_to_transfer;
int bytes_to_receive;
+ u32 dummy_cycles;
+ bool dummy_phase;
u32 genfifocs;
u32 genfifobus;
u32 dma_rx_bytes;
@@ -681,8 +685,14 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits,
transfer_len = xqspi->dma_rx_bytes;
else
transfer_len = xqspi->bytes_to_receive;
- } else {
+ } else if (xqspi->txbuf) {
transfer_len = xqspi->bytes_to_transfer;
+ } else {
+ /*
+ * The GEN_FIFO immediate_data field carries a number of
+ * dummy SCLK cycles, not a byte count.
+ */
+ transfer_len = xqspi->dummy_cycles;
}
if (xqspi->txbuf)
@@ -832,7 +842,8 @@ static irqreturn_t zynqmp_qspi_irq(int irq, void *dev_id)
(mask & GQSPI_IER_GENFIFOEMPTY_MASK))
zynqmp_qspi_readrxfifo(xqspi, GQSPI_RX_FIFO_FILL);
- if (xqspi->bytes_to_receive == 0 && xqspi->bytes_to_transfer == 0 &&
+ if (!xqspi->dummy_phase &&
+ xqspi->bytes_to_receive == 0 && xqspi->bytes_to_transfer == 0 &&
((status & GQSPI_IRQ_MASK) == GQSPI_IRQ_MASK)) {
zynqmp_gqspi_write(xqspi, GQSPI_IDR_OFST, GQSPI_ISR_IDR_MASK);
complete(&xqspi->data_completion);
@@ -1109,15 +1120,13 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
}
}
- if (op->dummy.nbytes) {
+ if (op->dummy.ncycles) {
xqspi->txbuf = NULL;
xqspi->rxbuf = NULL;
- /*
- * xqspi->bytes_to_transfer here represents the dummy circles
- * which need to be sent.
- */
- xqspi->bytes_to_transfer = op->dummy.nbytes * 8 / op->dummy.buswidth;
+ xqspi->dummy_cycles = op->dummy.ncycles;
+ xqspi->bytes_to_transfer = 0;
xqspi->bytes_to_receive = 0;
+ xqspi->dummy_phase = true;
/*
* Using op->data.buswidth instead of op->dummy.buswidth here because
* we need to use it to configure the correct SPI mode.
@@ -1136,6 +1145,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
xqspi->rxbuf = NULL;
xqspi->bytes_to_transfer = op->data.nbytes;
xqspi->bytes_to_receive = 0;
+ xqspi->dummy_phase = false;
zynqmp_qspi_write_op(xqspi, op->data.buswidth,
genfifoentry);
zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
@@ -1151,6 +1161,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
xqspi->rxbuf = (u8 *)op->data.buf.in;
xqspi->bytes_to_receive = op->data.nbytes;
xqspi->bytes_to_transfer = 0;
+ xqspi->dummy_phase = false;
err = zynqmp_qspi_read_op(xqspi, op->data.buswidth,
genfifoentry);
if (err)
@@ -1179,6 +1190,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
return_err:
+ xqspi->dummy_phase = false;
zynqmp_qspi_chipselect(mem->spi, true);
mutex_unlock(&xqspi->op_lock);
@@ -1206,6 +1218,7 @@ static const struct spi_controller_mem_ops zynqmp_qspi_mem_ops = {
static const struct spi_controller_mem_caps zynqmp_qspi_mem_caps = {
.per_op_freq = true,
+ .dummy_cycles = true,
};
/**
--
2.56.0
More information about the linux-riscv
mailing list