]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge branch 'cpufreq/qcom-hw' into cpufreq/arm/linux-next
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 8 Feb 2019 04:10:29 +0000 (09:40 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Fri, 8 Feb 2019 04:10:29 +0000 (09:40 +0530)
MAINTAINERS
drivers/cpufreq/Kconfig.arm
drivers/cpufreq/Makefile
drivers/cpufreq/armada-8k-cpufreq.c [new file with mode: 0644]
drivers/cpufreq/qcom-cpufreq-kryo.c
drivers/cpufreq/s5pv210-cpufreq.c
drivers/cpufreq/tegra124-cpufreq.c

index 4d04cebb4a7127eb94320e23aff16d304d9aeaff..b34df5d57cde67dcbbc452e23f586ab931bbb70d 100644 (file)
@@ -1737,6 +1737,7 @@ F:        arch/arm/configs/mvebu_*_defconfig
 F:     arch/arm/mach-mvebu/
 F:     arch/arm64/boot/dts/marvell/armada*
 F:     drivers/cpufreq/armada-37xx-cpufreq.c
+F:     drivers/cpufreq/armada-8k-cpufreq.c
 F:     drivers/cpufreq/mvebu-cpufreq.c
 F:     drivers/irqchip/irq-armada-370-xp.c
 F:     drivers/irqchip/irq-mvebu-*
@@ -3957,7 +3958,7 @@ M:        Viresh Kumar <viresh.kumar@linaro.org>
 L:     linux-pm@vger.kernel.org
 S:     Maintained
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
-T:     git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates)
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git (For ARM Updates)
 B:     https://bugzilla.kernel.org
 F:     Documentation/admin-guide/pm/cpufreq.rst
 F:     Documentation/admin-guide/pm/intel_pstate.rst
@@ -12596,11 +12597,11 @@ F:    Documentation/media/v4l-drivers/qcom_camss.rst
 F:     drivers/media/platform/qcom/camss/
 
 QUALCOMM CPUFREQ DRIVER MSM8996/APQ8096
-M:  Ilia Lin <ilia.lin@gmail.com>
-L:  linux-pm@vger.kernel.org
-S:  Maintained
-F:  Documentation/devicetree/bindings/opp/kryo-cpufreq.txt
-F:  drivers/cpufreq/qcom-cpufreq-kryo.c
+M:     Ilia Lin <ilia.lin@kernel.org>
+L:     linux-pm@vger.kernel.org
+S:     Maintained
+F:     Documentation/devicetree/bindings/opp/kryo-cpufreq.txt
+F:     drivers/cpufreq/qcom-cpufreq-kryo.c
 
 QUALCOMM EMAC GIGABIT ETHERNET DRIVER
 M:     Timur Tabi <timur@kernel.org>
index 688f10227793d73a687416ad2a3aa69fab53f3a6..10bc5c798d179076da5900eaa36aecba27c7fca0 100644 (file)
@@ -25,6 +25,17 @@ config ARM_ARMADA_37XX_CPUFREQ
          This adds the CPUFreq driver support for Marvell Armada 37xx SoCs.
          The Armada 37xx PMU supports 4 frequency and VDD levels.
 
+config ARM_ARMADA_8K_CPUFREQ
+       tristate "Armada 8K CPUFreq driver"
+       depends on ARCH_MVEBU && CPUFREQ_DT
+       help
+         This enables the CPUFreq driver support for Marvell
+         Armada8k SOCs.
+         Armada8K device has the AP806 which supports scaling
+         to any full integer divider.
+
+         If in doubt, say N.
+
 # big LITTLE core layer and glue drivers
 config ARM_BIG_LITTLE_CPUFREQ
        tristate "Generic ARM big LITTLE CPUfreq driver"
index 08c071be24912f86514907352aa82d14b625db8d..689b26c6f94957631abb3a90067bf3ecbe7b87e1 100644 (file)
@@ -50,6 +50,7 @@ obj-$(CONFIG_X86_SFI_CPUFREQ)         += sfi-cpufreq.o
 obj-$(CONFIG_ARM_BIG_LITTLE_CPUFREQ)   += arm_big_little.o
 
 obj-$(CONFIG_ARM_ARMADA_37XX_CPUFREQ)  += armada-37xx-cpufreq.o
