Skip to contentSkip to conversation

Add driver support for ESWIN eic700 SoC clock controller

PATCH Superseded [email protected] 3 participants 10 messages Nov 13, 2025 – Dec 22, 2025

Subsystems (3)

v8 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v8 cover Add driver support for ESWIN eic700 SoC clock controller

From: Xuyang Dong <[email protected]>

The link [1] provides the official documentation for the EIC7700. Section 3.2 covers the clock subsystem.

[1] https://www.sifive.com/document-file/eic7700x-datasheet

Updates:
Changes in v8:
- Added clock-tree link in cover-letter.
- Updated YAML file
- Added "Acked-by: Troy Mitchell <[email protected]>" for bindings.
- Updated driver file
- Changed Kconfig symbol type from bool to tristate to build this driver as module.
- Updated MAINTAINERS file
- Added entry "ESWIN EIC7700 CLOCK DRIVER".

- Link to v7: https://lore.kernel.org/all/[email protected]/

Changes in v7:
- Updated YAML file
- Added "Acked-by: Conor Dooley <[email protected]>" for bindings.
- Updated driver file
- Added description for clk of eswin_calc_pll().
- Added macro EIC7700_MUX_TBL to manage mux clock-tree.
- Added eswin_clk_register_mux_tbl() to register mux clocks with discontinuous parent indexes.

- Link to v6: https://lore.kernel.org/all/[email protected]/

Changes in v6:
- Removed config option patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Added an oscillator as the clock input, named xtal24m.
- Added clocks property.
- Updated driver file
- Replaced fixed_rate_clk_xtal_24m with xtal24m.
- Dropped fixed_rate_clk_xtal_24m from driver. Because clock xtal24m was registered by fixed-clock as oscillator.

- Link to v5: https://lore.kernel.org/all/[email protected]/

Changes in v5:
- Removed vendor prefix patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Placed the required after all properties.
- Removed patternProperties. Also removed compatible of eswin,pll-clock, eswin,mux-clock, eswin,divider-clock and eswin,gate-clock as we have moved clock tree from DTS to Linux driver.
- Removed the clock tree from DTS. Used clock-controller to manage all clock. Removed all child nodes in clock-controller.
- Removed '#address-cells' and '#size-cells' properties, because the clock controller did not need to define these properties.
- Removed eic7700-clocks.dtsi.
- Added dt-bindings header for clock IDs. Because used the IDs to register clocks.
- Updated driver file
- Modified the commit for clock driver. Dropped indentation in commit.
- Removed CLK_OF_DECLARE(). Used *clk_hw_register* to register clocks. Used devm_of_clk_add_hw_provider.
- Dropped singletons.
- Checked the value right after obtaining it.
- Removed the definitions of macro frequency in clk.h like CLK_FREQ_24M.
- Modified description of help in Kconfig.
- Added COMPILE_TEST. Added COMMON_CLK_ESWIN for clk.o. And added "select COMMON_CLK_ESWIN" for clk-eic7700.c. Without COMMON_CLK_EIC7700, clk.c could not be compiled.
- Used .determined_rate.
- Added macro definitions of EIC7700_DIV, EIC7700_FIXED, EIC7700_FACTOR, EIC7700_MUX and EIC7700_PLL to manage clock tree.
- Added clk-eic7700.h to place eic7700 SoC clock registers.
- Removed refdiv_val and postdiv1_val from clk_pll_recalc_rate(). Because these values were unused.

- Link to v4: https://lore.kernel.org/all/[email protected]/

