LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Jiri Kosina <jkosina@suse.cz>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Rob Herring <robh+dt@kernel.org>, Pawel Moll <Pawel.Moll@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] HID: i2c-hid: Add support for GPIO interrupts
Date: Tue, 27 Jan 2015 14:33:34 +0000	[thread overview]
Message-ID: <20150127143334.GF17721@leverpostej> (raw)
In-Reply-To: <20150127113041.GP1451@lahna.fi.intel.com>

On Tue, Jan 27, 2015 at 11:30:41AM +0000, Mika Westerberg wrote:
> On Tue, Jan 27, 2015 at 11:14:58AM +0000, Mark Rutland wrote:
> > On Tue, Jan 27, 2015 at 10:59:31AM +0000, Mika Westerberg wrote:
> > > On Tue, Jan 27, 2015 at 10:39:25AM +0000, Mark Rutland wrote:
> > > > > If the above is not the right way to use GPIOs as interrupt, can you
> > > > > please tell me how it is done then?
> > > > 
> > > > 
> > > > So lets say we have a device which generates an interrupt:
> > > > 
> > > > 	device@f00 {
> > > > 		compatible = "some-interrupting-device";
> > > > 		reg = <0xf00 0x100>;
> > > > 		interrupts = < ... >;
> > > > 	};
> > > > 
> > > > It's intended that this is connected to an interrupt controller:
> > > > 
> > > > 	ic: interrupt-controller@b00 {
> > > > 		compatible = "some-interrupt-controller";
> > > > 		reg = <0xb00 0x100>;
> > > > 		#interrupt-cells = <1>;
> > > > 	};
> > > > 
> > > > 	device@f00 {
> > > > 		compatible = "some-interrupting-device";
> > > > 		reg = <0xf00 0x100>;
> > > > 		interrupt-parent = <&ic>;
> > > > 		interrupts = <0x3>;
> > > > 	};
> > > > 
> > > > But in some cases, this gets connected to a GPIO controller. In these
> > > > cases, the device is still logically generating an interrupt, and the
> > > > fact that the endpoint is an interrupt controller is irrelevant from the
> > > > PoV of the device. So we acknowledge that the GPIO controller is also
> > > > capable of acting as an interrupt controller, and mark it as such:
> > > > 
> > > > 	gc: gpio-controller@000 {
> > > > 		compatible = "some-gpio-controller";
> > > > 		reg = <0x000 0x100>;
> > > > 		#gpio-cells = <1>;
> > > > 		#interrupt-cells = <1>;
> > > > 	};
> > > > 
> > > > 	device@f00 {
> > > > 		compatible = "some-interrupting-device";
> > > > 		reg = <0xf00 0x100>;
> > > > 		interrupt-parent = <&gc>;
> > > > 		interrupts = <0x1>;
> > > > 	};
> > > > 
> > > > Thus the device binding only describes the logical interrupt, and the
> > > > driver only needs to handle interrupts.
> > > 
> > > OK.
> > > 
> > > > In cases where the binding/driver actually care about the GPIO being a
> > > > GPIO (e.g. for card detect in an MMC controller), describing the GPIO as
> > > > a GPIO makes sense, and we can try gpio_to_irq as an optimisation over
> > > > polling the state of the GPIO.
> > > 
> > > Well, I've seen touch panels where you actually need to switch the GPIO
> > > to be output and do some magic before you can use the same GPIO as an
> > > interrupt.
> > 
> > Ok. That's a nasty case, but surely in that case the relevant GPIO
> > shoiuld be a GpioIO object for output?
> 
> I can't remember the details anymore, possibly it was GpioIo().
> 
> Nothing prevents you from using GpioIo() as an interrupt.

Certainly. As I mention above, in the case of something like a card
detect pin, it makes sense to be able to acquire an interrupt for the
GPIO.

> > > > > BTW, passing NULL to gpiod_get() implies property named "gpios" in DT
> > > > > (which is why I added it to the documentation).
> > > > 
> > > > Sure. My concern is that we should not need to deal with GPIOs in this
> > > > case were the GPIO is only there to function as an interrupt.
> > > > 
> > > > Given that GpioInt seems to describe an interrupt which happens to be
> > > > backed by a GPIO, I don't understand what it is necessary to translate
> > > > this as a GPIO rather than an interrupt. If it were going to be used as
> > > > a GPIO, then it would be a GpioIO object, no?
> > > 
> > > OK, so where do you propose we handle the translation if not in the
> > > driver? Also keep in mind that some of the devices may have multiple
> > > GpioInt()s.
> > 
> > To me it seems that GpioInt objects should be translated to interrupts
> > by some core code. How are interrupts described and handed in ACPI? Are
> > they resource along the lines of GpioInts, or are they a completely
> > separate class of device property?
> 
> They are similar resources in _CRS, like GpioIo/GpioInt etc. Below is
> from another touch panel:
> 
> 	Name (_CRS, ResourceTemplate () {
> 		I2cSerialBus (0x004C, ControllerInitiated, 0x00061A80,
> 			AddressingMode7Bit, "\\_SB.PCI0.I2C1", 0x00, ResourceConsumer,,)
> 		Interrupt (ResourceConsumer, Level, ActiveLow, Exclusive, ,, )
> 		{
> 		    0x00000022,
> 		}
> 	})
> 
> If we see one of the above we automatically add it to client->irq in
> case of I2C device.

Ok, that allays my fear w.r.t. ordering of the resources.

As I see it, the fact that we convert GpioInt entries to GPIOs rather
than irqs when parsing _CRS is the issue here, and to me it makes no
sense that we do so. Were we to treat them as interrupts, the binding is
fine as-is, and we'd do the same thing in DT and ACPI.

The reason GpioInt is separate from GpioIo is that a GpioInt _is_ an
interrupt (which happens to be backed by a GPIO), and is not something
that necessarily makes sense as a GPIO.

So why do we currently ignore the GpioInt/GpioIo distinction and treat
GpioInts as GPIOs rather than interrupts?

Thanks,
Mark.

  reply	other threads:[~2015-01-27 14:34 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26 14:29 [PATCH 1/2] HID: i2c-hid: The interrupt should be level sensitive Mika Westerberg
2015-01-26 14:29 ` [PATCH 2/2] HID: i2c-hid: Add support for GPIO interrupts Mika Westerberg
2015-01-26 14:37   ` Mark Rutland
2015-01-26 14:47     ` Mika Westerberg
2015-01-26 14:50       ` Mark Rutland
2015-01-26 15:16         ` Mika Westerberg
2015-01-26 16:01           ` Mark Rutland
2015-01-26 16:13             ` Mika Westerberg
2015-01-26 16:39               ` Mark Rutland
2015-01-27 10:16                 ` Mika Westerberg
2015-01-27 10:39                   ` Mark Rutland
2015-01-27 10:59                     ` Mika Westerberg
2015-01-27 11:14                       ` Mark Rutland
2015-01-27 11:30                         ` Mika Westerberg
2015-01-27 14:33                           ` Mark Rutland [this message]
2015-01-27 14:41                             ` Mika Westerberg
2015-01-27 15:06                               ` Mark Rutland
2015-01-27 15:21                                 ` Mika Westerberg
2015-01-27 15:57                                   ` Mark Rutland
2015-01-27 17:10                                     ` Mika Westerberg
2015-01-29 20:09 ` [PATCH 1/2] HID: i2c-hid: The interrupt should be level sensitive Benjamin Tissoires
2015-02-17 12:24   ` Jiri Kosina

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=20150127143334.GF17721@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=Pawel.Moll@arm.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=robh+dt@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).