readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
}
+static inline void wait_for_idle(struct rockchip_spi *rs)
+{
+ unsigned long timeout = jiffies + msecs_to_jiffies(5);
+
+ do {
+ if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
+ return;
+ } while (time_before(jiffies, timeout));
+
+ dev_warn(rs->dev, "spi controller is in busy state!\n");
+}
+
static u32 get_fifo_len(struct rockchip_spi *rs)
{
u32 fifo;
cpu_relax();
} while (remain);
+ /* If tx, wait until the FIFO data completely. */
+ if (rs->tx)
+ wait_for_idle(rs);
+
return 0;
}
unsigned long flags;
struct rockchip_spi *rs = data;
+ /* Wait until the FIFO data completely. */
+ wait_for_idle(rs);
+
spin_lock_irqsave(&rs->lock, flags);
rs->state &= ~TXBUSY;
rs->tx_sg = xfer->tx_sg;
rs->rx_sg = xfer->rx_sg;
- /* Delay until the FIFO data completely */
- if (xfer->tx_buf)
- xfer->delay_usecs
- = rs->fifo_len * rs->bpw * 1000000 / rs->speed;
-
if (rs->tx && rs->rx)
rs->tmode = CR0_XFM_TR;
else if (rs->tx)