mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Beniamino Galvani <b.galvani@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 06/11] clk: gate: unify enable and disable functions handling
Date: Sun, 27 Apr 2014 11:30:39 +0200	[thread overview]
Message-ID: <1398591044-3616-7-git-send-email-b.galvani@gmail.com> (raw)
In-Reply-To: <1398591044-3616-1-git-send-email-b.galvani@gmail.com>

To avoid code duplication and make easier to introduce new flags.

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 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 11c749a..54489c4 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)
-- 
1.7.10.4


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

  parent reply	other threads:[~2014-04-27  9:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-27  9:30 [PATCH 00/11] ARM: add initial support for Rockchip boards Beniamino Galvani
2014-04-27  9:30 ` [PATCH 01/11] net: add ARC EMAC driver Beniamino Galvani
2014-04-27  9:30 ` [PATCH 02/11] mfd: add act8846 driver Beniamino Galvani
2014-04-27  9:30 ` [PATCH 03/11] ARM: add basic support for Rockchip SoCs Beniamino Galvani
2014-04-27  9:30 ` [PATCH 04/11] ARM: rockchip: add PLL initialization function Beniamino Galvani
2014-04-27  9:30 ` [PATCH 05/11] clk: gate: add flags argument to clock gate constructor Beniamino Galvani
2014-04-27  9:30 ` Beniamino Galvani [this message]
2014-04-27  9:30 ` [PATCH 07/11] clk: gate: add CLK_GATE_HIWORD_MASK flag Beniamino Galvani
2014-04-27  9:30 ` [PATCH 08/11] clk: add rockchip clock gate driver Beniamino Galvani
2014-04-27  9:30 ` [PATCH 09/11] pinctrl: add rockchip pinctrl and gpio drivers Beniamino Galvani
2014-04-27  9:30 ` [PATCH 10/11] ARM: dts: add Rockchip devicetree files Beniamino Galvani
2014-04-27  9:30 ` [PATCH 11/11] ARM: rockchip: add radxa-rock board Beniamino Galvani
2014-04-28  7:26 ` [PATCH 00/11] ARM: add initial support for Rockchip boards Sascha Hauer
2014-04-28 20:54   ` Beniamino Galvani
2014-04-29  7:05     ` Sascha Hauer
2014-04-29 21:13       ` Beniamino Galvani
2014-04-29 21:59         ` Heiko Stübner
2014-05-01  7:48           ` Beniamino Galvani

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=1398591044-3616-7-git-send-email-b.galvani@gmail.com \
    --to=b.galvani@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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