Commit 1dea432a authored by Viresh Kumar's avatar Viresh Kumar Committed by Eduardo Valentin

thermal: cpu_cooling: Name cpufreq cooling devices as cpufreq_cdev

Objects of "struct cpufreq_cooling_device" are named a bit
inconsistently. Lets use cpufreq_cdev everywhere. Also note that the
lists containing such devices is renamed similarly too.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: default avatarLukasz Luba <lukasz.luba@arm.com>
Tested-by: default avatarLukasz Luba <lukasz.luba@arm.com>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent fb8ea308
...@@ -108,27 +108,27 @@ struct cpufreq_cooling_device { ...@@ -108,27 +108,27 @@ struct cpufreq_cooling_device {
static DEFINE_IDA(cpufreq_ida); static DEFINE_IDA(cpufreq_ida);
static DEFINE_MUTEX(cooling_list_lock); static DEFINE_MUTEX(cooling_list_lock);
static LIST_HEAD(cpufreq_dev_list); static LIST_HEAD(cpufreq_cdev_list);
/* Below code defines functions to be used for cpufreq as cooling device */ /* Below code defines functions to be used for cpufreq as cooling device */
/** /**
* get_level: Find the level for a particular frequency * get_level: Find the level for a particular frequency
* @cpufreq_dev: cpufreq_dev for which the property is required * @cpufreq_cdev: cpufreq_cdev for which the property is required
* @freq: Frequency * @freq: Frequency
* *
* Return: level on success, THERMAL_CSTATE_INVALID on error. * Return: level on success, THERMAL_CSTATE_INVALID on error.
*/ */
static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev,
unsigned int freq) unsigned int freq)
{ {
unsigned long level; unsigned long level;
for (level = 0; level <= cpufreq_dev->max_level; level++) { for (level = 0; level <= cpufreq_cdev->max_level; level++) {
if (freq == cpufreq_dev->freq_table[level]) if (freq == cpufreq_cdev->freq_table[level])
return level; return level;
if (freq > cpufreq_dev->freq_table[level]) if (freq > cpufreq_cdev->freq_table[level])
break; break;
} }
...@@ -148,12 +148,12 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, ...@@ -148,12 +148,12 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev,
*/ */
unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
{ {
struct cpufreq_cooling_device *cpufreq_dev; struct cpufreq_cooling_device *cpufreq_cdev;
mutex_lock(&cooling_list_lock); mutex_lock(&cooling_list_lock);
list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) {
if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { if (cpumask_test_cpu(cpu, &cpufreq_cdev->allowed_cpus)) {
unsigned long level = get_level(cpufreq_dev, freq); unsigned long level = get_level(cpufreq_cdev, freq);
mutex_unlock(&cooling_list_lock); mutex_unlock(&cooling_list_lock);
return level; return level;
...@@ -183,14 +183,14 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, ...@@ -183,14 +183,14 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
{ {
struct cpufreq_policy *policy = data; struct cpufreq_policy *policy = data;
unsigned long clipped_freq; unsigned long clipped_freq;
struct cpufreq_cooling_device *cpufreq_dev; struct cpufreq_cooling_device *cpufreq_cdev;
if (event != CPUFREQ_ADJUST) if (event != CPUFREQ_ADJUST)
return NOTIFY_DONE; return NOTIFY_DONE;
mutex_lock(&cooling_list_lock); mutex_lock(&cooling_list_lock);
list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) {
if (!cpumask_test_cpu(policy->cpu, &cpufreq_dev->allowed_cpus)) if (!cpumask_test_cpu(policy->cpu, &cpufreq_cdev->allowed_cpus))
continue; continue;
/* /*
...@@ -204,7 +204,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, ...@@ -204,7 +204,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
* But, if clipped_freq is greater than policy->max, we don't * But, if clipped_freq is greater than policy->max, we don't
* need to do anything. * need to do anything.
*/ */
clipped_freq = cpufreq_dev->clipped_freq; clipped_freq = cpufreq_cdev->clipped_freq;
if (policy->max > clipped_freq) if (policy->max > clipped_freq)
cpufreq_verify_within_limits(policy, 0, clipped_freq); cpufreq_verify_within_limits(policy, 0, clipped_freq);
...@@ -217,11 +217,11 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, ...@@ -217,11 +217,11 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
/** /**
* build_dyn_power_table() - create a dynamic power to frequency table * build_dyn_power_table() - create a dynamic power to frequency table
* @cpufreq_device: the cpufreq cooling device in which to store the table * @cpufreq_cdev: the cpufreq cooling device in which to store the table
* @capacitance: dynamic power coefficient for these cpus * @capacitance: dynamic power coefficient for these cpus
* *
* Build a dynamic power to frequency table for this cpu and store it * Build a dynamic power to frequency table for this cpu and store it
* in @cpufreq_device. This table will be used in cpu_power_to_freq() and * in @cpufreq_cdev. This table will be used in cpu_power_to_freq() and
* cpu_freq_to_power() to convert between power and frequency * cpu_freq_to_power() to convert between power and frequency
* efficiently. Power is stored in mW, frequency in KHz. The * efficiently. Power is stored in mW, frequency in KHz. The
* resulting table is in ascending order. * resulting table is in ascending order.
...@@ -230,7 +230,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, ...@@ -230,7 +230,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
* -ENOMEM if we run out of memory or -EAGAIN if an OPP was * -ENOMEM if we run out of memory or -EAGAIN if an OPP was
* added/enabled while the function was executing. * added/enabled while the function was executing.
*/ */
static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev,
u32 capacitance) u32 capacitance)
{ {
struct power_table *power_table; struct power_table *power_table;
...@@ -239,10 +239,10 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, ...@@ -239,10 +239,10 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device,
int num_opps = 0, cpu, i, ret = 0; int num_opps = 0, cpu, i, ret = 0;
unsigned long freq; unsigned long freq;
for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) {
dev = get_cpu_device(cpu); dev = get_cpu_device(cpu);
if (!dev) { if (!dev) {
dev_warn(&cpufreq_device->cool_dev->device, dev_warn(&cpufreq_cdev->cool_dev->device,
"No cpu device for cpu %d\n", cpu); "No cpu device for cpu %d\n", cpu);
continue; continue;
} }
...@@ -295,9 +295,9 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, ...@@ -295,9 +295,9 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device,
goto free_power_table; goto free_power_table;
} }
cpufreq_device->cpu_dev = dev; cpufreq_cdev->cpu_dev = dev;
cpufreq_device->dyn_power_table = power_table; cpufreq_cdev->dyn_power_table = power_table;
cpufreq_device->dyn_power_table_entries = i; cpufreq_cdev->dyn_power_table_entries = i;
return 0; return 0;
...@@ -307,26 +307,26 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, ...@@ -307,26 +307,26 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device,
return ret; return ret;
} }
static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_device, static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev,
u32 freq) u32 freq)
{ {
int i; int i;
struct power_table *pt = cpufreq_device->dyn_power_table; struct power_table *pt = cpufreq_cdev->dyn_power_table;
for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++)
if (freq < pt[i].frequency) if (freq < pt[i].frequency)
break; break;
return pt[i - 1].power; return pt[i - 1].power;
} }
static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device, static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev,
u32 power) u32 power)
{ {
int i; int i;
struct power_table *pt = cpufreq_device->dyn_power_table; struct power_table *pt = cpufreq_cdev->dyn_power_table;
for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) for (i = 1; i < cpufreq_cdev->dyn_power_table_entries; i++)
if (power < pt[i].power) if (power < pt[i].power)
break; break;
...@@ -335,37 +335,37 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device, ...@@ -335,37 +335,37 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device,
/** /**
* get_load() - get load for a cpu since last updated * get_load() - get load for a cpu since last updated
* @cpufreq_device: &struct cpufreq_cooling_device for this cpu * @cpufreq_cdev: &struct cpufreq_cooling_device for this cpu
* @cpu: cpu number * @cpu: cpu number
* @cpu_idx: index of the cpu in cpufreq_device->allowed_cpus * @cpu_idx: index of the cpu in cpufreq_cdev->allowed_cpus
* *
* Return: The average load of cpu @cpu in percentage since this * Return: The average load of cpu @cpu in percentage since this
* function was last called. * function was last called.
*/ */
static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu, static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu,
int cpu_idx) int cpu_idx)
{ {
u32 load; u32 load;
u64 now, now_idle, delta_time, delta_idle; u64 now, now_idle, delta_time, delta_idle;
now_idle = get_cpu_idle_time(cpu, &now, 0); now_idle = get_cpu_idle_time(cpu, &now, 0);
delta_idle = now_idle - cpufreq_device->time_in_idle[cpu_idx]; delta_idle = now_idle - cpufreq_cdev->time_in_idle[cpu_idx];
delta_time = now - cpufreq_device->time_in_idle_timestamp[cpu_idx]; delta_time = now - cpufreq_cdev->time_in_idle_timestamp[cpu_idx];
if (delta_time <= delta_idle) if (delta_time <= delta_idle)
load = 0; load = 0;
else else
load = div64_u64(100 * (delta_time - delta_idle), delta_time); load = div64_u64(100 * (delta_time - delta_idle), delta_time);
cpufreq_device->time_in_idle[cpu_idx] = now_idle; cpufreq_cdev->time_in_idle[cpu_idx] = now_idle;
cpufreq_device->time_in_idle_timestamp[cpu_idx] = now; cpufreq_cdev->time_in_idle_timestamp[cpu_idx] = now;
return load; return load;
} }
/** /**
* get_static_power() - calculate the static power consumed by the cpus * get_static_power() - calculate the static power consumed by the cpus
* @cpufreq_device: struct &cpufreq_cooling_device for this cpu cdev * @cpufreq_cdev: struct &cpufreq_cooling_device for this cpu cdev
* @tz: thermal zone device in which we're operating * @tz: thermal zone device in which we're operating
* @freq: frequency in KHz * @freq: frequency in KHz
* @power: pointer in which to store the calculated static power * @power: pointer in which to store the calculated static power
...@@ -378,25 +378,24 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu, ...@@ -378,25 +378,24 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu,
* *
* Return: 0 on success, -E* on failure. * Return: 0 on success, -E* on failure.
*/ */
static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, static int get_static_power(struct cpufreq_cooling_device *cpufreq_cdev,
struct thermal_zone_device *tz, unsigned long freq, struct thermal_zone_device *tz, unsigned long freq,
u32 *power) u32 *power)
{ {
struct dev_pm_opp *opp; struct dev_pm_opp *opp;
unsigned long voltage; unsigned long voltage;
struct cpumask *cpumask = &cpufreq_device->allowed_cpus; struct cpumask *cpumask = &cpufreq_cdev->allowed_cpus;
unsigned long freq_hz = freq * 1000; unsigned long freq_hz = freq * 1000;
if (!cpufreq_device->plat_get_static_power || if (!cpufreq_cdev->plat_get_static_power || !cpufreq_cdev->cpu_dev) {
!cpufreq_device->cpu_dev) {
*power = 0; *power = 0;
return 0; return 0;
} }
opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, opp = dev_pm_opp_find_freq_exact(cpufreq_cdev->cpu_dev, freq_hz,
true); true);
if (IS_ERR(opp)) { if (IS_ERR(opp)) {
dev_warn_ratelimited(cpufreq_device->cpu_dev, dev_warn_ratelimited(cpufreq_cdev->cpu_dev,
"Failed to find OPP for frequency %lu: %ld\n", "Failed to find OPP for frequency %lu: %ld\n",
freq_hz, PTR_ERR(opp)); freq_hz, PTR_ERR(opp));
return -EINVAL; return -EINVAL;
...@@ -406,31 +405,31 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, ...@@ -406,31 +405,31 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device,
dev_pm_opp_put(opp); dev_pm_opp_put(opp);
if (voltage == 0) { if (voltage == 0) {
dev_err_ratelimited(cpufreq_device->cpu_dev, dev_err_ratelimited(cpufreq_cdev->cpu_dev,
"Failed to get voltage for frequency %lu\n", "Failed to get voltage for frequency %lu\n",
freq_hz); freq_hz);
return -EINVAL; return -EINVAL;
} }
return cpufreq_device->plat_get_static_power(cpumask, tz->passive_delay, return cpufreq_cdev->plat_get_static_power(cpumask, tz->passive_delay,
voltage, power); voltage, power);
} }
/** /**
* get_dynamic_power() - calculate the dynamic power * get_dynamic_power() - calculate the dynamic power
* @cpufreq_device: &cpufreq_cooling_device for this cdev * @cpufreq_cdev: &cpufreq_cooling_device for this cdev
* @freq: current frequency * @freq: current frequency
* *
* Return: the dynamic power consumed by the cpus described by * Return: the dynamic power consumed by the cpus described by
* @cpufreq_device. * @cpufreq_cdev.
*/ */
static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device, static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
unsigned long freq) unsigned long freq)
{ {
u32 raw_cpu_power; u32 raw_cpu_power;
raw_cpu_power = cpu_freq_to_power(cpufreq_device, freq); raw_cpu_power = cpu_freq_to_power(cpufreq_cdev, freq);
return (raw_cpu_power * cpufreq_device->last_load) / 100; return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
} }
/* cpufreq cooling device callback functions are defined below */ /* cpufreq cooling device callback functions are defined below */
...@@ -448,9 +447,9 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device, ...@@ -448,9 +447,9 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device,
static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state) unsigned long *state)
{ {
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
*state = cpufreq_device->max_level; *state = cpufreq_cdev->max_level;
return 0; return 0;
} }
...@@ -467,9 +466,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, ...@@ -467,9 +466,9 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state) unsigned long *state)
{ {
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
*state = cpufreq_device->cpufreq_state; *state = cpufreq_cdev->cpufreq_state;
return 0; return 0;
} }
...@@ -487,21 +486,21 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, ...@@ -487,21 +486,21 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state) unsigned long state)
{ {
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus); unsigned int cpu = cpumask_any(&cpufreq_cdev->allowed_cpus);
unsigned int clip_freq; unsigned int clip_freq;
/* Request state should be less than max_level */ /* Request state should be less than max_level */
if (WARN_ON(state > cpufreq_device->max_level)) if (WARN_ON(state > cpufreq_cdev->max_level))
return -EINVAL; return -EINVAL;
/* Check if the old cooling action is same as new cooling action */ /* Check if the old cooling action is same as new cooling action */
if (cpufreq_device->cpufreq_state == state) if (cpufreq_cdev->cpufreq_state == state)
return 0; return 0;
clip_freq = cpufreq_device->freq_table[state]; clip_freq = cpufreq_cdev->freq_table[state];
cpufreq_device->cpufreq_state = state; cpufreq_cdev->cpufreq_state = state;
cpufreq_device->clipped_freq = clip_freq; cpufreq_cdev->clipped_freq = clip_freq;
cpufreq_update_policy(cpu); cpufreq_update_policy(cpu);
...@@ -538,10 +537,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, ...@@ -538,10 +537,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
unsigned long freq; unsigned long freq;
int i = 0, cpu, ret; int i = 0, cpu, ret;
u32 static_power, dynamic_power, total_load = 0; u32 static_power, dynamic_power, total_load = 0;
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
u32 *load_cpu = NULL; u32 *load_cpu = NULL;
cpu = cpumask_any_and(&cpufreq_device->allowed_cpus, cpu_online_mask); cpu = cpumask_any_and(&cpufreq_cdev->allowed_cpus, cpu_online_mask);
/* /*
* All the CPUs are offline, thus the requested power by * All the CPUs are offline, thus the requested power by
...@@ -555,16 +554,16 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, ...@@ -555,16 +554,16 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
freq = cpufreq_quick_get(cpu); freq = cpufreq_quick_get(cpu);
if (trace_thermal_power_cpu_get_power_enabled()) { if (trace_thermal_power_cpu_get_power_enabled()) {
u32 ncpus = cpumask_weight(&cpufreq_device->allowed_cpus); u32 ncpus = cpumask_weight(&cpufreq_cdev->allowed_cpus);
load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL); load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL);
} }
for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) {
u32 load; u32 load;
if (cpu_online(cpu)) if (cpu_online(cpu))
load = get_load(cpufreq_device, cpu, i); load = get_load(cpufreq_cdev, cpu, i);
else else
load = 0; load = 0;
...@@ -575,10 +574,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, ...@@ -575,10 +574,10 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
i++; i++;
} }
cpufreq_device->last_load = total_load; cpufreq_cdev->last_load = total_load;
dynamic_power = get_dynamic_power(cpufreq_device, freq); dynamic_power = get_dynamic_power(cpufreq_cdev, freq);
ret = get_static_power(cpufreq_device, tz, freq, &static_power); ret = get_static_power(cpufreq_cdev, tz, freq, &static_power);
if (ret) { if (ret) {
kfree(load_cpu); kfree(load_cpu);
return ret; return ret;
...@@ -586,7 +585,7 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, ...@@ -586,7 +585,7 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
if (load_cpu) { if (load_cpu) {
trace_thermal_power_cpu_get_power( trace_thermal_power_cpu_get_power(
&cpufreq_device->allowed_cpus, &cpufreq_cdev->allowed_cpus,
freq, load_cpu, i, dynamic_power, static_power); freq, load_cpu, i, dynamic_power, static_power);
kfree(load_cpu); kfree(load_cpu);
...@@ -619,12 +618,12 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, ...@@ -619,12 +618,12 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
cpumask_var_t cpumask; cpumask_var_t cpumask;
u32 static_power, dynamic_power; u32 static_power, dynamic_power;
int ret; int ret;
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
return -ENOMEM; return -ENOMEM;
cpumask_and(cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); cpumask_and(cpumask, &cpufreq_cdev->allowed_cpus, cpu_online_mask);
num_cpus = cpumask_weight(cpumask); num_cpus = cpumask_weight(cpumask);
/* None of our cpus are online, so no power */ /* None of our cpus are online, so no power */
...@@ -634,14 +633,14 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, ...@@ -634,14 +633,14 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
goto out; goto out;
} }
freq = cpufreq_device->freq_table[state]; freq = cpufreq_cdev->freq_table[state];
if (!freq) { if (!freq) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus; dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus;
ret = get_static_power(cpufreq_device, tz, freq, &static_power); ret = get_static_power(cpufreq_cdev, tz, freq, &static_power);
if (ret) if (ret)
goto out; goto out;
...@@ -679,24 +678,24 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, ...@@ -679,24 +678,24 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
int ret; int ret;
s32 dyn_power; s32 dyn_power;
u32 last_load, normalised_power, static_power; u32 last_load, normalised_power, static_power;
struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
cpu = cpumask_any_and(&cpufreq_device->allowed_cpus, cpu_online_mask); cpu = cpumask_any_and(&cpufreq_cdev->allowed_cpus, cpu_online_mask);
/* None of our cpus are online */ /* None of our cpus are online */
if (cpu >= nr_cpu_ids) if (cpu >= nr_cpu_ids)
return -ENODEV; return -ENODEV;
cur_freq = cpufreq_quick_get(cpu); cur_freq = cpufreq_quick_get(cpu);
ret = get_static_power(cpufreq_device, tz, cur_freq, &static_power); ret = get_static_power(cpufreq_cdev, tz, cur_freq, &static_power);
if (ret) if (ret)
return ret; return ret;
dyn_power = power - static_power; dyn_power = power - static_power;
dyn_power = dyn_power > 0 ? dyn_power : 0; dyn_power = dyn_power > 0 ? dyn_power : 0;
last_load = cpufreq_device->last_load ?: 1; last_load = cpufreq_cdev->last_load ?: 1;
normalised_power = (dyn_power * 100) / last_load; normalised_power = (dyn_power * 100) / last_load;
target_freq = cpu_power_to_freq(cpufreq_device, normalised_power); target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power);
*state = cpufreq_cooling_get_level(cpu, target_freq); *state = cpufreq_cooling_get_level(cpu, target_freq);
if (*state == THERMAL_CSTATE_INVALID) { if (*state == THERMAL_CSTATE_INVALID) {
...@@ -706,7 +705,7 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, ...@@ -706,7 +705,7 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
return -EINVAL; return -EINVAL;
} }
trace_thermal_power_cpu_limit(&cpufreq_device->allowed_cpus, trace_thermal_power_cpu_limit(&cpufreq_cdev->allowed_cpus,
target_freq, *state, power); target_freq, *state, power);
return 0; return 0;
} }
...@@ -771,7 +770,7 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -771,7 +770,7 @@ __cpufreq_cooling_register(struct device_node *np,
{ {
struct cpufreq_policy *policy; struct cpufreq_policy *policy;
struct thermal_cooling_device *cool_dev; struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev; struct cpufreq_cooling_device *cpufreq_cdev;
char dev_name[THERMAL_NAME_LENGTH]; char dev_name[THERMAL_NAME_LENGTH];
struct cpufreq_frequency_table *pos, *table; struct cpufreq_frequency_table *pos, *table;
cpumask_var_t temp_mask; cpumask_var_t temp_mask;
...@@ -798,49 +797,49 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -798,49 +797,49 @@ __cpufreq_cooling_register(struct device_node *np,
goto put_policy; goto put_policy;
} }
cpufreq_dev = kzalloc(sizeof(*cpufreq_dev), GFP_KERNEL); cpufreq_cdev = kzalloc(sizeof(*cpufreq_cdev), GFP_KERNEL);
if (!cpufreq_dev) { if (!cpufreq_cdev) {
cool_dev = ERR_PTR(-ENOMEM); cool_dev = ERR_PTR(-ENOMEM);
goto put_policy; goto put_policy;
} }
num_cpus = cpumask_weight(clip_cpus); num_cpus = cpumask_weight(clip_cpus);
cpufreq_dev->time_in_idle = kcalloc(num_cpus, cpufreq_cdev->time_in_idle = kcalloc(num_cpus,
sizeof(*cpufreq_dev->time_in_idle), sizeof(*cpufreq_cdev->time_in_idle),
GFP_KERNEL); GFP_KERNEL);
if (!cpufreq_dev->time_in_idle) { if (!cpufreq_cdev->time_in_idle) {
cool_dev = ERR_PTR(-ENOMEM); cool_dev = ERR_PTR(-ENOMEM);
goto free_cdev; goto free_cdev;
} }
cpufreq_dev->time_in_idle_timestamp = cpufreq_cdev->time_in_idle_timestamp =
kcalloc(num_cpus, sizeof(*cpufreq_dev->time_in_idle_timestamp), kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp),
GFP_KERNEL); GFP_KERNEL);
if (!cpufreq_dev->time_in_idle_timestamp) { if (!cpufreq_cdev->time_in_idle_timestamp) {
cool_dev = ERR_PTR(-ENOMEM); cool_dev = ERR_PTR(-ENOMEM);
goto free_time_in_idle; goto free_time_in_idle;
} }
/* Find max levels */ /* Find max levels */
cpufreq_for_each_valid_entry(pos, table) cpufreq_for_each_valid_entry(pos, table)
cpufreq_dev->max_level++; cpufreq_cdev->max_level++;
cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) *
cpufreq_dev->max_level, GFP_KERNEL); cpufreq_cdev->max_level, GFP_KERNEL);
if (!cpufreq_dev->freq_table) { if (!cpufreq_cdev->freq_table) {
cool_dev = ERR_PTR(-ENOMEM); cool_dev = ERR_PTR(-ENOMEM);
goto free_time_in_idle_timestamp; goto free_time_in_idle_timestamp;
} }
/* max_level is an index, not a counter */ /* max_level is an index, not a counter */
cpufreq_dev->max_level--; cpufreq_cdev->max_level--;
cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); cpumask_copy(&cpufreq_cdev->allowed_cpus, clip_cpus);
if (capacitance) { if (capacitance) {
cpufreq_dev->plat_get_static_power = plat_static_func; cpufreq_cdev->plat_get_static_power = plat_static_func;
ret = build_dyn_power_table(cpufreq_dev, capacitance); ret = build_dyn_power_table(cpufreq_cdev, capacitance);
if (ret) { if (ret) {
cool_dev = ERR_PTR(ret); cool_dev = ERR_PTR(ret);
goto free_table; goto free_table;
...@@ -856,12 +855,12 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -856,12 +855,12 @@ __cpufreq_cooling_register(struct device_node *np,
cool_dev = ERR_PTR(ret); cool_dev = ERR_PTR(ret);
goto free_power_table; goto free_power_table;
} }
cpufreq_dev->id = ret; cpufreq_cdev->id = ret;
/* Fill freq-table in descending order of frequencies */ /* Fill freq-table in descending order of frequencies */
for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) { for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) {
freq = find_next_max(table, freq); freq = find_next_max(table, freq);
cpufreq_dev->freq_table[i] = freq; cpufreq_cdev->freq_table[i] = freq;
/* Warn for duplicate entries */ /* Warn for duplicate entries */
if (!freq) if (!freq)
...@@ -871,20 +870,21 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -871,20 +870,21 @@ __cpufreq_cooling_register(struct device_node *np,
} }
snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
cpufreq_dev->id); cpufreq_cdev->id);
cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, cool_dev = thermal_of_cooling_device_register(np, dev_name,
cpufreq_cdev,
cooling_ops); cooling_ops);
if (IS_ERR(cool_dev)) if (IS_ERR(cool_dev))
goto remove_ida; goto remove_ida;
cpufreq_dev->clipped_freq = cpufreq_dev->freq_table[0]; cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0];
cpufreq_dev->cool_dev = cool_dev; cpufreq_cdev->cool_dev = cool_dev;
mutex_lock(&cooling_list_lock); mutex_lock(&cooling_list_lock);
/* Register the notifier for first cpufreq cooling device */ /* Register the notifier for first cpufreq cooling device */
first = list_empty(&cpufreq_dev_list); first = list_empty(&cpufreq_cdev_list);
list_add(&cpufreq_dev->node, &cpufreq_dev_list); list_add(&cpufreq_cdev->node, &cpufreq_cdev_list);
mutex_unlock(&cooling_list_lock); mutex_unlock(&cooling_list_lock);
if (first) if (first)
...@@ -894,17 +894,17 @@ __cpufreq_cooling_register(struct device_node *np, ...@@ -894,17 +894,17 @@ __cpufreq_cooling_register(struct device_node *np,
goto put_policy; goto put_policy;
remove_ida: remove_ida:
ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id);
free_power_table: free_power_table:
kfree(cpufreq_dev->dyn_power_table); kfree(cpufreq_cdev->dyn_power_table);
free_table: free_table:
kfree(cpufreq_dev->freq_table); kfree(cpufreq_cdev->freq_table);
free_time_in_idle_timestamp: free_time_in_idle_timestamp:
kfree(cpufreq_dev->time_in_idle_timestamp); kfree(cpufreq_cdev->time_in_idle_timestamp);
free_time_in_idle: free_time_in_idle:
kfree(cpufreq_dev->time_in_idle); kfree(cpufreq_cdev->time_in_idle);
free_cdev: free_cdev:
kfree(cpufreq_dev); kfree(cpufreq_cdev);
put_policy: put_policy:
cpufreq_cpu_put(policy); cpufreq_cpu_put(policy);
free_cpumask: free_cpumask:
...@@ -1029,30 +1029,30 @@ EXPORT_SYMBOL(of_cpufreq_power_cooling_register); ...@@ -1029,30 +1029,30 @@ EXPORT_SYMBOL(of_cpufreq_power_cooling_register);
*/ */
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
{ {
struct cpufreq_cooling_device *cpufreq_dev; struct cpufreq_cooling_device *cpufreq_cdev;
bool last; bool last;
if (!cdev) if (!cdev)
return; return;
cpufreq_dev = cdev->devdata; cpufreq_cdev = cdev->devdata;
mutex_lock(&cooling_list_lock); mutex_lock(&cooling_list_lock);
list_del(&cpufreq_dev->node); list_del(&cpufreq_cdev->node);
/* Unregister the notifier for the last cpufreq cooling device */ /* Unregister the notifier for the last cpufreq cooling device */
last = list_empty(&cpufreq_dev_list); last = list_empty(&cpufreq_cdev_list);
mutex_unlock(&cooling_list_lock); mutex_unlock(&cooling_list_lock);
if (last) if (last)
cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER); CPUFREQ_POLICY_NOTIFIER);
thermal_cooling_device_unregister(cpufreq_dev->cool_dev); thermal_cooling_device_unregister(cpufreq_cdev->cool_dev);
ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id);
kfree(cpufreq_dev->dyn_power_table); kfree(cpufreq_cdev->dyn_power_table);
kfree(cpufreq_dev->time_in_idle_timestamp); kfree(cpufreq_cdev->time_in_idle_timestamp);
kfree(cpufreq_dev->time_in_idle); kfree(cpufreq_cdev->time_in_idle);
kfree(cpufreq_dev->freq_table); kfree(cpufreq_cdev->freq_table);
kfree(cpufreq_dev); kfree(cpufreq_cdev);
} }
EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister); EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment