]> git.baikalelectronics.ru Git - uboot.git/commitdiff
clk: ccf: Add some helper functions for clock ops
authorSean Anderson <seanga2@gmail.com>
Sun, 20 Mar 2022 20:34:45 +0000 (16:34 -0400)
committerSean Anderson <seanga2@gmail.com>
Wed, 30 Mar 2022 17:03:29 +0000 (13:03 -0400)
Most CCF drivers follow a common pattern where their clock ops defer the
actual operation to the backing CCF clock. Add some generic implementations
of these functions to reduce duplication of code.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/20220320203446.740178-1-seanga2@gmail.com
drivers/clk/clk.c
include/linux/clk-provider.h

index eff0fa134f7aec84a29acfde83cbf30b988e8d0b..a5a3461b66c551976c7667f202ee0f24d7199215 100644 (file)
@@ -74,3 +74,68 @@ bool clk_dev_binded(struct clk *clk)
 
        return false;
 }
+
+/* Helper functions for clock ops */
+
+ulong ccf_clk_get_rate(struct clk *clk)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_get_rate(c);
+}
+
+ulong ccf_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_set_rate(c, rate);
+}
+
+int ccf_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       struct clk *c, *p;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+
+       err = clk_get_by_id(parent->id, &p);
+       if (err)
+               return err;
+
+       return clk_set_parent(c, p);
+}
+
+static int ccf_clk_endisable(struct clk *clk, bool enable)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return enable ? clk_enable(c) : clk_disable(c);
+}
+
+int ccf_clk_enable(struct clk *clk)
+{
+       return ccf_clk_endisable(clk, true);
+}
+
+int ccf_clk_disable(struct clk *clk)
+{
+       return ccf_clk_endisable(clk, false);
+}
+
+const struct clk_ops ccf_clk_ops = {
+       .set_rate = ccf_clk_set_rate,
+       .get_rate = ccf_clk_get_rate,
+       .set_parent = ccf_clk_set_parent,
+       .enable = ccf_clk_enable,
+       .disable = ccf_clk_disable,
+};
index 9a6116646dee2fa24b238f51fe34b3384dee2d4a..2d04882d05377525234938bc5e6099cdb84fb2d8 100644 (file)
@@ -254,4 +254,12 @@ const char *clk_hw_get_name(const struct clk *hw);
 ulong clk_generic_get_rate(struct clk *clk);
 
 struct clk *dev_get_clk_ptr(struct udevice *dev);
+
+ulong ccf_clk_get_rate(struct clk *clk);
+ulong ccf_clk_set_rate(struct clk *clk, unsigned long rate);
+int ccf_clk_set_parent(struct clk *clk, struct clk *parent);
+int ccf_clk_enable(struct clk *clk);
+int ccf_clk_disable(struct clk *clk);
+extern const struct clk_ops ccf_clk_ops;
+
 #endif /* __LINUX_CLK_PROVIDER_H */