linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* how to request gpiochip line which is only valid as an interrupt?
@ 2024-06-10 14:01 Marek Behún
  2024-06-11  9:03 ` Marek Behún
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Behún @ 2024-06-10 14:01 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Andy Shevchenko, linux-gpio

Hello Bartosz,

I would like to ask you if you could find some time to look at

  [PATCH v11 6/8] platform: cznic: turris-omnia-mcu: Add support for
                  MCU provided TRNG

  https://lore.kernel.org/soc/20240605161851.13911-7-kabel@kernel.org/

Andy Shevchenko added you to that conversation asking you about how to
correctly do the following part:

  irq = gpiod_to_irq(gpiochip_get_desc(&mcu->gc, irq_idx));

I am writing this to give some more light into the problem. What is
going on:
- the turris-omnia-mcu driver provides a gpio chip with interrupts
- some lines are gpio + irq, but some lines are interrupt only
- later, after the gpiochip is registered, another part of the
  turris-omnia-mcu driver wants to use one interrupt only line

To use the gpiod_to_irq() function, I need gpio descriptor for that
line. I can get that with gpiochip_get_desc(), since this is within the
driver, I have access to the gpiochip. But this is semantically a
little weird, because

  1. gpiochip_get_desc() is supposed to be used by gpio driver, not
     consumer (and the trng part of the turris-omnia-mcu code is a
     consumer of the gpio)

  2. reference counting?

Looking at gpiolib, maybe the better function to use would be
gpiochip_request_own_desc(). This also is defined in
include/gpio/driver.c instead of include/gpio/consumer.c, but at least
it's name suggests that it is used by code that also owns the
gpiochip...

One problem is that gpiochip_request_own_desc() won't work, because the
gpiochip initializes valid masks for both gpios and irqs, and the 
gpiochip_request_own_desc() function calls gpiod_request_commit(),
which executes the following code

  if (guard.gc->request) {
    offset = gpio_chip_hwgpio(desc);
    if (gpiochip_line_is_valid(guard.gc, offset))
      ret = guard.gc->request(guard.gc, offset);
    else
      ret = -EINVAL;
    ...
  }

So if a gpiochip line is not valid GPIO, only valid IRQchip line, then
the GPIO cannot be requested, even for interrupts.

What is the proper solution here?

Thank you

Marek

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

end of thread, other threads:[~2024-06-12 13:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-10 14:01 how to request gpiochip line which is only valid as an interrupt? Marek Behún
2024-06-11  9:03 ` Marek Behún
2024-06-11 19:22   ` Bartosz Golaszewski
2024-06-12  8:55     ` Marek Behún
2024-06-12  9:03       ` Marek Behún
2024-06-12 12:30         ` Bartosz Golaszewski
2024-06-12 13:32           ` Marek Behún
2024-06-12  9:19       ` Marek Behún

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