Skip to contentSkip to conversation

riscv: sophgo: add clock support for sg2042

PATCH Superseded Chen Wang 4 participants 15 messages Nov 27, 2023 – Nov 30, 2023

Subsystems (4)

v2 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Chen Wang

author
#0 lore raw

v2 cover riscv: sophgo: add clock support for sg2042

From: Chen Wang <[email protected]>

This series adds clock controller support for sophgo sg2042.

Thanks,
Chen

---

Changes in v2:
The patch series is based on v6.7-rc1. You can simply review or test the patches at the link [2].
- Squashed the patch adding clock definitions with the patch adding the binding for the clock controller.
- Updating dt-binding for syscon, remove oneOf for property compatible; define clock controller as child of syscon.
- DTS changes: merge sg2042-clock.dtsi into sg2042.dtsi; move clock-frequency property of osc to board devicethree due to the oscillator is outside the SoC.
- Fixed some bugs in driver code during testing, including removing warnings for rv32_defconfig.
- Updated MAINTAINERS info.

Changes in v1:
The patch series is based on v6.7-rc1. You can simply review or test the patches at the link [1].

---

Chen Wang (4):
dt-bindings: clock: sophgo: Add SG2042 bindings
dt-bindings: soc: sophgo: Add Sophgo syscon module
clk: sophgo: Add SG2042 clock generator driver
riscv: dts: add clock generator for Sophgo SG2042 SoC

 .../clock/sophgo/sophgo,sg2042-clkgen.yaml    |   42 +
 .../soc/sophgo/sophgo,sg2042-syscon.yaml      |   58 +
 MAINTAINERS                                   |    7 +
 .../boot/dts/sophgo/sg2042-milkv-pioneer.dts  |    4 +
 arch/riscv/boot/dts/sophgo/sg2042.dtsi        |   77 +
 drivers/clk/Kconfig                           |    1 +
 drivers/clk/Makefile                          |    1 +
 drivers/clk/sophgo/Kconfig                    |    8 +
 drivers/clk/sophgo/Makefile                   |    2 +
 drivers/clk/sophgo/clk-sophgo-sg2042.c        | 1357 +++++++++++++++++
 drivers/clk/sophgo/clk-sophgo-sg2042.h        |  222 +++
 include/dt-bindings/clock/sophgo-sg2042-clk.h |  169 ++
 12 files changed, 1948 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml
 create mode 100644 Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml
 create mode 100644 drivers/clk/sophgo/Kconfig
 create mode 100644 drivers/clk/sophgo/Makefile
 create mode 100644 drivers/clk/sophgo/clk-sophgo-sg2042.c
 create mode 100644 drivers/clk/sophgo/clk-sophgo-sg2042.h
 create mode 100644 include/dt-bindings/clock/sophgo-sg2042-clk.h

base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86

Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/4 dt-bindings: clock: sophgo: Add SG2042 bindings

From: Chen Wang <[email protected]>

Add bindings for the clock generator on the SG2042 RISC-V SoC.

---
 .../clock/sophgo/sophgo,sg2042-clkgen.yaml    |  42 +++++
 include/dt-bindings/clock/sophgo-sg2042-clk.h | 169 ++++++++++++++++++
 2 files changed, 211 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml
 create mode 100644 include/dt-bindings/clock/sophgo-sg2042-clk.h
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +42 -0
new file mode 100644
index 000000000000..6c0d0461e489
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/sophgo/sophgo,sg2042-clkgen.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo SG2042 Clock Generator
+
+maintainers:
+  - Chen Wang <[email protected]>
+
+properties:
+  compatible:
+    const: sophgo,sg2042-clkgen
+
+  clocks:
+    items:
+      - description: Clock Generation IC (25 MHz)
+
+  '#clock-cells':
+    const: 1
+    description:
+      See <dt-bindings/clock/sophgo-sg2042-clk.h> for valid indices.
+
+  assigned-clocks: true
+
+  assigned-clock-rates: true
+
+required:
+  - compatible
+  - clocks
+  - '#clock-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    clock-controller {
+            compatible = "sophgo,sg2042-clkgen";
+            clocks = <&cgi>;
+            #clock-cells = <1>;
+    };
include/dt-bindings/clock/sophgo-sg2042-clk.h new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/4] dt-bindings: clock: sophgo: Add SG2042 bindings

Quoted 33 lines · Chen Wang

From: Chen Wang <[email protected]>

Add bindings for the clock generator on the SG2042 RISC-V SoC.

---
 .../clock/sophgo/sophgo,sg2042-clkgen.yaml    |  42 +++++
 include/dt-bindings/clock/sophgo-sg2042-clk.h | 169 ++++++++++++++++++
 2 files changed, 211 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml
 create mode 100644 include/dt-bindings/clock/sophgo-sg2042-clk.h
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +15 -0
new file mode 100644
index 000000000000..6c0d0461e489
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/sophgo/sophgo,sg2042-clkgen.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo SG2042 Clock Generator
+
+maintainers:
+  - Chen Wang <[email protected]>
+
+properties:
+  compatible:
+    const: sophgo,sg2042-clkgen
+

Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml line 25

