Skip to content

Commit 8d45719

Browse files
Kamil Koniecznyvireshk
authored andcommitted
opp: core: add regulators enable and disable
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. Tested-by: Marek Szyprowski <[email protected]> Acked-by: Clément Péron <[email protected]> Tested-by: Clément Péron <[email protected]> Signed-off-by: Kamil Konieczny <[email protected]> [ Viresh: Enable the regulator only after it is programmed and add a flag to track its status. ] Signed-off-by: Viresh Kumar <[email protected]>
1 parent b23dfa3 commit 8d45719

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

drivers/opp/core.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
664664
return ret;
665665
}
666666

667-
static int _generic_set_opp_regulator(const struct opp_table *opp_table,
667+
static int _generic_set_opp_regulator(struct opp_table *opp_table,
668668
struct device *dev,
669669
unsigned long old_freq,
670670
unsigned long freq,
@@ -699,6 +699,18 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table,
699699
goto restore_freq;
700700
}
701701

702+
/*
703+
* Enable the regulator after setting its voltages, otherwise it breaks
704+
* some boot-enabled regulators.
705+
*/
706+
if (unlikely(!opp_table->regulator_enabled)) {
707+
ret = regulator_enable(reg);
708+
if (ret < 0)
709+
dev_warn(dev, "Failed to enable regulator: %d", ret);
710+
else
711+
opp_table->regulator_enabled = true;
712+
}
713+
702714
return 0;
703715

704716
restore_freq:
@@ -825,12 +837,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
825837
if (!_get_opp_count(opp_table))
826838
return 0;
827839

828-
if (!opp_table->required_opp_tables) {
840+
if (!opp_table->required_opp_tables && !opp_table->regulators) {
829841
dev_err(dev, "target frequency can't be 0\n");
830842
ret = -EINVAL;
831843
goto put_opp_table;
832844
}
833845

846+
if (opp_table->regulator_enabled) {
847+
regulator_disable(opp_table->regulators[0]);
848+
opp_table->regulator_enabled = false;
849+
}
850+
834851
ret = _set_required_opps(dev, opp_table, NULL);
835852
goto put_opp_table;
836853
}
@@ -1718,6 +1735,13 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
17181735
/* Make sure there are no concurrent readers while updating opp_table */
17191736
WARN_ON(!list_empty(&opp_table->opp_list));
17201737

1738+
if (opp_table->regulator_enabled) {
1739+
for (i = opp_table->regulator_count - 1; i >= 0; i--)
1740+
regulator_disable(opp_table->regulators[i]);
1741+
1742+
opp_table->regulator_enabled = false;
1743+
}
1744+
17211745
for (i = opp_table->regulator_count - 1; i >= 0; i--)
17221746
regulator_put(opp_table->regulators[i]);
17231747

drivers/opp/opp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ enum opp_table_access {
147147
* @clk: Device's clock handle
148148
* @regulators: Supply regulators
149149
* @regulator_count: Number of power supply regulators. Its value can be -1
150+
* @regulator_enabled: Set to true if regulators were previously enabled.
150151
* (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt
151152
* property).
152153
* @paths: Interconnect path handles
@@ -194,6 +195,7 @@ struct opp_table {
194195
struct clk *clk;
195196
struct regulator **regulators;
196197
int regulator_count;
198+
bool regulator_enabled;
197199
struct icc_path **paths;
198200
unsigned int path_count;
199201
bool genpd_performance_state;

0 commit comments

Comments
 (0)