[PATCH 2/2] clk: introduce a fallback stub driver

Caleb Connolly caleb.connolly at linaro.org
Wed Apr 10 19:06:58 CEST 2024


Add a stub_clk driver which does absolutely nothing and is configured as
the fallback stub for UCLASS_CLK. If there is a dependency on a clock
device which is not supported by any existing driver, and
CONFIG_CLK_STUB is enabled, then the stub driver will kick in.

This is intended to be useful during early bringup (e.g. if the serial
port is already configured for a default rate) or for clock controllers
that simply aren't vital for a platform to work.

Signed-off-by: Caleb Connolly <caleb.connolly at linaro.org>
---
 drivers/clk/Makefile       |  1 +
 drivers/clk/clk-fallback.c | 39 +++++++++++++++++++++++++++++++++++++++
 drivers/clk/clk-uclass.c   |  4 ++++
 drivers/core/Kconfig       | 10 ++++++++++
 4 files changed, 54 insertions(+)

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 638ad04baeb0..dd57f2fd0397 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -4,8 +4,9 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 #
 
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk-uclass.o
+obj-$(CONFIG_CLK_FALLBACK) += clk-fallback.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_rate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_factor.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o clk-gate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk-fixed-factor.o
diff --git a/drivers/clk/clk-fallback.c b/drivers/clk/clk-fallback.c
new file mode 100644
index 000000000000..f5733821e998
--- /dev/null
+++ b/drivers/clk/clk-fallback.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2024 Linaro Ltd.
+ *
+ * Stub clock driver for non-vital clocks.
+ */
+
+#include <clk.h>
+#include <clk-uclass.h>
+#include <dm.h>
+
+static ulong fallback_clk_set_rate(struct clk *clk, ulong rate)
+{
+	return (clk->rate = rate);
+}
+
+static ulong fallback_clk_get_rate(struct clk *clk)
+{
+	return clk->rate;
+}
+
+static int fallback_clk_nop(struct clk *clk)
+{
+	return 0;
+};
+
+static struct clk_ops fallback_clk_ops = {
+	.set_rate = fallback_clk_set_rate,
+	.get_rate = fallback_clk_get_rate,
+	.enable = fallback_clk_nop,
+	.disable = fallback_clk_nop,
+};
+
+U_BOOT_DRIVER(clk_fallback) = {
+	.name		= "clk_fallback",
+	.id		= UCLASS_CLK,
+	.ops		= &fallback_clk_ops,
+	.flags		= DM_FLAG_DEFAULT_PD_CTRL_OFF,
+};
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index ed6e60bc4841..c0cdb3cf529c 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -11,8 +11,9 @@
 #include <common.h>
 #include <clk.h>
 #include <clk-uclass.h>
 #include <dm.h>
+#include <dm/lists.h>
 #include <dt-structs.h>
 #include <errno.h>
 #include <log.h>
 #include <malloc.h>
@@ -801,6 +802,9 @@ int clk_uclass_post_probe(struct udevice *dev)
 
 UCLASS_DRIVER(clk) = {
 	.id		= UCLASS_CLK,
 	.name		= "clk",
+#if CONFIG_IS_ENABLED(CLK_FALLBACK)
+	.fallback_drv_name	= "clk_fallback",
+#endif
 	.post_probe	= clk_uclass_post_probe,
 };
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index 09075b9b7a15..1cf78b4303ca 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -476,5 +476,15 @@ menuconfig FALLBACK_DRIVERS
 	  driver to "stub" the resource. These stubs usually do nothing and
 	  are therefore only suitable in instances where the resource is not
 	  required.
 
+config CLK_FALLBACK
+	bool "Enable the clock fallback driver"
+	depends on FALLBACK_DRIVERS && CLK
+	help
+	  This provides a no-op clock driver that can be used as a fallback
+	  when no other driver is available. This is useful for systems with
+	  clock controllers that are not actually required for peripherals to
+	  work correctly (for example the RPMh clock controller on Qualcomm
+	  platforms).
+
 endmenu

-- 
2.44.0



More information about the U-Boot mailing list