linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gpio desc flags being lost
@ 2019-07-03  5:35 Chris Packham
  2019-07-03  6:28 ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Packham @ 2019-07-03  5:35 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel

Hi LinusW, Bartosz,

I was debugging something else and I noticed a problem with the gpio 
framework or the gpio-mmio driver (or both) in 5.2.0-rc6.

I have some gpio hogs in my device tree which seem to get requested at 
startup as expected

...
GPIO line 456 (sw-reset) hogged as output/low
GPIO line 459 (phy-1g-reset) hogged as output/low
GPIO line 460 (i2c-reset) hogged as output/low
GPIO line 461 (lm81-reset) hogged as output/low
GPIO line 462 (phy-led-reset) hogged as output/low
GPIO line 448 (pcie-reset) hogged as output/low
..

I wanted to see what state these lines were in

# cat /sys/kernel/debug/gpio
gpiochip4: GPIOs 448-455, parent: platform/fffa00029.dev-reset-ctl-2, 
fffa00029.dev-reset-ctl-2:

gpiochip3: GPIOs 456-463, parent: platform/fffa00020.dev-reset-ctl, 
fffa00020.dev-reset-ctl:

I expected the hogs to show up here.

# echo 448 >/sys/class/gpio/export

Now I'm pretty sure I shouldn't be allowed to do that.

# cat /sys/kernel/debug/gpio
gpiochip4: GPIOs 448-455, parent: platform/fffa00029.dev-reset-ctl-2, 
fffa00029.dev-reset-ctl-2:gpio-448 (                    |sysfs 
     ) in  lo

Doing a bit of debugging so far I see that after startup the desc->flags 
for those gpios is 0. But for the hogged ones it should be 0x800 (or 0x801).

I happen to have a 4.8.17 kernel for the board I'm using. Testing with 
that seems to be OK.

[root@linuxbox ~]# uname -a
Linux linuxbox 4.8.17-at1+ #3 SMP Wed Jul 3 05:30:55 UTC 2019 ppc GNU/Linux
[root@linuxbox ~]# cat /sys/kernel/debug/gpio
gpiochip4: GPIOs 448-455, parent: platform/fffa00029.dev-reset-ctl-2, 
fffa00029.dev-reset-ctl-2:
  gpio-448 (                    |pcie-reset          ) out lo

gpiochip3: GPIOs 456-463, parent: platform/fffa00020.dev-reset-ctl, 
fffa00020.dev-reset-ctl:
  gpio-456 (                    |sw-reset            ) out lo
  gpio-459 (                    |phy-1g-reset        ) out lo
  gpio-460 (                    |i2c-reset           ) out lo
  gpio-461 (                    |lm81-reset          ) out lo
  gpio-462 (                    |phy-led-reset       ) out lo

[root@linuxbox ~]# echo 448 >/sys/class/gpio/export
sh: write error: Device or resource busy

I'll do some proper bisecting tomorrow, but figured you might want to 
know sooner rather than later.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpio desc flags being lost
  2019-07-03  5:35 gpio desc flags being lost Chris Packham
@ 2019-07-03  6:28 ` Linus Walleij
  2019-07-03  9:29   ` Chris Packham
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2019-07-03  6:28 UTC (permalink / raw)
  To: Chris Packham; +Cc: Bartosz Golaszewski, linux-gpio, linux-kernel

On Wed, Jul 3, 2019 at 7:35 AM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:

> Doing a bit of debugging so far I see that after startup the desc->flags
> for those gpios is 0. But for the hogged ones it should be 0x800 (or 0x801).

Yeah that is wrong.

> I'll do some proper bisecting tomorrow, but figured you might want to
> know sooner rather than later.

Thanks, I have another critical GPIO fix queued so would be great if we
can fix this too before v5.2 is released.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpio desc flags being lost
  2019-07-03  6:28 ` Linus Walleij
@ 2019-07-03  9:29   ` Chris Packham
  2019-07-03 21:30     ` Chris Packham
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Packham @ 2019-07-03  9:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Bartosz Golaszewski, linux-gpio, linux-kernel

On 3/07/19 6:28 PM, Linus Walleij wrote:
> On Wed, Jul 3, 2019 at 7:35 AM Chris Packham
> <Chris.Packham@alliedtelesis.co.nz> wrote:
> 
>> Doing a bit of debugging so far I see that after startup the desc->flags
>> for those gpios is 0. But for the hogged ones it should be 0x800 (or 0x801).
> 
> Yeah that is wrong.
> 
>> I'll do some proper bisecting tomorrow, but figured you might want to
>> know sooner rather than later.
> 
> Thanks, I have another critical GPIO fix queued so would be great if we
> can fix this too before v5.2 is released.

Bit of an update. v4.19.54 works, v5.1.15 is broken. I'll keep bisecting 
between those tomorrow.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpio desc flags being lost
  2019-07-03  9:29   ` Chris Packham
@ 2019-07-03 21:30     ` Chris Packham
  2019-07-05 21:53       ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Packham @ 2019-07-03 21:30 UTC (permalink / raw)
  To: Linus Walleij, Ricardo Ribalda Delgado
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel

On 3/07/19 9:29 PM, Chris Packham wrote:
> On 3/07/19 6:28 PM, Linus Walleij wrote:
>> On Wed, Jul 3, 2019 at 7:35 AM Chris Packham
>> <Chris.Packham@alliedtelesis.co.nz> wrote:
>>
>>> Doing a bit of debugging so far I see that after startup the desc->flags
>>> for those gpios is 0. But for the hogged ones it should be 0x800 (or 0x801).
>>
>> Yeah that is wrong.
>>
>>> I'll do some proper bisecting tomorrow, but figured you might want to
>>> know sooner rather than later.
>>
>> Thanks, I have another critical GPIO fix queued so would be great if we
>> can fix this too before v5.2 is released.
> 
> Bit of an update. v4.19.54 works, v5.1.15 is broken. I'll keep bisecting
> between those tomorrow.
> 

The problem is caused by commit 3edfb7bd76bd1cba ("gpiolib: Show correct 
direction from the beginning"). I'll see if I can whip up a patch to fix it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpio desc flags being lost
  2019-07-03 21:30     ` Chris Packham
@ 2019-07-05 21:53       ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2019-07-05 21:53 UTC (permalink / raw)
  To: Chris Packham
  Cc: Ricardo Ribalda Delgado, Bartosz Golaszewski, linux-gpio, linux-kernel

On Wed, Jul 3, 2019 at 11:30 PM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:

> The problem is caused by commit 3edfb7bd76bd1cba ("gpiolib: Show correct
> direction from the beginning"). I'll see if I can whip up a patch to fix it.

Oh. I think:

               if (chip->get_direction && gpiochip_line_is_valid(chip, i))
                        desc->flags = !chip->get_direction(chip, i) ?
                                        (1 << FLAG_IS_OUT) : 0;
                else
                        desc->flags = !chip->direction_input ?
                                        (1 << FLAG_IS_OUT) : 0;


Needs to have desc->flags |=  ... &= ~

if (!chip->get_direction(chip, i))
    desc->flags |= (1 << FLAG_IS_OUT);
else
    desc->flags &= ~(1 << FLAG_IS_OUT);

And the same for direction_input()

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-05 21:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03  5:35 gpio desc flags being lost Chris Packham
2019-07-03  6:28 ` Linus Walleij
2019-07-03  9:29   ` Chris Packham
2019-07-03 21:30     ` Chris Packham
2019-07-05 21:53       ` Linus Walleij

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).