Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3366291ybb; Tue, 31 Mar 2020 03:54:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuTbbRWm+3BEHp1Lt0teM21RGqCEHY6ejU9V6A0RZP88/nuavEFtGUvoKK/q6L4lUTCjtYC X-Received: by 2002:a9d:2215:: with SMTP id o21mr7652626ota.113.1585652072080; Tue, 31 Mar 2020 03:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585652072; cv=none; d=google.com; s=arc-20160816; b=GHh6MGwJ/iLNxnjtj/OBQLiCXXU0U0XfEZRiviEniMn4ktCfh1PW3X8jI0YMwz81mN PxnF4NP6Ap0Y/rF274nfv+mudWZxCMrWE9K5/oqYquCuNb+Vx/lrmL3OK+1rO+LTALX7 6hkyhC5JL2TDPttiiV5g6Z0uiU9YuZ02RPz0l6ys1MxsRjpn/pye6yHxPObPCBPa9tVB hgrWseVKGXNoae+I+dChlPjYkHhiKb40CS+9QklZZ0q9yE68N9+OAel5prALlULZ97TD XFwYN6A4yfVYHGDk7gDMWMQ+irSz0O5BQ80Dmaz7FGT7s+jsRoSns/YMnBa0YX6YwQmF SXDg== 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=q7oDV/H6/P6d9AN0cMKC4ANMY58Y+v9kKfSxI3T+Yhs=; b=clHnBceFCcF6psqsrw5qqT0MmSi8WrzhtxL+d+FduZG4+d3yyEHKETcvRd3ofFft9+ roIxLk4zOzeSPdHsaGkgTtAcNAPMYxkNXP44XWaiShQTzNna15IWDMDN4ZCDHcfr4LoA fCb2matOx+4dsTMw9hWxfzqFXJdcZyv1cqFI17dXHVJ78FreL0IP6asKK7fIs17kn+hu dRXViGmKIvlkivXk4SZjWwQneoCkNt56rC5+tZSysUv8HP510k97xsnCTTy25FGb3wG9 LMv+ofAHbcXBdDfYe25cX9VRPaHgmJm2ldcYjmkq9ehQM4XkOQjvAmlaZMj3ZxaWOe6K mQUA== 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 f23si608295oti.69.2020.03.31.03.54.19; Tue, 31 Mar 2020 03:54:32 -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 S1730604AbgCaKw7 (ORCPT + 99 others); Tue, 31 Mar 2020 06:52:59 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbgCaKw6 (ORCPT ); Tue, 31 Mar 2020 06:52:58 -0400 IronPort-SDR: 1P4plBerY7IQTZL22Hwg8nR6CRKqgS5SAWf98T8t5krWdjzhsim2Hk8BZQxZ08EOzDWRYwZ3gk um5913RNInlQt8kiig8CX2DgKU/8B9oI6u7amTUuAnyxNmSGo8C2Hm48eDmxwkrEeR03Or0Sm5 jriOL+3ionDWwnPVcZk/H9V4IHes/1Y8phrM7Uv8lZvBxTcqJtGjlcY4/RBLiSnVQ7ceRkYasp e1P0/hZ1ANlzmVvE4vYsu911z0FSKdSK1BIYZo4KrDnBpvPoJY0viZgDRwdoYyhoW01b8qB32p Vok= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330801" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:57 -0800 IronPort-SDR: l1rAeDxAILvgDHaBpMuqEIFrvP79wM+CuJbktsJIsqh9YiM9efJzc3o/Om08nV7SsQb9Xdj32+ uxtFIqCwQxYAJtVDr5vdg1CsK+TP6CCW5La3PED1qbeMKix4fCHN5wiHdAtUuIUoH1gEmK2/Ux tXQLskPY9uEEnHbt7qD6ROu7alzk/3r8zg0qx5EZUdY/xc0kjeysUwSpcYpCqLzb7wN9Zhw2Rm jE3NPFmeQztNCL6pEWdkK3KfRdu3BA/KxCtlPCb9CrQ2jJntIm5cjGJNskSM8JD52LJNbh8r+F F4o= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 32/55] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 31 Mar 2020 03:50:28 -0700 Message-ID: <20200331105051.58896-33-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 c26470bcb38b..daa77eb9561b 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