Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 351063
b: refs/heads/master
c: 0e0e425
h: refs/heads/master
i:
  351061: b0bfa3d
  351059: abc1896
  351055: a77d212
v: v3
  • Loading branch information
Jonghwan Choi authored and Kukjin Kim committed Dec 23, 2012
1 parent 4d8a384 commit 03374ec
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 66 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9d0554fff9a21d846adcfbd14cfb02e82773162c
refs/heads/master: 0e0e425f58fc91b7559350e12060938f8fa7a1c2
151 changes: 86 additions & 65 deletions trunk/drivers/cpufreq/exynos-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,55 @@ static unsigned int exynos_getspeed(unsigned int cpu)
return clk_get_rate(exynos_info->cpu_clk) / 1000;
}

static int exynos_target(struct cpufreq_policy *policy,
unsigned int target_freq,
unsigned int relation)
static int exynos_cpufreq_get_index(unsigned int freq)
{
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;
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;

mutex_lock(&cpufreq_lock);
unsigned int index, old_index;
int ret = 0;

freqs.old = policy->cur;
freqs.cpu = policy->cpu;

if (frequency_locked && target_freq != locking_frequency) {
ret = -EAGAIN;
if (target_freq == freqs.old)
goto out;
}

/*
* The policy max have been changed so that we cannot get proper
* old_index with cpufreq_frequency_table_target(). Thus, ignore
* policy and get the index from the raw freqeuncy table.
*/
for (old_index = 0;
freq_table[old_index].frequency != CPUFREQ_TABLE_END;
old_index++)
if (freq_table[old_index].frequency == freqs.old)
break;

if (freq_table[old_index].frequency == CPUFREQ_TABLE_END) {
ret = -EINVAL;
old_index = exynos_cpufreq_get_index(freqs.old);
if (old_index < 0) {
ret = old_index;
goto out;
}

if (cpufreq_frequency_table_target(policy, freq_table,
target_freq, relation, &index)) {
ret = -EINVAL;
index = exynos_cpufreq_get_index(target_freq);
if (index < 0) {
ret = index;
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
* To support this level, need to control regulator for
Expand All @@ -109,13 +110,23 @@ static int exynos_target(struct cpufreq_policy *policy,
/* When the new frequency is higher than current frequency */
if ((freqs.new > freqs.old) && !safe_arm_volt) {
/* Firstly, voltage up to increase frequency */
regulator_set_voltage(arm_regulator, arm_volt,
arm_volt);
ret = regulator_set_voltage(arm_regulator, 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)
regulator_set_voltage(arm_regulator, safe_arm_volt,
if (safe_arm_volt) {
ret = regulator_set_voltage(arm_regulator, 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);

Expand All @@ -128,8 +139,43 @@ static int exynos_target(struct cpufreq_policy *policy,
/* down the voltage after frequency change */
regulator_set_voltage(arm_regulator, 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:
mutex_unlock(&cpufreq_lock);

Expand Down Expand Up @@ -166,51 +212,26 @@ static int exynos_cpufreq_resume(struct cpufreq_policy *policy)
static int exynos_cpufreq_pm_notifier(struct notifier_block *notifier,
unsigned long pm_event, void *v)
{
struct cpufreq_policy *policy = cpufreq_cpu_get(0); /* boot CPU */
static unsigned int saved_frequency;
unsigned int temp;
int ret;

mutex_lock(&cpufreq_lock);
switch (pm_event) {
case PM_SUSPEND_PREPARE:
if (frequency_locked)
goto out;

mutex_lock(&cpufreq_lock);
frequency_locked = true;
mutex_unlock(&cpufreq_lock);

if (locking_frequency) {
saved_frequency = exynos_getspeed(0);
ret = exynos_cpufreq_scale(locking_frequency);
if (ret < 0)
return NOTIFY_BAD;

mutex_unlock(&cpufreq_lock);
exynos_target(policy, locking_frequency,
CPUFREQ_RELATION_H);
mutex_lock(&cpufreq_lock);
}
break;

case PM_POST_SUSPEND:
if (saved_frequency) {
/*
* 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;
}
mutex_lock(&cpufreq_lock);
frequency_locked = false;
mutex_unlock(&cpufreq_lock);
break;
}
out:
mutex_unlock(&cpufreq_lock);

return NOTIFY_OK;
}
Expand Down

0 comments on commit 03374ec

Please sign in to comment.