Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5827065ybv; Wed, 12 Feb 2020 00:46:52 -0800 (PST) X-Google-Smtp-Source: APXvYqy1BQ68U73sSKpCPsZq0zKuFl7xD/L6t6dxtnpvc/7XBAqZeC4xqqd8qW+zdtqn5zmtJ9T9 X-Received: by 2002:aca:b608:: with SMTP id g8mr5639433oif.142.1581497212638; Wed, 12 Feb 2020 00:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581497212; cv=none; d=google.com; s=arc-20160816; b=e4DYksxbDHdCEYkUu26nuOj9OT63cnmTiSs6XKIXwwwJ+AxfOSJAkfv0zvn1FRiFS3 VAezNakyL7aQ4Drj0AjEImZ8HlmOMo6D32k5ssgiM0IY7su28GZMQGiZvLyl0KG/zBnB kpbmSriPq7srWw70rWuXA61A5wWnv/OsIN46RglfUloznYZRK0ZDl+PirKNOH2YKvShL h2yKsefjDvPLGpYjOCbJ4avMKflti+Tz7c8KaMSJtOG6bzjF1dCcHXBx/nkrtiYZ5Bck LTd8FD5Si62VfvBCQdik6CdCHeIFxt+cYz+uoXtENF2MHMMD36n0SEQIiMR1DGW1MrOJ pfhQ== 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=CQ2ob3MAf7NDzpESG72Y4fly4sH1Y6Yj+UlFecIsTZw=; b=j+FTZqFxWSvjYW/rNiZ0NFt0131KeAkXJjGhxohtwHJvHf+dSHiRageY6JGJHOkgiz OJPqSeo8gtNdGWOEo6zhzsF3qSEsj1EFl/Fo2c4/WotEpGhoLmx/aF6pBfJ2BNsqN3wH Tak0v2bbsxOmbSjDgjyeHmli2gOGkLT7WRd67wJbI/Ks3ECPKFTFLH0x7BcBzkZp03fL np9z6Y5GLe72glCq1Yp7jXCTTx5/g3PZksIPpdG6ivheMoVzM/vVg1MeYvSoiVjmQD24 PPzTzy7aoH8aiVJAt953G8BvTQKXAYaMt2QfGcCClGkHVO/WWRdZTcL5z2yLSgz6Xd0m jo4g== 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 i15si2930448oik.46.2020.02.12.00.46.40; Wed, 12 Feb 2020 00:46:52 -0800 (PST) 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 S1728546AbgBLIpn (ORCPT + 99 others); Wed, 12 Feb 2020 03:45:43 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:18979 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbgBLIpn (ORCPT ); Wed, 12 Feb 2020 03:45:43 -0500 IronPort-SDR: v5HZ2mwUoVvN3JyBthW4ucNJ8zCfEAzGLgGSYQIJQicN3sHkkFhwJYSnLRhacfNBMI0LUo6L7W 407ra1+fQaWPNjm6kYuuK2p2ot6EN2MCpsWVLlH+So9DmWtkWnE5ptF5aODAgV6Pp4c+QumbFo aaWXerUh4Vc7WFY+JW7HqDlcqDA95LvtNjfEszVRiVXDeJ5MzXUFaqRj/o44i8ach7M675BZUI QNj5BMq0c5XEWiQoV1RvOxR8XZxh51Sb6h8vNiAG5gr2jOD2epjMShkpHyLikLLfe4QUzD4gTy zPc= X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="45742575" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 12 Feb 2020 00:45:42 -0800 IronPort-SDR: +JSlk8LkqYPPurqfsLebXi7nHI61YYUpcN87omqGTs/KXxocL8RZhnzjSgwlKomhQG81ukE3aD 1rcwKneNg7bXF4J6Vp5lAMGEXDTpxJzQPkdSUSffrkUjmm/aGO7i0yE+QG/kV/4p8/OKaTujOU ly++HfcQAy1N5gwtbFN5+G4cFL6u7VpWAB1fMq81j7rdp7nPYGyGLIyt/m/stRqW1EXkkFQGTt YLOqK4pZ8OZgP4KLntv8qoN5lb2nGe0Y5DVGHW7PuUlY34mNTlHVNWN6FKYeAjIAdNJmU5Vezl hG0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v7 26/48] Input: atmel_mxt_ts - implement I2C retries Date: Wed, 12 Feb 2020 00:41:56 -0800 Message-ID: <20200212084218.32344-27-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200212084218.32344-1-jiada_wang@mentor.com> References: <20200212084218.32344-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 ff9a801e9e5e..b20b520cb278 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