Commit 0de06cfb authored by Sergei Miroshnichenko's avatar Sergei Miroshnichenko

RM#1357 stm32: qspi: Fix support for flashes smaller than 16MiB

parent 9866fea4
......@@ -111,6 +111,7 @@ struct stm32_qspi_priv {
size_t erase_size;
size_t write_size;
int fast_read_dummy;
int support_4bytes;
};
static struct stm32_qspi_priv *stm32_qspi = NULL;
......@@ -329,10 +330,14 @@ static int switch_to_memory_mapped(struct stm32_qspi_priv *priv)
goto fail;
writel(QSPI_CCR_FMODE_MEMORY_MAP
| SPINOR_OP_FAST_READ_4B
| (stm32_qspi->support_4bytes
? SPINOR_OP_FAST_READ_4B
: SPINOR_OP_FAST_READ)
| QSPI_CCR_IMODE_SINGLE_LINE
| QSPI_CCR_ADMODE_FOUR_LINES
| QSPI_CCR_ADSIZE_FOUR_BYTES
| (stm32_qspi->support_4bytes
? QSPI_CCR_ADSIZE_FOUR_BYTES
: QSPI_CCR_ADSIZE_THREE_BYTES)
| QSPI_CCR_DMODE_FOUR_LINES
| QSPI_CCR_DCYC(priv->fast_read_dummy),
&priv->regs->ccr);
......@@ -363,7 +368,9 @@ static int erase_block(struct stm32_qspi_priv *priv, u32 address)
| SPINOR_OP_SE
| QSPI_CCR_IMODE_SINGLE_LINE
| QSPI_CCR_ADMODE_SINGLE_LINE
| QSPI_CCR_ADSIZE_FOUR_BYTES
| (stm32_qspi->support_4bytes
? QSPI_CCR_ADSIZE_FOUR_BYTES
: QSPI_CCR_ADSIZE_THREE_BYTES)
| QSPI_CCR_DMODE_NONE
| QSPI_CCR_DCYC(0),
&priv->regs->ccr);
......@@ -442,7 +449,9 @@ static int write_page(struct stm32_qspi_priv *priv, u32 address, const u8 *buf,
| CONFIG_STM32_QSPI_FAST_PROGRAM_CMD
| QSPI_CCR_IMODE_SINGLE_LINE
| QSPI_CCR_ADMODE_FOUR_LINES
| QSPI_CCR_ADSIZE_FOUR_BYTES
| (stm32_qspi->support_4bytes
? QSPI_CCR_ADSIZE_FOUR_BYTES
: QSPI_CCR_ADSIZE_THREE_BYTES)
| QSPI_CCR_DMODE_FOUR_LINES
| QSPI_CCR_DCYC(0),
&priv->regs->ccr);
......@@ -587,10 +596,15 @@ int stm32_qspi_init(void)
return err;
}
err = enter_4_bytes_mode(stm32_qspi);
if (err) {
error("%s: unable to switch to 4 byte mode addressing: %d\n", __func__, err);
return err;
/* 4 bytes addressing is only supported for flashes bigger than 16MiB */
stm32_qspi->support_4bytes = !!(CONFIG_SPI_FLASH_SIZE_OFF > 24);
if (stm32_qspi->support_4bytes) {
err = enter_4_bytes_mode(stm32_qspi);
if (err) {
error("%s: unable to switch to 4 byte mode addressing: %d\n", __func__, err);
return err;
}
}
err = switch_to_memory_mapped(stm32_qspi);
......
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