From patchwork Tue Jun 2 18:45:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 49434 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B692120BD1 for ; Tue, 2 Jun 2015 18:46:21 +0000 (UTC) Received: by wgme6 with SMTP id e6sf42401683wgm.3 for ; Tue, 02 Jun 2015 11:46:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=BsZSmdJ2AG3c/TVUr/rttsCV3AHN1+slWVUOYoKtcWs=; b=IPBg8aFJ7cnTwgoNCR9qaatMIPuI9tASsbphKMJr9tRhA/AROD+02PNfieFVgQpok0 T19z5xNTQBwsJvRcaOosLUQVfAxGawt5jm32Q3Z/6axCndXQcklLWp2N/eUp7UjzpXAw +FrVe+GlCBp7wqnlwTz5JomjQqtyEq+BxUItViLhoN4tXuZSKQ1Y2Pw42YfwVHik3VmT evOKuhvQ05jJuJPfzwD8gFzUCKuwo63YFruFiKrLXC2wLtfxmtTixk96zrKxOL76b/3L X/9ngC8ant3nk5eOTF8MhzM3czyxhBr61Q+bkv3InxBcbj5DlNpV+yr4N3xgmxSlxuN5 rS7g== X-Gm-Message-State: ALoCoQn9LFdPIAnZsxNuueOL2+LjH0bWVqsryaqE0HznZuMvPh4VJmcSthKQLfjLFwNCamzWUum3 X-Received: by 10.152.37.101 with SMTP id x5mr26962482laj.5.1433270780952; Tue, 02 Jun 2015 11:46:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.74 with SMTP id y10ls401562lay.41.gmail; Tue, 02 Jun 2015 11:46:20 -0700 (PDT) X-Received: by 10.112.72.104 with SMTP id c8mr25907461lbv.77.1433270780806; Tue, 02 Jun 2015 11:46:20 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id r10si15566967lal.134.2015.06.02.11.46.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 11:46:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by labpy14 with SMTP id py14so120882636lab.0 for ; Tue, 02 Jun 2015 11:46:20 -0700 (PDT) X-Received: by 10.112.150.167 with SMTP id uj7mr20232085lbb.112.1433270780702; Tue, 02 Jun 2015 11:46:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3276762lbb; Tue, 2 Jun 2015 11:46:19 -0700 (PDT) X-Received: by 10.68.130.42 with SMTP id ob10mr14846645pbb.151.1433270778766; Tue, 02 Jun 2015 11:46:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qk1si27289912pbb.80.2015.06.02.11.46.17; Tue, 02 Jun 2015 11:46:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754591AbbFBSqR (ORCPT + 1 other); Tue, 2 Jun 2015 14:46:17 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:35180 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754366AbbFBSqQ (ORCPT ); Tue, 2 Jun 2015 14:46:16 -0400 Received: by pdbnf5 with SMTP id nf5so77625896pdb.2 for ; Tue, 02 Jun 2015 11:46:16 -0700 (PDT) X-Received: by 10.68.247.166 with SMTP id yf6mr14775907pbc.3.1433270775933; Tue, 02 Jun 2015 11:46:15 -0700 (PDT) Received: from localhost.localdomain ([223.190.86.187]) by mx.google.com with ESMTPSA id jx5sm18222527pbc.85.2015.06.02.11.46.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jun 2015 11:46:14 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, wsa@the-dreams.de, Vaibhav Hiremath , Haojian Zhuang Subject: [PATCH-RESEND 2/3] i2c: pxa: Add support for hardware lock Date: Wed, 3 Jun 2015 00:15:30 +0530 Message-Id: <1433270731-23790-3-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433270731-23790-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1433270731-23790-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: vaibhav.hiremath@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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);