Skip to contentSkip to conversation

clk: realtek: Add RTD1625 clock support

PATCH New Yu-Chun Lin 1 participant 10 messages Nov 24

Subsystems (3)
lore
Share & tools
lore

Yu-Chun Lin

author maintainer
#0 lore raw

v17 cover clk: realtek: Add RTD1625 clock support

Hello,

This patch series adds the clock controller support for Realtek's RTD1625 SoC platform.

Because the reset controllers share the same register space with the clock controllers on this platform, we utilize the Auxiliary Bus framework to decouple them. The clock controllers act as the primary devices, registering the reset controllers as auxiliary devices.

The series includes:
1. Device Tree Bindings:
- Add bindings for the Realtek RTD1625 Clock & Reset Controllers.

2. Clock Subsystem Infrastructure:
- Introduce a common probe, and add support for basic clocks including PLLs, gate clocks, mux clocks, and MMC-tuned PLLs.

3. Clock Platform Drivers:
- Add the clock controller drivers for RTD1625-CRT and RTD1625-ISO.
- These drivers provide the clock sources and instantiate the corresponding auxiliary reset devices.

Best regards,
Yu-Chun Lin
---
Changes in v17:

Patch 1 (dt-binding):
- Move the 'clocks' and 'clock-names' item descriptions to the top level, and keep only the item counts in the if/else branches.

Patch 2:
- Make the "Realtek Clock Common" Kconfig symbol a bare tristate and drop its prompt and help text.
- Change the type of aux_name from 'char *' to 'const char *'.

Patch 3 (PLL):
- Move the power-on sequence from '.enable()' to '.prepare()', and use 'regmap_read_poll_timeout()' instead of the atomic variant: 'wait_freq_ready()' can take up to 500 us, which is too long to busy-wait in atomic context.
- Drop the spinlock now that '.prepare()', '.unprepare()' and '.set_rate()' are all serialized by 'prepare_lock'.
- Turn 'ftbl_find_closest_by_rate()' into a macro so that tables other than 'struct rtk_freq_table' can use it.

Patch 4 (GATE):
- Return 0 instead of the error code from '.is_enabled()'.

Patch 6 (MMC PLL):
- Reuse the 'ftbl_find_closest_by_rate()' macro and drop the local duplicate.
- Make 'rate_tbl' optional and add a built-in default table, which also covers the SPI-NAND operating point at 99,999,206 Hz.
- Add an 'ssc' flag to 'struct rtk_clk_pll_mmc_rate', so that the SSC analog registers are left untouched in SPI-NAND mode.
- Replace 'shift' with 'phsel_mask' in 'struct rtk_clk_pll_mmc_phase', and use 'field_prep()'/'field_get()'.
- '.recalc_rate()' always computes the rate from the dividers instead of reverse-matching the rate table.

Patch 7 (CRT):
Add '.suppress_bind_attrs = true'

v16: https://lore.kernel.org/lkml/[email protected]/
v15: https://lore.kernel.org/lkml/[email protected]/
v14: https://lore.kernel.org/lkml/[email protected]/
v13: https://lore.kernel.org/lkml/[email protected]/
v12: https://lore.kernel.org/lkml/[email protected]/
v11: https://lore.kernel.org/lkml/[email protected]/
v10: https://lore.kernel.org/lkml/[email protected]/
v9: https://lore.kernel.org/lkml/[email protected]/
v8: https://lore.kernel.org/lkml/[email protected]/
v7: https://lore.kernel.org/lkml/[email protected]/
v6: https://lore.kernel.org/lkml/[email protected]/
v5: https://lore.kernel.org/lkml/[email protected]/
v4: https://lore.kernel.org/lkml/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

Cheng-Yu Lee (7):
clk: realtek: Introduce common probe()
clk: realtek: Add support for phase locked loops (PLLs)
clk: realtek: Add support for gate clock
clk: realtek: Add support for mux clock
clk: realtek: Add support for MMC-tuned PLL clocks
clk: realtek: Add RTD1625-CRT clock controller driver
clk: realtek: Add RTD1625-ISO clock controller driver

Yu-Chun Lin (2):
dt-bindings: clock: Add Realtek RTD1625 Clock & Reset Controller
arm64: dts: realtek: Add clock support for RTD1625

 .../bindings/clock/realtek,rtd1625-clk.yaml   |  93 ++
 MAINTAINERS                                   |   7 +
 arch/arm64/boot/dts/realtek/kent.dtsi         |  41 +
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/realtek/Kconfig                   |  39 +
 drivers/clk/realtek/Makefile                  |  12 +
 drivers/clk/realtek/clk-regmap-gate.c         |  59 ++
 drivers/clk/realtek/clk-regmap-gate.h         |  54 ++
 drivers/clk/realtek/clk-regmap-mux.c          |  40 +
 drivers/clk/realtek/clk-regmap-mux.h          |  42 +
 drivers/clk/realtek/clk-regmap-pll-mmc.c      | 443 +++++++++
 drivers/clk/realtek/clk-regmap-pll-mmc.h      |  69 ++
 drivers/clk/realtek/clk-regmap-pll.c          | 177 ++++
 drivers/clk/realtek/clk-regmap-pll.h          |  44 +
 drivers/clk/realtek/clk-rtd1625-crt.c         | 859 ++++++++++++++++++
 drivers/clk/realtek/clk-rtd1625-iso.c         | 140 +++
 drivers/clk/realtek/clk-rtk-common.c          |  84 ++
 drivers/clk/realtek/clk-rtk-common.h          |  37 +
 drivers/clk/realtek/freq_table.c              |  39 +
 drivers/clk/realtek/freq_table.h              |  45 +
 .../dt-bindings/clock/realtek,rtd1625-clk.h   | 166 ++++
 22 files changed, 2492 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/realtek,rtd1625-clk.yaml
 create mode 100644 drivers/clk/realtek/Kconfig
 create mode 100644 drivers/clk/realtek/Makefile
 create mode 100644 drivers/clk/realtek/clk-regmap-gate.c
 create mode 100644 drivers/clk/realtek/clk-regmap-gate.h
 create mode 100644 drivers/clk/realtek/clk-regmap-mux.c
 create mode 100644 drivers/clk/realtek/clk-regmap-mux.h
 create mode 100644 drivers/clk/realtek/clk-regmap-pll-mmc.c
 create mode 100644 drivers/clk/realtek/clk-regmap-pll-mmc.h
 create mode 100644 drivers/clk/realtek/clk-regmap-pll.c
 create mode 100644 drivers/clk/realtek/clk-regmap-pll.h
 create mode 100644 drivers/clk/realtek/clk-rtd1625-crt.c
 create mode 100644 drivers/clk/realtek/clk-rtd1625-iso.c
 create mode 100644 drivers/clk/realtek/clk-rtk-common.c
 create mode 100644 drivers/clk/realtek/clk-rtk-common.h
 create mode 100644 drivers/clk/realtek/freq_table.c
 create mode 100644 drivers/clk/realtek/freq_table.h
 create mode 100644 include/dt-bindings/clock/realtek,rtd1625-clk.h
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v17 1/9 dt-bindings: clock: Add Realtek RTD1625 Clock & Reset Controller

Add DT binding schema for Realtek RTD1625 clock and reset controller

---
The reset IDs have been accepted:
https://lore.kernel.org/lkml/[email protected]/

Changes in v17:
- Move the 'clocks' and 'clock-names' item descriptions to the top level, and keep only the item counts in the if/else branches.

---
 .../bindings/clock/realtek,rtd1625-clk.yaml   |  93 ++++++++++
 MAINTAINERS                                   |   6 +
 .../dt-bindings/clock/realtek,rtd1625-clk.h   | 166 ++++++++++++++++++
 3 files changed, 265 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/realtek,rtd1625-clk.yaml
 create mode 100644 include/dt-bindings/clock/realtek,rtd1625-clk.h
