diff options
author | Mike Turquette <mturquette@ti.com> | 2011-05-17 09:35:54 -0500 |
---|---|---|
committer | Nishanth Menon <nm@ti.com> | 2011-06-13 16:39:16 -0500 |
commit | 821d85f7102ca27538116b4ccbdafe0f5e134261 (patch) | |
tree | db20142528331aa742f3b69db8dbe6f5d9eb0edb /drivers/cpufreq/freq_table.c | |
parent | ddb65d34fbccef0fe087af4898d6d9fa8526fb88 (diff) | |
download | kernel_samsung_tuna-821d85f7102ca27538116b4ccbdafe0f5e134261.zip kernel_samsung_tuna-821d85f7102ca27538116b4ccbdafe0f5e134261.tar.gz kernel_samsung_tuna-821d85f7102ca27538116b4ccbdafe0f5e134261.tar.bz2 |
cpufreq: helpers for walking the frequency table
Two new functions for getting the next higher and next lower frequencies
in the cpufreq table, based upon a frequency supplied in kHz.
This is useful for cpufreq governors that do not target frequencies
based upon a percentage or a pre-determined value, but instead access
the cpufreq table directly.
Signed-off-by: Mike Turquette <mturquette@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Diffstat (limited to 'drivers/cpufreq/freq_table.c')
-rw-r--r-- | drivers/cpufreq/freq_table.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 90431cb..54c4de4 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c @@ -13,6 +13,7 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/cpufreq.h> +#include <linux/err.h> /********************************************************************* * FREQUENCY TABLE HELPERS * @@ -171,6 +172,78 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, } EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); +int cpufreq_frequency_table_next_lowest(struct cpufreq_policy *policy, + struct cpufreq_frequency_table *table, int *index) +{ + unsigned int cur_freq; + unsigned int next_lowest_freq; + int optimal_index = -1; + int i = 0; + + if (!policy || IS_ERR(policy) || !table || IS_ERR(table) || + !index || IS_ERR(index)) + return -ENOMEM; + + cur_freq = policy->cur; + next_lowest_freq = policy->min; + + /* we're at the lowest frequency in the table already, bail out */ + if (cur_freq == policy->min) + return -EINVAL; + + /* walk the list, find closest freq to cur_freq that is below it */ + while(table[i].frequency != CPUFREQ_TABLE_END) { + if (table[i].frequency < cur_freq && + table[i].frequency >= next_lowest_freq) { + next_lowest_freq = table[i].frequency; + optimal_index = table[i].index; + } + + i++; + } + + *index = optimal_index; + + return 0; +} +EXPORT_SYMBOL_GPL(cpufreq_frequency_table_next_lowest); + +int cpufreq_frequency_table_next_highest(struct cpufreq_policy *policy, + struct cpufreq_frequency_table *table, int *index) +{ + unsigned int cur_freq; + unsigned int next_higher_freq; + int optimal_index = -1; + int i = 0; + + if (!policy || IS_ERR(policy) || !table || IS_ERR(table) || + !index || IS_ERR(index)) + return -ENOMEM; + + cur_freq = policy->cur; + next_higher_freq = policy->max; + + /* we're at the highest frequency in the table already, bail out */ + if (cur_freq == policy->max) + return -EINVAL; + + /* walk the list, find closest freq to cur_freq that is above it */ + while(table[i].frequency != CPUFREQ_TABLE_END) { + if (table[i].frequency > cur_freq && + table[i].frequency <= next_higher_freq) { + next_higher_freq = table[i].frequency; + optimal_index = table[i].index; + } + + i++; + } + + *index = optimal_index; + + return 0; +} +EXPORT_SYMBOL_GPL(cpufreq_frequency_table_next_highest); + static DEFINE_PER_CPU(struct cpufreq_frequency_table *, cpufreq_show_table); /** * show_available_freqs - show available frequencies for the specified CPU |