+obj-$(CONFIG_ARM_ARMADA_8K_CPUFREQ)    += armada-8k-cpufreq.o
 obj-$(CONFIG_ARM_BRCMSTB_AVS_CPUFREQ)  += brcmstb-avs-cpufreq.o
 obj-$(CONFIG_ACPI_CPPC_CPUFREQ)                += cppc_cpufreq.o
 obj-$(CONFIG_ARCH_DAVINCI)             += davinci-cpufreq.o
diff --git a/drivers/cpufreq/armada-8k-cpufreq.c b/drivers/cpufreq/armada-8k-cpufreq.c
new file mode 100644 (file)
index 0000000..8a5ddb9
--- /dev/null
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * CPUFreq support for Armada 8K
+ *
+ * Copyright (C) 2018 Marvell
+ *
+ * Omri Itach <omrii@marvell.com>
+ * Gregory Clement <gregory.clement@bootlin.com>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/clk.h>
+#include <linux/cpu.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_opp.h>
+#include <linux/slab.h>
+
+/*
+ * Setup the opps list with the divider for the max frequency, that
+ * will be filled at runtime.
+ */
+static const int opps_div[] __initconst = {1, 2, 3, 4};
+
+static struct platform_device *armada_8k_pdev;
+
+struct freq_table {
+       struct device *cpu_dev;
+       unsigned int freq[ARRAY_SIZE(opps_div)];
+};
+
+/* If the CPUs share the same clock, then they are in the same cluster. */
+static void __init armada_8k_get_sharing_cpus(struct clk *cur_clk,
+                                             struct cpumask *cpumask)
+{
+       int cpu;
+
+       for_each_possible_cpu(cpu) {
+               struct device *cpu_dev;
+               struct clk *clk;
+
+               cpu_dev = get_cpu_device(cpu);
+               if (!cpu_dev) {
+                       pr_warn("Failed to get cpu%d device\n", cpu);
+                       continue;
+               }
+
+               clk = clk_get(cpu_dev, 0);
+               if (IS_ERR(clk)) {
+                       pr_warn("Cannot get clock for CPU %d\n", cpu);
+               } else {
+                       if (clk_is_match(clk, cur_clk))
+                               cpumask_set_cpu(cpu, cpumask);
+
+                       clk_put(clk);
+               }
+       }
+}
+
+static int __init armada_8k_add_opp(struct clk *clk, struct device *cpu_dev,
+                                   struct freq_table *freq_tables,
+                                   int opps_index)
+{
+       unsigned int cur_frequency;
+       unsigned int freq;
+       int i, ret;
+
+       /* Get nominal (current) CPU frequency. */
+       cur_frequency = clk_get_rate(clk);
+       if (!cur_frequency) {
+               dev_err(cpu_dev, "Failed to get clock rate for this CPU\n");
+               return -EINVAL;
+       }
+
+       freq_tables[opps_index].cpu_dev = cpu_dev;
+
+       for (i = 0; i < ARRAY_SIZE(opps_div); i++) {
+               freq = cur_frequency / opps_div[i];
+
+               ret = dev_pm_opp_add(cpu_dev, freq, 0);
+               if (ret)
+                       return ret;
+
+               freq_tables[opps_index].freq[i] = freq;
+       }
+
+       return 0;
+}
+
+static void armada_8k_cpufreq_free_table(struct freq_table *freq_tables)
+{
+       int opps_index, nb_cpus = num_possible_cpus();
+
+       for (opps_index = 0 ; opps_index <= nb_cpus; opps_index++) {
+               int i;
+
+               /* If cpu_dev is NULL then we reached the end of the array */
+               if (!freq_tables[opps_index].cpu_dev)
+                       break;
+
+               for (i = 0; i < ARRAY_SIZE(opps_div); i++) {
+                       /*
+                        * A 0Hz frequency is not valid, this meant
+                        * that it was not yet initialized so there is
+                        * no more opp to free
+                        */
+                       if (freq_tables[opps_index].freq[i] == 0)
+                               break;
+
+                       dev_pm_opp_remove(freq_tables[opps_index].cpu_dev,
+                                         freq_tables[opps_index].freq[i]);
+               }
+       }
+
+       kfree(freq_tables);
+}
+
+static int __init armada_8k_cpufreq_init(void)
+{
+       int ret = 0, opps_index = 0, cpu, nb_cpus;
+       struct freq_table *freq_tables;
+       struct device_node *node;
+       struct cpumask cpus;
+
+       node = of_find_compatible_node(NULL, NULL, "marvell,ap806-cpu-clock");
+       if (!node || !of_device_is_available(node))
+               return -ENODEV;
+
+       nb_cpus = num_possible_cpus();
+       freq_tables = kcalloc(nb_cpus, sizeof(*freq_tables), GFP_KERNEL);
+       cpumask_copy(&cpus, cpu_possible_mask);
+
+       /*
+        * For each CPU, this loop registers the operating points
+        * supported (which are the nominal CPU frequency and full integer
+        * divisions of it).
+        */
+       for_each_cpu(cpu, &cpus) {
+               struct cpumask shared_cpus;
+               struct device *cpu_dev;
+               struct clk *clk;
+
+               cpu_dev = get_cpu_device(cpu);
+
+               if (!cpu_dev) {
+                       pr_err("Cannot get CPU %d\n", cpu);
+                       continue;
+               }
+
+               clk = clk_get(cpu_dev, 0);
+
+               if (IS_ERR(clk)) {
+                       pr_err("Cannot get clock for CPU %d\n", cpu);
+                       ret = PTR_ERR(clk);
+                       goto remove_opp;
+               }
+
+               ret = armada_8k_add_opp(clk, cpu_dev, freq_tables, opps_index);
+               if (ret) {
+                       clk_put(clk);
+                       goto remove_opp;
+               }
+
+               opps_index++;
+               cpumask_clear(&shared_cpus);
+               armada_8k_get_sharing_cpus(clk, &shared_cpus);
+               dev_pm_opp_set_sharing_cpus(cpu_dev, &shared_cpus);
+               cpumask_andnot(&cpus, &cpus, &shared_cpus);
+               clk_put(clk);
+       }
+
+       armada_8k_pdev = platform_device_register_simple("cpufreq-dt", -1,
+                                                        NULL, 0);
+       ret = PTR_ERR_OR_ZERO(armada_8k_pdev);
+       if (ret)
+               goto remove_opp;
+
+       platform_set_drvdata(armada_8k_pdev, freq_tables);
+
+       return 0;
+
+remove_opp:
+       armada_8k_cpufreq_free_table(freq_tables);
+       return ret;
+}
+module_init(armada_8k_cpufreq_init);
+
+static void __exit armada_8k_cpufreq_exit(void)
+{
+       struct freq_table *freq_tables = platform_get_drvdata(armada_8k_pdev);
+
+       platform_device_unregister(armada_8k_pdev);
+       armada_8k_cpufreq_free_table(freq_tables);
+}
+module_exit(armada_8k_cpufreq_exit);
+
+MODULE_AUTHOR("Gregory Clement <gregory.clement@bootlin.com>");
+MODULE_DESCRIPTION("Armada 8K cpufreq driver");
+MODULE_LICENSE("GPL");
index 2a3675c24032bc8059c4c591698d6a7b5218cf1d..1c8583cc06a2aa5f95bfc4c4ce0ca6f56e9a5d62 100644 (file)
@@ -42,7 +42,7 @@ enum _msm8996_version {
        NUM_OF_MSM8996_VERSIONS,
 };
 
