Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp595829pja; Thu, 19 Mar 2020 08:04:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtDVLkp2c+R1VZQbZ1crfkpzKasq6qkWKOMLR+I9Wr9j8OEO6DQfmhH+bqIYcZx6TjIGQFa X-Received: by 2002:a05:6830:231d:: with SMTP id u29mr2530059ote.1.1584630240313; Thu, 19 Mar 2020 08:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584630240; cv=none; d=google.com; s=arc-20160816; b=xHBFFwHE62dCDcWe58inss+EdCXAFRjPe+uJAUhIjLkaBO/6HA+slBiGaxrEdS9EhC A9TcHKUSE02G4u5S8lUDHIw9DtELmyUVm/UvASs3YMtwOB9/hdEAZB3Gr5vximDwSiZ0 Prl+dUo3Q2+Zw8IEicZ5qBaYJQkTPu5Ql5SSEDlFBkPrMkPMfUtwaBy7vsJUICMQLM7/ 0xbckfxBLu5zgOfKcQ4TyxiPNjAulCZp4249XBb6Q1GZoKN0hP0dDZLgb7h+yBmxc2Zk RbMPu7dk4cihE3beBUxsdxSX6IlWbt1ilTkvW+D/UUtpczy2sew7xvPSA1HmysQ0hKWK 3R/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=25GNYV46y/o7srzvtdsxJ+CqIUucEqyVWzM8/TFmCLI=; b=aaaUAw4q8HtOXOIaqFU9lNquWOy5TUvj5Ks43eZd1LhqAvufDzLAuWcJIt9j90wMZF PpuJdIr998oDhVyZh3n1cJTdpNCnEaHZxf5Wd2W5WYRMgJ5NKYxWpGwBKo8ZOQhcb0pY 219xOobcj5flnxzOZuLUzVuqkKmb+LqyOVmLKQZoPQw8wvZ8k+t9v+GsuLBF0aLNmPP0 XBVXKNUqZ07x8iqtB7oYHqZ30ObFlJNy1CgIM6K5uVpc0qXRg4l4WBvvOgWi1aV1PyUC NJCnJzQtzhso0NhJaipTH6L4Lg6Yspbt+b9VU2oAKGqp0gYODTWdRU+94cR+d3kt9Vtr /Cug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c18si1281367otp.16.2020.03.19.08.03.29; Thu, 19 Mar 2020 08:04:00 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbgCSPCR (ORCPT + 99 others); Thu, 19 Mar 2020 11:02:17 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgCSPCQ (ORCPT ); Thu, 19 Mar 2020 11:02:16 -0400 IronPort-SDR: DDqhPAIgi65i0UbSP7JQ1AM3sPclp2C2kGTvBVe8Z0+dWglERdvX5/OmCPN6hLww43yblged7V 5dCJq9unJBYgKK4I9R1sKlvFBTiAriKZmvhCqYp2L8xaRWU/sZCOrAoM7xClfQwWVSkJTPefi+ +D6c4OK/wsLzclKfhHLwaoepKPxDM84U8RdJWi0goiXDhJe+E9NYI/V5LtIGXcLFuil0ESMh97 9feytIIZ7yXAXU+T1ZNjkl1PxhHUjHNKXCFN/7vbQyP4y89oSdKTed+eGnhC8ICeVqs7J27HLr HVg= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850336" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:15 -0800 IronPort-SDR: 8AHbllqAEXjVKi7pyS7LCzE63lgnJpSwq1IaOWeCJgxcLDCznpIgfnKRvj5DnXiZO9hTXLlcYQ qgjbNCS6UvuYyilE3IT3ka0GKGTBg6t2bIi/SL+jITUJFK4aIWIEtrFTkJOm/xGqoTm8z/eWwI lYT72GVel+K5MBm68fs9eytdzxQ4mgMZXEo0kaW/wzx0PeDdTjDOd9V+kGXLpJRJwUaHXHnLHb pNS2IwyISlfAbU1FE+lRyOmx67bNSALtEacWbDk26YxWrQI+xWCYZyy4ScCHkv98zD/v5kjSSJ 90E= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 29/52] Input: atmel_mxt_ts - implement I2C retries Date: Thu, 19 Mar 2020 07:59:53 -0700 Message-ID: <20200319150016.61398-30-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Dyer Some maXTouch chips (eg mXT1386) will not respond on the first I2C request when they are in a sleep state. It must be retried after a delay for the chip to wake up. Signed-off-by: Nick Dyer Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 63fd7a2cd03c3a572a5db39c52f4856819e1835d) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 45 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a1a322f41f9e..670159c2f218 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -216,6 +216,7 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_WAKEUP_TIME 25 /* msec */ #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ @@ -720,6 +721,7 @@ static int __mxt_read_chunk(struct i2c_client *client, struct i2c_msg xfer[2]; u8 buf[2]; int ret; + bool retry = false; buf[0] = reg & 0xff; buf[1] = (reg >> 8) & 0xff; @@ -736,17 +738,22 @@ static int __mxt_read_chunk(struct i2c_client *client, xfer[1].len = len; xfer[1].buf = val; - ret = i2c_transfer(client->adapter, xfer, 2); - if (ret == 2) { - ret = 0; - } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", - __func__, ret); +retry_read: + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); + if (ret != ARRAY_SIZE(xfer)) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_read; + } else { + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return -EIO; + } } - return ret; + return 0; } static int __mxt_read_reg(struct i2c_client *client, @@ -777,6 +784,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, u8 *buf; size_t count; int ret; + bool retry = false; count = len + 2; buf = kmalloc(count, GFP_KERNEL); @@ -787,14 +795,21 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, buf[1] = (reg >> 8) & 0xff; memcpy(&buf[2], val, len); +retry_write: ret = i2c_master_send(client, buf, count); - if (ret == count) { - ret = 0; - } else { - if (ret >= 0) + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + } + } else { + ret = 0; } kfree(buf); -- 2.17.1