From patchwork Tue Aug 27 06:26:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116119 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 43EE9112C for ; Tue, 27 Aug 2019 06:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C15620828 for ; Tue, 27 Aug 2019 06:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725860AbfH0G1I (ORCPT ); Tue, 27 Aug 2019 02:27:08 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G1I (ORCPT ); Tue, 27 Aug 2019 02:27:08 -0400 IronPort-SDR: Vwo1SmWntcc2XD0RzxL8LM2B6x8zWC8cyzvLhQzoX/97r6ceUClZOqQGkM2rbfpx5AdXi4JN8Q udiQIzRpEjIoaUkBR1YpqnzNOvXwxyA9yiIeQkaTOpSPRdMODvoR/aaUXTdEhmcQMeGbna7d6s /mqL+EFJGZWAsPqj+JkBtn9g9u4ZX2pxC9T2+Wp/nqJ/T7cNIRyPegHZ5mt3XkE3LHwmlCQpT8 X4Oayn1CSkCnxAYyg6xu2UL8cjUfaqgbEuRJq8STpK+zhgWZPs1fAt+fHnH/V8NBIb5ZVLUTzW +uw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784445" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:07 -0800 IronPort-SDR: FFTRG1H3H1NsBhx2NcIrn8yJ/CgbRqxnmgbR4z49ED/mZJf5F7OCMl+WmfM80kBAIJV7W85dgR 9FMNgic3TdLS+wi1oPzDUiXGfU7upA+j+OV9RQlZgWIbLrx1n01V06/lOD1tUtkFVVuQ47eYAE WwN/b113oW6K2fldhhb+mOJcjrcd7CIfoSMuNQUtX7WaoRlV6bogo7xaIhHD7EGZv987h6vSS0 EJt5SOVyGR0GSJQvR0uWrldQ1P6ta4jx31TgHb3W40WFuNJUHsyZM1vzCtHFHRDT7OThNig61z glo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 05/49] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Tue, 27 Aug 2019 15:26:30 +0900 Message-ID: <20190827062714.20266-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) 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) {