diff mbox series

[v1,2/3] Documentation: firmware-guide: gpio-properties: active_low only for GpioIo()

Message ID 20201028205101.47583-2-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/3] Documentation: firmware-guide: gpio-properties: Fix factual mistakes | expand

Commit Message

Andy Shevchenko Oct. 28, 2020, 8:51 p.m. UTC
It appears that people may misinterpret active_low field in _DSD
for GpioInt() resource. Add a paragraph to clarify this.

Reported-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 Documentation/firmware-guide/acpi/gpio-properties.rst | 3 +++
 1 file changed, 3 insertions(+)

Comments

Ricardo Ribalda Oct. 28, 2020, 9:10 p.m. UTC | #1
Hi Andy

Thanks for your patch and super fast response.

I think there are two different concepts here:

1) when the pin has a low value, it is  0 or a 1? =>active_low

2) when do I get an irq, low->high or high->low => irq polarity

When I read the acpi spec for GpioInt()
https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf page
934, it has the same problem as for GpioIo(), it does not express the
active_low and this is where the _DSD field comes handy.

Without using the active_low, how can we describe  a pin that is
active low and has to trigger an irq on both edges?

Thanks again


On Wed, Oct 28, 2020 at 9:51 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> It appears that people may misinterpret active_low field in _DSD
> for GpioInt() resource. Add a paragraph to clarify this.
>
> Reported-by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  Documentation/firmware-guide/acpi/gpio-properties.rst | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/Documentation/firmware-guide/acpi/gpio-properties.rst b/Documentation/firmware-guide/acpi/gpio-properties.rst
> index e6e65ceb2ca1..370fe46c6af9 100644
> --- a/Documentation/firmware-guide/acpi/gpio-properties.rst
> +++ b/Documentation/firmware-guide/acpi/gpio-properties.rst
> @@ -55,6 +55,9 @@ Since ACPI GpioIo() resource does not have a field saying whether it is
>  active low or high, the "active_low" argument can be used here.  Setting
>  it to 1 marks the GPIO as active low.
>
> +Note, active_low in _DSD does not make sense for GpioInt() resource and
> +must be 0. GpioInt() resource has its own means of defining it.
> +
>  In our Bluetooth example the "reset-gpios" refers to the second GpioIo()
>  resource, second pin in that resource with the GPIO number of 31.
>
> --
> 2.28.0
>
Mika Westerberg Oct. 29, 2020, 8:13 a.m. UTC | #2
On Wed, Oct 28, 2020 at 10:51:00PM +0200, Andy Shevchenko wrote:
> It appears that people may misinterpret active_low field in _DSD
> for GpioInt() resource. Add a paragraph to clarify this.
> 
> Reported-by: Ricardo Ribalda <ribalda@chromium.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Andy Shevchenko Oct. 29, 2020, 2:46 p.m. UTC | #3
On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> Hi Andy
> 
> Thanks for your patch and super fast response.
> 
> I think there are two different concepts here:
> 
> 1) when the pin has a low value, it is  0 or a 1? =>active_low

I'm not sure I have got it. GpioIo() has no such property and
_DSD active_low is documented as being polarity setting:

	active_low == 1 => active low polarity.

> 2) when do I get an irq, low->high or high->low => irq polarity

IRQ polarity is clearly defined by GpioInt() resource in the ACPI
specification.

> When I read the acpi spec for GpioInt()
> https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf page
> 934, it has the same problem as for GpioIo(), it does not express the
> active_low and this is where the _DSD field comes handy.

ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
Resource Descriptor Macro).

> Without using the active_low, how can we describe  a pin that is
> active low and has to trigger an irq on both edges?

This is nonsense.
What does it mean?
Ricardo Ribalda Oct. 29, 2020, 2:54 p.m. UTC | #4
Hi Andy

