From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Kent Gibson <warthog618@gmail.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH] gpiolib: notify user-space about line state changes triggered by kernel
Date: Fri, 18 Aug 2023 21:09:44 +0200 [thread overview]
Message-ID: <20230818190944.22177-1-brgl@bgdev.pl> (raw)
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>
---
drivers/gpio/gpiolib.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 76e0c38026c3..77e0d0afa2b5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2421,6 +2421,9 @@ int gpiod_direction_input(struct gpio_desc *desc)
}
if (ret == 0) {
clear_bit(FLAG_IS_OUT, &desc->flags);
+ blocking_notifier_call_chain(&desc->gdev->notifier,
+ GPIO_V2_LINE_CHANGED_CONFIG,
+ desc);
ret = gpio_set_bias(desc);
}
@@ -2466,8 +2469,12 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)
gc->set(gc, gpio_chip_hwgpio(desc), val);
}
- if (!ret)
+ if (!ret) {
set_bit(FLAG_IS_OUT, &desc->flags);
+ blocking_notifier_call_chain(&desc->gdev->notifier,
+ GPIO_V2_LINE_CHANGED_CONFIG,
+ desc);
+ }
trace_gpio_value(desc_to_gpio(desc), 0, val);
trace_gpio_direction(desc_to_gpio(desc), 0, ret);
return ret;
@@ -2654,9 +2661,15 @@ EXPORT_SYMBOL_GPL(gpiod_set_config);
int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
{
unsigned long config;
+ int ret;
config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
- return gpiod_set_config(desc, config);
+ ret = gpiod_set_config(desc, config);
+ if (!ret)
+ blocking_notifier_call_chain(&desc->gdev->notifier,
+ GPIO_V2_LINE_CHANGED_CONFIG,
+ desc);
+ return ret;
}
EXPORT_SYMBOL_GPL(gpiod_set_debounce);
@@ -2705,6 +2718,8 @@ void gpiod_toggle_active_low(struct gpio_desc *desc)
{
VALIDATE_DESC_VOID(desc);
change_bit(FLAG_ACTIVE_LOW, &desc->flags);
+ blocking_notifier_call_chain(&desc->gdev->notifier,
+ GPIO_V2_LINE_CHANGED_CONFIG, desc);
}
EXPORT_SYMBOL_GPL(gpiod_toggle_active_low);
@@ -3312,6 +3327,8 @@ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)
kfree_const(desc->label);
desc_set_label(desc, name);
+ blocking_notifier_call_chain(&desc->gdev->notifier,
+ GPIO_V2_LINE_CHANGED_CONFIG, desc);
return 0;
}
--
2.39.2
next reply other threads:[~2023-08-18 19:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-18 19:09 Bartosz Golaszewski [this message]
2023-08-21 10:43 ` [PATCH] gpiolib: notify user-space about line state changes triggered by kernel Andy Shevchenko
2023-08-24 8:47 ` 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=20230818190944.22177-1-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=warthog618@gmail.com \
/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.