Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock
@ 2026-12-01  8:56 Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
                   ` (12 more replies)
  0 siblings, 13 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

This series refactors the Meson PLL driver to remove the dedicated
PLL pre-divider (N) parameter from the PLL implementation and model it
as a separate divider clock.

Currently, the Meson PLL driver models the PLL pre-divider using a
dedicated n field in struct meson_clk_pll_data. This makes the
pre-divider part of the PLL-specific implementation, although the
Common Clock Framework already provides a generic divider clock.

The pre-divider is not intended to be dynamically adjusted. Each PLL
has a fixed N value as part of its configuration. Most PLLs use N = 1,
while a few special cases use N = 3 to satisfy their PLL input frequency
constraints. Modeling the pre-divider as a separate divider clock
removes PLL-specific handling and simplifies the PLL driver.

The series updates the Amlogic SoC clock drivers to use standalone
pre-divider clocks, with the PLL DCO taking the pre-divider clock as
its parent instead of the input clock directly. It also adds the
required clock IDs.

Some Amlogic PLL pre-dividers read as zero after reset, which
does not produce a usable clock. The existing divider implementation
reports the parent rate for a zero divisor, potentially hiding this
invalid state. In addition, when the requested pre-divider rate equals
the parent rate, the divider must be configured with a divisor of 1.
The zero value read from the register after reset must not prevent the
divider from being configured correctly.

To address these issues, the series introduces
CLK_DIVIDER_INVALID_ZERO, allowing dividers with an invalid zero
value to report a rate of zero instead of incorrectly reporting the
parent rate.

The common clock framework gained CLK_DIVIDER_INVALID_ZERO (BIT(9)),
so the divider flags no longer fit in the u8 field of struct
clk_regmap_div_data.

Widen the divider flags to u16.

Tested on: T7, C3, S4, AXG, GXL, SM1 and A1.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
Changes in v3:
- Rebase to clk-amlogic.
- return -EINVAL when divisor equals 0 in divider_ro_determine_rate().
- Separate patch for widen the divider flags.
- Split the SoC changes for prediv clock.
- Add CLK_DIVIDER_ONE_BASED for RO prediv.
- Drop CLK_SET_RATE_PARENT for hdmi clock.
- Update the comment for prediv table.
- Add CLK_GET_RATE_NOCACHE for pcie prediv clock.
- Rework meson_clk_pll_determine_rate().
- Described with a pll_mult_range for contiguous table.
- Covert the table to const unsigned int * array.
- Link to v2: https://lore.kernel.org/r/20261029-meson_refactor_n-v2-0-ff4ac74e527b@amlogic.com

Changes in v2:
- Add CLK_DIVIDER_INVALID_ZERO.
- Add all SoCs prediv clock index.
- Support table for pll m.
- Fix the `determine` logic: when `best_parent_rate` equals 0,
recalculate a new `parent_rate`.
- Add all SoCs pll prediv clocks.
- Link to v1: https://lore.kernel.org/r/20260923-meson_refactor_n-v1-0-3a8ce27121a2@amlogic.com

---
Jian Hu (13):
      clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag
      clk: meson: clk-regmap: Widen the divider flags to 16 bits
      dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs
      clk: meson: axg: Model the PLL pre-divider as a divider clock
      clk: meson: a1: Model the PLL pre-divider as a divider clock
      clk: meson: c3: Model the PLL pre-divider as a divider clock
      clk: meson: gxbb: Model the PLL pre-divider as a divider clock
      clk: meson: g12a: Model the PLL pre-divider as a divider clock
      clk: meson: meson8: Model the PLL pre-divider as a divider clock
      clk: meson: s4: Model the PLL pre-divider as a divider clock
      clk: meson: s7: Model the PLL pre-divider as a divider clock
      clk: meson: t7: Model the PLL pre-divider as a divider clock
      clk: meson: pll: Remove the dedicated n parameter

 drivers/clk/clk-divider.c                       |   5 +
 drivers/clk/meson/a1-pll.c                      |  69 ++++--
 drivers/clk/meson/axg.c                         | 210 +++++++++++-------
 drivers/clk/meson/c3-pll.c                      |  97 ++++++--
 drivers/clk/meson/clk-pll.c                     | 241 +++++++++++---------
 drivers/clk/meson/clk-pll.h                     |  14 +-
 drivers/clk/meson/clk-regmap.h                  |   2 +-
 drivers/clk/meson/g12a.c                        | 282 ++++++++++++++++++------
 drivers/clk/meson/gxbb.c                        | 260 +++++++++++++---------
 drivers/clk/meson/meson8-ddr.c                  |  33 ++-
 drivers/clk/meson/meson8b.c                     | 209 +++++++++++-------
 drivers/clk/meson/s4-pll.c                      | 130 ++++++++---
 drivers/clk/meson/s7-pll.c                      |  33 ++-
 drivers/clk/meson/t7-pll.c                      | 192 ++++++++++++----
 include/dt-bindings/clock/amlogic,a1-pll-clkc.h |   3 +
 include/dt-bindings/clock/amlogic,c3-pll-clkc.h |   3 +
 include/dt-bindings/clock/amlogic,s4-pll-clkc.h |   4 +
 include/dt-bindings/clock/amlogic,s7-pll-clkc.h |   1 +
 include/dt-bindings/clock/amlogic,t7-pll-clkc.h |   6 +
 include/dt-bindings/clock/axg-clkc.h            |   5 +
 include/dt-bindings/clock/g12a-clkc.h           |   8 +
 include/dt-bindings/clock/gxbb-clkc.h           |   4 +
 include/dt-bindings/clock/meson8-ddr-clkc.h     |   1 +
 include/dt-bindings/clock/meson8b-clkc.h        |   4 +
 include/linux/clk-provider.h                    |   3 +
 25 files changed, 1259 insertions(+), 560 deletions(-)
---
base-commit: 48275f2f75fd2a45a15f5fad2c8a2201ac465826
change-id: 20261126-meson_refactor_n-f6076ce11a53

Best regards,
-- 
Jian Hu <jian.hu@amlogic.com>



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  9:10   ` sashiko-bot
  2026-12-01  8:56 ` [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits Jian Hu via B4 Relay
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

When a divider register reads zero, divider_recalc_rate() currently
emits a warning (unless CLK_DIVIDER_ALLOW_ZERO is set) and returns
the parent rate.

This behaviour assumes a zero divisor acts as a pass-through, which
does not apply to all hardware. Some dividers, for example PLL
pre-dividers on Amlogic SoCs, come out of reset with a zero value
that does not produce a usable clock. Returning the parent rate
hides this fault behind an incorrect, plausible value.

CLK_DIVIDER_ALLOW_ZERO only suppresses the warning while still
reporting the parent rate, so it cannot represent this hardware
behaviour.

Add CLK_DIVIDER_INVALID_ZERO for dividers where a zero divisor value
is invalid. When this flag is set, recalc_rate() returns 0, making
the faulty state visible to the clock framework rather than hiding it
as a pass-through.

Return -EINVAL when the decoded divisor is zero in
divider_ro_determine_rate, rather than dividing by zero or reporting
a rate which does not exist.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/clk-divider.c    | 5 +++++
 include/linux/clk-provider.h | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index f68216c65d3d..74ae203e5ff8 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -143,6 +143,9 @@ unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
 
 	div = _get_div(table, val, flags, width);
 	if (!div) {
+		if (flags & CLK_DIVIDER_INVALID_ZERO)
+			return 0;
+
 		WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO),
 			"%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n",
 			clk_hw_get_name(hw));
@@ -380,6 +383,8 @@ int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
 	int div;
 
 	div = _get_div(table, val, flags, width);
+	if (!div)
+		return -EINVAL;
 
 	/* Even a read-only clock can propagate a rate change */
 	if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index a355d1ee5189..ee964f0c9b0d 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -747,6 +747,8 @@ struct clk_div_table {
  *	big endian.
  * CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc.
  *	Formula is 2 * (value read from hardware + 1).
+ * CLK_DIVIDER_INVALID_ZERO - A decoded divisor of zero indicates no usable
+ *	output. recalc_rate() returns 0 instead of the parent rate.
  */
 struct clk_divider {
 	struct clk_hw	hw;
@@ -770,6 +772,7 @@ struct clk_divider {
 #define CLK_DIVIDER_MAX_AT_ZERO		BIT(6)
 #define CLK_DIVIDER_BIG_ENDIAN		BIT(7)
 #define CLK_DIVIDER_EVEN_INTEGERS	BIT(8)
+#define CLK_DIVIDER_INVALID_ZERO	BIT(9)
 
 extern const struct clk_ops clk_divider_ops;
 extern const struct clk_ops clk_divider_ro_ops;

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The common clock framework gained CLK_DIVIDER_INVALID_ZERO (BIT(9)),
so the divider flags no longer fit in the u8 field of struct
clk_regmap_div_data.

Widen the divider flags to u16.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/clk-regmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/meson/clk-regmap.h b/drivers/clk/meson/clk-regmap.h
index 8e5c39b023e1..ee2a4b3408f0 100644
--- a/drivers/clk/meson/clk-regmap.h
+++ b/drivers/clk/meson/clk-regmap.h
@@ -75,7 +75,7 @@ struct clk_regmap_div_data {
 	unsigned int	offset;
 	u8		shift;
 	u8		width;
-	u8		flags;
+	u16		flags;
 	const struct clk_div_table	*table;
 };
 

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

Add clock IDs for the PLL pre-divider clocks. These IDs are
required for the subsequent conversion of the PLL pre-divider
into a standalone divider clock following the PLL framework refactoring.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 include/dt-bindings/clock/amlogic,a1-pll-clkc.h | 3 +++
 include/dt-bindings/clock/amlogic,c3-pll-clkc.h | 3 +++
 include/dt-bindings/clock/amlogic,s4-pll-clkc.h | 4 ++++
 include/dt-bindings/clock/amlogic,s7-pll-clkc.h | 1 +
 include/dt-bindings/clock/amlogic,t7-pll-clkc.h | 6 ++++++
 include/dt-bindings/clock/axg-clkc.h            | 5 +++++
 include/dt-bindings/clock/g12a-clkc.h           | 8 ++++++++
 include/dt-bindings/clock/gxbb-clkc.h           | 4 ++++
 include/dt-bindings/clock/meson8-ddr-clkc.h     | 1 +
 include/dt-bindings/clock/meson8b-clkc.h        | 4 ++++
 10 files changed, 39 insertions(+)

diff --git a/include/dt-bindings/clock/amlogic,a1-pll-clkc.h b/include/dt-bindings/clock/amlogic,a1-pll-clkc.h
index 0dfc5e78a2d5..c09f215bf75b 100644
--- a/include/dt-bindings/clock/amlogic,a1-pll-clkc.h
+++ b/include/dt-bindings/clock/amlogic,a1-pll-clkc.h
@@ -22,5 +22,8 @@
 #define CLKID_FCLK_DIV7		9
 #define CLKID_HIFI_PLL		10
 #define CLKID_SYS_PLL		11
+#define CLKID_FIXED_PREDIV	12
+#define CLKID_HIFI_PREDIV	13
+#define CLKID_SYS_PREDIV	14
 
 #endif /* __A1_PLL_CLKC_H */
diff --git a/include/dt-bindings/clock/amlogic,c3-pll-clkc.h b/include/dt-bindings/clock/amlogic,c3-pll-clkc.h
index fcdc558715e8..771be7d53bc0 100644
--- a/include/dt-bindings/clock/amlogic,c3-pll-clkc.h
+++ b/include/dt-bindings/clock/amlogic,c3-pll-clkc.h
@@ -36,5 +36,8 @@
 #define CLKID_MCLK1_SEL_EN			26
 #define CLKID_MCLK1_DIV				27
 #define CLKID_MCLK1				28
+#define CLKID_GP0_PREDIV			29
+#define CLKID_HIFI_PREDIV			30
+#define CLKID_MCLK_PREDIV			31
 
 #endif  /* _DT_BINDINGS_CLOCK_AMLOGIC_C3_PLL_CLKC_H */
diff --git a/include/dt-bindings/clock/amlogic,s4-pll-clkc.h b/include/dt-bindings/clock/amlogic,s4-pll-clkc.h
index af9f110f8b62..e194185f5be8 100644
--- a/include/dt-bindings/clock/amlogic,s4-pll-clkc.h
+++ b/include/dt-bindings/clock/amlogic,s4-pll-clkc.h
@@ -39,5 +39,9 @@
 #define CLKID_MPLL2			29
 #define CLKID_MPLL3_DIV			30
 #define CLKID_MPLL3			31
+#define CLKID_FIXED_PREDIV		32
+#define CLKID_GP0_PREDIV		33
+#define CLKID_HIFI_PREDIV		34
+#define CLKID_HDMI_PREDIV		35
 
 #endif /* _DT_BINDINGS_CLOCK_AMLOGIC_S4_PLL_CLKC_H */
diff --git a/include/dt-bindings/clock/amlogic,s7-pll-clkc.h b/include/dt-bindings/clock/amlogic,s7-pll-clkc.h
index 6bea314deb31..594dc94630c0 100644
--- a/include/dt-bindings/clock/amlogic,s7-pll-clkc.h
+++ b/include/dt-bindings/clock/amlogic,s7-pll-clkc.h
@@ -38,5 +38,6 @@
 #define CLKID_HDMI_PLL_PIX_DIV6P25		29
 #define CLKID_HDMI_PLL_PIX_DIV7P5		30
 #define CLKID_HDMI_PLL_PIX			31
+#define CLKID_FIXED_PLL_PREDIV			32
 
 #endif /* _DT_BINDINGS_CLOCK_AMLOGIC_S7_PLL_CLKC_H */
diff --git a/include/dt-bindings/clock/amlogic,t7-pll-clkc.h b/include/dt-bindings/clock/amlogic,t7-pll-clkc.h
index e2481f2f1163..69c90bc0be0a 100644
--- a/include/dt-bindings/clock/amlogic,t7-pll-clkc.h
+++ b/include/dt-bindings/clock/amlogic,t7-pll-clkc.h
@@ -9,20 +9,24 @@
 /* GP0 */
 #define CLKID_GP0_PLL_DCO	0
 #define CLKID_GP0_PLL		1
+#define CLKID_GP0_PREDIV	2
 
 /* GP1 */
 #define CLKID_GP1_PLL_DCO	0
 #define CLKID_GP1_PLL		1
+#define CLKID_GP1_PREDIV	2
 
 /* HIFI */
 #define CLKID_HIFI_PLL_DCO	0
 #define CLKID_HIFI_PLL		1
+#define CLKID_HIFI_PREDIV	2
 
 /* PCIE */
 #define CLKID_PCIE_PLL_DCO	0
 #define CLKID_PCIE_PLL_DCO_DIV2	1
 #define CLKID_PCIE_PLL_OD	2
 #define CLKID_PCIE_PLL		3
+#define CLKID_PCIE_PREDIV	4
 
 /* MPLL */
 #define CLKID_MPLL_PREDIV	0
@@ -39,6 +43,7 @@
 #define CLKID_HDMI_PLL_DCO	0
 #define CLKID_HDMI_PLL_OD	1
 #define CLKID_HDMI_PLL		2
+#define CLKID_HDMI_PREDIV	3
 
 /* MCLK */
 #define CLKID_MCLK_PLL_DCO	0
@@ -52,5 +57,6 @@
 #define CLKID_MCLK_1_DIV2	8
 #define CLKID_MCLK_1_PRE	9
 #define CLKID_MCLK_1		10
+#define CLKID_MCLK_PREDIV	11
 
 #endif /* __T7_PLL_CLKC_H */
diff --git a/include/dt-bindings/clock/axg-clkc.h b/include/dt-bindings/clock/axg-clkc.h
index 442162822b88..798b92919f60 100644
--- a/include/dt-bindings/clock/axg-clkc.h
+++ b/include/dt-bindings/clock/axg-clkc.h
@@ -144,5 +144,10 @@
 #define CLKID_VDIN_MEAS_SEL			134
 #define CLKID_VDIN_MEAS_DIV			135
 #define CLKID_VDIN_MEAS				136
+#define CLKID_FIXED_PREDIV			137
+#define CLKID_SYS_PREDIV			138
+#define CLKID_GP0_PREDIV			139
+#define CLKID_HIFI_PREDIV			140
+#define CLKID_PCIE_PREDIV			141
 
 #endif /* __AXG_CLKC_H */
diff --git a/include/dt-bindings/clock/g12a-clkc.h b/include/dt-bindings/clock/g12a-clkc.h
index fd09819da2ec..d2aa3df14149 100644
--- a/include/dt-bindings/clock/g12a-clkc.h
+++ b/include/dt-bindings/clock/g12a-clkc.h
@@ -287,5 +287,13 @@
 #define CLKID_MIPI_ISP_GATE			276
 #define CLKID_MIPI_ISP_CSI_PHY0			277
 #define CLKID_MIPI_ISP_CSI_PHY1			278
+#define CLKID_FIXED_PREDIV			279
+#define CLKID_SYS_PREDIV			280
+#define CLKID_GP0_PREDIV			281
+#define CLKID_HIFI_PREDIV			282
+#define CLKID_HDMI_PREDIV			283
+#define CLKID_PCIE_PREDIV			284
+#define CLKID_SYS1_PREDIV			285
+#define CLKID_GP1_PREDIV			286
 
 #endif /* __G12A_CLKC_H */
diff --git a/include/dt-bindings/clock/gxbb-clkc.h b/include/dt-bindings/clock/gxbb-clkc.h
index c0ce5e9c4151..e2e1ec60285d 100644
--- a/include/dt-bindings/clock/gxbb-clkc.h
+++ b/include/dt-bindings/clock/gxbb-clkc.h
@@ -212,5 +212,9 @@
 #define CLKID_HDMI_DIV		204
 #define CLKID_HDMI		205
 #define CLKID_ACODEC		206
+#define CLKID_FIXED_PREDIV	207
+#define CLKID_HDMI_PREDIV	208
+#define CLKID_SYS_PREDIV	209
+#define CLKID_GP0_PREDIV	210
 
 #endif /* __GXBB_CLKC_H */
diff --git a/include/dt-bindings/clock/meson8-ddr-clkc.h b/include/dt-bindings/clock/meson8-ddr-clkc.h
index a8e0fa2987ab..ce97a15c28a9 100644
--- a/include/dt-bindings/clock/meson8-ddr-clkc.h
+++ b/include/dt-bindings/clock/meson8-ddr-clkc.h
@@ -2,3 +2,4 @@
 
 #define DDR_CLKID_DDR_PLL_DCO			0
 #define DDR_CLKID_DDR_PLL			1
+#define DDR_CLKID_DDR_PREDIV			2
diff --git a/include/dt-bindings/clock/meson8b-clkc.h b/include/dt-bindings/clock/meson8b-clkc.h
index 385bf243c56c..c4fd127dca1e 100644
--- a/include/dt-bindings/clock/meson8b-clkc.h
+++ b/include/dt-bindings/clock/meson8b-clkc.h
@@ -221,5 +221,9 @@
 #define CLKID_VCLK2_EN		215
 #define CLKID_VID_PLL_LVDS_EN	216
 #define CLKID_HDMI_PLL_DCO_IN   217
+#define CLKID_PLL_FIXED_PREDIV	218
+#define CLKID_PLL_SYS_PREDIV	219
+#define CLKID_HDMI_PREDIV	220
+#define CLKID_GP_PREDIV		221
 
 #endif /* __MESON8B_CLKC_H */

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (2 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  9:11   ` sashiko-bot
  2026-12-01  8:56 ` [PATCH RFC RFT v3 05/13] clk: meson: a1: " Jian Hu via B4 Relay
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

The GP1 PLL table lists contiguous multipliers, describe it with a
pll_mult_range instead of a table.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/axg.c | 204 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 136 insertions(+), 68 deletions(-)

diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c
index 280842e9cb37..8c5a2640324c 100644
--- a/drivers/clk/meson/axg.c
+++ b/drivers/clk/meson/axg.c
@@ -107,6 +107,30 @@
 #define HHI_DPLL_TOP_I			0x318
 #define HHI_DPLL_TOP2_I			0x31C
 
+static struct clk_regmap axg_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset	= HHI_MPLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 * The same applies to sys_prediv.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap axg_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -119,11 +143,6 @@ static struct clk_regmap axg_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_MPLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_MPLL_CNTL2,
 			.shift   = 0,
@@ -143,8 +162,8 @@ static struct clk_regmap axg_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&axg_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -171,6 +190,23 @@ static struct clk_regmap axg_fixed_pll = {
 	},
 };
 
+static struct clk_regmap axg_sys_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset	= HHI_SYS_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "sys_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap axg_sys_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -183,11 +219,6 @@ static struct clk_regmap axg_sys_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_SYS_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_SYS_PLL_CNTL,
 			.shift   = 31,
@@ -202,8 +233,8 @@ static struct clk_regmap axg_sys_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "sys_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&axg_sys_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -227,37 +258,37 @@ static struct clk_regmap axg_sys_pll = {
 	},
 };
 
-static const struct pll_params_table axg_gp0_pll_params_table[] = {
-	PLL_PARAMS(40, 1),
-	PLL_PARAMS(41, 1),
-	PLL_PARAMS(42, 1),
-	PLL_PARAMS(43, 1),
-	PLL_PARAMS(44, 1),
-	PLL_PARAMS(45, 1),
-	PLL_PARAMS(46, 1),
-	PLL_PARAMS(47, 1),
-	PLL_PARAMS(48, 1),
-	PLL_PARAMS(49, 1),
-	PLL_PARAMS(50, 1),
-	PLL_PARAMS(51, 1),
-	PLL_PARAMS(52, 1),
-	PLL_PARAMS(53, 1),
-	PLL_PARAMS(54, 1),
-	PLL_PARAMS(55, 1),
-	PLL_PARAMS(56, 1),
-	PLL_PARAMS(57, 1),
-	PLL_PARAMS(58, 1),
-	PLL_PARAMS(59, 1),
-	PLL_PARAMS(60, 1),
-	PLL_PARAMS(61, 1),
-	PLL_PARAMS(62, 1),
-	PLL_PARAMS(63, 1),
-	PLL_PARAMS(64, 1),
-	PLL_PARAMS(65, 1),
-	PLL_PARAMS(66, 1),
-	PLL_PARAMS(67, 1),
-	PLL_PARAMS(68, 1),
-	{ /* sentinel */ },
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table axg_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap axg_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP0_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= axg_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
+static const struct pll_mult_range axg_gp0_pll_mult_range = {
+	.min = 40,
+	.max = 68,
 };
 
 static const struct reg_sequence axg_gp0_init_regs[] = {
@@ -280,11 +311,6 @@ static struct clk_regmap axg_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_GP0_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_GP0_PLL_CNTL1,
 			.shift   = 0,
@@ -300,17 +326,18 @@ static struct clk_regmap axg_gp0_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = axg_gp0_pll_params_table,
+		.range = &axg_gp0_pll_mult_range,
 		.init_regs = axg_gp0_init_regs,
 		.init_count = ARRAY_SIZE(axg_gp0_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&axg_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -332,6 +359,24 @@ static struct clk_regmap axg_gp0_pll = {
 	},
 };
 
+static struct clk_regmap axg_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset	= HHI_HIFI_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= axg_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence axg_hifi_pll_init_regs[] = {
 	{ .reg = HHI_HIFI_PLL_CNTL1,	.def = 0xc084b000 },
 	{ .reg = HHI_HIFI_PLL_CNTL2,	.def = 0xb75020be },
@@ -352,11 +397,6 @@ static struct clk_regmap axg_hifi_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_HIFI_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_HIFI_PLL_CNTL5,
 			.shift   = 0,
@@ -372,7 +412,7 @@ static struct clk_regmap axg_hifi_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = axg_gp0_pll_params_table,
+		.range = &axg_gp0_pll_mult_range,
 		.init_regs = axg_hifi_pll_init_regs,
 		.init_count = ARRAY_SIZE(axg_hifi_pll_init_regs),
 		.flags = CLK_MESON_PLL_ROUND_CLOSEST,
@@ -380,10 +420,11 @@ static struct clk_regmap axg_hifi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&axg_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -771,6 +812,32 @@ static struct clk_regmap axg_mpll3 = {
 	},
 };
 
+/*
+ * This AXG PCIe PLL needs pre-divider 3 to hit the target frequency 100Mhz.
+ */
+static const struct clk_div_table axg_pcie_pll_prediv_div_table[] = {
+	{ .val = 3, .div = 3 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap axg_pcie_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_PCIE_PLL_CNTL,
+		.shift   = 9,
+		.width   = 5,
+		.table = axg_pcie_pll_prediv_div_table,
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "pcie_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_params_table axg_pcie_pll_params_table[] = {
 	{
 		.m = 200,
@@ -801,11 +868,6 @@ static struct clk_regmap axg_pcie_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_PCIE_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_PCIE_PLL_CNTL1,
 			.shift   = 0,
@@ -828,10 +890,11 @@ static struct clk_regmap axg_pcie_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "pcie_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&axg_pcie_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -2067,10 +2130,15 @@ static struct clk_hw *axg_hw_clks[] = {
 	[CLKID_GEN_CLK_SEL]		= &axg_gen_clk_sel.hw,
 	[CLKID_GEN_CLK_DIV]		= &axg_gen_clk_div.hw,
 	[CLKID_GEN_CLK]			= &axg_gen_clk.hw,
+	[CLKID_SYS_PREDIV]		= &axg_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]		= &axg_sys_pll_dco.hw,
+	[CLKID_FIXED_PREDIV]		= &axg_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]		= &axg_fixed_pll_dco.hw,
+	[CLKID_GP0_PREDIV]		= &axg_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &axg_gp0_pll_dco.hw,
+	[CLKID_HIFI_PREDIV]		= &axg_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &axg_hifi_pll_dco.hw,
+	[CLKID_PCIE_PREDIV]		= &axg_pcie_prediv.hw,
 	[CLKID_PCIE_PLL_DCO]		= &axg_pcie_pll_dco.hw,
 	[CLKID_PCIE_PLL_OD]		= &axg_pcie_pll_od.hw,
 	[CLKID_VPU_0_DIV]		= &axg_vpu_0_div.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 05/13] clk: meson: a1: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (3 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 06/13] clk: meson: c3: " Jian Hu via B4 Relay
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/a1-pll.c | 69 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 55 insertions(+), 14 deletions(-)

diff --git a/drivers/clk/meson/a1-pll.c b/drivers/clk/meson/a1-pll.c
index 100c4221256e..5fa8db728aed 100644
--- a/drivers/clk/meson/a1-pll.c
+++ b/drivers/clk/meson/a1-pll.c
@@ -25,6 +25,29 @@
 
 #include <dt-bindings/clock/amlogic,a1-pll-clkc.h>
 
+static struct clk_regmap a1_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_FIXPLL_CTRL0,
+		.shift  = 10,
+		.width  = 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 */
+		.flags  = CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "fixpll_in",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap a1_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -37,11 +60,6 @@ static struct clk_regmap a1_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_FIXPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = ANACTRL_FIXPLL_CTRL1,
 			.shift   = 0,
@@ -61,8 +79,8 @@ static struct clk_regmap a1_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "fixpll_in",
+		.parent_hws = (const struct clk_hw *[]) {
+			&a1_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -83,6 +101,31 @@ static struct clk_regmap a1_fixed_pll = {
 	},
 };
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table a1_hifi_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap a1_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_HIFIPLL_CTRL0,
+		.shift = 10,
+		.width = 5,
+		.table = a1_hifi_pll_prediv_div_table,
+		/* CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration. */
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "hifipll_in",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_mult_range a1_hifi_pll_range = {
 	.min = 32,
 	.max = 64,
@@ -108,11 +151,6 @@ static struct clk_regmap a1_hifi_pll = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_HIFIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = ANACTRL_HIFIPLL_CTRL1,
 			.shift   = 0,
@@ -140,10 +178,11 @@ static struct clk_regmap a1_hifi_pll = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "hifipll_in",
+		.parent_hws = (const struct clk_hw *[]) {
+			&a1_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -281,6 +320,7 @@ static struct clk_regmap a1_fclk_div7 = {
 
 /* Array of all clocks registered by this provider */
 static struct clk_hw *a1_pll_hw_clks[] = {
+	[CLKID_FIXED_PREDIV]	= &a1_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]	= &a1_fixed_pll_dco.hw,
 	[CLKID_FIXED_PLL]	= &a1_fixed_pll.hw,
 	[CLKID_FCLK_DIV2_DIV]	= &a1_fclk_div2_div.hw,
@@ -291,6 +331,7 @@ static struct clk_hw *a1_pll_hw_clks[] = {
 	[CLKID_FCLK_DIV3]	= &a1_fclk_div3.hw,
 	[CLKID_FCLK_DIV5]	= &a1_fclk_div5.hw,
 	[CLKID_FCLK_DIV7]	= &a1_fclk_div7.hw,
+	[CLKID_HIFI_PREDIV]	= &a1_hifi_prediv.hw,
 	[CLKID_HIFI_PLL]	= &a1_hifi_pll.hw,
 };
 

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 06/13] clk: meson: c3: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (4 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 05/13] clk: meson: a1: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/c3-pll.c | 97 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 76 insertions(+), 21 deletions(-)

diff --git a/drivers/clk/meson/c3-pll.c b/drivers/clk/meson/c3-pll.c
index dd047d17488c..984f43f1c76c 100644
--- a/drivers/clk/meson/c3-pll.c
+++ b/drivers/clk/meson/c3-pll.c
@@ -230,6 +230,34 @@ static struct clk_regmap c3_fclk_div7 = {
 	},
 };
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table c3_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap c3_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data) {
+		.offset = ANACTRL_GP0PLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= c3_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "top",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence c3_gp0_pll_init_regs[] = {
 	{ .reg = ANACTRL_GP0PLL_CTRL2,	.def = 0x0 },
 	{ .reg = ANACTRL_GP0PLL_CTRL3,	.def = 0x48681c00 },
@@ -260,11 +288,6 @@ static struct clk_regmap c3_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 19,
 		},
-		.n = {
-			.reg_off = ANACTRL_GP0PLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_GP0PLL_CTRL0,
 			.shift   = 31,
@@ -282,10 +305,11 @@ static struct clk_regmap c3_gp0_pll_dco = {
 	.hw.init = &(struct clk_init_data) {
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "top",
+		.parent_hws = (const struct clk_hw *[]) {
+			&c3_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -318,6 +342,24 @@ static struct clk_regmap c3_gp0_pll = {
 	},
 };
 
+static struct clk_regmap c3_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data) {
+		.offset = ANACTRL_HIFIPLL_CTRL0,
+		.shift = 10,
+		.width = 5,
+		.table = c3_pll_prediv_div_table,
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "top",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence c3_hifi_pll_init_regs[] = {
 	{ .reg = ANACTRL_HIFIPLL_CTRL2,	.def = 0x0 },
 	{ .reg = ANACTRL_HIFIPLL_CTRL3,	.def = 0x6a285c00 },
@@ -343,11 +385,6 @@ static struct clk_regmap c3_hifi_pll_dco = {
 			.shift   = 0,
 			.width   = 19,
 		},
-		.n = {
-			.reg_off = ANACTRL_HIFIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_HIFIPLL_CTRL0,
 			.shift   = 31,
@@ -366,10 +403,11 @@ static struct clk_regmap c3_hifi_pll_dco = {
 	.hw.init = &(struct clk_init_data) {
 		.name = "hifi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "top",
+		.parent_hws = (const struct clk_hw *[]) {
+			&c3_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -391,6 +429,24 @@ static struct clk_regmap c3_hifi_pll = {
 	},
 };
 
+static struct clk_regmap c3_mclk_prediv = {
+	.data = &(struct clk_regmap_div_data) {
+		.offset = ANACTRL_MPLL_CTRL0,
+		.shift = 16,
+		.width = 5,
+		.table = c3_pll_prediv_div_table,
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "mclk_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "mclk",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence c3_mclk_pll_init_regs[] = {
 	{ .reg = ANACTRL_MPLL_CTRL1,	.def = 0x1420500f },
 	{ .reg = ANACTRL_MPLL_CTRL2,	.def = 0x00023041 },
@@ -415,11 +471,6 @@ static struct clk_regmap c3_mclk_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_MPLL_CTRL0,
-			.shift   = 16,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_MPLL_CTRL0,
 			.shift   = 31,
@@ -437,10 +488,11 @@ static struct clk_regmap c3_mclk_pll_dco = {
 	.hw.init = &(struct clk_init_data) {
 		.name = "mclk_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "mclk",
+		.parent_hws = (const struct clk_hw *[]) {
+			&c3_mclk_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -636,10 +688,13 @@ static struct clk_hw *c3_pll_hw_clks[] = {
 	[CLKID_FCLK_DIV5]	= &c3_fclk_div5.hw,
 	[CLKID_FCLK_DIV7_DIV]	= &c3_fclk_div7_div.hw,
 	[CLKID_FCLK_DIV7]	= &c3_fclk_div7.hw,
+	[CLKID_GP0_PREDIV]	= &c3_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]	= &c3_gp0_pll_dco.hw,
 	[CLKID_GP0_PLL]		= &c3_gp0_pll.hw,
+	[CLKID_HIFI_PREDIV]	= &c3_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]	= &c3_hifi_pll_dco.hw,
 	[CLKID_HIFI_PLL]	= &c3_hifi_pll.hw,
+	[CLKID_MCLK_PREDIV]	= &c3_mclk_prediv.hw,
 	[CLKID_MCLK_PLL_DCO]	= &c3_mclk_pll_dco.hw,
 	[CLKID_MCLK_PLL_OD]	= &c3_mclk_pll_od.hw,
 	[CLKID_MCLK_PLL]	= &c3_mclk_pll.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 07/13] clk: meson: gxbb: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (5 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 06/13] clk: meson: c3: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  9:16   ` sashiko-bot
  2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