Changes in v4:
- Updated YAML file
- Changed name from cpu-default-frequency to cpu-default-freq-hz.
- Dropped $ref of cpu-default-frequency.
- Added cpu-default-frequency for required.
- Removed cpu-default-frequency in updated file, because there was no need to add cpu-default-frequency.
- Moved DIVIDER to DIV.
- Arranged the IDs in order.
- Dropped EIC7700_NR_CLKS.
- Removed dt-bindings eswin,eic7700-clock.h. Because IDs was not used, and used clock device nodes.
- According to the updated driver codes, the YAML has been updated.
- Updated driver file
- Remove undocumented parameters "cpu_no_boost_1_6ghz" and "cpu-default-frequency".
- Modified the comment and used the correct Linux coding style.
- Removed codes of voltage, because it was not the clock driver.
- Updated the formula of clock frequency calculation. Removed the logic that only used register selection.
- Used CLK_OF_DECLARE() to register clocks. Registered pll-clock, mux-clock, divider-clock, and gate-clock in clk-eic7700.c. The specific implementation of clock registration was in clk.c.
- Added eic7700-clocks.dtsi.
- Moved device information to DTS. Put all clocks' node in the eic7700-clocks.dtsi.

- Link to v3: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Update example, drop child node and add '#clock-cells' to the parent
node.
- Change parent node from sys-crg to clock-controller for this yaml.
- Drop "syscon", "simple-mfd" to clear warnings/errors by using "make dt_binding_check". And these are not necessary.
- Add "cpu-default-frequency" definition in yaml for "undocumented ABI".
- Drop Reviewed-by, this is misunderstanding. We have not received such
an email.
- Link to v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Update example, drop child node.
- Clear warnings/errors for using "make dt_binding_check".
- Change to the correct format.
- Drop some non-stanard code.
- Use dev_err_probe() in probe functions.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Xuyang Dong (3):
dt-bindings: clock: eswin: Documentation for eic7700 SoC
clock: eswin: Add eic7700 clock driver
MAINTAINERS: Add entry for ESWIN EIC7700 clock driver

 .../bindings/clock/eswin,eic7700-clock.yaml   |   46 +
 MAINTAINERS                                   |    8 +
 drivers/clk/Kconfig                           |    1 +
 drivers/clk/Makefile                          |    1 +
 drivers/clk/eswin/Kconfig                     |   15 +
 drivers/clk/eswin/Makefile                    |    8 +
 drivers/clk/eswin/clk-eic7700.c               | 1033 +++++++++++++++++
 drivers/clk/eswin/clk-eic7700.h               |  122 ++
 drivers/clk/eswin/clk.c                       |  481 ++++++++
 drivers/clk/eswin/clk.h                       |  256 ++++
 .../dt-bindings/clock/eswin,eic7700-clock.h   |  280 +++++
 11 files changed, 2251 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml
 create mode 100644 drivers/clk/eswin/Kconfig
 create mode 100644 drivers/clk/eswin/Makefile
 create mode 100644 drivers/clk/eswin/clk-eic7700.c
 create mode 100644 drivers/clk/eswin/clk-eic7700.h
 create mode 100644 drivers/clk/eswin/clk.c
 create mode 100644 drivers/clk/eswin/clk.h
 create mode 100644 include/dt-bindings/clock/eswin,eic7700-clock.h

--
2.43.0

author maintainer
#1 lore raw

PATCH v8 1/3 dt-bindings: clock: eswin: Documentation for eic7700 SoC

From: Xuyang Dong <[email protected]>

Add device tree binding documentation for the ESWIN eic7700 clock controller module.

---
 .../bindings/clock/eswin,eic7700-clock.yaml   |  46 +++
 .../dt-bindings/clock/eswin,eic7700-clock.h   | 280 ++++++++++++++++++
 2 files changed, 326 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml
 create mode 100644 include/dt-bindings/clock/eswin,eic7700-clock.h
Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml new file +46 -0
new file mode 100644
index 000000000000..3125ae52bde6
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/eswin,eic7700-clock.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Eswin EIC7700 SoC clock controller
+
+maintainers:
+  - Yifeng Huang <[email protected]>
+  - Xuyang Dong <[email protected]>
+
+description:
+  The clock controller generates and supplies clock to all the modules
+  for eic7700 SoC.
+
+properties:
+  compatible:
+    const: eswin,eic7700-clock
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: External 24MHz oscillator clock
+
+  '#clock-cells':
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - '#clock-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    clock-controller@51828000 {
+        compatible = "eswin,eic7700-clock";
+        reg = <0x51828000 0x300>;
+        clocks = <&xtal24m>;
+        #clock-cells = <1>;
+    };
include/dt-bindings/clock/eswin,eic7700-clock.h new file +280 -0

280 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v8 2/3 clock: eswin: Add eic7700 clock driver

In reply to [email protected]

From: Xuyang Dong <[email protected]>

Add clock drivers for the EIC7700 SoC. The clock controller on the ESWIN EIC7700 provides various clocks to different IP blocks within the SoC.

---
 drivers/clk/Kconfig             |    1 +
 drivers/clk/Makefile            |    1 +
 drivers/clk/eswin/Kconfig       |   15 +
 drivers/clk/eswin/Makefile      |    8 +
 drivers/clk/eswin/clk-eic7700.c | 1033 +++++++++++++++++++++++++++++++
 drivers/clk/eswin/clk-eic7700.h |  122 ++++
 drivers/clk/eswin/clk.c         |  481 ++++++++++++++
 drivers/clk/eswin/clk.h         |  256 ++++++++
 8 files changed, 1917 insertions(+)
 create mode 100644 drivers/clk/eswin/Kconfig
 create mode 100644 drivers/clk/eswin/Makefile
 create mode 100644 drivers/clk/eswin/clk-eic7700.c
 create mode 100644 drivers/clk/eswin/clk-eic7700.h
 create mode 100644 drivers/clk/eswin/clk.c
 create mode 100644 drivers/clk/eswin/clk.h
drivers/clk/Kconfig +1 -0
index 3a1611008e48..2a9056d41093 100644
@@ -515,6 +515,7 @@ source "drivers/clk/actions/Kconfig"
 source "drivers/clk/analogbits/Kconfig"
 source "drivers/clk/baikal-t1/Kconfig"
 source "drivers/clk/bcm/Kconfig"
+source "drivers/clk/eswin/Kconfig"
 source "drivers/clk/hisilicon/Kconfig"
 source "drivers/clk/imgtec/Kconfig"
 source "drivers/clk/imx/Kconfig"
drivers/clk/Makefile +1 -0
index b74a1767ca27..9075f8cabd8d 100644
@@ -121,6 +121,7 @@ obj-$(CONFIG_CLK_BAIKAL_T1)		+= baikal-t1/
 obj-y					+= bcm/
 obj-$(CONFIG_ARCH_BERLIN)		+= berlin/
 obj-$(CONFIG_ARCH_DAVINCI)		+= davinci/
+obj-$(CONFIG_ARCH_ESWIN)		+= eswin/
 obj-$(CONFIG_ARCH_HISI)			+= hisilicon/
 obj-y					+= imgtec/
 obj-y					+= imx/
drivers/clk/eswin/Kconfig new file +15 -0
new file mode 100644
index 000000000000..86af60f852c2
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config COMMON_CLK_ESWIN
+	bool
+
+config COMMON_CLK_EIC7700
+	tristate "EIC7700 Clock Driver"
+	depends on ARCH_ESWIN || COMPILE_TEST
+	select COMMON_CLK_ESWIN
+	default ARCH_ESWIN
+	help
+	  This driver provides support for clock controller on ESWIN EIC7700
+	  SoC. The clock controller can generates and supplies clock to various
+	  peripherals within the SoC.
+	  Say yes here to support the clock controller on the EIC7700 SoC.
drivers/clk/eswin/Makefile new file +8 -0
new file mode 100644
index 000000000000..4a7c2af82164
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Eswin Clock specific Makefile
+#
+
+obj-$(CONFIG_COMMON_CLK_ESWIN)		+= clk.o
+
+obj-$(CONFIG_COMMON_CLK_EIC7700)	+= clk-eic7700.o
drivers/clk/eswin/clk-eic7700.c new file +1033 -0

1,033 lines not on this page · raw message

drivers/clk/eswin/clk-eic7700.h new file +122 -0

122 lines not on this page · raw message

drivers/clk/eswin/clk.c new file +481 -0

481 lines not on this page · raw message

drivers/clk/eswin/clk.h new file +256 -0

256 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH v8 3/3 MAINTAINERS: Add entry for ESWIN EIC7700 clock driver

In reply to [email protected]

