All of lore.kernel.org
 help / color / mirror / Atom feed
* gpio_chip::ngpio vs. gpio_dev::ngpio
@ 2021-05-03 13:19 Andy Shevchenko
  2021-05-03 14:03 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2021-05-03 13:19 UTC (permalink / raw)
  To: open list:GPIO SUBSYSTEM; +Cc: Linus Walleij, Bartosz Golaszewski

Hi!

Any shed of light what the difference is (between gpio_chip::ngpio and
gpio_dev::ngpio)?

-- 
With Best Regards,
Andy Shevchenko

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

* Re: gpio_chip::ngpio vs. gpio_dev::ngpio
  2021-05-03 13:19 gpio_chip::ngpio vs. gpio_dev::ngpio Andy Shevchenko
@ 2021-05-03 14:03 ` Linus Walleij
  2021-05-03 14:12   ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2021-05-03 14:03 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Mon, May 3, 2021 at 3:20 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:

> Any shed of light what the difference is (between gpio_chip::ngpio and
> gpio_dev::ngpio)?

The one in gpio_dev::ngpio is used when referring to that struct
so it could be renamed ndesc to clarify the usecase.

The gpiochip ngpio i.e. gdev->chip->ngpio cannot be used, because
sometimes the gpio_chip goes away but not the gpio_dev.

A typical case when this happens is when a gpio_chip and
corresponding gpio_dev is created by plugging in a USB-based
gpio device such as FTDI. Then the user start some gpio-event-mon
or gpio-hammer on that gpio_dev, flickering a LED or something.

If the user unplugs the USB device, the gpio_chip will disappear
and get "numbed" so that no operations reach the hardware, but
the userspace program will not end or crash.

When the user finals terminates the program with e.g. ctrl+C
the character device is closed and gpio_dev goes away and
for that the ngpio field is needed.

Yours,
Linus Walleij

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

* Re: gpio_chip::ngpio vs. gpio_dev::ngpio
  2021-05-03 14:03 ` Linus Walleij
@ 2021-05-03 14:12   ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-05-03 14:12 UTC (permalink / raw)
  To: Linus Walleij; +Cc: open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Mon, May 3, 2021 at 5:03 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, May 3, 2021 at 3:20 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
>
> > Any shed of light what the difference is (between gpio_chip::ngpio and
> > gpio_dev::ngpio)?
>
> The one in gpio_dev::ngpio is used when referring to that struct
> so it could be renamed ndesc to clarify the usecase.

It would be nice to have it renamed and better described in the kernel doc.
Esp. taking into account the lifetime of each of them.

(Sounds like a new item to somebody's, yours?, TODO list, after
cleaning that gpio_is_valid() thingy :-)

> The gpiochip ngpio i.e. gdev->chip->ngpio cannot be used, because
> sometimes the gpio_chip goes away but not the gpio_dev.
>
> A typical case when this happens is when a gpio_chip and
> corresponding gpio_dev is created by plugging in a USB-based
> gpio device such as FTDI. Then the user start some gpio-event-mon
> or gpio-hammer on that gpio_dev, flickering a LED or something.
>
> If the user unplugs the USB device, the gpio_chip will disappear
> and get "numbed" so that no operations reach the hardware, but
> the userspace program will not end or crash.
>
> When the user finals terminates the program with e.g. ctrl+C
> the character device is closed and gpio_dev goes away and
> for that the ngpio field is needed.

Thanks! It all makes sense to me.

-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2021-05-03 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-03 13:19 gpio_chip::ngpio vs. gpio_dev::ngpio Andy Shevchenko
2021-05-03 14:03 ` Linus Walleij
2021-05-03 14:12   ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.