From patchwork Thu May 28 13:32:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 6498771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DEA929F1C1 for ; Thu, 28 May 2015 13:39:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AFC8E20629 for ; Thu, 28 May 2015 13:39:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1725720627 for ; Thu, 28 May 2015 13:39:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YxxzB-0005BO-Ft; Thu, 28 May 2015 13:36:37 +0000 Received: from mail-pd0-f175.google.com ([209.85.192.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YxxyA-0004Xe-Ky for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2015 13:35:35 +0000 Received: by pdbki1 with SMTP id ki1so42068810pdb.1 for ; Thu, 28 May 2015 06:35:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HWOr4njEte/rtS+qHZtgM5RmdnAKTE/CI68NQp4gHn4=; b=My2K4Uk/VMJlRvsKpgH5wR9VMoUWIpprrFezFHuSpcYX2nNAJdqhfUn8vWU+yVwYz6 sN6vKFroTTLhjTkQhp4D9tlUfNeNe101v4AEGtimO1LoaXXA76hDr/lyMdcYzYr9qaK1 7Pn/cwnsrTbUvxLMw6+0uMSRUeuxFKzTVz5PjEGEa3n74fWdMlu+i9AxYkE9yvzRYO+c EhtN6Zh6IurQ680QSEmaP4Svf/q5/k8HR05z3JkL9WvdvLh3P80WTn3vsQd2MwTNH9o8 KJ68TdI4aM8Ut/i2ExcjPLOGk49uYfndZBBv5QAWiZA3t0PmZFTHulvOKZVWAqgt+wYl 61rQ== X-Gm-Message-State: ALoCoQn4R8JTtdTnR07SNP15VmvcdpkOMPKuD2LAWE7sWeYQO/gcC3jkG+Z1raOj1mp0lgao0u9R X-Received: by 10.68.232.194 with SMTP id tq2mr5653612pbc.90.1432820112909; Thu, 28 May 2015 06:35:12 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id f1sm2473461pds.62.2015.05.28.06.35.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 06:35:11 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Subject: [PATCH 2/3] i2c: pxa: Add support for hardware lock Date: Thu, 28 May 2015 19:02:47 +0530 Message-Id: <1432819968-17515-3-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432819968-17515-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1432819968-17515-1-git-send-email-vaibhav.hiremath@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150528_063534_758389_E7EC7647 X-CRM114-Status: GOOD ( 14.61 ) X-Spam-Score: -1.8 (-) Cc: Haojian Zhuang , Vaibhav Hiremath , linux-arm-kernel@lists.infradead.org, Wolfram Sang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case of PXA910 silicon, both AP and CP are present and these two ARM cores are sharing one pair of I2C pins. In order to keep I2C transaction operated with atomic, hardware lock (RIPC) is required. This patch extends support for atomic operation by adding hardware lock. Signed-off-by: Haojian Zhuang Signed-off-by: Vaibhav Hiremath --- drivers/i2c/busses/i2c-pxa.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/pxa-i2c.h | 4 +++ 2 files changed, 79 insertions(+) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index f51d512..eb26eb1 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -167,6 +167,7 @@ struct pxa_i2c { void __iomem *reg_isar; void __iomem *reg_ilcr; void __iomem *reg_iwcr; + void __iomem *hwlock_addr; unsigned long iobase; unsigned long iosize; @@ -368,6 +369,9 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret); static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id); +spinlock_t lock_for_ripc; +static int ripc_status; + /* enable/disable i2c unit */ static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable) { @@ -378,6 +382,57 @@ static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable) udelay(100); } +void mmp_hwlock_lock(struct i2c_adapter *adap) +{ + int cnt = 0; + unsigned long flags; + + struct pxa_i2c *i2c = adap->algo_data; + + spin_lock_irqsave(&lock_for_ripc, flags); + while(__raw_readl(i2c->hwlock_addr)) { + ripc_status = false; + spin_unlock_irqrestore(&lock_for_ripc, flags); + cpu_relax(); + udelay(50); + cnt++; + if (cnt >= 10000) { + pr_warn("AP: fail to lock ripc!\n"); + cnt = 0; + } + } + /* sure to hold ripc */ + ripc_status = true; + + spin_unlock_irqrestore(&lock_for_ripc, flags); +} + +void mmp_hwlock_unlock(struct i2c_adapter *adap) +{ + unsigned long flags; + + struct pxa_i2c *i2c = adap->algo_data; + + spin_lock_irqsave(&lock_for_ripc, flags); + __raw_writel(1, i2c->hwlock_addr); + ripc_status = false; + + spin_unlock_irqrestore(&lock_for_ripc, flags); +} + +int mmp_hwlock_trylock(struct i2c_adapter *adap) +{ + unsigned long flags; + + struct pxa_i2c *i2c = adap->algo_data; + + spin_lock_irqsave(&lock_for_ripc, flags); + ripc_status = !__raw_readl(i2c->hwlock_addr); + spin_unlock_irqrestore(&lock_for_ripc, flags); + + return ripc_status; +} + static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) { return !(readl(_ICR(i2c)) & ICR_SCLE); @@ -1347,6 +1402,14 @@ static int i2c_pxa_probe(struct platform_device *dev) i2c->iobase = res->start; i2c->iosize = resource_size(res); + res = platform_get_resource(dev, IORESOURCE_MEM, 1); + if (res) { + i2c->hwlock_addr = ioremap(res->start, resource_size(res)); + dev_info(&dev->dev, "hardware lock address: 0x%p\n", + i2c->hwlock_addr); + } else + dev_dbg(&dev->dev, "no hardware lock used\n"); + i2c->irq = irq; i2c->slave_addr = I2C_PXA_SLAVE_ADDR; @@ -1360,6 +1423,18 @@ static int i2c_pxa_probe(struct platform_device *dev) i2c->ilcr = plat->ilcr; i2c->iwcr = plat->iwcr; i2c->adap.class = plat->class; + + i2c->adap.hardware_lock = plat->hardware_lock; + i2c->adap.hardware_unlock = plat->hardware_unlock; + i2c->adap.hardware_trylock = plat->hardware_trylock; + } else { + if (i2c->hwlock_addr) { + spin_lock_init(&lock_for_ripc); + + i2c->adap.hardware_lock = mmp_hwlock_lock; + i2c->adap.hardware_unlock = mmp_hwlock_unlock; + i2c->adap.hardware_trylock = mmp_hwlock_trylock; + } } if (i2c->high_mode) { diff --git a/include/linux/i2c/pxa-i2c.h b/include/linux/i2c/pxa-i2c.h index d1a44e8..e6f5981 100644 --- a/include/linux/i2c/pxa-i2c.h +++ b/include/linux/i2c/pxa-i2c.h @@ -72,6 +72,10 @@ struct i2c_pxa_platform_data { unsigned long rate; unsigned int ilcr; unsigned int iwcr; + void (*hardware_lock)(struct i2c_adapter *); + void (*hardware_unlock)(struct i2c_adapter *); + int (*hardware_trylock)(struct i2c_adapter *); + }; extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info);