···228228stage. Just pass the values to this function, and the unsigned int229229index returns the number of the frequency table entry which contains230230the frequency the CPU shall be set to.231231+232232+The following macros can be used as iterators over cpufreq_frequency_table:233233+234234+cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency235235+table.236236+237237+cpufreq-for_each_valid_entry(pos, table) - iterates over all entries,238238+excluding CPUFREQ_ENTRY_INVALID frequencies.239239+Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and240240+"table" - the cpufreq_frequency_table * you want to iterate over.241241+242242+For example:243243+244244+ struct cpufreq_frequency_table *pos, *driver_freq_table;245245+246246+ cpufreq_for_each_entry(pos, driver_freq_table) {247247+ /* Do something with pos */248248+ pos->frequency = ...249249+ }
+5-4
arch/arm/mach-davinci/da850.c
···1092109210931093static int da850_round_armrate(struct clk *clk, unsigned long rate)10941094{10951095- int i, ret = 0, diff;10951095+ int ret = 0, diff;10961096 unsigned int best = (unsigned int) -1;10971097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table;10981098+ struct cpufreq_frequency_table *pos;1098109910991100 rate /= 1000; /* convert to kHz */1100110111011101- for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {11021102- diff = table[i].frequency - rate;11021102+ cpufreq_for_each_entry(pos, table) {11031103+ diff = pos->frequency - rate;11031104 if (diff < 0)11041105 diff = -diff;1105110611061107 if (diff < best) {11071108 best = diff;11081108- ret = table[i].frequency;11091109+ ret = pos->frequency;11091110 }11101111 }11111112
+5-11
arch/mips/loongson/lemote-2f/clock.c
···91919292int clk_set_rate(struct clk *clk, unsigned long rate)9393{9494+ struct cpufreq_frequency_table *pos;9495 int ret = 0;9596 int regval;9696- int i;97979898 if (likely(clk->ops && clk->ops->set_rate)) {9999 unsigned long flags;···106106 if (unlikely(clk->flags & CLK_RATE_PROPAGATES))107107 propagate_rate(clk);108108109109- for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END;110110- i++) {111111- if (loongson2_clockmod_table[i].frequency ==112112- CPUFREQ_ENTRY_INVALID)113113- continue;114114- if (rate == loongson2_clockmod_table[i].frequency)109109+ cpufreq_for_each_valid_entry(pos, loongson2_clockmod_table)110110+ if (rate == pos->frequency)115111 break;116116- }117117- if (rate != loongson2_clockmod_table[i].frequency)112112+ if (rate != pos->frequency)118113 return -ENOTSUPP;119114120115 clk->rate = rate;121116122117 regval = LOONGSON_CHIPCFG0;123123- regval = (regval & ~0x7) |124124- (loongson2_clockmod_table[i].driver_data - 1);118118+ regval = (regval & ~0x7) | (pos->driver_data - 1);125119 LOONGSON_CHIPCFG0 = regval;126120127121 return ret;
+4-5
drivers/cpufreq/acpi-cpufreq.c
···213213214214static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)215215{216216- int i;216216+ struct cpufreq_frequency_table *pos;217217 struct acpi_processor_performance *perf;218218219219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)···223223224224 perf = data->acpi_data;225225226226- for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {227227- if (msr == perf->states[data->freq_table[i].driver_data].status)228228- return data->freq_table[i].frequency;229229- }226226+ cpufreq_for_each_entry(pos, data->freq_table)227227+ if (msr == perf->states[pos->driver_data].status)228228+ return pos->frequency;230229 return data->freq_table[0].frequency;231230}232231
+8-8
drivers/cpufreq/arm_big_little.c
···226226/* get the minimum frequency in the cpufreq_frequency_table */227227static inline u32 get_table_min(struct cpufreq_frequency_table *table)228228{229229- int i;229229+ struct cpufreq_frequency_table *pos;230230 uint32_t min_freq = ~0;231231- for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++)232232- if (table[i].frequency < min_freq)233233- min_freq = table[i].frequency;231231+ cpufreq_for_each_entry(pos, table)232232+ if (pos->frequency < min_freq)233233+ min_freq = pos->frequency;234234 return min_freq;235235}236236237237/* get the maximum frequency in the cpufreq_frequency_table */238238static inline u32 get_table_max(struct cpufreq_frequency_table *table)239239{240240- int i;240240+ struct cpufreq_frequency_table *pos;241241 uint32_t max_freq = 0;242242- for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++)243243- if (table[i].frequency > max_freq)244244- max_freq = table[i].frequency;242242+ cpufreq_for_each_entry(pos, table)243243+ if (pos->frequency > max_freq)244244+ max_freq = pos->frequency;245245 return max_freq;246246}247247
+11
drivers/cpufreq/cpufreq.c
···237237}238238EXPORT_SYMBOL_GPL(cpufreq_cpu_put);239239240240+bool cpufreq_next_valid(struct cpufreq_frequency_table **pos)241241+{242242+ while ((*pos)->frequency != CPUFREQ_TABLE_END)243243+ if ((*pos)->frequency != CPUFREQ_ENTRY_INVALID)244244+ return true;245245+ else246246+ (*pos)++;247247+ return false;248248+}249249+EXPORT_SYMBOL_GPL(cpufreq_next_valid);250250+240251/*********************************************************************241252 * EXTERNALLY AFFECTING FREQUENCY CHANGES *242253 *********************************************************************/
+8-16
drivers/cpufreq/cpufreq_stats.c
···182182183183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)184184{185185- unsigned int i, j, count = 0, ret = 0;185185+ unsigned int i, count = 0, ret = 0;186186 struct cpufreq_stats *stat;187187 unsigned int alloc_size;188188 unsigned int cpu = policy->cpu;189189- struct cpufreq_frequency_table *table;189189+ struct cpufreq_frequency_table *pos, *table;190190191191 table = cpufreq_frequency_get_table(cpu);192192 if (unlikely(!table))···205205 stat->cpu = cpu;206206 per_cpu(cpufreq_stats_table, cpu) = stat;207207208208- for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {209209- unsigned int freq = table[i].frequency;210210- if (freq == CPUFREQ_ENTRY_INVALID)211211- continue;208208+ cpufreq_for_each_valid_entry(pos, table)212209 count++;213213- }214210215211 alloc_size = count * sizeof(int) + count * sizeof(u64);216212···224228#ifdef CONFIG_CPU_FREQ_STAT_DETAILS225229 stat->trans_table = stat->freq_table + count;226230#endif227227- j = 0;228228- for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {229229- unsigned int freq = table[i].frequency;230230- if (freq == CPUFREQ_ENTRY_INVALID)231231- continue;232232- if (freq_table_get_index(stat, freq) == -1)233233- stat->freq_table[j++] = freq;234234- }235235- stat->state_num = j;231231+ i = 0;232232+ cpufreq_for_each_valid_entry(pos, table)233233+ if (freq_table_get_index(stat, pos->frequency) == -1)234234+ stat->freq_table[i++] = pos->frequency;235235+ stat->state_num = i;236236 spin_lock(&cpufreq_stats_lock);237237 stat->last_time = get_jiffies_64();238238 stat->last_index = freq_table_get_index(stat, policy->cur);
+3-5
drivers/cpufreq/dbx500-cpufreq.c
···45454646static int dbx500_cpufreq_probe(struct platform_device *pdev)4747{4848- int i = 0;4848+ struct cpufreq_frequency_table *pos;49495050 freq_table = dev_get_platdata(&pdev->dev);5151 if (!freq_table) {···6060 }61616262 pr_info("dbx500-cpufreq: Available frequencies:\n");6363- while (freq_table[i].frequency != CPUFREQ_TABLE_END) {6464- pr_info(" %d Mhz\n", freq_table[i].frequency/1000);6565- i++;6666- }6363+ cpufreq_for_each_entry(pos, freq_table)6464+ pr_info(" %d Mhz\n", pos->frequency / 1000);67656866 return cpufreq_register_driver(&dbx500_cpufreq_driver);6967}
+4-5
drivers/cpufreq/elanfreq.c
···147147static int elanfreq_cpu_init(struct cpufreq_policy *policy)148148{149149 struct cpuinfo_x86 *c = &cpu_data(0);150150- unsigned int i;150150+ struct cpufreq_frequency_table *pos;151151152152 /* capability check */153153 if ((c->x86_vendor != X86_VENDOR_AMD) ||···159159 max_freq = elanfreq_get_cpu_frequency(0);160160161161 /* table init */162162- for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) {163163- if (elanfreq_table[i].frequency > max_freq)164164- elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID;165165- }162162+ cpufreq_for_each_entry(pos, elanfreq_table)163163+ if (pos->frequency > max_freq)164164+ pos->frequency = CPUFREQ_ENTRY_INVALID;166165167166 /* cpuinfo and default policy values */168167 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
+5-6
drivers/cpufreq/exynos-cpufreq.c
···2929static int exynos_cpufreq_get_index(unsigned int freq)3030{3131 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;3232- int index;3232+ struct cpufreq_frequency_table *pos;33333434- for (index = 0;3535- freq_table[index].frequency != CPUFREQ_TABLE_END; index++)3636- if (freq_table[index].frequency == freq)3434+ cpufreq_for_each_entry(pos, freq_table)3535+ if (pos->frequency == freq)3736 break;38373939- if (freq_table[index].frequency == CPUFREQ_TABLE_END)3838+ if (pos->frequency == CPUFREQ_TABLE_END)4039 return -EINVAL;41404242- return index;4141+ return pos - freq_table;4342}44434544static int exynos_cpufreq_scale(unsigned int target_freq)
+15-15
drivers/cpufreq/exynos5440-cpufreq.c
···114114115115static int init_div_table(void)116116{117117- struct cpufreq_frequency_table *freq_tbl = dvfs_info->freq_table;117117+ struct cpufreq_frequency_table *pos, *freq_tbl = dvfs_info->freq_table;118118 unsigned int tmp, clk_div, ema_div, freq, volt_id;119119- int i = 0;120119 struct dev_pm_opp *opp;121120122121 rcu_read_lock();123123- for (i = 0; freq_tbl[i].frequency != CPUFREQ_TABLE_END; i++) {124124-122122+ cpufreq_for_each_entry(pos, freq_tbl) {125123 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev,126126- freq_tbl[i].frequency * 1000, true);124124+ pos->frequency * 1000, true);127125 if (IS_ERR(opp)) {128126 rcu_read_unlock();129127 dev_err(dvfs_info->dev,130128 "failed to find valid OPP for %u KHZ\n",131131- freq_tbl[i].frequency);129129+ pos->frequency);132130 return PTR_ERR(opp);133131 }134132135135- freq = freq_tbl[i].frequency / 1000; /* In MHZ */133133+ freq = pos->frequency / 1000; /* In MHZ */136134 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK)137135 << P0_7_CPUCLKDEV_SHIFT;138136 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK)···155157 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT)156158 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT));157159158158- __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * i);160160+ __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 *161161+ (pos - freq_tbl));159162 }160163161164 rcu_read_unlock();···165166166167static void exynos_enable_dvfs(unsigned int cur_frequency)167168{168168- unsigned int tmp, i, cpu;169169+ unsigned int tmp, cpu;169170 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table;171171+ struct cpufreq_frequency_table *pos;170172 /* Disable DVFS */171173 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL);172174···182182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN);183183184184 /* Set initial performance index */185185- for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++)186186- if (freq_table[i].frequency == cur_frequency)185185+ cpufreq_for_each_entry(pos, freq_table)186186+ if (pos->frequency == cur_frequency)187187 break;188188189189- if (freq_table[i].frequency == CPUFREQ_TABLE_END) {189189+ if (pos->frequency == CPUFREQ_TABLE_END) {190190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n");191191 /* Assign the highest frequency */192192- i = 0;193193- cur_frequency = freq_table[i].frequency;192192+ pos = freq_table;193193+ cur_frequency = pos->frequency;194194 }195195196196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ",···199199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) {200200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);201201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT);202202- tmp |= (i << C0_3_PSTATE_NEW_SHIFT);202202+ tmp |= ((pos - freq_table) << C0_3_PSTATE_NEW_SHIFT);203203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);204204 }205205
+25-31
drivers/cpufreq/freq_table.c
···2121int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,2222 struct cpufreq_frequency_table *table)2323{2424+ struct cpufreq_frequency_table *pos;2425 unsigned int min_freq = ~0;2526 unsigned int max_freq = 0;2626- unsigned int i;2727+ unsigned int freq;27282828- for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {2929- unsigned int freq = table[i].frequency;3030- if (freq == CPUFREQ_ENTRY_INVALID) {3131- pr_debug("table entry %u is invalid, skipping\n", i);2929+ cpufreq_for_each_valid_entry(pos, table) {3030+ freq = pos->frequency;32313333- continue;3434- }3532 if (!cpufreq_boost_enabled()3636- && (table[i].flags & CPUFREQ_BOOST_FREQ))3333+ && (pos->flags & CPUFREQ_BOOST_FREQ))3734 continue;38353939- pr_debug("table entry %u: %u kHz\n", i, freq);3636+ pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);4037 if (freq < min_freq)4138 min_freq = freq;4239 if (freq > max_freq)···5457int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,5558 struct cpufreq_frequency_table *table)5659{5757- unsigned int next_larger = ~0, freq, i = 0;6060+ struct cpufreq_frequency_table *pos;6161+ unsigned int freq, next_larger = ~0;5862 bool found = false;59636064 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",···63656466 cpufreq_verify_within_cpu_limits(policy);65676666- for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) {6767- if (freq == CPUFREQ_ENTRY_INVALID)6868- continue;6868+ cpufreq_for_each_valid_entry(pos, table) {6969+ freq = pos->frequency;7070+6971 if ((freq >= policy->min) && (freq <= policy->max)) {7072 found = true;7173 break;···116118 .driver_data = ~0,117119 .frequency = 0,118120 };119119- unsigned int i;121121+ struct cpufreq_frequency_table *pos;122122+ unsigned int freq, i = 0;120123121124 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",122125 target_freq, relation, policy->cpu);···131132 break;132133 }133134134134- for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {135135- unsigned int freq = table[i].frequency;136136- if (freq == CPUFREQ_ENTRY_INVALID)137137- continue;135135+ cpufreq_for_each_valid_entry(pos, table) {136136+ freq = pos->frequency;137137+138138+ i = pos - table;138139 if ((freq < policy->min) || (freq > policy->max))139140 continue;140141 switch (relation) {···183184int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,184185 unsigned int freq)185186{186186- struct cpufreq_frequency_table *table;187187- int i;187187+ struct cpufreq_frequency_table *pos, *table;188188189189 table = cpufreq_frequency_get_table(policy->cpu);190190 if (unlikely(!table)) {···191193 return -ENOENT;192194 }193195194194- for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {195195- if (table[i].frequency == freq)196196- return i;197197- }196196+ cpufreq_for_each_valid_entry(pos, table)197197+ if (pos->frequency == freq)198198+ return pos - table;198199199200 return -EINVAL;200201}···205208static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,206209 bool show_boost)207210{208208- unsigned int i = 0;209211 ssize_t count = 0;210210- struct cpufreq_frequency_table *table = policy->freq_table;212212+ struct cpufreq_frequency_table *pos, *table = policy->freq_table;211213212214 if (!table)213215 return -ENODEV;214216215215- for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {216216- if (table[i].frequency == CPUFREQ_ENTRY_INVALID)217217- continue;217217+ cpufreq_for_each_valid_entry(pos, table) {218218 /*219219 * show_boost = true and driver_data = BOOST freq220220 * display BOOST freqs···223229 * show_boost = false and driver_data != BOOST freq224230 * display NON BOOST freqs225231 */226226- if (show_boost ^ (table[i].flags & CPUFREQ_BOOST_FREQ))232232+ if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ))227233 continue;228234229229- count += sprintf(&buf[count], "%d ", table[i].frequency);235235+ count += sprintf(&buf[count], "%d ", pos->frequency);230236 }231237 count += sprintf(&buf[count], "\n");232238
···136136137137static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)138138{139139+ struct cpufreq_frequency_table *pos;139140 const u32 *max_freqp;140141 u32 max_freq;141141- int i, cur_astate;142142+ int cur_astate;142143 struct resource res;143144 struct device_node *cpu, *dn;144145 int err = -ENODEV;···198197 pr_debug("initializing frequency table\n");199198200199 /* initialize frequency table */201201- for (i=0; pas_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) {202202- pas_freqs[i].frequency =203203- get_astate_freq(pas_freqs[i].driver_data) * 100000;204204- pr_debug("%d: %d\n", i, pas_freqs[i].frequency);200200+ cpufreq_for_each_entry(pos, pas_freqs) {201201+ pos->frequency = get_astate_freq(pos->driver_data) * 100000;202202+ pr_debug("%d: %d\n", (int)(pos - pas_freqs), pos->frequency);205203 }206204207205 cur_astate = get_cur_astate(policy->cpu);
+7-7
drivers/cpufreq/powernow-k6.c
···151151152152static int powernow_k6_cpu_init(struct cpufreq_policy *policy)153153{154154+ struct cpufreq_frequency_table *pos;154155 unsigned int i, f;155156 unsigned khz;156157···169168 }170169 }171170 if (param_max_multiplier) {172172- for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {173173- if (clock_ratio[i].driver_data == param_max_multiplier) {171171+ cpufreq_for_each_entry(pos, clock_ratio)172172+ if (pos->driver_data == param_max_multiplier) {174173 max_multiplier = param_max_multiplier;175174 goto have_max_multiplier;176175 }177177- }178176 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");179177 return -EINVAL;180178 }···201201 param_busfreq = busfreq * 10;202202203203 /* table init */204204- for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {205205- f = clock_ratio[i].driver_data;204204+ cpufreq_for_each_entry(pos, clock_ratio) {205205+ f = pos->driver_data;206206 if (f > max_multiplier)207207- clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID;207207+ pos->frequency = CPUFREQ_ENTRY_INVALID;208208 else209209- clock_ratio[i].frequency = busfreq * f;209209+ pos->frequency = busfreq * f;210210 }211211212212 /* cpuinfo and default policy values */
+5-4
drivers/cpufreq/ppc_cbe_cpufreq.c
···67676868static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)6969{7070+ struct cpufreq_frequency_table *pos;7071 const u32 *max_freqp;7172 u32 max_freq;7272- int i, cur_pmode;7373+ int cur_pmode;7374 struct device_node *cpu;74757576 cpu = of_get_cpu_node(policy->cpu, NULL);···103102 pr_debug("initializing frequency table\n");104103105104 /* initialize frequency table */106106- for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) {107107- cbe_freqs[i].frequency = max_freq / cbe_freqs[i].driver_data;108108- pr_debug("%d: %d\n", i, cbe_freqs[i].frequency);105105+ cpufreq_for_each_entry(pos, cbe_freqs) {106106+ pos->frequency = max_freq / pos->driver_data;107107+ pr_debug("%d: %d\n", (int)(pos - cbe_freqs), pos->frequency);109108 }110109111110 /* if DEBUG is enabled set_pmode() measures the latency
+17-23
drivers/cpufreq/s3c2416-cpufreq.c
···266266static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)267267{268268 int count, v, i, found;269269- struct cpufreq_frequency_table *freq;269269+ struct cpufreq_frequency_table *pos;270270 struct s3c2416_dvfs *dvfs;271271272272 count = regulator_count_voltages(s3c_freq->vddarm);···275275 return;276276 }277277278278- freq = s3c_freq->freq_table;279279- while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) {280280- if (freq->frequency == CPUFREQ_ENTRY_INVALID)281281- continue;278278+ if (!count)279279+ goto out;282280283283- dvfs = &s3c2416_dvfs_table[freq->driver_data];281281+ cpufreq_for_each_valid_entry(pos, s3c_freq->freq_table) {282282+ dvfs = &s3c2416_dvfs_table[pos->driver_data];284283 found = 0;285284286285 /* Check only the min-voltage, more is always ok on S3C2416 */···291292292293 if (!found) {293294 pr_debug("cpufreq: %dkHz unsupported by regulator\n",294294- freq->frequency);295295- freq->frequency = CPUFREQ_ENTRY_INVALID;295295+ pos->frequency);296296+ pos->frequency = CPUFREQ_ENTRY_INVALID;296297 }297297-298298- freq++;299298 }300299300300+out:301301 /* Guessed */302302 s3c_freq->regulator_latency = 1 * 1000 * 1000;303303}···336338static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)337339{338340 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq;339339- struct cpufreq_frequency_table *freq;341341+ struct cpufreq_frequency_table *pos;340342 struct clk *msysclk;341343 unsigned long rate;342344 int ret;···425427 s3c_freq->regulator_latency = 0;426428#endif427429428428- freq = s3c_freq->freq_table;429429- while (freq->frequency != CPUFREQ_TABLE_END) {430430+ cpufreq_for_each_entry(pos, s3c_freq->freq_table) {430431 /* special handling for dvs mode */431431- if (freq->driver_data == 0) {432432+ if (pos->driver_data == 0) {432433 if (!s3c_freq->hclk) {433434 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n",434434- freq->frequency);435435- freq->frequency = CPUFREQ_ENTRY_INVALID;435435+ pos->frequency);436436+ pos->frequency = CPUFREQ_ENTRY_INVALID;436437 } else {437437- freq++;438438 continue;439439 }440440 }441441442442 /* Check for frequencies we can generate */443443 rate = clk_round_rate(s3c_freq->armdiv,444444- freq->frequency * 1000);444444+ pos->frequency * 1000);445445 rate /= 1000;446446- if (rate != freq->frequency) {446446+ if (rate != pos->frequency) {447447 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n",448448- freq->frequency, rate);449449- freq->frequency = CPUFREQ_ENTRY_INVALID;448448+ pos->frequency, rate);449449+ pos->frequency = CPUFREQ_ENTRY_INVALID;450450 }451451-452452- freq++;453451 }454452455453 /* Datasheet says PLL stabalisation time must be at least 300us,
+5-10
drivers/cpufreq/s3c64xx-cpufreq.c
···118118 pr_err("Unable to check supported voltages\n");119119 }120120121121- freq = s3c64xx_freq_table;122122- while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) {123123- if (freq->frequency == CPUFREQ_ENTRY_INVALID)124124- continue;121121+ if (!count)122122+ goto out;125123124124+ cpufreq_for_each_valid_entry(freq, s3c64xx_freq_table) {126125 dvfs = &s3c64xx_dvfs_table[freq->driver_data];127126 found = 0;128127···136137 freq->frequency);137138 freq->frequency = CPUFREQ_ENTRY_INVALID;138139 }139139-140140- freq++;141140 }142141142142+out:143143 /* Guess based on having to do an I2C/SPI write; in future we144144 * will be able to query the regulator performance here. */145145 regulator_latency = 1 * 1000 * 1000;···177179 }178180#endif179181180180- freq = s3c64xx_freq_table;181181- while (freq->frequency != CPUFREQ_TABLE_END) {182182+ cpufreq_for_each_entry(freq, s3c64xx_freq_table) {182183 unsigned long r;183184184185 /* Check for frequencies we can generate */···193196 * frequency is the maximum we can support. */194197 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000)195198 freq->frequency = CPUFREQ_ENTRY_INVALID;196196-197197- freq++;198199 }199200200201 /* Datasheet says PLL stabalisation time (if we were to use
+8-11
drivers/mfd/db8500-prcmu.c
···1734173417351735static long round_armss_rate(unsigned long rate)17361736{17371737+ struct cpufreq_frequency_table *pos;17371738 long freq = 0;17381738- int i = 0;1739173917401740 /* cpufreq table frequencies is in KHz. */17411741 rate = rate / 1000;1742174217431743 /* Find the corresponding arm opp from the cpufreq table. */17441744- while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) {17451745- freq = db8500_cpufreq_table[i].frequency;17441744+ cpufreq_for_each_entry(pos, db8500_cpufreq_table) {17451745+ freq = pos->frequency;17461746 if (freq == rate)17471747 break;17481748- i++;17491748 }1750174917511750 /* Return the last valid value, even if a match was not found. */···1885188618861887static int set_armss_rate(unsigned long rate)18871888{18881888- int i = 0;18891889+ struct cpufreq_frequency_table *pos;1889189018901891 /* cpufreq table frequencies is in KHz. */18911892 rate = rate / 1000;1892189318931894 /* Find the corresponding arm opp from the cpufreq table. */18941894- while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) {18951895- if (db8500_cpufreq_table[i].frequency == rate)18951895+ cpufreq_for_each_entry(pos, db8500_cpufreq_table)18961896+ if (pos->frequency == rate)18961897 break;18971897- i++;18981898- }1899189819001900- if (db8500_cpufreq_table[i].frequency != rate)18991899+ if (pos->frequency != rate)19011900 return -EINVAL;1902190119031902 /* Set the new arm opp. */19041904- return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].driver_data);19031903+ return db8500_prcmu_set_arm_opp(pos->driver_data);19051904}1906190519071906static int set_plldsi_rate(unsigned long rate)
+5-9
drivers/net/irda/sh_sir.c
···217217static u32 sh_sir_find_sclk(struct clk *irda_clk)218218{219219 struct cpufreq_frequency_table *freq_table = irda_clk->freq_table;220220+ struct cpufreq_frequency_table *pos;220221 struct clk *pclk = clk_get(NULL, "peripheral_clk");221222 u32 limit, min = 0xffffffff, tmp;222222- int i, index = 0;223223+ int index = 0;223224224225 limit = clk_get_rate(pclk);225226 clk_put(pclk);226227227228 /* IrDA can not set over peripheral_clk */228228- for (i = 0;229229- freq_table[i].frequency != CPUFREQ_TABLE_END;230230- i++) {231231- u32 freq = freq_table[i].frequency;232232-233233- if (freq == CPUFREQ_ENTRY_INVALID)234234- continue;229229+ cpufreq_for_each_valid_entry(pos, freq_table) {230230+ u32 freq = pos->frequency;235231236232 /* IrDA should not over peripheral_clk */237233 if (freq > limit)···236240 tmp = freq % SCLK_BASE;237241 if (tmp < min) {238242 min = tmp;239239- index = i;243243+ index = pos - freq_table;240244 }241245 }242246
+5-15
drivers/sh/clk/core.c
···196196 struct cpufreq_frequency_table *freq_table,197197 unsigned long rate)198198{199199- int i;199199+ struct cpufreq_frequency_table *pos;200200201201- for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {202202- unsigned long freq = freq_table[i].frequency;203203-204204- if (freq == CPUFREQ_ENTRY_INVALID)205205- continue;206206-207207- if (freq == rate)208208- return i;209209- }201201+ cpufreq_for_each_valid_entry(pos, freq_table)202202+ if (pos->frequency == rate)203203+ return pos - freq_table;210204211205 return -ENOENT;212206}···569575 return abs(target - *best_freq);570576 }571577572572- for (freq = parent->freq_table; freq->frequency != CPUFREQ_TABLE_END;573573- freq++) {574574- if (freq->frequency == CPUFREQ_ENTRY_INVALID)575575- continue;576576-578578+ cpufreq_for_each_valid_entry(freq, parent->freq_table) {577579 if (unlikely(freq->frequency / target <= div_min - 1)) {578580 unsigned long freq_max;579581
+13-20
drivers/thermal/cpu_cooling.c
···144144 unsigned int *output,145145 enum cpufreq_cooling_property property)146146{147147- int i, j;147147+ int i;148148 unsigned long max_level = 0, level = 0;149149 unsigned int freq = CPUFREQ_ENTRY_INVALID;150150 int descend = -1;151151- struct cpufreq_frequency_table *table =151151+ struct cpufreq_frequency_table *pos, *table =152152 cpufreq_frequency_get_table(cpu);153153154154 if (!output)···157157 if (!table)158158 return -EINVAL;159159160160- for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {161161- /* ignore invalid entries */162162- if (table[i].frequency == CPUFREQ_ENTRY_INVALID)163163- continue;164164-160160+ cpufreq_for_each_valid_entry(pos, table) {165161 /* ignore duplicate entry */166166- if (freq == table[i].frequency)162162+ if (freq == pos->frequency)167163 continue;168164169165 /* get the frequency order */170166 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)171171- descend = !!(freq > table[i].frequency);167167+ descend = freq > pos->frequency;172168173173- freq = table[i].frequency;169169+ freq = pos->frequency;174170 max_level++;175171 }176172···186190 if (property == GET_FREQ)187191 level = descend ? input : (max_level - input);188192189189- for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {190190- /* ignore invalid entry */191191- if (table[i].frequency == CPUFREQ_ENTRY_INVALID)192192- continue;193193-193193+ i = 0;194194+ cpufreq_for_each_valid_entry(pos, table) {194195 /* ignore duplicate entry */195195- if (freq == table[i].frequency)196196+ if (freq == pos->frequency)196197 continue;197198198199 /* now we have a valid frequency entry */199199- freq = table[i].frequency;200200+ freq = pos->frequency;200201201202 if (property == GET_LEVEL && (unsigned int)input == freq) {202203 /* get level by frequency */203203- *output = descend ? j : (max_level - j);204204+ *output = descend ? i : (max_level - i);204205 return 0;205206 }206206- if (property == GET_FREQ && level == j) {207207+ if (property == GET_FREQ && level == i) {207208 /* get frequency by level */208209 *output = freq;209210 return 0;210211 }211211- j++;212212+ i++;212213 }213214214215 return -EINVAL;
+21
include/linux/cpufreq.h
···468468 * order */469469};470470471471+bool cpufreq_next_valid(struct cpufreq_frequency_table **pos);472472+473473+/*474474+ * cpufreq_for_each_entry - iterate over a cpufreq_frequency_table475475+ * @pos: the cpufreq_frequency_table * to use as a loop cursor.476476+ * @table: the cpufreq_frequency_table * to iterate over.477477+ */478478+479479+#define cpufreq_for_each_entry(pos, table) \480480+ for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++)481481+482482+/*483483+ * cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table484484+ * excluding CPUFREQ_ENTRY_INVALID frequencies.485485+ * @pos: the cpufreq_frequency_table * to use as a loop cursor.486486+ * @table: the cpufreq_frequency_table * to iterate over.487487+ */488488+489489+#define cpufreq_for_each_valid_entry(pos, table) \490490+ for (pos = table; cpufreq_next_valid(&pos); pos++)491491+471492int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,472493 struct cpufreq_frequency_table *table);473494