Re: configure gpio for interrupt function

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: David Brownell
Date: Tuesday, May 27, 2008 - 1:49 pm

On Tuesday 27 May 2008, Uwe Kleine-König wrote:

Let me describe your situation a bit differently:  the GPIO
hardware on your platform doesn't support IRQs, so you want to
overlay the EXT_IRQ functions as transparently as you can.

I don't happen to have come across GPIO controllers without
IRQ support before, unless maybe you consider PXA to work
like that.  (PXA docs write "GPIO" most places it'd be more
clear to say "pin", so that's highly confusing.)  I've used
systems with EXT_INT function options on pins that support
full GPIO functionality (including pin change IRQs) though.



That's part of the reason pinmux and GPIO are orthogonal!
Your platforms GPIO code can treat EXT_INT pins as input
GPIOs; it has no reason to care.

So the *cleanest* way to handle this would be as an EXT_IRQ with
an affiliated GPIO signal, instead of a single funky GPIO.  That
mapping could be done by gpio_to_irq().

An alternate implementation would make the irq_chip for those GPIOs
understand the GPIO-to-EXT_IRQ mappings, and use them for those
pins that are inputs *and* have request_irq() called.  It sounds
as messy as I'm sure the code would be.



Sure, no problem.  irq_to_gpio() can't succeed for all GPIOs.
On your platform, I might be inclined to make it fail in all
cases to force drivers to record both IRQ and GPIO.

(And yes, that implies gpio_keys needs to generalize a bit.
Right now it assumes a one-to-one mapping.)



This is another reason to prefer the "cleanest" solution above.
Drivers could request_irq() the EXT_IRQ(N) signal as IRQF_SHARED,
and the handler could check the relevant IRQ as needed.

Of course, this may require code using your platform to know
that it needs to track two values (EXT_IRQ and GPIO) not one.



I don't see a need to extend the API.  The current APIs will do what
you need, if you use them correctly:

  - gpio_to_irq() encapsulates your CPU's EXT_IRQ(x) pinmux logic;
    possibly just a table lookup.

  - irq_to_gpio() may fail in all cases

  - request_irq() kicks in irq_chip logic to ensure that the pin
    is either input GPIO (and remuxes it) or already EXT_INT ...

  - free_irq() can remux EXT_INT as GPIO, if it changed muxing in
    the first place.  (so gpio_direction_output can work, later.)

  - set_irq_type() configures the IRQ type via irq_chip hooks

Right?

 

That's true for that AT91 case, for example.



Deprecating irq_to_gpio() seems a bit strong to me, but maybe that's
because I've never worked on hardware that can't support it.  ISTR that
Russell King disliked it a lot, but couldn't explain "why" to me.  This
may be a good enough reason to do so:  an example showing non-portability
(albeit because the IRQ in question is _not_ a GPIO irq).

Why don't you whip up a patch doing the right thing for irq_to_gpio(),
and send it along.  Right now I'd be inclined to sign off on it.

- Dave




--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
configure gpio for interrupt function, Uwe , (Tue May 27, 6:02 am)
Re: configure gpio for interrupt function, David Brownell, (Tue May 27, 1:49 pm)
Re: configure gpio for interrupt function, Uwe , (Wed May 28, 12:17 am)