diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2011-05-15 13:19:51 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2011-05-24 16:20:05 -0400 |
commit | 72b2fd5cb89933a5b0dba32735d9b22ae3fb866e (patch) | |
tree | 19d14ce721d8d070ebdb80707e4f5f200de1be5d /drivers/cpufreq | |
parent | 46936340c4e545f3be935b9d34e0554d16dbac30 (diff) |
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>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/db8500-cpufreq.c | 167 |
1 files changed, 63 insertions, 104 deletions
diff --git a/drivers/cpufreq/db8500-cpufreq.c b/drivers/cpufreq/db8500-cpufreq.c index d196939fcdb9..d90456a809f9 100644 --- a/drivers/cpufreq/db8500-cpufreq.c +++ b/drivers/cpufreq/db8500-cpufreq.c | |||
@@ -1,134 +1,118 @@ | |||
1 | /* | 1 | /* |
2 | * CPU frequency scaling for u8500 | ||
3 | * Inspired by linux/arch/arm/mach-davinci/cpufreq.c | ||
4 | * | ||
5 | * Copyright (C) STMicroelectronics 2009 | 2 | * Copyright (C) STMicroelectronics 2009 |
6 | * Copyright (C) ST-Ericsson SA 2010 | 3 | * Copyright (C) ST-Ericsson SA 2010 |
7 | * | 4 | * |
8 | * License Terms: GNU General Public License v2 | 5 | * License Terms: GNU General Public License v2 |
9 | * | ||
10 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> | 6 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> |
11 | * Author: Martin Persson <martin.persson@stericsson.com> | 7 | * Author: Martin Persson <martin.persson@stericsson.com> |
12 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> | 8 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> |
13 | * | 9 | * |
14 | */ | 10 | */ |
15 | |||
16 | #include <linux/platform_device.h> | ||
17 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
18 | #include <linux/cpufreq.h> | 12 | #include <linux/cpufreq.h> |
19 | #include <linux/delay.h> | 13 | #include <linux/delay.h> |
14 | #include <linux/slab.h> | ||
20 | #include <linux/mfd/db8500-prcmu.h> | 15 | #include <linux/mfd/db8500-prcmu.h> |
21 | 16 | #include <mach/id.h> | |
22 | #include <mach/hardware.h> | ||
23 | |||
24 | #define DRIVER_NAME "cpufreq-u8500" | ||
25 | #define CPUFREQ_NAME "u8500" | ||
26 | |||
27 | static struct device *dev; | ||
28 | 17 | ||
29 | static struct cpufreq_frequency_table freq_table[] = { | 18 | static struct cpufreq_frequency_table freq_table[] = { |
30 | [0] = { | 19 | [0] = { |
31 | .index = 0, | 20 | .index = 0, |
32 | .frequency = 200000, | 21 | .frequency = 300000, |
33 | }, | 22 | }, |
34 | [1] = { | 23 | [1] = { |
35 | .index = 1, | 24 | .index = 1, |
36 | .frequency = 300000, | 25 | .frequency = 600000, |
37 | }, | 26 | }, |
38 | [2] = { | 27 | [2] = { |
28 | /* Used for MAX_OPP, if available */ | ||
39 | .index = 2, | 29 | .index = 2, |
40 | .frequency = 600000, | 30 | .frequency = CPUFREQ_TABLE_END, |
41 | }, | 31 | }, |
42 | [3] = { | 32 | [3] = { |
43 | /* Used for CPU_OPP_MAX, if available */ | ||
44 | .index = 3, | 33 | .index = 3, |
45 | .frequency = CPUFREQ_TABLE_END, | 34 | .frequency = CPUFREQ_TABLE_END, |
46 | }, | 35 | }, |
47 | [4] = { | ||
48 | .index = 4, | ||
49 | .frequency = CPUFREQ_TABLE_END, | ||
50 | }, | ||
51 | }; | 36 | }; |
52 | 37 | ||
53 | static enum prcmu_cpu_opp index2opp[] = { | 38 | static enum arm_opp idx2opp[] = { |
54 | CPU_OPP_EXT_CLK, | 39 | ARM_50_OPP, |
55 | CPU_OPP_50, | 40 | ARM_100_OPP, |
56 | CPU_OPP_100, | 41 | ARM_MAX_OPP |
57 | CPU_OPP_MAX | 42 | }; |
43 | |||
44 | static struct freq_attr *db8500_cpufreq_attr[] = { | ||
45 | &cpufreq_freq_attr_scaling_available_freqs, | ||
46 | NULL, | ||
58 | }; | 47 | }; |
59 | 48 | ||
60 | static int u8500_cpufreq_verify_speed(struct cpufreq_policy *policy) | 49 | static int db8500_cpufreq_verify_speed(struct cpufreq_policy *policy) |
61 | { | 50 | { |
62 | return cpufreq_frequency_table_verify(policy, freq_table); | 51 | return cpufreq_frequency_table_verify(policy, freq_table); |
63 | } | 52 | } |
64 | 53 | ||
65 | static int u8500_cpufreq_target(struct cpufreq_policy *policy, | 54 | static int db8500_cpufreq_target(struct cpufreq_policy *policy, |
66 | unsigned int target_freq, | 55 | unsigned int target_freq, |
67 | unsigned int relation) | 56 | unsigned int relation) |
68 | { | 57 | { |
69 | struct cpufreq_freqs freqs; | 58 | struct cpufreq_freqs freqs; |
70 | unsigned int index; | 59 | unsigned int idx; |
71 | int ret = 0; | ||
72 | 60 | ||
73 | /* | 61 | /* scale the target frequency to one of the extremes supported */ |
74 | * Ensure desired rate is within allowed range. Some govenors | ||
75 | * (ondemand) will just pass target_freq=0 to get the minimum. | ||
76 | */ | ||
77 | if (target_freq < policy->cpuinfo.min_freq) | 62 | if (target_freq < policy->cpuinfo.min_freq) |
78 | target_freq = policy->cpuinfo.min_freq; | 63 | target_freq = policy->cpuinfo.min_freq; |
79 | if (target_freq > policy->cpuinfo.max_freq) | 64 | if (target_freq > policy->cpuinfo.max_freq) |
80 | target_freq = policy->cpuinfo.max_freq; | 65 | target_freq = policy->cpuinfo.max_freq; |
81 | 66 | ||
82 | ret = cpufreq_frequency_table_target(policy, freq_table, | 67 | /* Lookup the next frequency */ |
83 | target_freq, relation, &index); | 68 | if (cpufreq_frequency_table_target |
84 | if (ret < 0) { | 69 | (policy, freq_table, target_freq, relation, &idx)) { |
85 | dev_err(dev, "Could not look up next frequency\n"); | 70 | return -EINVAL; |
86 | return ret; | ||
87 | } | 71 | } |
88 | 72 | ||
89 | freqs.old = policy->cur; | 73 | freqs.old = policy->cur; |
90 | freqs.new = freq_table[index].frequency; | 74 | freqs.new = freq_table[idx].frequency; |
91 | freqs.cpu = policy->cpu; | 75 | freqs.cpu = policy->cpu; |
92 | 76 | ||
93 | if (freqs.old == freqs.new) { | 77 | if (freqs.old == freqs.new) |
94 | dev_dbg(dev, "Current and target frequencies are equal\n"); | ||
95 | return 0; | 78 | return 0; |
96 | } | ||
97 | 79 | ||
98 | dev_dbg(dev, "transition: %u --> %u\n", freqs.old, freqs.new); | 80 | /* pre-change notification */ |
99 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 81 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
100 | 82 | ||
101 | ret = prcmu_set_cpu_opp(index2opp[index]); | 83 | /* request the PRCM unit for opp change */ |
102 | if (ret < 0) { | 84 | if (prcmu_set_arm_opp(idx2opp[idx])) { |
103 | dev_err(dev, "Failed to set OPP level\n"); | 85 | pr_err("db8500-cpufreq: Failed to set OPP level\n"); |
104 | return ret; | 86 | return -EINVAL; |
105 | } | 87 | } |
106 | 88 | ||
89 | /* post change notification */ | ||
107 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 90 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
108 | 91 | ||
109 | return ret; | 92 | return 0; |
110 | } | 93 | } |
111 | 94 | ||
112 | static unsigned int u8500_cpufreq_getspeed(unsigned int cpu) | 95 | static unsigned int db8500_cpufreq_getspeed(unsigned int cpu) |
113 | { | 96 | { |
114 | int i; | 97 | int i; |
115 | 98 | /* request the prcm to get the current ARM opp */ | |
116 | for (i = 0; prcmu_get_cpu_opp() != index2opp[i]; i++) | 99 | for (i = 0; prcmu_get_arm_opp() != idx2opp[i]; i++) |
117 | ; | 100 | ; |
118 | return freq_table[i].frequency; | 101 | return freq_table[i].frequency; |
119 | } | 102 | } |
120 | 103 | ||
121 | static int __cpuinit u8500_cpu_init(struct cpufreq_policy *policy) | 104 | static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy) |
122 | { | 105 | { |
123 | int res; | 106 | int res; |
107 | int i; | ||
124 | 108 | ||
125 | BUILD_BUG_ON(ARRAY_SIZE(index2opp) + 1 != ARRAY_SIZE(freq_table)); | 109 | BUILD_BUG_ON(ARRAY_SIZE(idx2opp) + 1 != ARRAY_SIZE(freq_table)); |
126 | 110 | ||
127 | if (cpu_is_u8500v2()) { | 111 | if (cpu_is_u8500v2() && !prcmu_is_u8400()) { |
128 | freq_table[1].frequency = 400000; | 112 | freq_table[0].frequency = 400000; |
129 | freq_table[2].frequency = 800000; | 113 | freq_table[1].frequency = 800000; |
130 | if (prcmu_has_arm_maxopp()) | 114 | if (prcmu_has_arm_maxopp()) |
131 | freq_table[3].frequency = 1000000; | 115 | freq_table[2].frequency = 1000000; |
132 | } | 116 | } |
133 | 117 | ||
134 | /* get policy fields based on the table */ | 118 | /* get policy fields based on the table */ |
@@ -136,13 +120,17 @@ static int __cpuinit u8500_cpu_init(struct cpufreq_policy *policy) | |||
136 | if (!res) | 120 | if (!res) |
137 | cpufreq_frequency_table_get_attr(freq_table, policy->cpu); | 121 | cpufreq_frequency_table_get_attr(freq_table, policy->cpu); |
138 | else { | 122 | else { |
139 | dev_err(dev, "u8500-cpufreq : Failed to read policy table\n"); | 123 | pr_err("db8500-cpufreq : Failed to read policy table\n"); |
140 | return res; | 124 | return res; |
141 | } | 125 | } |
142 | 126 | ||
143 | policy->min = policy->cpuinfo.min_freq; | 127 | policy->min = policy->cpuinfo.min_freq; |
144 | policy->max = policy->cpuinfo.max_freq; | 128 | 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 | |||
146 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; | 134 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
147 | 135 | ||
148 | /* | 136 | /* |
@@ -150,61 +138,32 @@ static int __cpuinit u8500_cpu_init(struct cpufreq_policy *policy) | |||
150 | * function with no/some/all drivers in the notification | 138 | * function with no/some/all drivers in the notification |
151 | * list. | 139 | * list. |
152 | */ | 140 | */ |
153 | policy->cpuinfo.transition_latency = 200 * 1000; /* in ns */ | 141 | policy->cpuinfo.transition_latency = 20 * 1000; /* in ns */ |
154 | 142 | ||
155 | /* policy sharing between dual CPUs */ | 143 | /* policy sharing between dual CPUs */ |
156 | cpumask_copy(policy->cpus, &cpu_present_map); | 144 | cpumask_copy(policy->cpus, &cpu_present_map); |
157 | 145 | ||
158 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | 146 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
159 | 147 | ||
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); | ||
170 | return 0; | 148 | return 0; |
171 | } | 149 | } |
172 | 150 | ||
173 | static struct cpufreq_driver u8500_driver = { | 151 | static struct cpufreq_driver db8500_cpufreq_driver = { |
174 | .owner = THIS_MODULE, | 152 | .flags = CPUFREQ_STICKY, |
175 | .flags = CPUFREQ_STICKY, | 153 | .verify = db8500_cpufreq_verify_speed, |
176 | .verify = u8500_cpufreq_verify_speed, | 154 | .target = db8500_cpufreq_target, |
177 | .target = u8500_cpufreq_target, | 155 | .get = db8500_cpufreq_getspeed, |
178 | .get = u8500_cpufreq_getspeed, | 156 | .init = db8500_cpufreq_init, |
179 | .init = u8500_cpu_init, | 157 | .name = "DB8500", |
180 | .exit = u8500_cpu_exit, | 158 | .attr = db8500_cpufreq_attr, |
181 | .name = CPUFREQ_NAME, | ||
182 | .attr = u8500_cpufreq_attr, | ||
183 | }; | 159 | }; |
184 | 160 | ||
185 | static int __init u8500_cpufreq_probe(struct platform_device *pdev) | 161 | static int __init db8500_cpufreq_register(void) |
186 | { | 162 | { |
187 | dev = &pdev->dev; | 163 | if (!cpu_is_u8500v20_or_later()) |
188 | return cpufreq_register_driver(&u8500_driver); | 164 | return -ENODEV; |
189 | } | ||
190 | |||
191 | static int __exit u8500_cpufreq_remove(struct platform_device *pdev) | ||
192 | { | ||
193 | return cpufreq_unregister_driver(&u8500_driver); | ||
194 | } | ||
195 | 165 | ||
196 | static struct platform_driver u8500_cpufreq_driver = { | 166 | pr_info("cpufreq for DB8500 started\n"); |
197 | .driver = { | 167 | return cpufreq_register_driver(&db8500_cpufreq_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); | ||
208 | } | 168 | } |
209 | 169 | device_initcall(db8500_cpufreq_register); | |
210 | device_initcall(u8500_cpufreq_init); | ||