diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/fsl_qspi.c | 25 | ||||
-rw-r--r-- | drivers/spi/fsl_qspi.h | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index 117f3fa..6e5c3b0 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -166,6 +166,26 @@ static inline u32 qspi_endian_xchg(u32 data) return data; #endif } +static inline u32 qspi_controller_busy(struct fsl_qspi_priv *priv) +{ + u32 sr; + u32 retry = 5; + + do { + sr = qspi_read32(priv->flags, &priv->regs->sr); + if ((sr & QSPI_SR_BUSY_MASK) || + (sr & QSPI_SR_AHB_ACC_MASK) || + (sr & QSPI_SR_IP_ACC_MASK)) { + debug("The controller is busy, sr = 0x%x\n", sr); + udelay(1); + } else { + break; + } + } while (--retry); + + return (sr & QSPI_SR_BUSY_MASK) || + (sr & QSPI_SR_AHB_ACC_MASK) || (sr & QSPI_SR_IP_ACC_MASK); +} static void qspi_set_lut(struct fsl_qspi_priv *priv) { @@ -759,6 +779,11 @@ int qspi_xfer(struct fsl_qspi_priv *priv, unsigned int bitlen, static u32 wr_sfaddr; u32 txbuf; + if (qspi_controller_busy(priv)) { + printf("ERROR : The controller is busy\n"); + return -EBUSY; + } + if (dout) { if (flags & SPI_XFER_BEGIN) { priv->cur_seqid = *(u8 *)dout; diff --git a/drivers/spi/fsl_qspi.h b/drivers/spi/fsl_qspi.h index 6cb3610..e468eb2 100644 --- a/drivers/spi/fsl_qspi.h +++ b/drivers/spi/fsl_qspi.h @@ -105,6 +105,10 @@ struct fsl_qspi_regs { #define QSPI_RBCT_RXBRD_SHIFT 8 #define QSPI_RBCT_RXBRD_USEIPS (1 << QSPI_RBCT_RXBRD_SHIFT) +#define QSPI_SR_AHB_ACC_SHIFT 2 +#define QSPI_SR_AHB_ACC_MASK (1 << QSPI_SR_AHB_ACC_SHIFT) +#define QSPI_SR_IP_ACC_SHIFT 1 +#define QSPI_SR_IP_ACC_MASK (1 << QSPI_SR_IP_ACC_SHIFT) #define QSPI_SR_BUSY_SHIFT 0 #define QSPI_SR_BUSY_MASK (1 << QSPI_SR_BUSY_SHIFT) |