From patchwork Fri Nov 22 08:23:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8183114DB for ; Fri, 22 Nov 2019 08:24:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A16620672 for ; Fri, 22 Nov 2019 08:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726750AbfKVIYL (ORCPT ); Fri, 22 Nov 2019 03:24:11 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52454 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYL (ORCPT ); Fri, 22 Nov 2019 03:24:11 -0500 IronPort-SDR: mDom/vDF8mefVQ5V+t282Io1sSIR/B25oVCwaZdoWYJeyz+gBrFPjwIzy4ZAm3w8kk/bzrUfFo DfW0vBPfkj16mBToiJDqdv7J15cwtAx8D/694XwSYlwKbIDR0XRrTyVZHEy8e6LQA3h04Woghx TzWO6Od2R8phnal2kHPb6qwa2MQDxr1OJG311TiyYHZ4LS1JlZYhy5Xfdx3Sw59i3AYQXz7rIE TWZhicodpRYQ9qkJz7iry3oTrFhVDJXUSoxwA3N15ifHxbEpbUFdcFt0sCGxx8H7Rv64GYz+/X sP4= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358880" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:10 -0800 IronPort-SDR: v8nQFh7VJJc+SOVaGqs/SHX7M2yYWkQPs53AhEDg/Hn32SxW8UI/t11NMq9EzKNg9AYbJtVajN mNQL6R8ZKKzlqVG1lsiXjyiis9uN3bgKC6JwQINLNsG+d6C2neCjSAIe0GFMIrXWbtp1Y9phvi gW+RU5d4RKTR5eSQY0YYT/SYp6ttlWibUASRM367O469eKE+hhdyLaFlMjQAS4wuGVBx24DcRF 5zN89+9+Q/GWGpw6t+wAp0YGbIp3ZOsnWrxPxNu8NLrPrpwS4or2trLAUr84irIElO2RLf9tx8 +ts= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 01/48] Input: introduce input_mt_report_slot_inactive Date: Fri, 22 Nov 2019 17:23:15 +0900 Message-ID: <20191122082402.18173-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 input_mt_report_slot_state() ignores the tool when the slot is closed. which has caused a bit of confusion. This patch introduces input_mt_report_slot_inactive() to report slot inactive state. replaces all input_mt_report_slot_state() with input_mt_report_slot_inactive() in case of close of slot. Suggested-by: Dmitry Torokhov Reported-by: kernel test robot Signed-off-by: Jiada Wang --- drivers/hid/hid-alps.c | 3 +-- drivers/hid/hid-multitouch.c | 6 ++---- drivers/input/misc/xen-kbdfront.c | 2 +- drivers/input/mouse/elan_i2c_core.c | 2 +- drivers/input/touchscreen/atmel_mxt_ts.c | 7 +++---- drivers/input/touchscreen/cyttsp4_core.c | 5 ++--- drivers/input/touchscreen/cyttsp_core.c | 2 +- drivers/input/touchscreen/melfas_mip4.c | 4 ++-- drivers/input/touchscreen/mms114.c | 2 +- drivers/input/touchscreen/raspberrypi-ts.c | 2 +- drivers/input/touchscreen/stmfts.c | 2 +- include/linux/input/mt.h | 5 +++++ 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index ae79a7c66737..36ca1d815d53 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c @@ -387,8 +387,7 @@ static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size) input_report_abs(hdata->input, ABS_MT_PRESSURE, z); } else { - input_mt_report_slot_state(hdata->input, - MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(hdata->input); } } diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3cfeb1629f79..15e6c04a76dd 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -896,7 +896,7 @@ static void mt_release_pending_palms(struct mt_device *td, clear_bit(slotnum, app->pending_palm_slots); input_mt_slot(input, slotnum); - input_mt_report_slot_state(input, MT_TOOL_PALM, false); + input_mt_report_slot_inactive(input); need_sync = true; } @@ -1640,9 +1640,7 @@ static void mt_release_contacts(struct hid_device *hid) if (mt) { for (i = 0; i < mt->num_slots; i++) { input_mt_slot(input_dev, i); - input_mt_report_slot_state(input_dev, - MT_TOOL_FINGER, - false); + input_mt_report_slot_inactive(input_dev); } input_mt_sync_frame(input_dev); input_sync(input_dev); diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c index 24bc5c5d876f..a1bba722b234 100644 --- a/drivers/input/misc/xen-kbdfront.c +++ b/drivers/input/misc/xen-kbdfront.c @@ -146,7 +146,7 @@ static void xenkbd_handle_mt_event(struct xenkbd_info *info, break; case XENKBD_MT_EV_UP: - input_mt_report_slot_state(info->mtouch, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(info->mtouch); break; case XENKBD_MT_EV_SYN: diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c index 8719da540383..3f9354baac4b 100644 --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c @@ -938,7 +938,7 @@ static void elan_report_contact(struct elan_tp_data *data, input_report_abs(input, ABS_MT_TOUCH_MINOR, minor); } else { input_mt_slot(input, contact_num); - input_mt_report_slot_state(input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input); } } diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 24c4b691b1c9..6e758af343ea 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -822,8 +822,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) * have happened. */ if (status & MXT_T9_RELEASE) { - input_mt_report_slot_state(input_dev, - MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input_dev); mxt_input_sync(data); } @@ -839,7 +838,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); } else { /* Touch no longer active, close out slot */ - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input_dev); } data->update_input = true; @@ -947,7 +946,7 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) dev_dbg(dev, "[%u] release\n", id); /* close out slot */ - input_mt_report_slot_state(input_dev, 0, 0); + input_mt_report_slot_inactive(input_dev); } data->update_input = true; diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c index 4b22d49a0f49..a3a85e2348a2 100644 --- a/drivers/input/touchscreen/cyttsp4_core.c +++ b/drivers/input/touchscreen/cyttsp4_core.c @@ -744,8 +744,7 @@ static void cyttsp4_report_slot_liftoff(struct cyttsp4_mt_data *md, for (t = 0; t < max_slots; t++) { input_mt_slot(md->input, t); - input_mt_report_slot_state(md->input, - MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(md->input); } } @@ -845,7 +844,7 @@ static void cyttsp4_final_sync(struct input_dev *input, int max_slots, int *ids) if (ids[t]) continue; input_mt_slot(input, t); - input_mt_report_slot_state(input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input); } input_sync(input); diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c index 3f5d463dbeed..697aa2c158f7 100644 --- a/drivers/input/touchscreen/cyttsp_core.c +++ b/drivers/input/touchscreen/cyttsp_core.c @@ -340,7 +340,7 @@ static void cyttsp_report_tchdata(struct cyttsp *ts) continue; input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input); } input_sync(input); diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c index 247c3aaba2d8..f67efdd040b2 100644 --- a/drivers/input/touchscreen/melfas_mip4.c +++ b/drivers/input/touchscreen/melfas_mip4.c @@ -391,7 +391,7 @@ static void mip4_clear_input(struct mip4_ts *ts) /* Screen */ for (i = 0; i < MIP4_MAX_FINGERS; i++) { input_mt_slot(ts->input, i); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(ts->input); } /* Keys */ @@ -534,7 +534,7 @@ static void mip4_report_touch(struct mip4_ts *ts, u8 *packet) } else { /* Release event */ input_mt_slot(ts->input, id); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(ts->input); } input_mt_sync_frame(ts->input); diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index a5ab774da4cc..8112bd77afae 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -550,7 +550,7 @@ static int __maybe_unused mms114_suspend(struct device *dev) /* Release all touch */ for (id = 0; id < MMS114_MAX_TOUCH; id++) { input_mt_slot(input_dev, id); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input_dev); } input_mt_report_pointer_emulation(input_dev, true); diff --git a/drivers/input/touchscreen/raspberrypi-ts.c b/drivers/input/touchscreen/raspberrypi-ts.c index 69881265d121..147ea4f8f87b 100644 --- a/drivers/input/touchscreen/raspberrypi-ts.c +++ b/drivers/input/touchscreen/raspberrypi-ts.c @@ -102,7 +102,7 @@ static void rpi_ts_poll(struct input_polled_dev *dev) released_ids = ts->known_ids & ~modified_ids; for_each_set_bit(i, &released_ids, RPI_TS_MAX_SUPPORTED_POINTS) { input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input); modified_ids &= ~(BIT(i)); } ts->known_ids = modified_ids; diff --git a/drivers/input/touchscreen/stmfts.c b/drivers/input/touchscreen/stmfts.c index b6f95f20f924..b54cc64e4ea6 100644 --- a/drivers/input/touchscreen/stmfts.c +++ b/drivers/input/touchscreen/stmfts.c @@ -198,7 +198,7 @@ static void stmfts_report_contact_release(struct stmfts_data *sdata, u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4; input_mt_slot(sdata->input, slot_id); - input_mt_report_slot_state(sdata->input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(sdata->input); input_sync(sdata->input); } diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h index 9e409bb13642..3b8580bd33c1 100644 --- a/include/linux/input/mt.h +++ b/include/linux/input/mt.h @@ -100,6 +100,11 @@ static inline bool input_is_mt_axis(int axis) bool input_mt_report_slot_state(struct input_dev *dev, unsigned int tool_type, bool active); +static inline void input_mt_report_slot_inactive(struct input_dev *dev) +{ + input_mt_report_slot_state(dev, 0, false); +} + void input_mt_report_finger_count(struct input_dev *dev, int count); void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count); void input_mt_drop_unused(struct input_dev *dev); From patchwork Fri Nov 22 08:23:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A605C14DB for ; Fri, 22 Nov 2019 08:24:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8626420672 for ; Fri, 22 Nov 2019 08:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbfKVIYY (ORCPT ); Fri, 22 Nov 2019 03:24:24 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60514 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYX (ORCPT ); Fri, 22 Nov 2019 03:24:23 -0500 IronPort-SDR: FGnyb6Lp5OvJwp+osvKOpEuR/AyqWiS6oT4m0rrRoKc9MvwGIe8XkTXSfpKmlzacdnIdoN46CZ VmuXEiWb0QuT7d5NfzCpyBEl5fpmOnctFObDXFcKiRXh42AqVOL6SJTvlZjvCsvev6YhXE3X33 y2uESeXnirpmhg/2cDDz2GiqS+2uAu2l3FnMGt1qnIgkus+K/ZuJurc6zqfnoN4U1eHCkTLBvW 7axRJDLlpS75XOgGRzjeqUmXXxqYAdjavfB6gHExCOB5AEIgxCD/LLiz4/n4L9rNmGSUjVqNKk eDs= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291094" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:13 -0800 IronPort-SDR: C3IfEUvY298/qipBdKiy3UCbbacTOf9HA5yUlE8UT8TnSfRaMJ3Da68IIPbzY3sHROgIBrjvMy 5qGYQGwsPBcaty00+milmYoYTRbqTbrtbScaszgf8fAXpvzTdn6+mqvAba8FNII40OplJBLBA4 PZTuE4HY78UsMNi/r/YGCkstszmA/hUlmsmR3HuyS7rKoGr94oNFcoapXxGaVwl26pIoKUJYMZ NMJY/RlI5ZAnFByX649egjb/duirt8lR+9Z+1mcr3DIGWwu1jNNk2p/1r9QH2/p2Bdnr7KCZbW tC0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 02/48] Input: atmel_mxt_ts - rework sysfs init/remove Date: Fri, 22 Nov 2019 17:23:16 +0900 Message-ID: <20191122082402.18173-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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] 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 6e758af343ea..ffe8a80f4d0a 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, S_IWUSR, 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 Fri Nov 22 08:23:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D32C14C0 for ; Fri, 22 Nov 2019 08:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EE6A20714 for ; Fri, 22 Nov 2019 08:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbfKVIYS (ORCPT ); Fri, 22 Nov 2019 03:24:18 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52461 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYS (ORCPT ); Fri, 22 Nov 2019 03:24:18 -0500 IronPort-SDR: ffk80AX5qNTu76qq1DwjKBDA8G1NJs7tE581Y2F2oX9JXpgEIyZUca8M/VQdkqZtpH0OL5JQup mKsl70Cniv7WY5lFYFGcIUw51MeB/WYjQMrEkDToekkjWyH+TDaIPgf4XRtCa7yZNVrwVywoNu rc8aiwRqjmo56WSOFlDlDWLl4v2Qjz4bNQEPE+XCdk7MH/MKn/IKFVumWAIVNNZesMsXeVQS+8 /T1bQDrU/mM+hln3TPcfiq9eOBR8bJ94ddTSwFtw26d4GPiIgR/6lpIlXhLYdVedmL0z+BWcZX QpE= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358886" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:17 -0800 IronPort-SDR: mBWLPye+yE7F4JJ5/wifG0vsFEaxac2qQ06vNw+XCA2pXOIQWhi8jb3R3rLsqLjfNKV5pa+vxM yupjmC8tr9L64wQ54fhKSYwKUcRERQZt6mVarsodNri2zhr5ke7LmJX9txU24dvXh//zmuaK9k a0xQJuL3aN+CJo4ZrCLip5TV4mN4lO+PTJ62PfiOAzNbNidmquiipifE/WGRHa8kB06PucdNhZ 3lv5JDVUNuggAJ/HEqVRERsHT+xHbQiXS5A8vf47YnFoB5BI0awdYS48bvGazrEHwrDsEsMeZG 27w= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 03/48] Input: atmel_mxt_ts - only read messages in mxt_acquire_irq() when necessary Date: Fri, 22 Nov 2019 17:23:17 +0900 Message-ID: <20191122082402.18173-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 workaround of reading all messages until an invalid is received is a way of forcing the CHG line high, which means that when using edge-triggered interrupts the interrupt can be acquired. With level-triggered interrupts the workaround is unnecessary. Also, most recent maXTouch chips have a feature called RETRIGEN which, when enabled, reasserts the interrupt line every cycle if there are messages waiting. This also makes the workaround unnecessary. Note: the RETRIGEN feature is only in some firmware versions/chips, it's not valid simply to enable the bit. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 1ae4e8281e491b22442cd5acdfca1862555f8ecb) [gdavis: Fix conflicts due to v4.6-rc7 commit eb43335c4095 ("Input: atmel_mxt_ts - use mxt_acquire_irq in mxt_soft_reset").] Signed-off-by: George G. Davis [jiada: reset use_retrigen_workaround at beginning of mxt_check_retrigen()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 51 ++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ffe8a80f4d0a..ce5a069b62d4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ struct t9_range { /* MXT_SPT_COMMSCONFIG_T18 */ #define MXT_COMMS_CTRL 0 #define MXT_COMMS_CMD 1 +#define MXT_COMMS_RETRIGEN BIT(6) /* MXT_DEBUG_DIAGNOSTIC_T37 */ #define MXT_DIAGNOSTIC_PAGEUP 0x01 @@ -308,6 +310,7 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; + bool use_retrigen_workaround; /* Cached parameters from object table */ u16 T5_address; @@ -318,6 +321,7 @@ struct mxt_data { u16 T71_address; u8 T9_reportid_min; u8 T9_reportid_max; + u16 T18_address; u8 T19_reportid; u16 T44_address; u8 T100_reportid_min; @@ -1190,9 +1194,11 @@ static int mxt_acquire_irq(struct mxt_data *data) enable_irq(data->irq); - error = mxt_process_messages_until_invalid(data); - if (error) - return error; + if (data->use_retrigen_workaround) { + error = mxt_process_messages_until_invalid(data); + if (error) + return error; + } return 0; } @@ -1282,6 +1288,33 @@ static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off) return crc; } +static int mxt_check_retrigen(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + int val; + + data->use_retrigen_workaround = false; + + if (irq_get_trigger_type(data->irq) & IRQF_TRIGGER_LOW) + return 0; + + if (data->T18_address) { + error = __mxt_read_reg(client, + data->T18_address + MXT_COMMS_CTRL, + 1, &val); + if (error) + return error; + + if (val & MXT_COMMS_RETRIGEN) + return 0; + } + + dev_warn(&client->dev, "Enabling RETRIGEN workaround\n"); + data->use_retrigen_workaround = true; + return 0; +} + static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg) { struct device *dev = &data->client->dev; @@ -1561,6 +1594,10 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); + ret = mxt_check_retrigen(data); + if (ret) + goto release_mem; + ret = mxt_soft_reset(data); if (ret) goto release_mem; @@ -1604,6 +1641,7 @@ static void mxt_free_object_table(struct mxt_data *data) data->T71_address = 0; data->T9_reportid_min = 0; data->T9_reportid_max = 0; + data->T18_address = 0; data->T19_reportid = 0; data->T44_address = 0; data->T100_reportid_min = 0; @@ -1678,6 +1716,9 @@ static int mxt_parse_object_table(struct mxt_data *data, object->num_report_ids - 1; data->num_touchids = object->num_report_ids; break; + case MXT_SPT_COMMSCONFIG_T18: + data->T18_address = object->start_address; + break; case MXT_SPT_MESSAGECOUNT_T44: data->T44_address = object->start_address; break; @@ -2141,6 +2182,10 @@ static int mxt_initialize(struct mxt_data *data) msleep(MXT_FW_RESET_TIME); } + error = mxt_check_retrigen(data); + if (error) + return error; + error = mxt_acquire_irq(data); if (error) return error; From patchwork Fri Nov 22 08:23:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2761214C0 for ; Fri, 22 Nov 2019 08:24:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 120EA20672 for ; Fri, 22 Nov 2019 08:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbfKVIYV (ORCPT ); Fri, 22 Nov 2019 03:24:21 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52461 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYV (ORCPT ); Fri, 22 Nov 2019 03:24:21 -0500 IronPort-SDR: SQIhX7JwH4BYZjXXm7jWcs47L8Lw6AKPwOcA3bL6bkSKxZOuRFSCGQZg5QbnsFYXWi/JLe5NtY UPoSvHvKIRKEa9Wu8Fof98yMAlG+7NiGIaAUHsxjT+DEoZSdyIDFbNI4wz5SfY/2T01e3VlPRZ MiyHHNh6R/3S56zdCFZWMIaAKInjFOYYDMdAiC7gVq3uywK5C1EDmo9aCmLq6rKnbLb5dyENFs YhdAszRSqCtBWnxn+0IpPfmvnvB1WABlp21Z5x6Ux/OUOooq2xrCZgocF/0y+bez/S48boWCxk ZNw= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358888" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:20 -0800 IronPort-SDR: XvyKyFn8UpO2pWmvMLeYvVcQbQH0VhQMgrbDOsMCblPh9PtRjvRO/mFSlBFZO0hdWa0qVZ7zwD vaA9Pwxu2c0M0IzVyPLkeIYvTrb5fWXTYSSNuIsT/qSi7TrCjT6f9OB+uUOO1wIaUL6kbzDZyw yoEDrxpQqZBZ0nPnxOH09H2WNFnzbCCyNYMg4aYt7llQ4Ab3qCFIFrltGwkeN/ajNOUjqVE17d exlc5RPufavfYq60N9nbBhasPIspyvE8t5oWSzIcSfKIvh7QaStgdazT+foqGJmHkGhW9MG4gl 0zI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 04/48] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Fri, 22 Nov 2019 17:23:18 +0900 Message-ID: <20191122082402.18173-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 ce5a069b62d4..9088b2d3266b 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 Fri Nov 22 08:23:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257383 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0455B14C0 for ; Fri, 22 Nov 2019 08:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2B4120672 for ; Fri, 22 Nov 2019 08:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbfKVIY1 (ORCPT ); Fri, 22 Nov 2019 03:24:27 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52461 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbfKVIYY (ORCPT ); Fri, 22 Nov 2019 03:24:24 -0500 IronPort-SDR: ewDxBn7sC45V0HzpCQoh7CeQW+cmbnBrOPikYepscSHphyelcghCvauDv5JHXOwhmXlrA6rS2a FsZ5jD5PF3VvJu4FFUa4Cbp6QYqoXUsaPVvkyWh17VNHPaLt4KXZu5Itb1k7H5sqa814dt1E00 N41rCPJQWXBHimB97uo70OftC/sBQaB+JRAxmpcfoVeyIUZk/IydgIsug5CgJslvGX/y44vvQQ 5npqm1XB0HW0dIHa28pw3zTeoW3l7E++WKj5iv9c052h38GxJ8fdZ/LasF5E4vU5vicuiCV2j5 +oQ= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358897" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:24 -0800 IronPort-SDR: MrR4zNjtpf45UUZ275EPPwhlhjrWVr6lRivcHlinQUmyym7E5Tr2GvnhPLcQSDCkatvTKoCq0m tXK38pE/4Eyam/bU/fJB6zk3k69aEQjw9ldpWlKVPtRH1kxuVXEm+LDY14F3kkBFsqBrssEr8d 7bO/8OragAiTVuD8iGT3jMw4xox+G5+a0VLALiWJIYVh5tj/sxhzWTfK4+AkXuLyaa78YF/Zuu esngP0v+lJYe70alknXdDv5jPDt2mHX/HDypunZ9QM7JHRdT1AX/b3dtEsjnkOuICDeiE70G3z XuA= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 05/48] Input: atmel_mxt_ts - output status from T48 Noise Supression Date: Fri, 22 Nov 2019 17:23:19 +0900 Message-ID: <20191122082402.18173-6-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 2895a6ff150a49f27a02938f8d262be238b296d8) Signed-off-by: George G. Davis 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 9088b2d3266b..41a69ec5395a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -324,6 +324,7 @@ struct mxt_data { u16 T18_address; u8 T19_reportid; u16 T44_address; + u8 T48_reportid; u8 T100_reportid_min; u8 T100_reportid_max; @@ -978,6 +979,24 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) data->update_input = true; } +static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status, state; + + status = msg[1]; + state = msg[4]; + + dev_dbg(dev, "T48 state %d status %02X %s%s%s%s%s\n", state, status, + status & 0x01 ? "FREQCHG " : "", + status & 0x02 ? "APXCHG " : "", + status & 0x04 ? "ALGOERR " : "", + status & 0x10 ? "STATCHG " : "", + status & 0x20 ? "NLVLCHG " : ""); + + return 0; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -987,6 +1006,8 @@ 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->T48_reportid) { + mxt_proc_t48_messages(data, message); } else if (!data->input_dev) { /* * Do not report events if input device @@ -1666,6 +1687,7 @@ static void mxt_free_object_table(struct mxt_data *data) data->T18_address = 0; data->T19_reportid = 0; data->T44_address = 0; + data->T48_reportid = 0; data->T100_reportid_min = 0; data->T100_reportid_max = 0; data->max_reportid = 0; @@ -1747,6 +1769,9 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_GPIOPWM_T19: data->T19_reportid = min_id; break; + case MXT_PROCG_NOISESUPPRESSION_T48: + data->T48_reportid = min_id; + break; case MXT_TOUCH_MULTITOUCHSCREEN_T100: data->multitouch = MXT_TOUCH_MULTITOUCHSCREEN_T100; data->T100_reportid_min = min_id; From patchwork Fri Nov 22 08:23:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257381 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33E1A14DB for ; Fri, 22 Nov 2019 08:24:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F00520672 for ; Fri, 22 Nov 2019 08:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbfKVIY2 (ORCPT ); Fri, 22 Nov 2019 03:24:28 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60514 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIY2 (ORCPT ); Fri, 22 Nov 2019 03:24:28 -0500 IronPort-SDR: f/zvAiMNPdrbEIrNnuV+n16RGHl1KskTGwMS5LwqoCot4Qk/d1UUzkJbEBfrp+JEql5K/htiLz apXxH3YNCnf67ykuUcHJ3fItchftoFZUSPBMab6gyNyDBggiGBH9YUk7LyMZMkbVrs96r2inn0 iSxU36Y/oLnW58SI8g6M51NnD1clT5H0IgfEKh7SK73BOwO+nXsKw2dxGUkKU6LtAF3/Ltpn7n nEdOM/Tcxn6O0droG5RStFz58x0IzYN7O4MO5h5ljl66h4iAvH9Q7zJxO0Ae2+39UaXRr/+1p/ edw= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291099" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:27 -0800 IronPort-SDR: UMcX7DOwHQvj9kqsStS02FNKagkUBdw7iq9bIOgIqUIQqEZlAryXXNeLz5AbFMy16gulDDApxD FUthyIhfQAdsgVUUmQs2lQC8kUSPuVR3IUa8URoaNAJ/C/vi4wUkcYY/y9PS92KTJxQut/qazK ZLFNDDFHabAIGBALnIxcbAxYCwXvypl//zc17qRIIN8cSriVTpXDliYy7DMfd7Fej4Skd3stG3 8S+XuA0/SZu37gEYX+W/LEstas7F1z874KX2rfmlrxfJSwLofjVzsr0ywvfp39LVqzHbzc5sGE sfc= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 06/48] Input: atmel_mxt_ts - output status from T42 Touch Suppression Date: Fri, 22 Nov 2019 17:23:20 +0900 Message-ID: <20191122082402.18173-7-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 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 41a69ec5395a..4e0dae004927 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 Fri Nov 22 08:23:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7FEC814DB for ; Fri, 22 Nov 2019 08:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6911B20717 for ; Fri, 22 Nov 2019 08:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbfKVIYd (ORCPT ); Fri, 22 Nov 2019 03:24:33 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:4441 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYc (ORCPT ); Fri, 22 Nov 2019 03:24:32 -0500 IronPort-SDR: N3d2Shrk4a6LmmTXE1e0dPTscKY53vIJzr9Z5g8HhTtyXNn59SSCeZDnnKLjEeZJUULYAc+Szb Jpmi/FHluN6A5oYl+Ut7zfrvP2kvx2RP9WrKjRM36laU6F4+qDXFDx8fQVzxTTPMfCFx+OJcaF v9RVi77bVTQ/Nr6PEvMD5mTMN/b0TaKC1SKQ5TILV6WnlayYFIfvLGNfRTgRflt1McIqbiZjMZ 96+F331rk+ON9SctbDg+gT3NtbtW6eI0c1eLl5fH/4R37ujlog0It1XXUni5JV1J1MZrr96T3j OhY= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457552" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:31 -0800 IronPort-SDR: ciqpEjF+8XXJDD870VAR6w1P4xHnifR06m8TY8j6xqLwgrsjXq4eYMdkrqXjGV+vFV78xLfRdh cgXeDGh8u6c37V5/wtD2Xti3UNLQIa773uk8tOZVvD69bUYSgu+2oGECBv82CiTEEatp3AIscD dLho/ZMHI39cfjBLoeLL8yOgmm6rns9Mqn5ShU5umPWsgRe2fTPIgf8h+T+rThyAUm382bpWtP hlzfLgdc9kpVroXs84UIDsYaA1/neX8yGDjfkfIpfx1AD7m+53HOtRdI68rf05t4kYeXFZdHS8 ZFM= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 07/48] Input: atmel_mxt_ts - implement T9 vector/orientation support Date: Fri, 22 Nov 2019 17:23:21 +0900 Message-ID: <20191122082402.18173-8-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 atmel touch messages contain orientation information as a byte in a packed format which can be passed straight on to Android if the input device configuration is correct. This requires vector reports to be enabled in maXTouch config (zero DISVECT bit 3 in T9 CTRL field) Android converts the format in InputReader.cpp, search for ORIENTATION_CALIBRATION_VECTOR. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit a6f0ee919d2631678169b23fb18f55b6dbabcd4c) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 4e0dae004927..405bff1c2055 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -817,6 +817,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) int y; int area; int amplitude; + u8 vector; id = message[0] - data->T9_reportid_min; status = message[1]; @@ -831,9 +832,10 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) area = message[5]; amplitude = message[6]; + vector = message[7]; dev_dbg(dev, - "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n", + "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u vector: %02X\n", id, (status & MXT_T9_DETECT) ? 'D' : '.', (status & MXT_T9_PRESS) ? 'P' : '.', @@ -843,7 +845,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) (status & MXT_T9_AMP) ? 'A' : '.', (status & MXT_T9_SUPPRESS) ? 'S' : '.', (status & MXT_T9_UNGRIP) ? 'U' : '.', - x, y, area, amplitude); + x, y, area, amplitude, vector); input_mt_slot(input_dev, id); @@ -868,6 +870,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_POSITION_Y, y); input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); + input_report_abs(input_dev, ABS_MT_ORIENTATION, vector); } else { /* Touch no longer active, close out slot */ input_mt_report_slot_inactive(input_dev); @@ -2180,8 +2183,9 @@ static int mxt_initialize_input_device(struct mxt_data *data) 0, 255, 0, 0); } - if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && - data->t100_aux_vect) { + if (data->multitouch == MXT_TOUCH_MULTI_T9 || + (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && + data->t100_aux_vect)) { input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 255, 0, 0); } From patchwork Fri Nov 22 08:23:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0ED6714ED for ; Fri, 22 Nov 2019 08:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4F5A20714 for ; Fri, 22 Nov 2019 08:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727158AbfKVIYg (ORCPT ); Fri, 22 Nov 2019 03:24:36 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:4441 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYf (ORCPT ); Fri, 22 Nov 2019 03:24:35 -0500 IronPort-SDR: tdpnniA2kz07zUJnoAD6QhKwO8mRKQx2BlJdK884m8PqiptUriJ1N5sOQiObmetbvCwYRiUUHL Pny+RNcp5GYyMx1ftNXMQ/nKjfCv3bxb+JKDZrb9xNGDKmObXvePxpZBtYxM7nUqZuj8Ano5dl /ULF/nsduCjmQp8SOsRzD9ZdIwCTxPGzBgzh56ZtOa8UqqTIC5O2CxaRo8SuiI/SZd04xZtBPn UX9MbW0N+xdX2yuEQLkqUjEONlXB9ZM5AyJ9I4YO0ibdVsCI0zUsKG28/ZwpZwk682IZQjcJHr uo8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457556" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:34 -0800 IronPort-SDR: tDcnMsOUugxqnaL7O+C8fZ0Yxmcp85JaaB0dbbiStgpff87Lwiu/QuOaUlTP08dwbCOWImWh4v LBTc2tLuFu5LlBrHntRYXE11LcViFP04YTx64yLCOdD7S2vBSlUpeN8DNb9AcGMfVQ3AG/pptz YQ4rcfINWK1Lh1nc4GxZNBJPVxzQJRMJUa6pQghe6ugBshnQwmvpyAPFx5CeWY2of1Hq0G0mRk DaOUK/3HvsUih6JSpEeF4w7KpvIbz3iIg36m2/JsgjPqxqOpA1We/Szh1sNGWM4fO7+Z9gnuoZ hYA= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 08/48] Input: atmel_mxt_ts - implement T15 Key Array support Date: Fri, 22 Nov 2019 17:23:22 +0900 Message-ID: <20191122082402.18173-9-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 There is a key array object in many maXTouch chips which allows some X/Y lines to be used as a key array. This patch maps them to a series of keys which may be configured in a platform data array. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 15bb074b5abf3a101f7b79544213f1c110ea4cab) [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] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 405bff1c2055..2df3104e94b9 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -314,6 +314,9 @@ struct mxt_data { 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; /* Cached parameters from object table */ u16 T5_address; @@ -324,6 +327,8 @@ struct mxt_data { u16 T71_address; u8 T9_reportid_min; u8 T9_reportid_max; + u8 T15_reportid_min; + u8 T15_reportid_max; u16 T18_address; u8 T19_reportid; u8 T42_reportid_min; @@ -987,6 +992,38 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) data->update_input = true; } +static void mxt_proc_t15_messages(struct mxt_data *data, u8 *msg) +{ + struct input_dev *input_dev = data->input_dev; + struct device *dev = &data->client->dev; + int key; + bool curr_state, new_state; + bool sync = false; + unsigned long keystates = le32_to_cpu((__force __le32)msg[2]); + + for (key = 0; key < data->t15_num_keys; key++) { + curr_state = test_bit(key, &data->t15_keystatus); + new_state = test_bit(key, &keystates); + + if (!curr_state && new_state) { + dev_dbg(dev, "T15 key press: %u\n", key); + __set_bit(key, &data->t15_keystatus); + input_event(input_dev, EV_KEY, + data->t15_keymap[key], 1); + sync = true; + } else if (curr_state && !new_state) { + dev_dbg(dev, "T15 key release: %u\n", key); + __clear_bit(key, &data->t15_keystatus); + input_event(input_dev, EV_KEY, + data->t15_keymap[key], 0); + sync = true; + } + } + + if (sync) + input_sync(input_dev); +} + static void mxt_proc_t42_messages(struct mxt_data *data, u8 *msg) { struct device *dev = &data->client->dev; @@ -1045,6 +1082,9 @@ 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->T15_reportid_min + && report_id <= data->T15_reportid_max) { + mxt_proc_t15_messages(data, message); } else { mxt_dump_message(data, message); } @@ -1706,6 +1746,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T71_address = 0; data->T9_reportid_min = 0; data->T9_reportid_max = 0; + data->T15_reportid_min = 0; + data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; data->T42_reportid_min = 0; @@ -1784,6 +1826,10 @@ static int mxt_parse_object_table(struct mxt_data *data, object->num_report_ids - 1; data->num_touchids = object->num_report_ids; break; + case MXT_TOUCH_KEYARRAY_T15: + data->T15_reportid_min = min_id; + data->T15_reportid_max = max_id; + break; case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; @@ -2077,6 +2123,7 @@ static int mxt_initialize_input_device(struct mxt_data *data) int error; unsigned int num_mt_slots; unsigned int mt_flags = 0; + int i; switch (data->multitouch) { case MXT_TOUCH_MULTI_T9: @@ -2190,6 +2237,15 @@ static int mxt_initialize_input_device(struct mxt_data *data) 0, 255, 0, 0); } + /* For T15 Key Array */ + if (data->T15_reportid_min) { + data->t15_keystatus = 0; + + for (i = 0; i < data->t15_num_keys; i++) + input_set_capability(input_dev, EV_KEY, + data->t15_keymap[i]); + } + input_set_drvdata(input_dev, data); error = input_register_device(input_dev); @@ -3148,8 +3204,10 @@ static void mxt_input_close(struct input_dev *dev) static int mxt_parse_device_properties(struct mxt_data *data) { static const char keymap_property[] = "linux,gpio-keymap"; + static const char buttons_property[] = "atmel,key-buttons"; struct device *dev = &data->client->dev; u32 *keymap; + u32 *buttonmap; int n_keys; int error; @@ -3179,6 +3237,33 @@ static int mxt_parse_device_properties(struct mxt_data *data) data->t19_num_keys = n_keys; } + if (device_property_present(dev, buttons_property)) { + n_keys = device_property_read_u32_array(dev, buttons_property, + NULL, 0); + if (n_keys <= 0) { + error = n_keys < 0 ? n_keys : -EINVAL; + dev_err(dev, "invalid/malformed '%s' property: %d\n", + buttons_property, error); + return error; + } + + buttonmap = devm_kmalloc_array(dev, n_keys, sizeof(*buttonmap), + GFP_KERNEL); + if (!buttonmap) + return -ENOMEM; + + error = device_property_read_u32_array(dev, buttons_property, + buttonmap, n_keys); + if (error) { + dev_err(dev, "failed to parse '%s' property: %d\n", + buttons_property, error); + return error; + } + + data->t15_keymap = buttonmap; + data->t15_num_keys = n_keys; + } + return 0; } From patchwork Fri Nov 22 08:23:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257371 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 608F214C0 for ; Fri, 22 Nov 2019 08:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B77120717 for ; Fri, 22 Nov 2019 08:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbfKVIYk (ORCPT ); Fri, 22 Nov 2019 03:24:40 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:4441 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYi (ORCPT ); Fri, 22 Nov 2019 03:24:38 -0500 IronPort-SDR: 3D+5cfH5tl/qS+vsitVBvRv22jNk4Y0tkfDDWEYXe3hEUuMTL4xfvOLQ/ZTl9MEBcwEHCR04dH Hvo+zR7oylZyKszzbSNdu0f45Omq1AfYy2QOsk6fiWl7389nlbj1x30KqHOOW7R/ec+U3n53if rRcObCvXitWqfIijhGg2X+mQjqJvzj6kQJdC7jRfM8GxqADeD8aEq6Ur7qahRpb5btLR+ZROf5 h4ClDXMbB5ADtLiSOjdtF2jlZ4AEHJqQb9H6w+ik25s85inVUJEDNdU7LzKD5SpY0tsrcqtsCo UE8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457558" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:38 -0800 IronPort-SDR: 381xu3DF+4Cgovhpec0OSIUUYMasd0L/LUbJpsD4nSSh2UZpE8rIfzLhTdqMy+K98PvjW+B5GS JdkYindOeGzcFTrr+MrKUjg8vA9oxEVf1OxCcZQD2W8alZWa4N9QzfER1H7EUbrpRCaxffERGL HpRqHKX2747vE0Kwd17ux/Ps+E455+fil7A9jXM2mNNIrhIXnAHKDHkdif3M3ydfPGQ8zIpZrV ppPAw/zLQY1hGoMLww5+fF7ipvP2pY+uZmIWb956ZIl+4lwSz+L8bkC7Sbb7URPheVyipUR2ag uj8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 09/48] Input: atmel_mxt_ts - handle reports from T47 Stylus object Date: Fri, 22 Nov 2019 17:23:23 +0900 Message-ID: <20191122082402.18173-10-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 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 2df3104e94b9..661bfe4a43b9 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 Fri Nov 22 08:23:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B85B614DB for ; Fri, 22 Nov 2019 08:24:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A16D20672 for ; Fri, 22 Nov 2019 08:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbfKVIYn (ORCPT ); Fri, 22 Nov 2019 03:24:43 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52480 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYn (ORCPT ); Fri, 22 Nov 2019 03:24:43 -0500 IronPort-SDR: TEW45UQ+LQKud7MqY6EO+BA5zEF3+M0hUBCi3WfXchkK5JHbA477ZEC2FY0VgDzJlKvMcWSdO7 RyYTTPYAFY003Yra5y7Kn+1zbwH+oPkHUtcDdv2eKEsYbzmRP2Z3fEL7T3nozgB2qxPOzObJfC twJygdMN0Q+gpB5h3FEwnFgQ8cj8W0abHIJUOsy+3pP58auV4hwSvxlBAF+gyfRZHH2/C1Pcs4 REiOurqjbxiGjOH4ETz5r9w8mZuqAarwumHOXnyu+H2zx8n+iVRG9x5aElDo2MNDnSPhKSO+ut WRc= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358908" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:42 -0800 IronPort-SDR: /t9QF+6M8YvBtYUv3YXoRM0y0DK1TLJ+hZkMQ3+0NUhkJa6rrh27UFXGbC+mAfpxjzQc3mpzCy 4FnHnvYa2cpuuYqIldFnZi7C4FC4KwGhY8cgBop3PPrI0bGxhKbJ+/qRs2rpgnhfSdIl1rA7pa RiJyh8YMtAbbkMDD2RNfqLCJjkyf/xVDXByAAmt1un/iiMNLG7YZmDKNXOEzR+NE+Oy1c9wk84 FYRskSaPAqWCJyZZ4nZylnkStepe48q7IeI3aNvxMxJsp4e9RxyziqLCp5qb3VGNYsOL3nRlJv Scg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 10/48] Input: atmel_mxt_ts - implement support for T107 active stylus Date: Fri, 22 Nov 2019 17:23:24 +0900 Message-ID: <20191122082402.18173-11-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 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 661bfe4a43b9..0557aea20067 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 Fri Nov 22 08:23:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 261F414DB for ; Fri, 22 Nov 2019 08:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1065020717 for ; Fri, 22 Nov 2019 08:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727225AbfKVIYr (ORCPT ); Fri, 22 Nov 2019 03:24:47 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60529 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYq (ORCPT ); Fri, 22 Nov 2019 03:24:46 -0500 IronPort-SDR: gAsw8te/IISiyIX3FhIWRoPwCaVAtZuX9yh0HyipeAfUklERO+yzUhwbgZILW/yoThucK7NNsJ mPWjwEN8L65VT443RxTE21UMN5H8etUvhG6mrJouN2l9rUuaSVnxmyxFuH12fIblRmHoPmqtTw jJRAplJHfrcCHIce7EnMyFt793Gvv9f5cARJNvvk/Jr9hU7juOqNmAomNyLCQANO/9KduBuccC Npnrl51BDrb25IG43pSj+X65pC8ny7dXU7jdFNk48qS1Q6T/TFZd8ggzj+iif5OUj1cMUtejLF p2E= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291105" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:45 -0800 IronPort-SDR: XsfLL80Ssp7HOQsQ4x2tRmPe2ddPF/QQYF9eeJerax2OHdfEpdmhi/LmfV8XCo+FfE+NSRZ4KL 5SBtB9T2RLa6ugpaNvgu9fKmYcHDq5ei+F9X4Fq+jT5D+0Fsn7jCLecEAKknaOS0EWCJjiI5lx zigwejykAPqCOq8LzqJ8teaH1Cnh1Owbo8h5htxU73Ohz63wnCAhHGiqdZZv524qpZLhj4wz+Y BZX1wC+Jh2nC9jK85+GF9jVRFFunYQ7CdUfbY1aWuFqrWb8Wj/E0WXaXbPkfLHsnHfNWS9erJt EBI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 11/48] Input: atmel_mxt_ts - add debug for T92 gesture and T93 touch seq msgs Date: Fri, 22 Nov 2019 17:23:25 +0900 Message-ID: <20191122082402.18173-12-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: Karl Tsou output T92 gesture and T93 touch sequence messages. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit cb98986f8342107bf4a536aed4160b20839e97c1) Signed-off-by: George G. Davis Reported-by: kbuild test robot [jiada: changed dev_debug() to dev_info()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0557aea20067..1498342c3d98 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -71,6 +71,8 @@ #define MXT_SPT_MESSAGECOUNT_T44 44 #define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71 71 +#define MXT_PROCI_SYMBOLGESTUREPROCESSOR 92 +#define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 @@ -349,6 +351,10 @@ struct mxt_data { u8 T42_reportid_max; u16 T44_address; u8 T48_reportid; + u16 T92_address; + u8 T92_reportid; + u16 T93_address; + u8 T93_reportid; u8 T100_reportid_min; u8 T100_reportid_max; u16 T107_address; @@ -1113,6 +1119,24 @@ static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) return 0; } +static void mxt_proc_t92_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + dev_info(dev, "T92 long stroke LSTR=%d %d\n", + (status & 0x80) ? 1 : 0, + status & 0x0F); +} + +static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + dev_info(dev, "T93 report double tap %d\n", status); +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1145,6 +1169,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); + } else if (report_id == data->T92_reportid) { + mxt_proc_t92_messages(data, message); + } else if (report_id == data->T93_reportid) { + mxt_proc_t93_messages(data, message); } else { mxt_dump_message(data, message); } @@ -1814,6 +1842,10 @@ static void mxt_free_object_table(struct mxt_data *data) data->T42_reportid_max = 0; data->T44_address = 0; data->T48_reportid = 0; + data->T92_reportid = 0; + data->T92_address = 0; + data->T93_reportid = 0; + data->T93_address = 0; data->T100_reportid_min = 0; data->T100_reportid_max = 0; data->max_reportid = 0; @@ -1906,6 +1938,14 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_PROCG_NOISESUPPRESSION_T48: data->T48_reportid = min_id; break; + case MXT_PROCI_SYMBOLGESTUREPROCESSOR: + data->T92_reportid = min_id; + data->T92_address = object->start_address; + break; + case MXT_PROCI_TOUCHSEQUENCELOGGER: + data->T93_reportid = min_id; + data->T93_address = object->start_address; + break; case MXT_TOUCH_MULTITOUCHSCREEN_T100: data->multitouch = MXT_TOUCH_MULTITOUCHSCREEN_T100; data->T100_reportid_min = min_id; From patchwork Fri Nov 22 08:23:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257379 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D142C14C0 for ; Fri, 22 Nov 2019 08:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1EAA20672 for ; Fri, 22 Nov 2019 08:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbfKVIYv (ORCPT ); Fri, 22 Nov 2019 03:24:51 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4406 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYu (ORCPT ); Fri, 22 Nov 2019 03:24:50 -0500 IronPort-SDR: sLaOKttonXZz0CT7HM4LdCbcT78SqTG5SwbyNb1pF1FfG5wKNFS1Dejac4CLmfA0zFKhZl0dQX SkyAcWkL9f11JI/Mre/Y6MkMM9S91308Smhp8d/d3YgI6k3Z5RbrwNMQWsHPnhJ8oe+2sR6klO 45CLOAv0+xBfcvLg0ORat6aZcahie2Ou5jx0DCvgrw/AeGVyRPg9aRSA3CzYTMLX75Z/nPO8Qs AbcFpQcCiiA0RaEgazCz6JifiJqheGy7VwS4kq0IQLIO5DomiixXC+wZ27ZMBES+afIfZG3STB eiw= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419424" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:49 -0800 IronPort-SDR: UxeGFQRLuhC23Gwz+f1Ni6ZIGvM8gofvv3hQyUjVGj6idiDSj4Ehxo/KLx6A14II1pMrEZSN4N azeVvOXOqflxFTR/roPRq8tMuUhvLYEV7g+GHyRNFLJMeRDSHY8WrBS8Rb1a9/oPnTrm9iBV2n vj/gmXoU45dIbVSMwwNNndN9Sqqz49ma4SJqhsv5lJ0Z20qMzBHTI9KCDIv+1kA4M05l2RkB6X KsVGf/tXEBQAU79DdZhlSHVf0ZMif+/5VP6PslzCcMbjn5s5hJAyjJ0QM1CcEwZORVaRjtPJTf DH8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 12/48] Input: atmel_mxt_ts - release touch state during suspend Date: Fri, 22 Nov 2019 17:23:26 +0900 Message-ID: <20191122082402.18173-13-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 --- Notes: - Squash fix from Dirk Behme: + Input: atmel_mxt_ts - remove superfluous data->suspended data->suspended is already set to false in mxt_load_fw(), so it's not needed here. Signed-off-by: Jiada Wang --- 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 1498342c3d98..cc4f0b5a0ae6 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 Fri Nov 22 08:23:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AB5714C0 for ; Fri, 22 Nov 2019 08:24:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4470B20718 for ; Fri, 22 Nov 2019 08:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727268AbfKVIY5 (ORCPT ); Fri, 22 Nov 2019 03:24:57 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60531 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbfKVIYy (ORCPT ); Fri, 22 Nov 2019 03:24:54 -0500 IronPort-SDR: JRRmBTuayW0ksdJ6jalHHL4Znv0g/iJgfJ7w8ymTQZFgPU29dvpTTOpkxCXtprUWujKPhWAxMh IoHAlZgHbRLbhkW7oQewMd5rNYXF/aOOKRrN2uIEo0zehKHfky8UV7HN7Zu4ITAoOjjvhNi2tw v0AFEMpgQvpqlukNFoe0IGkcl5chB9eiZuCGPPz41bkLN5P5UCBYoYYO3oGfOpn+xgXcN9etIM JGOwByJRalsq80LhK9Kg6UDjaX6/rLTKEoLP0rdPxv2/Kg46zCkks96W42O/zU/RCOqs/zTQkj zOY= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291107" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:53 -0800 IronPort-SDR: cGhBTZquow4sWk214p3LsRxswYGX7sh16Gx2Zq19CBwA8GtJA2kQyp8pGlFh+RiiaEhG7bOoWh jDiZI2mgEzzzAbBrGFYoCxbl/IyHmCtBEvKwxyW3l4BKA5mhthYUo399xuFdVkQkN0wiw1mDkG B2942afTc1xWrZo0AuTExivRLKkOXiYZEQgBeDnOqsXWg/Z/WHt4gaAtvZTdPUlnpqn1Hff7zd kcVZ2x1S06kp3SUNio+2VHrjHEhd8M+jR68QtlRrpHNl5i5GRJwDWu+R5TuDrDteWnv7Xm9q6Q 3K0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 13/48] Input: atmel_mxt_ts - add regulator control support Date: Fri, 22 Nov 2019 17:23:27 +0900 Message-ID: <20191122082402.18173-14-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 --- Notes: - Squash fixes by Dirk Behme: + Input: atmel_mxt_ts - in failure case disable the regulator If the second regulator_enable(), disable the previously enabled regulator, again. + Input: atmel_mxt_ts - disable only enabled regulators As enabling the regulators in mxt_regulator_enable() might fail, check if the regulators are really enabled and disable them only in this case. + Input: atmel_mxt_ts - use devm_regulator_get() Switch to devm_regulator_get() enabling us to drop the regulator_put() in the remove function. [jiada: Resolve forward port conflicts due to commit 5cecc2bccc03f ("Input: atmel_mxt_ts - fix -Wunused-const-variable")] Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 6 + MAINTAINERS | 1 + drivers/input/touchscreen/atmel_mxt_ts.c | 129 ++++++++++++++++-- include/dt-bindings/input/atmel_mxt_ts.h | 22 +++ 4 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 include/dt-bindings/input/atmel_mxt_ts.h diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index c88919480d37..e28139ce3cae 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -31,6 +31,12 @@ Optional properties for main touchpad device: - reset-gpios: GPIO specifier for the touchscreen's reset pin (active low) +- atmel,suspend-mode: Select method used to suspend: + MXT_SUSPEND_DEEP_SLEEP - use T7 to suspend the device into deep sleep + MXT_SUSPEND_T9_CTRL - use T9.CTRL to turn off touch processing + MXT_SUSPEND_REGULATOR - use regulators to power down device during suspend + Definitions are in . + Example: touch@4b { diff --git a/MAINTAINERS b/MAINTAINERS index c6c34d04ce95..b5358d9bd9c3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2787,6 +2787,7 @@ T: git git://github.com/ndyer/linux.git S: Maintained F: Documentation/devicetree/bindings/input/atmel,maxtouch.txt F: drivers/input/touchscreen/atmel_mxt_ts.c +F: include/dt-bindings/input/atmel_mxt_ts.h ATMEL WIRELESS DRIVER M: Simon Kelley diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index cc4f0b5a0ae6..031ba48b6e71 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,7 @@ 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 +3662,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; diff --git a/include/dt-bindings/input/atmel_mxt_ts.h b/include/dt-bindings/input/atmel_mxt_ts.h new file mode 100644 index 000000000000..e4c4c0f6fa37 --- /dev/null +++ b/include/dt-bindings/input/atmel_mxt_ts.h @@ -0,0 +1,22 @@ +/* + * Atmel maXTouch Touchscreen driver + * + * Copyright (C) 2015 Atmel Corporation + * Author: Nick Dyer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#ifndef __DT_BINDINGS_ATMEL_MXT_TS_H +#define __DT_BINDINGS_ATMEL_MXT_TS_H + +enum mxt_suspend_mode { + MXT_SUSPEND_DEEP_SLEEP = 0, + MXT_SUSPEND_T9_CTRL = 1, + MXT_SUSPEND_REGULATOR = 2, +}; + +#endif /* __DT_BINDINGS_ATMEL_MXT_TS_H */ From patchwork Fri Nov 22 08:23:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AE30930 for ; Fri, 22 Nov 2019 08:27:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 153972070E for ; Fri, 22 Nov 2019 08:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbfKVIY6 (ORCPT ); Fri, 22 Nov 2019 03:24:58 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60532 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727149AbfKVIY5 (ORCPT ); Fri, 22 Nov 2019 03:24:57 -0500 IronPort-SDR: JZN7us3t5pneTXfKaJZccCFFs/FfmwQDZRWjjThcGrcjtFJekDhqn5AQISz58H2na05skMHyv6 XNTYNQiCgU75+Sxt9ZB+ANF5X/XLtfdEFQUYciOp1EgVlRUnoYP+r6t2eEp3kaOQROR7hyHKa6 ws9cRJkDh5brc3Pti2xWbWRycc2P2B+rMiDYfxVfPa7E9Fkx4qgMNtAYzrPEnqxW/qrf9/aIkt yZLf6KO++T5le5i8MXkAyieCgWInH/A2HKAJg/W8f000kR0yUXE/BJHcLmq6+CwHGPzGaf03Kc bDM= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291110" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:24:56 -0800 IronPort-SDR: kx440i/9WV89SDmCQGkqYPHvP6EDT/KyHEQAxRfbdOKscq/xfxC55AD5Dkd4U2I3Y83Kmsn/RI vG16hZCkq5rQh5qrhlX4EYrtYOV5jMfKWVLLVYDzqiNXZSIvD8cyn649mREc4/LIdpJpNkymkZ v0mO+qAD/f6AqiohDQNBgw7307EDhZ435rys3JFizQiS7gbQ8bEIMPAsnRMxQfx5mKbdb2H+gj /u83tQ3BglhyYxlnkfs3cTKayIxZLLRu+7FciJg1KNq2qGQJ1BJcPF9XCaZ6sMEUe4zIUNa3Zj o4Q= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 14/48] Input: atmel_mxt_ts - report failures in suspend/resume Date: Fri, 22 Nov 2019 17:23:28 +0900 Message-ID: <20191122082402.18173-15-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 (cherry picked from ndyer/linux/for-upstream commit 93a57575403de4dd07cd64807d3c2ed7f2cca262) [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] 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 031ba48b6e71..c551ec93ca54 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 Fri Nov 22 08:23:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0404E14C0 for ; Fri, 22 Nov 2019 08:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E20A02070A for ; Fri, 22 Nov 2019 08:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727337AbfKVIZC (ORCPT ); Fri, 22 Nov 2019 03:25:02 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60534 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbfKVIZB (ORCPT ); Fri, 22 Nov 2019 03:25:01 -0500 IronPort-SDR: Nzzax3BkieBymU9hR+PoQWNpFxU8NaDh9NV9F7430cyFp8v5iCYWte+h4FgkayK9995dwAq5cQ 8SIvWl0mXc7WCIyWRwa2DuTshWhJPlvp2S6jEEZe7zUPAmG+sCJWplqamtYi2DsKNpJ3Bq2X+u UmO9oOnOXbIS9sNQfMNPreQmoO8ogjxTTFfVlczM1v58t1QHlyGbZsH/VNZzw1W/WUqr3HCQoi ASQjxE5H4hAyd3OH65a4q3vdGztCesIcDEnVZrtjXYp265ak5KFMvWZNj5JSzyhd5MVFaBqwFl EVM= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291111" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:01 -0800 IronPort-SDR: Qw1ksm0RyPUPU7GTkW+TQvRZFP4xRV3lG7KoBtqwRmOSbcamgwkdUE+0l9OO40v9nKULlPn9fJ p5mzWfUDNjrD0F5m/JBHU0g9iMuYMsfCjVpz2ltO4CAChE/DTDLu6w5P/pk6emdYRjUv8QSOw9 CGBpCxhh4anw9jzWNA3tzRsYmkD3jlMTNAA8MHE85qTsB0tVI2SLhz19qikYAkPX05WuWFDrIq It/VARj6LwpmqvOUooBdrxI7DL7mD5NmqEY4VHhLt/svqLLgk14haFLWtIbHS3mGq2vRclE9pV YhI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 15/48] Input: atmel_mxt_ts - allow specification of firmware file name Date: Fri, 22 Nov 2019 17:23:29 +0900 Message-ID: <20191122082402.18173-16-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 platforms which have multiple device instances using this driver, the firmware may be different on each device. This patch makes the user give the name of the firmware file when flashing. This also prevents accidental triggering of the firmware load process. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 76ebb7cee971cb42dfb0a3a9224403b8b09abcf1) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 43 ++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index c551ec93ca54..a0e367bc6e83 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -33,8 +33,7 @@ #include #include -/* Firmware files */ -#define MXT_FW_NAME "maxtouch.fw" +/* Configuration file */ #define MXT_CFG_NAME "maxtouch.cfg" #define MXT_CFG_MAGIC "OBP_RAW V1" @@ -335,6 +334,7 @@ struct mxt_data { bool use_retrigen_workaround; struct regulator *reg_vdd; struct regulator *reg_avdd; + char *fw_name; /* Cached parameters from object table */ u16 T5_address; @@ -3207,7 +3207,7 @@ static int mxt_check_firmware_format(struct device *dev, return -EINVAL; } -static int mxt_load_fw(struct device *dev, const char *fn) +static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); const struct firmware *fw = NULL; @@ -3217,9 +3217,9 @@ static int mxt_load_fw(struct device *dev, const char *fn) unsigned int frame = 0; int ret; - ret = request_firmware(&fw, fn, dev); + ret = request_firmware(&fw, data->fw_name, dev); if (ret) { - dev_err(dev, "Unable to open firmware %s\n", fn); + dev_err(dev, "Unable to open firmware %s\n", data->fw_name); return ret; } @@ -3339,6 +3339,33 @@ static int mxt_load_fw(struct device *dev, const char *fn) return ret; } +static int mxt_update_file_name(struct device *dev, char **file_name, + const char *buf, size_t count) +{ + char *file_name_tmp; + + /* Simple sanity check */ + if (count > 64) { + dev_warn(dev, "File name too long\n"); + return -EINVAL; + } + + file_name_tmp = krealloc(*file_name, count + 1, GFP_KERNEL); + if (!file_name_tmp) + return -ENOMEM; + + *file_name = file_name_tmp; + memcpy(*file_name, buf, count); + + /* Echo into the sysfs entry may append newline at the end of buf */ + if (buf[count - 1] == '\n') + (*file_name)[count - 1] = '\0'; + else + (*file_name)[count] = '\0'; + + return 0; +} + static ssize_t mxt_update_fw_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -3346,7 +3373,11 @@ static ssize_t mxt_update_fw_store(struct device *dev, struct mxt_data *data = dev_get_drvdata(dev); int error; - error = mxt_load_fw(dev, MXT_FW_NAME); + error = mxt_update_file_name(dev, &data->fw_name, buf, count); + if (error) + return error; + + error = mxt_load_fw(dev); if (error) { dev_err(dev, "The firmware update failed(%d)\n", error); count = error; From patchwork Fri Nov 22 08:23:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257391 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19B0814C0 for ; Fri, 22 Nov 2019 08:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF80F2070A for ; Fri, 22 Nov 2019 08:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727332AbfKVIZG (ORCPT ); Fri, 22 Nov 2019 03:25:06 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60534 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726500AbfKVIZE (ORCPT ); Fri, 22 Nov 2019 03:25:04 -0500 IronPort-SDR: ro1KjdsGD6BmsXrsVa2yNgYwiOXsLLNvMFREjrG7Hbjxwg6p9Od2mWsvHiTuKHEmdEvGCoyUli zsILPIEO50sy9AWn6qiJ/qeRqsK3QBXtCd/OPY5sVsjwv+8r6pla9vJpKnRALEa1E1qTDL+dVN xUJnKZwh2nhgvilN0e21qGG5uznBd2m/LW2zghP1g7eH84xopo+WbSWm9WnGCEK5/jEHz/lKol FSEkYo9o3p+i0jty7YMxD1Z180YLQ7pXPPN6uWMhfm4TXvF7cMItqJyFVQuAnMhjKkdgZeYoG6 +iU= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291116" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:04 -0800 IronPort-SDR: h94jbL+B3yChuasOhPeZGKiI6b7eCf4tFyTWlRkKELLLQQ0bvV4LKiubARqUkV+EGzy68iR74k Dai2zookAoWK1oqLvvLRtxaxkirpTxBPkNUWFRmTuVDgGUs4n+d/+3VTgEVo26YlxoHkf2iMeZ rESxgzOMJVUKBg+KpLa//e4g7N+6+dk1U0DBLN/sLaJFUw3hgpCjvdiWUIwphlIkx5RiM2IgIG Gj7g2R49X2RH56r2JsDxLPYinaVKeK8PT5IB86RBSbkQcuoTdDoEiZFG+VbF8Qr7P3dODsl/b7 pcs= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 16/48] Input: atmel_mxt_ts - handle cfg filename via pdata/sysfs Date: Fri, 22 Nov 2019 17:23:30 +0900 Message-ID: <20191122082402.18173-17-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 There may be multiple maXTouch chips on a single device which will require different configuration files. Add a platform data value for the configuration filename. Add sysfs entry to write configuration file if the platform data is not set. Split out the object initialisation code from mxt_initialize() into mxt_configure_objects() to allow this. Signed-off-by: Nick Dyer Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 71a2a4d1954460b949a16b607f72bafab294ca79) [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 Vladimir Zapolskiy: - Input: atmel_mxt_ts - fix error paths in mxt_configure_objects()] Signed-off-by: Vladimir Zapolskiy --- Notes: - Squash fix from Vladimir Zapolskiy: + Input: atmel_mxt_ts - fix error paths in mxt_configure_objects() Fail in mxt_update_cfg() is critical, because the driver state machine is broken and it can not be safely used afterwards. [jiada: Squash fix from ndyer/linux/for-upstream commit c909ada856861f305653b127db3ea0fa60264331 - Input: atmel_mxt_ts - check data->input_dev is not null in mxt_input_sync()] Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 3 + drivers/input/touchscreen/atmel_mxt_ts.c | 109 +++++++++++++++--- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index e28139ce3cae..713ce870805c 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -37,6 +37,9 @@ Optional properties for main touchpad device: MXT_SUSPEND_REGULATOR - use regulators to power down device during suspend Definitions are in . +- 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 { diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a0e367bc6e83..362b7630ec6e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -34,7 +34,6 @@ #include /* Configuration file */ -#define MXT_CFG_NAME "maxtouch.cfg" #define MXT_CFG_MAGIC "OBP_RAW V1" /* Registers */ @@ -335,6 +334,8 @@ struct mxt_data { struct regulator *reg_vdd; struct regulator *reg_avdd; char *fw_name; + char *cfg_name; + const char *pcfg_name; /* Cached parameters from object table */ u16 T5_address; @@ -377,6 +378,9 @@ struct mxt_data { /* Indicates whether device is in suspend */ bool suspended; + + /* Indicates whether device is updating configuration */ + bool updating_config; }; struct mxt_vb2_buffer { @@ -833,9 +837,11 @@ static void mxt_input_button(struct mxt_data *data, u8 *message) static void mxt_input_sync(struct mxt_data *data) { - input_mt_report_pointer_emulation(data->input_dev, - data->t19_num_keys); - input_sync(data->input_dev); + if (data->input_dev) { + input_mt_report_pointer_emulation(data->input_dev, + data->t19_num_keys); + input_sync(data->input_dev); + } } static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) @@ -2578,13 +2584,21 @@ static int mxt_initialize(struct mxt_data *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); - goto err_free_sysfs; + if (data->cfg_name) { + error = request_firmware_nowait(THIS_MODULE, true, + data->cfg_name, + &client->dev, + GFP_KERNEL, data, + mxt_config_cb); + if (error) { + dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", + error); + goto err_free_sysfs; + } + } else { + error = mxt_configure_objects(data, NULL); + if (error) + goto err_free_sysfs; } return 0; @@ -3081,19 +3095,21 @@ static int mxt_configure_objects(struct mxt_data *data, error = mxt_init_t7_power_cfg(data); if (error) { dev_err(dev, "Failed to initialize power cfg\n"); - return error; + goto err_free_object_table; } if (cfg) { error = mxt_update_cfg(data, cfg); - if (error) + if (error) { dev_warn(dev, "Error %d updating config\n", error); + goto err_free_object_table; + } } if (data->multitouch) { error = mxt_initialize_input_device(data); if (error) - return error; + goto err_free_object_table; } else { dev_warn(dev, "No touch object detected\n"); } @@ -3101,6 +3117,10 @@ static int mxt_configure_objects(struct mxt_data *data, mxt_debug_init(data); return 0; + +err_free_object_table: + mxt_free_object_table(data); + return error; } /* Firmware Version is returned as Major.Minor.Build */ @@ -3392,6 +3412,55 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static ssize_t mxt_update_cfg_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + const struct firmware *cfg; + int ret; + + ret = mxt_update_file_name(dev, &data->cfg_name, buf, count); + if (ret) + return ret; + + ret = request_firmware(&cfg, data->cfg_name, dev); + if (ret < 0) { + dev_err(dev, "Failure to request config file %s\n", + data->cfg_name); + ret = -ENOENT; + goto out; + } + + data->updating_config = true; + + mxt_free_input_device(data); + + if (data->suspended) { + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + enable_irq(data->irq); + mxt_regulator_enable(data); + } else if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) { + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + mxt_acquire_irq(data); + } + + data->suspended = false; + } + + ret = mxt_configure_objects(data, cfg); + if (ret) + goto release; + + ret = count; + +release: + release_firmware(cfg); +out: + data->updating_config = false; + return ret; +} + static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3406,11 +3475,13 @@ static const struct attribute_group mxt_fw_attr_group = { 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_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, + &dev_attr_update_cfg.attr, NULL }; @@ -3511,7 +3582,7 @@ static int mxt_stop(struct mxt_data *data) { int ret; - if (data->suspended || data->in_bootloader) + if (data->suspended || data->in_bootloader || data->updating_config) return 0; switch (data->suspend_mode) { @@ -3580,6 +3651,8 @@ static int mxt_parse_device_properties(struct mxt_data *data) int n_keys; int error; + device_property_read_string(dev, "atmel,cfg_name", &data->pcfg_name); + if (device_property_present(dev, keymap_property)) { n_keys = device_property_count_u32(dev, keymap_property); if (n_keys <= 0) { @@ -3704,6 +3777,12 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) if (error) return error; + if (data->pcfg_name) + mxt_update_file_name(&data->client->dev, + &data->cfg_name, + data->pcfg_name, + strlen(data->pcfg_name)); + data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(data->reset_gpio)) { From patchwork Fri Nov 22 08:23:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76CEE14C0 for ; Fri, 22 Nov 2019 08:25:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 619322070E for ; Fri, 22 Nov 2019 08:25:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbfKVIZK (ORCPT ); Fri, 22 Nov 2019 03:25:10 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4430 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbfKVIZJ (ORCPT ); Fri, 22 Nov 2019 03:25:09 -0500 IronPort-SDR: ZH5ZcX6CL+S4IM6cerZMlA0iWeFlf+7Dy2/Bp2HF+odIDqRIdn4ykC7tDyH/IdXJgHIZUSW2wZ T0n9gb6XORKMANiqiGFU2QkncEtJ9AwUHO0lXI2OMAlj9jp52KqeR75rkVh+PvohhkqeMsdo/7 SUgDdhScFz+hLDFUWTnXNkzLXLYUKmWOxw2f1YosSnIeIXf1s9Q4ZdUavUapOTB7ADmOBqQgpq N3K5QuQNqAYB6PpyARYjcNAqCW74xMQn4JnpSJdOF1yZs15urNwNJTVPOeG0sfeiNHdRwEoT+a NV4= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419447" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:08 -0800 IronPort-SDR: YhhMFZe3ywNjSzhTdd2x3arn9CtNAJVVPriao7GXIZq5YaOAxU1hZQTlZKE4j5EFGoPYDR8WKn HZ98PlOroRaiJSi8TVPS4aOuEx7FZNSzmTxTVGCVcOpSj4nG1onkzZugkwvwrC/ymmYAZfM7NM Chqj9fIaCi3+4/fM+oxsRUO2/FMD5bp2DDBXkZzrAwJTmTDrIDs7Tqy1Ci7bm02/HvVsjudkHQ wAN+pPxqU1/f4WGoqvrS/R2DK3F7ulFuAoOuPSfvz5KF3WPYEoMWJuYTuCeE+lM9eWa/Fltky+ 0nM= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 17/48] Input: atmel_mxt_ts - allow input name to be specified in platform data Date: Fri, 22 Nov 2019 17:23:31 +0900 Message-ID: <20191122082402.18173-18-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Jiada Wang --- .../devicetree/bindings/input/atmel,maxtouch.txt | 2 ++ drivers/input/touchscreen/atmel_mxt_ts.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index 713ce870805c..d7db16920083 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -40,6 +40,8 @@ Optional properties for main touchpad device: - 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. +- atmel,input_name: Override name of input device from the default. + Example: touch@4b { diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 362b7630ec6e..9ee3b6d40c8c 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 Fri Nov 22 08:23:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41CEF14DB for ; Fri, 22 Nov 2019 08:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BFD72070A for ; Fri, 22 Nov 2019 08:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727362AbfKVIZN (ORCPT ); Fri, 22 Nov 2019 03:25:13 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4430 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbfKVIZM (ORCPT ); Fri, 22 Nov 2019 03:25:12 -0500 IronPort-SDR: l9k0sPvPyOvlbjB5cvYHUaDGy3l7LS7gwX4eTbxKrx2yg/r7lChIT4OpY9oqEoQUGnIuNu1rK5 ntkI/E8G1S8edLRt6EaMFReZ1GB8wBL/M85wBpNGHuqK9f1D0X+HKkallT1kPKY/+6RTu3dmhf j/z8m4RuiAaAYMn2Glp3uZO6zTiRzKEMgTd5465DJNjtwF7/E9Fr0vv3oZ5no51bVliUkH27Em bEiVOyKZbW4zFj1p6sWLAhxT0C5bghcaT3WqT7hL2LG6dfaZsO6I1TkwlPBxZGkU+uioRQuC9J 7bU= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419449" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:12 -0800 IronPort-SDR: S/AZYVkvuzxGXz2j93hrAXYShck/ZomIlGZZ+HVArxlHZyXMQXepW7+ZUT4Nx3UGYhc3faMZca +dSZhzeYHyf6ANS/YMHs2qegGPZDtxBIODb6mt1YYFRYoHfFAf5Uwzk2DlcZd1jhqWXUg6zwCI Jk+DroXRhLI4cLgDTEs4+qHEfAdowV4dfURQZwUIXDSqcBKYsFfAYuCLUHwvSz0e5LSMMqKI5u zDQ0gSlZt9ovDhszA/yudR14dwPdnOyCrLuQ6PRlmaXIt/EcDVnL7umToLAN19NTON0MC13MF5 JdE= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 18/48] Input: atmel_mxt_ts - add config checksum attribute to sysfs Date: Fri, 22 Nov 2019 17:23:32 +0900 Message-ID: <20191122082402.18173-19-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: karl tsou Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 03477477ddbe5dcad42853ab3f84166a8f807acf) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9ee3b6d40c8c..81e3a71849c0 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3128,6 +3128,15 @@ static int mxt_configure_objects(struct mxt_data *data, return error; } +/* Configuration crc check sum is returned as hex xxxxxx */ +static ssize_t mxt_config_crc_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + + return scnprintf(buf, PAGE_SIZE, "%06x\n", data->config_crc); +} + /* Firmware Version is returned as Major.Minor.Build */ static ssize_t mxt_fw_version_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -3481,12 +3490,14 @@ 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_cfg, S_IWUSR, NULL, mxt_update_cfg_store); +static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, &dev_attr_update_cfg.attr, + &dev_attr_config_crc.attr, NULL }; From patchwork Fri Nov 22 08:23:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8966014DB for ; Fri, 22 Nov 2019 08:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 727792070A for ; Fri, 22 Nov 2019 08:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727405AbfKVIZS (ORCPT ); Fri, 22 Nov 2019 03:25:18 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727399AbfKVIZQ (ORCPT ); Fri, 22 Nov 2019 03:25:16 -0500 IronPort-SDR: tdEGD9UN4YWD+C2aE/ltPi3K7j9QEGhB+iUYicNfRf0GwpicZ+QGh0bZpFeEGMnkF7oME2JJdi SpUSVVNSM7uvf5bp0UFm5vDV4rQB1jT4uB81gOAvBdB9eT0wr+viB8sMwV/cyktA4V9zESA5UM aWiHGtFueb3Qi5XNhlBUH4X5Va2Dy29xyaZHxisBgg4mej74QJNAvkJ3gs4wishxL/uYp11wZ2 KEsZ+zLl21jSER7l0zaR/lqSKPqtclT/FW/UnctMJtEJDR1j7ZbK6aBoZbcRT/lPSIKLRlwhRX pu0= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358920" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:16 -0800 IronPort-SDR: gbqxfosOelEBBnw95s3btvDpTy3BnrZIO11O4ap18DJHSXY3YE1nikuB+nXhC+9kB1vMJlJng7 fjtw2G1y1kS9ovTBM6tQrF/vFgve2OAfUyJS0EnIaTJMd2ZOSJGoqErUEMQjmAiGBjdQhxATPz 3cu7loafyvsfI8J7Pv88fv0n/jNtFUBXKe3ascU04xyPMrwIuH4MK4z9LZHWqFv2JlVJoZg0X6 hpkHk30W3t/OJpqImwlw4Zsn8NEAk/oBuV2Mal36q5IitBX5WR4+5NlXZkhEV8W227DAnMcePb 2ks= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 19/48] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Fri, 22 Nov 2019 17:23:33 +0900 Message-ID: <20191122082402.18173-20-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 1bbe20ff3dcd6612e7942c495929eae5c138ece2) Signed-off-by: George G. Davis 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 81e3a71849c0..44bb77c0159c 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 Fri Nov 22 08:23:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 752A514C0 for ; Fri, 22 Nov 2019 08:25:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F7532071C for ; Fri, 22 Nov 2019 08:25:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727418AbfKVIZU (ORCPT ); Fri, 22 Nov 2019 03:25:20 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbfKVIZU (ORCPT ); Fri, 22 Nov 2019 03:25:20 -0500 IronPort-SDR: AE4rsWmIvCjm3c8QrExfcc7G0lgPnPKxgVGrYRPrtxkQlUr9/pev5I4p1l/2hy8LuknpeCT8ds LNlMxLHTdelvhbDWt6gu0uNTu9bc2PsFp5ULosoMx+zclEFWVL+jzEbV/WaDYNk8F0EcsYX44r MW/BbDwN33AAcZNx1//I/NUrSXqE7jyW02dUBCA2wgjGpZKbuCJ7HsWR/lL6vTmkxJrvt4iI+x dNgDQFMjJFGVzfVMHQa/xLTzHMEO43TqbAR9DhpPM0BoBTvXxp+0312jV45S+WKlqGfO9R/wJp RLU= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358922" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:19 -0800 IronPort-SDR: SoHED8XtekJl5VOTOSyaV+oV7992iFOM8QdaHBWijnwM6H6IpcbltXEJagGeqNcTKTXN4vz6Ik 65iMt3HsiCt6AyXzpTRnUHUKL+4HLTUmsFq7xNef4Uf80n2gMIOlnc1JrdS2wCFTgeKA/XYLKd 3Gbq8zrEVBoCUomBEefefVADm4tduUyjFM+C0toYrThT8d5GKSljdmlgLSHK9lzQ6WnI1JWhQy yzMMHu5od5gjFN663o6C2xJA1tRhAi6hpwxV3q+Enq/E484us7pwthKIqzoQn9ZhNbeB4Tw1gB Rno= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 20/48] Input: atmel_mxt_ts - refactor code to enter bootloader into separate func Date: Fri, 22 Nov 2019 17:23:34 +0900 Message-ID: <20191122082402.18173-21-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit bedd706a32522b946467e15f4f4f24de86a1b4d7) [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: Squash change from ndyer/linux/for-upstream commit d691d3ee6c6de84b38464a42 3207b3e23cb9dc3a - Input: atmel_mxt_ts - check firmware format before entering bootloader] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 43 +++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 44bb77c0159c..04627db23ad2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3257,23 +3257,10 @@ static int mxt_check_firmware_format(struct device *dev, return -EINVAL; } -static int mxt_load_fw(struct device *dev) +static int mxt_enter_bootloader(struct mxt_data *data) { - struct mxt_data *data = dev_get_drvdata(dev); - struct mxt_flash f = { 0, }; int ret; - 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, f.fw); - if (ret) - goto release_firmware; - if (data->suspended) { if (data->suspend_mode == MXT_SUSPEND_REGULATOR) mxt_regulator_enable(data); @@ -3291,14 +3278,14 @@ static int mxt_load_fw(struct device *dev) ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); if (ret) - goto release_firmware; + return ret; msleep(MXT_RESET_TIME); /* Do not need to scan since we know family ID */ ret = mxt_lookup_bootloader_address(data, 0); if (ret) - goto release_firmware; + return ret; mxt_sysfs_remove(data); mxt_free_input_device(data); @@ -3309,6 +3296,30 @@ static int mxt_load_fw(struct device *dev) reinit_completion(&data->bl_completion); + return 0; +} + +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); + 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, f.fw); + if (ret) + goto release_firmware; + + ret = mxt_enter_bootloader(data); + 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 */ From patchwork Fri Nov 22 08:23:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A58BA14ED for ; Fri, 22 Nov 2019 08:27:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 905B520714 for ; Fri, 22 Nov 2019 08:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbfKVIZ0 (ORCPT ); Fri, 22 Nov 2019 03:25:26 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727431AbfKVIZX (ORCPT ); Fri, 22 Nov 2019 03:25:23 -0500 IronPort-SDR: oWmG1OcHbjPK7HCR/H+anRdGgLSQCzMiDK/B6Z7xLRS1n+h93hoKGeUN2NgnPihjtFIhuEN3Dm UcH/27zxTZXj8Zb2sT6zv56F07NHwQjnQILyGSlnVd4LGNfi43ff0Dl1ZOjvY+IV8aRPQR8MNH OsyDfa4to7hMKhXssfyLbQS472Q4H/Bl3m0Ydv56bkq9KILzAA93cJmUjj1uRfrg4kzGdUINke 18mP5nYOtGPRSZgcza+a4WUtDJlWAP8NdwPCPVycfEJkUWZcneb6HVXmt0+h3YC6zDdi1shZh5 pxs= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358926" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:23 -0800 IronPort-SDR: XHDpIymJMyYDdAjqR0Y1jJHBxOaFPThvO/K2HKvRV3E2/McOUcR1S9QNKErPtfD9KM/6soLhij wivM2lJQyN8qR9HYtrdivBlUTmuELPvcAOba7CjSkMtWd49w9bp9PviTDXsofdPBtjegGiYQ57 wIWUowCWXxGe4/TUAl1KtAkl3nzAEGR4PF/wrsNa5PSU6bFPDgd+UwJX/m7FkMfZocGHRsO+1z +Bm6B8dtJTuFhMU11o+HIx6GbGBsnO+ybq2It9nSSMm1rYU7VNerzH+dLu/3H3r2Weg9Fsv38D 43E= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 21/48] Input: atmel_mxt_ts - combine bootloader version query with probe Date: Fri, 22 Nov 2019 17:23:35 +0900 Message-ID: <20191122082402.18173-22-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 04627db23ad2..d38ae9525e35 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 Fri Nov 22 08:23:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EDAA930 for ; Fri, 22 Nov 2019 08:27:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ED5820714 for ; Fri, 22 Nov 2019 08:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726698AbfKVI1S (ORCPT ); Fri, 22 Nov 2019 03:27:18 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbfKVIZ1 (ORCPT ); Fri, 22 Nov 2019 03:25:27 -0500 IronPort-SDR: bh+MaslaAVfRQi0k67EIbqcqu1OxmVgAlhwYusR7Jkwdz4KBqZEpS03P5dVDehpkPa6xodNTEm TJ3WJzsEggfmXmsYA6UlVzN8sL2mtnM4VjKnRHYHA9Sb+6aCGJIH2jZbUpTy0cQYp0CU+Ypk4l 9yCCdeeDp0YqYLkeu5SvgfGSz3+lkZo+XybHOUctB8ciB/6I1KAiRsWLz/D9ki471ZwXy+MFNL Jgs3O1CMUHzrFRIEMpriqTuuhAb3+XUd6zP/hpABhQRyTEVDG+RFKKZsjt/zlLvdv/6HBQk7lU Eug= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358928" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:26 -0800 IronPort-SDR: t7eGIw7uBRTj5X2ePYPkNnuYxEWjbImNenuNhWUosVILv1BKZ9qQzID7JTKc6GfMzg9Ic7QTj+ 9Nuxu/D6+HtMIePcI2a/zE/aHW1yrDuiSh/Nj8GF1MNm/rY5qW4p1fOdRE1twINtdnYy/y+yGN lLN6wCeNp/ktps6yT9hQ0Vtnz1lK/BMOwohug8w7imPDXP9b1o8vR7FHLu9fU0/9+NTfGmTPc7 AVpdYXUE/PxEPtOxwKmcUT320cxCwIgmK63GnT9uYYP+3F0ZVJ3a+clFbXHpZNgljtL4QwaBsd vSU= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 22/48] Input: atmel_mxt_ts - improve bootloader state machine handling Date: Fri, 22 Nov 2019 17:23:36 +0900 Message-ID: <20191122082402.18173-23-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 --- Notes: - Squash fix from George G. Davis: + input: atmel_mxt_ts - Fix 'mxt_send_bootloader_cmd' was not declared warning The following sparse warning was introduced by ndyer/linux/for-upstream commit 463e15ee95ee ("Input: atmel_mxt_ts - improve bootloader state machine handling"): drivers/input/touchscreen/atmel_mxt_ts.c:888:5: warning: symbol 'mxt_send_bootloader_cmd' was not declared. Should it be static? Fix the above sparse warning by restoring the 'mxt_send_bootloader_cmd' static declaration which was errantly removed by ndyer/linux/for-upstream commit 463e15ee95ee ("Input: atmel_mxt_ts - improve bootloader state machine handling"). Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 183 ++++++++++++----------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d38ae9525e35..1c5230f7a9af 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -305,6 +305,8 @@ struct mxt_flash { size_t frame_size; unsigned int count; unsigned int retry; + u8 previous; + bool complete; }; /* Each client has this additional data */ @@ -583,64 +585,121 @@ 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) { + /* + * 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->bl_completion, + MXT_FW_CHG_TIMEOUT); + if (ret) { /* - * 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. + * 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). */ - ret = mxt_wait_for_completion(data, &data->bl_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_err(dev, "Update wait error %d\n", ret); - return ret; - } + dev_warn(dev, "Update wait error %d\n", ret); } - ret = mxt_bootloader_read(data, &val, 1); + 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; + + 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; + + break; + + case MXT_FRAME_CRC_CHECK: + if (f->previous != MXT_WAITING_FRAME_DATA) + goto unexpected; 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++; + + 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++; + 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 +3360,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 +3375,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 +3384,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 Fri Nov 22 08:23:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EA3914C0 for ; Fri, 22 Nov 2019 08:25:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 588CE20708 for ; Fri, 22 Nov 2019 08:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbfKVIZa (ORCPT ); Fri, 22 Nov 2019 03:25:30 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfKVIZa (ORCPT ); Fri, 22 Nov 2019 03:25:30 -0500 IronPort-SDR: YzdUC/D3KGPrX5o5ONYcCBKzRY1/frBUGZshUMM5WPUDJ2xSb0qSmR3kQafdNFU6IxN892oSYd deq7fYksu45zLfoIopHg+22zU4GyRK3rHuJMtQ7xiSHOm94cYS/FsNNHL+FEaf2jVFJG76SfLb b8Y4PblrJofGELTiu+sjoMNK3WwidqwFakvRpnYDsvxwIj3i8RHsom0EPniFh38ALVIz7jBCq3 OzDFRtMhcGNBV6uFDHSKE8/yeojkgG/BlZTRE0cjcQUacGRfwRVbOdnTtWZEZYGzq33hoWQjPQ H3I= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358930" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:29 -0800 IronPort-SDR: QUEAV1pzUhF/EIwJ56uup30aSTa8AFA2SBwkUW4v+4x/oZsQ3QAHAWAsIPF2qsSHYf1I7tuq4x FdCN7CpRy1BTjXLvAf6XYCao03NoyvdBocGa5G+NdMc6x4QcEpG/COyQCr+rSMvOEtwPkj7xit mkl5vxzscGhXsvsT+vN4VQxwlv5XDyG5qEGoZ0+ROUw/8XeI2w2LXa5nI3O5r5JrMjQbDV0v3Z NB2/AZb9ix/08xBiHjRyuSAmb+UtTw+NA7TtYz8cf5R6QRs/m/nPnWfHrlGlGn+K73/nPXQhaL AQs= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 23/48] Input: atmel_mxt_ts - rename bl_completion to chg_completion Date: Fri, 22 Nov 2019 17:23:37 +0900 Message-ID: <20191122082402.18173-24-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit dda8453bfb44216645ede798918a314d4fca2481) [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: call complete(&data->chg_completion) only when in_bootloader is TRUE] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 1c5230f7a9af..520dc9670b38 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -381,9 +381,6 @@ struct mxt_data { u8 T100_reportid_max; u16 T107_address; - /* for fw update in bootloader */ - struct completion bl_completion; - /* for reset handling */ struct completion reset_completion; @@ -395,6 +392,9 @@ struct mxt_data { enum mxt_suspend_mode suspend_mode; + /* for power up handling */ + struct completion chg_completion; + /* Indicates whether device is in suspend */ bool suspended; @@ -611,7 +611,7 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) * 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->bl_completion, + ret = mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_CHG_TIMEOUT); if (ret) { /* @@ -1402,8 +1402,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) struct mxt_data *data = dev_id; if (data->in_bootloader) { - /* bootloader state transition completion */ - complete(&data->bl_completion); + complete(&data->chg_completion); return IRQ_HANDLED; } @@ -2167,9 +2166,9 @@ static void mxt_regulator_enable(struct mxt_data *data) msleep(MXT_CHG_DELAY); retry_wait: - reinit_completion(&data->bl_completion); + reinit_completion(&data->chg_completion); data->in_bootloader = true; - error = mxt_wait_for_completion(data, &data->bl_completion, + error = mxt_wait_for_completion(data, &data->chg_completion, MXT_POWERON_DELAY); if (error == -EINTR) goto retry_wait; @@ -3334,7 +3333,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) enable_irq(data->irq); } - reinit_completion(&data->bl_completion); + reinit_completion(&data->chg_completion); return 0; } @@ -3370,7 +3369,7 @@ static int mxt_load_fw(struct device *dev) } /* Wait for flash. */ - ret = mxt_wait_for_completion(data, &data->bl_completion, + ret = mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); if (ret) goto disable_irq; @@ -3381,7 +3380,7 @@ static int mxt_load_fw(struct device *dev) * the CHG line after bootloading has finished, so ignore potential * errors. */ - mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); + mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); data->in_bootloader = false; disable_irq: @@ -3802,7 +3801,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) data->irq = client->irq; i2c_set_clientdata(client, data); - init_completion(&data->bl_completion); + init_completion(&data->chg_completion); init_completion(&data->reset_completion); init_completion(&data->crc_completion); From patchwork Fri Nov 22 08:23:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 39C1C14DB for ; Fri, 22 Nov 2019 08:25:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C08A2071C for ; Fri, 22 Nov 2019 08:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbfKVIZg (ORCPT ); Fri, 22 Nov 2019 03:25:36 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfKVIZe (ORCPT ); Fri, 22 Nov 2019 03:25:34 -0500 IronPort-SDR: abfCg+7asPMTWpBjQ2sGDdcBwRL1iySVtvoKxn4vxRzwwjhBtNHgALoqW0nZUfWGLksn0/R8Zh io5KSiINUv9CG0g0roreS+48gcBK8S16dscYJvF6Jg6hVH7FK9aQwPqeluNmvDrlanKYO/bqoj 7XNnYhzBwMqpcf+ClL3kQSvAZgZxvwl5E2GV7ROWqa4hMQVIjxDxQcqMvqiZFc4rXY+G6JAseL bDOVxvAI7f53LoVyyQm74HX+7MXGu7QVo8MF3trepzpPhl/js+oGcSfaudLlBb9GVpyv2YnMRw 10U= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358932" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:33 -0800 IronPort-SDR: HYt+Mxd6EfaGsari0R9njzNthdq2vR8LL2pepvCb4XGXQ0T373ky4veDxBXze6Un2HLbEyJnNG Zt+R4NLf+uHuZgoUzSjopvPwh1YGaVMjK9Ce4r1ww7VelU8RSMmsI0l/UyA2Vop13TrZYGlSk/ AJVcLUfKrCCwNzJ/YQfytCSFhvWPli9c6v71KRqCv8euodXPoMb7wJnV8zVf5Vi80eiLWM4dx4 s4CFFZg4V8XvDTtDP4/HA9fjlA8XXyeePRY0/INheJ6vlJ9plrRE4BSdMMnKfOhWbW6don5KPA rSE= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 24/48] Input: atmel_mxt_ts - make bootloader interrupt driven Date: Fri, 22 Nov 2019 17:23:38 +0900 Message-ID: <20191122082402.18173-25-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 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] Reported-by: kbuild test robot Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 118 ++++++++++++----------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 520dc9670b38..842d407efc86 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,7 +309,8 @@ struct mxt_flash { unsigned int count; unsigned int retry; u8 previous; - bool complete; + struct completion flash_completion; + struct delayed_work work; }; /* Each client has this additional data */ @@ -355,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; @@ -599,28 +604,17 @@ 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; - /* - * 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); + /* Handle interrupt after download/flash process */ + if (f->pos >= f->fw->size) { + complete(&f->flash_completion); + return 0; } ret = mxt_bootloader_read(data, &state, 1); @@ -666,14 +660,12 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->pos += f->frame_size; f->count++; - 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; @@ -695,6 +687,9 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->previous = state; + /* Poll after 0.1s if no interrupt received */ + schedule_delayed_work(&f->work, msecs_to_jiffies(100)); + return 0; unexpected: @@ -1403,7 +1398,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) @@ -3304,16 +3303,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) @@ -3326,67 +3322,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 Fri Nov 22 08:23:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257405 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A866114DB for ; Fri, 22 Nov 2019 08:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93B382070E for ; Fri, 22 Nov 2019 08:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727506AbfKVIZj (ORCPT ); Fri, 22 Nov 2019 03:25:39 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727495AbfKVIZi (ORCPT ); Fri, 22 Nov 2019 03:25:38 -0500 IronPort-SDR: MaJtDyEI/JuCOdKTvuRr0V/beitdFb6f/soCebS99Y8qx93iDsuHWkpDOXkGBZm1sIKAtxU1/W UOLq0ItzKJU1F+DavhEDTMV08w4uRdSvYjWssKRtU1xdAmv8K9Ndp35VOmiixwW2hdFkMlxVIh 5LA88TILa9Q/gZgt/CN8YPODGpRoY4kJZjQ/zvaLgPgyQP1hKx5Wb66sjNU5THzLhRf9hP8O1p iUtJxKTZWOz3fHKnwQPsvac2Z8DyghEYMoTVfy+Tc9cEvTxvqMzZzxCWf0QvGyhJiPicWzesQ3 lgs= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358937" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:37 -0800 IronPort-SDR: qrIeMB0I+Mxk+TZMP0OwHvgsWC9BFe8NmwyvH9Of5GKRrWzdl+Qa0puWnfsQ3Jy2DUCckr35LA V975d81pgd9tFx+sQkNDsjw6HmJEkDlK0XQ+ozM6WTzR/JxHyeWPsXzr4D/ZPnl3ZzUa5A4IwI 6Kwkc9NFwsBB2fuDGU7YpzWTfYnE45sliBPanZSEBBsMnhIuLtHe9UY4pQBGS5ukYnNSNRHGng LZdo0XYVNqsgDHU0/zlcUuzRkX6+hZOT36VcuDt9FYNnAFQyrQTId42t5RKd8NzWDiRscgsDOJ MYU= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 25/48] Input: atmel_mxt_ts - delay enabling IRQ when not using regulators Date: Fri, 22 Nov 2019 17:23:39 +0900 Message-ID: <20191122082402.18173-26-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 842d407efc86..f5d67e43a786 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1451,9 +1451,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; + } + + /* Presence of data->irq means IRQ initialised */ + data->irq = data->client->irq; + } else { + enable_irq(data->irq); + } - if (data->use_retrigen_workaround) { + if (data->object_table && data->use_retrigen_workaround) { error = mxt_process_messages_until_invalid(data); if (error) return error; @@ -3373,7 +3388,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)); @@ -3800,7 +3817,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); @@ -3828,26 +3844,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 Fri Nov 22 08:23:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257407 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A816A14C0 for ; Fri, 22 Nov 2019 08:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9136C20672 for ; Fri, 22 Nov 2019 08:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfKVIZn (ORCPT ); Fri, 22 Nov 2019 03:25:43 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52499 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbfKVIZl (ORCPT ); Fri, 22 Nov 2019 03:25:41 -0500 IronPort-SDR: Ztu03b7eP7vCIqt5amD4wZiLZiWdWl+Uhfj/3rJFSNTYgOlX7ybVJoIsh51gSdJVP9ZMnUFkJj d+41wgxGlgHRVp9O3pG04PPn/sXOxd5JC21DzipxI+H8A0Ut4zQkHcny/nDr4VxX/pR5M1GTa7 3O+0HUK5YO5WJd6SsWeBBxPoYdyYo9uEAdhWs85dwKK1hGuRGoRX36PV0/1gHcDqTMIj1WsPCv GJbna5LGAKA4rc60ae1QaZfWR4pvksTZe2a6hNXc9D8TGSKg/ldl9NXJvdL53SA8OzHtRRHDFD TtU= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358940" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:40 -0800 IronPort-SDR: BGu81x4CW27EWPaPmm6sWFIgNopjnVu9qcHkh1zEtmvnhwMHKtCviyIDAaXYxBkoyUtgiCEJtd RlatjYoju4xdeZWuNCjj4dq+DEJhIZ+WwIlX3xsEmLZyLt8xZT7nPxKlo5/1/f9408VKLOjSe8 KSD0nsClsQoDueZynZztQG3xwSN6umpak/g7sKuqs9dGu1BNITa3SD40BCFQywQxY7jSRsNkvO O2MOtJXOQeOFE9us14E+IErboFHDK9LWtYLCKXQ8wF1W/h1f5bULRxBUuLk44LemgqC50zE72V 8n0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 26/48] Input: atmel_mxt_ts - implement I2C retries Date: Fri, 22 Nov 2019 17:23:40 +0900 Message-ID: <20191122082402.18173-27-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 f5d67e43a786..fc2f804e5293 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -216,6 +216,7 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_WAKEUP_TIME 25 /* msec */ #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ @@ -723,6 +724,7 @@ static int __mxt_read_chunk(struct i2c_client *client, struct i2c_msg xfer[2]; u8 buf[2]; int ret; + bool retry = false; buf[0] = reg & 0xff; buf[1] = (reg >> 8) & 0xff; @@ -739,17 +741,22 @@ static int __mxt_read_chunk(struct i2c_client *client, xfer[1].len = len; xfer[1].buf = val; - ret = i2c_transfer(client->adapter, xfer, 2); - if (ret == 2) { - ret = 0; - } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", - __func__, ret); +retry_read: + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); + if (ret != ARRAY_SIZE(xfer)) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_read; + } else { + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return -EIO; + } } - return ret; + return 0; } static int __mxt_read_reg(struct i2c_client *client, @@ -780,6 +787,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, u8 *buf; size_t count; int ret; + bool retry = false; count = len + 2; buf = kmalloc(count, GFP_KERNEL); @@ -790,14 +798,21 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, buf[1] = (reg >> 8) & 0xff; memcpy(&buf[2], val, len); +retry_write: ret = i2c_master_send(client, buf, count); - if (ret == count) { - ret = 0; - } else { - if (ret >= 0) + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + } + } else { + ret = 0; } kfree(buf); From patchwork Fri Nov 22 08:23:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1298930 for ; Fri, 22 Nov 2019 08:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC68C20714 for ; Fri, 22 Nov 2019 08:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbfKVIZp (ORCPT ); Fri, 22 Nov 2019 03:25:45 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60568 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727529AbfKVIZo (ORCPT ); Fri, 22 Nov 2019 03:25:44 -0500 IronPort-SDR: 6FKMhYuUEd7O25zaWCBe/YqzppFflF61uGsobbOuJqC7Cjup2dY8PwDG6B/ypUrDuOI5P72hSk 0plPCMxTOlCZRC14HStuVRAc8lFABa6FbaPXJyluxV6lTreZHwEPfwB75oKfhfnNTBMdvmCTKp nwlQ57OekxQeXik/QsrKSwAxC8+9nGGgfACGzLXedWicFSyycLB296e29hEZGtdwf8nnaZvLLH Z8HDGyl5HHdHgw7Jb0Dzb3IcSonGbfOn7vwdz2kh8zJUc1KwZabgT20sNLyCMQS8a6WMYH7Yz9 yuY= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291148" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:44 -0800 IronPort-SDR: 8vcvcRxrs7iO1JAqq+x+sUhEE4gMRC1dNJN16YfYxcDEQJ8ULcjqZhNcpoOOEVDzBKgi2+JlII 8n/Dzzf/VL8/VpP9Rhrlr/N5U6IUTc1kvPbeycGNp+2zNg9jwS1uABUzmKuK3bdMhOPJfkGThh GPpyQjYjbsVb0yNhmCYP4JH1zt0P+vc8Vr+8kX44V5VUFBc0lP0PSoECgsTfRd4MgoLbVUeqJQ kixQ/AcCJut5EZpoa1yM4HVgw8OwrVS5+28rQPzFDqN/O6AjSgQVJpsiEY19lAY5H5P0ty4ztH UFo= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 27/48] Input: atmel_mxt_ts - orientation is not present in hover Date: Fri, 22 Nov 2019 17:23:41 +0900 Message-ID: <20191122082402.18173-28-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 When in hover, the orientation information is not sent Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 0c885d5bd276bd9240c43aa046fc407cbe2ae864) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index fc2f804e5293..de77079e3324 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1029,10 +1029,6 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) distance = MXT_DISTANCE_HOVERING; hover = true; active = true; - - if (data->t100_aux_vect) - orientation = message[data->t100_aux_vect]; - break; case MXT_T100_TYPE_FINGER: From patchwork Fri Nov 22 08:23:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257409 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BB606C1 for ; Fri, 22 Nov 2019 08:25:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06B6F20717 for ; Fri, 22 Nov 2019 08:25:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727529AbfKVIZt (ORCPT ); Fri, 22 Nov 2019 03:25:49 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:60568 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727547AbfKVIZs (ORCPT ); Fri, 22 Nov 2019 03:25:48 -0500 IronPort-SDR: vMXDje9I8LJNit9RJAy2UR3JXr9RAwWH9FEAvJNkWzDvciDYf2NRjGdsJDtBs7qUL9Tw7OSmkG HYFfA87jG8e0oA1YypWkElzEhHd3AV/SRIm13Gw1l+z6mM5069FiENv08fhd9qffEgddEO4iEI OLr2pWkwLSxrT8GgnUjH1VT4ulEPP10lilZIzYsFrTIihKgxoher1bBDXQpQvWwvvcN43qp4bW yXpNKH3iyNhjSDXXhislecATSUateue8f8E+En8BKfeE7YG3C8wxNm74bv9QeR5Dht6jqSXYcz L3A= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291151" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:47 -0800 IronPort-SDR: JYq0kVfnfWrcx6yP4ME0NWzh8swUMHoZZD4i6/8xMRIHlJuDa4MgQ8O15NMVDa+QXnC2SxYv6c pvRl6xIXoIGJZcEUN+oQAOGh9++feJC6DpSNu3PXmhshUyGH3xp+HStYXsX0jt+lYNdGMzE18i YwmjKamJKBlI/ir7EG/2xnygxAzd+QYxJJGvlbkRdhnlzBNfpGJyjjmkibDGY6Uac6JhpvZRjl msZiKNZzq9YXvk72UgeDBFp6iUCs1PlyeB8t2/nTr6YB2ihiMmyug9DZETCMNzmEZalw7Khjk0 UJQ= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 28/48] Input: atmel_mxt_ts - implement debug output for messages Date: Fri, 22 Nov 2019 17:23:42 +0900 Message-ID: <20191122082402.18173-29-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Add a debug switch which causes all messages from the touch controller to be dumped to the dmesg log with a set prefix "MXT MSG:". This is used by Atmel user-space utilities to debug touch operation. Enabling this output does impact touch performance. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3c3fcfdd4889dfeb1c80ae8cd94a622c6342b06a) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 47 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index de77079e3324..6f4274a1c7e0 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -335,6 +335,7 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + bool debug_enabled; u8 max_reportid; u32 config_crc; u32 info_crc; @@ -460,8 +461,11 @@ static bool mxt_object_readable(unsigned int type) static void mxt_dump_message(struct mxt_data *data, u8 *message) { - dev_dbg(&data->client->dev, "message: %*ph\n", - data->T5_msg_size, message); + /* debug message with prefix 'MXT MSG:' used by + * Atmel user-space utilities to debug touch operation + */ + dev_dbg(&data->client->dev, "MXT MSG: %*ph\n", + data->T5_msg_size, message); } static int mxt_wait_for_completion(struct mxt_data *data, @@ -1214,6 +1218,7 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) 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_NOMSG) return 0; @@ -1248,9 +1253,12 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T93_reportid) { mxt_proc_t93_messages(data, message); } else { - mxt_dump_message(data, message); + dump = true; } + if (dump) + mxt_dump_message(data, message); + return 1; } @@ -3522,6 +3530,36 @@ static ssize_t mxt_update_cfg_store(struct device *dev, return ret; } +static ssize_t mxt_debug_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + char c; + + c = data->debug_enabled ? '1' : '0'; + return scnprintf(buf, PAGE_SIZE, "%c\n", c); +} + +static ssize_t mxt_debug_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + data->debug_enabled = (i == 1); + + dev_dbg(dev, "%s\n", i ? "debug enabled" : "debug disabled"); + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3538,6 +3576,8 @@ 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_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); +static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, + mxt_debug_enable_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3545,6 +3585,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_object.attr, &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, + &dev_attr_debug_enable.attr, NULL }; From patchwork Fri Nov 22 08:23:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257411 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 826CD14C0 for ; Fri, 22 Nov 2019 08:25:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C7032070E for ; Fri, 22 Nov 2019 08:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727571AbfKVIZw (ORCPT ); Fri, 22 Nov 2019 03:25:52 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62576 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727569AbfKVIZw (ORCPT ); Fri, 22 Nov 2019 03:25:52 -0500 IronPort-SDR: L1aTOU61/iBIXNaumfCAz2MfonMyUL5QXCUlHplYMOyHgSoTEw8N/bupk4F58ZszU3VnsUjkwa o+3I1mtuWLY0+cC5TUN2NfT7DvWW3hfD0FOkRehFnm8ZiZeDps5Sv0wsNUI1W4O4PSuqanSM7u q6Pl00P/uvC6xRbXLXPAbX0yRVLkVisWp4j5g9Bu0Bu3RMhYMp8YDX+TfEt3iITUHJkp3vchWA 1X7pp2Br8s2qG3fKV9Y5loRQBdH2NCLFLlRKfFskY6Vr6IqZpmHRdyaqzd/fqdLu9Nslsx/qaE XEc= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457607" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:51 -0800 IronPort-SDR: wkilgDf7sFUNQ9SYQCq7Al0pdseoxht27KC/+URh5pPY9BBwZc8TxbfvL199WMKYChtE+pmIMM BaUJLSfafhdho0N3e5djC4wWjsL3TvEYDvc2fumURU7uXtXqRfUdpUh7rgGtaAKEt4Z1gFGlHl CFE0Ma7qLNey2kaDmDjukz3bR02QKOORuj/cQbsfzHycg9bFD/itL4o+e7HB1zGt2iq0+HIv8W AJdgva5dfYGSKhnRnjFjokxrhSQu2pNcOTEY35vBSp7P/v9WSJfy6awe4oaJM/rGt0WQ1ST44F 898= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 29/48] Input: atmel_mxt_ts - implement improved debug message interface Date: Fri, 22 Nov 2019 17:23:43 +0900 Message-ID: <20191122082402.18173-30-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 078569c13c88dcb6f8d882bfe17168587712df7d) [gdavis: Resolve forward port conflicts due to v4.14.51 commit 960fe000b1d3 ("Input: atmel_mxt_ts - fix the firmware update").] Signed-off-by: George G. Davis [gdavis: Squash fixes from Dirk Behme: - Input: atmel_mxt_ts - add missing unlock in error path - Input: atmel_mxt_ts - add missing unlock in error path - Input: atmel_mxt_ts - call mxt_debug_msg_remove() in error path - Input: atmel_mxt_ts - protect debug_v2_enabled by mutex Signed-off-by: Dirk Behme [gdavis: Squash fix from Vladimir Zapolskiy: - Input: atmel_mxt_ts - simplify debug_msg binary attribute handling] Signed-off-by: Vladimir Zapolskiy --- Notes: - Squash fixes from Dirk Behme: + Input: atmel_mxt_ts - add missing unlock in error path Unlock the mutex in case the function is exited in the error case. + Input: atmel_mxt_ts - add missing unlock in error path + Input: atmel_mxt_ts - protect debug_v2_enabled by mutex Put the modification of debug_v2_enabled into the protected section. Same as in mxt_debug_msg_enable(). + Input: atmel_mxt_ts - call mxt_debug_msg_remove() in error path Add the missing mxt_debug_msg_remove() to the error path. - Squash fix from Vladimir Zapolskiy: + Input: atmel_mxt_ts - simplify debug_msg binary attribute handling The change introduces several updates, but all of them are related to "debug_msg" binary attribute: * removed dynamic initialization of data->debug_msg_attr * removed mxt_debug_msg_write callback * removed wrong check in mxt_debug_msg_remove() * mxt_debug_msg_remove() now is not called from mxt_free_object_table() avoiding multiple double deallocations. [jiada: Add NULL check for sysfs attribute debug_msg_attr] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 194 ++++++++++++++++++++++- 1 file changed, 192 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 6f4274a1c7e0..db91caff40e4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -242,6 +242,8 @@ enum t100_type { #define MXT_PIXELS_PER_MM 20 +#define DEBUG_MSG_MAX 200 + struct mxt_info { u8 family_id; u8 variant_id; @@ -336,6 +338,11 @@ struct mxt_data { u8 t100_aux_area; u8 t100_aux_vect; bool debug_enabled; + bool debug_v2_enabled; + u8 *debug_msg_data; + u16 debug_msg_count; + struct bin_attribute *debug_msg_attr; + struct mutex debug_msg_lock; u8 max_reportid; u32 config_crc; u32 info_crc; @@ -468,6 +475,144 @@ static void mxt_dump_message(struct mxt_data *data, u8 *message) data->T5_msg_size, message); } +static void mxt_debug_msg_enable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_msg_data = kcalloc(DEBUG_MSG_MAX, + data->T5_msg_size, GFP_KERNEL); + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + return; + } + + data->debug_v2_enabled = true; + mutex_unlock(&data->debug_msg_lock); + + dev_dbg(dev, "Enabled message output\n"); +} + +static void mxt_debug_msg_disable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (!data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_v2_enabled = false; + + kfree(data->debug_msg_data); + data->debug_msg_data = NULL; + data->debug_msg_count = 0; + mutex_unlock(&data->debug_msg_lock); + dev_dbg(dev, "Disabled message output\n"); +} + +static void mxt_debug_msg_add(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + mutex_lock(&data->debug_msg_lock); + + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + dev_err(dev, "No buffer!\n"); + return; + } + + if (data->debug_msg_count < DEBUG_MSG_MAX) { + memcpy(data->debug_msg_data + + data->debug_msg_count * data->T5_msg_size, + msg, + data->T5_msg_size); + data->debug_msg_count++; + } else { + dev_dbg(dev, "Discarding %u messages\n", data->debug_msg_count); + data->debug_msg_count = 0; + } + + mutex_unlock(&data->debug_msg_lock); + + sysfs_notify(&data->client->dev.kobj, NULL, "debug_notify"); +} + +static ssize_t mxt_debug_msg_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, size_t bytes) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct mxt_data *data = dev_get_drvdata(dev); + int count; + size_t bytes_read; + + if (!data->debug_msg_data) { + dev_err(dev, "No buffer!\n"); + return 0; + } + + count = bytes / data->T5_msg_size; + + if (count > DEBUG_MSG_MAX) + count = DEBUG_MSG_MAX; + + mutex_lock(&data->debug_msg_lock); + + if (count > data->debug_msg_count) + count = data->debug_msg_count; + + bytes_read = count * data->T5_msg_size; + + memcpy(buf, data->debug_msg_data, bytes_read); + data->debug_msg_count = 0; + + mutex_unlock(&data->debug_msg_lock); + + return bytes_read; +} + +static struct bin_attribute debug_msg_attr = { + .attr = { + .name = "debug_msg", + .mode = 0444, + }, + .read = mxt_debug_msg_read, +}; + +static int mxt_debug_msg_init(struct mxt_data *data) +{ + /* + * Binary attribute is not used in callback, removal is done by name, + * so it is safe to update a single struct bin_attribute entity + */ + debug_msg_attr.size = data->T5_msg_size * DEBUG_MSG_MAX; + + if (sysfs_create_bin_file(&data->client->dev.kobj, + &debug_msg_attr) < 0) { + dev_err(&data->client->dev, "Failed to create %s\n", + debug_msg_attr.attr.name); + return -EINVAL; + } + + data->debug_msg_attr = &debug_msg_attr; + + return 0; +} + +static void mxt_debug_msg_remove(struct mxt_data *data) +{ + if (data->debug_msg_attr) { + sysfs_remove_bin_file(&data->client->dev.kobj, + data->debug_msg_attr); + data->debug_msg_attr = NULL; + } +} + static int mxt_wait_for_completion(struct mxt_data *data, struct completion *comp, unsigned int timeout_ms) @@ -1259,6 +1404,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (dump) mxt_dump_message(data, message); + if (data->debug_v2_enabled) + mxt_debug_msg_add(data, message); + return 1; } @@ -2677,6 +2825,10 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_debug_msg_init(data); + if (error) + goto err_free_sysfs; + if (data->cfg_name) { error = request_firmware_nowait(THIS_MODULE, true, data->cfg_name, @@ -2686,16 +2838,18 @@ static int mxt_initialize(struct mxt_data *data) if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - goto err_free_sysfs; + goto err_free_dbg_msg; } } else { error = mxt_configure_objects(data, NULL); if (error) - goto err_free_sysfs; + goto err_free_dbg_msg; } return 0; +err_free_dbg_msg: + mxt_debug_msg_remove(data); err_free_sysfs: mxt_sysfs_remove(data); return error; @@ -3357,6 +3511,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) return ret; data->in_bootloader = true; + mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); @@ -3540,6 +3695,34 @@ static ssize_t mxt_debug_enable_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%c\n", c); } +static ssize_t mxt_debug_notify_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "0\n"); +} + +static ssize_t mxt_debug_v2_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + if (i == 1) + mxt_debug_msg_enable(data); + else + mxt_debug_msg_disable(data); + + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static ssize_t mxt_debug_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -3578,6 +3761,9 @@ static DEVICE_ATTR(update_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, mxt_debug_enable_store); +static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, + mxt_debug_v2_enable_store); +static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3586,6 +3772,8 @@ static struct attribute *mxt_attrs[] = { &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, &dev_attr_debug_enable.attr, + &dev_attr_debug_v2_enable.attr, + &dev_attr_debug_notify.attr, NULL }; @@ -3874,6 +4062,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) init_completion(&data->chg_completion); init_completion(&data->reset_completion); init_completion(&data->crc_completion); + mutex_init(&data->debug_msg_lock); data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ? MXT_SUSPEND_T9_CTRL : MXT_SUSPEND_DEEP_SLEEP; @@ -3932,6 +4121,7 @@ static int mxt_remove(struct i2c_client *client) disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); From patchwork Fri Nov 22 08:23:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257413 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F956C1 for ; Fri, 22 Nov 2019 08:26:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB18320714 for ; Fri, 22 Nov 2019 08:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbfKVIZ4 (ORCPT ); Fri, 22 Nov 2019 03:25:56 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62576 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbfKVIZy (ORCPT ); Fri, 22 Nov 2019 03:25:54 -0500 IronPort-SDR: 0PulPbwHco7Vk4EGGig3UQuazAxBSR0dyIQaTWeax7PBYX7mxP10mUQJI2GGgTLj6EguHf3WBB jAwaIFfUG7xQFsJXla33CT9ZetmsDG5MQTIUKSEc+q0LIMwWk7boI9Thz+68VmFqrsRC8Bjko9 3RYSq96D2prQNNKnbVpwIkHZVOv0hltKnk1cJutFqO9rVbffNvofeIR6UkKTD/All+pLHqOnEw ovfoWpzgwFPez8liKfSg7srMDUVI262HCzm2JogDqBZyaxRe3JY7JI6afVN4EYKi/U2gJA5C4q pd8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457612" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:54 -0800 IronPort-SDR: d1E7AVh7BzY1dPhf0PvWFshUe4bo1Ygcf5fwWplQZ+juaVyNy27JUfbdr8edmFi/BSFK+EF5rJ 2ZZrYL+HEYEE8zB4EfzPYIhR4djPPkVzVb9VXX71x1D1r0KKFGsggWjtfaxf6T/LgS+xhqVqf5 u6/WALKpLukLcjgR7QHxFW0xgJL6yZAuKGjWhfGcB1MNn2OdxwB+HzlHBrnRwXvmcmZbmNPQAR 7s5JDkASU+qt9i2M7+73lPqXkSlUEjnWGTYwGYPTH/h793h6jgQG1rWxKeFIIUo440BOg8xOe6 OnI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 30/48] Input: atmel_mxt_ts - eliminate data->raw_info_block Date: Fri, 22 Nov 2019 17:23:44 +0900 Message-ID: <20191122082402.18173-31-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Dynamically allocated in mxt_read_info_block() buffer buf is assigned both to data->info and data->raw_info_block, having both data->info and data->raw_info_block is redundant and confusing. This patch eliminates data->raw_info_block. Signed-off-by: Jiada Wang Signed-off-by: George G. Davis Signed-off-by: Vladimir Zapolskiy --- drivers/input/touchscreen/atmel_mxt_ts.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index db91caff40e4..54e2d5f81af9 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -323,7 +323,6 @@ struct mxt_data { char phys[64]; /* device physical location */ struct mxt_object *object_table; struct mxt_info *info; - void *raw_info_block; unsigned int irq; unsigned int max_x; unsigned int max_y; @@ -2070,9 +2069,8 @@ static void mxt_free_object_table(struct mxt_data *data) v4l2_device_unregister(&data->dbg.v4l2); #endif data->object_table = NULL; + kfree(data->info); data->info = NULL; - kfree(data->raw_info_block); - data->raw_info_block = NULL; kfree(data->msg_buf); data->msg_buf = NULL; data->T5_address = 0; @@ -2241,7 +2239,7 @@ static int mxt_read_info_block(struct mxt_data *data) u8 *crc_ptr; /* If info block already allocated, free it */ - if (data->raw_info_block) + if (data->info) mxt_free_object_table(data); /* Read 7-byte ID information block starting at address 0 */ @@ -2292,7 +2290,6 @@ static int mxt_read_info_block(struct mxt_data *data) goto err_free_mem; } - data->raw_info_block = id_buf; data->info = (struct mxt_info *)id_buf; dev_info(&client->dev, From patchwork Fri Nov 22 08:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257415 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C893114C0 for ; Fri, 22 Nov 2019 08:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B349E2071B for ; Fri, 22 Nov 2019 08:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727600AbfKVI0C (ORCPT ); Fri, 22 Nov 2019 03:26:02 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62576 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbfKVIZ6 (ORCPT ); Fri, 22 Nov 2019 03:25:58 -0500 IronPort-SDR: GSERgvB5Cmb10KfzY9WfM7Dkb+El5A5WPYUSB5Pq8vZbQUY31GMF6tpIu2+5rSJkwv3Wf9sM+T Bw6AGM2RfqlABpxxBfefSQyIpRshtKHNi9kgMOl/CoEXLTM+m6jtHAO1G9EpJa2m3ntm7194MU ZDM+VaPoGPMRPtX5Q3X/8jLFqxL9zzN/EpSdEtM+RLjIclZkLGSC2J0pcgdheKz6e/tBukqDJE /cFOgHQgasty3/SgWrrBiJ1SK44ZnF8yX0B98z1aHrGVrv0YN4Cf8v8WAZT/RaN0nBCE9jsJIz QTc= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457614" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:25:58 -0800 IronPort-SDR: afcT+dPclJ7XnbNAcQBEKVouhsrmrrcNR1SizvifURcMGIglyvQNWSHNwqkL579z6TVAGsNoDV 7zgrTrUhFZUapZRvZFjEz0Hso0IaahWKN8nsAvWTUh8rAZv6XfvxANYzi8ajbedI2l4m+cZrf4 zS/YWGDctssG0WYR2FaGsho1TnRAv/t8l6odBhsH+fEH4FOkl0a0j02VNxvlM9qFTbhsLo5H5b gqnP68HPnm78YRZQmWoFLda97bUaCLTOtbKGQpuokGmXIS3pi92Plq0bnQec+8JMfvUdlXzWlJ AmU= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 31/48] Input: atmel_mxt_ts - Change call-points of mxt_free_* functions Date: Fri, 22 Nov 2019 17:23:45 +0900 Message-ID: <20191122082402.18173-32-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Revamping the code to call mxt_free_object_table and mxt_free_input_device functions only in the following scenarios and code paths: 1) The error path of the mxt_probe() entry point 2) The mxt_remove de-init path entry point 3) All paths which definitely expect to populate the object table like: - the mxt_update_fw_store path which first calls mxt_load_fw and then resorts to calling mxt_initialize itself. - the mxt_read_info_block function which attempts to fill in the object table itself as the main non-error part of the logic. 4) All paths in the code expected to definitely allocate and register the input device such as: - the mxt_update_fw_store path which first calls mxt_load_fw and then resorts to calling mxt_initialize itself. - the mxt_update_cfg_store function which will call mxt_configure_objects. Signed-off-by: Kautuk Consul Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 54e2d5f81af9..acbba44d604c 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3339,21 +3339,21 @@ static int mxt_configure_objects(struct mxt_data *data, error = mxt_init_t7_power_cfg(data); if (error) { dev_err(dev, "Failed to initialize power cfg\n"); - goto err_free_object_table; + return error; } if (cfg) { error = mxt_update_cfg(data, cfg); if (error) { dev_warn(dev, "Error %d updating config\n", error); - goto err_free_object_table; + return error; } } if (data->multitouch) { error = mxt_initialize_input_device(data); if (error) - goto err_free_object_table; + return error; } else { dev_warn(dev, "No touch object detected\n"); } @@ -3361,10 +3361,6 @@ static int mxt_configure_objects(struct mxt_data *data, mxt_debug_init(data); return 0; - -err_free_object_table: - mxt_free_object_table(data); - return error; } /* Configuration crc check sum is returned as hex xxxxxx */ @@ -4100,16 +4096,21 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) error = mxt_initialize(data); if (error) - return error; + goto err_free_object; error = sysfs_create_group(&client->dev.kobj, &mxt_fw_attr_group); if (error) { dev_err(&client->dev, "Failure %d creating fw sysfs group\n", error); - return error; + goto err_free_object; } 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) From patchwork Fri Nov 22 08:23:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257419 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F196188B for ; Fri, 22 Nov 2019 08:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A1F720708 for ; Fri, 22 Nov 2019 08:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbfKVI0G (ORCPT ); Fri, 22 Nov 2019 03:26:06 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62576 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727602AbfKVI0D (ORCPT ); Fri, 22 Nov 2019 03:26:03 -0500 IronPort-SDR: bNSpA08vu544cPXokNX3bfqXVKaKYKrzf5g5+bCs12n0ezR+Rl0W71mEvsOHQdQatYjCwg8qI1 SFtHN3/W6/a8o6SZyxEHqjpN1cw/mcsVUSz6iZKV0uEX9craM81ykwjm/TaEsq2tJN76goBwiX rBtb8CsYjXO63Jsf5Ouc2lnRWHWDBtFDlZBDhSqxU2lbPq5DjbqcFKJHS5mh0s1zMzbLvkPv80 CRTPbhhEPL4k0pS+vSYqTuQ1mt+vhkg8BzcefzsLTJxd5eKvzTpRS7ojsPySvXatwSQAxqTrZ+ 7eI= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457617" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:02 -0800 IronPort-SDR: UioE6kYJSFYFyNAu85mw+hETNmUzPAiLLhz0U2/BSqXUaaa9b/JRS2EcwYGjSNY2DA5eBNXbFC EK/kK5F8nFh95L24sj8h+1+xZktvXR51O9nrZkqwxDDwwOLK9PBQ7fCDwsMtVfY+3As7p5B9bu OoMMdjIEWJdWgkqNdM0XqvVju3lNcJtagK/FwMYufptmlVmbKM7Il6YXy8PGbDd9QSgxpDHLZD CkV2+7EycZSxZ+OmmM7ESGN+TdABf6i5xzwe0DDwZo2rgyg1KpN2lomw9oH8EfIDSnyKWvSkVO 9ws= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 32/48] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Fri, 22 Nov 2019 17:23:46 +0900 Message-ID: <20191122082402.18173-33-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 acbba44d604c..3513413158c3 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1908,7 +1908,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 */ @@ -1971,30 +1971,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) + @@ -2018,14 +1994,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 Fri Nov 22 08:23:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257417 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4632F1593 for ; Fri, 22 Nov 2019 08:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FAD520672 for ; Fri, 22 Nov 2019 08:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727624AbfKVI0H (ORCPT ); Fri, 22 Nov 2019 03:26:07 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62576 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbfKVI0G (ORCPT ); Fri, 22 Nov 2019 03:26:06 -0500 IronPort-SDR: mWpYpRVWBUQqtFNXBGa5e9AixcM/NZo4ZIEax3bHzvtL8IXKGlBKvWiyfvEfHZ9/NYGLnJdRqy XLNIWigDaHV8yKpthb6sAJTyM0FfU5/q2APLYrGkZTuVIw1Y7cEA2m8Jna18cRV7UcVieDZCqw avwSDBKJKFQkjHymQl+IFlqzjyi6lIF2jpU/7b+Yd7aygKiqnQGLPLO5DUlmXiAUKQJekRn1Rr eSqf/pDS/J/N6NY3QsMO8OgdZxHsYN1WrrFRSgjJ25F5FclnEXffLKBx66Dzl8oQyzaTqhi8wf 3cs= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457621" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:06 -0800 IronPort-SDR: d9uHHP1QH23UTNue8XH0UmkzlCYjD/XiC3HyU8PpzRICQqy7CAi6iN7NxNl3BA0nCObtLd3M5I zbGxzYnYyLIraEyPwchcdJApmm/m854B7GENPOF2aymknBbHcN917l4p1grTuEffNNmXBy6hbZ B/5Ca6WxgpJVdWpvodnInEmrZF9aQ/6qS267UWL18QtUY5VDIEFFcNN3AkA34tSZqsvRFUrCtN pVp/8y8duXjyOlrCiBom4iO2unUY45UlSAHEgIXwPRoSgLu+/0wmTI+zmsD0pVbsZirnErN5SP Mxg= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 33/48] input: atmel_mxt_ts: export GPIO reset line via sysfs Date: Fri, 22 Nov 2019 17:23:47 +0900 Message-ID: <20191122082402.18173-34-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: "George G. Davis" N.B. Modifying the atmel_mxt_ts GPIO reset line during operation will cause problems with normal driver operation. This feature is provided as a diagnostic debug aid. It does not take into consideration any pending operations which may be in progress. Modifying the atmel_mxt_ts GPIO reset line at any time will inevitably cause the driver to fail. Signed-off-by: George G. Davis Signed-off-by: Rajeev Kumar Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 3513413158c3..f357d353447f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4085,6 +4085,19 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } + if (data->reset_gpio) { + error = gpiod_export(data->reset_gpio, 0); + if (error) + return error; + + error = gpiod_export_link(&client->dev, "reset", + data->reset_gpio); + if (error) { + gpiod_unexport(data->reset_gpio); + return error; + } + } + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { error = mxt_acquire_irq(data); if (error) @@ -4117,6 +4130,10 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) err_free_object: mxt_free_input_device(data); mxt_free_object_table(data); + if (data->reset_gpio) { + sysfs_remove_link(&client->dev.kobj, "reset"); + gpiod_unexport(data->reset_gpio); + } return error; } @@ -4126,6 +4143,10 @@ static int mxt_remove(struct i2c_client *client) disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + if (data->reset_gpio) { + sysfs_remove_link(&client->dev.kobj, "reset"); + gpiod_unexport(data->reset_gpio); + } mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); From patchwork Fri Nov 22 08:23:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257421 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 162EE1871 for ; Fri, 22 Nov 2019 08:26:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EAC8E20672 for ; Fri, 22 Nov 2019 08:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbfKVI0P (ORCPT ); Fri, 22 Nov 2019 03:26:15 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:23065 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfKVI0N (ORCPT ); Fri, 22 Nov 2019 03:26:13 -0500 IronPort-SDR: O7W54g9Zc1mfeqZ7QL3yZZBXBaMiEr6piTzJiNHzHEsy+1De8bjC60CLhkp96WTeuMGH9wXCMb zqmQcCdmab/9gkY0D3ZfzY1q3bTWL+knnFUSjyWWuynTq7jhlhQUC4wJg2xhHqW2gFtwvmzlTa rg5othlFxXTMibkqKbXOn1ElH+AXsFXT8ZfC2MlRuh1gNLIaY35eixcKFOE2AR4Y/kwe/aRidU njK+6MXeyC0Ihx9eqAY4sjCYnUl8heC2vUsr8r98vZqYCLXIvhR7EMdcUboOPj7o1FpE/c1wQZ CRM= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291168" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:12 -0800 IronPort-SDR: 95vGJvZy7P4A4RfrXVys4fungW696IkjKtZ4DNEoq8GnRe9DywS5XuVq2x3BNd5n0w0SuER+mI CCKnMtzqECMf+yNb8700wyq9twk/ldtKomgPZxre0NX0641+DodnG76Vk2Rv4e17LHw0rDW1oO ggBP37QNrolrvJyy5cDtLKCVE+9t2nQ4muur5WSveS9rZDIer0viqkfmrBAf7IeluerSUSe3EU kcW4lJEiP/HhMavlHIMDJYQJu5FbuNIz57kIFi721+RuRsNJrhEaCgiDG38azdETwptpWhHU/l Tjo= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 34/48] input: atmel_mxt_ts: Add Missing Delay for reset handling of Atmel touch panel controller in detachable displays. Date: Fri, 22 Nov 2019 17:23:48 +0900 Message-ID: <20191122082402.18173-35-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 f357d353447f..835cc7a29c2f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4112,6 +4112,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 Fri Nov 22 08:23:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B67236C1 for ; Fri, 22 Nov 2019 08:26:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9736020708 for ; Fri, 22 Nov 2019 08:26:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbfKVI0S (ORCPT ); Fri, 22 Nov 2019 03:26:18 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:23065 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfKVI0R (ORCPT ); Fri, 22 Nov 2019 03:26:17 -0500 IronPort-SDR: nvcvKgWq2RkXSypJPTbaRnCmoaJIP4UtSGlMHVl1fMwfpDWGKbmx3AYBtdCkCf4w7VE2MyY596 XE8Pb34L/BRbviVK1z+Jcb2x91EeNISeRJTvIxp59Ay30pwd1C2rhvJ8XGFp7jpBcFH7h681Zh lzYqFX8dhHzOkrnlbhVanO2XCK214rvLQwdyzdpRkoG98EcR+YKYWHZvNHtR+Vc439whdGp5A3 MtKjpaovoV5hm25wMniZPvBtR3zkYoeB8KBDGjB95o5ZR6QHDVBoa4hxRctmQLmUsos49FyvVj Bg8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291170" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:16 -0800 IronPort-SDR: Kis2qeohNWaflC5V6fBg+LsY8V4rTrV0g5d8yWnPUnTPEGxq1ktOT+EMhm4s5C/GqV+wzKf96U Nhj/GwjBdHpXL8K3LRnf3mUVWi8YiHB3rSzwJwrv1X+PTnLYTXTURoea5BtY4Fdinx2BeCB281 TzQvgonNn1z1lmvozVa/jNFiz8spP1ddFA6WqyEA64jgmsZv6XFZvpWOSjLpYO7NZLGEn40Rwt A8x1PihWKHJaQKW/h3ZjLfKm+dZ6uqWg1jBRfJrLIDhxTjWUHOBv8aYfssfM3XpjQRGbX56eoE X90= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 35/48] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Fri, 22 Nov 2019 17:23:49 +0900 Message-ID: <20191122082402.18173-36-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 835cc7a29c2f..74866015572f 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 { @@ -1359,6 +1364,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]; @@ -1389,6 +1412,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); @@ -1613,6 +1638,84 @@ 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 mxt_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 mxt_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; + + if (sscanf(buf, "%x", &cmd) == 1) { + 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; + } + return 0; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2091,6 +2194,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; @@ -2178,6 +2283,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; @@ -3764,6 +3873,7 @@ static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); +static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3774,6 +3884,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.attr, NULL }; From patchwork Fri Nov 22 08:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECF846C1 for ; Fri, 22 Nov 2019 08:26:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CED852071B for ; Fri, 22 Nov 2019 08:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727667AbfKVI0V (ORCPT ); Fri, 22 Nov 2019 03:26:21 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62590 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfKVI0V (ORCPT ); Fri, 22 Nov 2019 03:26:21 -0500 IronPort-SDR: yIzYNJRli41nIe4nEjz/Nxu1GACo24BisGR/HvPoZr4syCav1HxQx+pcTd60npUOX+9MGNaSrs jKsuL0bBK8gt3l6x2TcMYQZXNpQjOsRKuScHKz3NbnrsZBStqvEmr8DgVJK9H6JVto5BLv32a9 lEKYE2TiFskDzHzeGihrWQRXRJlaKJNi8tELclGvubFV2W55Njkzq2WDubaNK/vKfmA4RQYabl zPTj0ZID0siOUfRAGUoSf6bF6Fa+udrboxHIxhgsKOt+AXytikRa/dSKP35Z3r8S4+3K9EuaPP fEg= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457626" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:20 -0800 IronPort-SDR: t6jf3W1i1xNTlb/PWrS7U5etSeJoOSh81wdIz+EGWUnkTiwi1t0MYBgxbw6JD+o8r9T/snKyDt s7PV7ifRqBE6xxqoDDUdhDPqLW1vKspP+IUoPOn6kNAriFEpMM3lnKJi4/2z+jG+YoP0+cRf+I dX86cJiiZb1FZBhaD4U8zmDph6LGbTkX2XNG3+LusKBUBIYsqboIUWRvAdQQmSfRbKVZ57qEUk 9TVttOvh6CjKabg0l3Q+B8MphFugI79DI5eVrydgMjbSVRMVo+4Czc64TLw1oeuKZKTIhI6sGk 3jM= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 36/48] Input: atmel_mxt_ts: Limit the max bytes transferred in an i2c transaction Date: Fri, 22 Nov 2019 17:23:50 +0900 Message-ID: <20191122082402.18173-37-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: Balasubramani Vivekanandan In mxt_process_messages_until_invalid() function, driver tries to read all possible reportid in a single i2c transaction. Number of bytes read is limited by the max_reportid parameter. If the max_reportid is a very large value, then a large chunk of bytes will be requested from the controller in a single i2c transaction. This transaction can fail due to timeout. This is visible when the Atmel controller is connected to the SOC via a i2c mux hardware. mxt_process_messages_t44() reads the T44 message which contains the pending T5 message count. If the number of pending T5 messages returned by T44 message is too high then there is a risk of i2c transaction timeout while reading T5 messages in mxt_process_messages_t44(). New property 'atmel,mtu' is created. This property limits the maximum number of bytes that can read/transferred in an i2c transcation Signed-off-by: Balasubramani Vivekanandan Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 3 + drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++++---- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index d7db16920083..62c93d94bc5d 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -42,6 +42,8 @@ Optional properties for main touchpad device: - atmel,input_name: Override name of input device from the default. +- atmel,mtu: Maximum number of bytes that can read/transferred in an i2c transaction + Example: touch@4b { @@ -49,4 +51,5 @@ Example: reg = <0x4b>; interrupt-parent = <&gpio>; interrupts = ; + atmel,mtu = <200> }; diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 74866015572f..054aacc768b8 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -417,6 +417,7 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + unsigned int mtu; bool t25_status; }; @@ -1465,11 +1466,32 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) return num_valid; } +static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) +{ + u8 T5_msg_count_limit = data->mtu / data->T5_msg_size; + + if (!data->mtu) + return max_T5_msg_count; + + if (data->mtu < data->T5_msg_size) { + WARN(1, "mtu set is lesser than the T5 message size\n"); + /* Return count of 1, as fallback */ + return 1; + } + /* + * Return maximum number of T5 messages in single i2c transaction + * based on "atmel,mtu" property. + */ + return min(T5_msg_count_limit, max_T5_msg_count); +} + static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; - u8 count, num_left; + u8 T5_msg_count, total_pending; + u8 total_processed = 0; + u8 processed_valid = 0; /* Read T44 and T5 together */ ret = __mxt_read_reg(data->client, data->T44_address, @@ -1479,18 +1501,19 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - count = data->msg_buf[0]; + T5_msg_count = data->msg_buf[0]; /* * This condition may be caused by the CHG line being configured in * Mode 0. It results in unnecessary I2C operations but it is benign. */ - if (count == 0) + if (!T5_msg_count) return IRQ_NONE; - if (count > data->max_reportid) { - dev_warn(dev, "T44 count %d exceeded max report id\n", count); - count = data->max_reportid; + if (T5_msg_count > data->max_reportid) { + dev_warn(dev, "T44 count %d exceeded max report id\n", + T5_msg_count); + T5_msg_count = data->max_reportid; } /* Process first message */ @@ -1500,16 +1523,25 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - num_left = count - 1; + total_pending = T5_msg_count - 1; + if (!total_pending) + goto end; /* Process remaining messages if necessary */ - if (num_left) { - ret = mxt_read_and_process_messages(data, num_left); + T5_msg_count = mxt_max_msg_read_count(data, total_pending); + + do { + if ((total_pending - total_processed) < T5_msg_count) + T5_msg_count = total_pending - total_processed; + ret = mxt_read_and_process_messages(data, T5_msg_count); if (ret < 0) goto end; - else if (ret != num_left) - dev_warn(dev, "Unexpected invalid message\n"); - } + total_processed += T5_msg_count; + processed_valid += ret; + } while (total_processed < total_pending); + + if (processed_valid != total_pending) + dev_warn(dev, "Unexpected invalid message\n"); end: if (data->update_input) { @@ -1524,9 +1556,10 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) { struct device *dev = &data->client->dev; int count, read; - u8 tries = 2; + int tries; - count = data->max_reportid; + count = mxt_max_msg_read_count(data, data->max_reportid); + tries = (data->max_reportid / count) + 1; /* Read messages until we force an invalid */ do { @@ -4112,6 +4145,10 @@ static int mxt_parse_device_properties(struct mxt_data *data) } device_property_read_u32(dev, "atmel,suspend-mode", &data->suspend_mode); + device_property_read_u32(dev, "atmel,mtu", &data->mtu); + if (data->mtu) + dev_dbg(dev, "mtu is set as %d\n", data->mtu); + return 0; } From patchwork Fri Nov 22 08:23:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99D3D1593 for ; Fri, 22 Nov 2019 08:26:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85B472070E for ; Fri, 22 Nov 2019 08:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfKVI0Z (ORCPT ); Fri, 22 Nov 2019 03:26:25 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52542 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726554AbfKVI0Y (ORCPT ); Fri, 22 Nov 2019 03:26:24 -0500 IronPort-SDR: MgzCr4Y+OvHazrB/sbK1R4XFjM4vAxEqIeD6x/PxzBfxQDdk5I7CC/2rtz2RVeGl/8KBEpiCwR e5gibqYXfM5V+XsFkMueOxHufOKEkA5gfvy2hRHCBanYDv1sCO/xIsF0JVW/x2kSTErD+xJ/Ew Qx2irjbO2d/UlcUGDpK0vXJNNh8IdtiflJK2WsmB+H/nKcGTFY1hJnKYtEFcywoIlmC9wda2VI gP+GRrFxTFBvixXaSqAk2UE/79+q5/ExcI9B1uh3T3g3KEpN0lAOhKbspyzoe237N3ASeb+L2p tns= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358973" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:23 -0800 IronPort-SDR: NovqKH9ZCndvBlGwCA9ax4Neqe1mUqUpc86PgIE1FKWkb8HZnY767l8N0IHX9ykyAs/Dc7UVl0 5R7X+jM/N9AuryY+DcWypzhNFN2Tw4Q1ZjZsjedC4ofnPKKXb5kFd3dE7ygT05jqajyRWmksjI jc5EOnnzYS4uBH/eQ6jn47+YMWbEGja9KG3KPvUx413xb6lExUv5FIGebEIBLKCvZ7L65Fon3c 6LVVI9mFmxxXxkHoYcMj5ieI0Jk4BoByQIhWEuS3qu0LMYegj9iy87amr5UR0g6LqdvxB1bUG5 MUs= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 37/48] Input: atmel_mxt_ts: return error from mxt_process_messages_until_invalid() Date: Fri, 22 Nov 2019 17:23:51 +0900 Message-ID: <20191122082402.18173-38-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 054aacc768b8..a5af1f91d704 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1564,6 +1564,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 Fri Nov 22 08:23:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B313E1871 for ; Fri, 22 Nov 2019 08:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DF7D20714 for ; Fri, 22 Nov 2019 08:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbfKVI03 (ORCPT ); Fri, 22 Nov 2019 03:26:29 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52542 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727684AbfKVI02 (ORCPT ); Fri, 22 Nov 2019 03:26:28 -0500 IronPort-SDR: A2FizKez/TzSTNeVIsmqayaDj7Q70IhP+Fs2gAMEgGiLoL3wOef4dapzbLcBkto0uHA0Us8iT+ ZykxH6AA2dGVKlKJAXbyiITC6ci9r/N7QF8uzV5S+omDGpOEx0DkOzNcpNGCoNzabTJDTQlhRQ o+vCVeGNMMKnp0hD+aVz298G0kS7GVpqt7xmGHDrxcEbZYtF78mkZoLQRXqaaQ90jsxA+yx63y UL/SHr0VZkaj++a1mMcBBf9u5JvhotUDUKpq3GXZVKE54naTX1VcBZBanvEc6AUxYHCmArLCxn t78= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358977" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:27 -0800 IronPort-SDR: X36I+h29kYB8JKFqBgPfVSadAyhw1J0RpcInGTjZNM4Em+v2OSBRgAbEPFXQnidm2scBycIeBW cegempuayYyTa7L0FgO6X8J0B47r+yxRvEEsykgNPbvF+do15BEq7zkbu/SI9yKu98e/C4snUi chfbKycYNaH+maUPG8joOeM/P0P0A6LyVvGZMURm71jW1lfJQeXVUqY6qRSvYc7vxMmVpAmPbu DvhDYsoDXO5VCyBhW7XuRNDX/Py0b8dr2ryJFVjDatahPoqMgSx9IkDJH1chk/s+/bGA52/zON nzQ= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 38/48] Input: Atmel: improve error handling in mxt_start() Date: Fri, 22 Nov 2019 17:23:52 +0900 Message-ID: <20191122082402.18173-39-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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_start() does not return error in any of the failure cases which will allow input_dev->open() to return success even in case of any failure. This commit modifies mxt_start() to return error in failure cases. Signed-off-by: Deepak Das Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a5af1f91d704..1ebdca1ed815 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3974,12 +3974,13 @@ static int mxt_start(struct mxt_data *data) switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: - mxt_soft_reset(data); - + ret = mxt_soft_reset(data); + if (ret) + break; /* Touch enable */ /* 0x83 = SCANEN | RPTEN | ENABLE */ - mxt_write_object(data, - MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); + ret = mxt_write_object(data, + MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); break; case MXT_SUSPEND_REGULATOR: @@ -3993,27 +3994,26 @@ static int mxt_start(struct mxt_data *data) * Discard any touch messages still in message buffer * from before chip went to sleep */ - mxt_process_messages_until_invalid(data); + ret = mxt_process_messages_until_invalid(data); + if (ret) + break; ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); if (ret) - return ret; + break; /* Recalibrate since chip has been in deep sleep */ ret = mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); if (ret) - return ret; + break; ret = mxt_acquire_irq(data); - if (ret) - return ret; - - break; } - data->suspended = false; + if (!ret) + data->suspended = false; - return 0; + return ret; } static int mxt_stop(struct mxt_data *data) @@ -4333,6 +4333,7 @@ static int __maybe_unused mxt_resume(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct mxt_data *data = i2c_get_clientdata(client); struct input_dev *input_dev = data->input_dev; + int ret = 0; if (!input_dev) return 0; @@ -4340,11 +4341,11 @@ static int __maybe_unused mxt_resume(struct device *dev) mutex_lock(&input_dev->mutex); if (input_dev->users) - mxt_start(data); + ret = mxt_start(data); mutex_unlock(&input_dev->mutex); - return 0; + return ret; } static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); From patchwork Fri Nov 22 08:23:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257427 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F07AD1871 for ; Fri, 22 Nov 2019 08:26:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9DBA2070E for ; Fri, 22 Nov 2019 08:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbfKVI0c (ORCPT ); Fri, 22 Nov 2019 03:26:32 -0500 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:52542 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbfKVI0b (ORCPT ); Fri, 22 Nov 2019 03:26:31 -0500 IronPort-SDR: jZb8rEf5D3G7+52Sl1pHZ+V3lBdHpClphYcFHx3wSpLNOnL0HbGGm3mv0EJmBDpszkx+fx/KUX YAoi1K2ARRYrQMWzTuc7qln5k9QK/N8XdB6WRP5M8omtDdw3G5tLQtk74SbdMSxmvOQvT+nChn 5DYmUlLmT4IjMS+r4xlAKtej2oxHKA1Sosb3bJYDV2b+r3JgtVmCrhBJZc+AT3KTd8D85DAha6 tdDrIz5QWgIuKxkSaBeekN48hljThlETvmsaBJ6eqFrGwYbc3+MY+oAFtdpqRMn6PFm8KKe2FX /eA= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43358982" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:31 -0800 IronPort-SDR: piiUQaiULY+leSG0xY+rRPmJsOzuSqA9g+H/ui5eXhCIcWRpxlDFIU+yTiPv++hvouq7bXNrPq JfDT81rlmI8rOFGbd0QvL95YvI+AGfjRhA1S9zMrplMkQqKMnHAPgcO0CUsG54xPrGhEYIjYh4 8r/ro7MXjgt6gqNstj0fT5MKvjdEFKe+DDhW17663eGfnUYvno7TCztOscaMAuWVlqer7USJnX W23IBASG+NBRhDbSOq3hgW9XXoPoFm1sowdIPd9j7zAmLlcgP9cARZd7sRHz4yu77hBvYPx26Y m4M= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 39/48] Input: Atmel: improve error handling in mxt_initialize() Date: Fri, 22 Nov 2019 17:23:53 +0900 Message-ID: <20191122082402.18173-40-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 1ebdca1ed815..110c966e7f3a 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) @@ -2923,6 +2919,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; @@ -2934,16 +2956,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) { @@ -2957,7 +2976,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); } @@ -3649,8 +3670,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 Fri Nov 22 08:23:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257431 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74DCA6C1 for ; Fri, 22 Nov 2019 08:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F3302071F for ; Fri, 22 Nov 2019 08:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727130AbfKVI0h (ORCPT ); Fri, 22 Nov 2019 03:26:37 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4485 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726887AbfKVI0f (ORCPT ); Fri, 22 Nov 2019 03:26:35 -0500 IronPort-SDR: X8nzEv9CkszHrMqWs2Cn5Wt66os8qBWEgXHc5S4D/fXg03w4QsHvgzsD39ltMDSJQax6tKXORU Jm9G4N3OL9d/59dprwMTMvDedSqS2YIIB+mv8TqIDvdNW9v9Cgxzmkp2rhNg82IPsayIRy/Q6M uk+zRyckdLj7vLgM0ZGkkcbZ7RqhqJA6VAeiHnoEwLtkO22DcUntkVPMhgpiMu7urOl7WyZkZ/ w8mGZdea4NBM5iLVlcgPnPn3UpdrE0voxAI/i3ta3vwH74AcDAhlbtiw1a3r8kIsrcV238iQ9O u80= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419509" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:35 -0800 IronPort-SDR: eMBpF+qqcc94Gu8//rsvd4oNWAT7u58kxzZJNGumGQxAFgxz9ba562TU+xg19KPcX+20yuVW3y e+RudaxAMODHwxU/XIRi/VJCjT2BC78p7yqkpPkC/KPZNcuPTlnlJ5v/YOkznyutbRWXMS9h5X 9+alIxLLKJe+xL/or3QebaCj+faUNBYqXmNvwHJe7CFBl+TKccspjIcR1Y6vHrSyDK+2L+sDa4 3A0B8e7cY3tj2u6njJfHIN7nwvYBPasljQMBesPSvhSVqqiMN7tKtgCBPJv2eBbkjrC7/oXanM whA= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 40/48] Input: Atmel: improve error handling in mxt_update_cfg() Date: Fri, 22 Nov 2019 17:23:54 +0900 Message-ID: <20191122082402.18173-41-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 110c966e7f3a..92af95bd4eed 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2186,7 +2186,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 Fri Nov 22 08:23:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257435 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A1EF1593 for ; Fri, 22 Nov 2019 08:26:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24A4D2071B for ; Fri, 22 Nov 2019 08:26:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727022AbfKVI0l (ORCPT ); Fri, 22 Nov 2019 03:26:41 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4485 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726887AbfKVI0k (ORCPT ); Fri, 22 Nov 2019 03:26:40 -0500 IronPort-SDR: gIY1LfrtPAyFlfYcwRBDhCrPcPs7FPZM3xqxteZNKolO6/ZvWCC7e/H6suP0n6UA/T2fOtL3Q6 gLNBMLamuwYE4ISOegZjC9oKzWipn3myjgiCdmYGdQYwXP29G7sG2h4ItgNUoVinLRNDv7PW3F T78B9xOxRx7gE1ukt1bRWLL1kq77+Vn0kcqQpVjL4YDiMQ8NyaqK4OPysfYYqnP/B/Nz2/Murb In3RfkOg+4GV78nIKhCuunApp8pw0TYotr/m4dlqy4TjLpwO0rN1yJdB6MNoIprzWt9RABUiCt WL8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419510" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:39 -0800 IronPort-SDR: rN29y0X6XJFOufnfagWqX8oKH7k7O10myPX5C8lj14fz8QmPJI/joSequSDSfXCgIznJMGFLBL Rhdtl/IWVA+QdvbMbjEU6WMLSIPf6lx7lOx6s5mTWK8I0Yl8xU1iH+TZDm331Fa3MZ6O+UmXTX bUz23HjjUwzaYfHeMvOIUpD8Si2drcXtWSMK35IBj8/miJhrhSBVR3dsl0o2YnwrqykRmugoaN bAr87bX/DroVEFzSWMSyn4Gl6hocgpL7wFFbB1+LM+wlmyBQJFwTFKf/DsV/QuOUSk3Eb6lXKK tOQ= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 41/48] Input: Atmel: Improve error handling in mxt_initialize_input_device() Date: Fri, 22 Nov 2019 17:23:55 +0900 Message-ID: <20191122082402.18173-42-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Driver probe continues with a warning message when it fails to get the proper multitouch object configurations like TouchScreen resolution. But Driver probe should fail in case of above scneario because it will not behave as expected without the proper touchscreen configurations. This commit modifies mxt_initialize_input_device() to return error when it fails to get the proper touch screen configurations. Signed-off-by: Deepak Das Signed-off-by: Dean Jenkins Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 92af95bd4eed..e3ed74e7c270 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2762,15 +2762,19 @@ static int mxt_initialize_input_device(struct mxt_data *data) case MXT_TOUCH_MULTI_T9: num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; error = mxt_read_t9_resolution(data); - if (error) - dev_warn(dev, "Failed to initialize T9 resolution\n"); + if (error) { + dev_err(dev, "Failed to initialize T9 resolution\n"); + return error; + } break; case MXT_TOUCH_MULTITOUCHSCREEN_T100: num_mt_slots = data->num_touchids; error = mxt_read_t100_config(data); - if (error) - dev_warn(dev, "Failed to read T100 config\n"); + if (error) { + dev_err(dev, "Failed to read T100 config\n"); + return error; + } break; default: From patchwork Fri Nov 22 08:23:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EDC21593 for ; Fri, 22 Nov 2019 08:26:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4955520714 for ; Fri, 22 Nov 2019 08:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbfKVI0o (ORCPT ); Fri, 22 Nov 2019 03:26:44 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4485 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727020AbfKVI0m (ORCPT ); Fri, 22 Nov 2019 03:26:42 -0500 IronPort-SDR: nUKXrlh/pIQZ7db4cRbqISlRDADkhgjt0NBfcWs94CBz1s+Do6639qW5uwORufKLmXvOP58Jt1 SHV9gBrUtAdnkKDPvGXFlKxtPv0356hLzUKTVQ5I/6tIs/PtAqT+PXVVhsN9iaf7+lBSBNyOfL el96ThDw2fTC56NsYeGk2ANegplZrQT2l0GXoKMLdL3It/gBqApWqvBg7cfUcYPxn4+/3unYo+ kc/DAPkJe14z1KiC5lNYxOGRQolLcLPymmJhtZIrlnidHQ1Dlzz/y1KTVhn/DmI443MpUhmmjD wn8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419513" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:42 -0800 IronPort-SDR: EhT1w9diO6exW+ZYwZErq89l9cksFudE+O94WET14gCjsC2dNsgjgqr2NKiW1bnjoZwOYA2O8R dubRfX9BtVD9gfIhlXPJLUuyMQSX0uAPbRkbwgVzpIVOWb9nDo1jliFfvHFOb3O94mINyQ1FHW MCCDW14ZNUZF1rTFpmT9psFiX6U1Xylfatt7RPTs9rDBlRXblG5kOE6NcHs1pJfb+Nm2H+AlAR K2FtjQYqvwP0RYM2dYh2WZgTGj18N5dAcj0lAcpIsyrMEBBERhECgPzbk2wHW3mj//nH5J1kZV xgY= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 42/48] Input: Atmel: handle ReportID "0x00" while processing T5 messages Date: Fri, 22 Nov 2019 17:23:56 +0900 Message-ID: <20191122082402.18173-43-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 e3ed74e7c270..8d6478834fd8 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 @@ -1384,6 +1385,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; @@ -1454,6 +1460,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 Fri Nov 22 08:23:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 176201593 for ; Fri, 22 Nov 2019 08:26:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01C8C2071B for ; Fri, 22 Nov 2019 08:26:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727071AbfKVI0u (ORCPT ); Fri, 22 Nov 2019 03:26:50 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62619 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727020AbfKVI0t (ORCPT ); Fri, 22 Nov 2019 03:26:49 -0500 IronPort-SDR: pHJYfNGhEFg1ri6F6ezk2XGXXR3ZQz7TzrLpx6gf6l1Ufa+AtuF6p+Z2JS3prhaht9UR3n8nwp sqC3G+z861jY0XptT6+I3WbkEQpFabL6Al88pgBD/998dl+RkVyGr+zhHNOOEV6ACN6f3lxpE8 rDGfoS5Ns+VZptEQT6tZIMSENUErjreik8b2dwCtfWJV/ZlyeVpNR8ijI87X7J8f6HhelRExIp ACUUtCzGBSbuMlS+0Wc1rGwF9YuFS9lONExrjQDjs8whAM5NwmI48lNV6aEXXAPSVwmEzUlo8H wYo= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457653" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:46 -0800 IronPort-SDR: y7Xm8bc6Q1e8ExsbyeO81oiuXSlPMCboYZgkj/R83sYwM7K9DqgPgPDoF3m7o5reQc6kunpscn 1bkrZbfjJsKlfsG7gHMjSi2mXpZkFn3iRsDQjVd+g9EQjjQRp33dgrGhfxvaO606Q1zY92Sm2X b7sQQoMTWlrimyoD7/siZ+WxERUxaNPKl+uQH7IighXownZIJSupn3Cpx5Jk8ZRi9SWMiVnoE0 m2Ro+t1Ulix06lCP6psACcSW4vCTlwOtYt0upvwFKa4ecDORc8i71KOUprWE+jMavsk4VbgxQf sLI= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 43/48] Input: Atmel: use T44 object to process T5 messages Date: Fri, 22 Nov 2019 17:23:57 +0900 Message-ID: <20191122082402.18173-44-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 8d6478834fd8..0e4a870fafa5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1489,7 +1489,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; @@ -1502,7 +1502,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]; @@ -1512,7 +1512,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", @@ -1524,12 +1524,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); @@ -1553,7 +1555,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) @@ -1583,7 +1585,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; @@ -1594,7 +1596,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; @@ -1603,7 +1605,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; @@ -1619,12 +1621,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); @@ -1632,17 +1635,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, @@ -1777,8 +1785,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; } @@ -4032,8 +4043,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 Fri Nov 22 08:23:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57B481871 for ; Fri, 22 Nov 2019 08:26:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42A842071B for ; Fri, 22 Nov 2019 08:26:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727734AbfKVI0u (ORCPT ); Fri, 22 Nov 2019 03:26:50 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62619 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727072AbfKVI0u (ORCPT ); Fri, 22 Nov 2019 03:26:50 -0500 IronPort-SDR: jpUFIyIQEBPfuQmA8XEoNm7PTEtv4Fc+Sfmd9j3IiPsJrH+91ZBTXYQ/SP/eSsXsoFU3csoLhj J4AJRxKv6i6VhJbk0eAxHYY3o3C6pidv+qtqC6ujHy4yUVrcbBr1Z4MXhYKtp70OSHF/tbP1Ph baAzIvbPoDsT5cbVgNGEGA6HVMeZeC0cbGyGhiOmYbVB6oNWp40TuT491BHUeL8cKBUBB4HeGH cP1LQ4Beh3DCHvJV20Ccia0CKbczybIq4CoZ7TgrStQr0vsbs7T90FzRBRqHlUxGZBsqo6OYsE Pq4= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457655" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:49 -0800 IronPort-SDR: qConjet9okaLhLlqlQgHx8OwITqHCYCmT43hNJlIKqK8RAQYJlIumZXQ2hYRO8anrLXkMynRJI pI7Eb9cTk3ipbbmhLe38YlWRnojOHc8hoxuY5EoPMk4rXZqEptteN6fHFHfIoKearnvfhmRRzy GSV/OVxgzSPrRN6zxrYng5zcnBeCk7sjvhY9jmevNFyS3h9aEez+x8uv6EYfnsUNdphXFbuGtk ciiK3H7Qz3JpCEISBNmM9XiFT7eAa+sDupap9iQD/cJwZ4rUVNQVb298/o0P4Qc9Elf9KyF5eU PG8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 44/48] Input: atmel_mxt_ts: use gpiod_set_value_cansleep for reset pin Date: Fri, 22 Nov 2019 17:23:58 +0900 Message-ID: <20191122082402.18173-45-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: Balasubramani Vivekanandan In case of remote display, touch controller will be also remote. In such cases, the reset pin of the touch controller will be controlled through bridging ICs like Deserilizer and Serializer. Therefore accessing the gpio pins require transactions with the external IC. Using the function gpiod_set_value will print a warning like below WARNING: CPU: 0 PID: 576 at drivers/gpio/gpiolib.c:1441 gpiod_set_value+0x34/0x60() CPU: 0 PID: 576 Comm: modprobe Not tainted 3.14.79-08377-g84ea22f-dirty #4 Backtrace: [<80011c58>] (dump_backtrace) from [<80011e60>] (show_stack+0x18/0x1c) [<80011e48>] (show_stack) from [<8052d7ac>] (dump_stack+0x7c/0x9c) [<8052d730>] (dump_stack) from [<800241bc>] (warn_slowpath_common+0x74/0x9c) [<80024148>] (warn_slowpath_common) from [<80024288>] (warn_slowpath_null+0x24/0x2c) [<80024264>] (warn_slowpath_null) from [<8029e070>] (gpiod_set_value+0x34/0x60) [<8029e03c>] (gpiod_set_value) from [<7f492e98>] (mxt_probe+0x1e0/0x718 [atmel_mxt_ts]) [<7f492cb8>] (mxt_probe [atmel_mxt_ts]) from [<803c4d34>] (i2c_device_probe+0xcc/0xec) [<803c4c68>] (i2c_device_probe) from [<803252a0>] (driver_probe_device+0xc0/0x200) Signed-off-by: Balasubramani Vivekanandan Signed-off-by: Vladimir Zapolskiy Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis 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 0e4a870fafa5..78903806c0b4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2490,7 +2490,7 @@ static void mxt_regulator_enable(struct mxt_data *data) if (!data->reg_vdd || !data->reg_avdd) return; - gpiod_set_value(data->reset_gpio, 0); + gpiod_set_value_cansleep(data->reset_gpio, 0); error = regulator_enable(data->reg_vdd); if (error) @@ -2508,7 +2508,7 @@ static void mxt_regulator_enable(struct mxt_data *data) * voltage */ msleep(MXT_REGULATOR_DELAY); - gpiod_set_value(data->reset_gpio, 1); + gpiod_set_value_cansleep(data->reset_gpio, 1); msleep(MXT_CHG_DELAY); retry_wait: @@ -4313,7 +4313,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) disable_irq(data->irq); } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); - gpiod_set_value(data->reset_gpio, 1); + gpiod_set_value_cansleep(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } else { dev_dbg(&client->dev, From patchwork Fri Nov 22 08:23:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E93F51593 for ; Fri, 22 Nov 2019 08:26:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CABD42070A for ; Fri, 22 Nov 2019 08:26:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbfKVI0y (ORCPT ); Fri, 22 Nov 2019 03:26:54 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62619 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727072AbfKVI0x (ORCPT ); Fri, 22 Nov 2019 03:26:53 -0500 IronPort-SDR: NNX/WdYnl0pgXwwvNEkVt4p71GGYcqU/hLBOHaR4DpNJ5DMB3UVK4iV5DEIMppJHjccuMmisUL yHAwauf0pmu9abZym018GohMle3wvrroWr/dtIDItD0+ky3S8BZc+EbKB8sGI37ZcINY/gtBlU 09n647lSgyjNb3CmKUzu30Z++UKT8h4vdoYPKhGbC8UiQJou9ZuK4yKQg5HGjhxqH6ih2WcaS5 BYChLC1Smbu7hSBFIZeNrqq6XYVMXjfjJJzaug9eSbtQHXzBtpDuOZ1wxL4A01Cal0A98daTWl Ohw= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457658" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:53 -0800 IronPort-SDR: NRGWBFE7DkDJ3fTnL1zZqR1VtZoWeouk2j5ZiTTkZ/HinOupN3FmKibqNznTVt+KczRSOQ4ugx Khz1HRP9CzrUFXmYc5XPN7NiaziM7tsztLYOjYUNeJPWp4FChEY+csXcrQFXHuxO4AsHa26Etl YwLtdX6cHw2WDuFxGjQBsS0KGF4QVlL1gQ0YcyKYN8Goed4TwGZSoWv1AbjMh6scU3kS0H2Gby ArajvZRtrb1OBJyp8FJpkGLKNbYyQQqmpbpN7Bwu23398hKes3Kkky1wJEGNBMnC0Sulh9OkKf 5J0= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 45/48] input: touchscreen: atmel_mxt_ts: Added sysfs entry for touchscreen status Date: Fri, 22 Nov 2019 17:23:59 +0900 Message-ID: <20191122082402.18173-46-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Signed-off-by: Naveen Chakka Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 109 +++++++++++++++++++++-- 1 file changed, 102 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 78903806c0b4..d22a00ec69c1 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -222,6 +223,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 @@ -317,6 +319,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 +380,9 @@ struct mxt_data { const char *pcfg_name; const char *input_name; struct mxt_flash *flash; + struct work_struct watchdog_work; + struct timer_list watchdog_timer; + struct mxt_statusinfo mxt_status; /* Cached parameters from object table */ u16 T5_address; @@ -1624,11 +1635,30 @@ static int mxt_process_messages(struct mxt_data *data) return total_handled; } +static void mxt_start_wd_timer(struct mxt_data *data) +{ + mod_timer(&data->watchdog_timer, jiffies + + msecs_to_jiffies(MXT_WATCHDOG_TIMEOUT)); +} + +static void mxt_stop_wd_timer(struct mxt_data *data) +{ + /* + * Ensure we wait until the watchdog timer + * running on a different CPU finishes + */ + del_timer_sync(&data->watchdog_timer); + cancel_work_sync(&data->watchdog_work); + del_timer_sync(&data->watchdog_timer); +} + 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); @@ -1636,21 +1666,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, @@ -2970,6 +3004,36 @@ static int mxt_bootloader_status(struct mxt_data *data) return 0; } +static void mxt_watchdog_timer(struct timer_list *t) +{ + struct mxt_data *data = from_timer(data, t, watchdog_timer); + + if (!work_pending(&data->watchdog_work)) { + if (!data->mxt_status.intp_triggered) + schedule_work(&data->watchdog_work); + } + + mxt_start_wd_timer(data); +} + +static void mxt_watchdog_work(struct work_struct *work) +{ + struct mxt_data *data = + container_of(work, struct mxt_data, watchdog_work); + u16 info_buf; + int ret = 0; + u8 size = 2; + + ret = __mxt_read_reg(data->client, 0, size, &info_buf); + + if (ret) { + data->mxt_status.error_count++; + data->mxt_status.dev_status = false; + } else { + data->mxt_status.dev_status = true; + } +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -3947,6 +4011,22 @@ static const struct attribute_group mxt_fw_attr_group = { .attrs = mxt_fw_attrs, }; +static ssize_t mxt_touch_device_status(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(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); @@ -3958,6 +4038,7 @@ static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); +static DEVICE_ATTR(touch_dev_stat, 0444, mxt_touch_device_status, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3969,6 +4050,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, &dev_attr_t25.attr, + &dev_attr_touch_dev_stat.attr, NULL }; @@ -4321,6 +4403,13 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_TIME); } + INIT_WORK(&data->watchdog_work, mxt_watchdog_work); + + /* setup watchdog timer */ + timer_setup(&data->watchdog_timer, mxt_watchdog_timer, 0); + + mxt_start_wd_timer(data); + error = mxt_initialize(data); if (error) goto err_free_object; @@ -4335,8 +4424,11 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return 0; err_free_object: + cancel_work_sync(&data->watchdog_work); + mxt_stop_wd_timer(data); mxt_free_input_device(data); mxt_free_object_table(data); + del_timer(&data->watchdog_timer); if (data->reset_gpio) { sysfs_remove_link(&client->dev.kobj, "reset"); gpiod_unexport(data->reset_gpio); @@ -4359,6 +4451,9 @@ static int mxt_remove(struct i2c_client *client) mxt_free_input_device(data); mxt_free_object_table(data); + cancel_work_sync(&data->watchdog_work); + mxt_stop_wd_timer(data); + return 0; } From patchwork Fri Nov 22 08:24:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 843356C1 for ; Fri, 22 Nov 2019 08:26:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 66A7B20714 for ; Fri, 22 Nov 2019 08:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbfKVI05 (ORCPT ); Fri, 22 Nov 2019 03:26:57 -0500 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:62619 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbfKVI04 (ORCPT ); Fri, 22 Nov 2019 03:26:56 -0500 IronPort-SDR: aPWFnJJfncbRd6BIwUX/gqOkeY/0L01ZvfK9fB6VNnQ6xqYO4mhW51IW0DIEz5gbN2GKaDAHNc kqilWxNfC5SNHeQ6VKcTW3rcN5oxwuR0EFGB/9iWx90pmV2TKxZrAiNIKC/qQ7c2VPXzYX/xnx AwWKN9hy4qT49+z5jbuXwb+HKUu590Qg0bJ7zAQH6FX6JR+2CfZ6OapaflEwNJX9XGMXwvjWBI Ca6bnm1bVu/yro1hMMM/tGxSDSwwy8VXmLXxG5LO7qf0ydqpbUeidzeuCyk192lFGLrPSVTs43 wDg= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43457662" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:56 -0800 IronPort-SDR: eLS9Ny9s5SShUsN76NALs6tm5kN6tpk5CkpShrSofqCShIPB7PkA/nIDsKhbP6W0N7KYYxjOnI Hpa9qm1lluIb3XjTQ0+SMpLl3PrjNBcHYPGeT552tCxXS4ZG6Wc96BHGvNL1vHkw9LT5W97wl2 rdJwGMd8rYAHDWKW5LDhyZJVp9X51mTAFJ3a0XAZ9DTmm0+fzXXUO5DLOpzX8mOSerNsjYsWgp Iqv7//AuZxVKE2w+S29cETyRbPIvIZ/pzgcfAkwo9HezycsIA/922kv/iC9r9G/xHcc00fC4Ar Ao8= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 46/48] input: atmel_mxt_ts: added sysfs interface to update atmel T38 data Date: Fri, 22 Nov 2019 17:24:00 +0900 Message-ID: <20191122082402.18173-47-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 Atmel touch controller contains T38 object where a user can store its own data of length 64 bytes. T38 data will not be part of checksum calculation on executing T6 BACKUP command. format used to update the T38 data is given below: offset: offset address of the data to be written in the t38 object (in decimal) length: length of the data to be written into the t38 object(in decimal) data: actual data bytes to be written into the t38 object (values should be in hex) Ex: 1. 0 2 10 20 updates first two bytes of the t38 data with values 10 and 20 2. 19 6 10 2f 30 4a 50 60 updates 6 bytes of t38 data from the index 19-24 with hex values Signed-off-by: Naveen Chakka Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d22a00ec69c1..a867960dc59b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4027,6 +4027,106 @@ static ssize_t mxt_touch_device_status(struct device *dev, struct return ret; } +static ssize_t mxt_t38_data_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + struct mxt_object *object; + size_t count = 0, size; + u8 i, *t38_buf; + + if (!data->object_table) + return -ENXIO; + + object = mxt_get_object(data, MXT_SPT_USERDATA_T38); + size = mxt_obj_size(object); + + /* Pre-allocate buffer large enough to hold max size of t38 object.*/ + t38_buf = kmalloc(size, GFP_KERNEL); + if (!t38_buf) + return -ENOMEM; + + count = __mxt_read_reg(data->client, object->start_address, + size, t38_buf); + if (count) + goto end; + + for (i = 0; i < size; i++) + count += scnprintf(buf + count, PAGE_SIZE - count, + "[%2u]: %02x\n", i, t38_buf[i]); + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); +end: + kfree(t38_buf); + return count; +} + +static ssize_t mxt_t38_data_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + struct mxt_object *object; + ssize_t ret = 0, pos, offset; + unsigned int i, len, index; + u8 *t38_buf; + + if (!data->object_table) + return -ENXIO; + + object = mxt_get_object(data, MXT_SPT_USERDATA_T38); + + /* Pre-allocate buffer large enough to hold max size of t38 object.*/ + t38_buf = kmalloc(mxt_obj_size(object), GFP_KERNEL); + if (!t38_buf) + return -ENOMEM; + + ret = sscanf(buf, "%zd %d%zd", &offset, &len, &pos); + if (ret != 2) { + dev_err(dev, "Bad format: Invalid parameter to update t38\n"); + ret = -EINVAL; + goto end; + } + + if (len == 0) { + dev_err(dev, + "Bad format: Data length should not be equal to 0\n"); + ret = -EINVAL; + goto end; + } + + if (offset < 0 || ((offset + len) > 64)) { + dev_err(dev, "Invalid offset value to update t38\n"); + ret = -EINVAL; + goto end; + } + + index = pos; + for (i = 0; i < len; i++) { + ret = sscanf(buf + index, "%hhx%zd", t38_buf + i, &pos); + if (ret != 1) { + dev_err(dev, "Bad format: Invalid Data\n"); + ret = -EINVAL; + goto end; + } + index += pos; + } + + ret = __mxt_write_reg(data->client, object->start_address + offset, + len, t38_buf); + if (ret) + goto end; + + ret = mxt_t6_command(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE, + true); + if (ret) + dev_err(dev, "backup command failed\n"); + else + ret = count; +end: + kfree(t38_buf); + return ret; +} + 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); @@ -4039,6 +4139,7 @@ static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); static DEVICE_ATTR(touch_dev_stat, 0444, mxt_touch_device_status, NULL); +static DEVICE_ATTR(t38_data, 0600, mxt_t38_data_show, mxt_t38_data_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -4051,6 +4152,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_notify.attr, &dev_attr_t25.attr, &dev_attr_touch_dev_stat.attr, + &dev_attr_t38_data.attr, NULL }; From patchwork Fri Nov 22 08:24:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2273B6C1 for ; Fri, 22 Nov 2019 08:27:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE5AF20708 for ; Fri, 22 Nov 2019 08:27:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbfKVI1C (ORCPT ); Fri, 22 Nov 2019 03:27:02 -0500 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:23094 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbfKVI1B (ORCPT ); Fri, 22 Nov 2019 03:27:01 -0500 IronPort-SDR: DSBZQ6mN7a7QbSzH56ulacYF8e9s4LFNZs+86CabF76uCR/6WvIcJaAb+l2enzJ/8Xi2mfmvLB ZZy0dysZDTWanCUZLTSOSPmsg2DOspWKI6ht81fs5MT/P71w2dZ1JABmiKLnxjq86vkr+zzNZK hVhnzEejymB1fcst41KREOObjInAf9FyLIxTBBdUf2OE+LHsmAyGZbe73D576ASkX8ddtwlO2U 5ICHs8Gh5RpXsqUR6JbKQJnaREl+hiAefMIj1EiJ0uM6VusYekGPVHGo0/R7UYKowXNQFkr0F3 2g8= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="45291197" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:26:59 -0800 IronPort-SDR: ZJ/12K09rbuRyQ/2BW7+8aKfj+cIoNCdaEa0bnyrf/RE4qRdNdOewF5QwVdtayBcKxbHgdEHgc eV0ee4gPtVsObp05sbuc9mH6ZE13QSZWfnkSupodDWlNSM1BgTRRtxawTSwpPjqa96jFza/JOn k7VzLoUDe/dQpEPwJTe/Kg753yOFtCrm/mEhjjitZ8jCTGcTtVX1pkVWpCZ89O03VRSm7u4+Sm UrXaLdewrsfGrRUu4mwcDLKAurMdRUIl6/H/1RqBWZiSIB+fy9QeaxRhLjEsnEHFj2WedPzY6n SHY= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 47/48] Input: atmel_mxt_ts: Implement synchronization during various operation Date: Fri, 22 Nov 2019 17:24:01 +0900 Message-ID: <20191122082402.18173-48-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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: Sanjeev Chugh There could be scope of race conditions when sysfs is being handled and at the same time, device removal is occurring. For example, we don't want the device removal to begin if the Atmel device cfg update is going on or firmware update is going on. In such cases, wait for device update to be completed before the removal continues. Thread Thread 2: ========================= ========================= mxt_update_fw_store() mxt_remove() mutex_lock(&data->lock) ... mxt_initialize() //Tries to acquire lock request_firmware_nowait() mutex_lock(&data->lock) ... ==>waits for lock() ... . ... . mutex_unlock(&data->lock) . //Gets lock and proceeds mxt_free_input_device(); ... mutex_unlock(&data->lock) //Frees atmel driver data kfree(data) If the request_firmware_nowait() completes after the driver removal, and callback is triggered. But kernel crashes since the module is already removed. This commit adds state machine to serialize such scenarios. Signed-off-by: Sanjeev Chugh Signed-off-by: Bhuvanesh Surachari Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 222 ++++++++++++++++++++--- 1 file changed, 196 insertions(+), 26 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a867960dc59b..243820b102b8 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -224,6 +224,7 @@ enum t100_type { #define MXT_POWERON_DELAY 150 /* msec */ #define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ #define MXT_WATCHDOG_TIMEOUT 1000 /* msec */ +#define MXT_CONFIG_TIMEOUT 1000 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -247,6 +248,20 @@ enum t100_type { #define DEBUG_MSG_MAX 200 +enum device_state { + MXT_STATE_READY, + MXT_STATE_UPDATING_CONFIG, + MXT_STATE_UPDATING_CONFIG_ASYNC, + MXT_STATE_START, + MXT_STATE_STOP, + MXT_STATE_GOING_AWAY +}; + +enum mxt_cmd { + UPDATE_CFG, + UPDATE_FW +}; + struct mxt_info { u8 family_id; u8 variant_id; @@ -426,11 +441,15 @@ struct mxt_data { /* Indicates whether device is in suspend */ bool suspended; - /* Indicates whether device is updating configuration */ - bool updating_config; + struct mutex lock; unsigned int mtu; bool t25_status; + + /* State handling for probe/remove, open/close and config update */ + enum device_state e_state; + + struct completion update_cfg_completion; }; struct mxt_vb2_buffer { @@ -1657,6 +1676,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) struct mxt_data *data = dev_id; int ret; + mutex_lock(&data->lock); data->mxt_status.intp_triggered = true; if (data->in_bootloader) { @@ -1684,6 +1704,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) exit: data->mxt_status.intp_triggered = false; + mutex_unlock(&data->lock); + return ret; } @@ -2264,6 +2286,8 @@ static void mxt_free_object_table(struct mxt_data *data) video_unregister_device(&data->dbg.vdev); v4l2_device_unregister(&data->dbg.v4l2); #endif + mutex_lock(&data->lock); + data->object_table = NULL; kfree(data->info); data->info = NULL; @@ -2293,6 +2317,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T100_reportid_min = 0; data->T100_reportid_max = 0; data->max_reportid = 0; + + mutex_unlock(&data->lock); } static int mxt_parse_object_table(struct mxt_data *data, @@ -2974,8 +3000,15 @@ static int mxt_configure_objects(struct mxt_data *data, static void mxt_config_cb(const struct firmware *cfg, void *ctx) { + struct mxt_data *data = ctx; + mxt_configure_objects(ctx, cfg); release_firmware(cfg); + complete(&data->update_cfg_completion); + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); } static int mxt_bootloader_status(struct mxt_data *data) @@ -3088,6 +3121,15 @@ static int mxt_initialize(struct mxt_data *data) goto err_free_sysfs; if (data->cfg_name) { + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_GOING_AWAY) { + data->e_state = MXT_STATE_UPDATING_CONFIG_ASYNC; + } else { + mutex_unlock(&data->lock); + return -EBUSY; + } + reinit_completion(&data->update_cfg_completion); + mutex_unlock(&data->lock); error = request_firmware_nowait(THIS_MODULE, true, data->cfg_name, &client->dev, @@ -3867,30 +3909,58 @@ static int mxt_update_file_name(struct device *dev, char **file_name, return 0; } +static int mxt_process_operation(struct mxt_data *data, + enum mxt_cmd cmd, + void *cmd_data); + static ssize_t mxt_update_fw_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { struct mxt_data *data = dev_get_drvdata(dev); + char *filename = NULL; + int ret; + + ret = mxt_update_file_name(dev, &filename, buf, count); + if (ret) + goto out; + + ret = mxt_process_operation(data, UPDATE_FW, filename); + kfree(filename); + + if (ret) + goto out; + + return count; +out: + return ret; +} + +static int mxt_fw_update(struct mxt_data *data, + const char *filename) +{ + struct device *dev = &data->client->dev; + unsigned int len = 0; int error; - error = mxt_update_file_name(dev, &data->fw_name, buf, count); + len = strlen(filename); + error = mxt_update_file_name(dev, &data->fw_name, filename, len); if (error) return error; error = mxt_load_fw(dev); if (error) { dev_err(dev, "The firmware update failed(%d)\n", error); - count = error; - } else { - dev_info(dev, "The firmware update succeeded\n"); - - error = mxt_initialize(data); - if (error) - return error; + return error; } - return count; + error = mxt_initialize(data); + if (error) + return error; + + dev_info(dev, "The firmware update succeeded\n"); + + return error; } static ssize_t mxt_update_cfg_store(struct device *dev, @@ -3898,14 +3968,38 @@ static ssize_t mxt_update_cfg_store(struct device *dev, const char *buf, size_t count) { struct mxt_data *data = dev_get_drvdata(dev); + char *filename = NULL; + int ret; + + ret = mxt_update_file_name(dev, &filename, buf, count); + if (ret) + goto out; + + ret = mxt_process_operation(data, UPDATE_CFG, filename); + kfree(filename); + + if (ret) + goto out; + + return count; +out: + return ret; +} + +static int mxt_cfg_update(struct mxt_data *data, + char *filename) +{ + struct device *dev = &data->client->dev; const struct firmware *cfg; + unsigned int len = 0; int ret; - ret = mxt_update_file_name(dev, &data->cfg_name, buf, count); + len = strlen(filename); + ret = mxt_update_file_name(dev, &data->cfg_name, filename, len); if (ret) return ret; - ret = request_firmware(&cfg, data->cfg_name, dev); + ret = request_firmware(&cfg, data->cfg_name, &data->client->dev); if (ret < 0) { dev_err(dev, "Failure to request config file %s\n", data->cfg_name); @@ -3913,8 +4007,6 @@ static ssize_t mxt_update_cfg_store(struct device *dev, goto out; } - data->updating_config = true; - mxt_free_input_device(data); if (data->suspended) { @@ -3930,15 +4022,8 @@ static ssize_t mxt_update_cfg_store(struct device *dev, } ret = mxt_configure_objects(data, cfg); - if (ret) - goto release; - - ret = count; - -release: release_firmware(cfg); out: - data->updating_config = false; return ret; } @@ -4202,8 +4287,17 @@ static int mxt_start(struct mxt_data *data) { int ret = 0; - if (!data->suspended || data->in_bootloader) + mutex_lock(&data->lock); + if (!data->suspended) { + mutex_unlock(&data->lock); return 0; + } + if (data->in_bootloader || data->e_state != MXT_STATE_READY) { + mutex_unlock(&data->lock); + return -EBUSY; + } + data->e_state = MXT_STATE_START; + mutex_unlock(&data->lock); switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -4247,8 +4341,12 @@ static int mxt_start(struct mxt_data *data) ret = mxt_acquire_irq(data); } + mutex_lock(&data->lock); if (!ret) data->suspended = false; + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); return ret; } @@ -4257,8 +4355,19 @@ static int mxt_stop(struct mxt_data *data) { int ret; - if (data->suspended || data->in_bootloader || data->updating_config) + mutex_lock(&data->lock); + if (data->suspended) { + mutex_unlock(&data->lock); return 0; + } + if (data->in_bootloader || (data->e_state != MXT_STATE_READY && + data->e_state != MXT_STATE_GOING_AWAY)) { + mutex_unlock(&data->lock); + return -EBUSY; + } + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_STOP; + mutex_unlock(&data->lock); switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -4288,8 +4397,15 @@ static int mxt_stop(struct mxt_data *data) break; } + mutex_lock(&data->lock); data->suspended = true; + + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); + return 0; + } static int mxt_input_open(struct input_dev *dev) @@ -4443,12 +4559,15 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", client->adapter->nr, client->addr); + mutex_init(&data->lock); + data->client = client; i2c_set_clientdata(client, data); init_completion(&data->chg_completion); init_completion(&data->reset_completion); init_completion(&data->crc_completion); + init_completion(&data->update_cfg_completion); mutex_init(&data->debug_msg_lock); data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ? @@ -4542,6 +4661,18 @@ static int mxt_remove(struct i2c_client *client) { struct mxt_data *data = i2c_get_clientdata(client); + mutex_lock(&data->lock); + if (data->e_state == MXT_STATE_UPDATING_CONFIG_ASYNC || + data->e_state == MXT_STATE_UPDATING_CONFIG) { + data->e_state = MXT_STATE_GOING_AWAY; + mutex_unlock(&data->lock); + mxt_wait_for_completion(data, &data->update_cfg_completion, + MXT_CONFIG_TIMEOUT); + } else { + data->e_state = MXT_STATE_GOING_AWAY; + mutex_unlock(&data->lock); + } + disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); if (data->reset_gpio) { @@ -4598,6 +4729,45 @@ static int __maybe_unused mxt_resume(struct device *dev) return ret; } +static int mxt_process_operation(struct mxt_data *data, + enum mxt_cmd cmd, + void *cmd_data) +{ + int ret = 0; + + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_READY) { + mutex_unlock(&data->lock); + dev_err(&data->client->dev, "Atmel touch device is shutting down\n"); + return -EBUSY; + } + data->e_state = MXT_STATE_UPDATING_CONFIG; + reinit_completion(&data->update_cfg_completion); + mutex_unlock(&data->lock); + + switch (cmd) { + case UPDATE_CFG: + case UPDATE_FW: + if (cmd == UPDATE_CFG) + ret = mxt_cfg_update(data, (char *)cmd_data); + else + ret = mxt_fw_update(data, (char *)cmd_data); + break; + + default: + break; + } + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_UPDATING_CONFIG_ASYNC) { + complete(&data->update_cfg_completion); + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + } + mutex_unlock(&data->lock); + + return ret; +} + static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); static const struct of_device_id mxt_of_match[] = { From patchwork Fri Nov 22 08:24:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11257449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D62236C1 for ; Fri, 22 Nov 2019 08:27:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C03AB20714 for ; Fri, 22 Nov 2019 08:27:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbfKVI1E (ORCPT ); Fri, 22 Nov 2019 03:27:04 -0500 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:4507 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbfKVI1D (ORCPT ); Fri, 22 Nov 2019 03:27:03 -0500 IronPort-SDR: WmE4YpRTIdKexfKlXc+xiQIxrcGVPaBsL0TL0yy1gxZmTsipzFQk/F3Zs/MbIeU7D14kXCFwwf UfNrLB7mzmxNIIp9rw5U4j2+cD8WCTWX4CE2vJBmRIzgujpp81XtqWqs2j638wTROzIsIAwUzO LX+Ic8XZhXQ/OPA2HvAPdwQ7f7entQ7/RMETJAK04wiLYRxlaXiy2TR2unQNeTxPduviOYu0rd 43O1em9ICCtS61Q3xw+Em2cIQnrx8nKmcGrqQn6MACm8PHWNfm0F1YRHQ1BFBam+XNlCiHT+zI FA4= X-IronPort-AV: E=Sophos;i="5.69,229,1571731200"; d="scan'208";a="43419521" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 22 Nov 2019 00:27:03 -0800 IronPort-SDR: 9l9ljm6lWSenEIbXSZW35AakmKv0BEFPwkciDkX2Oi0LFlamqYbVh8mT0/SuhefPHepGspJZED PyLAMqWK015XGGKSTkHMDmIOLffEyUMCeaLwVjhsy9cj7M8mZJdgtoncBGG3e7kS5NATtNUGA0 pCOvGzLCyAhAbZNvAYsD1fpKVeuM2w1FD8b+pdZVSV5vxblQ6lfPU89mCu0ai8WK+R1dLvRVkl SrMHqS0PZ0F6M2ciVtoU7xNnLdd9CEonU7clAuP3HH6v9gaYOz9BytaXGEnoHDOJvogTEJUDEM whs= From: Jiada Wang To: , , , , CC: , , , , Subject: [PATCH v6 48/48] Input: atmel_mxt_ts - Fix compilation warning Date: Fri, 22 Nov 2019 17:24:02 +0900 Message-ID: <20191122082402.18173-49-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122082402.18173-1-jiada_wang@mentor.com> References: <20191122082402.18173-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 243820b102b8..3e2697810cf0 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2049,7 +2049,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",