forked from luck/tmp_suning_uos_patched
519f64bf15
because of summer time holidays/vacations. The biggest change in the diffstat is in the Qualcomm clk driver, where they got support for CPUs and handful of SoCs. After that, the at91 driver got a major rewrite for newer DT bindings that should make things easier going forward and the TI code moved to a clockdomain based design. The long tail is mostly small driver updates for newer clks and some simpler SoC clock drivers such as the Hisilicon and imx support. In the core framework, we only have two small changes this time. One is a new clk API to get all clks for a device with the bulk clk APIs. This allows drivers that don't care about doing anything besides turning on all the clks to just clk_get() them all and turn them on. The other change is the beginning of a way to support save and restore of clk settings in the clk framework. TI is the only user right now, but we will want to expand upon this design in the future to support more save and restore of clk registers. At least this gets us started and works well enough for one SoC, but there's more work in the future. Core: - clk_bulk_get_all() API and friends to get all the clks for a device - Basic clk state save/restore hooks New Drivers: - Renesas RZ/A2 (R7S9210) SoC, including early clocks - Rensas RZ/G1N (R8A7744) and RZ/G2E (R8A774C0) SoCs - Rensas RZ/G2M (r8a774a1) SoC - Qualcomm Krait CPU clk support - Qualcomm QCS404 GCC support - Qualcomm SDM660 GCC support - Qualcomm SDM845 camera clock controller - Ingenic jz4725b CGU - Hisilicon 3670 SoC support - TI SCI clks on K3 SoCs - iMX6 MMDC clks - Reset Controller (RMU) support for Actions Semi Owl S900 and S700 SoCs Updates: - Rework at91 PMC clock driver for new DT bindings - Nvidia Tegra clk driver MBIST workaround fix - S2RAM support for Marvell mvebu periph clks - Use updated printk format for OF node names - Fix TI code to only search DT subnodes - Various static analysis finds - Tag various drivers with SPDX license tags - Support dynamic frequency switching (DFS) on qcom SDM845 GCC - Only use s2mps11 dt-binding defines instead of redefining them in the driver - Add some more missing clks to qcom MSM8996 GCC - Quad SPI clks on qcom SDM845 - Add support for CMT timer clocks on R-Car V3H - Add support for SHDI and various timer clocks on R-Car V3M - Improve OSC and RCLK (watchdog) handling on R-Car Gen3 SoCs - Amlogic clk-pll driver improvements and updates - Amlogic axg audio controller system clocks - Register Amlogic meson8b clock controller early - Add support for SATA and Fine Display Processor (FDP) clocks on R-Car M3-N - Consolidation of system suspend related code in Exynos, S5P, S3C SoC clk drivers - Fixes for system suspend support on Exynos542x (Odroid boards) and Exynos5433 SoC - Remove obsoleted Exynos4212 ISP clock definitions - Migrated TI am3/4/5 and dra7 SoCs to clockdomain based design - TI RTC+DDR sleep mode support for clock save/restore - Allwinner A64 display engine support and fixes - Allwinner A83t display engine support and fixes -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEE9L57QeeUxqYDyoaDrQKIl8bklSUFAlvY4ysRHHNib3lkQGtl cm5lbC5vcmcACgkQrQKIl8bklSVaDBAA3Wv/rsCn4FJ2ZgIWYWQqr69lAWDcBVVe 4nNbFqzEmRoml8e+XOfVFwnbsai4B5ALVxyMnRlkDyxQ5TFQtF957U12Pf8upPa5 R447YBt4tw40NCj8u5KNAaBmYYHdmXXDvsBPXyQn+1iy/9R8Is8AcDmv+D2ucuJF PPBXOwb+2CstUQhuwlXyvsAw/tqq/rJDVyAZVJUoqXJwlNMjr76V0m0ZXHN6NcyC F2SfnzIO4srRteTeKXVFcMU/3uHC3zofEfammSJjGZkk4WHULuPpkD17RMEyBul1 Ju1S1nzGiKvYME/mmbIcRPNcpry65EVo/wn6IjAcG2m4GaWSq3F6qIttnoc6dnra R2VylIEy7HnNcAf8fkQdkd/l+h/TDp3iVrXg0p/rRxRk4Jlc86n2PWO6jtsZv4S+ NySeRhTb51KrTl72J76LP+dfDWdbeZfkAqr0Qx6QM04OznVYSTHlnQaeM1Nx2SZR 5+k126NdxDp7xgoJNfq18wzufrlefjuRTg2Kck1YuFuhV4Fjmq7ZC81bSSaakYPh /t073TcSZ+VfEYP5hVsl/pjMdFzHcj8pbavhs0UNIYLQNXe494Bm9PyYJOzQKnwz Zpbf7V6eplh8J1I03VI8RHviNp340iv2hhz9vp4mNP1vIhgdNiz7R2gn5sLSoFt+ vei0J0vEzCA= =V5aK -----END PGP SIGNATURE----- Merge tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux Pull clk updates from Stephen Boyd: "This time it looks like a quieter release cycle in the clk tree. I guess that's because of summer time holidays/vacations. The biggest change in the diffstat is in the Qualcomm clk driver, where they got support for CPUs and handful of SoCs. After that, the at91 driver got a major rewrite for newer DT bindings that should make things easier going forward and the TI code moved to a clockdomain based design. The long tail is mostly small driver updates for newer clks and some simpler SoC clock drivers such as the Hisilicon and imx support. In the core framework, we only have two small changes this time. One is a new clk API to get all clks for a device with the bulk clk APIs. This allows drivers that don't care about doing anything besides turning on all the clks to just clk_get() them all and turn them on. The other change is the beginning of a way to support save and restore of clk settings in the clk framework. TI is the only user right now, but we will want to expand upon this design in the future to support more save and restore of clk registers. At least this gets us started and works well enough for one SoC, but there's more work in the future. Core: - clk_bulk_get_all() API and friends to get all the clks for a device - Basic clk state save/restore hooks New Drivers: - Renesas RZ/A2 (R7S9210) SoC, including early clocks - Rensas RZ/G1N (R8A7744) and RZ/G2E (R8A774C0) SoCs - Rensas RZ/G2M (r8a774a1) SoC - Qualcomm Krait CPU clk support - Qualcomm QCS404 GCC support - Qualcomm SDM660 GCC support - Qualcomm SDM845 camera clock controller - Ingenic jz4725b CGU - Hisilicon 3670 SoC support - TI SCI clks on K3 SoCs - iMX6 MMDC clks - Reset Controller (RMU) support for Actions Semi Owl S900 and S700 SoCs Updates: - Rework at91 PMC clock driver for new DT bindings - Nvidia Tegra clk driver MBIST workaround fix - S2RAM support for Marvell mvebu periph clks - Use updated printk format for OF node names - Fix TI code to only search DT subnodes - Various static analysis finds - Tag various drivers with SPDX license tags - Support dynamic frequency switching (DFS) on qcom SDM845 GCC - Only use s2mps11 dt-binding defines instead of redefining them in the driver - Add some more missing clks to qcom MSM8996 GCC - Quad SPI clks on qcom SDM845 - Add support for CMT timer clocks on R-Car V3H - Add support for SHDI and various timer clocks on R-Car V3M - Improve OSC and RCLK (watchdog) handling on R-Car Gen3 SoCs - Amlogic clk-pll driver improvements and updates - Amlogic axg audio controller system clocks - Register Amlogic meson8b clock controller early - Add support for SATA and Fine Display Processor (FDP) clocks on R-Car M3-N - Consolidation of system suspend related code in Exynos, S5P, S3C SoC clk drivers - Fixes for system suspend support on Exynos542x (Odroid boards) and Exynos5433 SoC - Remove obsoleted Exynos4212 ISP clock definitions - Migrated TI am3/4/5 and dra7 SoCs to clockdomain based design - TI RTC+DDR sleep mode support for clock save/restore - Allwinner A64 display engine support and fixes - Allwinner A83t display engine support and fixes" * tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux: (186 commits) clk: qcom: Remove unused arrays in SDM845 GCC clk: fixed-rate: fix of_node_get-put imbalance clk: s2mps11: Add used attribute to s2mps11_dt_match clk: qcom: gcc-sdm660: Add MODULE_LICENSE clk: qcom: Add safe switch hook for krait mux clocks dt-bindings: clock: Document qcom,krait-cc clk: qcom: Add Krait clock controller driver dt-bindings: arm: Document qcom,kpss-gcc clk: qcom: Add KPSS ACC/GCC driver clk: qcom: Add support for Krait clocks clk: qcom: Add IPQ806X's HFPLLs clk: qcom: Add MSM8960/APQ8064's HFPLLs dt-bindings: clock: Document qcom,hfpll clk: qcom: Add HFPLL driver clk: qcom: Add support for High-Frequency PLLs (HFPLLs) ARM: Add Krait L2 register accessor functions clk: imx6q: add mmdc0 ipg clock clk: imx6sl: add mmdc ipg clocks clk: imx6sll: add mmdc1 ipg clock clk: imx6sx: add mmdc1 ipg clock ...
254 lines
6.5 KiB
C
254 lines
6.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Marvell MVEBU CPU clock handling.
|
|
*
|
|
* Copyright (C) 2012 Marvell
|
|
*
|
|
* Gregory CLEMENT <gregory.clement@free-electrons.com>
|
|
*
|
|
*/
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/clk-provider.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/io.h>
|
|
#include <linux/of.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/mvebu-pmsu.h>
|
|
#include <asm/smp_plat.h>
|
|
|
|
#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
|
|
|
|
#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;
|
|
void __iomem *pmu_dfs;
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
static int clk_cpu_off_set_rate(struct clk_hw *hwclk, unsigned long rate,
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
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;
|
|
}
|
|
|
|
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;
|
|
|
|
cur_rate = clk_hw_get_rate(hwclk);
|
|
|
|
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);
|
|
}
|
|
|
|
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,
|
|
};
|
|
|
|
static void __init of_cpu_clk_setup(struct device_node *node)
|
|
{
|
|
struct cpu_clk *cpuclk;
|
|
void __iomem *clock_complex_base = of_iomap(node, 0);
|
|
void __iomem *pmu_dfs_base = of_iomap(node, 1);
|
|
int ncpus = 0;
|
|
struct device_node *dn;
|
|
|
|
if (clock_complex_base == NULL) {
|
|
pr_err("%s: clock-complex base register not set\n",
|
|
__func__);
|
|
return;
|
|
}
|
|
|
|
if (pmu_dfs_base == NULL)
|
|
pr_warn("%s: pmu-dfs base register not set, dynamic frequency scaling not available\n",
|
|
__func__);
|
|
|
|
for_each_of_cpu_node(dn)
|
|
ncpus++;
|
|
|
|
cpuclk = kcalloc(ncpus, sizeof(*cpuclk), GFP_KERNEL);
|
|
if (WARN_ON(!cpuclk))
|
|
goto cpuclk_out;
|
|
|
|
clks = kcalloc(ncpus, sizeof(*clks), GFP_KERNEL);
|
|
if (WARN_ON(!clks))
|
|
goto clks_out;
|
|
|
|
for_each_of_cpu_node(dn) {
|
|
struct clk_init_data init;
|
|
struct clk *clk;
|
|
char *clk_name = kzalloc(5, GFP_KERNEL);
|
|
int cpu, err;
|
|
|
|
if (WARN_ON(!clk_name))
|
|
goto bail_out;
|
|
|
|
err = of_property_read_u32(dn, "reg", &cpu);
|
|
if (WARN_ON(err))
|
|
goto bail_out;
|
|
|
|
sprintf(clk_name, "cpu%d", cpu);
|
|
|
|
cpuclk[cpu].parent_name = of_clk_get_parent_name(node, 0);
|
|
cpuclk[cpu].clk_name = clk_name;
|
|
cpuclk[cpu].cpu = cpu;
|
|
cpuclk[cpu].reg_base = clock_complex_base;
|
|
if (pmu_dfs_base)
|
|
cpuclk[cpu].pmu_dfs = pmu_dfs_base + 4 * cpu;
|
|
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);
|
|
while(ncpus--)
|
|
kfree(cpuclk[ncpus].clk_name);
|
|
clks_out:
|
|
kfree(cpuclk);
|
|
cpuclk_out:
|
|
iounmap(clock_complex_base);
|
|
}
|
|
|
|
CLK_OF_DECLARE(armada_xp_cpu_clock, "marvell,armada-xp-cpu-clock",
|
|
of_cpu_clk_setup);
|
|
|
|
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);
|