12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
22 #include <linux/slab.h>
24 static unsigned int transition_latency;
25 static unsigned int voltage_tolerance;
28 static struct clk *cpu_clk;
37 static unsigned int cpu0_get_speed(
unsigned int cpu)
43 unsigned int target_freq,
unsigned int relation)
47 unsigned long freq_Hz, volt = 0, volt_old = 0, tol = 0;
54 pr_err(
"failed to match target freqency %d: %d\n",
62 freqs.new = freq_Hz / 1000;
65 if (freqs.old == freqs.new)
76 pr_err(
"failed to find OPP for %ld\n", freq_Hz);
80 tol = volt * voltage_tolerance / 100;
84 pr_debug(
"%u MHz, %ld mV --> %u MHz, %ld mV\n",
85 freqs.old / 1000, volt_old ? volt_old / 1000 : -1,
86 freqs.new / 1000, volt ? volt / 1000 : -1);
89 if (cpu_reg && freqs.new > freqs.old) {
90 ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
92 pr_err(
"failed to scale voltage up: %d\n", ret);
93 freqs.new = freqs.old;
100 pr_err(
"failed to set clock rate: %d\n", ret);
102 regulator_set_voltage_tol(cpu_reg, volt_old, tol);
107 if (cpu_reg && freqs.new < freqs.old) {
108 ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
110 pr_err(
"failed to scale voltage down: %d\n", ret);
112 freqs.new = freqs.old;
129 if (policy->
cpu != 0)
134 pr_err(
"invalid frequency table: %d\n", ret);
138 policy->
cpuinfo.transition_latency = transition_latency;
147 cpumask_setall(policy->
cpus);
161 static struct freq_attr *cpu0_cpufreq_attr[] = {
168 .verify = cpu0_verify_speed,
169 .target = cpu0_set_target,
170 .get = cpu0_get_speed,
171 .init = cpu0_cpufreq_init,
172 .exit = cpu0_cpufreq_exit,
173 .name =
"generic_cpu0",
174 .attr = cpu0_cpufreq_attr,
177 static int __devinit cpu0_cpufreq_driver_init(
void)
184 pr_err(
"failed to find cpu0 node\n");
190 pr_err(
"failed to get cpu0 device\n");
198 if (IS_ERR(cpu_clk)) {
199 ret = PTR_ERR(cpu_clk);
200 pr_err(
"failed to get cpu0 clock: %d\n", ret);
205 if (IS_ERR(cpu_reg)) {
206 pr_warn(
"failed to get cpu0 regulator\n");
210 ret = of_init_opp_table(cpu_dev);
212 pr_err(
"failed to init OPP table: %d\n", ret);
216 ret = opp_init_cpufreq_table(cpu_dev, &freq_table);
218 pr_err(
"failed to init cpufreq table: %d\n", ret);
222 of_property_read_u32(np,
"voltage-tolerance", &voltage_tolerance);
224 if (of_property_read_u32(np,
"clock-latency", &transition_latency))
229 unsigned long min_uV, max_uV;
247 transition_latency += ret * 1000;
252 pr_err(
"failed register driver: %d\n", ret);
260 opp_free_cpufreq_table(cpu_dev, &freq_table);