[PATCH 02/17] clk: gate: Add inverted gate support

Sascha Hauer s.hauer at pengutronix.de
Thu Jun 20 02:54:06 EDT 2013


This adds support for gates which need 0 to enable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk-gate.c | 37 +++++++++++++++++++++++++++++++++----
 include/linux/clk.h    |  2 ++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index a455094..f632d85 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -25,6 +25,8 @@ struct clk_gate {
 	void __iomem *reg;
 	int shift;
 	const char *parent;
+#define CLK_GATE_INVERTED	(1 << 0)
+	unsigned flags;
 };
 
 static int clk_gate_enable(struct clk *clk)
@@ -33,7 +35,12 @@ static int clk_gate_enable(struct clk *clk)
 	u32 val;
 
 	val = readl(g->reg);
-	val |= 1 << g->shift;
+
+	if (g->flags & CLK_GATE_INVERTED)
+		val &= ~(1 << g->shift);
+	else
+		val |= 1 << g->shift;
+
 	writel(val, g->reg);
 
 	return 0;
@@ -45,7 +52,12 @@ static void clk_gate_disable(struct clk *clk)
 	u32 val;
 
 	val = readl(g->reg);
-	val &= ~(1 << g->shift);
+
+	if (g->flags & CLK_GATE_INVERTED)
+		val |= 1 << g->shift;
+	else
+		val &= ~(1 << g->shift);
+
 	writel(val, g->reg);
 }
 
@@ -57,9 +69,9 @@ static int clk_gate_is_enabled(struct clk *clk)
 	val = readl(g->reg);
 
 	if (val & (1 << g->shift))
-		return 1;
+		return g->flags & CLK_GATE_INVERTED ? 0 : 1;
 	else
-		return 0;
+		return g->flags & CLK_GATE_INVERTED ? 1 : 0;
 }
 
 struct clk_ops clk_gate_ops = {
@@ -90,3 +102,20 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 
 	return &g->clk;
 }
+
+struct clk *clk_gate_inverted(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	struct clk *clk;
+	struct clk_gate *g;
+
+	clk = clk_gate(name, parent, reg, shift);
+	if (IS_ERR(clk))
+		return clk;
+
+	g = container_of(clk, struct clk_gate, clk);
+
+	g->flags = CLK_GATE_INVERTED;
+
+	return clk;
+}
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 9c41cb8..718faa0 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -214,6 +214,8 @@ struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
 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,
+		u8 shift);
 
 int clk_is_enabled_always(struct clk *clk);
 
-- 
1.8.3.1




More information about the barebox mailing list