From patchwork Wed Feb 12 08:41:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11377913 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 ADE42924 for ; Wed, 12 Feb 2020 08:43:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E0F120661 for ; Wed, 12 Feb 2020 08:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728530AbgBLInB (ORCPT ); Wed, 12 Feb 2020 03:43:01 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:18832 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728452AbgBLInB (ORCPT ); Wed, 12 Feb 2020 03:43:01 -0500 IronPort-SDR: BZ/rJxFT/U6m11qtpuhM/n48c2ha1WZUnNMCW2IyxWM/d1zFWTIEqSnwWswXTsSyKpZXhmThOX hqn/o6YwFCHlDJN3ucsjzTb9XOwkZo4gGQqSosawFSeQ7hSuGAZj2dlyBcdyI1k4KnD3Xe3u0m s5db+ARgWX9qYZJZz+vBmHojAlfefV3PegC19f25cmnfK8vLWnQRX3LxzO1sby8/cdH+iEdQzu kkLUk0PQohcHRzjQuLMUFjZbij3pnyuD9Modx8t/H3CVbvU/LdkZgRqGlipiJZI9/ma158JwIV DBY= X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="45742494" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 12 Feb 2020 00:43:01 -0800 IronPort-SDR: iDSiWtfM7ZF9Ep/nVXFsKJDPaTpRyeaI8R7jvykLbY5k/QeOF1nqBOEqA1u4xjGrgQsraMmwQg D10wO+NPpHQMQFHO6h9slNP3QVykez+xROExmeMqAT9qCDjTVjLQdKSFjwflNFum0zD7OJAdCz c2zHS6xLZHdutPFwNZjnSn2bXbx+5lpVGLeY0TwhXXxlZ1M9ZznPPmAUpfIvDCqfXhV1duLsPD x3ekxzoh2VhXDRBCk/Age9CZ7JlmXqr0NQ24gxgp3xwmQA/ib+wiHAw8dZhDdVXkQxXETJRolA 6dA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v7 04/48] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Wed, 12 Feb 2020 00:41:34 -0800 Message-ID: <20200212084218.32344-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200212084218.32344-1-jiada_wang@mentor.com> References: <20200212084218.32344-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 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 e184d0e67ef8..6e22e01f1aa2 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) {