Skip to content

Commit 7fa9f44

Browse files
committed
spi: microchip-core-qspi: fix transfer_one() for reads
If a transfer is a pure read, only read_op() is called by the driver, which only reads from the rx FIFO, without actually affecting the bus. Without affecting the bus, nothing will have actually populated the FIFOs and the driver will spin forever, waiting for data that will not arrive. Use write_read_op() instead, modifying it so that it will emit dummy data to generate clock pulses if the tx buffer is empty, thereby populating the rx FIFO with the requested read. Fixes: 858175e ("spi: microchip-core-qspi: Add regular transfers") Signed-off-by: Conor Dooley <[email protected]>
1 parent e9803a6 commit 7fa9f44

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/spi/spi-microchip-core-qspi.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ static inline void mchp_coreqspi_write_read_op(struct mchp_coreqspi *qspi)
236236
while (readl_relaxed(qspi->regs + REG_STATUS) & STATUS_TXFIFOFULL)
237237
;
238238

239-
data = *(u32 *)qspi->txbuf;
240-
qspi->txbuf += 4;
239+
data = qspi->txbuf ? *((u32 *)qspi->txbuf) : 0xaa;
240+
if (qspi->txbuf)
241+
qspi->txbuf += 4;
241242
qspi->tx_len -= 4;
242243
writel_relaxed(data, qspi->regs + REG_X4_TX_DATA);
243244

@@ -289,7 +290,8 @@ static inline void mchp_coreqspi_write_read_op(struct mchp_coreqspi *qspi)
289290
while (qspi->tx_len--) {
290291
while (readl_relaxed(qspi->regs + REG_STATUS) & STATUS_TXFIFOFULL)
291292
;
292-
data = *qspi->txbuf++;
293+
data = qspi->txbuf ? *qspi->txbuf : 0xaa;
294+
qspi->txbuf++;
293295
writel_relaxed(data, qspi->regs + REG_TX_DATA);
294296
}
295297

@@ -654,19 +656,17 @@ static int mchp_coreqspi_transfer_one(struct spi_controller *ctlr, struct spi_de
654656
{
655657
struct mchp_coreqspi *qspi = spi_controller_get_devdata(ctlr);
656658

657-
if ((t->tx_buf) && (t->rx_buf)){
658-
qspi->txbuf = (u8 *)t->tx_buf;
659-
qspi->rxbuf = (u8 *)t->rx_buf;
660-
qspi->tx_len = t->len;
661-
mchp_coreqspi_write_read_op(qspi);
662-
} else if (t->tx_buf) {
659+
qspi->tx_len = t->len;
660+
661+
if (t->tx_buf)
663662
qspi->txbuf = (u8 *)t->tx_buf;
664-
qspi->tx_len = t->len;
663+
664+
if (!t->rx_buf) {
665665
mchp_coreqspi_write_op(qspi);
666666
} else {
667667
qspi->rxbuf = (u8 *)t->rx_buf;
668668
qspi->rx_len = t->len;
669-
mchp_coreqspi_read_op(qspi);
669+
mchp_coreqspi_write_read_op(qspi);
670670
}
671671

672672
return 0;

0 commit comments

Comments
 (0)