-struct platform_device *cpufreq_dt_pdev, *kryo_cpufreq_pdev;
+static struct platform_device *cpufreq_dt_pdev, *kryo_cpufreq_pdev;
 
 static enum _msm8996_version qcom_cpufreq_kryo_get_msm_id(void)
 {
index dbecd7667db28a5b325284a519fba0107ff45354..5b4289460bc9ecdb61ef7cbbda15eca84cc2e4ab 100644 (file)
@@ -584,7 +584,7 @@ static struct notifier_block s5pv210_cpufreq_reboot_notifier = {
 static int s5pv210_cpufreq_probe(struct platform_device *pdev)
 {
        struct device_node *np;
-       int id;
+       int id, result = 0;
 
        /*
         * HACK: This is a temporary workaround to get access to clock
@@ -594,18 +594,39 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
         * this whole driver as soon as S5PV210 gets migrated to use
         * cpufreq-dt driver.
         */
+       arm_regulator = regulator_get(NULL, "vddarm");
+       if (IS_ERR(arm_regulator)) {
+               if (PTR_ERR(arm_regulator) == -EPROBE_DEFER)
+                       pr_debug("vddarm regulator not ready, defer\n");
+               else
+                       pr_err("failed to get regulator vddarm\n");
+               return PTR_ERR(arm_regulator);
+       }
+
+       int_regulator = regulator_get(NULL, "vddint");
+       if (IS_ERR(int_regulator)) {
+               if (PTR_ERR(int_regulator) == -EPROBE_DEFER)
+                       pr_debug("vddint regulator not ready, defer\n");
+               else
+                       pr_err("failed to get regulator vddint\n");
+               result = PTR_ERR(int_regulator);
+               goto err_int_regulator;
+       }
+
        np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock");
        if (!np) {
                pr_err("%s: failed to find clock controller DT node\n",
                        __func__);
-               return -ENODEV;
+               result = -ENODEV;
+               goto err_clock;
        }
 
        clk_base = of_iomap(np, 0);
        of_node_put(np);
        if (!clk_base) {
                pr_err("%s: failed to map clock registers\n", __func__);
-               return -EFAULT;
+               result = -EFAULT;
+               goto err_clock;
        }
 
        for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") {
@@ -614,7 +635,8 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
                        pr_err("%s: failed to get alias of dmc node '%pOFn'\n",
                                __func__, np);
                        of_node_put(np);
-                       return id;
+                       result = id;
+                       goto err_clk_base;
                }
 
                dmc_base[id] = of_iomap(np, 0);
@@ -622,33 +644,40 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev)
                        pr_err("%s: failed to map dmc%d registers\n",
                                __func__, id);
                        of_node_put(np);
-                       return -EFAULT;
+                       result = -EFAULT;
+                       goto err_dmc;
                }
        }
 
        for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) {
                if (!dmc_base[id]) {
                        pr_err("%s: failed to find dmc%d node\n", __func__, id);
-                       return -ENODEV;
+                       result = -ENODEV;
+                       goto err_dmc;
                }
        }
 
