linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Ivo Clarysse <ivo.clarysse@gmail.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>,
	Sascha Hauer <kernel@pengutronix.de>,
	linux-arm-kernel@lists.infradead.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCHv3 4/5] mtd: mxc_nand fixups
Date: Tue, 22 Jun 2010 17:54:16 +0200	[thread overview]
Message-ID: <80iq5bqd07.fsf_-_@merkur.tec.linutronix.de> (raw)
In-Reply-To: <AANLkTikRj_dMkKLyFhW78yld9jIYAIFncfPaPAF8WqUY@mail.gmail.com> (Ivo Clarysse's message of "Mon, 21 Jun 2010 13:47:41 +0200")

The v2 version of this patch has 2 problems. I believe that this new
version addresses the problems and still respects the strange behavior
of the i.MX21.

Problem 1: The v2 patch passes IRQF_NOAUTOEN to request_irq(), but that
flag is not evaluated by request_irq(). That flag is only evaluated in
set_irq_flags(), which is now used by this patch.

Problem 2: We are still having problems with irq's possibly being
enabled twice when threaded interrupts are used. This happens because
the main thread that enables the irq can proceed even if the interrupt
hasn't fired yet (NFC_INT is set, but the irq thread hasn't processed it
yet). In this case it is possible for the main thread to enable the irq
again with a later call to wait_op_done().

This patch addresses the problem by allowing the function that enabled
the irq to also be responsible for disabling the irq. This obviously
avoids and double enabling.

In order to prevent interrupt flooding, the interrupt handler will mask
the interrupt. After the main thread has disabled the irq, it will
unmask the interrupt. This should allow the i.MX21 to work correctly
despite its masking behavior.

And finally, this patch correctly clears the interrupt bit each
time. Previously there was a case where the interrupt bit was not being
cleared.

The patch is against linux-next 20100618.

The patch is against linux-next 20100618.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/mtd/nand/mxc_nand.c |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Index: linux-next-20100618/drivers/mtd/nand/mxc_nand.c
===================================================================
--- linux-next-20100618.orig/drivers/mtd/nand/mxc_nand.c
+++ linux-next-20100618/drivers/mtd/nand/mxc_nand.c
@@ -30,6 +30,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
+#include <linux/irq.h>
 
 #include <asm/mach/flash.h>
 #include <mach/mxc_nand.h>
@@ -173,8 +174,12 @@ static const char *part_probes[] = { "Re
 static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
 {
 	struct mxc_nand_host *host = dev_id;
+	uint16_t tmp;
 
-	disable_irq_nosync(irq);
+	/* mask interrupts */
+	tmp = readw(host->regs + NFC_CONFIG1);
+	tmp |= NFC_INT_MSK;
+	writew(tmp, host->regs + NFC_CONFIG1);
 
 	wake_up(&host->irq_waitq);
 
@@ -197,10 +202,18 @@ static void wait_op_done(struct mxc_nand
 			wait_event(host->irq_waitq,
 				readw(host->regs + NFC_CONFIG2) & NFC_INT);
 
-			tmp = readw(host->regs + NFC_CONFIG2);
-			tmp  &= ~NFC_INT;
-			writew(tmp, host->regs + NFC_CONFIG2);
+			disable_irq(host->irq);
+
+			/* unmask interrupts */
+			tmp = readw(host->regs + NFC_CONFIG1);
+			tmp &= ~NFC_INT_MSK;
+			writew(tmp, host->regs + NFC_CONFIG1);
 		}
+
+		/* clear interrupt flag */
+		tmp = readw(host->regs + NFC_CONFIG2);
+		tmp &= ~NFC_INT;
+		writew(tmp, host->regs + NFC_CONFIG2);
 	} else {
 		while (max_retries-- > 0) {
 			if (readw(host->regs + NFC_CONFIG2) & NFC_INT) {
@@ -846,7 +859,9 @@ static int __init mxcnd_probe(struct pla
 
 	host->irq = platform_get_irq(pdev, 0);
 
-	err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host);
+	/* request irq as disabled */
+	set_irq_flags(host->irq, IRQF_VALID | IRQF_NOAUTOEN);
+	err = request_irq(host->irq, mxc_nfc_irq, 0, DRIVER_NAME, host);
 	if (err)
 		goto eirq;
 

  reply	other threads:[~2010-06-22 15:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-18 17:01 [PATCH 4/5] mtd: mxc_nand fixups John Ogness
2010-06-18 20:54 ` Sascha Hauer
2010-06-19 20:25   ` John Ogness
     [not found]     ` <AANLkTimA7Rbm_nHpVYpEPqaPCjrOse9s8YyiInWlhfEK@mail.gmail.com>
2010-06-20  9:21       ` [PATCHv2 " John Ogness
2010-06-21 11:47         ` Ivo Clarysse
2010-06-22 15:54           ` John Ogness [this message]
2010-06-23  7:34             ` [PATCHv3 " Ivo Clarysse
2010-06-23  8:48               ` John Ogness
2010-06-23  9:23                 ` Ivo Clarysse
2010-06-23 10:10                   ` John Ogness
2010-06-24  7:27                     ` Sascha Hauer
2010-06-24 10:16                       ` John Ogness
2010-06-25 14:50                         ` Ivo Clarysse
2010-06-26  9:17                           ` John Ogness
2010-07-01 14:24                             ` Ivo Clarysse
2010-06-25 14:46                       ` Ivo Clarysse

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=80iq5bqd07.fsf_-_@merkur.tec.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=ivo.clarysse@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).