mbox series

[RFCv3,0/4] gpiolib: track irq enabled/disabled state

Message ID 20180831143744.126063-1-hverkuil@xs4all.nl
Headers show
Series gpiolib: track irq enabled/disabled state | expand

Message

Hans Verkuil Aug. 31, 2018, 2:37 p.m. UTC
From: Hans Verkuil <hans.verkuil@cisco.com>

Hi all,

This is the third RFC patch series which attempts to allow drivers to 
disable the irq and drive the gpio as an output.

Please be gentle with me: I am neither an expert on the gpio internals, nor on
the irq internals.

My previous version moved the code that marked a gpio pin as 'used by an irq'
to the places where the irq was enabled/disabled, but that is wrong. The
problem is that userspace can also request to use an irq for a gpio pin,
so the FLAG_USED_AS_IRQ flag really should be set when the irq is requested,
otherwise a driver can request the irq, but userspace can do so as well if
the irq is disabled since disabling the irq cleared the FLAG_USED_AS_IRQ
flag and now gpiolib doesn't know that there already is an irq handler
associated with the gpio.

What is needed instead is a new flag FLAG_IRQ_IS_ENABLED that keeps track
if the irq is enabled or not.

The first patch adds that flag and allows the direction to be changed to
output unless both FLAG_USED_AS_IRQ and FLAG_IRQ_IS_ENABLED are set.

The second patch makes helper functions available for drivers that
implement the irq_request/release_resources hooks: this should simplify
such drivers as these helpers call try_module_get(chip->gpiodev->owner),
something that none of the drivers currently implementing these hooks
do.

The third patch overrides the irq_disable and irq_enable hooks when using
the irqchip helpers so gpiolib will know when the irq is enabled/disabled.

Drivers that do not use these helpers will have to call this themselves,
and the fourth patch converts one such driver.

The nice thing is that as far as I can tell no drivers need to be patched.

Drivers that do not use the helpers will need to be updated over time so
they call gpiochip_en/disable_irq, but that can be done one by one.

This patch series has been tested on my BeagleBone Black board with the
tda998x driver.

Regards,

        Hans

Hans Verkuil (4):
  gpiolib: add flag to indicate if the irq is disabled
  gpiolib: export gpiochip_irq_reqres/relres()
  gpiolib: override irq_enable/disable
  gpio-bcm-kona: use new req/relres and dis/enable_irq funcs

 drivers/gpio/gpio-bcm-kona.c |  14 +--
 drivers/gpio/gpiolib.c       | 178 +++++++++++++++++++++++++----------
 drivers/gpio/gpiolib.h       |   1 +
 include/linux/gpio/driver.h  |   7 ++
 4 files changed, 139 insertions(+), 61 deletions(-)