forked from mirrors/linux
		
	cpufreq: add cpufreq_driver_resolve_freq()
Cpufreq governors may need to know what a particular target frequency maps to in the driver without necessarily wanting to set the frequency. Support this operation via a new cpufreq API, cpufreq_driver_resolve_freq(). This API returns the lowest driver frequency equal or greater than the target frequency (CPUFREQ_RELATION_L), subject to any policy (min/max) or driver limitations. The mapping is also cached in the policy so that a subsequent fast_switch operation can avoid repeating the same lookup. The API will call a new cpufreq driver callback, resolve_freq(), if it has been registered by the driver. Otherwise the frequency is resolved via cpufreq_frequency_table_target(). Rather than require ->target() style drivers to provide a resolve_freq() callback it is left to the caller to ensure that the driver implements this callback if necessary to use cpufreq_driver_resolve_freq(). Suggested-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Steve Muckle <smuckle@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
		
							parent
							
								
									da7de91c3e
								
							
						
					
					
						commit
						e3c0623608
					
				
					 2 changed files with 41 additions and 0 deletions
				
			
		| 
						 | 
					@ -492,6 +492,29 @@ void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
 | 
					EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
 | 
				
			||||||
 | 
					 * one.
 | 
				
			||||||
 | 
					 * @target_freq: target frequency to resolve.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The target to driver frequency mapping is cached in the policy.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Return: Lowest driver-supported frequency greater than or equal to the
 | 
				
			||||||
 | 
					 * given target_freq, subject to policy (min/max) and driver limitations.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
 | 
				
			||||||
 | 
										 unsigned int target_freq)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						target_freq = clamp_val(target_freq, policy->min, policy->max);
 | 
				
			||||||
 | 
						policy->cached_target_freq = target_freq;
 | 
				
			||||||
 | 
						if (cpufreq_driver->resolve_freq)
 | 
				
			||||||
 | 
							return cpufreq_driver->resolve_freq(policy, target_freq);
 | 
				
			||||||
 | 
						policy->cached_resolved_idx =
 | 
				
			||||||
 | 
							cpufreq_frequency_table_target(policy, target_freq,
 | 
				
			||||||
 | 
										       CPUFREQ_RELATION_L);
 | 
				
			||||||
 | 
						return policy->freq_table[policy->cached_resolved_idx].frequency;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*********************************************************************
 | 
					/*********************************************************************
 | 
				
			||||||
 *                          SYSFS INTERFACE                          *
 | 
					 *                          SYSFS INTERFACE                          *
 | 
				
			||||||
 *********************************************************************/
 | 
					 *********************************************************************/
 | 
				
			||||||
| 
						 | 
					@ -2199,6 +2222,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
 | 
				
			||||||
	policy->min = new_policy->min;
 | 
						policy->min = new_policy->min;
 | 
				
			||||||
	policy->max = new_policy->max;
 | 
						policy->max = new_policy->max;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						policy->cached_target_freq = UINT_MAX;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pr_debug("new min and max freqs are %u - %u kHz\n",
 | 
						pr_debug("new min and max freqs are %u - %u kHz\n",
 | 
				
			||||||
		 policy->min, policy->max);
 | 
							 policy->min, policy->max);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,6 +120,10 @@ struct cpufreq_policy {
 | 
				
			||||||
	bool			fast_switch_possible;
 | 
						bool			fast_switch_possible;
 | 
				
			||||||
	bool			fast_switch_enabled;
 | 
						bool			fast_switch_enabled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						 /* Cached frequency lookup from cpufreq_driver_resolve_freq. */
 | 
				
			||||||
 | 
						unsigned int cached_target_freq;
 | 
				
			||||||
 | 
						int cached_resolved_idx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Synchronization for frequency transitions */
 | 
						/* Synchronization for frequency transitions */
 | 
				
			||||||
	bool			transition_ongoing; /* Tracks transition status */
 | 
						bool			transition_ongoing; /* Tracks transition status */
 | 
				
			||||||
	spinlock_t		transition_lock;
 | 
						spinlock_t		transition_lock;
 | 
				
			||||||
| 
						 | 
					@ -270,6 +274,16 @@ struct cpufreq_driver {
 | 
				
			||||||
					unsigned int index);
 | 
										unsigned int index);
 | 
				
			||||||
	unsigned int	(*fast_switch)(struct cpufreq_policy *policy,
 | 
						unsigned int	(*fast_switch)(struct cpufreq_policy *policy,
 | 
				
			||||||
				       unsigned int target_freq);
 | 
									       unsigned int target_freq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Caches and returns the lowest driver-supported frequency greater than
 | 
				
			||||||
 | 
						 * or equal to the target frequency, subject to any driver limitations.
 | 
				
			||||||
 | 
						 * Does not set the frequency. Only to be implemented for drivers with
 | 
				
			||||||
 | 
						 * target().
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						unsigned int	(*resolve_freq)(struct cpufreq_policy *policy,
 | 
				
			||||||
 | 
										unsigned int target_freq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION
 | 
						 * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION
 | 
				
			||||||
	 * unset.
 | 
						 * unset.
 | 
				
			||||||
| 
						 | 
					@ -501,6 +515,8 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
 | 
				
			||||||
int __cpufreq_driver_target(struct cpufreq_policy *policy,
 | 
					int __cpufreq_driver_target(struct cpufreq_policy *policy,
 | 
				
			||||||
				   unsigned int target_freq,
 | 
									   unsigned int target_freq,
 | 
				
			||||||
				   unsigned int relation);
 | 
									   unsigned int relation);
 | 
				
			||||||
 | 
					unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
 | 
				
			||||||
 | 
										 unsigned int target_freq);
 | 
				
			||||||
int cpufreq_register_governor(struct cpufreq_governor *governor);
 | 
					int cpufreq_register_governor(struct cpufreq_governor *governor);
 | 
				
			||||||
void cpufreq_unregister_governor(struct cpufreq_governor *governor);
 | 
					void cpufreq_unregister_governor(struct cpufreq_governor *governor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue