]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
cpufreq / highbank: add support for highbank cpufreq
authorMark Langsdorf <mark.langsdorf@calxeda.com>
Mon, 28 Jan 2013 16:13:15 +0000 (16:13 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 1 Feb 2013 23:01:15 +0000 (00:01 +0100)
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>
arch/arm/boot/dts/highbank.dts
arch/arm/mach-highbank/Kconfig
drivers/cpufreq/Kconfig.arm
drivers/cpufreq/Makefile
drivers/cpufreq/cpufreq-cpu0.c
drivers/cpufreq/highbank-cpufreq.c [new file with mode: 0644]

index 5927a8df562536550b101669f45978f33907e0ac..6aad34ad9517f37424071dcac4859c400a93d1f5 100644 (file)
                        next-level-cache = <&L2>;
                        clocks = <&a9pll>;
                        clock-names = "cpu";
+                       operating-points = <
+                               /* kHz    ignored */
+                                1300000  1000000
+                                1200000  1000000
+                                1100000  1000000
+                                 800000  1000000
+                                 400000  1000000
+                                 200000  1000000
+                       >;
+                       clock-latency = <100000>;
                };
 
                cpu@901 {
index 2388085beaa28597bc64520b0b598928b89ff999..44b12f9c1584a205f4b66f48fe426a3293a342cb 100644 (file)
@@ -1,5 +1,7 @@
 config ARCH_HIGHBANK
        bool "Calxeda ECX-1000/2000 (Highbank/Midway)" if ARCH_MULTI_V7
+       select ARCH_HAS_CPUFREQ
+       select ARCH_HAS_OPP
        select ARCH_WANT_OPTIONAL_GPIOLIB
        select ARM_AMBA
        select ARM_GIC
index a0b3661d90b0e9bcb8a9d4bfe3d3553b61518fff..ffe55b8a98cc10fc5a5c5140373b1a17a4c16a6d 100644 (file)
@@ -83,3 +83,18 @@ config ARM_SPEAR_CPUFREQ
        default y
        help
          This adds the CPUFreq driver support for SPEAr SOCs.
+
+config ARM_HIGHBANK_CPUFREQ
+       tristate "Calxeda Highbank-based"
+       depends on ARCH_HIGHBANK
+       select CPU_FREQ_TABLE
+       select GENERIC_CPUFREQ_CPU0
+       select PM_OPP
+       select REGULATOR
+
+       default m
+       help
+         This adds the CPUFreq driver for Calxeda Highbank SoC
+         based boards.
+
+         If in doubt, say N.
index 24d4a63fd6cfed078df90ff5f170984cba968f1d..e2a5da77370fec9ff4d1e5dbb57fa5fb6cea41d9 100644 (file)
@@ -51,8 +51,9 @@ obj-$(CONFIG_ARM_EXYNOS_CPUFREQ)      += exynos-cpufreq.o
 obj-$(CONFIG_ARM_EXYNOS4210_CPUFREQ)   += exynos4210-cpufreq.o
 obj-$(CONFIG_ARM_EXYNOS4X12_CPUFREQ)   += exynos4x12-cpufreq.o
 obj-$(CONFIG_ARM_EXYNOS5250_CPUFREQ)   += exynos5250-cpufreq.o
-obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ)     += omap-cpufreq.o
+obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ)    += omap-cpufreq.o
 obj-$(CONFIG_ARM_SPEAR_CPUFREQ)                += spear-cpufreq.o
+obj-$(CONFIG_ARM_HIGHBANK_CPUFREQ)     += highbank-cpufreq.o
 
 ##################################################################################
 # PowerPC platform drivers
index debc5a7c8db6207feeb9c428ccc44b8fcaed8d2f..38ae178ce4ef6176c42aaf7c0930645f8fbbf25a 100644 (file)
@@ -182,7 +182,11 @@ static int cpu0_cpufreq_driver_init(void)
        struct device_node *np;
        int ret;
 
