[PATCH v3 10/10] regulator: make the subsystem aware of shared GPIOs

Bartosz Golaszewski posted 10 patches 5 months, 1 week ago
There is a newer version of this series
[PATCH v3 10/10] regulator: make the subsystem aware of shared GPIOs
Posted by Bartosz Golaszewski 5 months, 1 week ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

GPIOLIB is now aware of shared GPIOs and - for platforms where access to
such pins is managed internally - we don't need to keep track of the
enable count.

Once all users in the kernel switch to using the new mechanism, we'll be
able to drop the internal counting of users from the regulator code.

Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/regulator/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 84bc38911dba308539a25dd3af30a5c24802b890..e13cf5e120466cebc4d3f8400b89be07d3303338 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2737,6 +2737,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");
@@ -2749,6 +2756,7 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
 		return -ENOMEM;
 	}
 
+skip_compare:
 	pin = new_pin;
 	new_pin = NULL;
 

-- 
2.48.1
Re: [PATCH v3 10/10] regulator: make the subsystem aware of shared GPIOs
Posted by Andy Shevchenko 5 months, 1 week ago
On Wed, Oct 29, 2025 at 12:20:46PM +0100, Bartosz Golaszewski wrote:
> 
> GPIOLIB is now aware of shared GPIOs and - for platforms where access to
> such pins is managed internally - we don't need to keep track of the
> enable count.
> 
> Once all users in the kernel switch to using the new mechanism, we'll be
> able to drop the internal counting of users from the regulator code.

I am wondering if you took into account the layering violation (or others
put it as "transferring of ownership") in the regulator core for the platform
based GPIO regulators? This popped up during the discussion of
https://lore.kernel.org/platform-driver-x86/20251024050537.92440-1-qiuwenbo@gnome.org/

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 10/10] regulator: make the subsystem aware of shared GPIOs
Posted by Bartosz Golaszewski 5 months, 1 week ago
On Wed, Oct 29, 2025 at 12:54 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Oct 29, 2025 at 12:20:46PM +0100, Bartosz Golaszewski wrote:
> >
> > GPIOLIB is now aware of shared GPIOs and - for platforms where access to
> > such pins is managed internally - we don't need to keep track of the
> > enable count.
> >
> > Once all users in the kernel switch to using the new mechanism, we'll be
> > able to drop the internal counting of users from the regulator code.
>
> I am wondering if you took into account the layering violation (or others
> put it as "transferring of ownership") in the regulator core for the platform
> based GPIO regulators? This popped up during the discussion of
> https://lore.kernel.org/platform-driver-x86/20251024050537.92440-1-qiuwenbo@gnome.org/
>

I am aware of this weird ownership transfer in regulator but these
changes don't affect it. The layering is still being violated though.

This should be fixed and I've looked into it but it's not trivial so
it's another big rework for the future.

Bart
Re: [PATCH v3 10/10] regulator: make the subsystem aware of shared GPIOs
Posted by Andy Shevchenko 5 months, 1 week ago
On Wed, Oct 29, 2025 at 01:41:10PM +0100, Bartosz Golaszewski wrote:
> On Wed, Oct 29, 2025 at 12:54 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Wed, Oct 29, 2025 at 12:20:46PM +0100, Bartosz Golaszewski wrote:
> > >
> > > GPIOLIB is now aware of shared GPIOs and - for platforms where access to
> > > such pins is managed internally - we don't need to keep track of the
> > > enable count.
> > >
> > > Once all users in the kernel switch to using the new mechanism, we'll be
> > > able to drop the internal counting of users from the regulator code.
> >
> > I am wondering if you took into account the layering violation (or others
> > put it as "transferring of ownership") in the regulator core for the platform
> > based GPIO regulators? This popped up during the discussion of
> > https://lore.kernel.org/platform-driver-x86/20251024050537.92440-1-qiuwenbo@gnome.org/
> 
> I am aware of this weird ownership transfer in regulator but these
> changes don't affect it. The layering is still being violated though.
> 
> This should be fixed and I've looked into it but it's not trivial so
> it's another big rework for the future.

OK, thanks for clarifications!

-- 
With Best Regards,
Andy Shevchenko