Skip to contentSkip to conversation

Introduce MediaTek frequency hopping driver

PATCH Superseded Johnson Wang 3 participants 12 messages Oct 13, 2022 – Nov 1, 2022 1 message not in the archive

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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 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: arm: 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

 .../arm/mediatek/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              | 268 ++++++++++++++++++
 drivers/clk/mediatek/clk-pllfh.h              |  82 ++++++
 10 files changed, 834 insertions(+), 53 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/mediatek/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
#1 lore raw

PATCH v4 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
index 54e6cfd29dfc..a4eca5fd539c 100644
@@ -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
maintainer Reviewed-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] clk: mediatek: Export PLL operations symbols

Il 13/10/22 13:23, Johnson Wang ha scritto:

Quoted 6 lines

Export PLL operations and register functions for different type of clock driver used.

#3 lore raw

PATCH v4 2/4 dt-bindings: arm: mediatek: Add new bindings of MediaTek frequency hopping

In reply to Johnson Wang

Add the new binding documentation for MediaTek frequency hopping and spread spectrum clocking control.

---
 .../arm/mediatek/mediatek,mt8186-fhctl.yaml   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +53 -0
new file mode 100644
index 000000000000..59111946966c
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/mediatek/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
maintainer
#4 lore raw

Re: [PATCH v4 2/4] dt-bindings: arm: mediatek: Add new bindings of MediaTek frequency hopping

Quoting Johnson Wang (2022-10-13 04:23:34)

Quoted 19 lines

Add the new binding documentation for MediaTek frequency hopping and spread spectrum clocking control.

---
 .../arm/mediatek/mediatek,mt8186-fhctl.yaml   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +0 -0
new file mode 100644
index 000000000000..59111946966c

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml line 7

Quoted 7 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +7 -0
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/arm/mediatek/mediatek,mt8186-fhctl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek frequency hopping and spread spectrum clocking control

The driver patch is in drivers/clk so why not put the binding in bindings/clock as well?

Quoted 4 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +4 -0
+
+maintainers:
+  - Edward-JW Yang <[email protected]>
+

[...]

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml line 48

