mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Juergen Beisert <jbe@pengutronix.de>
Subject: [PATCH 02/17] clk: gate: Add inverted gate support
Date: Thu, 20 Jun 2013 08:54:06 +0200	[thread overview]
Message-ID: <1371711261-10039-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>

This adds support for gates which need 0 to enable.

Signed-off-by: Sascha Hauer <s.hauer@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


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

  parent reply	other threads:[~2013-06-20  6:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20  6:54 [PATCH] convert MXS to common clk Sascha Hauer
2013-06-20  6:54 ` [PATCH 01/17] clk: divider: Add onebased divider support Sascha Hauer
2013-06-20  6:54 ` Sascha Hauer [this message]
2013-06-20  6:54 ` [PATCH 03/17] clk: add prototype for clk_is_enabled Sascha Hauer
2013-06-20  6:54 ` [PATCH 04/17] ARM: MXS: Add MXS specific clk types Sascha Hauer
2013-06-21 12:14   ` Jürgen Beisert
2013-06-20  6:54 ` [PATCH 05/17] ARM: MXS: add clk drivers Sascha Hauer
2013-06-20  6:54 ` [PATCH 06/17] ARM: MXS: remove board specific clock setups Sascha Hauer
2013-06-20  6:54 ` [PATCH 07/17] mci: mxs: Use dev_* Sascha Hauer
2013-06-20  6:54 ` [PATCH 08/17] net: fec: Use clk API unconditionally Sascha Hauer
2013-06-20  6:54 ` [PATCH 09/17] mci: mxs: use common clk API Sascha Hauer
2013-06-20  6:54 ` [PATCH 10/17] mtd: gpmi-nand: switch to clk support Sascha Hauer
2013-06-20  6:54 ` [PATCH 11/17] serial: auart: Use " Sascha Hauer
2013-06-20  6:54 ` [PATCH 12/17] serial: stm: " Sascha Hauer
2013-06-20  6:54 ` [PATCH 13/17] spi: mxs: " Sascha Hauer
2013-06-20  6:54 ` [PATCH 14/17] ARM: MXS: octotp: switch to " Sascha Hauer
2013-06-20  6:54 ` [PATCH 15/17] ARM: MXS: remove imx_enable_enetclk Sascha Hauer
2013-06-20  6:54 ` [PATCH 16/17] video: stm: switch to clk support Sascha Hauer
2013-06-20  6:54 ` [PATCH 17/17] ARM: MXS: remove old clock support 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=1371711261-10039-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jbe@pengutronix.de \
    /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