On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > Hi Andy
> >
> > Thanks for your patch and super fast response.
> >
> > I think there are two different concepts here:
> >
> > 1) when the pin has a low value, it is  0 or a 1? =>active_low
>
> I'm not sure I have got it. GpioIo() has no such property and
> _DSD active_low is documented as being polarity setting:
>
>         active_low == 1 => active low polarity.
>
> > 2) when do I get an irq, low->high or high->low => irq polarity
>
> IRQ polarity is clearly defined by GpioInt() resource in the ACPI
> specification.
>
> > When I read the acpi spec for GpioInt()
> > https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf page
> > 934, it has the same problem as for GpioIo(), it does not express the
> > active_low and this is where the _DSD field comes handy.
>
> ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> Resource Descriptor Macro).
>
> > Without using the active_low, how can we describe  a pin that is
> > active low and has to trigger an irq on both edges?
>
> This is nonsense.
> What does it mean?

Let me try to explain myself again:

I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both

The problem is that the value of that pin is inverted: Low means 1 and
high means 0.

How can I describe that the pin "is inverted" without using the _DSD field?

Best regards

>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Andy Shevchenko Oct. 29, 2020, 5:17 p.m. UTC | #5
On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:

...

> > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > Resource Descriptor Macro).
> >
> > > Without using the active_low, how can we describe  a pin that is
> > > active low and has to trigger an irq on both edges?
> >
> > This is nonsense.
> > What does it mean?
>
> Let me try to explain myself again:
>
> I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
>
> The problem is that the value of that pin is inverted: Low means 1 and
> high means 0.
>
> How can I describe that the pin "is inverted" without using the _DSD field?

"Both edges" and "inverted" or "polarity low" in one sentence make no sense.
Andy Shevchenko Oct. 29, 2020, 5:20 p.m. UTC | #6
On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
>
> ...
>
> > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > Resource Descriptor Macro).
> > >
> > > > Without using the active_low, how can we describe  a pin that is
> > > > active low and has to trigger an irq on both edges?
> > >
> > > This is nonsense.
> > > What does it mean?
> >
> > Let me try to explain myself again:
> >
> > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> >
> > The problem is that the value of that pin is inverted: Low means 1 and
> > high means 0.
> >
> > How can I describe that the pin "is inverted" without using the _DSD field?
>
> "Both edges" and "inverted" or "polarity low" in one sentence make no sense.

To be on the constructive side, I can *imagine* so badly designed
hardware that uses level and edge at the same time, but before I go to
conclusions, can you share relevant (pieces of) datasheet?
Andy Shevchenko Oct. 29, 2020, 5:25 p.m. UTC | #7
On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> >
> > ...
> >
> > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > Resource Descriptor Macro).
> > > >
> > > > > Without using the active_low, how can we describe  a pin that is
> > > > > active low and has to trigger an irq on both edges?
> > > >
> > > > This is nonsense.
> > > > What does it mean?
> > >
> > > Let me try to explain myself again:
> > >
> > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > >
> > > The problem is that the value of that pin is inverted: Low means 1 and
> > > high means 0.
> > >
> > > How can I describe that the pin "is inverted" without using the _DSD field?
> >
> > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
>
> To be on the constructive side, I can *imagine* so badly designed
> hardware that uses level and edge at the same time, but before I go to
> conclusions, can you share relevant (pieces of) datasheet?

The [1] is a real example of how GPIO is being used to detect changing
of current level of the signal.
Note, ACPI tables for that device have problems [2], but I guess you
may get the idea.


