clk: rockchip: Add new clock-type for the ddrclk
Subsystems (2)
PATCH 1/3 clk: rockchip: Add new clock-type for the ddrclk
Changing the DDR clock frequency requires special care, this patch adds the DDR clock driver code from the Linux kernel repository. While we're here, let's also update drivers/clk/rockchip/Makefile to make it more readable.
--- drivers/clk/rockchip/Makefile | 29 ++++-- drivers/clk/rockchip/clk-ddr.c | 131 ++++++++++++++++++++++++++++ drivers/clk/rockchip/clk-pll.c | 6 +- drivers/clk/rockchip/clk.c | 7 ++ drivers/clk/rockchip/clk.h | 1 + include/soc/rockchip/rockchip_sip.h | 23 +++++ 6 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 drivers/clk/rockchip/clk-ddr.c create mode 100644 include/soc/rockchip/rockchip_sip.h
drivers/clk/rockchip/Makefile +21 -8
@@ -1,8 +1,21 @@ -# SPDX-License-Identifier: GPL-2.0-only -obj-y += clk-cpu.o clk-pll.o clk.o clk-muxgrf.o clk-mmc-phase.o clk-inverter.o -obj-$(CONFIG_RESET_CONTROLLER) += softrst.o -obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o -obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o -obj-$(CONFIG_ARCH_RK3399) += clk-rk3399.o -obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o -obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.o +# SPDX-License-Identifier: GPL-2.0 +# +# Rockchip Clock specific Makefile +# + +obj-y += clk-rockchip.o + +clk-rockchip-y += clk.o +clk-rockchip-y += clk-pll.o +clk-rockchip-y += clk-cpu.o +clk-rockchip-y += clk-inverter.o +clk-rockchip-y += clk-mmc-phase.o +clk-rockchip-y += clk-muxgrf.o +clk-rockchip-y += clk-ddr.o + +clk-rockchip-$(CONFIG_RESET_CONTROLLER) += softrst.o + +obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o +obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o +obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o +obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.o
drivers/clk/rockchip/clk-ddr.c new file +131 -0
131 lines not on this page · raw message
drivers/clk/rockchip/clk-pll.c +5 -1
@@ -913,7 +913,10 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned } rate64 = rate64 >> cur.s; -return (unsigned long )rate64; +if (pll->type == pll_rk3588_ddr) +return (unsigned long )rate64 *2 ; +else +return (unsigned long )rate64; } static int rockchip_rk3588_pll_set_params(struct rockchip_clk_pll *pll,
@@ -1169,6 +1172,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,break ;case pll_rk3588:case pll_rk3588_core: +case pll_rk3588_ddr:if (!pll->rate_table) init.ops = &rockchip_rk3588_pll_clk_norate_ops;else
drivers/clk/rockchip/clk.c +7 -0
@@ -497,6 +497,13 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx, list->gate_flags, flags, &ctx->lock);break ;case branch_ddrclk: + clk =rockchip_clk_register_ddrclk ( + list->name, list->flags, + list->parent_names, list->num_parents, + list->muxdiv_offset, list->mux_shift, + list->mux_width, list->div_shift, + list->div_width, list->div_flags, + ctx->reg_base, &ctx->lock);break ; }
drivers/clk/rockchip/clk.h +1 -0
@@ -267,6 +267,7 @@ enum rockchip_pll_type { pll_rk3399, pll_rk3588, pll_rk3588_core, + pll_rk3588_ddr, }; #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
include/soc/rockchip/rockchip_sip.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd +* Author: Lin Huang <[email protected]> +*/ +#ifndef __SOC_ROCKCHIP_SIP_H +#define __SOC_ROCKCHIP_SIP_H + +#define ROCKCHIP_SIP_SUSPEND_MODE 0x82000003 +#define ROCKCHIP_SLEEP_PD_CONFIG 0xff + +#define ROCKCHIP_SIP_DRAM_FREQ 0x82000008 +#define ROCKCHIP_SIP_CONFIG_DRAM_INIT 0x00 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE 0x01 +#define ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE 0x02 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_AT_SR 0x03 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_BW 0x04 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE 0x05 +#define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ 0x06 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM 0x07 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD 0x08 + +#endif
Signature · 1 line
2.39.1
PATCH 2/3 clk: rockchip: Add linked gate clock support
Recent Rockchip SoCs have a new hardware block called Native Interface Unit (NIU), which gates clocks to devices behind them. These clock gates will only have a running output clock when all of the following conditions are met:
1. the parent clock is enabled
2. the enable bit is set correctly
3. the linked clock is enabled
To handle them this code registers them as a normal gate type clock, which takes care of condition 1 + 2. Thus the complete handling of these clocks has been moved into its own driver.
--- drivers/clk/rockchip/Makefile | 1 + drivers/clk/rockchip/clk.c | 67 ++++++++++++++++++++++++++------ drivers/clk/rockchip/clk.h | 25 +++++++++++- drivers/clk/rockchip/gate-link.c | 44 +++++++++++++++++++++ 4 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 drivers/clk/rockchip/gate-link.c
drivers/clk/rockchip/Makefile +1 -0
@@ -12,6 +12,7 @@ clk-rockchip-y += clk-inverter.o clk-rockchip-y += clk-mmc-phase.o clk-rockchip-y += clk-muxgrf.o clk-rockchip-y += clk-ddr.o +clk-rockchip-y += gate-link.o clk-rockchip-$(CONFIG_RESET_CONTROLLER) += softrst.o
drivers/clk/rockchip/clk.c +55 -12
113 lines not on this page · raw message
drivers/clk/rockchip/clk.h +23 -2
@@ -500,6 +500,7 @@ enum rockchip_clk_branch_type { branch_divider, branch_fraction_divider, branch_gate, + branch_linked_gate, branch_mmc, branch_inverter, branch_factor,
@@ -883,17 +884,37 @@ struct rockchip_clk_branch {#define SGRF_GATE (_id, cname, pname) \ FACTOR(_id, cname, pname, 0, 1, 1) +static inline struct clk *rockchip_clk_get_lookup (struct rockchip_clk_provider *ctx, +unsigned int id) +{ +return ctx->clk_data.clks[id]; +} + +static inline void rockchip_clk_set_lookup (struct rockchip_clk_provider *ctx, +struct clk *clk,unsigned int id) +{ + ctx->clk_data.clks[id] = clk; +} + +struct rockchip_gate_link_platdata { +struct rockchip_clk_provider *ctx; +struct rockchip_clk_branch *clkbr; +}; +struct rockchip_clk_provider *rockchip_clk_init (struct device_node *np,void __iomem *base,unsigned long nr_clks);void rockchip_clk_of_add_provider (struct device_node *np,struct rockchip_clk_provider *ctx); -void rockchip_clk_add_lookup (struct rockchip_clk_provider *ctx, -struct clk *clk,unsigned int id);unsigned long rockchip_clk_find_max_clk_id (struct rockchip_clk_branch *list,unsigned int nr_clk);void rockchip_clk_register_branches (struct rockchip_clk_provider *ctx,struct rockchip_clk_branch *list,unsigned int nr_clk); +void rockchip_clk_register_late_branches (struct device *dev, +struct rockchip_clk_provider *ctx, +struct rockchip_clk_branch *list, +unsigned int nr_clk); +void rockchip_clk_register_plls (struct rockchip_clk_provider *ctx,struct rockchip_pll_clock *pll_list,unsigned int nr_pll,int grf_lock_offset);
drivers/clk/rockchip/gate-link.c new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.39.1
PATCH 3/3 clk: rockchip: Update RK3188 driver
In reply to Alexander ShiyanThis patch updates the RK3188-clk driver to reflect the latest changes from the Linux kernel repository.
--- drivers/clk/rockchip/clk-rk3188.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/rockchip/clk-rk3188.c +2 -2
@@ -338,7 +338,7 @@ static struct rockchip_clk_branch common_clk_branches[] __initdata = {GATE (0 ,"pclkin_cif0" ,"ext_cif0" ,0 ,RK2928_CLKGATE_CON (3 ),3 ,GFLAGS ), -INVERTER (0 ,"pclk_cif0" ,"pclkin_cif0" , +INVERTER (PCLK_CIF0 ,"pclk_cif0" ,"pclkin_cif0" ,RK2928_CLKSEL_CON (30 ),8 ,IFLAGS ), FACTOR(0, "xin12m", "xin24m", 0, 1, 2),
@@ -596,7 +596,7 @@ static struct rockchip_clk_branch rk3066a_clk_branches[] __initdata = {GATE (0 ,"pclkin_cif1" ,"ext_cif1" ,0 ,RK2928_CLKGATE_CON (3 ),4 ,GFLAGS ), -INVERTER (0 ,"pclk_cif1" ,"pclkin_cif1" , +INVERTER (PCLK_CIF1 ,"pclk_cif1" ,"pclkin_cif1" ,RK2928_CLKSEL_CON (30 ),12 ,IFLAGS ), COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
Signature · 1 line
2.39.1
Sascha Hauer
AppliedQuoted 6 lines · Alexander Shiyan
Changing the DDR clock frequency requires special care, this patch adds the DDR clock driver code from the Linux kernel repository. While we're here, let's also update
drivers/clk/rockchip/Makefileto make it more readable.
Applied, thanks!
[1/3] clk: rockchip: Add new clock-type for the ddrclk
https://git.pengutronix.de/cgit/barebox/commit/?id=4e7465c80e36 (link may not be stable)
[2/3] clk: rockchip: Add linked gate clock support
https://git.pengutronix.de/cgit/barebox/commit/?id=0336060c12ad (link may not be stable)
[3/3] clk: rockchip: Update RK3188 driver
https://git.pengutronix.de/cgit/barebox/commit/?id=8ca5cf10b81e (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>
Hi Alexander,
Quoted 4 lines · Alexander Shiyan
Changing the DDR clock frequency requires special care, this patch adds the DDR clock driver code from the Linux kernel repository. While we're here, let's also update
drivers/clk/rockchip/Makefileto make it more readable.
This patch currently breaks build on ARMv7 Rockchip SoCs. It fails with undefined reference to __arm_smccc_smc.
Looking at upstream Linux it seems that this driver is only used on RK3399, the SoC we just removed support for.
Where do we go from here? I could fix this patch, but as it's unused I could equally well drop it without loosing anything.
Sascha
Quoted 272 lines
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/clk/rockchip/Makefile | 29 ++++-- drivers/clk/rockchip/clk-ddr.c | 131 ++++++++++++++++++++++++++++ drivers/clk/rockchip/clk-pll.c | 6 +- drivers/clk/rockchip/clk.c | 7 ++ drivers/clk/rockchip/clk.h | 1 + include/soc/rockchip/rockchip_sip.h | 23 +++++ 6 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 drivers/clk/rockchip/clk-ddr.c create mode 100644 include/soc/rockchip/rockchip_sip.hdrivers/clk/rockchip/Makefile +21
-8@@ -1,8 +1,21 @@ -# SPDX-License-Identifier: GPL-2.0-only -obj-y += clk-cpu.o clk-pll.o clk.o clk-muxgrf.o clk-mmc-phase.o clk-inverter.o -obj-$(CONFIG_RESET_CONTROLLER) += softrst.o -obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o -obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o -obj-$(CONFIG_ARCH_RK3399) += clk-rk3399.o -obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o -obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.o +# SPDX-License-Identifier: GPL-2.0 +# +# Rockchip Clock specific Makefile +# + +obj-y += clk-rockchip.o + +clk-rockchip-y += clk.o +clk-rockchip-y += clk-pll.o +clk-rockchip-y += clk-cpu.o +clk-rockchip-y += clk-inverter.o +clk-rockchip-y += clk-mmc-phase.o +clk-rockchip-y += clk-muxgrf.o +clk-rockchip-y += clk-ddr.o + +clk-rockchip-$(CONFIG_RESET_CONTROLLER) += softrst.o + +obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o +obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o +obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o +obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.odrivers/clk/rockchip/clk-ddr.c new file +131
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2016 Rockchip Electronics Co. Ltd. +* Author: Lin Huang <[email protected]> +*/ + +#include <common.h> +#include <linux/arm-smccc.h> +#include <soc/rockchip/rockchip_sip.h> + +#include "clk.h" + +struct rockchip_ddrclk { +struct clk_hw hw; +void __iomem *reg_base; +int mux_offset; +int mux_shift; +int mux_width; +int div_shift; +int div_width; +int ddr_flag; +}; + +#define to_rockchip_ddrclk_hw (hw) container_of(hw, struct rockchip_ddrclk, hw) + +static int rockchip_ddrclk_sip_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ , drate,0 , +ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static unsigned long +rockchip_ddrclk_sip_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ ,0 ,0 , +ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static long rockchip_ddrclk_sip_round_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long *prate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ , rate,0 , +ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static int rockchip_ddrclk_get_parent (struct clk_hw *hw) +{ +struct rockchip_ddrclk *ddrclk =to_rockchip_ddrclk_hw (hw); +u32 val; + + val =readl (ddrclk->reg_base + + ddrclk->mux_offset) >> ddrclk->mux_shift; + val &=GENMASK (ddrclk->mux_width -1 ,0 ); + +return val; +} + +static const struct clk_ops rockchip_ddrclk_sip_ops = { + .recalc_rate = rockchip_ddrclk_sip_recalc_rate, + .set_rate = rockchip_ddrclk_sip_set_rate, + .round_rate = rockchip_ddrclk_sip_round_rate, + .get_parent = rockchip_ddrclk_get_parent, +}; + +struct clk *rockchip_clk_register_ddrclk (const char *name,int flags, +const char *const *parent_names, +u8 num_parents,int mux_offset, +int mux_shift,int mux_width, +int div_shift,int div_width, +int ddr_flag,void __iomem *reg_base, +spinlock_t *lock) +{ +struct rockchip_ddrclk *ddrclk; +struct clk_init_data init; +struct clk *clk; + + ddrclk =kzalloc (sizeof (*ddrclk),GFP_KERNEL ); +if (!ddrclk) +return ERR_PTR (-ENOMEM ); + + init.name = name; + init.parent_names = parent_names; + init.num_parents = num_parents; + + init.flags = flags; + init.flags |=CLK_SET_RATE_NO_REPARENT ; + +switch (ddr_flag) { +case ROCKCHIP_DDRCLK_SIP : + init.ops = &rockchip_ddrclk_sip_ops; +break ; +default : +pr_err ("%s: unsupported ddrclk type %d\n" , __func__, ddr_flag); +kfree (ddrclk); +return ERR_PTR (-EINVAL ); + } + + ddrclk->reg_base = reg_base; + ddrclk->hw.init = &init; + ddrclk->mux_offset = mux_offset; + ddrclk->mux_shift = mux_shift; + ddrclk->mux_width = mux_width; + ddrclk->div_shift = div_shift; + ddrclk->div_width = div_width; + ddrclk->ddr_flag = ddr_flag; + + clk =clk_register (NULL , &ddrclk->hw); +if (IS_ERR (clk)) +kfree (ddrclk); + +return clk; +} +EXPORT_SYMBOL_GPL (rockchip_clk_register_ddrclk);drivers/clk/rockchip/clk-pll.c +5
-1@@ -913,7 +913,10 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned } rate64 = rate64 >> cur.s; -return (unsigned long )rate64; +if (pll->type == pll_rk3588_ddr) +return (unsigned long )rate64 *2 ; +else +return (unsigned long )rate64; } static int rockchip_rk3588_pll_set_params(struct rockchip_clk_pll *pll,@@ -1169,6 +1172,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,break ;case pll_rk3588:case pll_rk3588_core: +case pll_rk3588_ddr:if (!pll->rate_table) init.ops = &rockchip_rk3588_pll_clk_norate_ops;else drivers/clk/rockchip/clk.c +7
-0@@ -497,6 +497,13 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx, list->gate_flags, flags, &ctx->lock);break ;case branch_ddrclk: + clk =rockchip_clk_register_ddrclk ( + list->name, list->flags, + list->parent_names, list->num_parents, + list->muxdiv_offset, list->mux_shift, + list->mux_width, list->div_shift, + list->div_width, list->div_flags, + ctx->reg_base, &ctx->lock);break ; }drivers/clk/rockchip/clk.h +1
-0@@ -267,6 +267,7 @@ enum rockchip_pll_type { pll_rk3399, pll_rk3588, pll_rk3588_core, + pll_rk3588_ddr, }; #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \include/soc/rockchip/rockchip_sip.h new file +23
-0@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd +* Author: Lin Huang <[email protected]> +*/ +#ifndef __SOC_ROCKCHIP_SIP_H +#define __SOC_ROCKCHIP_SIP_H + +#define ROCKCHIP_SIP_SUSPEND_MODE 0x82000003 +#define ROCKCHIP_SLEEP_PD_CONFIG 0xff + +#define ROCKCHIP_SIP_DRAM_FREQ 0x82000008 +#define ROCKCHIP_SIP_CONFIG_DRAM_INIT 0x00 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE 0x01 +#define ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE 0x02 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_AT_SR 0x03 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_BW 0x04 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE 0x05 +#define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ 0x06 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM 0x07 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD 0x08 + +#endif Signature · 1 line
2.39.1
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hello.
Good catch, I thought it was used even in RK3588 because there are mentions of DDRPLL in the datasheet.
Perhaps the right solution in this case would be to remove this unit.
вт, 15 апр. 2025 г. в 10:48, Sascha Hauer <[email protected]>:
Quoted 298 lines
Hi Alexander,
Quoted 4 lines · Alexander Shiyan
Changing the DDR clock frequency requires special care, this patch adds the DDR clock driver code from the Linux kernel repository. While we're here, let's also update
drivers/clk/rockchip/Makefileto make it more readable.This patch currently breaks build on ARMv7 Rockchip SoCs. It fails with undefined reference to
__arm_smccc_smc.Looking at upstream Linux it seems that this driver is only used on RK3399, the SoC we just removed support for.
Where do we go from here? I could fix this patch, but as it's unused I could equally well drop it without loosing anything.
Sascha
Quoted 268 lines
Signed-off-by Alexander Shiyan <[email protected]>--- drivers/clk/rockchip/Makefile | 29 ++++-- drivers/clk/rockchip/clk-ddr.c | 131 ++++++++++++++++++++++++++++ drivers/clk/rockchip/clk-pll.c | 6 +- drivers/clk/rockchip/clk.c | 7 ++ drivers/clk/rockchip/clk.h | 1 + include/soc/rockchip/rockchip_sip.h | 23 +++++ 6 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 drivers/clk/rockchip/clk-ddr.c create mode 100644 include/soc/rockchip/rockchip_sip.hdrivers/clk/rockchip/Makefile +21
-8@@ -1,8 +1,21 @@ -# SPDX-License-Identifier: GPL-2.0-only -obj-y += clk-cpu.o clk-pll.o clk.o clk-muxgrf.o clk-mmc-phase.o clk-inverter.o -obj-$(CONFIG_RESET_CONTROLLER) += softrst.o -obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o -obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o -obj-$(CONFIG_ARCH_RK3399) += clk-rk3399.o -obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o -obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.o +# SPDX-License-Identifier: GPL-2.0 +# +# Rockchip Clock specific Makefile +# + +obj-y += clk-rockchip.o + +clk-rockchip-y += clk.o +clk-rockchip-y += clk-pll.o +clk-rockchip-y += clk-cpu.o +clk-rockchip-y += clk-inverter.o +clk-rockchip-y += clk-mmc-phase.o +clk-rockchip-y += clk-muxgrf.o +clk-rockchip-y += clk-ddr.o + +clk-rockchip-$(CONFIG_RESET_CONTROLLER) += softrst.o + +obj-$(CONFIG_ARCH_RK3188) += clk-rk3188.o +obj-$(CONFIG_ARCH_RK3288) += clk-rk3288.o +obj-$(CONFIG_ARCH_RK3568) += clk-rk3568.o +obj-$(CONFIG_ARCH_RK3588) += clk-rk3588.o rst-rk3588.odrivers/clk/rockchip/clk-ddr.c new file +131
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2016 Rockchip Electronics Co. Ltd. +* Author: Lin Huang <[email protected]> +*/ + +#include <common.h> +#include <linux/arm-smccc.h> +#include <soc/rockchip/rockchip_sip.h> + +#include "clk.h" + +struct rockchip_ddrclk { +struct clk_hw hw; +void __iomem *reg_base; +int mux_offset; +int mux_shift; +int mux_width; +int div_shift; +int div_width; +int ddr_flag; +}; + +#define to_rockchip_ddrclk_hw (hw) container_of(hw, struct rockchip_ddrclk, hw) + +static int rockchip_ddrclk_sip_set_rate (struct clk_hw *hw,unsigned long drate, +unsigned long prate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ , drate,0 , +ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static unsigned long +rockchip_ddrclk_sip_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ ,0 ,0 , +ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static long rockchip_ddrclk_sip_round_rate (struct clk_hw *hw, +unsigned long rate, +unsigned long *prate) +{ +struct arm_smccc_res res; + +arm_smccc_smc (ROCKCHIP_SIP_DRAM_FREQ , rate,0 , +ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE , +0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static int rockchip_ddrclk_get_parent (struct clk_hw *hw) +{ +struct rockchip_ddrclk *ddrclk =to_rockchip_ddrclk_hw (hw); +u32 val; + + val =readl (ddrclk->reg_base + + ddrclk->mux_offset) >> ddrclk->mux_shift; + val &=GENMASK (ddrclk->mux_width -1 ,0 ); + +return val; +} + +static const struct clk_ops rockchip_ddrclk_sip_ops = { + .recalc_rate = rockchip_ddrclk_sip_recalc_rate, + .set_rate = rockchip_ddrclk_sip_set_rate, + .round_rate = rockchip_ddrclk_sip_round_rate, + .get_parent = rockchip_ddrclk_get_parent, +}; + +struct clk *rockchip_clk_register_ddrclk (const char *name,int flags, +const char *const *parent_names, +u8 num_parents,int mux_offset, +int mux_shift,int mux_width, +int div_shift,int div_width, +int ddr_flag,void __iomem *reg_base, +spinlock_t *lock) +{ +struct rockchip_ddrclk *ddrclk; +struct clk_init_data init; +struct clk *clk; + + ddrclk =kzalloc (sizeof (*ddrclk),GFP_KERNEL ); +if (!ddrclk) +return ERR_PTR (-ENOMEM ); + + init.name = name; + init.parent_names = parent_names; + init.num_parents = num_parents; + + init.flags = flags; + init.flags |=CLK_SET_RATE_NO_REPARENT ; + +switch (ddr_flag) { +case ROCKCHIP_DDRCLK_SIP : + init.ops = &rockchip_ddrclk_sip_ops; +break ; +default : +pr_err ("%s: unsupported ddrclk type %d\n" , __func__, ddr_flag); +kfree (ddrclk); +return ERR_PTR (-EINVAL ); + } + + ddrclk->reg_base = reg_base; + ddrclk->hw.init = &init; + ddrclk->mux_offset = mux_offset; + ddrclk->mux_shift = mux_shift; + ddrclk->mux_width = mux_width; + ddrclk->div_shift = div_shift; + ddrclk->div_width = div_width; + ddrclk->ddr_flag = ddr_flag; + + clk =clk_register (NULL , &ddrclk->hw); +if (IS_ERR (clk)) +kfree (ddrclk); + +return clk; +} +EXPORT_SYMBOL_GPL (rockchip_clk_register_ddrclk);drivers/clk/rockchip/clk-pll.c +5
-1@@ -913,7 +913,10 @@ static unsigned long rockchip_rk3588_pll_recalc_rate(struct clk_hw *hw, unsigned } rate64 = rate64 >> cur.s; -return (unsigned long )rate64; +if (pll->type == pll_rk3588_ddr) +return (unsigned long )rate64 *2 ; +else +return (unsigned long )rate64; } static int rockchip_rk3588_pll_set_params(struct rockchip_clk_pll *pll,@@ -1169,6 +1172,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,break ;case pll_rk3588:case pll_rk3588_core: +case pll_rk3588_ddr:if (!pll->rate_table) init.ops = &rockchip_rk3588_pll_clk_norate_ops;else drivers/clk/rockchip/clk.c +7
-0@@ -497,6 +497,13 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx, list->gate_flags, flags, &ctx->lock);break ;case branch_ddrclk: + clk =rockchip_clk_register_ddrclk ( + list->name, list->flags, + list->parent_names, list->num_parents, + list->muxdiv_offset, list->mux_shift, + list->mux_width, list->div_shift, + list->div_width, list->div_flags, + ctx->reg_base, &ctx->lock);break ; }drivers/clk/rockchip/clk.h +1
-0@@ -267,6 +267,7 @@ enum rockchip_pll_type { pll_rk3399, pll_rk3588, pll_rk3588_core, + pll_rk3588_ddr, }; #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \include/soc/rockchip/rockchip_sip.h new file +23
-1@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd +* Author: Lin Huang <[email protected]> +*/ +#ifndef __SOC_ROCKCHIP_SIP_H +#define __SOC_ROCKCHIP_SIP_H + +#define ROCKCHIP_SIP_SUSPEND_MODE 0x82000003 +#define ROCKCHIP_SLEEP_PD_CONFIG 0xff + +#define ROCKCHIP_SIP_DRAM_FREQ 0x82000008 +#define ROCKCHIP_SIP_CONFIG_DRAM_INIT 0x00 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_RATE 0x01 +#define ROCKCHIP_SIP_CONFIG_DRAM_ROUND_RATE 0x02 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_AT_SR 0x03 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_BW 0x04 +#define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE 0x05 +#define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ 0x06 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM 0x07 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD 0x08 + +#endif --Quoted 4 lines
2.39.1
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |