Commit 3a70dd2d authored by Peter Hess's avatar Peter Hess Committed by Mark Brown

spi: mediatek: fix fifo rx mode

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: a568231f ("spi: mediatek: Add spi bus for Mediatek MT8173")
Signed-off-by: default avatarPeter Hess <peter.hess@ph-home.de>
Signed-off-by: default avatarFrank Wunderlich <frank-w@public-files.de>
Link: https://lore.kernel.org/r/20210706121609.680534-1-linux@fw-web.deSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 69e1818a
...@@ -427,13 +427,23 @@ static int mtk_spi_fifo_transfer(struct spi_master *master, ...@@ -427,13 +427,23 @@ static int mtk_spi_fifo_transfer(struct spi_master *master,
mtk_spi_setup_packet(master); mtk_spi_setup_packet(master);
cnt = xfer->len / 4; 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; remainder = xfer->len % 4;
if (remainder > 0) { if (remainder > 0) {
reg_val = 0; reg_val = 0;
memcpy(&reg_val, xfer->tx_buf + (cnt * 4), remainder); if (xfer->tx_buf) {
writel(reg_val, mdata->base + SPI_TX_DATA_REG); 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); mtk_spi_enable_transfer(master);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment