Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d326aa36 authored by Quentin Perret's avatar Quentin Perret
Browse files

ANDROID: PM / OPP: cpufreq-dt: Move power estimation function



The cpufreq-dt driver has a function estimating the power of CPUs using
the dynamic-power-coefficient DT binding and the parameters of PM_OPP.
Since this function can be useful to other drivers, relocate it to
PM_OPP which is already a dependency anyway.

Change-Id: I34f8f9cd9433c622c82f23f32ae9968a096a4390
Signed-off-by: default avatarQuentin Perret <quentin.perret@arm.com>
parent 23977789
Loading
Loading
Loading
Loading
+1 −42
Original line number Diff line number Diff line
@@ -150,50 +150,9 @@ static int resources_available(void)
	return 0;
}

static int __maybe_unused of_est_power(unsigned long *mW, unsigned long *KHz,
				       int cpu)
{
	unsigned long mV, Hz, MHz;
	struct device *cpu_dev;
	struct dev_pm_opp *opp;
	struct device_node *np;
	u32 cap;
	u64 tmp;

	cpu_dev = get_cpu_device(cpu);
	if (!cpu_dev)
		return -ENODEV;

	np = of_node_get(cpu_dev->of_node);
	if (!np)
		return -EINVAL;

	if (of_property_read_u32(np, "dynamic-power-coefficient", &cap))
		return -EINVAL;

	Hz = *KHz * 1000;
	opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);
	if (IS_ERR(opp))
		return -EINVAL;

	mV = dev_pm_opp_get_voltage(opp) / 1000;
	dev_pm_opp_put(opp);
	if (!mV)
		return -EINVAL;

	MHz = Hz / 1000000;
	tmp = (u64)cap * mV * mV * MHz;
	do_div(tmp, 1000000000);

	*mW = (unsigned long)tmp;
	*KHz = Hz / 1000;

	return 0;
}

static int cpufreq_init(struct cpufreq_policy *policy)
{
	struct em_data_callback em_cb = EM_DATA_CB(of_est_power);
	struct em_data_callback em_cb = EM_DATA_CB(of_dev_pm_opp_get_cpu_power);
	struct cpufreq_frequency_table *freq_table;
	struct opp_table *opp_table = NULL;
	struct private_data *priv;
+41 −0
Original line number Diff line number Diff line
@@ -777,3 +777,44 @@ struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
	return of_node_get(opp->np);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);

int of_dev_pm_opp_get_cpu_power(unsigned long *mW, unsigned long *KHz, int cpu)
{
	unsigned long mV, Hz, MHz;
	struct device *cpu_dev;
	struct dev_pm_opp *opp;
	struct device_node *np;
	u32 cap;
	u64 tmp;

	cpu_dev = get_cpu_device(cpu);
	if (!cpu_dev)
		return -ENODEV;

	np = of_node_get(cpu_dev->of_node);
	if (!np)
		return -EINVAL;

	if (of_property_read_u32(np, "dynamic-power-coefficient", &cap))
		return -EINVAL;

	Hz = *KHz * 1000;
	opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);
	if (IS_ERR(opp))
		return -EINVAL;

	mV = dev_pm_opp_get_voltage(opp) / 1000;
	dev_pm_opp_put(opp);
	if (!mV)
		return -EINVAL;

	MHz = Hz / 1000000;
	tmp = (u64)cap * mV * mV * MHz;
	do_div(tmp, 1000000000);

	*mW = (unsigned long)tmp;
	*KHz = Hz / 1000;

	return 0;
}
EXPORT_SYMBOL_GPL(of_dev_pm_opp_get_cpu_power);
+5 −0
Original line number Diff line number Diff line
@@ -301,6 +301,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpuma
struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np);
struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
int of_dev_pm_opp_get_cpu_power(unsigned long *mW, unsigned long *KHz, int cpu);
#else
static inline int dev_pm_opp_of_add_table(struct device *dev)
{
@@ -343,6 +344,10 @@ static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
{
	return NULL;
}
static inline int of_dev_pm_opp_get_cpu_power(unsigned long *mW, unsigned long *KHz, int cpu)
{
	return -ENOTSUPP;
}
#endif

#endif		/* __LINUX_OPP_H__ */