summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBeniamino Galvani <b.galvani@gmail.com>2014-04-27 11:30:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-04-29 08:15:24 +0200
commitb80f5d58009130254bd660df36f0543e73dc959f (patch)
tree5314121b5c4f47ed4b2151a63e2a42b3584c7b2f
parent32a2a673c6d24a85751f88fb14bb8302fc11c4a9 (diff)
downloadbarebox-b80f5d58009130254bd660df36f0543e73dc959f.tar.gz
barebox-b80f5d58009130254bd660df36f0543e73dc959f.tar.xz
clk: gate: unify enable and disable functions handling
To avoid code duplication and make easier to introduce new flags. Signed-off-by: Beniamino Galvani <b.galvani@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/clk/clk-gate.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index 11c749a8d9..54489c4214 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -30,36 +30,33 @@ struct clk_gate {
#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
-static int clk_gate_enable(struct clk *clk)
+static void clk_gate_endisable(struct clk *clk, int enable)
{
- struct clk_gate *g = container_of(clk, struct clk_gate, clk);
+ struct clk_gate *gate = container_of(clk, struct clk_gate, clk);
+ int set = gate->flags & CLK_GATE_INVERTED ? 1 : 0;
u32 val;
- val = readl(g->reg);
+ set ^= enable;
+ val = readl(gate->reg);
- if (g->flags & CLK_GATE_INVERTED)
- val &= ~(1 << g->shift);
+ if (set)
+ val |= BIT(gate->shift);
else
- val |= 1 << g->shift;
+ val &= ~BIT(gate->shift);
- writel(val, g->reg);
+ writel(val, gate->reg);
+}
+
+static int clk_gate_enable(struct clk *clk)
+{
+ clk_gate_endisable(clk, 1);
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);
-
- if (g->flags & CLK_GATE_INVERTED)
- val |= 1 << g->shift;
- else
- val &= ~(1 << g->shift);
-
- writel(val, g->reg);
+ clk_gate_endisable(clk, 0);
}
static int clk_gate_is_enabled(struct clk *clk)