21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/sched.h>
51 static struct clk *cpu_clk;
52 static struct clk *pll_x_clk;
53 static struct clk *pll_p_clk;
54 static struct clk *emc_clk;
56 static unsigned long target_cpu_speed[
NUM_CPUS];
58 static bool is_suspended;
65 static unsigned int tegra_getspeed(
unsigned int cpu)
76 static int tegra_cpu_clk_set_rate(
unsigned long rate)
84 clk_prepare_enable(pll_x_clk);
88 pr_err(
"Failed to switch cpu to clock pll_p\n");
97 pr_err(
"Failed to change pll_x to %lu\n", rate);
103 pr_err(
"Failed to switch cpu to clock pll_x\n");
108 clk_disable_unprepare(pll_x_clk);
112 static int tegra_update_cpu_speed(
unsigned long rate)
117 freqs.
old = tegra_getspeed(0);
120 if (freqs.old == freqs.new)
129 else if (rate >= 456000)
137 #ifdef CONFIG_CPU_FREQ_DEBUG
139 freqs.old, freqs.new);
142 ret = tegra_cpu_clk_set_rate(freqs.new * 1000);
144 pr_err(
"cpu-tegra: Failed to set cpu frequency to %d kHz\n",
155 static
unsigned long tegra_cpu_highest_speed(
void)
157 unsigned long rate = 0;
161 rate =
max(rate, target_cpu_speed[i]);
166 unsigned int target_freq,
167 unsigned int relation)
185 target_cpu_speed[policy->cpu] =
freq;
187 ret = tegra_update_cpu_speed(tegra_cpu_highest_speed());
200 pr_info(
"Tegra cpufreq suspend: setting frequency to %d kHz\n",
202 tegra_update_cpu_speed(freq_table[0].
frequency);
204 is_suspended =
false;
212 .notifier_call = tegra_pm_notify,
222 return PTR_ERR(cpu_clk);
225 if (IS_ERR(pll_x_clk))
226 return PTR_ERR(pll_x_clk);
229 if (IS_ERR(pll_p_clk))
230 return PTR_ERR(pll_p_clk);
233 if (IS_ERR(emc_clk)) {
235 return PTR_ERR(emc_clk);
238 clk_prepare_enable(emc_clk);
239 clk_prepare_enable(cpu_clk);
243 policy->
cur = tegra_getspeed(policy->
cpu);
244 target_cpu_speed[policy->
cpu] = policy->
cur;
247 policy->
cpuinfo.transition_latency = 300 * 1000;
252 if (policy->
cpu == 0)
253 register_pm_notifier(&tegra_cpu_pm_notifier);
261 clk_disable_unprepare(emc_clk);
267 static struct freq_attr *tegra_cpufreq_attr[] = {
273 .verify = tegra_verify_speed,
274 .target = tegra_target,
275 .get = tegra_getspeed,
276 .init = tegra_cpu_init,
277 .exit = tegra_cpu_exit,
279 .attr = tegra_cpufreq_attr,
282 static int __init tegra_cpufreq_init(
void)
287 static void __exit tegra_cpufreq_exit(
void)