Commit 4114b17a authored by Christophe Kerello's avatar Christophe Kerello Committed by Miquel Raynal

mtd: rawnand: stm32_fmc2: avoid to lock the CPU bus

We are currently using nand_soft_waitrdy to poll the status of the NAND
flash. FMC2 enables the wait feature bit (this feature is mandatory for
the sequencer mode). By enabling this feature, we can't poll the status
of the NAND flash, the read status command is stucked in FMC2 pipeline
until R/B# signal is high, and locks the CPU bus.
To avoid to lock the CPU bus, we poll FMC2 ISR register. This register
reports the status of the R/B# signal.

Fixes: 2cd457f3 ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver")
Signed-off-by: default avatarChristophe Kerello <christophe.kerello@st.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent c79f46a2
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
/* Max ECC buffer length */ /* Max ECC buffer length */
#define FMC2_MAX_ECC_BUF_LEN (FMC2_BCHDSRS_LEN * FMC2_MAX_SG) #define FMC2_MAX_ECC_BUF_LEN (FMC2_BCHDSRS_LEN * FMC2_MAX_SG)
#define FMC2_TIMEOUT_US 1000
#define FMC2_TIMEOUT_MS 1000 #define FMC2_TIMEOUT_MS 1000
/* Timings */ /* Timings */
...@@ -53,6 +54,8 @@ ...@@ -53,6 +54,8 @@
#define FMC2_PMEM 0x88 #define FMC2_PMEM 0x88
#define FMC2_PATT 0x8c #define FMC2_PATT 0x8c
#define FMC2_HECCR 0x94 #define FMC2_HECCR 0x94
#define FMC2_ISR 0x184
#define FMC2_ICR 0x188
#define FMC2_CSQCR 0x200 #define FMC2_CSQCR 0x200
#define FMC2_CSQCFGR1 0x204 #define FMC2_CSQCFGR1 0x204
#define FMC2_CSQCFGR2 0x208 #define FMC2_CSQCFGR2 0x208
...@@ -118,6 +121,12 @@ ...@@ -118,6 +121,12 @@
#define FMC2_PATT_ATTHIZ(x) (((x) & 0xff) << 24) #define FMC2_PATT_ATTHIZ(x) (((x) & 0xff) << 24)
#define FMC2_PATT_DEFAULT 0x0a0a0a0a #define FMC2_PATT_DEFAULT 0x0a0a0a0a
/* Register: FMC2_ISR */
#define FMC2_ISR_IHLF BIT(1)
/* Register: FMC2_ICR */
#define FMC2_ICR_CIHLF BIT(1)
/* Register: FMC2_CSQCR */ /* Register: FMC2_CSQCR */
#define FMC2_CSQCR_CSQSTART BIT(0) #define FMC2_CSQCR_CSQSTART BIT(0)
...@@ -1322,6 +1331,31 @@ static void stm32_fmc2_write_data(struct nand_chip *chip, const void *buf, ...@@ -1322,6 +1331,31 @@ static void stm32_fmc2_write_data(struct nand_chip *chip, const void *buf,
stm32_fmc2_set_buswidth_16(fmc2, true); stm32_fmc2_set_buswidth_16(fmc2, true);
} }
static int stm32_fmc2_waitrdy(struct nand_chip *chip, unsigned long timeout_ms)
{
struct stm32_fmc2_nfc *fmc2 = to_stm32_nfc(chip->controller);
const struct nand_sdr_timings *timings;
u32 isr, sr;
/* Check if there is no pending requests to the NAND flash */
if (readl_relaxed_poll_timeout_atomic(fmc2->io_base + FMC2_SR, sr,
sr & FMC2_SR_NWRF, 1,
FMC2_TIMEOUT_US))
dev_warn(fmc2->dev, "Waitrdy timeout\n");
/* Wait tWB before R/B# signal is low */
timings = nand_get_sdr_timings(&chip->data_interface);
ndelay(PSEC_TO_NSEC(timings->tWB_max));
/* R/B# signal is low, clear high level flag */
writel_relaxed(FMC2_ICR_CIHLF, fmc2->io_base + FMC2_ICR);
/* Wait R/B# signal is high */
return readl_relaxed_poll_timeout_atomic(fmc2->io_base + FMC2_ISR,
isr, isr & FMC2_ISR_IHLF,
5, 1000 * timeout_ms);
}
static int stm32_fmc2_exec_op(struct nand_chip *chip, static int stm32_fmc2_exec_op(struct nand_chip *chip,
const struct nand_operation *op, const struct nand_operation *op,
bool check_only) bool check_only)
...@@ -1366,7 +1400,7 @@ static int stm32_fmc2_exec_op(struct nand_chip *chip, ...@@ -1366,7 +1400,7 @@ static int stm32_fmc2_exec_op(struct nand_chip *chip,
break; break;
case NAND_OP_WAITRDY_INSTR: case NAND_OP_WAITRDY_INSTR:
ret = nand_soft_waitrdy(chip, ret = stm32_fmc2_waitrdy(chip,
instr->ctx.waitrdy.timeout_ms); instr->ctx.waitrdy.timeout_ms);
break; break;
} }
......
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