Quoted 10 lines
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +10 -0
+  clocks:
+    items:
+      - description: Clock Generation IC (25 MHz)
+
+  '#clock-cells':
+    const: 1
+    description:
+      See <dt-bindings/clock/sophgo-sg2042-clk.h> for valid indices.
+
+  assigned-clocks: true

Drop

Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml line 27

Quoted 2 lines
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +2 -0
+
+  assigned-clock-rates: true

Drop

Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml line 39

Quoted 12 lines
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +12 -0
+
+required:
+  - compatible
+  - clocks
+  - '#clock-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    clock-controller {
+            compatible = "sophgo,sg2042-clkgen";

Use 4 spaces for example indentation.

include/dt-bindings/clock/sophgo-sg2042-clk.h

Quoted 8 lines
Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml new file +3 -0
+            clocks = <&cgi>;
+            #clock-cells = <1>;
+    };
include/dt-bindings/clock/sophgo-sg2042-clk.h new file +0 -0
new file mode 100644
index 000000000000..a8e05c00c3bf

The same filename as binding.

include/dt-bindings/clock/sophgo-sg2042-clk.h line 1

Quoted 2 lines
include/dt-bindings/clock/sophgo-sg2042-clk.h new file +1 -0
@@ -0,0 +1,169 @@
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */

Any particular reason for a bit different license than the bindings? How is your DTS licensed?

include/dt-bindings/clock/sophgo-sg2042-clk.h line 10

Quoted 9 lines
include/dt-bindings/clock/sophgo-sg2042-clk.h new file +9 -0
+/*
+ * Copyright (C) 2023 Sophgo Technology Inc. All rights reserved.
+ */
+
+#ifndef __DT_BINDINGS_CLOCK_SOPHGO_SG2042_H__
+#define __DT_BINDINGS_CLOCK_SOPHGO_SG2042_H__
+
+/* Divider clocks */
+#define DIV_CLK_MPLL_RP_CPU_NORMAL_0 0

Missing tabs before each value.

Best regards,
Krzysztof

author
#3 lore raw

PATCH v2 2/4 dt-bindings: soc: sophgo: Add Sophgo syscon module

In reply to Chen Wang

From: Chen Wang <[email protected]>

Add documentation to describe Sophgo System Controller Registers for SG2042.

---
 .../soc/sophgo/sophgo,sg2042-syscon.yaml      | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +58 -0
new file mode 100644
index 000000000000..329d645091b4
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/sophgo/sophgo,sg2042-syscon.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo SG2042 SoC system controller
+
+maintainers:
+  - Chen Wang <[email protected]>
+
+description:
+  The Sophgo SG2042 SoC system controller provides register information such
+  as offset, mask and shift to configure some modules, such as clocks, reset
+  signals and pinctrl.
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - sophgo,sg2042-syscon
+      - const: syscon
+
+  reg:
+    maxItems: 1
+
+  clock-controller:
+    # Child node
+    type: object
+    $ref: ../../clock/sophgo/sophgo,sg2042-clkgen.yaml
+    description:
+      Clock controller for the SoC clocks. This child node definition
+      should follow the bindings specified in
+      Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    syscon@30010000 {
+        compatible = "sophgo,sg2042-syscon", "syscon";
+        reg = <0x30010000 0x1000>;
+    };
+
+    syscon@30020000 {
+        compatible = "sophgo,sg2042-syscon", "syscon";
+        reg = <0x30020000 0x1000>;
+
+        clock-controller {
+            compatible = "sophgo,sg2042-clkgen";
+            clocks = <&osc>;
+            #clock-cells = <1>;
+        };
+    };
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v2 2/4] dt-bindings: soc: sophgo: Add Sophgo syscon module

Quoted 37 lines · Chen Wang

From: Chen Wang <[email protected]>

Add documentation to describe Sophgo System Controller Registers for SG2042.

---
 .../soc/sophgo/sophgo,sg2042-syscon.yaml      | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +20 -0
new file mode 100644
index 000000000000..329d645091b4
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/sophgo/sophgo,sg2042-syscon.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo SG2042 SoC system controller
+
+maintainers:
+  - Chen Wang <[email protected]>
+
+description:
+  The Sophgo SG2042 SoC system controller provides register information such
+  as offset, mask and shift to configure some modules, such as clocks, reset
+  signals and pinctrl.
+
+properties:
+  compatible:
+    items:
+      - enum:

Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml line 30

Quoted 10 lines
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +10 -0
+          - sophgo,sg2042-syscon
+      - const: syscon
+
+  reg:
+    maxItems: 1
+
+  clock-controller:
+    # Child node
+    type: object
+    $ref: ../../clock/sophgo/sophgo,sg2042-clkgen.yaml

Use full path, so /schemas/clock/
(look at other bindings how they do it)

Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml line 34

Quoted 4 lines
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +4 -0
+    description:
+      Clock controller for the SoC clocks. This child node definition
+      should follow the bindings specified in
+      Documentation/devicetree/bindings/clock/sophgo/sophgo,sg2042-clkgen.yaml

Drop description.

Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +4 -0
+
+required:
+  - compatible
+  - reg

clock-controller, no?

Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml line 50

