From patchwork Tue Mar 31 10:49:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 208001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3A6CC43331 for ; Tue, 31 Mar 2020 10:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ABCB20772 for ; Tue, 31 Mar 2020 10:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730334AbgCaKvG (ORCPT ); Tue, 31 Mar 2020 06:51:06 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgCaKvF (ORCPT ); Tue, 31 Mar 2020 06:51:05 -0400 IronPort-SDR: aCB4JxTxc9Y9tMj++e/S06rHfbdDp+Kkl7YKkyw4Ngh23QbMawaxUDjULDtjj4Ah01rHBWk4fg knJKrZeNpcXJoOby1JRzrs3m1u8TRyjHVW0LH1k7/8uE1u6nYY0IDc7/XnSbsueM/W/XP+OaHE fmVVfWnt1Hq4mpGnVUbh/H00/S0zQQRebfB9n7zRZV9eL6VbtdeupPmFl0BykelVeIq8Dg9BE4 t8/poVrxgqfpj5zE3kJkbhepU6Mx3msP9ds/QA8z/TUksSyzhnZovEBJcWke8BuUmvQRQZR4+G EPs= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330711" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:05 -0800 IronPort-SDR: Ak8knzeVk6K0E0AAhx/lR2fhhdqTYizAMAmRReciaM4aHa8b8x5oJuqR5M8amu1ma1aD6NGS3P u1ruG12rtKC05ttS5aTCnxudQ4h82FXEY0eBm63py05x/oNFAZPG591s4viTFkLngiKzlVdgyQ 5HYg8mz7iCKXJu1oQK97agBp4ABtfgBUhcnWieoVvt7SBzagKWNg+whB9QqLc0zFaSEJfCD0V7 uFLqRYVxjpGis7KvWuo7sWOA+OnvqhaRdL9i+fRMSqWI56RvhHlhA6EI0GAVGjMPSEHwzz+vzZ V+g= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 02/55] Input: atmel_mxt_ts - rework sysfs init/remove Date: Tue, 31 Mar 2020 03:49:58 -0700 Message-ID: <20200331105051.58896-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 An error in the sysfs init may otherwise interfere with the async return from the firmware loader Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3114584ae77c2b03b6dad87174f010d002e9c05d) [gdavis: Forward port and fixup conflicts. Also fixed sysfs leaks in both the mxt_initialize() and mxt_probe() error return cases.] Signed-off-by: George G. Davis [jiada: keep call mxt_initialize() before sysfs creation replace S_IWUSR with 0200] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a2189739e30f..49bdf5cf3a0d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2086,10 +2086,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) return 0; err_free_mem: + data->input_dev = NULL; input_free_device(input_dev); return error; } +static int mxt_sysfs_init(struct mxt_data *data); +static void mxt_sysfs_remove(struct mxt_data *data); + static int mxt_configure_objects(struct mxt_data *data, const struct firmware *cfg); @@ -2141,16 +2145,24 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_sysfs_init(data); + if (error) + return error; + error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, &client->dev, GFP_KERNEL, data, mxt_config_cb); if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - return error; + goto err_free_sysfs; } return 0; + +err_free_sysfs: + mxt_sysfs_remove(data); + return error; } static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep) @@ -2803,6 +2815,7 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); } else { @@ -2909,16 +2922,25 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static DEVICE_ATTR(update_fw, 0200, NULL, mxt_update_fw_store); + +static struct attribute *mxt_fw_attrs[] = { + &dev_attr_update_fw.attr, + NULL +}; + +static const struct attribute_group mxt_fw_attr_group = { + .attrs = mxt_fw_attrs, +}; + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); -static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, - &dev_attr_update_fw.attr, NULL }; @@ -2926,6 +2948,28 @@ static const struct attribute_group mxt_attr_group = { .attrs = mxt_attrs, }; +static int mxt_sysfs_init(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + if (error) { + dev_err(&client->dev, "Failure %d creating sysfs group\n", + error); + return error; + } + + return 0; +} + +static void mxt_sysfs_remove(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + + sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); +} + static void mxt_start(struct mxt_data *data) { switch (data->suspend_mode) { @@ -3112,19 +3156,14 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) if (error) return error; - error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + error = sysfs_create_group(&client->dev.kobj, &mxt_fw_attr_group); if (error) { - dev_err(&client->dev, "Failure %d creating sysfs group\n", + dev_err(&client->dev, "Failure %d creating fw sysfs group\n", error); - goto err_free_object; + return error; } return 0; - -err_free_object: - mxt_free_input_device(data); - mxt_free_object_table(data); - return error; } static int mxt_remove(struct i2c_client *client) @@ -3132,7 +3171,8 @@ static int mxt_remove(struct i2c_client *client) struct mxt_data *data = i2c_get_clientdata(client); disable_irq(data->irq); - sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); + sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); From patchwork Tue Mar 31 10:50:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 208000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB3A6C43331 for ; Tue, 31 Mar 2020 10:51:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA86320772 for ; Tue, 31 Mar 2020 10:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730527AbgCaKvN (ORCPT ); Tue, 31 Mar 2020 06:51:13 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgCaKvN (ORCPT ); Tue, 31 Mar 2020 06:51:13 -0400 IronPort-SDR: CLqJfG46vJa2aBd6gTzLHPAQ+nZzQAoqQNZA782rvjL+YO0LiTGut6WtIB7OByGLAqeIC24+V9 nr6ZAp8v/+V8fZZYPbWSuhgIzv5lb8Ln+Io1ESW0zdy6U5bc+vwXGUlblo2SMU7EgKbQwkFtEj BNDHlYNkvoqrtb/SX5Sa4oYZTByiiqaMQ+I6EzM62hBHJhIfrAB9JIpjji5HdFnXbfDnZ5Gl0r hCN2SyePW8HGgdAkY13VAFoQRrnuEZ55TkD4IpoJzbvIOVh1HWGJlWAwSJk8pKRbddHM2O/XkT 0Kk= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330719" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:12 -0800 IronPort-SDR: MZNJWNuQ59fLGae+UTcZN6oQXcccZ3qvvKHiQ4T9QaRj9rVIVyFQgl5MvyNJzUR/K54iJsm/7h Z3n2TgYDuxfJUUTgDkGVbrYT4muMD/r1PRR6/S25avRBOI9G2d/FeK+8hxnw0Y2u/2TslWOV0V ktkhcwhkZE8hp4kUqZZL4nHQQVapfekHFNx8xnPYB3KJiR3H8MOgP899aQeHhGk0urmHkdHBep 7ucV1nPcGL+n0uHODk+sVY259/VlG5HUSpBiu4Q2UljvX28tnW4QXULqqGE79XnxfLZRMruVYQ 2AE= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 04/55] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Tue, 31 Mar 2020 03:50:00 -0700 Message-ID: <20200331105051.58896-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 3f1ebe14802f..7e6a66e3e1e0 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) { From patchwork Tue Mar 31 10:50:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2590DC10F26 for ; Tue, 31 Mar 2020 10:51:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEE2A20772 for ; Tue, 31 Mar 2020 10:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730377AbgCaKvX (ORCPT ); Tue, 31 Mar 2020 06:51:23 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730424AbgCaKvU (ORCPT ); Tue, 31 Mar 2020 06:51:20 -0400 IronPort-SDR: 4rVpxID+bA2mfJoVXMtBTbdg3O4QRfjHEoJcEhUVP7p1My5NfDA8fXfsBcPDdRT2gZr3UGEnPQ /mwR9g1LX7rojL/XViRyJpgOCboI3uDxdVnbiyNSVjvgYpGY+q+h5n0yRf7f2i+ewge/RuRLJ1 MhZRfx+F7D6uIeZTw1jpXQRw49GtEt309vq/13aFQVmOQ+6WzBcxF7LLONTl6nM1Z+veYIoi73 hZaWBsX2+BOGgfwfuuKUAzuJKgR90pgM+t6nmYde1HrQEP8jvxDtBZe9Z8FaTvuksGSXt8AyMJ P10= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330725" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:20 -0800 IronPort-SDR: RZ+I+4MxsrXODsWjEBP1HPOY9RNdGXxeapsC1ki+zerD5OuzBG1IndRVXF4b6ajHOomLFxQeeN EHiysL6i0EEGw0Mub9nKRcrEnL6B6VHbi7oCnCUsq2lFg3X/khlRYR2d/SoUdzhWgxXdicVFPz fd5uHGeExe4fP7RJnB7uxf/tmPQ4fbYZwFX6fGtnRfjWlCwi9RWlXJJ7oeTydRMYmoL/7/VDMo HifUM8yQkT4AFQ3MaKDiJ3UnuFddIZaXLoeE2BRSI7B6Cr6jbu/cWgKix9Akhy+bUUDInRmC0i 1QY= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 06/55] Input: atmel_mxt_ts - output status from T42 Touch Suppression Date: Tue, 31 Mar 2020 03:50:02 -0700 Message-ID: <20200331105051.58896-7-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 This patch outputs status from T42 touch suppression Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit ab95b5a309999d2c098daaa9f88d9fcfae7eb516) Signed-off-by: George G. Davis [jiada: Replace dev_info() with dev_dbg()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a53985a7736f..f6465edaa57e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -155,6 +155,9 @@ struct t37_debug { #define MXT_RESET_VALUE 0x01 #define MXT_BACKUP_VALUE 0x55 +/* Define for MXT_PROCI_TOUCHSUPPRESSION_T42 */ +#define MXT_T42_MSG_TCHSUP BIT(0) + /* T100 Multiple Touch Touchscreen */ #define MXT_T100_CTRL 0 #define MXT_T100_CFG1 1 @@ -323,6 +326,8 @@ struct mxt_data { u8 T9_reportid_max; u16 T18_address; u8 T19_reportid; + u8 T42_reportid_min; + u8 T42_reportid_max; u16 T44_address; u8 T48_reportid; u8 T100_reportid_min; @@ -979,6 +984,17 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) data->update_input = true; } +static void mxt_proc_t42_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + if (status & MXT_T42_MSG_TCHSUP) + dev_dbg(dev, "T42 suppress\n"); + else + dev_dbg(dev, "T42 normal\n"); +} + static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) { struct device *dev = &data->client->dev; @@ -1006,6 +1022,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (report_id == data->T6_reportid) { mxt_proc_t6_messages(data, message); + } else if (report_id >= data->T42_reportid_min + && report_id <= data->T42_reportid_max) { + mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); } else if (!data->input_dev) { @@ -1686,6 +1705,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T9_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T42_reportid_min = 0; + data->T42_reportid_max = 0; data->T44_address = 0; data->T48_reportid = 0; data->T100_reportid_min = 0; @@ -1763,6 +1784,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_PROCI_TOUCHSUPPRESSION_T42: + data->T42_reportid_min = min_id; + data->T42_reportid_max = max_id; + break; case MXT_SPT_MESSAGECOUNT_T44: data->T44_address = object->start_address; break; From patchwork Tue Mar 31 10:50:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207998 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD35EC2BA15 for ; Tue, 31 Mar 2020 10:51:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D5B4214D8 for ; Tue, 31 Mar 2020 10:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730408AbgCaKvb (ORCPT ); Tue, 31 Mar 2020 06:51:31 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730595AbgCaKvb (ORCPT ); Tue, 31 Mar 2020 06:51:31 -0400 IronPort-SDR: kQIX7DTzQPOLzxOxGhsYNcbpFOUXdIK9qfr6TZnzEJeLUIfTjQKecy3b14B2Uc7S+c3020z2Jt WKonRITSWglWrmbXYwev84ImENOjWZhVFyBSl/T8Yljmh8gT1LpmijLKWDohY9/y8oD3DIohQ5 om68vR4ty3pAS5i29n00N8sQNn/QaWMQjcT9LbMHwbar9dtYFy+sAHywumLB6oSqXL++80z0zv pNTV1Y5wC7CIoV5g/7hcyaQvv329+1Jn0u/zYlCKHZNJFajB+j+p8lBvVboZapt7uwgoEHgfID blU= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330735" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:30 -0800 IronPort-SDR: e6uBJNHe7NEccN2Pu4rtFvVqePZyvDONhmq21jAMhhjPSdmyoT3OLZR5Uu7EwKMIseeVYSsWIt tH4/Vu4VLTa57D9Ry5osoCgtjEunCqS4HvWReKfajeipTeCEtrjpe4XwxDdkmv03TckmAUYgDM HtMyUrL7yEWQTTVszIWx/RvkOXpNJO6vQXJe61VqESKY3lkle8eMOR6IM8XAyEcXB50P3tjm7W 54TkemYrNlaOfDaGIK4HlHB86TOJNg8eI7a5emkHU9GDrRU+8LzKCj2OrndGqOwnGlT7GIqUbL zPk= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 09/55] Input: atmel_mxt_ts - handle reports from T47 Stylus object Date: Tue, 31 Mar 2020 03:50:05 -0700 Message-ID: <20200331105051.58896-10-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 This patch handles reports from T47 Stylus object Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 56405a5ea08eb34cfe83f3121867c9de0a5c48c1) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d05249b02781..ba58cdd5b76d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -823,6 +823,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) int area; int amplitude; u8 vector; + int tool; id = message[0] - data->T9_reportid_min; status = message[1]; @@ -836,6 +837,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) y >>= 2; area = message[5]; + amplitude = message[6]; vector = message[7]; @@ -865,12 +867,20 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) mxt_input_sync(data); } + /* A size of zero indicates touch is from a linked T47 Stylus */ + if (area == 0) { + area = MXT_TOUCH_MAJOR_DEFAULT; + tool = MT_TOOL_PEN; + } else { + tool = MT_TOOL_FINGER; + } + /* if active, pressure must be non-zero */ if (!amplitude) amplitude = MXT_PRESSURE_DEFAULT; /* Touch active */ - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); + input_mt_report_slot_state(input_dev, tool, 1); input_report_abs(input_dev, ABS_MT_POSITION_X, x); input_report_abs(input_dev, ABS_MT_POSITION_Y, y); input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); From patchwork Tue Mar 31 10:50:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F745C2BA16 for ; Tue, 31 Mar 2020 10:51:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 464F620B1F for ; Tue, 31 Mar 2020 10:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730595AbgCaKvh (ORCPT ); Tue, 31 Mar 2020 06:51:37 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbgCaKvf (ORCPT ); Tue, 31 Mar 2020 06:51:35 -0400 IronPort-SDR: 4OKMDMhbqOmbc06j7Nhzo9ksUZXDb7OQCbK1HVQrtNfghr0Ygxukd78xR/v/DvtbtApuEuZesy pD+e9K36lVEc1fsNT0iOvD2iAuS4EutAAn5cCNXXHWMRJGwey8VzzPPaHOvSjIaD6O7jtehJMM IOB9Ick8A2rdiOlu9NEc1ZLe8qBSH6vv7fj++Inv43pTV/bux06vj2OxTXEIfPgrR3APl5UpMp BcM11FNwN0A2/DmwcJy6ku0fFq4m2Y8xBFFidSehBXX62XTyk+yoMJpZWKozzUoTVNnGtDhVxB 7gw= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330739" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:34 -0800 IronPort-SDR: 0ndoXwaqnZ7T0FplxYbtjeWCRO3/Zn4saMBbKVnOL4WxkWeqRRZJs+H9sex6Gf+v4jQ66gp+vs YGYOIfusY2sxJjE8kTmw4ytWSn84TgqyX1La5OA3i0iy2KDLRYxmMSgjR8ONFwaLEoq1nF4ad2 D8B8aRh3lLZ2RicCahk/6Cvgb5+TptWzpiMxcHLekZFZUmyiSbVhFYqDZZsgcB1QMK2GUVbLVZ VriF9k0DOcoZOxQN+x4R8Coni/X67Lr8H862Ccy/P/bT/vXGomRUCejsjVlSK6jJm31jzWExfB idA= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 10/55] Input: atmel_mxt_ts - implement support for T107 active stylus Date: Tue, 31 Mar 2020 03:50:06 -0700 Message-ID: <20200331105051.58896-11-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 This patch implements support for T107 active stylus Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 20e357dd9acf8c2040068c8b22d6bc1401a1893f) [gdavis: Forward port and fix conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 117 ++++++++++++++++++++++- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ba58cdd5b76d..63db8b66eb67 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -72,6 +72,7 @@ #define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71 71 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 +#define MXT_PROCI_ACTIVESTYLUS_T107 107 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -181,6 +182,7 @@ struct t37_debug { enum t100_type { MXT_T100_TYPE_FINGER = 1, MXT_T100_TYPE_PASSIVE_STYLUS = 2, + MXT_T100_TYPE_ACTIVE_STYLUS = 3, MXT_T100_TYPE_HOVERING_FINGER = 4, MXT_T100_TYPE_GLOVE = 5, MXT_T100_TYPE_LARGE_TOUCH = 6, @@ -192,6 +194,16 @@ enum t100_type { #define MXT_TOUCH_MAJOR_DEFAULT 1 #define MXT_PRESSURE_DEFAULT 1 +/* Gen2 Active Stylus */ +#define MXT_T107_STYLUS_STYAUX 42 +#define MXT_T107_STYLUS_STYAUX_PRESSURE BIT(0) +#define MXT_T107_STYLUS_STYAUX_PEAK BIT(4) + +#define MXT_T107_STYLUS_HOVER BIT(0) +#define MXT_T107_STYLUS_TIPSWITCH BIT(1) +#define MXT_T107_STYLUS_BUTTON0 BIT(2) +#define MXT_T107_STYLUS_BUTTON1 BIT(3) + /* Delay times */ #define MXT_BACKUP_TIME 50 /* msec */ #define MXT_RESET_GPIO_TIME 20 /* msec */ @@ -313,10 +325,12 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; - bool use_retrigen_workaround; unsigned long t15_keystatus; int t15_num_keys; const unsigned int *t15_keymap; + u8 stylus_aux_pressure; + u8 stylus_aux_peak; + bool use_retrigen_workaround; /* Cached parameters from object table */ u16 T5_address; @@ -337,6 +351,7 @@ struct mxt_data { u8 T48_reportid; u8 T100_reportid_min; u8 T100_reportid_max; + u16 T107_address; /* for fw update in bootloader */ struct completion bl_completion; @@ -908,6 +923,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) u8 major = 0; u8 pressure = 0; u8 orientation = 0; + bool active = false; + bool hover = false; id = message[0] - data->T100_reportid_min - 2; @@ -926,6 +943,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_HOVERING_FINGER: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_HOVERING; + hover = true; + active = true; if (data->t100_aux_vect) orientation = message[data->t100_aux_vect]; @@ -936,6 +955,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_GLOVE: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; if (data->t100_aux_area) major = message[data->t100_aux_area]; @@ -950,6 +971,9 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_PASSIVE_STYLUS: tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; /* * Passive stylus is reported with size zero so @@ -962,6 +986,31 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) break; + case MXT_T100_TYPE_ACTIVE_STYLUS: + /* Report input buttons */ + input_report_key(input_dev, BTN_STYLUS, + message[6] & MXT_T107_STYLUS_BUTTON0); + input_report_key(input_dev, BTN_STYLUS2, + message[6] & MXT_T107_STYLUS_BUTTON1); + + /* stylus in range, but position unavailable */ + if (!(message[6] & MXT_T107_STYLUS_HOVER)) + break; + + tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + active = true; + major = MXT_TOUCH_MAJOR_DEFAULT; + + if (!(message[6] & MXT_T107_STYLUS_TIPSWITCH)) { + hover = true; + distance = MXT_DISTANCE_HOVERING; + } else if (data->stylus_aux_pressure) { + pressure = message[data->stylus_aux_pressure]; + } + + break; + case MXT_T100_TYPE_LARGE_TOUCH: /* Ignore suppressed touch */ break; @@ -976,12 +1025,12 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) * Values reported should be non-zero if tool is touching the * device */ - if (!pressure && type != MXT_T100_TYPE_HOVERING_FINGER) + if (!pressure && !hover) pressure = MXT_PRESSURE_DEFAULT; input_mt_slot(input_dev, id); - if (status & MXT_T100_DETECT) { + if (active) { dev_dbg(dev, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n", id, type, x, y, major, pressure, orientation); @@ -992,6 +1041,7 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); input_report_abs(input_dev, ABS_MT_DISTANCE, distance); input_report_abs(input_dev, ABS_MT_ORIENTATION, orientation); + } else { dev_dbg(dev, "[%u] release\n", id); @@ -1863,6 +1913,9 @@ static int mxt_parse_object_table(struct mxt_data *data, /* first two report IDs reserved */ data->num_touchids = object->num_report_ids - 2; break; + case MXT_PROCI_ACTIVESTYLUS_T107: + data->T107_address = object->start_address; + break; } end_address = object->start_address @@ -2023,6 +2076,54 @@ static int mxt_read_t9_resolution(struct mxt_data *data) return 0; } +static int mxt_set_up_active_stylus(struct input_dev *input_dev, + struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + struct mxt_object *object; + u8 styaux; + int aux; + u8 ctrl; + + object = mxt_get_object(data, MXT_PROCI_ACTIVESTYLUS_T107); + if (!object) + return 0; + + error = __mxt_read_reg(client, object->start_address, 1, &ctrl); + if (error) + return error; + + /* Check enable bit */ + if (!(ctrl & 0x01)) + return 0; + + error = __mxt_read_reg(client, + object->start_address + MXT_T107_STYLUS_STYAUX, + 1, &styaux); + if (error) + return error; + + /* map aux bits */ + aux = 7; + + if (styaux & MXT_T107_STYLUS_STYAUX_PRESSURE) + data->stylus_aux_pressure = aux++; + + if (styaux & MXT_T107_STYLUS_STYAUX_PEAK) + data->stylus_aux_peak = aux++; + + input_set_capability(input_dev, EV_KEY, BTN_STYLUS); + input_set_capability(input_dev, EV_KEY, BTN_STYLUS2); + input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); + + dev_dbg(&client->dev, + "T107 active stylus, aux map pressure:%u peak:%u\n", + data->stylus_aux_pressure, data->stylus_aux_peak); + + return 0; +} + static int mxt_read_t100_config(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2229,7 +2330,7 @@ static int mxt_initialize_input_device(struct mxt_data *data) if (data->multitouch == MXT_TOUCH_MULTI_T9 || (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && - data->t100_aux_ampl)) { + (data->t100_aux_ampl || data->stylus_aux_pressure))) { input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); } @@ -2247,6 +2348,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) 0, 255, 0, 0); } + /* For T107 Active Stylus */ + if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && + data->T107_address) { + error = mxt_set_up_active_stylus(input_dev, data); + if (error) + dev_warn(dev, "Failed to read T107 config\n"); + } + /* For T15 Key Array */ if (data->T15_reportid_min) { data->t15_keystatus = 0; From patchwork Tue Mar 31 10:50:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207996 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7236DC2BA18 for ; Tue, 31 Mar 2020 10:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5137C208E0 for ; Tue, 31 Mar 2020 10:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730642AbgCaKvo (ORCPT ); Tue, 31 Mar 2020 06:51:44 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbgCaKvn (ORCPT ); Tue, 31 Mar 2020 06:51:43 -0400 IronPort-SDR: fTmDiu2gVmVsmYVWD9gWBUxMqDzyruG3Ari/cObswLzM2if1ytHR+B0xGsJf1Bsh5LQlfohTMr H64Nb0Y0YjAgoVcQJSb+lhWuLFY+GOWhV21MaQ+86wuE6q0kAjAaeEz5w+lnGetxz9rOlxTWmd 5f3QpP3C/omtTkooaWkT6x1p+9Abf2AT6C7qNyw3JuAlLTvJXV6YBwAGC7cLu+tOCXFB+YVlWW 9KI1YovgtZ5Rzw3rYbtDlohKyHBFQpaNPWwvXP2tFXbSx2DhJvlAidJzesATeRZB5VLha8Fgtf Vls= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330744" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:42 -0800 IronPort-SDR: sWhtBtM2VPhAEIGvu4FUp2LcVw04IJY0v8QQ+ETwPV8+Jp447Kama4IBrTUZUrj8Ei8vZ0hwvL EDtlrmwJ0hYAMQrITkOD2SuyAKknwKAJDMFMA1nFYXZoP5bXt9uCnrS5XKpitqg3D+v6wUkCZV C+eZNQl9ERl7s5eqmLjo8M+8yViYR0TINDhAZ6WHjXATOVtEfFmDbBGk5MCTCFZ9YoYPizbYNW mOTfHtL+ctao71TSVB8ls+rKhiYmVfIVlkuuHxFTaaTr2n1b/avUN7zEWYcpLnDfHRD6+w9Vkg +g8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 12/55] Input: atmel_mxt_ts - release touch state during suspend Date: Tue, 31 Mar 2020 03:50:08 -0700 Message-ID: <20200331105051.58896-13-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 If fingers are down as the MXT chip goes into suspend it does not send a lift message. In addition, it may not complete its final measurement cycle immediately, which means touch messages may be received by the interrupt handler after mxt_stop() has completed. So: - disable irq during suspend - flush any messages created after suspend - tell app layer that slots were released at suspend Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 26794433086dbc7dea18d2f6a1c8d61ab25bcfda) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fix from Dirk Behme: - Input: atmel_mxt_ts - remove superfluous data->suspended] Signed-off-by: Dirk Behme --- drivers/input/touchscreen/atmel_mxt_ts.c | 52 ++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 6126bb8a7acc..9aafed92db9c 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -372,6 +372,9 @@ struct mxt_data { unsigned int t19_num_keys; enum mxt_suspend_mode suspend_mode; + + /* Indicates whether device is in suspend */ + bool suspended; }; struct mxt_vb2_buffer { @@ -1151,10 +1154,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); - } else if (!data->input_dev) { + } else if (!data->input_dev || data->suspended) { /* - * Do not report events if input device - * is not yet registered. + * Do not report events if input device is not + * yet registered or returning from suspend */ mxt_dump_message(data, message); } else if (report_id >= data->T9_reportid_min && @@ -3135,6 +3138,11 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + if (data->suspended) { + enable_irq(data->irq); + data->suspended = false; + } + if (!data->in_bootloader) { /* Change to the bootloader mode */ data->in_bootloader = true; @@ -3306,8 +3314,27 @@ static void mxt_sysfs_remove(struct mxt_data *data) sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); } +static void mxt_reset_slots(struct mxt_data *data) +{ + struct input_dev *input_dev = data->input_dev; + int id; + + if (!input_dev) + return; + + for (id = 0; id < data->num_touchids; id++) { + input_mt_slot(input_dev, id); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + } + + mxt_input_sync(data); +} + static void mxt_start(struct mxt_data *data) { + if (!data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: mxt_soft_reset(data); @@ -3320,16 +3347,29 @@ static void mxt_start(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + /* + * Discard any touch messages still in message buffer + * from before chip went to sleep + */ + mxt_process_messages_until_invalid(data); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); /* Recalibrate since chip has been in deep sleep */ mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + + mxt_acquire_irq(data); break; } + + data->suspended = false; } static void mxt_stop(struct mxt_data *data) { + if (data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ @@ -3339,9 +3379,15 @@ static void mxt_stop(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + disable_irq(data->irq); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + + mxt_reset_slots(data); break; } + + data->suspended = true; } static int mxt_input_open(struct input_dev *dev) From patchwork Tue Mar 31 10:50:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 963CFC2D0EE for ; Tue, 31 Mar 2020 10:51:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CB2320B1F for ; Tue, 31 Mar 2020 10:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730436AbgCaKvw (ORCPT ); Tue, 31 Mar 2020 06:51:52 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbgCaKvu (ORCPT ); Tue, 31 Mar 2020 06:51:50 -0400 IronPort-SDR: U3X0+ElcFdZO99sjuo/5i6gpf6OaDJT0iRfT4AdduUerUnpwLFJiXtLm8tyNI/rjOWefrbVByj 7/cfs8rr0Cib/gELZNtkKDlWcAA55hNLVlfDlBa0l66pSbpB8DSv2jT3W8fRWNMLMgV6Gr28nT 3Es8vt5rbHjBaqbu/T1vf0D1pvjam1CZPF8KOl7bA8DwilossogEiXbi3QyLuTPNcKWwhOSR7r 1BwK7N2utjGmdja7upGF6vvLAG0oBG3jKgQs34O2ZaPW9t56NW3l5VaA95QlAvW/cMpew2eOBu VXk= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330748" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:50 -0800 IronPort-SDR: 7I+4n7Dywgdg7JRZVzjzxmMKCj8CQmEAW8T+UIY8oHDQx+wBbh/b/4c7vi/X/j0cK08eOtHlEv Z8//VjmDYd20xr9vZFtt6HGdGtXXLkCx2ni9rq4xeHyXNVNfe+FoOFj8HkTausaY6VtmiK2YO6 yqZRdmmnQEkZdjNMTW56izh/WKpaqXbESh5F3dPLA/UIW19zQIKq2VNQB5IjxcXTqqiyJw507b 7aPbt/e6vb0bACwF2VVCdD2GgRTaSkq8uDOWfF5dfa9k2KO8Jwx3fBsuHaD3mWbZOFIaZ4AqJa /3o= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 14/55] Input: atmel_mxt_ts - add regulator control support Date: Tue, 31 Mar 2020 03:50:10 -0700 Message-ID: <20200331105051.58896-15-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Allow the driver to optionally manage enabling/disable power to the touch controller itself. If the regulators are not present then use the deep sleep power mode instead. For a correct power on sequence, it is required that we have control over the RESET line. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 14052b61bb66c2f2283c00e733e131be7a9b8bfc) [gdavis: Resolve forward port conflicts due to v4.14-rc1 commmit f657b00df22e ("Input: atmel_mxt_ts - add support for reset line") and applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fixes from Dirk Behme: - Input: atmel_mxt_ts - in failure case disable the regulator - Input: atmel_mxt_ts - disable only enabled regulators - Input: atmel_mxt_ts - use devm_regulator_get()] Signed-off-by: Dirk Behme [jiada: Replace white-spaces with tab for MXT_CHG_DELAY separate Documentation/ and include/dt-bindings/ portion change to another commit] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 130 +++++++++++++++++++++-- 1 file changed, 121 insertions(+), 9 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9aafed92db9c..ef8baf64659e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include /* Firmware files */ #define MXT_FW_NAME "maxtouch.fw" @@ -215,6 +217,9 @@ 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_REGULATOR_DELAY 150 /* msec */ +#define MXT_CHG_DELAY 100 /* msec */ +#define MXT_POWERON_DELAY 150 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -275,11 +280,6 @@ enum v4l_dbg_inputs { MXT_V4L_INPUT_MAX, }; -enum mxt_suspend_mode { - MXT_SUSPEND_DEEP_SLEEP = 0, - MXT_SUSPEND_T9_CTRL = 1, -}; - /* Config update context */ struct mxt_cfg { u8 *raw; @@ -333,6 +333,8 @@ struct mxt_data { u8 stylus_aux_pressure; u8 stylus_aux_peak; bool use_retrigen_workaround; + struct regulator *reg_vdd; + struct regulator *reg_avdd; /* Cached parameters from object table */ u16 T5_address; @@ -2073,6 +2075,94 @@ static int mxt_read_info_block(struct mxt_data *data) return error; } +static void mxt_regulator_enable(struct mxt_data *data) +{ + int error; + + if (!data->reg_vdd || !data->reg_avdd) + return; + + gpiod_set_value(data->reset_gpio, 0); + + error = regulator_enable(data->reg_vdd); + if (error) + return; + + error = regulator_enable(data->reg_avdd); + if (error) { + regulator_disable(data->reg_vdd); + return; + } + + /* + * According to maXTouch power sequencing specification, RESET line + * must be kept low until some time after regulators come up to + * voltage + */ + msleep(MXT_REGULATOR_DELAY); + gpiod_set_value(data->reset_gpio, 1); + msleep(MXT_CHG_DELAY); + +retry_wait: + reinit_completion(&data->bl_completion); + data->in_bootloader = true; + error = mxt_wait_for_completion(data, &data->bl_completion, + MXT_POWERON_DELAY); + if (error == -EINTR) + goto retry_wait; + + data->in_bootloader = false; +} + +static void mxt_regulator_disable(struct mxt_data *data) +{ + if (!data->reg_vdd || !data->reg_avdd) + return; + + if (regulator_is_enabled(data->reg_vdd)) + regulator_disable(data->reg_vdd); + if (regulator_is_enabled(data->reg_avdd)) + regulator_disable(data->reg_avdd); +} + +static int mxt_probe_regulators(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + int error; + + /* Must have reset GPIO to use regulator support */ + if (!data->reset_gpio) { + error = -EINVAL; + goto fail; + } + + data->reg_vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(data->reg_vdd)) { + error = PTR_ERR(data->reg_vdd); + dev_err(dev, "Error %d getting vdd regulator\n", error); + goto fail; + } + + data->reg_avdd = devm_regulator_get(dev, "avdd"); + if (IS_ERR(data->reg_avdd)) { + error = PTR_ERR(data->reg_avdd); + dev_err(dev, "Error %d getting avdd regulator\n", error); + goto fail_release; + } + + mxt_regulator_enable(data); + + dev_dbg(dev, "Initialised regulators\n"); + return 0; + +fail_release: + regulator_put(data->reg_vdd); +fail: + data->reg_vdd = NULL; + data->reg_avdd = NULL; + return error; +} + static int mxt_read_t9_resolution(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -3139,7 +3229,12 @@ static int mxt_load_fw(struct device *dev, const char *fn) goto release_firmware; if (data->suspended) { - enable_irq(data->irq); + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) + mxt_regulator_enable(data); + + if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) + enable_irq(data->irq); + data->suspended = false; } @@ -3345,6 +3440,11 @@ static void mxt_start(struct mxt_data *data) MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); break; + case MXT_SUSPEND_REGULATOR: + enable_irq(data->irq); + mxt_regulator_enable(data); + break; + case MXT_SUSPEND_DEEP_SLEEP: default: /* @@ -3377,6 +3477,12 @@ static void mxt_stop(struct mxt_data *data) MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0); break; + case MXT_SUSPEND_REGULATOR: + disable_irq(data->irq); + mxt_regulator_disable(data); + mxt_reset_slots(data); + break; + case MXT_SUSPEND_DEEP_SLEEP: default: disable_irq(data->irq); @@ -3469,6 +3575,8 @@ static int mxt_parse_device_properties(struct mxt_data *data) data->t15_num_keys = n_keys; } + device_property_read_u32(dev, "atmel,suspend-mode", + &data->suspend_mode); return 0; } @@ -3555,14 +3663,18 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } - disable_irq(client->irq); - - if (data->reset_gpio) { + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + error = mxt_probe_regulators(data); + if (error) + return error; + } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } + disable_irq(data->irq); + error = mxt_initialize(data); if (error) return error; From patchwork Tue Mar 31 10:50:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34802C2D0E8 for ; Tue, 31 Mar 2020 10:52:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 14CD920B1F for ; Tue, 31 Mar 2020 10:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730433AbgCaKv5 (ORCPT ); Tue, 31 Mar 2020 06:51:57 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730680AbgCaKvz (ORCPT ); Tue, 31 Mar 2020 06:51:55 -0400 IronPort-SDR: IVrQqMxgAJxe+ql3bkIGDk9i8Y+GDbV0IwlSkZdE1QXL3PXPoZeQvS/8ysbsLvQFzJCYeohf5G xg00ILEYfHIPBnLm4ZQClAgBOtET3xwcHsA3HbxTIKbPY2Mp4LB7KBbyc/1JnbRjGeAxIw/hfa DwHPb/MUfgl1nSWUA5hnTOZPVzFtPNX2CivoKEShBIwV/JMMqcL15u0Gzyd+Sd3uUuTY9gWqbe x8e4NyATAq3rc8vELgSvM/PnB5kh8IvUlOf/ps/5ZaWcm3AhiLSdXo0b0fcNZhqqLbG+Ye8FSB uW8= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330751" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:51:54 -0800 IronPort-SDR: HPy7A/TyhWuIr46ikYVEOAU53I7xr0OgvRWGnmkxz5M7gYRzTkPDAqM6YcTMS7Ljebqq3ACl5w DG1TnZ4TUzoNJJ5LdbFdLadU8jLnGFZuh09Z0mKynb/e4Tf2sZ6hgeSB96So7jH+KlF84tbZrP E6OqUYW+vDyi1C0qGgKfYlYeyo+ZtsWR90o91ur3KAUM8/18TJm5C8G+wj6xnOlQDfcL3iE+32 ut+6rBpjBp5Y/HA3hU13N8C+TEmnk6pn+gtE0zZ7af+H9fOA2OKY+zJFPeAint2K9vEM9tLlXo Dxg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 15/55] Input: atmel_mxt_ts - report failures in suspend/resume Date: Tue, 31 Mar 2020 03:50:11 -0700 Message-ID: <20200331105051.58896-16-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 This patch reports failures in suspend/resume Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 93a57575403d) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Fix compilation warning Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 51 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ef8baf64659e..f8783e37436f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3425,10 +3425,12 @@ static void mxt_reset_slots(struct mxt_data *data) mxt_input_sync(data); } -static void mxt_start(struct mxt_data *data) +static int mxt_start(struct mxt_data *data) { + int ret = 0; + if (!data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -3453,28 +3455,42 @@ static void mxt_start(struct mxt_data *data) */ mxt_process_messages_until_invalid(data); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + if (ret) + return ret; /* Recalibrate since chip has been in deep sleep */ - mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + ret = mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + if (ret) + return ret; + + ret = mxt_acquire_irq(data); + if (ret) + return ret; - mxt_acquire_irq(data); break; } data->suspended = false; + + return 0; } -static void mxt_stop(struct mxt_data *data) +static int mxt_stop(struct mxt_data *data) { + int ret; + if (data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ - mxt_write_object(data, + ret = mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0); + if (ret) + return ret; + break; case MXT_SUSPEND_REGULATOR: @@ -3487,29 +3503,40 @@ static void mxt_stop(struct mxt_data *data) default: disable_irq(data->irq); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + if (ret) + return ret; mxt_reset_slots(data); break; } data->suspended = true; + return 0; } static int mxt_input_open(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_start(data); + ret = mxt_start(data); - return 0; + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); + + return ret; } static void mxt_input_close(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_stop(data); + ret = mxt_stop(data); + + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); } static int mxt_parse_device_properties(struct mxt_data *data) From patchwork Tue Mar 31 10:50:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B87EC43331 for ; Tue, 31 Mar 2020 10:52:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7BCFB20B1F for ; Tue, 31 Mar 2020 10:52:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730696AbgCaKwH (ORCPT ); Tue, 31 Mar 2020 06:52:07 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730703AbgCaKwF (ORCPT ); Tue, 31 Mar 2020 06:52:05 -0400 IronPort-SDR: RnH/U8uSMH1rgYuVzUe9cmBIKCTakYEzXqu/ASHilqRanshH4/HvlsAsVgbynpdwjvmVD2IKMi vHwP/UCL8QCT9zeNR+W9fx/yM2GNIeKKEr3E64hGnvsgQ+HMNbLrcRlV96NeKmx00iLUbk4ac1 PWzPIBoeYarpHoMAnAmb9dlMYWMCYDX+ENAMMUDbxGvsodbW8uKw6kpLrv4XbKX91thdEJJycN oSw8/1dBZM66Rq27AmldKAqEnrRKAUNRGqu/sH5rl6qWMOFSEwN89g3fTMQ9AgtzZs4mehfQwk nQ0= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330761" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:04 -0800 IronPort-SDR: FtYqO1U+45+jymj+6IQFZTHycjlrEMETJCxbrCZJqlRkl4tOn2wY7FXHayHI3zv+uMwh+HgqDW hQGtv2W78fgfMJgMbu0wBxnJ4dTw54V1YmQiMEZX2hwkkmmpxNXWabL5zsNHOWMnsQQALb/zSa lhjXigU/InRK0Qiko+tJJPferT4AdONuV8mVMMGjmztbCEUSQddDy6ARilwnVZxuCT1Bc4Cl46 Mlrbpmo92vgN+SlX98aLOB1pb7wlVojRoWcVRoemndnn1rd07dlaKuspQb8yaMhLlJMOspLnM6 mQ4= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 18/55] Input: atmel_mxt_ts: Rename mxt_hw_version_show to hw_version_show Date: Tue, 31 Mar 2020 03:50:14 -0700 Message-ID: <20200331105051.58896-19-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Rename mxt_hw_version_show to hw_version_show to address checkpatch warning Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index b2a37a9597f3..cec823de4096 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3114,8 +3114,8 @@ static ssize_t fw_version_show(struct device *dev, } /* Hardware Version is returned as FamilyID.VariantID */ -static ssize_t mxt_hw_version_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t hw_version_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mxt_data *data = dev_get_drvdata(dev); struct mxt_info *info = data->info; @@ -3404,7 +3404,7 @@ static const struct attribute_group mxt_fw_attr_group = { }; static DEVICE_ATTR_RO(fw_version); -static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); +static DEVICE_ATTR_RO(hw_version); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); static struct attribute *mxt_attrs[] = { From patchwork Tue Mar 31 10:50:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207992 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77500C2D0EE for ; Tue, 31 Mar 2020 10:52:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53DED208E4 for ; Tue, 31 Mar 2020 10:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730482AbgCaKwS (ORCPT ); Tue, 31 Mar 2020 06:52:18 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43515 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730481AbgCaKwR (ORCPT ); Tue, 31 Mar 2020 06:52:17 -0400 IronPort-SDR: KMeHU56svksp1Ud8CpIXFd3UYUJtlVGfDBV7DaD1b6O4ZOzNeC3LatiBuQePRxE+w1HwTB/oQH qmQdF09xopCLTxoNsfixP661gu+IqrmPnTpIfWRKy/qG9IGKKu8hhVyIpriKFozrtAIwohUS9c 37h4XyXFfDld7/ju3iBQFdDR5P01nsQvOA1/F42kZzvrnJHzQ5+gsAqA/zPAvyWg0Gnyo+fkho SRIpQQCj3pcvkO4FWbp91tnZquwhzsWmlIxj1vmA+SzwgF+sHYR6fRQZJ7jhSgFfo7zFVGZOP7 4hw= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330772" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:16 -0800 IronPort-SDR: R7OMOUh4sdEig5MGqfUA7b+V/vgTcBls5KVPQs60Sc2D+FxpdmlclfYXnJN6BRcKb8rt7MYLXr PzGf3xLQkvMpsUvihZB7yFu9ueoyXx+EpqHL2apl2B3XVro1CY7llEQNwbRhSJrUa0ebB8liSz uVGqTeDF3LabUG9tBf4A1uZhsvsEn2rDDIhpw+l3Qv2KSxYm+h+MHf3uw5xHQy9FIrI/XeEVnL v6ZnRUxUdMdXGgWXTzsiWKKdzLKYp3edI7Fi2r9HIj6xAwt4aF/2I2KMaPkYQ9dIfd7W+bXarS jkI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 21/55] dt-bindings: input: atmel: provide name of configuration file Date: Tue, 31 Mar 2020 03:50:17 -0700 Message-ID: <20200331105051.58896-22-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Add support to set name of configuration file Signed-off-by: Jiada Wang --- Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index 0307e7f7bb43..29bb84a920d6 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -40,6 +40,9 @@ Optional properties for main touchpad device: - vdd: Required supply regulator when MXT_SUSPEND_REGULATOR is used to suspend - avdd: Required supply regulator when MXT_SUSPEND_REGULATOR is used to suspend +- atmel,cfg_name: Provide name of configuration file in OBP_RAW format. This + will be downloaded from the firmware loader on probe to the device. + Example: touch@4b { From patchwork Tue Mar 31 10:50:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76353C2D0E8 for ; Tue, 31 Mar 2020 10:52:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57E2D208E0 for ; Tue, 31 Mar 2020 10:52:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730483AbgCaKwk (ORCPT ); Tue, 31 Mar 2020 06:52:40 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43589 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730410AbgCaKwk (ORCPT ); Tue, 31 Mar 2020 06:52:40 -0400 IronPort-SDR: IlEyzTrZ/iHDjmRfOyAUKck7waKJubEXq9VDLpCi2uXxlcQ6j0fnro7nL6PBFVAZMefqNW9fvg fVnv6bHkcQKKyRdUMEqDfSyfn5TH+USfjkNm7AsrD1f1Eiv+mCASIB1n6BeI2ecsTzVRkxi1SK vyZlWCpMHJJjsa8pory1WmcdkjwnosXM/RnBkCc/Tw4C4EGAQHTFzRCVKjjBx2b/qMBYZt4Jpy mzgqHTVVpWNQbXfzqHmIfF0EkOvjZCdbLWsXmyTzPAOlgs2TgwkU08vY7A9/6EVH4d50Uf3kff ju4= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330777" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:20 -0800 IronPort-SDR: VCb3GzgQuZMCQk4GyI3gjJkVazkmEJORCNejFtqLBC8fK9Hj9iZw+7cQIqly5V8C1FzTqhtJXV wt7HH04b26EVKW2Hczyx/X9+28rtCcbdFxvweFAyx16oqqcON83otFGrW+jiYFpd1rI2gM2WUH x4U0gQZkNHZTelzh/t1fN4axxFL3WxiuQeyCzCVPE8j/qbQiLnWXBQEoWKkLnEDl2b/CsKqtpg 6eheewasmf2TJBxY28RsPNsUvYP11MReoASOlFmUQI/sP9O+Mq6bmo9wP1JOmyAPoXiSuiwhyD iI8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 22/55] Input: atmel_mxt_ts - allow input name to be specified in platform data Date: Tue, 31 Mar 2020 03:50:18 -0700 Message-ID: <20200331105051.58896-23-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Android systems identify the input device and map to IDC file by using the input device name. To avoid unnecessary deltas to the driver file, allow this to be set from the platform data. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit cbf94a7bda754d2e1899d9f50313a0bccc91422d) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Separate Documentation/ portion change to another commit] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d1865250f492..dfc20c0ca0a5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,7 @@ struct mxt_data { char *fw_name; char *cfg_name; const char *pcfg_name; + const char *input_name; /* Cached parameters from object table */ u16 T5_address; @@ -2412,7 +2413,11 @@ static int mxt_initialize_input_device(struct mxt_data *data) if (!input_dev) return -ENOMEM; - input_dev->name = "Atmel maXTouch Touchscreen"; + if (data->input_name) + input_dev->name = data->input_name; + else + input_dev->name = "Atmel maXTouch Touchscreen"; + input_dev->phys = data->phys; input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = dev; @@ -3653,6 +3658,8 @@ static int mxt_parse_device_properties(struct mxt_data *data) device_property_read_string(dev, "atmel,cfg_name", &data->pcfg_name); + device_property_read_string(dev, "atmel,input_name", &data->input_name); + if (device_property_present(dev, keymap_property)) { n_keys = device_property_count_u32(dev, keymap_property); if (n_keys <= 0) { From patchwork Tue Mar 31 10:50:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 731E9C43331 for ; Tue, 31 Mar 2020 10:54:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53BDD20781 for ; Tue, 31 Mar 2020 10:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730697AbgCaKyh (ORCPT ); Tue, 31 Mar 2020 06:54:37 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43589 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730533AbgCaKwl (ORCPT ); Tue, 31 Mar 2020 06:52:41 -0400 IronPort-SDR: Jjfj1x3GLGu+OQoz8Otq97fQMTfka2E8LBBGP7RDfOlH996AmqMMRoFtzKYQ0rd/g+q8DwcrSL RROHHkbZip2f7wbjHehCfaAicY9oTrWscTDihi5EeVZVlPeMMwyle5nzYPjZC1W31+wpWNscrO MW00d5fcI0bf1MkqC/K0wID52H86xQrly7krDDU+W0Exi3S4Lj29EsdRKp8VuMG2Qn65eiXz4U 5etBn8Bzl3N87hybZXRc2Tw4KRj+H1qQB/fHMWYwSC2dgWn5CR8TPVsbjiMoyd1zUWZu5BeKSI bjs= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330784" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:31 -0800 IronPort-SDR: j/Kk1Nw1R3lZu8YgXxlXawA/OD1F2sSEVx4lCUfHw6nzLg117J81hgMySnG8goUhf29wfN4b+W 93zhcddnIFwsnbqYfD5rt7X77Frf0cB1fO3I9ul5NRcWCcZVqSe0tDzcBoPudUuBupe0Q/9zw5 XeMRBgnb3dX2VP5q5bofSpD9SEhAtoevr1xfPNQA37128kY/tkNguwJ1Ayf64yWqIvK11mI0Qy LJDSz2sjs6JqcifzVAZ9AOKukH1Mfc1Mg7JrEKhh6rFrWfLqhHapvfaUd88XA4/eQMx2T1lg6b ZhE= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 25/55] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Tue, 31 Mar 2020 03:50:21 -0700 Message-ID: <20200331105051.58896-26-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Refactor firmware flash to extract context into struct Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 1bbe20ff3dcd6612e7942c495929eae5c138ece2) Signed-off-by: George G. Davis [jiada: Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 +++++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 67931cf64629..2c4b68802bc3 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -291,6 +291,22 @@ struct mxt_cfg { struct mxt_info info; }; +/* Firmware frame structure */ +struct mxt_fw_frame { + __be16 size; + u8 data[]; +}; + +/* Firmware update context */ +struct mxt_flash { + const struct firmware *fw; + struct mxt_fw_frame *frame; + loff_t pos; + size_t frame_size; + unsigned int count; + unsigned int retry; +}; + /* Each client has this additional data */ struct mxt_data { struct i2c_client *client; @@ -3244,21 +3260,17 @@ static int mxt_check_firmware_format(struct device *dev, static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - const struct firmware *fw = NULL; - unsigned int frame_size; - unsigned int pos = 0; - unsigned int retry = 0; - unsigned int frame = 0; + struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&fw, data->fw_name, dev); + ret = request_firmware(&f.fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); return ret; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, fw); + ret = mxt_check_firmware_format(dev, f.fw); if (ret) goto release_firmware; @@ -3312,41 +3324,42 @@ static int mxt_load_fw(struct device *dev) goto disable_irq; } - while (pos < fw->size) { + while (f.pos < f.fw->size) { + f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); + ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); if (ret) goto disable_irq; - frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); - /* Take account of CRC bytes */ - frame_size += 2; + f.frame_size = __be16_to_cpu(f.frame->size) + 2U; /* Write one frame to device */ - ret = mxt_bootloader_write(data, fw->data + pos, frame_size); + ret = mxt_bootloader_write(data, f.fw->data + f.pos, + f.frame_size); if (ret) goto disable_irq; ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); if (ret) { - retry++; + f.retry++; /* Back off by 20ms per retry */ - msleep(retry * 20); + msleep(f.retry * 20); - if (retry > 20) { + if (f.retry > 20) { dev_err(dev, "Retry count exceeded\n"); goto disable_irq; } } else { - retry = 0; - pos += frame_size; - frame++; + f.retry = 0; + f.pos += f.frame_size; + f.count++; } - if (frame % 50 == 0) - dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n", - frame, pos, fw->size); + if (f.count % 50 == 0) + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f.count, f.pos, f.fw->size); } /* Wait for flash. */ @@ -3355,7 +3368,7 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos); + dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3369,7 +3382,7 @@ static int mxt_load_fw(struct device *dev) disable_irq: disable_irq(data->irq); release_firmware: - release_firmware(fw); + release_firmware(f.fw); return ret; } From patchwork Tue Mar 31 10:50:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 104A7C2D0F3 for ; Tue, 31 Mar 2020 10:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E51CF20772 for ; Tue, 31 Mar 2020 10:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730758AbgCaKwn (ORCPT ); Tue, 31 Mar 2020 06:52:43 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43593 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730739AbgCaKwm (ORCPT ); Tue, 31 Mar 2020 06:52:42 -0400 IronPort-SDR: H0FMrk3rZITyUbkekZtFY6TVq0gtVnDNvvr8fPBijDEh0fOMjNK/oCSfRREImRB5FpqijCOZwx gRKqzd9biEZ8AugEIqv6e/Ub6x4eNpZ+fpaAMrQaTr8WddePCFJCUUT4JTkOrHpt+2zF+FkipX IY9ldvFxSH2ccG2Fnfnt0NKZKfkJM1mwifh/Xrb0zxPsvm3bRz1i9SS30u6fS/HZRNWsCNIqTs HGCfaDC5YPOU+nVvMkgnTIETFOjZ9PC+PXCkKVi559HgBOHzPmcJa1lDzZfZraCwzNLH6OcBTf KZM= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330790" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:38 -0800 IronPort-SDR: E7PXX0zs2PIMiFs4wsNLxmGnJ+JBPB8DfvY7UIHBfcPLRcLHDQ8cVFsamDB3IHsmq/Vqwk7Z4P OH0ycQspC7uE25wwUalK3BDewt3iTmDi4fkjLdpBOzRl+HJu2yaVs4eVtqUCFnIVslxiIppoNB QEt/GWU85m5i/m6S2s11Xi7rYbSovS25+qdzOBFzZrO507ayUMKuq3Mmz3vvh8Bxorei7Xr+1w Ft+9rNJfVNSBPq2B2xmtu+E2w73Ch03A3bwixcZXvSyuEMTnya+FGbKGq1f4u6CiFXoN2FwNsr 4Cs= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 27/55] Input: atmel_mxt_ts - combine bootloader version query with probe Date: Tue, 31 Mar 2020 03:50:23 -0700 Message-ID: <20200331105051.58896-28-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 This removes some complexity from the bootloader state machine, and means that we always output some debug about the version as soon as we start talking to the bootloader. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit a2d141f170c80fea6663af98aab0be32abc0ddb0) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 45 +++++++----------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 11b2f133e6be..71d5781d3539 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -558,47 +558,31 @@ static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) { struct device *dev = &data->client->dev; int error; - u8 val; - bool crc_failure; + u8 buf[3]; + bool crc_failure, extended_id; error = mxt_lookup_bootloader_address(data, alt_address); if (error) return error; - error = mxt_bootloader_read(data, &val, 1); + /* Check bootloader status and version information */ + error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) return error; - /* Check app crc fail mode */ - crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; + crc_failure = (buf[0] & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; + extended_id = buf[0] & MXT_BOOT_EXTENDED_ID; - dev_err(dev, "Detected bootloader, status:%02X%s\n", - val, crc_failure ? ", APP_CRC_FAIL" : ""); + dev_info(dev, "Found bootloader addr:%02x ID:%u%s%u%s\n", + data->bootloader_addr, + extended_id ? (buf[1] & MXT_BOOT_ID_MASK) : buf[0], + extended_id ? " version:" : "", + extended_id ? buf[2] : 0, + crc_failure ? ", APP_CRC_FAIL" : ""); return 0; } -static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val) -{ - struct device *dev = &data->client->dev; - u8 buf[3]; - - if (val & MXT_BOOT_EXTENDED_ID) { - if (mxt_bootloader_read(data, &buf[0], 3) != 0) { - dev_err(dev, "%s: i2c failure\n", __func__); - return val; - } - - dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]); - - return buf[0]; - } else { - dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK); - - return val; - } -} - static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, bool wait) { @@ -632,9 +616,6 @@ static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, if (ret) return ret; - if (state == MXT_WAITING_BOOTLOAD_CMD) - val = mxt_get_bootloader_version(data, val); - switch (state) { case MXT_WAITING_BOOTLOAD_CMD: case MXT_WAITING_FRAME_DATA: @@ -3283,7 +3264,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); /* Do not need to scan since we know family ID */ - ret = mxt_lookup_bootloader_address(data, 0); + ret = mxt_probe_bootloader(data, 0); if (ret) return ret; From patchwork Tue Mar 31 10:50:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1767C43331 for ; Tue, 31 Mar 2020 10:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B8BAB20B80 for ; Tue, 31 Mar 2020 10:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730778AbgCaKwr (ORCPT ); Tue, 31 Mar 2020 06:52:47 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730760AbgCaKwo (ORCPT ); Tue, 31 Mar 2020 06:52:44 -0400 IronPort-SDR: 3KvejIdFQHpMsDY7FZPAlN8epkASGCIY19e47nHZ1fxOIBmLZ1aRPerAK5228hrS79WfDseQGd OSDSgvaykh1ymwLllkKkafWJZjRADVdhnp1pUbZg2nQu2blwrjXm13QlB5/smqJqh0Xegx8jAd uY/rSlx40sozhquqpBG9f/fRa5dVtiF/cpfXhK0cmRxnLGi1sLo7vOW4OIF8rhPql5DKat3dPq vwcch6IuI8Wjd87imI2WaHo4NiXmE4hfKzMgNEZuz6i4eRlgJ+hMW6CEugSgQBnhyfmLt4t7L8 lE0= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330792" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:42 -0800 IronPort-SDR: GHMqegbnzZR40zkcteNJcyP3cCiDbs9j3JRgkaTmopQ0Z+Y0gCvQgYQmufgRZRPZV9/7f+ynG0 H94gheD3I1qDjDP4ThElATg/k8zwCECpP94/cqDYx3wgcAsMXJK1KcNaDY4IETNanqcj75F2Gx jaI2d6SKwMj6eLTdm1crBhznn11AmT2VnqRJ7c224waIs7YyFYKCLq788YadkORJnO7bLbwPnR 1bV2XJCz/OnwrKCPYOCWLEWW9fwU/prxQkvHvPUpZzINTAZ7II0lWn2R+7ShbnsLM0NeTvALVM Ebk= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 28/55] Input: atmel_mxt_ts - improve bootloader state machine handling Date: Tue, 31 Mar 2020 03:50:24 -0700 Message-ID: <20200331105051.58896-29-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 The code is much clearer if we switch on the actual state the bootloader is in, rather than the state we want it to be in, and allows the removal of a goto retry tangle. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 463e15ee95ee6e6274017ff645839dbe34d75c99) [gdavis: Squash fix from George G. Davis: - input: atmel_mxt_ts - Fix 'mxt_send_bootloader_cmd' was not declared warning] Signed-off-by: George G. Davis [jiada: only wait on some status change, cleanup code style] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 165 +++++++++++++---------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 71d5781d3539..0f1c0e5c6169 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -305,6 +305,9 @@ struct mxt_flash { size_t frame_size; unsigned int count; unsigned int retry; + u8 previous; + bool complete; + bool wait; }; /* Each client has this additional data */ @@ -583,15 +586,27 @@ static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) return 0; } -static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, - bool wait) +static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock); + +static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) +{ + f->frame = (struct mxt_fw_frame *)(f->fw->data + f->pos); + + /* Take account of CRC bytes */ + f->frame_size = __be16_to_cpu(f->frame->size) + 2U; + + /* Write one frame to device */ + return mxt_bootloader_write(data, f->fw->data + f->pos, + f->frame_size); +} + +static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) { struct device *dev = &data->client->dev; - u8 val; + u8 state; int ret; -recheck: - if (wait) { + if (f->wait) { /* * In application update mode, the interrupt * line signals state transitions. We must wait for the @@ -607,40 +622,96 @@ static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, * by writing length 0x000 to device (iff we are in * WAITING_FRAME_DATA state). */ - dev_err(dev, "Update wait error %d\n", ret); + dev_warn(dev, "Update wait error %d\n", ret); return ret; } } - ret = mxt_bootloader_read(data, &val, 1); + f->wait = false; + + ret = mxt_bootloader_read(data, &state, 1); if (ret) return ret; + /* Remove don't care bits */ + if (state & ~MXT_BOOT_STATUS_MASK) + state &= ~MXT_BOOT_STATUS_MASK; + switch (state) { case MXT_WAITING_BOOTLOAD_CMD: + dev_info(dev, "Unlocking bootloader\n"); + ret = mxt_send_bootloader_cmd(data, true); + if (ret) + return ret; + f->wait = true; + + break; + case MXT_WAITING_FRAME_DATA: - case MXT_APP_CRC_FAIL: - val &= ~MXT_BOOT_STATUS_MASK; + if (f->previous != MXT_WAITING_BOOTLOAD_CMD && + f->previous != MXT_FRAME_CRC_PASS && + f->previous != MXT_FRAME_CRC_FAIL) + goto unexpected; + + ret = mxt_write_firmware_frame(data, f); + if (ret) + return ret; + + f->wait = true; + + break; + + case MXT_FRAME_CRC_CHECK: + if (f->previous != MXT_WAITING_FRAME_DATA) + goto unexpected; + f->wait = true; break; + case MXT_FRAME_CRC_PASS: - if (val == MXT_FRAME_CRC_CHECK) { - goto recheck; - } else if (val == MXT_FRAME_CRC_FAIL) { - dev_err(dev, "Bootloader CRC fail\n"); - return -EINVAL; + if (f->previous != MXT_FRAME_CRC_CHECK) + goto unexpected; + + /* Next frame */ + f->retry = 0; + f->pos += f->frame_size; + f->count++; + f->wait = true; + + if (f->pos >= f->fw->size) { + f->complete = true; + dev_info(dev, "Sent %u frames, %zu bytes\n", + f->count, f->fw->size); + } else if (f->count % 50 == 0) { + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f->count, f->pos, f->fw->size); + } + + break; + + case MXT_FRAME_CRC_FAIL: + if (f->retry > 20) { + dev_err(dev, "Retry count exceeded\n"); + return -EIO; } + + /* Back off by 20ms per retry */ + dev_dbg(dev, "Bootloader frame CRC failure\n"); + f->retry++; + f->wait = true; + msleep(f->retry * 20); break; + default: return -EINVAL; } - if (val != state) { - dev_err(dev, "Invalid bootloader state %02X != %02X\n", - val, state); - return -EINVAL; - } + f->previous = state; return 0; + +unexpected: + dev_err(dev, "Unexpected state transition\n"); + return -EINVAL; } static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) @@ -3301,57 +3372,13 @@ static int mxt_load_fw(struct device *dev) if (ret) goto release_firmware; - ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); - if (ret) { - /* Bootloader may still be unlocked from previous attempt */ - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false); - if (ret) - goto disable_irq; - } else { - dev_info(dev, "Unlocking bootloader\n"); - - /* Unlock bootloader */ - ret = mxt_send_bootloader_cmd(data, true); + while (true) { + ret = mxt_check_bootloader(data, &f); if (ret) - goto disable_irq; - } - - while (f.pos < f.fw->size) { - f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); - - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); - if (ret) - goto disable_irq; - - /* Take account of CRC bytes */ - f.frame_size = __be16_to_cpu(f.frame->size) + 2U; - - /* Write one frame to device */ - ret = mxt_bootloader_write(data, f.fw->data + f.pos, - f.frame_size); - if (ret) - goto disable_irq; - - ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); - if (ret) { - f.retry++; - - /* Back off by 20ms per retry */ - msleep(f.retry * 20); - - if (f.retry > 20) { - dev_err(dev, "Retry count exceeded\n"); - goto disable_irq; - } - } else { - f.retry = 0; - f.pos += f.frame_size; - f.count++; - } + return ret; - if (f.count % 50 == 0) - dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", - f.count, f.pos, f.fw->size); + if (f.complete) + break; } /* Wait for flash. */ @@ -3360,7 +3387,6 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3370,7 +3396,6 @@ static int mxt_load_fw(struct device *dev) mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); data->in_bootloader = false; - disable_irq: disable_irq(data->irq); release_firmware: From patchwork Tue Mar 31 10:50:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98320C2D0EF for ; Tue, 31 Mar 2020 10:53:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E47A208E0 for ; Tue, 31 Mar 2020 10:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730532AbgCaKww (ORCPT ); Tue, 31 Mar 2020 06:52:52 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730799AbgCaKwv (ORCPT ); Tue, 31 Mar 2020 06:52:51 -0400 IronPort-SDR: Mh/9UWCrg97px4e3TZ3cK39kjE4R65MYk++NVbRlEZ1Tf8mg6+Nu3fQHDyPhsdprs9em5jgnsU qpaGG5kJZRGzEwFomARDdJu+iXMy/ivVZ7m8z26KZc8HtNx3NdljUTmJ6HzfX09fo9UUq36gDd aZcW6KWG66xe1YKikqPFszNRjkLAf7lYkiqY4NLE8Ir8oSoqKChWvmbot7QJyIBVs8zT7ieA2n us8HzgAT4gMUxTUKrxF4YVy1fzPJJhGvJefV/WTSUKF0Iopi8UPc6yUYZ7TYTC/mqeGhtpixUJ eoQ= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330797" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:50 -0800 IronPort-SDR: x4h9gm0LaMB3S3kcae4s4iEsM63QLi5ivHF7rv9DXsc0/qOmYAySRaYSuAESOk+0HAseTLOJix R/aK680gv7efy5cgmDaNyOe4MMZV7OBGyRcDjMof0nfVdjnrcgJ7747O3QLoZGYWzrNY3FvSUR TpZxqRcBXmByw8yMxArhdIT2bAB10iUwcOe9gCj2Jn7WiDmS2sUw+6IxDZEsmpc/aMzH+SYJtU B2VF44Y6N1nTWGpw5e6//f47Vn+8glnxViA+JIOX27S8JrWXMfCXH6GoYIAsQdBq/gqNObOdnY Cm0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 30/55] Input: atmel_mxt_ts - make bootloader interrupt driven Date: Tue, 31 Mar 2020 03:50:26 -0700 Message-ID: <20200331105051.58896-31-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 Make bootloader interrupt driven Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 67a3eea0cfc724c3c2a7410ac064f74227c7c6ef) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Replace two use msecs_to_jiffies() instead of HZ, remove check of &data->flash->work don't poll to call mxt_check_bootloader() in mxt_check_bootloader()] Reported-by: kbuild test robot Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 127 ++++++++++------------- 1 file changed, 57 insertions(+), 70 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ed142b24d12d..62f11afb26ae 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,7 @@ enum t100_type { #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ +#define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -299,6 +301,7 @@ struct mxt_fw_frame { /* Firmware update context */ struct mxt_flash { + struct mxt_data *data; const struct firmware *fw; struct mxt_fw_frame *frame; loff_t pos; @@ -306,8 +309,8 @@ struct mxt_flash { unsigned int count; unsigned int retry; u8 previous; - bool complete; - bool wait; + struct completion flash_completion; + struct delayed_work work; }; /* Each client has this additional data */ @@ -356,6 +359,7 @@ struct mxt_data { char *cfg_name; const char *pcfg_name; const char *input_name; + struct mxt_flash *flash; /* Cached parameters from object table */ u16 T5_address; @@ -600,35 +604,19 @@ static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) f->frame_size); } -static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) +static int mxt_check_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; + struct mxt_flash *f = data->flash; u8 state; int ret; - if (f->wait) { - /* - * In application update mode, the interrupt - * line signals state transitions. We must wait for the - * CHG assertion before reading the status byte. - * Once the status byte has been read, the line is deasserted. - */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_CHG_TIMEOUT); - if (ret) { - /* - * TODO: handle -ERESTARTSYS better by terminating - * fw update process before returning to userspace - * by writing length 0x000 to device (iff we are in - * WAITING_FRAME_DATA state). - */ - dev_warn(dev, "Update wait error %d\n", ret); - return ret; - } + /* Handle interrupt after download/flash process */ + if (f->pos >= f->fw->size) { + complete(&f->flash_completion); + return 0; } - f->wait = false; - ret = mxt_bootloader_read(data, &state, 1); if (ret) return ret; @@ -643,7 +631,6 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) ret = mxt_send_bootloader_cmd(data, true); if (ret) return ret; - f->wait = true; break; @@ -657,14 +644,11 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) if (ret) return ret; - f->wait = true; - break; case MXT_FRAME_CRC_CHECK: if (f->previous != MXT_WAITING_FRAME_DATA) goto unexpected; - f->wait = true; break; case MXT_FRAME_CRC_PASS: @@ -675,16 +659,13 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->retry = 0; f->pos += f->frame_size; f->count++; - f->wait = true; - if (f->pos >= f->fw->size) { - f->complete = true; + if (f->pos >= f->fw->size) dev_info(dev, "Sent %u frames, %zu bytes\n", f->count, f->fw->size); - } else if (f->count % 50 == 0) { + else if (f->count % 50 == 0) dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", f->count, f->pos, f->fw->size); - } break; @@ -697,7 +678,6 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) /* Back off by 20ms per retry */ dev_dbg(dev, "Bootloader frame CRC failure\n"); f->retry++; - f->wait = true; msleep(f->retry * 20); break; @@ -1415,7 +1395,11 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->in_bootloader) { complete(&data->chg_completion); - return IRQ_HANDLED; + + if (data->flash) + cancel_delayed_work_sync(&data->flash->work); + + return IRQ_RETVAL(mxt_check_bootloader(data)); } if (!data->object_table) @@ -3316,16 +3300,13 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (data->suspend_mode == MXT_SUSPEND_REGULATOR) mxt_regulator_enable(data); - if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) - enable_irq(data->irq); - data->suspended = false; } if (!data->in_bootloader) { - /* Change to the bootloader mode */ - data->in_bootloader = true; + disable_irq(data->irq); + /* Change to the bootloader mode */ ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); if (ret) @@ -3338,67 +3319,73 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (ret) return ret; + data->in_bootloader = true; mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); - } else { - enable_irq(data->irq); } - reinit_completion(&data->chg_completion); + dev_dbg(&data->client->dev, "Entered bootloader\n"); return 0; } +static void mxt_fw_work(struct work_struct *work) +{ + struct mxt_flash *f = + container_of(work, struct mxt_flash, work.work); + + mxt_check_bootloader(f->data); +} + static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&f.fw, data->fw_name, dev); + data->flash = devm_kzalloc(dev, sizeof(struct mxt_flash), GFP_KERNEL); + if (!data->flash) + return -ENOMEM; + + data->flash->data = data; + + ret = request_firmware(&data->flash->fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); - return ret; + goto free; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, f.fw); + ret = mxt_check_firmware_format(dev, data->flash->fw); if (ret) goto release_firmware; - ret = mxt_enter_bootloader(data); - if (ret) - goto release_firmware; + init_completion(&data->flash->flash_completion); + INIT_DELAYED_WORK(&data->flash->work, mxt_fw_work); + reinit_completion(&data->flash->flash_completion); - while (true) { - ret = mxt_check_bootloader(data, &f); + if (!data->in_bootloader) { + ret = mxt_enter_bootloader(data); if (ret) - return ret; - - if (f.complete) - break; + goto release_firmware; } - /* Wait for flash. */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_RESET_TIME); - if (ret) - goto disable_irq; + enable_irq(data->irq); + /* Poll after 0.1s if no interrupt received */ + schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); - /* - * Wait for device to reset. Some bootloader versions do not assert - * the CHG line after bootloading has finished, so ignore potential - * errors. - */ - mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); + /* Wait for flash. */ + ret = mxt_wait_for_completion(data, &data->flash->flash_completion, + MXT_BOOTLOADER_WAIT); - data->in_bootloader = false; -disable_irq: disable_irq(data->irq); + cancel_delayed_work_sync(&data->flash->work); + data->in_bootloader = false; release_firmware: - release_firmware(f.fw); + release_firmware(data->flash->fw); +free: + devm_kfree(dev, data->flash); return ret; } From patchwork Tue Mar 31 10:50:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD4CBC2D0E8 for ; Tue, 31 Mar 2020 10:52:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B944320B80 for ; Tue, 31 Mar 2020 10:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730815AbgCaKwy (ORCPT ); Tue, 31 Mar 2020 06:52:54 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbgCaKwy (ORCPT ); Tue, 31 Mar 2020 06:52:54 -0400 IronPort-SDR: uwjge014RS0QTx2uGcl9vbYp7rBHGc1iaHwtGpkGe1BQxkrEFw1I5bD13cNnG3Jd7MWIIkeYW5 pOjMTbDxrvbpEGW6pFe0MPatN2GBnz41n308TNbiRprrAtgYYTshDlnFj7N85iYrew2LulQOUn 1vHArfVdHlu4adeeGMnDIM+gFWccyslAvKuvr99sdsjyD0fAOKJMn+P3QNJhn1c+gmzitPycjf 7UPSjqlxM7ylKSqRej8cFQQKZI1KiOtEg2HInXn85rn5KI7C7t0C7ZcFb0ovo4dQCekXVSwFdO UQQ= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330799" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:53 -0800 IronPort-SDR: ohzFJPOinnaU7WizE5qg1+J0hl4ebvquRRFMAyhS2hSfZkfKe/PdUCVMKpYuzDKsgSKhVHwYnq 6r6UGTmWluHF1lqsFEa7T9bbpJLXL0VdBzMemVphSeajtXywyWaWbhUwv3Cu/nXcDbf009Bf5F L5poNBhHV3PgxpEbJcEHH2W8Sb1c7mCYgIEFCXLG9kFlmMaf/+ckZLS3hhhrpYUYOGN5AluzKV MwM3Ezgqibf9jeTmCvKtImYCTIs9yONDHYrlUoRUy5EWqlXE3Il1FQHwFSm8k8CmNe2xLCKlqK Msc= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 31/55] Input: atmel_mxt_ts - delay enabling IRQ when not using regulators Date: Tue, 31 Mar 2020 03:50:27 -0700 Message-ID: <20200331105051.58896-32-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 The path of enabling the IRQ in the probe function is not safe in level triggered operation, if it was already powered up and there is a message waiting on the device (eg finger down) because the object table has not yet been read. This forces the ISR into a hard loop. Delay enabling the interrupt until it is first needed. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 64c9dadc4a3250a185baf06ab0f628be45d5d9a0) [gdavis: Resolve forward port conflicts due to v4.14-rc1 commit 8cc8446b9b62 ("Input: atmel_mxt_ts - use more managed resources") and applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 40 +++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 62f11afb26ae..c26470bcb38b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1448,9 +1448,24 @@ static int mxt_acquire_irq(struct mxt_data *data) { int error; - enable_irq(data->irq); + if (!data->irq) { + error = devm_request_threaded_irq(&data->client->dev, + data->client->irq, + NULL, mxt_interrupt, + IRQF_ONESHOT, + data->client->name, data); + if (error) { + dev_err(&data->client->dev, "Error requesting irq\n"); + return error; + } - if (data->use_retrigen_workaround) { + /* Presence of data->irq means IRQ initialised */ + data->irq = data->client->irq; + } else { + enable_irq(data->irq); + } + + if (data->object_table && data->use_retrigen_workaround) { error = mxt_process_messages_until_invalid(data); if (error) return error; @@ -3370,7 +3385,9 @@ static int mxt_load_fw(struct device *dev) goto release_firmware; } - enable_irq(data->irq); + ret = mxt_acquire_irq(data); + if (ret) + goto release_firmware; /* Poll after 0.1s if no interrupt received */ schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); @@ -3798,7 +3815,6 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) client->adapter->nr, client->addr); data->client = client; - data->irq = client->irq; i2c_set_clientdata(client, data); init_completion(&data->chg_completion); @@ -3826,26 +3842,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, - NULL, mxt_interrupt, IRQF_ONESHOT, - client->name, data); - if (error) { - dev_err(&client->dev, "Failed to register interrupt\n"); - return error; - } - if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + error = mxt_acquire_irq(data); + if (error) + return error; + error = mxt_probe_regulators(data); if (error) return error; + + disable_irq(data->irq); } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } - disable_irq(data->irq); - error = mxt_initialize(data); if (error) return error; From patchwork Tue Mar 31 10:50:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE4BFC2D0EF for ; Tue, 31 Mar 2020 10:53:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 900442145D for ; Tue, 31 Mar 2020 10:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730591AbgCaKw7 (ORCPT ); Tue, 31 Mar 2020 06:52:59 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbgCaKw6 (ORCPT ); Tue, 31 Mar 2020 06:52:58 -0400 IronPort-SDR: 1P4plBerY7IQTZL22Hwg8nR6CRKqgS5SAWf98T8t5krWdjzhsim2Hk8BZQxZ08EOzDWRYwZ3gk um5913RNInlQt8kiig8CX2DgKU/8B9oI6u7amTUuAnyxNmSGo8C2Hm48eDmxwkrEeR03Or0Sm5 jriOL+3ionDWwnPVcZk/H9V4IHes/1Y8phrM7Uv8lZvBxTcqJtGjlcY4/RBLiSnVQ7ceRkYasp e1P0/hZ1ANlzmVvE4vYsu911z0FSKdSK1BIYZo4KrDnBpvPoJY0viZgDRwdoYyhoW01b8qB32p Vok= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330801" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:52:57 -0800 IronPort-SDR: l1rAeDxAILvgDHaBpMuqEIFrvP79wM+CuJbktsJIsqh9YiM9efJzc3o/Om08nV7SsQb9Xdj32+ uxtFIqCwQxYAJtVDr5vdg1CsK+TP6CCW5La3PED1qbeMKix4fCHN5wiHdAtUuIUoH1gEmK2/Ux tXQLskPY9uEEnHbt7qD6ROu7alzk/3r8zg0qx5EZUdY/xc0kjeysUwSpcYpCqLzb7wN9Zhw2Rm jE3NPFmeQztNCL6pEWdkK3KfRdu3BA/KxCtlPCb9CrQ2jJntIm5cjGJNskSM8JD52LJNbh8r+F F4o= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 32/55] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 31 Mar 2020 03:50:28 -0700 Message-ID: <20200331105051.58896-33-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 c26470bcb38b..daa77eb9561b 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 */ @@ -720,6 +721,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; @@ -736,17 +738,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, @@ -777,6 +784,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); @@ -787,14 +795,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); From patchwork Tue Mar 31 10:50: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: 207986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9328EC43331 for ; Tue, 31 Mar 2020 10:53:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F4FF214DB for ; Tue, 31 Mar 2020 10:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730645AbgCaKxV (ORCPT ); Tue, 31 Mar 2020 06:53:21 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730598AbgCaKxU (ORCPT ); Tue, 31 Mar 2020 06:53:20 -0400 IronPort-SDR: MHBBYfaseZtE4A0L1dFpRXP8VRuCf+rSr8KVUlTQ7Er4BIMwbita81KnxXzD5AEJdPfpAldqOP 5QW8QXBarFrQB4PYjVvWQkPMMAFXizLEQVuXGoyN58MQxBbnnBJddLmdzrrqNI0DyOPFXcdESU 4bDZmqYqoKK9xuaBQrM+lTWMouV5Tb7NnwiOE01Xg9mWbRhMJjYpiOhGBmPRnfM1up9VhQ04BP R7uR2POSqPSXmPQTFVrHFy0Sil7p5kqV/ggFdkMcS4YGKZPpywd38U8BRs9OcjoOophe/dYlPB Pe8= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330818" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:20 -0800 IronPort-SDR: hbJ35K90321e1qZKqCZeIqrAvJ3jNp9qATj24CTvxdzuhCmLgiFQmQG0JRSHGEak6eqevf5Xn+ TK8PIeZmqEuosLYDcsvkEBxnn7o6KLOoiW9CXBGpv3XYu1G4Jlcrt4tcdHSlHtsSLMbbc7DOZE XybKvOm/WsWgmN8zTSznz+C8E6EdJAkIy8ZSR1hgFbZPYMgom1SodIkwFmOhqXhMrLSEeC7J5a /HC1YOO+rCIxend2QtxoLGmIxtBDW2WnslFBOxNtYRs1/V4SggthmBK+p6t+w+GluavTCZuTZQ NoM= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 38/55] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Tue, 31 Mar 2020 03:50:34 -0700 Message-ID: <20200331105051.58896-39-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Kautuk Consul We now prefer to rely on the calculated CRC and not on the CRC stored in the file. The new logic is as follows: 1) stored CRC of file != calculated CRC of file, then refuse the possible corrupted file 2) calculated CRC of file != CRC of configuration in controller, then update configuration in controller 3) calculated CRC of file == CRC of configuration in controller, then ignore configuration file Signed-off-by: Kautuk Consul Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++----------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 860e8ddd4c6b..11e65f32b1a2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1905,7 +1905,7 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) int ret; int offset; int i; - u32 info_crc, config_crc, calculated_crc; + u32 info_crc, config_crc, calculated_crc = 0; u16 crc_start = 0; /* Make zero terminated copy of the OBP_RAW file */ @@ -1968,30 +1968,6 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) } cfg.raw_pos += offset; - /* - * The Info Block CRC is calculated over mxt_info and the object - * table. If it does not match then we are trying to load the - * configuration from a different chip or firmware version, so - * the configuration CRC is invalid anyway. - */ - if (info_crc == data->info_crc) { - if (config_crc == 0 || data->config_crc == 0) { - dev_info(dev, "CRC zero, attempting to apply config\n"); - } else if (config_crc == data->config_crc) { - dev_dbg(dev, "Config CRC 0x%06X: OK\n", - data->config_crc); - ret = 0; - goto release_raw; - } else { - dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", - data->config_crc, config_crc); - } - } else { - dev_warn(dev, - "Warning: Info CRC error - device=0x%06X file=0x%06X\n", - data->info_crc, info_crc); - } - /* Malloc memory to store configuration */ cfg.start_ofs = MXT_OBJECT_START + data->info->object_num * sizeof(struct mxt_object) + @@ -2015,14 +1991,45 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) else dev_warn(dev, "Could not find CRC start\n"); - if (crc_start > cfg.start_ofs) { + if (crc_start > cfg.start_ofs) calculated_crc = mxt_calculate_crc(cfg.mem, crc_start - cfg.start_ofs, cfg.mem_size); - if (config_crc > 0 && config_crc != calculated_crc) - dev_warn(dev, "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", - calculated_crc, config_crc); + /* If the CRC stored in the file is not the same as what + * was calculated by mxt_calculate_crc, this means we + * have to refuse the config file and abort download. + */ + if (config_crc != calculated_crc) { + dev_warn(dev, + "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", + calculated_crc, config_crc); + ret = 0; + goto release_mem; + } + + /* + * The Info Block CRC is calculated over mxt_info and the object + * table. If it does not match then we are trying to load the + * configuration from a different chip or firmware version, so + * the configuration CRC is invalid anyway. + */ + if (info_crc == data->info_crc) { + if (config_crc == 0 || data->config_crc == 0) { + dev_info(dev, "CRC zero, attempting to apply config\n"); + } else if (config_crc == data->config_crc) { + dev_dbg(dev, "Config CRC 0x%06X: OK\n", + data->config_crc); + ret = 0; + goto release_mem; + } else { + dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", + data->config_crc, config_crc); + } + } else { + dev_warn(dev, + "Warning: Info CRC error - device=0x%06X file=0x%06X\n", + data->info_crc, info_crc); } ret = mxt_upload_cfg_mem(data, &cfg); From patchwork Tue Mar 31 10:50:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 387D4C2D0EF for ; Tue, 31 Mar 2020 10:53:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 194B820772 for ; Tue, 31 Mar 2020 10:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730913AbgCaKx2 (ORCPT ); Tue, 31 Mar 2020 06:53:28 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730426AbgCaKx2 (ORCPT ); Tue, 31 Mar 2020 06:53:28 -0400 IronPort-SDR: 6/0j/f/+9NchP81t2XhkzmxWKBRblQHwrv/Ngk3HUjVdI4IUDfrzsWTbfFhZlnUTw01Dr+Mt3L lUj2deaTLNTIdMmKalu+Vpxo1oe6G7mMP9Z46BY/H6K7Fb3IW9AyToFM4Z59mMcvVz0MJs8NyD vviEjLCYmCUu674qbv7yL2c+g8tj9RiX9wcj4jN1ROnBc66oE5LkNeTE8MPHQtHkrCcB17wj6A eGU0s5IAe8WsJ8tNUiwbixlglP5XaAzfhVX8KhbnMPTS6wC9e/bVJk6S6LviwbKJ7bDC9hhbEf 0fg= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330824" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:27 -0800 IronPort-SDR: uSsoBXL1GYn/EeL2k5Om+kok4Fo2TiN7Qh+W3TdJb74RcHLdkvNF+iWEuioIVUYEZw0Q7ol8p6 kSgKkFb91l9GZ0beflbR0RP6h6iVDuEn3JC2MbZ1fNwIXztPrwUd67wk1I2ECbLm81cN26g3Za KLOtz26Mm+adwdVAt2eTAtx896hNSC408cKK12YNdtChWfCn4zSITsDAE78rS1OSsazubsd+yM fhC7L2+BxStAf6CxpTXSFeHSLeeBxqNB4y/ML3OBvg9gYYiB67e6XsdISBqUX/alKTc0si+SGZ hRU= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 40/55] input: atmel_mxt_ts: Add Missing Delay for reset handling of Atmel touch panel controller in detachable displays. Date: Tue, 31 Mar 2020 03:50:36 -0700 Message-ID: <20200331105051.58896-41-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: keerthikumarp In case of attached display, the touchpanel reset is controlled via imx gpio's from atmel driver and the delay between touchpanel reset and the time at which the chip becomes capable to communicate with the host processor, has be taken care. However in case of detachable displays, the touchpanel reset is controlled via a deserializer gpio which is triggered just before the atmel driver is probed.The delay between touchpanel reset and the time at which the chip becomes capable to communicate (as specified in datasheet) was not being accounted for. This patch introduces that delay. Signed-off-by: keerthikumarp Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index cfeeacdd4084..fb7cd06cab53 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4118,6 +4118,10 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); + } else { + dev_dbg(&client->dev, + "atmel reset pin not found in device tree"); + msleep(MXT_RESET_TIME); } error = mxt_initialize(data); From patchwork Tue Mar 31 10:50:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 667AAC43331 for ; Tue, 31 Mar 2020 10:53:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 471AE208E4 for ; Tue, 31 Mar 2020 10:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730788AbgCaKxd (ORCPT ); Tue, 31 Mar 2020 06:53:33 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730922AbgCaKxc (ORCPT ); Tue, 31 Mar 2020 06:53:32 -0400 IronPort-SDR: gACpHvx8AF09s5oBgrpHixyEMGCDTmi6bfT6xCB1mCW+wkC6UgTXffcpWqa0wow79cETnaalbh IMr8/fUCtTYrXb7nXXo3kd6wtEOBx1TvB4qLg5AjwovVPhiqi0SpCDo4xSg3f04T0BoLFdllBt wnhYiYmoE3NIYqq3m7KuN0Jaz3g0R8oCwxEEPGPzvVlyo4Lyt3CG+/UQfaQmQRrFIF9F1XOD7u 1mhcZYNuq66KJerE8Yx7YJjbkFuUJ7VCheOpPIcLc7saaEBTFuGHJRdm+mjAaBO6/bBJcrqStd v2o= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330829" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:31 -0800 IronPort-SDR: HdUupt5FmIYReew7TVjcfq8faoFEISBln0DQn2ResxPtE5QaIk1WPlXtK8A5MQe/LGnJtYnNv3 HKUt1u3vyL+QwwrSMfnUuLq2xyHW8PrO2HGdrQupzUHCUdgHAYl4JUX7AVpCxtaXeap3qzia4o RE6et8Ph8n6xxJpD81eU6tvXTc0WBqqr03U90hc14piTzsJxslpEiw8H9Zi2/dJyDEcgJJgK+b VNRJk/v2hCdAgsMLX2iK13g4dGQldjkUcamyTn55YjmcmDkSBV5SoLwOhGO/BIyAZ631CUDhcr 8XI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 41/55] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Tue, 31 Mar 2020 03:50:37 -0700 Message-ID: <20200331105051.58896-42-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Nikhil Ravindran The self test object T25 runs self test routines in device to find faults Sysfs entry add to start self test routine and read back the test results for atmel touchcontrollers.The feature will be used for A-IVI and CAF projects. Signed-off-by: Nikhil Ravindran Signed-off-by: George G. Davis [jiada: Rename mxt_t25_selftest_show to t25_selftest_show Rename mxt_t25_selftest_store to t25_selftest_show Rename attr t25 to t25_selftest Replace DEVICE_ATTR with DEVICE_ATTR_RW] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index fb7cd06cab53..54cd6219cbaa 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,9 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + u16 T25_address; + u8 T25_reportid; + u8 t25_msg[6]; bool debug_enabled; bool debug_v2_enabled; u8 *debug_msg_data; @@ -413,6 +416,8 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + + bool t25_status; }; struct mxt_vb2_buffer { @@ -1356,6 +1361,24 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) dev_info(dev, "T93 report double tap %d\n", status); } +static void mxt_proc_t25_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + /* Output debug if status has changed */ + dev_dbg(dev, "T25 Status 0x%x Info: %x %x %x %x %x\n", + msg[1], + msg[2], + msg[3], + msg[4], + msg[5], + msg[6]); + + /* Save current status */ + memcpy(&data->t25_msg[0], &msg[1], sizeof(data->t25_msg)); + data->t25_status = false; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1386,6 +1409,8 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T19_reportid) { mxt_input_button(data, message); data->update_input = true; + } else if (report_id == data->T25_reportid) { + mxt_proc_t25_messages(data, message); } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); @@ -1610,6 +1635,86 @@ static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, return 0; } +static int mxt_t25_command(struct mxt_data *data, u8 cmd, bool wait) +{ + u16 reg; + int timeout_counter = 0; + int ret; + u8 val[2]; + + reg = data->T25_address; + val[0] = 0x3; + val[1] = cmd; + + data->t25_status = true; + ret = __mxt_write_reg(data->client, reg, sizeof(val), val); + if (ret) { + data->t25_status = false; + return ret; + } + + if (!wait) + return 0; + + do { + msleep(MXT_WAKEUP_TIME); + ret = __mxt_read_reg(data->client, reg + 1, 1, &val[1]); + if (ret) + return ret; + } while ((val[1] != 0) && (timeout_counter++ <= 100)); + + if (timeout_counter > 100) { + dev_err(&data->client->dev, "Command failed!\n"); + data->t25_status = false; + return -EIO; + } + return 0; +} + +/* Firmware Version is returned as Major.Minor.Build */ +static ssize_t t25_selftest_show(struct device *dev, struct + device_attribute * attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + ssize_t offset = 0; + + if (data->t25_status) + return -EAGAIN; + + if (data->t25_msg[0] == 0xFE) + offset += scnprintf(buf, PAGE_SIZE, "PASS\n"); + else + offset += scnprintf(buf, PAGE_SIZE, "FAILED\n"); + + offset += scnprintf(buf + offset, PAGE_SIZE, "%x %x %x %x %x %x\n", + data->t25_msg[0], + data->t25_msg[1], + data->t25_msg[2], + data->t25_msg[3], + data->t25_msg[4], + data->t25_msg[5]); + return offset; +} + +static ssize_t t25_selftest_store(struct device *dev, struct + device_attribute * attr, const char *buf, + size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u32 cmd; + int ret; + + ret = kstrtou32(buf, 0, &cmd); + if (ret) + return ret; + + if (mxt_t25_command(data, (u8)cmd, 1) == 0) + return count; + + dev_dbg(dev, "mxt_t25_cmd_store write cmd %x error\n", cmd); + return -EINVAL; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2088,6 +2193,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T25_address = 0; + data->T25_reportid = 0; data->T42_reportid_min = 0; data->T42_reportid_max = 0; data->T44_address = 0; @@ -2175,6 +2282,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_SPT_SELFTEST_T25: + data->T25_address = object->start_address; + data->T25_reportid = min_id; + break; case MXT_PROCI_TOUCHSUPPRESSION_T42: data->T42_reportid_min = min_id; data->T42_reportid_max = max_id; @@ -3769,6 +3880,7 @@ static DEVICE_ATTR_RO(config_crc); static DEVICE_ATTR_RW(debug_enable); static DEVICE_ATTR_RW(debug_v2_enable); static DEVICE_ATTR_RO(debug_notify); +static DEVICE_ATTR_RW(t25_selftest); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3779,6 +3891,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_enable.attr, &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, + &dev_attr_t25_selftest.attr, NULL }; From patchwork Tue Mar 31 10:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0458C2D0E8 for ; Tue, 31 Mar 2020 10:53:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF26220772 for ; Tue, 31 Mar 2020 10:53:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730619AbgCaKxn (ORCPT ); Tue, 31 Mar 2020 06:53:43 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730946AbgCaKxm (ORCPT ); Tue, 31 Mar 2020 06:53:42 -0400 IronPort-SDR: cs4m7RbYzpTVVfnPAxKfUQDAlJkAHFQqqDTBIwGhOVCG4Fee/1Ne8/A3JMfF/HAbr6970xsfwc XHeQli4H6kpmY1dU5YNab0ITiyd64IOolSo90slStPlnd3Fy5RGds//9sevPKF0qpd8Ji5oYQ5 mMBgFD5mxTFVxLfbtr2QN2FA3DsjLap1PC8bCCaSutAhcQLWVgwp0hHjmO43mzt5VWSK6USztx wm53Jne3+hRBOKvgtHpQB+JHOu5Lt7ZNiIOuWMLStyH1CdwDodW6Tk2kPo1MYs/d/KdzEtyQbk qzQ= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330838" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:42 -0800 IronPort-SDR: +bMCQJJLPyqQABm5RnUXGfLNY9Hj6Vn8Rgt5hxaSnEmP2wMyR4frc0uc8Wfk1nE2wYwkH6W45y fNH8eckyDYA9xgoBi4n6uLU295Nhxjux1peD7SqJ1zzLtEgT0uw4dclDHtd37lVAF90JgjIY1G gBrmKAdZKB92z+RZwDsnCfiRoHSHCmxf3SvzttomhG5/ijL6MFc1YwoOlLv8pHd//T+LluRGQn W2+UWOTbenVP8qVFClPHDRak+gYf3DIx8Jwahvj+ubFfOll8kuGThmToKU0Z/3oJhVH26Waxd0 7Hw= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 44/55] Input: atmel_mxt_ts: return error from mxt_process_messages_until_invalid() Date: Tue, 31 Mar 2020 03:50:40 -0700 Message-ID: <20200331105051.58896-45-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Dean Jenkins mxt_process_messages_until_invalid() failed to propagate the error code from mxt_read_and_process_messages() so return the error code. Signed-off-by: Dean Jenkins Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 384b53717139..bbec5a8e0bb6 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1561,6 +1561,8 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) /* Read messages until we force an invalid */ do { read = mxt_read_and_process_messages(data, count); + if (read < 0) + return read; if (read < count) return 0; } while (--tries); From patchwork Tue Mar 31 10:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ACC3C2D0EE for ; Tue, 31 Mar 2020 10:53:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAF77208E0 for ; Tue, 31 Mar 2020 10:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730437AbgCaKxv (ORCPT ); Tue, 31 Mar 2020 06:53:51 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730442AbgCaKxu (ORCPT ); Tue, 31 Mar 2020 06:53:50 -0400 IronPort-SDR: SSFl0qJwqO+AbHaEmZa5DTVOGlFh97f7Q7eReDAnscd2boUFkigb9oh20omrq941CbJCDIel3T K5OhvwiqwUXmb7Vr97uoZ+/QCaeTYUfbUSrqpQCJ9UfzQ3A7EYdDjRjB0tfNgX6EpiJ2iw5GuJ au9sijOMGwcqUelkejYYWj7+o/kjRPZe6A79BX9+dZTPzoe2IK//W6mHJgmqK+2EoOksut5+Ut AGJzSZG2p2FBYnBxDTMEmqxvQMAv0k4Zn/7L1eUpAf8guONAeu1YC/zrD9NpJBnVBoMSzJstdh jpE= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330842" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:50 -0800 IronPort-SDR: kauWWYYMfgeOWRryf6wVPxzi03A7Wy1c553H2DUA/4YMHuOJFiK6hPM6uqJbUzd7d7qxaR2IpD Z0aVu1KZ9JnilC4ib+05caxR1GXoSgawZoNQofpuDHziZ+kXWV0VIgOEKFv5feNTJ/h+5kgy6L zXXgcg+0eac6EqRhIk10OJiJAb7StiYso5gAPsD86oUxBmXpvHotpYnj8TK066B/gkYf9ApN1T Q28ZaIaiU3xAYPwK5OOqsLuIDmohVWV/YZIYv+VIy3aKPUxeZ2hxqXS/MKyAtcdJoDhyjwgq/+ Big= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 46/55] Input: Atmel: improve error handling in mxt_initialize() Date: Tue, 31 Mar 2020 03:50:42 -0700 Message-ID: <20200331105051.58896-47-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Deepak Das Currently mxt_initialize() tries to probe bootloader mode even if valid bootloader address is not specified. This commit modifies mxt_initialize() to return error if Device is not in appmode and bootloader address is not specified. This commit also returns error code from mxt_send_bootloader_cmd() in mxt_initialize(). Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 58 +++++++++++++++++------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0f7ee987a9c5..258dcd8a68e5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -716,17 +716,13 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) return 0; } -static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) +static int mxt_probe_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; int error; u8 buf[3]; bool crc_failure, extended_id; - error = mxt_lookup_bootloader_address(data, alt_address); - if (error) - return error; - /* Check bootloader status and version information */ error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) @@ -2922,6 +2918,32 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) release_firmware(cfg); } +static int mxt_bootloader_status(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = mxt_lookup_bootloader_address(data, false); + if (error) { + dev_info(&client->dev, + "Bootloader address is not specified\n"); + return error; + } + /* Check bootloader state */ + error = mxt_probe_bootloader(data); + if (error) { + dev_info(&client->dev, "Trying alternate bootloader address\n"); + mxt_lookup_bootloader_address(data, true); + error = mxt_probe_bootloader(data); + if (error) { + dev_err(&client->dev, + "Chip is not in appmode or bootloader mode\n"); + return error; + } + } + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2933,16 +2955,13 @@ static int mxt_initialize(struct mxt_data *data) if (!error) break; - /* Check bootloader state */ - error = mxt_probe_bootloader(data, false); - if (error) { - dev_info(&client->dev, "Trying alternate bootloader address\n"); - error = mxt_probe_bootloader(data, true); - if (error) { - /* Chip is not in appmode or bootloader mode */ - return error; - } - } + dev_info(&client->dev, + "info block read failed (%d), so try bootloader method\n", + error); + + error = mxt_bootloader_status(data); + if (error) + return error; /* OK, we are in bootloader, see if we can recover */ if (++recovery_attempts > 1) { @@ -2956,7 +2975,9 @@ static int mxt_initialize(struct mxt_data *data) } /* Attempt to exit bootloader into app mode */ - mxt_send_bootloader_cmd(data, false); + error = mxt_send_bootloader_cmd(data, false); + if (error) + return error; msleep(MXT_FW_RESET_TIME); } @@ -3648,8 +3669,11 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); + ret = mxt_lookup_bootloader_address(data, false); + if (ret) + return ret; /* Do not need to scan since we know family ID */ - ret = mxt_probe_bootloader(data, 0); + ret = mxt_probe_bootloader(data); if (ret) return ret; From patchwork Tue Mar 31 10:50:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF009C43331 for ; Tue, 31 Mar 2020 10:53:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B643A208E0 for ; Tue, 31 Mar 2020 10:53:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730748AbgCaKx4 (ORCPT ); Tue, 31 Mar 2020 06:53:56 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730442AbgCaKxy (ORCPT ); Tue, 31 Mar 2020 06:53:54 -0400 IronPort-SDR: FI83d+LP6hQCVO7qeDjAtyqLRylOo0iZxrYFONzU18h1LGhmaQplFE3XNm37X1mpkJqvt5nli9 gS+CRKsiLu/0FMxDsednGFADXt8IrSjvha+8+sQ3a/olLvttgsqMdGOjC05TclxGuuNoqdFY61 IRzWk+PsvtQrZ1+z2Ft9qYeddI59LvtqIjevviIONGU4QY9vkJdi53yGvPnNzYJaaWWX9oRrhx y67agsZnn1PUqhIBzME8hQ6/Xf5+UhhGFTxu5e1blkc4KiJvsg1WmZMlE1vG4wEmClU25yHvy1 gwU= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330846" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:53:53 -0800 IronPort-SDR: 9nLGWcYtbMcKIIL9wJ8C5xMlioyufVD/KUUOGX5rjnF/YBam1WnLR76VJJxlVTMSzARajY1kqb 5uoPI7prUwh1IphNNqK/uFWD5u4MJv/VSyrNObWXmGeVjRl9ZHoneaJIW3vhfy5iMiOf3Ifjr4 Evk1leMshBBGptTupOi0j5GbCyYnjH9a63yVLsgAIOtPrymnE6omQDhcMMyjNnQ742yhg7JEFu Y7heyLgJatbMc05HedJ7RDpkxiYYbkKaxLvG2j3AO5ZoPNUyTxVxdiW1osCsELvT74YCqP+WTV f0k= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 47/55] Input: Atmel: improve error handling in mxt_update_cfg() Date: Tue, 31 Mar 2020 03:50:43 -0700 Message-ID: <20200331105051.58896-48-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Deepak Das mxt_update_cfg() failed to propagate the error code from mxt_init_t7_power_cfg() so return the error code. Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 258dcd8a68e5..069a532bd0b2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2185,7 +2185,9 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) dev_info(dev, "Config successfully updated\n"); /* T7 config may have changed */ - mxt_init_t7_power_cfg(data); + ret = mxt_init_t7_power_cfg(data); + if (ret) + dev_warn(dev, "Power Config failed to update\n"); release_mem: kfree(cfg.mem); From patchwork Tue Mar 31 10:50:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C79BC2D0EE for ; Tue, 31 Mar 2020 10:54:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CA5B2145D for ; Tue, 31 Mar 2020 10:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbgCaKyC (ORCPT ); Tue, 31 Mar 2020 06:54:02 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:43597 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731003AbgCaKyB (ORCPT ); Tue, 31 Mar 2020 06:54:01 -0400 IronPort-SDR: LfYK4xXidlKhgWxwGVYhbfep5kZnennVjBl3ds599EZUOJCCrf0fNItbyEuwmao4Xji0D0WbGg d/EBeIbaGDY75CmBOS9wsX0915GiCNSrOq/GTotjM0YYEcLvV4kadApp3S6HMjcnOQmMZ7u5m+ jlubRW1FFe4D7U2DT1WlPfN8dy0WNLINxUwqOv2mPrCVr6nr6uw46P64F2vujPkk0KfI5LCLxo GthR4+R/w/5BonaPdje5j1IaS4laxMWc+Ah8wl3Dpriv3XbRoQ0wnGlAeQoaH6wQGRv4XIek+y fqA= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47330849" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:54:01 -0800 IronPort-SDR: fIo6CUoCqI+lV6D2t1nx4/2oUiJ8JKYojbFpAkU+lPjYaFzWEUfG4ecyY4AaTi4ConJUNnCf7t EyAoC3oI1Pm7SrVVVQ7Nnxxv8OqakFjn49z9WRLznL1ivmjiBhteDyzYczlHGEr/5ZsqMjdFSV 2EWCvfca8XU3N05zQ1ND7GdaM0xsbZg+Tc5p6Gk/MeT8LYpI6L5Kn9Ez8COnKuWVFbcUDagf40 LiHMqpb/VbBbbyEbhNSvBYIIMtgIoqP9ZCfEsocQr9NvjvhQoV/6BKWB5eWxfa9+u0AyEvIItH iyI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 49/55] Input: Atmel: handle ReportID "0x00" while processing T5 messages Date: Tue, 31 Mar 2020 03:50:45 -0700 Message-ID: <20200331105051.58896-50-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Deepak Das ReportID "0x00" is reserved by Atmel and should not be used by any Atmel touch controller. reportID is the first byte retrieved from T5 message payload. Currently Atmel driver continues to process the T5 messages even if the reportID "0x00" is returned by Touch Controller. This commit modifies Atmel touch driver to return -EINVAL if ReportID "0x00" is received while processing T5 messages. Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ed357e958f07..496b1f67d9a5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -76,6 +76,7 @@ #define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 +#define MXT_RPTID_RESERVED 0 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -1381,6 +1382,11 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) u8 report_id = message[0]; bool dump = data->debug_enabled; + if (report_id == MXT_RPTID_RESERVED) { + dev_err(&data->client->dev, + "Received Reserved ReportID 0x00\n"); + return -EINVAL; + } if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1451,6 +1457,8 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) ret = mxt_proc_message(data, data->msg_buf + data->T5_msg_size * i); + if (ret < 0) + return ret; if (ret == 1) num_valid++; } From patchwork Tue Mar 31 10:50:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20A01C2D0F4 for ; Tue, 31 Mar 2020 10:54:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9CDD208E0 for ; Tue, 31 Mar 2020 10:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730343AbgCaKyH (ORCPT ); Tue, 31 Mar 2020 06:54:07 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:28112 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731022AbgCaKyG (ORCPT ); Tue, 31 Mar 2020 06:54:06 -0400 IronPort-SDR: 3QT/4FfFCJQ8fvWqjW4aI/ZwD37htnd3TJ5BNsacQxIoWMeVQ84L/MXD35apxcGDtpWOEinzF4 EaYIDDrINeZGgHksFKbQNt9ksHF+rQgCPXP1GaxsUl2+5PRufbPzdvto22ifP4IJJL72sWlXqY PLZ+jtGNMIFrVvg7yMmtKtbJClHBwGpGX83kMcglqQbZ4cZhgbxHqhrjNWqyH8X0MDj6NkI3eb SECHHzQ0xI5E7WX+329R+iP+lYE6si9xVUef/rGJe8RmOMoZq4ybSbeWGyQA/yQ9FlmBygB/M2 QOQ= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47293532" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:54:05 -0800 IronPort-SDR: v5yK/Hh79EleBojzpfueYy0HACQA3adMo0K5ZUQjf5sVHaTQUshYM26caZe8BbsSZBJ9EKmnZi ev8XX6Gtp8HZ/oEzL9cvRk2Hg5dkWxo4ZomUfOglz9NomTSXCKXGzalWoPwiZaNOQ9lrBL+ycL 5EDdVhM8GCVMqGnAiSX2UYU+w7/ASUN0eLS2HN8V/x5xwOS1acSMN46oQrKI6VDPef18toieJB phhXWiUqX776JB2kchOtgs8bZlRV2Z43nm00P9rIz9flVtuRv5z3tf65xkPIoPQtfWzzWKVGrB Nsg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 50/55] Input: Atmel: use T44 object to process T5 messages Date: Tue, 31 Mar 2020 03:50:46 -0700 Message-ID: <20200331105051.58896-51-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Deepak Das T44 object returns the count of valid T5 messages in the buffer. According to atmel, this count should be the main criteria to read the number of T5 messages. Following is the statement from atmel confirming the same :- "For the readout of messages we recommend to stop after the last message is read out from the buffer. One way to identify the amount of new messages is to read T44. The other way is to monitor the /CHG line which indicates independent of mode 0 or mode 1 if there are still data in the buffer. 0xFF indicates that there is no message pending anymore, but it is not recommended to use this as the main criteria to control the data transfer." This commit modifies the logic to readout the T5 messages on the basis of T44 object. Signed-off-by: Deepak Das Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 496b1f67d9a5..1cabe75df562 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1486,7 +1486,7 @@ static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) return min(T5_msg_count_limit, max_T5_msg_count); } -static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) +static int mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; @@ -1499,7 +1499,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->T5_msg_size + 1, data->msg_buf); if (ret) { dev_err(dev, "Failed to read T44 and T5 (%d)\n", ret); - return IRQ_NONE; + return ret; } T5_msg_count = data->msg_buf[0]; @@ -1509,7 +1509,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) * Mode 0. It results in unnecessary I2C operations but it is benign. */ if (!T5_msg_count) - return IRQ_NONE; + return processed_valid; if (T5_msg_count > data->max_reportid) { dev_warn(dev, "T44 count %d exceeded max report id\n", @@ -1521,12 +1521,14 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) ret = mxt_proc_message(data, data->msg_buf + 1); if (ret < 0) { dev_warn(dev, "Unexpected invalid message\n"); - return IRQ_NONE; + return ret; } total_pending = T5_msg_count - 1; - if (!total_pending) + if (!total_pending) { + processed_valid = 1; goto end; + } /* Process remaining messages if necessary */ T5_msg_count = mxt_max_msg_read_count(data, total_pending); @@ -1550,7 +1552,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return processed_valid; } static int mxt_process_messages_until_invalid(struct mxt_data *data) @@ -1580,7 +1582,7 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) return -EBUSY; } -static irqreturn_t mxt_process_messages(struct mxt_data *data) +static int mxt_process_messages(struct mxt_data *data) { int total_handled, num_handled; u8 count = data->last_message_count; @@ -1591,7 +1593,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) /* include final invalid message */ total_handled = mxt_read_and_process_messages(data, count + 1); if (total_handled < 0) - return IRQ_NONE; + return total_handled; /* if there were invalid messages, then we are done */ else if (total_handled <= count) goto update_count; @@ -1600,7 +1602,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) do { num_handled = mxt_read_and_process_messages(data, 2); if (num_handled < 0) - return IRQ_NONE; + return num_handled; total_handled += num_handled; @@ -1616,12 +1618,13 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return total_handled; } static irqreturn_t mxt_interrupt(int irq, void *dev_id) { struct mxt_data *data = dev_id; + int ret; if (data->in_bootloader) { complete(&data->chg_completion); @@ -1629,17 +1632,22 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->flash) cancel_delayed_work_sync(&data->flash->work); - return IRQ_RETVAL(mxt_check_bootloader(data)); + ret = mxt_check_bootloader(data); + return IRQ_RETVAL(ret); } if (!data->object_table) return IRQ_HANDLED; - if (data->T44_address) { - return mxt_process_messages_t44(data); - } else { - return mxt_process_messages(data); - } + if (data->T44_address) + ret = mxt_process_messages_t44(data); + else + ret = mxt_process_messages(data); + + if (ret <= 0) + return IRQ_NONE; + else + return IRQ_HANDLED; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -1776,8 +1784,11 @@ static int mxt_acquire_irq(struct mxt_data *data) } if (data->object_table && data->use_retrigen_workaround) { - error = mxt_process_messages_until_invalid(data); - if (error) + if (data->T44_address) + error = mxt_process_messages_t44(data); + else + error = mxt_process_messages_until_invalid(data); + if (error < 0) return error; } @@ -4039,8 +4050,12 @@ static int mxt_start(struct mxt_data *data) * Discard any touch messages still in message buffer * from before chip went to sleep */ - ret = mxt_process_messages_until_invalid(data); - if (ret) + + if (data->T44_address) + ret = mxt_process_messages_t44(data); + else + ret = mxt_process_messages_until_invalid(data); + if (ret < 0) break; ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); From patchwork Tue Mar 31 10:50:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F88C2D0E8 for ; Tue, 31 Mar 2020 10:54:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68BEB208E0 for ; Tue, 31 Mar 2020 10:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731032AbgCaKyO (ORCPT ); Tue, 31 Mar 2020 06:54:14 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:28112 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731003AbgCaKyN (ORCPT ); Tue, 31 Mar 2020 06:54:13 -0400 IronPort-SDR: fP+CHhHOtu0jj/MFMzpPHfyD4cEkO1lb6qnq9win5YBQ0VOa5GBzGRaIic2Knu7lZ7B+0cKbF1 1m6EigS7BmmRB7L9dvqGrK/bpRaPemxr9avwzIcY7Y+LLWdd+HWnh/WwHRwXEA3Rn40qF6qKX8 5M7+0oCJFVg3fZ3adrAaJR0+nhnqw1utgdtjXBld9g62EnLutzuXfllLd8CSJiZ32s3/39J6tn 5+Bn3VQ4lJt1u2ElA4/Xi4SZz6/5PaYOh41+9Crfu3c9ha8xAX4fJVtTu2THEWcesbF2vQMdw+ mHc= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47293538" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:54:13 -0800 IronPort-SDR: zhaGSYVqUzraej9GcJ0tN5iX/VqNOYz9ish0CJvGWGtm/OhkqanQN80KcsGeztP2SkvW8xruKp ramrbVuE/MEGSvZM/qAr5Cx5xslK5n1UIsIA156UyVVTDgwaXF7oZIKULuu8uz/nXjjese7fey 9L2B0OBptPSmKSOakvOwgGrgXGet/twdgaYVg/XaawA4KcXrBkjzQyFB9Ft6JdOzRxeRW9HF2y 0cmzLldLtNMeC6R4nCCPPelRTWVo3WqcocHN0KaHGmQfSXkUkJL2aGEKAGgERNq1gZeqtwf+mM VzI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 52/55] input: touchscreen: atmel_mxt_ts: Added sysfs entry for touchscreen status Date: Tue, 31 Mar 2020 03:50:48 -0700 Message-ID: <20200331105051.58896-53-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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: Naveen Chakka To know the current communication status of the touch controller during runtime, sysfs interface is added sysfs interface: /sys/class/i2c-dev/i2c-*/device/*/touch_dev_stat Executing the above sysfs interface provides two output values 1)Status of the touch device value 0 represents device is inactive value 1 represents device is active 2)Error counter value represents the number of times device in inactive since last read New module_param "debug_state" is introduced, by set its value, a watchdog work is scheduled to periodically check device state. default value is false. Signed-off-by: Naveen Chakka Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis [jiada: Rename mxt_touch_device_status to touch_dev_stat_show Replace DEVICE_ATTR to DEVICE_ATTR_RO] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 90 ++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 14bd64d194b0..dda10bb51cb3 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -222,6 +222,7 @@ enum t100_type { #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ #define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ +#define MXT_WATCHDOG_TIMEOUT 1000 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -245,6 +246,9 @@ enum t100_type { #define DEBUG_MSG_MAX 200 +#define MXT_DEBUG_STATE false +static bool debug_state = MXT_DEBUG_STATE; + struct mxt_info { u8 family_id; u8 variant_id; @@ -317,6 +321,12 @@ struct mxt_flash { struct delayed_work work; }; +struct mxt_statusinfo { + bool dev_status; + bool intp_triggered; + u32 error_count; +}; + /* Each client has this additional data */ struct mxt_data { struct i2c_client *client; @@ -372,6 +382,8 @@ struct mxt_data { const char *pcfg_name; const char *input_name; struct mxt_flash *flash; + struct delayed_work watchdog_work; + struct mxt_statusinfo mxt_status; /* Cached parameters from object table */ u16 T5_address; @@ -1626,6 +1638,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) struct mxt_data *data = dev_id; int ret; + data->mxt_status.intp_triggered = true; + if (data->in_bootloader) { complete(&data->chg_completion); @@ -1633,21 +1647,25 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) cancel_delayed_work_sync(&data->flash->work); ret = mxt_check_bootloader(data); - return IRQ_RETVAL(ret); + ret = IRQ_RETVAL(ret); + goto exit; } - if (!data->object_table) - return IRQ_HANDLED; + if (!data->object_table) { + ret = IRQ_HANDLED; + goto exit; + } if (data->T44_address) ret = mxt_process_messages_t44(data); else ret = mxt_process_messages(data); - if (ret <= 0) - return IRQ_NONE; - else - return IRQ_HANDLED; + ret = (ret <= 0) ? IRQ_NONE : IRQ_HANDLED; + +exit: + data->mxt_status.intp_triggered = false; + return ret; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -2969,6 +2987,31 @@ static int mxt_bootloader_status(struct mxt_data *data) return 0; } +static void mxt_watchdog_work(struct work_struct *work) +{ + struct mxt_data *data = + container_of(work, struct mxt_data, watchdog_work.work); + u16 info_buf; + int ret; + + if (data->suspended || data->in_bootloader || + data->mxt_status.intp_triggered) + goto sched_work; + + ret = __mxt_read_reg(data->client, 0, sizeof(info_buf), &info_buf); + + if (ret) { + data->mxt_status.error_count++; + data->mxt_status.dev_status = false; + } else { + data->mxt_status.dev_status = true; + } + +sched_work: + schedule_delayed_work(&data->watchdog_work, + msecs_to_jiffies(MXT_WATCHDOG_TIMEOUT)); +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -3956,6 +3999,22 @@ static const struct attribute_group mxt_fw_attr_group = { .attrs = mxt_fw_attrs, }; +static ssize_t touch_dev_stat_show(struct device *dev, struct + device_attribute * attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + int ret = 0; + + if (data->mxt_status.dev_status) + data->mxt_status.error_count = 0; + + ret = snprintf(buf, PAGE_SIZE, "%d %d\n", data->mxt_status.dev_status, + data->mxt_status.error_count); + /* clear the error counter once it is read */ + data->mxt_status.error_count = 0; + return ret; +} + static DEVICE_ATTR_RO(fw_version); static DEVICE_ATTR_RO(hw_version); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); @@ -3965,6 +4024,7 @@ static DEVICE_ATTR_RW(debug_enable); static DEVICE_ATTR_RW(debug_v2_enable); static DEVICE_ATTR_RO(debug_notify); static DEVICE_ATTR_RW(t25_selftest); +static DEVICE_ATTR_RO(touch_dev_stat); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3976,6 +4036,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, &dev_attr_t25_selftest.attr, + &dev_attr_touch_dev_stat.attr, NULL }; @@ -4329,6 +4390,12 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_TIME); } + if (debug_state) { + INIT_DELAYED_WORK(&data->watchdog_work, mxt_watchdog_work); + schedule_delayed_work(&data->watchdog_work, + msecs_to_jiffies(MXT_WATCHDOG_TIMEOUT)); + } + error = mxt_initialize(data); if (error) goto err_free_object; @@ -4343,6 +4410,8 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return 0; err_free_object: + if (debug_state) + cancel_delayed_work_sync(&data->watchdog_work); mxt_free_input_device(data); mxt_free_object_table(data); if (data->reset_gpio) { @@ -4367,6 +4436,9 @@ static int mxt_remove(struct i2c_client *client) mxt_free_input_device(data); mxt_free_object_table(data); + if (debug_state) + cancel_delayed_work_sync(&data->watchdog_work); + return 0; } @@ -4463,3 +4535,7 @@ module_i2c_driver(mxt_driver); MODULE_AUTHOR("Joonyoung Shim "); MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); MODULE_LICENSE("GPL"); + +module_param(debug_state, bool, 0); +MODULE_PARM_DESC(debug_state, "Enable/Disable watchdog work to check device state (default=" + __MODULE_STRING(MXT_DEBUG_STATE) ")"); From patchwork Tue Mar 31 10:50:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 207979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF481C2D0EE for ; Tue, 31 Mar 2020 10:54:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB2A420B1F for ; Tue, 31 Mar 2020 10:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731073AbgCaKyY (ORCPT ); Tue, 31 Mar 2020 06:54:24 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:28112 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731063AbgCaKyY (ORCPT ); Tue, 31 Mar 2020 06:54:24 -0400 IronPort-SDR: 3tyijdcCR69WBS1sFv8W8UnChHo4wjViFODb5czt4K4clU4kUboF7DVkb6yB+LjPk2IG7l2c1F rZHVqz4nXL2ZsZhujr9QBc/PAtSnSwBmFrIRePtoQ38sTCa2R61fZcsqGfCnfq8UDCsl17vbJv wlzBZejEkq+BcTkfdL+SGzR9b4DAP/GzSDWA4BhZ64MNbXh4TdFGRJQoi8oMPd4OBf1FzVgvnA MwKeHvcLXLzskSakUZnX2txKVTMnkTygjceOzHAOzp5qhy185sk7pYTqGQyGJ8wdUsijC6ueq0 f1I= X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="47293543" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 31 Mar 2020 02:54:24 -0800 IronPort-SDR: lvuXWb17PRMuN201wB7IVkmS/3GlGX8aYkGySmjGd9cJfnwdMuz89/DtSi2DiJcUUw/Y6GhYTu w7CJrBj/wA93M45V+UDKFYdtz4Piogxpynch878wc+iQXzGzLh56CnZmPeQREtYFsRuZo1Cy/Y MbOhGMy+nX0dGHwngz4nyURHpLUq79ObiNC1EcuhSRYGP2Dw1C1t0UvE6gNx8UwaWgv8qb4AK8 QjQPs0TnyxuTk1nBoqsS0x0F44dprBky5qLiQcNshl1pPWb3wxz93sTawLVaBvcpDlItt3/R5S 1OA= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v10 55/55] Input: atmel_mxt_ts - Fix compilation warning Date: Tue, 31 Mar 2020 03:50:51 -0700 Message-ID: <20200331105051.58896-56-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200331105051.58896-1-jiada_wang@mentor.com> References: <20200331105051.58896-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 fix "make W=1" compilation warnings from Atmel driver as per the compilation logs. Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d244d97d134e..b2edf51e1595 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2032,7 +2032,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg) byte_offset = reg + i - cfg->start_ofs; - if (byte_offset >= 0 && byte_offset < cfg->mem_size) { + if (byte_offset < cfg->mem_size) { *(cfg->mem + byte_offset) = val; } else { dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",