diff options
author | Steffen Trumtrar <s.trumtrar@pengutronix.de> | 2016-09-22 16:46:38 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-09-26 08:03:34 +0200 |
commit | a6c453168c44c6f8ef05e464b3b5738a4d3293d4 (patch) | |
tree | ace50103171f2885f1c1aa2395813b1cca279fa1 /drivers/mtd/nand | |
parent | acc6cc82a190f1577e71164a4d10422e5d216ffb (diff) | |
download | barebox-a6c453168c44c6f8ef05e464b3b5738a4d3293d4.tar.gz barebox-a6c453168c44c6f8ef05e464b3b5738a4d3293d4.tar.xz |
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 <s.trumtrar@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r-- | drivers/mtd/nand/nand_denali.c | 39 |
1 files changed, 23 insertions, 16 deletions
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 <linux/mtd/mtd.h> #include <linux/mtd/nand.h> #include <io.h> +#include <clock.h> #include <of_mtd.h> #include <errno.h> #include <asm/io.h> @@ -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; } /* |