Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c0ebcf7 authored by Viresh Kumar's avatar Viresh Kumar Committed by Rafael J. Wysocki
Browse files

cpufreq: Implement light weight ->target_index() routine



Currently, the prototype of cpufreq_drivers target routines is:

int target(struct cpufreq_policy *policy, unsigned int target_freq,
		unsigned int relation);

And most of the drivers call cpufreq_frequency_table_target() to get a valid
index of their frequency table which is closest to the target_freq. And they
don't use target_freq and relation after that.

So, it makes sense to just do this work in cpufreq core before calling
cpufreq_frequency_table_target() and simply pass index instead. But this can be
done only with drivers which expose their frequency table with cpufreq core. For
others we need to stick with the old prototype of target() until those drivers
are converted to expose frequency tables.

This patch implements the new light weight prototype for target_index() routine.
It looks like this:

int target_index(struct cpufreq_policy *policy, unsigned int index);

CPUFreq core will call cpufreq_frequency_table_target() before calling this
routine and pass index to it. Because CPUFreq core now requires to call routines
present in freq_table.c CONFIG_CPU_FREQ_TABLE must be enabled all the time.

This also marks target() interface as deprecated. So, that new drivers avoid
using it. And Documentation is updated accordingly.

It also converts existing .target() to newly defined light weight
.target_index() routine for many driver.

Acked-by: default avatarHans-Christian Egtvedt <egtvedt@samfundet.no>
Acked-by: default avatarJesper Nilsson <jesper.nilsson@axis.com>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarRussell King <linux@arm.linux.org.uk>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Tested-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rjw@rjwysocki.net>
parent 6ddee424
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ Contents:
1.1  Initialization
1.2  Per-CPU Initialization
1.3  verify
1.4  target or setpolicy?
1.5  target
1.4  target/target_index or setpolicy?
1.5  target/target_index
1.6  setpolicy
2.   Frequency Table Helpers

@@ -56,7 +56,8 @@ cpufreq_driver.init - A pointer to the per-CPU initialization
cpufreq_driver.verify -		A pointer to a "verification" function.

cpufreq_driver.setpolicy _or_ 
cpufreq_driver.target -		See below on the differences.
cpufreq_driver.target/
target_index		-	See below on the differences.

And optionally

@@ -66,7 +67,7 @@ cpufreq_driver.resume - A pointer to a per-CPU resume function
				which is called with interrupts disabled
				and _before_ the pre-suspend frequency
				and/or policy is restored by a call to
				->target or ->setpolicy.
				->target/target_index or ->setpolicy.

cpufreq_driver.attr -		A pointer to a NULL-terminated list of
				"struct freq_attr" which allow to
@@ -103,8 +104,8 @@ policy->governor must contain the "default policy" for
				this CPU. A few moments later,
				cpufreq_driver.verify and either
				cpufreq_driver.setpolicy or
				cpufreq_driver.target is called with
				these values.
				cpufreq_driver.target/target_index is called
				with these values.

For setting some of these values (cpuinfo.min[max]_freq, policy->min[max]), the
frequency table helpers might be helpful. See the section 2 for more information
@@ -133,20 +134,28 @@ range) is within policy->min and policy->max. If necessary, increase
policy->max first, and only if this is no solution, decrease policy->min.


1.4 target or setpolicy?
1.4 target/target_index or setpolicy?
----------------------------

Most cpufreq drivers or even most cpu frequency scaling algorithms 
only allow the CPU to be set to one frequency. For these, you use the
->target call.
->target/target_index call.

Some cpufreq-capable processors switch the frequency between certain
limits on their own. These shall use the ->setpolicy call


1.4. target
1.4. target/target_index
-------------

The target_index call has two arguments: struct cpufreq_policy *policy,
and unsigned int index (into the exposed frequency table).

The CPUfreq driver must set the new frequency when called here. The
actual frequency must be determined by freq_table[index].frequency.

Deprecated:
----------
The target call has three arguments: struct cpufreq_policy *policy,
unsigned int target_frequency, unsigned int relation.