[1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
[2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
Ricardo Ribalda Oct. 29, 2020, 5:32 p.m. UTC | #8
Hi Andy

On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > >
> > > ...
> > >
> > > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > > Resource Descriptor Macro).
> > > > >
> > > > > > Without using the active_low, how can we describe  a pin that is
> > > > > > active low and has to trigger an irq on both edges?
> > > > >
> > > > > This is nonsense.
> > > > > What does it mean?
> > > >
> > > > Let me try to explain myself again:
> > > >
> > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > >
> > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > high means 0.
> > > >
> > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > >
> > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> >
> > To be on the constructive side, I can *imagine* so badly designed
> > hardware that uses level and edge at the same time, but before I go to
> > conclusions, can you share relevant (pieces of) datasheet?
>
> The [1] is a real example of how GPIO is being used to detect changing
> of current level of the signal.
> Note, ACPI tables for that device have problems [2], but I guess you
> may get the idea.


This is exactly what I need to do. Get an IRQ whenever the value
changes. But the pin is "inverted"

This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
userspace a "1" when the switch is closed and "0"  when it is open.



>
>
> [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
>
> --
> With Best Regards,
> Andy Shevchenko
Ricardo Ribalda Oct. 29, 2020, 6:09 p.m. UTC | #9
(clicked on reply instead of reply all sorry)

On Thu, Oct 29, 2020 at 6:32 PM Ricardo Ribalda <ribalda@google.com> wrote:
>
> Hi Andy
>
> On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > >
> > > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > > >
> > > > ...
> > > >
> > > > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > > > Resource Descriptor Macro).
> > > > > >
> > > > > > > Without using the active_low, how can we describe  a pin that is
> > > > > > > active low and has to trigger an irq on both edges?
> > > > > >
> > > > > > This is nonsense.
> > > > > > What does it mean?
> > > > >
> > > > > Let me try to explain myself again:
> > > > >
> > > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > > >
> > > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > > high means 0.
> > > > >
> > > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > > >
> > > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> > >
> > > To be on the constructive side, I can *imagine* so badly designed
> > > hardware that uses level and edge at the same time, but before I go to
> > > conclusions, can you share relevant (pieces of) datasheet?
> >
> > The [1] is a real example of how GPIO is being used to detect changing
> > of current level of the signal.
> > Note, ACPI tables for that device have problems [2], but I guess you
> > may get the idea.
>
>
> This is exactly what I need to do. Get an IRQ whenever the value
> changes. But the pin is "inverted"
>
> This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
> userspace a "1" when the switch is closed and "0"  when it is open.
>
And there are also other devices where the swith works the other way
around, so the acpi should be verbose enough to describe both
situations.

With my proposal (use the same active_low field as with GpioIO) we
cover both usecases.

>
>
> >
> >
> > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> > [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
>
>
>
> --
> Ricardo Ribalda
Andy Shevchenko Oct. 29, 2020, 6:10 p.m. UTC | #10
On Thu, Oct 29, 2020 at 7:32 PM Ricardo Ribalda <ribalda@google.com> wrote:
> On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > > >
> > > > ...
> > > >
> > > > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > > > Resource Descriptor Macro).
> > > > > >
> > > > > > > Without using the active_low, how can we describe  a pin that is
> > > > > > > active low and has to trigger an irq on both edges?
> > > > > >
> > > > > > This is nonsense.
> > > > > > What does it mean?
> > > > >
> > > > > Let me try to explain myself again:
> > > > >
> > > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > > >
> > > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > > high means 0.
> > > > >
> > > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > > >
> > > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> > >
> > > To be on the constructive side, I can *imagine* so badly designed
> > > hardware that uses level and edge at the same time, but before I go to
> > > conclusions, can you share relevant (pieces of) datasheet?
> >
> > The [1] is a real example of how GPIO is being used to detect changing
> > of current level of the signal.
> > Note, ACPI tables for that device have problems [2], but I guess you
> > may get the idea.
>
>
> This is exactly what I need to do. Get an IRQ whenever the value
> changes. But the pin is "inverted"

Yes. It's fine. The above is using GpioIo() resource where polarity is
part of the _DSD (okay, the actual ACPI table doesn't have it, but you
can do it).

> This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
> userspace a "1" when the switch is closed and "0"  when it is open.

> > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> > [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
Andy Shevchenko Oct. 29, 2020, 6:13 p.m. UTC | #11
On Thu, Oct 29, 2020 at 8:10 PM Ricardo Ribalda <ribalda@google.com> wrote:
> On Thu, Oct 29, 2020 at 6:32 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > > > <andy.shevchenko@gmail.com> wrote:
> > > > > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > > > >
> > > > > ...
> > > > >
> > > > > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > > > > Resource Descriptor Macro).
> > > > > > >
> > > > > > > > Without using the active_low, how can we describe  a pin that is
> > > > > > > > active low and has to trigger an irq on both edges?
> > > > > > >
> > > > > > > This is nonsense.
> > > > > > > What does it mean?
> > > > > >
> > > > > > Let me try to explain myself again:
> > > > > >
> > > > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > > > >
> > > > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > > > high means 0.
> > > > > >
> > > > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > > > >
> > > > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> > > >
> > > > To be on the constructive side, I can *imagine* so badly designed
> > > > hardware that uses level and edge at the same time, but before I go to
> > > > conclusions, can you share relevant (pieces of) datasheet?
> > >
> > > The [1] is a real example of how GPIO is being used to detect changing
> > > of current level of the signal.
> > > Note, ACPI tables for that device have problems [2], but I guess you
> > > may get the idea.
> >
> >
> > This is exactly what I need to do. Get an IRQ whenever the value
> > changes. But the pin is "inverted"
> >
> > This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
> > userspace a "1" when the switch is closed and "0"  when it is open.
> >
> And there are also other devices where the swith works the other way
> around, so the acpi should be verbose enough to describe both
> situations.
>
> With my proposal (use the same active_low field as with GpioIO) we
> cover both usecases.

Even without your proposal it's feasible.
You see, the problem here is that if you describe GPIO as Interrupt,
the edge and level together make complete nonsense.

Solution: do *not* describe it as Interrupt.

> > > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> > > [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
Ricardo Ribalda Oct. 29, 2020, 6:58 p.m. UTC | #12
On Thu, Oct 29, 2020 at 7:13 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Thu, Oct 29, 2020 at 8:10 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > On Thu, Oct 29, 2020 at 6:32 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> > > > <andy.shevchenko@gmail.com> wrote:
> > > > > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > > > > <andy.shevchenko@gmail.com> wrote:
> > > > > > On Thu, Oct 29, 2020 at 4:55 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > > > > On Thu, Oct 29, 2020 at 3:45 PM Andy Shevchenko
> > > > > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > > > > > On Wed, Oct 28, 2020 at 10:10:42PM +0100, Ricardo Ribalda wrote:
> > > > > >
> > > > > > ...
> > > > > >
> > > > > > > > ActiveLevel field is described in 19.6.55 GpioInt (GPIO Interrupt Connection
> > > > > > > > Resource Descriptor Macro).
> > > > > > > >
> > > > > > > > > Without using the active_low, how can we describe  a pin that is
> > > > > > > > > active low and has to trigger an irq on both edges?
> > > > > > > >
> > > > > > > > This is nonsense.
> > > > > > > > What does it mean?
> > > > > > >
> > > > > > > Let me try to explain myself again:
> > > > > > >
> > > > > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > > > > >
> > > > > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > > > > high means 0.
> > > > > > >
> > > > > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > > > > >
> > > > > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> > > > >
> > > > > To be on the constructive side, I can *imagine* so badly designed
> > > > > hardware that uses level and edge at the same time, but before I go to
> > > > > conclusions, can you share relevant (pieces of) datasheet?
> > > >
> > > > The [1] is a real example of how GPIO is being used to detect changing
> > > > of current level of the signal.
> > > > Note, ACPI tables for that device have problems [2], but I guess you
> > > > may get the idea.
> > >
> > >
> > > This is exactly what I need to do. Get an IRQ whenever the value
> > > changes. But the pin is "inverted"
> > >
> > > This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
> > > userspace a "1" when the switch is closed and "0"  when it is open.
> > >
> > And there are also other devices where the swith works the other way
> > around, so the acpi should be verbose enough to describe both
> > situations.
> >
> > With my proposal (use the same active_low field as with GpioIO) we
> > cover both usecases.
>
> Even without your proposal it's feasible.
> You see, the problem here is that if you describe GPIO as Interrupt,
> the edge and level together make complete nonsense.
>
> Solution: do *not* describe it as Interrupt.

Now I get my mistake:

I thought that gpiod_to_irq will not work unless it was a GpioInt()
but it works fine. So in this case I will just convert it to that.

Could we say that doing gpiod_get_value() from a GpioInt() is always
wrong? Can we modify the code to avoid it?

Sorry for the confusion and thanks for your help.


>
> > > > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> > > > [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
>
>
> --
> With Best Regards,
> Andy Shevchenko



--
Ricardo Ribalda
Andy Shevchenko Oct. 29, 2020, 7:11 p.m. UTC | #13
On Thu, Oct 29, 2020 at 07:58:39PM +0100, Ricardo Ribalda wrote:
> On Thu, Oct 29, 2020 at 7:13 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Thu, Oct 29, 2020 at 8:10 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > On Thu, Oct 29, 2020 at 6:32 PM Ricardo Ribalda <ribalda@google.com> wrote:
> > > > On Thu, Oct 29, 2020 at 6:26 PM Andy Shevchenko
> > > > <andy.shevchenko@gmail.com> wrote:
> > > > > On Thu, Oct 29, 2020 at 7:20 PM Andy Shevchenko
> > > > > <andy.shevchenko@gmail.com> wrote:
> > > > > > On Thu, Oct 29, 2020 at 7:17 PM Andy Shevchenko
> > > > > > <andy.shevchenko@gmail.com> wrote:

...

> > > > > > > > Let me try to explain myself again:
> > > > > > > >
> > > > > > > > I have a gpio pin that produces IRQs on both edges. so ActiveLevel is Both
> > > > > > > >
> > > > > > > > The problem is that the value of that pin is inverted: Low means 1 and
> > > > > > > > high means 0.
> > > > > > > >
> > > > > > > > How can I describe that the pin "is inverted" without using the _DSD field?
> > > > > > >
> > > > > > > "Both edges" and "inverted" or "polarity low" in one sentence make no sense.
> > > > > >
> > > > > > To be on the constructive side, I can *imagine* so badly designed
> > > > > > hardware that uses level and edge at the same time, but before I go to
> > > > > > conclusions, can you share relevant (pieces of) datasheet?
> > > > >
> > > > > The [1] is a real example of how GPIO is being used to detect changing
> > > > > of current level of the signal.
> > > > > Note, ACPI tables for that device have problems [2], but I guess you
> > > > > may get the idea.
> > > >
> > > >
> > > > This is exactly what I need to do. Get an IRQ whenever the value
> > > > changes. But the pin is "inverted"
> > > >
> > > > This is the "schematic" :  https://ibb.co/f8GMBbP . I want to pass to
> > > > userspace a "1" when the switch is closed and "0"  when it is open.
> > > >
> > > And there are also other devices where the swith works the other way
> > > around, so the acpi should be verbose enough to describe both
> > > situations.
> > >
> > > With my proposal (use the same active_low field as with GpioIO) we
> > > cover both usecases.
> >
> > Even without your proposal it's feasible.
> > You see, the problem here is that if you describe GPIO as Interrupt,
> > the edge and level together make complete nonsense.
> >
> > Solution: do *not* describe it as Interrupt.
> 
> Now I get my mistake:
> 
> I thought that gpiod_to_irq will not work unless it was a GpioInt()
> but it works fine. So in this case I will just convert it to that.

It's actually that gpio_to_irq() is solely for GPIOs which initially are not IRQs.

> Could we say that doing gpiod_get_value() from a GpioInt() is always
> wrong?

But it's not wrong. Some cases simply make little or no sense, but in principal
why not? Yes, it may be fragile or too much customized.

> Can we modify the code to avoid it?

GpioInt() is orthogonal to GPIO APIs in Linux kernel. It close to be
impossible. Also see above.

> Sorry for the confusion and thanks for your help.

No problem, you're welcome, it's good that you started a discussion!

> > > > > [1]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L138
> > > > > [2]: https://elixir.bootlin.com/linux/latest/source/drivers/extcon/extcon-intel-int3496.c#L45
diff mbox series

Patch

diff --git a/Documentation/firmware-guide/acpi/gpio-properties.rst b/Documentation/firmware-guide/acpi/gpio-properties.rst
index e6e65ceb2ca1..370fe46c6af9 100644
--- a/Documentation/firmware-guide/acpi/gpio-properties.rst
+++ b/Documentation/firmware-guide/acpi/gpio-properties.rst
@@ -55,6 +55,9 @@  Since ACPI GpioIo() resource does not have a field saying whether it is
 active low or high, the "active_low" argument can be used here.  Setting
 it to 1 marks the GPIO as active low.
 
+Note, active_low in _DSD does not make sense for GpioInt() resource and
+must be 0. GpioInt() resource has its own means of defining it.
+
 In our Bluetooth example the "reset-gpios" refers to the second GpioIo()
 resource, second pin in that resource with the GPIO number of 31.