Skip to content

Commit 0fddf9a

Browse files
saschahauerrichardweinberger
authored andcommitted
mtd: rawnand: gpmi: Set WAIT_FOR_READY timeout based on program/erase times
06781a5 Fixes the calculation of the DEVICE_BUSY_TIMEOUT register value from busy_timeout_cycles. busy_timeout_cycles is calculated wrong though: It is calculated based on the maximum page read time, but the timeout is also used for page write and block erase operations which require orders of magnitude bigger timeouts. Fix this by calculating busy_timeout_cycles from the maximum of tBERS_max and tPROG_max. This is for now the easiest and most obvious way to fix the driver. There's room for improvements though: The NAND_OP_WAITRDY_INSTR tells us the desired timeout for the current operation, so we could program the timeout dynamically for each operation instead of setting a fixed timeout. Also we could wire up the interrupt handler to actually detect and forward timeouts occurred when waiting for the chip being ready. As a sidenote I verified that the change in 06781a5 is really correct. I wired up the interrupt handler in my tree and measured the time between starting the operation and the timeout interrupt handler coming in. The time increases 41us with each step in the timeout register which corresponds to 4096 clock cycles with the 99MHz clock that I have. Fixes: 06781a5 ("mtd: rawnand: gpmi: Fix setting busy timeout setting") Fixes: b120612 ("mtd: rawniand: gpmi: use core timings instead of an empirical derivation") Cc: [email protected] Signed-off-by: Sascha Hauer <[email protected]> Acked-by: Han Xu <[email protected]> Tested-by: Tomasz Moń <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 3234649 commit 0fddf9a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,10 @@ static int gpmi_nfc_compute_timings(struct gpmi_nand_data *this,
850850
unsigned int tRP_ps;
851851
bool use_half_period;
852852
int sample_delay_ps, sample_delay_factor;
853-
u16 busy_timeout_cycles;
853+
unsigned int busy_timeout_cycles;
854854
u8 wrn_dly_sel;
855855
unsigned long clk_rate, min_rate;
856+
u64 busy_timeout_ps;
856857

857858
if (sdr->tRC_min >= 30000) {
858859
/* ONFI non-EDO modes [0-3] */
@@ -885,7 +886,8 @@ static int gpmi_nfc_compute_timings(struct gpmi_nand_data *this,
885886
addr_setup_cycles = TO_CYCLES(sdr->tALS_min, period_ps);
886887
data_setup_cycles = TO_CYCLES(sdr->tDS_min, period_ps);
887888
data_hold_cycles = TO_CYCLES(sdr->tDH_min, period_ps);
888-
busy_timeout_cycles = TO_CYCLES(sdr->tWB_max + sdr->tR_max, period_ps);
889+
busy_timeout_ps = max(sdr->tBERS_max, sdr->tPROG_max);
890+
busy_timeout_cycles = TO_CYCLES(busy_timeout_ps, period_ps);
889891

890892
hw->timing0 = BF_GPMI_TIMING0_ADDRESS_SETUP(addr_setup_cycles) |
891893
BF_GPMI_TIMING0_DATA_HOLD(data_hold_cycles) |

0 commit comments

Comments
 (0)