diff mbox series

spi: mediatek: fix fifo rx mode

Message ID 20210706121609.680534-1-linux@fw-web.de
State New
Headers show
Series spi: mediatek: fix fifo rx mode | expand

Commit Message

Frank Wunderlich July 6, 2021, 12:16 p.m. UTC
From: Peter Hess <peter.hess@ph-home.de>

In FIFO mode were two problems:
- RX mode was never handled and
- in this case the tx_buf pointer was NULL and caused an exception

fix this by handling RX mode in mtk_spi_fifo_transfer

Fixes: a568231f4632 ("spi: mediatek: Add spi bus for Mediatek MT8173")
Signed-off-by: Peter Hess <peter.hess@ph-home.de>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
 drivers/spi/spi-mt65xx.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Mark Brown July 12, 2021, 10:45 a.m. UTC | #1
On Tue, 6 Jul 2021 14:16:09 +0200, Frank Wunderlich wrote:
> In FIFO mode were two problems:

> - RX mode was never handled and

> - in this case the tx_buf pointer was NULL and caused an exception

> 

> fix this by handling RX mode in mtk_spi_fifo_transfer


Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: mediatek: fix fifo rx mode
      commit: 3a70dd2d050331ee4cf5ad9d5c0a32d83ead9a43

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Frank Wunderlich July 23, 2021, 1:46 p.m. UTC | #2
Hi

Can we add stable-tag i've missed to fix older kernel versions or inform greg to add patch to at least 5.4/5.10?

Regards Frank
Mark Brown July 23, 2021, 1:52 p.m. UTC | #3
On Fri, Jul 23, 2021 at 03:46:02PM +0200, Frank Wunderlich wrote:

> Can we add stable-tag i've missed to fix older kernel versions or

> inform greg to add patch to at least 5.4/5.10?


Let the stable people know once it's in mainline (IIRC it is already) -
there's a good chance they'll pick it up anyway based on the commit log.

Please don't top post, reply in line with needed context.  This allows
readers to readily follow the flow of conversation and understand what
you are talking about and also helps ensure that everything in the
discussion is being addressed.

Please fix your mail client to word wrap within paragraphs at something
substantially less than 80 columns.  Doing this makes your messages much
easier to read and reply to.
diff mbox series

Patch

diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 976f73b9e299..8d5fa7f1e506 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -427,13 +427,23 @@  static int mtk_spi_fifo_transfer(struct spi_master *master,
 	mtk_spi_setup_packet(master);
 
 	cnt = xfer->len / 4;
-	iowrite32_rep(mdata->base + SPI_TX_DATA_REG, xfer->tx_buf, cnt);
+	if (xfer->tx_buf)
+		iowrite32_rep(mdata->base + SPI_TX_DATA_REG, xfer->tx_buf, cnt);
+
+	if (xfer->rx_buf)
+		ioread32_rep(mdata->base + SPI_RX_DATA_REG, xfer->rx_buf, cnt);
 
 	remainder = xfer->len % 4;
 	if (remainder > 0) {
 		reg_val = 0;
-		memcpy(&reg_val, xfer->tx_buf + (cnt * 4), remainder);
-		writel(reg_val, mdata->base + SPI_TX_DATA_REG);
+		if (xfer->tx_buf) {
+			memcpy(&reg_val, xfer->tx_buf + (cnt * 4), remainder);
+			writel(reg_val, mdata->base + SPI_TX_DATA_REG);
+		}
+		if (xfer->rx_buf) {
+			reg_val = readl(mdata->base + SPI_RX_DATA_REG);
+			memcpy(xfer->rx_buf + (cnt * 4), &reg_val, remainder);
+		}
 	}
 
 	mtk_spi_enable_transfer(master);