Documentation/devicetree/bindings/clock/realtek,rtd1625-clk.yaml new file +93 -0
new file mode 100644
index 000000000000..d126e07b6729
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/realtek,rtd1625-clk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek RTD1625 Clock & Reset Controller
+
+maintainers:
+  - Cheng-Yu Lee <[email protected]>
+  - Yu-Chun Lin <[email protected]>
+
+description:
+  The Realtek RTD1625 Clock Controller manages and distributes clock
+  signals to various controllers and implements a Reset Controller for the
+  SoC peripherals.
+
+properties:
+  compatible:
+    enum:
+      - realtek,rtd1625-crt-clk
+      - realtek,rtd1625-iso-clk
+      - realtek,rtd1625-iso-s-clk
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    minItems: 1
+    items:
+      - description: External 27 MHz oscillator
+      - description: CRT SYS clock input
+      - description: CRT SYSH clock input
+      - description: CRT DDSA divide-by-four clock input
+      - description: CRT miscellaneous gate clock input
+
+  clock-names:
+    minItems: 1
+    items:
+      - const: osc27m
+      - const: clk_sys
+      - const: clk_sysh
+      - const: clk_ddsa_div4
+      - const: clk_en_misc
+
+  "#clock-cells":
+    const: 1
+
+  "#reset-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - "#clock-cells"
+  - "#reset-cells"
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          const: realtek,rtd1625-iso-clk
+
+    then:
+      properties:
+        clocks:
+          minItems: 5
+
+        clock-names:
+          minItems: 5
+
+    else:
+      properties:
+        clocks:
+          maxItems: 1
+
+        clock-names:
+          maxItems: 1
+
+additionalProperties: false
+
+examples:
+  - |
+    clock-controller@98000000 {
+      compatible = "realtek,rtd1625-crt-clk";
+      reg = <0x98000000 0x1000>;
+      clocks = <&osc27m>;
+      clock-names = "osc27m";
+      #clock-cells = <1>;
+      #reset-cells = <1>;
+    };
MAINTAINERS +6 -0
index 93abbb315065..c51f9fc157c8 100644
@@ -23537,6 +23537,12 @@ S:	Maintained
 F:	include/sound/rt*.h
 F:	sound/soc/codecs/rt*
 
+REALTEK CLOCK DRIVERS
+M:	Cheng-Yu Lee <[email protected]>
+M:	Yu-Chun Lin <[email protected]>
+S:	Supported
+F:	include/dt-bindings/clock/realtek*
+
 REALTEK OTTO WATCHDOG
 M:	Sander Vanheule <[email protected]>
 L:	[email protected]
include/dt-bindings/clock/realtek,rtd1625-clk.h new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v17 2/9 clk: realtek: Introduce common probe()

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Add rtk_clk_probe() to set up the shared regmap, register clock hardware, and add the clock provider.

Additionally, if the "#reset-cells" property is present in the device tree, it creates and registers an auxiliary device using the provided aux_name. This allows the dedicated reset driver to bind to this device, enabling both clock and reset drivers to share the same regmap.

---
Changes in v17:
- Make the "Realtek Clock Common" Kconfig symbol a bare tristate and drop its prompt and help text.
- Change the type of aux_name from 'char *' to 'const char *'.

---
 MAINTAINERS                          |  1 +
 drivers/clk/Kconfig                  |  1 +
 drivers/clk/Makefile                 |  1 +
 drivers/clk/realtek/Kconfig          | 22 ++++++++
 drivers/clk/realtek/Makefile         |  4 ++
 drivers/clk/realtek/clk-rtk-common.c | 84 ++++++++++++++++++++++++++++
 drivers/clk/realtek/clk-rtk-common.h | 37 ++++++++++++
 7 files changed, 150 insertions(+)
 create mode 100644 drivers/clk/realtek/Kconfig
 create mode 100644 drivers/clk/realtek/Makefile
 create mode 100644 drivers/clk/realtek/clk-rtk-common.c
 create mode 100644 drivers/clk/realtek/clk-rtk-common.h
MAINTAINERS +1 -0
index c51f9fc157c8..54873a33038b 100644
@@ -23541,6 +23541,7 @@ REALTEK CLOCK DRIVERS
 M:	Cheng-Yu Lee <[email protected]>
 M:	Yu-Chun Lin <[email protected]>
 S:	Supported
