diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2013-01-30 09:27:49 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-02-01 18:01:16 -0500 |
commit | 5553f9e26f6f49a93ba732fd222eac6973a4cf35 (patch) | |
tree | 039a24ab646dc51c047f7b6695dcbb73f190a6e0 /drivers | |
parent | 58ddcead4f163a01cef96aa5ba88f374011d8aea (diff) |
cpufreq: instantiate cpufreq-cpu0 as a platform_driver
As multiplatform build is being adopted by more and more ARM platforms,
initcall function should be used very carefully. For example, when
GENERIC_CPUFREQ_CPU0 is built in the kernel, cpu0_cpufreq_driver_init()
will be called on all the platforms to initialize cpufreq-cpu0 driver.
To eliminate this undesired the effect, the patch changes cpufreq-cpu0
driver to have it instantiated as a platform_driver. Then it will only
run on platforms that create the platform_device "cpufreq-cpu0".
Along with the change, it also changes cpu_dev to be &pdev->dev,
so that managed functions can start working, and module build gets
supported too.
The highbank-cpufreq driver is also updated accordingly to adapt the
changes on cpufreq-cpu0.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Langsdorf <mark.langsdorf@calxeda.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/cpufreq/Kconfig | 2 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq-cpu0.c | 35 | ||||
-rw-r--r-- | drivers/cpufreq/highbank-cpufreq.c | 5 |
3 files changed, 29 insertions, 13 deletions
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index e0a899f25e37..cbcb21e32771 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig | |||
@@ -185,7 +185,7 @@ config CPU_FREQ_GOV_CONSERVATIVE | |||
185 | If in doubt, say N. | 185 | If in doubt, say N. |
186 | 186 | ||
187 | config GENERIC_CPUFREQ_CPU0 | 187 | config GENERIC_CPUFREQ_CPU0 |
188 | bool "Generic CPU0 cpufreq driver" | 188 | tristate "Generic CPU0 cpufreq driver" |
189 | depends on HAVE_CLK && REGULATOR && PM_OPP && OF | 189 | depends on HAVE_CLK && REGULATOR && PM_OPP && OF |
190 | select CPU_FREQ_TABLE | 190 | select CPU_FREQ_TABLE |
191 | help | 191 | help |
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c index 38ae178ce4ef..a108f66271ee 100644 --- a/drivers/cpufreq/cpufreq-cpu0.c +++ b/drivers/cpufreq/cpufreq-cpu0.c | |||
@@ -12,12 +12,12 @@ | |||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
13 | 13 | ||
14 | #include <linux/clk.h> | 14 | #include <linux/clk.h> |
15 | #include <linux/cpu.h> | ||
16 | #include <linux/cpufreq.h> | 15 | #include <linux/cpufreq.h> |
17 | #include <linux/err.h> | 16 | #include <linux/err.h> |
18 | #include <linux/module.h> | 17 | #include <linux/module.h> |
19 | #include <linux/of.h> | 18 | #include <linux/of.h> |
20 | #include <linux/opp.h> | 19 | #include <linux/opp.h> |
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/regulator/consumer.h> | 21 | #include <linux/regulator/consumer.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | 23 | ||
@@ -177,7 +177,7 @@ static struct cpufreq_driver cpu0_cpufreq_driver = { | |||
177 | .attr = cpu0_cpufreq_attr, | 177 | .attr = cpu0_cpufreq_attr, |
178 | }; | 178 | }; |
179 | 179 | ||
180 | static int cpu0_cpufreq_driver_init(void) | 180 | static int cpu0_cpufreq_probe(struct platform_device *pdev) |
181 | { | 181 | { |
182 | struct device_node *np; | 182 | struct device_node *np; |
183 | int ret; | 183 | int ret; |
@@ -192,23 +192,17 @@ static int cpu0_cpufreq_driver_init(void) | |||
192 | return -ENOENT; | 192 | return -ENOENT; |
193 | } | 193 | } |
194 | 194 | ||
195 | cpu_dev = get_cpu_device(0); | 195 | cpu_dev = &pdev->dev; |
196 | if (!cpu_dev) { | ||
197 | pr_err("failed to get cpu0 device\n"); | ||
198 | ret = -ENODEV; | ||
199 | goto out_put_node; | ||
200 | } | ||
201 | |||
202 | cpu_dev->of_node = np; | 196 | cpu_dev->of_node = np; |
203 | 197 | ||
204 | cpu_clk = clk_get(cpu_dev, NULL); | 198 | cpu_clk = devm_clk_get(cpu_dev, NULL); |
205 | if (IS_ERR(cpu_clk)) { | 199 | if (IS_ERR(cpu_clk)) { |
206 | ret = PTR_ERR(cpu_clk); | 200 | ret = PTR_ERR(cpu_clk); |
207 | pr_err("failed to get cpu0 clock: %d\n", ret); | 201 | pr_err("failed to get cpu0 clock: %d\n", ret); |
208 | goto out_put_node; | 202 | goto out_put_node; |
209 | } | 203 | } |
210 | 204 | ||
211 | cpu_reg = regulator_get(cpu_dev, "cpu0"); | 205 | cpu_reg = devm_regulator_get(cpu_dev, "cpu0"); |
212 | if (IS_ERR(cpu_reg)) { | 206 | if (IS_ERR(cpu_reg)) { |
213 | pr_warn("failed to get cpu0 regulator\n"); | 207 | pr_warn("failed to get cpu0 regulator\n"); |
214 | cpu_reg = NULL; | 208 | cpu_reg = NULL; |
@@ -271,7 +265,24 @@ out_put_node: | |||
271 | of_node_put(np); | 265 | of_node_put(np); |
272 | return ret; | 266 | return ret; |
273 | } | 267 | } |
274 | late_initcall(cpu0_cpufreq_driver_init); | 268 | |
269 | static int cpu0_cpufreq_remove(struct platform_device *pdev) | ||
270 | { | ||
271 | cpufreq_unregister_driver(&cpu0_cpufreq_driver); | ||
272 | opp_free_cpufreq_table(cpu_dev, &freq_table); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | static struct platform_driver cpu0_cpufreq_platdrv = { | ||
278 | .driver = { | ||
279 | .name = "cpufreq-cpu0", | ||
280 | .owner = THIS_MODULE, | ||
281 | }, | ||
282 | .probe = cpu0_cpufreq_probe, | ||
283 | .remove = cpu0_cpufreq_remove, | ||
284 | }; | ||
285 | module_platform_driver(cpu0_cpufreq_platdrv); | ||
275 | 286 | ||
276 | MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>"); | 287 | MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>"); |
277 | MODULE_DESCRIPTION("Generic CPU0 cpufreq driver"); | 288 | MODULE_DESCRIPTION("Generic CPU0 cpufreq driver"); |
diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c index 53f25e5aa6b7..66e3a71b81a3 100644 --- a/drivers/cpufreq/highbank-cpufreq.c +++ b/drivers/cpufreq/highbank-cpufreq.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/err.h> | 20 | #include <linux/err.h> |
21 | #include <linux/of.h> | 21 | #include <linux/of.h> |
22 | #include <linux/mailbox.h> | 22 | #include <linux/mailbox.h> |
23 | #include <linux/platform_device.h> | ||
23 | 24 | ||
24 | #define HB_CPUFREQ_CHANGE_NOTE 0x80000001 | 25 | #define HB_CPUFREQ_CHANGE_NOTE 0x80000001 |
25 | #define HB_CPUFREQ_IPC_LEN 7 | 26 | #define HB_CPUFREQ_IPC_LEN 7 |
@@ -65,6 +66,7 @@ static struct notifier_block hb_cpufreq_clk_nb = { | |||
65 | 66 | ||
66 | static int hb_cpufreq_driver_init(void) | 67 | static int hb_cpufreq_driver_init(void) |
67 | { | 68 | { |
69 | struct platform_device_info devinfo = { .name = "cpufreq-cpu0", }; | ||
68 | struct device *cpu_dev; | 70 | struct device *cpu_dev; |
69 | struct clk *cpu_clk; | 71 | struct clk *cpu_clk; |
70 | struct device_node *np; | 72 | struct device_node *np; |
@@ -104,6 +106,9 @@ static int hb_cpufreq_driver_init(void) | |||
104 | goto out_put_node; | 106 | goto out_put_node; |
105 | } | 107 | } |
106 | 108 | ||
109 | /* Instantiate cpufreq-cpu0 */ | ||
110 | platform_device_register_full(&devinfo); | ||
111 | |||
107 | out_put_node: | 112 | out_put_node: |
108 | of_node_put(np); | 113 | of_node_put(np); |
109 | return ret; | 114 | return ret; |