From: Xuyang Dong <[email protected]>

Add Yifeng Huang and myself as maintainer of ESWIN EIC7700 clock driver.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index ddecf1ef3bed..61f9f77385fd 100644
@@ -9246,6 +9246,14 @@ T:	git https://github.com/eswincomputing/linux-next.git
 F:	Documentation/devicetree/bindings/riscv/eswin.yaml
 F:	arch/riscv/boot/dts/eswin/
 
+ESWIN EIC7700 CLOCK DRIVER
+M:	Xuyang Dong <[email protected]>
+M:	Yifeng Huang <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml
+F:	drivers/clk/eswin/
+F:	include/dt-bindings/clock/eswin,eic7700-clock.h
+
 ET131X NETWORK DRIVER
 M:	Mark Einon <[email protected]>
 S:	Odd Fixes
Signature · 1 line
2.43.0
author maintainer
#8 lore raw
In reply to [email protected]
Quoted 6 lines

The link [1] provides the official documentation for the EIC7700. Section 3.2 covers the clock subsystem.

[1] https://www.sifive.com/document-file/eic7700x-datasheet

Quoted 11 lines

Updates:
Changes in v8:
- Added clock-tree link in cover-letter.
- Updated YAML file
- Added "Acked-by: Troy Mitchell <[email protected]>" for bindings.
- Updated driver file
- Changed Kconfig symbol type from bool to tristate to build this driver as module.
- Updated MAINTAINERS file
- Added entry "ESWIN EIC7700 CLOCK DRIVER".

Hi Troy and all,

Just a gentle reminder about this patch series. Could you please review the clock driver in patch v8 2/3? Thanks for your time and consideration!

Best regards,
Xuyang Dong

author maintainer
#9 lore raw
Quoted 18 lines
Quoted 6 lines

The link [1] provides the official documentation for the EIC7700. Section 3.2 covers the clock subsystem.

[1] https://www.sifive.com/document-file/eic7700x-datasheet

Quoted 11 lines

Updates:
Changes in v8:
- Added clock-tree link in cover-letter.
- Updated YAML file
- Added "Acked-by: Troy Mitchell <[email protected]>" for bindings.
- Updated driver file
- Changed Kconfig symbol type from bool to tristate to build this driver as module.
- Updated MAINTAINERS file
- Added entry "ESWIN EIC7700 CLOCK DRIVER".

Quoted 6 lines

Hi Troy and all,

Just a gentle reminder about this patch series. Could you please review the clock driver in patch v8 2/3? Thanks for your time and consideration!

Hi Troy and all,

I hope this message finds you well.
This is a gentle reminder regarding the clock driver patch in v8, patch 2/3 of the series. If you have some time, we’d greatly appreciate your review and feedback. Thanks for your time and support!

Best regards,
Xuyang Dong

#3 lore raw

Re: [PATCH v8 2/3] clock: eswin: Add eic7700 clock driver

In reply to [email protected]

Hi Xuyang,
This is a quick review.

Quoted 24 lines · On Thu, Nov 13, 2025 at 09:38:46AM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

Add clock drivers for the EIC7700 SoC. The clock controller on the ESWIN EIC7700 provides various clocks to different IP blocks within the SoC.

---
 drivers/clk/Kconfig             |    1 +
 drivers/clk/Makefile            |    1 +
 drivers/clk/eswin/Kconfig       |   15 +
 drivers/clk/eswin/Makefile      |    8 +
 drivers/clk/eswin/clk-eic7700.c | 1033 +++++++++++++++++++++++++++++++
 drivers/clk/eswin/clk-eic7700.h |  122 ++++
 drivers/clk/eswin/clk.c         |  481 ++++++++++++++
 drivers/clk/eswin/clk.h         |  256 ++++++++
 8 files changed, 1917 insertions(+)
 create mode 100644 drivers/clk/eswin/Kconfig
 create mode 100644 drivers/clk/eswin/Makefile
 create mode 100644 drivers/clk/eswin/clk-eic7700.c
 create mode 100644 drivers/clk/eswin/clk-eic7700.h
 create mode 100644 drivers/clk/eswin/clk.c
 create mode 100644 drivers/clk/eswin/clk.h

