spi: fsl_qspi: Fix flash write issue on i.MX7ULP
PATCH 1/1 spi: fsl_qspi: Fix flash write issue on i.MX7ULP
The page write sequence in spi-mem is changed with orignal spi-flash. When the max_write_size is set by driver, the orignal sequence is
1. WREN
2. write max_write_size data to flash
3. wait for WIP clean
4. back to #1 if having data remained in a page.
The new sequence is:
1. WREN
2. write (max_write_size - command length) data to flash
3. back to #2 if having data remained in a page
4. wait for WIP clean
i.MX7ULP has 64 bytes TX buffer (max_write_size), while other iMX chips have 512 bytes (page size is 256). So when adapt qspi with the new sequence, we have to check the WIP before each write on mx7ulp. Otherwise the WIP may set due to previous write is not completed by flash device, then cause current write failed.
--- drivers/spi/fsl_qspi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/spi/fsl_qspi.c +22 -0
@@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;#define OFFSET_BITS_MASK GENMASK(23, 0)#define FLASH_STATUS_WEL 0x02 +#define FLASH_STATUS_WIP 0x01/* SEQID */ #define SEQID_WREN 1
@@ -634,6 +635,27 @@ static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len) QSPI_MCR_RESERVED_MASK | QSPI_MCR_END_CFD_LE);qspi_write32 (priv->flags, ®s->rbct,QSPI_RBCT_RXBRD_USEIPS ); +if (TX_BUFFER_SIZE <=256 ) { + status_reg =0 ; +do { +WATCHDOG_RESET (); + +qspi_write32 (priv->flags, ®s->ipcr, + (SEQID_RDSR <<QSPI_IPCR_SEQID_SHIFT ) |1 ); +while (qspi_read32 (priv->flags, ®s->sr) &QSPI_SR_BUSY_MASK ) + ; + + reg =qspi_read32 (priv->flags, ®s->rbsr); +if (reg &QSPI_RBSR_RDBFL_MASK ) { + status_reg =qspi_read32 (priv->flags, ®s->rbdr[0 ]); + status_reg =qspi_endian_xchg (status_reg); + } +qspi_write32 (priv->flags, ®s->mcr, +qspi_read32 (priv->flags, ®s->mcr) | +QSPI_MCR_CLR_RXF_MASK ); + }while ((status_reg &FLASH_STATUS_WIP ) ==FLASH_STATUS_WIP ); + } + status_reg =0 ;while ((status_reg &FLASH_STATUS_WEL ) !=FLASH_STATUS_WEL ) {WATCHDOG_RESET ();
Signature · 1 line
2.7.4
PATCH 1/1 spi: fsl_qspi: Fix flash write issue on i.MX7ULP
Quoted 38 lines · Ye Li
The page write sequence in spi-mem is changed with orignal spi-flash. When the
max_write_sizeis set by driver, the orignal sequence is
1. WREN
2. writemax_write_sizedata to flash
3. wait for WIP clean
4. back to #1 if having data remained in a page.The new sequence is:
1. WREN
2. write (max_write_size- command length) data to flash
3. back to #2 if having data remained in a page
4. wait for WIP cleani.MX7ULP has 64 bytes TX buffer (
max_write_size), while other iMX chips have 512 bytes (page size is 256). So when adapt qspi with the new sequence, we have to check the WIP before each write on mx7ulp. Otherwise the WIP may set due to previous write is not completed by flash device, then cause current write failed.Signed-off-by Ye Li <[email protected]>--- drivers/spi/fsl_qspi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/spi/fsl_qspi.c +1
-0@@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR;#define OFFSET_BITS_MASK GENMASK(23, 0)#define FLASH_STATUS_WEL 0x02 +#define FLASH_STATUS_WIP 0x01/* SEQID */ #define SEQID_WREN 1
drivers/spi/fsl_qspi.c static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len) · line 638
Quoted 4 lines
drivers/spi/fsl_qspi.c +1
-0@@ -634,6 +635,27 @@ static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len) QSPI_MCR_RESERVED_MASK | QSPI_MCR_END_CFD_LE);qspi_write32 (priv->flags, ®s->rbct,QSPI_RBCT_RXBRD_USEIPS ); +if (TX_BUFFER_SIZE <=256 ) {
Checking macro look odd here, since the driver is already moved to dm try driver data on effected SoC compatible or similar.