linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time
@ 2017-06-13 13:58 Michał Mirosław
  2017-06-13 13:58 ` [PATCH 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 13:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Liam Girdwood, Mark Brown, Tony Lindgren, linux-omap

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/regulator/tps65910-regulator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 696116ebdf50a..81672a58fcc23 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1107,6 +1107,7 @@ static int tps65910_probe(struct platform_device *pdev)
 
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65910:
+		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
 		pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
 		pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
 		pmic->ext_sleep_control = tps65910_ext_sleep_control;
@@ -1119,6 +1120,7 @@ static int tps65910_probe(struct platform_device *pdev)
 					DCDCCTRL_DCDCCKSYNC_MASK);
 		break;
 	case TPS65911:
+		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
 		pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
 		pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
 		pmic->ext_sleep_control = tps65911_ext_sleep_control;
@@ -1144,8 +1146,7 @@ static int tps65910_probe(struct platform_device *pdev)
 	if (!pmic->rdev)
 		return -ENOMEM;
 
-	for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
-			i++, info++) {
+	for (i = 0; i < pmic->num_regulators; i++, info++) {
 		/* Register the regulators */
 		pmic->info[i] = info;
 
-- 
2.11.0

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

* [PATCH 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 13:58 [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Michał Mirosław
@ 2017-06-13 13:58 ` Michał Mirosław
  2017-06-13 14:01 ` [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Keerthy
  2017-06-13 14:41 ` [PATCH v2 " Michał Mirosław
  2 siblings, 0 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 13:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Liam Girdwood, Mark Brown, Tony Lindgren, linux-omap

This allows for (acyclic) references from tps6591x supplies to
its outputs.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/regulator/tps65910-regulator.c | 39 ++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 81672a58fcc23..f7987168ba4ed 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1082,7 +1082,8 @@ static int tps65910_probe(struct platform_device *pdev)
 	struct tps65910_reg *pmic;
 	struct tps65910_board *pmic_plat_data;
 	struct of_regulator_match *tps65910_reg_matches = NULL;
-	int i, err;
+	bool made_progress;
+	int i, err, pending;
 
 	pmic_plat_data = dev_get_platdata(tps65910->dev);
 	if (!pmic_plat_data && tps65910->dev->of_node)
@@ -1146,6 +1147,7 @@ static int tps65910_probe(struct platform_device *pdev)
 	if (!pmic->rdev)
 		return -ENOMEM;
 
+	/* prepare regulator description */
 	for (i = 0; i < pmic->num_regulators; i++, info++) {
 		/* Register the regulators */
 		pmic->info[i] = info;
@@ -1196,18 +1198,32 @@ static int tps65910_probe(struct platform_device *pdev)
 		pmic->desc[i].owner = THIS_MODULE;
 		pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
 		pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
+	}
+
+	/* Register regulators - loop, as one regulator's output
+	 * might be anothers input */
+
+	config.dev = pmic->mfd->dev;
+	config.driver_data = pmic;
+	config.regmap = pmic->mfd->regmap;
+	pending = pmic->num_regulators;
+
+reg_retry:
+	made_progress = false;
+	for (i = 0; i < pmic->num_regulators; i++) {
+		if (pmic->rdev[i])
+			continue;
 
-		config.dev = tps65910->dev;
 		config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
-		config.driver_data = pmic;
-		config.regmap = tps65910->regmap;
-
 		if (tps65910_reg_matches)
 			config.of_node = tps65910_reg_matches[i].of_node;
 
 		rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
 					       &config);
 		if (IS_ERR(rdev)) {
+			if (PTR_ERR(rdev) == -EPROBE_DEFER)
+				continue;
+
 			dev_err(tps65910->dev,
 				"failed to register %s regulator\n",
 				pdev->name);
@@ -1216,8 +1232,19 @@ static int tps65910_probe(struct platform_device *pdev)
 
 		/* Save regulator for cleanup */
 		pmic->rdev[i] = rdev;
+
+		made_progress = true;
+		--pending;
 	}
-	return 0;
+
+	/* all done? */
+	if (!pending)
+		return 0;
+
+	if (made_progress)
+		goto reg_retry;
+
+	return -EPROBE_DEFER;
 }
 
 static void tps65910_shutdown(struct platform_device *pdev)
-- 
2.11.0

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

