mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <dev@lynxeye.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 3/7] clk: allow to instanciate clk gate without registering it
Date: Sun, 30 Jun 2013 23:08:45 +0200	[thread overview]
Message-ID: <1372626529-23443-3-git-send-email-dev@lynxeye.de> (raw)
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>

Allows to reuse the clk gate code within other clocks.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 drivers/clk/clk-gate.c | 31 +++++++++++++++++++++++++------
 include/linux/clk.h    |  4 ++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index f632d85..f33effd 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -29,6 +29,8 @@ struct clk_gate {
 	unsigned flags;
 };
 
+#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
+
 static int clk_gate_enable(struct clk *clk)
 {
 	struct clk_gate *g = container_of(clk, struct clk_gate, clk);
@@ -80,11 +82,10 @@ struct clk_ops clk_gate_ops = {
 	.is_enabled = clk_gate_is_enabled,
 };
 
-struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
-		u8 shift)
+struct clk *clk_gate_alloc(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;
@@ -94,13 +95,31 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 	g->clk.parent_names = &g->parent;
 	g->clk.num_parents = 1;
 
-	ret = clk_register(&g->clk);
+	return &g->clk;
+}
+
+void clk_gate_free(struct clk *clk_gate)
+{
+	struct clk_gate *g = to_clk_gate(clk_gate);
+
+	free(g);
+}
+
+struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
+		u8 shift)
+{
+	struct clk *g;
+	int ret;
+
+	g = clk_gate_alloc(name , parent, reg, shift);
+
+	ret = clk_register(g);
 	if (ret) {
-		free(g);
+		free(to_clk_gate(g));
 		return ERR_PTR(ret);
 	}
 
-	return &g->clk;
+	return g;
 }
 
 struct clk *clk_gate_inverted(const char *name, const char *parent,
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 1cb661e..cc4f114 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -214,6 +214,10 @@ 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_alloc(const char *name, const char *parent,
+		void __iomem *reg, u8 shift);
+void clk_gate_free(struct clk *clk_gate);
 struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
 struct clk *clk_gate_inverted(const char *name, const char *parent, void __iomem *reg,
-- 
1.8.3.1


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

  parent reply	other threads:[~2013-06-30 21:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-30 21:08 [PATCH v2 1/7] clk: add clock lookup from devicetree Lucas Stach
2013-06-30 21:08 ` [PATCH v2 2/7] tegra: change clocksource driver to be more lowlevel Lucas Stach
2013-06-30 21:08 ` Lucas Stach [this message]
2013-06-30 21:08 ` [PATCH v2 4/7] clk: allow to instanciate clk mux without registering it Lucas Stach
2013-06-30 21:08 ` [PATCH v2 5/7] tegra: deduplicate clk defines Lucas Stach
2013-06-30 21:08 ` [PATCH v2 6/7] tegra: add new clock framework driver Lucas Stach
2013-06-30 21:08 ` [PATCH v2 7/7] tegra: add peripheral clocks Lucas Stach
2013-07-02  6:36 ` [PATCH v2 1/7] clk: add clock lookup from devicetree 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=1372626529-23443-3-git-send-email-dev@lynxeye.de \
    --to=dev@lynxeye.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