public inbox for linux-gpio@vger.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>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH v3 6/6] gpiolib: notify user-space about in-kernel line state changes
Date: Wed, 16 Oct 2024 17:17:14 +0800	[thread overview]
Message-ID: <20241016091714.GA207325@rigel> (raw)
In-Reply-To: <CAMRc=McR_eMizF6r30NqbgK4mE5ErzR=wbkD4O-Czn=+Oj4AXQ@mail.gmail.com>

On Wed, Oct 16, 2024 at 01:52:49AM -0700, Bartosz Golaszewski wrote:
> On Wed, 16 Oct 2024 10:37:47 +0200, Kent Gibson <warthog618@gmail.com> said:
> > On Wed, Oct 16, 2024 at 03:27:30PM +0800, Kent Gibson wrote:
> >> On Wed, Oct 16, 2024 at 01:19:44PM +0800, Kent Gibson wrote:
> >> > On Tue, Oct 15, 2024 at 12:56:18PM +0200, Bartosz Golaszewski wrote:
> >> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >> > >
> >> > > -	return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config);
> >> > > +	ret = gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config);
> >> > > +	if (ret == 0) {
> >> > > +		/* These are the only options we notify the userspace about. */
> >> > > +		switch (pinconf_to_config_param(config)) {
> >> > > +		case PIN_CONFIG_BIAS_DISABLE:
> >> > > +		case PIN_CONFIG_BIAS_PULL_DOWN:
> >> > > +		case PIN_CONFIG_BIAS_PULL_UP:
> >> > > +		case PIN_CONFIG_DRIVE_OPEN_DRAIN:
> >> > > +		case PIN_CONFIG_DRIVE_OPEN_SOURCE:
> >> > > +		case PIN_CONFIG_DRIVE_PUSH_PULL:
> >> > > +		case PIN_CONFIG_INPUT_DEBOUNCE:
> >> > > +			gpiod_line_state_notify(desc,
> >> > > +						GPIO_V2_LINE_CHANGED_CONFIG);
> >> > > +			break;
> >> > > +		default:
> >> > > +			break;
> >> > > +		}
> >> > > +	}
> >> > > +
> >> > > +	return ret;
> >> > >  }
> >> >
> >> > Ah, the debounce - I forgot about that, and other features that cdev
> >> > might emulate.
> >> >
> >> > What happens if userspace requests a line with debounce that is
> >> > supported by hardware?  Seems to me we'll see both a LINE_REQUESTED and a
> >> > LINE_CONFIG_CHANGED when the line is requested.
> >> >
> >>
> >> This is problematic for me to test at the moment, as gpiosim doesn't support
> >> debounce. Any chance we could make that configurable?  Similarly drive.
> >>
> >> > Conversely, what if a config change impacts features that don't result in a
> >> > notification from gpiod_set_config(), like active low, or emulated
> >> > drive or debounce?
> >> >
> >>
> >> Bah, drive is emulated in gpiolib itself, so that should be fine.
> >>
> >> When changing config cdev always calls gpiod_direction_input/output(), so I
> >> think that covers the active low case.
> >>
> >> But I have a test taking a line from input to output|open_drain and I
> >> get two change events.  The first is the most interesting as it reports
> >> input|open_drain, the second then reports output|open_drain.
> >> That is due to gpiod_direction_output() calling gpiod_set_config() to
> >> set the drive, and later to set the direction, in that order.
> >> Given it will be setting the direction, it should inhibit the event from
> >> the drive setting?
> >>
> >
> > Ok, I oversimplified, it was actually
> >
> > input -> output|active_low|open_drain
> >
> > and
> >
> > input -> output|open_source
> >
> > fails the same way.
> >
>
> Does the following help?
>
> @@ -2830,7 +2860,7 @@ int gpiod_direction_output(struct gpio_desc
> *desc, int value)
>  			goto set_output_value;
>  		/* Emulate open drain by not actively driving the line high */
>  		if (value) {
> -			ret = gpiod_direction_input(desc);
> +			ret = gpiod_direction_input_nonotify(desc);
>  			goto set_output_flag;
>  		}
>  	} else if (test_bit(FLAG_OPEN_SOURCE, &flags)) {
> @@ -2839,7 +2869,7 @@ int gpiod_direction_output(struct gpio_desc
> *desc, int value)
>  			goto set_output_value;
>  		/* Emulate open source by not actively driving the line low */
>  		if (!value) {
> -			ret = gpiod_direction_input(desc);
> +			ret = gpiod_direction_input_nonotify(desc);
>  			goto set_output_flag;
>  		}
>  	} else {
>

That fixes the drive problems.

> >> Still haven't tested any debounce changes...
> >>
> >
> > Have now.
> >
> > input -> input|debounce
> >
> > does not report the debounce.  Only get the one event and it does not
> > contain any debounce.
> >
>
> You mean, you get a CHANGED_CONFIG event but the debounce value is not
> in the associated line info?
>

Correct.

Cheers,
Kent.

  reply	other threads:[~2024-10-16  9:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 10:56 [PATCH v3 0/6] gpio: notify user-space about config changes in the kernel Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 1/6] gpiolib: notify user-space when a driver requests its own desc Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 2/6] gpio: cdev: prepare gpio_desc_to_lineinfo() for being called from atomic Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 3/6] gpiolib: add a per-gpio_device line state notification workqueue Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 4/6] gpio: cdev: put emitting the line state events on a workqueue Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 5/6] gpiolib: switch the line state notifier to atomic Bartosz Golaszewski
2024-10-15 10:56 ` [PATCH v3 6/6] gpiolib: notify user-space about in-kernel line state changes Bartosz Golaszewski
2024-10-16  5:19   ` Kent Gibson
2024-10-16  7:27     ` Kent Gibson
2024-10-16  7:50       ` Bartosz Golaszewski
2024-10-16  8:57         ` Kent Gibson
2024-10-16  9:02           ` Bartosz Golaszewski
2024-10-16  9:08             ` Kent Gibson
2024-10-16  8:37       ` Kent Gibson
2024-10-16  8:52         ` Bartosz Golaszewski
2024-10-16  9:17           ` Kent Gibson [this message]
2024-10-16  9:22             ` Bartosz Golaszewski
2024-10-16  9:43               ` Kent Gibson
2024-10-16 10:12                 ` Bartosz Golaszewski
2024-10-16 10:22                   ` Kent Gibson

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=20241016091714.GA207325@rigel \
    --to=warthog618@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox