Commit d218ed77 authored by Viresh Kumar's avatar Viresh Kumar Committed by Rafael J. Wysocki

cpufreq: Return index from cpufreq_frequency_table_target()

This routine can't fail unless the frequency table is invalid and
doesn't contain any valid entries.

Make it return the index and WARN() in case it is used for an invalid
table.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 23727845
...@@ -245,12 +245,11 @@ policy->max, and all other criteria are met. This is helpful for the ...@@ -245,12 +245,11 @@ policy->max, and all other criteria are met. This is helpful for the
int cpufreq_frequency_table_target(struct cpufreq_policy *policy, int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
unsigned int target_freq, unsigned int target_freq,
unsigned int relation, unsigned int relation);
unsigned int *index);
is the corresponding frequency table helper for the ->target is the corresponding frequency table helper for the ->target
stage. Just pass the values to this function, and the unsigned int stage. Just pass the values to this function, and this function
index returns the number of the frequency table entry which contains returns the number of the frequency table entry which contains
the frequency the CPU shall be set to. the frequency the CPU shall be set to.
The following macros can be used as iterators over cpufreq_frequency_table: The following macros can be used as iterators over cpufreq_frequency_table:
......
...@@ -91,8 +91,8 @@ static unsigned int amd_powersave_bias_target(struct cpufreq_policy *policy, ...@@ -91,8 +91,8 @@ static unsigned int amd_powersave_bias_target(struct cpufreq_policy *policy,
else { else {
unsigned int index; unsigned int index;
cpufreq_frequency_table_target(policy, index = cpufreq_frequency_table_target(policy,
policy->cur - 1, CPUFREQ_RELATION_H, &index); policy->cur - 1, CPUFREQ_RELATION_H);
freq_next = policy->freq_table[index].frequency; freq_next = policy->freq_table[index].frequency;
} }
......
...@@ -1914,7 +1914,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, ...@@ -1914,7 +1914,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
unsigned int relation) unsigned int relation)
{ {
unsigned int old_target_freq = target_freq; unsigned int old_target_freq = target_freq;
int index, retval; int index;
if (cpufreq_disabled()) if (cpufreq_disabled())
return -ENODEV; return -ENODEV;
...@@ -1943,12 +1943,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, ...@@ -1943,12 +1943,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
if (!cpufreq_driver->target_index) if (!cpufreq_driver->target_index)
return -EINVAL; return -EINVAL;
retval = cpufreq_frequency_table_target(policy, target_freq, relation, index = cpufreq_frequency_table_target(policy, target_freq, relation);
&index);
if (unlikely(retval)) {
pr_err("%s: Unable to find matching freq\n", __func__);
return retval;
}
return __target_index(policy, index); return __target_index(policy, index);
} }
......
...@@ -65,7 +65,7 @@ static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy, ...@@ -65,7 +65,7 @@ static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy,
{ {
unsigned int freq_req, freq_reduc, freq_avg; unsigned int freq_req, freq_reduc, freq_avg;
unsigned int freq_hi, freq_lo; unsigned int freq_hi, freq_lo;
unsigned int index = 0; unsigned int index;
unsigned int delay_hi_us; unsigned int delay_hi_us;
struct policy_dbs_info *policy_dbs = policy->governor_data; struct policy_dbs_info *policy_dbs = policy->governor_data;
struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs); struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
...@@ -79,19 +79,17 @@ static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy, ...@@ -79,19 +79,17 @@ static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy,
return freq_next; return freq_next;
} }
cpufreq_frequency_table_target(policy, freq_next, relation, &index); index = cpufreq_frequency_table_target(policy, freq_next, relation);
freq_req = freq_table[index].frequency; freq_req = freq_table[index].frequency;
freq_reduc = freq_req * od_tuners->powersave_bias / 1000; freq_reduc = freq_req * od_tuners->powersave_bias / 1000;
freq_avg = freq_req - freq_reduc; freq_avg = freq_req - freq_reduc;
/* Find freq bounds for freq_avg in freq_table */ /* Find freq bounds for freq_avg in freq_table */
index = 0; index = cpufreq_frequency_table_target(policy, freq_avg,
cpufreq_frequency_table_target(policy, freq_avg, CPUFREQ_RELATION_H, CPUFREQ_RELATION_H);
&index);
freq_lo = freq_table[index].frequency; freq_lo = freq_table[index].frequency;
index = 0; index = cpufreq_frequency_table_target(policy, freq_avg,
cpufreq_frequency_table_target(policy, freq_avg, CPUFREQ_RELATION_L, CPUFREQ_RELATION_L);
&index);
freq_hi = freq_table[index].frequency; freq_hi = freq_table[index].frequency;
/* Find out how long we have to be in hi and lo freqs */ /* Find out how long we have to be in hi and lo freqs */
......
...@@ -114,9 +114,8 @@ int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy) ...@@ -114,9 +114,8 @@ int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy)
EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify); EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify);
int cpufreq_frequency_table_target(struct cpufreq_policy *policy, int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
unsigned int target_freq, unsigned int target_freq,
unsigned int relation, unsigned int relation)
unsigned int *index)
{ {
struct cpufreq_frequency_table optimal = { struct cpufreq_frequency_table optimal = {
.driver_data = ~0, .driver_data = ~0,
...@@ -129,6 +128,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, ...@@ -129,6 +128,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *pos; struct cpufreq_frequency_table *pos;
struct cpufreq_frequency_table *table = policy->freq_table; struct cpufreq_frequency_table *table = policy->freq_table;
unsigned int freq, diff, i = 0; unsigned int freq, diff, i = 0;
int index;
pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
target_freq, relation, policy->cpu); target_freq, relation, policy->cpu);
...@@ -192,16 +192,18 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, ...@@ -192,16 +192,18 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
} }
} }
if (optimal.driver_data > i) { if (optimal.driver_data > i) {
if (suboptimal.driver_data > i) if (suboptimal.driver_data > i) {
return -EINVAL; WARN(1, "Invalid frequency table: %d\n", policy->cpu);
*index = suboptimal.driver_data; return 0;
} else }
*index = optimal.driver_data;
pr_debug("target index is %u, freq is:%u kHz\n", *index, index = suboptimal.driver_data;
table[*index].frequency); } else
index = optimal.driver_data;
return 0; pr_debug("target index is %u, freq is:%u kHz\n", index,
table[index].frequency);
return index;
} }
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
......
...@@ -760,8 +760,8 @@ void powernv_cpufreq_work_fn(struct work_struct *work) ...@@ -760,8 +760,8 @@ void powernv_cpufreq_work_fn(struct work_struct *work)
struct cpufreq_policy policy; struct cpufreq_policy policy;
cpufreq_get_policy(&policy, cpu); cpufreq_get_policy(&policy, cpu);
cpufreq_frequency_table_target(&policy, policy.cur, index = cpufreq_frequency_table_target(&policy, policy.cur,
CPUFREQ_RELATION_C, &index); CPUFREQ_RELATION_C);
powernv_cpufreq_target_index(&policy, index); powernv_cpufreq_target_index(&policy, index);
cpumask_andnot(&mask, &mask, policy.cpus); cpumask_andnot(&mask, &mask, policy.cpus);
} }
......
...@@ -293,11 +293,8 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy, ...@@ -293,11 +293,8 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy,
__func__, policy, target_freq, relation); __func__, policy, target_freq, relation);
if (ftab) { if (ftab) {
if (cpufreq_frequency_table_target(policy, target_freq, index = cpufreq_frequency_table_target(policy, target_freq,
relation, &index)) { relation);
s3c_freq_dbg("%s: table failed\n", __func__);
return -EINVAL;
}
s3c_freq_dbg("%s: adjust %d to entry %d (%u)\n", __func__, s3c_freq_dbg("%s: adjust %d to entry %d (%u)\n", __func__,
target_freq, index, ftab[index].frequency); target_freq, index, ftab[index].frequency);
...@@ -314,7 +311,6 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy, ...@@ -314,7 +311,6 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy,
pll = NULL; pll = NULL;
} else { } else {
struct cpufreq_policy tmp_policy; struct cpufreq_policy tmp_policy;
int ret;
/* we keep the cpu pll table in Hz, to ensure we get an /* we keep the cpu pll table in Hz, to ensure we get an
* accurate value for the PLL output. */ * accurate value for the PLL output. */
...@@ -324,18 +320,12 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy, ...@@ -324,18 +320,12 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy,
tmp_policy.cpu = policy->cpu; tmp_policy.cpu = policy->cpu;
tmp_policy.freq_table = pll_reg; tmp_policy.freq_table = pll_reg;
/* cpufreq_frequency_table_target uses a pointer to 'index' /* cpufreq_frequency_table_target returns the index
* which is the number of the table entry, not the value of * of the table entry, not the value of
* the table entry's index field. */ * the table entry's index field. */
ret = cpufreq_frequency_table_target(&tmp_policy, target_freq, index = cpufreq_frequency_table_target(&tmp_policy, target_freq,
relation, &index); relation);
if (ret < 0) {
pr_err("%s: no PLL available\n", __func__);
goto err_notpossible;
}
pll = pll_reg + index; pll = pll_reg + index;
s3c_freq_dbg("%s: target %u => %u\n", s3c_freq_dbg("%s: target %u => %u\n",
...@@ -345,10 +335,6 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy, ...@@ -345,10 +335,6 @@ static int s3c_cpufreq_target(struct cpufreq_policy *policy,
} }
return s3c_cpufreq_settarget(policy, target_freq, pll); return s3c_cpufreq_settarget(policy, target_freq, pll);
err_notpossible:
pr_err("no compatible settings for %d\n", target_freq);
return -EINVAL;
} }
struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name) struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
......
...@@ -246,11 +246,8 @@ static int s5pv210_target(struct cpufreq_policy *policy, unsigned int index) ...@@ -246,11 +246,8 @@ static int s5pv210_target(struct cpufreq_policy *policy, unsigned int index)
new_freq = s5pv210_freq_table[index].frequency; new_freq = s5pv210_freq_table[index].frequency;
/* Finding current running level index */ /* Finding current running level index */
if (cpufreq_frequency_table_target(policy, old_freq, CPUFREQ_RELATION_H, priv_index = cpufreq_frequency_table_target(policy, old_freq,
&priv_index)) { CPUFREQ_RELATION_H);
ret = -EINVAL;
goto exit;
}
arm_volt = dvs_conf[index].arm_volt; arm_volt = dvs_conf[index].arm_volt;
int_volt = dvs_conf[index].int_volt; int_volt = dvs_conf[index].int_volt;
......
...@@ -599,8 +599,7 @@ int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy); ...@@ -599,8 +599,7 @@ int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy);
int cpufreq_frequency_table_target(struct cpufreq_policy *policy, int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
unsigned int target_freq, unsigned int target_freq,
unsigned int relation, unsigned int relation);
unsigned int *index);
int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
unsigned int freq); unsigned int freq);
......
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