From patchwork Mon Jul 6 19:24:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 50789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 009D3229FC for ; Mon, 6 Jul 2015 19:29:27 +0000 (UTC) Received: by wguu7 with SMTP id u7sf53488031wgu.0 for ; Mon, 06 Jul 2015 12:29:26 -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=ZfzV+ybHvON6EqB9OXk9ZpEQzqn6f6YcB5+NmESWIS0=; b=bv8lOYrCfrEkSkBrVHxI0gF1Tcejy5d3+JnOymdSaLJiV0dT/j1WU/i+mDw5AhcTcz 9MzjrHUmWCm0c6ZytbnpdELk3q7Q1BVTC84bUE0dZw4pFgJEdSj8aDQgE3LYvdgJbUjg 28twrWJizGKrotqUwbapDicwZuZx/w+VmzVQZv7OkYojR8X+EWANRLUhuCX86SeOnbSO 4aMa729eSyDljAcM94zoZdd87hL1YhujY8YuLUrTCAqmvDALh6ghvehW4BV3g73sTkWi GNjifQd72Fvq4eJ1B86iq2DPtMIAZK8LZxiksVqA/zRLp4vtAxXwzh9Mcotvk/QEI47l f4Bw== X-Gm-Message-State: ALoCoQly37OT9TdXaGXVEsBwhRr3BP5l08LMpuhMS9vf+32XALDToKoTPD9VmIKx6hsVzID0HIIa X-Received: by 10.194.175.36 with SMTP id bx4mr217549wjc.1.1436210966279; Mon, 06 Jul 2015 12:29:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.195 with SMTP id da3ls736022lac.43.gmail; Mon, 06 Jul 2015 12:29:26 -0700 (PDT) X-Received: by 10.112.55.70 with SMTP id q6mr355038lbp.99.1436210965988; Mon, 06 Jul 2015 12:29:25 -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 l9si16015480laf.165.2015.07.06.12.29.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 12:29:25 -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 labgy5 with SMTP id gy5so15629905lab.2 for ; Mon, 06 Jul 2015 12:29:25 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr457959lbb.36.1436210965817; Mon, 06 Jul 2015 12:29:25 -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 hn6csp1921778lbb; Mon, 6 Jul 2015 12:29:24 -0700 (PDT) X-Received: by 10.68.228.168 with SMTP id sj8mr885715pbc.102.1436210963915; Mon, 06 Jul 2015 12:29:23 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rl6si17680745pbc.99.2015.07.06.12.29.22; Mon, 06 Jul 2015 12:29:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 S1755215AbbGFT2L (ORCPT + 8 others); Mon, 6 Jul 2015 15:28:11 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:34338 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755178AbbGFT2J (ORCPT ); Mon, 6 Jul 2015 15:28:09 -0400 Received: by pdbep18 with SMTP id ep18so110936886pdb.1 for ; Mon, 06 Jul 2015 12:28:08 -0700 (PDT) X-Received: by 10.70.129.204 with SMTP id ny12mr814534pdb.77.1436210888067; Mon, 06 Jul 2015 12:28:08 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id x7sm19293964pas.28.2015.07.06.12.28.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jul 2015 12:28:06 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, wsa@the-dreams.de, robert.jarzmik@free.fr, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, Yi Zhang , Vaibhav Hiremath Subject: [PATCH-v3 07/11] i2c: pxa: enable/disable i2c module across msg xfer Date: Tue, 7 Jul 2015 00:54:51 +0530 Message-Id: <1436210695-19159-8-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436210695-19159-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1436210695-19159-1-git-send-email-vaibhav.hiremath@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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: , 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. 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 2de9300..dfd1dd0 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)) @@ -1271,6 +1307,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);