Add generic clock ops to be used by every AT91 PMC driver
built on top of CCF.

Signed-off-by: Claudiu Beznea <claudiu.bez...@microchip.com>
---
 drivers/clk/at91/pmc.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/at91/pmc.h |  2 ++
 2 files changed, 73 insertions(+)

diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c
index 29c6452497b7..660e23192149 100644
--- a/drivers/clk/at91/pmc.c
+++ b/drivers/clk/at91/pmc.c
@@ -5,8 +5,79 @@
  */
 
 #include <asm/io.h>
+#include <clk-uclass.h>
 #include <common.h>
 
+#include "pmc.h"
+
+static int at91_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args)
+{
+       if (args->args_count != 2) {
+               debug("AT91: clk: Invalid args_count: %d\n", args->args_count);
+               return -EINVAL;
+       }
+
+       clk->id = AT91_TO_CLK_ID(args->args[0], args->args[1]);
+
+       return 0;
+}
+
+static ulong at91_clk_get_rate(struct clk *clk)
+{
+       struct clk *c;
+       int ret;
+
+       ret = clk_get_by_id(clk->id, &c);
+       if (ret)
+               return ret;
+
+       return clk_get_rate(c);
+}
+
+static ulong at91_clk_set_rate(struct clk *clk, ulong rate)
+{
+       struct clk *c;
+       int ret;
+
+       ret = clk_get_by_id(clk->id, &c);
+       if (ret)
+               return ret;
+
+       return clk_set_rate(c, rate);
+}
+
+static int at91_clk_enable(struct clk *clk)
+{
+       struct clk *c;
+       int ret;
+
+       ret = clk_get_by_id(clk->id, &c);
+       if (ret)
+               return ret;
+
+       return clk_enable(c);
+}
+
+static int at91_clk_disable(struct clk *clk)
+{
+       struct clk *c;
+       int ret;
+
+       ret = clk_get_by_id(clk->id, &c);
+       if (ret)
+               return ret;
+
+       return clk_disable(c);
+}
+
+const struct clk_ops at91_clk_ops = {
+       .of_xlate       = at91_clk_of_xlate,
+       .set_rate       = at91_clk_set_rate,
+       .get_rate       = at91_clk_get_rate,
+       .enable         = at91_clk_enable,
+       .disable        = at91_clk_disable,
+};
+
 /**
  * pmc_read() - read content at address base + off into val
  *
diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h
index 176855e7a0ed..a6a714fd220b 100644
--- a/drivers/clk/at91/pmc.h
+++ b/drivers/clk/at91/pmc.h
@@ -75,6 +75,8 @@ extern const struct clk_programmable_layout 
at91rm9200_programmable_layout;
 extern const struct clk_programmable_layout at91sam9g45_programmable_layout;
 extern const struct clk_programmable_layout at91sam9x5_programmable_layout;
 
+extern const struct clk_ops at91_clk_ops;
+
 struct clk *at91_clk_main_rc(void __iomem *reg, const char *name,
                        const char *parent_name);
 struct clk *at91_clk_main_osc(void __iomem *reg, const char *name,
-- 
2.7.4

Reply via email to