All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO
@ 2018-06-19 15:10 Charles Keepax
  2018-06-19 15:24 ` Applied "regulator: arizona-ldo1: Use correct device to get enable GPIO" to the regulator tree Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Charles Keepax @ 2018-06-19 15:10 UTC (permalink / raw)
  To: broonie, hias; +Cc: lgirdwood, linus.walleij, patches, linux-kernel

Currently the enable GPIO is being looked up on the regulator
device itself but that does not have its own DT node, this causes
the lookup to fail and the regulator not to get its GPIO. The DT
node is shared across the whole MFD and as such the lookup needs
to happen on that parent device. Moving the lookup to the parent
device also means devres can no longer be used as the life time
would attach to the wrong device.

Additionally, the enable GPIO is active high so we should be passing
GPIOD_OUT_LOW to ensure the regulator starts in its off state allowing
the driver to enable it when it is ready.

Fixes: e1739e86f0cb ("regulator: arizona-ldo1: Look up a descriptor and pass to the core")
Reported-by: Matthias Reichl <hias@horus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Changes since v1:
 - Pass GPIOD_OUT_LOW to gpiod_get_optional

Thanks,
Charles

 drivers/regulator/arizona-ldo1.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index f6d6a4ad9e8a..e976d073f28d 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -36,6 +36,8 @@ struct arizona_ldo1 {
 
 	struct regulator_consumer_supply supply;
 	struct regulator_init_data init_data;
+
+	struct gpio_desc *ena_gpiod;
 };
 
 static int arizona_ldo1_hc_list_voltage(struct regulator_dev *rdev,
@@ -253,12 +255,17 @@ static int arizona_ldo1_common_init(struct platform_device *pdev,
 		}
 	}
 
-	/* We assume that high output = regulator off */
-	config.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "wlf,ldoena",
-						   GPIOD_OUT_HIGH);
+	/* We assume that high output = regulator off
+	 * Don't use devm, since we need to get against the parent device
+	 * so clean up would happen at the wrong time
+	 */
+	config.ena_gpiod = gpiod_get_optional(parent_dev, "wlf,ldoena",
+					      GPIOD_OUT_LOW);
 	if (IS_ERR(config.ena_gpiod))
 		return PTR_ERR(config.ena_gpiod);
 
+	ldo1->ena_gpiod = config.ena_gpiod;
+
 	if (pdata->init_data)
 		config.init_data = pdata->init_data;
 	else
@@ -276,6 +283,9 @@ static int arizona_ldo1_common_init(struct platform_device *pdev,
 	of_node_put(config.of_node);
 
 	if (IS_ERR(ldo1->regulator)) {
+		if (config.ena_gpiod)
+			gpiod_put(config.ena_gpiod);
+
 		ret = PTR_ERR(ldo1->regulator);
 		dev_err(&pdev->dev, "Failed to register LDO1 supply: %d\n",
 			ret);
@@ -334,8 +344,19 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int arizona_ldo1_remove(struct platform_device *pdev)
+{
+	struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
+
+	if (ldo1->ena_gpiod)
+		gpiod_put(ldo1->ena_gpiod);
+
+	return 0;
+}
+
 static struct platform_driver arizona_ldo1_driver = {
 	.probe = arizona_ldo1_probe,
+	.remove = arizona_ldo1_remove,
 	.driver		= {
 		.name	= "arizona-ldo1",
 	},
-- 
2.11.0


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

* Applied "regulator: arizona-ldo1: Use correct device to get enable GPIO" to the regulator tree
  2018-06-19 15:10 [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Charles Keepax
@ 2018-06-19 15:24 ` Mark Brown
  2018-06-19 20:46 ` [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Andy Shevchenko
  2018-06-29  8:05 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2018-06-19 15:24 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Matthias Reichl, Mark Brown, broonie, hias, lgirdwood,
	linus.walleij, patches, linux-kernel, linux-kernel

The patch

   regulator: arizona-ldo1: Use correct device to get enable GPIO

has been applied to the regulator tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From a9191579ba1086d91842199263e6fe6bb5eec1ba Mon Sep 17 00:00:00 2001
From: Charles Keepax <ckeepax@opensource.cirrus.com>
Date: Tue, 19 Jun 2018 16:10:00 +0100
Subject: [PATCH] regulator: arizona-ldo1: Use correct device to get enable
 GPIO

Currently the enable GPIO is being looked up on the regulator
device itself but that does not have its own DT node, this causes
the lookup to fail and the regulator not to get its GPIO. The DT
node is shared across the whole MFD and as such the lookup needs
to happen on that parent device. Moving the lookup to the parent
device also means devres can no longer be used as the life time
would attach to the wrong device.

Additionally, the enable GPIO is active high so we should be passing
GPIOD_OUT_LOW to ensure the regulator starts in its off state allowing
the driver to enable it when it is ready.

Fixes: e1739e86f0cb ("regulator: arizona-ldo1: Look up a descriptor and pass to the core")
Reported-by: Matthias Reichl <hias@horus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/regulator/arizona-ldo1.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index f6d6a4ad9e8a..e976d073f28d 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -36,6 +36,8 @@ struct arizona_ldo1 {
 
 	struct regulator_consumer_supply supply;
 	struct regulator_init_data init_data;
+
+	struct gpio_desc *ena_gpiod;
 };
 
 static int arizona_ldo1_hc_list_voltage(struct regulator_dev *rdev,
@@ -253,12 +255,17 @@ static int arizona_ldo1_common_init(struct platform_device *pdev,
 		}
 	}
 
-	/* We assume that high output = regulator off */
-	config.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "wlf,ldoena",
-						   GPIOD_OUT_HIGH);
+	/* We assume that high output = regulator off
+	 * Don't use devm, since we need to get against the parent device
+	 * so clean up would happen at the wrong time
+	 */
+	config.ena_gpiod = gpiod_get_optional(parent_dev, "wlf,ldoena",
+					      GPIOD_OUT_LOW);
 	if (IS_ERR(config.ena_gpiod))
 		return PTR_ERR(config.ena_gpiod);
 
+	ldo1->ena_gpiod = config.ena_gpiod;
+
 	if (pdata->init_data)
 		config.init_data = pdata->init_data;
 	else
@@ -276,6 +283,9 @@ static int arizona_ldo1_common_init(struct platform_device *pdev,
 	of_node_put(config.of_node);
 
 	if (IS_ERR(ldo1->regulator)) {
+		if (config.ena_gpiod)
+			gpiod_put(config.ena_gpiod);
+
 		ret = PTR_ERR(ldo1->regulator);
 		dev_err(&pdev->dev, "Failed to register LDO1 supply: %d\n",
 			ret);
@@ -334,8 +344,19 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int arizona_ldo1_remove(struct platform_device *pdev)
+{
+	struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
+
+	if (ldo1->ena_gpiod)
+		gpiod_put(ldo1->ena_gpiod);
+
+	return 0;
+}
+
 static struct platform_driver arizona_ldo1_driver = {
 	.probe = arizona_ldo1_probe,
+	.remove = arizona_ldo1_remove,
 	.driver		= {
 		.name	= "arizona-ldo1",
 	},
-- 
2.17.1


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

* Re: [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO
  2018-06-19 15:10 [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Charles Keepax
  2018-06-19 15:24 ` Applied "regulator: arizona-ldo1: Use correct device to get enable GPIO" to the regulator tree Mark Brown
