public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Timur Tabi <timur@freescale.com>
Cc: linux-kernel@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: Ok to call disable_irq before request_irq?
Date: Tue, 05 Apr 2011 04:17:01 +0200	[thread overview]
Message-ID: <4D9A7B9D.7060604@metafoo.de> (raw)
In-Reply-To: <BANLkTikQk0OAS+41g=pk9BaqAWaVhQB9rg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

On 04/05/2011 02:53 AM, Timur Tabi wrote:
> Is it okay to call disable_irq() before calling request_irq()?  My
> device creates lots of spurious interrupts, and so I want the
> interrupt enable only when I expect a real interrupt to occur.  It
> seems to work, but I just want to make sure it's a proper technique.
> 

It might work in your case, but in general that would certainly be really bad
practice.
If the irq was not requested before request_irq should enable the IRQ
regardless of whether irq_disable was called or not.

I have a patch which adds the IRQF_NOAUTOEN flag, which allows you to request a
IRQ without automatically enabling it. Unfortunately the current version of the
patch will fail if your irq_chip implements the irq_startup callback. I've
attached the patch.

- Lars

[-- Attachment #2: irqf_noautoen.patch --]
[-- Type: text/x-diff, Size: 1681 bytes --]

commit 0fefae8354e9045e720def1233bfe51592e2dc90
Author: Lars-Peter Clausen <lars@metafoo.de>
Date:   Thu Mar 31 19:47:41 2011 +0200

    IRQF_NOAUTOEN

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 943c9b5..d596640 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -59,6 +59,7 @@
  * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend
  * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set
  * IRQF_NO_THREAD - Interrupt cannot be threaded
+ * IRQF_NOAUTOEN - Do not enable the interrupt on request
  */
 #define IRQF_DISABLED		0x00000020
 #define IRQF_SAMPLE_RANDOM	0x00000040
@@ -72,6 +73,7 @@
 #define IRQF_NO_SUSPEND		0x00004000
 #define IRQF_FORCE_RESUME	0x00008000
 #define IRQF_NO_THREAD		0x00010000
+#define IRQF_NOAUTOEN		0x00020000
 
 #define IRQF_TIMER		(__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
 
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 12a80fd..e5c538f 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -863,6 +863,10 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
 	int ret, nested, shared = 0;
 	cpumask_var_t mask;
 
+	if (new->flags & (IRQF_NOAUTOEN | IRQF_SHARED) ==
+		(IRQF_NOAUTOEN | IRQF_SHARED))
+		return -EINVAL;
+
 	if (!desc)
 		return -EINVAL;
 
@@ -998,7 +1002,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
 		if (new->flags & IRQF_ONESHOT)
 			desc->istate |= IRQS_ONESHOT;
 
-		if (irq_settings_can_autoenable(desc))
+		if (irq_settings_can_autoenable(desc) &&
+			!(new->flags & IRQF_NOAUTOEN))
 			irq_startup(desc);
 		else
 			/* Undo nested disables: */

      reply	other threads:[~2011-04-05  2:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05  0:53 Ok to call disable_irq before request_irq? Timur Tabi
2011-04-05  2:17 ` Lars-Peter Clausen [this message]

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=4D9A7B9D.7060604@metafoo.de \
    --to=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=timur@freescale.com \
    /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