The GP0 PLL table lists contiguous multipliers, describe it with a
pll_mult_range instead of a table.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/gxbb.c | 260 ++++++++++++++++++++++++++++-------------------
 1 file changed, 158 insertions(+), 102 deletions(-)

diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c
index 2d5128c0bf9e..b7350788b73e 100644
--- a/drivers/clk/meson/gxbb.c
+++ b/drivers/clk/meson/gxbb.c
@@ -115,6 +115,29 @@
 #define HHI_BT656_CLK_CNTL		0x3d4
 #define HHI_SAR_CLK_CNTL		0x3d8
 
+static struct clk_regmap gxbb_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_MPLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 3 gives a divisor of 3.
+		 * The hardware design sets the division factor of this prescaler
+		 * to 3 to produce a 2G output.
+		 */
+		.flags = CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap gxbb_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -127,11 +150,6 @@ static struct clk_regmap gxbb_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_MPLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_MPLL_CNTL2,
 			.shift   = 0,
@@ -151,8 +169,8 @@ static struct clk_regmap gxbb_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxbb_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -192,6 +210,28 @@ static struct clk_fixed_factor gxbb_hdmi_pll_pre_mult = {
 	},
 };
 
+static struct clk_regmap gxbb_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_HDMI_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxbb_hdmi_pll_pre_mult.hw
+		},
+		.num_parents = 1,
+		/*
+		 * Display directly handle hdmi pll registers ATM, we need
+		 * NOCACHE to keep our view of the clock as accurate as possible
+		 */
+		.flags = CLK_GET_RATE_NOCACHE,
+	},
+};
+
 static struct clk_regmap gxbb_hdmi_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -204,11 +244,6 @@ static struct clk_regmap gxbb_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_HDMI_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_HDMI_PLL_CNTL2,
 			.shift   = 0,
@@ -229,7 +264,29 @@ static struct clk_regmap gxbb_hdmi_pll_dco = {
 		.name = "hdmi_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
 		.parent_hws = (const struct clk_hw *[]) {
-			&gxbb_hdmi_pll_pre_mult.hw
+			&gxbb_hdmi_prediv.hw
+		},
+		.num_parents = 1,
+		/*
+		 * Display directly handle hdmi pll registers ATM, we need
+		 * NOCACHE to keep our view of the clock as accurate as possible
+		 */
+		.flags = CLK_GET_RATE_NOCACHE,
+	},
+};
+
+static struct clk_regmap gxl_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_HDMI_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
 		},
 		.num_parents = 1,
 		/*
@@ -252,11 +309,6 @@ static struct clk_regmap gxl_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_HDMI_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		/*
 		 * On gxl, there is a register shift due to
 		 * HHI_HDMI_PLL_CNTL1 which does not exist on gxbb,
@@ -282,8 +334,8 @@ static struct clk_regmap gxl_hdmi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hdmi_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxl_hdmi_prediv.hw
 		},
 		.num_parents = 1,
 		/*
@@ -414,6 +466,23 @@ static struct clk_regmap gxl_hdmi_pll = {
 	},
 };
 
+static struct clk_regmap gxbb_sys_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_SYS_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "sys_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap gxbb_sys_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -426,11 +495,6 @@ static struct clk_regmap gxbb_sys_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_SYS_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_SYS_PLL_CNTL,
 			.shift   = 31,
@@ -445,8 +509,8 @@ static struct clk_regmap gxbb_sys_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "sys_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxbb_sys_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -470,39 +534,37 @@ static struct clk_regmap gxbb_sys_pll = {
 	},
 };
 
-static const struct pll_params_table gxbb_gp0_pll_params_table[] = {
-	PLL_PARAMS(32, 1),
-	PLL_PARAMS(33, 1),
-	PLL_PARAMS(34, 1),
-	PLL_PARAMS(35, 1),
-	PLL_PARAMS(36, 1),
-	PLL_PARAMS(37, 1),
-	PLL_PARAMS(38, 1),
-	PLL_PARAMS(39, 1),
-	PLL_PARAMS(40, 1),
-	PLL_PARAMS(41, 1),
-	PLL_PARAMS(42, 1),
-	PLL_PARAMS(43, 1),
-	PLL_PARAMS(44, 1),
-	PLL_PARAMS(45, 1),
-	PLL_PARAMS(46, 1),
-	PLL_PARAMS(47, 1),
-	PLL_PARAMS(48, 1),
-	PLL_PARAMS(49, 1),
-	PLL_PARAMS(50, 1),
-	PLL_PARAMS(51, 1),
-	PLL_PARAMS(52, 1),
-	PLL_PARAMS(53, 1),
-	PLL_PARAMS(54, 1),
-	PLL_PARAMS(55, 1),
-	PLL_PARAMS(56, 1),
-	PLL_PARAMS(57, 1),
-	PLL_PARAMS(58, 1),
-	PLL_PARAMS(59, 1),
-	PLL_PARAMS(60, 1),
-	PLL_PARAMS(61, 1),
-	PLL_PARAMS(62, 1),
-	{ /* sentinel */ },
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table gxbb_gp0_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap gxbb_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP0_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= gxbb_gp0_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
+static const struct pll_mult_range gxbb_gp0_pll_mult_range = {
+	.min = 32,
+	.max = 62,
 };
 
 static const struct reg_sequence gxbb_gp0_pll_init_regs[] = {
@@ -523,11 +585,6 @@ static struct clk_regmap gxbb_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_GP0_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_GP0_PLL_CNTL,
 			.shift   = 31,
@@ -538,13 +595,32 @@ static struct clk_regmap gxbb_gp0_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = gxbb_gp0_pll_params_table,
+		.range = &gxbb_gp0_pll_mult_range,
 		.init_regs = gxbb_gp0_pll_init_regs,
 		.init_count = ARRAY_SIZE(gxbb_gp0_pll_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxbb_gp0_prediv.hw
+		},
+		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
+	},
+};
+
+static struct clk_regmap gxl_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP0_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= gxbb_gp0_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
 		.parent_data = &(const struct clk_parent_data) {
 			.fw_name = "xtal",
 		},
@@ -552,33 +628,9 @@ static struct clk_regmap gxbb_gp0_pll_dco = {
 	},
 };
 
-static const struct pll_params_table gxl_gp0_pll_params_table[] = {
-	PLL_PARAMS(42, 1),
-	PLL_PARAMS(43, 1),
-	PLL_PARAMS(44, 1),
-	PLL_PARAMS(45, 1),
-	PLL_PARAMS(46, 1),
-	PLL_PARAMS(47, 1),
-	PLL_PARAMS(48, 1),
-	PLL_PARAMS(49, 1),
-	PLL_PARAMS(50, 1),
-	PLL_PARAMS(51, 1),
-	PLL_PARAMS(52, 1),
-	PLL_PARAMS(53, 1),
-	PLL_PARAMS(54, 1),
-	PLL_PARAMS(55, 1),
-	PLL_PARAMS(56, 1),
-	PLL_PARAMS(57, 1),
-	PLL_PARAMS(58, 1),
-	PLL_PARAMS(59, 1),
-	PLL_PARAMS(60, 1),
-	PLL_PARAMS(61, 1),
-	PLL_PARAMS(62, 1),
-	PLL_PARAMS(63, 1),
-	PLL_PARAMS(64, 1),
-	PLL_PARAMS(65, 1),
-	PLL_PARAMS(66, 1),
-	{ /* sentinel */ },
+static const struct pll_mult_range gxl_gp0_pll_mult_range = {
+	.min = 42,
+	.max = 66,
 };
 
 static const struct reg_sequence gxl_gp0_pll_init_regs[] = {
@@ -601,11 +653,6 @@ static struct clk_regmap gxl_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_GP0_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_GP0_PLL_CNTL1,
 			.shift   = 0,
@@ -621,17 +668,18 @@ static struct clk_regmap gxl_gp0_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = gxl_gp0_pll_params_table,
+		.range = &gxl_gp0_pll_mult_range,
 		.init_regs = gxl_gp0_pll_init_regs,
 		.init_count = ARRAY_SIZE(gxl_gp0_pll_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&gxl_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -2371,7 +2419,7 @@ static struct clk_regmap gxbb_cts_encp_sel = {
 	.data = &(struct clk_regmap_mux_data){
 		.offset = HHI_VID_CLK_DIV,
 		.mask = 0xf,
-		.shift = 24,
+		.shift = 20,
 		.table = gxbb_cts_parents_val_table,
 	},
 	.hw.init = &(struct clk_init_data){
@@ -3007,11 +3055,15 @@ static struct clk_hw *gxbb_hw_clks[] = {
 	[CLKID_GEN_CLK_SEL]	    = &gxbb_gen_clk_sel.hw,
 	[CLKID_GEN_CLK_DIV]	    = &gxbb_gen_clk_div.hw,
 	[CLKID_GEN_CLK]		    = &gxbb_gen_clk.hw,
+	[CLKID_FIXED_PREDIV]	    = &gxbb_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]	    = &gxbb_fixed_pll_dco.hw,
+	[CLKID_HDMI_PREDIV]	    = &gxbb_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]	    = &gxbb_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]	    = &gxbb_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL_OD2]	    = &gxbb_hdmi_pll_od2.hw,
+	[CLKID_SYS_PREDIV]	    = &gxbb_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]	    = &gxbb_sys_pll_dco.hw,
+	[CLKID_GP0_PREDIV]	    = &gxbb_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]	    = &gxbb_gp0_pll_dco.hw,
 	[CLKID_VID_PLL_DIV]	    = &gxbb_vid_pll_div.hw,
 	[CLKID_VID_PLL_SEL]	    = &gxbb_vid_pll_sel.hw,
@@ -3214,11 +3266,15 @@ static struct clk_hw *gxl_hw_clks[] = {
 	[CLKID_GEN_CLK_SEL]	    = &gxbb_gen_clk_sel.hw,
 	[CLKID_GEN_CLK_DIV]	    = &gxbb_gen_clk_div.hw,
 	[CLKID_GEN_CLK]		    = &gxbb_gen_clk.hw,
+	[CLKID_FIXED_PREDIV]	    = &gxbb_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]	    = &gxbb_fixed_pll_dco.hw,
+	[CLKID_HDMI_PREDIV]	    = &gxl_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]	    = &gxl_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]	    = &gxl_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL_OD2]	    = &gxl_hdmi_pll_od2.hw,
+	[CLKID_SYS_PREDIV]	    = &gxbb_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]	    = &gxbb_sys_pll_dco.hw,
+	[CLKID_GP0_PREDIV]	    = &gxl_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]	    = &gxl_gp0_pll_dco.hw,
 	[CLKID_VID_PLL_DIV]	    = &gxbb_vid_pll_div.hw,
 	[CLKID_VID_PLL_SEL]	    = &gxbb_vid_pll_sel.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 08/13] clk: meson: g12a: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (6 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  9:19   ` sashiko-bot
  2026-12-01  8:56 ` [PATCH RFC RFT v3 09/13] clk: meson: meson8: " Jian Hu via B4 Relay
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/g12a.c | 275 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 217 insertions(+), 58 deletions(-)

diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c
index beed610e4a82..09eb842e0b1a 100644
--- a/drivers/clk/meson/g12a.c
+++ b/drivers/clk/meson/g12a.c
@@ -137,6 +137,30 @@
 #define HHI_SYS1_PLL_CNTL5		0x394
 #define HHI_SYS1_PLL_CNTL6		0x398
 
+static struct clk_regmap g12a_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_FIX_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 * The same applies below.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap g12a_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -149,11 +173,6 @@ static struct clk_regmap g12a_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_FIX_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_FIX_PLL_CNTL1,
 			.shift   = 0,
@@ -173,8 +192,8 @@ static struct clk_regmap g12a_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -201,6 +220,34 @@ static struct clk_regmap g12a_fixed_pll = {
 	},
 };
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table g12a_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap g12a_sys_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_SYS_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= g12a_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "sys_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_mult_range g12a_sys_pll_mult_range = {
 	.min = 128,
 	.max = 250,
@@ -218,11 +265,6 @@ static struct clk_regmap g12a_sys_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_SYS_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_SYS_PLL_CNTL0,
 			.shift   = 31,
@@ -238,12 +280,12 @@ static struct clk_regmap g12a_sys_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "sys_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_sys_prediv.hw
 		},
 		.num_parents = 1,
 		/* This clock feeds the CPU, avoid disabling it */
-		.flags = CLK_IS_CRITICAL,
+		.flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
 	},
 };
 
