linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Kerr <jeremy.kerr@canonical.com>
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/4] clk: Add simple gated clock
Date: Fri, 20 May 2011 07:27:49 +0000	[thread overview]
Message-ID: <1305876469.327589.409938867568.4.gpush@pororo> (raw)
In-Reply-To: <1305876469.325655.313573683829.0.gpush@pororo>

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>

---
 drivers/clk/Kconfig    |    4 ++++
 drivers/clk/Makefile   |    1 +
 drivers/clk/clk-gate.c |   41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/clk.h    |   13 +++++++++++++
 4 files changed, 59 insertions(+)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 0a27963..75d2902 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -9,3 +9,7 @@ config GENERIC_CLK
 config GENERIC_CLK_FIXED
 	bool
 	depends on GENERIC_CLK
+
+config GENERIC_CLK_GATE
+	bool
+	depends on GENERIC_CLK
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 9a3325a..d186446 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -2,3 +2,4 @@
 obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
 obj-$(CONFIG_GENERIC_CLK)	+= clk.o
 obj-$(CONFIG_GENERIC_CLK_FIXED)	+= clk-fixed.o
+obj-$(CONFIG_GENERIC_CLK_GATE)	+= clk-gate.o
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
new file mode 100644
index 0000000..833e0da
--- /dev/null
+++ b/drivers/clk/clk-gate.c
@@ -0,0 +1,41 @@
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <asm/io.h>
+
+#define to_clk_gate(clk) container_of(clk, struct clk_gate, hw)
+
+static unsigned long clk_gate_get_rate(struct clk_hw *clk)
+{
+	return clk_get_rate(clk_get_parent(clk->clk));
+}
+
+static int clk_gate_enable(struct clk_hw *clk)
+{
+	struct clk_gate *gate = to_clk_gate(clk);
+	u32 reg;
+
+	reg = __raw_readl(gate->reg);
+	reg |= 1 << gate->bit_idx;
+	__raw_writel(reg, gate->reg);
+
+	return 0;
+}
+
+static void clk_gate_disable(struct clk_hw *clk)
+{
+	struct clk_gate *gate = to_clk_gate(clk);
+	u32 reg;
+
+	reg = __raw_readl(gate->reg);
+	reg &= ~(1 << gate->bit_idx);
+	__raw_writel(reg, gate->reg);
+}
+
+struct clk_hw_ops clk_gate_ops = {
+	.recalc_rate = clk_gate_get_rate,
+	.enable = clk_gate_enable,
+	.disable = clk_gate_disable,
+};
+EXPORT_SYMBOL_GPL(clk_gate_ops);
+
diff --git a/include/linux/clk.h b/include/linux/clk.h
index fd62e86..7c26135 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -124,6 +124,19 @@ extern struct clk_hw_ops clk_fixed_ops;
 
 #endif /* CONFIG_GENERIC_CLK_FIXED */
 
+#ifdef CONFIG_GENERIC_CLK_GATE
+
+struct clk_gate {
+	struct clk_hw	hw;
+	void __iomem	*reg;
+	u8		bit_idx;
+};
+
+extern struct clk_hw_ops clk_gate_ops;
+
+#endif /* CONFIG_GENERIC_CLK_GATE */
+
+
 #else /* !CONFIG_GENERIC_CLK */
 
 /*

  reply	other threads:[~2011-05-20  7:27 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-20  7:27 [PATCH 0/4] Add a generic struct clk Jeremy Kerr
2011-05-20  7:27 ` Jeremy Kerr [this message]
2011-05-20 11:37   ` [PATCH 4/4] clk: Add simple gated clock Arnd Bergmann
2011-05-20 22:19   ` Rob Herring
2011-05-20  7:27 ` [PATCH 2/4] clk: Implement clk_set_rate Jeremy Kerr
2011-05-20 12:25   ` Sascha Hauer
2011-05-24  7:59   ` Colin Cross
2011-05-25 19:03   ` Sascha Hauer
     [not found]     ` <1306373867.2875.162.camel@pororo>
2011-05-26  6:54       ` Sascha Hauer
2011-05-30  5:05   ` Mike Frysinger
2011-05-20  7:27 ` [PATCH 3/4] clk: Add fixed-rate clock Jeremy Kerr
2011-05-30  5:01   ` Mike Frysinger
2011-05-30  5:02   ` Mike Frysinger
2011-05-20  7:27 ` [PATCH 1/4] clk: Add a generic clock infrastructure Jeremy Kerr
2011-05-20 11:59   ` Sascha Hauer
2011-05-20 13:25     ` Thomas Gleixner
2011-05-20 13:36       ` Sascha Hauer
2011-05-23 23:55   ` Colin Cross
2011-05-24  7:02     ` Sascha Hauer
2011-05-24  7:51       ` Colin Cross
2011-05-24  8:38         ` Sascha Hauer
2011-05-25 11:22           ` Richard Zhao
2011-05-25 11:43         ` Thomas Gleixner
2011-05-24  4:30   ` viresh kumar
2011-05-25 10:47   ` Richard Zhao
2011-05-30  5:00     ` Mike Frysinger
2011-05-23 23:12 ` [PATCH 0/4] Add a generic struct clk Colin Cross
2011-05-24  6:26   ` Sascha Hauer
2011-05-24  7:31     ` Colin Cross
2011-05-24  8:09       ` Sascha Hauer
2011-05-24 19:41         ` Colin Cross
2011-05-25  2:32           ` Richard Zhao
2011-05-25  6:23           ` Sascha Hauer
2011-05-25  7:51           ` Thomas Gleixner
2011-05-27 14:39           ` Mark Brown
2011-05-24 17:22   ` Richard Zhao
2011-05-24 17:52     ` Colin Cross
2011-05-25  2:08       ` Richard Zhao
2011-05-30  5:20 ` Mike Frysinger
2011-07-10  9:09 ` Mark Brown
2011-07-10  9:50   ` Russell King - ARM Linux
2011-07-10 10:00     ` Russell King - ARM Linux
2011-07-10 11:27     ` Mark Brown
2011-07-10 11:52       ` Russell King - ARM Linux
2011-07-11  2:49   ` Jeremy Kerr
2011-07-11  3:57     ` Mark Brown

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=1305876469.327589.409938867568.4.gpush@pororo \
    --to=jeremy.kerr@canonical.com \
    --cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).