Skip to contentSkip to conversation

Add support for AST2700 clk driver

PATCH Applied Ryan Chen 2 participants 13 messages Sep 17, 2025 – Oct 1, 2025

Subsystems (4)

v14 of 16 Applied Latest is v16 →

lore
Share & tools
lore

Ryan Chen

author reviewer
#0 lore raw

v14 cover Add support for AST2700 clk driver

This patch series is add clk driver for AST2700.

AST2700 is the 8th generation of Integrated Remote Management Processor introduced by ASPEED Technology Inc. Which is Board Management controller (BMC) SoC family. AST2700 have two SoC connected, one is SoC0, another is SoC1, it has it's own scu, this driver inlcude SCU0 and SCU1 driver.

v14:
- patch (3/3) : remove duplcate Signed-off-by.

v13:
- clk-ast2700.c
- remove unnecessary ().
- refine ast2700_soc1_configure_i3c_clk to be easy readable.

v12:
-fix mistakes commit message Acked-by:Krzysztof Kozlowski <[email protected]> to Acked-by: Krzysztof Kozlowski <[email protected]>

v11:
-update patch(1/3) commit message subject prefix dt-binding: to dt-bindings:

v10:
-aspeed,ast2700-scu.h:
-add SOC0_CLK_AHBMUX, SOC0_CLK_MPHYSRC, SOC0_CLK_U2PHY_REFCLKSRC,
SOC1_CLK_I3C.
-clk-ast2700.c
-add #include <linux/auxiliary_bus.h>
-remove #include <soc/aspeed/reset-aspeed.h>
-use devm_auxiliary_device_create replace aspeed_reset_controller_register -reset-aspeed.c:
-remove aspeed_reset_unregister_adev, aspeed_reset_adev_release,
aspeed_reset_controller_register.
-compatible name change reset_aspeed.reset0/1 -> clk_ast2700.reset0/1 -remove reset-aspeed.h

v9:
-aspeed,ast2700-scu.h: no change.
add more clear commit description.
-clk-ast2700.c:
add inlcude bitfield.h
remove redundant clk_parent_data soc0_mpll_div8/soc0_ahb/uart13clk/ uart14clk/uart15clk/uart16clk/soc1_ahb/d_clk_sels

v8:
-aspeed,ast2700-scu.h: remove no use soc0 clock, add new clock -clk-ast2700.c: remove include <linux/auxiliary_bus.h>, include <linux/clk-provider.h>, include <linux/of_address.h> -clk-ast2700.c: add include <linux/mod_devicetable.h> -clk-ast2700.c: modify include <soc/aspeed/reset-aspeed.h> order before dt-bindings
-clk-ast2700.c: modify define to be tabbed out space -clk-ast2700.c: add union struct for each clk type

	union {
		struct ast2700_clk_fixed_factor_data factor;
		struct ast2700_clk_fixed_rate_data rate;
		struct ast2700_clk_gate_data gate;
		struct ast2700_clk_div_data div;
		struct ast2700_clk_pll_data pll;
		struct ast2700_clk_mux_data mux;
	} data;

-clk-ast2700.c: modify clk_data = device_get_match_data(dev); -clk-ast2700.c: modify builtin_platform_driver_probe to arch_initcall(clk_ast2700_init)
-clk-ast2700.c: ast2700_clk_hw_register_hpll explain: scu010[4:2], scu010[4:2] = 010, hpll force 1.8Ghz
scu010[4:2] = 011, hpll force 1.7Ghz
scu010[4:2] = 110, hpll force 1.2Ghz
scu010[4:2] = 111, hpll force 800Mhz
others depend on hpll parameter register setting.

v7:
-reset-aspeed.h: fix declare static inline aspeed_reset_controller_register if the function is not used.

v6:
-patch-2: add reset-aspeed.h
-reset-aspeed: add include cleanup.h for guard() -reset-aspeed: change ids name clk_aspeed to reset_aspeed -reset-aspeed: move aspeed_reset_controller_register, aspeed_reset_adev_release, aspeed_reset_unregister_adev from clk-ast2700.c -reset-aspeed: drop base check, since it check in clk-ast2700.c -clk-ast2700: sync each gate name from *clk to *clk-gate name. -clk-ast2700: add CLK_GATE_ASPEED to diff clk_hw_register_gate and ast2700_clk_hw_register_gate.

v5:
-patch-2 Kconfig: add select AUXILIARY_BUS
-reset-aspeed: #define to_aspeed_reset(p) turn into static inline function. -reset-aspeed: modify spin_lock_irqsave to guard(spinlock_irqsave) -reset-aspeed: remove unnecessary parentheses.
-clk-ast2700: use <linux/units.h> and refrain from define clk

v4:
-yaml: keep size-cells=<1>.
-merge clk,reset dt binding header with yaml the same patch. -rename clk,reset dt binding header to aspeed,ast2700-scu.h -reset-aspeed: update tables tabs sapces to consistent spaces. -reset-aspeed: remove no use dev_set_drvdata.
-clk-ast2700: modify reset_name to const int scu in struct clk_data. -clk-ast2700: use scu number in clk_data generate reset_name for reset
driver register.
-clk-ast2700: fix pll number mix up scu0,scu1. -clk-ast2700: update dt-binding clock include file.

v3:
-yaml: v2 missing send yaml patch, v3 add. -yaml: drop 64bits address example.
-yaml: add discription about soc0 and soc1 -dt-bindings: remove (), *_NUMS, reserved. -dt-bindings: remove dulipated define number. -dt-bindings: merge clk and reset to be one patch. -reset-aspeed: add auxiliary device for reset driver. -clk-ast2700: modify reset to be auxiliary add. -clk-ast2700: modify to be platform driver. -clk-ast2700: modify each clk to const clk array.

v2:
-yaml: drop 64bits address example.
-yaml: add discription about soc0 and soc1
-dt-bindings: remove (), *_NUMS, reserved.
-dt-bindings: remove dulipated define number
-clk-ast2700: drop WARN_ON, weird comment.

Ryan Chen (3):
dt-bindings: clock: ast2700: modify soc0/1 clock define
reset: aspeed: register AST2700 reset auxiliary bus device
clk: aspeed: add AST2700 clock driver

 drivers/clk/Kconfig                           |    8 +
 drivers/clk/Makefile                          |    1 +
 drivers/clk/clk-ast2700.c                     | 1139 +++++++++++++++++
 drivers/reset/Kconfig                         |    7 +
 drivers/reset/Makefile                        |    1 +
 drivers/reset/reset-aspeed.c                  |  253 ++++
 .../dt-bindings/clock/aspeed,ast2700-scu.h    |    4 +
 7 files changed, 1413 insertions(+)
 create mode 100644 drivers/clk/clk-ast2700.c
 create mode 100644 drivers/reset/reset-aspeed.c
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v14 1/3 dt-bindings: clock: ast2700: modify soc0/1 clock define

-add SOC0_CLK_AHBMUX:
add SOC0_CLK_AHBMUX for ahb clock source divide.
mpll->

      ahb_mux -> div_table -> clk_ahb

hpll->