+2 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ Most cpufreq drivers (in fact, all except one, longrun) or even most
cpu frequency scaling algorithms only offer the CPU to be set to one
frequency. In order to offer dynamic frequency scaling, the cpufreq
core must be able to tell these drivers of a "target frequency". So
these specific drivers will be transformed to offer a "->target"
these specific drivers will be transformed to offer a "->target/target_index"
call instead of the existing "->setpolicy" call. For "longrun", all
stays the same, though.

@@ -71,7 +71,7 @@ CPU can be set to switch independently | CPU can only be set
		    /			       the limits of policy->{min,max}
		   /			            \
		  /				     \
	Using the ->setpolicy call,		 Using the ->target call,
	Using the ->setpolicy call,		 Using the ->target/target_index call,
	    the limits and the			  the frequency closest
	     "policy" is set.			  to target_freq is set.
						  It is assured that it
+0 −20
Original line number Diff line number Diff line
@@ -62,26 +62,6 @@ struct cpufreq_frequency_table sa11x0_freq_table[NR_FREQS+1] = {
	{ .frequency = CPUFREQ_TABLE_END, },
};

/* rounds up(!)  */
unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
{
	int i;

	for (i = 0; i < NR_FREQS; i++)
		if (sa11x0_freq_table[i].frequency >= khz)
			break;

	return i;
}

unsigned int sa11x0_ppcr_to_freq(unsigned int idx)
{
	unsigned int freq = 0;
	if (idx < NR_FREQS)
		freq = sa11x0_freq_table[idx].frequency;
	return freq;
}

unsigned int sa11x0_getspeed(unsigned int cpu)
{
	if (cpu)
+0 −2
Original line number Diff line number Diff line
@@ -21,9 +21,7 @@ extern void sa1110_mb_enable(void);
extern void sa1110_mb_disable(void);

extern struct cpufreq_frequency_table sa11x0_freq_table[];
extern unsigned int sa11x0_freq_to_ppcr(unsigned int khz);
extern unsigned int sa11x0_getspeed(unsigned int cpu);
extern unsigned int sa11x0_ppcr_to_freq(unsigned int idx);

struct flash_platform_data;
struct resource;
+6 −15
Original line number Diff line number Diff line
@@ -424,17 +424,17 @@ static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq,
}

static int acpi_cpufreq_target(struct cpufreq_policy *policy,
			       unsigned int target_freq, unsigned int relation)
			       unsigned int index)
{
	struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu);
	struct acpi_processor_performance *perf;
	struct cpufreq_freqs freqs;
	struct drv_cmd cmd;
	unsigned int next_state = 0; /* Index into freq_table */
	unsigned int next_perf_state = 0; /* Index into perf table */
	int result = 0;

	pr_debug("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu);
	pr_debug("acpi_cpufreq_target %d (%d)\n",
			data->freq_table[index].frequency, policy->cpu);

	if (unlikely(data == NULL ||
	     data->acpi_data == NULL || data->freq_table == NULL)) {
@@ -442,16 +442,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
	}

	perf = data->acpi_data;
	result = cpufreq_frequency_table_target(policy,
						data->freq_table,
						target_freq,
						relation, &next_state);
	if (unlikely(result)) {
		result = -ENODEV;
		goto out;
	}

	next_perf_state = data->freq_table[next_state].driver_data;
	next_perf_state = data->freq_table[index].driver_data;
	if (perf->state == next_perf_state) {
		if (unlikely(data->resume)) {
			pr_debug("Called after resume, resetting to P%d\n",
@@ -493,7 +484,7 @@ static int acpi_cpufreq_target(struct cpufreq_policy *policy,
		cmd.mask = cpumask_of(policy->cpu);

	freqs.old = perf->states[perf->state].core_frequency * 1000;
	freqs.new = data->freq_table[next_state].frequency;
	freqs.new = data->freq_table[index].frequency;
	cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);

	drv_write(&cmd);
@@ -923,7 +914,7 @@ static struct freq_attr *acpi_cpufreq_attr[] = {

static struct cpufreq_driver acpi_cpufreq_driver = {
	.verify		= cpufreq_generic_frequency_table_verify,
	.target		= acpi_cpufreq_target,
	.target_index	= acpi_cpufreq_target,
	.bios_limit	= acpi_processor_get_bios_limit,
	.init		= acpi_cpufreq_cpu_init,
	.exit		= acpi_cpufreq_cpu_exit,
Loading