Skip to content

Commit f9ccdec

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: Reuse cpufreq_driver_resolve_freq() in __cpufreq_driver_target()
__cpufreq_driver_target() open codes cpufreq_driver_resolve_freq(), lets make the former reuse the later. Separate out __resolve_freq() to accept relation as well as an argument and use it at both the locations. Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 3e0f897 commit f9ccdec

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,8 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
524524
}
525525
EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
526526

527-
/**
528-
* cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
529-
* one.
530-
* @policy: associated policy to interrogate
531-
* @target_freq: target frequency to resolve.
532-
*
533-
* The target to driver frequency mapping is cached in the policy.
534-
*
535-
* Return: Lowest driver-supported frequency greater than or equal to the
536-
* given target_freq, subject to policy (min/max) and driver limitations.
537-
*/
538-
unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
539-
unsigned int target_freq)
527+
static unsigned int __resolve_freq(struct cpufreq_policy *policy,
528+
unsigned int target_freq, unsigned int relation)
540529
{
541530
target_freq = clamp_val(target_freq, policy->min, policy->max);
542531
policy->cached_target_freq = target_freq;
@@ -545,7 +534,7 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
545534
unsigned int idx;
546535

547536
idx = cpufreq_frequency_table_target(policy, target_freq,
548-
CPUFREQ_RELATION_L);
537+
relation);
549538
policy->cached_resolved_idx = idx;
550539
return policy->freq_table[idx].frequency;
551540
}
@@ -555,6 +544,23 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
555544

556545
return target_freq;
557546
}
547+
548+
/**
549+
* cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
550+
* one.
551+
* @policy: associated policy to interrogate
552+
* @target_freq: target frequency to resolve.
553+
*
554+
* The target to driver frequency mapping is cached in the policy.
555+
*
556+
* Return: Lowest driver-supported frequency greater than or equal to the
557+
* given target_freq, subject to policy (min/max) and driver limitations.
558+
*/
559+
unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
560+
unsigned int target_freq)
561+
{
562+
return __resolve_freq(policy, target_freq, CPUFREQ_RELATION_L);
563+
}
558564
EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq);
559565

560566
unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)
@@ -2231,13 +2237,11 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
22312237
unsigned int relation)
22322238
{
22332239
unsigned int old_target_freq = target_freq;
2234-
int index;
22352240

22362241
if (cpufreq_disabled())
22372242
return -ENODEV;
22382243

2239-
/* Make sure that target_freq is within supported range */
2240-
target_freq = clamp_val(target_freq, policy->min, policy->max);
2244+
target_freq = __resolve_freq(policy, target_freq, relation);
22412245

22422246
pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
22432247
policy->cpu, target_freq, relation, old_target_freq);
@@ -2258,9 +2262,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
22582262
if (!cpufreq_driver->target_index)
22592263
return -EINVAL;
22602264

2261-
index = cpufreq_frequency_table_target(policy, target_freq, relation);
2262-
2263-
return __target_index(policy, index);
2265+
return __target_index(policy, policy->cached_resolved_idx);
22642266
}
22652267
EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
22662268

0 commit comments

Comments
 (0)