aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/loongson2_cpufreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/cpufreq/loongson2_cpufreq.c')
-rw-r--r--drivers/cpufreq/loongson2_cpufreq.c57
1 files changed, 7 insertions, 50 deletions
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index 7bc3c44d34e2..a43609218105 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -53,51 +53,24 @@ static unsigned int loongson2_cpufreq_get(unsigned int cpu)
53 * Here we notify other drivers of the proposed change and the final change. 53 * Here we notify other drivers of the proposed change and the final change.
54 */ 54 */
55static int loongson2_cpufreq_target(struct cpufreq_policy *policy, 55static int loongson2_cpufreq_target(struct cpufreq_policy *policy,
56 unsigned int target_freq, 56 unsigned int index)
57 unsigned int relation)
58{ 57{
59 unsigned int cpu = policy->cpu; 58 unsigned int cpu = policy->cpu;
60 unsigned int newstate = 0;
61 cpumask_t cpus_allowed; 59 cpumask_t cpus_allowed;
62 struct cpufreq_freqs freqs;
63 unsigned int freq; 60 unsigned int freq;
64 61
65 cpus_allowed = current->cpus_allowed; 62 cpus_allowed = current->cpus_allowed;
66 set_cpus_allowed_ptr(current, cpumask_of(cpu)); 63 set_cpus_allowed_ptr(current, cpumask_of(cpu));
67 64
68 if (cpufreq_frequency_table_target
69 (policy, &loongson2_clockmod_table[0], target_freq, relation,
70 &newstate))
71 return -EINVAL;
72
73 freq = 65 freq =
74 ((cpu_clock_freq / 1000) * 66 ((cpu_clock_freq / 1000) *
75 loongson2_clockmod_table[newstate].driver_data) / 8; 67 loongson2_clockmod_table[index].driver_data) / 8;
76 if (freq < policy->min || freq > policy->max)
77 return -EINVAL;
78
79 pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
80
81 freqs.old = loongson2_cpufreq_get(cpu);
82 freqs.new = freq;
83 freqs.flags = 0;
84
85 if (freqs.new == freqs.old)
86 return 0;
87
88 /* notifiers */
89 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
90 68
91 set_cpus_allowed_ptr(current, &cpus_allowed); 69 set_cpus_allowed_ptr(current, &cpus_allowed);
92 70
93 /* setting the cpu frequency */ 71 /* setting the cpu frequency */
94 clk_set_rate(cpuclk, freq); 72 clk_set_rate(cpuclk, freq);
95 73
96 /* notifiers */
97 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
98
99 pr_debug("cpufreq: set frequency %u kHz\n", freq);
100
101 return 0; 74 return 0;
102} 75}
103 76
@@ -131,40 +104,24 @@ static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
131 return ret; 104 return ret;
132 } 105 }
133 106
134 policy->cur = loongson2_cpufreq_get(policy->cpu); 107 return cpufreq_generic_init(policy, &loongson2_clockmod_table[0], 0);
135
136 cpufreq_frequency_table_get_attr(&loongson2_clockmod_table[0],
137 policy->cpu);
138
139 return cpufreq_frequency_table_cpuinfo(policy,
140 &loongson2_clockmod_table[0]);
141}
142
143static int loongson2_cpufreq_verify(struct cpufreq_policy *policy)
144{
145 return cpufreq_frequency_table_verify(policy,
146 &loongson2_clockmod_table[0]);
147} 108}
148 109
149static int loongson2_cpufreq_exit(struct cpufreq_policy *policy) 110static int loongson2_cpufreq_exit(struct cpufreq_policy *policy)
150{ 111{
112 cpufreq_frequency_table_put_attr(policy->cpu);
151 clk_put(cpuclk); 113 clk_put(cpuclk);
152 return 0; 114 return 0;
153} 115}
154 116
155static struct freq_attr *loongson2_table_attr[] = {
156 &cpufreq_freq_attr_scaling_available_freqs,
157 NULL,
158};
159
160static struct cpufreq_driver loongson2_cpufreq_driver = { 117static struct cpufreq_driver loongson2_cpufreq_driver = {
161 .name = "loongson2", 118 .name = "loongson2",
162 .init = loongson2_cpufreq_cpu_init, 119 .init = loongson2_cpufreq_cpu_init,
163 .verify = loongson2_cpufreq_verify, 120 .verify = cpufreq_generic_frequency_table_verify,
164 .target = loongson2_cpufreq_target, 121 .target_index = loongson2_cpufreq_target,
165 .get = loongson2_cpufreq_get, 122 .get = loongson2_cpufreq_get,
166 .exit = loongson2_cpufreq_exit, 123 .exit = loongson2_cpufreq_exit,
167 .attr = loongson2_table_attr, 124 .attr = cpufreq_generic_attr,
168}; 125};
169 126
170static struct platform_device_id platform_device_ids[] = { 127static struct platform_device_id platform_device_ids[] = {