Linux-PM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] opp: core: add regulators enable and disable
@ 2020-05-15  7:57 ` Viresh Kumar
  2020-05-15  7:57   ` [PATCH 1/2] opp: Reorder the code for !target_freq case Viresh Kumar
                     ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Viresh Kumar @ 2020-05-15  7:57 UTC (permalink / raw)
  To: k.konieczny, peron.clem, m.szyprowski, Nishanth Menon,
	Stephen Boyd, Viresh Kumar
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael Wysocki, broonie,
	linux-kernel

Hi,

This series reintroduces the usage of regulator_enable/disable() to the
OPP core after the previous attempt was reverted [1] shortly after getting
applied. This time the regulator is enabled only after it is configured
by the OPP core.

Marek, Kamil and Clément: Can you guys please test this out and report
if this doesn't work as expected ?

--
viresh

[1] https://lore.kernel.org/lkml/20191017102758.8104-1-m.szyprowski@samsung.com/

Kamil Konieczny (1):
  opp: core: add regulators enable and disable

Viresh Kumar (1):
  opp: Reorder the code for !target_freq case

 drivers/opp/core.c | 39 ++++++++++++++++++++++++++++++++++-----
 drivers/opp/opp.h  |  2 ++
 2 files changed, 36 insertions(+), 5 deletions(-)

-- 
2.25.0.rc1.19.g042ed3e048af


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

* [PATCH 1/2] opp: Reorder the code for !target_freq case
  2020-05-15  7:57 ` [PATCH 0/2] opp: core: add regulators enable and disable Viresh Kumar
@ 2020-05-15  7:57   ` Viresh Kumar
  2020-05-15  7:57   ` [PATCH 2/2] opp: core: add regulators enable and disable Viresh Kumar
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Viresh Kumar @ 2020-05-15  7:57 UTC (permalink / raw)
  To: k.konieczny, peron.clem, m.szyprowski, Viresh Kumar,
	Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael Wysocki, broonie,
	linux-kernel

Reorder the code a bit to make it more readable. Add additional comment
as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index e4f01e7771a2..dda8164fad56 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -817,15 +817,20 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	}
 
 	if (unlikely(!target_freq)) {
-		if (opp_table->required_opp_tables) {
-			ret = _set_required_opps(dev, opp_table, NULL);
-		} else if (!_get_opp_count(opp_table)) {
+		/*
+		 * Some drivers need to support cases where some platforms may
+		 * have OPP table for the device, while others don't and
+		 * opp_set_rate() just needs to behave like clk_set_rate().
+		 */
+		if (!_get_opp_count(opp_table))
 			return 0;
-		} else {
+
+		if (!opp_table->required_opp_tables) {
 			dev_err(dev, "target frequency can't be 0\n");
 			ret = -EINVAL;
 		}
 
+		ret = _set_required_opps(dev, opp_table, NULL);
 		goto put_opp_table;
 	}
 
-- 
2.25.0.rc1.19.g042ed3e048af


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

* [PATCH 2/2] opp: core: add regulators enable and disable
  2020-05-15  7:57 ` [PATCH 0/2] opp: core: add regulators enable and disable Viresh Kumar
  2020-05-15  7:57   ` [PATCH 1/2] opp: Reorder the code for !target_freq case Viresh Kumar
@ 2020-05-15  7:57   ` Viresh Kumar
  2020-05-15  9:16   ` [PATCH 0/2] " Marek Szyprowski
  2020-05-15 12:00   ` Clément Péron
  3 siblings, 0 replies; 6+ messages in thread
From: Viresh Kumar @ 2020-05-15  7:57 UTC (permalink / raw)
  To: k.konieczny, peron.clem, m.szyprowski, Viresh Kumar,
	Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael Wysocki, broonie,
	linux-kernel

From: Kamil Konieczny <k.konieczny@samsung.com>

Add enable regulators to dev_pm_opp_set_regulators() and disable
regulators to dev_pm_opp_put_regulators(). Even if bootloader
leaves regulators enabled, they should be enabled in kernel in
order to increase the reference count.

Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com>
[ Viresh: Enable the regulator only after it is programmed and add a
	  flag to track its status. ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c | 28 ++++++++++++++++++++++++++--
 drivers/opp/opp.h  |  2 ++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index dda8164fad56..da6533d5526f 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -664,7 +664,7 @@ static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
 	return ret;
 }
 
