]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
clk: sandbox: Create a special fixed-rate driver
authorSimon Glass <sjg@chromium.org>
Mon, 15 Mar 2021 04:25:24 +0000 (17:25 +1300)
committerSimon Glass <sjg@chromium.org>
Fri, 26 Mar 2021 04:03:08 +0000 (17:03 +1300)
Create a version of this driver for sandbox so that it can use the
of-platdata struct.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/sandbox.dtsi
arch/sandbox/include/asm/clk.h
drivers/clk/clk_sandbox.c
test/dm/of_platdata.c

index 7455c99a73936c661b681ba916acea0c4870c7c9..5bf84451c9943cc7e6d0f96a07769cbf9fb20e64 100644 (file)
@@ -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>;
        };
index 6972b9e743add0f2f3e2c1b7e1459b9344016b13..df7156fe31742cb79f0b8ee5bc7c4f5f27e0ccc9 100644 (file)
@@ -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.
  *
index e1313f6d880dbfdf14cf18907d58d7f09faad420..57acf7d8553bbfc628f7c46fa58fe9b2b4b319e3 100644 (file)
@@ -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)
 {
@@ -171,3 +172,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,
+};
index e9804cc27fa84e029634dd6023347432a9c437d4..93ad5727255f772be65c5089283dd93435cb1cc6 100644 (file)
@@ -185,7 +185,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);