public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
To: Russell King - ARM Linux <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
Cc: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	Mark Brown
	<broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>,
	linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org,
	olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Chris Ball <cjb-2X9k7bc8m7Mdnm+yROfE0A@public.gmane.org>,
	Liam Girdwood <lrg-l0cyMroinI0@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [RFC PATCH 0/3] If an IRQ is a GPIO, request and configure it
Date: Fri, 5 Aug 2011 11:30:46 +0100	[thread overview]
Message-ID: <20110805103045.GG28651@trinity.fluff.org> (raw)
In-Reply-To: <20110805094017.GC20575-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>

On Fri, Aug 05, 2011 at 10:40:17AM +0100, Russell King - ARM Linux wrote:
> On Thu, Aug 04, 2011 at 05:00:17PM -0600, Stephen Warren wrote:
> > In http://www.spinics.net/lists/linux-tegra/msg01731.html, Mark Brown
> > pointed out that it was a little silly forcing every board or driver
> > to gpio_request() a GPIO that is later converted to an IRQ, and passed
> > to request_irq. The first patch in this series instead makes the core
> > IRQ code perform these calls when appropriate, to avoid duplicating it
> > everywhere.
> 
> Trying to go from IRQ to GPIO is not a good idea - most of the
> IRQ <-> GPIO macros we have today are just plain broken.  Many of them
> just add or subtract a constant, which means non-GPIO IRQs have an
> apparant GPIO number too.  Couple this with the fact that all positive
> GPIO numbers are valid, and this is a recipe for wrong GPIOs getting
> used and GPIOs being requested for non-GPIO IRQs.

Yes, and there's a pile without these defined/
 
> I think this was also discussed in the past, and the conclusion was that
> IRQs should be kept separate from GPIOs.  Maybe views have changed since
> then...
> 
> However, if we do want to do this, then it would be much better to provide
> a new API for requesting GPIO IRQs, eg:
> 
> gpio_request_irq()
> 
> which would wrap around request_threaded_irq(), takes a GPIO number,
> does the GPIO->IRQ conversion internally, and whatever GPIO setup is
> required.  Something like this:
> 
> int gpio_request_threaded_irq(int gpio, irq_handler_t handler,
> 	irq_handler_t thread_fn, unsigned long flags, const char *name,
> 	void *dev)
> {
> 	int ret;
> 
> 	if (!gpio_valid(gpio))
> 		return -EINVAL;
> 
> 	ret = gpio_request_one(gpio, GPIOF_IN, name);
> 	if (ret)
> 		return ret;
> 
> 	ret = request_threaded_irq(gpio_to_irq(gpio), handler, thread_fn,
> 				flags, name, dev);
> 	if (ret)
> 		gpio_free(gpio);
> 
> 	return ret;
> }
> 
> This then limits the exposure of the GPIO<->IRQ conversion macros to just
> GPIOs, where the buggy nature of the existing conversions won't impact on
> non-GPIO IRQs.

What about the case where we need to turn GPIO numbers into interrupts
to pass to other drivers? In the case where we have a gpio chip that is
providing interrupt services to other drivers (such as serial chip).

Having looked at a couple of IIO drivers, it seems that the need to use
irq_to_gpio() seems to be to check if the device needs to be service. It
would be useful to see if this is due to a problem with the threadder IRQ
handler (and if so, may need fixing for the general case).

-- 
Ben Dooks, ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.

  parent reply	other threads:[~2011-08-05 10:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-04 23:00 [RFC PATCH 0/3] If an IRQ is a GPIO, request and configure it Stephen Warren
     [not found] ` <1312498820-2275-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-08-04 23:00   ` [PATCH 1/3] irq: " Stephen Warren
2011-08-05  0:01     ` Mark Brown
     [not found]       ` <20110805000148.GB13321-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2011-08-05  3:53         ` Stephen Warren
2011-08-05  5:35           ` Mark Brown
     [not found]             ` <20110805053510.GA16956-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2011-08-05  8:06               ` Ben Dooks
2011-08-05  8:29                 ` Mark Brown
2011-08-05 15:29             ` Stephen Warren
2011-08-05 16:15               ` Mark Brown
2011-08-05  1:54     ` Rob Herring
2011-08-05  4:05       ` Stephen Warren
2011-08-05  7:58     ` Ben Dooks
2011-09-02  8:36     ` Thomas Gleixner
2011-09-02 15:24       ` Stephen Warren
     [not found]         ` <74CDBE0F657A3D45AFBB94109FB122FF04B327A55C-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2011-09-02 15:34           ` Stephen Warren
2011-09-02 15:50           ` Thomas Gleixner
2011-08-04 23:00   ` [PATCH 2/3] mmc: tegra: Don't gpio_request GPIOs used as IRQs Stephen Warren
2011-08-04 23:00   ` [PATCH 3/3] ASoC: jack_add_gpios: " Stephen Warren
2011-08-05  7:55   ` [RFC PATCH 0/3] If an IRQ is a GPIO, request and configure it Ben Dooks
2011-08-05  9:40 ` Russell King - ARM Linux
     [not found]   ` <20110805094017.GC20575-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2011-08-05 10:30     ` Ben Dooks [this message]
2011-08-05 20:25       ` Linus Walleij
2011-08-05 15:43   ` Stephen Warren
2011-08-05 19:15     ` Russell King - ARM Linux
2011-08-05 19:33       ` Stephen Warren
2011-08-05 21:40         ` Russell King - ARM Linux

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=20110805103045.GG28651@trinity.fluff.org \
    --to=ben-linux-elnmno+kys3ytjvyw6ydsg@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
    --cc=ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org \
    --cc=cjb-2X9k7bc8m7Mdnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lrg-l0cyMroinI0@public.gmane.org \
    --cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
    --cc=swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.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