-new add clock:
SOC0_CLK_MPHYSRC: UFS MPHY clock source.
SOC0_CLK_U2PHY_REFCLKSRC: USB2.0 phy clock reference source.
SOC1_CLK_I3C: I3C clock source.

---
 include/dt-bindings/clock/aspeed,ast2700-scu.h | 4 ++++
 1 file changed, 4 insertions(+)
include/dt-bindings/clock/aspeed,ast2700-scu.h +4 -0
index 63021af3caf5..bacf712e8e04 100644
@@ -68,6 +68,9 @@
 #define SCU0_CLK_GATE_UFSCLK	53
 #define SCU0_CLK_GATE_EMMCCLK	54
 #define SCU0_CLK_GATE_RVAS1CLK	55
+#define SCU0_CLK_U2PHY_REFCLKSRC 56
+#define SCU0_CLK_AHBMUX			57
+#define SCU0_CLK_MPHYSRC		58
 
 /* SOC1 clk */
 #define SCU1_CLKIN		0
@@ -159,5 +162,6 @@
 #define SCU1_CLK_GATE_PORTCUSB2CLK	84
 #define SCU1_CLK_GATE_PORTDUSB2CLK	85
 #define SCU1_CLK_GATE_LTPI1TXCLK	86
+#define SCU1_CLK_I3C				87
 
 #endif
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw

Re: [PATCH v14 1/3] dt-bindings: clock: ast2700: modify soc0/1 clock define

Quoting Ryan Chen (2025-09-16 19:05:37)

Quoted 6 lines

-add SOC0_CLK_AHBMUX:
add SOC0_CLK_AHBMUX for ahb clock source divide.
mpll->

      ahb_mux -> div_table -> clk_ahb

hpll->

Quoted 8 lines

-new add clock:
SOC0_CLK_MPHYSRC: UFS MPHY clock source.
SOC0_CLK_U2PHY_REFCLKSRC: USB2.0 phy clock reference source.
SOC1_CLK_I3C: I3C clock source.

---

Applied to clk-next

maintainer Applied
#3 lore raw

Re: [PATCH v14 1/3] dt-bindings: clock: ast2700: modify soc0/1 clock define

In reply to Ryan Chen

Quoting Ryan Chen (2025-09-16 19:05:37)

Quoted 6 lines

-add SOC0_CLK_AHBMUX:
add SOC0_CLK_AHBMUX for ahb clock source divide.
mpll->

      ahb_mux -> div_table -> clk_ahb

hpll->

Quoted 8 lines

-new add clock:
SOC0_CLK_MPHYSRC: UFS MPHY clock source.
SOC0_CLK_U2PHY_REFCLKSRC: USB2.0 phy clock reference source.
SOC1_CLK_I3C: I3C clock source.

---

Applied to clk-next

author reviewer
#4 lore raw

PATCH v14 2/3 reset: aspeed: register AST2700 reset auxiliary bus device

In reply to Ryan Chen

The AST2700 reset driver is registered as an auxiliary device due to reset and clock controller share the same register region.

---
 drivers/reset/Kconfig        |   7 +
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-aspeed.c | 253 +++++++++++++++++++++++++++++++++++
 3 files changed, 261 insertions(+)
 create mode 100644 drivers/reset/reset-aspeed.c
drivers/reset/Kconfig +7 -0
index 635eef469ab7..78b7078478d4 100644
@@ -22,6 +22,13 @@ config RESET_A10SR
 	  This option enables support for the external reset functions for
 	  peripheral PHYs on the Altera Arria10 System Resource Chip.
 
+config RESET_ASPEED
+	tristate "ASPEED Reset Driver"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	select AUXILIARY_BUS
+	help
+	  This enables the reset controller driver for AST2700.
+
 config RESET_ATH79
 	bool "AR71xx Reset Driver" if COMPILE_TEST
 	default ATH79
drivers/reset/Makefile +1 -0
index a917d2522e8d..f7934f9fb90b 100644
@@ -6,6 +6,7 @@ obj-y += starfive/
 obj-y += sti/
 obj-y += tegra/
 obj-$(CONFIG_RESET_A10SR) += reset-a10sr.o
+obj-$(CONFIG_RESET_ASPEED) += reset-aspeed.o
 obj-$(CONFIG_RESET_ATH79) += reset-ath79.o
 obj-$(CONFIG_RESET_AXS10X) += reset-axs10x.o
 obj-$(CONFIG_RESET_BCM6345) += reset-bcm6345.o
drivers/reset/reset-aspeed.c new file +253 -0

253 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer Applied
#5 lore raw

Re: [PATCH v14 2/3] reset: aspeed: register AST2700 reset auxiliary bus device

Quoting Ryan Chen (2025-09-16 19:05:38)

Quoted 6 lines

The AST2700 reset driver is registered as an auxiliary device due to reset and clock controller share the same register region.

---

Applied to clk-next

author reviewer
#7 lore raw

PATCH v14 3/3 clk: aspeed: add AST2700 clock driver

In reply to Ryan Chen

Add AST2700 clock controller driver and also use axiliary device framework register the reset controller driver. Due to clock and reset using the same register region.

---
 drivers/clk/Kconfig       |    8 +
 drivers/clk/Makefile      |    1 +
 drivers/clk/clk-ast2700.c | 1139 +++++++++++++++++++++++++++++++++++++
 3 files changed, 1148 insertions(+)
 create mode 100644 drivers/clk/clk-ast2700.c
drivers/clk/Kconfig +8 -0
index 4d56475f94fc..b3a6eb374a53 100644
@@ -296,6 +296,14 @@ config COMMON_CLK_ASPEED
 	  The G4 and G5 series, including the ast2400 and ast2500, are supported
 	  by this driver.
 
+config COMMON_CLK_AST2700
+	bool "Clock driver for AST2700 SoC"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	help
+	  This driver provides support for clock on AST2700 SoC.
+	  The driver is responsible for managing the various clocks required
+	  by the peripherals and cores within the AST2700.
+
 config COMMON_CLK_S2MPS11
 	tristate "Clock driver for S2MPS1X/S5M8767 MFD"
 	depends on MFD_SEC_CORE || COMPILE_TEST
drivers/clk/Makefile +1 -0
index 18ed29cfdc11..0c47294715d3 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_COMMON_CLK_FSL_SAI)	+= clk-fsl-sai.o
 obj-$(CONFIG_COMMON_CLK_GEMINI)		+= clk-gemini.o
 obj-$(CONFIG_COMMON_CLK_ASPEED)		+= clk-aspeed.o
 obj-$(CONFIG_MACH_ASPEED_G6)		+= clk-ast2600.o
+obj-$(CONFIG_COMMON_CLK_AST2700)	+= clk-ast2700.o
 obj-$(CONFIG_ARCH_HIGHBANK)		+= clk-highbank.o
 obj-$(CONFIG_CLK_HSDK)			+= clk-hsdk-pll.o
 obj-$(CONFIG_COMMON_CLK_K210)		+= clk-k210.o
drivers/clk/clk-ast2700.c new file +1139 -0

1,139 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer Applied
#8 lore raw

Re: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoting Ryan Chen (2025-09-16 19:05:39)

Quoted 7 lines

Add AST2700 clock controller driver and also use axiliary device framework register the reset controller driver. Due to clock and reset using the same register region.

---

Applied to clk-next

maintainer
#9 lore raw

Re: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoting Stephen Boyd (2025-09-21 13:14:37)

Quoted 10 lines

Quoting Ryan Chen (2025-09-16 19:05:39)

Quoted 7 lines

Add AST2700 clock controller driver and also use axiliary device framework register the reset controller driver. Due to clock and reset using the same register region.

---

Applied to clk-next

Unapplied. Found some problems.

maintainer
#10 lore raw

Re: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

In reply to Ryan Chen

Quoting Ryan Chen (2025-09-16 19:05:39)

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +1 -0
new file mode 100644
index 000000000000..7766bc17876f
@@ -0,0 +1,1139 @@
+// SPDX-License-Identifier: GPL-2.0

drivers/clk/clk-ast2700.c line 11

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+/*
+ * Copyright (c) 2024 ASPEED Technology Inc.
+ * Author: Ryan Chen <[email protected]>
+ */
+#include <linux/auxiliary_bus.h>
+#include <linux/bitfield.h>
+#include <linux/clk-provider.h>
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/of_platform.h>

Is this include used?

drivers/clk/clk-ast2700.c line 21

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/units.h>
+
+#include <dt-bindings/clock/aspeed,ast2700-scu.h>
+
+#define SCU_CLK_12MHZ  (12 * HZ_PER_MHZ)
+#define SCU_CLK_24MHZ  (24 * HZ_PER_MHZ)
+#define SCU_CLK_25MHZ  (25 * HZ_PER_MHZ)
+#define SCU_CLK_192MHZ (192 * HZ_PER_MHZ)

Please inline these where they're used to make it more readable and shorter. We don't have to look at the definition of 192MHZ to know that it is 192 MHz

drivers/clk/clk-ast2700.c line 202

Quoted 9 lines
drivers/clk/clk-ast2700.c new file +9 -0
+
+static const struct clk_div_table ast2700_clk_uart_div_table[] = {
+       { 0x0, 1 },
+       { 0x1, 13 },
+       { 0 }
+};
+
+static const struct clk_parent_data soc0_clkin[] = {
+       { .fw_name = "soc0-clkin", .name = "soc0-clkin" },

This is wrong. Please use clk_hw pointers, or the .index member of 'struct clk_parent_data' instead of having both the .fw_name and .name members set in the parent data. The .fw_name should match some string in the DT binding for this device. The .name shouldn't be used unless we're migrating existing code from string based parent descriptions to clk_hw or clk_parent_data structures.

drivers/clk/clk-ast2700.c line 329

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+
+static const struct clk_parent_data uart13clk[] = {

This isn't used.

drivers/clk/clk-ast2700.c line 333

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +4 -0
+       { .fw_name = "uart13clk", .name = "uart13clk" },
+};
+
+static const struct clk_parent_data uart14clk[] = {

This isn't used.

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+       { .fw_name = "uart14clk", .name = "uart14clk" },
+};
+
+static const struct clk_parent_data soc1_i3c[] = {
+       { .fw_name = "soc1-i3c", .name = "soc1-i3c" },
+};
+

drivers/clk/clk-ast2700.c line 737

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+
+static struct clk_hw *ast2700_clk_hw_register_hpll(void __iomem *reg,
+                                                  const char *name, const char *parent_name,
+                                                  struct ast2700_clk_ctrl *clk_ctrl)
+{
+       unsigned int mult, div;
+       u32 val;
+
+       val = readl(clk_ctrl->base + SCU0_HWSTRAP1);
+       if ((readl(clk_ctrl->base) & REVISION_ID) && (val & BIT(3))) {

This can be read once during probe and then passed as an argument?

Quoted 22 lines
drivers/clk/clk-ast2700.c new file +22 -0
+               switch ((val & GENMASK(4, 2)) >> 2) {
+               case 2:
+                       return devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,
+                                                              0, 1800 * HZ_PER_MHZ);
+               case 3:
+                       return devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,
+                                                              0, 1700 * HZ_PER_MHZ);
+               case 6:
+                       return devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,
+                                                              0, 1200 * HZ_PER_MHZ);
+               case 7:
+                       return devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,
+                                                              0, 800 * HZ_PER_MHZ);
+               default:
+                       return ERR_PTR(-EINVAL);
+               }
+       } else if ((val & GENMASK(3, 2)) != 0) {
+               switch ((val & GENMASK(3, 2)) >> 2) {
+               case 1:
+                       return devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,
+                                                              0, 1900 * HZ_PER_MHZ);
+               case 2:

[...]

Quoted 34 lines
drivers/clk/clk-ast2700.c new file +34 -0
+static int ast2700_clk_enable(struct clk_hw *hw)
+{
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+
+       if (readl(gate->reg) & clk)
+               writel(clk, gate->reg + 0x04);
+
+       return 0;
+}
+
+static void ast2700_clk_disable(struct clk_hw *hw)
+{
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+
+       /* Clock is set to enable, so use write to set register */
+       writel(clk, gate->reg);
+}
+
+static const struct clk_ops ast2700_clk_gate_ops = {
+       .enable = ast2700_clk_enable,
+       .disable = ast2700_clk_disable,
+       .is_enabled = ast2700_clk_is_enabled,
+};
+
+static struct clk_hw *ast2700_clk_hw_register_gate(struct device *dev, const char *name,
+                                                  const struct clk_parent_data *parent,
+                                                  void __iomem *reg, u8 clock_idx,
+                                                  unsigned long clk_gate_flags, spinlock_t *lock)
+{
+       struct clk_gate *gate;
+       struct clk_hw *hw;
+       struct clk_init_data init;

drivers/clk/clk-ast2700.c line 935

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       int ret = -EINVAL;
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               return ERR_PTR(-ENOMEM);
+
+       init.name = name;
+       init.ops = &ast2700_clk_gate_ops;
+       init.flags = clk_gate_flags;
+       init.parent_names = parent ? &parent->name : NULL;

Don't use string names to describe parent child relationships.

Quoted 171 lines
drivers/clk/clk-ast2700.c new file +171 -0
+       init.num_parents = parent ? 1 : 0;
+
+       gate->reg = reg;
+       gate->bit_idx = clock_idx;
+       gate->flags = 0;
+       gate->lock = lock;
+       gate->hw.init = &init;
+
+       hw = &gate->hw;
+       ret = clk_hw_register(dev, hw);
+       if (ret) {
+               kfree(gate);
+               hw = ERR_PTR(ret);
+       }
+
+       return hw;
+}
+
+static void ast2700_soc1_configure_i3c_clk(struct ast2700_clk_ctrl *clk_ctrl)
+{
+       if (readl(clk_ctrl->base + SCU1_REVISION_ID) & REVISION_ID) {
+               u32 val;
+
+               /* I3C 250MHz = HPLL/4 */
+               val = readl(clk_ctrl->base + SCU1_CLK_SEL2) & ~SCU1_CLK_I3C_DIV_MASK;
+               val |= FIELD_PREP(SCU1_CLK_I3C_DIV_MASK, SCU1_CLK_I3C_DIV(4));
+               writel(val, clk_ctrl->base + SCU1_CLK_SEL2);
+       }
+}
+
+static int ast2700_soc_clk_probe(struct platform_device *pdev)
+{
+       const struct ast2700_clk_data *clk_data;
+       struct clk_hw_onecell_data *clk_hw_data;
+       struct ast2700_clk_ctrl *clk_ctrl;
+       struct device *dev = &pdev->dev;
+       struct auxiliary_device *adev;
+       void __iomem *clk_base;
+       struct clk_hw **hws;
+       char *reset_name;
+       int ret;
+       int i;
+
+       clk_ctrl = devm_kzalloc(dev, sizeof(*clk_ctrl), GFP_KERNEL);
+       if (!clk_ctrl)
+               return -ENOMEM;
+       clk_ctrl->dev = dev;
+       dev_set_drvdata(&pdev->dev, clk_ctrl);
+
+       spin_lock_init(&clk_ctrl->lock);
+
+       clk_base = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(clk_base))
+               return PTR_ERR(clk_base);
+
+       clk_ctrl->base = clk_base;
+
+       clk_data = device_get_match_data(dev);
+       if (!clk_data)
+               return -ENODEV;
+
+       clk_ctrl->clk_data = clk_data;
+       reset_name = devm_kasprintf(dev, GFP_KERNEL, "reset%d", clk_data->scu);
+
+       clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, clk_data->nr_clks),
+                                  GFP_KERNEL);
+       if (!clk_hw_data)
+               return -ENOMEM;
+
+       clk_hw_data->num = clk_data->nr_clks;
+       hws = clk_hw_data->hws;
+
+       if (clk_data->scu)
+               ast2700_soc1_configure_i3c_clk(clk_ctrl);
+
+       for (i = 0; i < clk_data->nr_clks; i++) {
+               const struct ast2700_clk_info *clk = &clk_data->clk_info[i];
+               void __iomem *reg;
+
+               if (clk->type == CLK_FIXED) {
+                       const struct ast2700_clk_fixed_rate_data *fixed_rate = &clk->data.rate;
+
+                       hws[i] = devm_clk_hw_register_fixed_rate(dev, clk->name, NULL, 0,
+                                                                fixed_rate->fixed_rate);
+               } else if (clk->type == CLK_FIXED_FACTOR) {
+                       const struct ast2700_clk_fixed_factor_data *factor = &clk->data.factor;
+
+                       hws[i] = devm_clk_hw_register_fixed_factor(dev, clk->name,
+                                                                  factor->parent->name,
+                                                                  0, factor->mult, factor->div);
+               } else if (clk->type == DCLK_FIXED) {
+                       const struct ast2700_clk_pll_data *pll = &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_dclk(reg, clk->name, clk_ctrl);
+               } else if (clk->type == CLK_HPLL) {
+                       const struct ast2700_clk_pll_data *pll = &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_hpll(reg, clk->name,
+                                                             pll->parent->name, clk_ctrl);
+               } else if (clk->type == CLK_PLL) {
+                       const struct ast2700_clk_pll_data *pll = &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_pll(i, reg, clk->name,
+                                                            pll->parent->name, clk_ctrl);
+               } else if (clk->type == CLK_UART_PLL) {
+                       const struct ast2700_clk_pll_data *pll = &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_uartpll(reg, clk->name,
+                                                                pll->parent->name, clk_ctrl);
+               } else if (clk->type == CLK_MUX) {
+                       const struct ast2700_clk_mux_data *mux = &clk->data.mux;
+
+                       reg = clk_ctrl->base + mux->reg;
+                       hws[i] = devm_clk_hw_register_mux_parent_data_table(dev, clk->name,
+                                                                           mux->parents,
+                                                                           mux->num_parents, 0,
+                                                                           reg, mux->bit_shift,
+                                                                           mux->bit_width, 0,
+                                                                           NULL, &clk_ctrl->lock);
+               } else if (clk->type == CLK_MISC) {
+                       const struct ast2700_clk_pll_data *misc = &clk->data.pll;
+
+                       reg = clk_ctrl->base + misc->reg;
+                       hws[i] = ast2700_clk_hw_register_misc(i, reg, clk->name,
+                                                             misc->parent->name, clk_ctrl);
+               } else if (clk->type == CLK_DIVIDER) {
+                       const struct ast2700_clk_div_data *div = &clk->data.div;
+
+                       reg = clk_ctrl->base + div->reg;
+                       hws[i] = devm_clk_hw_register_divider_table(dev, clk->name,
+                                                                   div->parent->name, 0,
+                                                                   reg, div->bit_shift,
+                                                                   div->bit_width, 0,
+                                                                   div->div_table,
+                                                                   &clk_ctrl->lock);
+               } else if (clk->type == CLK_GATE_ASPEED) {
+                       const struct ast2700_clk_gate_data *gate = &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] = ast2700_clk_hw_register_gate(dev, clk->name, gate->parent,
+                                                             reg, gate->bit, gate->flags,
+                                                             &clk_ctrl->lock);
+
+               } else {
+                       const struct ast2700_clk_gate_data *gate = &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] = devm_clk_hw_register_gate_parent_data(dev, clk->name, gate->parent,
+                                                                      0, reg, clk->clk_idx, 0,
+                                                                      &clk_ctrl->lock);
+               }
+
+               if (IS_ERR(hws[i]))
+                       return PTR_ERR(hws[i]);
+       }
+
+       ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
+       if (ret)
+               return ret;
+
+       adev = devm_auxiliary_device_create(dev, reset_name, (__force void *)clk_base);
+       if (!adev)
+               return -ENODEV;
+
+       return 0;
+}
+

[...]

drivers/clk/clk-ast2700.c line 1139

Quoted 5 lines
drivers/clk/clk-ast2700.c new file +5 -0
+static int __init clk_ast2700_init(void)
+{
+       return platform_driver_register(&ast2700_scu_driver);
+}
+arch_initcall(clk_ast2700_init);

Just use module_platform_driver()?

author reviewer
#11 lore raw

RE: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoted 17 lines

Subject: Re: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoting Ryan Chen (2025-09-16 19:05:39)

drivers/clk/clk-ast2700.c line 7

Quoted 12 lines
drivers/clk/clk-ast2700.c new renamed from drivers/clk/clk-ast2700.c +0 -0

file mode 100644 index 000000000000..7766bc17876f

drivers/clk/clk-ast2700.c new file +7 -0
@@ -0,0 +1,1139 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 ASPEED Technology Inc.
+ * Author: Ryan Chen <[email protected]>  */ #include
+<linux/auxiliary_bus.h> #include <linux/bitfield.h> #include
+<linux/clk-provider.h> #include <linux/io.h> #include
+<linux/mod_devicetable.h> #include <linux/of_platform.h>

Is this include used?

Will remove in next version.

Quoted 9 lines

drivers/clk/clk-ast2700.c