@ 2018-06-19 20:46 ` Andy Shevchenko
  2018-06-20  8:14   ` Charles Keepax
  2018-06-29  8:05 ` Linus Walleij
  2 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2018-06-19 20:46 UTC (permalink / raw)
  To: Charles Keepax
  Cc: Mark Brown, hias, Liam Girdwood, Linus Walleij, patches,
	Linux Kernel Mailing List

On Tue, Jun 19, 2018 at 6:10 PM, Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
> Currently the enable GPIO is being looked up on the regulator
> device itself but that does not have its own DT node, this causes
> the lookup to fail and the regulator not to get its GPIO. The DT
> node is shared across the whole MFD and as such the lookup needs
> to happen on that parent device.

> Moving the lookup to the parent
> device also means devres can no longer be used as the life time
> would attach to the wrong device.

This part I didn't get.
Why we can't use devm_...(parent_dev, ...) instead?

>
> Additionally, the enable GPIO is active high so we should be passing
> GPIOD_OUT_LOW to ensure the regulator starts in its off state allowing
> the driver to enable it when it is ready.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO
  2018-06-19 20:46 ` [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Andy Shevchenko
@ 2018-06-20  8:14   ` Charles Keepax
  0 siblings, 0 replies; 5+ messages in thread
From: Charles Keepax @ 2018-06-20  8:14 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Mark Brown, hias, Liam Girdwood, Linus Walleij, patches,
	Linux Kernel Mailing List

On Tue, Jun 19, 2018 at 11:46:36PM +0300, Andy Shevchenko wrote:
> On Tue, Jun 19, 2018 at 6:10 PM, Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> > Currently the enable GPIO is being looked up on the regulator
> > device itself but that does not have its own DT node, this causes
> > the lookup to fail and the regulator not to get its GPIO. The DT
> > node is shared across the whole MFD and as such the lookup needs
> > to happen on that parent device.
> 
> > Moving the lookup to the parent
> > device also means devres can no longer be used as the life time
> > would attach to the wrong device.
> 
> This part I didn't get.
> Why we can't use devm_...(parent_dev, ...) instead?
> 

Because it is possible to unbind the regulator driver itself,
which would leave the GPIO as acquired, since the MFD is never
unbound. Then when you rebind the regulator the GPIO would
already be held by the previous instantiation of the regulator
driver.

Thanks,
Charles

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

* Re: [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO
  2018-06-19 15:10 [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Charles Keepax
  2018-06-19 15:24 ` Applied "regulator: arizona-ldo1: Use correct device to get enable GPIO" to the regulator tree Mark Brown
  2018-06-19 20:46 ` [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Andy Shevchenko
@ 2018-06-29  8:05 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2018-06-29  8:05 UTC (permalink / raw)
  To: Charles Keepax; +Cc: Mark Brown, hias, Liam Girdwood, patches, linux-kernel

On Tue, Jun 19, 2018 at 5:10 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:

> Currently the enable GPIO is being looked up on the regulator
> device itself but that does not have its own DT node, this causes
> the lookup to fail and the regulator not to get its GPIO. The DT
> node is shared across the whole MFD and as such the lookup needs
> to happen on that parent device. Moving the lookup to the parent
> device also means devres can no longer be used as the life time
> would attach to the wrong device.
>
> Additionally, the enable GPIO is active high so we should be passing
> GPIOD_OUT_LOW to ensure the regulator starts in its off state allowing
> the driver to enable it when it is ready.
>
> Fixes: e1739e86f0cb ("regulator: arizona-ldo1: Look up a descriptor and pass to the core")
> Reported-by: Matthias Reichl <hias@horus.com>
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> ---
>
> Changes since v1:
>  - Pass GPIOD_OUT_LOW to gpiod_get_optional

Nice, thanks for fixing this!
Sorry for screwing it up :(

I wish I could be more careful, but without access to the
hardware it is sometimes pretty tricky not to break things
by mistake.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-06-29  8:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-19 15:10 [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Charles Keepax
2018-06-19 15:24 ` Applied "regulator: arizona-ldo1: Use correct device to get enable GPIO" to the regulator tree Mark Brown
2018-06-19 20:46 ` [PATCH v2] regulator: arizona-ldo1: Use correct device to get enable GPIO Andy Shevchenko
2018-06-20  8:14   ` Charles Keepax
2018-06-29  8:05 ` Linus Walleij

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.