mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 01/10] clk: Add clk gate support
Date: Mon,  8 Oct 2012 21:44:10 +0200	[thread overview]
Message-ID: <1349725459-20226-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1349725459-20226-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/clk/Makefile   |    3 +-
 drivers/clk/clk-gate.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/clk.h    |    2 ++
 3 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/clk-gate.c

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 39a75a4..3cc7163 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 0000000..cf1bb1a
--- /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 e9031dd..00588bf 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);
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-10-08 19:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 19:44 [PATCH] i.MX clk Sascha Hauer
2012-10-08 19:44 ` Sascha Hauer [this message]
2012-10-08 19:44 ` [PATCH 02/10] ARM i.MX: Add clk_gate inline function Sascha Hauer
2012-10-08 19:44 ` [PATCH 03/10] ARM i.MX21: Fix CSPI parent clock Sascha Hauer
2012-10-08 19:44 ` [PATCH 04/10] ARM i.MX21: Enable all needed clocks during startup Sascha Hauer
2012-10-08 19:44 ` [PATCH 05/10] ARM i.MX25: " Sascha Hauer
2012-10-08 20:49   ` Roberto Nibali
2012-10-08 20:58     ` Sascha Hauer
2012-10-08 21:18       ` Roberto Nibali
2012-10-10  7:49   ` Sascha Hauer
2012-10-08 19:44 ` [PATCH 06/10] ARM i.MX21: Add lcdc per gate Sascha Hauer
2012-10-08 19:44 ` [PATCH 07/10] ARM i.MX27: " Sascha Hauer
2012-10-08 19:44 ` [PATCH 08/10] ARM i.MX25: " Sascha Hauer
2012-10-08 19:44 ` [PATCH 09/10] video i.MX: Use regular clk_[en|dis]able functions Sascha Hauer
2012-10-08 19:44 ` [PATCH 10/10] ARM i.MX: Enable clocks in common place Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1349725459-20226-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox