Skip to content

Commit b2d2c2b

Browse files
LeSpockymiquelraynal
authored andcommitted
mtd: rawnand: atmel: Fix pulse read timing for certain flash chips
Prevent PMECC errors when reading from AMD/Spansion S34ML02G1 flash on SAM9X60 SoC, after switching to ONFI timing mode 3. From reading the S34ML02G1 and the SAM9X60 datasheets again, it seems like we have to wait tREA after rising RE# before sampling the data. Thus pulse must be at least tREA. The previous approach to set this timing worked on sam9g20 and sama5d2 with the same flash (S34ML02G1), probably because those have a slower mck clock rate and thus the resolution of the timings setup is not as tight as with sam9x60. The approach to fix the issue was carried over from u-boot, which itself got it from at91bootstrap. It has been successfully tested in at91bootstrap, U-Boot and Linux on sam9x60 and sama5d2, for several months here. Link: linux4sam/at91bootstrap#174 Link: linux4sam/at91bootstrap@e2dfd81 Link: https://lore.kernel.org/u-boot/20240415075755.780653-1-ada@thorsis.com/ Link: https://source.denx.de/u-boot/u-boot/-/commit/344e2f2cd4a407f847b301804f37d036e8a0a10c Cc: Li Bin <bin.li@microchip.com> Signed-off-by: Alexander Dahl <ada@thorsis.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent dfea8f7 commit b2d2c2b

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/mtd/nand/raw/atmel/nand-controller.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ static int atmel_smc_nand_prepare_smcconf(struct atmel_nand *nand,
12401240
const struct nand_interface_config *conf,
12411241
struct atmel_smc_cs_conf *smcconf)
12421242
{
1243-
u32 ncycles, totalcycles, timeps, mckperiodps;
1243+
u32 ncycles, totalcycles, timeps, mckperiodps, pulse;
12441244
struct atmel_nand_controller *nc;
12451245
int ret;
12461246

@@ -1366,11 +1366,16 @@ static int atmel_smc_nand_prepare_smcconf(struct atmel_nand *nand,
13661366
ATMEL_SMC_MODE_TDFMODE_OPTIMIZED;
13671367

13681368
/*
1369-
* Read pulse timing directly matches tRP:
1369+
* Read pulse timing would directly match tRP,
1370+
* but some NAND flash chips (S34ML01G2 and W29N02KVxxAF)
1371+
* do not work properly in timing mode 3.
1372+
* The workaround is to extend the SMC NRD pulse to meet tREA
1373+
* timing.
13701374
*
1371-
* NRD_PULSE = tRP
1375+
* NRD_PULSE = max(tRP, tREA)
13721376
*/
1373-
ncycles = DIV_ROUND_UP(conf->timings.sdr.tRP_min, mckperiodps);
1377+
pulse = max(conf->timings.sdr.tRP_min, conf->timings.sdr.tREA_max);
1378+
ncycles = DIV_ROUND_UP(pulse, mckperiodps);
13741379
totalcycles += ncycles;
13751380
ret = atmel_smc_cs_conf_set_pulse(smcconf, ATMEL_SMC_NRD_SHIFT,
13761381
ncycles);

0 commit comments

Comments
 (0)