[...]

Quoted 5 lines
drivers/clk/eswin/clk-eic7700.c new file +0 -0
new file mode 100644
index 000000000000..03540db9cb7d

[...]

drivers/clk/eswin/clk-eic7700.c line 994

Quoted 12 lines
drivers/clk/eswin/clk-eic7700.c new file +12 -0
+static int eic7700_clk_probe(struct platform_device *pdev)
+{
+	struct eswin_clock_data *clk_data;
+	struct device *dev = &pdev->dev;
+
+	clk_data = eswin_clk_init(dev, EIC7700_NR_CLKS);
+	if (!clk_data)
+		return dev_err_probe(dev, -EAGAIN, "failed to get clk data!\n");
+
+	eswin_clk_register_fixed_rate(eic7700_fixed_rate_clks,
+				      ARRAY_SIZE(eic7700_fixed_rate_clks),
+				      clk_data, dev);

Please check returned value here and check other places.

Quoted 21 lines
drivers/clk/eswin/clk-eic7700.c new file +21 -0
+
+	eswin_clk_register_pll(eic7700_pll_clks, ARRAY_SIZE(eic7700_pll_clks),
+			       clk_data, dev);
+
+	eswin_clk_register_fixed_factor(eic7700_fixed_factor_clks,
+					ARRAY_SIZE(eic7700_fixed_factor_clks),
+					clk_data, dev);
+
+	eswin_clk_register_mux(eic7700_mux_clks, ARRAY_SIZE(eic7700_mux_clks),
+			       clk_data, dev);
+
+	eswin_clk_register_divider(eic7700_div_clks,
+				   ARRAY_SIZE(eic7700_div_clks), clk_data, dev);
+
+	eswin_clk_register_gate(eic7700_gate_clks,
+				ARRAY_SIZE(eic7700_gate_clks), clk_data, dev);
+
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+					   &clk_data->clk_data);
+}
+

[...]

Quoted 5 lines
drivers/clk/eswin/clk.c new file +0 -0
new file mode 100644
index 000000000000..92998da98009

[...]

drivers/clk/eswin/clk.c line 62