+F:	drivers/clk/realtek/*
 F:	include/dt-bindings/clock/realtek*
 
 REALTEK OTTO WATCHDOG
drivers/clk/Kconfig +1 -0
index 37a8e35d4178..eb9256459251 100644
@@ -532,6 +532,7 @@ source "drivers/clk/nuvoton/Kconfig"
 source "drivers/clk/pistachio/Kconfig"
 source "drivers/clk/qcom/Kconfig"
 source "drivers/clk/ralink/Kconfig"
+source "drivers/clk/realtek/Kconfig"
 source "drivers/clk/renesas/Kconfig"
 source "drivers/clk/rockchip/Kconfig"
 source "drivers/clk/samsung/Kconfig"
drivers/clk/Makefile +1 -0
index 52d138d4ffc8..3930bf20667b 100644
@@ -156,6 +156,7 @@ obj-$(CONFIG_COMMON_CLK_PISTACHIO)	+= pistachio/
 obj-$(CONFIG_COMMON_CLK_PXA)		+= pxa/
 obj-$(CONFIG_COMMON_CLK_QCOM)		+= qcom/
 obj-y					+= ralink/
+obj-$(CONFIG_COMMON_CLK_REALTEK)	+= realtek/
 obj-y					+= renesas/
 obj-$(CONFIG_COMMON_CLK_ROCKCHIP)	+= rockchip/
 obj-$(CONFIG_COMMON_CLK_SAMSUNG)	+= samsung/
drivers/clk/realtek/Kconfig new file +22 -0
new file mode 100644
index 000000000000..fc16fd71c50b
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config COMMON_CLK_REALTEK
+	tristate "Clock driver for Realtek SoCs"
+	depends on ARCH_REALTEK || COMPILE_TEST
+	default ARCH_REALTEK
+	help
+	  Enable the common clock framework infrastructure for Realtek
+	  system-on-chip platforms.
+
+	  This provides the base support required by individual Realtek
+	  clock controller drivers to expose clocks to peripheral devices.
+
+	  If you have a Realtek-based platform, say Y.
+
+if COMMON_CLK_REALTEK
+
+config RTK_CLK_COMMON
+	tristate
+	select AUXILIARY_BUS
+	select REGMAP_MMIO
+
+endif
drivers/clk/realtek/Makefile new file +4 -0
new file mode 100644
index 000000000000..13000ed4ba11
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
+
+clk-rtk-y += clk-rtk-common.o
drivers/clk/realtek/clk-rtk-common.c new file +84 -0

84 lines not on this page · raw message

drivers/clk/realtek/clk-rtk-common.h new file +37 -0
new file mode 100644
index 000000000000..ff9eb7bfff7b
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2016-2026 Realtek Semiconductor Corporation
+ * Author: Cheng-Yu Lee <[email protected]>
+ */
+
+#ifndef __CLK_REALTEK_COMMON_H
+#define __CLK_REALTEK_COMMON_H
+
+#include <linux/clk-provider.h>
+
+#define __rtk_clk_regmap_hw(_p) ((_p)->hw)
+
+struct device;
+struct platform_device;
+struct regmap;
+
+struct rtk_clk_regmap {
+	struct clk_hw hw;
+	struct regmap *regmap;
+};
+
+struct rtk_clk_desc {
+	struct clk_hw_onecell_data *clk_data;
+	struct rtk_clk_regmap **clks;
+	size_t num_clks;
+	const char *aux_name;
+};
+
+static inline struct rtk_clk_regmap *to_rtk_clk_regmap(struct clk_hw *hw)
+{
+	return container_of(hw, struct rtk_clk_regmap, hw);
+}
+
+int rtk_clk_probe(struct platform_device *pdev, const struct rtk_clk_desc *desc);
+
+#endif /* __CLK_REALTEK_COMMON_H */
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v17 3/9 clk: realtek: Add support for phase locked loops (PLLs)

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Provide a full set of PLL operations for programmable PLLs and a read-only variant for fixed or hardware-managed PLLs.

