[PATCH v2 04/10] gpio: shared-proxy: implement the shared GPIO proxy driver
Bartosz Golaszewski
brgl at bgdev.pl
Fri Oct 24 00:03:15 PDT 2025
On Wed, Oct 22, 2025 at 8:04 PM Andy Shevchenko
<andriy.shevchenko at intel.com> wrote:
>
> On Wed, Oct 22, 2025 at 03:10:43PM +0200, Bartosz Golaszewski wrote:
> >
> > Add a virtual GPIO proxy driver which arbitrates access to a single
> > shared GPIO by multiple users. It works together with the core shared
> > GPIO support from GPIOLIB and functions by acquiring a reference to a
> > shared GPIO descriptor exposed by gpiolib-shared and making sure that
> > the state of the GPIO stays consistent.
> >
> > In general: if there's only one user at the moment: allow it to do
> > anything as if this was a normal GPIO (in essence: just propagate calls
> > to the underlying real hardware driver). If there are more users: don't
> > allow to change the direction set by the initial user, allow to change
> > configuration options but warn about possible conflicts and finally:
> > treat the output-high value as a reference counted, logical "GPIO
> > enabled" setting, meaning: the GPIO value is set to high when the first
> > user requests it to be high and back to low once the last user stops
> > "voting" for high.
>
> I have two Q:s about the design:
> 1) why can't the value be counted on the struct gpio_desc level?
No, I specifically tried to limit the impact on users not needing this
to a minimum.
> 2) can gpio-aggregator facilities be reused (to some extent)?
I don't see how but if you have a precise idea, let me know.
>
> ...
>
> > +#include <linux/auxiliary_bus.h>
> > +#include <linux/cleanup.h>
> > +#include <linux/device.h>
> > +#include <linux/gpio/consumer.h>
> > +#include <linux/gpio/driver.h>
> > +#include <linux/module.h>
>
> + types.h
>
> > +#include "gpiolib-shared.h"
>
> ...
>
> > +out:
> > + if (shared_desc->highcnt)
> > + dev_dbg(proxy->dev,
> > + "Voted for value '%s', effective value is 'high', number of votes for 'high': %u\n",
> > + value ? "high" : "low", shared_desc->highcnt);
> > + else
> > + dev_dbg(proxy->dev, "Voted for value 'low', effective value is 'low'\n");
>
> You can unify and maybe save a few bytes here and there by doing something like
> this:
>
> const char *tmp; // name is a placeholder
>
> tmp = str_high_low(shared_desc->highcnt);
> dev_dbg(proxy->dev,
> "Voted for value '%s', effective value is '%s', number of votes for '%s': %u\n",
> str_high_low(value), tmp, tmp, shared_desc->highcnt);
>
This doesn't make sense, we don't "vote for low". We only vote for
high. It's not: which option gets the most votes, it's: if there's at
least one vote for high, then we go high.
Bart
More information about the linux-arm-kernel
mailing list