Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5142125ybl; Mon, 26 Aug 2019 23:31:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr4HiFUTPM2f9O7THTKK23z97SGsLAywGxbFpX6UCcfdwSEZzp8BOyekm99+SyhbHv3iRW X-Received: by 2002:a17:90b:f03:: with SMTP id br3mr21920879pjb.67.1566887488515; Mon, 26 Aug 2019 23:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566887488; cv=none; d=google.com; s=arc-20160816; b=rBXLzWOXyvaWkUAgcoPIxtipqaOyMKGn8a/pHzy1OaiDgcmsdF0lQvRYYB4SoDlMJA kC78Pcp4OWu4CzlKXuk0MPacphii6P/P7aRBfLVhmOhbJEojFDbvlYVOwu/5YHZL27uH t7i8g6ZQoB//T/50JdmZZzpq+2/N8p6BXrW9lgUvAkKWp0Jd1SxGSd5ybxRD6qpG5lRY Z1oa8eePw241evHx0N+X2uCdEapBip6iT0Qw6kRa+mIogppZTRLwk8MyXTcHWRgW4oXF z3A+ZRSHVw4cZ042nZhrqJOp9aIGfeYzdK1sbbQg8I79xsijdmnp6EIstbU3Lrjqinz2 o93g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=9O6klyN6uWLvwoNEWvXjutiDX+3mYlF0ERnuLWLG5dQ=; b=pFRv8po/jvXqxqipswR+viAwjP6rc5fVr6FESLjf9Bc+LQRoXpotImeDPUkVFA7idJ mXiGFT8yKEn/lc7jhvQnQsBFk1Li4xbTWrPoo+iDDsYXb1kZ08MfTx4I8fbF6G5d4lkh aDpH2VwxFgBQeADdq5jDemwmv/W4heqBiVyMe8Hmv/ykWbQNQATu2BUsWQsMd0Z4ubw2 D3yI2NFw2NQ25oifFhAicCjKoNAj4DFtMOZfkNHspRt9HLU0CteQq/4CxROBzOlbtJcy EbBxPdd4V3IV+Ql5Gmmk5oJN26+B/bX0+uI5h7HVtS6x+Jd+H8RKjy+HXyBRASpsw7Ew mE9g== 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 v24si11117639pgn.64.2019.08.26.23.31.12; Mon, 26 Aug 2019 23:31:28 -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 S1729289AbfH0G3k (ORCPT + 99 others); Tue, 27 Aug 2019 02:29:40 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47201 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0G3j (ORCPT ); Tue, 27 Aug 2019 02:29:39 -0400 IronPort-SDR: ek1sMtJ9KaWWV9ABSeQKrvqTBenSfhSjZs2FMpbuAKP/fxCfitXEW2CSqaN8eLpBSvK55+wJ7p 2tZQ5FKYBBBh8BT3RgzZIwiXIxuHRJic5iyajXXxGVOVVj6u7rs4f3QTM/WkIB+DDSHlLTgWqg EjgoYcWrtRnl72BQcTizmDfx08Tyr0yqNUr+6Sq7uJj3ux8x7ilftp0iOsmTNuuqeYCwvPL+pk VEw0kYVgnFbAhOy2510zGGvB5umSBxUjdn+PWz23VO8TLKiqPSMOmr/C4Tq1SwJihxVzLMuqyx ArA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754979" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:38 -0800 IronPort-SDR: 0cy/XRMIk7qQijTRjn+mpOZ41vKR85yEC5E++F8SfhVQ3aD04d9QMZtwP7o48nfbAKfqoe15CM gFXv670RxfRVbcEzEh5wV5AKqgM1jM3qFg8k3UmYeHD+QTNUsiZSQElEIINvg2dSRP+L+VWN0w 9WGJ/12MaMNlYkDICJTMA+Z5+zRrzabWGlXfOoM2BQ4KUtQmKlwxLFb6GGWgWjNiJ4ZfLWGZIS gew2hxFPVzv4tYgO+vH0aSw1udQRy4PkScBI9RIQGvB9JA766oTkdYBdiaPEvICc770o/EShIE sEU= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 27/49] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 27 Aug 2019 15:29:21 +0900 Message-ID: <20190827062943.20698-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062943.20698-1-jiada_wang@mentor.com> References: <20190827062943.20698-1-jiada_wang@mentor.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) 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 daf119c2957d..5b7ab798f27d 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); -- 2.19.2