---
Changes in v17:
- Move the power-on sequence from '.enable()' to '.prepare()', and use 'regmap_read_poll_timeout()' instead of the atomic variant: 'wait_freq_ready()' can take up to 500 us, which is too long to busy-wait in atomic context.
- Drop the spinlock now that '.prepare()', '.unprepare()' and '.set_rate()' are all serialized by 'prepare_lock'.
- Turn 'ftbl_find_closest_by_rate()' into a macro so that tables other than 'struct rtk_freq_table' can use it.

---
 drivers/clk/realtek/Makefile         |   2 +
 drivers/clk/realtek/clk-regmap-pll.c | 177 +++++++++++++++++++++++++++
 drivers/clk/realtek/clk-regmap-pll.h |  44 +++++++
 drivers/clk/realtek/freq_table.c     |  38 ++++++
 drivers/clk/realtek/freq_table.h     |  45 +++++++
 5 files changed, 306 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-regmap-pll.c
 create mode 100644 drivers/clk/realtek/clk-regmap-pll.h
 create mode 100644 drivers/clk/realtek/freq_table.c
 create mode 100644 drivers/clk/realtek/freq_table.h
drivers/clk/realtek/Makefile +2 -0
index 13000ed4ba11..6fbe6e07b760 100644
@@ -2,3 +2,5 @@
 obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
 
 clk-rtk-y += clk-rtk-common.o
+clk-rtk-y += clk-regmap-pll.o
+clk-rtk-y += freq_table.o
drivers/clk/realtek/clk-regmap-pll.c new file +177 -0

177 lines not on this page · raw message

drivers/clk/realtek/clk-regmap-pll.h new file +44 -0

44 lines not on this page · raw message

drivers/clk/realtek/freq_table.c new file +38 -0
new file mode 100644
index 000000000000..3446657a437b
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/types.h>
+#include "freq_table.h"
+
+#define IS_FREQ_TABLE_END(_f) ((_f)->rate == 0)
+
+const struct rtk_freq_table *ftbl_find_by_rate(const struct rtk_freq_table *ftbl,
+					       unsigned long rate)
+{
+	const struct rtk_freq_table *best = NULL;
+	unsigned long best_rate = 0;
+
+	for (; !IS_FREQ_TABLE_END(ftbl); ftbl++) {
+		if (ftbl->rate == rate)
+			return ftbl;
+
+		if (ftbl->rate > rate)
+			continue;
+
+		if (ftbl->rate > best_rate) {
+			best_rate = ftbl->rate;
+			best = ftbl;
+		}
+	}
+
+	return best;
+}
+
+const struct rtk_freq_table *ftbl_find_by_val_with_mask(const struct rtk_freq_table *ftbl,
+							u32 mask, u32 value)
+{
+	for (; !IS_FREQ_TABLE_END(ftbl); ftbl++) {
+		if ((ftbl->val & mask) == (value & mask))
+			return ftbl;
+	}
+	return NULL;
+}
drivers/clk/realtek/freq_table.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH v17 4/9 clk: realtek: Add support for gate clock

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Introduce clk_regmap_gate_ops supporting enable, disable, and is_enabled for standard regmap gate clocks. To accommodate hardware designs, the enable and disable operations handle a 'write_en' flag, which asserts an adjacent write-enable bit (bit_idx + 1) simultaneously when modifying the gate bit.

---
Changes in v17:
- Return 0 instead of the error code from '.is_enabled()'.

---
 drivers/clk/realtek/Makefile          |  1 +
 drivers/clk/realtek/clk-regmap-gate.c | 59 +++++++++++++++++++++++++++
 drivers/clk/realtek/clk-regmap-gate.h | 54 ++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-regmap-gate.c
 create mode 100644 drivers/clk/realtek/clk-regmap-gate.h
drivers/clk/realtek/Makefile +1 -0
index 6fbe6e07b760..9397d677f52d 100644
@@ -2,5 +2,6 @@
 obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
 
 clk-rtk-y += clk-rtk-common.o
+clk-rtk-y += clk-regmap-gate.o
 clk-rtk-y += clk-regmap-pll.o
 clk-rtk-y += freq_table.o
drivers/clk/realtek/clk-regmap-gate.c new file +59 -0

