summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2025-11-20 09:23:08 +0000
committerMark Brown <broonie@kernel.org>2025-11-20 09:23:08 +0000
commitc22f7a5cd205492c48c6deb72f5efe2ae63c931e (patch)
treef0dc02e8a02f97b06548d4f9b42fcc9f83e1e316 /drivers/regulator
parent21e68bcb1b0c688c2d9ca0d457922febac650ac1 (diff)
parentb871d9adffe5a64a1fd9edcb1aebbcc995b17901 (diff)
gpio: improve support for shared GPIOs
Merge series from Bartosz Golaszewski <brgl@bgdev.pl>: Problem statement: GPIOs are implemented as a strictly exclusive resource in the kernel but there are lots of platforms on which single pin is shared by multiple devices which don't communicate so need some way of properly sharing access to a GPIO. What we have now is the GPIOD_FLAGS_BIT_NONEXCLUSIVE flag which was introduced as a hack and doesn't do any locking or arbitration of access - it literally just hand the same GPIO descriptor to all interested users. The proposed solution is composed of three major parts: the high-level, shared GPIO proxy driver that arbitrates access to the shared pin and exposes a regular GPIO chip interface to consumers, a low-level shared GPIOLIB module that scans firmware nodes and creates auxiliary devices that attach to the proxy driver and finally a set of core GPIOLIB changes that plug the former into the GPIO lookup path. The changes are implemented in a way that allows to seamlessly compile out any code related to sharing GPIOs for systems that don't need it. The practical use-case for this are the powerdown GPIOs shared by speakers on Qualcomm db845c platform, however I have also extensively tested it using gpio-virtuser on arm64 qemu with various DT configurations.
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2eab56df042e..53b2b2d3746f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2742,6 +2742,13 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
mutex_lock(&regulator_list_mutex);
+ if (gpiod_is_shared(gpiod))
+ /*
+ * The sharing of this GPIO pin is managed internally by
+ * GPIOLIB. We don't need to keep track of its enable count.
+ */
+ goto skip_compare;
+
list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
if (gpiod_is_equal(pin->gpiod, gpiod)) {
rdev_dbg(rdev, "GPIO is already used\n");
@@ -2754,6 +2761,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
return -ENOMEM;
}
+skip_compare:
pin = new_pin;
new_pin = NULL;