Skip to content

Commit 72b2fd5

Browse files
author
Linus Walleij
committed
cpufreq: update DB8500 cpufreq driver
This updates the ux500 cpufreq driver to the new interface from the updated DB8500 PRCMU Cc: Arnd Bergmann <arnd@arndb.de> Acked-by: Dave Jones <davej@redhat.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 4693634 commit 72b2fd5

1 file changed

Lines changed: 63 additions & 104 deletions

File tree

‎drivers/cpufreq/db8500-cpufreq.c‎

Lines changed: 63 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,169 @@
11
/*
2-
* CPU frequency scaling for u8500
3-
* Inspired by linux/arch/arm/mach-davinci/cpufreq.c
4-
*
52
* Copyright (C) STMicroelectronics 2009
63
* Copyright (C) ST-Ericsson SA 2010
74
*
85
* License Terms: GNU General Public License v2
9-
*
106
* Author: Sundar Iyer <sundar.iyer@stericsson.com>
117
* Author: Martin Persson <martin.persson@stericsson.com>
128
* Author: Jonas Aaberg <jonas.aberg@stericsson.com>
139
*
1410
*/
15-
16-
#include <linux/platform_device.h>
1711
#include <linux/kernel.h>
1812
#include <linux/cpufreq.h>
1913
#include <linux/delay.h>
14+
#include <linux/slab.h>
2015
#include <linux/mfd/db8500-prcmu.h>
21-
22-
#include <mach/hardware.h>
23-
24-
#define DRIVER_NAME "cpufreq-u8500"
25-
#define CPUFREQ_NAME "u8500"
26-
27-
static struct device *dev;
16+
#include <mach/id.h>
2817

2918
static struct cpufreq_frequency_table freq_table[] = {
3019
[0] = {
3120
.index = 0,
32-
.frequency = 200000,
21+
.frequency = 300000,
3322
},
3423
[1] = {
3524
.index = 1,
36-
.frequency = 300000,
25+
.frequency = 600000,
3726
},
3827
[2] = {
28+
/* Used for MAX_OPP, if available */
3929
.index = 2,
40-
.frequency = 600000,
30+
.frequency = CPUFREQ_TABLE_END,
4131
},
4232
[3] = {
43-
/* Used for CPU_OPP_MAX, if available */
4433
.index = 3,
4534
.frequency = CPUFREQ_TABLE_END,
4635
},
47-
[4] = {
48-
.index = 4,
49-
.frequency = CPUFREQ_TABLE_END,
50-
},
5136
};
5237

