From patchwork Thu Mar 19 14:59:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447435 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 ACD046CA for ; Thu, 19 Mar 2020 15:07:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83C4920BED for ; Thu, 19 Mar 2020 15:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728051AbgCSPHg (ORCPT ); Thu, 19 Mar 2020 11:07:36 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5879 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727178AbgCSPHf (ORCPT ); Thu, 19 Mar 2020 11:07:35 -0400 IronPort-SDR: s7RHOcHhz7lZPoLoCWT0PRVI6pNHzFcNx3U5DqeDA6SoR/EkRGql/NxbPI3Esu5RVuhdvr7bN3 m8d9ZUDHGytCkV2/iuxjqtb7eahjLO1Yw7Q5RODTr+1JF5G1TljlSnbBheKEhHf/Nqga1H46DR nk+qSL6ZfB7EtAK66eJKXJYs7O04BG/ddp3/9gDwJXuGXt0M/A363sjIisVWG013fz0Nla6jlt QTlK+t2qetWYXCENgnVhDc94BP2Qusf0N6D2KO6DRu3HQL4DKe6xAG/z+u/18ZOGNc7zyWUw+N 98g= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926656" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:27 -0800 IronPort-SDR: BGb2/R/yOgpJFw5BqoZPb/nmlbRMnzoTnZnJgjrE/7wSVXI01+2GR/BTrhoyQENqwStsSYfxSH aBGginbAsIA11lKepwl1MHD/cQIqSFGDun1kfEvcgAeA90LVC+hEpqXn2jxC8qJxuwrAsZ0V29 QoMmBDvG10siNnnrl/lIfkFwRIKFo/kPRrZq7NSsRD9UkalUp9CsOU1he3t4ayModoySuYKrU6 /Z2eK08tKRjf7/9Upx0pZVPCPVHDWP0DlDolaqEiblEDwCIKv/GJJyoJRc84Yp+E7aF15Nt9VQ Sq4= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 01/52] Input: introduce input_mt_report_slot_inactive Date: Thu, 19 Mar 2020 07:59:25 -0700 Message-ID: <20200319150016.61398-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 362805ddf377..e2ce790ff4a4 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 ae60442efda0..a2189739e30f 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 6bcffc930384..02a73d9a4def 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 69c6d559eeb0..776ed9e4629d 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -549,7 +549,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 0e2e08f3f433..ef6aaed217cf 100644 --- a/drivers/input/touchscreen/raspberrypi-ts.c +++ b/drivers/input/touchscreen/raspberrypi-ts.c @@ -100,7 +100,7 @@ static void rpi_ts_poll(struct input_dev *input) 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 Thu Mar 19 14:59:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447431 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 9BA51913 for ; Thu, 19 Mar 2020 15:07:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C7B620BED for ; Thu, 19 Mar 2020 15:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727178AbgCSPHj (ORCPT ); Thu, 19 Mar 2020 11:07:39 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5879 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728308AbgCSPHi (ORCPT ); Thu, 19 Mar 2020 11:07:38 -0400 IronPort-SDR: wRSxf5HblxQ9NwYT/GBjzJCJSrEAZwQ4Iowek5/+9BCDrc2NvG2QbPk8z1QxzoXLDHdUSSWRnt dMhfHe3raYTp6xhHOkeOb59vcD7W4fE+Xgbm7JeNExuwEl5kV3qTNnizJDnMrUzyuEm5me7PIa DkRGXNAmEHrPN7gpzaIxkenK84ij7+L407lRod24ryhFNoPjqKAsQPRT9ojO/SoqivZJgTxYHe z4sJzbZykPn63FzMJPKbGaPrqe/xwRaSTW7CBdRmvlCYbaYbAvyrh6CW0bpOPee0rvPKzVwegc /t0= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926665" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:30 -0800 IronPort-SDR: NX7S6w1EKKo/U3RM91oBUeld1qZA4Yij+7/9LBJlrVgADf2aaDkglnKrMJUcfY8tFeTqqoupC6 EK6GtAjnKz1u1CxqDDFENYlQMeozI721oQkkkN7pqd33N4ava0QCCf5fsaGum6E/xkrQKb94DM y3d5FQBl9Pft6URIM2lk1RPfzizNbTFhjyjr5psVBo3RWQlg6SSoaHhDsTqpJyrKcq1i58K1mG Pdz4kp/8eQUwCDKBh5h2zxv6UyGHjXehxry5csji+2a8rkTXzucNhp6JHycQiWvdyd6EaW9qKN g6E= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 02/52] Input: atmel_mxt_ts - rework sysfs init/remove Date: Thu, 19 Mar 2020 07:59:26 -0700 Message-ID: <20200319150016.61398-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer An error in the sysfs init may otherwise interfere with the async return from the firmware loader Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3114584ae77c2b03b6dad87174f010d002e9c05d) [gdavis: Forward port and fixup conflicts. Also fixed sysfs leaks in both the mxt_initialize() and mxt_probe() error return cases.] Signed-off-by: George G. Davis [jiada: keep call mxt_initialize() before sysfs creation replace S_IWUSR with 0200] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a2189739e30f..49bdf5cf3a0d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2086,10 +2086,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) return 0; err_free_mem: + data->input_dev = NULL; input_free_device(input_dev); return error; } +static int mxt_sysfs_init(struct mxt_data *data); +static void mxt_sysfs_remove(struct mxt_data *data); + static int mxt_configure_objects(struct mxt_data *data, const struct firmware *cfg); @@ -2141,16 +2145,24 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_sysfs_init(data); + if (error) + return error; + error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, &client->dev, GFP_KERNEL, data, mxt_config_cb); if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - return error; + goto err_free_sysfs; } return 0; + +err_free_sysfs: + mxt_sysfs_remove(data); + return error; } static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep) @@ -2803,6 +2815,7 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); } else { @@ -2909,16 +2922,25 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static DEVICE_ATTR(update_fw, 0200, NULL, mxt_update_fw_store); + +static struct attribute *mxt_fw_attrs[] = { + &dev_attr_update_fw.attr, + NULL +}; + +static const struct attribute_group mxt_fw_attr_group = { + .attrs = mxt_fw_attrs, +}; + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); -static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, - &dev_attr_update_fw.attr, NULL }; @@ -2926,6 +2948,28 @@ static const struct attribute_group mxt_attr_group = { .attrs = mxt_attrs, }; +static int mxt_sysfs_init(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + if (error) { + dev_err(&client->dev, "Failure %d creating sysfs group\n", + error); + return error; + } + + return 0; +} + +static void mxt_sysfs_remove(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + + sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); +} + static void mxt_start(struct mxt_data *data) { switch (data->suspend_mode) { @@ -3112,19 +3156,14 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) if (error) return error; - error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + error = sysfs_create_group(&client->dev.kobj, &mxt_fw_attr_group); if (error) { - dev_err(&client->dev, "Failure %d creating sysfs group\n", + dev_err(&client->dev, "Failure %d creating fw sysfs group\n", error); - goto err_free_object; + return error; } return 0; - -err_free_object: - mxt_free_input_device(data); - mxt_free_object_table(data); - return error; } static int mxt_remove(struct i2c_client *client) @@ -3132,7 +3171,8 @@ static int mxt_remove(struct i2c_client *client) struct mxt_data *data = i2c_get_clientdata(client); disable_irq(data->irq); - sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); + sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); From patchwork Thu Mar 19 14:59:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447433 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 52881913 for ; Thu, 19 Mar 2020 15:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C60820BED for ; Thu, 19 Mar 2020 15:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728470AbgCSPHl (ORCPT ); Thu, 19 Mar 2020 11:07:41 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5879 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728447AbgCSPHk (ORCPT ); Thu, 19 Mar 2020 11:07:40 -0400 IronPort-SDR: pseR6uDw419tJb7VrnwuxcbBd6hsGmVKF0frDOF7rUSmKAcxUf1l7zfT6yTrB66TQ0QWvdzkC5 ht797pJnc3lJ4PGNghsb5Hxo29l5ltyy+8gBJFU/xt98/qaeHmyGMjjQKBdLOsGLAmPiRT737N QpOm5/YxviCwEfzWSMxSKUsKjQlMOKvyqX6wIQfezLD0eJKVTKip7aC06mwpsvkCI+gpLKx647 c81s2mf3mluVG5CFBq27YOoXu+CepsybwZggKs4USLigSgD6hnFHYblqTT7mrs+cn4rbwplQiM 8Z4= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926675" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:34 -0800 IronPort-SDR: Tw8ayBNr/GWXjbA4G6iCmU8EShf0LvhIyS7sfdAO6TmzSHVLa7/moA5weMhLQeF3p5ZRXqP/Qf cJwkerfYB9qpVkyrsy9Ht4rXdrhsju7i/RD4BMktX+qoVj0lhi5z4pLnR/4Ebe2Sy95UaegrOT x6143BHoAyuytc3aSm10j4KM5mz5HvqsbHewnkzlBUgJT8Lg7lEpFEN+CmzLasQ4+niqPIcYDP mrS0GQRtZY1XlI7tIFFr0skvvROCjkO6bCOxccCv19dRt8V+bkY1YyHOe2Sp8eUYw//OgHvkt9 tA4= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 03/52] Input: atmel_mxt_ts - only read messages in mxt_acquire_irq() when necessary Date: Thu, 19 Mar 2020 07:59:27 -0700 Message-ID: <20200319150016.61398-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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() call mxt_check_retrigen() after mxt_acquire_irq() in mxt_initialize() replace white-spaces with tab for MXT_COMMS_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 49bdf5cf3a0d..3f1ebe14802f 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; @@ -2145,6 +2186,10 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_check_retrigen(data); + if (error) + return error; + error = mxt_sysfs_init(data); if (error) return error; From patchwork Thu Mar 19 14:59:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447313 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 3A2AB1668 for ; Thu, 19 Mar 2020 15:00:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2261D20B1F for ; Thu, 19 Mar 2020 15:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727504AbgCSPAj (ORCPT ); Thu, 19 Mar 2020 11:00:39 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:15923 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727279AbgCSPAj (ORCPT ); Thu, 19 Mar 2020 11:00:39 -0400 IronPort-SDR: aq9BidRel6u2dHiaDJejrznQabVWcfiPPFH28pVCrpcPy7uOPOy6uVuBMswiEYLRHhXxalLjTD uKq1vuPQN3sm6VuR2sX8PJg2VbJbCzPyQtbXYv7KmQP/yXo8sZlENlUNimQroYPwlSztJXd3nV Rfbe41je5n0JV0hmfFxKSxpuxUP0x1UTtC529Jk8/B/jN+Rx5DUQTXsNMY3N72TVAw3WZodCOt 3mB8N3DFnUx9FOhbzuAcQ+HjVWP30N/2hWKsPO+lnPcLeo4bFBm4znv1o7XjzA5g9x3UQxTQrT JT8= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850130" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:38 -0800 IronPort-SDR: V666wCBxE7uhKD5NWWFiTqoOOsLRkXJrRveIYym1WNZCWKtzP0x97v1QPSH2t0oGS5T+aZk5W/ hyCgiu6UFOeySoCZSgy6NjeR6HOaxNhZjY9MLrfQNQimU+jrOLcXvGzvwB47Q6fT3RsRNN2Iyn s0S0cT1vWhzbwRkqF71ZiJcLm0LYzcj9ESTap6APZIR6TQhDZ4u9BxMhdXL0ZN/t5ybq/7owq2 AeSYNod7d9SwBrcU0ac2w72rCCR04an8iekEeX2npB1KAdvwOgjNanEm/WiHk1yLr1t9gJZdWB J98= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 04/52] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Thu, 19 Mar 2020 07:59:28 -0700 Message-ID: <20200319150016.61398-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer On some firmware variants, the size of the info block exceeds what can be read in a single transfer. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 74c4f5277cfa403d43fafc404119dc57a08677db) [gdavis: Forward port and fix conflicts due to v4.14.51 commit 960fe000b1d3 ("Input: atmel_mxt_ts - fix the firmware update").] Signed-off-by: George G. Davis [jiada: Change mxt_read_blks() to __mxt_read_reg(), original __mxt_read_reg() to __mxt_read_chunk()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 3f1ebe14802f..7e6a66e3e1e0 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -40,7 +40,7 @@ #define MXT_OBJECT_START 0x07 #define MXT_OBJECT_SIZE 6 #define MXT_INFO_CHECKSUM_SIZE 3 -#define MXT_MAX_BLOCK_WRITE 256 +#define MXT_MAX_BLOCK_WRITE 255 /* Object types */ #define MXT_DEBUG_DIAGNOSTIC_T37 37 @@ -624,8 +624,8 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) return 0; } -static int __mxt_read_reg(struct i2c_client *client, - u16 reg, u16 len, void *val) +static int __mxt_read_chunk(struct i2c_client *client, + u16 reg, u16 len, void *val) { struct i2c_msg xfer[2]; u8 buf[2]; @@ -659,6 +659,28 @@ static int __mxt_read_reg(struct i2c_client *client, return ret; } +static int __mxt_read_reg(struct i2c_client *client, + u16 reg, u16 len, void *buf) +{ + u16 offset = 0; + int error; + u16 size; + + while (offset < len) { + size = min(MXT_MAX_BLOCK_WRITE, len - offset); + + error = __mxt_read_chunk(client, + reg + offset, + size, buf + offset); + if (error) + return error; + + offset += size; + } + + return 0; +} + static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, const void *val) { From patchwork Thu Mar 19 14:59:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447315 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 3F48D1864 for ; Thu, 19 Mar 2020 15:00:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 273DD2072D for ; Thu, 19 Mar 2020 15:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727781AbgCSPAo (ORCPT ); Thu, 19 Mar 2020 11:00:44 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727279AbgCSPAn (ORCPT ); Thu, 19 Mar 2020 11:00:43 -0400 IronPort-SDR: 8XGDnuUyuOCwZhIDb9bfcvKZFrLALdq+iFd3hT3XYk2GERyZHlEqRpdp4xBPag89psGCAOVaBy KGxlxBbjLhkZAZjU7KH1wRvBlqx1vsrh/HgOtoKvuU7mqBAhwpDMmDoLHxPzWMfgn2hi/eJqCk gLLRxLbO5QC5jUXue7cHnoKJ1uQkuGwlSR+c6JcuC86XOMdBImzu1LwudsHQ1sURojW1jEAkHs sWVz2VvtFL/fbQv301/5cm4u9kL46uyCEkpstwDUafCABMsSypYLDWm4nsXuVd6OXe+XremJU+ JlQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818554" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:42 -0800 IronPort-SDR: mloZxVZhsFG+CYizjp1oXWDHunfMMbWUZ1XMdkgdPBb91xeEqZ94pF9++CpEQaNg73ZRXxqFLT ZgG8S47oJ11BsIHFdjijXDa8OjvQusJd6lXn5T737iocPSKBls0heNlcgn8Ap/V5dweTIF3PwP MkUaDAZJirEWI3CDCsWZ5J5HaZgzeBUwHZ3FjdgKnWlMg3Oy0HWI/M6hV49m/TaePJ/py+JyOs k9ojIOkGC/NCZylLuRGWwJMP5hR4Hv4Hy9i2aMX8an8s0XjE/wRsK0R2ITa0JNS2+MOvFqgDbv I+g= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 05/52] Input: atmel_mxt_ts - output status from T48 Noise Supression Date: Thu, 19 Mar 2020 07:59:29 -0700 Message-ID: <20200319150016.61398-6-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer This patch outputs status from T48 Noise Supression 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 7e6a66e3e1e0..a53985a7736f 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 Thu Mar 19 14:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447317 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 D520E1894 for ; Thu, 19 Mar 2020 15:00:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF74F20BED for ; Thu, 19 Mar 2020 15:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbgCSPAs (ORCPT ); Thu, 19 Mar 2020 11:00:48 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727279AbgCSPAr (ORCPT ); Thu, 19 Mar 2020 11:00:47 -0400 IronPort-SDR: enNJyyVokVwnmQDg3IpZDe7jY0p7gSyg/fvmgRrK7OpwioHsorMSK6pDt4z9SPV9JHMYym7MSj TJevLncblTDf3MC4THTGaOgewG70HKHucTnk32fAVZPLhQ9ZmWbrQQQvFrKkNnFpourfeDOaxc y62jcdefPst/vchO3l5t1ZURD/FHtdOSm9eyNdJA54+y6i/ev9mB/eEW8bOIX1Kf0mCCNPWXSb k1K4CV90RlW9LsIlR7DpqDcb3392hlkSEoZaNRitqIlme7jGgU2t9xd5QEA8I8Xc1ZN9waWQy2 vd4= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818564" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:45 -0800 IronPort-SDR: +31qAcOJ+d2j/zuoQeW+eja0Ow2nJN+Qu0wTNP5GgJQXSouupaK/Abq6oUIpEVjLK96O2dA7wW +dXW6+NZWDctReWK6OPPkaE+AfecfrwI4JcNJwUTWCRNAfOMnj4X6jANTwhsbOGCXvbGy8iJTO OsCdGv2eRjVitekeb0N7J5NpkRWzMfl8ZlyLk7tyB7+vK6EKev/ABAd41cgPe6xwCeKPnzA7bs U2vbqAjirNuc+FYfU00RPN0QA/jT9L2jkZOMMl/ZEi8avqkTtGHqTyD837LytOk8D8ibjkmjro Fg4= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 06/52] Input: atmel_mxt_ts - output status from T42 Touch Suppression Date: Thu, 19 Mar 2020 07:59:30 -0700 Message-ID: <20200319150016.61398-7-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer This patch outputs status from T42 touch suppression Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit ab95b5a309999d2c098daaa9f88d9fcfae7eb516) Signed-off-by: George G. Davis [jiada: Replace dev_info() with dev_dbg()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a53985a7736f..f6465edaa57e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -155,6 +155,9 @@ struct t37_debug { #define MXT_RESET_VALUE 0x01 #define MXT_BACKUP_VALUE 0x55 +/* Define for MXT_PROCI_TOUCHSUPPRESSION_T42 */ +#define MXT_T42_MSG_TCHSUP BIT(0) + /* T100 Multiple Touch Touchscreen */ #define MXT_T100_CTRL 0 #define MXT_T100_CFG1 1 @@ -323,6 +326,8 @@ struct mxt_data { u8 T9_reportid_max; u16 T18_address; u8 T19_reportid; + u8 T42_reportid_min; + u8 T42_reportid_max; u16 T44_address; u8 T48_reportid; u8 T100_reportid_min; @@ -979,6 +984,17 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) data->update_input = true; } +static void mxt_proc_t42_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + if (status & MXT_T42_MSG_TCHSUP) + dev_dbg(dev, "T42 suppress\n"); + else + dev_dbg(dev, "T42 normal\n"); +} + static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) { struct device *dev = &data->client->dev; @@ -1006,6 +1022,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (report_id == data->T6_reportid) { mxt_proc_t6_messages(data, message); + } else if (report_id >= data->T42_reportid_min + && report_id <= data->T42_reportid_max) { + mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); } else if (!data->input_dev) { @@ -1686,6 +1705,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T9_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T42_reportid_min = 0; + data->T42_reportid_max = 0; data->T44_address = 0; data->T48_reportid = 0; data->T100_reportid_min = 0; @@ -1763,6 +1784,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_PROCI_TOUCHSUPPRESSION_T42: + data->T42_reportid_min = min_id; + data->T42_reportid_max = max_id; + break; case MXT_SPT_MESSAGECOUNT_T44: data->T44_address = object->start_address; break; From patchwork Thu Mar 19 14:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447319 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 76C2D1668 for ; Thu, 19 Mar 2020 15:00:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60AC120BED for ; Thu, 19 Mar 2020 15:00:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbgCSPAv (ORCPT ); Thu, 19 Mar 2020 11:00:51 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgCSPAu (ORCPT ); Thu, 19 Mar 2020 11:00:50 -0400 IronPort-SDR: 0YxweX9C+skqOgnvbFsvF9uFhwjLlxuHSnZH/hBhuOcvOme5mkAJq0OEm1S+h1TzWeqa+zeFaS vuQa1U+fhgubjC7rCv/O06MegjoTBsZ1NPTw2B1xsqF7QTI5VxEjeIJiuWawEuzHqnWR8mmnBo EkSAYZICyayInxSqNx3aQ1ksCay4M+lO4VqCZ7Xc7rIVVB+DwDoVtAAejS/AeJkyoFuXuKIuH2 iZ+iF/MES1iqQvyCI6jcEhXNIUNfavq7z9+HjDzBcgOVN0a7onejq1bvqPxtIVgj6aIwupf/M6 fJY= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818575" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:49 -0800 IronPort-SDR: 3abvqoVS/qA4BXc4EkwupiCewjZPmWyo/BZ4bJe8hvLI0u1zqNPmxouPCnCRFFQ5T++hTuLvKH UAk7nkXexwCHjWdi9eMwxVmL5rJ5snm6maDdu9M8URCnxORb3U3kDircAMhpyRMbawJ4gJ+KaB xCAflkgolJDmgVMtCbvPhG6D8CrufvTXsRlzRVy8lLWk7goEiznW8zsffqsHtxN4jfMn12J7vF 99D34NUgYE4KGfA3XhE1P1H9JqZQBpbPHWKTidrpeleqR8BHmvTQ9IybWuetcA0iSrSHs+CM4c tg0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 07/52] Input: atmel_mxt_ts - implement T9 vector/orientation support Date: Thu, 19 Mar 2020 07:59:31 -0700 Message-ID: <20200319150016.61398-8-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 f6465edaa57e..df2e0ba76e63 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 Thu Mar 19 14:59:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447321 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 B8CA21864 for ; Thu, 19 Mar 2020 15:00:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A31342145D for ; Thu, 19 Mar 2020 15:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbgCSPAz (ORCPT ); Thu, 19 Mar 2020 11:00:55 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgCSPAy (ORCPT ); Thu, 19 Mar 2020 11:00:54 -0400 IronPort-SDR: 4jBEADPS4AYCKNA2uG4tyoBCJ4JKgBp/NayqnmoDcsxwJYV+9cV6jEMwAXUpo0pXDo+ZV8oOln 8tZEGCmoOwf8w1gha6ZubUvqQYyIHI8iE8eWW9+ahKiP1uGv8DMxnY2H0Mk51+ze3+LRKCPoBv 6a1b74Bg2O5h8by3nwvk/xYy7Oovj3dlWyuuhLaDALKY4/AtJUnsTCeJrL1XDh7XL6rGL/zmUX 1mKxN80ZBz0TiWb6/1AaO3eQ9O+/+7b/gAA8puWRjzAhkTu7F45gUNKdMv6yby+Hm7qtsF2pyA ur0= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818584" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:53 -0800 IronPort-SDR: mrJ21MCoz/CWbzKX2RTL6YIlKIKJUqGBxG1wD3KtxIZGx71F+MkHYnTBS63w3RBqDfyGxbayFM KLJEewkCzpzuVUaNnaJak0w9yD73v6q44RwpiulAQH52/pimIAKfN71FN06zAbuiEPtq9q8ZMh I6/9xV+8UT4qqSWSpSgvL+3wQvkOf24Jf5yjkeIgx4UZbEf0PglgafCbfRSj7KP3SL8hj9ZqHk fQcPcAR2EEbV4KbeGN5iLBOnxeEBS22//8iWx4laIJtffLqTPZZT9H9K7kPdkYDR7sv0N26+gi 89c= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 08/52] Input: atmel_mxt_ts - implement T15 Key Array support Date: Thu, 19 Mar 2020 07:59:32 -0700 Message-ID: <20200319150016.61398-9-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 df2e0ba76e63..d05249b02781 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 Thu Mar 19 14:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447323 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 6E5CF913 for ; Thu, 19 Mar 2020 15:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56C4320BED for ; Thu, 19 Mar 2020 15:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgCSPBA (ORCPT ); Thu, 19 Mar 2020 11:01:00 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgCSPA7 (ORCPT ); Thu, 19 Mar 2020 11:00:59 -0400 IronPort-SDR: Y7bPV8FtReL4o62/wc/UuUYIWX2h61ho6EQEwutN2qJTaXDIG36WXcImzUxYVobQ2BDlQqz6l+ YyveSE4hrd1Mr6Awd7hKuoc9l2xRhTFjauAct++cbG5dWSppHDgazKb88/2XAb194Uu54rTwG6 d56rElj2xysTG9DmaJykNtEIjLhUYrkJ9VH+Bjkz2qAoSzd57WUOxapQmAxVM3EEMgc2q+eQvW 7ZBTS/pxKsUtGddPYj8tMXHwe2wgu+otYa+nw2UnRnTC7HDLUk6EbWIzj0pK+P7WVjT9s5L0fo wfk= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818602" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:00:57 -0800 IronPort-SDR: x14uGwY+wFqudEV6VZB2dBYFjSEQ0lbm5p+WUdtYX59949hbtQnDke1pT1ZzUxw7B83IwK/mAs 6PWB499Ihy+5Qolvk8EtR6AOxSXpcekt1eJlb8HTzEeFuwKWqX8+x0EqXyRZnPVCWGj8BOgged ymnDg/WnJS97VUxk2Zr9NOY/0vapkWbQw7okTQGdpWBqpoGMebYBpVRSOQlobG9FZsoH2rDSV+ MULfFpKG+IiIZkyETbLps9SZIyEril8iV6VddHxrtd+WS+Ii9WdcW320d2Iw9DYqev/yn2hyXQ WDs= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 09/52] Input: atmel_mxt_ts - handle reports from T47 Stylus object Date: Thu, 19 Mar 2020 07:59:33 -0700 Message-ID: <20200319150016.61398-10-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer This patch handles reports from T47 Stylus object Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 56405a5ea08eb34cfe83f3121867c9de0a5c48c1) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d05249b02781..ba58cdd5b76d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -823,6 +823,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) int area; int amplitude; u8 vector; + int tool; id = message[0] - data->T9_reportid_min; status = message[1]; @@ -836,6 +837,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) y >>= 2; area = message[5]; + amplitude = message[6]; vector = message[7]; @@ -865,12 +867,20 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) mxt_input_sync(data); } + /* A size of zero indicates touch is from a linked T47 Stylus */ + if (area == 0) { + area = MXT_TOUCH_MAJOR_DEFAULT; + tool = MT_TOOL_PEN; + } else { + tool = MT_TOOL_FINGER; + } + /* if active, pressure must be non-zero */ if (!amplitude) amplitude = MXT_PRESSURE_DEFAULT; /* Touch active */ - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); + input_mt_report_slot_state(input_dev, tool, 1); input_report_abs(input_dev, ABS_MT_POSITION_X, x); input_report_abs(input_dev, ABS_MT_POSITION_Y, y); input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); From patchwork Thu Mar 19 14:59:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447325 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 2F04B6CA for ; Thu, 19 Mar 2020 15:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E54B20BED for ; Thu, 19 Mar 2020 15:01:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbgCSPBE (ORCPT ); Thu, 19 Mar 2020 11:01:04 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5218 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbgCSPBE (ORCPT ); Thu, 19 Mar 2020 11:01:04 -0400 IronPort-SDR: 23JtsyWvh8Vo2Gr/Y+vmIA7nLXbVNtr8DtJuH12HS3k5av+G8CZmsPZ6FX1oBIFZf4/oAP/wsF 4uCPEWJE1O8mzb1KzwTyo+C/YCBe6kI+uJP4Yc1rqb0dguQt6yN9ocCIqLkZew00nCnU/cvrs2 TbVpPQnpjt3vc3apd8S3yXYMz69Nb0RIVsWPMzFF/ycf90pF1dm3uG9tgRdjIOaWuBYFnb1vAQ 5I5k8sJlxoyjkSCKHQmzTF7jSxKPq/O3Q4pCVj19dxBtMuo1tzdCIzMrTu6dg0WFOCn67+k6Wd BKw= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818608" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:01 -0800 IronPort-SDR: fDHQvUQiEH3jB3kgHOuIiFwKgBRbT6HR33Bzm+ym8dnMYeSUUWK6mwvEevGesA1oQyw+H5NYXr YbkvefrOuzsLIz5PakysqGXfrjVT8RgBOmCA8ysVdsLkdI4z5DVaAB9LxWYVkNvNoM1zrf2WzE atH4MEs/hvci/Mn5PdmmmZyuY2Y94WKLB7VXsJnmZ0bK0Qzx3OvaJGuhAmfgHnzrR55K3/zhSM 5di85KwReq1ElpYbXa4a+FlEFceSiWcbfFljxKppU5QjX1x7BzZIL1w7C6Ah2PfaUS+pmkcvJJ ggo= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 10/52] Input: atmel_mxt_ts - implement support for T107 active stylus Date: Thu, 19 Mar 2020 07:59:34 -0700 Message-ID: <20200319150016.61398-11-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer This patch implements support for T107 active stylus Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 20e357dd9acf8c2040068c8b22d6bc1401a1893f) [gdavis: Forward port and fix conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 117 ++++++++++++++++++++++- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ba58cdd5b76d..63db8b66eb67 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -72,6 +72,7 @@ #define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71 71 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 +#define MXT_PROCI_ACTIVESTYLUS_T107 107 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -181,6 +182,7 @@ struct t37_debug { enum t100_type { MXT_T100_TYPE_FINGER = 1, MXT_T100_TYPE_PASSIVE_STYLUS = 2, + MXT_T100_TYPE_ACTIVE_STYLUS = 3, MXT_T100_TYPE_HOVERING_FINGER = 4, MXT_T100_TYPE_GLOVE = 5, MXT_T100_TYPE_LARGE_TOUCH = 6, @@ -192,6 +194,16 @@ enum t100_type { #define MXT_TOUCH_MAJOR_DEFAULT 1 #define MXT_PRESSURE_DEFAULT 1 +/* Gen2 Active Stylus */ +#define MXT_T107_STYLUS_STYAUX 42 +#define MXT_T107_STYLUS_STYAUX_PRESSURE BIT(0) +#define MXT_T107_STYLUS_STYAUX_PEAK BIT(4) + +#define MXT_T107_STYLUS_HOVER BIT(0) +#define MXT_T107_STYLUS_TIPSWITCH BIT(1) +#define MXT_T107_STYLUS_BUTTON0 BIT(2) +#define MXT_T107_STYLUS_BUTTON1 BIT(3) + /* Delay times */ #define MXT_BACKUP_TIME 50 /* msec */ #define MXT_RESET_GPIO_TIME 20 /* msec */ @@ -313,10 +325,12 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; - bool use_retrigen_workaround; unsigned long t15_keystatus; int t15_num_keys; const unsigned int *t15_keymap; + u8 stylus_aux_pressure; + u8 stylus_aux_peak; + bool use_retrigen_workaround; /* Cached parameters from object table */ u16 T5_address; @@ -337,6 +351,7 @@ struct mxt_data { u8 T48_reportid; u8 T100_reportid_min; u8 T100_reportid_max; + u16 T107_address; /* for fw update in bootloader */ struct completion bl_completion; @@ -908,6 +923,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) u8 major = 0; u8 pressure = 0; u8 orientation = 0; + bool active = false; + bool hover = false; id = message[0] - data->T100_reportid_min - 2; @@ -926,6 +943,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_HOVERING_FINGER: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_HOVERING; + hover = true; + active = true; if (data->t100_aux_vect) orientation = message[data->t100_aux_vect]; @@ -936,6 +955,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_GLOVE: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; if (data->t100_aux_area) major = message[data->t100_aux_area]; @@ -950,6 +971,9 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_PASSIVE_STYLUS: tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; /* * Passive stylus is reported with size zero so @@ -962,6 +986,31 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) break; + case MXT_T100_TYPE_ACTIVE_STYLUS: + /* Report input buttons */ + input_report_key(input_dev, BTN_STYLUS, + message[6] & MXT_T107_STYLUS_BUTTON0); + input_report_key(input_dev, BTN_STYLUS2, + message[6] & MXT_T107_STYLUS_BUTTON1); + + /* stylus in range, but position unavailable */ + if (!(message[6] & MXT_T107_STYLUS_HOVER)) + break; + + tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + active = true; + major = MXT_TOUCH_MAJOR_DEFAULT; + + if (!(message[6] & MXT_T107_STYLUS_TIPSWITCH)) { + hover = true; + distance = MXT_DISTANCE_HOVERING; + } else if (data->stylus_aux_pressure) { + pressure = message[data->stylus_aux_pressure]; + } + + break; + case MXT_T100_TYPE_LARGE_TOUCH: /* Ignore suppressed touch */ break; @@ -976,12 +1025,12 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) * Values reported should be non-zero if tool is touching the * device */ - if (!pressure && type != MXT_T100_TYPE_HOVERING_FINGER) + if (!pressure && !hover) pressure = MXT_PRESSURE_DEFAULT; input_mt_slot(input_dev, id); - if (status & MXT_T100_DETECT) { + if (active) { dev_dbg(dev, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n", id, type, x, y, major, pressure, orientation); @@ -992,6 +1041,7 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); input_report_abs(input_dev, ABS_MT_DISTANCE, distance); input_report_abs(input_dev, ABS_MT_ORIENTATION, orientation); + } else { dev_dbg(dev, "[%u] release\n", id); @@ -1863,6 +1913,9 @@ static int mxt_parse_object_table(struct mxt_data *data, /* first two report IDs reserved */ data->num_touchids = object->num_report_ids - 2; break; + case MXT_PROCI_ACTIVESTYLUS_T107: + data->T107_address = object->start_address; + break; } end_address = object->start_address @@ -2023,6 +2076,54 @@ static int mxt_read_t9_resolution(struct mxt_data *data) return 0; } +static int mxt_set_up_active_stylus(struct input_dev *input_dev, + struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + struct mxt_object *object; + u8 styaux; + int aux; + u8 ctrl; + + object = mxt_get_object(data, MXT_PROCI_ACTIVESTYLUS_T107); + if (!object) + return 0; + + error = __mxt_read_reg(client, object->start_address, 1, &ctrl); + if (error) + return error; + + /* Check enable bit */ + if (!(ctrl & 0x01)) + return 0; + + error = __mxt_read_reg(client, + object->start_address + MXT_T107_STYLUS_STYAUX, + 1, &styaux); + if (error) + return error; + + /* map aux bits */ + aux = 7; + + if (styaux & MXT_T107_STYLUS_STYAUX_PRESSURE) + data->stylus_aux_pressure = aux++; + + if (styaux & MXT_T107_STYLUS_STYAUX_PEAK) + data->stylus_aux_peak = aux++; + + input_set_capability(input_dev, EV_KEY, BTN_STYLUS); + input_set_capability(input_dev, EV_KEY, BTN_STYLUS2); + input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); + + dev_dbg(&client->dev, + "T107 active stylus, aux map pressure:%u peak:%u\n", + data->stylus_aux_pressure, data->stylus_aux_peak); + + return 0; +} + static int mxt_read_t100_config(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2229,7 +2330,7 @@ static int mxt_initialize_input_device(struct mxt_data *data) if (data->multitouch == MXT_TOUCH_MULTI_T9 || (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && - data->t100_aux_ampl)) { + (data->t100_aux_ampl || data->stylus_aux_pressure))) { input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); } @@ -2247,6 +2348,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) 0, 255, 0, 0); } + /* For T107 Active Stylus */ + if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && + data->T107_address) { + error = mxt_set_up_active_stylus(input_dev, data); + if (error) + dev_warn(dev, "Failed to read T107 config\n"); + } + /* For T15 Key Array */ if (data->T15_reportid_min) { data->t15_keystatus = 0; From patchwork Thu Mar 19 14:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447327 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 8F6B66CA for ; Thu, 19 Mar 2020 15:01:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78F782145D for ; Thu, 19 Mar 2020 15:01:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727933AbgCSPBG (ORCPT ); Thu, 19 Mar 2020 11:01:06 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:15962 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbgCSPBG (ORCPT ); Thu, 19 Mar 2020 11:01:06 -0400 IronPort-SDR: 2AJezrPb2vHfM5s9CYJH69wZVx1/zqueMALsKHJWYHzk43gp7iePUsLAPqB5mHbVs2U4hgYNbb Zs0aFkYgHlduIJ1trX0bxc3U1iMEUyXtjG1vER5cEmZAKbd9bJCU8zkXJRdaDF1DB5G5uqIOS0 UkyP8Dw82tVjPdcUHue659Y7KBNFVK4c4VADI+uNTu+tUD7e90ejznZ8pGRD4+ka93fjGXpRcc lddAk92IXa+UqtFxXrkbA2d4IXvNCzbV6VDWAXREVz9BCSAQMd+2oa1ZSF2x2RAsuhtKrw0oCY 3Wk= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850172" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:05 -0800 IronPort-SDR: jLo1JtNBzHXTpufAJErvVX4hMAlj4NUOySv/ulXXPMj4KNh14qStoksuqRcp8NdxkFleVs8fdT 8a2jsOq6E9vMkMRYqJ6AqSWsCx9VwVTRdNFLG1795IsfJ5LuN3eljj31j47JT93vEo7fpJL7tE gde8s8Oc4MrlM2NKqybZqYbJE6EjzJtsoVl9aZLaptSOlethBXUZ5Yf3Cfe0iX9a7bFkQ4/OdA yJwYH/M+SbyYrpQGiuL0qHWwNWyoxZ76a7UbGSwUI+yU3+GPgVE1+iEzA+wvgc9UCr6/Vvc8fp 1TE= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 11/52] Input: atmel_mxt_ts - add debug for T92 gesture and T93 touch seq msgs Date: Thu, 19 Mar 2020 07:59:35 -0700 Message-ID: <20200319150016.61398-12-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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: Karl Tsou 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 63db8b66eb67..6126bb8a7acc 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 Thu Mar 19 14:59:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447329 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 DB3996CA for ; Thu, 19 Mar 2020 15:01:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4A6820B1F for ; Thu, 19 Mar 2020 15:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726871AbgCSPBK (ORCPT ); Thu, 19 Mar 2020 11:01:10 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:15962 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbgCSPBK (ORCPT ); Thu, 19 Mar 2020 11:01:10 -0400 IronPort-SDR: Xcc6SLOnZrJ5Mpu5Xl8yPxMTKMtWnVj0MLpsFBMs+NlGWFzSLNE1M6BSH2BmOT5BCw9FN8SxzU lEw69fcRS8eLm8NXq/ZynbhVd1faWJe6GMP17OlwqwRnxQ96Yb01egkgkGcv3V/I1SfsLSe7nr eqGjioaT/R20/KudtNO5jUt8VLB9scdOZSYX7yXA+QMFldBBhmUidBHsCo4XA0kDK3KDV4tR/5 g4EuHnyzg84xhZ/ufjVrCyzmGYGYoFWHcV1ZR+QrZQTpaQtzOli55kaLXh0TRlz0aX19hMX7Kg cLs= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850179" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:09 -0800 IronPort-SDR: nBhRZztXMqhAvb09vcNqVy5bLr1sk2ZxH2d40ReYOCCjgvJW49PsXIAJNE6QwMEwXQKK5kM+LZ EBTnYlzHcx0it3r7Assz7gk8d9lLtlVRcABEK6ZTalLExxJ63PBwbSyerQfkP2lMMM5bdQrYJT 6UV7uUqILdDXT4qItor1si59IMaWgmTEXw4wB1MmCI/3M2bx0aMM6L+C+JOozpuTn7FOZBatTs +OjgB3xmdnSi0voFiNK4TnfWpnZtEclluPTB2PjR+BUGtzBxnouXPlq6M1K7100p1IVwRwRRLD 8S8= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 12/52] Input: atmel_mxt_ts - release touch state during suspend Date: Thu, 19 Mar 2020 07:59:36 -0700 Message-ID: <20200319150016.61398-13-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer If fingers are down as the MXT chip goes into suspend it does not send a lift message. In addition, it may not complete its final measurement cycle immediately, which means touch messages may be received by the interrupt handler after mxt_stop() has completed. So: - disable irq during suspend - flush any messages created after suspend - tell app layer that slots were released at suspend Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 26794433086dbc7dea18d2f6a1c8d61ab25bcfda) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fix from Dirk Behme: - Input: atmel_mxt_ts - remove superfluous data->suspended] Signed-off-by: Dirk Behme --- drivers/input/touchscreen/atmel_mxt_ts.c | 52 ++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 6126bb8a7acc..9aafed92db9c 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -372,6 +372,9 @@ struct mxt_data { unsigned int t19_num_keys; enum mxt_suspend_mode suspend_mode; + + /* Indicates whether device is in suspend */ + bool suspended; }; struct mxt_vb2_buffer { @@ -1151,10 +1154,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); - } else if (!data->input_dev) { + } else if (!data->input_dev || data->suspended) { /* - * Do not report events if input device - * is not yet registered. + * Do not report events if input device is not + * yet registered or returning from suspend */ mxt_dump_message(data, message); } else if (report_id >= data->T9_reportid_min && @@ -3135,6 +3138,11 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + if (data->suspended) { + enable_irq(data->irq); + data->suspended = false; + } + if (!data->in_bootloader) { /* Change to the bootloader mode */ data->in_bootloader = true; @@ -3306,8 +3314,27 @@ static void mxt_sysfs_remove(struct mxt_data *data) sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); } +static void mxt_reset_slots(struct mxt_data *data) +{ + struct input_dev *input_dev = data->input_dev; + int id; + + if (!input_dev) + return; + + for (id = 0; id < data->num_touchids; id++) { + input_mt_slot(input_dev, id); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + } + + mxt_input_sync(data); +} + static void mxt_start(struct mxt_data *data) { + if (!data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: mxt_soft_reset(data); @@ -3320,16 +3347,29 @@ static void mxt_start(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + /* + * Discard any touch messages still in message buffer + * from before chip went to sleep + */ + mxt_process_messages_until_invalid(data); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); /* Recalibrate since chip has been in deep sleep */ mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + + mxt_acquire_irq(data); break; } + + data->suspended = false; } static void mxt_stop(struct mxt_data *data) { + if (data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ @@ -3339,9 +3379,15 @@ static void mxt_stop(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + disable_irq(data->irq); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + + mxt_reset_slots(data); break; } + + data->suspended = true; } static int mxt_input_open(struct input_dev *dev) From patchwork Thu Mar 19 14:59:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447331 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 4CBDC6CA for ; Thu, 19 Mar 2020 15:01:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E20D20BED for ; Thu, 19 Mar 2020 15:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727957AbgCSPBP (ORCPT ); Thu, 19 Mar 2020 11:01:15 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:15962 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbgCSPBP (ORCPT ); Thu, 19 Mar 2020 11:01:15 -0400 IronPort-SDR: HAqqYjj4bii24FoB/u31+K9R7FH1NIXOhQHxtgh0jiJmo+f+9pqrgQWOMcM+NXJDTCmPcs/MJ3 tt6KBd4fTIpzYW1o+zwMQpD0S5tP/+cEpo/4Yu//aqvJ8osk71jmqZ/c5w7W5tj2DRQzegW7S/ GifWmkdwQo5LjuNo9xLU7nAQSlgE+CqOnzfvS1nc5U1opgFROkSD3Fgorihoo/JtbFxTrtNj9/ +GEKILtEFiBwW9kds4zof6aJhIVJZlnd+u5HLyAUkCb5sR+NnyOTYGVC5OAzR/wVmTK7TA8oaR 3KU= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850186" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:13 -0800 IronPort-SDR: AZeIdfsJ4S8gaSQnOJi6c00MRAQ0vvIKNclIlyovIjSoBzSih4MXYMmHjN192U/AxDMN69lmq1 BGqcs7/patg5FjxlsFku09JNa15tYcyaX93YCAzsL97UjPtERNi1VaHndxjuljYqpG+AykRIDh AQM8o5mu3LYHjJkYxWcTAoEI2kjAbg97DkBIg/1x97LzvZVurGTq6ElyGhccSXwbJbA20Kp2qd 9kKiZS5XaZK1oc7jWkLWL0xESH6p+WO34XRiqV1Tjb7f7Gtwosq/o+oUpCwxqhiG+5UGFq+1mq CLg= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 13/52] Input: atmel_mxt_ts - add regulator control support Date: Thu, 19 Mar 2020 07:59:37 -0700 Message-ID: <20200319150016.61398-14-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Allow the driver to optionally manage enabling/disable power to the touch controller itself. If the regulators are not present then use the deep sleep power mode instead. For a correct power on sequence, it is required that we have control over the RESET line. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 14052b61bb66c2f2283c00e733e131be7a9b8bfc) [gdavis: Resolve forward port conflicts due to v4.14-rc1 commmit f657b00df22e ("Input: atmel_mxt_ts - add support for reset line") and applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fixes from Dirk Behme: - Input: atmel_mxt_ts - in failure case disable the regulator - Input: atmel_mxt_ts - disable only enabled regulators - Input: atmel_mxt_ts - use devm_regulator_get()] Signed-off-by: Dirk Behme [jiada: Replace white-spaces with tab for MXT_CHG_DELAY separate Documentation/ and include/dt-bindings/ portion change to another commit] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 130 +++++++++++++++++++++-- 1 file changed, 121 insertions(+), 9 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9aafed92db9c..ef8baf64659e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include /* Firmware files */ #define MXT_FW_NAME "maxtouch.fw" @@ -215,6 +217,9 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_REGULATOR_DELAY 150 /* msec */ +#define MXT_CHG_DELAY 100 /* msec */ +#define MXT_POWERON_DELAY 150 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -275,11 +280,6 @@ enum v4l_dbg_inputs { MXT_V4L_INPUT_MAX, }; -enum mxt_suspend_mode { - MXT_SUSPEND_DEEP_SLEEP = 0, - MXT_SUSPEND_T9_CTRL = 1, -}; - /* Config update context */ struct mxt_cfg { u8 *raw; @@ -333,6 +333,8 @@ struct mxt_data { u8 stylus_aux_pressure; u8 stylus_aux_peak; bool use_retrigen_workaround; + struct regulator *reg_vdd; + struct regulator *reg_avdd; /* Cached parameters from object table */ u16 T5_address; @@ -2073,6 +2075,94 @@ static int mxt_read_info_block(struct mxt_data *data) return error; } +static void mxt_regulator_enable(struct mxt_data *data) +{ + int error; + + if (!data->reg_vdd || !data->reg_avdd) + return; + + gpiod_set_value(data->reset_gpio, 0); + + error = regulator_enable(data->reg_vdd); + if (error) + return; + + error = regulator_enable(data->reg_avdd); + if (error) { + regulator_disable(data->reg_vdd); + return; + } + + /* + * According to maXTouch power sequencing specification, RESET line + * must be kept low until some time after regulators come up to + * voltage + */ + msleep(MXT_REGULATOR_DELAY); + gpiod_set_value(data->reset_gpio, 1); + msleep(MXT_CHG_DELAY); + +retry_wait: + reinit_completion(&data->bl_completion); + data->in_bootloader = true; + error = mxt_wait_for_completion(data, &data->bl_completion, + MXT_POWERON_DELAY); + if (error == -EINTR) + goto retry_wait; + + data->in_bootloader = false; +} + +static void mxt_regulator_disable(struct mxt_data *data) +{ + if (!data->reg_vdd || !data->reg_avdd) + return; + + if (regulator_is_enabled(data->reg_vdd)) + regulator_disable(data->reg_vdd); + if (regulator_is_enabled(data->reg_avdd)) + regulator_disable(data->reg_avdd); +} + +static int mxt_probe_regulators(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + int error; + + /* Must have reset GPIO to use regulator support */ + if (!data->reset_gpio) { + error = -EINVAL; + goto fail; + } + + data->reg_vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(data->reg_vdd)) { + error = PTR_ERR(data->reg_vdd); + dev_err(dev, "Error %d getting vdd regulator\n", error); + goto fail; + } + + data->reg_avdd = devm_regulator_get(dev, "avdd"); + if (IS_ERR(data->reg_avdd)) { + error = PTR_ERR(data->reg_avdd); + dev_err(dev, "Error %d getting avdd regulator\n", error); + goto fail_release; + } + + mxt_regulator_enable(data); + + dev_dbg(dev, "Initialised regulators\n"); + return 0; + +fail_release: + regulator_put(data->reg_vdd); +fail: + data->reg_vdd = NULL; + data->reg_avdd = NULL; + return error; +} + static int mxt_read_t9_resolution(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -3139,7 +3229,12 @@ static int mxt_load_fw(struct device *dev, const char *fn) goto release_firmware; if (data->suspended) { - enable_irq(data->irq); + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) + mxt_regulator_enable(data); + + if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) + enable_irq(data->irq); + data->suspended = false; } @@ -3345,6 +3440,11 @@ static void mxt_start(struct mxt_data *data) MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); break; + case MXT_SUSPEND_REGULATOR: + enable_irq(data->irq); + mxt_regulator_enable(data); + break; + case MXT_SUSPEND_DEEP_SLEEP: default: /* @@ -3377,6 +3477,12 @@ static void mxt_stop(struct mxt_data *data) MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0); break; + case MXT_SUSPEND_REGULATOR: + disable_irq(data->irq); + mxt_regulator_disable(data); + mxt_reset_slots(data); + break; + case MXT_SUSPEND_DEEP_SLEEP: default: disable_irq(data->irq); @@ -3469,6 +3575,8 @@ static int mxt_parse_device_properties(struct mxt_data *data) data->t15_num_keys = n_keys; } + device_property_read_u32(dev, "atmel,suspend-mode", + &data->suspend_mode); return 0; } @@ -3555,14 +3663,18 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } - disable_irq(client->irq); - - if (data->reset_gpio) { + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + error = mxt_probe_regulators(data); + if (error) + return error; + } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } + disable_irq(data->irq); + error = mxt_initialize(data); if (error) return error; From patchwork Thu Mar 19 14:59:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447451 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 6E4F7913 for ; Thu, 19 Mar 2020 15:08:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5815F2072D for ; Thu, 19 Mar 2020 15:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727555AbgCSPIo (ORCPT ); Thu, 19 Mar 2020 11:08:44 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5928 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPIo (ORCPT ); Thu, 19 Mar 2020 11:08:44 -0400 IronPort-SDR: mX/mF8i9E4LParg3Cw+l34119zw9wzWI7U/RAfLBA3H0gcpX4tGtvHTowLGUxFVpqNyy2OvTXf AibtdvNaS8v1QkN1M0XdcxGJxm7pk9/+4jO2XKdElA/5XAnR2PzXHQlCPtHw9K5TfNFKAY6quB oOlTHZFW2kBE3Gesyg/oeTwOk0gqwSeQ8CDWKRZ8/p7A5DHIntvtYr795jEXrHzjwUZq1tFIrg 1chzlYkAv4JHYOFO7mSNrsj1rB5vQcfiGJ+hkydKsThXXsUGVko+llw0qL//EdcV2GKVn6/mbg /e0= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926777" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:17 -0800 IronPort-SDR: 8cp5apIWSgCOeGSuyZn0SAWGtSTO2dfEkughUIyAl9Ip2uIsINXEY97MAdqgjsUNPbkiNXhRm4 sr3ekubsGnbh5xTPO3+lp0zPo6gVhVaT9tA4X2AYfZGBg2liiQxgbNVj6+Oi5klnbCpdayLP3q k8S7b0aCMiSEtNMtP2sDAs4w1R1KUY2N2VLkA01s+pCYPBWXkxp+TKxfepi1wapg7QTfszcL3d 1G1uRxuJ/wDWzbYCj/+9sgDOLDD6+9VkDGCehBGRQeU2EN1nLdZfYfVBbkJOKjMHGhft5OO/6+ j1c= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 14/52] dt-bindings: input: atmel: add suspend mode support Date: Thu, 19 Mar 2020 07:59:38 -0700 Message-ID: <20200319150016.61398-15-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add suspend mode support for atmel touchscreen driver Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 6 +++++ MAINTAINERS | 1 + include/dt-bindings/input/atmel_mxt_ts.h | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+) 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 e48ab79879ac..350ae664e6f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2873,6 +2873,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/include/dt-bindings/input/atmel_mxt_ts.h b/include/dt-bindings/input/atmel_mxt_ts.h new file mode 100644 index 000000000000..41ed0f8111aa --- /dev/null +++ b/include/dt-bindings/input/atmel_mxt_ts.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * 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 Thu Mar 19 14:59:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447453 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 B79FC913 for ; Thu, 19 Mar 2020 15:08:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E8A72072D for ; Thu, 19 Mar 2020 15:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727498AbgCSPIs (ORCPT ); Thu, 19 Mar 2020 11:08:48 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5928 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPIr (ORCPT ); Thu, 19 Mar 2020 11:08:47 -0400 IronPort-SDR: A8yGx2caq0RoiWgRNRZWS3bQ1UByrXl1VDPUuJAtQHwKvqjI3sZudhN3QnSyxefsVGvSYFEoxa ikj1/HJM3BiQZkvmJjdifroqJxNsrZ4CC8sRp9xQZNI8a61rwXBWLWmo3Ygc8UTcs31yVvFn9z pyWTZdObnvihsyWq9rWQFdbVX7DJipoPsoHjPr/vAmiu/ms9tbSNMXUSQpEXbTT9dOArRlMdHg xAMXQshGFX1rzkyiIpAIKttjfFteoylXAV0Bg5JLiaFXINEdA1r1EaiNelPYtBephmLNiDrLW0 O1A= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926793" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:20 -0800 IronPort-SDR: /zGOg02V4r6x9SiLSpbak/vE1F1oXs580t9Wn9GhQCBpIoJ++53SPV1a4QniHq+zSecym2tSSE UmZsvG98OhlGWRlVAnXiXTKDjTZmGmZp7kmhCyYPneDEmAVg5me6oOFoWeHmBa3Gfqqi4TilLk toj39TO/Ak/XFt8Our9LagbeBerSvxNAXFNVBdQgrhC8uB8+ysCfqCo4V42tyFullnGme/6+fc nQCaEcd9ho9jNEfDV9wWU1n2gcRzD4iCgkc5KqL7yBbzS6QlyXRm77tqvHQ4TOPlFTjU/TiXLE ICc= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 15/52] Input: atmel_mxt_ts - report failures in suspend/resume Date: Thu, 19 Mar 2020 07:59:39 -0700 Message-ID: <20200319150016.61398-16-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer This patch reports failures in suspend/resume Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 93a57575403d) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Fix compilation warning Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 51 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index ef8baf64659e..f8783e37436f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3425,10 +3425,12 @@ static void mxt_reset_slots(struct mxt_data *data) mxt_input_sync(data); } -static void mxt_start(struct mxt_data *data) +static int mxt_start(struct mxt_data *data) { + int ret = 0; + if (!data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -3453,28 +3455,42 @@ static void mxt_start(struct mxt_data *data) */ mxt_process_messages_until_invalid(data); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + if (ret) + return ret; /* Recalibrate since chip has been in deep sleep */ - mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + ret = mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + if (ret) + return ret; + + ret = mxt_acquire_irq(data); + if (ret) + return ret; - mxt_acquire_irq(data); break; } data->suspended = false; + + return 0; } -static void mxt_stop(struct mxt_data *data) +static int mxt_stop(struct mxt_data *data) { + int ret; + if (data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ - mxt_write_object(data, + ret = mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0); + if (ret) + return ret; + break; case MXT_SUSPEND_REGULATOR: @@ -3487,29 +3503,40 @@ static void mxt_stop(struct mxt_data *data) default: disable_irq(data->irq); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + if (ret) + return ret; mxt_reset_slots(data); break; } data->suspended = true; + return 0; } static int mxt_input_open(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_start(data); + ret = mxt_start(data); - return 0; + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); + + return ret; } static void mxt_input_close(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_stop(data); + ret = mxt_stop(data); + + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); } static int mxt_parse_device_properties(struct mxt_data *data) From patchwork Thu Mar 19 14:59:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447333 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 6A508913 for ; Thu, 19 Mar 2020 15:01:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 545902072D for ; Thu, 19 Mar 2020 15:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgCSPB0 (ORCPT ); Thu, 19 Mar 2020 11:01:26 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5326 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727470AbgCSPB0 (ORCPT ); Thu, 19 Mar 2020 11:01:26 -0400 IronPort-SDR: A0RnMW872/LsAGAnDC9loRPWo0F9AnKDoXkG+N7O+lPAbi6zj9wMxNsLL7NX3L28ZTU7eWM1AT L51LxHshm+1p1LTq1FcEOOJzOZdz7aR/VJ3Ko7z/qzgy+9lY2Do8tCq6e9G+H2nfB4chE0IKnU x66tMIdRdBQsJ3aMVJFOlMyn2Zxe9MQAs0kiHNhZtOBMS5Ie1CcsvL1sBm9x6X4QeXs6v2cza5 LNkgqVxq7pfhT6p1EEBAqoLs2aMGRIgFo8ez3C+hPg7dkJuAtaHVBRtdtA9Xua/dtKW9FgB/tS /0o= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818671" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:24 -0800 IronPort-SDR: cRMiJ7ao3znRQ/de7XczIhuuuj0HpkHhMccz/THEMD/j/ar1rXbnvu6D4jLLlSdbXaXTZ26wzw QfA6pKYk+lZtn8TMaOFa+i6BLb6kedpLseCt3h2h3BEbvODryU37hFtI794Alz8UBOFUYhFtua wOApsxlhUSwVku6zP4xnefjH9+vYDg/7seWX7mTBYbDQWkZFAOU0pDR6Olch+Uh5i1I4pjRfVT N0qQ7IhTW2/QImfVKgITRRiFm6bb1m5onD+Mwp4dpCbnlmk0BNgZcldtKp21OavBvDnMtZH6q/ yg4= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 16/52] Input: atmel_mxt_ts - allow specification of firmware file name Date: Thu, 19 Mar 2020 07:59:40 -0700 Message-ID: <20200319150016.61398-17-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 f8783e37436f..0e30ff372a43 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 Thu Mar 19 14:59:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447455 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 80CD96CA for ; Thu, 19 Mar 2020 15:08:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FE5B2072D for ; Thu, 19 Mar 2020 15:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727724AbgCSPIz (ORCPT ); Thu, 19 Mar 2020 11:08:55 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5936 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPIz (ORCPT ); Thu, 19 Mar 2020 11:08:55 -0400 IronPort-SDR: hetNF/ujTtxreZ6YFVk8z9MhJnj2FR59AoDpX6cZEYvG5kV82O+khOkc5nAeHJdS4QrE9dtzdR nnLLOlwfFX+5eRKbPpfmL7F7DBWvtri2hzvjk2TNKCsNkQHuO5HjZ3DKo2ssmg2yuUuHOQd+Xw pjnBVTtBQzO8wr4d8DVwY69+Oce932q8Rp80qfzVN/wi5T+beyQbVfJ3Sc8v/8rbStwRKCKi21 X2CCMfaG4unAAJTEnGECKU0qJQu0Uvkry1KarpvC+TbYT6c3oE5XV9p/ls1qeqfvBL6Bp3aIuR EKA= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926822" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:29 -0800 IronPort-SDR: gj2U72aBqKE+TZAJsODZEihCB4BZbVETygDHuXguYMA1R3K4QXnVy0Hq/hVEdmWx08bpiBtPrS C+dWcO18ThQPgGLd6F2C5TAxZ9tVLbl89ciKBklpIARDtzZzFUzVhD4f9DEeyC/ULbzw6pj5/s yUSlr2HyYtesT6J7IIQdCin07TSnHbslz0L2OUadw9SsMaTljKlryMLPIP4KWwXRFDSr/+Hmic CIzCrjxJpAO/i6+0oAAP8jqn9Z/tP4RXzcOGzQvdDBGhdnEwPVpLmm2cCU3n9f52dXwkeooQtL v/g= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 17/52] Input: atmel_mxt_ts - handle cfg filename via pdata/sysfs Date: Thu, 19 Mar 2020 07:59:41 -0700 Message-ID: <20200319150016.61398-18-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 [jiada: Separate Documentation/ portion change to another commit Change Symbolic permissions 'S_IWUSR' to 0200] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 109 +++++++++++++++++++---- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0e30ff372a43..3ef98e14c94e 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, 0200, 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, 0200, 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) { @@ -3705,6 +3778,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 Thu Mar 19 14:59:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447457 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 495776CA for ; Thu, 19 Mar 2020 15:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3284E2072D for ; Thu, 19 Mar 2020 15:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727733AbgCSPI7 (ORCPT ); Thu, 19 Mar 2020 11:08:59 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5936 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPI7 (ORCPT ); Thu, 19 Mar 2020 11:08:59 -0400 IronPort-SDR: XpzddIKqmBnCcZ1zEWUlBMpp6ePbYlJqibb3EzHjnkuWkWCqFNauKVkInmP/T0+Wb7zKl3peMf Tu+G79SXUBMZY5I9JEm0ZVgdsCRr7szz1gsT/EvjS7humN4i6F7gz3AkP4kvHe98+p8y1rAEr6 fEknKcT1A7iyVOHmH/oTa+frymAmdJGw7tqv1nvg7jzQkkhhaW5kxB6b7W5TbVmU9UqolwUCaX WOnXb58AI/yYCAfFE6QUBpwq8YPnbWt9D+u2gFwvSoMWopw9+k/LDuo7DRX5ruAgV5zp3Z0MyD sH4= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926843" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:32 -0800 IronPort-SDR: 0nXmbnI2F+DjT/64+txdGLxD0MaYfr72IO8BkJxpfDTyD1kG4i7bxEIc5ZQl2wlwFk73ak/gWU G/FK6EZ80HkhZy9brGhT3WBYK2EZDL9+9OGJKa+ezRlmbmtYFZX+1puAzkBsmCNehnX95LZEs/ 7IeK8SSKFpBI+U9ir/stx4DpZKHjk6u9wTtBirE9AJXjcZftQg7FmjSQuQYngDwE3eZtgPuKYP 5FrG2yE8T9oBRfXA6xY1c1ajeWT/ly+wp5mHbYirj1c04zRlAWUC0KZqvRZQLKNRoF2YnWtCHj 8N4= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 18/52] dt-bindings: input: atmel: provide name of configuration file Date: Thu, 19 Mar 2020 07:59:42 -0700 Message-ID: <20200319150016.61398-19-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add support to set name of configuration file Signed-off-by: Jiada Wang --- Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index 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 { From patchwork Thu Mar 19 14:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447459 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 701D5913 for ; Thu, 19 Mar 2020 15:09:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59BA520CC7 for ; Thu, 19 Mar 2020 15:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgCSPJG (ORCPT ); Thu, 19 Mar 2020 11:09:06 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5956 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPJG (ORCPT ); Thu, 19 Mar 2020 11:09:06 -0400 IronPort-SDR: Amn3w9kvJCY9IGucDbC/S6ntif9zKsG1WCyIhjyvxXqbcpi3BxAPMUp96fOvkeSSG5gmwnpglS STULuLssD/H927p9RGe341Rttv0XeZVUXfQfYmeONqG8WGe12zOvHgpMc5JDVqeJeagvY+3uUr S1aynOznvosnE9m6XOi2kwfAtA8froZCPBUf9bhL+8gZncNFg11/0gaWJOy6/wRoKoeMiAoFtF BPZkasYSRFaL+vvKR2a6mwHHoIqgVATze2WjBlzpj9SK4264rFWlDE3JtIhus6Uc0yNDysmQcY 0e4= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926859" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:36 -0800 IronPort-SDR: +FOnKRzCPSsw49JPLxcC5GqTzcUHT7kOftklaPsUwd3J9WicnG0u60PAWq/LqQ6zUThSrcHvAo uYkkRpYfjlaunoIFB4WAJX9co8YgQ5a5j5orF07UGvbE/rkO3wG8yV9PIo5qnEWGXvNg24LlVE 4Idwf35ogDGGrlI8/IxyJSdd5l0aKrUjwHs8w8tjMJ8QhoA2Bps8BYd5nIVgSsYLdBTUj1S1mm o5powKlRhSpcafkR29VsEyFpmuTUKsvvUZcOMFLJY/TJz/JADqmSFMy8r40M6ZlJTkX3qLnkcQ bcA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 19/52] Input: atmel_mxt_ts - allow input name to be specified in platform data Date: Thu, 19 Mar 2020 07:59:43 -0700 Message-ID: <20200319150016.61398-20-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Android systems identify the input device and map to IDC file by using the input device name. To avoid unnecessary deltas to the driver file, allow this to be set from the platform data. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit cbf94a7bda754d2e1899d9f50313a0bccc91422d) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Separate Documentation/ portion change to another commit] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 3ef98e14c94e..c884c254ad2d 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 Thu Mar 19 14:59:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447335 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 BD4DF913 for ; Thu, 19 Mar 2020 15:01:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A3A2620CC7 for ; Thu, 19 Mar 2020 15:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727470AbgCSPBm (ORCPT ); Thu, 19 Mar 2020 11:01:42 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5374 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727428AbgCSPBl (ORCPT ); Thu, 19 Mar 2020 11:01:41 -0400 IronPort-SDR: 4Qg4svZXAvUjSgWybK+6foiDzKn6tS+4RwUVo0XPoEksD1mNCYFROqxqBllV4qvdaysWdiGU0u 4mmtwjWE9tjqWCOlM2HIp/aKhfPz1Ylm5foegGjXnbCkK0rJmZ3mdespnYwBY4z2y7RKgKYvGi mAIZBXZVV3Wi8qMX8Y6vDmcM9luIyAH4/8eFkgKx4e6xfNwPtyvZ14L1KvSBYY/t7mDzZmuavX lIEoiVTByw/6PL2WMA4pYpaGJkoTo+4pHFgkJ9HVPE+84BKLVtLb/AJpdHn719mf0GJH3BguUS lHQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818732" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:40 -0800 IronPort-SDR: xEsbXQoYGc/XXf4d9iGzTzf5HRxBgseMhlU4/Aiy2cUo+1GN8fOj2d5s6kyuNZ/YgN4aYOgEmr PjWC+Z61slivZkKN3Yl+YCF8EixhzeLVwZxw2x76nErmp0a4tRKgyR5GWQCI/VwyluYwujiR5k ZrY4gBto7HURYuIicClMk16hsqyTNG/ibBHA9GDM0TfVPRwbASZEc6tmYB0u2Bv2PfYNLN5fbh iQFyz69jw7E7BtZkRIqTa9rpGxdp6jWoQK6CY/EPP/gVMfuI85CYV/k9MvGGdOyZyU8GWJtCSI 0MM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 20/52] dt-bindings: input: atmel: support to specify input name Date: Thu, 19 Mar 2020 07:59:44 -0700 Message-ID: <20200319150016.61398-21-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 Support to specify input name Signed-off-by: Jiada Wang --- Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 2 ++ 1 file changed, 2 insertions(+) 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 { From patchwork Thu Mar 19 14:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447337 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 42B736CA for ; Thu, 19 Mar 2020 15:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AE702072D for ; Thu, 19 Mar 2020 15:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728009AbgCSPBv (ORCPT ); Thu, 19 Mar 2020 11:01:51 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16057 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbgCSPBv (ORCPT ); Thu, 19 Mar 2020 11:01:51 -0400 IronPort-SDR: TNgvDA/KA46KYzSH5F2jb3EAU33a5W1Q+RTaPW6EdIcB59dPMeuH0sxMeN2Y4GJrrd7peXTKOC /g7mZrajPqWNAbMAKJVIEoTA/yBIDTBaC/okhNNXK2Vlr2mO3QeTL5XfgIEOmxmcq2BQqcPDrc 1NBuP8De3UysYhHURT4XGWkKRt88m2zq5Q6wRjlYvqd6ARaUe4K124FcKl+CuS/CvKE75RKNU/ n9mqtSrrbiK8Dn1/xWF7SC6gaZfRQPdlhX7EenKrUPUrHgtoMKnow9WaVCfO3fe4G2PP+pxWW2 0sw= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850273" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:44 -0800 IronPort-SDR: GifHhdW9reHsOWogjSgcwZvkwmP2j3u57IFc+zwcZktN6TY/ZF53GcsTXew8owpgGEh54bcg2x pqr6Y1x5eXBTTihMFbUoRJqxJkGVpgJb9upEXMlcq+OKoa9o07Ny8mS5F9oriulCjOzngd75S7 fqxcrmsNRSjdztUypj1wPMEhu4+zN5azZ271UgFNp0AKEhVWxfJhBkgS48Z4sLQK0hqexQiyZN f7XhGGtxz2gS2+krkbFimkyjt+NmkTNRzlYsJTGaEDrt3DjytqZot7IQbm02Akz0oogQJ2SRhS +I0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 21/52] Input: atmel_mxt_ts - add config checksum attribute to sysfs Date: Thu, 19 Mar 2020 07:59:45 -0700 Message-ID: <20200319150016.61398-22-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 Add config checksum attribute to sysfs Signed-off-by: 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 [jiada: Add commit description Change Symbolic permissions 'S_IRUGO' to 0444] 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 c884c254ad2d..7441dc71bbab 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, 0200, NULL, mxt_update_cfg_store); +static DEVICE_ATTR(config_crc, 0444, 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 Thu Mar 19 14:59:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447339 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 7299F913 for ; Thu, 19 Mar 2020 15:01:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CD3E2072D for ; Thu, 19 Mar 2020 15:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727464AbgCSPBy (ORCPT ); Thu, 19 Mar 2020 11:01:54 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16057 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbgCSPBy (ORCPT ); Thu, 19 Mar 2020 11:01:54 -0400 IronPort-SDR: 620UCLGBEiSmZSvZyW6HnxYUJdaC35/EZ2gYPlkDc3sd+Bz/mS3ucBSPKix37lyR4N0fp60y3v QMfZnhUsSo4gtmgMUkuXDEaT/v19rmURNOKV6GiC/Js0t4hWFUxenFg7dV3qstk7gVC2JLBJ29 MO9HW9qQAH3MXFEqH7+vE9PVDfZADNAcX/WId0TNpkYuo/9sL4u7GM2ALFFLJvEE3452VOy1yQ o6GEqcfL5wZZX3dJUKmcjDcr8H5otCe3Bm09SQpuYQ6zhCns3zbjVvMLCPTXF77nghksH9goUB B5E= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850283" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:48 -0800 IronPort-SDR: zIMX+jzSTn0o3WVvrJPe1U41yNdyIcMbBtZrXiRstJh8fcDlkBisxrXv8zeLW1WBUzpcJPk6UZ jci47mG9NfXifxh0z+z9cGd1ldtrLiAIL9bXTJRaNXJU6f8wvi/CV0Hij1Zlmz6qn4ra1O88HN yDbPiLz2oGdj07VPOtVea7yxo6UVAE+kY8U85TYuPBtNQ5d6H1UNV91QrgoFf3XeAOkNRyn+s8 dWR57WkaZ0hgy1z/UOJTSCiVkL8RfnPYIm7iJL/7haQTd1RU4lFvtiEKLKaqfwGE+q0AK+j2fU meM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 22/52] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Thu, 19 Mar 2020 07:59:46 -0700 Message-ID: <20200319150016.61398-23-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Refactor firmware flash to extract context into struct Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 1bbe20ff3dcd6612e7942c495929eae5c138ece2) Signed-off-by: George G. Davis [jiada: Add commit description] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 +++++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 7441dc71bbab..e5dc554a0845 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 Thu Mar 19 14:59:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447341 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 CA57B6CA for ; Thu, 19 Mar 2020 15:02:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2EB920B1F for ; Thu, 19 Mar 2020 15:02:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727690AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32318 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgCSPCI (ORCPT ); Thu, 19 Mar 2020 11:02:08 -0400 IronPort-SDR: OyItQqcIyCP/SBzqXQJCiP0w+FrwGmauM2MFaD9XlSQn98S4nBc/vqxwHA5wWBMcTmHQ05TKUK oRc0W63LN56vaAd7msQcM2+hYubbIX14JC4J0VZYudqZKvIs2awgQiTEhE+szhuQI4c8viBkcz bPhDeoPGiQKAY9YSGFYwxLg27VEqkxMi7sls27S2ynFRlLKxQAZrUUvIZQiyuwX603QQR7IHMw yiy1OyR2LHVebqPafF2XFFtJeNQ/dE8k+YtUnOsCFly4vu3kaardv24sIDNixubvwrD+eBPUnw POk= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46890921" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:52 -0800 IronPort-SDR: 0fluhvLogtlYw42cqS6Gs1FsUeJQ1gp22+Esg0fqFlplIcZEx8eExGTbrVOYRazaKQvOsiBZ3f U6TPLB6V28YvHEjWv1CAeCLsEPCi9MI0s+QWo5+Aobgqa607IxACY7pGnQaudZBwIGaE0q9jAl 7PcK+4frl7Lus6QfYyckzmZ30yImRmliYSIrSuoiAN9TGiJIBw1oA1OcqGoP1RTBeDdVW1Y4k3 Bz460MkebPFIYxniJVOAdWWurBrtnsBFWMyahuEDOhxVy8WS0n1kXmJVmIJn66LVa63sOIn1Bb plE= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 23/52] Input: atmel_mxt_ts - refactor code to enter bootloader into separate func Date: Thu, 19 Mar 2020 07:59:47 -0700 Message-ID: <20200319150016.61398-24-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Refactor code to enter bootloader into separate func 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 Add commit description] 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 e5dc554a0845..b4d0835ba196 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 Thu Mar 19 14:59:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447381 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 C129D6CA for ; Thu, 19 Mar 2020 15:03:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB26920CC7 for ; Thu, 19 Mar 2020 15:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728059AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32318 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 IronPort-SDR: wsBm9OJ5BrWEUx9FXRVEk3wNI5zEgNhs8MJ9EJbHUHIyD2xE2wsS7It1qWygHYDFvcZVdrvQ2/ kneeP7d2A3VKWe/gX2OJe6PbITp+Dn10sNyUDu4dHwOiwPuy7pdFHAHDqvO30Ys7Xo4kr2gwoj 1/QpcIfCrkao7mU+XQer+X+sDCu+zxtg1FHuhjqbDGl+5YNVa6qKnBqdK8u7DD3w660bqQIEC2 t8kx2nA8emmPx49SUB1yvAOrgnjfpHulRVxnSMOfz/FFGadk+lKtZfttRlG/lHPPFW3vkD6vW5 ZVQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46890925" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:01:56 -0800 IronPort-SDR: vDMOe30BYfCDN4tGoOf0E9kdQwP7uuCn9nI+QgAIHeWL6QXCnI2bVIgF7ZD39SA1O20pHzet6s T2bYDg6u9bl7wU0sRHyzloPxjkXPjMCgzQ/UADCJulsMe0fKDEHulj68cCLNNAGmcNmYEzaTbG f5e1rjzwr7l15CF24hcVpFXYqw6PTRKkPljE7MywNs6uutq0uA+Gags2AQHH4DhSBMQUkGzrpg B5h0PERcB8DTeJ5TKH6Kiuu4dOz0a7k8/OTVzed5MqzVVxdQp+yKP6yFB8nL5lVvA9G3cg8LnS wzA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 24/52] Input: atmel_mxt_ts - combine bootloader version query with probe Date: Thu, 19 Mar 2020 07:59:48 -0700 Message-ID: <20200319150016.61398-25-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 b4d0835ba196..d3d6e4e60f67 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 Thu Mar 19 14:59:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447367 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 2B45C913 for ; Thu, 19 Mar 2020 15:02:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B88320CC7 for ; Thu, 19 Mar 2020 15:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727725AbgCSPC6 (ORCPT ); Thu, 19 Mar 2020 11:02:58 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32318 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727755AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 IronPort-SDR: cj+kJ7WwwbDNnRmAbytJyGJueg4MWyKgXToi8mHW1SBtdMu/r8xVePixQWNCHPFqL4xKR7qLKU llCrKqmIemAdIDXRhMvIy5E9VbZ1Vy3hp+o2MrzhYS3cVJRs2l0p7obtuVUZK0IV3D3zTwxJkA j1CFSs6jO2rGZKFy+iinVVN0DCtLHncn4zqjNiOsSezl1lQDzsNAuTpsv3BlPPrC4DZbK2JQ/M F3tJwbCCBCi08G9mKUFpEi6UJiJuPig9MPboFE3QrUGH+lxF5CoAx9bzPyJ0ET5YDJTo0olcnu 22M= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46890933" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:00 -0800 IronPort-SDR: 00fadSNKOcGanxNOgACkAJ5jAfils4q1yKVSXJLCPt9jTO5eUXU17ifmDkUMWdN1++X0ars9ja jBPBWnOmPFy3ubdxdPxPYQXFLa7fd/9rWVuXMvE6bQWxubVM72IIBDHj7EFwVpyQUtiLeyXV93 yyNIV8cqp6XlQrHpHCJ30MIHW1g77AFS5wlzJ4hSxu/vOJoI3Q1AuqCiezXcgGIyQ1cbvV63au HTJYw6lZ9cYUndRG8vuSJg/T/zc+5e+WuAFiKLy3vaglL6RlkjkOmZqjWrD4+gFDRBv4loIv2N 1dQ= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 25/52] Input: atmel_mxt_ts - improve bootloader state machine handling Date: Thu, 19 Mar 2020 07:59:49 -0700 Message-ID: <20200319150016.61398-26-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer The code is much clearer if we switch on the actual state the bootloader is in, rather than the state we want it to be in, and allows the removal of a goto retry tangle. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 463e15ee95ee6e6274017ff645839dbe34d75c99) [gdavis: Squash fix from George G. Davis: - input: atmel_mxt_ts - Fix 'mxt_send_bootloader_cmd' was not declared warning] Signed-off-by: George G. Davis [jiada: only wait on some status change, cleanup code style] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 165 +++++++++++++---------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d3d6e4e60f67..c287ab3ebeac 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -305,6 +305,9 @@ struct mxt_flash { size_t frame_size; unsigned int count; unsigned int retry; + u8 previous; + bool complete; + bool wait; }; /* Each client has this additional data */ @@ -583,15 +586,27 @@ static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) return 0; } -static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, - bool wait) +static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock); + +static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) +{ + f->frame = (struct mxt_fw_frame *)(f->fw->data + f->pos); + + /* Take account of CRC bytes */ + f->frame_size = __be16_to_cpu(f->frame->size) + 2U; + + /* Write one frame to device */ + return mxt_bootloader_write(data, f->fw->data + f->pos, + f->frame_size); +} + +static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) { struct device *dev = &data->client->dev; - u8 val; + u8 state; int ret; -recheck: - if (wait) { + if (f->wait) { /* * In application update mode, the interrupt * line signals state transitions. We must wait for the @@ -607,40 +622,96 @@ static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, * by writing length 0x000 to device (iff we are in * WAITING_FRAME_DATA state). */ - dev_err(dev, "Update wait error %d\n", ret); + dev_warn(dev, "Update wait error %d\n", ret); return ret; } } - ret = mxt_bootloader_read(data, &val, 1); + f->wait = false; + + ret = mxt_bootloader_read(data, &state, 1); if (ret) return ret; + /* Remove don't care bits */ + if (state & ~MXT_BOOT_STATUS_MASK) + state &= ~MXT_BOOT_STATUS_MASK; + switch (state) { case MXT_WAITING_BOOTLOAD_CMD: + dev_info(dev, "Unlocking bootloader\n"); + ret = mxt_send_bootloader_cmd(data, true); + if (ret) + return ret; + f->wait = true; + + break; + case MXT_WAITING_FRAME_DATA: - case MXT_APP_CRC_FAIL: - val &= ~MXT_BOOT_STATUS_MASK; + if (f->previous != MXT_WAITING_BOOTLOAD_CMD && + f->previous != MXT_FRAME_CRC_PASS && + f->previous != MXT_FRAME_CRC_FAIL) + goto unexpected; + + ret = mxt_write_firmware_frame(data, f); + if (ret) + return ret; + + f->wait = true; + + break; + + case MXT_FRAME_CRC_CHECK: + if (f->previous != MXT_WAITING_FRAME_DATA) + goto unexpected; + f->wait = true; break; + case MXT_FRAME_CRC_PASS: - if (val == MXT_FRAME_CRC_CHECK) { - goto recheck; - } else if (val == MXT_FRAME_CRC_FAIL) { - dev_err(dev, "Bootloader CRC fail\n"); - return -EINVAL; + if (f->previous != MXT_FRAME_CRC_CHECK) + goto unexpected; + + /* Next frame */ + f->retry = 0; + f->pos += f->frame_size; + f->count++; + f->wait = true; + + if (f->pos >= f->fw->size) { + f->complete = true; + dev_info(dev, "Sent %u frames, %zu bytes\n", + f->count, f->fw->size); + } else if (f->count % 50 == 0) { + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f->count, f->pos, f->fw->size); + } + + break; + + case MXT_FRAME_CRC_FAIL: + if (f->retry > 20) { + dev_err(dev, "Retry count exceeded\n"); + return -EIO; } + + /* Back off by 20ms per retry */ + dev_dbg(dev, "Bootloader frame CRC failure\n"); + f->retry++; + f->wait = true; + msleep(f->retry * 20); break; + default: return -EINVAL; } - if (val != state) { - dev_err(dev, "Invalid bootloader state %02X != %02X\n", - val, state); - return -EINVAL; - } + f->previous = state; return 0; + +unexpected: + dev_err(dev, "Unexpected state transition\n"); + return -EINVAL; } static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) @@ -3301,57 +3372,13 @@ static int mxt_load_fw(struct device *dev) if (ret) goto release_firmware; - ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); - if (ret) { - /* Bootloader may still be unlocked from previous attempt */ - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false); - if (ret) - goto disable_irq; - } else { - dev_info(dev, "Unlocking bootloader\n"); - - /* Unlock bootloader */ - ret = mxt_send_bootloader_cmd(data, true); + while (true) { + ret = mxt_check_bootloader(data, &f); if (ret) - goto disable_irq; - } - - while (f.pos < f.fw->size) { - f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); - - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); - if (ret) - goto disable_irq; - - /* Take account of CRC bytes */ - f.frame_size = __be16_to_cpu(f.frame->size) + 2U; - - /* Write one frame to device */ - ret = mxt_bootloader_write(data, f.fw->data + f.pos, - f.frame_size); - if (ret) - goto disable_irq; - - ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); - if (ret) { - f.retry++; - - /* Back off by 20ms per retry */ - msleep(f.retry * 20); - - if (f.retry > 20) { - dev_err(dev, "Retry count exceeded\n"); - goto disable_irq; - } - } else { - f.retry = 0; - f.pos += f.frame_size; - f.count++; - } + return ret; - if (f.count % 50 == 0) - dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", - f.count, f.pos, f.fw->size); + if (f.complete) + break; } /* Wait for flash. */ @@ -3360,7 +3387,6 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3370,7 +3396,6 @@ static int mxt_load_fw(struct device *dev) mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); data->in_bootloader = false; - disable_irq: disable_irq(data->irq); release_firmware: From patchwork Thu Mar 19 14:59:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447355 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 008E26CA for ; Thu, 19 Mar 2020 15:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF0A52137B for ; Thu, 19 Mar 2020 15:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728103AbgCSPCL (ORCPT ); Thu, 19 Mar 2020 11:02:11 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32319 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 IronPort-SDR: ZPIXWN2epu8rTmYhP+MZHaQhnB8S6TiKzDlJtkFDCTYrf8tGjfwwvxccZ3tOGtvBeKsXTL9DcE s/NhPrCFxkitnqPgwi+EdV/ImLmwKkFz4kQkCzhHWUipAWvW94mR4aAAtrY+zqX1sBwHHsjZFL C+MBQpPNIhUqvzSOjehRI833CrF7wITpWMR5Pk1p0yR+SVBtvd7eLbd9uaXyusWaimLt8NxRSm EjpK45xJ0zZRnLH96cWdAQJB+MWfvvoWXAwsnocwsvczAn2jWUOKqqYMGs6NgJtQp0+KHdHueh 6dQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46890938" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:03 -0800 IronPort-SDR: g/1lThu/cUWsaIkxGco71fNb/FgJYIzDvEqR7PqsV7e1Z9zay5Lr9pulp3a9zA4A1pl5KMn586 1vmInq1EyHWewRLNIVjftdwdGROgHkwjd7YMQF3Df198BfiBA4PLBD5WbbvsL3MuWLfu987c4d qQCv0iqitxT1gghiUETJ/bG9HMsV3N3Vc6klyp1GNjZ+fwN52OrVaBk0OWhnhPpJ7A40xHZk4Q wPAWwWnh0NJ1OPShoclUOwK54E+mlHQrG/h9gP/hKrGFekyZvGfjBa07UARC0T5Fb4ZhX+jP6Q 1vU= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 26/52] Input: atmel_mxt_ts - rename bl_completion to chg_completion Date: Thu, 19 Mar 2020 07:59:50 -0700 Message-ID: <20200319150016.61398-27-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 Rename bl_completion to chg_completion 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 Add commit description] 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 c287ab3ebeac..e94da2e0b073 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -382,9 +382,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; @@ -396,6 +393,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; @@ -613,7 +613,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) { /* @@ -1414,8 +1414,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; } @@ -2179,9 +2178,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; @@ -3346,7 +3345,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; } @@ -3382,7 +3381,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; @@ -3393,7 +3392,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: @@ -3815,7 +3814,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 Thu Mar 19 14:59:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447359 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 0E06A6CA for ; Thu, 19 Mar 2020 15:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E275B2137B for ; Thu, 19 Mar 2020 15:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727102AbgCSPCL (ORCPT ); Thu, 19 Mar 2020 11:02:11 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32318 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgCSPCJ (ORCPT ); Thu, 19 Mar 2020 11:02:09 -0400 IronPort-SDR: qzUkUYayZo2eVz4qT5tbThfvXKkQ3NIeiJJU9Hg3Snzi5vdrnks0SKmWJcRNcu6riBHEME/CCg sEl9cQTr5VtYxSRHIcfq3+LcMHl5EMRNpY4EXqLtxJj+Sh7TXF7uMBlLjYXbK1BVVDMkuAKyja ylG+H9o4+lJY60FshdA1oxJrPwjrH4kq2a5W3o0Gc9TFLAB/aqw/j9mtpuot6pDESw/vPUqpdd WU+cTM+L/YDaELdTFe365zGeWnpzynjKlNAKZsEN6c32Qf23FPddjxvp55Z95/u0GgW7G+MwYM 89E= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46890951" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:08 -0800 IronPort-SDR: K4A3tHczVrnEBIbbF11pkgVuEbGyFcd5nR0C51fpFmezuzMvzOlenGj4hGTF8w4vq8bCZluY8i l6Fc6vAxc2BDwLktBXZGSmF+h5yCtqBQZglVBJzBJqesN58mK7XctJPAPpZ5ZB3w38fDwSywm3 PHrqwROFOQBEA4eDOV1ibumDp2pfoipy+wa1tPDFZjrui0zdIfsWbWqrM0h0QkQAEjpInts1rm EJSCQqtA/6sMpgLHuVWugsBiHBHL6+WdTadpGl9A9vX+l7+wH3grei++xCaL3lOKXroFmrpTsH cdg= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 27/52] Input: atmel_mxt_ts - make bootloader interrupt driven Date: Thu, 19 Mar 2020 07:59:51 -0700 Message-ID: <20200319150016.61398-28-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Make bootloader interrupt driven Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 67a3eea0cfc724c3c2a7410ac064f74227c7c6ef) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Replace two use msecs_to_jiffies() instead of HZ, remove check of &data->flash->work don't poll to call mxt_check_bootloader() in mxt_check_bootloader()] Reported-by: kbuild test robot Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 127 ++++++++++------------- 1 file changed, 57 insertions(+), 70 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index e94da2e0b073..ad4a105fe591 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,7 @@ enum t100_type { #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ +#define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -299,6 +301,7 @@ struct mxt_fw_frame { /* Firmware update context */ struct mxt_flash { + struct mxt_data *data; const struct firmware *fw; struct mxt_fw_frame *frame; loff_t pos; @@ -306,8 +309,8 @@ struct mxt_flash { unsigned int count; unsigned int retry; u8 previous; - bool complete; - bool wait; + struct completion flash_completion; + struct delayed_work work; }; /* Each client has this additional data */ @@ -356,6 +359,7 @@ struct mxt_data { char *cfg_name; const char *pcfg_name; const char *input_name; + struct mxt_flash *flash; /* Cached parameters from object table */ u16 T5_address; @@ -600,35 +604,19 @@ static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) f->frame_size); } -static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) +static int mxt_check_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; + struct mxt_flash *f = data->flash; u8 state; int ret; - if (f->wait) { - /* - * In application update mode, the interrupt - * line signals state transitions. We must wait for the - * CHG assertion before reading the status byte. - * Once the status byte has been read, the line is deasserted. - */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_CHG_TIMEOUT); - if (ret) { - /* - * TODO: handle -ERESTARTSYS better by terminating - * fw update process before returning to userspace - * by writing length 0x000 to device (iff we are in - * WAITING_FRAME_DATA state). - */ - dev_warn(dev, "Update wait error %d\n", ret); - return ret; - } + /* Handle interrupt after download/flash process */ + if (f->pos >= f->fw->size) { + complete(&f->flash_completion); + return 0; } - f->wait = false; - ret = mxt_bootloader_read(data, &state, 1); if (ret) return ret; @@ -643,7 +631,6 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) ret = mxt_send_bootloader_cmd(data, true); if (ret) return ret; - f->wait = true; break; @@ -657,14 +644,11 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) if (ret) return ret; - f->wait = true; - break; case MXT_FRAME_CRC_CHECK: if (f->previous != MXT_WAITING_FRAME_DATA) goto unexpected; - f->wait = true; break; case MXT_FRAME_CRC_PASS: @@ -675,16 +659,13 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->retry = 0; f->pos += f->frame_size; f->count++; - f->wait = true; - if (f->pos >= f->fw->size) { - f->complete = true; + if (f->pos >= f->fw->size) dev_info(dev, "Sent %u frames, %zu bytes\n", f->count, f->fw->size); - } else if (f->count % 50 == 0) { + else if (f->count % 50 == 0) dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", f->count, f->pos, f->fw->size); - } break; @@ -697,7 +678,6 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) /* Back off by 20ms per retry */ dev_dbg(dev, "Bootloader frame CRC failure\n"); f->retry++; - f->wait = true; msleep(f->retry * 20); break; @@ -1415,7 +1395,11 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->in_bootloader) { complete(&data->chg_completion); - return IRQ_HANDLED; + + if (data->flash) + cancel_delayed_work_sync(&data->flash->work); + + return IRQ_RETVAL(mxt_check_bootloader(data)); } if (!data->object_table) @@ -3316,16 +3300,13 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (data->suspend_mode == MXT_SUSPEND_REGULATOR) mxt_regulator_enable(data); - if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) - enable_irq(data->irq); - data->suspended = false; } if (!data->in_bootloader) { - /* Change to the bootloader mode */ - data->in_bootloader = true; + disable_irq(data->irq); + /* Change to the bootloader mode */ ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); if (ret) @@ -3338,67 +3319,73 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (ret) return ret; + data->in_bootloader = true; mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); - } else { - enable_irq(data->irq); } - reinit_completion(&data->chg_completion); + dev_dbg(&data->client->dev, "Entered bootloader\n"); return 0; } +static void mxt_fw_work(struct work_struct *work) +{ + struct mxt_flash *f = + container_of(work, struct mxt_flash, work.work); + + mxt_check_bootloader(f->data); +} + static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&f.fw, data->fw_name, dev); + data->flash = devm_kzalloc(dev, sizeof(struct mxt_flash), GFP_KERNEL); + if (!data->flash) + return -ENOMEM; + + data->flash->data = data; + + ret = request_firmware(&data->flash->fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); - return ret; + goto free; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, f.fw); + ret = mxt_check_firmware_format(dev, data->flash->fw); if (ret) goto release_firmware; - ret = mxt_enter_bootloader(data); - if (ret) - goto release_firmware; + init_completion(&data->flash->flash_completion); + INIT_DELAYED_WORK(&data->flash->work, mxt_fw_work); + reinit_completion(&data->flash->flash_completion); - while (true) { - ret = mxt_check_bootloader(data, &f); + if (!data->in_bootloader) { + ret = mxt_enter_bootloader(data); if (ret) - return ret; - - if (f.complete) - break; + goto release_firmware; } - /* Wait for flash. */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_RESET_TIME); - if (ret) - goto disable_irq; + enable_irq(data->irq); + /* Poll after 0.1s if no interrupt received */ + schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); - /* - * Wait for device to reset. Some bootloader versions do not assert - * the CHG line after bootloading has finished, so ignore potential - * errors. - */ - mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); + /* Wait for flash. */ + ret = mxt_wait_for_completion(data, &data->flash->flash_completion, + MXT_BOOTLOADER_WAIT); - data->in_bootloader = false; -disable_irq: disable_irq(data->irq); + cancel_delayed_work_sync(&data->flash->work); + data->in_bootloader = false; release_firmware: - release_firmware(f.fw); + release_firmware(data->flash->fw); +free: + devm_kfree(dev, data->flash); return ret; } From patchwork Thu Mar 19 14:59:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447353 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 AB24B6CA for ; Thu, 19 Mar 2020 15:02:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94A58215A4 for ; Thu, 19 Mar 2020 15:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727550AbgCSPCP (ORCPT ); Thu, 19 Mar 2020 11:02:15 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbgCSPCN (ORCPT ); Thu, 19 Mar 2020 11:02:13 -0400 IronPort-SDR: F0nOklVfXIA3ZcihUc3iikvUnwWRSlugPqhcFtLr9bQzOzWjkM8zA9qSDOZG+Pvt3mkcNcb7yv Lqz05usMIGuIatepm97flzXhPxjUy0sufyEDSR5z/nQYEUWFYnF2oAVSmIgRhZVSPSzYaY/PB1 H8m0/AIwAjAx9dh7LKjagl6p6qLqyELCdbI2L8bX9KXM3xOubL+DLSJlKAXrMrq1SgTEt0LJ1E DxUJIoA3qbQw2apC9mhQGvxNNFzcC1tYhKaitDXBjg1PvyjHAQTB9Swh7IqHnFNiFEhwTEPMYv q/0= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850327" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:12 -0800 IronPort-SDR: Nlriu48f2o9f4dwVVGH1kWZpqLfke52zK27+jOufvshaOeOP7LBDviQPdlAZrcAe6HitimZWvU AUpHuvoTvzFEdB3W49z7clBm2O/IjnlgdM1xufkc6vxLkd8AjE649SFAy2OWhU8hueNxe7pruz S0oUwqIqkhqvpul8O+czh4YDOHBySsMaDZeZ88o0jPsaP4niL5Gclwa/C+fk5FqqU/pyhLSrS2 xkbGLu41xCJSLsN88IF8RsAszuQxg0ujL/FTaT6jeO6KSdfi/WUpI3DJQ8oLCo07L9D7vlSS8Q Rcw= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 28/52] Input: atmel_mxt_ts - delay enabling IRQ when not using regulators Date: Thu, 19 Mar 2020 07:59:52 -0700 Message-ID: <20200319150016.61398-29-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 ad4a105fe591..a1a322f41f9e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1448,9 +1448,24 @@ static int mxt_acquire_irq(struct mxt_data *data) { int error; - enable_irq(data->irq); + if (!data->irq) { + error = devm_request_threaded_irq(&data->client->dev, + data->client->irq, + NULL, mxt_interrupt, + IRQF_ONESHOT, + data->client->name, data); + if (error) { + dev_err(&data->client->dev, "Error requesting irq\n"); + return error; + } - if (data->use_retrigen_workaround) { + /* Presence of data->irq means IRQ initialised */ + data->irq = data->client->irq; + } else { + enable_irq(data->irq); + } + + if (data->object_table && data->use_retrigen_workaround) { error = mxt_process_messages_until_invalid(data); if (error) return error; @@ -3370,7 +3385,9 @@ static int mxt_load_fw(struct device *dev) goto release_firmware; } - enable_irq(data->irq); + ret = mxt_acquire_irq(data); + if (ret) + goto release_firmware; /* Poll after 0.1s if no interrupt received */ schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); @@ -3798,7 +3815,6 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) client->adapter->nr, client->addr); data->client = client; - data->irq = client->irq; i2c_set_clientdata(client, data); init_completion(&data->chg_completion); @@ -3826,26 +3842,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, - NULL, mxt_interrupt, IRQF_ONESHOT, - client->name, data); - if (error) { - dev_err(&client->dev, "Failed to register interrupt\n"); - return error; - } - if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + error = mxt_acquire_irq(data); + if (error) + return error; + error = mxt_probe_regulators(data); if (error) return error; + + disable_irq(data->irq); } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } - disable_irq(data->irq); - error = mxt_initialize(data); if (error) return error; From patchwork Thu Mar 19 14:59:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447343 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 1224E6CA for ; Thu, 19 Mar 2020 15:02:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F016320B1F for ; Thu, 19 Mar 2020 15:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728112AbgCSPCQ (ORCPT ); Thu, 19 Mar 2020 11:02:16 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgCSPCQ (ORCPT ); Thu, 19 Mar 2020 11:02:16 -0400 IronPort-SDR: DDqhPAIgi65i0UbSP7JQ1AM3sPclp2C2kGTvBVe8Z0+dWglERdvX5/OmCPN6hLww43yblged7V 5dCJq9unJBYgKK4I9R1sKlvFBTiAriKZmvhCqYp2L8xaRWU/sZCOrAoM7xClfQwWVSkJTPefi+ +D6c4OK/wsLzclKfhHLwaoepKPxDM84U8RdJWi0goiXDhJe+E9NYI/V5LtIGXcLFuil0ESMh97 9feytIIZ7yXAXU+T1ZNjkl1PxhHUjHNKXCFN/7vbQyP4y89oSdKTed+eGnhC8ICeVqs7J27HLr HVg= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850336" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:15 -0800 IronPort-SDR: 8AHbllqAEXjVKi7pyS7LCzE63lgnJpSwq1IaOWeCJgxcLDCznpIgfnKRvj5DnXiZO9hTXLlcYQ qgjbNCS6UvuYyilE3IT3ka0GKGTBg6t2bIi/SL+jITUJFK4aIWIEtrFTkJOm/xGqoTm8z/eWwI lYT72GVel+K5MBm68fs9eytdzxQ4mgMZXEo0kaW/wzx0PeDdTjDOd9V+kGXLpJRJwUaHXHnLHb pNS2IwyISlfAbU1FE+lRyOmx67bNSALtEacWbDk26YxWrQI+xWCYZyy4ScCHkv98zD/v5kjSSJ 90E= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 29/52] Input: atmel_mxt_ts - implement I2C retries Date: Thu, 19 Mar 2020 07:59:53 -0700 Message-ID: <20200319150016.61398-30-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 a1a322f41f9e..670159c2f218 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -216,6 +216,7 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_WAKEUP_TIME 25 /* msec */ #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ @@ -720,6 +721,7 @@ static int __mxt_read_chunk(struct i2c_client *client, struct i2c_msg xfer[2]; u8 buf[2]; int ret; + bool retry = false; buf[0] = reg & 0xff; buf[1] = (reg >> 8) & 0xff; @@ -736,17 +738,22 @@ static int __mxt_read_chunk(struct i2c_client *client, xfer[1].len = len; xfer[1].buf = val; - ret = i2c_transfer(client->adapter, xfer, 2); - if (ret == 2) { - ret = 0; - } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", - __func__, ret); +retry_read: + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); + if (ret != ARRAY_SIZE(xfer)) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_read; + } else { + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return -EIO; + } } - return ret; + return 0; } static int __mxt_read_reg(struct i2c_client *client, @@ -777,6 +784,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, u8 *buf; size_t count; int ret; + bool retry = false; count = len + 2; buf = kmalloc(count, GFP_KERNEL); @@ -787,14 +795,21 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, buf[1] = (reg >> 8) & 0xff; memcpy(&buf[2], val, len); +retry_write: ret = i2c_master_send(client, buf, count); - if (ret == count) { - ret = 0; - } else { - if (ret >= 0) + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + } + } else { + ret = 0; } kfree(buf); From patchwork Thu Mar 19 14:59:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447351 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 AF881139A for ; Thu, 19 Mar 2020 15:02:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99B1F2173E for ; Thu, 19 Mar 2020 15:02:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727720AbgCSPCX (ORCPT ); Thu, 19 Mar 2020 11:02:23 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgCSPCV (ORCPT ); Thu, 19 Mar 2020 11:02:21 -0400 IronPort-SDR: 0zTL7Za8JOUEyJPdPMenA9n7460q6vvYfF4VzN0cpemyXMwJxtlcpG0ZkS5ULfOYzlmxD8e+Eq P3PXeO4++u3unfcFIt6jcwE52SbZnRgdtHkriuY1BvJ6vbEVj73M2jOtOWFUuwDbqbSrUTBM1U x+8hufDwcqu8SovbEjB8nW4uv5OfukistON63N3rdHtUUjyYvwtHG2glOxVBULSFnRBwhOBjuI xE4Wfj6r90SoUrnRR9RfW4+NmGECBAolfm4JFmr/3+tJOenj7rpHnUUT0Ute8IVcfVdw7zeqp1 nWM= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850344" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:19 -0800 IronPort-SDR: 7+VyomUZtwuDSYAh/SY6xAWH61GxtJJCC9q1OnWr8SWj/fLw5gaLoApLCfNrm9kXu4FPX7oWeH mbhS/18AQcub+EhPx3bzxG1WDZDSqq+xWFXhe8SrhXp8NCB3kx/4xZlHS/Grez27r193G3cO21 aXFarAcgjeZlNEpuheWnHUCG0h3TuWmpO+E2g5z1g4AXP9xwwDFDSvro3rr1DwFcbFL6uC2LeY aTGLE+v4+2pNFYdEu3sIRNDzxvRx5h0lNfUIxs/26AgXtv9Katg99ivA1M8TIvIcLYMvfqimpT R+s= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 30/52] Input: atmel_mxt_ts - orientation is not present in hover Date: Thu, 19 Mar 2020 07:59:54 -0700 Message-ID: <20200319150016.61398-31-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 670159c2f218..2c3a59ff70c4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1026,10 +1026,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 Thu Mar 19 14:59:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447345 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 956E2913 for ; Thu, 19 Mar 2020 15:02:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E9632145D for ; Thu, 19 Mar 2020 15:02:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728129AbgCSPCY (ORCPT ); Thu, 19 Mar 2020 11:02:24 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728207AbgCSPCY (ORCPT ); Thu, 19 Mar 2020 11:02:24 -0400 IronPort-SDR: Bv49ZsGTTNOxYrDxlZi43iL1dBnPC1rLdbrwd9rCzcB68DK1Pely9KV9zPSK61rBkqSJ6fJ60K c1ggTCpMVJht3wFQzFcmZ54WtISbqGLoQNDc2Pf+3WkALroF9QBehJTn55lIv/EVxbzds4Huzo S7FmnGv1/fpJNY4utwKOV+Pn8bSmopRliVp+EiiFUUxtLhLz3vIThINWLmgwTAmK1ZKsykov0s 8sFSRmBEnhBH3bIlrRTjPUtajza7Xhg0ZEPVrYrrNxryug6kZSeTaXgdbIwhBpb+nSPIRTGsva Rrg= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850347" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:23 -0800 IronPort-SDR: OhiAWB4TLJDcXnwdj0IrUqS8MTXx3b1Be1OUlqFd+GjkmwtnedSafK6Q21PeUWxBeo1c1lwnHg gHzzIhvTqakO9bnnYh7woP6dVZufH0kgnBjTv1f2aPe79Zd/dnwmvcgDiyqryJ4Ools0pcaag3 63o6zqCD4sKBIgonuszlecKGOV794+xtterg/1J+4QzHwDR4Gs55zD0M+1SOCTwFZU9WqvjoMl CWAByLYVIYgESEctvggX5GQ/l9rH7U4xquCyRSLKRR34QeX4ZTGU4gpCxrQtj4Jv4nkdI7+z58 7sY= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 31/52] Input: atmel_mxt_ts - implement debug output for messages Date: Thu, 19 Mar 2020 07:59:55 -0700 Message-ID: <20200319150016.61398-32-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 [jiada: Replace symbolic permissions 'S_IWUSR | S_IRUSR' with 0600] 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 2c3a59ff70c4..10da40c6c91b 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, @@ -1211,6 +1215,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; @@ -1245,9 +1250,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; } @@ -3519,6 +3527,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, 0200, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3535,6 +3573,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, 0200, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, 0444, mxt_config_crc_show, NULL); +static DEVICE_ATTR(debug_enable, 0600, mxt_debug_enable_show, + mxt_debug_enable_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3542,6 +3582,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 Thu Mar 19 14:59:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447347 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 950DA913 for ; Thu, 19 Mar 2020 15:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6BA5A2145D for ; Thu, 19 Mar 2020 15:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728207AbgCSPC3 (ORCPT ); Thu, 19 Mar 2020 11:02:29 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727754AbgCSPC3 (ORCPT ); Thu, 19 Mar 2020 11:02:29 -0400 IronPort-SDR: lhFgc0e6hGbGGYRBSjfdvX4bW8aP1WLPGs3q9xLO7y7DiELuwuk62MtJ0Y8gtsO533l8APHg+4 4OiGkBh9yuea3JBA/DtJu05xngZvyVVomIOG7kILLXmdVojF8Kpc8+vx/MMxIpyhzCZwz8uD07 eFsGAjkdNy+f3HoQ1CFusN6kbEIpvsR7J3vfsKTC09Og1z3x7zhOy0URORZW18svQMZaggswCx 5Hs3ljGRVSbNlbcWA1A70YgPjtrxMUdzdlBjbPmYDwVuwlNRUCkyMZZaBJiIlLQVnL8KOyJl+u Ghs= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850353" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:27 -0800 IronPort-SDR: u1wpgXUT2lm18szSxBcQoRjBzChb+hHv9+0rKVQONds0qOFt/MWiUDwlHF595O47LeDJAxb0Na Ys+znmit4MlI2cynCZP+tBcrnzZwDsM+rogJPDJLF2SH9zy1JFZ5m/4H+twa8S88Ksr70szg9k 5GsQYSoqXXaYnXFSZ2LKvRLj8XPrPiK/SkQ0J/rlXRdwOv4ReS7OSn3CgRH5KIiKhiGXODLRVc 1yCxHPHY71DztNEqxjhDPHcvIaUrB3NLfrWxA8WVkKJL3AF8cu5XLdjf+dQQBHBHKl/U5xKQ7w jQg= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 32/52] Input: atmel_mxt_ts - implement improved debug message interface Date: Thu, 19 Mar 2020 07:59:56 -0700 Message-ID: <20200319150016.61398-33-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 Implement improved debug message interface 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 [jiada: Replace symbolic permissions to octal permissions] 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 10da40c6c91b..15bc1b1864de 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) @@ -1256,6 +1401,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; } @@ -2674,6 +2822,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, @@ -2683,16 +2835,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; @@ -3354,6 +3508,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); @@ -3537,6 +3692,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) { @@ -3575,6 +3758,9 @@ static DEVICE_ATTR(update_cfg, 0200, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, 0444, mxt_config_crc_show, NULL); static DEVICE_ATTR(debug_enable, 0600, mxt_debug_enable_show, mxt_debug_enable_store); +static DEVICE_ATTR(debug_v2_enable, 0600, NULL, + mxt_debug_v2_enable_store); +static DEVICE_ATTR(debug_notify, 0444, mxt_debug_notify_show, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3583,6 +3769,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 }; @@ -3872,6 +4060,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; @@ -3930,6 +4119,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 Thu Mar 19 14:59:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447349 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 B55776CA for ; Thu, 19 Mar 2020 15:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E3CD2145D for ; Thu, 19 Mar 2020 15:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727818AbgCSPCd (ORCPT ); Thu, 19 Mar 2020 11:02:33 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16097 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727754AbgCSPCc (ORCPT ); Thu, 19 Mar 2020 11:02:32 -0400 IronPort-SDR: ywqCJ5OIu1WocdUXo8+6Woh83R/3/CtrN2DmMNfwtH/to564qozAv2iMTPsVHfxhg1nVOe1yRe 3qfQm1Xg2Cyb1Hv3dvlQ10CtN2l3CV9kxrL24A3SX4A3/rR3KfSd2WTZSUP+avSAAT1iysPdqk HUBeHB19ulM5gFPgzUPEF7E9BO8t+D5U77VvwCEclsbemmy+JkZGnCaa7qZyzPFJf32CT+encm DIpRq6uwEIN9Vb1VapC2DS52pdhFDTeGKPbt4G6v/x15bU9fLa1U7nzrf1hrINlI65OmqXUhI2 GXw= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850363" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:31 -0800 IronPort-SDR: /NjeRM/tk6vq/RGBX4srdWBYpAhWY4DMAwdbnEyKmPf01VF4o5IMaH7glAFqCuf6NNW1sYWmtq oNXjnd8MOFgSbWTeAENIIkcyEbmNb+AD6YnCJ6dCpuTRjJaFZid2klSZJh99Ebqy5twf5km4Ai Oso0FqwYaLg4gCHibF/RtGV6pPSqYp506Q61aYH55+OXXpXBgu6OLFsEdARf/lBa4mWtF2mhAk jjSSb1cU5dYd202VIu1L8kNPtY5fkuW6tNuaH+2r68Xds8HrJR30+LvPao3XFXYVnYGLX2fyX3 Xxs= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 33/52] Input: atmel_mxt_ts - eliminate data->raw_info_block Date: Thu, 19 Mar 2020 07:59:57 -0700 Message-ID: <20200319150016.61398-34-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 15bc1b1864de..48ec60be26db 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; @@ -2067,9 +2066,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; @@ -2238,7 +2236,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 */ @@ -2289,7 +2287,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 Thu Mar 19 14:59:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447395 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 740D66CA for ; Thu, 19 Mar 2020 15:05:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D21220B1F for ; Thu, 19 Mar 2020 15:05:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgCSPFl (ORCPT ); Thu, 19 Mar 2020 11:05:41 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5760 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgCSPFl (ORCPT ); Thu, 19 Mar 2020 11:05:41 -0400 X-Greylist: delayed 313 seconds by postgrey-1.27 at vger.kernel.org; Thu, 19 Mar 2020 11:05:41 EDT IronPort-SDR: ND40/2p0SCXA/bySmETgeF6jIFcWrUTKkrAcDrAnZ0B/AiTwcT8fTBeqfIx/EZ9xLBNSsWYhl/ Y03vtotzMxhHHJEd4iwCjeJh4zPGNnlnV1vaKwai89jj3iXcn5rn009H5TsDgdZLFpV/exuW+n SVcAufhSGV3WKJNP+LSLiZGiDHa4ZsaesIMaWSj4Gq7YeDm4RZwJkndwAT28b4YBaRxiWi4h6a gNFCmRB1iRFo15yu+WFG2mfeLSn5sNb/QkjdEAOHaIepGAzvW/3rsXtq01b7hRZmb733KAt03e ZWc= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46926983" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:35 -0800 IronPort-SDR: CaWIPBwHH287pTnKem2ZSIHPHoj54oZByP8YSmChTvdIeJxt6D+KJW4dWptW45Iqjx4mOuVgJY jmHXqUN9KHyTJsGE1VfanK1SbPr5G1LQtJbCLohuUg2tnP3FUt/aV60n4HtXMNMQ4D5UZSx0hb Z811byonBPDyw7HVFo2tKCfXzQ61oqkUNq5EzxO8PDEt3LucIwoYEwSwtN2Ns6MmlGgOJd1OIf 5Bm/gKW7rF+pNkL3RMkWwFcfex/WK7aSVXctpu7iBhEF7kuLxCzhQkvdz7MCgRC9NvMxCRdS9t 9GM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 34/52] Input: atmel_mxt_ts - Change call-points of mxt_free_* functions Date: Thu, 19 Mar 2020 07:59:58 -0700 Message-ID: <20200319150016.61398-35-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 48ec60be26db..de8cafb76712 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3336,21 +3336,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"); } @@ -3358,10 +3358,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 */ @@ -4098,16 +4094,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 Thu Mar 19 14:59:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447357 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 63230139A for ; Thu, 19 Mar 2020 15:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D0A62137B for ; Thu, 19 Mar 2020 15:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbgCSPCk (ORCPT ); Thu, 19 Mar 2020 11:02:40 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5502 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbgCSPCj (ORCPT ); Thu, 19 Mar 2020 11:02:39 -0400 IronPort-SDR: 2qtrN4WugbcOk+Uby41+K5wCh5tFlmT2AhnyDzsMM9vEj8LejBKnw7Y4PpxxWr2k3HCfNRskRV 9oBpzGC/gnQg4sRxtrdDRTa4ia+hWQskIADaa2uFQjp6uJ6XbKZ+nPRPWKQSDYEy61VRLA+mPs yQQvWEENJdDAQ20u+I7nn58U6BIqbjQW+a8l+4E4ZFOOAhmCiq+3SLuyqRgbyHa/cf1Xl4VWgH aX/uhtecBXWZkKMkhwdh4Uj2TcDc5JkPU/Vh4PBtBeYlY2LRsP1NojFqsyWSuQx30gILrUl9CP 7mY= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818853" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:38 -0800 IronPort-SDR: bK8a+XM1Ah6QxtP4Ksw6l9UYPipgU2hv0mF2L6NPaqpvaAqTpKyQmoJH3Cldcx80rplUbkU20Y 6VLmBO0NG8HEH+KRKyUCt+45Cd3InuFH1ke5tCtVx1G5bGrgdS08OcpN71nRpPI0Vlgr1SqVzl Hgzyl7TmJFytittaY0i6smjVlXSYDBBD7T1IWq7jfhEWPhgNgTWrMMYqThs83bO3XbmUnm0LRY VLI3xw8Ig4GHwt1+INVV/SxEvvldrhQkvZaHj0BJ3qeaY3y8HLeccKDl9QDAbpZIp3waj6wfFm kWM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 35/52] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Thu, 19 Mar 2020 07:59:59 -0700 Message-ID: <20200319150016.61398-36-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 de8cafb76712..18372e8d1ef2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1905,7 +1905,7 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) int ret; int offset; int i; - u32 info_crc, config_crc, calculated_crc; + u32 info_crc, config_crc, calculated_crc = 0; u16 crc_start = 0; /* Make zero terminated copy of the OBP_RAW file */ @@ -1968,30 +1968,6 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) } cfg.raw_pos += offset; - /* - * The Info Block CRC is calculated over mxt_info and the object - * table. If it does not match then we are trying to load the - * configuration from a different chip or firmware version, so - * the configuration CRC is invalid anyway. - */ - if (info_crc == data->info_crc) { - if (config_crc == 0 || data->config_crc == 0) { - dev_info(dev, "CRC zero, attempting to apply config\n"); - } else if (config_crc == data->config_crc) { - dev_dbg(dev, "Config CRC 0x%06X: OK\n", - data->config_crc); - ret = 0; - goto release_raw; - } else { - dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", - data->config_crc, config_crc); - } - } else { - dev_warn(dev, - "Warning: Info CRC error - device=0x%06X file=0x%06X\n", - data->info_crc, info_crc); - } - /* Malloc memory to store configuration */ cfg.start_ofs = MXT_OBJECT_START + data->info->object_num * sizeof(struct mxt_object) + @@ -2015,14 +1991,45 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) else dev_warn(dev, "Could not find CRC start\n"); - if (crc_start > cfg.start_ofs) { + if (crc_start > cfg.start_ofs) calculated_crc = mxt_calculate_crc(cfg.mem, crc_start - cfg.start_ofs, cfg.mem_size); - if (config_crc > 0 && config_crc != calculated_crc) - dev_warn(dev, "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", - calculated_crc, config_crc); + /* If the CRC stored in the file is not the same as what + * was calculated by mxt_calculate_crc, this means we + * have to refuse the config file and abort download. + */ + if (config_crc != calculated_crc) { + dev_warn(dev, + "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", + calculated_crc, config_crc); + ret = 0; + goto release_mem; + } + + /* + * The Info Block CRC is calculated over mxt_info and the object + * table. If it does not match then we are trying to load the + * configuration from a different chip or firmware version, so + * the configuration CRC is invalid anyway. + */ + if (info_crc == data->info_crc) { + if (config_crc == 0 || data->config_crc == 0) { + dev_info(dev, "CRC zero, attempting to apply config\n"); + } else if (config_crc == data->config_crc) { + dev_dbg(dev, "Config CRC 0x%06X: OK\n", + data->config_crc); + ret = 0; + goto release_mem; + } else { + dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", + data->config_crc, config_crc); + } + } else { + dev_warn(dev, + "Warning: Info CRC error - device=0x%06X file=0x%06X\n", + data->info_crc, info_crc); } ret = mxt_upload_cfg_mem(data, &cfg); From patchwork Thu Mar 19 15:00:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447365 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 1A140913 for ; Thu, 19 Mar 2020 15:02:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 030B72072D for ; Thu, 19 Mar 2020 15:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbgCSPCo (ORCPT ); Thu, 19 Mar 2020 11:02:44 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:5502 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728287AbgCSPCn (ORCPT ); Thu, 19 Mar 2020 11:02:43 -0400 IronPort-SDR: vlsjRHpcXiLoa3gqLqNLp/lDS8T+cj+P/9dzLE+M9v5SFZZUW1a5a2p6SaLa1Bcz84QdYqQPBY 2PWRHGrLGjtoX/ONQa7e3aOUFAAhYoXItRVjVz6XdgEvbJUUli9rqCWub9mgLmvhX1SRpbVakM NIFEFzG94QoxrMfSPkaQCiAMtUiry09iEMyuh0fj5Kh/XAeyYedFEZ1Pv6ca/YEPrttOYVKEgD vFiv5c3AN/lgVxmsA4soIYrVBEZJg1R3aK5Sg9/NOcnMKTHbTepTfyfYPa3XYo6RNXQ2EfMBYM 7L8= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46818860" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:43 -0800 IronPort-SDR: CKCIL9tpA0XvZJErtxAM/Y2cQM+DlSH5z4UWVmX/DRvwv0KMdlF+J2Ais3BczfXUIUVrZBhYJj 0Jr0VGPgyIkxuJ/mwPBK4GWjT+ufMXga7jRoHCERclxlG/kUM0eZKCzr6x2ZA8h/EhvK6cl34l sK6+EgHRLpKbYsKgvVRu0OH/r1esUX/ygoJsec3lSeL6j5L0EjJmtM/1dhqnW8aGdAJXP0hAaj TGvdIMspGANEWyWkQb/77GmIlFCL+bvnjF4Ayc7ayCtPenykgQMSEr4JpqPvXoHa9rov+rIdYT 9hk= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 36/52] input: atmel_mxt_ts: export GPIO reset line via sysfs Date: Thu, 19 Mar 2020 08:00:00 -0700 Message-ID: <20200319150016.61398-37-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 18372e8d1ef2..fd3db4f8d55d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4083,6 +4083,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) @@ -4115,6 +4128,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; } @@ -4124,6 +4141,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 Thu Mar 19 15:00:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447361 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 2CDEC6CA for ; Thu, 19 Mar 2020 15:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 168DC20CC7 for ; Thu, 19 Mar 2020 15:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728287AbgCSPCs (ORCPT ); Thu, 19 Mar 2020 11:02:48 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16159 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727800AbgCSPCr (ORCPT ); Thu, 19 Mar 2020 11:02:47 -0400 IronPort-SDR: 8LOk2rvlUau9xVpE4UgLuH4EVmEgfWFWCabIs6xpy4XJTF0i7Jy69R1Q/3JvXwVeEN49pjWYNi XSeYFHaLDarli/nessTwp55C8nYaKMyATkskc0vQ8FcTb5YHJjVqT89H7O6jTfatAEoTLnlPDf 5g6ANQUemIJUYwGnmJgz6z3Z2PWpHqj17nHmrcFb7i+cYK38/oYPhVucD7NBXJsxpR90ammF2z A5i03E3z9e8zIeKWzITMgUfc4dxT7s8Id/rXxNgm/+XIgX8shbcDX1SmV1XdX872aw+HQefCdZ fJ4= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850388" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:46 -0800 IronPort-SDR: 8GvjBJLQVkveyXDY6aYi3uRO5ZOmThxV3xdzi8BtfmsoQCcuN/z6EXXsB3lz62mWbuIlBnORh2 j6RL2anoHVmwPAZmobBV1B9vVdishJrcyNIjuf6C4JdtSkK88bz2COZBfma96SwHOxUsNzDZ6V LWBPlFhniWt2y1b23PJ92jrVeOt9rn6PAuixscJ4ZwZR6acJC3VcPMQYQtfIF4Sb/18I5BZVT0 BirRgOepIQZyD8GOjWcEXRilz2m6vh7zfQZkohJkD3jHQ6ffp87HKsdqztL5bGa2jvRr+7pr93 09U= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 37/52] input: atmel_mxt_ts: Add Missing Delay for reset handling of Atmel touch panel controller in detachable displays. Date: Thu, 19 Mar 2020 08:00:01 -0700 Message-ID: <20200319150016.61398-38-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 fd3db4f8d55d..edffdec0d2a2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4110,6 +4110,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 Thu Mar 19 15:00:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447363 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 856FF6CA for ; Thu, 19 Mar 2020 15:02:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6565420BED for ; Thu, 19 Mar 2020 15:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728313AbgCSPCw (ORCPT ); Thu, 19 Mar 2020 11:02:52 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16159 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbgCSPCv (ORCPT ); Thu, 19 Mar 2020 11:02:51 -0400 IronPort-SDR: aw8MG52B+1v/Y8gbwF/Jdz4zS7+BPvSmJKzQhqWXsovUMDK+/MejbCE5tRs3S4JHlISGRT8cpk 2jKZ+Zs5enXxVnNLB7Ra29m1j3mjr56UILCIF8yj4DdWrWU686omacGWzR8LTMi7lbbEGs6hAN 8fqotZXWPRwRXcVVpqj0j+QX8nEASO8JEqsVTNEXguLMAtoymk0vOszWaoaoX4kE06OLZSGiM3 OA0FA6fPn/AVsTYJn1edQ9y2XQlopEgnlU68IElqIDg4hP4nXVpctN2E+YFzhef7rtBb8Xuncr LQo= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850401" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:50 -0800 IronPort-SDR: WdpMbYcntqpRPPikVRRsCEISuGsRZYeKRXlaX+Oj2CxcoArcjwyTMuVb/mUFDa32j9PDp0ZWkC 9l1dqF2cfpbAjEK9/QZND4avs+GdUJv4HiDrQaDh1bbnQXMeK2xC4WigrmVYvtTsie4NVjEOZp VPg3Y8CPbgWibNQenY6OofIYC3HN/SwCUwr+vWdyU4ojGX9+iv5ojfOD8yvE3fDv22HRars9yi 1PutEi7EGGC1C0e6zmUceF25z405Qqt3x4Jt2qfCHOrJGx5dJD7OKT7NXfFg87lwEkXT9LVZy0 CJY= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 38/52] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Thu, 19 Mar 2020 08:00:02 -0700 Message-ID: <20200319150016.61398-39-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index edffdec0d2a2..fe646d7edccf 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,9 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + u16 T25_address; + u8 T25_reportid; + u8 t25_msg[6]; bool debug_enabled; bool debug_v2_enabled; u8 *debug_msg_data; @@ -413,6 +416,8 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + + bool t25_status; }; struct mxt_vb2_buffer { @@ -1356,6 +1361,24 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) dev_info(dev, "T93 report double tap %d\n", status); } +static void mxt_proc_t25_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + /* Output debug if status has changed */ + dev_dbg(dev, "T25 Status 0x%x Info: %x %x %x %x %x\n", + msg[1], + msg[2], + msg[3], + msg[4], + msg[5], + msg[6]); + + /* Save current status */ + memcpy(&data->t25_msg[0], &msg[1], sizeof(data->t25_msg)); + data->t25_status = false; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1386,6 +1409,8 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T19_reportid) { mxt_input_button(data, message); data->update_input = true; + } else if (report_id == data->T25_reportid) { + mxt_proc_t25_messages(data, message); } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); @@ -1610,6 +1635,86 @@ static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, return 0; } +static int mxt_t25_command(struct mxt_data *data, u8 cmd, bool wait) +{ + u16 reg; + int timeout_counter = 0; + int ret; + u8 val[2]; + + reg = data->T25_address; + val[0] = 0x3; + val[1] = cmd; + + data->t25_status = true; + ret = __mxt_write_reg(data->client, reg, sizeof(val), val); + if (ret) { + data->t25_status = false; + return ret; + } + + if (!wait) + return 0; + + do { + msleep(MXT_WAKEUP_TIME); + ret = __mxt_read_reg(data->client, reg + 1, 1, &val[1]); + if (ret) + return ret; + } while ((val[1] != 0) && (timeout_counter++ <= 100)); + + if (timeout_counter > 100) { + dev_err(&data->client->dev, "Command failed!\n"); + data->t25_status = false; + return -EIO; + } + return 0; +} + +/* Firmware Version is returned as Major.Minor.Build */ +static ssize_t 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; + int ret; + + ret = kstrtou32(buf, 0, &cmd); + if (ret) + return ret; + + if (mxt_t25_command(data, (u8)cmd, 1) == 0) + return count; + + dev_dbg(dev, "mxt_t25_cmd_store write cmd %x error\n", cmd); + return -EINVAL; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2088,6 +2193,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T25_address = 0; + data->T25_reportid = 0; data->T42_reportid_min = 0; data->T42_reportid_max = 0; data->T44_address = 0; @@ -2175,6 +2282,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_SPT_SELFTEST_T25: + data->T25_address = object->start_address; + data->T25_reportid = min_id; + break; case MXT_PROCI_TOUCHSUPPRESSION_T42: data->T42_reportid_min = min_id; data->T42_reportid_max = max_id; @@ -3761,6 +3872,7 @@ static DEVICE_ATTR(debug_enable, 0600, mxt_debug_enable_show, static DEVICE_ATTR(debug_v2_enable, 0600, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, 0444, 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, @@ -3771,6 +3883,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 Thu Mar 19 15:00:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447383 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 1F953913 for ; Thu, 19 Mar 2020 15:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0912220CC7 for ; Thu, 19 Mar 2020 15:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727608AbgCSPD2 (ORCPT ); Thu, 19 Mar 2020 11:03:28 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbgCSPC4 (ORCPT ); Thu, 19 Mar 2020 11:02:56 -0400 IronPort-SDR: jF1Ppi4WRtyGgQrY9zFZyrc3eF9GValARb77kH460p3ISRNWrHQvJaf9ceI6iqWc4yD4/JYYnm nJc26cO6pXjaT76mfucmrV2OfsVLfpLYllbuSbRGgiivV/mFArDH1BNW62aZtXMAxkmQRJQYLT W6KGPftuh55kyyC22A57zjcJYfoQIgHaK/n3y7kYNwe8PaKQ6tCh/lZHxWdyYDwu1enJ+4Pp/2 cGpTTF6S7qiUa0epSdO7WQ9a0uSgBMsOPeYHtAr6gdyeLsIGhZhvt1ZBrp8yDcv6XYp8hHu5hG 0Dc= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891019" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:55 -0800 IronPort-SDR: exR7hdURaWid+agzLLL3WwkP2pkKXpn8VpscSoPFDYktUs3ulb7pb3Ne7N5aDGUNNSYJ1PCKo9 S3RlyXE5xHS68+R77OKjwt3+AcTyKlqAGDXVDOXWTXIiDSoQbWfIbPO6OQ1V/hWvmFB7UZ8Lp7 9EhQAvPtW+hoRtQlQolX1bzpePMSCuAFEEV7qIi35MxuCxv5XGL1ExChWUmengSbeZHTFv6WGv xpoOJsqwOxe7ACdGO+AP/EsazzYxARTrYV7Jecf28n4JDNRGEwBPzNd78a/eTCH5MZpMGbVewA 1YA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 39/52] Input: atmel_mxt_ts: Limit the max bytes transferred in an i2c transaction Date: Thu, 19 Mar 2020 08:00:03 -0700 Message-ID: <20200319150016.61398-40-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 --- drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++++++++----- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index fe646d7edccf..13258da70305 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; }; @@ -1462,11 +1463,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, @@ -1476,18 +1498,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 */ @@ -1497,16 +1520,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) { @@ -1521,9 +1553,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 Thu Mar 19 15:00:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447369 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 DF0C6913 for ; Thu, 19 Mar 2020 15:03:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5DBB212CC for ; Thu, 19 Mar 2020 15:03:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727755AbgCSPC7 (ORCPT ); Thu, 19 Mar 2020 11:02:59 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727858AbgCSPC7 (ORCPT ); Thu, 19 Mar 2020 11:02:59 -0400 IronPort-SDR: hwU5uiOcTi+ztXV52I0bmrg9hoAOnZA1WdqsLSqg3mcPleNMv+JTyACJcqcGj8TKn1IUS4xD8m H6xIEnyk5n+6K4rx0Gl/uWf/SLdrDi9B4WqpOllEBufkjlJLlIK++z9n0zKMHZagO9zweWktBe cY4vvIbxlTpcJsmajX3kRSc14NVb8QhdGi2qa/mcqd1uvMcqY/hEtkEtJBiH4w2Idj295yhpVk WV1mvjbczGe4lWDo/8N04CWaDvFP6sOYew2+gjX5ySOHnknlOeZofSGEy0e5QuDQ12jnMdCGa/ hIo= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891026" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:02:59 -0800 IronPort-SDR: 5nyN4dqat9EO2p62EV/6vQMmu+VPTR1xmZts6A1EuKt77la/FlhFz/V+DFKYwnl9U4NDrQcVpc oVwPw84tUCgjUwobISzyHSzSTeJZqVWdjCGC97FNYO5JFjuYXPCH0T5rL3C9pI1eYuzfXTTrMC oFhOxYjGIA86oI+YuSgGBK5UMKo0bRzlvcJsnI1giwedEeR71qKnCvmwsGsN1NC32OysIirY/N psdMMeuZOQIhXE7c3O0GWSR7dWTXzinRX84eNr72MZUd9UuyorsMARNxDRUhbgWyiP3WDtF1uu 4zE= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 40/52] dt-bindings: input: atmel: support to set max bytes transferred Date: Thu, 19 Mar 2020 08:00:04 -0700 Message-ID: <20200319150016.61398-41-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-1-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add support to set max bytes transferred in an i2c transaction Signed-off-by: Jiada Wang --- Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index 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> }; From patchwork Thu Mar 19 15:00:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447371 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 3B054913 for ; Thu, 19 Mar 2020 15:03:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2480820B1F for ; Thu, 19 Mar 2020 15:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728372AbgCSPDD (ORCPT ); Thu, 19 Mar 2020 11:03:03 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728370AbgCSPDD (ORCPT ); Thu, 19 Mar 2020 11:03:03 -0400 IronPort-SDR: 22/m8Pr2ZEdlhlF9WqeDi6uOdg54KgQeINoEaIKmFnoyD/cBD6XTC/XSw3E/bfEMR6Di0Fvaop nrlLzOtZFBSjnSv8BOG/oWwh8JZjCT+DVrd5DdhvrS0YkrBqEkzdJtFH+OzQF2hGTDwz+j2r6p DPt9WuGviVc71dt2uNYWj/Lpkn4lMOHgApSMJbtdxlgEG9AB0BwH0Q7bTtsu2N5ocfyrx2aSWp G5qyYec3g6l6XdDGiDOV00z6ypNLkHWwU02U7pw9ovwSXLl7k6RmNONa5/uBYHVtDJouW5XBUT Ehg= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891033" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:02 -0800 IronPort-SDR: K5vGjlBOXhGv6FN/B2bu7F7wIS2bhhecQzdeSdKfmnpAUuNBY8827cL3CuxQAyyHoNOwYQOXt0 B3LubGo0uIxSK0rGtNoVbMgFHu36kL3nu+JBgAM/fEMQdILmkzPBQ+GLUpq32pBUbn9PI0pFY6 5BOn/bs1Pp7rF95QmDK0Z2b9RlcChzEzrFxOmky64KHfFILBiFC5papkcEwRhskpSg9JeNjHnr /sPjs5huNUK+mRXGBd//Zg2eMxzZJL1KGyLIDyobmKhMixKQyXoDs2fwM4GmZwB/qtJaMRm+9b 1F0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 41/52] Input: atmel_mxt_ts: return error from mxt_process_messages_until_invalid() Date: Thu, 19 Mar 2020 08:00:05 -0700 Message-ID: <20200319150016.61398-42-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 13258da70305..6ee83eda7170 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1561,6 +1561,8 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) /* Read messages until we force an invalid */ do { read = mxt_read_and_process_messages(data, count); + if (read < 0) + return read; if (read < count) return 0; } while (--tries); From patchwork Thu Mar 19 15:00:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447373 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 631066CA for ; Thu, 19 Mar 2020 15:03:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4CC5F20CC7 for ; Thu, 19 Mar 2020 15:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728312AbgCSPDI (ORCPT ); Thu, 19 Mar 2020 11:03:08 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727880AbgCSPDH (ORCPT ); Thu, 19 Mar 2020 11:03:07 -0400 IronPort-SDR: yWju7VJK1UJzrmeRb7wvc8ffyUZxOV2qNkj1v0w1k6wVxB3oymiorjPiTXcKsJ6lkw2oCOEBqv 8UUHHZkppCq1ltsCf58Qmr97vTmaAPZwZY0COL8xGOOL+qDKqjj3F3UIQpXcA32gqRrgH+p0Tj bfKefhWQUvssy5xRCKVl0aSiCm4PJi4tNvuVmeiYBM1gLd/sljW/qYUgmbuSqshwkVFcRZxWhD VTBZHTTCEGJSZa6PsVtW/nmmYWSVo5ZxlDbfJKyzdlP82MrKPlDkvo2n+NiWLy/Ax57Jp7uoOM zPs= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891044" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:06 -0800 IronPort-SDR: YvMk6tss4/JbxGtRXJZONODjGVMT2dv7dBTsJZ//tGP9SG9BhpJEy2L5DVOA16ix/LSYeP7fkS 7kAj0CUXvz5uYTsZvOa2CVIDxTQE5dq9Nzd9oeyqIVZswcHTEiH2nBkBmG8C29V69iXVy3uq9X GGDuot/DuKjjtR0dBTCit2xsfIziix8//84RRH6T9vQ+hQEsznM9mEH0qQIN6Faw0jc1okZuxH rCvjNRlQUD8n9cYQYZ1892s51WZvZAZZpDz2Yrteod3yRzfkQbolKBLw0y3jJwRS7z5Y2nwI57 uH0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 42/52] Input: Atmel: improve error handling in mxt_start() Date: Thu, 19 Mar 2020 08:00:06 -0700 Message-ID: <20200319150016.61398-43-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 6ee83eda7170..2048cfbdc80c 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3973,12 +3973,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: @@ -3992,27 +3993,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) @@ -4335,6 +4335,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; @@ -4344,11 +4345,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 Thu Mar 19 15:00:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447375 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 C4078913 for ; Thu, 19 Mar 2020 15:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD12220CC7 for ; Thu, 19 Mar 2020 15:03:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727880AbgCSPDM (ORCPT ); Thu, 19 Mar 2020 11:03:12 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728414AbgCSPDL (ORCPT ); Thu, 19 Mar 2020 11:03:11 -0400 IronPort-SDR: d8tlHPMi8Ms+RPENXGomVwBSwn7DzzTUeThfhWj1x+4BJmhrHGLSicbiBJKdcmH8E1fbABaWWb LVn7qB94xfEmD5dG8psYm3qRJrMMBim7x+tyEV8zKOtBDPWynx6N938lppCpdWKodW4fmI62ud Furlc/0ietHVEOlX79VZYvZEuhCuAG6QS1H3cPC0AbW5knelvWG7HpQsaJADZnDGMUJm+72RLL N1o7m8xqZcEEw2imqy+7eUkGWh0w15385MQdTxXeIpj6/MRzVWQYvI5E6V+GP4nX3FVfBYJrx5 VDE= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891051" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:10 -0800 IronPort-SDR: GtjVRSaOC6mBHsx6MecHHu3OB6Gz7MdfnYCpZq7riB/23ZEID8ND7cD77Ce9+vy2Q5hIF3fThe 1rCDc0bVeFFtWs/jPjZ/MWBFdCGe0ynj3EZuaEyrsX+3vLTlyguur8WBcP4BBWElVGjo9O5OC8 S5vODTZDod0UUrZjumJuJPu4kGqZJhnGuk4YxkKDWfMxzNd5yyRcCnUwGWTpOcs/5v8gRHJw7h w4C+XRxVa4uHu40zcYOlyM60u6NzNhnyJQj+9qkqmpH6AOoTnvNPGNq3yyxUV/q7t1dTkWT+lr 0BM= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 43/52] Input: Atmel: improve error handling in mxt_initialize() Date: Thu, 19 Mar 2020 08:00:07 -0700 Message-ID: <20200319150016.61398-44-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 2048cfbdc80c..1eedde24e38f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -716,17 +716,13 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) return 0; } -static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) +static int mxt_probe_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; int error; u8 buf[3]; bool crc_failure, extended_id; - error = mxt_lookup_bootloader_address(data, alt_address); - if (error) - return error; - /* Check bootloader status and version information */ error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) @@ -2922,6 +2918,32 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) release_firmware(cfg); } +static int mxt_bootloader_status(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = mxt_lookup_bootloader_address(data, false); + if (error) { + dev_info(&client->dev, + "Bootloader address is not specified\n"); + return error; + } + /* Check bootloader state */ + error = mxt_probe_bootloader(data); + if (error) { + dev_info(&client->dev, "Trying alternate bootloader address\n"); + mxt_lookup_bootloader_address(data, true); + error = mxt_probe_bootloader(data); + if (error) { + dev_err(&client->dev, + "Chip is not in appmode or bootloader mode\n"); + return error; + } + } + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2933,16 +2955,13 @@ static int mxt_initialize(struct mxt_data *data) if (!error) break; - /* Check bootloader state */ - error = mxt_probe_bootloader(data, false); - if (error) { - dev_info(&client->dev, "Trying alternate bootloader address\n"); - error = mxt_probe_bootloader(data, true); - if (error) { - /* Chip is not in appmode or bootloader mode */ - return error; - } - } + dev_info(&client->dev, + "info block read failed (%d), so try bootloader method\n", + error); + + error = mxt_bootloader_status(data); + if (error) + return error; /* OK, we are in bootloader, see if we can recover */ if (++recovery_attempts > 1) { @@ -2956,7 +2975,9 @@ static int mxt_initialize(struct mxt_data *data) } /* Attempt to exit bootloader into app mode */ - mxt_send_bootloader_cmd(data, false); + error = mxt_send_bootloader_cmd(data, false); + if (error) + return error; msleep(MXT_FW_RESET_TIME); } @@ -3648,8 +3669,11 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); + ret = mxt_lookup_bootloader_address(data, false); + if (ret) + return ret; /* Do not need to scan since we know family ID */ - ret = mxt_probe_bootloader(data, 0); + ret = mxt_probe_bootloader(data); if (ret) return ret; From patchwork Thu Mar 19 15:00:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447377 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 2D0C96CA for ; Thu, 19 Mar 2020 15:03:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1697C212CC for ; Thu, 19 Mar 2020 15:03:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728438AbgCSPDQ (ORCPT ); Thu, 19 Mar 2020 11:03:16 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728435AbgCSPDO (ORCPT ); Thu, 19 Mar 2020 11:03:14 -0400 IronPort-SDR: 5Jq3RKvLYTAyLEqWcpKPL+X7sjRYA9I00NjWhYhzpEP+ecJhAozwJkNb5TYHC/OfWosxuyRGXt 01Avo63f0kjPIhuEelXmOP94ZEiMsgWS4fpwPy8iQFaNg+SmGQHNN2lm+FGVwRucaKLO5GAzHz J60QJcJDuL1DdoKz3144OPo2otj1Y0eKMD5FQDHfoFlkyoJt4MyfiRANgBwILixsfXSGydw+GZ zuaLkryr5ZaZQdAcEtZgPCd4hkougaim5q8gpd7zvzkrhYWGo3EWLMMC3Z8ZRerx9RR9J+bQ2d g7A= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891060" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:14 -0800 IronPort-SDR: o9oTlPpDDDoKlapVti8kaUvE0cke1Is3vdMmgwl1RQFVcs9yu+cN7kKSFkI3evS8/yl9WgqStB DE69twgXtjO/a50kROpTpAST5s46mmqF/fkRI6r679HKoFTjVXMEyHJlO5ZqXzFyBaQqCDDkMc kb2yxlOdB0d/XZEdEuISKvHVNpwyvu/8Ist4iQhViIAUOZGlI43ubiGje8fa3W2HWMZqGgKkfL uMqNRaFysSW9KhRxTrTyGDlQo5etfoC0eH4svwsZg8LRyhUzrI61aDCr8uQ1RioNbHHML7PpfB uO8= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 44/52] Input: Atmel: improve error handling in mxt_update_cfg() Date: Thu, 19 Mar 2020 08:00:08 -0700 Message-ID: <20200319150016.61398-45-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 1eedde24e38f..edab65337061 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2185,7 +2185,9 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) dev_info(dev, "Config successfully updated\n"); /* T7 config may have changed */ - mxt_init_t7_power_cfg(data); + ret = mxt_init_t7_power_cfg(data); + if (ret) + dev_warn(dev, "Power Config failed to update\n"); release_mem: kfree(cfg.mem); From patchwork Thu Mar 19 15:00:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447379 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 1B7156CA for ; Thu, 19 Mar 2020 15:03:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 051A821473 for ; Thu, 19 Mar 2020 15:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728464AbgCSPDU (ORCPT ); Thu, 19 Mar 2020 11:03:20 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32379 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728435AbgCSPDT (ORCPT ); Thu, 19 Mar 2020 11:03:19 -0400 IronPort-SDR: pnEWoouqL2/muF07ofLVYUyUy/HQD2rYos/wwYYyrndkTUgTbtuXEzf3b9yRBrSktuokXqiVg5 qIt4KkVYLTSeH+5ZkVMKURu6W2Eubs8SoD6beJirL/wjCgccRJoVQ/ai3n4mB74BaE8njYSvQN NH9jYB+zKNFvvzgfSCqTs+s9/jHYZ++qbOS7Hm5W8Pgi9DyR2FD4uQtEBoh1AP46hIou5nFWXB lWVR8vYNrJL8ztRpjg8g38N4fo8/lLhamOE9DQo2QOImh1TdWISsxPpvEoH0sCPY5wwkQjuxsv oSU= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891070" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:18 -0800 IronPort-SDR: lESiGKohi5ReR/Powo1gz/WoWbBgQye/3KGJ/7wruXSWk6WRigfNw3CAeaW67MWmNF2aQQ1xQB y/85Sj0dYMPz8OnFyZs9S1UDw+eQtjIKThNmseDfy6DdO4JsEkyjRl3W2RpUlF9jutWawaQzjI p0fE348BY5FK6gN5N9pI2Q+N6uo2Dv7WTnvTF/wZUK5NqEodlr0l2PzBeNn7QCbPvK+bILCLri aYY1mDdiES5NHL+BKqixwOR80kT4wOWbStRlQ7FWdLXUutemTvYAdEyJEvSso5+STfiGQWb7G3 P64= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 45/52] Input: Atmel: Improve error handling in mxt_initialize_input_device() Date: Thu, 19 Mar 2020 08:00:09 -0700 Message-ID: <20200319150016.61398-46-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 edab65337061..994232c43554 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2761,15 +2761,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 Thu Mar 19 15:00:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447397 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 D60976CA for ; Thu, 19 Mar 2020 15:06:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF7D420BED for ; Thu, 19 Mar 2020 15:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727879AbgCSPG1 (ORCPT ); Thu, 19 Mar 2020 11:06:27 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5803 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727858AbgCSPG1 (ORCPT ); Thu, 19 Mar 2020 11:06:27 -0400 IronPort-SDR: dyBhasTIP4xAvkPQjy4XzWktdg0cjcjW/uXVrM6WgRmIZJ7ebsxKSSIN9V6y6kEaZVfxore488 NFgKFDnFR/iWWjBczAgSmkagFnc9XU7Rfy9NEuzDK8Tkh7zGLw/Bw776b7JD8TbPrre0rU+C8P DR4STE0EQG17A1YyY7crbhUGLeIiBiSCIMaKs7fOnMbVAp8FPTLeNqmUT9VP6poICfrGB8BKcw Dbv4LmY6i2bkV966PFnQyAJuGDrRXtfVAYmcnWdwMsT9lkyb5/fVC7XPyrDEvteMrXQPEgIR0k xpg= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46927060" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:22 -0800 IronPort-SDR: zaOb566Jh7wRAf/JNK7/8EMUwTtcK+da1BnPD+80152hVdLeVfxLObvn4+dK1EzA+GYQM4aUH3 d6R9vGtF4tuWrf1NbIEQZ6KRLo2gMh2sF3OD95Aw+53XP08p8+SmrbPK1GiVao9quqvcMCyAdx Pon1Ml+KYwHstuqkQZdNXw5HjBqTjLs1odB7N8fUxaZMAacuD76RIj9A7e6uP5E5lYFtIiRaTX QMlzad6znJtuHHg8EQCBVc3DAZlJE8vkBRvSdw9iicl3xfoz7uHdTYPxSEa3PGLPoWfdJL3l/9 vws= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 46/52] Input: Atmel: handle ReportID "0x00" while processing T5 messages Date: Thu, 19 Mar 2020 08:00:10 -0700 Message-ID: <20200319150016.61398-47-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 994232c43554..6b4809903ee8 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -76,6 +76,7 @@ #define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 +#define MXT_RPTID_RESERVED 0 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -1381,6 +1382,11 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) u8 report_id = message[0]; bool dump = data->debug_enabled; + if (report_id == MXT_RPTID_RESERVED) { + dev_err(&data->client->dev, + "Received Reserved ReportID 0x00\n"); + return -EINVAL; + } if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1451,6 +1457,8 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) ret = mxt_proc_message(data, data->msg_buf + data->T5_msg_size * i); + if (ret < 0) + return ret; if (ret == 1) num_valid++; } From patchwork Thu Mar 19 15:00:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447385 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 A5F1B6CA for ; Thu, 19 Mar 2020 15:03:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84B7E2072D for ; Thu, 19 Mar 2020 15:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728510AbgCSPD3 (ORCPT ); Thu, 19 Mar 2020 11:03:29 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:16231 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727327AbgCSPD2 (ORCPT ); Thu, 19 Mar 2020 11:03:28 -0400 IronPort-SDR: HCt1SeNIB3cChz/WFpd4T35CWVxG6Xs6005QHF9kW4QmzaKmkKhJE65trUWdsum9TyTo+7WBRU qrsgIThJnh6snVeOvsC8Mak1+rLx0DC6e62F8wvbsN+UWHUq4tEFlVm9vbZQNbinHSPLyQq95L WVuTJxsj2u5EnTgFWIb8XgCKIZ3JyyHX/UiXDoODZzDHVa9rKPCX3cJgVaWlXkz32g9axDGmfN w2z7GvtcNzQSwPFQAfxndVFOsF+Dgbz4UpCRiKuezDLtYky7LxbuRRyBGVQwIbK8AzRm/mbRQ7 b5o= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="48850470" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:26 -0800 IronPort-SDR: QtUDylF9bag05m8tngPL4HCNpgtooKKBEAd3j552ZkOQVrVEooM+N+GlsilGUZ+oKu6L9Rhjrh mg5HUzptEilRNg8OYoluBSskz2O5WGEoOH43hyzkRtOSWlR/ITOwqfkwK0O/3L1v+jTuDEeHeI wTUPtC68b21Z+Dg943lwglCiAxPaLbwl709LTYvyna0DioYApKmysGJ6xtn0qmwOuKlxnQBPbg t81OiBDqgIXIIVtiWlXoD6+vcB0dExmAssEWSJUI/A3rfWjw4NHFCt0fT0Gu6BtL7Pwg137tDM 2jA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 47/52] Input: Atmel: use T44 object to process T5 messages Date: Thu, 19 Mar 2020 08:00:11 -0700 Message-ID: <20200319150016.61398-48-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 6b4809903ee8..0ca8308e2e8d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1486,7 +1486,7 @@ static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) return min(T5_msg_count_limit, max_T5_msg_count); } -static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) +static int mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; @@ -1499,7 +1499,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->T5_msg_size + 1, data->msg_buf); if (ret) { dev_err(dev, "Failed to read T44 and T5 (%d)\n", ret); - return IRQ_NONE; + return ret; } T5_msg_count = data->msg_buf[0]; @@ -1509,7 +1509,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) * Mode 0. It results in unnecessary I2C operations but it is benign. */ if (!T5_msg_count) - return IRQ_NONE; + return processed_valid; if (T5_msg_count > data->max_reportid) { dev_warn(dev, "T44 count %d exceeded max report id\n", @@ -1521,12 +1521,14 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) ret = mxt_proc_message(data, data->msg_buf + 1); if (ret < 0) { dev_warn(dev, "Unexpected invalid message\n"); - return IRQ_NONE; + return ret; } total_pending = T5_msg_count - 1; - if (!total_pending) + if (!total_pending) { + processed_valid = 1; goto end; + } /* Process remaining messages if necessary */ T5_msg_count = mxt_max_msg_read_count(data, total_pending); @@ -1550,7 +1552,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return processed_valid; } static int mxt_process_messages_until_invalid(struct mxt_data *data) @@ -1580,7 +1582,7 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) return -EBUSY; } -static irqreturn_t mxt_process_messages(struct mxt_data *data) +static int mxt_process_messages(struct mxt_data *data) { int total_handled, num_handled; u8 count = data->last_message_count; @@ -1591,7 +1593,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) /* include final invalid message */ total_handled = mxt_read_and_process_messages(data, count + 1); if (total_handled < 0) - return IRQ_NONE; + return total_handled; /* if there were invalid messages, then we are done */ else if (total_handled <= count) goto update_count; @@ -1600,7 +1602,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) do { num_handled = mxt_read_and_process_messages(data, 2); if (num_handled < 0) - return IRQ_NONE; + return num_handled; total_handled += num_handled; @@ -1616,12 +1618,13 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return total_handled; } static irqreturn_t mxt_interrupt(int irq, void *dev_id) { struct mxt_data *data = dev_id; + int ret; if (data->in_bootloader) { complete(&data->chg_completion); @@ -1629,17 +1632,22 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->flash) cancel_delayed_work_sync(&data->flash->work); - return IRQ_RETVAL(mxt_check_bootloader(data)); + ret = mxt_check_bootloader(data); + return IRQ_RETVAL(ret); } if (!data->object_table) return IRQ_HANDLED; - if (data->T44_address) { - return mxt_process_messages_t44(data); - } else { - return mxt_process_messages(data); - } + if (data->T44_address) + ret = mxt_process_messages_t44(data); + else + ret = mxt_process_messages(data); + + if (ret <= 0) + return IRQ_NONE; + else + return IRQ_HANDLED; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -1776,8 +1784,11 @@ static int mxt_acquire_irq(struct mxt_data *data) } if (data->object_table && data->use_retrigen_workaround) { - error = mxt_process_messages_until_invalid(data); - if (error) + if (data->T44_address) + error = mxt_process_messages_t44(data); + else + error = mxt_process_messages_until_invalid(data); + if (error < 0) return error; } @@ -4031,8 +4042,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 Thu Mar 19 15:00:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447387 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 1565D6CA for ; Thu, 19 Mar 2020 15:03:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F280220CC7 for ; Thu, 19 Mar 2020 15:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728548AbgCSPDh (ORCPT ); Thu, 19 Mar 2020 11:03:37 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32457 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728521AbgCSPDb (ORCPT ); Thu, 19 Mar 2020 11:03:31 -0400 IronPort-SDR: IZuMOuB/mqutYeX9ljraj9pFBJVWklUyBh3gigyKEDfEkWkDzmSubFFhxzOwdrs5KEzxe+Wd1l nm98rUhFU4tpqATqI2QkI4fnnKa35WQCWDU2hgH8waS5mp3G7KzGIYZvH9nojKq2VGL3DDkz9B 8E4/BJ4Yx2oPYrpT5QHvzPsrgcoVxGBXedCRHaiwxHxCwlC90ATgiLf8eeFPlYjRw87LOfWOoE m68EwCqXWiEsQiRj2HsmDOcpDichDhuv06jILwwZeY12+sl0OYvpOl0OWij8qHF+OL52WbX0Px kfQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891124" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:30 -0800 IronPort-SDR: CV6LiE4d6KH0ffSNGiX0cpuawVrzHcSJVS/u3kWOuJmR9vDrMLqESFT/fJKdVLChcMasWxt5ho 7ODM8gNvYAvyCSUz67rCLGIZzi9qiMm0WGb5OHaBTMjiBAjYQbVmGXfmOFQSOYvuWfYZvZxuKb 0xF9CyL23HsSlYZFor2Wl5ZO719L4EAsblA+QShO7lfjWDWRioMXMR3sVvOEND43nmvsSF8/F4 tlL3NWlg0PGUC29h/HyskxbAdGHNGy3Lch81CcPBcPx15/1FWb5lx8GAjFRUiLxzSQhDOPXf/6 xzk= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 48/52] Input: atmel_mxt_ts: use gpiod_set_value_cansleep for reset pin Date: Thu, 19 Mar 2020 08:00:12 -0700 Message-ID: <20200319150016.61398-49-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 0ca8308e2e8d..9d2636567513 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2489,7 +2489,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) @@ -2507,7 +2507,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 Thu Mar 19 15:00:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447393 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 6F5F1913 for ; Thu, 19 Mar 2020 15:04:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E79020CC7 for ; Thu, 19 Mar 2020 15:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727902AbgCSPDy (ORCPT ); Thu, 19 Mar 2020 11:03:54 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32457 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728536AbgCSPDg (ORCPT ); Thu, 19 Mar 2020 11:03:36 -0400 IronPort-SDR: MeMtjqlCUiTTO3TtgykFN/tG5KNlZ1p+TU+62fv64Cmr+/zfjMWAtHh6gL3HQ2Yld3WWpfbwZj c3c7ryAbGVC0awyxzspGeegNX5QvUs0Eij1hN98WP2JN9zaa465dK0tA8YFgRdz5h/qPyIXz/5 /8Sj3y9+m3fbnWi8049ulbzK4F/w2zVdaQ16p9M5ARTDs3nwIHM/ZsG7yFUaVGdlVmVblBGQtL sh5M9ygJGimUrUMCfeFHUsrlwq48mKUyEDN1K1Be3lUiWdp+Id9Yu40ZN1AC76D7pBwu3V9ky2 W1c= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891138" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:34 -0800 IronPort-SDR: IqmiUn8SLrlzm4s3JeKLlJvpQ9LisN3fyXHIT05P2UM4DG/tVXYmW1/J4m4/xZlMkzvqMSv7I9 I3y1Aouyhv0E4wnOsGz3LoF5DNqHAPz86Ck8LMTYPQtOF/GdiuARX1MQKCob3jjP14kgftdO1J COS0ZTnoTEr0xaFJKhg0zIhoirRKy07eNeJgG5hak4YZhUIUwXIdZKk94IiR8zm1dwAjoxuVmU nhlU9Qzktn7vJ6JcUXUYDz3Cfd7B4ut3+iddNt7o43+KKvkHr61fYMa2iMCQIbjdC2K+GMmohH 1O0= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 49/52] input: touchscreen: atmel_mxt_ts: Added sysfs entry for touchscreen status Date: Thu, 19 Mar 2020 08:00:13 -0700 Message-ID: <20200319150016.61398-50-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 | 112 +++++++++++++++++++++-- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9d2636567513..a0f90113a98d 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; @@ -1621,11 +1632,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); @@ -1633,21 +1663,25 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) cancel_delayed_work_sync(&data->flash->work); ret = mxt_check_bootloader(data); - return IRQ_RETVAL(ret); + ret = IRQ_RETVAL(ret); + goto exit; } - if (!data->object_table) - return IRQ_HANDLED; + if (!data->object_table) { + ret = IRQ_HANDLED; + goto exit; + } if (data->T44_address) ret = mxt_process_messages_t44(data); else ret = mxt_process_messages(data); - if (ret <= 0) - return IRQ_NONE; - else - return IRQ_HANDLED; + ret = (ret <= 0) ? IRQ_NONE : IRQ_HANDLED; + +exit: + data->mxt_status.intp_triggered = false; + return ret; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -2969,6 +3003,39 @@ 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; + + if (data->suspended || data->in_bootloader) + return; + + 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; @@ -3946,6 +4013,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); @@ -3957,6 +4040,7 @@ static DEVICE_ATTR(debug_v2_enable, 0600, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, 0444, 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, @@ -3968,6 +4052,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 +4406,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 +4427,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 +4454,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 Thu Mar 19 15:00:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447389 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 6AFB4913 for ; Thu, 19 Mar 2020 15:03:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5492220CC7 for ; Thu, 19 Mar 2020 15:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728568AbgCSPDj (ORCPT ); Thu, 19 Mar 2020 11:03:39 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32457 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbgCSPDj (ORCPT ); Thu, 19 Mar 2020 11:03:39 -0400 IronPort-SDR: Or07yC/Eowb8qlGVB/6Cf/JUYv1qPy+miL14lv0yrBEk2oQJcKx7HNz33N6SFNh9Kyt14HgHxF Ot+bstdxI6Jo6tu/83La4qSZcAYXY16EciCuoy8CMkjqhotGUbrCP7tHWDyirJdLzq9GQppkOU aV2iVHkO854dzcqcRwhQSWGh1jBqDRPEUYT2BhG+rI5sK5rgZ3X46x3ww8KtDm70RZ7QtF4LAa wDG1ERTHj0LnlbJsT0W647MEq5WyzeSHpPYMONmrJP5hRN3u8Zm9+IeaFkTlg/vvYlM+SNlO9A fpY= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891153" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:38 -0800 IronPort-SDR: tTdy9z1UjJ75ZkK/hix1SV8rftCDx2ifYZ8MFd6bbGBErur0oETmnma8In0xky0Mxu7hmlX2zG HkU6DWywk1odNl8uSa0ymI7VTAIsjwCliTPqad8qZI/k3GTtb+sQYPsXti6cPVj7f4vuzM51nB ZnWhO/ZB+rriz45UFZOHjBeCXW/388ZUKHQOHBFLvWmN/MzBdpfLXEDMWPuD426xSYxKHW+TZO 0exRWnz+6SLQrELL8C/tPCCAjgliDhn9J2PvHBoBayTkih5geJWz3rjQRMdunBn1zpit4xkXcL swA= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 50/52] input: atmel_mxt_ts: added sysfs interface to update atmel T38 data Date: Thu, 19 Mar 2020 08:00:14 -0700 Message-ID: <20200319150016.61398-51-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 a0f90113a98d..50b3cc194196 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4029,6 +4029,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); @@ -4041,6 +4141,7 @@ static DEVICE_ATTR(debug_v2_enable, 0600, NULL, static DEVICE_ATTR(debug_notify, 0444, 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, @@ -4053,6 +4154,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 Thu Mar 19 15:00:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447391 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 A1AF2913 for ; Thu, 19 Mar 2020 15:03:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 773D52072D for ; Thu, 19 Mar 2020 15:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728591AbgCSPDn (ORCPT ); Thu, 19 Mar 2020 11:03:43 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:32457 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728576AbgCSPDn (ORCPT ); Thu, 19 Mar 2020 11:03:43 -0400 IronPort-SDR: 8EdNT4LMhqbCE+UKbRyFklJQsocCOKv41P3kMFFIwJoPvasFUSJc7sluaYN5ZNJtOCq3iUzCYh Nxd2WnbyRLx+bLGGE2S1s1dfjbzCfPuh1HNfKtiY/zXMI+0TXer+wmtzR9nuhfpHjkj9sLqLE8 +fcKyil5FdPZlVDp1At90rrbGg3KOUECgxqiHXEUxzfLgaDOCIe2FDgKibagsfTztcELCmzUYD oi8WtB8Efs1l0BakCd9nJ2BakDF2UPsqMA9koEmfFHyR4/Ttl6S2c2qKU0sj1/iBzUHcI01NDX rKQ= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46891167" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:42 -0800 IronPort-SDR: iMU4atmCqg4P80U8gohvrIEsXNe4By47tvZEipzNmqn5zUuI0pds3Ac28hhHW1LLNonI9Z9vWW XJ/HrH2j/pjMsPDwzNMch3qIBBT4MmGgH32eMJbW+mi5Tq505TlNRzY0mlkLILDoNDBlfVPd2N HuF+DY7iIX/B0aAPmdDDx8aqMe3Q07OYYXts+E0meCWif0be3Xd5tCj5rDNxeMxP8SBVPJBz7i hgCTvgxwvGqsyl+sBytu8SfI9KlEeUKW/hPTlXzK9Ygn3Av49D9Vsr7PeQ/uiTz8Mr45RNeemO Fww= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 51/52] Input: atmel_mxt_ts: Implement synchronization during various operation Date: Thu, 19 Mar 2020 08:00:15 -0700 Message-ID: <20200319150016.61398-52-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 50b3cc194196..a8e80e77624d 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 36E5 /* 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 { @@ -1654,6 +1673,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) { @@ -1681,6 +1701,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) exit: data->mxt_status.intp_triggered = false; + mutex_unlock(&data->lock); + return ret; } @@ -2263,6 +2285,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; @@ -2292,6 +2316,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, @@ -2973,8 +2999,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) @@ -3090,6 +3123,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, @@ -3869,30 +3911,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, @@ -3900,14 +3970,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); @@ -3915,8 +4009,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) { @@ -3932,15 +4024,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; } @@ -4204,8 +4289,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: @@ -4249,8 +4343,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; } @@ -4259,8 +4357,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 || data->e_state == MXT_STATE_UPDATING_CONFIG) { + mutex_unlock(&data->lock); return 0; + } + if ((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: @@ -4290,8 +4399,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) @@ -4446,12 +4562,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) ? @@ -4545,6 +4664,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) { @@ -4605,6 +4736,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 Thu Mar 19 15:00:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11447399 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 F13F26CA for ; Thu, 19 Mar 2020 15:06:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA92620BED for ; Thu, 19 Mar 2020 15:06:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727425AbgCSPGw (ORCPT ); Thu, 19 Mar 2020 11:06:52 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:5833 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727183AbgCSPGw (ORCPT ); Thu, 19 Mar 2020 11:06:52 -0400 IronPort-SDR: frHQI7gmou2DTYNl0SN9ICJNA/fa6VE4RSZ7FCwFgWGaCHe9WcYhpuK4dNO97ni09SeDupanRc Jq9vo/ZIg///D2XAuBwdQDLibR4lZqhhjyOvWlPhqL9sWPtwuW5p7flch3KP8svku67PoR0UU8 2IGMwwbjru0JBV4Z7D0r2J6SgCKBGiHWjNorZHNWl2UnkS107jiL1k40v4jezDrS+BcE+qMVtd b0rmAXFWIPIaBqLaUANdSgw+NFQbm+6TdqiEmRx4AZFWh3N2HakCYxXMkwxEUYHciA4VXp8CKn o6s= X-IronPort-AV: E=Sophos;i="5.70,572,1574150400"; d="scan'208";a="46927151" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 19 Mar 2020 07:03:46 -0800 IronPort-SDR: a8I4DIKisE09+xItcWC9u5+rEINlZH9hGL9eUge0z0yPQei6GkZeDE1rwGTjZYLMKqHARP7bvr S/2p1m+rHzmxKWOhRmV6RemAepiJzMMNdiUJgNiWOmMOlWTueJXRnGd2vfAuhc2lTSa4qsAB/p Q+6weqw0FZ9OAL0H9SqXK4K+4fCfp97K+fABWFK8zkZ6So82MvO8sfwCFENcV84nqpHPqQqFT3 iAvVQHqj7AguFrTC1IekVM8Y1241lvEtHyG+gbrzugjZeyd+B5ckjI8+j4FT4UWKdkzGfEsgTX UJU= From: Jiada Wang To: , , , , , CC: , , , , Subject: [PATCH v8 52/52] Input: atmel_mxt_ts - Fix compilation warning Date: Thu, 19 Mar 2020 08:00:16 -0700 Message-ID: <20200319150016.61398-53-jiada_wang@mentor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200319150016.61398-1-jiada_wang@mentor.com> References: <20200319150016.61398-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 a8e80e77624d..b1e27a07de6a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2048,7 +2048,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",