1 // SPDX-License-Identifier: GPL-2.0-only
3 * CPUFreq support for Armada 370/XP platforms.
5 * Copyright (C) 2012-2016 Marvell
7 * Yehuda Yitschak <yehuday@marvell.com>
8 * Gregory Clement <gregory.clement@free-electrons.com>
9 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
12 #define pr_fmt(fmt) "mvebu-pmsu: " fmt
14 #include <linux/clk.h>
15 #include <linux/cpu.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/of_address.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_opp.h>
21 #include <linux/resource.h>
23 static int __init armada_xp_pmsu_cpufreq_init(void)
25 struct device_node *np;
29 if (!of_machine_is_compatible("marvell,armadaxp"))
33 * In order to have proper cpufreq handling, we need to ensure
34 * that the Device Tree description of the CPU clock includes
35 * the definition of the PMU DFS registers. If not, we do not
36 * register the clock notifier and the cpufreq driver. This
37 * piece of code is only for compatibility with old Device
40 np = of_find_compatible_node(NULL, NULL, "marvell,armada-xp-cpu-clock");
44 ret = of_address_to_resource(np, 1, &res);
46 pr_warn(FW_WARN "not enabling cpufreq, deprecated armada-xp-cpu-clock binding\n");
54 * For each CPU, this loop registers the operating points
55 * supported (which are the nominal CPU frequency and half of
56 * it), and registers the clock notifier that will take care
57 * of doing the PMSU part of a frequency transition.
59 for_each_possible_cpu(cpu) {
60 struct device *cpu_dev;
64 cpu_dev = get_cpu_device(cpu);
66 pr_err("Cannot get CPU %d\n", cpu);
70 clk = clk_get(cpu_dev, NULL);
72 pr_err("Cannot get clock for CPU %d\n", cpu);
76 ret = dev_pm_opp_add(cpu_dev, clk_get_rate(clk), 0);
82 ret = dev_pm_opp_add(cpu_dev, clk_get_rate(clk) / 2, 0);
84 dev_pm_opp_remove(cpu_dev, clk_get_rate(clk));
86 dev_err(cpu_dev, "Failed to register OPPs\n");
90 ret = dev_pm_opp_set_sharing_cpus(cpu_dev,
91 cpumask_of(cpu_dev->id));
93 dev_err(cpu_dev, "%s: failed to mark OPPs as shared: %d\n",
98 platform_device_register_simple("cpufreq-dt", -1, NULL, 0);
101 device_initcall(armada_xp_pmsu_cpufreq_init);