53-
static enum prcmu_cpu_opp index2opp[] = {
54-
CPU_OPP_EXT_CLK,
55-
CPU_OPP_50,
56-
CPU_OPP_100,
57-
CPU_OPP_MAX
38+
static enum arm_opp idx2opp[] = {
39+
ARM_50_OPP,
40+
ARM_100_OPP,
41+
ARM_MAX_OPP
42+
};
43+
44+
static struct freq_attr *db8500_cpufreq_attr[] = {
45+
&cpufreq_freq_attr_scaling_available_freqs,
46+
NULL,
5847
};
5948

60-
static int u8500_cpufreq_verify_speed(struct cpufreq_policy *policy)
49+
static int db8500_cpufreq_verify_speed(struct cpufreq_policy *policy)
6150
{
6251
return cpufreq_frequency_table_verify(policy, freq_table);
6352
}
6453

65-
static int u8500_cpufreq_target(struct cpufreq_policy *policy,
54+
static int db8500_cpufreq_target(struct cpufreq_policy *policy,
6655
unsigned int target_freq,
6756
unsigned int relation)
6857
{
6958
struct cpufreq_freqs freqs;
70-
unsigned int index;
71-
int ret = 0;
59+
unsigned int idx;
7260

73-
/*
74-
* Ensure desired rate is within allowed range. Some govenors
75-
* (ondemand) will just pass target_freq=0 to get the minimum.
76-
*/
61+
/* scale the target frequency to one of the extremes supported */
7762
if (target_freq < policy->cpuinfo.min_freq)
7863
target_freq = policy->cpuinfo.min_freq;
7964
if (target_freq > policy->cpuinfo.max_freq)
8065
target_freq = policy->cpuinfo.max_freq;
8166

82-
ret = cpufreq_frequency_table_target(policy, freq_table,
83-
target_freq, relation, &index);
84-
if (ret < 0) {
85-
dev_err(dev, "Could not look up next frequency\n");
86-
return ret;
67+
/* Lookup the next frequency */
68+
if (cpufreq_frequency_table_target
69+
(policy, freq_table, target_freq, relation, &idx)) {
70+
return -EINVAL;
8771
}
8872

8973
freqs.old = policy->cur;
90-
freqs.new = freq_table[index].frequency;
74+
freqs.new = freq_table[idx].frequency;
9175
freqs.cpu = policy->cpu;
9276

93-
if (freqs.old == freqs.new) {
94-
dev_dbg(dev, "Current and target frequencies are equal\n");
77+
if (freqs.old == freqs.new)
9578
return 0;
96-
}
9779

98-
dev_dbg(dev, "transition: %u --> %u\n", freqs.old, freqs.new);
80+
/* pre-change notification */
9981
cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
10082

101-
ret = prcmu_set_cpu_opp(index2opp[index]);
102-
if (ret < 0) {
103-
dev_err(dev, "Failed to set OPP level\n");
104-
return ret;
83+
/* request the PRCM unit for opp change */
84+
if (prcmu_set_arm_opp(idx2opp[idx])) {
85+
pr_err("db8500-cpufreq: Failed to set OPP level\n");
86+
return -EINVAL;
10587
}
10688

89+
/* post change notification */
10790
cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
10891

109-
return ret;
92+
return 0;
11093
}
11194

112-
static unsigned int u8500_cpufreq_getspeed(unsigned int cpu)
95+
static unsigned int db8500_cpufreq_getspeed(unsigned int cpu)
11396
{
11497
int i;
115-
116-
for (i = 0; prcmu_get_cpu_opp() != index2opp[i]; i++)
98+
/* request the prcm to get the current ARM opp */
99+
for (i = 0; prcmu_get_arm_opp() != idx2opp[i]; i++)
117100
;
118101
return freq_table[i].frequency;
119102
}
120103

121-
static int __cpuinit u8500_cpu_init(struct cpufreq_policy *policy)
104+
static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy)
122105
{
123106
int res;
107+
int i;
124108

125-
BUILD_BUG_ON(ARRAY_SIZE(index2opp) + 1 != ARRAY_SIZE(freq_table));
109+
BUILD_BUG_ON(ARRAY_SIZE(idx2opp) + 1 != ARRAY_SIZE(freq_table));
126110

127-
if (cpu_is_u8500v2()) {
128-
freq_table[1].frequency = 400000;
129-
freq_table[2].frequency = 800000;
111+
if (cpu_is_u8500v2() && !prcmu_is_u8400()) {
112+
freq_table[0].frequency = 400000;
113+
freq_table[1].frequency = 800000;
130114
if (prcmu_has_arm_maxopp())
131-
freq_table[3].frequency = 1000000;
115+
freq_table[2].frequency = 1000000;
132116
}
133117

134118
/* get policy fields based on the table */
135119
res = cpufreq_frequency_table_cpuinfo(policy, freq_table);
136120
if (!res)
137121
cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
138122
else {
139-
dev_err(dev, "u8500-cpufreq : Failed to read policy table\n");
123+
pr_err("db8500-cpufreq : Failed to read policy table\n");
140124
return res;
141125
}
142126

143127
policy->min = policy->cpuinfo.min_freq;
144128
policy->max = policy->cpuinfo.max_freq;
145-
policy->cur = u8500_cpufreq_getspeed(policy->cpu);
129+
policy->cur = db8500_cpufreq_getspeed(policy->cpu);
130+
131+
for (i = 0; freq_table[i].frequency != policy->cur; i++)
132+
;
133+
146134
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
147135

148136
/*
149137
* FIXME : Need to take time measurement across the target()
150138
* function with no/some/all drivers in the notification
151139
* list.
152140
*/
153-
policy->cpuinfo.transition_latency = 200 * 1000; /* in ns */
141+
policy->cpuinfo.transition_latency = 20 * 1000; /* in ns */
154142

155143
/* policy sharing between dual CPUs */
156144
cpumask_copy(policy->cpus, &cpu_present_map);
157145

158146
policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
159147

160-
return res;
161-
}
162-
163-
static struct freq_attr *u8500_cpufreq_attr[] = {
164-
&cpufreq_freq_attr_scaling_available_freqs,
165-
NULL,
166-
};
167-
static int u8500_cpu_exit(struct cpufreq_policy *policy)
168-
{
169-
cpufreq_frequency_table_put_attr(policy->cpu);
170148
return 0;
171149
}
172150

173-
static struct cpufreq_driver u8500_driver = {
174-
.owner = THIS_MODULE,
175-
.flags = CPUFREQ_STICKY,
176-
.verify = u8500_cpufreq_verify_speed,
177-
.target = u8500_cpufreq_target,
178-
.get = u8500_cpufreq_getspeed,
179-
.init = u8500_cpu_init,
180-
.exit = u8500_cpu_exit,
181-
.name = CPUFREQ_NAME,
182-
.attr = u8500_cpufreq_attr,
151+
static struct cpufreq_driver db8500_cpufreq_driver = {
152+
.flags = CPUFREQ_STICKY,
153+
.verify = db8500_cpufreq_verify_speed,
154+
.target = db8500_cpufreq_target,
155+
.get = db8500_cpufreq_getspeed,
156+
.init = db8500_cpufreq_init,
157+
.name = "DB8500",
158+
.attr = db8500_cpufreq_attr,
183159
};
184160

185-
static int __init u8500_cpufreq_probe(struct platform_device *pdev)
161+
static int __init db8500_cpufreq_register(void)
186162
{
187-
dev = &pdev->dev;
188-
return cpufreq_register_driver(&u8500_driver);
189-
}
190-
191-
static int __exit u8500_cpufreq_remove(struct platform_device *pdev)
192-
{
193-
return cpufreq_unregister_driver(&u8500_driver);
194-
}
163+
if (!cpu_is_u8500v20_or_later())
164+
return -ENODEV;
195165

196-
static struct platform_driver u8500_cpufreq_driver = {
197-
.driver = {
198-
.name = DRIVER_NAME,
199-
.owner = THIS_MODULE,
200-
},
201-
.remove = __exit_p(u8500_cpufreq_remove),
202-
};
203-
204-
static int __init u8500_cpufreq_init(void)
205-
{
206-
return platform_driver_probe(&u8500_cpufreq_driver,
207-
&u8500_cpufreq_probe);
166+
pr_info("cpufreq for DB8500 started\n");
167+
return cpufreq_register_driver(&db8500_cpufreq_driver);
208168
}
209-
210-
device_initcall(u8500_cpufreq_init);
169+
device_initcall(db8500_cpufreq_register);

0 commit comments

Comments
 (0)