|
37 | 37 | /* Max ECC buffer length */
|
38 | 38 | #define FMC2_MAX_ECC_BUF_LEN (FMC2_BCHDSRS_LEN * FMC2_MAX_SG)
|
39 | 39 |
|
| 40 | +#define FMC2_TIMEOUT_US 1000 |
40 | 41 | #define FMC2_TIMEOUT_MS 1000
|
41 | 42 |
|
42 | 43 | /* Timings */
|
|
53 | 54 | #define FMC2_PMEM 0x88
|
54 | 55 | #define FMC2_PATT 0x8c
|
55 | 56 | #define FMC2_HECCR 0x94
|
| 57 | +#define FMC2_ISR 0x184 |
| 58 | +#define FMC2_ICR 0x188 |
56 | 59 | #define FMC2_CSQCR 0x200
|
57 | 60 | #define FMC2_CSQCFGR1 0x204
|
58 | 61 | #define FMC2_CSQCFGR2 0x208
|
|
118 | 121 | #define FMC2_PATT_ATTHIZ(x) (((x) & 0xff) << 24)
|
119 | 122 | #define FMC2_PATT_DEFAULT 0x0a0a0a0a
|
120 | 123 |
|
| 124 | +/* Register: FMC2_ISR */ |
| 125 | +#define FMC2_ISR_IHLF BIT(1) |
| 126 | + |
| 127 | +/* Register: FMC2_ICR */ |
| 128 | +#define FMC2_ICR_CIHLF BIT(1) |
| 129 | + |
121 | 130 | /* Register: FMC2_CSQCR */
|
122 | 131 | #define FMC2_CSQCR_CSQSTART BIT(0)
|
123 | 132 |
|
@@ -1322,6 +1331,31 @@ static void stm32_fmc2_write_data(struct nand_chip *chip, const void *buf,
|
1322 | 1331 | stm32_fmc2_set_buswidth_16(fmc2, true);
|
1323 | 1332 | }
|
1324 | 1333 |
|
| 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 | + |
1325 | 1359 | static int stm32_fmc2_exec_op(struct nand_chip *chip,
|
1326 | 1360 | const struct nand_operation *op,
|
1327 | 1361 | bool check_only)
|
@@ -1366,8 +1400,8 @@ static int stm32_fmc2_exec_op(struct nand_chip *chip,
|
1366 | 1400 | break;
|
1367 | 1401 |
|
1368 | 1402 | 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); |
1371 | 1405 | break;
|
1372 | 1406 | }
|
1373 | 1407 | }
|
|
0 commit comments