-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
The existing GPIO API has a somewhat baroque approach to configuring interrupts and callbacks, the motivation for which is unclear:
- The
gpio_callbackstructure provides the handler to use in the callback, and specifies the pins for which the callback applies; - The
gpio_{add,remove}_callback()API adds or removesgpio_callbackobjects from registry maintained in the driver but does not automatically enable what's been added; - The
gpio_{en,dis}able_callbackAPI operates on pins in isolation of whether any callback handlers happen to be registered for them.
The combination seems to allow for multiple drivers/application functions to request notification of interrupts occurring on a pin, but if somebody takes advantage of that any one of them can enable or disable the callback for all them.
This comment on work to clean up the GPIO API on proposes a change that moves the pin's interrupt-related configuration (viz. edge/level, high/low) from being performed through GPIO configuration into being provided in the callback structure.
So if the API may be changed, two questions:
Is there any motivation for allowing multiple consumers of interrupts on a single pin-in-driver?Yes, a soft-reset feature- Taking into account the answer, does it make sense to change the API so that configuring a pin for interrupt and enabling it are not two separate operations?
Tentatively my answers would be "no", and "yes", which could be accomplished by using something like gpio_enable_interrupt to handle the registration, configuration, and enable operations and gpio_disable_interrupt to disable, return the GPIO to its non-interrupt configuration, and remove the callback registration.
It would be nice to have this along with the other improvements of #16648, although it's not directly related to device tree flags so probably belongs in a coordinated PR.
I would like to have consensus on the value and approach before anybody's asked to spend time on this.