summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-09-29 01:21:41 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-10 09:47:51 +0200
commit477b665671ef0a0004f91587367bbcba2b3baaa9 (patch)
tree9c5d1e4ed1c7158846b9118ee9c61c5b657381a3
parentcec48e77b8d77fc0f4f79e209a44cfc77eee0f88 (diff)
downloadbarebox-477b665671ef0a0004f91587367bbcba2b3baaa9.tar.gz
barebox-477b665671ef0a0004f91587367bbcba2b3baaa9.tar.xz
clk: Add clk gate support
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/clk/Makefile3
-rw-r--r--drivers/clk/clk-gate.c78
-rw-r--r--include/linux/clk.h2
3 files changed, 82 insertions, 1 deletions
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 39a75a4e4a..3cc7163829 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -1,2 +1,3 @@
-obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o clk-mux.o
+obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \
+ clk-mux.o clk-gate.o
obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
new file mode 100644
index 0000000000..cf1bb1af62
--- /dev/null
+++ b/drivers/clk/clk-gate.c
@@ -0,0 +1,78 @@
+/*
+ * clk-gate.c - generic barebox clock support. Based on Linux clk support
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+struct clk_gate {
+ struct clk clk;
+ void __iomem *reg;
+ int shift;
+ const char *parent;
+};
+
+static int clk_gate_enable(struct clk *clk)
+{
+ struct clk_gate *g = container_of(clk, struct clk_gate, clk);
+ u32 val;
+
+ val = readl(g->reg);
+ val |= 1 << g->shift;
+ writel(val, g->reg);
+
+ return 0;
+}
+
+static void clk_gate_disable(struct clk *clk)
+{
+ struct clk_gate *g = container_of(clk, struct clk_gate, clk);
+ u32 val;
+
+ val = readl(g->reg);
+ val &= ~(1 << g->shift);
+ writel(val, g->reg);
+}
+
+struct clk_ops clk_gate_ops = {
+ .enable = clk_gate_enable,
+ .disable = clk_gate_disable,
+};
+
+struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
+ u8 shift)
+{
+ struct clk_gate *g = xzalloc(sizeof(*g));
+ int ret;
+
+ g->parent = parent;
+ g->reg = reg;
+ g->shift = shift;
+ g->clk.ops = &clk_gate_ops;
+ g->clk.name = name;
+ g->clk.parent_names = &g->parent;
+ g->clk.num_parents = 1;
+
+ ret = clk_register(&g->clk);
+ if (ret) {
+ free(g);
+ return ERR_PTR(ret);
+ }
+
+ return &g->clk;
+}
diff --git a/include/linux/clk.h b/include/linux/clk.h
index e9031dd17a..00588bff05 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -188,6 +188,8 @@ struct clk *clk_fixed_factor(const char *name,
const char *parent, unsigned int mult, unsigned int div);
struct clk *clk_mux(const char *name, void __iomem *reg,
u8 shift, u8 width, const char **parents, u8 num_parents);
+struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
+ u8 shift);
int clk_register(struct clk *clk);