aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorMark Langsdorf <mark.langsdorf@calxeda.com>2013-01-28 11:13:15 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-02-01 18:01:15 -0500
commit6754f556103be5bd172263b1075ddbb7157afbad (patch)
treecd913973afd0247175e3adeecaf19d484753580a /drivers/cpufreq
parent300586778d405f0a4d1f6dc51fcfb4fed567d020 (diff)
cpufreq / highbank: add support for highbank cpufreq
Highbank processors depend on the external ECME to perform voltage management based on a requested frequency. Communication between the A9 cores and the ECME happens over the pl320 IPC channel. Signed-off-by: Mark Langsdorf <mark.langsdorf@calxeda.com> Reviewed-by: Shawn Guo <shawn.guo@linaro.org> Reviewed-by: Mike Turquette <mturquette@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/Kconfig.arm15
-rw-r--r--drivers/cpufreq/Makefile3
-rw-r--r--drivers/cpufreq/cpufreq-cpu0.c6
-rw-r--r--drivers/cpufreq/highbank-cpufreq.c115
4 files changed, 137 insertions, 2 deletions
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index a0b3661d90b0..ffe55b8a98cc 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -83,3 +83,18 @@ config ARM_SPEAR_CPUFREQ
83 default y 83 default y
84 help 84 help
85 This adds the CPUFreq driver support for SPEAr SOCs. 85 This adds the CPUFreq driver support for SPEAr SOCs.
86
87config ARM_HIGHBANK_CPUFREQ
88 tristate "Calxeda Highbank-based"
89 depends on ARCH_HIGHBANK
90 select CPU_FREQ_TABLE
91 select GENERIC_CPUFREQ_CPU0
92 select PM_OPP
93 select REGULATOR
94
95 default m
96 help
97 This adds the CPUFreq driver for Calxeda Highbank SoC
98 based boards.
99
100 If in doubt, say N.
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 24d4a63fd6cf..e2a5da77370f 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -51,8 +51,9 @@ obj-$(CONFIG_ARM_EXYNOS_CPUFREQ) += exynos-cpufreq.o
51obj-$(CONFIG_ARM_EXYNOS4210_CPUFREQ) += exynos4210-cpufreq.o 51obj-$(CONFIG_ARM_EXYNOS4210_CPUFREQ) += exynos4210-cpufreq.o
52obj-$(CONFIG_ARM_EXYNOS4X12_CPUFREQ) += exynos4x12-cpufreq.o 52obj-$(CONFIG_ARM_EXYNOS4X12_CPUFREQ) += exynos4x12-cpufreq.o
53obj-$(CONFIG_ARM_EXYNOS5250_CPUFREQ) += exynos5250-cpufreq.o 53obj-$(CONFIG_ARM_EXYNOS5250_CPUFREQ) += exynos5250-cpufreq.o
54obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o 54obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o
55obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o 55obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
56obj-$(CONFIG_ARM_HIGHBANK_CPUFREQ) += highbank-cpufreq.o
56 57
57################################################################################## 58##################################################################################
58# PowerPC platform drivers 59# PowerPC platform drivers
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c
index debc5a7c8db6..38ae178ce4ef 100644
--- a/drivers/cpufreq/cpufreq-cpu0.c
+++ b/drivers/cpufreq/cpufreq-cpu0.c
@@ -182,7 +182,11 @@ static int cpu0_cpufreq_driver_init(void)
182 struct device_node *np; 182 struct device_node *np;
183 int ret; 183 int ret;
184 184
185 np = of_find_node_by_path("/cpus/cpu@0"); 185 for_each_child_of_node(of_find_node_by_path("/cpus"), np) {
186 if (of_get_property(np, "operating-points", NULL))
187 break;
188 }
189
186 if (!np) { 190 if (!np) {
187 pr_err("failed to find cpu0 node\n"); 191 pr_err("failed to find cpu0 node\n");
188 return -ENOENT; 192 return -ENOENT;
diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
new file mode 100644
index 000000000000..53f25e5aa6b7
--- /dev/null
+++ b/drivers/cpufreq/highbank-cpufreq.c
@@ -0,0 +1,115 @@
1/*
2 * Copyright (C) 2012 Calxeda, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This driver provides the clk notifier callbacks that are used when
9 * the cpufreq-cpu0 driver changes to frequency to alert the highbank
10 * EnergyCore Management Engine (ECME) about the need to change
11 * voltage. The ECME interfaces with the actual voltage regulators.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/clk.h>
19#include <linux/cpu.h>
20#include <linux/err.h>
21#include <linux/of.h>
22#include <linux/mailbox.h>
23
24#define HB_CPUFREQ_CHANGE_NOTE 0x80000001
25#define HB_CPUFREQ_IPC_LEN 7
26#define HB_CPUFREQ_VOLT_RETRIES 15
27
28static int hb_voltage_change(unsigned int freq)
29{
30 int i;
31 u32 msg[HB_CPUFREQ_IPC_LEN];
32
33 msg[0] = HB_CPUFREQ_CHANGE_NOTE;
34 msg[1] = freq / 1000000;
35 for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
36 msg[i] = 0;
37
38 return pl320_ipc_transmit(msg);
39}
40
41static int hb_cpufreq_clk_notify(struct notifier_block *nb,
42 unsigned long action, void *hclk)
43{
44 struct clk_notifier_data *clk_data = hclk;
45 int i = 0;
46
47 if (action == PRE_RATE_CHANGE) {
48 if (clk_data->new_rate > clk_data->old_rate)
49 while (hb_voltage_change(clk_data->new_rate))
50 if (i++ > HB_CPUFREQ_VOLT_RETRIES)
51 return NOTIFY_BAD;
52 } else if (action == POST_RATE_CHANGE) {
53 if (clk_data->new_rate < clk_data->old_rate)
54 while (hb_voltage_change(clk_data->new_rate))
55 if (i++ > HB_CPUFREQ_VOLT_RETRIES)
56 return NOTIFY_BAD;
57 }
58
59 return NOTIFY_DONE;
60}
61
62static struct notifier_block hb_cpufreq_clk_nb = {
63 .notifier_call = hb_cpufreq_clk_notify,
64};
65
66static int hb_cpufreq_driver_init(void)
67{
68 struct device *cpu_dev;
69 struct clk *cpu_clk;
70 struct device_node *np;
71 int ret;
72
73 if (!of_machine_is_compatible("calxeda,highbank"))
74 return -ENODEV;
75
76 for_each_child_of_node(of_find_node_by_path("/cpus"), np)
77 if (of_get_property(np, "operating-points", NULL))
78 break;
79
80 if (!np) {
81 pr_err("failed to find highbank cpufreq node\n");
82 return -ENOENT;
83 }
84
85 cpu_dev = get_cpu_device(0);
86 if (!cpu_dev) {
87 pr_err("failed to get highbank cpufreq device\n");
88 ret = -ENODEV;
89 goto out_put_node;
90 }
91
92 cpu_dev->of_node = np;
93
94 cpu_clk = clk_get(cpu_dev, NULL);
95 if (IS_ERR(cpu_clk)) {
96 ret = PTR_ERR(cpu_clk);
97 pr_err("failed to get cpu0 clock: %d\n", ret);
98 goto out_put_node;
99 }
100
101 ret = clk_notifier_register(cpu_clk, &hb_cpufreq_clk_nb);
102 if (ret) {
103 pr_err("failed to register clk notifier: %d\n", ret);
104 goto out_put_node;
105 }
106
107out_put_node:
108 of_node_put(np);
109 return ret;
110}
111module_init(hb_cpufreq_driver_init);
112
113MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@calxeda.com>");
114MODULE_DESCRIPTION("Calxeda Highbank cpufreq driver");
115MODULE_LICENSE("GPL");