* Re: [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time
  2017-06-13 13:58 [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Michał Mirosław
  2017-06-13 13:58 ` [PATCH 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
@ 2017-06-13 14:01 ` Keerthy
  2017-06-13 14:35   ` Michał Mirosław
  2017-06-13 14:41 ` [PATCH v2 " Michał Mirosław
  2 siblings, 1 reply; 12+ messages in thread
From: Keerthy @ 2017-06-13 14:01 UTC (permalink / raw)
  To: Michał Mirosław, linux-kernel
  Cc: Liam Girdwood, Mark Brown, Tony Lindgren, linux-omap



On Tuesday 13 June 2017 07:28 PM, Michał Mirosław wrote:

Missing commit log?

> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/regulator/tps65910-regulator.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
> index 696116ebdf50a..81672a58fcc23 100644
> --- a/drivers/regulator/tps65910-regulator.c
> +++ b/drivers/regulator/tps65910-regulator.c
> @@ -1107,6 +1107,7 @@ static int tps65910_probe(struct platform_device *pdev)
>  
>  	switch (tps65910_chip_id(tps65910)) {
>  	case TPS65910:
> +		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
>  		pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
>  		pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
>  		pmic->ext_sleep_control = tps65910_ext_sleep_control;
> @@ -1119,6 +1120,7 @@ static int tps65910_probe(struct platform_device *pdev)
>  					DCDCCTRL_DCDCCKSYNC_MASK);
>  		break;
>  	case TPS65911:
> +		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
>  		pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
>  		pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
>  		pmic->ext_sleep_control = tps65911_ext_sleep_control;
> @@ -1144,8 +1146,7 @@ static int tps65910_probe(struct platform_device *pdev)
>  	if (!pmic->rdev)
>  		return -ENOMEM;
>  
> -	for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
> -			i++, info++) {
> +	for (i = 0; i < pmic->num_regulators; i++, info++) {
>  		/* Register the regulators */
>  		pmic->info[i] = info;
>  
> 

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

* Re: [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time
  2017-06-13 14:01 ` [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Keerthy
@ 2017-06-13 14:35   ` Michał Mirosław
  0 siblings, 0 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 14:35 UTC (permalink / raw)
  To: Keerthy
  Cc: linux-kernel, Liam Girdwood, Mark Brown, Tony Lindgren, linux-omap

On Tue, Jun 13, 2017 at 07:31:21PM +0530, Keerthy wrote:
> On Tuesday 13 June 2017 07:28 PM, Michał Mirosław wrote:
> 
> Missing commit log?
[...]

Oh, indeed. I'll fix this in a moment.

Best Regards,
Michał Mirosław

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

* [PATCH v2 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time
  2017-06-13 13:58 [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Michał Mirosław
  2017-06-13 13:58 ` [PATCH 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
  2017-06-13 14:01 ` [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Keerthy
@ 2017-06-13 14:41 ` Michał Mirosław
  2017-06-13 14:41   ` [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
  2017-06-13 17:44   ` [PATCH v2 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Mark Brown
  2 siblings, 2 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 14:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tony Lindgren, Liam Girdwood, Mark Brown, j-keerthy, linux-omap

Check TPS65910_NUM_REGS at build time instead of silently registering
not all regulators at runtime.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
v2:
  - added commit message

 drivers/regulator/tps65910-regulator.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 696116ebdf50a..81672a58fcc23 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1107,6 +1107,7 @@ static int tps65910_probe(struct platform_device *pdev)
 
 	switch (tps65910_chip_id(tps65910)) {
 	case TPS65910:
+		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
 		pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
 		pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
 		pmic->ext_sleep_control = tps65910_ext_sleep_control;
@@ -1119,6 +1120,7 @@ static int tps65910_probe(struct platform_device *pdev)
 					DCDCCTRL_DCDCCKSYNC_MASK);
 		break;
 	case TPS65911:
+		BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
 		pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
 		pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
 		pmic->ext_sleep_control = tps65911_ext_sleep_control;
@@ -1144,8 +1146,7 @@ static int tps65910_probe(struct platform_device *pdev)
 	if (!pmic->rdev)
 		return -ENOMEM;
 
-	for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
-			i++, info++) {
+	for (i = 0; i < pmic->num_regulators; i++, info++) {
 		/* Register the regulators */
 		pmic->info[i] = info;
 
-- 
2.11.0

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

* [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 14:41 ` [PATCH v2 " Michał Mirosław
@ 2017-06-13 14:41   ` Michał Mirosław
  2017-06-13 17:46     ` Mark Brown
  2017-06-13 17:44   ` [PATCH v2 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Mark Brown
  1 sibling, 1 reply; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 14:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tony Lindgren, Liam Girdwood, Mark Brown, j-keerthy, linux-omap

This allows for (acyclic) references from tps6591x supplies to
its outputs.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
v2:
  - no changes

 drivers/regulator/tps65910-regulator.c | 39 ++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 81672a58fcc23..f7987168ba4ed 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -1082,7 +1082,8 @@ static int tps65910_probe(struct platform_device *pdev)
 	struct tps65910_reg *pmic;
 	struct tps65910_board *pmic_plat_data;
 	struct of_regulator_match *tps65910_reg_matches = NULL;
-	int i, err;
+	bool made_progress;
+	int i, err, pending;
 
 	pmic_plat_data = dev_get_platdata(tps65910->dev);
 	if (!pmic_plat_data && tps65910->dev->of_node)
@@ -1146,6 +1147,7 @@ static int tps65910_probe(struct platform_device *pdev)
 	if (!pmic->rdev)
 		return -ENOMEM;
 
+	/* prepare regulator description */
 	for (i = 0; i < pmic->num_regulators; i++, info++) {
 		/* Register the regulators */
 		pmic->info[i] = info;
@@ -1196,18 +1198,32 @@ static int tps65910_probe(struct platform_device *pdev)
 		pmic->desc[i].owner = THIS_MODULE;
 		pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
 		pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
+	}
+
+	/* Register regulators - loop, as one regulator's output
+	 * might be anothers input */
+
+	config.dev = pmic->mfd->dev;
+	config.driver_data = pmic;
+	config.regmap = pmic->mfd->regmap;
+	pending = pmic->num_regulators;
+
+reg_retry:
+	made_progress = false;
+	for (i = 0; i < pmic->num_regulators; i++) {
+		if (pmic->rdev[i])
+			continue;
 
-		config.dev = tps65910->dev;
 		config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
-		config.driver_data = pmic;
-		config.regmap = tps65910->regmap;
-
 		if (tps65910_reg_matches)
 			config.of_node = tps65910_reg_matches[i].of_node;
 
 		rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
 					       &config);
 		if (IS_ERR(rdev)) {
+			if (PTR_ERR(rdev) == -EPROBE_DEFER)
+				continue;
+
 			dev_err(tps65910->dev,
 				"failed to register %s regulator\n",
 				pdev->name);
@@ -1216,8 +1232,19 @@ static int tps65910_probe(struct platform_device *pdev)
 
 		/* Save regulator for cleanup */
 		pmic->rdev[i] = rdev;
+
+		made_progress = true;
+		--pending;
 	}
-	return 0;
+
+	/* all done? */
+	if (!pending)
+		return 0;
+
+	if (made_progress)
+		goto reg_retry;
+
+	return -EPROBE_DEFER;
 }
 
 static void tps65910_shutdown(struct platform_device *pdev)
-- 
2.11.0

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

* Re: [PATCH v2 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time
  2017-06-13 14:41 ` [PATCH v2 " Michał Mirosław
  2017-06-13 14:41   ` [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
@ 2017-06-13 17:44   ` Mark Brown
  1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2017-06-13 17:44 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: linux-kernel, Tony Lindgren, Liam Girdwood, j-keerthy, linux-omap

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

On Tue, Jun 13, 2017 at 04:41:56PM +0200, Michał Mirosław wrote:
> Check TPS65910_NUM_REGS at build time instead of silently registering
> not all regulators at runtime.

Please don't send new versions of patches in reply to existing threads,
it makes it hard to figure out what the current versions of things are.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 14:41   ` [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
@ 2017-06-13 17:46     ` Mark Brown
  2017-06-13 20:22       ` Michał Mirosław
  0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2017-06-13 17:46 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: linux-kernel, Tony Lindgren, Liam Girdwood, j-keerthy, linux-omap

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

On Tue, Jun 13, 2017 at 04:41:58PM +0200, Michał Mirosław wrote:

> This allows for (acyclic) references from tps6591x supplies to
> its outputs.

This is clearly not something that should be open coded in individual
drivers, aside from the code duplication it is obviously possible to
have two different chips supplying each other which this wouldn't help
at all.  Is this happening for you with current kernels, we have a few
mechanisms for deferring bindings of supplies which should help here.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 17:46     ` Mark Brown
@ 2017-06-13 20:22       ` Michał Mirosław
  2017-06-13 20:42         ` Mark Brown
  2017-06-14  7:56         ` Javier Martinez Canillas
  0 siblings, 2 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-13 20:22 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel, Tony Lindgren, Liam Girdwood, j-keerthy, linux-omap

On Tue, Jun 13, 2017 at 06:46:28PM +0100, Mark Brown wrote:
> On Tue, Jun 13, 2017 at 04:41:58PM +0200, Michał Mirosław wrote:
> > This allows for (acyclic) references from tps6591x supplies to
> > its outputs.
> This is clearly not something that should be open coded in individual
> drivers, aside from the code duplication it is obviously possible to
> have two different chips supplying each other which this wouldn't help
> at all.  Is this happening for you with current kernels, we have a few
> mechanisms for deferring bindings of supplies which should help here.

What mechanisms would that be? What I observed is that whenever
a regulator's supply is not available but described in device-tree,
the whole device's registration is deferred.

The device-tree I'm working on contains:

pmic: tps65911@2d { 
    compatible = "ti,tps65911"; 
    reg = <0x2d>; 
    ...
    vcc3-supply = <&vio_reg>; // ldo6, ldo7, ldo8
    ...
    regulators {
        vio_reg: vio {
            regulator-min-microvolt = <1800000>;
            regulator-max-microvolt = <1800000>;
            regulator-always-on;
        };
        ...
    }
}

Best Regards,
Michał Mirosław

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

* Re: [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 20:22       ` Michał Mirosław
@ 2017-06-13 20:42         ` Mark Brown
  2017-06-14  7:56         ` Javier Martinez Canillas
  1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2017-06-13 20:42 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: linux-kernel, Tony Lindgren, Liam Girdwood, j-keerthy, linux-omap

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

On Tue, Jun 13, 2017 at 10:22:17PM +0200, Michał Mirosław wrote:
> On Tue, Jun 13, 2017 at 06:46:28PM +0100, Mark Brown wrote:

> > at all.  Is this happening for you with current kernels, we have a few
> > mechanisms for deferring bindings of supplies which should help here.

> What mechanisms would that be? What I observed is that whenever
> a regulator's supply is not available but described in device-tree,
> the whole device's registration is deferred.

Mainly "Don't use regulators as supplies until the parent is bound",
there were some older ones IIRC.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-13 20:22       ` Michał Mirosław
  2017-06-13 20:42         ` Mark Brown
@ 2017-06-14  7:56         ` Javier Martinez Canillas
  2017-06-14 12:14           ` Michał Mirosław
  1 sibling, 1 reply; 12+ messages in thread
From: Javier Martinez Canillas @ 2017-06-14  7:56 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Mark Brown, Linux Kernel, Tony Lindgren, Liam Girdwood, Keerthy,
	linux-omap

Hello Michal,

What kernel version are you using?

It shouldn't be necessary anymore to resolve regulators dependencies
during regulator_register(), now that logic to lookup the parent
supply has been moved to regulator_get() instead.

On Tue, Jun 13, 2017 at 10:22 PM, Michał Mirosław
<mirq-linux@rere.qmqm.pl> wrote:
> On Tue, Jun 13, 2017 at 06:46:28PM +0100, Mark Brown wrote:
>> On Tue, Jun 13, 2017 at 04:41:58PM +0200, Michał Mirosław wrote:
>> > This allows for (acyclic) references from tps6591x supplies to
>> > its outputs.
>> This is clearly not something that should be open coded in individual
>> drivers, aside from the code duplication it is obviously possible to
>> have two different chips supplying each other which this wouldn't help
>> at all.  Is this happening for you with current kernels, we have a few
>> mechanisms for deferring bindings of supplies which should help here.
>
> What mechanisms would that be? What I observed is that whenever

The specific commit that adds the mechanism Mark is referring to is:

commit 6261b06de565baafa590e58a531a1a5522cea0b6
Author: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Date:   Tue Mar 24 18:56:05 2015 -0700

    regulator: Defer lookup of supply to regulator_get

    Instead of resolving regulator supplies during registration move this to
    the time of a consumer retrieving a handle. The benefit is that it's
    possible for one driver to register regulators with internal
    dependencies out of order.

    Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
    Signed-off-by: Mark Brown <broonie@kernel.org>

> a regulator's supply is not available but described in device-tree,

What do you mean by not available? At some point it the parent supply
should be registered with the regulator core and prevent the client
device to defer its probe when calling regulator_get().

Now, if you don't have a client device that calls regulator_get() to
resolve the parent supply but still need the parent supply to be
enabled, this commit does in the core what you attempt to do in your
driver:

commit 5e3ca2b349b1e2c80b060b51bbf2af37448fad85
Author: Javier Martinez Canillas <javier@osg.samsung.com>
Date:   Wed Mar 23 20:59:34 2016 -0300

    regulator: Try to resolve regulators supplies on registration

    Commit 6261b06de565 ("regulator: Defer lookup of supply to regulator_get")
    moved the regulator supplies lookup logic from the regulators registration
    to the regulators get time.

    Unfortunately, that changed the behavior of the regulator core since now a
    parent supply with a child regulator marked as always-on, won't be enabled
    unless a client driver attempts to get the child regulator during boot.

    This patch tries to resolve the parent supply for the already registered
    regulators each time that a new regulator is registered. So the regulators
    that have child regulators marked as always on will be enabled regardless
    if a driver gets the child regulator or not.

    That was the behavior before the mentioned commit, since parent supplies
    were looked up at regulator registration time instead of during child get.

    Since regulator_resolve_supply() checks for rdev->supply, most of the times
    it will be a no-op. Errors aren't checked to keep the possible out of order
    dependencies which was the motivation for the mentioned commit.

    Also, the supply being available will be enforced on regulator get anyways
    in case the resolve fails on regulators registration.

    Fixes: 6261b06de565 ("regulator: Defer lookup of supply to regulator_get")
    Suggested-by: Mark Brown <broonie@kernel.org>
    Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
    Signed-off-by: Mark Brown <broonie@kernel.org>
    Cc: <stable@vger.kernel.org> # 4.1+

> the whole device's registration is deferred.
>
> The device-tree I'm working on contains:
>
> pmic: tps65911@2d {
>     compatible = "ti,tps65911";
>     reg = <0x2d>;
>     ...
>     vcc3-supply = <&vio_reg>; // ldo6, ldo7, ldo8
>     ...
>     regulators {
>         vio_reg: vio {
>             regulator-min-microvolt = <1800000>;
>             regulator-max-microvolt = <1800000>;
>             regulator-always-on;
>         };
>         ...
>     }
> }

I don't see anything wrong with this DTS, it should work....

I did something similar for the max77802 PMIC in
arch/arm/boot/dts/exynos5800-peach-pi.dts, some regulators have as
input supplies regulators from the same PMIC and may not be
necessarily registered in the order to resolve parent supplies on
child registration.

>
> Best Regards,
> Michał Mirosław

Best regards,
Javier

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

* Re: [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip
  2017-06-14  7:56         ` Javier Martinez Canillas
@ 2017-06-14 12:14           ` Michał Mirosław
  0 siblings, 0 replies; 12+ messages in thread
From: Michał Mirosław @ 2017-06-14 12:14 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Mark Brown, Linux Kernel, Tony Lindgren, Liam Girdwood, Keerthy,
	linux-omap

On Wed, Jun 14, 2017 at 09:56:37AM +0200, Javier Martinez Canillas wrote:
> Hello Michal,
> 
> What kernel version are you using?

This was on v4.10 and then v4.11. Both have commits you referred to.
I'll have to recreate the configuration where this patch was needed,
so let's drop it for now.

Best Regards,
Michał Mirosław

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

end of thread, other threads:[~2017-06-14 12:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-13 13:58 [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Michał Mirosław
2017-06-13 13:58 ` [PATCH 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
2017-06-13 14:01 ` [PATCH 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Keerthy
2017-06-13 14:35   ` Michał Mirosław
2017-06-13 14:41 ` [PATCH v2 " Michał Mirosław
2017-06-13 14:41   ` [PATCH v2 2/2] regulator: tps65910: Allow supply references to the same chip Michał Mirosław
2017-06-13 17:46     ` Mark Brown
2017-06-13 20:22       ` Michał Mirosław
2017-06-13 20:42         ` Mark Brown
2017-06-14  7:56         ` Javier Martinez Canillas
2017-06-14 12:14           ` Michał Mirosław
2017-06-13 17:44   ` [PATCH v2 1/2] regulator: tps65910: check TPS65910_NUM_REGS at build time Mark Brown

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).