2012-11-17 22:22:23 +08:00
|
|
|
/*
|
|
|
|
* Marvell MVEBU CPU clock handling.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Marvell
|
|
|
|
*
|
|
|
|
* Gregory CLEMENT <gregory.clement@free-electrons.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
2015-06-20 06:00:46 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/clk.h>
|
2012-11-17 22:22:23 +08:00
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/delay.h>
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
#include <linux/mvebu-pmsu.h>
|
|
|
|
#include <asm/smp_plat.h>
|
2012-11-17 22:22:23 +08:00
|
|
|
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
#define SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET 0x0
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_CTRL_RESET_ALL 0xff
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_CTRL_RESET_SHIFT 8
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_CTRL2_OFFSET 0x8
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_CTRL2_NBCLK_RATIO_SHIFT 16
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_VALUE_OFFSET 0xC
|
|
|
|
#define SYS_CTRL_CLK_DIVIDER_MASK 0x3F
|
|
|
|
|
|
|
|
#define PMU_DFS_RATIO_SHIFT 16
|
|
|
|
#define PMU_DFS_RATIO_MASK 0x3F
|
2012-11-17 22:22:23 +08:00
|
|
|
|
|
|
|
#define MAX_CPU 4
|
|
|
|
struct cpu_clk {
|
|
|
|
struct clk_hw hw;
|
|
|
|
int cpu;
|
|
|
|
const char *clk_name;
|
|
|
|
const char *parent_name;
|
|
|
|
void __iomem *reg_base;
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
void __iomem *pmu_dfs;
|
2012-11-17 22:22:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct clk **clks;
|
|
|
|
|
|
|
|
static struct clk_onecell_data clk_data;
|
|
|
|
|
|
|
|
#define to_cpu_clk(p) container_of(p, struct cpu_clk, hw)
|
|
|
|
|
|
|
|
static unsigned long clk_cpu_recalc_rate(struct clk_hw *hwclk,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct cpu_clk *cpuclk = to_cpu_clk(hwclk);
|
|
|
|
u32 reg, div;
|
|
|
|
|
|
|
|
reg = readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_VALUE_OFFSET);
|
|
|
|
div = (reg >> (cpuclk->cpu * 8)) & SYS_CTRL_CLK_DIVIDER_MASK;
|
|
|
|
return parent_rate / div;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long clk_cpu_round_rate(struct clk_hw *hwclk, unsigned long rate,
|
|
|
|
unsigned long *parent_rate)
|
|
|
|
{
|
|
|
|
/* Valid ratio are 1:1, 1:2 and 1:3 */
|
|
|
|
u32 div;
|
|
|
|
|
|
|
|
div = *parent_rate / rate;
|
|
|
|
if (div == 0)
|
|
|
|
div = 1;
|
|
|
|
else if (div > 3)
|
|
|
|
div = 3;
|
|
|
|
|
|
|
|
return *parent_rate / div;
|
|
|
|
}
|
|
|
|
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
static int clk_cpu_off_set_rate(struct clk_hw *hwclk, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
|
2012-11-17 22:22:23 +08:00
|
|
|
{
|
|
|
|
struct cpu_clk *cpuclk = to_cpu_clk(hwclk);
|
|
|
|
u32 reg, div;
|
|
|
|
u32 reload_mask;
|
|
|
|
|
|
|
|
div = parent_rate / rate;
|
|
|
|
reg = (readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_VALUE_OFFSET)
|
|
|
|
& (~(SYS_CTRL_CLK_DIVIDER_MASK << (cpuclk->cpu * 8))))
|
|
|
|
| (div << (cpuclk->cpu * 8));
|
|
|
|
writel(reg, cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_VALUE_OFFSET);
|
|
|
|
/* Set clock divider reload smooth bit mask */
|
|
|
|
reload_mask = 1 << (20 + cpuclk->cpu);
|
|
|
|
|
|
|
|
reg = readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET)
|
|
|
|
| reload_mask;
|
|
|
|
writel(reg, cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET);
|
|
|
|
|
|
|
|
/* Now trigger the clock update */
|
|
|
|
reg = readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET)
|
|
|
|
| 1 << 24;
|
|
|
|
writel(reg, cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET);
|
|
|
|
|
|
|
|
/* Wait for clocks to settle down then clear reload request */
|
|
|
|
udelay(1000);
|
|
|
|
reg &= ~(reload_mask | 1 << 24);
|
|
|
|
writel(reg, cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET);
|
|
|
|
udelay(1000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
static int clk_cpu_on_set_rate(struct clk_hw *hwclk, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
unsigned long fabric_div, target_div, cur_rate;
|
|
|
|
struct cpu_clk *cpuclk = to_cpu_clk(hwclk);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PMU DFS registers are not mapped, Device Tree does not
|
|
|
|
* describes them. We cannot change the frequency dynamically.
|
|
|
|
*/
|
|
|
|
if (!cpuclk->pmu_dfs)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2015-07-31 08:20:57 +08:00
|
|
|
cur_rate = clk_hw_get_rate(hwclk);
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
|
|
|
|
reg = readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL2_OFFSET);
|
|
|
|
fabric_div = (reg >> SYS_CTRL_CLK_DIVIDER_CTRL2_NBCLK_RATIO_SHIFT) &
|
|
|
|
SYS_CTRL_CLK_DIVIDER_MASK;
|
|
|
|
|
|
|
|
/* Frequency is going up */
|
|
|
|
if (rate == 2 * cur_rate)
|
|
|
|
target_div = fabric_div / 2;
|
|
|
|
/* Frequency is going down */
|
|
|
|
else
|
|
|
|
target_div = fabric_div;
|
|
|
|
|
|
|
|
if (target_div == 0)
|
|
|
|
target_div = 1;
|
|
|
|
|
|
|
|
reg = readl(cpuclk->pmu_dfs);
|
|
|
|
reg &= ~(PMU_DFS_RATIO_MASK << PMU_DFS_RATIO_SHIFT);
|
|
|
|
reg |= (target_div << PMU_DFS_RATIO_SHIFT);
|
|
|
|
writel(reg, cpuclk->pmu_dfs);
|
|
|
|
|
|
|
|
reg = readl(cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET);
|
|
|
|
reg |= (SYS_CTRL_CLK_DIVIDER_CTRL_RESET_ALL <<
|
|
|
|
SYS_CTRL_CLK_DIVIDER_CTRL_RESET_SHIFT);
|
|
|
|
writel(reg, cpuclk->reg_base + SYS_CTRL_CLK_DIVIDER_CTRL_OFFSET);
|
|
|
|
|
|
|
|
return mvebu_pmsu_dfs_request(cpuclk->cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_cpu_set_rate(struct clk_hw *hwclk, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
if (__clk_is_enabled(hwclk->clk))
|
|
|
|
return clk_cpu_on_set_rate(hwclk, rate, parent_rate);
|
|
|
|
else
|
|
|
|
return clk_cpu_off_set_rate(hwclk, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
2012-11-17 22:22:23 +08:00
|
|
|
static const struct clk_ops cpu_ops = {
|
|
|
|
.recalc_rate = clk_cpu_recalc_rate,
|
|
|
|
.round_rate = clk_cpu_round_rate,
|
|
|
|
.set_rate = clk_cpu_set_rate,
|
|
|
|
};
|
|
|
|
|
2013-10-08 19:17:45 +08:00
|
|
|
static void __init of_cpu_clk_setup(struct device_node *node)
|
2012-11-17 22:22:23 +08:00
|
|
|
{
|
|
|
|
struct cpu_clk *cpuclk;
|
|
|
|
void __iomem *clock_complex_base = of_iomap(node, 0);
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
void __iomem *pmu_dfs_base = of_iomap(node, 1);
|
2012-11-17 22:22:23 +08:00
|
|
|
int ncpus = 0;
|
|
|
|
struct device_node *dn;
|
|
|
|
|
|
|
|
if (clock_complex_base == NULL) {
|
|
|
|
pr_err("%s: clock-complex base register not set\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
if (pmu_dfs_base == NULL)
|
|
|
|
pr_warn("%s: pmu-dfs base register not set, dynamic frequency scaling not available\n",
|
|
|
|
__func__);
|
|
|
|
|
2012-11-17 22:22:23 +08:00
|
|
|
for_each_node_by_type(dn, "cpu")
|
|
|
|
ncpus++;
|
|
|
|
|
2017-04-20 02:15:21 +08:00
|
|
|
cpuclk = kcalloc(ncpus, sizeof(*cpuclk), GFP_KERNEL);
|
2012-11-17 22:22:23 +08:00
|
|
|
if (WARN_ON(!cpuclk))
|
2013-08-23 10:34:01 +08:00
|
|
|
goto cpuclk_out;
|
2012-11-17 22:22:23 +08:00
|
|
|
|
2017-04-20 02:15:21 +08:00
|
|
|
clks = kcalloc(ncpus, sizeof(*clks), GFP_KERNEL);
|
2012-11-17 22:22:23 +08:00
|
|
|
if (WARN_ON(!clks))
|
2013-01-16 02:44:26 +08:00
|
|
|
goto clks_out;
|
2012-11-17 22:22:23 +08:00
|
|
|
|
|
|
|
for_each_node_by_type(dn, "cpu") {
|
|
|
|
struct clk_init_data init;
|
|
|
|
struct clk *clk;
|
|
|
|
char *clk_name = kzalloc(5, GFP_KERNEL);
|
|
|
|
int cpu, err;
|
|
|
|
|
|
|
|
if (WARN_ON(!clk_name))
|
2013-01-16 02:44:26 +08:00
|
|
|
goto bail_out;
|
2012-11-17 22:22:23 +08:00
|
|
|
|
|
|
|
err = of_property_read_u32(dn, "reg", &cpu);
|
|
|
|
if (WARN_ON(err))
|
2013-01-16 02:44:26 +08:00
|
|
|
goto bail_out;
|
2012-11-17 22:22:23 +08:00
|
|
|
|
|
|
|
sprintf(clk_name, "cpu%d", cpu);
|
|
|
|
|
2015-10-17 07:35:11 +08:00
|
|
|
cpuclk[cpu].parent_name = of_clk_get_parent_name(node, 0);
|
2012-11-17 22:22:23 +08:00
|
|
|
cpuclk[cpu].clk_name = clk_name;
|
|
|
|
cpuclk[cpu].cpu = cpu;
|
|
|
|
cpuclk[cpu].reg_base = clock_complex_base;
|
clk: mvebu: extend clk-cpu for dynamic frequency scaling
This commit extends the existing clk-cpu driver used on Marvell Armada
XP platforms to support the dynamic frequency scaling of the CPU
clock. Non-dynamic frequency change was already supported (and used
before secondary CPUs are started), but the dynamic frequency change
requires a completely different procedure.
In order to achieve this, the clk_cpu_set_rate() function is reworked
to handle two separate cases:
- The case where the clock is enabled, which is the new dynamic
frequency change code, implemented in clk_cpu_on_set_rate(). This
part will be used for cpufreq activities.
- The case where the clock is disabled, which is the existing
frequency change code, moved in clk_cpu_off_set_rate(). This part
is already used to set the clock frequency of the secondary CPUs
before starting them.
In order to implement the dynamic frequency change function, we need
to access the PMU DFS registers, which are outside the currently
mapped "Clock Complex" registers, so a new area of registers is now
mapped. This affects the Device Tree binding, but we are careful to do
it in a backward-compatible way (by allowing the second pair of
registers to be non-existent, and in this case, ensuring
clk_cpu_on_set_rate() returns an error).
Note that technically speaking, the clk_cpu_on_set_rate() does not do
the entire procedure needed to change the frequency dynamically, as it
involves touching a number of PMSU registers. This is done through a
clock notifier registered by the PMSU driver in followup commits.
Cc: <devicetree@vger.kernel.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1404920715-19834-4-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
2014-07-09 23:45:11 +08:00
|
|
|
if (pmu_dfs_base)
|
|
|
|
cpuclk[cpu].pmu_dfs = pmu_dfs_base + 4 * cpu;
|
2012-11-17 22:22:23 +08:00
|
|
|
cpuclk[cpu].hw.init = &init;
|
|
|
|
|
|
|
|
init.name = cpuclk[cpu].clk_name;
|
|
|
|
init.ops = &cpu_ops;
|
|
|
|
init.flags = 0;
|
|
|
|
init.parent_names = &cpuclk[cpu].parent_name;
|
|
|
|
init.num_parents = 1;
|
|
|
|
|
|
|
|
clk = clk_register(NULL, &cpuclk[cpu].hw);
|
|
|
|
if (WARN_ON(IS_ERR(clk)))
|
|
|
|
goto bail_out;
|
|
|
|
clks[cpu] = clk;
|
|
|
|
}
|
|
|
|
clk_data.clk_num = MAX_CPU;
|
|
|
|
clk_data.clks = clks;
|
|
|
|
of_clk_add_provider(node, of_clk_src_onecell_get, &clk_data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
bail_out:
|
|
|
|
kfree(clks);
|
2013-01-16 02:44:26 +08:00
|
|
|
while(ncpus--)
|
|
|
|
kfree(cpuclk[ncpus].clk_name);
|
|
|
|
clks_out:
|
2012-11-17 22:22:23 +08:00
|
|
|
kfree(cpuclk);
|
2013-08-23 10:34:01 +08:00
|
|
|
cpuclk_out:
|
|
|
|
iounmap(clock_complex_base);
|
2012-11-17 22:22:23 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 19:02:36 +08:00
|
|
|
CLK_OF_DECLARE(armada_xp_cpu_clock, "marvell,armada-xp-cpu-clock",
|
|
|
|
of_cpu_clk_setup);
|
2017-01-27 11:25:42 +08:00
|
|
|
|
|
|
|
static void __init of_mv98dx3236_cpu_clk_setup(struct device_node *node)
|
|
|
|
{
|
|
|
|
of_clk_add_provider(node, of_clk_src_simple_get, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CLK_OF_DECLARE(mv98dx3236_cpu_clock, "marvell,mv98dx3236-cpu-clock",
|
|
|
|
of_mv98dx3236_cpu_clk_setup);
|