Skip to content

Commit e3ac0f3

Browse files
lukaszluba-armrafaeljw
authored andcommitted
OPP: OF: Export dev_opp_pm_calc_power() for usage from EM
There are device drivers which can modify voltage values for OPPs. It could be due to the chip binning and those drivers have specific chip knowledge about it. This adjustment can happen after Energy Model is registered, thus EM can have stale data about power. Export dev_opp_pm_calc_power() which can be used by Energy Model to calculate new power with the new voltage for OPPs. Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent fec50db commit e3ac0f3

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

drivers/opp/of.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,20 +1494,26 @@ _get_dt_power(struct device *dev, unsigned long *uW, unsigned long *kHz)
14941494
return 0;
14951495
}
14961496

1497-
/*
1498-
* Callback function provided to the Energy Model framework upon registration.
1497+
/**
1498+
* dev_pm_opp_calc_power() - Calculate power value for device with EM
1499+
* @dev : Device for which an Energy Model has to be registered
1500+
* @uW : New power value that is calculated
1501+
* @kHz : Frequency for which the new power is calculated
1502+
*
14991503
* This computes the power estimated by @dev at @kHz if it is the frequency
15001504
* of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
15011505
* (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled
15021506
* frequency and @uW to the associated power. The power is estimated as
15031507
* P = C * V^2 * f with C being the device's capacitance and V and f
15041508
* respectively the voltage and frequency of the OPP.
1509+
* It is also used as a callback function provided to the Energy Model
1510+
* framework upon registration.
15051511
*
15061512
* Returns -EINVAL if the power calculation failed because of missing
15071513
* parameters, 0 otherwise.
15081514
*/
1509-
static int __maybe_unused _get_power(struct device *dev, unsigned long *uW,
1510-
unsigned long *kHz)
1515+
int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
1516+
unsigned long *kHz)
15111517
{
15121518
struct dev_pm_opp *opp;
15131519
struct device_node *np;
@@ -1544,6 +1550,7 @@ static int __maybe_unused _get_power(struct device *dev, unsigned long *uW,
15441550

15451551
return 0;
15461552
}
1553+
EXPORT_SYMBOL_GPL(dev_pm_opp_calc_power);
15471554

15481555
static bool _of_has_opp_microwatt_property(struct device *dev)
15491556
{
@@ -1619,7 +1626,7 @@ int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus)
16191626
goto failed;
16201627
}
16211628

1622-
EM_SET_ACTIVE_POWER_CB(em_cb, _get_power);
1629+
EM_SET_ACTIVE_POWER_CB(em_cb, dev_pm_opp_calc_power);
16231630

16241631
register_em:
16251632
ret = em_dev_register_perf_domain(dev, nr_opp, &em_cb, cpus, true);

include/linux/pm_opp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
476476
int of_get_required_opp_performance_state(struct device_node *np, int index);
477477
int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
478478
int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
479+
int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
480+
unsigned long *kHz);
479481
static inline void dev_pm_opp_of_unregister_em(struct device *dev)
480482
{
481483
em_dev_unregister_perf_domain(dev);
@@ -539,6 +541,12 @@ static inline void dev_pm_opp_of_unregister_em(struct device *dev)
539541
{
540542
}
541543

544+
static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
545+
unsigned long *kHz)
546+
{
547+
return -EOPNOTSUPP;
548+
}
549+
542550
static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
543551
{
544552
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)