aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-30 18:50:47 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-30 18:50:47 -0400
commit89d4f82aa5ccf08dc28dc8b463844e6d7eed591b (patch)
tree91e7e6ff2c5eda51bb48528244387f32c000433e
parent6712d2931933ada259b82f06c03a855b19937074 (diff)
parent4229e1c61a4a7ac21d5d0790f6add1c9b98d33e7 (diff)
Merge branch 'cpufreq-macros' into pm-cpufreq
-rw-r--r--Documentation/cpu-freq/cpu-drivers.txt19
-rw-r--r--arch/arm/mach-davinci/da850.c9
-rw-r--r--arch/mips/loongson/lemote-2f/clock.c16
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c9
-rw-r--r--drivers/cpufreq/arm_big_little.c16
-rw-r--r--drivers/cpufreq/cpufreq.c11
-rw-r--r--drivers/cpufreq/cpufreq_stats.c24
-rw-r--r--drivers/cpufreq/dbx500-cpufreq.c8
-rw-r--r--drivers/cpufreq/elanfreq.c9
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c11
-rw-r--r--drivers/cpufreq/exynos5440-cpufreq.c30
-rw-r--r--drivers/cpufreq/freq_table.c56
-rw-r--r--drivers/cpufreq/longhaul.c11
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c10
-rw-r--r--drivers/cpufreq/powernow-k6.c14
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c9
-rw-r--r--drivers/cpufreq/s3c2416-cpufreq.c40
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c15
-rw-r--r--drivers/mfd/db8500-prcmu.c19
-rw-r--r--drivers/net/irda/sh_sir.c14
-rw-r--r--drivers/sh/clk/core.c20
-rw-r--r--drivers/thermal/cpu_cooling.c33
-rw-r--r--include/linux/cpufreq.h21
23 files changed, 208 insertions, 216 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/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index 85399c98f84a..45ce065e7170 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -1092,20 +1092,21 @@ int da850_register_cpufreq(char *async_clk)
1092 1092
1093static int da850_round_armrate(struct clk *clk, unsigned long rate) 1093static int da850_round_armrate(struct clk *clk, unsigned long rate)
1094{ 1094{
1095 int i, ret = 0, diff; 1095 int ret = 0, diff;
1096 unsigned int best = (unsigned int) -1; 1096 unsigned int best = (unsigned int) -1;
1097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table; 1097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table;
1098 struct cpufreq_frequency_table *pos;
1098 1099
1099 rate /= 1000; /* convert to kHz */ 1100 rate /= 1000; /* convert to kHz */
1100 1101
1101 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 1102 cpufreq_for_each_entry(pos, table) {
1102 diff = table[i].frequency - rate; 1103 diff = pos->frequency - rate;
1103 if (diff < 0) 1104 if (diff < 0)
1104 diff = -diff; 1105 diff = -diff;
1105 1106
1106 if (diff < best) { 1107 if (diff < best) {
1107 best = diff; 1108 best = diff;
1108 ret = table[i].frequency; 1109 ret = pos->frequency;
1109 } 1110 }
1110 } 1111 }
1111 1112
diff --git a/arch/mips/loongson/lemote-2f/clock.c b/arch/mips/loongson/lemote-2f/clock.c
index e1f427f4f5f3..1eed38e28b1e 100644
--- a/arch/mips/loongson/lemote-2f/clock.c
+++ b/arch/mips/loongson/lemote-2f/clock.c
@@ -91,9 +91,9 @@ EXPORT_SYMBOL(clk_put);
91 91
92int clk_set_rate(struct clk *clk, unsigned long rate) 92int clk_set_rate(struct clk *clk, unsigned long rate)
93{ 93{
94 struct cpufreq_frequency_table *pos;
94 int ret = 0; 95 int ret = 0;
95 int regval; 96 int regval;
96 int i;
97 97
98 if (likely(clk->ops && clk->ops->set_rate)) { 98 if (likely(clk->ops && clk->ops->set_rate)) {
99 unsigned long flags; 99 unsigned long flags;
@@ -106,22 +106,16 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
106 if (unlikely(clk->flags & CLK_RATE_PROPAGATES)) 106 if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
107 propagate_rate(clk); 107 propagate_rate(clk);
108 108
109 for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END; 109 cpufreq_for_each_valid_entry(pos, loongson2_clockmod_table)
110 i++) { 110 if (rate == pos->frequency)
111 if (loongson2_clockmod_table[i].frequency ==
112 CPUFREQ_ENTRY_INVALID)
113 continue;
114 if (rate == loongson2_clockmod_table[i].frequency)
115 break; 111 break;
116 } 112 if (rate != pos->frequency)
117 if (rate != loongson2_clockmod_table[i].frequency)
118 return -ENOTSUPP; 113 return -ENOTSUPP;
119 114
120 clk->rate = rate; 115 clk->rate = rate;
121 116
122 regval = LOONGSON_CHIPCFG0; 117 regval = LOONGSON_CHIPCFG0;
123 regval = (regval & ~0x7) | 118 regval = (regval & ~0x7) | (pos->driver_data - 1);
124 (loongson2_clockmod_table[i].driver_data - 1);
125 LOONGSON_CHIPCFG0 = regval; 119 LOONGSON_CHIPCFG0 = regval;
126 120
127 return ret; 121 return ret;
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 000e4e0afd7e..b0c18ed8d83f 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -213,7 +213,7 @@ static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
213 213
214static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) 214static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
215{ 215{
216 int i; 216 struct cpufreq_frequency_table *pos;
217 struct acpi_processor_performance *perf; 217 struct acpi_processor_performance *perf;
218 218
219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) 219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
@@ -223,10 +223,9 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
223 223
224 perf = data->acpi_data; 224 perf = data->acpi_data;
225 225
226 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { 226 cpufreq_for_each_entry(pos, data->freq_table)
227 if (msr == perf->states[data->freq_table[i].driver_data].status) 227 if (msr == perf->states[pos->driver_data].status)
228 return data->freq_table[i].frequency; 228 return pos->frequency;
229 }
230 return data->freq_table[0].frequency; 229 return data->freq_table[0].frequency;
231} 230}
232 231
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index bad2ed317ba2..1f4d4e315057 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -226,22 +226,22 @@ static inline u32 get_table_count(struct cpufreq_frequency_table *table)
226/* get the minimum frequency in the cpufreq_frequency_table */ 226/* get the minimum frequency in the cpufreq_frequency_table */
227static inline u32 get_table_min(struct cpufreq_frequency_table *table) 227static inline u32 get_table_min(struct cpufreq_frequency_table *table)
228{ 228{
229 int i; 229 struct cpufreq_frequency_table *pos;
230 uint32_t min_freq = ~0; 230 uint32_t min_freq = ~0;
231 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 231 cpufreq_for_each_entry(pos, table)
232 if (table[i].frequency < min_freq) 232 if (pos->frequency < min_freq)
233 min_freq = table[i].frequency; 233 min_freq = pos->frequency;
234 return min_freq; 234 return min_freq;
235} 235}
236 236
237/* get the maximum frequency in the cpufreq_frequency_table */ 237/* get the maximum frequency in the cpufreq_frequency_table */
238static inline u32 get_table_max(struct cpufreq_frequency_table *table) 238static inline u32 get_table_max(struct cpufreq_frequency_table *table)
239{ 239{
240 int i; 240 struct cpufreq_frequency_table *pos;
241 uint32_t max_freq = 0; 241 uint32_t max_freq = 0;
242 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 242 cpufreq_for_each_entry(pos, table)
243 if (table[i].frequency > max_freq) 243 if (pos->frequency > max_freq)
244 max_freq = table[i].frequency; 244 max_freq = pos->frequency;
245 return max_freq; 245 return max_freq;
246} 246}
247 247
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/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index ecaaebf969fc..0cd9b4dcef99 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -182,11 +182,11 @@ static void cpufreq_stats_free_table(unsigned int cpu)
182 182
183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) 183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
184{ 184{
185 unsigned int i, j, count = 0, ret = 0; 185 unsigned int i, count = 0, ret = 0;
186 struct cpufreq_stats *stat; 186 struct cpufreq_stats *stat;
187 unsigned int alloc_size; 187 unsigned int alloc_size;
188 unsigned int cpu = policy->cpu; 188 unsigned int cpu = policy->cpu;
189 struct cpufreq_frequency_table *table; 189 struct cpufreq_frequency_table *pos, *table;
190 190
191 table = cpufreq_frequency_get_table(cpu); 191 table = cpufreq_frequency_get_table(cpu);
192 if (unlikely(!table)) 192 if (unlikely(!table))
@@ -205,12 +205,8 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
205 stat->cpu = cpu; 205 stat->cpu = cpu;
206 per_cpu(cpufreq_stats_table, cpu) = stat; 206 per_cpu(cpufreq_stats_table, cpu) = stat;
207 207
208 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 208 cpufreq_for_each_valid_entry(pos, table)
209 unsigned int freq = table[i].frequency;
210 if (freq == CPUFREQ_ENTRY_INVALID)
211 continue;
212 count++; 209 count++;
213 }
214 210
215 alloc_size = count * sizeof(int) + count * sizeof(u64); 211 alloc_size = count * sizeof(int) + count * sizeof(u64);
216 212
@@ -228,15 +224,11 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
228#ifdef CONFIG_CPU_FREQ_STAT_DETAILS 224#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
229 stat->trans_table = stat->freq_table + count; 225 stat->trans_table = stat->freq_table + count;
230#endif 226#endif
231 j = 0; 227 i = 0;
232 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 228 cpufreq_for_each_valid_entry(pos, table)
233 unsigned int freq = table[i].frequency; 229 if (freq_table_get_index(stat, pos->frequency) == -1)
234 if (freq == CPUFREQ_ENTRY_INVALID) 230 stat->freq_table[i++] = pos->frequency;
235 continue; 231 stat->state_num = i;
236 if (freq_table_get_index(stat, freq) == -1)
237 stat->freq_table[j++] = freq;
238 }
239 stat->state_num = j;
240 spin_lock(&cpufreq_stats_lock); 232 spin_lock(&cpufreq_stats_lock);
241 stat->last_time = get_jiffies_64(); 233 stat->last_time = get_jiffies_64();
242 stat->last_index = freq_table_get_index(stat, policy->cur); 234 stat->last_index = freq_table_get_index(stat, policy->cur);
diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c
index 412a78bb0c94..4bebc1b5db48 100644
--- a/drivers/cpufreq/dbx500-cpufreq.c
+++ b/drivers/cpufreq/dbx500-cpufreq.c
@@ -45,7 +45,7 @@ static struct cpufreq_driver dbx500_cpufreq_driver = {
45 45
46static int dbx500_cpufreq_probe(struct platform_device *pdev) 46static int dbx500_cpufreq_probe(struct platform_device *pdev)
47{ 47{
48 int i = 0; 48 struct cpufreq_frequency_table *pos;
49 49
50 freq_table = dev_get_platdata(&pdev->dev); 50 freq_table = dev_get_platdata(&pdev->dev);
51 if (!freq_table) { 51 if (!freq_table) {
@@ -60,10 +60,8 @@ static int dbx500_cpufreq_probe(struct platform_device *pdev)
60 } 60 }
61 61
62 pr_info("dbx500-cpufreq: Available frequencies:\n"); 62 pr_info("dbx500-cpufreq: Available frequencies:\n");
63 while (freq_table[i].frequency != CPUFREQ_TABLE_END) { 63 cpufreq_for_each_entry(pos, freq_table)
64 pr_info(" %d Mhz\n", freq_table[i].frequency/1000); 64 pr_info(" %d Mhz\n", pos->frequency / 1000);
65 i++;
66 }
67 65
68 return cpufreq_register_driver(&dbx500_cpufreq_driver); 66 return cpufreq_register_driver(&dbx500_cpufreq_driver);
69} 67}
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index 7f5d2a68c353..1c06e786c9ba 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -147,7 +147,7 @@ static int elanfreq_target(struct cpufreq_policy *policy,
147static int elanfreq_cpu_init(struct cpufreq_policy *policy) 147static int elanfreq_cpu_init(struct cpufreq_policy *policy)
148{ 148{
149 struct cpuinfo_x86 *c = &cpu_data(0); 149 struct cpuinfo_x86 *c = &cpu_data(0);
150 unsigned int i; 150 struct cpufreq_frequency_table *pos;
151 151
152 /* capability check */ 152 /* capability check */
153 if ((c->x86_vendor != X86_VENDOR_AMD) || 153 if ((c->x86_vendor != X86_VENDOR_AMD) ||
@@ -159,10 +159,9 @@ static int elanfreq_cpu_init(struct cpufreq_policy *policy)
159 max_freq = elanfreq_get_cpu_frequency(0); 159 max_freq = elanfreq_get_cpu_frequency(0);
160 160
161 /* table init */ 161 /* table init */
162 for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { 162 cpufreq_for_each_entry(pos, elanfreq_table)
163 if (elanfreq_table[i].frequency > max_freq) 163 if (pos->frequency > max_freq)
164 elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; 164 pos->frequency = CPUFREQ_ENTRY_INVALID;
165 }
166 165
167 /* cpuinfo and default policy values */ 166 /* cpuinfo and default policy values */
168 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 167 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index f99cfe24e7bc..9c132550d910 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -29,17 +29,16 @@ static unsigned int locking_frequency;
29static int exynos_cpufreq_get_index(unsigned int freq) 29static int exynos_cpufreq_get_index(unsigned int freq)
30{ 30{
31 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table; 31 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;
32 int index; 32 struct cpufreq_frequency_table *pos;
33 33
34 for (index = 0; 34 cpufreq_for_each_entry(pos, freq_table)
35 freq_table[index].frequency != CPUFREQ_TABLE_END; index++) 35 if (pos->frequency == freq)
36 if (freq_table[index].frequency == freq)
37 break; 36 break;
38 37
39 if (freq_table[index].frequency == CPUFREQ_TABLE_END) 38 if (pos->frequency == CPUFREQ_TABLE_END)
40 return -EINVAL; 39 return -EINVAL;
41 40
42 return index; 41 return pos - freq_table;
43} 42}
44 43
45static int exynos_cpufreq_scale(unsigned int target_freq) 44static int exynos_cpufreq_scale(unsigned int target_freq)
diff --git a/drivers/cpufreq/exynos5440-cpufreq.c b/drivers/cpufreq/exynos5440-cpufreq.c
index a6b8214d7b77..f33f25b483ca 100644
--- a/drivers/cpufreq/exynos5440-cpufreq.c
+++ b/drivers/cpufreq/exynos5440-cpufreq.c
@@ -114,25 +114,23 @@ static struct cpufreq_freqs freqs;
114 114
115static int init_div_table(void) 115static int init_div_table(void)
116{ 116{
117 struct cpufreq_frequency_table *freq_tbl = dvfs_info->freq_table; 117 struct cpufreq_frequency_table *pos, *freq_tbl = dvfs_info->freq_table;
118 unsigned int tmp, clk_div, ema_div, freq, volt_id; 118 unsigned int tmp, clk_div, ema_div, freq, volt_id;
119 int i = 0;
120 struct dev_pm_opp *opp; 119 struct dev_pm_opp *opp;
121 120
122 rcu_read_lock(); 121 rcu_read_lock();
123 for (i = 0; freq_tbl[i].frequency != CPUFREQ_TABLE_END; i++) { 122 cpufreq_for_each_entry(pos, freq_tbl) {
124
125 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev, 123 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev,
126 freq_tbl[i].frequency * 1000, true); 124 pos->frequency * 1000, true);
127 if (IS_ERR(opp)) { 125 if (IS_ERR(opp)) {
128 rcu_read_unlock(); 126 rcu_read_unlock();
129 dev_err(dvfs_info->dev, 127 dev_err(dvfs_info->dev,
130 "failed to find valid OPP for %u KHZ\n", 128 "failed to find valid OPP for %u KHZ\n",
131 freq_tbl[i].frequency); 129 pos->frequency);
132 return PTR_ERR(opp); 130 return PTR_ERR(opp);
133 } 131 }
134 132
135 freq = freq_tbl[i].frequency / 1000; /* In MHZ */ 133 freq = pos->frequency / 1000; /* In MHZ */
136 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK) 134 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK)
137 << P0_7_CPUCLKDEV_SHIFT; 135 << P0_7_CPUCLKDEV_SHIFT;
138 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK) 136 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK)
@@ -157,7 +155,8 @@ static int init_div_table(void)
157 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT) 155 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT)
158 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT)); 156 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT));
159 157
160 __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * i); 158 __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 *
159 (pos - freq_tbl));
161 } 160 }
162 161
163 rcu_read_unlock(); 162 rcu_read_unlock();
@@ -166,8 +165,9 @@ static int init_div_table(void)
166 165
167static void exynos_enable_dvfs(unsigned int cur_frequency) 166static void exynos_enable_dvfs(unsigned int cur_frequency)
168{ 167{
169 unsigned int tmp, i, cpu; 168 unsigned int tmp, cpu;
170 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table; 169 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table;
170 struct cpufreq_frequency_table *pos;
171 /* Disable DVFS */ 171 /* Disable DVFS */
172 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL); 172 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL);
173 173
@@ -182,15 +182,15 @@ static void exynos_enable_dvfs(unsigned int cur_frequency)
182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN); 182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN);
183 183
184 /* Set initial performance index */ 184 /* Set initial performance index */
185 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) 185 cpufreq_for_each_entry(pos, freq_table)
186 if (freq_table[i].frequency == cur_frequency) 186 if (pos->frequency == cur_frequency)
187 break; 187 break;
188 188
189 if (freq_table[i].frequency == CPUFREQ_TABLE_END) { 189 if (pos->frequency == CPUFREQ_TABLE_END) {
190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n"); 190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n");
191 /* Assign the highest frequency */ 191 /* Assign the highest frequency */
192 i = 0; 192 pos = freq_table;
193 cur_frequency = freq_table[i].frequency; 193 cur_frequency = pos->frequency;
194 } 194 }
195 195
196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ", 196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ",
@@ -199,7 +199,7 @@ static void exynos_enable_dvfs(unsigned int cur_frequency)
199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) { 199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) {
200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);
201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT); 201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT);
202 tmp |= (i << C0_3_PSTATE_NEW_SHIFT); 202 tmp |= ((pos - freq_table) << C0_3_PSTATE_NEW_SHIFT);
203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);
204 } 204 }
205 205
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 08e7bbcf6d73..8e518c689393 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -21,22 +21,19 @@
21int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 21int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
22 struct cpufreq_frequency_table *table) 22 struct cpufreq_frequency_table *table)
23{ 23{
24 struct cpufreq_frequency_table *pos;
24 unsigned int min_freq = ~0; 25 unsigned int min_freq = ~0;
25 unsigned int max_freq = 0; 26 unsigned int max_freq = 0;
26 unsigned int i; 27 unsigned int freq;
27 28
28 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 29 cpufreq_for_each_valid_entry(pos, table) {
29 unsigned int freq = table[i].frequency; 30 freq = pos->frequency;
30 if (freq == CPUFREQ_ENTRY_INVALID) {
31 pr_debug("table entry %u is invalid, skipping\n", i);
32 31
33 continue;
34 }
35 if (!cpufreq_boost_enabled() 32 if (!cpufreq_boost_enabled()
36 && (table[i].flags & CPUFREQ_BOOST_FREQ)) 33 && (pos->flags & CPUFREQ_BOOST_FREQ))
37 continue; 34 continue;
38 35
39 pr_debug("table entry %u: %u kHz\n", i, freq); 36 pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);
40 if (freq < min_freq) 37 if (freq < min_freq)
41 min_freq = freq; 38 min_freq = freq;
42 if (freq > max_freq) 39 if (freq > max_freq)
@@ -57,7 +54,8 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_cpuinfo);
57int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, 54int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
58 struct cpufreq_frequency_table *table) 55 struct cpufreq_frequency_table *table)
59{ 56{
60 unsigned int next_larger = ~0, freq, i = 0; 57 struct cpufreq_frequency_table *pos;
58 unsigned int freq, next_larger = ~0;
61 bool found = false; 59 bool found = false;
62 60
63 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", 61 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
@@ -65,9 +63,9 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
65 63
66 cpufreq_verify_within_cpu_limits(policy); 64 cpufreq_verify_within_cpu_limits(policy);
67 65
68 for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) { 66 cpufreq_for_each_valid_entry(pos, table) {
69 if (freq == CPUFREQ_ENTRY_INVALID) 67 freq = pos->frequency;
70 continue; 68
71 if ((freq >= policy->min) && (freq <= policy->max)) { 69 if ((freq >= policy->min) && (freq <= policy->max)) {
72 found = true; 70 found = true;
73 break; 71 break;
@@ -118,7 +116,8 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
118 .driver_data = ~0, 116 .driver_data = ~0,
119 .frequency = 0, 117 .frequency = 0,
120 }; 118 };
121 unsigned int i; 119 struct cpufreq_frequency_table *pos;
120 unsigned int freq, i = 0;
122 121
123 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", 122 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
124 target_freq, relation, policy->cpu); 123 target_freq, relation, policy->cpu);
@@ -132,10 +131,10 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
132 break; 131 break;
133 } 132 }
134 133
135 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 134 cpufreq_for_each_valid_entry(pos, table) {
136 unsigned int freq = table[i].frequency; 135 freq = pos->frequency;
137 if (freq == CPUFREQ_ENTRY_INVALID) 136
138 continue; 137 i = pos - table;
139 if ((freq < policy->min) || (freq > policy->max)) 138 if ((freq < policy->min) || (freq > policy->max))
140 continue; 139 continue;
141 switch (relation) { 140 switch (relation) {
@@ -184,8 +183,7 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
184int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, 183int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
185 unsigned int freq) 184 unsigned int freq)
186{ 185{
187 struct cpufreq_frequency_table *table; 186 struct cpufreq_frequency_table *pos, *table;
188 int i;
189 187
190 table = cpufreq_frequency_get_table(policy->cpu); 188 table = cpufreq_frequency_get_table(policy->cpu);
191 if (unlikely(!table)) { 189 if (unlikely(!table)) {
@@ -193,10 +191,9 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
193 return -ENOENT; 191 return -ENOENT;
194 } 192 }
195 193
196 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 194 cpufreq_for_each_valid_entry(pos, table)
197 if (table[i].frequency == freq) 195 if (pos->frequency == freq)
198 return i; 196 return pos - table;
199 }
200 197
201 return -EINVAL; 198 return -EINVAL;
202} 199}
@@ -208,16 +205,13 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index);
208static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, 205static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
209 bool show_boost) 206 bool show_boost)
210{ 207{
211 unsigned int i = 0;
212 ssize_t count = 0; 208 ssize_t count = 0;
213 struct cpufreq_frequency_table *table = policy->freq_table; 209 struct cpufreq_frequency_table *pos, *table = policy->freq_table;
214 210
215 if (!table) 211 if (!table)
216 return -ENODEV; 212 return -ENODEV;
217 213
218 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 214 cpufreq_for_each_valid_entry(pos, table) {
219 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
220 continue;
221 /* 215 /*
222 * show_boost = true and driver_data = BOOST freq 216 * show_boost = true and driver_data = BOOST freq
223 * display BOOST freqs 217 * display BOOST freqs
@@ -229,10 +223,10 @@ static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
229 * show_boost = false and driver_data != BOOST freq 223 * show_boost = false and driver_data != BOOST freq
230 * display NON BOOST freqs 224 * display NON BOOST freqs
231 */ 225 */
232 if (show_boost ^ (table[i].flags & CPUFREQ_BOOST_FREQ)) 226 if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ))
233 continue; 227 continue;
234 228
235 count += sprintf(&buf[count], "%d ", table[i].frequency); 229 count += sprintf(&buf[count], "%d ", pos->frequency);
236 } 230 }
237 count += sprintf(&buf[count], "\n"); 231 count += sprintf(&buf[count], "\n");
238 232
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 5c4369b5d834..c913906a719e 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -530,6 +530,7 @@ static int longhaul_get_ranges(void)
530 530
531static void longhaul_setup_voltagescaling(void) 531static void longhaul_setup_voltagescaling(void)
532{ 532{
533 struct cpufreq_frequency_table *freq_pos;
533 union msr_longhaul longhaul; 534 union msr_longhaul longhaul;
534 struct mV_pos minvid, maxvid, vid; 535 struct mV_pos minvid, maxvid, vid;
535 unsigned int j, speed, pos, kHz_step, numvscales; 536 unsigned int j, speed, pos, kHz_step, numvscales;
@@ -608,18 +609,16 @@ static void longhaul_setup_voltagescaling(void)
608 /* Calculate kHz for one voltage step */ 609 /* Calculate kHz for one voltage step */
609 kHz_step = (highest_speed - min_vid_speed) / numvscales; 610 kHz_step = (highest_speed - min_vid_speed) / numvscales;
610 611
611 j = 0; 612 cpufreq_for_each_entry(freq_pos, longhaul_table) {
612 while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { 613 speed = freq_pos->frequency;
613 speed = longhaul_table[j].frequency;
614 if (speed > min_vid_speed) 614 if (speed > min_vid_speed)
615 pos = (speed - min_vid_speed) / kHz_step + minvid.pos; 615 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
616 else 616 else
617 pos = minvid.pos; 617 pos = minvid.pos;
618 longhaul_table[j].driver_data |= mV_vrm_table[pos] << 8; 618 freq_pos->driver_data |= mV_vrm_table[pos] << 8;
619 vid = vrm_mV_table[mV_vrm_table[pos]]; 619 vid = vrm_mV_table[mV_vrm_table[pos]];
620 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", 620 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
621 speed, j, vid.mV); 621 speed, (int)(freq_pos - longhaul_table), vid.mV);
622 j++;
623 } 622 }
624 623
625 can_scale_voltage = 1; 624 can_scale_voltage = 1;
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index 84c84b5f0f3a..35dd4d7ffee0 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -136,9 +136,10 @@ void restore_astate(int cpu)
136 136
137static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) 137static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
138{ 138{
139 struct cpufreq_frequency_table *pos;
139 const u32 *max_freqp; 140 const u32 *max_freqp;
140 u32 max_freq; 141 u32 max_freq;
141 int i, cur_astate; 142 int cur_astate;
142 struct resource res; 143 struct resource res;
143 struct device_node *cpu, *dn; 144 struct device_node *cpu, *dn;
144 int err = -ENODEV; 145 int err = -ENODEV;
@@ -197,10 +198,9 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
197 pr_debug("initializing frequency table\n"); 198 pr_debug("initializing frequency table\n");
198 199
199 /* initialize frequency table */ 200 /* initialize frequency table */
200 for (i=0; pas_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 201 cpufreq_for_each_entry(pos, pas_freqs) {
201 pas_freqs[i].frequency = 202 pos->frequency = get_astate_freq(pos->driver_data) * 100000;
202 get_astate_freq(pas_freqs[i].driver_data) * 100000; 203 pr_debug("%d: %d\n", (int)(pos - pas_freqs), pos->frequency);
203 pr_debug("%d: %d\n", i, pas_freqs[i].frequency);
204 } 204 }
205 205
206 cur_astate = get_cur_astate(policy->cpu); 206 cur_astate = get_cur_astate(policy->cpu);
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index 78904e6ca4a0..c8012bc86910 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -151,6 +151,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
151 151
152static int powernow_k6_cpu_init(struct cpufreq_policy *policy) 152static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
153{ 153{
154 struct cpufreq_frequency_table *pos;
154 unsigned int i, f; 155 unsigned int i, f;
155 unsigned khz; 156 unsigned khz;
156 157
@@ -168,12 +169,11 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
168 } 169 }
169 } 170 }
170 if (param_max_multiplier) { 171 if (param_max_multiplier) {
171 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 172 cpufreq_for_each_entry(pos, clock_ratio)
172 if (clock_ratio[i].driver_data == param_max_multiplier) { 173 if (pos->driver_data == param_max_multiplier) {
173 max_multiplier = param_max_multiplier; 174 max_multiplier = param_max_multiplier;
174 goto have_max_multiplier; 175 goto have_max_multiplier;
175 } 176 }
176 }
177 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n"); 177 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");
178 return -EINVAL; 178 return -EINVAL;
179 } 179 }
@@ -201,12 +201,12 @@ have_busfreq:
201 param_busfreq = busfreq * 10; 201 param_busfreq = busfreq * 10;
202 202
203 /* table init */ 203 /* table init */
204 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 204 cpufreq_for_each_entry(pos, clock_ratio) {
205 f = clock_ratio[i].driver_data; 205 f = pos->driver_data;
206 if (f > max_multiplier) 206 if (f > max_multiplier)
207 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 207 pos->frequency = CPUFREQ_ENTRY_INVALID;
208 else 208 else
209 clock_ratio[i].frequency = busfreq * f; 209 pos->frequency = busfreq * f;
210 } 210 }
211 211
212 /* cpuinfo and default policy values */ 212 /* cpuinfo and default policy values */
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index 5be8a48dba74..5a4c5a639f61 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -67,9 +67,10 @@ static int set_pmode(unsigned int cpu, unsigned int slow_mode)
67 67
68static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy) 68static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
69{ 69{
70 struct cpufreq_frequency_table *pos;
70 const u32 *max_freqp; 71 const u32 *max_freqp;
71 u32 max_freq; 72 u32 max_freq;
72 int i, cur_pmode; 73 int cur_pmode;
73 struct device_node *cpu; 74 struct device_node *cpu;
74 75
75 cpu = of_get_cpu_node(policy->cpu, NULL); 76 cpu = of_get_cpu_node(policy->cpu, NULL);
@@ -102,9 +103,9 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
102 pr_debug("initializing frequency table\n"); 103 pr_debug("initializing frequency table\n");
103 104
104 /* initialize frequency table */ 105 /* initialize frequency table */
105 for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 106 cpufreq_for_each_entry(pos, cbe_freqs) {
106 cbe_freqs[i].frequency = max_freq / cbe_freqs[i].driver_data; 107 pos->frequency = max_freq / pos->driver_data;
107 pr_debug("%d: %d\n", i, cbe_freqs[i].frequency); 108 pr_debug("%d: %d\n", (int)(pos - cbe_freqs), pos->frequency);
108 } 109 }
109 110
110 /* if DEBUG is enabled set_pmode() measures the latency 111 /* if DEBUG is enabled set_pmode() measures the latency
diff --git a/drivers/cpufreq/s3c2416-cpufreq.c b/drivers/cpufreq/s3c2416-cpufreq.c
index 4626f90559b5..2fd53eaaec20 100644
--- a/drivers/cpufreq/s3c2416-cpufreq.c
+++ b/drivers/cpufreq/s3c2416-cpufreq.c
@@ -266,7 +266,7 @@ out:
266static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq) 266static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
267{ 267{
268 int count, v, i, found; 268 int count, v, i, found;
269 struct cpufreq_frequency_table *freq; 269 struct cpufreq_frequency_table *pos;
270 struct s3c2416_dvfs *dvfs; 270 struct s3c2416_dvfs *dvfs;
271 271
272 count = regulator_count_voltages(s3c_freq->vddarm); 272 count = regulator_count_voltages(s3c_freq->vddarm);
@@ -275,12 +275,11 @@ static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
275 return; 275 return;
276 } 276 }
277 277
278 freq = s3c_freq->freq_table; 278 if (!count)
279 while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 279 goto out;
280 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
281 continue;
282 280
283 dvfs = &s3c2416_dvfs_table[freq->driver_data]; 281 cpufreq_for_each_valid_entry(pos, s3c_freq->freq_table) {
282 dvfs = &s3c2416_dvfs_table[pos->driver_data];
284 found = 0; 283 found = 0;
285 284
286 /* Check only the min-voltage, more is always ok on S3C2416 */ 285 /* Check only the min-voltage, more is always ok on S3C2416 */
@@ -292,13 +291,12 @@ static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
292 291
293 if (!found) { 292 if (!found) {
294 pr_debug("cpufreq: %dkHz unsupported by regulator\n", 293 pr_debug("cpufreq: %dkHz unsupported by regulator\n",
295 freq->frequency); 294 pos->frequency);
296 freq->frequency = CPUFREQ_ENTRY_INVALID; 295 pos->frequency = CPUFREQ_ENTRY_INVALID;
297 } 296 }
298
299 freq++;
300 } 297 }
301 298
299out:
302 /* Guessed */ 300 /* Guessed */
303 s3c_freq->regulator_latency = 1 * 1000 * 1000; 301 s3c_freq->regulator_latency = 1 * 1000 * 1000;
304} 302}
@@ -338,7 +336,7 @@ static struct notifier_block s3c2416_cpufreq_reboot_notifier = {
338static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy) 336static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)
339{ 337{
340 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq; 338 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq;
341 struct cpufreq_frequency_table *freq; 339 struct cpufreq_frequency_table *pos;
342 struct clk *msysclk; 340 struct clk *msysclk;
343 unsigned long rate; 341 unsigned long rate;
344 int ret; 342 int ret;
@@ -427,31 +425,27 @@ static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)
427 s3c_freq->regulator_latency = 0; 425 s3c_freq->regulator_latency = 0;
428#endif 426#endif
429 427
430 freq = s3c_freq->freq_table; 428 cpufreq_for_each_entry(pos, s3c_freq->freq_table) {
431 while (freq->frequency != CPUFREQ_TABLE_END) {
432 /* special handling for dvs mode */ 429 /* special handling for dvs mode */
433 if (freq->driver_data == 0) { 430 if (pos->driver_data == 0) {
434 if (!s3c_freq->hclk) { 431 if (!s3c_freq->hclk) {
435 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n", 432 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n",
436 freq->frequency); 433 pos->frequency);
437 freq->frequency = CPUFREQ_ENTRY_INVALID; 434 pos->frequency = CPUFREQ_ENTRY_INVALID;
438 } else { 435 } else {
439 freq++;
440 continue; 436 continue;
441 } 437 }
442 } 438 }
443 439
444 /* Check for frequencies we can generate */ 440 /* Check for frequencies we can generate */
445 rate = clk_round_rate(s3c_freq->armdiv, 441 rate = clk_round_rate(s3c_freq->armdiv,
446 freq->frequency * 1000); 442 pos->frequency * 1000);
447 rate /= 1000; 443 rate /= 1000;
448 if (rate != freq->frequency) { 444 if (rate != pos->frequency) {
449 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n", 445 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n",
450 freq->frequency, rate); 446 pos->frequency, rate);
451 freq->frequency = CPUFREQ_ENTRY_INVALID; 447 pos->frequency = CPUFREQ_ENTRY_INVALID;
452 } 448 }
453
454 freq++;
455 } 449 }
456 450
457 /* Datasheet says PLL stabalisation time must be at least 300us, 451 /* Datasheet says PLL stabalisation time must be at least 300us,
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index ff7d3ecb85f0..176e84cc3991 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -118,11 +118,10 @@ static void __init s3c64xx_cpufreq_config_regulator(void)
118 pr_err("Unable to check supported voltages\n"); 118 pr_err("Unable to check supported voltages\n");
119 } 119 }
120 120
121 freq = s3c64xx_freq_table; 121 if (!count)
122 while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 122 goto out;
123 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
124 continue;
125 123
124 cpufreq_for_each_valid_entry(freq, s3c64xx_freq_table) {
126 dvfs = &s3c64xx_dvfs_table[freq->driver_data]; 125 dvfs = &s3c64xx_dvfs_table[freq->driver_data];
127 found = 0; 126 found = 0;
128 127
@@ -137,10 +136,9 @@ static void __init s3c64xx_cpufreq_config_regulator(void)
137 freq->frequency); 136 freq->frequency);
138 freq->frequency = CPUFREQ_ENTRY_INVALID; 137 freq->frequency = CPUFREQ_ENTRY_INVALID;
139 } 138 }
140
141 freq++;
142 } 139 }
143 140
141out:
144 /* Guess based on having to do an I2C/SPI write; in future we 142 /* Guess based on having to do an I2C/SPI write; in future we
145 * will be able to query the regulator performance here. */ 143 * will be able to query the regulator performance here. */
146 regulator_latency = 1 * 1000 * 1000; 144 regulator_latency = 1 * 1000 * 1000;
@@ -179,8 +177,7 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
179 } 177 }
180#endif 178#endif
181 179
182 freq = s3c64xx_freq_table; 180 cpufreq_for_each_entry(freq, s3c64xx_freq_table) {
183 while (freq->frequency != CPUFREQ_TABLE_END) {
184 unsigned long r; 181 unsigned long r;
185 182
186 /* Check for frequencies we can generate */ 183 /* Check for frequencies we can generate */
@@ -196,8 +193,6 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
196 * frequency is the maximum we can support. */ 193 * frequency is the maximum we can support. */
197 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000) 194 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000)
198 freq->frequency = CPUFREQ_ENTRY_INVALID; 195 freq->frequency = CPUFREQ_ENTRY_INVALID;
199
200 freq++;
201 } 196 }
202 197
203 /* Datasheet says PLL stabalisation time (if we were to use 198 /* Datasheet says PLL stabalisation time (if we were to use
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 7694e0700d34..b11fdd63eecd 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -1734,18 +1734,17 @@ static struct cpufreq_frequency_table db8500_cpufreq_table[] = {
1734 1734
1735static long round_armss_rate(unsigned long rate) 1735static long round_armss_rate(unsigned long rate)
1736{ 1736{
1737 struct cpufreq_frequency_table *pos;
1737 long freq = 0; 1738 long freq = 0;
1738 int i = 0;
1739 1739
1740 /* cpufreq table frequencies is in KHz. */ 1740 /* cpufreq table frequencies is in KHz. */
1741 rate = rate / 1000; 1741 rate = rate / 1000;
1742 1742
1743 /* Find the corresponding arm opp from the cpufreq table. */ 1743 /* Find the corresponding arm opp from the cpufreq table. */
1744 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1744 cpufreq_for_each_entry(pos, db8500_cpufreq_table) {
1745 freq = db8500_cpufreq_table[i].frequency; 1745 freq = pos->frequency;
1746 if (freq == rate) 1746 if (freq == rate)
1747 break; 1747 break;
1748 i++;
1749 } 1748 }
1750 1749
1751 /* Return the last valid value, even if a match was not found. */ 1750 /* Return the last valid value, even if a match was not found. */
@@ -1886,23 +1885,21 @@ static void set_clock_rate(u8 clock, unsigned long rate)
1886 1885
1887static int set_armss_rate(unsigned long rate) 1886static int set_armss_rate(unsigned long rate)
1888{ 1887{
1889 int i = 0; 1888 struct cpufreq_frequency_table *pos;
1890 1889
1891 /* cpufreq table frequencies is in KHz. */ 1890 /* cpufreq table frequencies is in KHz. */
1892 rate = rate / 1000; 1891 rate = rate / 1000;
1893 1892
1894 /* Find the corresponding arm opp from the cpufreq table. */ 1893 /* Find the corresponding arm opp from the cpufreq table. */
1895 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1894 cpufreq_for_each_entry(pos, db8500_cpufreq_table)
1896 if (db8500_cpufreq_table[i].frequency == rate) 1895 if (pos->frequency == rate)
1897 break; 1896 break;
1898 i++;
1899 }
1900 1897
1901 if (db8500_cpufreq_table[i].frequency != rate) 1898 if (pos->frequency != rate)
1902 return -EINVAL; 1899 return -EINVAL;
1903 1900
1904 /* Set the new arm opp. */ 1901 /* Set the new arm opp. */
1905 return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].driver_data); 1902 return db8500_prcmu_set_arm_opp(pos->driver_data);
1906} 1903}
1907 1904
1908static int set_plldsi_rate(unsigned long rate) 1905static int set_plldsi_rate(unsigned long rate)
diff --git a/drivers/net/irda/sh_sir.c b/drivers/net/irda/sh_sir.c
index cadf52e22464..e3fe9a286136 100644
--- a/drivers/net/irda/sh_sir.c
+++ b/drivers/net/irda/sh_sir.c
@@ -217,21 +217,17 @@ crc_init_out:
217static u32 sh_sir_find_sclk(struct clk *irda_clk) 217static u32 sh_sir_find_sclk(struct clk *irda_clk)
218{ 218{
219 struct cpufreq_frequency_table *freq_table = irda_clk->freq_table; 219 struct cpufreq_frequency_table *freq_table = irda_clk->freq_table;
220 struct cpufreq_frequency_table *pos;
220 struct clk *pclk = clk_get(NULL, "peripheral_clk"); 221 struct clk *pclk = clk_get(NULL, "peripheral_clk");
221 u32 limit, min = 0xffffffff, tmp; 222 u32 limit, min = 0xffffffff, tmp;
222 int i, index = 0; 223 int index = 0;
223 224
224 limit = clk_get_rate(pclk); 225 limit = clk_get_rate(pclk);
225 clk_put(pclk); 226 clk_put(pclk);
226 227
227 /* IrDA can not set over peripheral_clk */ 228 /* IrDA can not set over peripheral_clk */
228 for (i = 0; 229 cpufreq_for_each_valid_entry(pos, freq_table) {
229 freq_table[i].frequency != CPUFREQ_TABLE_END; 230 u32 freq = pos->frequency;
230 i++) {
231 u32 freq = freq_table[i].frequency;
232
233 if (freq == CPUFREQ_ENTRY_INVALID)
234 continue;
235 231
236 /* IrDA should not over peripheral_clk */ 232 /* IrDA should not over peripheral_clk */
237 if (freq > limit) 233 if (freq > limit)
@@ -240,7 +236,7 @@ static u32 sh_sir_find_sclk(struct clk *irda_clk)
240 tmp = freq % SCLK_BASE; 236 tmp = freq % SCLK_BASE;
241 if (tmp < min) { 237 if (tmp < min) {
242 min = tmp; 238 min = tmp;
243 index = i; 239 index = pos - freq_table;
244 } 240 }
245 } 241 }
246 242
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index 74727851820d..be56b22ca941 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -196,17 +196,11 @@ int clk_rate_table_find(struct clk *clk,
196 struct cpufreq_frequency_table *freq_table, 196 struct cpufreq_frequency_table *freq_table,
197 unsigned long rate) 197 unsigned long rate)
198{ 198{
199 int i; 199 struct cpufreq_frequency_table *pos;
200
201 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
202 unsigned long freq = freq_table[i].frequency;
203 200
204 if (freq == CPUFREQ_ENTRY_INVALID) 201 cpufreq_for_each_valid_entry(pos, freq_table)
205 continue; 202 if (pos->frequency == rate)
206 203 return pos - freq_table;
207 if (freq == rate)
208 return i;
209 }
210 204
211 return -ENOENT; 205 return -ENOENT;
212} 206}
@@ -575,11 +569,7 @@ long clk_round_parent(struct clk *clk, unsigned long target,
575 return abs(target - *best_freq); 569 return abs(target - *best_freq);
576 } 570 }
577 571
578 for (freq = parent->freq_table; freq->frequency != CPUFREQ_TABLE_END; 572 cpufreq_for_each_valid_entry(freq, parent->freq_table) {
579 freq++) {
580 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
581 continue;
582
583 if (unlikely(freq->frequency / target <= div_min - 1)) { 573 if (unlikely(freq->frequency / target <= div_min - 1)) {
584 unsigned long freq_max; 574 unsigned long freq_max;
585 575
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262c4bd2..84a75f89bf74 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -144,11 +144,11 @@ static int get_property(unsigned int cpu, unsigned long input,
144 unsigned int *output, 144 unsigned int *output,
145 enum cpufreq_cooling_property property) 145 enum cpufreq_cooling_property property)
146{ 146{
147 int i, j; 147 int i;
148 unsigned long max_level = 0, level = 0; 148 unsigned long max_level = 0, level = 0;
149 unsigned int freq = CPUFREQ_ENTRY_INVALID; 149 unsigned int freq = CPUFREQ_ENTRY_INVALID;
150 int descend = -1; 150 int descend = -1;
151 struct cpufreq_frequency_table *table = 151 struct cpufreq_frequency_table *pos, *table =
152 cpufreq_frequency_get_table(cpu); 152 cpufreq_frequency_get_table(cpu);
153 153
154 if (!output) 154 if (!output)
@@ -157,20 +157,16 @@ static int get_property(unsigned int cpu, unsigned long input,
157 if (!table) 157 if (!table)
158 return -EINVAL; 158 return -EINVAL;
159 159
160 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 160 cpufreq_for_each_valid_entry(pos, table) {
161 /* ignore invalid entries */
162 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
163 continue;
164
165 /* ignore duplicate entry */ 161 /* ignore duplicate entry */
166 if (freq == table[i].frequency) 162 if (freq == pos->frequency)
167 continue; 163 continue;
168 164
169 /* get the frequency order */ 165 /* get the frequency order */
170 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) 166 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
171 descend = !!(freq > table[i].frequency); 167 descend = freq > pos->frequency;
172 168
173 freq = table[i].frequency; 169 freq = pos->frequency;
174 max_level++; 170 max_level++;
175 } 171 }
176 172
@@ -190,29 +186,26 @@ static int get_property(unsigned int cpu, unsigned long input,
190 if (property == GET_FREQ) 186 if (property == GET_FREQ)
191 level = descend ? input : (max_level - input); 187 level = descend ? input : (max_level - input);
192 188
193 for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 189 i = 0;
194 /* ignore invalid entry */ 190 cpufreq_for_each_valid_entry(pos, table) {
195 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
196 continue;
197
198 /* ignore duplicate entry */ 191 /* ignore duplicate entry */
199 if (freq == table[i].frequency) 192 if (freq == pos->frequency)
200 continue; 193 continue;
201 194
202 /* now we have a valid frequency entry */ 195 /* now we have a valid frequency entry */
203 freq = table[i].frequency; 196 freq = pos->frequency;
204 197
205 if (property == GET_LEVEL && (unsigned int)input == freq) { 198 if (property == GET_LEVEL && (unsigned int)input == freq) {
206 /* get level by frequency */ 199 /* get level by frequency */
207 *output = descend ? j : (max_level - j); 200 *output = descend ? i : (max_level - i);
208 return 0; 201 return 0;
209 } 202 }
210 if (property == GET_FREQ && level == j) { 203 if (property == GET_FREQ && level == i) {
211 /* get frequency by level */ 204 /* get frequency by level */
212 *output = freq; 205 *output = freq;
213 return 0; 206 return 0;
214 } 207 }
215 j++; 208 i++;
216 } 209 }
217 210
218 return -EINVAL; 211 return -EINVAL;
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