All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v2] gpiolib: notify user-space about line state changes triggered by kernel
Date: Thu, 24 Aug 2023 17:27:07 +0800	[thread overview]
Message-ID: <ZOcia3Nt+SzypTGm@sol> (raw)
In-Reply-To: <CAMRc=MdEqm2U9AfPiw5kerJpB1hXyvEQ1_m7EhgoFZ+G3UyDAA@mail.gmail.com>

On Thu, Aug 24, 2023 at 11:11:18AM +0200, Bartosz Golaszewski wrote:
> On Thu, Aug 24, 2023 at 11:08 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Thu, Aug 24, 2023 at 10:55:44AM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > > We currently only emit CHANGED_CONFIG events when the user-space changes
> > > GPIO config. We won't be notified if changes come from in-kernel. Let's
> > > call the notifier chain whenever kernel users change direction or any of
> > > the active-low, debounce or consumer name settings. We don't notify the
> > > user-space about the persistence as the uAPI has no notion of it.
> > >
> > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > ---
> > > v1 -> v2:
> > > - use the gpiod_line_state_notify() helper
> > > - reorder the code in gpiod_set_debounce() for better readability
> > >
> > >  drivers/gpio/gpiolib.c | 16 ++++++++++++++--
> > >  1 file changed, 14 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > index 40a0022ea719..1cb7731550ca 100644
> > > --- a/drivers/gpio/gpiolib.c
> > > +++ b/drivers/gpio/gpiolib.c
> > > @@ -2439,6 +2439,7 @@ int gpiod_direction_input(struct gpio_desc *desc)
> > >       }
> > >       if (ret == 0) {
> > >               clear_bit(FLAG_IS_OUT, &desc->flags);
> > > +             gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG);
> > >               ret = gpio_set_bias(desc);
> > >       }
> > >
> >
> > gpiod_direction_input() is called by cdev when a line is requested.
> > So requesting a line now creates two events - REQUESTED and
> > HANGED_CONFIG? Even worse - it calls gpiod_direction_input() first, so we
> > will get CHANGED_CONFIG then REQUESTED??
> >
> > And a config change from cdev can call this and then generate a
> > CHANGED_CONFIG event itself, so again double events.
> >
> > Same for output and probably debounce too (that one is a bit more
> > convoluted).
> 
> Ah, should have tested it with user-space too...
> 
> Back to the drawing board I guess. May be the reason why we're not
> doing it in the first place yet.
> 

I think we were only looking at it from the userspace PoV, so what
constitutes a "change" is only well defined when driven from userspace.
This might be difficult to generalise without redefining what
"changed" means, or providing cdev with a separate gpiolib API so you
can tell whether the change is actually part of a cdev request, or ...

So, yeah - more thought required.

Got a use case that requires this, or just a nice to have?

Cheers,
Kent.

  reply	other threads:[~2023-08-24  9:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24  8:55 [PATCH v2] gpiolib: notify user-space about line state changes triggered by kernel Bartosz Golaszewski
2023-08-24  9:08 ` Kent Gibson
2023-08-24  9:11   ` Bartosz Golaszewski
2023-08-24  9:27     ` Kent Gibson [this message]
2023-08-24  9:32       ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZOcia3Nt+SzypTGm@sol \
    --to=warthog618@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.