summaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk-gate.c
diff options
context:
space:
mode:
authorLucas Stach <dev@lynxeye.de>2013-06-30 23:08:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-07-02 08:36:09 +0200
commit98a2fe8f95847f84b37616762aa0bf43c0e1f015 (patch)
tree23bf025f2f8044440930c82de2f60dd8f47e7194 /drivers/clk/clk-gate.c
parentc780cd044e9f87f70c07a85103e16c35e83824e1 (diff)
downloadbarebox-98a2fe8f95847f84b37616762aa0bf43c0e1f015.tar.gz
barebox-98a2fe8f95847f84b37616762aa0bf43c0e1f015.tar.xz
clk: allow to instanciate clk gate without registering it
Allows to reuse the clk gate code within other clocks. Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clk/clk-gate.c')
-rw-r--r--drivers/clk/clk-gate.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index f632d8555b..f33effd426 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,