Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4193501pxk; Tue, 8 Sep 2020 13:10:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5TyIcgeFqGdegTVCRZ+x1+L2D1ChNafMEGd2stLrbRT74tu8QdVJBzim04OUaz5F2ieav X-Received: by 2002:a17:906:5611:: with SMTP id f17mr124266ejq.427.1599595807209; Tue, 08 Sep 2020 13:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599595807; cv=none; d=google.com; s=arc-20160816; b=WXLxfP5HzocXRL9Y3UX2L66v3vMcY47Mlgkt9RZSHcD6+Wz93Mwu1Xug7ebt+uy9QZ /R6YB9NHyi6tsXmVvsUyPBnHRNrc9DArjqiNXDGb1GcP1vNeVof/+iRy+IuapWHFeivw vb1Pj+M3mJK5xVZ7a/bBVAjYZnK/I76otY2WiWjOOksADizSMqjXMOSePVPQo9RtRKm4 HKDFU94vGYe1+PRBZDWXJUMvLBxjNGMwWNvQ55iZBXloD1xeKE53KCD+rP2R3oUP5Bqa FZRVDxpqlG13QGQ113R2/z+YOWuHae6aC/6I+10qFPLRLjfmZqmw2OHh7crgu4ynHm8x bHpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:ironport-sdr:ironport-sdr; bh=eL34dPxRwfKaAV7Qd0a3MwFrO9/IgNScvRiwhCeBaYk=; b=XJ04GOcCOnkmSaa9+EW1H7dZOcq3T7WTvEmbCcyy9JvKH12umfJHYlou9JU65LxLXJ gWa08QTmjkX87LWJ3VXBx+ukg9PKJpOaxZEiT2mjfOBsemy0TRF5j2RCtH6xrIuanD6s +S7N2ZAY+SgnEGAjaXglyZul01epucT4AgermoJd7rD6b7PahCfi1uTWxrVZtwWgwlj+ dS3/gaD//Z4cq2zVsge1xcBimvCHsYi7gTfhjvb1/k0GwjWgn3CwRii2QrkmaL2eYT0O 4DwrdZoe8X+eY7CuX2wtAKJ7Lgxe/0lCD+oEeIS6utywnpllL6w1mYOjeLoUtt50Zigl ydpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p2si89580edj.495.2020.09.08.13.09.44; Tue, 08 Sep 2020 13:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731208AbgIHUHE (ORCPT + 99 others); Tue, 8 Sep 2020 16:07:04 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:33588 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730242AbgIHPUy (ORCPT ); Tue, 8 Sep 2020 11:20:54 -0400 IronPort-SDR: A73xvdNyxsY1l7xwjxJRzrRhOuzXupkcYc7ZnS9I/MNbCnhE9r2NMD/gVfWfXdzVty37py88yS NsXtFfY/Muyg63BxZjpYbBXfRFG04MmYT57C+RXVz3+GCiQompLecUbPTf3XMslGO9QxZutYcm up9zpP34cHyNIjuEQb4bmnArGmKRsAqVQJeEEjoI6qmG7OD/+5r+/46QfuanAknkowz+r4WEmX IZEhD2jPoyRil9+uKahwsYvK6FCYApCTsqvO7emc+uIJe8z/xQdKmOenGmv46BKG+QbiRE3Vrk YjI= X-IronPort-AV: E=Sophos;i="5.76,406,1592899200"; d="scan'208";a="54874117" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 08 Sep 2020 07:16:21 -0800 IronPort-SDR: znhbrejcoFm31kQaQGxCn2w+iduSV/IKA2TT4r1XS0EBSjw2Pr5fv1wQumrikkaJ1hSuarFb4s GV3qBM/i3FpkYx6cmzVbLKW8qjXfCZ8k6zSdKu0b+ABC5WveJ1o2d4k8gvxQ8QXOtB/wbotcBs TW68eAoAHaXsXVvjJ5x/aQYwqluOE83Bsgh0GFK6EXUY8UrxELnM5osWO7dmkESPBhEN7a/eXg uKiZ33eIxolrJL0wGX6LZatW/wPKcNJABrnVbCSAQZ3EMQr24R8ZRk+x0sKCoQbgj/DHNUh1oV Hsk= From: Jiada Wang To: , CC: , , , , , Subject: [PATCH v3 1/1] Input: atmel_mxt_ts - implement I2C retries Date: Wed, 9 Sep 2020 00:16:17 +0900 Message-ID: <20200908151617.12199-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 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 [jiada: return exact errno when i2c_transfer & i2c_master_send fails, add "_MS" suffix MXT_WAKEUP_TIME] 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 a2189739e30f..145780f78122 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -196,6 +196,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_MS 25 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -626,6 +627,7 @@ static int __mxt_read_reg(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; @@ -642,17 +644,22 @@ static int __mxt_read_reg(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_MS); + retry = true; + goto retry_read; + } else { + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return ret < 0 ? ret : -EIO; + } } - return ret; + return 0; } static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, @@ -661,6 +668,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); @@ -671,14 +679,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; + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME_MS); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); + ret = ret < 0 ? ret : -EIO; + } } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + ret = 0; } kfree(buf); -- 2.17.1