Quoted 8 lines
drivers/clk/eswin/clk.c new file +8 -0
+static int eswin_calc_pll(u32 *frac_val, u32 *fbdiv_val, u64 rate,
+			  const struct eswin_clk_pll *clk)
+{
+	u64 rem = 0;
+	u32 tmp1 = 0, tmp2 = 0;
+
+	if (clk->id == EIC7700_CLK_APLL_FOUT1 ||
+	    clk->id == EIC7700_CLK_PLL_CPU) {

clk.c appears to be a generic library for ESWIN SoCs, but it references specific IDs (EIC7700_...) from a specific chip.

If you add the chip like EIC77XX later, will you add more if/else here?

Could you ove the algorithmic parameters (like rate * 4) into the eswin_clk_pll structure flags or data fields. The calculation logic should be generic based on the struct fields, not the ID.

Please check other places.

Quoted 39 lines
drivers/clk/eswin/clk.c new file +39 -0
+		rate = rate * 4;
+		rem = do_div(rate, 1000);
+		if (rem)
+			tmp1 = rem;
+
+		rem = do_div(rate, 1000);
+		if (rem)
+			tmp2 = rem;
+
+		rem = do_div(rate, 24);
+		/* fbdiv = rate * 4 / 24000000 */
+		*fbdiv_val = rate;
+		/* frac = rate * 4 % 24000000 * (2 ^ 24) */
+		*frac_val = (u64)((1000 * (1000 * rem + tmp2) + tmp1) << 24)
+				  / 24 / 1000000;
+	} else {
+		pr_err("Invalid pll set req, rate %lld, clk id %d\n", rate,
+		       clk->id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static inline struct eswin_clk_pll *to_pll_clk(struct clk_hw *hw)
+{
+	return container_of(hw, struct eswin_clk_pll, hw);
+}
+
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct eswin_clk_pll *clk = to_pll_clk(hw);
+	struct clk *clk_cpu_lp_pll = NULL;
+	struct clk *clk_cpu_mux = NULL;
+	struct clk *clk_cpu_pll = NULL;
+	u32 postdiv1_val = 0, refdiv_val = 1;
+	u32 frac_val, fbdiv_val, val;
+	bool lock_flag = false;

drivers/clk/eswin/clk.c line 111

Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+	int try_count = 0;
+	int ret;
+
+	ret = eswin_calc_pll(&frac_val,  &fbdiv_val, (u64)rate, clk);
+	if (ret)
+		return ret;
+
+	/* Must switch the CPU to other CLK before we change the CPU PLL. */
+	if (clk->id == EIC7700_CLK_PLL_CPU) {
+		clk_cpu_mux = __clk_lookup("mux_cpu_root_3mux1_gfree");

It seems you want to switch to a safe clock source before setting up the PLL, right?

I am not sure whether your approach is correct, but the use of __clk_lookup() should be avoided whenever possible.
Would it be feasible to obtain a proper clock handle somewhere and perform the necessary configuration from within a clk_notifier instead?

Quoted 5 lines
drivers/clk/eswin/clk.c new file +5 -0
+		if (!clk_cpu_mux) {
+			pr_err("failed to get clk: %s\n",
+			       "mux_cpu_root_3mux1_gfree");
+			return -EINVAL;
+		}
#4 lore raw

Re: [PATCH v8 2/3] clock: eswin: Add eic7700 clock driver

Hi ESWIN folks,

Please refer to my comments below

Quoted 6 lines · Troy Mitchell

Hi Xuyang,
This is a quick review.

Quoted 2 lines · On Thu, Nov 13, 2025 at 09:38:46AM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

...

Quoted 27 lines
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct eswin_clk_pll *clk = to_pll_clk(hw);
+	struct clk *clk_cpu_lp_pll = NULL;
+	struct clk *clk_cpu_mux = NULL;
+	struct clk *clk_cpu_pll = NULL;
+	u32 postdiv1_val = 0, refdiv_val = 1;
+	u32 frac_val, fbdiv_val, val;
+	bool lock_flag = false;

drivers/clk/eswin/clk.c line 111

Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+	int try_count = 0;
+	int ret;
+
+	ret = eswin_calc_pll(&frac_val,  &fbdiv_val, (u64)rate, clk);
+	if (ret)
+		return ret;
+
+	/* Must switch the CPU to other CLK before we change the CPU PLL. */
+	if (clk->id == EIC7700_CLK_PLL_CPU) {
+		clk_cpu_mux = __clk_lookup("mux_cpu_root_3mux1_gfree");

It seems you want to switch to a safe clock source before setting up the PLL, right?

I am not sure whether your approach is correct, but the use of __clk_lookup() should be avoided whenever possible.
Would it be feasible to obtain a proper clock handle somewhere and perform the necessary configuration from within a clk_notifier instead?

Quoted 5 lines

drivers/clk/eswin/clk.c line 116

Quoted 5 lines
drivers/clk/eswin/clk.c new file +5 -0
+		if (!clk_cpu_mux) {
+			pr_err("failed to get clk: %s\n",
+			       "mux_cpu_root_3mux1_gfree");
+			return -EINVAL;
+		}

I have a strong feeling that this switch to safe clock and back to PLL can be done with something very similar to this:

"Add notifier for PLL0 clock and set it 1.5GHz on the JH7110 SoC"
https://lore.kernel.org/all/[email protected]/

Please take a look. Thanks!

Bo

#5 lore raw

Re: [PATCH v8 2/3] clock: eswin: Add eic7700 clock driver

Quoted 50 lines · Bo Gan

Hi ESWIN folks,

Please refer to my comments below

Quoted 6 lines · Troy Mitchell

Hi Xuyang,
This is a quick review.

Quoted 2 lines · On Thu, Nov 13, 2025 at 09:38:46AM +0800, [email protected] wrote:

From: Xuyang Dong <[email protected]>

...

Quoted 27 lines
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct eswin_clk_pll *clk = to_pll_clk(hw);
+	struct clk *clk_cpu_lp_pll = NULL;
+	struct clk *clk_cpu_mux = NULL;
+	struct clk *clk_cpu_pll = NULL;
+	u32 postdiv1_val = 0, refdiv_val = 1;
+	u32 frac_val, fbdiv_val, val;
+	bool lock_flag = false;

drivers/clk/eswin/clk.c line 111

Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+	int try_count = 0;
+	int ret;
+
+	ret = eswin_calc_pll(&frac_val,  &fbdiv_val, (u64)rate, clk);
+	if (ret)
+		return ret;
+
+	/* Must switch the CPU to other CLK before we change the CPU PLL. */
+	if (clk->id == EIC7700_CLK_PLL_CPU) {
+		clk_cpu_mux = __clk_lookup("mux_cpu_root_3mux1_gfree");

It seems you want to switch to a safe clock source before setting up the PLL, right?

I am not sure whether your approach is correct, but the use of __clk_lookup() should be avoided whenever possible.
Would it be feasible to obtain a proper clock handle somewhere and perform the necessary configuration from within a clk_notifier instead?

Quoted 5 lines

drivers/clk/eswin/clk.c line 116

Quoted 5 lines
drivers/clk/eswin/clk.c new file +5 -0
+		if (!clk_cpu_mux) {
+			pr_err("failed to get clk: %s\n",
+			       "mux_cpu_root_3mux1_gfree");
+			return -EINVAL;
+		}

I have a strong feeling that this switch to safe clock and back to PLL can be done with something very similar to this:

Quoted 3 lines

"Add notifier for PLL0 clock and set it 1.5GHz on the JH7110 SoC"
https://lore.kernel.org/all/[email protected]/

YES, That's what I want.
Thanks for your link!

- Troy

Quoted 3 lines

Please take a look. Thanks!

Bo

author maintainer
#6 lore raw

Re: Re: [PATCH v8 2/3] clock: eswin: Add eic7700 clock driver

Quoted 39 lines
Quoted 39 lines

...

Quoted 27 lines
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct eswin_clk_pll *clk = to_pll_clk(hw);
+	struct clk *clk_cpu_lp_pll = NULL;
+	struct clk *clk_cpu_mux = NULL;
+	struct clk *clk_cpu_pll = NULL;
+	u32 postdiv1_val = 0, refdiv_val = 1;
+	u32 frac_val, fbdiv_val, val;
+	bool lock_flag = false;

drivers/clk/eswin/clk.c line 111

Quoted 10 lines
drivers/clk/eswin/clk.c new file +10 -0
+	int try_count = 0;
+	int ret;
+
+	ret = eswin_calc_pll(&frac_val,  &fbdiv_val, (u64)rate, clk);
+	if (ret)
+		return ret;
+
+	/* Must switch the CPU to other CLK before we change the CPU PLL. */
+	if (clk->id == EIC7700_CLK_PLL_CPU) {
+		clk_cpu_mux = __clk_lookup("mux_cpu_root_3mux1_gfree");

It seems you want to switch to a safe clock source before setting up the PLL, right?

I am not sure whether your approach is correct, but the use of __clk_lookup() should be avoided whenever possible.
Would it be feasible to obtain a proper clock handle somewhere and perform the necessary configuration from within a clk_notifier instead?

Quoted 5 lines

drivers/clk/eswin/clk.c line 116

Quoted 5 lines
drivers/clk/eswin/clk.c new file +5 -0
+		if (!clk_cpu_mux) {
+			pr_err("failed to get clk: %s\n",
+			       "mux_cpu_root_3mux1_gfree");
+			return -EINVAL;
+		}

I have a strong feeling that this switch to safe clock and back to PLL can be done with something very similar to this:

Quoted 10 lines
Quoted 3 lines

"Add notifier for PLL0 clock and set it 1.5GHz on the JH7110 SoC"
https://lore.kernel.org/all/[email protected]/

YES, That's what I want.
Thanks for your link!

- Troy

Quoted 3 lines

Please take a look. Thanks!

Bo

Thanks. The mentioned problems will be corrected in the subsequent patch version.

Regards,
Xuyang Dong