[PATCH 13/30] clk: sandbox: Create a special fixed-rate driver
Simon Glass
sjg at chromium.org
Thu Dec 31 05:09:43 CET 2020
Create a version of this driver for sandbox so that it can use the
of-platdata struct.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
arch/sandbox/dts/sandbox.dtsi | 2 +-
arch/sandbox/include/asm/clk.h | 8 ++++++++
drivers/clk/clk_sandbox.c | 33 +++++++++++++++++++++++++++++++++
test/dm/of_platdata.c | 2 +-
4 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index d842f021760..4f35f5fef3e 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -31,7 +31,7 @@
clk_fixed: clk-fixed {
u-boot,dm-pre-reloc;
- compatible = "fixed-clock";
+ compatible = "sandbox,fixed-clock";
#clock-cells = <0>;
clock-frequency = <1234>;
};
diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h
index 03c00b0694c..9f26587a2f2 100644
--- a/arch/sandbox/include/asm/clk.h
+++ b/arch/sandbox/include/asm/clk.h
@@ -61,6 +61,14 @@ struct sandbox_clk_test {
struct clk_bulk bulk;
};
+/* Platform data for the sandbox fixed-rate clock driver */
+struct sandbox_clk_fixed_rate_plat {
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct dtd_sandbox_fixed_clock dtplat;
+#endif
+ struct clk_fixed_rate fixed;
+};
+
/**
* sandbox_clk_query_rate - Query the current rate of a sandbox clock.
*
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c
index a5c1c9d300c..633cc47f9d9 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/clk_sandbox.c
@@ -9,6 +9,7 @@
#include <errno.h>
#include <malloc.h>
#include <asm/clk.h>
+#include <linux/clk-provider.h>
static ulong sandbox_clk_get_rate(struct clk *clk)
{
@@ -154,3 +155,35 @@ int sandbox_clk_query_requested(struct udevice *dev, int id)
return -EINVAL;
return priv->requested[id];
}
+
+int clk_fixed_rate_of_to_plat(struct udevice *dev)
+{
+ struct clk_fixed_rate *cplat;
+
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+ struct sandbox_clk_fixed_rate_plat *plat = dev_get_plat(dev);
+
+ cplat = &plat->fixed;
+ cplat->fixed_rate = plat->dtplat.clock_frequency;
+#else
+ cplat = to_clk_fixed_rate(dev);
+#endif
+ clk_fixed_rate_ofdata_to_plat_(dev, cplat);
+
+ return 0;
+}
+
+static const struct udevice_id sandbox_clk_fixed_rate_match[] = {
+ { .compatible = "sandbox,fixed-clock" },
+ { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sandbox_fixed_clock) = {
+ .name = "sandbox_fixed_clock",
+ .id = UCLASS_CLK,
+ .of_match = sandbox_clk_fixed_rate_match,
+ .of_to_plat = clk_fixed_rate_of_to_plat,
+ .plat_auto = sizeof(struct sandbox_clk_fixed_rate_plat),
+ .ops = &clk_fixed_rate_ops,
+ .flags = DM_FLAG_PRE_RELOC,
+};
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index cfc43a5b038..73d3d1e747b 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -184,7 +184,7 @@ static int dm_test_of_plat_phandle(struct unit_test_state *uts)
plat = dev_get_plat(dev);
ut_assertok(device_get_by_driver_info_idx(plat->clocks[0].idx, &clk));
- ut_asserteq_str("fixed_clock", clk->name);
+ ut_asserteq_str("sandbox_fixed_clock", clk->name);
ut_assertok(device_get_by_driver_info_idx(plat->clocks[1].idx, &clk));
ut_asserteq_str("sandbox_clk", clk->name);
--
2.29.2.729.g45daf8777d-goog
More information about the U-Boot
mailing list