summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cpu-freq/cpu-drivers.txt19
-rw-r--r--drivers/cpufreq/cpufreq.c11
-rw-r--r--include/linux/cpufreq.h21
3 files changed, 51 insertions, 0 deletions
diff --git a/Documentation/cpu-freq/cpu-drivers.txt b/Documentation/cpu-freq/cpu-drivers.txt
index 48da5fdcb9f1..b045fe54986a 100644
--- a/Documentation/cpu-freq/cpu-drivers.txt
+++ b/Documentation/cpu-freq/cpu-drivers.txt
@@ -228,3 +228,22 @@ is the corresponding frequency table helper for the ->target
228stage. Just pass the values to this function, and the unsigned int 228stage. Just pass the values to this function, and the unsigned int
229index returns the number of the frequency table entry which contains 229index returns the number of the frequency table entry which contains
230the frequency the CPU shall be set to. 230the frequency the CPU shall be set to.
231
232The following macros can be used as iterators over cpufreq_frequency_table:
233
234cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency
235table.
236
237cpufreq-for_each_valid_entry(pos, table) - iterates over all entries,
238excluding CPUFREQ_ENTRY_INVALID frequencies.
239Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and
240"table" - the cpufreq_frequency_table * you want to iterate over.
241
242For example:
243
244 struct cpufreq_frequency_table *pos, *driver_freq_table;
245
246 cpufreq_for_each_entry(pos, driver_freq_table) {
247 /* Do something with pos */
248 pos->frequency = ...
249 }
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index abda6609d3e7..a517da996aaf 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -237,6 +237,17 @@ void cpufreq_cpu_put(struct cpufreq_policy *policy)
237} 237}
238EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 238EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
239 239
240bool cpufreq_next_valid(struct cpufreq_frequency_table **pos)
241{
242 while ((*pos)->frequency != CPUFREQ_TABLE_END)
243 if ((*pos)->frequency != CPUFREQ_ENTRY_INVALID)
244 return true;
245 else
246 (*pos)++;
247 return false;
248}
249EXPORT_SYMBOL_GPL(cpufreq_next_valid);
250
240/********************************************************************* 251/*********************************************************************
241 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 252 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
242 *********************************************************************/ 253 *********************************************************************/
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 5ae5100c1f24..77a5fa191502 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -468,6 +468,27 @@ struct cpufreq_frequency_table {
468 * order */ 468 * order */
469}; 469};
470 470
471bool cpufreq_next_valid(struct cpufreq_frequency_table **pos);
472
473/*
474 * cpufreq_for_each_entry - iterate over a cpufreq_frequency_table
475 * @pos: the cpufreq_frequency_table * to use as a loop cursor.
476 * @table: the cpufreq_frequency_table * to iterate over.
477 */
478
479#define cpufreq_for_each_entry(pos, table) \
480 for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++)
481
482/*
483 * cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table
484 * excluding CPUFREQ_ENTRY_INVALID frequencies.
485 * @pos: the cpufreq_frequency_table * to use as a loop cursor.
486 * @table: the cpufreq_frequency_table * to iterate over.
487 */
488
489#define cpufreq_for_each_valid_entry(pos, table) \
490 for (pos = table; cpufreq_next_valid(&pos); pos++)
491
471int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 492int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
472 struct cpufreq_frequency_table *table); 493 struct cpufreq_frequency_table *table);
473 494