aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorStratos Karafotis <stratosk@semaphore.gr>2014-04-25 16:15:38 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-04-29 18:06:21 -0400
commit041526f915a90b2b628cd0253e2c85da8040276d (patch)
tree0d2a0c45505584f942bd30723af84d2c09261de3 /drivers
parent27e289dce29764e488c1e13e9aa6950cad1f4aab (diff)
cpufreq: Use cpufreq_for_each_* macros for frequency table iteration
The cpufreq core now supports the cpufreq_for_each_entry and cpufreq_for_each_valid_entry macros helpers for iteration over the cpufreq_frequency_table, so use them. It should have no functional changes. Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr> Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c9
-rw-r--r--drivers/cpufreq/arm_big_little.c16
-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
14 files changed, 116 insertions, 146 deletions
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_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 d00e5d1abd25..f4024d4d3534 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -528,6 +528,7 @@ static int longhaul_get_ranges(void)
528 528
529static void longhaul_setup_voltagescaling(void) 529static void longhaul_setup_voltagescaling(void)
530{ 530{
531 struct cpufreq_frequency_table *freq_pos;
531 union msr_longhaul longhaul; 532 union msr_longhaul longhaul;
532 struct mV_pos minvid, maxvid, vid; 533 struct mV_pos minvid, maxvid, vid;
533 unsigned int j, speed, pos, kHz_step, numvscales; 534 unsigned int j, speed, pos, kHz_step, numvscales;
@@ -606,18 +607,16 @@ static void longhaul_setup_voltagescaling(void)
606 /* Calculate kHz for one voltage step */ 607 /* Calculate kHz for one voltage step */
607 kHz_step = (highest_speed - min_vid_speed) / numvscales; 608 kHz_step = (highest_speed - min_vid_speed) / numvscales;
608 609
609 j = 0; 610 cpufreq_for_each_entry(freq_pos, longhaul_table) {
610 while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { 611 speed = freq_pos->frequency;
611 speed = longhaul_table[j].frequency;
612 if (speed > min_vid_speed) 612 if (speed > min_vid_speed)
613 pos = (speed - min_vid_speed) / kHz_step + minvid.pos; 613 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
614 else 614 else
615 pos = minvid.pos; 615 pos = minvid.pos;
616 longhaul_table[j].driver_data |= mV_vrm_table[pos] << 8; 616 freq_pos->driver_data |= mV_vrm_table[pos] << 8;
617 vid = vrm_mV_table[mV_vrm_table[pos]]; 617 vid = vrm_mV_table[mV_vrm_table[pos]];
618 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", 618 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
619 speed, j, vid.mV); 619 speed, (int)(freq_pos - longhaul_table), vid.mV);
620 j++;
621 } 620 }
622 621
623 can_scale_voltage = 1; 622 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 49f120e1bc7b..a133236a0013 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -159,6 +159,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
159 159
160static int powernow_k6_cpu_init(struct cpufreq_policy *policy) 160static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
161{ 161{
162 struct cpufreq_frequency_table *pos;
162 unsigned int i, f; 163 unsigned int i, f;
163 unsigned khz; 164 unsigned khz;
164 165
@@ -176,12 +177,11 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
176 } 177 }
177 } 178 }
178 if (param_max_multiplier) { 179 if (param_max_multiplier) {
179 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 180 cpufreq_for_each_entry(pos, clock_ratio)
180 if (clock_ratio[i].driver_data == param_max_multiplier) { 181 if (pos->driver_data == param_max_multiplier) {
181 max_multiplier = param_max_multiplier; 182 max_multiplier = param_max_multiplier;
182 goto have_max_multiplier; 183 goto have_max_multiplier;
183 } 184 }
184 }
185 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n"); 185 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");
186 return -EINVAL; 186 return -EINVAL;
187 } 187 }
@@ -209,12 +209,12 @@ have_busfreq:
209 param_busfreq = busfreq * 10; 209 param_busfreq = busfreq * 10;
210 210
211 /* table init */ 211 /* table init */
212 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 212 cpufreq_for_each_entry(pos, clock_ratio) {
213 f = clock_ratio[i].driver_data; 213 f = pos->driver_data;
214 if (f > max_multiplier) 214 if (f > max_multiplier)
215 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 215 pos->frequency = CPUFREQ_ENTRY_INVALID;
216 else 216 else
217 clock_ratio[i].frequency = busfreq * f; 217 pos->frequency = busfreq * f;
218 } 218 }
219 219
220 /* cpuinfo and default policy values */ 220 /* 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