Quoted 8 lines
drivers/clk/clk-ast2700.c new file +7 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/units.h>
+
+#include <dt-bindings/clock/aspeed,ast2700-scu.h>
+
+#define SCU_CLK_12MHZ  (12 * HZ_PER_MHZ) #define SCU_CLK_24MHZ

(24 *

Quoted 5 lines

drivers/clk/clk-ast2700.c line 16

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+HZ_PER_MHZ) #define SCU_CLK_25MHZ  (25 * HZ_PER_MHZ) #define
+SCU_CLK_192MHZ (192 * HZ_PER_MHZ)

Please inline these where they're used to make it more readable and shorter. We don't have to look at the definition of 192MHZ to know that it is 192 MHz

OK, I will remove it to inline.

Quoted 18 lines

drivers/clk/clk-ast2700.c line 202

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +9 -0
+
+static const struct clk_div_table ast2700_clk_uart_div_table[] = {
+       { 0x0, 1 },
+       { 0x1, 13 },
+       { 0 }
+};
+
+static const struct clk_parent_data soc0_clkin[] = {
+       { .fw_name = "soc0-clkin", .name = "soc0-clkin" },

This is wrong. Please use clk_hw pointers, or the .index member of 'struct clk_parent_data' instead of having both the .fw_name and .name members set in the parent data. The .fw_name should match some string in the DT binding for this device. The .name shouldn't be used unless we're migrating existing code from string based parent descriptions to clk_hw or clk_parent_data structures.

Understood your concern, do you have some reference that I can refer?

Quoted 4 lines

drivers/clk/clk-ast2700.c line 329

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+
+static const struct clk_parent_data uart13clk[] = {

This isn't used.

Will remove

Quoted 6 lines

drivers/clk/clk-ast2700.c line 333

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +3 -0
+       { .fw_name = "uart13clk", .name = "uart13clk" }, };
+
+static const struct clk_parent_data uart14clk[] = {

This isn't used.

Will remove

Quoted 10 lines

drivers/clk/clk-ast2700.c

Quoted 9 lines
drivers/clk/clk-ast2700.c new file +8 -0
+       { .fw_name = "uart14clk", .name = "uart14clk" }, };
+
+static const struct clk_parent_data soc1_i3c[] = {
+       { .fw_name = "soc1-i3c", .name = "soc1-i3c" }, };
+
+
+static struct clk_hw *ast2700_clk_hw_register_hpll(void __iomem *reg,
+                                                  const char

*name, const char *parent_name,

Quoted 9 lines

drivers/clk/clk-ast2700.c line 737

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+                                                  struct
+ast2700_clk_ctrl *clk_ctrl) {
+       unsigned int mult, div;
+       u32 val;
+
+       val = readl(clk_ctrl->base + SCU0_HWSTRAP1);
+       if ((readl(clk_ctrl->base) & REVISION_ID) && (val & BIT(3))) {

This can be read once during probe and then passed as an argument?

My basic idea is keeping argument simple, that will add 2 new arguments in function. Does you intend me to modify?
Otherwise, the struct ast2700_clk_ctrl have base, that should be ok?

Or, could I just add into the struct ast2700_clk_ctrl?

struct ast2700_clk_ctrl {
    ...

+ u32 scu0_hwstrap1_val;
+ u32 revision_id_val;
};

Quoted 302 lines

drivers/clk/clk-ast2700.c

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +3 -0
+               switch ((val & GENMASK(4, 2)) >> 2) {
+               case 2:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 49

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1800 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 51

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 3:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 52

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1700 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 54

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 6:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 55

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1200 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 57

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 7:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 58

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 800 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               default:
+                       return ERR_PTR(-EINVAL);
+               }
+       } else if ((val & GENMASK(3, 2)) != 0) {
+               switch ((val & GENMASK(3, 2)) >> 2) {
+               case 1:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 66

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1900 * HZ_PER_MHZ);

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+               case 2:

[...]

Quoted 14 lines
drivers/clk/clk-ast2700.c new file +14 -0
+static int ast2700_clk_enable(struct clk_hw *hw) {
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+
+       if (readl(gate->reg) & clk)
+               writel(clk, gate->reg + 0x04);
+
+       return 0;
+}
+
+static void ast2700_clk_disable(struct clk_hw *hw) {
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       /* Clock is set to enable, so use write to set register */
+       writel(clk, gate->reg);
+}
+
+static const struct clk_ops ast2700_clk_gate_ops = {
+       .enable = ast2700_clk_enable,
+       .disable = ast2700_clk_disable,
+       .is_enabled = ast2700_clk_is_enabled, };
+
+static struct clk_hw *ast2700_clk_hw_register_gate(struct device *dev,

const char *name,

Quoted 1 line

+ const struct

clk_parent_data *parent,

Quoted 1 line

+ void __iomem

*reg, u8 clock_idx,

Quoted 5 lines
drivers/clk/clk-ast2700.c new file +5 -0
+                                                  unsigned long
+clk_gate_flags, spinlock_t *lock) {
+       struct clk_gate *gate;
+       struct clk_hw *hw;
+       struct clk_init_data init;

drivers/clk/clk-ast2700.c line 935

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       int ret = -EINVAL;
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               return ERR_PTR(-ENOMEM);
+
+       init.name = name;
+       init.ops = &ast2700_clk_gate_ops;
+       init.flags = clk_gate_flags;
+       init.parent_names = parent ? &parent->name : NULL;

Don't use string names to describe parent child relationships.

Quoted 15 lines
drivers/clk/clk-ast2700.c new file +15 -0
+       init.num_parents = parent ? 1 : 0;
+
+       gate->reg = reg;
+       gate->bit_idx = clock_idx;
+       gate->flags = 0;
+       gate->lock = lock;
+       gate->hw.init = &init;
+
+       hw = &gate->hw;
+       ret = clk_hw_register(dev, hw);
+       if (ret) {
+               kfree(gate);
+               hw = ERR_PTR(ret);
+       }
+

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       return hw;
+}
+
+static void ast2700_soc1_configure_i3c_clk(struct ast2700_clk_ctrl
+*clk_ctrl) {
+       if (readl(clk_ctrl->base + SCU1_REVISION_ID) & REVISION_ID) {
+               u32 val;
+
+               /* I3C 250MHz = HPLL/4 */
+               val = readl(clk_ctrl->base + SCU1_CLK_SEL2) &

~SCU1_CLK_I3C_DIV_MASK;

Quoted 1 line

+ val |= FIELD_PREP(SCU1_CLK_I3C_DIV_MASK,

SCU1_CLK_I3C_DIV(4));

Quoted 29 lines
drivers/clk/clk-ast2700.c new file +29 -0
+               writel(val, clk_ctrl->base + SCU1_CLK_SEL2);
+       }
+}
+
+static int ast2700_soc_clk_probe(struct platform_device *pdev) {
+       const struct ast2700_clk_data *clk_data;
+       struct clk_hw_onecell_data *clk_hw_data;
+       struct ast2700_clk_ctrl *clk_ctrl;
+       struct device *dev = &pdev->dev;
+       struct auxiliary_device *adev;
+       void __iomem *clk_base;
+       struct clk_hw **hws;
+       char *reset_name;
+       int ret;
+       int i;
+
+       clk_ctrl = devm_kzalloc(dev, sizeof(*clk_ctrl), GFP_KERNEL);
+       if (!clk_ctrl)
+               return -ENOMEM;
+       clk_ctrl->dev = dev;
+       dev_set_drvdata(&pdev->dev, clk_ctrl);
+
+       spin_lock_init(&clk_ctrl->lock);
+
+       clk_base = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(clk_base))
+               return PTR_ERR(clk_base);
+
+       clk_ctrl->base = clk_base;

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+
+       clk_data = device_get_match_data(dev);
+       if (!clk_data)
+               return -ENODEV;
+
+       clk_ctrl->clk_data = clk_data;
+       reset_name = devm_kasprintf(dev, GFP_KERNEL, "reset%d",
+ clk_data->scu);
+
+       clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws,

clk_data->nr_clks),

drivers/clk/clk-ast2700.c

Quoted 12 lines
drivers/clk/clk-ast2700.c new file +12 -0
+                                  GFP_KERNEL);
+       if (!clk_hw_data)
+               return -ENOMEM;
+
+       clk_hw_data->num = clk_data->nr_clks;
+       hws = clk_hw_data->hws;
+
+       if (clk_data->scu)
+               ast2700_soc1_configure_i3c_clk(clk_ctrl);
+
+       for (i = 0; i < clk_data->nr_clks; i++) {
+               const struct ast2700_clk_info *clk =

&clk_data->clk_info[i];

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               void __iomem *reg;
+
+               if (clk->type == CLK_FIXED) {
+                       const struct ast2700_clk_fixed_rate_data
+ *fixed_rate = &clk->data.rate;
+
+                       hws[i] = devm_clk_hw_register_fixed_rate(dev,

clk->name, NULL, 0,

Quoted 1 line

+

fixed_rate->fixed_rate);

drivers/clk/clk-ast2700.c

Quoted 5 lines
drivers/clk/clk-ast2700.c new file +5 -0
+               } else if (clk->type == CLK_FIXED_FACTOR) {
+                       const struct ast2700_clk_fixed_factor_data
+ *factor = &clk->data.factor;
+
+                       hws[i] =

devm_clk_hw_register_fixed_factor(dev, clk->name,

Quoted 1 line

+

factor->parent->name,

Quoted 1 line

+

0, factor->mult, factor->div);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == DCLK_FIXED) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_dclk(reg,

clk->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_HPLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_hpll(reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_PLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_pll(i, reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_UART_PLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_uartpll(reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_MUX) {
+                       const struct ast2700_clk_mux_data *mux =
+ &clk->data.mux;
+
+                       reg = clk_ctrl->base + mux->reg;
+                       hws[i] =

devm_clk_hw_register_mux_parent_data_table(dev, clk->name,

Quoted 1 line

+

mux->parents,

Quoted 1 line

+

mux->num_parents, 0,

Quoted 1 line

+

reg, mux->bit_shift,

Quoted 1 line

+

mux->bit_width, 0,

Quoted 1 line

+

NULL, &clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_MISC) {
+                       const struct ast2700_clk_pll_data *misc =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + misc->reg;
+                       hws[i] = ast2700_clk_hw_register_misc(i, reg,

clk->name,

Quoted 1 line

+

misc->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_DIVIDER) {
+                       const struct ast2700_clk_div_data *div =
+ &clk->data.div;
+
+                       reg = clk_ctrl->base + div->reg;
+                       hws[i] =

devm_clk_hw_register_divider_table(dev, clk->name,

Quoted 1 line

+

div->parent->name, 0,

Quoted 1 line

+

reg, div->bit_shift,

Quoted 1 line

+

div->bit_width, 0,

Quoted 1 line

+

div->div_table,

Quoted 1 line

+

&clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_GATE_ASPEED) {
+                       const struct ast2700_clk_gate_data *gate =
+ &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] = ast2700_clk_hw_register_gate(dev,

clk->name, gate->parent,

Quoted 1 line

+

reg, gate->bit, gate->flags,

drivers/clk/clk-ast2700.c

Quoted 9 lines
drivers/clk/clk-ast2700.c new file +9 -0
+
+ &clk_ctrl->lock);
+
+               } else {
+                       const struct ast2700_clk_gate_data *gate =
+ &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] =

devm_clk_hw_register_gate_parent_data(dev, clk->name, gate->parent,

Quoted 1 line

+

0, reg, clk->clk_idx, 0,

Quoted 1 line

+

&clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               }
+
+               if (IS_ERR(hws[i]))
+                       return PTR_ERR(hws[i]);
+       }
+
+       ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,

clk_hw_data);

drivers/clk/clk-ast2700.c

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +4 -0
+       if (ret)
+               return ret;
+
+       adev = devm_auxiliary_device_create(dev, reset_name, (__force

void *)clk_base);

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+       if (!adev)
+               return -ENODEV;
+
+       return 0;
+}
+

[...]

Quoted 6 lines

drivers/clk/clk-ast2700.c line 1139

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +4 -0
+static int __init clk_ast2700_init(void) {
+       return platform_driver_register(&ast2700_scu_driver);
+}
+arch_initcall(clk_ast2700_init);

Just use module_platform_driver()?

The clock driver should be core in the SoC platform. Should I modify it to platform module?

author reviewer
#12 lore raw

RE: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoted 58 lines

Subject: RE: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoted 17 lines

Subject: Re: [PATCH v14 3/3] clk: aspeed: add AST2700 clock driver

Quoting Ryan Chen (2025-09-16 19:05:39)

drivers/clk/clk-ast2700.c line 7

Quoted 12 lines
drivers/clk/clk-ast2700.c new file +7 -0
new file mode 100644 index 000000000000..7766bc17876f
@@ -0,0 +1,1139 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2024 ASPEED Technology Inc.
+ * Author: Ryan Chen <[email protected]>  */ #include
+<linux/auxiliary_bus.h> #include <linux/bitfield.h> #include
+<linux/clk-provider.h> #include <linux/io.h> #include
+<linux/mod_devicetable.h> #include <linux/of_platform.h>

Is this include used?

Will remove in next version.

Quoted 8 lines

drivers/clk/clk-ast2700.c

Quoted 8 lines
drivers/clk/clk-ast2700.c new file +7 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/units.h>
+
+#include <dt-bindings/clock/aspeed,ast2700-scu.h>
+
+#define SCU_CLK_12MHZ  (12 * HZ_PER_MHZ) #define

SCU_CLK_24MHZ

Quoted 7 lines

(24 *

drivers/clk/clk-ast2700.c line 16

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+HZ_PER_MHZ) #define SCU_CLK_25MHZ  (25 * HZ_PER_MHZ) #define
+SCU_CLK_192MHZ (192 * HZ_PER_MHZ)

Please inline these where they're used to make it more readable and shorter. We don't have to look at the definition of 192MHZ to know that it is 192 MHz

OK, I will remove it to inline.

Quoted 18 lines

drivers/clk/clk-ast2700.c line 202

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +9 -0
+
+static const struct clk_div_table ast2700_clk_uart_div_table[] = {
+       { 0x0, 1 },
+       { 0x1, 13 },
+       { 0 }
+};
+
+static const struct clk_parent_data soc0_clkin[] = {
+       { .fw_name = "soc0-clkin", .name = "soc0-clkin" },

This is wrong. Please use clk_hw pointers, or the .index member of 'struct clk_parent_data' instead of having both the .fw_name and .name members set in the parent data. The .fw_name should match some string in the DT binding for this device. The .name shouldn't be used unless we're migrating existing code from string based parent descriptions to clk_hw or clk_parent_data structures.

Quoted 1 line

Understood your concern, do you have some reference that I can refer?

Hello Stephen,
After looking deeper, the devm_clk_hw_register_fixed_factor use parent_name
https://github.com/torvalds/linux/blob/master/drivers/clk/clk-fixed-factor.c#L293-L302
Do you mean no longer use this function anymore?

Ryan

Quoted 369 lines
Quoted 5 lines

drivers/clk/clk-ast2700.c line 329

Quoted 3 lines
drivers/clk/clk-ast2700.c new file +2 -0
+
+static const struct clk_parent_data uart13clk[] = {

This isn't used.

Will remove

Quoted 6 lines

drivers/clk/clk-ast2700.c line 333

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +3 -0
+       { .fw_name = "uart13clk", .name = "uart13clk" }, };
+
+static const struct clk_parent_data uart14clk[] = {

This isn't used.

Will remove

Quoted 10 lines

drivers/clk/clk-ast2700.c

Quoted 9 lines
drivers/clk/clk-ast2700.c new file +8 -0
+       { .fw_name = "uart14clk", .name = "uart14clk" }, };
+
+static const struct clk_parent_data soc1_i3c[] = {
+       { .fw_name = "soc1-i3c", .name = "soc1-i3c" }, };
+
+
+static struct clk_hw *ast2700_clk_hw_register_hpll(void __iomem *reg,
+                                                  const char

*name, const char *parent_name,

Quoted 10 lines

drivers/clk/clk-ast2700.c line 791

Quoted 8 lines
drivers/clk/clk-ast2700.c new file +8 -0
+                                                  struct
+ast2700_clk_ctrl *clk_ctrl) {
+       unsigned int mult, div;
+       u32 val;
+
+       val = readl(clk_ctrl->base + SCU0_HWSTRAP1);
+       if ((readl(clk_ctrl->base) & REVISION_ID) && (val & BIT(3)))
+ {

This can be read once during probe and then passed as an argument?

My basic idea is keeping argument simple, that will add 2 new arguments in function.
Does you intend me to modify?
Otherwise, the struct ast2700_clk_ctrl have base, that should be ok?

Or, could I just add into the struct ast2700_clk_ctrl?

struct ast2700_clk_ctrl {
    ...
(quoted diff) +2 -0
+    u32 scu0_hwstrap1_val;
+    u32 revision_id_val;

};

Quoted 60 lines

drivers/clk/clk-ast2700.c

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +3 -0
+               switch ((val & GENMASK(4, 2)) >> 2) {
+               case 2:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 50

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1800 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 52

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 3:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 53

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1700 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 55

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 6:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 56

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1200 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c line 58

Quoted 2 lines
drivers/clk/clk-ast2700.c new file +2 -0
+               case 7:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 59

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 800 * HZ_PER_MHZ);

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               default:
+                       return ERR_PTR(-EINVAL);
+               }
+       } else if ((val & GENMASK(3, 2)) != 0) {
+               switch ((val & GENMASK(3, 2)) >> 2) {
+               case 1:
+                       return

devm_clk_hw_register_fixed_rate(clk_ctrl->dev, name, NULL,

drivers/clk/clk-ast2700.c line 67

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+

0, 1900 * HZ_PER_MHZ);

Quoted 1 line
drivers/clk/clk-ast2700.c new file +1 -0
+               case 2:

[...]

Quoted 15 lines
drivers/clk/clk-ast2700.c new file +15 -0
+static int ast2700_clk_enable(struct clk_hw *hw) {
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+
+       if (readl(gate->reg) & clk)
+               writel(clk, gate->reg + 0x04);
+
+       return 0;
+}
+
+static void ast2700_clk_disable(struct clk_hw *hw) {
+       struct clk_gate *gate = to_clk_gate(hw);
+       u32 clk = BIT(gate->bit_idx);
+
+       /* Clock is set to enable, so use write to set register */

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       writel(clk, gate->reg);
+}
+
+static const struct clk_ops ast2700_clk_gate_ops = {
+       .enable = ast2700_clk_enable,
+       .disable = ast2700_clk_disable,
+       .is_enabled = ast2700_clk_is_enabled, };
+
+static struct clk_hw *ast2700_clk_hw_register_gate(struct device
+*dev,

const char *name,

Quoted 3 lines
Quoted 1 line

+ const struct

clk_parent_data *parent,

Quoted 1 line

+ void

__iomem

Quoted 2 lines

*reg, u8 clock_idx,

Quoted 1 line

+ unsigned

long

Quoted 244 lines
Quoted 4 lines
drivers/clk/clk-ast2700.c new file +4 -0
+clk_gate_flags, spinlock_t *lock) {
+       struct clk_gate *gate;
+       struct clk_hw *hw;
+       struct clk_init_data init;

drivers/clk/clk-ast2700.c line 935

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       int ret = -EINVAL;
+
+       gate = kzalloc(sizeof(*gate), GFP_KERNEL);
+       if (!gate)
+               return ERR_PTR(-ENOMEM);
+
+       init.name = name;
+       init.ops = &ast2700_clk_gate_ops;
+       init.flags = clk_gate_flags;
+       init.parent_names = parent ? &parent->name : NULL;

Don't use string names to describe parent child relationships.

Quoted 15 lines
drivers/clk/clk-ast2700.c new file +15 -0
+       init.num_parents = parent ? 1 : 0;
+
+       gate->reg = reg;
+       gate->bit_idx = clock_idx;
+       gate->flags = 0;
+       gate->lock = lock;
+       gate->hw.init = &init;
+
+       hw = &gate->hw;
+       ret = clk_hw_register(dev, hw);
+       if (ret) {
+               kfree(gate);
+               hw = ERR_PTR(ret);
+       }
+

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       return hw;
+}
+
+static void ast2700_soc1_configure_i3c_clk(struct ast2700_clk_ctrl
+*clk_ctrl) {
+       if (readl(clk_ctrl->base + SCU1_REVISION_ID) & REVISION_ID) {
+               u32 val;
+
+               /* I3C 250MHz = HPLL/4 */
+               val = readl(clk_ctrl->base + SCU1_CLK_SEL2) &

~SCU1_CLK_I3C_DIV_MASK;

Quoted 1 line

+ val |= FIELD_PREP(SCU1_CLK_I3C_DIV_MASK,

SCU1_CLK_I3C_DIV(4));

Quoted 30 lines
drivers/clk/clk-ast2700.c new file +30 -0
+               writel(val, clk_ctrl->base + SCU1_CLK_SEL2);
+       }
+}
+
+static int ast2700_soc_clk_probe(struct platform_device *pdev) {
+       const struct ast2700_clk_data *clk_data;
+       struct clk_hw_onecell_data *clk_hw_data;
+       struct ast2700_clk_ctrl *clk_ctrl;
+       struct device *dev = &pdev->dev;
+       struct auxiliary_device *adev;
+       void __iomem *clk_base;
+       struct clk_hw **hws;
+       char *reset_name;
+       int ret;
+       int i;
+
+       clk_ctrl = devm_kzalloc(dev, sizeof(*clk_ctrl), GFP_KERNEL);
+       if (!clk_ctrl)
+               return -ENOMEM;
+       clk_ctrl->dev = dev;
+       dev_set_drvdata(&pdev->dev, clk_ctrl);
+
+       spin_lock_init(&clk_ctrl->lock);
+
+       clk_base = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(clk_base))
+               return PTR_ERR(clk_base);
+
+       clk_ctrl->base = clk_base;
+

drivers/clk/clk-ast2700.c

Quoted 10 lines
drivers/clk/clk-ast2700.c new file +10 -0
+       clk_data = device_get_match_data(dev);
+       if (!clk_data)
+               return -ENODEV;
+
+       clk_ctrl->clk_data = clk_data;
+       reset_name = devm_kasprintf(dev, GFP_KERNEL, "reset%d",
+ clk_data->scu);
+
+       clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data,
+ hws,

clk_data->nr_clks),

drivers/clk/clk-ast2700.c

Quoted 12 lines
drivers/clk/clk-ast2700.c new file +12 -0
+                                  GFP_KERNEL);
+       if (!clk_hw_data)
+               return -ENOMEM;
+
+       clk_hw_data->num = clk_data->nr_clks;
+       hws = clk_hw_data->hws;
+
+       if (clk_data->scu)
+               ast2700_soc1_configure_i3c_clk(clk_ctrl);
+
+       for (i = 0; i < clk_data->nr_clks; i++) {
+               const struct ast2700_clk_info *clk =

&clk_data->clk_info[i];

drivers/clk/clk-ast2700.c

Quoted 8 lines
drivers/clk/clk-ast2700.c new file +8 -0
+               void __iomem *reg;
+
+               if (clk->type == CLK_FIXED) {
+                       const struct ast2700_clk_fixed_rate_data
+ *fixed_rate = &clk->data.rate;
+
+                       hws[i] =
+ devm_clk_hw_register_fixed_rate(dev,

clk->name, NULL, 0,

Quoted 1 line

+

fixed_rate->fixed_rate);

drivers/clk/clk-ast2700.c

Quoted 5 lines
drivers/clk/clk-ast2700.c new file +5 -0
+               } else if (clk->type == CLK_FIXED_FACTOR) {
+                       const struct ast2700_clk_fixed_factor_data
+ *factor = &clk->data.factor;
+
+                       hws[i] =

devm_clk_hw_register_fixed_factor(dev, clk->name,

Quoted 1 line

+

factor->parent->name,

Quoted 1 line

+

0, factor->mult, factor->div);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == DCLK_FIXED) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_dclk(reg,

clk->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_HPLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_hpll(reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_PLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] = ast2700_clk_hw_register_pll(i, reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               } else if (clk->type == CLK_UART_PLL) {
+                       const struct ast2700_clk_pll_data *pll =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + pll->reg;
+                       hws[i] =
+ ast2700_clk_hw_register_uartpll(reg,

clk->name,

Quoted 1 line

+

pll->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_MUX) {
+                       const struct ast2700_clk_mux_data *mux =
+ &clk->data.mux;
+
+                       reg = clk_ctrl->base + mux->reg;
+                       hws[i] =

devm_clk_hw_register_mux_parent_data_table(dev, clk->name,

Quoted 1 line

+

mux->parents,

Quoted 1 line

+

mux->num_parents, 0,

Quoted 1 line

+

reg, mux->bit_shift,

Quoted 1 line

+

mux->bit_width, 0,

Quoted 1 line

+

NULL, &clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 7 lines
drivers/clk/clk-ast2700.c new file +7 -0
+               } else if (clk->type == CLK_MISC) {
+                       const struct ast2700_clk_pll_data *misc =
+ &clk->data.pll;
+
+                       reg = clk_ctrl->base + misc->reg;
+                       hws[i] = ast2700_clk_hw_register_misc(i,
+ reg,

clk->name,

Quoted 1 line

+

misc->parent->name, clk_ctrl);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_DIVIDER) {
+                       const struct ast2700_clk_div_data *div =
+ &clk->data.div;
+
+                       reg = clk_ctrl->base + div->reg;
+                       hws[i] =

devm_clk_hw_register_divider_table(dev, clk->name,

Quoted 1 line

+

div->parent->name, 0,

Quoted 1 line

+

reg, div->bit_shift,

Quoted 1 line

+

div->bit_width, 0,

Quoted 1 line

+

div->div_table,

Quoted 1 line

+

&clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+               } else if (clk->type == CLK_GATE_ASPEED) {
+                       const struct ast2700_clk_gate_data *gate =
+ &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] = ast2700_clk_hw_register_gate(dev,

clk->name, gate->parent,

Quoted 1 line

+

reg, gate->bit, gate->flags,

drivers/clk/clk-ast2700.c

Quoted 9 lines
drivers/clk/clk-ast2700.c new file +9 -0
+
+ &clk_ctrl->lock);
+
+               } else {
+                       const struct ast2700_clk_gate_data *gate =
+ &clk->data.gate;
+
+                       reg = clk_ctrl->base + gate->reg;
+                       hws[i] =

devm_clk_hw_register_gate_parent_data(dev, clk->name, gate->parent,

Quoted 1 line

+

0, reg, clk->clk_idx, 0,

Quoted 1 line

+

&clk_ctrl->lock);

drivers/clk/clk-ast2700.c

Quoted 8 lines
drivers/clk/clk-ast2700.c new file +8 -0
+               }
+
+               if (IS_ERR(hws[i]))
+                       return PTR_ERR(hws[i]);
+       }
+
+       ret = devm_of_clk_add_hw_provider(dev,
+ of_clk_hw_onecell_get,

clk_hw_data);

drivers/clk/clk-ast2700.c

Quoted 5 lines
drivers/clk/clk-ast2700.c new file +5 -0
+       if (ret)
+               return ret;
+
+       adev = devm_auxiliary_device_create(dev, reset_name,
+ (__force

void *)clk_base);

Quoted 6 lines
drivers/clk/clk-ast2700.c new file +6 -0
+       if (!adev)
+               return -ENODEV;
+
+       return 0;
+}
+

[...]

Quoted 6 lines

drivers/clk/clk-ast2700.c line 1139

Quoted 4 lines
drivers/clk/clk-ast2700.c new file +4 -0
+static int __init clk_ast2700_init(void) {
+       return platform_driver_register(&ast2700_scu_driver);
+}
+arch_initcall(clk_ast2700_init);

Just use module_platform_driver()?

The clock driver should be core in the SoC platform. Should I modify it to platform module?