2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* linux/drivers/cpufreq/freq_table.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 - 2003 Dominik Brodowski
|
2008-05-22 08:52:05 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
2012-10-23 01:29:03 +02:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/cpufreq.h>
|
2013-08-06 19:23:03 +02:00
|
|
|
#include <linux/module.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* FREQUENCY TABLE HELPERS *
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
|
|
|
|
struct cpufreq_frequency_table *table)
|
|
|
|
{
|
|
|
|
unsigned int min_freq = ~0;
|
|
|
|
unsigned int max_freq = 0;
|
2006-05-30 23:58:41 +02:00
|
|
|
unsigned int i;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-01-18 07:56:41 +01:00
|
|
|
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned int freq = table[i].frequency;
|
|
|
|
if (freq == CPUFREQ_ENTRY_INVALID) {
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("table entry %u is invalid, skipping\n", i);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-30 11:55:15 +01:00
|
|
|
pr_debug("table entry %u: %u kHz, %u driver_data\n",
|
|
|
|
i, freq, table[i].driver_data);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (freq < min_freq)
|
|
|
|
min_freq = freq;
|
|
|
|
if (freq > max_freq)
|
|
|
|
max_freq = freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
policy->min = policy->cpuinfo.min_freq = min_freq;
|
|
|
|
policy->max = policy->cpuinfo.max_freq = max_freq;
|
|
|
|
|
|
|
|
if (policy->min == ~0)
|
|
|
|
return -EINVAL;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_cpuinfo);
|
|
|
|
|
|
|
|
|
|
|
|
int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
|
|
|
|
struct cpufreq_frequency_table *table)
|
|
|
|
{
|
2013-10-02 10:43:15 +02:00
|
|
|
unsigned int next_larger = ~0, freq, i = 0;
|
|
|
|
bool found = false;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
|
2006-10-26 12:50:58 +02:00
|
|
|
policy->min, policy->max, policy->cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2013-10-02 10:43:19 +02:00
|
|
|
cpufreq_verify_within_cpu_limits(policy);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2013-10-02 10:43:15 +02:00
|
|
|
for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
if (freq == CPUFREQ_ENTRY_INVALID)
|
|
|
|
continue;
|
2013-10-02 10:43:15 +02:00
|
|
|
if ((freq >= policy->min) && (freq <= policy->max)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((next_larger > freq) && (freq > policy->max))
|
2005-04-17 00:20:36 +02:00
|
|
|
next_larger = freq;
|
|
|
|
}
|
|
|
|
|
2013-10-02 10:43:15 +02:00
|
|
|
if (!found) {
|
2005-04-17 00:20:36 +02:00
|
|
|
policy->max = next_larger;
|
2013-10-02 10:43:19 +02:00
|
|
|
cpufreq_verify_within_cpu_limits(policy);
|
2013-10-02 10:43:15 +02:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("verification lead to (%u - %u kHz) for cpu %u\n",
|
2006-10-26 12:50:58 +02:00
|
|
|
policy->min, policy->max, policy->cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_verify);
|
|
|
|
|
2013-10-03 16:57:55 +02:00
|
|
|
/*
|
|
|
|
* Generic routine to verify policy & frequency table, requires driver to call
|
|
|
|
* cpufreq_frequency_table_get_attr() prior to it.
|
|
|
|
*/
|
|
|
|
int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy)
|
|
|
|
{
|
|
|
|
struct cpufreq_frequency_table *table =
|
|
|
|
cpufreq_frequency_get_table(policy->cpu);
|
|
|
|
if (!table)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return cpufreq_frequency_table_verify(policy, table);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
|
|
|
|
struct cpufreq_frequency_table *table,
|
|
|
|
unsigned int target_freq,
|
|
|
|
unsigned int relation,
|
|
|
|
unsigned int *index)
|
|
|
|
{
|
2006-05-31 00:09:31 +02:00
|
|
|
struct cpufreq_frequency_table optimal = {
|
2013-03-30 11:55:15 +01:00
|
|
|
.driver_data = ~0,
|
2006-05-31 00:09:31 +02:00
|
|
|
.frequency = 0,
|
|
|
|
};
|
|
|
|
struct cpufreq_frequency_table suboptimal = {
|
2013-03-30 11:55:15 +01:00
|
|
|
.driver_data = ~0,
|
2006-05-31 00:09:31 +02:00
|
|
|
.frequency = 0,
|
|
|
|
};
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
|
2006-10-26 12:50:58 +02:00
|
|
|
target_freq, relation, policy->cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
switch (relation) {
|
|
|
|
case CPUFREQ_RELATION_H:
|
|
|
|
suboptimal.frequency = ~0;
|
|
|
|
break;
|
|
|
|
case CPUFREQ_RELATION_L:
|
|
|
|
optimal.frequency = ~0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-18 07:56:41 +01:00
|
|
|
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned int freq = table[i].frequency;
|
|
|
|
if (freq == CPUFREQ_ENTRY_INVALID)
|
|
|
|
continue;
|
|
|
|
if ((freq < policy->min) || (freq > policy->max))
|
|
|
|
continue;
|
2009-01-18 07:56:41 +01:00
|
|
|
switch (relation) {
|
2005-04-17 00:20:36 +02:00
|
|
|
case CPUFREQ_RELATION_H:
|
|
|
|
if (freq <= target_freq) {
|
|
|
|
if (freq >= optimal.frequency) {
|
|
|
|
optimal.frequency = freq;
|
2013-03-30 11:55:15 +01:00
|
|
|
optimal.driver_data = i;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (freq <= suboptimal.frequency) {
|
|
|
|
suboptimal.frequency = freq;
|
2013-03-30 11:55:15 +01:00
|
|
|
suboptimal.driver_data = i;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CPUFREQ_RELATION_L:
|
|
|
|
if (freq >= target_freq) {
|
|
|
|
if (freq <= optimal.frequency) {
|
|
|
|
optimal.frequency = freq;
|
2013-03-30 11:55:15 +01:00
|
|
|
optimal.driver_data = i;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (freq >= suboptimal.frequency) {
|
|
|
|
suboptimal.frequency = freq;
|
2013-03-30 11:55:15 +01:00
|
|
|
suboptimal.driver_data = i;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 11:55:15 +01:00
|
|
|
if (optimal.driver_data > i) {
|
|
|
|
if (suboptimal.driver_data > i)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -EINVAL;
|
2013-03-30 11:55:15 +01:00
|
|
|
*index = suboptimal.driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
} else
|
2013-03-30 11:55:15 +01:00
|
|
|
*index = optimal.driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("target is %u (%u kHz, %u)\n", *index, table[*index].frequency,
|
2013-03-30 11:55:15 +01:00
|
|
|
table[*index].driver_data);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
|
|
|
|
|
2009-10-29 14:34:13 +01:00
|
|
|
static DEFINE_PER_CPU(struct cpufreq_frequency_table *, cpufreq_show_table);
|
2005-04-17 00:20:36 +02:00
|
|
|
/**
|
2007-11-21 23:52:15 +01:00
|
|
|
* show_available_freqs - show available frequencies for the specified CPU
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2009-01-18 07:56:41 +01:00
|
|
|
static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int cpu = policy->cpu;
|
|
|
|
ssize_t count = 0;
|
|
|
|
struct cpufreq_frequency_table *table;
|
|
|
|
|
2009-10-29 14:34:13 +01:00
|
|
|
if (!per_cpu(cpufreq_show_table, cpu))
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
2009-10-29 14:34:13 +01:00
|
|
|
table = per_cpu(cpufreq_show_table, cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2009-01-18 07:56:41 +01:00
|
|
|
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
|
|
|
|
continue;
|
|
|
|
count += sprintf(&buf[count], "%d ", table[i].frequency);
|
|
|
|
}
|
|
|
|
count += sprintf(&buf[count], "\n");
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct freq_attr cpufreq_freq_attr_scaling_available_freqs = {
|
2006-10-26 12:50:58 +02:00
|
|
|
.attr = { .name = "scaling_available_frequencies",
|
|
|
|
.mode = 0444,
|
|
|
|
},
|
2005-04-17 00:20:36 +02:00
|
|
|
.show = show_available_freqs,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_freq_attr_scaling_available_freqs);
|
|
|
|
|
2013-10-03 16:57:55 +02:00
|
|
|
struct freq_attr *cpufreq_generic_attr[] = {
|
|
|
|
&cpufreq_freq_attr_scaling_available_freqs,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_attr);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* if you use these, you must assure that the frequency table is valid
|
|
|
|
* all the time between get_attr and put_attr!
|
|
|
|
*/
|
2006-02-28 06:43:23 +01:00
|
|
|
void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned int cpu)
|
|
|
|
{
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("setting show_table for cpu %u to %p\n", cpu, table);
|
2009-10-29 14:34:13 +01:00
|
|
|
per_cpu(cpufreq_show_table, cpu) = table;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
|
|
|
|
|
|
|
|
void cpufreq_frequency_table_put_attr(unsigned int cpu)
|
|
|
|
{
|
2011-03-27 15:04:46 +02:00
|
|
|
pr_debug("clearing show_table for cpu %u\n", cpu);
|
2009-10-29 14:34:13 +01:00
|
|
|
per_cpu(cpufreq_show_table, cpu) = NULL;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
|
|
|
|
|
2013-09-16 15:26:03 +02:00
|
|
|
int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
|
|
|
|
struct cpufreq_frequency_table *table)
|
|
|
|
{
|
|
|
|
int ret = cpufreq_frequency_table_cpuinfo(policy, table);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
cpufreq_frequency_table_get_attr(table, policy->cpu);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show);
|
|
|
|
|
2013-01-14 14:23:03 +01:00
|
|
|
void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy)
|
|
|
|
{
|
|
|
|
pr_debug("Updating show_table for new_cpu %u from last_cpu %u\n",
|
|
|
|
policy->cpu, policy->last_cpu);
|
|
|
|
per_cpu(cpufreq_show_table, policy->cpu) = per_cpu(cpufreq_show_table,
|
|
|
|
policy->last_cpu);
|
|
|
|
per_cpu(cpufreq_show_table, policy->last_cpu) = NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
|
|
|
|
{
|
2009-10-29 14:34:13 +01:00
|
|
|
return per_cpu(cpufreq_show_table, cpu);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
|
|
|
|
|
2009-01-18 07:56:41 +01:00
|
|
|
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
|
|
|
|
MODULE_DESCRIPTION("CPUfreq frequency table helpers");
|
|
|
|
MODULE_LICENSE("GPL");
|