-static int _generic_set_opp_regulator(const struct opp_table *opp_table,
+static int _generic_set_opp_regulator(struct opp_table *opp_table,
 				      struct device *dev,
 				      unsigned long old_freq,
 				      unsigned long freq,
@@ -699,6 +699,18 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table,
 			goto restore_freq;
 	}
 
+	/*
+	 * Enable the regulator after setting its voltages, otherwise it breaks
+	 * some boot-enabled regulators.
+	 */
+	if (unlikely(!opp_table->regulator_enabled)) {
+		ret = regulator_enable(reg);
+		if (ret < 0)
+			dev_warn(dev, "Failed to enable regulator: %d", ret);
+		else
+			opp_table->regulator_enabled = true;
+	}
+
 	return 0;
 
 restore_freq:
@@ -825,11 +837,16 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 		if (!_get_opp_count(opp_table))
 			return 0;
 
-		if (!opp_table->required_opp_tables) {
+		if (!opp_table->required_opp_tables && !opp_table->regulators) {
 			dev_err(dev, "target frequency can't be 0\n");
 			ret = -EINVAL;
 		}
 
+		if (opp_table->regulator_enabled) {
+			regulator_disable(opp_table->regulators[0]);
+			opp_table->regulator_enabled = false;
+		}
+
 		ret = _set_required_opps(dev, opp_table, NULL);
 		goto put_opp_table;
 	}
@@ -1675,6 +1692,13 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
 	/* Make sure there are no concurrent readers while updating opp_table */
 	WARN_ON(!list_empty(&opp_table->opp_list));
 
+	if (opp_table->regulator_enabled) {
+		for (i = opp_table->regulator_count - 1; i >= 0; i--)
+			regulator_disable(opp_table->regulators[i]);
+
+		opp_table->regulator_enabled = false;
+	}
+
 	for (i = opp_table->regulator_count - 1; i >= 0; i--)
 		regulator_put(opp_table->regulators[i]);
 
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index d14e27102730..b4b2713d84f1 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -144,6 +144,7 @@ enum opp_table_access {
  * @clk: Device's clock handle
  * @regulators: Supply regulators
  * @regulator_count: Number of power supply regulators. Its value can be -1
+ * @regulator_enabled: Set to true if regulators were previously enabled.
  * (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt
  * property).
  * @genpd_performance_state: Device's power domain support performance state.
@@ -189,6 +190,7 @@ struct opp_table {
 	struct clk *clk;
 	struct regulator **regulators;
 	int regulator_count;
+	bool regulator_enabled;
 	bool genpd_performance_state;
 	bool is_genpd;
 
-- 
2.25.0.rc1.19.g042ed3e048af


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

* Re: [PATCH 0/2] opp: core: add regulators enable and disable
  2020-05-15  7:57 ` [PATCH 0/2] opp: core: add regulators enable and disable Viresh Kumar
  2020-05-15  7:57   ` [PATCH 1/2] opp: Reorder the code for !target_freq case Viresh Kumar
  2020-05-15  7:57   ` [PATCH 2/2] opp: core: add regulators enable and disable Viresh Kumar
@ 2020-05-15  9:16   ` Marek Szyprowski
  2020-05-15 12:00   ` Clément Péron
  3 siblings, 0 replies; 6+ messages in thread
From: Marek Szyprowski @ 2020-05-15  9:16 UTC (permalink / raw)
  To: Viresh Kumar, k.konieczny, peron.clem, Nishanth Menon,
	Stephen Boyd, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, broonie, linux-kernel

Hi Viresh,

On 15.05.2020 09:57, Viresh Kumar wrote:
> This series reintroduces the usage of regulator_enable/disable() to the
> OPP core after the previous attempt was reverted [1] shortly after getting
> applied. This time the regulator is enabled only after it is configured
> by the OPP core.
>
> Marek, Kamil and Clément: Can you guys please test this out and report
> if this doesn't work as expected ?

Works fine for my test cases, especially Samsung Chromebook Peach-Pit/Pi 
still boots fine. Feel free to add to the both patches:

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

Thanks!

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

* Re: [PATCH 0/2] opp: core: add regulators enable and disable
  2020-05-15  7:57 ` [PATCH 0/2] opp: core: add regulators enable and disable Viresh Kumar
                     ` (2 preceding siblings ...)
  2020-05-15  9:16   ` [PATCH 0/2] " Marek Szyprowski
@ 2020-05-15 12:00   ` Clément Péron
  2020-05-21 12:23     ` Clément Péron
  3 siblings, 1 reply; 6+ messages in thread
From: Clément Péron @ 2020-05-15 12:00 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: k.konieczny, Marek Szyprowski, Nishanth Menon, Stephen Boyd,
	Viresh Kumar, open list:ALLWINNER CPUFREQ DRIVER,
	Vincent Guittot, Rafael Wysocki, Mark Brown, linux-kernel

Hi Viresh,

On Fri, 15 May 2020 at 09:57, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> Hi,
>
> This series reintroduces the usage of regulator_enable/disable() to the
> OPP core after the previous attempt was reverted [1] shortly after getting
> applied. This time the regulator is enabled only after it is configured
> by the OPP core.
>
> Marek, Kamil and Clément: Can you guys please test this out and report
> if this doesn't work as expected ?

I have reviewed the patch and it seems fine for my use case.
Unfortunately I can't test it until next week.

Acked-by: Clément Péron <peron.clem@gmail.com>

Regards,
Clement


>
> --
> viresh
>
> [1] https://lore.kernel.org/lkml/20191017102758.8104-1-m.szyprowski@samsung.com/
>
> Kamil Konieczny (1):
>   opp: core: add regulators enable and disable
>
> Viresh Kumar (1):
>   opp: Reorder the code for !target_freq case
>
>  drivers/opp/core.c | 39 ++++++++++++++++++++++++++++++++++-----
>  drivers/opp/opp.h  |  2 ++
>  2 files changed, 36 insertions(+), 5 deletions(-)
>
> --
> 2.25.0.rc1.19.g042ed3e048af
>

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

* Re: [PATCH 0/2] opp: core: add regulators enable and disable
  2020-05-15 12:00   ` Clément Péron
@ 2020-05-21 12:23     ` Clément Péron
  0 siblings, 0 replies; 6+ messages in thread
From: Clément Péron @ 2020-05-21 12:23 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: k.konieczny, Marek Szyprowski, Nishanth Menon, Stephen Boyd,
	Viresh Kumar, open list:ALLWINNER CPUFREQ DRIVER,
	Vincent Guittot, Rafael Wysocki, Mark Brown, linux-kernel

Hi,

On Fri, 15 May 2020 at 14:00, Clément Péron <peron.clem@gmail.com> wrote:
>
> Hi Viresh,
>
> On Fri, 15 May 2020 at 09:57, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > Hi,
> >
> > This series reintroduces the usage of regulator_enable/disable() to the
> > OPP core after the previous attempt was reverted [1] shortly after getting
> > applied. This time the regulator is enabled only after it is configured
> > by the OPP core.
> >
> > Marek, Kamil and Clément: Can you guys please test this out and report
> > if this doesn't work as expected ?
>
> I have reviewed the patch and it seems fine for my use case.
> Unfortunately I can't test it until next week.

Ok, before the patch the regulator was released by regulator_late_cleanup() :
[   33.756849] vdd-gpu: disabling

Now it works fine and the vdd-gpu is no more disabled.

Tested-by: Clément Péron <peron.clem@gmail.com>

Regards,
Clement

>
> Acked-by: Clément Péron <peron.clem@gmail.com>
>
> Regards,
> Clement
>
>
> >
> > --
> > viresh
> >
> > [1] https://lore.kernel.org/lkml/20191017102758.8104-1-m.szyprowski@samsung.com/
> >
> > Kamil Konieczny (1):
> >   opp: core: add regulators enable and disable
> >
> > Viresh Kumar (1):
> >   opp: Reorder the code for !target_freq case
> >
> >  drivers/opp/core.c | 39 ++++++++++++++++++++++++++++++++++-----
> >  drivers/opp/opp.h  |  2 ++
> >  2 files changed, 36 insertions(+), 5 deletions(-)
> >
> > --
> > 2.25.0.rc1.19.g042ed3e048af
> >

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200515075745eucas1p2f14c7fcec7c3d190704ddc6f608b6ce9@eucas1p2.samsung.com>
2020-05-15  7:57 ` [PATCH 0/2] opp: core: add regulators enable and disable Viresh Kumar
2020-05-15  7:57   ` [PATCH 1/2] opp: Reorder the code for !target_freq case Viresh Kumar
2020-05-15  7:57   ` [PATCH 2/2] opp: core: add regulators enable and disable Viresh Kumar
2020-05-15  9:16   ` [PATCH 0/2] " Marek Szyprowski
2020-05-15 12:00   ` Clément Péron
2020-05-21 12:23     ` Clément Péron

Linux-PM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pm/0 linux-pm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pm linux-pm/ https://lore.kernel.org/linux-pm \
		linux-pm@vger.kernel.org
	public-inbox-index linux-pm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git