@@ -265,6 +307,24 @@ static struct clk_regmap g12a_sys_pll = {
 	},
 };
 
+static struct clk_regmap g12b_sys1_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_SYS1_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= g12a_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "sys1_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap g12b_sys1_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -277,11 +337,6 @@ static struct clk_regmap g12b_sys1_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_SYS1_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_SYS1_PLL_CNTL0,
 			.shift   = 31,
@@ -297,12 +352,12 @@ static struct clk_regmap g12b_sys1_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "sys1_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12b_sys1_prediv.hw
 		},
 		.num_parents = 1,
 		/* This clock feeds the CPU, avoid disabling it */
-		.flags = CLK_IS_CRITICAL,
+		.flags = CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
 	},
 };
 
@@ -386,6 +441,24 @@ static struct clk_fixed_factor g12b_sys1_pll_div16 = {
 	},
 };
 
+static struct clk_regmap g12a_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP0_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= g12a_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_mult_range g12a_gp0_pll_mult_range = {
 	.min = 125,
 	.max = 255,
@@ -415,11 +488,6 @@ static struct clk_regmap g12a_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_GP0_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_GP0_PLL_CNTL1,
 			.shift   = 0,
@@ -442,10 +510,11 @@ static struct clk_regmap g12a_gp0_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -468,6 +537,23 @@ static struct clk_regmap g12a_gp0_pll = {
 	},
 };
 
+static struct clk_regmap sm1_gp1_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP1_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp1_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap sm1_gp1_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -480,11 +566,6 @@ static struct clk_regmap sm1_gp1_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_GP1_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_GP1_PLL_CNTL1,
 			.shift   = 0,
@@ -504,8 +585,8 @@ static struct clk_regmap sm1_gp1_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp1_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&sm1_gp1_prediv.hw
 		},
 		.num_parents = 1,
 		/* This clock feeds the DSU, avoid disabling it */
@@ -531,6 +612,24 @@ static struct clk_regmap sm1_gp1_pll = {
 	},
 };
 
+static struct clk_regmap g12a_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_HIFI_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= g12a_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 /*
  * Internal hifi pll emulation configuration parameters
  */
@@ -555,11 +654,6 @@ static struct clk_regmap g12a_hifi_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_HIFI_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_HIFI_PLL_CNTL1,
 			.shift   = 0,
@@ -583,10 +677,11 @@ static struct clk_regmap g12a_hifi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -609,6 +704,32 @@ static struct clk_regmap g12a_hifi_pll = {
 	},
 };
 
+static struct clk_regmap g12a_pcie_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_PCIE_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= g12a_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "pcie_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+		/*
+		 * The PCIe prediv register reads zero on power-on.
+		 * CLK_DIVIDER_INVALID_ZERO makes the first rate return 0 Hz,
+		 * which gets cached by CCF. The PCIe PLL enable callback
+		 * later writes a valid non-zero divider value. Use
+		 * CLK_GET_RATE_NOCACHE to avoid stale cached rate.
+		 */
+		.flags	= CLK_GET_RATE_NOCACHE,
+	},
+};
+
 /*
  * The Meson G12A PCIE PLL is fined tuned to deliver a very precise
  * 100MHz reference clock for the PCIe Analog PHY, and thus requires
@@ -647,11 +768,6 @@ static struct clk_regmap g12a_pcie_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_PCIE_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_PCIE_PLL_CNTL1,
 			.shift   = 0,
@@ -674,10 +790,11 @@ static struct clk_regmap g12a_pcie_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "pcie_pll_dco",
 		.ops = &meson_clk_pcie_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_pcie_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -729,6 +846,33 @@ static struct clk_fixed_factor g12a_pcie_pll = {
 	},
 };
 
+static struct clk_regmap g12a_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_HDMI_PLL_CNTL0,
+		.shift	= 10,
+		.width	= 5,
+		/*
+		 * The pre-divider register reads zero until the display driver
+		 * programs the HDMI PLL, so a zero divisor is not a fault here:
+		 * treat it as a bypass instead of warning at registration.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+		/*
+		 * Display directly handle hdmi pll registers ATM, we need
+		 * NOCACHE to keep our view of the clock as accurate as possible
+		 */
+		.flags = CLK_GET_RATE_NOCACHE,
+	},
+};
+
 static struct clk_regmap g12a_hdmi_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -741,11 +885,6 @@ static struct clk_regmap g12a_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HHI_HDMI_PLL_CNTL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_HDMI_PLL_CNTL1,
 			.shift   = 0,
@@ -765,8 +904,8 @@ static struct clk_regmap g12a_hdmi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hdmi_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&g12a_hdmi_prediv.hw
 		},
 		.num_parents = 1,
 		/*
@@ -4594,9 +4733,13 @@ static struct clk_hw *g12a_hw_clks[] = {
 	[CLKID_VCLK2_VENCLMMC]		= &g12a_vclk2_venclmmc.hw,
 	[CLKID_VCLK2_VENCL]		= &g12a_vclk2_vencl.hw,
 	[CLKID_VCLK2_OTHER1]		= &g12a_vclk2_other1.hw,
+	[CLKID_FIXED_PREDIV]		= &g12a_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]		= &g12a_fixed_pll_dco.hw,
+	[CLKID_SYS_PREDIV]		= &g12a_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]		= &g12a_sys_pll_dco.hw,
+	[CLKID_GP0_PREDIV]		= &g12a_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &g12a_gp0_pll_dco.hw,
+	[CLKID_HIFI_PREDIV]		= &g12a_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &g12a_hifi_pll_dco.hw,
 	[CLKID_DMA]			= &g12a_dma.hw,
 	[CLKID_EFUSE]			= &g12a_efuse.hw,
@@ -4619,6 +4762,7 @@ static struct clk_hw *g12a_hw_clks[] = {
 	[CLKID_VAPB_1]			= &g12a_vapb_1.hw,
 	[CLKID_VAPB_SEL]		= &g12a_vapb_sel.hw,
 	[CLKID_VAPB]			= &g12a_vapb.hw,
+	[CLKID_HDMI_PREDIV]		= &g12a_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]		= &g12a_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]		= &g12a_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL_OD2]		= &g12a_hdmi_pll_od2.hw,
@@ -4694,6 +4838,7 @@ static struct clk_hw *g12a_hw_clks[] = {
 	[CLKID_CPU_CLK_AXI]		= &g12a_cpu_clk_axi.hw,
 	[CLKID_CPU_CLK_TRACE_DIV]	= &g12a_cpu_clk_trace_div.hw,
 	[CLKID_CPU_CLK_TRACE]		= &g12a_cpu_clk_trace.hw,
+	[CLKID_PCIE_PREDIV]		= &g12a_pcie_prediv.hw,
 	[CLKID_PCIE_PLL_DCO]		= &g12a_pcie_pll_dco.hw,
 	[CLKID_PCIE_PLL_DCO_DIV2]	= &g12a_pcie_pll_dco_div2.hw,
 	[CLKID_PCIE_PLL_OD]		= &g12a_pcie_pll_od.hw,
@@ -4821,9 +4966,13 @@ static struct clk_hw *g12b_hw_clks[] = {
 	[CLKID_VCLK2_VENCLMMC]		= &g12a_vclk2_venclmmc.hw,
 	[CLKID_VCLK2_VENCL]		= &g12a_vclk2_vencl.hw,
 	[CLKID_VCLK2_OTHER1]		= &g12a_vclk2_other1.hw,
+	[CLKID_FIXED_PREDIV]		= &g12a_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]		= &g12a_fixed_pll_dco.hw,
+	[CLKID_SYS_PREDIV]		= &g12a_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]		= &g12a_sys_pll_dco.hw,
+	[CLKID_GP0_PREDIV]		= &g12a_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &g12a_gp0_pll_dco.hw,
+	[CLKID_HIFI_PREDIV]		= &g12a_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &g12a_hifi_pll_dco.hw,
 	[CLKID_DMA]			= &g12a_dma.hw,
 	[CLKID_EFUSE]			= &g12a_efuse.hw,
@@ -4846,6 +4995,7 @@ static struct clk_hw *g12b_hw_clks[] = {
 	[CLKID_VAPB_1]			= &g12a_vapb_1.hw,
 	[CLKID_VAPB_SEL]		= &g12a_vapb_sel.hw,
 	[CLKID_VAPB]			= &g12a_vapb.hw,
+	[CLKID_HDMI_PREDIV]		= &g12a_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]		= &g12a_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]		= &g12a_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL_OD2]		= &g12a_hdmi_pll_od2.hw,
@@ -4921,6 +5071,7 @@ static struct clk_hw *g12b_hw_clks[] = {
 	[CLKID_CPU_CLK_AXI]		= &g12a_cpu_clk_axi.hw,
 	[CLKID_CPU_CLK_TRACE_DIV]	= &g12a_cpu_clk_trace_div.hw,
 	[CLKID_CPU_CLK_TRACE]		= &g12a_cpu_clk_trace.hw,
+	[CLKID_PCIE_PREDIV]		= &g12a_pcie_prediv.hw,
 	[CLKID_PCIE_PLL_DCO]		= &g12a_pcie_pll_dco.hw,
 	[CLKID_PCIE_PLL_DCO_DIV2]	= &g12a_pcie_pll_dco_div2.hw,
 	[CLKID_PCIE_PLL_OD]		= &g12a_pcie_pll_od.hw,
@@ -4936,6 +5087,7 @@ static struct clk_hw *g12b_hw_clks[] = {
 	[CLKID_VDEC_HEVCF]		= &g12a_vdec_hevcf.hw,
 	[CLKID_TS_DIV]			= &g12a_ts_div.hw,
 	[CLKID_TS]			= &g12a_ts.hw,
+	[CLKID_SYS1_PREDIV]		= &g12b_sys1_prediv.hw,
 	[CLKID_SYS1_PLL_DCO]		= &g12b_sys1_pll_dco.hw,
 	[CLKID_SYS1_PLL]		= &g12b_sys1_pll.hw,
 	[CLKID_SYS1_PLL_DIV16_EN]	= &g12b_sys1_pll_div16_en.hw,
@@ -5089,9 +5241,13 @@ static struct clk_hw *sm1_hw_clks[] = {
 	[CLKID_VCLK2_VENCLMMC]		= &g12a_vclk2_venclmmc.hw,
 	[CLKID_VCLK2_VENCL]		= &g12a_vclk2_vencl.hw,
 	[CLKID_VCLK2_OTHER1]		= &g12a_vclk2_other1.hw,
+	[CLKID_FIXED_PREDIV]		= &g12a_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]		= &g12a_fixed_pll_dco.hw,
+	[CLKID_SYS_PREDIV]		= &g12a_sys_prediv.hw,
 	[CLKID_SYS_PLL_DCO]		= &g12a_sys_pll_dco.hw,
+	[CLKID_GP0_PREDIV]		= &g12a_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &g12a_gp0_pll_dco.hw,
+	[CLKID_HIFI_PREDIV]		= &g12a_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &g12a_hifi_pll_dco.hw,
 	[CLKID_DMA]			= &g12a_dma.hw,
 	[CLKID_EFUSE]			= &g12a_efuse.hw,
@@ -5114,6 +5270,7 @@ static struct clk_hw *sm1_hw_clks[] = {
 	[CLKID_VAPB_1]			= &g12a_vapb_1.hw,
 	[CLKID_VAPB_SEL]		= &g12a_vapb_sel.hw,
 	[CLKID_VAPB]			= &g12a_vapb.hw,
+	[CLKID_HDMI_PREDIV]		= &g12a_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]		= &g12a_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]		= &g12a_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL_OD2]		= &g12a_hdmi_pll_od2.hw,
@@ -5189,6 +5346,7 @@ static struct clk_hw *sm1_hw_clks[] = {
 	[CLKID_CPU_CLK_AXI]		= &g12a_cpu_clk_axi.hw,
 	[CLKID_CPU_CLK_TRACE_DIV]	= &g12a_cpu_clk_trace_div.hw,
 	[CLKID_CPU_CLK_TRACE]		= &g12a_cpu_clk_trace.hw,
+	[CLKID_PCIE_PREDIV]		= &g12a_pcie_prediv.hw,
 	[CLKID_PCIE_PLL_DCO]		= &g12a_pcie_pll_dco.hw,
 	[CLKID_PCIE_PLL_DCO_DIV2]	= &g12a_pcie_pll_dco_div2.hw,
 	[CLKID_PCIE_PLL_OD]		= &g12a_pcie_pll_od.hw,
@@ -5205,6 +5363,7 @@ static struct clk_hw *sm1_hw_clks[] = {
 	[CLKID_TS_DIV]			= &g12a_ts_div.hw,
 	[CLKID_TS]			= &g12a_ts.hw,
 	[CLKID_GP1_PLL_DCO]		= &sm1_gp1_pll_dco.hw,
+	[CLKID_GP1_PREDIV]		= &sm1_gp1_prediv.hw,
 	[CLKID_GP1_PLL]			= &sm1_gp1_pll.hw,
 	[CLKID_DSU_CLK_DYN0_SEL]	= &sm1_dsu_clk_dyn0_sel.hw,
 	[CLKID_DSU_CLK_DYN0_DIV]	= &sm1_dsu_clk_dyn0_div.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 09/13] clk: meson: meson8: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (7 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 10/13] clk: meson: s4: " Jian Hu via B4 Relay
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/meson8-ddr.c |  33 +++++++--
 drivers/clk/meson/meson8b.c    | 153 +++++++++++++++++++++++++++++++----------
 2 files changed, 144 insertions(+), 42 deletions(-)

diff --git a/drivers/clk/meson/meson8-ddr.c b/drivers/clk/meson/meson8-ddr.c
index 0f93774f7371..4bf40fb86dbe 100644
--- a/drivers/clk/meson/meson8-ddr.c
+++ b/drivers/clk/meson/meson8-ddr.c
@@ -23,6 +23,29 @@
 #define DDR_CLK_CNTL			0x18
 #define DDR_CLK_STS			0x1c
 
+static struct clk_regmap meson8_ddr_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = AM_DDR_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "ddr_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap meson8_ddr_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -35,11 +58,6 @@ static struct clk_regmap meson8_ddr_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = AM_DDR_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = AM_DDR_PLL_CNTL,
 			.shift   = 31,
@@ -54,8 +72,8 @@ static struct clk_regmap meson8_ddr_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "ddr_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
+		.parent_hws = (const struct clk_hw *[]) {
+			&meson8_ddr_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -79,6 +97,7 @@ static struct clk_regmap meson8_ddr_pll = {
 };
 
 static struct clk_hw *meson8_ddr_hw_clks[] = {
+	[DDR_CLKID_DDR_PREDIV]		= &meson8_ddr_prediv.hw,
 	[DDR_CLKID_DDR_PLL_DCO]		= &meson8_ddr_pll_dco.hw,
 	[DDR_CLKID_DDR_PLL]		= &meson8_ddr_pll.hw,
 };
diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
index bc029c6ab622..ae2bab501597 100644
--- a/drivers/clk/meson/meson8b.c
+++ b/drivers/clk/meson/meson8b.c
@@ -119,6 +119,31 @@ static const struct pll_params_table sys_pll_params_table[] = {
 	{ /* sentinel */ },
 };
 
+static struct clk_regmap meson8b_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_MPLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 4 gives a divisor of 4.
+		 * The hardware design sets the division factor of this prescaler
+		 * to 4 to produce a 2.55G output.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+			.name = "xtal",
+			.index = -1,
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap meson8b_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -131,11 +156,6 @@ static struct clk_regmap meson8b_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_MPLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_MPLL_CNTL2,
 			.shift   = 0,