59 lines not on this page · raw message

drivers/clk/realtek/clk-regmap-gate.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH v17 5/9 clk: realtek: Add support for mux clock

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Add a simple regmap-based clk_ops implementation for Realtek mux clocks.

The implementation supports parent selection and rate determination through regmap-backed register access.

---
Changes in v17:
- None.

---
 drivers/clk/realtek/Makefile         |  1 +
 drivers/clk/realtek/clk-regmap-mux.c | 40 ++++++++++++++++++++++++++
 drivers/clk/realtek/clk-regmap-mux.h | 42 ++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-regmap-mux.c
 create mode 100644 drivers/clk/realtek/clk-regmap-mux.h
drivers/clk/realtek/Makefile +1 -0
index 9397d677f52d..4be39e2dd5b4 100644
@@ -3,5 +3,6 @@ obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
 
 clk-rtk-y += clk-rtk-common.o
 clk-rtk-y += clk-regmap-gate.o
+clk-rtk-y += clk-regmap-mux.o
 clk-rtk-y += clk-regmap-pll.o
 clk-rtk-y += freq_table.o
drivers/clk/realtek/clk-regmap-mux.c new file +40 -0
new file mode 100644
index 000000000000..ba86f314bb5e
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2026 Realtek Semiconductor Corporation
+ * Author: Cheng-Yu Lee <[email protected]>
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/export.h>
+#include <linux/regmap.h>
+#include "clk-regmap-mux.h"
+
+static u8 rtk_clk_regmap_mux_get_parent(struct clk_hw *hw)
+{
+	struct rtk_clk_regmap_mux *clkm = to_rtk_clk_regmap_mux(hw);
+	u32 val;
+	int ret;
+
+	ret = regmap_read(clkm->clkr.regmap, clkm->mux_ofs, &val);
+	if (ret)
+		return 0xff;
+
+	val = (val >> clkm->shift) & clkm->mask;
+
+	return val;
+}
+
+static int rtk_clk_regmap_mux_set_parent(struct clk_hw *hw, u8 index)
+{
+	struct rtk_clk_regmap_mux *clkm = to_rtk_clk_regmap_mux(hw);
+
+	return regmap_update_bits(clkm->clkr.regmap, clkm->mux_ofs,
+				  clkm->mask << clkm->shift, (u32)index << clkm->shift);
+}
+
+const struct clk_ops rtk_clk_regmap_mux_ops = {
+	.set_parent = rtk_clk_regmap_mux_set_parent,
+	.get_parent = rtk_clk_regmap_mux_get_parent,
+	.determine_rate = __clk_mux_determine_rate,
+};
+EXPORT_SYMBOL_NS_GPL(rtk_clk_regmap_mux_ops, "CLK_REALTEK");
drivers/clk/realtek/clk-regmap-mux.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH v17 6/9 clk: realtek: Add support for MMC-tuned PLL clocks

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Add clk_pll_mmc_ops for enable/disable, rate control, and status operations on MMC PLL clocks.

Also add clk_pll_mmc_phase_ops to support phase get/set operations.

---
Changes in v17:
- Reuse the 'ftbl_find_closest_by_rate()' macro and drop the local duplicate.
- Make 'rate_tbl' optional and add a built-in default table covering both operating points of this PLL: the eMMC and the SPI-NAND controllers are clocked by the same PLL instance on this SoC, 196,999,969 Hz with SSC enabled for eMMC and 99,999,206 Hz with SSC disabled for SPI-NAND.
- Add an 'ssc' flag to 'struct rtk_clk_pll_mmc_rate', so that the SSC analog registers are left untouched in SPI-NAND mode.
- Replace 'shift' with 'phsel_mask' in 'struct rtk_clk_pll_mmc_phase', and use 'field_prep()'/'field_get()'.
- '.recalc_rate()' always computes the rate from the dividers instead of reverse-matching the rate table.

