diff options
Diffstat (limited to 'drivers/cpufreq/freq_table.c')
-rw-r--r-- | drivers/cpufreq/freq_table.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 08e7bbcf6d73..1632981c4b25 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c | |||
@@ -21,22 +21,19 @@ | |||
21 | int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, | 21 | int 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); | |||
57 | int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, | 54 | int 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,15 +131,19 @@ 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; |
140 | if (freq == target_freq) { | ||
141 | optimal.driver_data = i; | ||
142 | break; | ||
143 | } | ||
141 | switch (relation) { | 144 | switch (relation) { |
142 | case CPUFREQ_RELATION_H: | 145 | case CPUFREQ_RELATION_H: |
143 | if (freq <= target_freq) { | 146 | if (freq < target_freq) { |
144 | if (freq >= optimal.frequency) { | 147 | if (freq >= optimal.frequency) { |
145 | optimal.frequency = freq; | 148 | optimal.frequency = freq; |
146 | optimal.driver_data = i; | 149 | optimal.driver_data = i; |
@@ -153,7 +156,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, | |||
153 | } | 156 | } |
154 | break; | 157 | break; |
155 | case CPUFREQ_RELATION_L: | 158 | case CPUFREQ_RELATION_L: |
156 | if (freq >= target_freq) { | 159 | if (freq > target_freq) { |
157 | if (freq <= optimal.frequency) { | 160 | if (freq <= optimal.frequency) { |
158 | optimal.frequency = freq; | 161 | optimal.frequency = freq; |
159 | optimal.driver_data = i; | 162 | optimal.driver_data = i; |
@@ -184,8 +187,7 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); | |||
184 | int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, | 187 | int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, |
185 | unsigned int freq) | 188 | unsigned int freq) |
186 | { | 189 | { |
187 | struct cpufreq_frequency_table *table; | 190 | struct cpufreq_frequency_table *pos, *table; |
188 | int i; | ||
189 | 191 | ||
190 | table = cpufreq_frequency_get_table(policy->cpu); | 192 | table = cpufreq_frequency_get_table(policy->cpu); |
191 | if (unlikely(!table)) { | 193 | if (unlikely(!table)) { |
@@ -193,10 +195,9 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, | |||
193 | return -ENOENT; | 195 | return -ENOENT; |
194 | } | 196 | } |
195 | 197 | ||
196 | for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { | 198 | cpufreq_for_each_valid_entry(pos, table) |
197 | if (table[i].frequency == freq) | 199 | if (pos->frequency == freq) |
198 | return i; | 200 | return pos - table; |
199 | } | ||
200 | 201 | ||
201 | return -EINVAL; | 202 | return -EINVAL; |
202 | } | 203 | } |
@@ -208,16 +209,13 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index); | |||
208 | static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, | 209 | static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, |
209 | bool show_boost) | 210 | bool show_boost) |
210 | { | 211 | { |
211 | unsigned int i = 0; | ||
212 | ssize_t count = 0; | 212 | ssize_t count = 0; |
213 | struct cpufreq_frequency_table *table = policy->freq_table; | 213 | struct cpufreq_frequency_table *pos, *table = policy->freq_table; |
214 | 214 | ||
215 | if (!table) | 215 | if (!table) |
216 | return -ENODEV; | 216 | return -ENODEV; |
217 | 217 | ||
218 | for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { | 218 | cpufreq_for_each_valid_entry(pos, table) { |
219 | if (table[i].frequency == CPUFREQ_ENTRY_INVALID) | ||
220 | continue; | ||
221 | /* | 219 | /* |
222 | * show_boost = true and driver_data = BOOST freq | 220 | * show_boost = true and driver_data = BOOST freq |
223 | * display BOOST freqs | 221 | * display BOOST freqs |
@@ -229,10 +227,10 @@ static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, | |||
229 | * show_boost = false and driver_data != BOOST freq | 227 | * show_boost = false and driver_data != BOOST freq |
230 | * display NON BOOST freqs | 228 | * display NON BOOST freqs |
231 | */ | 229 | */ |
232 | if (show_boost ^ (table[i].flags & CPUFREQ_BOOST_FREQ)) | 230 | if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ)) |
233 | continue; | 231 | continue; |
234 | 232 | ||
235 | count += sprintf(&buf[count], "%d ", table[i].frequency); | 233 | count += sprintf(&buf[count], "%d ", pos->frequency); |
236 | } | 234 | } |
237 | count += sprintf(&buf[count], "\n"); | 235 | count += sprintf(&buf[count], "\n"); |
238 | 236 | ||