linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Jander <david.jander@protonic.nl>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: David Jander <david@protonic.nl>,
	Grant Likely <grant.likely@secretlab.ca>,
	linux-input@vger.kernel.org
Subject: Re: [PATCH v4 3/3] Input: gpio_keys.c: Enable use with non-local GPIO chips.
Date: Fri, 16 Mar 2012 09:17:01 +0100	[thread overview]
Message-ID: <20120316091701.4ee5f380@archvile> (raw)
In-Reply-To: <20120316072004.GB16291@core.coreip.homeip.net>

On Fri, 16 Mar 2012 00:20:04 -0700
Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:

> Hi David,
> 
> On Tue, Jun 14, 2011 at 11:08:11AM +0200, David Jander wrote:
> > Use a threaded interrupt handler in order to permit the handler to use
> > a GPIO driver that causes things like I2C transactions being done inside
> > the handler context.
> > Also, gpio_keys_init needs to be declared as a late_initcall, to make sure
> > all needed GPIO drivers have been loaded if the drivers are built into the
> > kernel.
> 
> Don't want to resurrect the whole initcall discussion, but could you
> tell me again why the interrup handler needs to be threaded? We do not
> access hardware from it, hardware is accessed from workqueue context.
> Here is the ISR in its entirety:

Sorry, the reason described is apparently not very clear. The real reason seems
to be that I would like this driver to work with I2C GPIO expanders, and its
the GPIO expanders "interrupt controller" which has itself a threaded handler
(due to I2C transfers done in it to ack an IRQ). So this is actually a nested
and threaded interrupt controller (because the IRQ line of the GPIO expander
is connected to a different GPIO acting itself also as interrupt line).
In irq/manage.c, function __setup_irq():

...
	/*
	 * Check whether the interrupt nests into another interrupt
	 * thread.
	 */
	nested = irq_settings_is_nested_thread(desc);
	if (nested) {
		if (!new->thread_fn) {
			ret = -EINVAL;
			goto out_mput;
		}
...

This is were requesting a non-threaded IRQ from this GPIO controller will fail.

I know this is not a trivial setup, but IMHO it is very useful (for
connecting keyboards), and a nice demonstration of the powerful features this
GPIO driver has :-)

> static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
> {
>         struct gpio_button_data *bdata = dev_id;
>         const struct gpio_keys_button *button = bdata->button;
> 
>         BUG_ON(irq != gpio_to_irq(button->gpio));
> 
>         if (bdata->timer_debounce)
>                 mod_timer(&bdata->timer,
>                         jiffies + msecs_to_jiffies(bdata->timer_debounce));
>         else
>                 schedule_work(&bdata->work);
> 
>         return IRQ_HANDLED;
> }
> 
> It looks to me that non-threaded handler would work as well? Or
> gpio_to_irq() can sleep with certain chips?

Not in my case. I just checked again. If I change request_threaded_irq() to
request_irq(), I get this:

...
[    6.409810] gpio-keys gpio_keys.0: Unable to claim irq 0; error -22
[    6.416106] gpio-keys: probe of gpio_keys.0 failed with error -22
...

This error -22 (-EINVAL) is returned from __setup_irq() (see above).

BTW: The connections of CPU-GPIO -> IRQ of PCA9539 -> GPIO -> gpio_key is
entirely done in the device tree, which is also sort of cool ;-)

Best regards,

-- 
David Jander
Protonic Holland.

  reply	other threads:[~2012-03-16  8:34 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-14  9:08 [PATCH v4 0/3] Input: gpio_keys.c: Add support for OF and I2C GPIO chips David Jander
2011-06-14  9:08 ` [PATCH v4 1/3] Input: gpio_keys.c: Simplify platform_device -> device casting David Jander
2011-06-16 19:28   ` Grant Likely
2011-06-18 10:19   ` Dmitry Torokhov
2011-06-20  6:52     ` David Jander
2011-06-20  8:32       ` Dmitry Torokhov
2011-06-14  9:08 ` [PATCH v4 2/3] Input: gpio_keys.c: Added support for device-tree platform data David Jander
2011-06-16 19:25   ` Grant Likely
2011-06-17  8:58     ` David Jander
2011-06-17 12:54       ` Grant Likely
2011-06-23  8:24         ` Dmitry Torokhov
2011-06-23  8:55           ` David Jander
2011-06-14  9:08 ` [PATCH v4 3/3] Input: gpio_keys.c: Enable use with non-local GPIO chips David Jander
2011-06-16 19:27   ` Grant Likely
2011-06-18 10:17     ` Dmitry Torokhov
2011-06-18 13:18       ` Grant Likely
2011-06-18 14:51         ` Dmitry Torokhov
2011-06-18 15:16           ` Grant Likely
2011-06-20  7:48             ` David Jander
2011-06-20  8:45               ` Dmitry Torokhov
2011-06-20  9:33                 ` David Jander
2011-06-20 18:49                   ` Grant Likely
2011-06-20 18:13                 ` Grant Likely
2011-06-21 11:46                 ` Mark Brown
     [not found]                   ` <BANLkTikjUR_9wq_tGfomLZNdurvmEH1Jxw@mail.gmail.com>
2011-06-21 14:36                     ` David Jander
2011-06-21 17:27                     ` Mark Brown
2011-06-21 20:48                       ` Dmitry Torokhov
2011-06-21 23:02                         ` Mark Brown
2011-06-22  6:11                           ` David Jander
2011-06-22  7:00                           ` Dmitry Torokhov
2011-06-22 11:38                             ` Mark Brown
2011-06-22 14:58                               ` Grant Likely
2011-06-22 21:43                                 ` Dmitry Torokhov
2011-06-20 17:03         ` H Hartley Sweeten
2011-06-20 18:20           ` Grant Likely
2011-06-21  6:55             ` David Jander
2011-06-21  7:04               ` Grant Likely
2012-03-16  7:20   ` Dmitry Torokhov
2012-03-16  8:17     ` David Jander [this message]
2012-03-16  8:32       ` Dmitry Torokhov
2012-03-16  8:48         ` David Jander
2012-03-16 10:19           ` Ben Dooks
2012-03-16 10:18     ` Ben Dooks
2012-03-16 11:08       ` David Jander

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=20120316091701.4ee5f380@archvile \
    --to=david.jander@protonic.nl \
    --cc=david@protonic.nl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-input@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).