From patchwork Tue Sep 17 09:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148385 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 B0607912 for ; Tue, 17 Sep 2019 09:36:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98C0420862 for ; Tue, 17 Sep 2019 09:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbfIQJgF (ORCPT ); Tue, 17 Sep 2019 05:36:05 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgE (ORCPT ); Tue, 17 Sep 2019 05:36:04 -0400 IronPort-SDR: jeDmZW6D5hd/0g2X1V+NmTzqx0+VURaycNPkQiBBCJCneFqXZ4D/2GcKLwZkQIacnq3mppvtcT dC3k2DdHyvY4y0oA2UpkY1sS2ufQKNB9Tjp7JGJQolufuIpaxLPoGGXfUnya6/8RmYvrIsRWH6 SPOTJbyvNhfzplkqhosV2kcWzkauAafpSqNvPjNDT3vUk4c4+Ar7aX1IzXWgF0ANb45rp6DOKb KZFQCSE3gI3B6jiZHR8kd3+nIB6wCXjcpOPsVbpTCgqO1VmhL9ipt8ARKhsAJWH7wk0Tlm32UU fSY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422994" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:04 -0800 IronPort-SDR: fJ+orLfWgXKWZChBMpfWJb5UbNBCO7pHugKrCBXTs4DyucCdS5a5iDGFxwuWT4eqv2MyvOB5+Z yTQQGyivf3w2eq5URj/jCp8ZCNmn7vum0EdelcYPcMJjRJq0SN1gZFcbLTo22Q3NF3vFolGkZG hd8A5XHFlIECkULZFzbsa47q3RjFiEmeIcJc9gsqO03zwfeCta5m22bslERIVnp34/aVarsp8I TJJfX3/Uw4rcpAKaDkznd/1xChZxFtHqdmLhIN1D6vnIZK9WA5uDXY+uRTvFNjcTOwF3b94rCk +WE= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 05/49] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Tue, 17 Sep 2019 18:35:06 +0900 Message-ID: <20190917093550.18335-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer On some firmware variants, the size of the info block exceeds what can be read in a single transfer. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 74c4f5277cfa403d43fafc404119dc57a08677db) [gdavis: Forward port and fix conflicts due to v4.14.51 commit 960fe000b1d3 ("Input: atmel_mxt_ts - fix the firmware update").] Signed-off-by: George G. Davis [jiada: Change mxt_read_blks() to __mxt_read_reg(), original __mxt_read_reg() to __mxt_read_chunk()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 35cbe60094ab..45bab5253775 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -40,7 +40,7 @@ #define MXT_OBJECT_START 0x07 #define MXT_OBJECT_SIZE 6 #define MXT_INFO_CHECKSUM_SIZE 3 -#define MXT_MAX_BLOCK_WRITE 256 +#define MXT_MAX_BLOCK_WRITE 255 /* Object types */ #define MXT_DEBUG_DIAGNOSTIC_T37 37 @@ -624,8 +624,8 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) return 0; } -static int __mxt_read_reg(struct i2c_client *client, - u16 reg, u16 len, void *val) +static int __mxt_read_chunk(struct i2c_client *client, + u16 reg, u16 len, void *val) { struct i2c_msg xfer[2]; u8 buf[2]; @@ -659,6 +659,28 @@ static int __mxt_read_reg(struct i2c_client *client, return ret; } +static int __mxt_read_reg(struct i2c_client *client, + u16 reg, u16 len, void *buf) +{ + u16 offset = 0; + int error; + u16 size; + + while (offset < len) { + size = min(MXT_MAX_BLOCK_WRITE, len - offset); + + error = __mxt_read_chunk(client, + reg + offset, + size, buf + offset); + if (error) + return error; + + offset += size; + } + + return 0; +} + static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, const void *val) {