14 #include <linux/module.h>
16 #include <linux/sched.h>
20 #include <asm/clock.h>
26 static struct clk *cpuclk;
28 static void (*saved_cpu_wait) (
void);
34 .notifier_call = loongson2_cpu_freq_notifier
46 static unsigned int loongson2_cpufreq_get(
unsigned int cpu)
55 unsigned int target_freq,
56 unsigned int relation)
58 unsigned int cpu = policy->
cpu;
59 unsigned int newstate = 0;
67 cpus_allowed =
current->cpus_allowed;
78 if (freq < policy->
min || freq > policy->
max)
81 pr_debug(
"cpufreq: requested frequency %u Hz\n", target_freq * 1000);
84 freqs.old = loongson2_cpufreq_get(cpu);
88 if (freqs.new == freqs.old)
94 set_cpus_allowed_ptr(
current, &cpus_allowed);
102 pr_debug(
"cpufreq: set frequency %u kHz\n", freq);
107 static int loongson2_cpufreq_cpu_init(
struct cpufreq_policy *policy)
115 if (IS_ERR(cpuclk)) {
117 return PTR_ERR(cpuclk);
130 policy->
cur = loongson2_cpufreq_get(policy->
cpu);
139 static int loongson2_cpufreq_verify(
struct cpufreq_policy *policy)
151 static struct freq_attr *loongson2_table_attr[] = {
159 .init = loongson2_cpufreq_cpu_init,
160 .verify = loongson2_cpufreq_verify,
161 .target = loongson2_cpufreq_target,
162 .get = loongson2_cpufreq_get,
163 .exit = loongson2_cpufreq_exit,
164 .attr = loongson2_table_attr,
169 .name =
"loongson2_cpufreq",
178 .name =
"loongson2_cpufreq",
181 .id_table = platform_device_ids,
191 static void loongson2_cpu_wait(
void)
197 cpu_freq = LOONGSON_CHIPCFG0;
198 LOONGSON_CHIPCFG0 &= ~0x7;
199 LOONGSON_CHIPCFG0 = cpu_freq;
200 spin_unlock_irqrestore(&loongson2_wait_lock, flags);
203 static int __init cpufreq_init(
void)
212 pr_info(
"cpufreq: Loongson-2F CPU frequency driver.\n");
219 if (!ret && !nowait) {
227 static void __exit cpufreq_exit(
void)
229 if (!nowait && saved_cpu_wait)