Quoted 12 lines
Documentation/devicetree/bindings/soc/sophgo/sophgo,sg2042-syscon.yaml new file +12 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    syscon@30010000 {
+        compatible = "sophgo,sg2042-syscon", "syscon";
+        reg = <0x30010000 0x1000>;
+    };
+
+    syscon@30020000 {
+        compatible = "sophgo,sg2042-syscon", "syscon";

Wait, these are two different devices. Why do you use the same compatible for them? Is their register layout exactly the same?

Best regards,
Krzysztof

author
#5 lore raw

PATCH v2 3/4 clk: sophgo: Add SG2042 clock generator driver

In reply to Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

---
 MAINTAINERS                            |    7 +
 drivers/clk/Kconfig                    |    1 +
 drivers/clk/Makefile                   |    1 +
 drivers/clk/sophgo/Kconfig             |    8 +
 drivers/clk/sophgo/Makefile            |    2 +
 drivers/clk/sophgo/clk-sophgo-sg2042.c | 1357 ++++++++++++++++++++++++
 drivers/clk/sophgo/clk-sophgo-sg2042.h |  222 ++++
 7 files changed, 1598 insertions(+)
 create mode 100644 drivers/clk/sophgo/Kconfig
 create mode 100644 drivers/clk/sophgo/Makefile
 create mode 100644 drivers/clk/sophgo/clk-sophgo-sg2042.c
 create mode 100644 drivers/clk/sophgo/clk-sophgo-sg2042.h
MAINTAINERS +7 -0
index 97f51d5ec1cf..93187d59b498 100644
@@ -20269,6 +20269,13 @@ S:	Maintained
 F:	arch/riscv/boot/dts/sophgo/
 F:	Documentation/devicetree/bindings/riscv/sophgo.yaml
 
+SOPHGO CLOCK DRIVER
+M:	Chen Wang <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/clock/sophgo/
+F:	drivers/clk/sophgo/
+F:	include/dt-bindings/clock/sophgo-sg2042-clk.h
+
 SOUND
 M:	Jaroslav Kysela <[email protected]>
 M:	Takashi Iwai <[email protected]>
drivers/clk/Kconfig +1 -0
index c30d0d396f7a..514343934fda 100644
@@ -499,6 +499,7 @@ source "drivers/clk/rockchip/Kconfig"
 source "drivers/clk/samsung/Kconfig"
 source "drivers/clk/sifive/Kconfig"
 source "drivers/clk/socfpga/Kconfig"
+source "drivers/clk/sophgo/Kconfig"
 source "drivers/clk/sprd/Kconfig"
 source "drivers/clk/starfive/Kconfig"
 source "drivers/clk/sunxi/Kconfig"
drivers/clk/Makefile +1 -0
index ed71f2e0ee36..aa5d2cf0b6a6 100644
@@ -119,6 +119,7 @@ obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
 obj-$(CONFIG_COMMON_CLK_SAMSUNG)	+= samsung/
 obj-$(CONFIG_CLK_SIFIVE)		+= sifive/
 obj-y					+= socfpga/
+obj-$(CONFIG_ARCH_SOPHGO)		+= sophgo/
 obj-$(CONFIG_PLAT_SPEAR)		+= spear/
 obj-y					+= sprd/
 obj-$(CONFIG_ARCH_STI)			+= st/
drivers/clk/sophgo/Kconfig new file +8 -0
new file mode 100644
index 000000000000..b0fbe4499870
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config CLK_SOPHGO_SG2042
+	bool "Sophgo SG2042 clock support"
+	depends on ARCH_SOPHGO || COMPILE_TEST
+	default ARCH_SOPHGO
+	help
+	  Say yes here to support the clock controller on the Sophgo SG2042 SoC.
drivers/clk/sophgo/Makefile new file +2 -0
new file mode 100644
index 000000000000..13834cce260c
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_CLK_SOPHGO_SG2042)	+= clk-sophgo-sg2042.o
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +1357 -0

1,357 lines not on this page · raw message

drivers/clk/sophgo/clk-sophgo-sg2042.h new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