@@ -155,10 +175,8 @@ static struct clk_regmap meson8b_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
-			.name = "xtal",
-			.index = -1,
+		.parent_hws = (const struct clk_hw *[]) {
+			&meson8b_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -185,17 +203,42 @@ static struct clk_regmap meson8b_fixed_pll = {
 	},
 };
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table meson8b_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap meson8b_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_VID_PLL_CNTL,
+		.shift	= 10,
+		.width	= 5,
+		.table	= meson8b_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+			.index = -1,
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_fixed_factor hdmi_pll_dco_in = {
 	.mult = 2,
 	.div = 1,
 	.hw.init = &(struct clk_init_data){
 		.name = "hdmi_pll_dco_in",
 		.ops = &clk_fixed_factor_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
-			.index = -1,
+		.parent_hws = (const struct clk_hw *[]) {
+			&meson8b_hdmi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -247,11 +290,6 @@ static struct clk_regmap meson8b_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_VID_PLL_CNTL,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HHI_VID_PLL_CNTL2,
 			.shift   = 0,
@@ -279,6 +317,7 @@ static struct clk_regmap meson8b_hdmi_pll_dco = {
 			&hdmi_pll_dco_in.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -318,6 +357,26 @@ static struct clk_regmap meson8b_hdmi_pll_hdmi_out = {
 	},
 };
 
+static struct clk_regmap meson8b_sys_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_SYS_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= meson8b_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "sys_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+			.name = "xtal",
+			.index = -1,
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap meson8b_sys_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -330,11 +389,6 @@ static struct clk_regmap meson8b_sys_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_SYS_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_SYS_PLL_CNTL,
 			.shift   = 31,
@@ -350,12 +404,11 @@ static struct clk_regmap meson8b_sys_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "sys_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
-			.name = "xtal",
-			.index = -1,
+		.parent_hws = (const struct clk_hw *[]) {
+			&meson8b_sys_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -2035,6 +2088,32 @@ static struct clk_regmap meson8b_mali = {
 	},
 };
 
+/* The GP PLL needs pre-divider 3 to achieve the target frequency 364Mhz */
+static const struct clk_div_table meson8b_gp_prediv_div_table[] = {
+	{ .val = 3, .div = 3 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap meson8m2_gp_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HHI_GP_PLL_CNTL,
+		.shift	= 9,
+		.width	= 5,
+		.table	= meson8b_gp_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "xtal",
+			.name = "xtal",
+			.index = -1,
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence meson8m2_gp_pll_init_regs[] = {
 	{ .reg = HHI_GP_PLL_CNTL2,	.def = 0x59c88000 },
 	{ .reg = HHI_GP_PLL_CNTL3,	.def = 0xca463823 },
@@ -2059,11 +2138,6 @@ static struct clk_regmap meson8m2_gp_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HHI_GP_PLL_CNTL,
-			.shift   = 9,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HHI_GP_PLL_CNTL,
 			.shift   = 31,
@@ -2081,12 +2155,11 @@ static struct clk_regmap meson8m2_gp_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "xtal",
-			.name = "xtal",
-			.index = -1,
+		.parent_hws = (const struct clk_hw *[]) {
+			&meson8m2_gp_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -2920,8 +2993,11 @@ static struct clk_hw *meson8_hw_clks[] = {
 	[CLKID_NAND_SEL]	    = &meson8b_nand_clk_sel.hw,
 	[CLKID_NAND_DIV]	    = &meson8b_nand_clk_div.hw,
 	[CLKID_NAND_CLK]	    = &meson8b_nand_clk.hw,
+	[CLKID_PLL_FIXED_PREDIV]    = &meson8b_fixed_prediv.hw,
 	[CLKID_PLL_FIXED_DCO]	    = &meson8b_fixed_pll_dco.hw,
+	[CLKID_HDMI_PREDIV]	    = &meson8b_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]	    = &meson8b_hdmi_pll_dco.hw,
+	[CLKID_PLL_SYS_PREDIV]	    = &meson8b_sys_prediv.hw,
 	[CLKID_PLL_SYS_DCO]	    = &meson8b_sys_pll_dco.hw,
 	[CLKID_CPU_CLK_DIV2]	    = &meson8b_cpu_clk_div2.hw,
 	[CLKID_CPU_CLK_DIV3]	    = &meson8b_cpu_clk_div3.hw,
@@ -3124,8 +3200,11 @@ static struct clk_hw *meson8b_hw_clks[] = {
 	[CLKID_NAND_SEL]	    = &meson8b_nand_clk_sel.hw,
 	[CLKID_NAND_DIV]	    = &meson8b_nand_clk_div.hw,
 	[CLKID_NAND_CLK]	    = &meson8b_nand_clk.hw,
+	[CLKID_PLL_FIXED_PREDIV]    = &meson8b_fixed_prediv.hw,
 	[CLKID_PLL_FIXED_DCO]	    = &meson8b_fixed_pll_dco.hw,
+	[CLKID_HDMI_PREDIV]	    = &meson8b_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]	    = &meson8b_hdmi_pll_dco.hw,
+	[CLKID_PLL_SYS_PREDIV]	    = &meson8b_sys_prediv.hw,
 	[CLKID_PLL_SYS_DCO]	    = &meson8b_sys_pll_dco.hw,
 	[CLKID_CPU_CLK_DIV2]	    = &meson8b_cpu_clk_div2.hw,
 	[CLKID_CPU_CLK_DIV3]	    = &meson8b_cpu_clk_div3.hw,
@@ -3339,8 +3418,11 @@ static struct clk_hw *meson8m2_hw_clks[] = {
 	[CLKID_NAND_SEL]	    = &meson8b_nand_clk_sel.hw,
 	[CLKID_NAND_DIV]	    = &meson8b_nand_clk_div.hw,
 	[CLKID_NAND_CLK]	    = &meson8b_nand_clk.hw,
+	[CLKID_PLL_FIXED_PREDIV]    = &meson8b_fixed_prediv.hw,
 	[CLKID_PLL_FIXED_DCO]	    = &meson8b_fixed_pll_dco.hw,
+	[CLKID_HDMI_PREDIV]	    = &meson8b_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]	    = &meson8b_hdmi_pll_dco.hw,
+	[CLKID_PLL_SYS_PREDIV]	    = &meson8b_sys_prediv.hw,
 	[CLKID_PLL_SYS_DCO]	    = &meson8b_sys_pll_dco.hw,
 	[CLKID_CPU_CLK_DIV2]	    = &meson8b_cpu_clk_div2.hw,
 	[CLKID_CPU_CLK_DIV3]	    = &meson8b_cpu_clk_div3.hw,
@@ -3410,6 +3492,7 @@ static struct clk_hw *meson8m2_hw_clks[] = {
 	[CLKID_MALI_1_DIV]	    = &meson8b_mali_1_div.hw,
 	[CLKID_MALI_1]		    = &meson8b_mali_1.hw,
 	[CLKID_MALI]		    = &meson8b_mali.hw,
+	[CLKID_GP_PREDIV]	    = &meson8m2_gp_prediv.hw,
 	[CLKID_GP_PLL_DCO]	    = &meson8m2_gp_pll_dco.hw,
 	[CLKID_GP_PLL]		    = &meson8m2_gp_pll.hw,
 	[CLKID_VPU_0_SEL]	    = &meson8m2_vpu_0_sel.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 10/13] clk: meson: s4: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (8 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 09/13] clk: meson: meson8: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 11/13] clk: meson: s7: " Jian Hu via B4 Relay
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/s4-pll.c | 130 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 102 insertions(+), 28 deletions(-)

diff --git a/drivers/clk/meson/s4-pll.c b/drivers/clk/meson/s4-pll.c
index 56ce6f566e53..52c1836a53d3 100644
--- a/drivers/clk/meson/s4-pll.c
+++ b/drivers/clk/meson/s4-pll.c
@@ -51,6 +51,29 @@
  * Meanwhile, these clock won't ever change at runtime.
  * For the above reasons, we can only use ro_ops for fixed PLL related clocks.
  */
+static struct clk_regmap s4_fixed_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_FIXPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 */
+		.flags = CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "fixed_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = (const struct clk_parent_data []) {
+			{ .fw_name = "xtal", }
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap s4_fixed_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -68,11 +91,6 @@ static struct clk_regmap s4_fixed_pll_dco = {
 			.shift   = 0,
 			.width   = 17,
 		},
-		.n = {
-			.reg_off = ANACTRL_FIXPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_FIXPLL_CTRL0,
 			.shift   = 31,
@@ -87,8 +105,8 @@ static struct clk_regmap s4_fixed_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "fixed_pll_dco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = (const struct clk_parent_data []) {
-			{ .fw_name = "xtal", }
+		.parent_hws = (const struct clk_hw *[]) {
+			&s4_fixed_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -273,6 +291,34 @@ static struct clk_regmap s4_fclk_div2p5 = {
 	},
 };
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table s4_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap s4_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_GP0PLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= s4_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = (const struct clk_parent_data []) {
+			{ .fw_name = "xtal", }
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_mult_range s4_gp0_pll_mult_range = {
 	.min = 125,
 	.max = 250,
@@ -302,11 +348,6 @@ static struct clk_regmap s4_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_GP0PLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_GP0PLL_CTRL0,
 			.shift   = 31,
@@ -324,10 +365,11 @@ static struct clk_regmap s4_gp0_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = (const struct clk_parent_data []) {
-			{ .fw_name = "xtal", }
+		.parent_hws = (const struct clk_hw *[]) {
+			&s4_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -350,6 +392,24 @@ static struct clk_regmap s4_gp0_pll = {
 	},
 };
 
+static struct clk_regmap s4_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_HIFIPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= s4_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = (const struct clk_parent_data []) {
+			{ .fw_name = "xtal", }
+		},
+		.num_parents = 1,
+	},
+};
+
 /*
  * Internal hifi pll emulation configuration parameters
  */
@@ -373,11 +433,6 @@ static struct clk_regmap s4_hifi_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_HIFIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = ANACTRL_HIFIPLL_CTRL1,
 			.shift   = 0,
@@ -402,10 +457,11 @@ static struct clk_regmap s4_hifi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = (const struct clk_parent_data []) {
-			{ .fw_name = "xtal", }
+		.parent_hws = (const struct clk_hw *[]) {
+			&s4_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -428,6 +484,24 @@ static struct clk_regmap s4_hifi_pll = {
 	},
 };
 
+static struct clk_regmap s4_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = ANACTRL_HDMIPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= s4_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data){
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = (const struct clk_parent_data []) {
+			{ .fw_name = "xtal", }
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap s4_hdmi_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -440,11 +514,6 @@ static struct clk_regmap s4_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = ANACTRL_HDMIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = ANACTRL_HDMIPLL_CTRL0,
 			.shift   = 31,
@@ -460,10 +529,11 @@ static struct clk_regmap s4_hdmi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hdmi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = (const struct clk_parent_data []) {
-			{ .fw_name = "xtal", }
+		.parent_hws = (const struct clk_hw *[]) {
+			&s4_hdmi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -760,6 +830,7 @@ static struct clk_regmap s4_mpll3 = {
 
 /* Array of all clocks provided by this provider */
 static struct clk_hw *s4_pll_hw_clks[] = {
+	[CLKID_FIXED_PREDIV]		= &s4_fixed_prediv.hw,
 	[CLKID_FIXED_PLL_DCO]		= &s4_fixed_pll_dco.hw,
 	[CLKID_FIXED_PLL]		= &s4_fixed_pll.hw,
 	[CLKID_FCLK_DIV2_DIV]		= &s4_fclk_div2_div.hw,
@@ -774,10 +845,13 @@ static struct clk_hw *s4_pll_hw_clks[] = {
 	[CLKID_FCLK_DIV7]		= &s4_fclk_div7.hw,
 	[CLKID_FCLK_DIV2P5_DIV]		= &s4_fclk_div2p5_div.hw,
 	[CLKID_FCLK_DIV2P5]		= &s4_fclk_div2p5.hw,
+	[CLKID_GP0_PREDIV]		= &s4_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &s4_gp0_pll_dco.hw,
 	[CLKID_GP0_PLL]			= &s4_gp0_pll.hw,
+	[CLKID_HIFI_PREDIV]		= &s4_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &s4_hifi_pll_dco.hw,
 	[CLKID_HIFI_PLL]		= &s4_hifi_pll.hw,
+	[CLKID_HDMI_PREDIV]		= &s4_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]		= &s4_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]		= &s4_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL]		= &s4_hdmi_pll.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 11/13] clk: meson: s7: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (9 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 10/13] clk: meson: s4: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 12/13] clk: meson: t7: " Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/s7-pll.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/meson/s7-pll.c b/drivers/clk/meson/s7-pll.c
index 5b115c3ff35e..0387c25082ac 100644
--- a/drivers/clk/meson/s7-pll.c
+++ b/drivers/clk/meson/s7-pll.c
@@ -38,6 +38,29 @@
 #define HDMIPLL_CTRL3			0x1cc
 #define HDMIPLL_STS			0x1dc
 
+static struct clk_regmap s7_fixed_pll_prediv = {
+	.data = &(struct clk_regmap_div_data) {
+		.offset = FIXPLL_CTRL0,
+		.shift	= 11,
+		.width	= 5,
+		/*
+		 * CLK_DIVIDER_ONE_BASED: the register value is the divisor
+		 * itself, so a value of 1 gives a divisor of 1 and the PLL
+		 * input is not divided. The hardware keeps this pre-divider
+		 * at 1, which minimizes the PLL jitter.
+		 */
+		.flags	= CLK_DIVIDER_ONE_BASED,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "fixed_pll_prediv",
+		.ops = &clk_regmap_divider_ro_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "fix",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap s7_fixed_pll_vco = {
 	.data = &(struct meson_clk_pll_data) {
 		.en = {
@@ -50,11 +73,6 @@ static struct clk_regmap s7_fixed_pll_vco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = FIXPLL_CTRL0,
-			.shift   = 11,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = FIXPLL_STS,
 			.shift   = 31,
@@ -69,8 +87,8 @@ static struct clk_regmap s7_fixed_pll_vco = {
 	.hw.init = &(struct clk_init_data) {
 		.name = "fixed_pll_vco",
 		.ops = &meson_clk_pll_ro_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "fix",
+		.parent_hws = (const struct clk_hw *[]) {
+			&s7_fixed_pll_prediv.hw
 		},
 		.num_parents = 1,
 	},
@@ -631,6 +649,7 @@ static struct clk_regmap s7_hdmi_pll_pix = {
 };
 
 static struct clk_hw *s7_pll_hws[] = {
+	[CLKID_FIXED_PLL_PREDIV]	= &s7_fixed_pll_prediv.hw,
 	[CLKID_FIXED_PLL_VCO]		= &s7_fixed_pll_vco.hw,
 	[CLKID_FIXED_PLL]		= &s7_fixed_pll.hw,
 	[CLKID_FCLK_DIV2_DIV]		= &s7_fclk_div2_div.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 12/13] clk: meson: t7: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (10 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 11/13] clk: meson: s7: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  2026-12-01  8:56 ` [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The pre-divider is currently described by a dedicated n parameter,
although it is a plain divider between the input clock and the DCO.

Model it as a regular divider clock and make it the parent of the DCO.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/t7-pll.c | 192 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 150 insertions(+), 42 deletions(-)

diff --git a/drivers/clk/meson/t7-pll.c b/drivers/clk/meson/t7-pll.c
index 0a622f45fa36..fb20e9e5f991 100644
--- a/drivers/clk/meson/t7-pll.c
+++ b/drivers/clk/meson/t7-pll.c
@@ -71,6 +71,34 @@
 #define MCLK_PLL_CNTL4		0x10
 #define MCLK_PLL_STS		0x14
 
+/* Force the pre-divider at 1 to minimize PLL jitter */
+static const struct clk_div_table t7_pll_prediv_div_table[] = {
+	{ .val = 1, .div = 1 },
+	{ /* sentinel */ }
+};
+
+static struct clk_regmap t7_gp0_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = GP0PLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		/*
+		 * CLK_DIVIDER_INVALID_ZERO to report 0 Hz during registration.
+		 * The same applies below.
+		 */
+		.flags = CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "gp0_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct pll_mult_range t7_media_pll_mult_range = {
 	.min = 125,
 	.max = 250,
@@ -97,11 +125,6 @@ static struct clk_regmap t7_gp0_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = GP0PLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = GP0PLL_STS,
 			.shift   = 31,
@@ -119,10 +142,11 @@ static struct clk_regmap t7_gp0_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp0_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "in0",
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_gp0_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -144,6 +168,24 @@ static struct clk_regmap t7_gp0_pll = {
 	},
 };
 
+static struct clk_regmap t7_gp1_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = GP1PLL_CTRL0,
+		.shift	= 16,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "gp1_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+	},
+};
+
 /*
  * Compared with GP0 PLL, GP1 PLL is a newly designed PLL with
  * a DCO range of 1.6GHz to 3.2GHz.
@@ -171,11 +213,6 @@ static struct clk_regmap t7_gp1_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = GP1PLL_CTRL0,
-			.shift   = 16,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = GP1PLL_STS,
 			.shift   = 31,
@@ -193,10 +230,11 @@ static struct clk_regmap t7_gp1_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "gp1_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "in0",
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_gp1_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -218,6 +256,24 @@ static struct clk_regmap t7_gp1_pll = {
 	},
 };
 
+static struct clk_regmap t7_hifi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HIFIPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "hifi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence t7_hifi_init_regs[] = {
 	{ .reg = HIFIPLL_CTRL1, .def = 0x00000000 },
 	{ .reg = HIFIPLL_CTRL2, .def = 0x00000000 },
@@ -239,11 +295,6 @@ static struct clk_regmap t7_hifi_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = HIFIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.frac = {
 			.reg_off = HIFIPLL_CTRL1,
 			.shift   = 0,
@@ -267,10 +318,11 @@ static struct clk_regmap t7_hifi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hifi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "in0",
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_hifi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -292,6 +344,32 @@ static struct clk_regmap t7_hifi_pll = {
 	},
 };
 
+static struct clk_regmap t7_pcie_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = PCIEPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "pcie_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+		/*
+		 * The PCIe prediv register reads zero on power-on.
+		 * CLK_DIVIDER_INVALID_ZERO makes the first rate return 0 Hz,
+		 * which gets cached by CCF. The PCIe PLL enable callback
+		 * later writes a valid non-zero divider value. Use
+		 * CLK_GET_RATE_NOCACHE to avoid stale cached rate.
+		 */
+		.flags = CLK_GET_RATE_NOCACHE,
+	},
+};
+
 /*
  * The T7 PCIE PLL is fined tuned to deliver a very precise
  * 100MHz reference clock for the PCIe Analog PHY, and thus requires
@@ -324,11 +402,6 @@ static struct clk_regmap t7_pcie_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = PCIEPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = PCIEPLL_CTRL0,
 			.shift   = 31,
@@ -345,10 +418,11 @@ static struct clk_regmap t7_pcie_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "pcie_pll_dco",
 		.ops = &meson_clk_pcie_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "in0",
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_pcie_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -624,6 +698,24 @@ static struct clk_regmap t7_mpll3 = {
 	},
 };
 
+static struct clk_regmap t7_hdmi_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = HDMIPLL_CTRL0,
+		.shift	= 10,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "hdmi_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+	},
+};
+
 static const struct reg_sequence t7_hdmi_init_regs[] = {
 	{ .reg = HDMIPLL_CTRL1, .def = 0x00000000 },
 	{ .reg = HDMIPLL_CTRL2, .def = 0x00000000 },
@@ -645,11 +737,6 @@ static struct clk_regmap t7_hdmi_pll_dco = {
 			.shift   = 0,
 			.width   = 9,
 		},
-		.n = {
-			.reg_off = HDMIPLL_CTRL0,
-			.shift   = 10,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = HDMIPLL_CTRL0,
 			.shift   = 31,
@@ -667,10 +754,11 @@ static struct clk_regmap t7_hdmi_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "hdmi_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = (const struct clk_parent_data []) {
-			{ .fw_name = "in0", }
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_hdmi_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -722,6 +810,24 @@ static const struct reg_sequence t7_mclk_init_regs[] = {
 	{ .reg = MCLK_PLL_CNTL4, .def = 0x00180303 },
 };
 
+static struct clk_regmap t7_mclk_prediv = {
+	.data = &(struct clk_regmap_div_data){
+		.offset = MCLK_PLL_CNTL0,
+		.shift	= 16,
+		.width	= 5,
+		.table	= t7_pll_prediv_div_table,
+		.flags	= CLK_DIVIDER_INVALID_ZERO,
+	},
+	.hw.init = &(struct clk_init_data) {
+		.name = "mclk_prediv",
+		.ops = &clk_regmap_divider_ops,
+		.parent_data = &(const struct clk_parent_data) {
+			.fw_name = "in0",
+		},
+		.num_parents = 1,
+	},
+};
+
 static struct clk_regmap t7_mclk_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
 		.en = {
@@ -734,11 +840,6 @@ static struct clk_regmap t7_mclk_pll_dco = {
 			.shift   = 0,
 			.width   = 8,
 		},
-		.n = {
-			.reg_off = MCLK_PLL_CNTL0,
-			.shift   = 16,
-			.width   = 5,
-		},
 		.l = {
 			.reg_off = MCLK_PLL_CNTL0,
 			.shift   = 31,
@@ -761,10 +862,11 @@ static struct clk_regmap t7_mclk_pll_dco = {
 	.hw.init = &(struct clk_init_data){
 		.name = "mclk_pll_dco",
 		.ops = &meson_clk_pll_ops,
-		.parent_data = &(const struct clk_parent_data) {
-			.fw_name = "in0",
+		.parent_hws = (const struct clk_hw *[]) {
+			&t7_mclk_prediv.hw
 		},
 		.num_parents = 1,
+		.flags = CLK_SET_RATE_PARENT,
 	},
 };
 
@@ -939,21 +1041,25 @@ static struct clk_regmap t7_mclk_1 = {
 };
 
 static struct clk_hw *t7_gp0_hw_clks[] = {
+	[CLKID_GP0_PREDIV]		= &t7_gp0_prediv.hw,
 	[CLKID_GP0_PLL_DCO]		= &t7_gp0_pll_dco.hw,
 	[CLKID_GP0_PLL]			= &t7_gp0_pll.hw,
 };
 
 static struct clk_hw *t7_gp1_hw_clks[] = {
+	[CLKID_GP1_PREDIV]		= &t7_gp1_prediv.hw,
 	[CLKID_GP1_PLL_DCO]		= &t7_gp1_pll_dco.hw,
 	[CLKID_GP1_PLL]			= &t7_gp1_pll.hw,
 };
 
 static struct clk_hw *t7_hifi_hw_clks[] = {
+	[CLKID_HIFI_PREDIV]		= &t7_hifi_prediv.hw,
 	[CLKID_HIFI_PLL_DCO]		= &t7_hifi_pll_dco.hw,
 	[CLKID_HIFI_PLL]		= &t7_hifi_pll.hw,
 };
 
 static struct clk_hw *t7_pcie_hw_clks[] = {
+	[CLKID_PCIE_PREDIV]		= &t7_pcie_prediv.hw,
 	[CLKID_PCIE_PLL_DCO]		= &t7_pcie_pll_dco.hw,
 	[CLKID_PCIE_PLL_DCO_DIV2]	= &t7_pcie_pll_dco_div2.hw,
 	[CLKID_PCIE_PLL_OD]		= &t7_pcie_pll_od.hw,
@@ -973,12 +1079,14 @@ static struct clk_hw *t7_mpll_hw_clks[] = {
 };
 
 static struct clk_hw *t7_hdmi_hw_clks[] = {
+	[CLKID_HDMI_PREDIV]		= &t7_hdmi_prediv.hw,
 	[CLKID_HDMI_PLL_DCO]		= &t7_hdmi_pll_dco.hw,
 	[CLKID_HDMI_PLL_OD]		= &t7_hdmi_pll_od.hw,
 	[CLKID_HDMI_PLL]		= &t7_hdmi_pll.hw,
 };
 
 static struct clk_hw *t7_mclk_hw_clks[] = {
+	[CLKID_MCLK_PREDIV]		= &t7_mclk_prediv.hw,
 	[CLKID_MCLK_PLL_DCO]		= &t7_mclk_pll_dco.hw,
 	[CLKID_MCLK_PRE]		= &t7_mclk_pre_od.hw,
 	[CLKID_MCLK_PLL]		= &t7_mclk_pll.hw,

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter
  2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
                   ` (11 preceding siblings ...)
  2026-12-01  8:56 ` [PATCH RFC RFT v3 12/13] clk: meson: t7: " Jian Hu via B4 Relay
@ 2026-12-01  8:56 ` Jian Hu via B4 Relay
  12 siblings, 0 replies; 18+ messages in thread
From: Jian Hu via B4 Relay @ 2026-12-01  8:56 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Neil Armstrong,
	Jerome Brunet, Kevin Hilman, Martin Blumenstingl, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Carlo Caione, linux-clk, linux-kernel, linux-amlogic,
	linux-arm-kernel, devicetree, Jian Hu

From: Jian Hu <jian.hu@amlogic.com>

The Meson PLL framework models the PLL pre-divider (N) using a dedicated
field in struct meson_clk_pll_data. Since the common clock framework
already provides a generic divider implementation, there is no need to
keep PLL-specific support for it.

Remove the dedicated n parameter from the framework and simplify the PLL
rate calculation accordingly.

The parent rate is now negotiated on every rate request: the middle of the
multiplier range is tried first, then the boundary the computed multiplier
overflowed, and the request is rejected if the multiplier still does not fit.

The PLL tables are arrays of struct pll_params_table entries, which only
carry a multiplier now that the pre-divider is gone. Replace them with
0-terminated arrays of unsigned int.

Signed-off-by: Jian Hu <jian.hu@amlogic.com>
---
 drivers/clk/meson/axg.c     |  10 +-
 drivers/clk/meson/clk-pll.c | 241 +++++++++++++++++++++++++-------------------
 drivers/clk/meson/clk-pll.h |  14 +--
 drivers/clk/meson/g12a.c    |   7 +-
 drivers/clk/meson/meson8b.c |  58 ++---------
 5 files changed, 150 insertions(+), 180 deletions(-)

diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c
index 8c5a2640324c..55c0f4ffb075 100644
--- a/drivers/clk/meson/axg.c
+++ b/drivers/clk/meson/axg.c
@@ -838,13 +838,7 @@ static struct clk_regmap axg_pcie_prediv = {
 	},
 };
 
-static const struct pll_params_table axg_pcie_pll_params_table[] = {
-	{
-		.m = 200,
-		.n = 3,
-	},
-	{ /* sentinel */ },
-};
+static const unsigned int axg_pcie_pll_mult_table[] = { 200, 0 };
 
 static const struct reg_sequence axg_pcie_pll_init_regs[] = {
 	{ .reg = HHI_PCIE_PLL_CNTL1,	.def = 0x0084a2aa },
@@ -883,7 +877,7 @@ static struct clk_regmap axg_pcie_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = axg_pcie_pll_params_table,
+		.table = axg_pcie_pll_mult_table,
 		.init_regs = axg_pcie_pll_init_regs,
 		.init_count = ARRAY_SIZE(axg_pcie_pll_init_regs),
 	},
diff --git a/drivers/clk/meson/clk-pll.c b/drivers/clk/meson/clk-pll.c
index 29b5222983df..cbe1da6fe636 100644
--- a/drivers/clk/meson/clk-pll.c
+++ b/drivers/clk/meson/clk-pll.c
@@ -14,7 +14,7 @@
  *        +--------------------------------+
  *        |                                |
  *        |             +--+               |
- *  in >>-----[ /N ]--->|  |      +-----+  |
+ *  in >>-------------->|  |      +-----+  |
  *        |             |  |------| DCO |---->> out
  *        |  +--------->|  |      +--v--+  |
  *        |  |          +--+         |     |
@@ -23,7 +23,7 @@
  *        |                                |
  *        +--------------------------------+
  *
- * out = in * (m + frac / frac_max) / n
+ * out = in * (m + frac / frac_max)
  */
 
 #include <linux/clk-provider.h>
@@ -31,6 +31,7 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/math64.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 
 #include "clk-regmap.h"
@@ -52,8 +53,7 @@ static int __pll_round_closest_mult(struct meson_clk_pll_data *pll)
 }
 
 static unsigned long __pll_params_to_rate(unsigned long parent_rate,
-					  unsigned int m, unsigned int n,
-					  unsigned int frac,
+					  unsigned int m, unsigned int frac,
 					  struct meson_clk_pll_data *pll)
 {
 	u64 rate = (u64)parent_rate * m;
@@ -66,7 +66,7 @@ static unsigned long __pll_params_to_rate(unsigned long parent_rate,
 		rate += DIV_ROUND_UP_ULL(frac_rate, frac_max);
 	}
 
-	return DIV_ROUND_UP_ULL(rate, n);
+	return rate;
 }
 
 static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
@@ -74,19 +74,7 @@ static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-	unsigned int m, n, frac;
-
-	n = MESON_PARM_APPLICABLE(&pll->n) ?
-		meson_parm_read(clk->map, &pll->n) :
-		1;
-
-	/*
-	 * On some HW, N is set to zero on init. This value is invalid as
-	 * it would result in a division by zero. The rate can't be
-	 * calculated in this case
-	 */
-	if (n == 0)
-		return 0;
+	unsigned int m, frac;
 
 	m = meson_parm_read(clk->map, &pll->m);
 
@@ -94,21 +82,20 @@ static unsigned long meson_clk_pll_recalc_rate(struct clk_hw *hw,
 		meson_parm_read(clk->map, &pll->frac) :
 		0;
 
-	return __pll_params_to_rate(parent_rate, m, n, frac, pll);
+	return __pll_params_to_rate(parent_rate, m, frac, pll);
 }
 
 static unsigned int __pll_params_with_frac(unsigned long rate,
 					   unsigned long parent_rate,
 					   unsigned int m,
-					   unsigned int n,
 					   struct meson_clk_pll_data *pll)
 {
 	unsigned int frac_max = pll->frac_max ? pll->frac_max :
 						(1 << pll->frac.width);
-	u64 val = (u64)rate * n;
+	u64 val = (u64)rate;
 
 	/* Bail out if we are already over the requested rate */
-	if (rate < parent_rate * m / n)
+	if (rate < parent_rate * m)
 		return 0;
 
 	if (pll->flags & CLK_MESON_PLL_ROUND_CLOSEST)
@@ -139,58 +126,77 @@ static bool meson_clk_pll_is_better(unsigned long rate,
 	return false;
 }
 
-static int meson_clk_get_pll_table_index(unsigned int index,
-					 unsigned int *m,
-					 unsigned int *n,
-					 struct meson_clk_pll_data *pll)
+static unsigned int meson_clk_pll_min_mult(struct meson_clk_pll_data *pll)
 {
-	if (!pll->table[index].n)
-		return -EINVAL;
+	unsigned int i, min_mult = UINT_MAX;
 
-	*m = pll->table[index].m;
-	*n = pll->table[index].n;
+	if (pll->range)
+		return pll->range->min;
 
-	return 0;
+	for (i = 0; pll->table && pll->table[i]; i++)
+		min_mult = min(min_mult, pll->table[i]);
+
+	return min_mult == UINT_MAX ? 0 : min_mult;
 }
 
-static unsigned int meson_clk_get_pll_range_m(unsigned long rate,
-					      unsigned long parent_rate,
-					      unsigned int n,
-					      struct meson_clk_pll_data *pll)
+static unsigned int meson_clk_pll_max_mult(struct meson_clk_pll_data *pll)
 {
-	u64 val = (u64)rate * n;
+	unsigned int i, max_mult = 0;
+
+	if (pll->range)
+		return pll->range->max;
+
+	for (i = 0; pll->table && pll->table[i]; i++)
+		max_mult = max(max_mult, pll->table[i]);
+
+	return max_mult;
+}
 
+static unsigned int meson_clk_pll_rate_to_mult(unsigned long rate,
+					       unsigned long parent_rate,
+					       struct meson_clk_pll_data *pll)
+{
 	if (__pll_round_closest_mult(pll))
-		return DIV_ROUND_CLOSEST_ULL(val, parent_rate);
+		return DIV_ROUND_CLOSEST_ULL(rate, parent_rate);
 
-	return div_u64(val,  parent_rate);
+	return div_u64(rate, parent_rate);
 }
 
-static int meson_clk_get_pll_range_index(unsigned long rate,
-					 unsigned long parent_rate,
-					 unsigned int index,
+/* m_hint must be non-zero */
+static int meson_clk_get_pll_parent_rate(struct clk_rate_request *req,
+					 unsigned int m_hint,
+					 unsigned long *parent_rate,
 					 unsigned int *m,
-					 unsigned int *n,
 					 struct meson_clk_pll_data *pll)
 {
-	*n = index + 1;
+	unsigned long pr;
 
-	/* Check the predivider range */
-	if (*n >= (MESON_PARM_APPLICABLE(&pll->n) ? 1 << pll->n.width : 2))
+	pr = clk_hw_round_rate(req->best_parent_hw,
+			       DIV_ROUND_UP_ULL(req->rate, m_hint));
+	if (!pr)
 		return -EINVAL;
 
-	if (*n == 1) {
-		/* Get the boundaries out the way */
-		if (rate <= pll->range->min * parent_rate) {
-			*m = pll->range->min;
-			return -ENODATA;
-		} else if (rate >= pll->range->max * parent_rate) {
-			*m = pll->range->max;
-			return -ENODATA;
-		}
+	*parent_rate = pr;
+	*m = meson_clk_pll_rate_to_mult(req->rate, pr, pll);
+
+	return 0;
+}
+
+static int meson_clk_get_pll_range(unsigned long rate,
+				   unsigned long parent_rate,
+				   unsigned int *m,
+				   struct meson_clk_pll_data *pll)
+{
+	/* Get the boundaries out the way */
+	if (rate <= pll->range->min * parent_rate) {
+		*m = pll->range->min;
+		return -ENODATA;
+	} else if (rate >= pll->range->max * parent_rate) {
+		*m = pll->range->max;
+		return -ENODATA;
 	}
 
-	*m = meson_clk_get_pll_range_m(rate, parent_rate, *n, pll);
+	*m = meson_clk_pll_rate_to_mult(rate, parent_rate, pll);
 
 	/* the pre-divider gives a multiplier too big - stop */
 	if (*m >= (1 << pll->m.width))
@@ -199,50 +205,42 @@ static int meson_clk_get_pll_range_index(unsigned long rate,
 	return 0;
 }
 
-static int meson_clk_get_pll_get_index(unsigned long rate,
-				       unsigned long parent_rate,
-				       unsigned int index,
-				       unsigned int *m,
-				       unsigned int *n,
-				       struct meson_clk_pll_data *pll)
-{
-	if (pll->range)
-		return meson_clk_get_pll_range_index(rate, parent_rate,
-						     index, m, n, pll);
-	else if (pll->table)
-		return meson_clk_get_pll_table_index(index, m, n, pll);
-
-	return -EINVAL;
-}
-
-static int meson_clk_get_pll_settings(unsigned long rate,
-				      unsigned long parent_rate,
-				      unsigned int *best_m,
-				      unsigned int *best_n,
-				      struct meson_clk_pll_data *pll)
+static int meson_clk_get_pll_table(unsigned long rate,
+				   unsigned long parent_rate,
+				   unsigned int *m,
+				   struct meson_clk_pll_data *pll)
 {
-	unsigned long best = 0, now = 0;
-	unsigned int i, m, n;
-	int ret;
+	unsigned long now, best = 0;
+	unsigned int i;
+	int ret = -EINVAL;
 
-	for (i = 0, ret = 0; !ret; i++) {
-		ret = meson_clk_get_pll_get_index(rate, parent_rate,
-						  i, &m, &n, pll);
-		if (ret == -EINVAL)
-			break;
+	for (i = 0; pll->table[i]; i++) {
+		now = (unsigned long)pll->table[i] * parent_rate;
 
-		now = __pll_params_to_rate(parent_rate, m, n, 0, pll);
 		if (meson_clk_pll_is_better(rate, best, now, pll)) {
 			best = now;
-			*best_m = m;
-			*best_n = n;
-
-			if (now == rate)
-				break;
+			*m = pll->table[i];
+			ret = 0;
 		}
+
+		if (now == rate)
+			break;
 	}
 
-	return best ? 0 : -EINVAL;
+	return ret;
+}
+
+static int meson_clk_get_pll_mult(unsigned long rate,
+				  unsigned long parent_rate,
+				  unsigned int *m,
+				  struct meson_clk_pll_data *pll)
+{
+	if (pll->range)
+		return meson_clk_get_pll_range(rate, parent_rate, m, pll);
+	else if (pll->table)
+		return meson_clk_get_pll_table(rate, parent_rate, m, pll);
+
+	return -EINVAL;
 }
 
 static int meson_clk_pll_determine_rate(struct clk_hw *hw,
@@ -250,16 +248,53 @@ static int meson_clk_pll_determine_rate(struct clk_hw *hw,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-	unsigned int m, n, frac;
-	unsigned long round;
+	unsigned int m, m_min, m_max, frac;
+	unsigned long parent_rate, round;
 	int ret;
 
-	ret = meson_clk_get_pll_settings(req->rate, req->best_parent_rate,
-					 &m, &n, pll);
+	if (!req->best_parent_hw)
+		return -EINVAL;
+
+	m_min = meson_clk_pll_min_mult(pll);
+	m_max = meson_clk_pll_max_mult(pll);
+	if (!m_min || !m_max)
+		return -EINVAL;
+
+	/*
+	 * The pre-divider is a regular clock now, so the parent rate must be
+	 * negotiated. Aim for the middle of the multiplier range first, so a
+	 * divider parent, which can only round down, still leaves the
+	 * multiplier within [m_min, m_max].
+	 */
+	ret = meson_clk_get_pll_parent_rate(req,
+					    DIV_ROUND_UP(m_min + m_max, 2),
+					    &parent_rate, &m, pll);
 	if (ret)
 		return ret;
 
-	round = __pll_params_to_rate(req->best_parent_rate, m, n, 0, pll);
+	/* Parent rounded too far: retry from the other end of the range */
+	if (m > m_max)
+		ret = meson_clk_get_pll_parent_rate(req, m_min, &parent_rate,
+						    &m, pll);
+	else if (!m || m < m_min)
+		ret = meson_clk_get_pll_parent_rate(req, m_max, &parent_rate,
+						    &m, pll);
+	if (ret)
+		return ret;
+
+	if (!m || m < m_min || m > m_max)
+		return -EINVAL;
+
+	/*
+	 * -ENODATA only means the multiplier was clamped to one of the range
+	 * boundaries, which is a usable setting.
+	 */
+	ret = meson_clk_get_pll_mult(req->rate, parent_rate, &m, pll);
+	if (ret && ret != -ENODATA)
+		return ret;
+
+	req->best_parent_rate = parent_rate;
+	round = __pll_params_to_rate(parent_rate, m, 0, pll);
 
 	if (!MESON_PARM_APPLICABLE(&pll->frac) || req->rate == round) {
 		req->rate = round;
@@ -270,8 +305,8 @@ static int meson_clk_pll_determine_rate(struct clk_hw *hw,
 	 * The rate provided by the setting is not an exact match, let's
 	 * try to improve the result using the fractional parameter
 	 */
-	frac = __pll_params_with_frac(req->rate, req->best_parent_rate, m, n, pll);
-	req->rate = __pll_params_to_rate(req->best_parent_rate, m, n, frac, pll);
+	frac = __pll_params_with_frac(req->rate, parent_rate, m, pll);
+	req->rate = __pll_params_to_rate(parent_rate, m, frac, pll);
 
 	return 0;
 }
@@ -440,7 +475,7 @@ static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_clk_pll_data *pll = meson_clk_pll_data(clk);
-	unsigned int enabled, m, n, frac = 0;
+	unsigned int enabled, m, frac = 0;
 	unsigned long old_rate;
 	int ret;
 
@@ -449,20 +484,18 @@ static int meson_clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 
 	old_rate = clk_hw_get_rate(hw);
 
-	ret = meson_clk_get_pll_settings(rate, parent_rate, &m, &n, pll);
-	if (ret)
+	ret = meson_clk_get_pll_mult(rate, parent_rate, &m, pll);
+	if (ret && ret != -ENODATA)
 		return ret;
 
 	enabled = meson_parm_read(clk->map, &pll->en);
 	if (enabled)
 		meson_clk_pll_disable(hw);
 
-	if (MESON_PARM_APPLICABLE(&pll->n))
-		meson_parm_write(clk->map, &pll->n, n);
 	meson_parm_write(clk->map, &pll->m, m);
 
 	if (MESON_PARM_APPLICABLE(&pll->frac)) {
-		frac = __pll_params_with_frac(rate, parent_rate, m, n, pll);
+		frac = __pll_params_with_frac(rate, parent_rate, m, pll);
 		meson_parm_write(clk->map, &pll->frac, frac);
 	}
 
diff --git a/drivers/clk/meson/clk-pll.h b/drivers/clk/meson/clk-pll.h
index 8384b75ae38d..1100bd795056 100644
--- a/drivers/clk/meson/clk-pll.h
+++ b/drivers/clk/meson/clk-pll.h
@@ -11,22 +11,11 @@
 #include <linux/regmap.h>
 #include "parm.h"
 
-struct pll_params_table {
-	unsigned int	m;
-	unsigned int	n;
-};
-
 struct pll_mult_range {
 	unsigned int	min;
 	unsigned int	max;
 };
 
-#define PLL_PARAMS(_m, _n)						\
-	{								\
-		.m		= (_m),					\
-		.n		= (_n),					\
-	}
-
 #define CLK_MESON_PLL_ROUND_CLOSEST	BIT(0)
 #define CLK_MESON_PLL_NOINIT_ENABLED	BIT(1)
 #define CLK_MESON_PLL_RST_ACTIVE_LOW	BIT(2)
@@ -34,7 +23,6 @@ struct pll_mult_range {
 struct meson_clk_pll_data {
 	struct parm en;
 	struct parm m;
-	struct parm n;
 	struct parm frac;
 	struct parm l;
 	struct parm rst;
@@ -42,7 +30,7 @@ struct meson_clk_pll_data {
 	struct parm l_detect;
 	const struct reg_sequence *init_regs;
 	unsigned int init_count;
-	const struct pll_params_table *table;
+	const unsigned int *table;
 	const struct pll_mult_range *range;
 	unsigned int frac_max;
 	u8 flags;
diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c
index 09eb842e0b1a..c121c6f52ae1 100644
--- a/drivers/clk/meson/g12a.c
+++ b/drivers/clk/meson/g12a.c
@@ -751,10 +751,7 @@ static const struct reg_sequence g12a_pcie_pll_init_regs[] = {
 };
 
 /* Keep a single entry table for recalc/round_rate() ops */
-static const struct pll_params_table g12a_pcie_pll_table[] = {
-	PLL_PARAMS(150, 1),
-	{0, 0},
-};
+static const unsigned int g12a_pcie_pll_mult_table[] = { 150, 0 };
 
 static struct clk_regmap g12a_pcie_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
@@ -783,7 +780,7 @@ static struct clk_regmap g12a_pcie_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = g12a_pcie_pll_table,
+		.table = g12a_pcie_pll_mult_table,
 		.init_regs = g12a_pcie_pll_init_regs,
 		.init_count = ARRAY_SIZE(g12a_pcie_pll_init_regs),
 	},
diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
index ae2bab501597..9a165c8cd5b3 100644
--- a/drivers/clk/meson/meson8b.c
+++ b/drivers/clk/meson/meson8b.c
@@ -95,29 +95,8 @@ struct meson8b_clk_reset {
 	struct regmap *regmap;
 };
 
-static const struct pll_params_table sys_pll_params_table[] = {
-	PLL_PARAMS(50, 1),
-	PLL_PARAMS(51, 1),
-	PLL_PARAMS(52, 1),
-	PLL_PARAMS(53, 1),
-	PLL_PARAMS(54, 1),
-	PLL_PARAMS(55, 1),
-	PLL_PARAMS(56, 1),
-	PLL_PARAMS(57, 1),
-	PLL_PARAMS(58, 1),
-	PLL_PARAMS(59, 1),
-	PLL_PARAMS(60, 1),
-	PLL_PARAMS(61, 1),
-	PLL_PARAMS(62, 1),
-	PLL_PARAMS(63, 1),
-	PLL_PARAMS(64, 1),
-	PLL_PARAMS(65, 1),
-	PLL_PARAMS(66, 1),
-	PLL_PARAMS(67, 1),
-	PLL_PARAMS(68, 1),
-	PLL_PARAMS(84, 1),
-	{ /* sentinel */ },
-};
+static const unsigned int sys_pll_mult_table[] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
+						   61, 62, 63, 64, 65, 66, 67, 68, 84, 0 };
 
 static struct clk_regmap meson8b_fixed_prediv = {
 	.data = &(struct clk_regmap_div_data){
@@ -257,26 +236,8 @@ static const struct reg_sequence meson8b_hdmi_pll_init_regs[] = {
 	{ .reg = HHI_VID2_PLL_CNTL2,	.def = 0x0430a800 },
 };
 
-static const struct pll_params_table meson8b_hdmi_pll_params_table[] = {
-	PLL_PARAMS(40, 1),
-	PLL_PARAMS(42, 1),
-	PLL_PARAMS(44, 1),
-	PLL_PARAMS(45, 1),
-	PLL_PARAMS(49, 1),
-	PLL_PARAMS(52, 1),
-	PLL_PARAMS(54, 1),
-	PLL_PARAMS(56, 1),
-	PLL_PARAMS(59, 1),
-	PLL_PARAMS(60, 1),
-	PLL_PARAMS(61, 1),
-	PLL_PARAMS(62, 1),
-	PLL_PARAMS(64, 1),
-	PLL_PARAMS(66, 1),
-	PLL_PARAMS(68, 1),
-	PLL_PARAMS(71, 1),
-	PLL_PARAMS(82, 1),
-	{ /* sentinel */ }
-};
+static const unsigned int meson8b_hdmi_pll_mult_table[] = { 40, 42, 44, 45, 49, 52, 54, 56, 60,
+							    61, 62, 64, 66, 68, 71, 82, 0 };
 
 static struct clk_regmap meson8b_hdmi_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
@@ -305,7 +266,7 @@ static struct clk_regmap meson8b_hdmi_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = meson8b_hdmi_pll_params_table,
+		.table = meson8b_hdmi_pll_mult_table,
 		.init_regs = meson8b_hdmi_pll_init_regs,
 		.init_count = ARRAY_SIZE(meson8b_hdmi_pll_init_regs),
 	},
@@ -399,7 +360,7 @@ static struct clk_regmap meson8b_sys_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = sys_pll_params_table,
+		.table = sys_pll_mult_table,
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "sys_pll_dco",
@@ -2121,10 +2082,7 @@ static const struct reg_sequence meson8m2_gp_pll_init_regs[] = {
 	{ .reg = HHI_GP_PLL_CNTL5,	.def = 0x00003000 },
 };
 
-static const struct pll_params_table meson8m2_gp_pll_params_table[] = {
-	PLL_PARAMS(182, 3),
-	{ /* sentinel */ },
-};
+static const unsigned int meson8m2_gp_pll_mult_table[] = { 182, 0 };
 
 static struct clk_regmap meson8m2_gp_pll_dco = {
 	.data = &(struct meson_clk_pll_data){
@@ -2148,7 +2106,7 @@ static struct clk_regmap meson8m2_gp_pll_dco = {
 			.shift   = 29,
 			.width   = 1,
 		},
-		.table = meson8m2_gp_pll_params_table,
+		.table = meson8m2_gp_pll_mult_table,
 		.init_regs = meson8m2_gp_pll_init_regs,
 		.init_count = ARRAY_SIZE(meson8m2_gp_pll_init_regs),
 	},

-- 
2.47.1



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag
  2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
@ 2026-12-01  9:10   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01  9:10 UTC (permalink / raw)
  To: Jian Hu
  Cc: linux-clk, linux-amlogic, devicetree, robh, conor+dt,
	neil.armstrong

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: divider: divider_ro_determine_rate() ignores
  CLK_DIVIDER_ALLOW_ZERO
--

commit 4e759b85217f16d179883cd2a607d512a8a7c0a5
Author: Jian Hu <jian.hu@amlogic.com>

clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag

This commit adds the CLK_DIVIDER_INVALID_ZERO flag so divider_recalc_rate()
returns 0 instead of parent_rate when the decoded divisor is zero, and
makes divider_ro_determine_rate() return -EINVAL on a zero divisor.

> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index f68216c65d3df..74ae203e5ff8a 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -143,6 +143,9 @@ unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
>  
>  	div = _get_div(table, val, flags, width);
>  	if (!div) {
> +		if (flags & CLK_DIVIDER_INVALID_ZERO)
> +			return 0;
> +
>  		WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO),
>  			"%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n",
>  			clk_hw_get_name(hw));
> @@ -380,6 +383,8 @@ int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
>  	int div;
>  
>  	div = _get_div(table, val, flags, width);
> +	if (!div)
> +		return -EINVAL;

[Severity: Medium]
Does returning -EINVAL here unconditionally break read-only dividers where
a zero divisor is a valid divide-by-one bypass (such as those using
CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, like DEFINE_SG2044_DIV_RO
in drivers/clk/sophgo/clk-sg2044.c)?

When CLK_DIVIDER_INVALID_ZERO is not set, divider_recalc_rate() treats
!div as a pass-through and returns parent_rate, whereas
divider_ro_determine_rate() now rejects it with -EINVAL instead of treating
div as 1.  This breaks clk_round_rate(), clk_set_rate() and parent rate
propagation across read-only bypass dividers when the register reads 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
@ 2026-12-01  9:11   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01  9:11 UTC (permalink / raw)
  To: Jian Hu
  Cc: linux-clk, linux-amlogic, devicetree, robh, conor+dt,
	neil.armstrong

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] clk: meson: axg: commit message names GP1 PLL instead of GP0 PLL
--

commit 7989ff308dcbefe13c9c6a419d2e8d552914382b
Author: Jian Hu <jian.hu@amlogic.com>

clk: meson: axg: Model the PLL pre-divider as a divider clock

This commit models the AXG PLL pre-dividers as separate divider clocks
parenting the DCOs and replaces axg_gp0_pll_params_table with
axg_gp0_pll_mult_range.

> The GP1 PLL table lists contiguous multipliers, describe it with a
> pll_mult_range instead of a table.

[Severity: Low]
This isn't a bug, but the commit message refers to the GP1 PLL table,
whereas AXG has no GP1 PLL and the patch converts axg_gp0_pll_params_table
(used by axg_gp0_pll_dco and axg_hifi_pll_dco) to axg_gp0_pll_mult_range.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=4

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC RFT v3 07/13] clk: meson: gxbb: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
@ 2026-12-01  9:16   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01  9:16 UTC (permalink / raw)
  To: Jian Hu
  Cc: linux-clk, linux-amlogic, devicetree, robh, conor+dt,
	neil.armstrong

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] clk: meson: gxbb: accidental revert of gxbb_cts_encp_sel mux
  shift to 20
- [Medium] clk: meson: gxbb: missing zero-divisor flag on gxbb and gxl
  hdmi_prediv
--

commit 3ea24038e4185d59261a086515637e35e0fcb1ea
Author: Jian Hu <jian.hu@amlogic.com>

clk: meson: gxbb: Model the PLL pre-divider as a divider clock

This commit models the GXBB and GXL PLL pre-dividers as separate divider
clocks parenting the DCOs and replaces the GP0 PLL parameter tables with
multiplier ranges.

> diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c
> index 2d5128c0bf9e6..b7350788b73ed 100644
> --- a/drivers/clk/meson/gxbb.c
> +++ b/drivers/clk/meson/gxbb.c
[ ... ]
> @@ -192,6 +210,28 @@ static struct clk_fixed_factor gxbb_hdmi_pll_pre_mult = {
>  	},
>  };
>  
> +static struct clk_regmap gxbb_hdmi_prediv = {
> +	.data = &(struct clk_regmap_div_data){
> +		.offset = HHI_HDMI_PLL_CNTL,
> +		.shift	= 9,
> +		.width	= 5,
> +		.flags	= CLK_DIVIDER_ONE_BASED,
> +	},
> +	.hw.init = &(struct clk_init_data){
> +		.name = "hdmi_prediv",
> +		.ops = &clk_regmap_divider_ro_ops,
> +		.parent_hws = (const struct clk_hw *[]) {
> +			&gxbb_hdmi_pll_pre_mult.hw
> +		},
> +		.num_parents = 1,
> +		/*
> +		 * Display directly handle hdmi pll registers ATM, we need
> +		 * NOCACHE to keep our view of the clock as accurate as possible
> +		 */
> +		.flags = CLK_GET_RATE_NOCACHE,
> +	},
> +};
[ ... ]
> @@ -229,7 +264,29 @@ static struct clk_regmap gxbb_hdmi_pll_dco = {
>  		.name = "hdmi_pll_dco",
>  		.ops = &meson_clk_pll_ro_ops,
>  		.parent_hws = (const struct clk_hw *[]) {
> -			&gxbb_hdmi_pll_pre_mult.hw
> +			&gxbb_hdmi_prediv.hw
> +		},
> +		.num_parents = 1,
> +		/*
> +		 * Display directly handle hdmi pll registers ATM, we need
> +		 * NOCACHE to keep our view of the clock as accurate as possible
> +		 */
> +		.flags = CLK_GET_RATE_NOCACHE,
> +	},
> +};
> +
> +static struct clk_regmap gxl_hdmi_prediv = {
> +	.data = &(struct clk_regmap_div_data){
> +		.offset = HHI_HDMI_PLL_CNTL,
> +		.shift	= 9,
> +		.width	= 5,
> +		.flags	= CLK_DIVIDER_ONE_BASED,
> +	},

[Severity: Medium]
Should gxbb_hdmi_prediv and gxl_hdmi_prediv also set
CLK_DIVIDER_INVALID_ZERO?

Previously, meson_clk_pll_recalc_rate() returned 0 when the pre-divider n
field read 0.  With only CLK_DIVIDER_ONE_BASED, if HHI_HDMI_PLL_CNTL[13:9]
is 0 at boot before the display driver initializes the HDMI PLL,
divider_recalc_rate() triggers a WARN() during clock registration and
returns the parent rate instead of 0 Hz.

[ ... ]

> @@ -2371,7 +2419,7 @@ static struct clk_regmap gxbb_cts_encp_sel = {
>  	.data = &(struct clk_regmap_mux_data){
>  		.offset = HHI_VID_CLK_DIV,
>  		.mask = 0xf,
> -		.shift = 24,
> +		.shift = 20,
>  		.table = gxbb_cts_parents_val_table,
>  	},
>  	.hw.init = &(struct clk_init_data){

[Severity: High]
Was this change to gxbb_cts_encp_sel.data.shift accidental?

It reverts ebffd9ffac2c ("clk: meson: gxbb: fix ENCP clock selection"),
causing cts_encp_sel to access the ENCT clock selector at bits [23:20] of
HHI_VID_CLK_DIV instead of the ENCP clock selector at bits [27:24].

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=7

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC RFT v3 08/13] clk: meson: g12a: Model the PLL pre-divider as a divider clock
  2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
@ 2026-12-01  9:19   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01  9:19 UTC (permalink / raw)
  To: Jian Hu
  Cc: linux-clk, linux-amlogic, devicetree, robh, conor+dt,
	neil.armstrong

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: meson: g12a: CLK_GET_RATE_NOCACHE on prediv clocks does
  not update children
--

commit 1cb730ae65d6d705f933c3659db77a276e9bbf91
Author: Jian Hu <jian.hu@amlogic.com>

clk: meson: g12a: Model the PLL pre-divider as a divider clock

This commit replaces the embedded n pre-divider parameter on G12A/G12B/SM1
PLL DCO clocks with standalone clk_regmap divider clocks wired as parents of
each PLL DCO.

> diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c
> index beed610e4a825..09eb842e0b1aa 100644
> --- a/drivers/clk/meson/g12a.c
> +++ b/drivers/clk/meson/g12a.c
[ ... ]
> @@ -609,6 +704,32 @@ static struct clk_regmap g12a_hifi_pll = {
>  	},
>  };
>  
> +static struct clk_regmap g12a_pcie_prediv = {
> +	.data = &(struct clk_regmap_div_data){
> +		.offset = HHI_PCIE_PLL_CNTL0,
> +		.shift	= 10,
> +		.width	= 5,
> +		.table	= g12a_pll_prediv_div_table,
> +		.flags	= CLK_DIVIDER_INVALID_ZERO,
> +	},
> +	.hw.init = &(struct clk_init_data){
> +		.name = "pcie_prediv",
> +		.ops = &clk_regmap_divider_ops,
> +		.parent_data = &(const struct clk_parent_data) {
> +			.fw_name = "xtal",
> +		},
> +		.num_parents = 1,
> +		/*
> +		 * The PCIe prediv register reads zero on power-on.
> +		 * CLK_DIVIDER_INVALID_ZERO makes the first rate return 0 Hz,
> +		 * which gets cached by CCF. The PCIe PLL enable callback
> +		 * later writes a valid non-zero divider value. Use
> +		 * CLK_GET_RATE_NOCACHE to avoid stale cached rate.
> +		 */
> +		.flags	= CLK_GET_RATE_NOCACHE,
> +	},
> +};
[ ... ]
> @@ -674,10 +790,11 @@ static struct clk_regmap g12a_pcie_pll_dco = {
>  	.hw.init = &(struct clk_init_data){
>  		.name = "pcie_pll_dco",
>  		.ops = &meson_clk_pcie_pll_ops,
> -		.parent_data = &(const struct clk_parent_data) {
> -			.fw_name = "xtal",
> +		.parent_hws = (const struct clk_hw *[]) {
> +			&g12a_pcie_prediv.hw
>  		},
>  		.num_parents = 1,
> +		.flags = CLK_SET_RATE_PARENT,
>  	},
>  };
>  
> @@ -729,6 +846,33 @@ static struct clk_fixed_factor g12a_pcie_pll = {
>  	},
>  };
>  
> +static struct clk_regmap g12a_hdmi_prediv = {
> +	.data = &(struct clk_regmap_div_data){
> +		.offset = HHI_HDMI_PLL_CNTL0,
> +		.shift	= 10,
> +		.width	= 5,
> +		/*
> +		 * The pre-divider register reads zero until the display driver
> +		 * programs the HDMI PLL, so a zero divisor is not a fault here:
> +		 * treat it as a bypass instead of warning at registration.
> +		 */
> +		.flags	= CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO,
> +	},
> +	.hw.init = &(struct clk_init_data){
> +		.name = "hdmi_prediv",
> +		.ops = &clk_regmap_divider_ro_ops,
> +		.parent_data = &(const struct clk_parent_data) {
> +			.fw_name = "xtal",
> +		},
> +		.num_parents = 1,
> +		/*
> +		 * Display directly handle hdmi pll registers ATM, we need
> +		 * NOCACHE to keep our view of the clock as accurate as possible
> +		 */
> +		.flags = CLK_GET_RATE_NOCACHE,
> +	},
> +};

[Severity: Medium]
Does setting CLK_GET_RATE_NOCACHE on g12a_pcie_prediv and g12a_hdmi_prediv
actually refresh their rates when clk_get_rate() is called on descendant
clocks such as CLKID_PCIE_PLL or CLKID_HDMI_PLL?

In clk_core_get_rate_recalc(), CCF only invokes __clk_recalc_rates() if
CLK_GET_RATE_NOCACHE is set on the queried clock itself, and
__clk_recalc_rates() walks downward using core->parent->rate from the parent's
cache without walking upward to recalculate ancestors:

drivers/clk/clk.c:clk_core_get_rate_recalc() {
	if (core && (core->flags & CLK_GET_RATE_NOCACHE))
		__clk_recalc_rates(core, false, 0);

	return clk_core_get_rate_nolock(core);
}

For PCIe, HHI_PCIE_PLL_CNTL0 reads 0 at boot, so g12a_pcie_prediv and its
descendants register with a cached rate of 0 Hz.  Because meson_clk_pcie_pll_ops
has no .set_rate callback and only writes g12a_pcie_pll_init_regs in .enable
(meson_clk_pcie_pll_enable()), and none of g12a_pcie_pll_dco..g12a_pcie_pll
carry CLK_GET_RATE_NOCACHE, CLKID_PCIE_PLL remains cached at 0 Hz even after
clk_prepare_enable().  At this commit (prior to commit "clk: meson: pll:
Remove the dedicated n parameter" adding parent rate negotiation to
meson_clk_pll_determine_rate()), clk_set_rate(CLKID_PCIE_PLL, 100000000) from
assigned-clock-rates on usb3_pcie_phy also fails with -EINVAL because
req->best_parent_rate is 0.

Similarly, for HDMI, calling clk_get_rate() on g12a_hdmi_pll_dco or
g12a_hdmi_pll after the display driver directly updates HHI_HDMI_PLL_CNTL0
recalculates from g12a_hdmi_prediv's cached rate rather than re-reading the
pre-divider register.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=8

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-12-01  9:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
2026-12-01  9:10   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  9:11   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 05/13] clk: meson: a1: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 06/13] clk: meson: c3: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
2026-12-01  9:16   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
2026-12-01  9:19   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 09/13] clk: meson: meson8: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 10/13] clk: meson: s4: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 11/13] clk: meson: s7: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 12/13] clk: meson: t7: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox