[PATCH 2/2] clk: rockchip: add clock output/input switch driver

ZhuXiangyu 1194781887 at qq.com
Sat Nov 21 02:58:56 PST 2026


Add a small driver for the Rockchip GRF-controlled clock output/input
switch. It exposes a single gate bit as a clock, allowing the SAI MCLK
pin direction to be controlled through the clock framework.

Tested on an RK3506B board with the ES8388 codec: this clock drives the
I2S MCLK and audio playback works.

Tested-by: ZhuXiangyu <1194781887 at qq.com>
Signed-off-by: ZhuXiangyu <1194781887 at qq.com>
---
 drivers/clk/rockchip/Kconfig   |  8 ++++
 drivers/clk/rockchip/Makefile  |  1 +
 drivers/clk/rockchip/clk-out.c | 70 ++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-out.c

diff --git a/drivers/clk/rockchip/Kconfig b/drivers/clk/rockchip/Kconfig
index 4b55f48d..dfbdb231 100644
--- a/drivers/clk/rockchip/Kconfig
+++ b/drivers/clk/rockchip/Kconfig
@@ -156,4 +156,12 @@ config CLK_RK3588
 	help
 	  Build the driver for RK3588 Clock Driver.
 
+config ROCKCHIP_CLK_OUT
+	tristate "Rockchip clock output/input switch"
+	help
+	  Say Y or M here to enable the Rockchip clock output/input switch
+	  driver. It exposes a GRF-controlled clock gate used for the SAI
+	  MCLK output pins. The pin direction is controlled through the
+	  common clock framework.
+
 endif
diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index 554b7eb8..eed5fb59 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -4,6 +4,7 @@
 #
 
 obj-$(CONFIG_COMMON_CLK_ROCKCHIP) += clk-rockchip.o
+obj-$(CONFIG_ROCKCHIP_CLK_OUT) += clk-out.o
 
 clk-rockchip-y += clk.o
 clk-rockchip-y += clk-pll.o
diff --git a/drivers/clk/rockchip/clk-out.c b/drivers/clk/rockchip/clk-out.c
new file mode 100644
index 00000000..de56ff1f
--- /dev/null
+++ b/drivers/clk/rockchip/clk-out.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Rockchip Electronics Co., Ltd.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+static DEFINE_SPINLOCK(clk_out_lock);
+
+static int rockchip_clk_out_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	const char *clk_name;
+	const char *parent_name;
+	struct clk_hw *hw;
+	void __iomem *reg;
+	u8 clk_gate_flags = CLK_GATE_HIWORD_MASK;
+	u32 shift;
+	int ret;
+
+	ret = device_property_read_string(dev, "clock-output-names", &clk_name);
+	if (ret)
+		return ret;
+
+	ret = device_property_read_u32(dev, "rockchip,bit-shift", &shift);
+	if (ret)
+		return ret;
+
+	if (device_property_read_bool(dev, "rockchip,bit-set-to-disable"))
+		clk_gate_flags |= CLK_GATE_SET_TO_DISABLE;
+
+	parent_name = of_clk_get_parent_name(node, 0);
+	if (!parent_name)
+		return -EINVAL;
+
+	reg = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(reg))
+		return PTR_ERR(reg);
+
+	hw = devm_clk_hw_register_gate(dev, clk_name, parent_name,
+				       CLK_SET_RATE_PARENT, reg, shift,
+				       clk_gate_flags, &clk_out_lock);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+
+	return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
+}
+
+static const struct of_device_id rockchip_clk_out_match[] = {
+	{ .compatible = "rockchip,clk-out" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, rockchip_clk_out_match);
+
+static struct platform_driver rockchip_clk_out_driver = {
+	.driver = {
+		.name = "rockchip-clk-out",
+		.of_match_table = rockchip_clk_out_match,
+	},
+	.probe = rockchip_clk_out_probe,
+};
+module_platform_driver(rockchip_clk_out_driver);
+
+MODULE_DESCRIPTION("Rockchip Clock Input-Output-Switch");
+MODULE_AUTHOR("Sugar Zhang <sugar.zhang at rock-chips.com>");
+MODULE_LICENSE("GPL");
-- 
2.47.3




More information about the Linux-rockchip mailing list