-       arm_regulator = regulator_get(NULL, "vddarm");
-       if (IS_ERR(arm_regulator)) {
-               pr_err("failed to get regulator vddarm\n");
-               return PTR_ERR(arm_regulator);
-       }
-
-       int_regulator = regulator_get(NULL, "vddint");
-       if (IS_ERR(int_regulator)) {
-               pr_err("failed to get regulator vddint\n");
-               regulator_put(arm_regulator);
-               return PTR_ERR(int_regulator);
-       }
-
        register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
 
        return cpufreq_register_driver(&s5pv210_driver);
+
+err_dmc:
+       for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
+               if (dmc_base[id]) {
+                       iounmap(dmc_base[id]);
+                       dmc_base[id] = NULL;
+               }
+
+err_clk_base:
+       iounmap(clk_base);
+
+err_clock:
+       regulator_put(int_regulator);
+
+err_int_regulator:
+       regulator_put(arm_regulator);
+
+       return result;
 }
 
 static struct platform_driver s5pv210_cpufreq_platdrv = {
index 43530254201a8b3a5f98fdcb032ea6c3b635bb96..4bb154f6c54cdcef9ca19ed3a071e1a2f674b474 100644 (file)
@@ -134,6 +134,8 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, priv);
 
+       of_node_put(np);
+
        return 0;
 
 out_switch_to_pllx: