From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH 2/3] nand: denali: use is_timeout in while loop
Date: Thu, 22 Sep 2016 16:46:38 +0200 [thread overview]
Message-ID: <20160922144639.28305-2-s.trumtrar@pengutronix.de> (raw)
In-Reply-To: <20160922144639.28305-1-s.trumtrar@pengutronix.de>
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>
---
drivers/mtd/nand/nand_denali.c | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/drivers/mtd/nand/nand_denali.c b/drivers/mtd/nand/nand_denali.c
index ceb5a8b87e42..6a6c0e462514 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;
}
/*
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-09-22 14:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 14:46 [PATCH 1/3] nand: denali: use correct interrupts in read_page Steffen Trumtrar
2016-09-22 14:46 ` Steffen Trumtrar [this message]
2016-09-22 14:46 ` [PATCH 3/3] nand: denali: get rid of compile-time debug information Steffen Trumtrar
2016-09-26 6:03 ` [PATCH 1/3] nand: denali: use correct interrupts in read_page Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160922144639.28305-2-s.trumtrar@pengutronix.de \
--to=s.trumtrar@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox