Commit f8e94f0e authored by Dominik Brodowski's avatar Dominik Brodowski Committed by Linus Torvalds

[PATCH] cpufreq: powernow-k6 cleanup

Clean up searching for best frequency, and add one safety check.
parent c2654518
...@@ -144,6 +144,9 @@ static int powernow_k6_verify(struct cpufreq_policy *policy) ...@@ -144,6 +144,9 @@ static int powernow_k6_verify(struct cpufreq_policy *policy)
policy->max = clock_ratio[j] * busfreq; policy->max = clock_ratio[j] * busfreq;
cpufreq_verify_within_limits(policy, (20 * busfreq),
(max_multiplier * busfreq));
return 0; return 0;
} }
...@@ -156,53 +159,44 @@ static int powernow_k6_verify(struct cpufreq_policy *policy) ...@@ -156,53 +159,44 @@ static int powernow_k6_verify(struct cpufreq_policy *policy)
*/ */
static int powernow_k6_setpolicy (struct cpufreq_policy *policy) static int powernow_k6_setpolicy (struct cpufreq_policy *policy)
{ {
unsigned int number_states = 0; unsigned int i;
unsigned int i, j=4; unsigned int optimal;
if (!powernow_driver) if (!powernow_driver || !policy || policy->cpu)
return -EINVAL; return -EINVAL;
for (i=0; i<8; i++) switch(policy->policy) {
if ((policy->min <= (busfreq * clock_ratio[i])) &&
(policy->max >= (busfreq * clock_ratio[i])))
{
number_states++;
j = i;
}
if (number_states == 1) {
/* if only one state is within the limit borders, it
is easily detected and set */
powernow_k6_set_state(j);
return 0;
}
/* more than one state within limit */
switch (policy->policy) {
case CPUFREQ_POLICY_POWERSAVE: case CPUFREQ_POLICY_POWERSAVE:
j = 6; optimal = 6;
for (i=0; i<8; i++)
if ((policy->min <= (busfreq * clock_ratio[i])) &&
(policy->max >= (busfreq * clock_ratio[i])) &&
(clock_ratio[i] < clock_ratio[j]))
j = i;
break; break;
case CPUFREQ_POLICY_PERFORMANCE: case CPUFREQ_POLICY_PERFORMANCE:
j = 4; optimal = max_multiplier;
for (i=0; i<8; i++)
if ((policy->min <= (busfreq * clock_ratio[i])) &&
(policy->max >= (busfreq * clock_ratio[i])) &&
(clock_ratio[i] > clock_ratio[j]))
j = i;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
for (i=0;i<8;i++) {
unsigned int freq = busfreq * clock_ratio[i];
if (clock_ratio[i] > max_multiplier) if (clock_ratio[i] > max_multiplier)
return -EINVAL; continue;
if ((freq > policy->max) ||
(freq < policy->min))
continue;
switch(policy->policy) {
case CPUFREQ_POLICY_POWERSAVE:
if (freq < (clock_ratio[optimal] * busfreq))
optimal = i;
break;
case CPUFREQ_POLICY_PERFORMANCE:
if (freq > (clock_ratio[optimal] * busfreq))
optimal = i;
break;
}
}
powernow_k6_set_state(optimal);
powernow_k6_set_state(j);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment