From a6c453168c44c6f8ef05e464b3b5738a4d3293d4 Mon Sep 17 00:00:00 2001 From: Steffen Trumtrar Date: Thu, 22 Sep 2016 16:46:38 +0200 Subject: nand: denali: use is_timeout in while loop Instead of using udelay and a countdown, use the is_timeout function. Also, move the code closer to the kernel version, i.e. check for the correct bank and clean the interrupt status. Signed-off-by: Steffen Trumtrar Signed-off-by: Sascha Hauer --- drivers/mtd/nand/nand_denali.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'drivers/mtd/nand/nand_denali.c') diff --git a/drivers/mtd/nand/nand_denali.c b/drivers/mtd/nand/nand_denali.c index ceb5a8b87e..6a6c0e4625 100644 --- a/drivers/mtd/nand/nand_denali.c +++ b/drivers/mtd/nand/nand_denali.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -633,26 +634,32 @@ static uint32_t read_interrupt_status(struct denali_nand_info *denali) static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask) { - unsigned long comp_res = 1000; uint32_t intr_status = 0; + uint64_t start; - do { + if (!is_flash_bank_valid(denali->flash_bank)) { + dev_dbg(denali->dev, "No valid chip selected (%d)\n", + denali->flash_bank); + return 0; + } + + start = get_time_ns(); + + while (!is_timeout(start, 1000 * MSECOND)) { intr_status = read_interrupt_status(denali); - if (intr_status & irq_mask) { - /* our interrupt was detected */ - break; - } - udelay(1); - comp_res--; - } while (comp_res != 0); - - if (comp_res == 0) { - /* timeout */ - intr_status = 0; - dev_dbg(denali->dev, "timeout occurred, status = 0x%x, mask = 0x%x\n", - intr_status, irq_mask); + + if (intr_status != 0) + clear_interrupt(denali, intr_status); + + if (intr_status & irq_mask) + return intr_status; } - return intr_status; + + /* timeout */ + dev_dbg(denali->dev, "timeout occurred, status = 0x%x, mask = 0x%x\n", + intr_status, irq_mask); + + return 0; } /* -- cgit v1.2.3