summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpiolib-shared.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2025-11-12 14:55:35 +0100
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2025-11-17 10:16:51 +0100
commiteb374f764a7012eda28019266a6d9191670c4fa5 (patch)
tree95af5d515b7797c05613a65b787c7820082a6ff3 /drivers/gpio/gpiolib-shared.c
parent1e4f6db614a310cc34d07ffbf031c76ea9581bcf (diff)
gpio: provide gpiod_is_shared()
Provide an interface allowing consumers to check if a GPIO descriptor represents a GPIO that can potentially be shared by multiple consumers at the same time. This is exposed to allow subsystems that already work around the limitations of the current non-exclusive GPIO handling in some ways, to gradually convert to relying on the new shared GPIO feature of GPIOLIB. Extend the gpiolib-shared module to mark the GPIO shared proxy descriptors with a flag checked by the new interface. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20251112-gpio-shared-v4-6-b51f97b1abd8@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-shared.c')
-rw-r--r--drivers/gpio/gpiolib-shared.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
index 1fcbf53b6eca..fa1d16635ea7 100644
--- a/drivers/gpio/gpiolib-shared.c
+++ b/drivers/gpio/gpiolib-shared.c
@@ -315,6 +315,24 @@ int gpio_device_setup_shared(struct gpio_device *gdev)
guard(mutex)(&gpio_shared_lock);
list_for_each_entry(entry, &gpio_shared_list, list) {
+ list_for_each_entry(ref, &entry->refs, list) {
+ if (gdev->dev.parent == &ref->adev.dev) {
+ /*
+ * This is a shared GPIO proxy. Mark its
+ * descriptor as such and return here.
+ */
+ __set_bit(GPIOD_FLAG_SHARED_PROXY,
+ &gdev->descs[0].flags);
+ return 0;
+ }
+ }
+ }
+
+ /*
+ * This is not a shared GPIO proxy but it still may be the device
+ * exposing shared pins. Find them and create the proxy devices.
+ */
+ list_for_each_entry(entry, &gpio_shared_list, list) {
if (!device_match_fwnode(&gdev->dev, entry->fwnode))
continue;