From patchwork Thu May 28 13:03:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 6498641 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 49E529F1CC for ; Thu, 28 May 2015 13:19:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64E212053F for ; Thu, 28 May 2015 13:19:53 +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 6FB2920529 for ; Thu, 28 May 2015 13:19:52 +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 1YxxfL-0004bD-3d; Thu, 28 May 2015 13:16:07 +0000 Received: from mail-pa0-f52.google.com ([209.85.220.52]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YxxWy-0005DN-Fh for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2015 13:07:29 +0000 Received: by pabru16 with SMTP id ru16so23255663pab.1 for ; Thu, 28 May 2015 06:07:09 -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=qraLoBviWFhuJTl8LBbtoSHFR1/0PXnw3padupvQ3IA=; b=mWevwfkN35I469z8svBf5SaLCGDtlfKGKMp0nEYK/2Fg4/4zBmj/6ltK3ViV36TRE8 yJ5FIs2s4e25Agz66VOXTtwsRp0gcO8nLB1fw/FGtsH2KXmva5X7XEma+tVPaeiboN56 u2xX2aeGkm4wxyBTNPKGwD+BnqjrVv/OcsN5UEcMk8/94XczTi2pKeZwhz/9eWPUDMHV MRNUDEXwmSL83JxgLJSt2UqzJuRgqxCgRsMLL+XixsTKb1zrtirj8x0Rn5edpcyBlpCk jHNgqtvOmJbDNDnwpGjqJK0p6FtbjHUkWAJJTRTSbL+jfYV/NbuTs25uYtGYClAbC4xo 1gYA== X-Gm-Message-State: ALoCoQl4QCaAmeviYpdOP5BBh0oDBh0XPhdi4R5Lx6c8OqnjeuRp+a5qElff6yapsz0P15Cqee3C X-Received: by 10.68.57.200 with SMTP id k8mr5368537pbq.61.1432818429690; Thu, 28 May 2015 06:07:09 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id dc5sm2392557pbc.53.2015.05.28.06.07.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 06:07:08 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Subject: [PATCH 12/12] i2c: pxa: enable/disable i2c module across msg xfer Date: Thu, 28 May 2015 18:33:44 +0530 Message-Id: <1432818224-17070-13-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432818224-17070-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1432818224-17070-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_060728_663258_51BCE2D3 X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: -0.7 (/) Cc: Yi Zhang , 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 From: Yi Zhang Enable i2c module/unit before transmission and disable when it finishes. why? It's because the i2c bus may be distrubed if the slave device, typically a touch, powers on. Signed-off-by: Yi Zhang [vaibhav.hiremath@linaro.org: ported to latest kernel & also improved changelog] Signed-off-by: Vaibhav Hiremath Signed-off-by: Vaibhav Hiremath --- drivers/i2c/busses/i2c-pxa.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 844e1fc..f51d512 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -368,6 +368,16 @@ 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); +/* enable/disable i2c unit */ +static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable) +{ + if (enable) + writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c)); + else + writel(readl(_ICR(i2c)) & ~ICR_IUE, _ICR(i2c)); + udelay(100); +} + static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) { return !(readl(_ICR(i2c)) & ICR_SCLE); @@ -575,8 +585,7 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c) i2c_pxa_set_slave(i2c, 0); /* enable unit */ - writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c)); - udelay(100); + i2c_pxa_enable(i2c, true); } @@ -933,6 +942,9 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, struct pxa_i2c *i2c = adap->algo_data; int ret, i; + /* Enable i2c unit */ + i2c_pxa_enable(i2c, true); + /* If the I2C controller is disabled we need to reset it (probably due to a suspend/resume destroying state). We do this here as we can then avoid worrying about resuming the @@ -953,6 +965,10 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, ret = -EREMOTEIO; out: i2c_pxa_set_slave(i2c, ret); + + /* disable i2c unit */ + i2c_pxa_enable(i2c, false); + return ret; } @@ -1168,6 +1184,9 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num struct pxa_i2c *i2c = adap->algo_data; int ret, i; + /* Enable i2c unit */ + i2c_pxa_enable(i2c, true); + enable_irq(i2c->irq); for (i = adap->retries; i >= 0; i--) { ret = i2c_pxa_do_xfer(i2c, msgs, num); @@ -1183,6 +1202,9 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num out: i2c_pxa_set_slave(i2c, ret); disable_irq(i2c->irq); + /* disable i2c unit */ + i2c_pxa_enable(i2c, false); + return ret; } @@ -1407,6 +1429,9 @@ static int i2c_pxa_probe(struct platform_device *dev) ret = 0; } } + + i2c_pxa_enable(i2c, false); + #ifdef CONFIG_I2C_PXA_SLAVE pr_info("I2C: %s: PXA I2C adapter, slave address %d\n", dev_name(&i2c->adap.dev), i2c->slave_addr);