---
 drivers/clk/realtek/Kconfig              |   3 +
 drivers/clk/realtek/Makefile             |   2 +
 drivers/clk/realtek/clk-regmap-pll-mmc.c | 443 +++++++++++++++++++++++
 drivers/clk/realtek/clk-regmap-pll-mmc.h |  69 ++++
 drivers/clk/realtek/freq_table.c         |   1 +
 5 files changed, 518 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-regmap-pll-mmc.c
 create mode 100644 drivers/clk/realtek/clk-regmap-pll-mmc.h
drivers/clk/realtek/Kconfig +3 -0
index fc16fd71c50b..f3197031f753 100644
@@ -19,4 +19,7 @@ config RTK_CLK_COMMON
 	select AUXILIARY_BUS
 	select REGMAP_MMIO
 
+config RTK_CLK_PLL_MMC
+	bool
+
 endif
drivers/clk/realtek/Makefile +2 -0
index 4be39e2dd5b4..5fefe9bf901f 100644
@@ -6,3 +6,5 @@ clk-rtk-y += clk-regmap-gate.o
 clk-rtk-y += clk-regmap-mux.o
 clk-rtk-y += clk-regmap-pll.o
 clk-rtk-y += freq_table.o
+
+clk-rtk-$(CONFIG_RTK_CLK_PLL_MMC) += clk-regmap-pll-mmc.o
drivers/clk/realtek/clk-regmap-pll-mmc.c new file +443 -0

443 lines not on this page · raw message

drivers/clk/realtek/clk-regmap-pll-mmc.h new file +69 -0

69 lines not on this page · raw message

drivers/clk/realtek/freq_table.c +1 -0
index 3446657a437b..bf3d46df20c8 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <linux/limits.h>
 #include <linux/types.h>
 #include "freq_table.h"
 
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH v17 7/9 clk: realtek: Add RTD1625-CRT clock controller driver

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Add support for the CRT (Clock, Reset, and Test) domain clock controller on the Realtek RTD1625 SoC. This driver provides essential clock sources (including PLLs), gating, and multiplexing functionalities for the platform's peripherals.

Because the reset controller shares the same register space with this CRT clock controller, this driver also acts as the parent device and registers the reset controller as an auxiliary device on the auxiliary bus.

---
Changes in v17:
- Add '.suppress_bind_attrs = true'

---
 drivers/clk/realtek/Kconfig           |  14 +
 drivers/clk/realtek/Makefile          |   1 +
 drivers/clk/realtek/clk-rtd1625-crt.c | 859 ++++++++++++++++++++++++++
 3 files changed, 874 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-rtd1625-crt.c
drivers/clk/realtek/Kconfig +14 -0
index f3197031f753..7d5b13e32914 100644
@@ -22,4 +22,18 @@ config RTK_CLK_COMMON
 config RTK_CLK_PLL_MMC
 	bool
 
+config CLK_RTD1625
+	tristate "RTD1625 Clock Controller"
+	select RTK_CLK_COMMON
+	select RTK_CLK_PLL_MMC
+	help
+	  Support for the clock controller on Realtek RTD1625 SoCs.
+
+	  This driver provides clock sources, gating, multiplexing, and
+	  (via an auxiliary device) reset control for peripherals on the
+	  RTD1625 platform.
+
+	  Say Y here if your system is based on the RTD1625 and you need
+	  its peripheral devices to function.
+
 endif
drivers/clk/realtek/Makefile +1 -0
index 5fefe9bf901f..dd4c667e9808 100644
@@ -8,3 +8,4 @@ clk-rtk-y += clk-regmap-pll.o
 clk-rtk-y += freq_table.o
 
 clk-rtk-$(CONFIG_RTK_CLK_PLL_MMC) += clk-regmap-pll-mmc.o
+obj-$(CONFIG_CLK_RTD1625) += clk-rtd1625-crt.o
drivers/clk/realtek/clk-rtd1625-crt.c new file +859 -0

859 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH v17 8/9 clk: realtek: Add RTD1625-ISO clock controller driver

In reply to Yu-Chun Lin

From: Cheng-Yu Lee <[email protected]>

Add support for the ISO (Isolation) domain clock controller on the Realtek RTD1625 SoC. This controller manages clocks in the always-on power domain, ensuring essential services remain functional even when the main system power is gated.