Quoted 49 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +49 -0
+static void __init sg2042_clk_init(struct device_node *node)
+{
+	struct sg2042_clk_data *clk_data = NULL;
+	int i, ret = 0;
+	int num_clks = 0;
+
+	num_clks = ARRAY_SIZE(sg2042_pll_clks) +
+		   ARRAY_SIZE(sg2042_div_clks) +
+		   ARRAY_SIZE(sg2042_gate_clks) +
+		   ARRAY_SIZE(sg2042_mux_clks);
+	if (num_clks == 0) {
+		ret = -EINVAL;
+		goto error_out;
+	}
+
+	ret = sg2042_clk_init_clk_data(node, num_clks, &clk_data);
+	if (ret < 0)
+		goto error_out;
+
+	ret = sg2042_clk_register_plls(clk_data, sg2042_pll_clks,
+				ARRAY_SIZE(sg2042_pll_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_divs(clk_data, sg2042_div_clks,
+				ARRAY_SIZE(sg2042_div_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_gates(clk_data, sg2042_gate_clks,
+				ARRAY_SIZE(sg2042_gate_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_muxs(clk_data, sg2042_mux_clks,
+				ARRAY_SIZE(sg2042_mux_clks));
+	if (ret)
+		goto cleanup;
+
+	for (i = 0; i < num_clks; i++)
+		dbg_info("provider [%d]: %s\n", i, clk_hw_get_name(clk_data->onecell_data.hws[i]));
+	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, &clk_data->onecell_data);
+	if (ret)
+		goto cleanup;
+
+	return;
+
+cleanup:
+	for (i = 0; i < num_clks; i++) {

drivers/clk/sophgo/clk-sophgo-sg2042.c line 1357

Quoted 10 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +10 -0
+		if (clk_data->onecell_data.hws[i] != NULL)
+			clk_hw_unregister(clk_data->onecell_data.hws[i]);
+	}
+	kfree(clk_data);
+
+error_out:
+	pr_err("%s failed error number %d\n", __func__, ret);
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

Quoted 4 lines
drivers/clk/sophgo/clk-sophgo-sg2042.h new file +0 -1
new file mode 100644
index 000000000000..ca1c8b9a937a
--- /dev/null

...

drivers/clk/sophgo/clk-sophgo-sg2042.h line 220

Quoted 8 lines
drivers/clk/sophgo/clk-sophgo-sg2042.h new file +8 -0
+#define to_sg2042_mux_nb(_nb) container_of(_nb, struct sg2042_mux_clock, clk_nb)
+
+#ifdef DEBUG
+	#define dbg_info(format, arg...) \
+		pr_info("--> %s: "format"", __func__, ## arg)
+#else
+	#define dbg_info(format, arg...)
+#endif

Drop custom debug prints.

drivers/clk/sophgo/clk-sophgo-sg2042.h line 222

Quoted 2 lines
drivers/clk/sophgo/clk-sophgo-sg2042.h new file +2 -0
+
+#endif /* __CLK_SOPHGO_SG2042_H */

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 61 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

Quoted 53 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +53 -0
+static void __init sg2042_clk_init(struct device_node *node)
+{
+	struct sg2042_clk_data *clk_data = NULL;
+	int i, ret = 0;
+	int num_clks = 0;
+
+	num_clks = ARRAY_SIZE(sg2042_pll_clks) +
+		   ARRAY_SIZE(sg2042_div_clks) +
+		   ARRAY_SIZE(sg2042_gate_clks) +
+		   ARRAY_SIZE(sg2042_mux_clks);
+	if (num_clks == 0) {
+		ret = -EINVAL;
+		goto error_out;
+	}
+
+	ret = sg2042_clk_init_clk_data(node, num_clks, &clk_data);
+	if (ret < 0)
+		goto error_out;
+
+	ret = sg2042_clk_register_plls(clk_data, sg2042_pll_clks,
+				ARRAY_SIZE(sg2042_pll_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_divs(clk_data, sg2042_div_clks,
+				ARRAY_SIZE(sg2042_div_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_gates(clk_data, sg2042_gate_clks,
+				ARRAY_SIZE(sg2042_gate_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_muxs(clk_data, sg2042_mux_clks,
+				ARRAY_SIZE(sg2042_mux_clks));
+	if (ret)
+		goto cleanup;
+
+	for (i = 0; i < num_clks; i++)
+		dbg_info("provider [%d]: %s\n", i, clk_hw_get_name(clk_data->onecell_data.hws[i]));
+	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, &clk_data->onecell_data);
+	if (ret)
+		goto cleanup;
+
+	return;
+
+cleanup:
+	for (i = 0; i < num_clks; i++) {
+		if (clk_data->onecell_data.hws[i] != NULL)
+			clk_hw_unregister(clk_data->onecell_data.hws[i]);
+	}
+	kfree(clk_data);
Quoted 8 lines

drivers/clk/sophgo/clk-sophgo-sg2042.c line 1357

Quoted 6 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +6 -0
+
+error_out:
+	pr_err("%s failed error number %d\n", __func__, ret);
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think this driver is still for platform device though I move the clock controller node as a child of the system contoller node. System controller node is just a block of registers which are used to control some other platform devices ,such as clock controller, reset controller and pin controller for this SoC.

And I also see other similar code in kernel, for example: drivers/clk/clk-k210.c.

And I'm confused by your input "so you cannot use other way of init ordering." Do you mean "so you CAN use other way of init ordering"? What's the other way of init ordering do you mean?

Thanks,

Chen

#8 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 72 lines · Chen Wang
Quoted 61 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

Quoted 53 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +53 -0
+static void __init sg2042_clk_init(struct device_node *node)
+{
+	struct sg2042_clk_data *clk_data = NULL;
+	int i, ret = 0;
+	int num_clks = 0;
+
+	num_clks = ARRAY_SIZE(sg2042_pll_clks) +
+		   ARRAY_SIZE(sg2042_div_clks) +
+		   ARRAY_SIZE(sg2042_gate_clks) +
+		   ARRAY_SIZE(sg2042_mux_clks);
+	if (num_clks == 0) {
+		ret = -EINVAL;
+		goto error_out;
+	}
+
+	ret = sg2042_clk_init_clk_data(node, num_clks, &clk_data);
+	if (ret < 0)
+		goto error_out;
+
+	ret = sg2042_clk_register_plls(clk_data, sg2042_pll_clks,
+				ARRAY_SIZE(sg2042_pll_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_divs(clk_data, sg2042_div_clks,
+				ARRAY_SIZE(sg2042_div_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_gates(clk_data, sg2042_gate_clks,
+				ARRAY_SIZE(sg2042_gate_clks));
+	if (ret)
+		goto cleanup;
+
+	ret = sg2042_clk_register_muxs(clk_data, sg2042_mux_clks,
+				ARRAY_SIZE(sg2042_mux_clks));
+	if (ret)
+		goto cleanup;
+
+	for (i = 0; i < num_clks; i++)
+		dbg_info("provider [%d]: %s\n", i, clk_hw_get_name(clk_data->onecell_data.hws[i]));
+	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, &clk_data->onecell_data);
+	if (ret)
+		goto cleanup;
+
+	return;
+
+cleanup:
+	for (i = 0; i < num_clks; i++) {
+		if (clk_data->onecell_data.hws[i] != NULL)
+			clk_hw_unregister(clk_data->onecell_data.hws[i]);
+	}
+	kfree(clk_data);
Quoted 8 lines

drivers/clk/sophgo/clk-sophgo-sg2042.c line 1357

Quoted 6 lines
drivers/clk/sophgo/clk-sophgo-sg2042.c new file +6 -0
+
+error_out:
+	pr_err("%s failed error number %d\n", __func__, ret);
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

Quoted 6 lines

hi, Krzysztof,

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

Quoted 11 lines

this driver is still for platform device though I move the clock controller node as a child of the system contoller node. System controller node is just a block of registers which are used to control some other platform devices ,such as clock controller, reset controller and pin controller for this SoC.

And I also see other similar code in kernel, for example:
drivers/clk/clk-k210.c.

And I'm confused by your input "so you cannot use other way of init ordering." Do you mean "so you CAN use other way of init ordering"?

No, I meant you cannot. If you want to use syscon, then your driver should be a proper driver. Therefore add a driver.

Quoted 1 line

What's the other way of init ordering do you mean?

The one coming not from initcalls but driver model.

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Chen Wang
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

drivers/clk/sophgo/clk-sophgo-sg2042.c new file +3 -0
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
Quoted 2 lines

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Quoted 8 lines
Quoted 4 lines

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

hi, Krzysztof,

I found that the initcall method cannot be used for the clock controller of sg2042. We need to initialize the clock earlier because there are two dw-apb-timers in sg2042 (Sorry, I have not added them in the current DTS of sg2042, will be submitted later). The initialization of these timers (timer_probe()) depends on the initialization of the clock controller. If we use the initcall mechanism, it will be too late for the timer. So it seems better to use CLK_OF_DECLARE provided by CCF.

I have a question here that I would like to discuss. The design of sg2042 is like this, according to the design of memorymap in its TRM:

070:3001:0000 ~ 070:3001:0FFF SYS_CTRL 4K 070:3001:1000 ~ 070:3001:1FFF PINMUX 4K 070:3001:2000 ~ 070:3001:2FFF CLOCK 4K 070:3001:3000 ~ 070:3001:3FFF RESET 4K

But also as per hw design (I don't know why and I don't like it also :( ), some of the PLL/GATE CLOCK control registers are defined in the scope of SYS_CTRL, and others are defined in the scope of CLOCK. That's why in the current code, I define the syscon node corresponding to SYS_CTRL. The purpose is just to get the regmap of syscon for the clock controller through the device tree (through device_node_to_regmap()), so that the syscon defined in SYS_CTRL can be accessed through the regmap from clock. The clock controller driver itself does not rely on other operations of syscon.

So based on the above analysis, is it still necessary for us to define the clock controller as a child node of syscon? In the version v1 of this patch, I actually did not define the clock controller as a child node of syscon, but only accessed syscon through the phandle method. [1]

After more read of the TRM, I believe this situation only exists for clock. That is to say, there will be only one child node of clook under syscon. From a hardware design perspective, CLOCK and SYS_CTRL are two different blocks. So I think it is better to restore the original method, that is, restore clock and syscon to nodes of the same level, and let clock use phandle to access syscon.

What do you think or do you have any good suggestions?

Thanks

Chen

Quoted 21 lines
Quoted 7 lines

this driver is still for platform device though I move the clock controller node as a child of the system contoller node. System controller node is just a block of registers which are used to control some other platform devices ,such as clock controller, reset controller and pin controller for this SoC.

Quoted 5 lines

And I also see other similar code in kernel, for example:
drivers/clk/clk-k210.c.

And I'm confused by your input "so you cannot use other way of init ordering." Do you mean "so you CAN use other way of init ordering"?

No, I meant you cannot. If you want to use syscon, then your driver should be a proper driver. Therefore add a driver.

Quoted 1 line

What's the other way of init ordering do you mean?

The one coming not from initcalls but driver model.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 30 lines · Chen Wang
Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Chen Wang
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

drivers/clk/sophgo/clk-sophgo-sg2042.c new file +3 -0
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
Quoted 2 lines

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Quoted 8 lines
Quoted 4 lines

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

hi, Krzysztof,

Quoted 7 lines

I found that the initcall method cannot be used for the clock controller of sg2042. We need to initialize the clock earlier because there are two dw-apb-timers in sg2042 (Sorry, I have not added them in the current DTS of sg2042, will be submitted later). The initialization of these timers (timer_probe()) depends on the initialization of the clock controller. If we use the initcall mechanism, it will be too late for the timer. So it seems better to use CLK_OF_DECLARE provided by CCF.

Sure, that's fine, but don't use syscon in such case.

Quoted 19 lines

I have a question here that I would like to discuss. The design of sg2042 is like this, according to the design of memorymap in its TRM:

070:3001:0000 ~ 070:3001:0FFF SYS_CTRL 4K
070:3001:1000 ~ 070:3001:1FFF PINMUX 4K
070:3001:2000 ~ 070:3001:2FFF CLOCK 4K
070:3001:3000 ~ 070:3001:3FFF RESET 4K

But also as per hw design (I don't know why and I don't like it also :( ), some of the PLL/GATE CLOCK control registers are defined in the scope of SYS_CTRL, and others are defined in the scope of CLOCK. That's why in the current code, I define the syscon node corresponding to SYS_CTRL. The purpose is just to get the regmap of syscon for the clock controller through the device tree (through device_node_to_regmap()), so that the syscon defined in SYS_CTRL can be accessed through the regmap from clock. The clock controller driver itself does not rely on other operations of syscon.

Quoted 4 lines

So based on the above analysis, is it still necessary for us to define the clock controller as a child node of syscon? In the version v1 of this patch, I actually did not define the clock controller as a child node of syscon, but only accessed syscon through the phandle method. [1]

I have impression you ask me if your solution is ok, but I already pointed the problem. Address the problem - how do you enforce ordering of syscon and CLK_OF_DECLARE? What initcalls are both?

Quoted 9 lines

After more read of the TRM, I believe this situation only exists for clock. That is to say, there will be only one child node of clook under syscon. From a hardware design perspective, CLOCK and SYS_CTRL are two different blocks. So I think it is better to restore the original method, that is, restore clock and syscon to nodes of the same level, and let clock use phandle to access syscon.

What do you think or do you have any good suggestions?

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 29 lines · Krzysztof Kozlowski
Quoted 28 lines · Chen Wang
Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Chen Wang
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

drivers/clk/sophgo/clk-sophgo-sg2042.c new file +3 -0
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
Quoted 2 lines

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Quoted 8 lines
Quoted 4 lines

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

hi, Krzysztof,

Quoted 8 lines
Quoted 7 lines

I found that the initcall method cannot be used for the clock controller of sg2042. We need to initialize the clock earlier because there are two dw-apb-timers in sg2042 (Sorry, I have not added them in the current DTS of sg2042, will be submitted later). The initialization of these timers (timer_probe()) depends on the initialization of the clock controller. If we use the initcall mechanism, it will be too late for the timer. So it seems better to use CLK_OF_DECLARE provided by CCF.

Sure, that's fine, but don't use syscon in such case.

Yes, syscon is inappropriate. As per suggestion from Conor in anther email, I will define a sg2042 specific sysctl to handle this.

Quoted 39 lines
Quoted 19 lines

I have a question here that I would like to discuss. The design of sg2042 is like this, according to the design of memorymap in its TRM:

070:3001:0000 ~ 070:3001:0FFF SYS_CTRL 4K
070:3001:1000 ~ 070:3001:1FFF PINMUX 4K
070:3001:2000 ~ 070:3001:2FFF CLOCK 4K
070:3001:3000 ~ 070:3001:3FFF RESET 4K

But also as per hw design (I don't know why and I don't like it also :( ), some of the PLL/GATE CLOCK control registers are defined in the scope of SYS_CTRL, and others are defined in the scope of CLOCK. That's why in the current code, I define the syscon node corresponding to SYS_CTRL. The purpose is just to get the regmap of syscon for the clock controller through the device tree (through device_node_to_regmap()), so that the syscon defined in SYS_CTRL can be accessed through the regmap from clock. The clock controller driver itself does not rely on other operations of syscon.

Quoted 4 lines

So based on the above analysis, is it still necessary for us to define the clock controller as a child node of syscon? In the version v1 of this patch, I actually did not define the clock controller as a child node of syscon, but only accessed syscon through the phandle method. [1]

I have impression you ask me if your solution is ok, but I already pointed the problem. Address the problem - how do you enforce ordering of syscon and CLK_OF_DECLARE? What initcalls are both?

Quoted 8 lines

After more read of the TRM, I believe this situation only exists for clock. That is to say, there will be only one child node of clook under syscon. From a hardware design perspective, CLOCK and SYS_CTRL are two different blocks. So I think it is better to restore the original method, that is, restore clock and syscon to nodes of the same level, and let clock use phandle to access syscon.

What do you think or do you have any good suggestions?

Best regards,
Krzysztof

#12 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

In reply to Chen Wang
Quoted 55 lines · Chen Wang
Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Chen Wang
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

drivers/clk/sophgo/clk-sophgo-sg2042.c new file +3 -0
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
Quoted 2 lines

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Quoted 8 lines
Quoted 4 lines

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

hi, Krzysztof,

I found that the initcall method cannot be used for the clock controller of sg2042. We need to initialize the clock earlier because there are two dw-apb-timers in sg2042 (Sorry, I have not added them in the current DTS of sg2042, will be submitted later). The initialization of these timers (timer_probe()) depends on the initialization of the clock controller. If we use the initcall mechanism, it will be too late for the timer. So it seems better to use CLK_OF_DECLARE provided by CCF.

I have a question here that I would like to discuss. The design of sg2042 is like this, according to the design of memorymap in its TRM:

070:3001:0000 ~ 070:3001:0FFF SYS_CTRL 4K
070:3001:1000 ~ 070:3001:1FFF PINMUX 4K
070:3001:2000 ~ 070:3001:2FFF CLOCK 4K
070:3001:3000 ~ 070:3001:3FFF RESET 4K

But also as per hw design (I don't know why and I don't like it also :( ), some of the PLL/GATE CLOCK control registers are defined in the scope of SYS_CTRL, and others are defined in the scope of CLOCK. That's why in the current code, I define the syscon node corresponding to SYS_CTRL. The purpose is just to get the regmap of syscon for the clock controller through the device tree (through device_node_to_regmap()), so that the syscon defined in SYS_CTRL can be accessed through the regmap from clock. The clock controller driver itself does not rely on other operations of syscon.

Quoted 4 lines

So based on the above analysis, is it still necessary for us to define the clock controller as a child node of syscon? In the version v1 of this patch, I actually did not define the clock controller as a child node of syscon, but only accessed syscon through the phandle method. [1]

In that version of the code, clkgen, your DTS, looked like:
+ clkgen: clock-controller {
+ compatible = "sophgo,sg2042-clkgen";
+ #clock-cells = <1>;
+ system-ctrl = <&sys_ctrl>;
+ clocks = <&cgi>;
+ assigned-clocks = \

+ assigned-clock-rates = \

+ };

It had no register regions of its own, just what it got from the sys ctrl block, which is why I said that. The syscon block looked like:

+ sys_ctrl: syscon@7030010000 {
+ compatible = "sophgo,sg2042-syscon", "syscon";
+ reg = <0x70 0x30010000 0x0 0x8000>;
+ };

which given the register map does not seem like an accurate reflection of the size of this region. The "0x8000" should be "0x1000".

Quoted 7 lines

After more read of the TRM, I believe this situation only exists for clock. That is to say, there will be only one child node of clook under syscon. From a hardware design perspective, CLOCK and SYS_CTRL are two different blocks. So I think it is better to restore the original method, that is, restore clock and syscon to nodes of the same level, and let clock use phandle to access syscon.

This sounds two me like there are two different devices. One the "CLOCK" region at 070:3001:2000 that should be documented as being "sophgo,sg2042-clkgen" or similar and the second being the "SYS_CTRL" at 070:3001:0000 that is called something like "sophgo,sg2042-sysctrl". Having more than one clock controller is not a problem and sounds like a more accurate description of the hardware.

Quoted 31 lines

What do you think or do you have any good suggestions?

Thanks

Chen

Quoted 21 lines
Quoted 7 lines

this driver is still for platform device though I move the clock controller node as a child of the system contoller node. System controller node is just a block of registers which are used to control some other platform devices ,such as clock controller, reset controller and pin controller for this SoC.

Quoted 5 lines

And I also see other similar code in kernel, for example:
drivers/clk/clk-k210.c.

And I'm confused by your input "so you cannot use other way of init ordering." Do you mean "so you CAN use other way of init ordering"?

No, I meant you cannot. If you want to use syscon, then your driver should be a proper driver. Therefore add a driver.

Quoted 1 line

What's the other way of init ordering do you mean?

The one coming not from initcalls but driver model.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v2 3/4] clk: sophgo: Add SG2042 clock generator driver

Quoted 78 lines · Conor Dooley
Quoted 53 lines · Chen Wang
Quoted 17 lines · Krzysztof Kozlowski
Quoted 16 lines · Chen Wang
Quoted 11 lines · Krzysztof Kozlowski
Quoted 5 lines · Chen Wang

From: Chen Wang <[email protected]>

Add a driver for the SOPHGO SG2042 clock generator.

...

drivers/clk/sophgo/clk-sophgo-sg2042.c new file +3 -0
+}
+
+CLK_OF_DECLARE(sg2042_clk, "sophgo,sg2042-clkgen", sg2042_clk_init);
Quoted 2 lines

No, this should be platform device. It's a child of another device, so you cannot use other way of init ordering.

hi, Krzysztof,

Quoted 8 lines
Quoted 4 lines

Thanks for your review.

I don't quite understand your opinion. Do you mean CLK_OF_DECLARE is only used for platform device so it can not be use here? But I think

No, I meant you mix init ordering: you depend now on syscon earlier initcall than CLK_OF_DECLARE. Do you remember which one is first? If anything changes here, your driver is broken. There is no dependency, no probe deferral.

hi, Krzysztof,

I found that the initcall method cannot be used for the clock controller of sg2042. We need to initialize the clock earlier because there are two dw-apb-timers in sg2042 (Sorry, I have not added them in the current DTS of sg2042, will be submitted later). The initialization of these timers (timer_probe()) depends on the initialization of the clock controller. If we use the initcall mechanism, it will be too late for the timer. So it seems better to use CLK_OF_DECLARE provided by CCF.

I have a question here that I would like to discuss. The design of sg2042 is like this, according to the design of memorymap in its TRM:

070:3001:0000 ~ 070:3001:0FFF SYS_CTRL 4K
070:3001:1000 ~ 070:3001:1FFF PINMUX 4K
070:3001:2000 ~ 070:3001:2FFF CLOCK 4K
070:3001:3000 ~ 070:3001:3FFF RESET 4K

But also as per hw design (I don't know why and I don't like it also :( ), some of the PLL/GATE CLOCK control registers are defined in the scope of SYS_CTRL, and others are defined in the scope of CLOCK. That's why in the current code, I define the syscon node corresponding to SYS_CTRL. The purpose is just to get the regmap of syscon for the clock controller through the device tree (through device_node_to_regmap()), so that the syscon defined in SYS_CTRL can be accessed through the regmap from clock. The clock controller driver itself does not rely on other operations of syscon.

Quoted 4 lines

So based on the above analysis, is it still necessary for us to define the clock controller as a child node of syscon? In the version v1 of this patch, I actually did not define the clock controller as a child node of syscon, but only accessed syscon through the phandle method. [1]

In that version of the code, clkgen, your DTS, looked like:

(quoted diff) +8 -0
+	clkgen: clock-controller {
+		compatible = "sophgo,sg2042-clkgen";
+		#clock-cells = <1>;
+		system-ctrl = <&sys_ctrl>;
+		clocks = <&cgi>;
+		assigned-clocks = \
 
+		assigned-clock-rates = \
 
+	};

It had no register regions of its own, just what it got from the sys ctrl block, which is why I said that. The syscon block looked like:

(quoted diff) +4 -0
+		sys_ctrl: syscon@7030010000 {
+			compatible = "sophgo,sg2042-syscon", "syscon";
+			reg = <0x70 0x30010000 0x0 0x8000>;
+		};
Quoted 2 lines

which given the register map does not seem like an accurate reflection of the size of this region. The "0x8000" should be "0x1000".

Thanks for your carefully checking.

The history is when I was working on v1, the description in TRM was:

070:3001:0000 ~ 070:3001:7FFF SYS_CTRL 32K

Now the TRM is updated and the SYS_CTRL is divided into 4 parts.

Quoted 6 lines
Quoted 6 lines

After more read of the TRM, I believe this situation only exists for clock. That is to say, there will be only one child node of clook under syscon.
From a hardware design perspective, CLOCK and SYS_CTRL are two different
blocks. So I think it is better to restore the original method, that is, restore clock and syscon to nodes of the same level, and let clock use phandle to access syscon.

Quoted 6 lines

This sounds two me like there are two different devices. One the "CLOCK" region at 070:3001:2000 that should be documented as being "sophgo,sg2042-clkgen" or similar and the second being the "SYS_CTRL" at 070:3001:0000 that is called something like "sophgo,sg2042-sysctrl". Having more than one clock controller is not a problem and sounds like a more accurate description of the hardware.

Yes, I agree a new "sg2042-sysctrl" is better and "syscon" should not be used as per input from Krzysztof.

Actually in the TRM, the "SYS_CTRL" is described as a block composed of many registers for different misc functions, and controlling of clocks are just part of it. The hw designer scatter clock registers into differnet area of registers and make people confused.

Quoted 30 lines
Quoted 30 lines

What do you think or do you have any good suggestions?

Thanks

Chen

Quoted 20 lines
Quoted 11 lines

this driver is still for platform device though I move the clock controller node as a child of the system contoller node. System controller node is just a block of registers which are used to control some other platform devices ,such as clock controller, reset controller and pin controller for this SoC.

And I also see other similar code in kernel, for example:
drivers/clk/clk-k210.c.

And I'm confused by your input "so you cannot use other way of init ordering." Do you mean "so you CAN use other way of init ordering"?

No, I meant you cannot. If you want to use syscon, then your driver should be a proper driver. Therefore add a driver.

Quoted 1 line

What's the other way of init ordering do you mean?

The one coming not from initcalls but driver model.

Best regards,
Krzysztof

author
#14 lore raw

PATCH v2 4/4 riscv: dts: add clock generator for Sophgo SG2042 SoC

In reply to Chen Wang

From: Chen Wang <[email protected]>

Add clock generator node to device tree for SG2042, and enable clock for uart.

---
 .../boot/dts/sophgo/sg2042-milkv-pioneer.dts  |  4 +
 arch/riscv/boot/dts/sophgo/sg2042.dtsi        | 77 +++++++++++++++++++
 2 files changed, 81 insertions(+)
arch/riscv/boot/dts/sophgo/sg2042-milkv-pioneer.dts +4 -0
index 49b4b9c2c101..0b3b3b2b0c64 100644
@@ -14,6 +14,10 @@ chosen {
 	};
 };
 
+&cgi {
+	clock-frequency = <25000000>;
+};
+
 &uart0 {
 	status = "okay";
 };
arch/riscv/boot/dts/sophgo/sg2042.dtsi +77 -0

101 lines not on this page · raw message

Signature · 1 line
2.25.1