From patchwork Thu Dec 15 01:24:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Zhao X-Patchwork-Id: 5737 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 420D223E04 for ; Thu, 15 Dec 2011 01:25:15 +0000 (UTC) Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com [74.125.83.52]) by fiordland.canonical.com (Postfix) with ESMTP id 32678A180EC for ; Thu, 15 Dec 2011 01:25:15 +0000 (UTC) Received: by mail-ee0-f52.google.com with SMTP id e52so1692373eek.11 for ; Wed, 14 Dec 2011 17:25:15 -0800 (PST) Received: by 10.204.157.12 with SMTP id z12mr283957bkw.18.1323912314967; Wed, 14 Dec 2011 17:25:14 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs25770bkc; Wed, 14 Dec 2011 17:25:14 -0800 (PST) Received: by 10.224.105.11 with SMTP id r11mr1943275qao.68.1323912312857; Wed, 14 Dec 2011 17:25:12 -0800 (PST) Received: from ch1outboundpool.messaging.microsoft.com (ch1ehsobe003.messaging.microsoft.com. [216.32.181.183]) by mx.google.com with ESMTPS id hp8si3325790qab.110.2011.12.14.17.25.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 17:25:12 -0800 (PST) Received-SPF: neutral (google.com: 216.32.181.183 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) client-ip=216.32.181.183; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.181.183 is neither permitted nor denied by best guess record for domain of B20223@freescale.com) smtp.mail=B20223@freescale.com Received: from mail52-ch1-R.bigfish.com (10.43.68.246) by CH1EHSOBE005.bigfish.com (10.43.70.55) with Microsoft SMTP Server id 14.1.225.23; Thu, 15 Dec 2011 01:25:13 +0000 Received: from mail52-ch1 (localhost [127.0.0.1]) by mail52-ch1-R.bigfish.com (Postfix) with ESMTP id 6F694500311; Thu, 15 Dec 2011 01:25:16 +0000 (UTC) X-SpamScore: 10 X-BigFish: VS10(z1039ozc8kzz1202hzz8275dhz2dh2a8h668h839h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail52-ch1 (localhost.localdomain [127.0.0.1]) by mail52-ch1 (MessageSwitch) id 1323912314290397_2792; Thu, 15 Dec 2011 01:25:14 +0000 (UTC) Received: from CH1EHSMHS017.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.243]) by mail52-ch1.bigfish.com (Postfix) with ESMTP id 41B3B4E0043; Thu, 15 Dec 2011 01:25:14 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS017.bigfish.com (10.43.70.17) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 15 Dec 2011 01:25:11 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.355.3; Wed, 14 Dec 2011 19:25:08 -0600 Received: from b20223-02.ap.freescale.net (b20223-02.ap.freescale.net [10.192.242.124]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id pBF1OvgK018541; Wed, 14 Dec 2011 19:25:06 -0600 (CST) From: Richard Zhao To: CC: , Richard Zhao Subject: [RFC V2 5/8] ARM i.MX: clk: add generic support of gate2b Date: Thu, 15 Dec 2011 09:24:52 +0800 Message-ID: <1323912295-21144-5-git-send-email-richard.zhao@freescale.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323912295-21144-1-git-send-email-richard.zhao@freescale.com> References: <1323854638-3455-1-git-send-email-richard.zhao@linaro.org> <1323912295-21144-1-git-send-email-richard.zhao@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com From: Richard Zhao gate with two control bits is found in imx5/6 CCGR registers. Signed-off-by: Richard Zhao --- arch/arm/plat-mxc/Kconfig | 4 ++ arch/arm/plat-mxc/Makefile | 1 + arch/arm/plat-mxc/clk-gate2b.c | 88 ++++++++++++++++++++++++++++++++ arch/arm/plat-mxc/include/mach/clock.h | 22 ++++++++ 4 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 arch/arm/plat-mxc/clk-gate2b.c diff --git a/arch/arm/plat-mxc/Kconfig b/arch/arm/plat-mxc/Kconfig index 903c15e..0f27f05 100644 --- a/arch/arm/plat-mxc/Kconfig +++ b/arch/arm/plat-mxc/Kconfig @@ -110,4 +110,8 @@ config IMX_CLK_PLLV2 bool depends on GENERIC_CLK +config IMX_CLK_GATE2B + bool + depends on GENERIC_CLK + endif diff --git a/arch/arm/plat-mxc/Makefile b/arch/arm/plat-mxc/Makefile index 96d45dc..0689e78 100644 --- a/arch/arm/plat-mxc/Makefile +++ b/arch/arm/plat-mxc/Makefile @@ -7,6 +7,7 @@ obj-y := clock.o time.o devices.o cpu.o system.o irq-common.o obj-$(CONFIG_ARM_GIC) += gic.o obj-$(CONFIG_IMX_CLK_PLLV2) += clk-pllv2.o +obj-$(CONFIG_IMX_CLK_GATE2B) += clk-gate2b.o obj-$(CONFIG_MXC_TZIC) += tzic.o obj-$(CONFIG_MXC_AVIC) += avic.o diff --git a/arch/arm/plat-mxc/clk-gate2b.c b/arch/arm/plat-mxc/clk-gate2b.c new file mode 100644 index 0000000..f406508 --- /dev/null +++ b/arch/arm/plat-mxc/clk-gate2b.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011 Richard Zhao, Linaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include + +#define to_clk_gate2b(ck) container_of(ck, struct clk_gate2b, clk) + +static int clk_gate2b_enable(struct clk *clk) +{ + struct clk_gate2b *gate2b = to_clk_gate2b(clk); + unsigned long flags; + u32 reg; + + if (gate2b->lock) + spin_lock_irqsave(gate2b->lock, flags); + + reg = __raw_readl(gate2b->reg); + reg &= ~(0x3 << gate2b->shift); + reg |= gate2b->val_en << gate2b->shift; + __raw_writel(reg, gate2b->reg); + + if (gate2b->lock) + spin_unlock_irqrestore(gate2b->lock, flags); + + return 0; +} + +static void clk_gate2b_disable(struct clk *clk) +{ + struct clk_gate2b *gate2b = to_clk_gate2b(clk); + unsigned long flags; + u32 reg; + + if (gate2b->lock) + spin_lock_irqsave(gate2b->lock, flags); + + reg = __raw_readl(gate2b->reg); + reg &= ~(0x3 << gate2b->shift); + reg |= gate2b->val_dis << gate2b->shift; + __raw_writel(reg, gate2b->reg); + + if (gate2b->lock) + spin_unlock_irqrestore(gate2b->lock, flags); + +} + +struct clk_hw_ops clk_gate2b_ops = { + .enable = clk_gate2b_enable, + .disable = clk_gate2b_disable, +}; +EXPORT_SYMBOL_GPL(clk_gate2b_ops); + +int clk_gate2b_set_val(struct clk *clk, int en, int dis) +{ + struct clk_gate2b *gate2b = to_clk_gate2b(clk); + unsigned long flags; + u32 reg, val; + + en &= 0x3; + dis &= 0x3; + + if (gate2b->lock) + spin_lock_irqsave(gate2b->lock, flags); + + reg = __raw_readl(gate2b->reg); + val = (reg >> gate2b->shift) & 0x3; + reg &= ~(0x3 << gate2b->shift); + if (val == gate2b->val_en && val != en) + reg |= en << gate2b->shift; + else if (val == gate2b->val_dis && val != dis) + reg |= dis << gate2b->shift; + __raw_writel(reg, gate2b->reg); + gate2b->val_en = en; + gate2b->val_dis = dis; + + if (gate2b->lock) + spin_unlock_irqrestore(gate2b->lock, flags); + + return 0; +} +EXPORT_SYMBOL_GPL(clk_gate2b_set_val); diff --git a/arch/arm/plat-mxc/include/mach/clock.h b/arch/arm/plat-mxc/include/mach/clock.h index 2eb11c7..f62256e 100644 --- a/arch/arm/plat-mxc/include/mach/clock.h +++ b/arch/arm/plat-mxc/include/mach/clock.h @@ -87,6 +87,28 @@ extern struct clk_hw_ops clk_pllv2_ops; .base = (_base), \ } +/** + * gate with 2 control bits + * + * @parent the parent clk + * @reg the register address + * @shift control bits offset + * @en_val value when clk enabled + * @dis_val value when clk disabled + */ +struct clk_gate2b { + struct clk clk; + void __iomem *reg; + u8 shift; + u8 val_en:2; + u8 val_dis:2; + spinlock_t *lock; +}; + +extern struct clk_hw_ops clk_gate2b_ops; + +int clk_gate2b_set_val(struct clk *clk, int en, int dis); + #endif /* CONFIG_GENERIC_CLK */ #endif /* __ASSEMBLY__ */ #endif /* __ASM_ARCH_MXC_CLOCK_H__ */