Introduce MediaTek frequency hopping driver
Subsystems (3)
v5 cover Introduce MediaTek frequency hopping driver
The purpose of this serie is to enhance frequency hopping and spread spectrum clocking feature for MT8186.
We introduce new PLL register APIs and some helpers for FHCTL hardware control. For MT8186 PLL driver, we replace mtk_clk_register_plls() with newly added API to support frequency hopping and SSC function for specific PLLs.
Changes in v5:
- Add the reviewed-by tags.
- Move binding document to bindings/clock folder.
- change some coding style in clk-pllfh.c
Changes in v4:
- Fixup iospace error in the binding.
- Use GENMASK marco and remove extra line.
Changes in v3:
- Change binding file name.
- Add some constraints for properties.
- Rename "mediatek,hopping-ssc-percents" to "mediatek,hopping-ssc-percent".
- Add new config symbol.
Changes in v2:
- Use SoC-specific compatible instead of generic one.
- Use standard clocks property and vendor-specific property in dt-binding.
- Remove some unused arguments and fix some coding style.
Johnson Wang (4):
clk: mediatek: Export PLL operations symbols
dt-bindings: clock: mediatek: Add new bindings of MediaTek frequency
hopping
clk: mediatek: Add new clock driver to handle FHCTL hardware
clk: mediatek: Change PLL register API for MT8186
.../bindings/clock/mediatek,mt8186-fhctl.yaml | 53 ++++ drivers/clk/mediatek/Kconfig | 8 + drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-fhctl.c | 244 ++++++++++++++++ drivers/clk/mediatek/clk-fhctl.h | 26 ++ drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 66 ++++- drivers/clk/mediatek/clk-pll.c | 84 +++--- drivers/clk/mediatek/clk-pll.h | 55 ++++ drivers/clk/mediatek/clk-pllfh.c | 275 ++++++++++++++++++ drivers/clk/mediatek/clk-pllfh.h | 82 ++++++ 10 files changed, 841 insertions(+), 53 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt8186-fhctl.yaml create mode 100644 drivers/clk/mediatek/clk-fhctl.c create mode 100644 drivers/clk/mediatek/clk-fhctl.h create mode 100644 drivers/clk/mediatek/clk-pllfh.c create mode 100644 drivers/clk/mediatek/clk-pllfh.h
Signature · 1 line
2.18.0
PATCH v5 1/4 clk: mediatek: Export PLL operations symbols
Export PLL operations and register functions for different type of clock driver used.
--- drivers/clk/mediatek/clk-pll.c | 84 ++++++++++++++-------------------- drivers/clk/mediatek/clk-pll.h | 55 ++++++++++++++++++++++ 2 files changed, 89 insertions(+), 50 deletions(-)
drivers/clk/mediatek/clk-pll.c +34 -50
@@ -27,37 +27,10 @@#define AUDPLL_TUNER_EN BIT(31) -#define POSTDIV_MASK 0x7 -/* default 7 bits integer, can be overridden with pcwibits. */ #define INTEGER_BITS 7 -/* -* MediaTek PLLs are configured through their pcw value. The pcw value describes -* a divider in the PLL feedback loop which consists of 7 bits for the integer -* part and the remaining bits (if present) for the fractional part. Also they -* have a 3 bit power-of-two post divider. -*/ - -struct mtk_clk_pll { -struct clk_hw hw; -void __iomem *base_addr; -void __iomem *pd_addr; -void __iomem *pwr_addr; -void __iomem *tuner_addr; -void __iomem *tuner_en_addr; -void __iomem *pcw_addr; -void __iomem *pcw_chg_addr; -void __iomem *en_addr; -const struct mtk_pll_data *data; -}; - -static inline struct mtk_clk_pll *to_mtk_clk_pll (struct clk_hw *hw) -{ - return container_of(hw, struct mtk_clk_pll, hw); -} - -static int mtk_pll_is_prepared (struct clk_hw *hw) +int mtk_pll_is_prepared (struct clk_hw *hw) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);
@@ -161,8 +134,8 @@ static void mtk_pll_set_rate_regs(struct mtk_clk_pll *pll, u32 pcw,* @fin: The input frequency * */ -static void mtk_pll_calc_values (struct mtk_clk_pll *pll,u32 *pcw,u32 *postdiv, -u32 freq,u32 fin) +void mtk_pll_calc_values (struct mtk_clk_pll *pll,u32 *pcw,u32 *postdiv, +u32 freq,u32 fin) {unsigned long fmin = pll->data->fmin ? pll->data->fmin : (1000 *MHZ );const struct mtk_pll_div_table *div_table = pll->data->div_table;
@@ -198,8 +171,8 @@ static void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv, *pcw = (u32 )_pcw; } -static int mtk_pll_set_rate (struct clk_hw *hw,unsigned long rate, -unsigned long parent_rate) +int mtk_pll_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);u32 pcw =0 ;
@@ -211,8 +184,7 @@ static int mtk_pll_set_rate(struct clk_hw *hw, unsigned long rate,return 0 ; } -static unsigned long mtk_pll_recalc_rate (struct clk_hw *hw, -unsigned long parent_rate) +unsigned long mtk_pll_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);u32 postdiv;
@@ -227,8 +199,8 @@ static unsigned long mtk_pll_recalc_rate(struct clk_hw *hw,return __mtk_pll_recalc_rate (pll, parent_rate, pcw, postdiv); } -static long mtk_pll_round_rate (struct clk_hw *hw,unsigned long rate, -unsigned long *prate) +long mtk_pll_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *prate) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);u32 pcw =0 ;
@@ -239,7 +211,7 @@ static long mtk_pll_round_rate(struct clk_hw *hw, unsigned long rate,return __mtk_pll_recalc_rate (pll, *prate, pcw, postdiv); } -static int mtk_pll_prepare (struct clk_hw *hw) +int mtk_pll_prepare (struct clk_hw *hw) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);u32 r;
@@ -273,7 +245,7 @@ static int mtk_pll_prepare(struct clk_hw *hw)return 0 ; } -static void mtk_pll_unprepare (struct clk_hw *hw) +void mtk_pll_unprepare (struct clk_hw *hw) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);u32 r;
@@ -301,7 +273,7 @@ static void mtk_pll_unprepare(struct clk_hw *hw)writel (r, pll->pwr_addr); } -static const struct clk_ops mtk_pll_ops = { +const struct clk_ops mtk_pll_ops = { .is_prepared = mtk_pll_is_prepared, .prepare = mtk_pll_prepare, .unprepare = mtk_pll_unprepare,
@@ -310,18 +282,15 @@ static const struct clk_ops mtk_pll_ops = { .set_rate = mtk_pll_set_rate, }; -static struct clk_hw *mtk_clk_register_pll (const struct mtk_pll_data *data, -void __iomem *base) +struct clk_hw *mtk_clk_register_pll_ops (struct mtk_clk_pll *pll, +const struct mtk_pll_data *data, +void __iomem *base, +const struct clk_ops *pll_ops) { -struct mtk_clk_pll *pll;struct clk_init_data init = {};int ret;const char *parent_name ="clk26m" ; - pll =kzalloc (sizeof (*pll),GFP_KERNEL ); -if (!pll) -return ERR_PTR (-ENOMEM ); - pll->base_addr = base + data->reg; pll->pwr_addr = base + data->pwr_reg; pll->pd_addr = base + data->pd_reg;
@@ -343,7 +312,7 @@ static struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data, init.name = data->name; init.flags = (data->flags &PLL_AO ) ?CLK_IS_CRITICAL :0 ; - init.ops = &mtk_pll_ops; + init.ops = pll_ops;if (data->parent_name) init.parent_names = &data->parent_name;else
@@ -360,7 +329,22 @@ static struct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data,return &pll->hw; } -static void mtk_clk_unregister_pll (struct clk_hw *hw) +struct clk_hw *mtk_clk_register_pll (const struct mtk_pll_data *data, +void __iomem *base) +{ +struct mtk_clk_pll *pll; +struct clk_hw *hw; + + pll =kzalloc (sizeof (*pll),GFP_KERNEL ); +if (!pll) +return ERR_PTR (-ENOMEM ); + + hw =mtk_clk_register_pll_ops (pll, data, base, &mtk_pll_ops); + +return hw; +} + +void mtk_clk_unregister_pll (struct clk_hw *hw) {struct mtk_clk_pll *pll;
@@ -423,8 +407,8 @@ int mtk_clk_register_plls(struct device_node *node, }EXPORT_SYMBOL_GPL (mtk_clk_register_plls); -static __iomem void *mtk_clk_pll_get_base (struct clk_hw *hw, -const struct mtk_pll_data *data) +__iomem void *mtk_clk_pll_get_base (struct clk_hw *hw, +const struct mtk_pll_data *data) {struct mtk_clk_pll *pll =to_mtk_clk_pll (hw);
drivers/clk/mediatek/clk-pll.h +55 -0
77 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v5 2/4 dt-bindings: clock: mediatek: Add new bindings of MediaTek frequency hopping
In reply to Johnson WangAdd the new binding documentation for MediaTek frequency hopping and spread spectrum clocking control.
--- .../bindings/clock/mediatek,mt8186-fhctl.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt8186-fhctl.yaml
Documentation/devicetree/bindings/clock/mediatek,mt8186-fhctl.yaml new file +53 -0
@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/mediatek,mt8186-fhctl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek frequency hopping and spread spectrum clocking control + +maintainers: + - Edward-JW Yang <[email protected]> + +description: | + Frequency hopping control (FHCTL) is a piece of hardware that control + some PLLs to adopt "hopping" mechanism to adjust their frequency. + Spread spectrum clocking (SSC) is another function provided by this hardware. + +properties: + compatible: + const: mediatek,mt8186-fhctl + + reg: + maxItems: 1 + + clocks: + description: Phandles of the PLL with FHCTL hardware capability. + minItems: 1 + maxItems: 30 + + mediatek,hopping-ssc-percent: + description: The percentage of spread spectrum clocking for one PLL. + minItems: 1 + maxItems: 30 + items: + default: 0 + minimum: 0 + maximum: 8 + +required: + - compatible + - reg + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8186-clk.h> + fhctl: fhctl@1000ce00 { + compatible = "mediatek,mt8186-fhctl"; + reg = <0x1000ce00 0x200>; + clocks = <&apmixedsys CLK_APMIXED_MSDCPLL>; + mediatek,hopping-ssc-percent = <3>; + };
Signature · 1 line
2.18.0
PATCH v5 3/4 clk: mediatek: Add new clock driver to handle FHCTL hardware
In reply to Johnson WangTo implement frequency hopping and spread spectrum clocking function, we introduce new clock type and APIs to handle FHCTL hardware.
--- drivers/clk/mediatek/Kconfig | 7 + drivers/clk/mediatek/Makefile | 1 + drivers/clk/mediatek/clk-fhctl.c | 244 +++++++++++++++++++++++++++ drivers/clk/mediatek/clk-fhctl.h | 26 +++ drivers/clk/mediatek/clk-pllfh.c | 275 +++++++++++++++++++++++++++++++ drivers/clk/mediatek/clk-pllfh.h | 82 +++++++++ 6 files changed, 635 insertions(+) create mode 100644 drivers/clk/mediatek/clk-fhctl.c create mode 100644 drivers/clk/mediatek/clk-fhctl.h create mode 100644 drivers/clk/mediatek/clk-pllfh.c create mode 100644 drivers/clk/mediatek/clk-pllfh.h
drivers/clk/mediatek/Kconfig +7 -0
@@ -11,6 +11,13 @@ config COMMON_CLK_MEDIATEK help MediaTek SoCs' clock support. +config COMMON_CLK_MEDIATEK_FHCTL + bool "clock driver for MediaTek FHCTL hardware control" + select COMMON_CLK_MEDIATEK + help + This driver supports MediaTek frequency hopping and + spread spectrum clocking features. + config COMMON_CLK_MT2701 bool "Clock driver for MediaTek MT2701" depends on (ARCH_MEDIATEK && ARM) || COMPILE_TEST
drivers/clk/mediatek/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_COMMON_CLK_MEDIATEK) += clk-mtk.o clk-pll.o clk-gate.o clk-apmixed.o clk-cpumux.o reset.o clk-mux.o +obj-$(CONFIG_COMMON_CLK_MEDIATEK_FHCTL) += clk-fhctl.o clk-pllfh.o obj-$(CONFIG_COMMON_CLK_MT6765) += clk-mt6765.o obj-$(CONFIG_COMMON_CLK_MT6765_AUDIOSYS) += clk-mt6765-audio.o
drivers/clk/mediatek/clk-fhctl.c new file +244 -0
244 lines not on this page · raw message
drivers/clk/mediatek/clk-fhctl.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2022 MediaTek Inc. +* Author: Edward-JW Yang <[email protected]> +*/ + +#ifndef __CLK_FHCTL_H +#define __CLK_FHCTL_H + +struct fhctl_offset { +u32 offset_hp_en; +u32 offset_clk_con; +u32 offset_rst_con; +u32 offset_slope0; +u32 offset_slope1; +u32 offset_cfg; +u32 offset_updnlmt; +u32 offset_dds; +u32 offset_dvfs; +u32 offset_mon; +}; +const struct fhctl_offset *fhctl_get_offset_table (void ); +const struct fh_operation *fhctl_get_ops (void ); +void fhctl_hw_init (struct mtk_fh *fh); + +#endif
drivers/clk/mediatek/clk-pllfh.c new file +275 -0
275 lines not on this page · raw message
drivers/clk/mediatek/clk-pllfh.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v5 4/4 clk: mediatek: Change PLL register API for MT8186
In reply to Johnson WangUse mtk_clk_register_pllfhs() to enhance frequency hopping and spread spectrum clocking control for MT8186.
--- drivers/clk/mediatek/Kconfig | 1 + drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 66 +++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-)
drivers/clk/mediatek/Kconfig +1 -0
@@ -560,6 +560,7 @@ config COMMON_CLK_MT8186 bool "Clock driver for MediaTek MT8186" depends on ARM64 || COMPILE_TEST select COMMON_CLK_MEDIATEK + select COMMON_CLK_MEDIATEK_FHCTL default ARCH_MEDIATEK help This driver supports MediaTek MT8186 clocks.
drivers/clk/mediatek/clk-mt8186-apmixedsys.c +63 -3
102 lines not on this page · raw message
Signature · 1 line
2.18.0
Chen-Yu Tsai
AppliedQuoted 6 lines · Johnson Wang
The purpose of this serie is to enhance frequency hopping and spread spectrum clocking feature for MT8186.
We introduce new PLL register APIs and some helpers for FHCTL hardware control. For MT8186 PLL driver, we replacemtk_clk_register_plls()with newly added API to support frequency hopping and SSC function for specific PLLs.
Quoted 6 lines
Changes in v5:
- Add the reviewed-by tags.
- Move binding document to bindings/clock folder.
- change some coding style inclk-pllfh.c[...]
Applied, thanks!
[1/4] clk: mediatek: Export PLL operations symbols
commit: 029c936ae7e14ce49d043527087abb5f4b0ea48c
[2/4] dt-bindings: clock: mediatek: Add new bindings of MediaTek frequency hopping
commit: cfcefe36bf939107eeba7b1114e3d82e31f92893
[3/4] clk: mediatek: Add new clock driver to handle FHCTL hardware
commit: d7964de8a8ea800910fdd4e365c42a9e7d5c54aa
[4/4] clk: mediatek: Change PLL register API for MT8186
commit: 633e34d0f46ed36f1de15ede00e4b31f4d7cccaeBest regards,
Signature · 1 line
Chen-Yu Tsai <[email protected]>