Devicetree
 help / color / mirror / Atom feed
* [PATCH 2/2] clk: rockchip: add clock output/input switch driver
       [not found] <20261121105856.1414984-1-1194781887@qq.com>
@ 2026-11-21 10:58 ` ZhuXiangyu
  2026-11-21 11:03   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: ZhuXiangyu @ 2026-11-21 10:58 UTC (permalink / raw)
  To: Stephen Boyd, Heiko Stuebner
  Cc: Brian Masney, Jerome Brunet, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, linux-clk, linux-arm-kernel, linux-rockchip,
	devicetree, linux-kernel, ZhuXiangyu

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@qq.com>
Signed-off-by: ZhuXiangyu <1194781887@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@rock-chips.com>");
+MODULE_LICENSE("GPL");
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] clk: rockchip: add clock output/input switch driver
  2026-11-21 10:58 ` [PATCH 2/2] clk: rockchip: add clock output/input switch driver ZhuXiangyu
@ 2026-11-21 11:03   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-21 11:03 UTC (permalink / raw)
  To: ZhuXiangyu, Stephen Boyd, Heiko Stuebner
  Cc: Brian Masney, Jerome Brunet, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, linux-clk, linux-arm-kernel, linux-rockchip,
	devicetree, linux-kernel

On 21/11/2026 11:58, ZhuXiangyu wrote:
> 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@qq.com>

No, this makes no sense. Please do not invent own stuff, like
author-testing-tags. Look how other people did it.

> Signed-off-by: ZhuXiangyu <1194781887@qq.com>
> ---

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-21 11:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261121105856.1414984-1-1194781887@qq.com>
2026-11-21 10:58 ` [PATCH 2/2] clk: rockchip: add clock output/input switch driver ZhuXiangyu
2026-11-21 11:03   ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox