Skip to content

Commit

Permalink
spi: mediatek: Fix fifo transfer
Browse files Browse the repository at this point in the history
commit 0d5c395 upstream.

Commit 3a70dd2 ("spi: mediatek: fix fifo rx mode") claims that
fifo RX mode was never handled, and adds the presumably missing code
to the FIFO transfer function. However, the claim that receive data
was not handled is incorrect. It was handled as part of interrupt
handling after the transfer was complete. The code added with the above
mentioned commit reads data from the receive FIFO before the transfer
is started, which is wrong. This results in an actual transfer error
on a Hayato Chromebook.

Remove the code trying to handle receive data before the transfer is
started to fix the problem.

Fixes: 3a70dd2 ("spi: mediatek: fix fifo rx mode")
Cc: Peter Hess <[email protected]>
Cc: Frank Wunderlich <[email protected]>
Cc: Tzung-Bi Shih <[email protected]>
Cc: Hsin-Yi Wang <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
Tested-by: Hsin-Yi Wang <[email protected]>
Tested-by: Tzung-Bi Shih <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
groeck authored and gregkh committed Aug 8, 2021
1 parent 7254e2d commit 9c645a0
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions drivers/spi/spi-mt65xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,15 @@ static int mtk_spi_fifo_transfer(struct spi_master *master,
mtk_spi_prepare_transfer(master, xfer);
mtk_spi_setup_packet(master);

cnt = xfer->len / 4;
if (xfer->tx_buf)
if (xfer->tx_buf) {
cnt = xfer->len / 4;
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;
if (xfer->tx_buf) {
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->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);
Expand Down

0 comments on commit 9c645a0

Please sign in to comment.