From patchwork Tue Jul 21 12:41:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 51305 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id CEDB222AA3 for ; Tue, 21 Jul 2015 12:46:28 +0000 (UTC) Received: by lbbvz8 with SMTP id vz8sf47243837lbb.2 for ; Tue, 21 Jul 2015 05:46:27 -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=e3CB9NSVBhmHbnmMoS0WRFlbYBaO7w4CTtmVDM/UJ2A=; b=JLNKGFS+n8U1VX7MWFWsjXIx0+i0yAgSZDkugeEVYk5G9cdL0tmz7+Ed+7kldDCTDx jIC17wbpL0mSmJnx6TFHgGbFL0fcTe2LCnog3LNQmHLjYJ3y+rnBu2YzjP62lMEBkJWx INEom24ZFcht9vW54H2dApfW/sMO6VtOzWMrXF5b69iDWLdufg8I2YM5HifUDZCUR/XW trFrIaMO2jOc7DYorsv5m4pgf9IX+COb1+ibc+jEq+IpZACFrEzoWBXidVlicmSsw62y Zi2EIi6cmJwb5wpCLwYUHHT7s/PqSRNnYWdmRpsg7WcmTDaaaodVNql2bMTxW59ofs2e Zinw== X-Gm-Message-State: ALoCoQnj+qjhjzycuhwlMaKFwLs8et/CbbK0OLZy2aAf68ywMLLxrJSFFYcgvtSawfp/zFxPJny5 X-Received: by 10.194.179.42 with SMTP id dd10mr17637290wjc.7.1437482787757; Tue, 21 Jul 2015 05:46:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.162 with SMTP id n2ls914180laf.82.gmail; Tue, 21 Jul 2015 05:46:27 -0700 (PDT) X-Received: by 10.112.198.100 with SMTP id jb4mr20904725lbc.97.1437482787553; Tue, 21 Jul 2015 05:46:27 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id ay7si20699293lbc.60.2015.07.21.05.46.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 05:46:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by laem6 with SMTP id m6so116912000lae.0 for ; Tue, 21 Jul 2015 05:46:27 -0700 (PDT) X-Received: by 10.152.18.162 with SMTP id x2mr32950471lad.73.1437482787148; Tue, 21 Jul 2015 05:46:27 -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.7.198 with SMTP id l6csp1424254lba; Tue, 21 Jul 2015 05:46:25 -0700 (PDT) X-Received: by 10.70.136.196 with SMTP id qc4mr73339063pdb.150.1437482784968; Tue, 21 Jul 2015 05:46:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id an7si9225740pad.131.2015.07.21.05.46.23; Tue, 21 Jul 2015 05:46:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 S932787AbbGUMqO (ORCPT + 28 others); Tue, 21 Jul 2015 08:46:14 -0400 Received: from mail-pd0-f171.google.com ([209.85.192.171]:33147 "EHLO mail-pd0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932494AbbGUMqJ (ORCPT ); Tue, 21 Jul 2015 08:46:09 -0400 Received: by pdbnt7 with SMTP id nt7so49419594pdb.0 for ; Tue, 21 Jul 2015 05:46:08 -0700 (PDT) X-Received: by 10.66.146.226 with SMTP id tf2mr73895729pab.4.1437482768689; Tue, 21 Jul 2015 05:46:08 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by smtp.gmail.com with ESMTPSA id f4sm27378854pdc.95.2015.07.21.05.46.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jul 2015 05:46:07 -0700 (PDT) From: Vaibhav Hiremath To: linux-arm-kernel@lists.infradead.org Cc: robert.jarzmik@free.fr, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, Yi Zhang , Vaibhav Hiremath Subject: [PATCH-v5 2/5] i2c: pxa: enable/disable i2c module across msg xfer Date: Tue, 21 Jul 2015 18:11:03 +0530 Message-Id: <1437482466-16126-3-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437482466-16126-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1437482466-16126-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.50 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: , From: Yi Zhang Enable i2c module/unit before transmission and disable when it finishes. why? It's because the i2c bus may be disturbed if the slave device, typically a touch, powers on. As we do not want to break slave mode support, this patch introduces DT property to control disable of the I2C module after xfer in master mode of operation. i2c-disable-after-xfer : If set, driver will disable I2C module after msg xfer Signed-off-by: Yi Zhang Signed-off-by: Vaibhav Hiremath --- drivers/i2c/busses/i2c-pxa.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 66cf437..abf04f2 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -161,6 +161,7 @@ struct pxa_i2c { unsigned char master_code; unsigned long rate; bool highmode_enter; + bool disable_after_xfer; }; #define _IBMR(i2c) ((i2c)->reg_ibmr) @@ -284,6 +285,24 @@ 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 int i2c_pxa_is_enabled(struct pxa_i2c *i2c) +{ + return (readl(_ICR(i2c)) & ICR_IUE); +} + +static inline void i2c_pxa_enable(struct pxa_i2c *i2c, bool enable) +{ + if (enable) { + if (!i2c_pxa_is_enabled(i2c)) { + writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c)); + udelay(100); + } + } else { + writel(readl(_ICR(i2c)) & ~ICR_IUE, _ICR(i2c)); + } +} + static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) { return !(readl(_ICR(i2c)) & ICR_SCLE); @@ -480,8 +499,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); } @@ -832,6 +850,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 @@ -852,6 +873,11 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, ret = -EREMOTEIO; out: i2c_pxa_set_slave(i2c, ret); + + /* disable i2c unit */ + if (i2c->disable_after_xfer) + i2c_pxa_enable(i2c, false); + return ret; } @@ -1067,6 +1093,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); + for (i = adap->retries; i >= 0; i--) { ret = i2c_pxa_do_xfer(i2c, msgs, num); if (ret != I2C_RETRY) @@ -1080,6 +1109,10 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num ret = -EREMOTEIO; out: i2c_pxa_set_slave(i2c, ret); + /* disable i2c unit */ + if (i2c->disable_after_xfer) + i2c_pxa_enable(i2c, false); + return ret; } @@ -1120,6 +1153,9 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, /* For device tree we always use the dynamic or alias-assigned ID */ i2c->adap.nr = -1; + i2c->disable_after_xfer = of_property_read_bool(np, + "i2c-disable-after-xfer"); + if (of_get_property(np, "mrvl,i2c-polling", NULL)) i2c->use_pio = 1; if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) @@ -1264,6 +1300,9 @@ static int i2c_pxa_probe(struct platform_device *dev) platform_set_drvdata(dev, i2c); + if (i2c->disable_after_xfer) + i2c_pxa_enable(i2c, false); + #ifdef CONFIG_I2C_PXA_SLAVE dev_info(&i2c->adap.dev, " PXA I2C adapter, slave address %d\n", i2c->slave_addr);