From patchwork Fri May 20 07:27:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 802462 Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4K7TsvA031027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 20 May 2011 07:30:16 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by bombadil.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QNK8B-0001L0-PA; Fri, 20 May 2011 07:28:19 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QNK8A-0004PK-1H; Fri, 20 May 2011 07:28:18 +0000 Received: from ipv6.ozlabs.org ([2402:b800:7003:1:1::1] helo=ozlabs.org) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QNK7u-0004NO-JJ for linux-arm-kernel@lists.infradead.org; Fri, 20 May 2011 07:28:03 +0000 Received: by ozlabs.org (Postfix, from userid 1023) id 94038B71F2; Fri, 20 May 2011 17:27:57 +1000 (EST) MIME-Version: 1.0 Subject: [PATCH 4/4] clk: Add simple gated clock Message-Id: <1305876469.327589.409938867568.4.gpush@pororo> In-Reply-To: <1305876469.325655.313573683829.0.gpush@pororo> To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sh@vger.kernel.org From: Jeremy Kerr Date: Fri, 20 May 2011 15:27:49 +0800 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110520_032803_177971_A5878134 X-CRM114-Status: GOOD ( 12.56 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Thomas Gleixner X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 20 May 2011 07:30:16 +0000 (UTC) Signed-off-by: Jeremy Kerr --- drivers/clk/Kconfig | 4 ++++ drivers/clk/Makefile | 1 + drivers/clk/clk-gate.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 13 +++++++++++++ 4 files changed, 59 insertions(+) diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 0a27963..75d2902 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -9,3 +9,7 @@ config GENERIC_CLK config GENERIC_CLK_FIXED bool depends on GENERIC_CLK + +config GENERIC_CLK_GATE + bool + depends on GENERIC_CLK diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 9a3325a..d186446 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o obj-$(CONFIG_GENERIC_CLK) += clk.o obj-$(CONFIG_GENERIC_CLK_FIXED) += clk-fixed.o +obj-$(CONFIG_GENERIC_CLK_GATE) += clk-gate.o diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c new file mode 100644 index 0000000..833e0da --- /dev/null +++ b/drivers/clk/clk-gate.c @@ -0,0 +1,41 @@ + +#include +#include +#include + +#define to_clk_gate(clk) container_of(clk, struct clk_gate, hw) + +static unsigned long clk_gate_get_rate(struct clk_hw *clk) +{ + return clk_get_rate(clk_get_parent(clk->clk)); +} + +static int clk_gate_enable(struct clk_hw *clk) +{ + struct clk_gate *gate = to_clk_gate(clk); + u32 reg; + + reg = __raw_readl(gate->reg); + reg |= 1 << gate->bit_idx; + __raw_writel(reg, gate->reg); + + return 0; +} + +static void clk_gate_disable(struct clk_hw *clk) +{ + struct clk_gate *gate = to_clk_gate(clk); + u32 reg; + + reg = __raw_readl(gate->reg); + reg &= ~(1 << gate->bit_idx); + __raw_writel(reg, gate->reg); +} + +struct clk_hw_ops clk_gate_ops = { + .recalc_rate = clk_gate_get_rate, + .enable = clk_gate_enable, + .disable = clk_gate_disable, +}; +EXPORT_SYMBOL_GPL(clk_gate_ops); + diff --git a/include/linux/clk.h b/include/linux/clk.h index fd62e86..7c26135 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -124,6 +124,19 @@ extern struct clk_hw_ops clk_fixed_ops; #endif /* CONFIG_GENERIC_CLK_FIXED */ +#ifdef CONFIG_GENERIC_CLK_GATE + +struct clk_gate { + struct clk_hw hw; + void __iomem *reg; + u8 bit_idx; +}; + +extern struct clk_hw_ops clk_gate_ops; + +#endif /* CONFIG_GENERIC_CLK_GATE */ + + #else /* !CONFIG_GENERIC_CLK */ /*