-       np = of_find_node_by_path("/cpus/cpu@0");
+       for_each_child_of_node(of_find_node_by_path("/cpus"), np) {
+               if (of_get_property(np, "operating-points", NULL))
+                       break;
+       }
+
        if (!np) {
                pr_err("failed to find cpu0 node\n");
                return -ENOENT;
diff --git a/drivers/cpufreq/highbank-cpufreq.c b/drivers/cpufreq/highbank-cpufreq.c
new file mode 100644 (file)
index 0000000..53f25e5
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2012 Calxeda, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This driver provides the clk notifier callbacks that are used when
+ * the cpufreq-cpu0 driver changes to frequency to alert the highbank
+ * EnergyCore Management Engine (ECME) about the need to change
+ * voltage. The ECME interfaces with the actual voltage regulators.
+ */
+
+#define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/clk.h>
+#include <linux/cpu.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/mailbox.h>
+
+#define HB_CPUFREQ_CHANGE_NOTE 0x80000001
+#define HB_CPUFREQ_IPC_LEN     7
+#define HB_CPUFREQ_VOLT_RETRIES        15
+
+static int hb_voltage_change(unsigned int freq)
+{
+       int i;
+       u32 msg[HB_CPUFREQ_IPC_LEN];
+
+       msg[0] = HB_CPUFREQ_CHANGE_NOTE;
+       msg[1] = freq / 1000000;
+       for (i = 2; i < HB_CPUFREQ_IPC_LEN; i++)
+               msg[i] = 0;
+
+       return pl320_ipc_transmit(msg);
+}
+
+static int hb_cpufreq_clk_notify(struct notifier_block *nb,
+                               unsigned long action, void *hclk)
+{
+       struct clk_notifier_data *clk_data = hclk;
+       int i = 0;
+
+       if (action == PRE_RATE_CHANGE) {
+               if (clk_data->new_rate > clk_data->old_rate)
+                       while (hb_voltage_change(clk_data->new_rate))
+                               if (i++ > HB_CPUFREQ_VOLT_RETRIES)
+                                       return NOTIFY_BAD;
+       } else if (action == POST_RATE_CHANGE) {
+               if (clk_data->new_rate < clk_data->old_rate)
+                       while (hb_voltage_change(clk_data->new_rate))
+                               if (i++ > HB_CPUFREQ_VOLT_RETRIES)
+                                       return NOTIFY_BAD;
+       }
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block hb_cpufreq_clk_nb = {
+       .notifier_call = hb_cpufreq_clk_notify,
+};
+
+static int hb_cpufreq_driver_init(void)
+{
+       struct device *cpu_dev;
+       struct clk *cpu_clk;
+       struct device_node *np;
+       int ret;
+
+       if (!of_machine_is_compatible("calxeda,highbank"))
+               return -ENODEV;
+
+       for_each_child_of_node(of_find_node_by_path("/cpus"), np)
+               if (of_get_property(np, "operating-points", NULL))
+                       break;
+
+       if (!np) {
+               pr_err("failed to find highbank cpufreq node\n");
+               return -ENOENT;
+       }
+
+       cpu_dev = get_cpu_device(0);
+       if (!cpu_dev) {
+               pr_err("failed to get highbank cpufreq device\n");
+               ret = -ENODEV;
+               goto out_put_node;
+       }
+
+       cpu_dev->of_node = np;
+
+       cpu_clk = clk_get(cpu_dev, NULL);
+       if (IS_ERR(cpu_clk)) {
+               ret = PTR_ERR(cpu_clk);
+               pr_err("failed to get cpu0 clock: %d\n", ret);
+               goto out_put_node;
+       }
+
+       ret = clk_notifier_register(cpu_clk, &hb_cpufreq_clk_nb);
+       if (ret) {
+               pr_err("failed to register clk notifier: %d\n", ret);
+               goto out_put_node;
+       }
+
+out_put_node:
+       of_node_put(np);
+       return ret;
+}
+module_init(hb_cpufreq_driver_init);
+
+MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@calxeda.com>");
+MODULE_DESCRIPTION("Calxeda Highbank cpufreq driver");
+MODULE_LICENSE("GPL");