From patchwork Tue Oct 29 07:19:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11217369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4F451599 for ; Tue, 29 Oct 2019 07:21:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B91CC20663 for ; Tue, 29 Oct 2019 07:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726302AbfJ2HVt (ORCPT ); Tue, 29 Oct 2019 03:21:49 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:41262 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727931AbfJ2HVt (ORCPT ); Tue, 29 Oct 2019 03:21:49 -0400 IronPort-SDR: mYnwxgrUuxUc5YT1r4sdG52LxQik5pWfQSywJZSRpSkWQLqflU1tMfD3g66jCsNvWS+x0XPJ5G F70PmaFctg6jcnM9iM7IbKTk9+9ApetrP4wGx6eGITU373CiAj4Fifti0I16hi+hceJfC4Cd/u yYLNd8e0b3H7UionTsGm5jwHPEelcbphGa2Z9h/PVXc435IJmJOn5X02im72jklysFTUvkcP70 Rw2y01blf91bhcR/uCcP5ZbWYsvRXg9dQhAPaC6coYPB8OwtppIz4lyYoyO3mgs7CmIogsKLXN uec= X-IronPort-AV: E=Sophos;i="5.68,243,1569312000"; d="scan'208";a="42663274" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 28 Oct 2019 23:21:48 -0800 IronPort-SDR: tmNBiHETjBEdEZHyxw9slPZmwJs4WS21UiIBHQxklhXOvvVRIWh0190+hX/pVRgMuUZ5/KA/Ln frKRpeomKioFKsAj668kfftiaFw8cZvSKVZO3AwTujQ8MVHT3icHf6M5nDZjfIuLtyeGCjdIkH +NKQHURz4t2JV3I88PTjBwi+y8KJL7NYyE2BqHflV4XT7Du0He6O2/y0MQLG9rJnVJVxFRpzPY 0+rmC6qctokzpKAINVw3G2/Z8dDTvg2ZLkJGrhvCrEAcmaKy9K9+7kD3ZvPzpPReI6GJCXXO9Y EQo= From: Jiada Wang To: , , , CC: , , , , Subject: [PATCH v4 26/48] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 29 Oct 2019 16:19:48 +0900 Message-ID: <20191029072010.8492-27-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029072010.8492-1-jiada_wang@mentor.com> References: <20191029072010.8492-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@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 9bbfaeadf3b1..0039a1804a8c 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 */ @@ -723,6 +724,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; @@ -739,17 +741,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, @@ -780,6 +787,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); @@ -790,14 +798,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);