Because the reset controller shares the same register space with this ISO clock controller, this driver also acts as the parent device and registers the reset controller as an auxiliary device on the auxiliary bus.

---
Changes in v17:
- None.

---
 drivers/clk/realtek/Makefile          |   1 +
 drivers/clk/realtek/clk-rtd1625-iso.c | 140 ++++++++++++++++++++++++++
 2 files changed, 141 insertions(+)
 create mode 100644 drivers/clk/realtek/clk-rtd1625-iso.c
drivers/clk/realtek/Makefile +1 -0
index dd4c667e9808..04990a44c88a 100644
@@ -9,3 +9,4 @@ clk-rtk-y += freq_table.o
 
 clk-rtk-$(CONFIG_RTK_CLK_PLL_MMC) += clk-regmap-pll-mmc.o
 obj-$(CONFIG_CLK_RTD1625) += clk-rtd1625-crt.o
+obj-$(CONFIG_CLK_RTD1625) += clk-rtd1625-iso.o
drivers/clk/realtek/clk-rtd1625-iso.c new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH v17 9/9 arm64: dts: realtek: Add clock support for RTD1625

In reply to Yu-Chun Lin

Add the clock controller nodes and osc27m fixed clock for the Realtek RTD1625 SoC.

---
Changes in v17:
- None.

---
 arch/arm64/boot/dts/realtek/kent.dtsi | 41 +++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
arch/arm64/boot/dts/realtek/kent.dtsi +41 -0
index df0d5ee3b1b9..fdb2bc2b3c79 100644
@@ -5,6 +5,7 @@
  * Copyright (c) 2024 Realtek Semiconductor Corp.
  */
 
+#include <dt-bindings/clock/realtek,rtd1625-clk.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 
@@ -26,6 +27,15 @@ timer {
 			     <GIC_PPI 12 IRQ_TYPE_LEVEL_HIGH>;
 	};
 
+	clocks {
+		osc27m: osc {
+			compatible = "fixed-clock";
+			clock-frequency = <27000000>;
+			clock-output-names = "osc27m";
+			#clock-cells = <0>;
+		};
+	};
+
 	cpus {
 		#address-cells = <1>;
 		#size-cells = <0>;
@@ -141,6 +151,28 @@ rbus: bus@98000000 {
 			#address-cells = <1>;
 			#size-cells = <1>;
 
+			cc: clock-controller@0 {
+				compatible = "realtek,rtd1625-crt-clk";
+				reg = <0x0 0x900>;
+				clocks = <&osc27m>;
+				clock-names = "osc27m";
+				#clock-cells = <1>;
+				#reset-cells = <1>;
+			};
+
+			ic: clock-controller@7088 {
+				compatible = "realtek,rtd1625-iso-clk";
+				reg = <0x7088 0x8>;
+				clocks = <&osc27m>, <&cc RTD1625_CRT_CLK_SYS>,
+					 <&cc RTD1625_CRT_CLK_SYSH>,
+					 <&cc RTD1625_CRT_CLK_DDSA_DIV4>,
+					 <&cc RTD1625_CRT_CLK_EN_MISC>;
+				clock-names = "osc27m", "clk_sys", "clk_sysh", "clk_ddsa_div4",
+					      "clk_en_misc";
+				#clock-cells = <1>;
+				#reset-cells = <1>;
+			};
+
 			uart0: serial@7800 {
 				compatible = "snps,dw-apb-uart";
 				reg = <0x7800 0x100>;
@@ -205,6 +237,15 @@ isom_pinctrl: pinctrl@146200 {
 				reg = <0x146200 0x34>;
 			};
 
+			iso_s_cc: clock-controller@146310 {
+				compatible = "realtek,rtd1625-iso-s-clk";
+				reg = <0x146310 0x8>;
+				clocks = <&osc27m>;
+				clock-names = "osc27m";
+				#clock-cells = <1>;
+				#reset-cells = <1>;
+			};
+
 			ve4_pinctrl: pinctrl@14e000 {
 				compatible = "realtek,rtd1625-ve4-pinctrl";
 				reg = <0x14e000 0x84>;
Signature · 1 line
2.43.0