提交 0e0e425f 编写于 作者: J Jonghwan Choi 提交者: Kukjin Kim

cpufreq: exynos: Split exynos_target function into two functions

Split exynos_target function into exynos_target & exynos_cpufreq_scale.
The exynos_cpufreq_scale changes the voltage & frequency.
Signed-off-by: NJonghwan Choi <jhbird.choi@samsung.com>
Signed-off-by: NKukjin Kim <kgene.kim@samsung.com>
上级 9d0554ff
...@@ -42,54 +42,55 @@ static unsigned int exynos_getspeed(unsigned int cpu) ...@@ -42,54 +42,55 @@ static unsigned int exynos_getspeed(unsigned int cpu)
return clk_get_rate(exynos_info->cpu_clk) / 1000; return clk_get_rate(exynos_info->cpu_clk) / 1000;
} }
static int exynos_target(struct cpufreq_policy *policy, static int exynos_cpufreq_get_index(unsigned int freq)
unsigned int target_freq, {
unsigned int relation) struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;
int index;
for (index = 0;
freq_table[index].frequency != CPUFREQ_TABLE_END; index++)
if (freq_table[index].frequency == freq)
break;
if (freq_table[index].frequency == CPUFREQ_TABLE_END)
return -EINVAL;
return index;
}
static int exynos_cpufreq_scale(unsigned int target_freq)
{ {
unsigned int index, old_index;
unsigned int arm_volt, safe_arm_volt = 0;
int ret = 0;
struct cpufreq_frequency_table *freq_table = exynos_info->freq_table; struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;
unsigned int *volt_table = exynos_info->volt_table; unsigned int *volt_table = exynos_info->volt_table;
struct cpufreq_policy *policy = cpufreq_cpu_get(0);
unsigned int arm_volt, safe_arm_volt = 0;
unsigned int mpll_freq_khz = exynos_info->mpll_freq_khz; unsigned int mpll_freq_khz = exynos_info->mpll_freq_khz;
unsigned int index, old_index;
mutex_lock(&cpufreq_lock); int ret = 0;
freqs.old = policy->cur; freqs.old = policy->cur;
freqs.cpu = policy->cpu;
if (frequency_locked && target_freq != locking_frequency) { if (target_freq == freqs.old)
ret = -EAGAIN;
goto out; goto out;
}
/* /*
* The policy max have been changed so that we cannot get proper * The policy max have been changed so that we cannot get proper
* old_index with cpufreq_frequency_table_target(). Thus, ignore * old_index with cpufreq_frequency_table_target(). Thus, ignore
* policy and get the index from the raw freqeuncy table. * policy and get the index from the raw freqeuncy table.
*/ */
for (old_index = 0; old_index = exynos_cpufreq_get_index(freqs.old);
freq_table[old_index].frequency != CPUFREQ_TABLE_END; if (old_index < 0) {
old_index++) ret = old_index;
if (freq_table[old_index].frequency == freqs.old)
break;
if (freq_table[old_index].frequency == CPUFREQ_TABLE_END) {
ret = -EINVAL;
goto out; goto out;
} }
if (cpufreq_frequency_table_target(policy, freq_table, index = exynos_cpufreq_get_index(target_freq);
target_freq, relation, &index)) { if (index < 0) {
ret = -EINVAL; ret = index;
goto out; goto out;
} }
freqs.new = freq_table[index].frequency;
freqs.cpu = policy->cpu;
if (freqs.new == freqs.old)
goto out;
/* /*
* ARM clock source will be changed APLL to MPLL temporary * ARM clock source will be changed APLL to MPLL temporary
* To support this level, need to control regulator for * To support this level, need to control regulator for
...@@ -109,13 +110,23 @@ static int exynos_target(struct cpufreq_policy *policy, ...@@ -109,13 +110,23 @@ static int exynos_target(struct cpufreq_policy *policy,
/* When the new frequency is higher than current frequency */ /* When the new frequency is higher than current frequency */
if ((freqs.new > freqs.old) && !safe_arm_volt) { if ((freqs.new > freqs.old) && !safe_arm_volt) {
/* Firstly, voltage up to increase frequency */ /* Firstly, voltage up to increase frequency */
regulator_set_voltage(arm_regulator, arm_volt, ret = regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
arm_volt); if (ret) {
pr_err("%s: failed to set cpu voltage to %d\n",
__func__, arm_volt);
goto out;
}
} }
if (safe_arm_volt) if (safe_arm_volt) {
regulator_set_voltage(arm_regulator, safe_arm_volt, ret = regulator_set_voltage(arm_regulator, safe_arm_volt,
safe_arm_volt); safe_arm_volt);
if (ret) {
pr_err("%s: failed to set cpu voltage to %d\n",
__func__, safe_arm_volt);
goto out;
}
}
exynos_info->set_freq(old_index, index); exynos_info->set_freq(old_index, index);
...@@ -128,8 +139,43 @@ static int exynos_target(struct cpufreq_policy *policy, ...@@ -128,8 +139,43 @@ static int exynos_target(struct cpufreq_policy *policy,
/* down the voltage after frequency change */ /* down the voltage after frequency change */
regulator_set_voltage(arm_regulator, arm_volt, regulator_set_voltage(arm_regulator, arm_volt,
arm_volt); arm_volt);
if (ret) {
pr_err("%s: failed to set cpu voltage to %d\n",
__func__, arm_volt);
goto out;
}
}
out:
cpufreq_cpu_put(policy);
return ret;
}
static int exynos_target(struct cpufreq_policy *policy,
unsigned int target_freq,
unsigned int relation)
{
struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;
unsigned int index;
int ret;
mutex_lock(&cpufreq_lock);
if (frequency_locked)
goto out;
if (cpufreq_frequency_table_target(policy, freq_table,
target_freq, relation, &index)) {
ret = -EINVAL;
goto out;
} }
freqs.new = freq_table[index].frequency;
ret = exynos_cpufreq_scale(freqs.new);
out: out:
mutex_unlock(&cpufreq_lock); mutex_unlock(&cpufreq_lock);
...@@ -166,51 +212,26 @@ static int exynos_cpufreq_resume(struct cpufreq_policy *policy) ...@@ -166,51 +212,26 @@ static int exynos_cpufreq_resume(struct cpufreq_policy *policy)
static int exynos_cpufreq_pm_notifier(struct notifier_block *notifier, static int exynos_cpufreq_pm_notifier(struct notifier_block *notifier,
unsigned long pm_event, void *v) unsigned long pm_event, void *v)
{ {
struct cpufreq_policy *policy = cpufreq_cpu_get(0); /* boot CPU */ int ret;
static unsigned int saved_frequency;
unsigned int temp;
mutex_lock(&cpufreq_lock);
switch (pm_event) { switch (pm_event) {
case PM_SUSPEND_PREPARE: case PM_SUSPEND_PREPARE:
if (frequency_locked) mutex_lock(&cpufreq_lock);
goto out;
frequency_locked = true; frequency_locked = true;
mutex_unlock(&cpufreq_lock);
if (locking_frequency) { ret = exynos_cpufreq_scale(locking_frequency);
saved_frequency = exynos_getspeed(0); if (ret < 0)
return NOTIFY_BAD;
mutex_unlock(&cpufreq_lock);
exynos_target(policy, locking_frequency,
CPUFREQ_RELATION_H);
mutex_lock(&cpufreq_lock);
}
break; break;
case PM_POST_SUSPEND: case PM_POST_SUSPEND:
if (saved_frequency) { mutex_lock(&cpufreq_lock);
/*
* While frequency_locked, only locking_frequency
* is valid for target(). In order to use
* saved_frequency while keeping frequency_locked,
* we temporarly overwrite locking_frequency.
*/
temp = locking_frequency;
locking_frequency = saved_frequency;
mutex_unlock(&cpufreq_lock);
exynos_target(policy, locking_frequency,
CPUFREQ_RELATION_H);
mutex_lock(&cpufreq_lock);
locking_frequency = temp;
}
frequency_locked = false; frequency_locked = false;
mutex_unlock(&cpufreq_lock);
break; break;
} }
out:
mutex_unlock(&cpufreq_lock);
return NOTIFY_OK; return NOTIFY_OK;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册