Skip to content

Commit 2eedf62

Browse files
chadmedvireshk
authored andcommitted
OPP: decouple dt properties in opp_parse_supplies()
The opp-microwatt property was added with the intention of providing platforms a way to specify a precise value for the power consumption of a device at a given OPP to enable better energy-aware scheduling decisions by informing the kernel of the total static and dynamic power of a device at a given OPP, removing the reliance on the EM subsystem's often flawed estimations. This property is parsed by opp_parse_supplies(), which creates a hard dependency on the opp-microvolt property. Some platforms, such as Apple Silicon, do not describe their device's voltage regulators in the DT as they cannot be controlled by the kernel and/or rely on opaque firmware algorithms to control their voltage and current characteristics at runtime. We can, however, experimentally determine the power consumption of a given device at a given OPP, taking advantage of opp-microwatt to provide EAS on such devices as was initially intended. Allow platforms to specify and consume any subset of opp-microvolt, opp-microamp, or opp-microwatt without a hard dependency on opp-microvolt to enable this functionality on such platforms. Tested-by: James Calligeros <jcalligeros99@gmail.com> Signed-off-by: James Calligeros <jcalligeros99@gmail.com> Co-developed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent e5acb19 commit 2eedf62

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

drivers/opp/of.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,12 @@ static u32 *opp_parse_microvolt(struct dev_pm_opp *opp, struct device *dev,
654654
/*
655655
* Missing property isn't a problem, but an invalid
656656
* entry is. This property isn't optional if regulator
657-
* information is provided.
657+
* information is provided. Check only for the first OPP, as
658+
* regulator_count may get initialized after that to a valid
659+
* value.
658660
*/
659-
if (opp_table->regulator_count > 0) {
661+
if (list_empty(&opp_table->opp_list) &&
662+
opp_table->regulator_count > 0) {
660663
dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n",
661664
__func__);
662665
return ERR_PTR(-EINVAL);
@@ -674,7 +677,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
674677
bool triplet;
675678

676679
microvolt = opp_parse_microvolt(opp, dev, opp_table, &triplet);
677-
if (IS_ERR_OR_NULL(microvolt))
680+
if (IS_ERR(microvolt))
678681
return PTR_ERR(microvolt);
679682

680683
microamp = _parse_named_prop(opp, dev, opp_table, "microamp", NULL);
@@ -689,15 +692,26 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
689692
goto free_microamp;
690693
}
691694

692-
for (i = 0, j = 0; i < opp_table->regulator_count; i++) {
693-
opp->supplies[i].u_volt = microvolt[j++];
695+
/*
696+
* Initialize regulator_count if it is uninitialized and no properties
697+
* are found.
698+
*/
699+
if (unlikely(opp_table->regulator_count == -1)) {
700+
opp_table->regulator_count = 0;
701+
return 0;
702+
}
694703

695-
if (triplet) {
696-
opp->supplies[i].u_volt_min = microvolt[j++];
697-
opp->supplies[i].u_volt_max = microvolt[j++];
698-
} else {
699-
opp->supplies[i].u_volt_min = opp->supplies[i].u_volt;
700-
opp->supplies[i].u_volt_max = opp->supplies[i].u_volt;
704+
for (i = 0, j = 0; i < opp_table->regulator_count; i++) {
705+
if (microvolt) {
706+
opp->supplies[i].u_volt = microvolt[j++];
707+
708+
if (triplet) {
709+
opp->supplies[i].u_volt_min = microvolt[j++];
710+
opp->supplies[i].u_volt_max = microvolt[j++];
711+
} else {
712+
opp->supplies[i].u_volt_min = opp->supplies[i].u_volt;
713+
opp->supplies[i].u_volt_max = opp->supplies[i].u_volt;
714+
}
701715
}
702716

703717
if (microamp)

0 commit comments

Comments
 (0)