From b80f5d58009130254bd660df36f0543e73dc959f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 27 Apr 2014 11:30:39 +0200 Subject: clk: gate: unify enable and disable functions handling To avoid code duplication and make easier to introduce new flags. Signed-off-by: Beniamino Galvani Signed-off-by: Sascha Hauer --- drivers/clk/clk-gate.c | 33 +++++++++++++++------------------ 1 file 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) -- cgit v1.2.3