Skip to content

Commit 4114b17

Browse files
Christophe Kerellomiquelraynal
authored andcommitted
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: 2cd457f ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver") Signed-off-by: Christophe Kerello <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent c79f46a commit 4114b17

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

drivers/mtd/nand/raw/stm32_fmc2_nand.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/* Max ECC buffer length */
3838
#define FMC2_MAX_ECC_BUF_LEN (FMC2_BCHDSRS_LEN * FMC2_MAX_SG)
3939

40+
#define FMC2_TIMEOUT_US 1000
4041
#define FMC2_TIMEOUT_MS 1000
4142

4243
/* Timings */
@@ -53,6 +54,8 @@
5354
#define FMC2_PMEM 0x88
5455
#define FMC2_PATT 0x8c
5556
#define FMC2_HECCR 0x94
57+
#define FMC2_ISR 0x184
58+
#define FMC2_ICR 0x188
5659
#define FMC2_CSQCR 0x200
5760
#define FMC2_CSQCFGR1 0x204
5861
#define FMC2_CSQCFGR2 0x208
@@ -118,6 +121,12 @@
118121
#define FMC2_PATT_ATTHIZ(x) (((x) & 0xff) << 24)
119122
#define FMC2_PATT_DEFAULT 0x0a0a0a0a
120123

124+
/* Register: FMC2_ISR */
125+
#define FMC2_ISR_IHLF BIT(1)
126+
127+
/* Register: FMC2_ICR */
128+
#define FMC2_ICR_CIHLF BIT(1)
129+
121130
/* Register: FMC2_CSQCR */
122131
#define FMC2_CSQCR_CSQSTART BIT(0)
123132

@@ -1322,6 +1331,31 @@ static void stm32_fmc2_write_data(struct nand_chip *chip, const void *buf,
13221331
stm32_fmc2_set_buswidth_16(fmc2, true);
13231332
}
13241333

1334+
static int stm32_fmc2_waitrdy(struct nand_chip *chip, unsigned long timeout_ms)
1335+
{
1336+
struct stm32_fmc2_nfc *fmc2 = to_stm32_nfc(chip->controller);
1337+
const struct nand_sdr_timings *timings;
1338+
u32 isr, sr;
1339+
1340+
/* Check if there is no pending requests to the NAND flash */
1341+
if (readl_relaxed_poll_timeout_atomic(fmc2->io_base + FMC2_SR, sr,
1342+
sr & FMC2_SR_NWRF, 1,
1343+
FMC2_TIMEOUT_US))
1344+
dev_warn(fmc2->dev, "Waitrdy timeout\n");
1345+
1346+
/* Wait tWB before R/B# signal is low */
1347+
timings = nand_get_sdr_timings(&chip->data_interface);
1348+
ndelay(PSEC_TO_NSEC(timings->tWB_max));
1349+
1350+
/* R/B# signal is low, clear high level flag */
1351+
writel_relaxed(FMC2_ICR_CIHLF, fmc2->io_base + FMC2_ICR);
1352+
1353+
/* Wait R/B# signal is high */
1354+
return readl_relaxed_poll_timeout_atomic(fmc2->io_base + FMC2_ISR,
1355+
isr, isr & FMC2_ISR_IHLF,
1356+
5, 1000 * timeout_ms);
1357+
}
1358+
13251359
static int stm32_fmc2_exec_op(struct nand_chip *chip,
13261360
const struct nand_operation *op,
13271361
bool check_only)
@@ -1366,8 +1400,8 @@ static int stm32_fmc2_exec_op(struct nand_chip *chip,
13661400
break;
13671401

13681402
case NAND_OP_WAITRDY_INSTR:
1369-
ret = nand_soft_waitrdy(chip,
1370-
instr->ctx.waitrdy.timeout_ms);
1403+
ret = stm32_fmc2_waitrdy(chip,
1404+
instr->ctx.waitrdy.timeout_ms);
13711405
break;
13721406
}
13731407
}

0 commit comments

Comments
 (0)