14 #include <linux/kernel.h>
15 #include <linux/types.h>
21 #include <linux/export.h>
23 static struct clk *cpuclk;
30 cpufreq_verify_within_limits(policy, policy->
cpuinfo.min_freq,
35 static unsigned int at32_get_speed(
unsigned int cpu)
40 return (
unsigned int)((
clk_get_rate(cpuclk) + 500) / 1000);
43 static unsigned int ref_freq;
44 static unsigned long loops_per_jiffy_ref;
47 unsigned int target_freq,
48 unsigned int relation)
57 if(freq < (policy->
min * 1000) || freq > (policy->
max * 1000))
60 pr_debug(
"cpufreq: requested frequency %u Hz\n", target_freq * 1000);
62 freqs.old = at32_get_speed(0);
63 freqs.new = (freq + 500) / 1000;
73 if (freqs.old < freqs.new)
75 loops_per_jiffy_ref, ref_freq, freqs.new);
77 if (freqs.new < freqs.old)
79 loops_per_jiffy_ref, ref_freq, freqs.new);
82 pr_debug(
"cpufreq: set frequency %lu Hz\n", freq);
94 pr_debug(
"cpufreq: could not get CPU clk\n");
95 return PTR_ERR(cpuclk);
100 policy->
cpuinfo.transition_latency = 0;
101 policy->
cur = at32_get_speed(0);
105 printk(
"cpufreq: AT32AP CPU frequency driver\n");
113 .init = at32_cpufreq_driver_init,
114 .verify = at32_verify_speed,
115 .target = at32_set_target,
116 .get = at32_get_speed,
120 static int __init at32_cpufreq_init(
void)