[1/4] spi: mxic: Fix transmit path
diff mbox series

Message ID 20190919202504.9619-1-miquel.raynal@bootlin.com
State New
Headers show
Series
  • [1/4] spi: mxic: Fix transmit path
Related show

Commit Message

Miquel Raynal Sept. 19, 2019, 8:25 p.m. UTC
In certain circumstances, it is needed to check INT_TX_EMPTY and
INT_RX_NOT_EMPTY in the transmit path, not only in the receive
path. In both cases, the delay penalty is negligible.

Fixes: b942d80b0a39 ("spi: Add MXIC controller driver")
Cc: stable@vger.kernel.org
Suggested-by: Mason Yang <masonccyang@mxic.com.tw>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/spi/spi-mxic.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

Comments

Mark Brown Sept. 20, 2019, 11:02 a.m. UTC | #1
On Thu, Sep 19, 2019 at 10:25:01PM +0200, Miquel Raynal wrote:
> In certain circumstances, it is needed to check INT_TX_EMPTY and
> INT_RX_NOT_EMPTY in the transmit path, not only in the receive
> path. In both cases, the delay penalty is negligible.

In which circumstances and why is this required?

Patch
diff mbox series

diff --git a/drivers/spi/spi-mxic.c b/drivers/spi/spi-mxic.c
index f48563c09b97..eaa7a6a9044d 100644
--- a/drivers/spi/spi-mxic.c
+++ b/drivers/spi/spi-mxic.c
@@ -304,25 +304,21 @@  static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,
 
 		writel(data, mxic->regs + TXD(nbytes % 4));
 
+		ret = readl_poll_timeout(mxic->regs + INT_STS, sts,
+					 sts & INT_TX_EMPTY, 0, USEC_PER_SEC);
+		if (ret)
+			return ret;
+
+		ret = readl_poll_timeout(mxic->regs + INT_STS, sts,
+					 sts & INT_RX_NOT_EMPTY, 0,
+					 USEC_PER_SEC);
+		if (ret)
+			return ret;
+
+		data = readl(mxic->regs + RXD);
 		if (rxbuf) {
-			ret = readl_poll_timeout(mxic->regs + INT_STS, sts,
-						 sts & INT_TX_EMPTY, 0,
-						 USEC_PER_SEC);
-			if (ret)
-				return ret;
-
-			ret = readl_poll_timeout(mxic->regs + INT_STS, sts,
-						 sts & INT_RX_NOT_EMPTY, 0,
-						 USEC_PER_SEC);
-			if (ret)
-				return ret;
-
-			data = readl(mxic->regs + RXD);
 			data >>= (8 * (4 - nbytes));
 			memcpy(rxbuf + pos, &data, nbytes);
-			WARN_ON(readl(mxic->regs + INT_STS) & INT_RX_NOT_EMPTY);
-		} else {
-			readl(mxic->regs + RXD);
 		}
 		WARN_ON(readl(mxic->regs + INT_STS) & INT_RX_NOT_EMPTY);