Quoted 12 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +12 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/mt8186-clk.h>
+    fhctl: fhctl@1000ce00 {

Is it a clock-controller? 'fhctl' isn't a generic node name.

Quoted 4 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +4 -0
+        compatible = "mediatek,mt8186-fhctl";
+        reg = <0x1000ce00 0x200>;
+        clocks = <&apmixedsys CLK_APMIXED_MSDCPLL>;
+        mediatek,hopping-ssc-percent = <3>;
#5 lore raw

Re: [PATCH v4 2/4] dt-bindings: arm: mediatek: Add new bindings of MediaTek frequency hopping

Quoted 39 lines · Stephen Boyd

Quoting Johnson Wang (2022-10-13 04:23:34)

Quoted 38 lines

Add the new binding documentation for MediaTek frequency hopping and spread spectrum clocking control.

Reviewed-by AngeloGioacchino Del Regno <

[email protected]>

---
 .../arm/mediatek/mediatek,mt8186-fhctl.yaml   | 53
+++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186- fhctl.yaml

diff --git a/Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186- fhctl.yaml b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186- fhctl.yaml
new file mode 100644
index 000000000000..59111946966c
--- /dev/null
+++
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186- fhctl.yaml

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +4 -0
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 

https://urldefense.com/v3/__http://devicetree.org/schemas/arm/mediatek/mediatek,mt8186-fhctl.yaml*__;Iw!!CTRNKA9wMg0ARbw!yfDH4W14Pek7w3YBrdcBAGj3OSSWGlWk8av4DmHT69Ej4ax75zKqpy89ZvX1Z_aKDPzu$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!yfDH4W14Pek7w3YBrdcBAGj3OSSWGlWk8av4DmHT69Ej4ax75zKqpy89ZvX1Z9gRczPi$

Quoted 7 lines
Quoted 3 lines
(quoted diff) +2 -0
+
+title: MediaTek frequency hopping and spread spectrum clocking

control

The driver patch is in drivers/clk so why not put the binding in bindings/clock as well?

Hi Stephen,

Sure, I will move this binding in the next version.

Quoted 6 lines
Quoted 4 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +4 -0
+
+maintainers:
+  - Edward-JW Yang <[email protected]>
+

[...]

Quoted 15 lines

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml line 48

Quoted 12 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +12 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/mt8186-clk.h>
+    fhctl: fhctl@1000ce00 {

Is it a clock-controller? 'fhctl' isn't a generic node name.

This node is used for determining if PLLs adopt "hopping" method to adjust their frequency.
It doesn't provide any clock but actually change the behavior of some PLLs with new .set_rate callback.
Do you think this node acts like one kind of clock-controller?

BRs,
Johnson Wang

Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +4 -0
+        compatible = "mediatek,mt8186-fhctl";
+        reg = <0x1000ce00 0x200>;
+        clocks = <&apmixedsys CLK_APMIXED_MSDCPLL>;
+        mediatek,hopping-ssc-percent = <3>;

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH v4 2/4] dt-bindings: arm: mediatek: Add new bindings of MediaTek frequency hopping

Quoted 17 lines · Stephen Boyd

Quoting Johnson Wang (王聖鑫) (2022-10-17 05:55:09)

Quoted 9 lines · Stephen Boyd
Quoted 7 lines

Quoting Johnson Wang (2022-10-13 04:23:34)

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml line 48

Quoted 3 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +3 -0
+  - |
+    #include <dt-bindings/clock/mt8186-clk.h>
+    fhctl: fhctl@1000ce00 {

Is it a clock-controller? 'fhctl' isn't a generic node name.

Quoted 6 lines

This node is used for determining if PLLs adopt "hopping" method to adjust their frequency.
It doesn't provide any clock but actually change the behavior of some
PLLs with new .set_rate callback.
Do you think this node acts like one kind of clock-controller?

Quoted 3 lines

Why can't we add the reg and properties to the node that implements the
PLL?

Hi Stephen,

Now we use standard clocks property to get clock indices from apmixedsys node.

If we integrate the reg and properties into apmixedsys node, we have to figure out another way to get indices... (I think one node shouldn't take itself as input?)

There is an idea in my mind. Add these prperties into apmixedsys node.

	mediatek,hopping-clocks = <CLK_APMIXED_MAINPLL>,
			          <CLK_APMIXED_MSDCPLL>;
	mediatek,ssc-percent = <2 3>;

But I don't really know if this violates some rules. Could you please give us some suggestion? Thanks!

BRs,
Johnson Wang

#8 lore raw

Re: [PATCH v4 2/4] dt-bindings: arm: mediatek: Add new bindings of MediaTek frequency hopping

Quoted 41 lines · Johnson Wang (王聖鑫)
Quoted 18 lines · Stephen Boyd

Quoting Johnson Wang (王聖鑫) (2022-10-17 05:55:09)

Quoted 9 lines · Stephen Boyd
Quoted 7 lines

Quoting Johnson Wang (2022-10-13 04:23:34)

Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml line 48

Quoted 3 lines
Documentation/devicetree/bindings/arm/mediatek/mediatek,mt8186-fhctl.yaml new file +3 -0
+  - |
+    #include <dt-bindings/clock/mt8186-clk.h>
+    fhctl: fhctl@1000ce00 {

Is it a clock-controller? 'fhctl' isn't a generic node name.

Quoted 7 lines

This node is used for determining if PLLs adopt "hopping" method to
adjust their frequency.
It doesn't provide any clock but actually change the behavior of some
PLLs with new .set_rate callback.
Do you think this node acts like one kind of clock-controller?

Quoted 3 lines

Why can't we add the reg and properties to the node that implements the
PLL?

Hi Stephen,

Now we use standard clocks property to get clock indices from apmixedsys node.

If we integrate the reg and properties into apmixedsys node, we have to
figure out another way to get indices... (I think one node shouldn't take itself as input?)

There is an idea in my mind. Add these prperties into apmixedsys node.

	mediatek,hopping-clocks = <CLK_APMIXED_MAINPLL>,
			          <CLK_APMIXED_MSDCPLL>;
	mediatek,ssc-percent = <2 3>;
Quoted 6 lines

But I don't really know if this violates some rules. Could you please give us some suggestion? Thanks!

BRs,
Johnson Wang

Hi Stephen,

A gentle ping for this.

Could you please give me some advices if you prefer intergrating these into one node?

Thank you very much!

BRs,
Johnson Wang

#9 lore raw

PATCH v4 3/4 clk: mediatek: Add new clock driver to handle FHCTL hardware

In reply to Johnson Wang

To 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 | 268 +++++++++++++++++++++++++++++++
 drivers/clk/mediatek/clk-pllfh.h |  82 ++++++++++
 6 files changed, 628 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
index 843cea0c7a44..38f667eadda3 100644
@@ -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
index ea3b73240303..e24080fd6e7f 100644
@@ -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
new file mode 100644
index 000000000000..51275febf086
@@ -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 +268 -0

268 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
maintainer Reviewed-by on v4 3/4
#10 lore raw

Re: [PATCH v4 3/4] clk: mediatek: Add new clock driver to handle FHCTL hardware

Il 13/10/22 13:23, Johnson Wang ha scritto:

Quoted 20 lines

To 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 | 268 +++++++++++++++++++++++++++++++
  drivers/clk/mediatek/clk-pllfh.h |  82 ++++++++++
  6 files changed, 628 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

..snip..

Quoted 6 lines
drivers/clk/mediatek/clk-pllfh.c new file +0 -0
new file mode 100644
index 000000000000..a728ff749db1
@@ -0,0 +1,268 @@

..snip..

Quoted 9 lines
drivers/clk/mediatek/clk-pllfh.c new file +9 -0
+
+int mtk_clk_register_pllfhs(struct device_node *node,
+			    const struct mtk_pll_data *plls, int num_plls,
+			    struct mtk_pllfh_data *pllfhs, int num_fhs,
+			    struct clk_hw_onecell_data *clk_data)
+{
+	void __iomem *base;
+	int i;
+	struct clk_hw *hw;

drivers/clk/mediatek/clk-pllfh.c line 193

Quoted 10 lines
drivers/clk/mediatek/clk-pllfh.c new file +10 -0
+
+	base = of_iomap(node, 0);
+	if (!base) {
+		pr_err("%s(): ioremap failed\n", __func__);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < num_plls; i++) {
+		const struct mtk_pll_data *pll = &plls[i];
+		struct mtk_pllfh_data *pllfh;
		bool use_fhctl;

		pllfh = get_pllfh_by_id(pllfhs, num_fhs, pll->id);
		use_fhctl = fhctl_is_supported_and_enabled(pllfh);

		if (use_fhctl)
			hw = mtk_clk_register_pllfh(pll, pllfh, base);
		else
			hw = mtk_clk_register_pll(pll, base);

		if (IS_ERR(hw) {
			pr_err("Failed to register %s clk %s: %d\n",
			       use_fhctl ? "fhpll" : "pll", pll->name,
			       PTR_ERR(hw));
			goto err;
		}

.... that's better.

Quoted 26 lines
drivers/clk/mediatek/clk-pllfh.c new file +26 -0
+
+		clk_data->hws[pll->id] = hw;
+	}
+
+	return 0;
+
+err:
+	while (--i >= 0) {
+		const struct mtk_pll_data *pll = &plls[i];
+		struct mtk_pllfh_data *pllfh;
+
+		pllfh = get_pllfh_by_id(pllfhs, num_fhs, pll->id);
+
+		if (fhctl_is_supported_and_enabled(pllfh))
+			mtk_clk_unregister_pllfh(clk_data->hws[pll->id]);
+		else
+			mtk_clk_unregister_pll(clk_data->hws[pll->id]);
+
+		clk_data->hws[pll->id] = ERR_PTR(-ENOENT);
+	}
+
+	iounmap(base);
+
+	return PTR_ERR(hw);
+}
+

..snip..

Quoted 6 lines
drivers/clk/mediatek/clk-pllfh.h new file +0 -0
new file mode 100644
index 000000000000..effc7976c496

drivers/clk/mediatek/clk-pllfh.h line 8

Quoted 8 lines
drivers/clk/mediatek/clk-pllfh.h new file +8 -0
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ * Author: Edward-JW Yang <[email protected]>
+ */
+
+#ifndef __DRV_CLKFH_H
+#define __DRV_CLKFH_H

This should be __CLK_PLLFH_H.

...after which:

#11 lore raw

PATCH v4 4/4 clk: mediatek: Change PLL register API for MT8186

In reply to Johnson Wang

Use 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
index 38f667eadda3..22e8e79475ee 100644
@@ -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
maintainer Reviewed-by on v4 4/4
#12 lore raw

Re: [PATCH v4 4/4] clk: mediatek: Change PLL register API for MT8186

Il 13/10/22 13:23, Johnson Wang ha scritto:

Quoted 6 lines

Use mtk_clk_register_pllfhs() to enhance frequency hopping and spread spectrum clocking control for MT8186.