2021-07-06 12:43:42

by Frank Wunderlich

[permalink] [raw]
Subject: [PATCH] spi: mediatek: fix fifo rx mode

From: Peter Hess <[email protected]>

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 <[email protected]>
Signed-off-by: Frank Wunderlich <[email protected]>
---
drivers/spi/spi-mt65xx.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

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);
--
2.25.1


2021-07-12 11:13:04

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] spi: mediatek: fix fifo rx mode

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

2021-07-23 13:48:49

by Frank Wunderlich

[permalink] [raw]
Subject: Re: [PATCH] spi: mediatek: fix fifo rx mode

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

2021-07-23 13:54:23

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] spi: mediatek: fix fifo rx mode

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.


Attachments:
(No filename) (762.00 B)
signature.asc (499.00 B)
Download all attachments