devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes
@ 2016-03-11 21:01 Hans de Goede
       [not found] ` <1457730069-31760-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2016-03-11 21:01 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Mark Brown, Liam Girdwood
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede

The axp20x and axp22x pmics have ldo regulators which are muxed to the
outside via gpio pins. Unfortunately regulator enable / disable is
implemented in the hardware via selecting a specific pin-mux option.

So if we want to use these pins as gpio pins we must not register
a regulator for these pins at all, otherwise any gpio use (switching
to input, or writing a value) gets undone when the regulator subsys
disables unused regulators at the end of kernel-init.

This commits allows the use of  "status = disabled" in regulator dts
nodes and makes regulator_register return ENODEV when this is set.

Note that this commit changes the loop to find the of-node in
regulator_of_get_init_data from using for_each_available_child_of_node
to using for_each_child_of_node. regulator_register is the only user
of regulator_of_get_init_data and the use of for_each_available_child...
makes little sense there since this will only cause the constraints
from regulator dts nodes marked as disabled to not be used, the
actual registration of the regulator would still continue.

So in a way this patch could be seen as a bugfix as it actually makes
regulators with an of_node which is marked as not available not register,
but this behavior change may cause some issues in some places.

Note that individual regulator drivers / callers of regulator_register
which may encounter disabled regulator (child) nodes need to be patched to
handle ENODEV (to not make it fail their probe method).

Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/regulator/core.c         | 6 ++++++
 drivers/regulator/of_regulator.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 744c988..5589203 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3894,6 +3894,12 @@ regulator_register(const struct regulator_desc *regulator_desc,
 		rdev->dev.of_node = of_node_get(config->of_node);
 	}
 
+	if (rdev->dev.of_node && !of_device_is_available(rdev->dev.of_node)) {
+		kfree(config);
+		kfree(rdev);
+		return ERR_PTR(-ENODEV);
+	}
+
 	mutex_lock(&regulator_list_mutex);
 
 	mutex_init(&rdev->mutex);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 499e437..06ad766 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -310,7 +310,7 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
 		return NULL;
 	}
 
-	for_each_available_child_of_node(search, child) {
+	for_each_child_of_node(search, child) {
 		name = of_get_property(child, "regulator-compatible", NULL);
 		if (!name)
 			name = child->name;
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] regulator: axp20x: Handle regulator_register returning ENODEV
       [not found] ` <1457730069-31760-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2016-03-11 21:01   ` Hans de Goede
  2016-03-11 21:01   ` [PATCH 3/3] ARM: dts: sunxi: Disable axp22x ldo_io# regulators by default Hans de Goede
  2016-03-29  9:57   ` [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes Maxime Ripard
  2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2016-03-11 21:01 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Mark Brown, Liam Girdwood
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede

Handle regulator_register returning ENODEV, this may happen when
the dts node for the regulator contains "status = disabled" which
is useful for the ldo_io regulators, to avoid the regulator code
getting in the way of gpio use of these pins.

Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/regulator/axp20x-regulator.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 679018c..4250b1b 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -421,6 +421,9 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
 
 		rdev = devm_regulator_register(&pdev->dev, desc, &config);
 		if (IS_ERR(rdev)) {
+			if (PTR_ERR(rdev) == -ENODEV)
+				continue;
+
 			dev_err(&pdev->dev, "Failed to register %s\n",
 				regulators[i].name);
 
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] ARM: dts: sunxi: Disable axp22x ldo_io# regulators by default
       [not found] ` <1457730069-31760-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  2016-03-11 21:01   ` [PATCH 2/3] regulator: axp20x: Handle regulator_register returning ENODEV Hans de Goede
@ 2016-03-11 21:01   ` Hans de Goede
  2016-03-29  9:57   ` [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes Maxime Ripard
  2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2016-03-11 21:01 UTC (permalink / raw)
  To: Maxime Ripard, Chen-Yu Tsai, Mark Brown, Liam Girdwood
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw, Hans de Goede

Use of these as regulators conflicts with use of the gpio pins as
gpios, so disabled the ldo_io# regulators by default.

Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 arch/arm/boot/dts/axp22x.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boot/dts/axp22x.dtsi b/arch/arm/boot/dts/axp22x.dtsi
index 76302f5..0cfec50 100644
--- a/arch/arm/boot/dts/axp22x.dtsi
+++ b/arch/arm/boot/dts/axp22x.dtsi
@@ -126,10 +126,12 @@
 
 		reg_ldo_io0: ldo_io0 {
 			regulator-name = "ldo_io0";
+			status = "disabled";
 		};
 
 		reg_ldo_io1: ldo_io1 {
 			regulator-name = "ldo_io1";
+			status = "disabled";
 		};
 
 		reg_rtc_ldo: rtc_ldo {
-- 
2.7.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes
       [not found] ` <1457730069-31760-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  2016-03-11 21:01   ` [PATCH 2/3] regulator: axp20x: Handle regulator_register returning ENODEV Hans de Goede
  2016-03-11 21:01   ` [PATCH 3/3] ARM: dts: sunxi: Disable axp22x ldo_io# regulators by default Hans de Goede
@ 2016-03-29  9:57   ` Maxime Ripard
  2 siblings, 0 replies; 4+ messages in thread
From: Maxime Ripard @ 2016-03-29  9:57 UTC (permalink / raw)
  To: Mark Brown, Hans de Goede
  Cc: Chen-Yu Tsai, Liam Girdwood,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, devicetree,
	linux-sunxi-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1842 bytes --]

Hi Mark,

On Fri, Mar 11, 2016 at 10:01:07PM +0100, Hans de Goede wrote:
> The axp20x and axp22x pmics have ldo regulators which are muxed to the
> outside via gpio pins. Unfortunately regulator enable / disable is
> implemented in the hardware via selecting a specific pin-mux option.
> 
> So if we want to use these pins as gpio pins we must not register
> a regulator for these pins at all, otherwise any gpio use (switching
> to input, or writing a value) gets undone when the regulator subsys
> disables unused regulators at the end of kernel-init.
> 
> This commits allows the use of  "status = disabled" in regulator dts
> nodes and makes regulator_register return ENODEV when this is set.
> 
> Note that this commit changes the loop to find the of-node in
> regulator_of_get_init_data from using for_each_available_child_of_node
> to using for_each_child_of_node. regulator_register is the only user
> of regulator_of_get_init_data and the use of for_each_available_child...
> makes little sense there since this will only cause the constraints
> from regulator dts nodes marked as disabled to not be used, the
> actual registration of the regulator would still continue.
> 
> So in a way this patch could be seen as a bugfix as it actually makes
> regulators with an of_node which is marked as not available not register,
> but this behavior change may cause some issues in some places.
> 
> Note that individual regulator drivers / callers of regulator_register
> which may encounter disabled regulator (child) nodes need to be patched to
> handle ENODEV (to not make it fail their probe method).
> 
> Signed-off-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Any comments on this one?

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-29  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-11 21:01 [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes Hans de Goede
     [not found] ` <1457730069-31760-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-11 21:01   ` [PATCH 2/3] regulator: axp20x: Handle regulator_register returning ENODEV Hans de Goede
2016-03-11 21:01   ` [PATCH 3/3] ARM: dts: sunxi: Disable axp22x ldo_io# regulators by default Hans de Goede
2016-03-29  9:57   ` [PATCH 1/3] regulator: core: Allow use of "status = disabled" in regulator dts nodes Maxime Ripard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).