From patchwork Tue Sep 17 09:32:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148377 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 E4FD213BD for ; Tue, 17 Sep 2019 09:34:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF63720862 for ; Tue, 17 Sep 2019 09:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbfIQJes (ORCPT ); Tue, 17 Sep 2019 05:34:48 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21876 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbfIQJer (ORCPT ); Tue, 17 Sep 2019 05:34:47 -0400 IronPort-SDR: x0X6iVCiTfMnYhX/tiMJ5Wavw7IeHUonNw4r3Ok4WD5pQETL7jgME5nSdWMvFu8Tz+PML0XDYB v7tcLLWKanEpEP/mf3xxT/N1uD6ZlQIevzLLTeqU60as2uUtZ0D5yDzIMFRJVRLnWnpn09CQJn C3AJ2p0V+b4PpgeEMP3P/goxsIUzYEmEjPdvfO6YScLiGj9VJtoXwjwZ7zUp/wuzenaO25XALw dOgmzpp3hlQF5rx/727B0ANknnRko6vZcfw1sct0FPtfWNH5Jgtf0BJOWZmZ99xhvH9WL5N91C U1M= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422943" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:34:46 -0800 IronPort-SDR: ea0qeJFJ6pWHiW2TkJP7zDez6MYjT9gPKvp0pqx6lumJzcW+K5KRGrmXzoVTNITPXlbyZG3Rlg YF5eAL6Ti3SqTotQrpsu5VQvuo+tyKB/nV4/VSSZBE2IIqOTnsgqDKh0PUO6P2D/I6ZjK+Gvd4 JE7hkFvOt6GOJatweeP1LugdIEpm8dDU0hkMeoKQd9E4SQDeqY/K3AsdNHeEGHzO2O5HY4ZnD/ JzlFP4Dr4pBNcmdhw1xFchzJCmW0EYk2EnFmGkvtOcR690FFOV9evid2phrspk8lpS0ibsBsjC rjg= From: Jiada Wang To: , , , , CC: , Subject: [PATCH v3 01/49] Input: switch to use return value of input_mt_report_slot_state Date: Tue, 17 Sep 2019 18:32:32 +0900 Message-ID: <20190917093320.18134-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093320.18134-1-jiada_wang@mentor.com> References: <20190917093320.18134-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Currently several places are calling input_mt_report_slot_state() like following: input_mt_report_slot_state(dev, tool_type, active) if (active) { ... < report events for active slot > } when 'active' is false, input_mt_report_slot_state() will always return false, so instead of checking 'active', switch to use return value of input_mt_report_slot_state() Signed-off-by: Jiada Wang --- drivers/hid/hid-asus.c | 3 +-- drivers/hid/hid-elan.c | 3 +-- drivers/hid/hid-logitech-hidpp.c | 5 ++--- drivers/hid/hid-magicmouse.c | 3 +-- drivers/hid/hid-multitouch.c | 3 +-- drivers/hid/hid-sony.c | 8 ++++---- drivers/hid/wacom_wac.c | 15 +++++---------- drivers/input/mouse/elantech.c | 5 ++--- drivers/input/mouse/focaltech.c | 3 +-- drivers/input/mouse/sentelic.c | 3 +-- drivers/input/mouse/synaptics.c | 3 +-- drivers/input/rmi4/rmi_2d_sensor.c | 6 ++---- drivers/input/touchscreen/chipone_icn8505.c | 4 ++-- drivers/input/touchscreen/egalax_ts.c | 3 +-- drivers/input/touchscreen/hideep.c | 7 +++---- drivers/input/touchscreen/ili210x.c | 3 +-- drivers/input/touchscreen/mms114.c | 4 ++-- drivers/input/touchscreen/penmount.c | 5 ++--- drivers/input/touchscreen/raydium_i2c_ts.c | 4 ++-- drivers/input/touchscreen/sis_i2c.c | 5 ++--- drivers/input/touchscreen/surface3_spi.c | 4 ++-- drivers/input/touchscreen/wacom_w8001.c | 3 +-- drivers/input/touchscreen/zforce_ts.c | 6 ++---- 23 files changed, 42 insertions(+), 66 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 8063b1d567b1..55f1004f0e58 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -240,9 +240,8 @@ static int asus_report_input(struct asus_drvdata *drvdat, u8 *data, int size) MT_TOOL_PALM : MT_TOOL_FINGER; input_mt_slot(drvdat->input, i); - input_mt_report_slot_state(drvdat->input, toolType, down); - if (down) { + if (input_mt_report_slot_state(drvdat->input, toolType, down)) { asus_report_contact_down(drvdat, toolType, contactData); contactData += drvdat->tp->contact_size; } diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 45c4f888b7c4..84a317c6feb6 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c @@ -216,8 +216,7 @@ static void elan_report_mt_slot(struct elan_drvdata *drvdata, u8 *data, bool active = !!data; input_mt_slot(input, slot_num); - input_mt_report_slot_state(input, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, active)) { x = ((data[0] & 0xF0) << 4) | data[1]; y = drvdata->max_y - (((data[0] & 0x07) << 8) | data[2]); diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 21268c9fa71a..a7b552a797f1 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -2295,9 +2295,8 @@ static void wtp_touch_event(struct hidpp_device *hidpp, slot = input_mt_get_slot_by_key(hidpp->input, touch_report->finger_id); input_mt_slot(hidpp->input, slot); - input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER, - touch_report->contact_status); - if (touch_report->contact_status) { + if (input_mt_report_slot_state(hidpp->input, MT_TOOL_FINGER, + touch_report->contact_status)) { input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_X, touch_report->x); input_event(hidpp->input, EV_ABS, ABS_MT_POSITION_Y, diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 34138667f8af..5f9f6426d7b8 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -282,10 +282,9 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda msc->ntouches++; input_mt_slot(input, id); - input_mt_report_slot_state(input, MT_TOOL_FINGER, down); /* Generate the input events for this touch. */ - if (down) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, down)) { input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major << 2); input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor << 2); input_report_abs(input, ABS_MT_ORIENTATION, -orientation); diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index b603c14d043b..672396ed413e 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -1020,8 +1020,7 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, } input_mt_slot(input, slotnum); - input_mt_report_slot_state(input, tool, active); - if (active) { + if (input_mt_report_slot_state(input, tool, active)) { /* this finger is in proximity of the sensor */ int wide = (*slot->w > *slot->h); int major = max(*slot->w, *slot->h); diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 49dd2d905c7f..8ba21584a84a 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1092,9 +1092,9 @@ static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size) active = !(rd[offset] >> 7); input_mt_slot(sc->touchpad, n); - input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(sc->touchpad, + MT_TOOL_FINGER, active)) { input_report_abs(sc->touchpad, ABS_MT_POSITION_X, x); input_report_abs(sc->touchpad, ABS_MT_POSITION_Y, y); } @@ -1146,9 +1146,9 @@ static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size) y = ((rd[offset+1] & 0xF0) >> 4) | (rd[offset+2] << 4); input_mt_slot(sc->touchpad, n); - input_mt_report_slot_state(sc->touchpad, MT_TOOL_FINGER, active & 0x03); - if (active & 0x03) { + if (input_mt_report_slot_state(sc->touchpad, + MT_TOOL_FINGER, active & 0x03)) { contactx = rd[offset+3] & 0x0F; contacty = rd[offset+3] >> 4; input_report_abs(sc->touchpad, ABS_MT_TOUCH_MAJOR, diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 7a8ddc999a8e..c49b261753f0 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1504,9 +1504,8 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom) if (slot < 0) continue; input_mt_slot(input, slot); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) { int t_x = get_unaligned_le16(&data[offset + 2]); int t_y = get_unaligned_le16(&data[offset + 4 + y_offset]); @@ -1570,8 +1569,7 @@ static int wacom_mt_touch(struct wacom_wac *wacom) continue; input_mt_slot(input, slot); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) { int x = get_unaligned_le16(&data[offset + x_offset + 7]); int y = get_unaligned_le16(&data[offset + x_offset + 9]); input_report_abs(input, ABS_MT_POSITION_X, x); @@ -1599,8 +1597,7 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom) bool touch = p && report_touch_events(wacom); input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) { int x = le16_to_cpup((__le16 *)&data[i * 2 + 2]) & 0x7fff; int y = le16_to_cpup((__le16 *)&data[i * 2 + 6]) & 0x7fff; @@ -2842,8 +2839,7 @@ static int wacom_bpt_touch(struct wacom_wac *wacom) && (data[offset + 3] & 0x80); input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) { int x = get_unaligned_be16(&data[offset + 3]) & 0x7ff; int y = get_unaligned_be16(&data[offset + 5]) & 0x7ff; if (features->quirks & WACOM_QUIRK_BBTOUCH_LOWRES) { @@ -2879,9 +2875,8 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data) touch = touch && report_touch_events(wacom); input_mt_slot(input, slot); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) { int x = (data[2] << 4) | (data[4] >> 4); int y = (data[3] << 4) | (data[4] & 0x0f); int width, height; diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index 2d8434b7b623..da06490bb914 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -343,8 +343,7 @@ static void elantech_set_slot(struct input_dev *dev, int slot, bool active, unsigned int x, unsigned int y) { input_mt_slot(dev, slot); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, active)) { input_report_abs(dev, ABS_MT_POSITION_X, x); input_report_abs(dev, ABS_MT_POSITION_Y, y); } @@ -608,7 +607,7 @@ static void process_packet_status_v4(struct psmouse *psmouse) for (i = 0; i < ETP_MAX_FINGERS; i++) { if ((fingers & (1 << i)) == 0) { input_mt_slot(dev, i); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(dev); } } diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c index 6fd5fff0cbff..fd627fab16c0 100644 --- a/drivers/input/mouse/focaltech.c +++ b/drivers/input/mouse/focaltech.c @@ -124,8 +124,7 @@ static void focaltech_report_state(struct psmouse *psmouse) bool active = finger->active && finger->valid; input_mt_slot(dev, i); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, active)) { unsigned int clamped_x, clamped_y; /* * The touchpad might report invalid data, so we clamp diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c index e99d9bf1a267..1a8a2e19c514 100644 --- a/drivers/input/mouse/sentelic.c +++ b/drivers/input/mouse/sentelic.c @@ -683,8 +683,7 @@ static void fsp_set_slot(struct input_dev *dev, int slot, bool active, unsigned int x, unsigned int y) { input_mt_slot(dev, slot); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, active)) { input_report_abs(dev, ABS_MT_POSITION_X, x); input_report_abs(dev, ABS_MT_POSITION_Y, y); } diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index b1956ed4c0dd..6969b37ba731 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -882,8 +882,7 @@ static void synaptics_report_semi_mt_slot(struct input_dev *dev, int slot, bool active, int x, int y) { input_mt_slot(dev, slot); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); - if (active) { + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, active)) { input_report_abs(dev, ABS_MT_POSITION_X, x); input_report_abs(dev, ABS_MT_POSITION_Y, synaptics_invert_y(y)); } diff --git a/drivers/input/rmi4/rmi_2d_sensor.c b/drivers/input/rmi4/rmi_2d_sensor.c index ea549efe4bc4..c0f7be7c3737 100644 --- a/drivers/input/rmi4/rmi_2d_sensor.c +++ b/drivers/input/rmi4/rmi_2d_sensor.c @@ -76,10 +76,8 @@ void rmi_2d_sensor_abs_report(struct rmi_2d_sensor *sensor, else input_mt_slot(input, slot); - input_mt_report_slot_state(input, obj->mt_tool, - obj->type != RMI_2D_OBJECT_NONE); - - if (obj->type != RMI_2D_OBJECT_NONE) { + if (input_mt_report_slot_state(input, obj->mt_tool, + obj->type != RMI_2D_OBJECT_NONE)) { obj->x = sensor->tracking_pos[slot].x; obj->y = sensor->tracking_pos[slot].y; diff --git a/drivers/input/touchscreen/chipone_icn8505.c b/drivers/input/touchscreen/chipone_icn8505.c index c768186ce856..9880101cd14b 100644 --- a/drivers/input/touchscreen/chipone_icn8505.c +++ b/drivers/input/touchscreen/chipone_icn8505.c @@ -344,8 +344,8 @@ static irqreturn_t icn8505_irq(int irq, void *dev_id) bool act = icn8505_touch_active(touch->event); input_mt_slot(icn8505->input, touch->slot); - input_mt_report_slot_state(icn8505->input, MT_TOOL_FINGER, act); - if (!act) + if (!input_mt_report_slot_state(icn8505->input, + MT_TOOL_FINGER, act)) continue; touchscreen_report_pos(icn8505->input, &icn8505->prop, diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c index 83ac8c128192..c0774c29e496 100644 --- a/drivers/input/touchscreen/egalax_ts.c +++ b/drivers/input/touchscreen/egalax_ts.c @@ -99,12 +99,11 @@ static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id) } input_mt_slot(input_dev, id); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, down); dev_dbg(&client->dev, "%s id:%d x:%d y:%d z:%d", down ? "down" : "up", id, x, y, z); - if (down) { + if (input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, down)) { 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, z); diff --git a/drivers/input/touchscreen/hideep.c b/drivers/input/touchscreen/hideep.c index 84fbbf415c43..6f4c96f45a02 100644 --- a/drivers/input/touchscreen/hideep.c +++ b/drivers/input/touchscreen/hideep.c @@ -693,10 +693,9 @@ static void hideep_report_slot(struct input_dev *input, const struct hideep_event *event) { input_mt_slot(input, event->index & 0x0f); - input_mt_report_slot_state(input, - __GET_MT_TOOL_TYPE(event->type), - !(event->flag & HIDEEP_MT_RELEASED)); - if (!(event->flag & HIDEEP_MT_RELEASED)) { + if (input_mt_report_slot_state(input, + __GET_MT_TOOL_TYPE(event->type), + !(event->flag & HIDEEP_MT_RELEASED))) { input_report_abs(input, ABS_MT_POSITION_X, le16_to_cpup(&event->x)); input_report_abs(input, ABS_MT_POSITION_Y, diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index e9006407c9bc..2a5698e129d8 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -154,8 +154,7 @@ static bool ili210x_report_events(struct ili210x *priv, u8 *touchdata) } input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); - if (!touch) + if (!input_mt_report_slot_state(input, MT_TOOL_FINGER, touch)) continue; touchscreen_report_pos(input, &priv->prop, x, y, true); diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index a5ab774da4cc..ea46da04e517 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -178,9 +178,9 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou x, y, touch->width, touch->strength); input_mt_slot(input_dev, id); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); - if (touch->pressed) { + if (input_mt_report_slot_state(input_dev, + MT_TOOL_FINGER, touch->pressed)) { touchscreen_report_pos(input_dev, &data->props, x, y, true); input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); diff --git a/drivers/input/touchscreen/penmount.c b/drivers/input/touchscreen/penmount.c index 12abb3b36128..2721a608d7fc 100644 --- a/drivers/input/touchscreen/penmount.c +++ b/drivers/input/touchscreen/penmount.c @@ -69,9 +69,8 @@ static void pm_mtevent(struct pm *pm, struct input_dev *input) for (i = 0; i < pm->maxcontacts; ++i) { input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, - pm->slots[i].active); - if (pm->slots[i].active) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, + pm->slots[i].active)) { input_event(input, EV_ABS, ABS_MT_POSITION_X, pm->slots[i].x); input_event(input, EV_ABS, ABS_MT_POSITION_Y, pm->slots[i].y); } diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c index 6ed9f22e6401..d9f253a82eba 100644 --- a/drivers/input/touchscreen/raydium_i2c_ts.c +++ b/drivers/input/touchscreen/raydium_i2c_ts.c @@ -801,9 +801,9 @@ static void raydium_mt_event(struct raydium_data *ts) u8 wx, wy; input_mt_slot(ts->input, i); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, state); - if (!state) + if (!input_mt_report_slot_state(ts->input, + MT_TOOL_FINGER, state)) continue; input_report_abs(ts->input, ABS_MT_POSITION_X, diff --git a/drivers/input/touchscreen/sis_i2c.c b/drivers/input/touchscreen/sis_i2c.c index 6274555f1673..55857328bbc7 100644 --- a/drivers/input/touchscreen/sis_i2c.c +++ b/drivers/input/touchscreen/sis_i2c.c @@ -189,10 +189,9 @@ static int sis_ts_report_contact(struct sis_ts_data *ts, const u8 *data, u8 id) return -ENOENT; input_mt_slot(input, slot); - input_mt_report_slot_state(input, MT_TOOL_FINGER, - status == SIS_STATUS_DOWN); - if (status == SIS_STATUS_DOWN) { + if (input_mt_report_slot_state(input, MT_TOOL_FINGER, + status == SIS_STATUS_DOWN)) { pressure = height = width = 1; if (id != SIS_ALL_IN_ONE_PACKAGE) { if (SIS_PKT_HAS_AREA(id)) { diff --git a/drivers/input/touchscreen/surface3_spi.c b/drivers/input/touchscreen/surface3_spi.c index ce4828b1415a..6981790dd541 100644 --- a/drivers/input/touchscreen/surface3_spi.c +++ b/drivers/input/touchscreen/surface3_spi.c @@ -75,8 +75,8 @@ static void surface3_spi_report_touch(struct surface3_ts_data *ts_data, return; input_mt_slot(ts_data->input_dev, slot); - input_mt_report_slot_state(ts_data->input_dev, MT_TOOL_FINGER, st); - if (st) { + if (input_mt_report_slot_state(ts_data->input_dev, + MT_TOOL_FINGER, st)) { input_report_abs(ts_data->input_dev, ABS_MT_POSITION_X, get_unaligned_le16(&finger->x)); diff --git a/drivers/input/touchscreen/wacom_w8001.c b/drivers/input/touchscreen/wacom_w8001.c index 3715d1eace92..cf2f233cdbfb 100644 --- a/drivers/input/touchscreen/wacom_w8001.c +++ b/drivers/input/touchscreen/wacom_w8001.c @@ -155,8 +155,7 @@ static void parse_multi_touch(struct w8001 *w8001) bool touch = data[0] & (1 << i); input_mt_slot(dev, i); - input_mt_report_slot_state(dev, MT_TOOL_FINGER, touch); - if (touch) { + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, touch)) { x = (data[6 * i + 1] << 7) | data[6 * i + 2]; y = (data[6 * i + 3] << 7) | data[6 * i + 4]; /* data[5,6] and [11,12] is finger capacity */ diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c index 5230519b0f74..37ae4599c0db 100644 --- a/drivers/input/touchscreen/zforce_ts.c +++ b/drivers/input/touchscreen/zforce_ts.c @@ -386,10 +386,8 @@ static int zforce_touch_event(struct zforce_ts *ts, u8 *payload) /* the zforce id starts with "1", so needs to be decreased */ input_mt_slot(ts->input, point.id - 1); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, - point.state != STATE_UP); - - if (point.state != STATE_UP) { + if (input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, + point.state != STATE_UP)) { input_report_abs(ts->input, ABS_MT_POSITION_X, point.coord_x); input_report_abs(ts->input, ABS_MT_POSITION_Y, From patchwork Tue Sep 17 09:32:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148381 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 438A7912 for ; Tue, 17 Sep 2019 09:34:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 19D7421881 for ; Tue, 17 Sep 2019 09:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfIQJev (ORCPT ); Tue, 17 Sep 2019 05:34:51 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21876 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbfIQJeu (ORCPT ); Tue, 17 Sep 2019 05:34:50 -0400 IronPort-SDR: hIkGUG33Nunk3KdqYWFnpulbd/9pvemvlHHJF524bQqaBGA5/Mtk5F7tIgLuqvFUOFHCUkvYnq CcB83v2dpMdZoLa+XWLl1wDEDdHZuH9HW0aLYAtnPSWR5FX95k1mJmALWc4JNyUaTBw0PAcbFr M5+aR/uIsKEjUsDXGFFXwE8HYvDNCyEroeDNn7pHoJKdMuwfDqB4CYVvbKd10REtiIKm/BmmGg 1pOzHa5jE7b7HRRJ8qFUHKkraEt072FriQnrNd4s92CUtrXOQJf+V+JfXUR7WoUe6NUjhTz8u/ 0xA= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422944" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:34:49 -0800 IronPort-SDR: zT1A8eo8IUxJ3ZY0zefYQ0cqGOdw3a/7GqAVOzpGvit5JZmvTfGzFlGip/r1bxLXD5NocBMXRO f8A6r7hzMSuFXCJvTpQb0cKgZaXY12DKCKHebW1bZCAT5Oro0XGxOZzEd56eQSCbZcWwH1+rv1 Wwj2+B7OlFLttUMgFvnHVbytw/3d1KFhNNjxBHVvrnMp5vmypzYMTnMcbXPxoKCLixlmfNSx/1 j2RzOfKNln3WDQS2RbSaCT6a9gSrqEEj+qXOsQBHEfKavCLkdrCNWvK1gDHzeDnGPdTiZaz2HU DgA= From: Jiada Wang To: , , , , CC: , Subject: [PATCH v3 02/49] Input: introduce input_mt_report_slot_inactive Date: Tue, 17 Sep 2019 18:32:33 +0900 Message-ID: <20190917093320.18134-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093320.18134-1-jiada_wang@mentor.com> References: <20190917093320.18134-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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. Signed-off-by: Jiada Wang --- drivers/hid/hid-alps.c | 3 +-- drivers/hid/hid-multitouch.c | 6 ++---- drivers/input/input-mt.c | 2 +- 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 +++++ 13 files changed, 22 insertions(+), 22 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 672396ed413e..b2221f2030c1 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -880,7 +880,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; } @@ -1620,9 +1620,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/input-mt.c b/drivers/input/input-mt.c index a81e14148407..7626fe5bfe44 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c @@ -145,7 +145,7 @@ bool input_mt_report_slot_state(struct input_dev *dev, slot->frame = mt->frame; if (!active) { - input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); + input_mt_report_slot_inactive(dev); return false; } 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 d9b103a81a79..b72358d4b35c 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 4a5f482cf1af..573b94a049b2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -822,8 +822,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) * have happened. */ if (status & MXT_T9_RELEASE) { - input_mt_report_slot_state(input_dev, - MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input_dev); mxt_input_sync(data); } @@ -839,7 +838,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); } else { /* Touch no longer active, close out slot */ - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input_dev); } data->update_input = true; @@ -947,7 +946,7 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) dev_dbg(dev, "[%u] release\n", id); /* close out slot */ - input_mt_report_slot_state(input_dev, 0, 0); + input_mt_report_slot_inactive(input_dev); } data->update_input = true; diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c index 4b22d49a0f49..a3a85e2348a2 100644 --- a/drivers/input/touchscreen/cyttsp4_core.c +++ b/drivers/input/touchscreen/cyttsp4_core.c @@ -744,8 +744,7 @@ static void cyttsp4_report_slot_liftoff(struct cyttsp4_mt_data *md, for (t = 0; t < max_slots; t++) { input_mt_slot(md->input, t); - input_mt_report_slot_state(md->input, - MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(md->input); } } @@ -845,7 +844,7 @@ static void cyttsp4_final_sync(struct input_dev *input, int max_slots, int *ids) if (ids[t]) continue; input_mt_slot(input, t); - input_mt_report_slot_state(input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input); } input_sync(input); diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c index 3f5d463dbeed..697aa2c158f7 100644 --- a/drivers/input/touchscreen/cyttsp_core.c +++ b/drivers/input/touchscreen/cyttsp_core.c @@ -340,7 +340,7 @@ static void cyttsp_report_tchdata(struct cyttsp *ts) continue; input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input); } input_sync(input); diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c index 247c3aaba2d8..f67efdd040b2 100644 --- a/drivers/input/touchscreen/melfas_mip4.c +++ b/drivers/input/touchscreen/melfas_mip4.c @@ -391,7 +391,7 @@ static void mip4_clear_input(struct mip4_ts *ts) /* Screen */ for (i = 0; i < MIP4_MAX_FINGERS; i++) { input_mt_slot(ts->input, i); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(ts->input); } /* Keys */ @@ -534,7 +534,7 @@ static void mip4_report_touch(struct mip4_ts *ts, u8 *packet) } else { /* Release event */ input_mt_slot(ts->input, id); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(ts->input); } input_mt_sync_frame(ts->input); diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c index ea46da04e517..d4e088364bed 100644 --- a/drivers/input/touchscreen/mms114.c +++ b/drivers/input/touchscreen/mms114.c @@ -550,7 +550,7 @@ static int __maybe_unused mms114_suspend(struct device *dev) /* Release all touch */ for (id = 0; id < MMS114_MAX_TOUCH; id++) { input_mt_slot(input_dev, id); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(input_dev); } input_mt_report_pointer_emulation(input_dev, true); diff --git a/drivers/input/touchscreen/raspberrypi-ts.c b/drivers/input/touchscreen/raspberrypi-ts.c index 69881265d121..147ea4f8f87b 100644 --- a/drivers/input/touchscreen/raspberrypi-ts.c +++ b/drivers/input/touchscreen/raspberrypi-ts.c @@ -102,7 +102,7 @@ static void rpi_ts_poll(struct input_polled_dev *dev) released_ids = ts->known_ids & ~modified_ids; for_each_set_bit(i, &released_ids, RPI_TS_MAX_SUPPORTED_POINTS) { input_mt_slot(input, i); - input_mt_report_slot_state(input, MT_TOOL_FINGER, 0); + input_mt_report_slot_inactive(input); modified_ids &= ~(BIT(i)); } ts->known_ids = modified_ids; diff --git a/drivers/input/touchscreen/stmfts.c b/drivers/input/touchscreen/stmfts.c index b6f95f20f924..b54cc64e4ea6 100644 --- a/drivers/input/touchscreen/stmfts.c +++ b/drivers/input/touchscreen/stmfts.c @@ -198,7 +198,7 @@ static void stmfts_report_contact_release(struct stmfts_data *sdata, u8 slot_id = (event[0] & STMFTS_MASK_TOUCH_ID) >> 4; input_mt_slot(sdata->input, slot_id); - input_mt_report_slot_state(sdata->input, MT_TOOL_FINGER, false); + input_mt_report_slot_inactive(sdata->input); input_sync(sdata->input); } diff --git a/include/linux/input/mt.h b/include/linux/input/mt.h index 9e409bb13642..ab9a34c312f9 100644 --- a/include/linux/input/mt.h +++ b/include/linux/input/mt.h @@ -97,6 +97,11 @@ static inline bool input_is_mt_axis(int axis) return axis == ABS_MT_SLOT || input_is_mt_value(axis); } +static inline void input_mt_report_slot_inactive(struct input_dev *dev) +{ + input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); + +} bool input_mt_report_slot_state(struct input_dev *dev, unsigned int tool_type, bool active); From patchwork Tue Sep 17 09:32:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148379 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 CCC9113BD for ; Tue, 17 Sep 2019 09:34:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABC5120862 for ; Tue, 17 Sep 2019 09:34:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727814AbfIQJex (ORCPT ); Tue, 17 Sep 2019 05:34:53 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21876 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbfIQJex (ORCPT ); Tue, 17 Sep 2019 05:34:53 -0400 IronPort-SDR: 9BId0rwHIH3e6n+uAaDzfkpNQJX8h1EjTkebeKVFgbIfaQnhTMxFARq51ypIrWf7+/hUqOJ05q GVVvo+xVBDgJD/YjBwLl+YoRANe+HO/e09oLhqeFTFkBx+sPulXQhWrVzNPQbJbbAGw5SRM9Nv DhYGxU3aYURLWDocSjqGBIUcpz1uoNX0B5ljnzzrL64SVf8U9duW0vZCiMIxqEAI1uEfv3PfW3 42BTTVUT0VZRIBdpI5ViEfdh/mYptpKaG71kxZf5tmZQ8zk4Hhx9V0JM2qoRXPr034Raksj6Pl EEc= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422948" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:34:52 -0800 IronPort-SDR: Q7olUkWHv20JAOemYWxVjQ7BtBQfrpq33bjbDDhb7KVlRf3zr76x3JQU04q0ERFyMD/6/PA1O6 nehcI5toZHiZHTFPVn+3T6lJixeV34wsR6sWOs4oUH4nfDRCL5GuIXUnfyNd8WfCAN5eSGp5uv TuX8FqSdPq/TwecuecOpEtwOoQDjMxCn2UfRZeZv7k/DIsKgrXmcVxGBmNArD3O+cxpNFPAEak LGHst8piJ5U5XrtyMvTe4D2Dpiuu9cXO7UtYXs304EYXPDlNzeWe6wYHb2pNxuizlrPNhHZjZb Tzg= From: Jiada Wang To: , , , , CC: , Subject: [PATCH v3 03/49] Input: atmel_mxt_ts - rework sysfs init/remove Date: Tue, 17 Sep 2019 18:32:34 +0900 Message-ID: <20190917093320.18134-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093320.18134-1-jiada_wang@mentor.com> References: <20190917093320.18134-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer An error in the sysfs init may otherwise interfere with the async return from the firmware loader Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3114584ae77c2b03b6dad87174f010d002e9c05d) [gdavis: Forward port and fixup conflicts. Also fixed sysfs leaks in both the mxt_initialize() and mxt_probe() error return cases.] Signed-off-by: George G. Davis [jiada: keep call mxt_initialize() before sysfs creation] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 573b94a049b2..17263c260124 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2086,10 +2086,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) return 0; err_free_mem: + data->input_dev = NULL; input_free_device(input_dev); return error; } +static int mxt_sysfs_init(struct mxt_data *data); +static void mxt_sysfs_remove(struct mxt_data *data); + static int mxt_configure_objects(struct mxt_data *data, const struct firmware *cfg); @@ -2141,16 +2145,24 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_sysfs_init(data); + if (error) + return error; + error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, &client->dev, GFP_KERNEL, data, mxt_config_cb); if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - return error; + goto err_free_sysfs; } return 0; + +err_free_sysfs: + mxt_sysfs_remove(data); + return error; } static int mxt_set_t7_power_cfg(struct mxt_data *data, u8 sleep) @@ -2803,6 +2815,7 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); } else { @@ -2909,16 +2922,25 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); + +static struct attribute *mxt_fw_attrs[] = { + &dev_attr_update_fw.attr, + NULL +}; + +static const struct attribute_group mxt_fw_attr_group = { + .attrs = mxt_fw_attrs, +}; + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); -static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, - &dev_attr_update_fw.attr, NULL }; @@ -2926,6 +2948,28 @@ static const struct attribute_group mxt_attr_group = { .attrs = mxt_attrs, }; +static int mxt_sysfs_init(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); + if (error) { + dev_err(&client->dev, "Failure %d creating sysfs group\n", + error); + return error; + } + + return 0; +} + +static void mxt_sysfs_remove(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + + sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); +} + static void mxt_start(struct mxt_data *data) { switch (data->suspend_mode) { @@ -3113,19 +3157,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) @@ -3133,7 +3172,8 @@ static int mxt_remove(struct i2c_client *client) struct mxt_data *data = i2c_get_clientdata(client); disable_irq(data->irq); - sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); + sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); From patchwork Tue Sep 17 09:32:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148383 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 6FA09912 for ; Tue, 17 Sep 2019 09:35:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D166218AC for ; Tue, 17 Sep 2019 09:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbfIQJe6 (ORCPT ); Tue, 17 Sep 2019 05:34:58 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21876 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727843AbfIQJe5 (ORCPT ); Tue, 17 Sep 2019 05:34:57 -0400 IronPort-SDR: 8ZNFfkmDIPXLmeKSohIEQbmIbpSSALB95R4qhK1M8p6VIS0fr0v9lsWBd6xW+hlCUJHxgm6cqc otVxeXnKINKDpOw+LPDrvzpr+8AMbKJvhzsVwhaTSwILUPVOVBjfaGy348kMmmd9D8BCIAEr+X zU2IkqXdvk6xoBLEjdTvaczoDvSJqZtH0n+Za8uOAvUhTE7SzLFpks/rrBSFJOAnrwMRwu/LpD a2Gec8fkKm4xLca5IczKDRmxLYdGUzofwXY+nVw9BaO/Mc2X56q3fP8s+ezmCm0/nJXcv+v1Sq E5s= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422954" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:34:56 -0800 IronPort-SDR: faGpSfMIK0ze1+xK+LdclQEaiYdN6Yho6BYy8PQEO9L82KF1yPjCVMqsJYqtKerkkFYpgjBnwW iF8AlsTy86oubDFS/+chKn/dorcQsjgi0AvthP4ylAZaZVlHri5Tf6dyq5mp0+p0sOfBSeCxTv HeVautLqaAKOwU5/pMCNd3+35BlotSxQGGwsO0N+lZXzH9L34/8nti9aE8wu54ICA8noukaqSc ulWQ13SbVrt/fqEva2J4BFGFCY8S+vOoqoSa3IpmTSlrkUeTxHvE5Vy030xWnWSE3drChmRfWc 2vE= From: Jiada Wang To: , , , , CC: , Subject: [PATCH v3 04/49] Input: atmel_mxt_ts - only read messages in mxt_acquire_irq() when necessary Date: Tue, 17 Sep 2019 18:32:35 +0900 Message-ID: <20190917093320.18134-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093320.18134-1-jiada_wang@mentor.com> References: <20190917093320.18134-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer The workaround of reading all messages until an invalid is received is a way of forcing the CHG line high, which means that when using edge-triggered interrupts the interrupt can be acquired. With level-triggered interrupts the workaround is unnecessary. Also, most recent maXTouch chips have a feature called RETRIGEN which, when enabled, reasserts the interrupt line every cycle if there are messages waiting. This also makes the workaround unnecessary. Note: the RETRIGEN feature is only in some firmware versions/chips, it's not valid simply to enable the bit. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 1ae4e8281e491b22442cd5acdfca1862555f8ecb) [gdavis: Fix conflicts due to v4.6-rc7 commit eb43335c4095 ("Input: atmel_mxt_ts - use mxt_acquire_irq in mxt_soft_reset").] Signed-off-by: George G. Davis [jiada: reset use_retrigen_workaround at beginning of mxt_check_retrigen()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 51 ++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 17263c260124..35cbe60094ab 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ struct t9_range { /* MXT_SPT_COMMSCONFIG_T18 */ #define MXT_COMMS_CTRL 0 #define MXT_COMMS_CMD 1 +#define MXT_COMMS_RETRIGEN BIT(6) /* MXT_DEBUG_DIAGNOSTIC_T37 */ #define MXT_DIAGNOSTIC_PAGEUP 0x01 @@ -308,6 +310,7 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; + bool use_retrigen_workaround; /* Cached parameters from object table */ u16 T5_address; @@ -318,6 +321,7 @@ struct mxt_data { u16 T71_address; u8 T9_reportid_min; u8 T9_reportid_max; + u16 T18_address; u8 T19_reportid; u16 T44_address; u8 T100_reportid_min; @@ -1190,9 +1194,11 @@ static int mxt_acquire_irq(struct mxt_data *data) enable_irq(data->irq); - error = mxt_process_messages_until_invalid(data); - if (error) - return error; + if (data->use_retrigen_workaround) { + error = mxt_process_messages_until_invalid(data); + if (error) + return error; + } return 0; } @@ -1282,6 +1288,33 @@ static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off) return crc; } +static int mxt_check_retrigen(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + int val; + + data->use_retrigen_workaround = false; + + if (irq_get_trigger_type(data->irq) & IRQF_TRIGGER_LOW) + return 0; + + if (data->T18_address) { + error = __mxt_read_reg(client, + data->T18_address + MXT_COMMS_CTRL, + 1, &val); + if (error) + return error; + + if (val & MXT_COMMS_RETRIGEN) + return 0; + } + + dev_warn(&client->dev, "Enabling RETRIGEN workaround\n"); + data->use_retrigen_workaround = true; + return 0; +} + static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg) { struct device *dev = &data->client->dev; @@ -1561,6 +1594,10 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); + ret = mxt_check_retrigen(data); + if (ret) + goto release_mem; + ret = mxt_soft_reset(data); if (ret) goto release_mem; @@ -1604,6 +1641,7 @@ static void mxt_free_object_table(struct mxt_data *data) data->T71_address = 0; data->T9_reportid_min = 0; data->T9_reportid_max = 0; + data->T18_address = 0; data->T19_reportid = 0; data->T44_address = 0; data->T100_reportid_min = 0; @@ -1678,6 +1716,9 @@ static int mxt_parse_object_table(struct mxt_data *data, object->num_report_ids - 1; data->num_touchids = object->num_report_ids; break; + case MXT_SPT_COMMSCONFIG_T18: + data->T18_address = object->start_address; + break; case MXT_SPT_MESSAGECOUNT_T44: data->T44_address = object->start_address; break; @@ -2141,6 +2182,10 @@ static int mxt_initialize(struct mxt_data *data) msleep(MXT_FW_RESET_TIME); } + error = mxt_check_retrigen(data); + if (error) + return error; + error = mxt_acquire_irq(data); if (error) return error; From patchwork Tue Sep 17 09:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148385 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 B0607912 for ; Tue, 17 Sep 2019 09:36:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98C0420862 for ; Tue, 17 Sep 2019 09:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbfIQJgF (ORCPT ); Tue, 17 Sep 2019 05:36:05 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgE (ORCPT ); Tue, 17 Sep 2019 05:36:04 -0400 IronPort-SDR: jeDmZW6D5hd/0g2X1V+NmTzqx0+VURaycNPkQiBBCJCneFqXZ4D/2GcKLwZkQIacnq3mppvtcT dC3k2DdHyvY4y0oA2UpkY1sS2ufQKNB9Tjp7JGJQolufuIpaxLPoGGXfUnya6/8RmYvrIsRWH6 SPOTJbyvNhfzplkqhosV2kcWzkauAafpSqNvPjNDT3vUk4c4+Ar7aX1IzXWgF0ANb45rp6DOKb KZFQCSE3gI3B6jiZHR8kd3+nIB6wCXjcpOPsVbpTCgqO1VmhL9ipt8ARKhsAJWH7wk0Tlm32UU fSY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422994" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:04 -0800 IronPort-SDR: fJ+orLfWgXKWZChBMpfWJb5UbNBCO7pHugKrCBXTs4DyucCdS5a5iDGFxwuWT4eqv2MyvOB5+Z yTQQGyivf3w2eq5URj/jCp8ZCNmn7vum0EdelcYPcMJjRJq0SN1gZFcbLTo22Q3NF3vFolGkZG hd8A5XHFlIECkULZFzbsa47q3RjFiEmeIcJc9gsqO03zwfeCta5m22bslERIVnp34/aVarsp8I TJJfX3/Uw4rcpAKaDkznd/1xChZxFtHqdmLhIN1D6vnIZK9WA5uDXY+uRTvFNjcTOwF3b94rCk +WE= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 05/49] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Tue, 17 Sep 2019 18:35:06 +0900 Message-ID: <20190917093550.18335-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer On some firmware variants, the size of the info block exceeds what can be read in a single transfer. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 74c4f5277cfa403d43fafc404119dc57a08677db) [gdavis: Forward port and fix conflicts due to v4.14.51 commit 960fe000b1d3 ("Input: atmel_mxt_ts - fix the firmware update").] Signed-off-by: George G. Davis [jiada: Change mxt_read_blks() to __mxt_read_reg(), original __mxt_read_reg() to __mxt_read_chunk()] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 35cbe60094ab..45bab5253775 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -40,7 +40,7 @@ #define MXT_OBJECT_START 0x07 #define MXT_OBJECT_SIZE 6 #define MXT_INFO_CHECKSUM_SIZE 3 -#define MXT_MAX_BLOCK_WRITE 256 +#define MXT_MAX_BLOCK_WRITE 255 /* Object types */ #define MXT_DEBUG_DIAGNOSTIC_T37 37 @@ -624,8 +624,8 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) return 0; } -static int __mxt_read_reg(struct i2c_client *client, - u16 reg, u16 len, void *val) +static int __mxt_read_chunk(struct i2c_client *client, + u16 reg, u16 len, void *val) { struct i2c_msg xfer[2]; u8 buf[2]; @@ -659,6 +659,28 @@ static int __mxt_read_reg(struct i2c_client *client, return ret; } +static int __mxt_read_reg(struct i2c_client *client, + u16 reg, u16 len, void *buf) +{ + u16 offset = 0; + int error; + u16 size; + + while (offset < len) { + size = min(MXT_MAX_BLOCK_WRITE, len - offset); + + error = __mxt_read_chunk(client, + reg + offset, + size, buf + offset); + if (error) + return error; + + offset += size; + } + + return 0; +} + static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, const void *val) { From patchwork Tue Sep 17 09:35:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148387 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 7636E912 for ; Tue, 17 Sep 2019 09:36:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D1F720862 for ; Tue, 17 Sep 2019 09:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727924AbfIQJgI (ORCPT ); Tue, 17 Sep 2019 05:36:08 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgI (ORCPT ); Tue, 17 Sep 2019 05:36:08 -0400 IronPort-SDR: teX0sjMnnoUn54zVN1y20AdRM6lHxguYiC+xr7OsFC/1QwPVaogIBeQAZsQXkMokkfCFv1dj2A pyCGvbBuZe2GjKbQgZfC9kA/LubuBiLEAgwgFNWCDKG/EpXSe+RoB3x1xLXR3jRHYpG3s2s2KA j109qVIOeCy03nkpEYF0gJ3hAFQYDaMR3gGQLz9ArCtp4aMj2Le69IkcmzvvVllJHTIj/KViIv OmJz09RrSqOU6OZlI2LmswhyLaazAmXO/pYndjRDlPAv9LNodu1ArtHhFvbfeBAZSwB4H/rYiC 99I= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41422998" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:07 -0800 IronPort-SDR: 3cKwkyYibhhAggBZo9fJ8FzLGVT3oRrjm3zPgbgDuYGu1/olZPgDqoxY17qceDRj0bL+iSm/cv T+zOi5p0Ua73CyFJ5VSn0mi793f+w3l2wv5qp4H+e+FrsBwHkXfHjkXbPjwHGO1CMT6iuzDTfB LUEuelbfIlUTae9NERWhXvVC2KXpGTD/hprj315AiseTVGP83BCMKg9tNOHZTPa9PICON3nDRC wr9X91evAAi8SFztMBj3azLXAl+RotRYTgZUDr2mo5K4mCVWCQDGCX3CIv3PKINlLuu+Jy9Z+R DSs= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 06/49] Input: atmel_mxt_ts - output status from T48 Noise Supression Date: Tue, 17 Sep 2019 18:35:07 +0900 Message-ID: <20190917093550.18335-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093550.18335-1-jiada_wang@mentor.com> References: <20190917093550.18335-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 45bab5253775..351347e2eced 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 Tue Sep 17 09:35:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148391 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 2741814DB for ; Tue, 17 Sep 2019 09:36:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1099421881 for ; Tue, 17 Sep 2019 09:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727326AbfIQJgL (ORCPT ); Tue, 17 Sep 2019 05:36:11 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgL (ORCPT ); Tue, 17 Sep 2019 05:36:11 -0400 IronPort-SDR: oA0yeBMqQRFU2kl9NA5hT3bvGMPnuIWPna4ysJ6nxjqwF44fWDZmkNdMoG/YhXoNPKHs5zuFD9 LWPyk0+z56xzmRgmTX/wgKt9A7ioyCsB5PYHIpTz7B4boDsgLEj0exqEUDJUIT/E0Pj9og0gW4 FJeVYtCBaOtdJwRlAg1xS+iJfWJHcM6BpZvSjRDspLv1I3KNQIFrwI5IUBRZzAfiuNiVIfu4G7 fWNV35qU+Zg7G9TEqdquRmasRn1mqSO3vvvyKZ21r0H8KkqTIEz8ySZyyGVFYymG1rhDZ/dRKX vSw= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423002" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:10 -0800 IronPort-SDR: cX39jof2JZwc/YLk6snfkUhD7ou4yYLt7FW/rw/4o8ourlXdqgza3/bu9IQS8c2uVSK8+SSHJM U8YDvvfen78l1hXlwLxEW1UrYBFYY0kpV78c9L62q4lj02tm3Q2F4gVv/YErDrJbICxlcMvqG2 xza+lBXHgSJymiloz8J/M+XuXde7XYPtqrEpvS0RlUOX4H+yT88TMGhZ15cpMMhG3xYw7u0RLY h2ph7kT49oPN6vxKTDbz9vrN3gwB/+XdckljkpoOizrVK1qdIHdztawE+KWQMnsNC+89f3sb+N nqI= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 07/49] Input: atmel_mxt_ts - output status from T42 Touch Suppression Date: Tue, 17 Sep 2019 18:35:08 +0900 Message-ID: <20190917093550.18335-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093550.18335-1-jiada_wang@mentor.com> References: <20190917093550.18335-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 351347e2eced..19fa3e58269a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -155,6 +155,9 @@ struct t37_debug { #define MXT_RESET_VALUE 0x01 #define MXT_BACKUP_VALUE 0x55 +/* Define for MXT_PROCI_TOUCHSUPPRESSION_T42 */ +#define MXT_T42_MSG_TCHSUP BIT(0) + /* T100 Multiple Touch Touchscreen */ #define MXT_T100_CTRL 0 #define MXT_T100_CFG1 1 @@ -323,6 +326,8 @@ struct mxt_data { u8 T9_reportid_max; u16 T18_address; u8 T19_reportid; + u8 T42_reportid_min; + u8 T42_reportid_max; u16 T44_address; u8 T48_reportid; u8 T100_reportid_min; @@ -979,6 +984,17 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) data->update_input = true; } +static void mxt_proc_t42_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + if (status & MXT_T42_MSG_TCHSUP) + dev_dbg(dev, "T42 suppress\n"); + else + dev_dbg(dev, "T42 normal\n"); +} + static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) { struct device *dev = &data->client->dev; @@ -1006,6 +1022,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (report_id == data->T6_reportid) { mxt_proc_t6_messages(data, message); + } else if (report_id >= data->T42_reportid_min + && report_id <= data->T42_reportid_max) { + mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); } else if (!data->input_dev) { @@ -1686,6 +1705,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T9_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T42_reportid_min = 0; + data->T42_reportid_max = 0; data->T44_address = 0; data->T48_reportid = 0; data->T100_reportid_min = 0; @@ -1763,6 +1784,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_PROCI_TOUCHSUPPRESSION_T42: + data->T42_reportid_min = min_id; + data->T42_reportid_max = max_id; + break; case MXT_SPT_MESSAGECOUNT_T44: data->T44_address = object->start_address; break; From patchwork Tue Sep 17 09:35:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148389 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 2D85714DB for ; Tue, 17 Sep 2019 09:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1553021881 for ; Tue, 17 Sep 2019 09:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbfIQJgP (ORCPT ); Tue, 17 Sep 2019 05:36:15 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgO (ORCPT ); Tue, 17 Sep 2019 05:36:14 -0400 IronPort-SDR: 040SLHFMXizPPE3raU6D5tdCBTqn+ZYF30GMqexFf/zIkEtC8kEGO+ik4w+oT5JRbl5ktuZYJm hc4aQd3Wd/ynhQr646QpeS/bRGHNHsh3BV/e0WjGdAU/X7OpSs18u7IkZljYJPMFplxtdbfzmL 4Y/HhzfuXO+Y7mDsT1KBGySVbAWBXKIHu24yuM/fs+emvz0caU8qV0pKlXo+wiXlf7W2BOIFj+ 0Vc9SL9t7tUOBoJbVSCLAULyuigvdlfomBN5MW9ZGqP2u9+HYyR32YfXv1fa57i48UfBYFRuMp dsY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423005" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:13 -0800 IronPort-SDR: 1tTdPTZblhLE6y7s3cfBapsfQzNQROoIXCJbiThNm652YmXbr75puFDVcYzOdbewCF6nrvxFKY 4Tjo9/lUuAutluSUMP2kB8LxmCMuISzuchX4oC++vWO2Pxihwrr8ut3wqQa8EfC9X6nFENBR2P p6MLPF1grllpIe/Nox+KoAIZH6uLMSS7WipU93KvWFLa1t/4vDn18owuuj54ml4okU6wv6m6iz O86P9MuGwE3+NsOgIto6GJsnFhOnLDJr6kkkjQlLGmcDlPgvgO7fAVE5iZuNyAVo+Pz4jBI7Mx T/A= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 08/49] Input: atmel_mxt_ts - implement T9 vector/orientation support Date: Tue, 17 Sep 2019 18:35:09 +0900 Message-ID: <20190917093550.18335-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093550.18335-1-jiada_wang@mentor.com> References: <20190917093550.18335-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 19fa3e58269a..68c8237f7932 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 Tue Sep 17 09:35:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148393 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 978B8912 for ; Tue, 17 Sep 2019 09:36:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76DC521881 for ; Tue, 17 Sep 2019 09:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726500AbfIQJgT (ORCPT ); Tue, 17 Sep 2019 05:36:19 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:21929 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJgT (ORCPT ); Tue, 17 Sep 2019 05:36:19 -0400 IronPort-SDR: ZU7hZT/XlFkTD73BZmZTw9pOUanTclQ7hx2mpO2xH7Y/AcsFwPZzT6921jLyomyoC5vNELzrP/ gKvBW6utXla4AEMnCBvDmXLra8bQO19LKKg8wgNXGR8I2nsZoFCWp/XRYoAUJdFu+ccp1k2Noz fR0jXmABe9aBbLzk/oZFMAahk8WdD3uU5H9ZP4mRlTOx9bphGyTPRx0JRk6XLPm5kl+HEmFocy lhgSVq18HNQ/vf0/79JvOsdUDOYrGSXVS768X2hf68UqN1KMXBs03z8MsuT0OF8a0IpgKgSVOl Gqc= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423010" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:36:17 -0800 IronPort-SDR: MhsUm4a3r3MNoHUr5zjo2adJYdu7Ztk7NT9C7+mYec+8VkwRjwR/+qrE/vICigIYYBd8GIxhRR MSo/TWa7umnV5G/2uKbZ04L28Cct70dnufeiFWQTwpQGfQrCY9X6hUIiXzGFV48I4GyNq2JMA8 h4//qOULV9/05f1z8C1psKedUBZfAVRgyNBS8b6P4JJFGhchgDe6y0CJnvSW+tdNLfaOSxVFpm owef5Vni+BpeyAQ1WgtZ2DXlUhzcSX6rqz8JiWonjSMdNKDqf3x+Rdks8kg0U6Cgy6y/5vBhLZ UZQ= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 09/49] Input: atmel_mxt_ts - implement T15 Key Array support Date: Tue, 17 Sep 2019 18:35:10 +0900 Message-ID: <20190917093550.18335-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093550.18335-1-jiada_wang@mentor.com> References: <20190917093550.18335-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 68c8237f7932..1d738c488bdd 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; @@ -3180,6 +3238,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 Tue Sep 17 09:36:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148395 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 7F0C8912 for ; Tue, 17 Sep 2019 09:37:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67DAB21881 for ; Tue, 17 Sep 2019 09:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbfIQJhf (ORCPT ); Tue, 17 Sep 2019 05:37:35 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22003 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJhe (ORCPT ); Tue, 17 Sep 2019 05:37:34 -0400 IronPort-SDR: f81VCh94+u1ugFEew6iX4wP8U6bALzCxW/hkhAzv8Px5H8AJbLOUXI4OBPKX3OiCA2sm7MKE6p QEpgzmFWM1FIqx3VuJu4dBRE34Sw90LWxDYKyqkI5IXF8Jk4ot685aCjac/NDmDMlQLBN7hVbq KvVh4UTDJ8L4dbx5CHH7SVweoSZmzA6zPXwy0XETCKRaHT50TtIB/8i0VKs4DUR/ejDgV2uJym KXfqiYed+MF9wNlDWSzheFRHlWKZKEhybHWO2v9C9bwsmFnElruLI6180pb1tKDfDAWD+In/Lm mVU= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423042" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:37:34 -0800 IronPort-SDR: ajMO0UBwfGU5rRvIM7SrBpNJ4gw2stQjAb4qHqNkvAgIeg6/nGFfHl8pxSpRtcs21ZcO7P+YTp 0GHW5eYexeyXvnQAwoOIo90PtIBHUlojUJkX1+tJO+zbWrhvTy1CLULFKCG96Kmfs/A1QMJFF7 y0XVbMJEQTRmuBTIPtanSNS5j/KA1wCDhW3xSo3HFeFfbPhrmA+rbiK10+knKA1GuKich9pQT0 C8LUF7FYWAAaRZYAnxqwBZE4wz0FZuFTA0Dr5bqvBM1BR+yrq5DpOxll2aiw59N2DVnY+WiGaJ mjU= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 10/49] Input: atmel_mxt_ts - handle reports from T47 Stylus object Date: Tue, 17 Sep 2019 18:36:25 +0900 Message-ID: <20190917093704.18439-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 1d738c488bdd..83dad225458e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -823,6 +823,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) int area; int amplitude; u8 vector; + int tool; id = message[0] - data->T9_reportid_min; status = message[1]; @@ -836,6 +837,7 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) y >>= 2; area = message[5]; + amplitude = message[6]; vector = message[7]; @@ -865,12 +867,20 @@ static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) mxt_input_sync(data); } + /* A size of zero indicates touch is from a linked T47 Stylus */ + if (area == 0) { + area = MXT_TOUCH_MAJOR_DEFAULT; + tool = MT_TOOL_PEN; + } else { + tool = MT_TOOL_FINGER; + } + /* if active, pressure must be non-zero */ if (!amplitude) amplitude = MXT_PRESSURE_DEFAULT; /* Touch active */ - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); + input_mt_report_slot_state(input_dev, tool, 1); input_report_abs(input_dev, ABS_MT_POSITION_X, x); input_report_abs(input_dev, ABS_MT_POSITION_Y, y); input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); From patchwork Tue Sep 17 09:36:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148397 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 CEFDB912 for ; Tue, 17 Sep 2019 09:37:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADA9A20862 for ; Tue, 17 Sep 2019 09:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728156AbfIQJhj (ORCPT ); Tue, 17 Sep 2019 05:37:39 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22003 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJhi (ORCPT ); Tue, 17 Sep 2019 05:37:38 -0400 IronPort-SDR: oULJnbfc3Hcc1mVdS2wodMGu7pQmO/xyiA6sWEz/DDhlbY5RffVWz5uAGzOpySnP/okNqNkQWb yU+ZKZMowzlj7xsxE8df3J1D9rcW12h4qjNWO9J77KUjiraHtnN8EyLaEj9g+oOBU0/qFu2fEA J1L13TQA0H91IA2hb/1PmX4cti+sQAkxu+7NBUNUf8/DQ1xODO1KVWlNoot3/zrl5tbUErU5R/ axYOjk2yF4YY/dB5sJojuxo9IQEmUJKK4fGOYfdY2vD9ed7/jKubRTAFwGmgoTMjDD+K9vYoq9 vLE= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423045" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:37:37 -0800 IronPort-SDR: BnU0sQOUIPYPx59QmJhlpR0ml4M9TiMEJEhl02q/vQbmPk3o3MIuVJaBLDwAAWXoUHRGlY98gI 3uwHxPGG/Vy8hQ6eLbLWkWqQ4LZgCiQbdYAye6X3wcdagZJLSKEDe5GbkXsoeFGWRpzWuEcN8h RFJpregdsUKZ53WQgRTA8gDxUYnsFzC5/5MCR/AX39wHeaMvGqXmuHW8cFFOYXuOaOiCTtb+zT J9Swnr239VAwdfWdcU2ez4pLfTr8TPgS4ZOmhFP7U0WSH3cD1D9ECQc31S/0SCJw9ODUqKXO5w tpw= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 11/49] Input: atmel_mxt_ts - implement support for T107 active stylus Date: Tue, 17 Sep 2019 18:36:26 +0900 Message-ID: <20190917093704.18439-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093704.18439-1-jiada_wang@mentor.com> References: <20190917093704.18439-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 83dad225458e..4e237209cb34 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -72,6 +72,7 @@ #define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71 71 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 +#define MXT_PROCI_ACTIVESTYLUS_T107 107 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -181,6 +182,7 @@ struct t37_debug { enum t100_type { MXT_T100_TYPE_FINGER = 1, MXT_T100_TYPE_PASSIVE_STYLUS = 2, + MXT_T100_TYPE_ACTIVE_STYLUS = 3, MXT_T100_TYPE_HOVERING_FINGER = 4, MXT_T100_TYPE_GLOVE = 5, MXT_T100_TYPE_LARGE_TOUCH = 6, @@ -192,6 +194,16 @@ enum t100_type { #define MXT_TOUCH_MAJOR_DEFAULT 1 #define MXT_PRESSURE_DEFAULT 1 +/* Gen2 Active Stylus */ +#define MXT_T107_STYLUS_STYAUX 42 +#define MXT_T107_STYLUS_STYAUX_PRESSURE BIT(0) +#define MXT_T107_STYLUS_STYAUX_PEAK BIT(4) + +#define MXT_T107_STYLUS_HOVER BIT(0) +#define MXT_T107_STYLUS_TIPSWITCH BIT(1) +#define MXT_T107_STYLUS_BUTTON0 BIT(2) +#define MXT_T107_STYLUS_BUTTON1 BIT(3) + /* Delay times */ #define MXT_BACKUP_TIME 50 /* msec */ #define MXT_RESET_GPIO_TIME 20 /* msec */ @@ -313,10 +325,12 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; - bool use_retrigen_workaround; unsigned long t15_keystatus; int t15_num_keys; const unsigned int *t15_keymap; + u8 stylus_aux_pressure; + u8 stylus_aux_peak; + bool use_retrigen_workaround; /* Cached parameters from object table */ u16 T5_address; @@ -337,6 +351,7 @@ struct mxt_data { u8 T48_reportid; u8 T100_reportid_min; u8 T100_reportid_max; + u16 T107_address; /* for fw update in bootloader */ struct completion bl_completion; @@ -908,6 +923,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) u8 major = 0; u8 pressure = 0; u8 orientation = 0; + bool active = false; + bool hover = false; id = message[0] - data->T100_reportid_min - 2; @@ -926,6 +943,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_HOVERING_FINGER: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_HOVERING; + hover = true; + active = true; if (data->t100_aux_vect) orientation = message[data->t100_aux_vect]; @@ -936,6 +955,8 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_GLOVE: tool = MT_TOOL_FINGER; distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; if (data->t100_aux_area) major = message[data->t100_aux_area]; @@ -950,6 +971,9 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) case MXT_T100_TYPE_PASSIVE_STYLUS: tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + hover = false; + active = true; /* * Passive stylus is reported with size zero so @@ -962,6 +986,31 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) break; + case MXT_T100_TYPE_ACTIVE_STYLUS: + /* Report input buttons */ + input_report_key(input_dev, BTN_STYLUS, + message[6] & MXT_T107_STYLUS_BUTTON0); + input_report_key(input_dev, BTN_STYLUS2, + message[6] & MXT_T107_STYLUS_BUTTON1); + + /* stylus in range, but position unavailable */ + if (!(message[6] & MXT_T107_STYLUS_HOVER)) + break; + + tool = MT_TOOL_PEN; + distance = MXT_DISTANCE_ACTIVE_TOUCH; + active = true; + major = MXT_TOUCH_MAJOR_DEFAULT; + + if (!(message[6] & MXT_T107_STYLUS_TIPSWITCH)) { + hover = true; + distance = MXT_DISTANCE_HOVERING; + } else if (data->stylus_aux_pressure) { + pressure = message[data->stylus_aux_pressure]; + } + + break; + case MXT_T100_TYPE_LARGE_TOUCH: /* Ignore suppressed touch */ break; @@ -976,12 +1025,12 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) * Values reported should be non-zero if tool is touching the * device */ - if (!pressure && type != MXT_T100_TYPE_HOVERING_FINGER) + if (!pressure && !hover) pressure = MXT_PRESSURE_DEFAULT; input_mt_slot(input_dev, id); - if (status & MXT_T100_DETECT) { + if (active) { dev_dbg(dev, "[%u] type:%u x:%u y:%u a:%02X p:%02X v:%02X\n", id, type, x, y, major, pressure, orientation); @@ -992,6 +1041,7 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); input_report_abs(input_dev, ABS_MT_DISTANCE, distance); input_report_abs(input_dev, ABS_MT_ORIENTATION, orientation); + } else { dev_dbg(dev, "[%u] release\n", id); @@ -1863,6 +1913,9 @@ static int mxt_parse_object_table(struct mxt_data *data, /* first two report IDs reserved */ data->num_touchids = object->num_report_ids - 2; break; + case MXT_PROCI_ACTIVESTYLUS_T107: + data->T107_address = object->start_address; + break; } end_address = object->start_address @@ -2023,6 +2076,54 @@ static int mxt_read_t9_resolution(struct mxt_data *data) return 0; } +static int mxt_set_up_active_stylus(struct input_dev *input_dev, + struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + struct mxt_object *object; + u8 styaux; + int aux; + u8 ctrl; + + object = mxt_get_object(data, MXT_PROCI_ACTIVESTYLUS_T107); + if (!object) + return 0; + + error = __mxt_read_reg(client, object->start_address, 1, &ctrl); + if (error) + return error; + + /* Check enable bit */ + if (!(ctrl & 0x01)) + return 0; + + error = __mxt_read_reg(client, + object->start_address + MXT_T107_STYLUS_STYAUX, + 1, &styaux); + if (error) + return error; + + /* map aux bits */ + aux = 7; + + if (styaux & MXT_T107_STYLUS_STYAUX_PRESSURE) + data->stylus_aux_pressure = aux++; + + if (styaux & MXT_T107_STYLUS_STYAUX_PEAK) + data->stylus_aux_peak = aux++; + + input_set_capability(input_dev, EV_KEY, BTN_STYLUS); + input_set_capability(input_dev, EV_KEY, BTN_STYLUS2); + input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); + + dev_dbg(&client->dev, + "T107 active stylus, aux map pressure:%u peak:%u\n", + data->stylus_aux_pressure, data->stylus_aux_peak); + + return 0; +} + static int mxt_read_t100_config(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2229,7 +2330,7 @@ static int mxt_initialize_input_device(struct mxt_data *data) if (data->multitouch == MXT_TOUCH_MULTI_T9 || (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && - data->t100_aux_ampl)) { + (data->t100_aux_ampl || data->stylus_aux_pressure))) { input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); } @@ -2247,6 +2348,14 @@ static int mxt_initialize_input_device(struct mxt_data *data) 0, 255, 0, 0); } + /* For T107 Active Stylus */ + if (data->multitouch == MXT_TOUCH_MULTITOUCHSCREEN_T100 && + data->T107_address) { + error = mxt_set_up_active_stylus(input_dev, data); + if (error) + dev_warn(dev, "Failed to read T107 config\n"); + } + /* For T15 Key Array */ if (data->T15_reportid_min) { data->t15_keystatus = 0; From patchwork Tue Sep 17 09:36:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148403 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 B3DE217E6 for ; Tue, 17 Sep 2019 09:37:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92F0B21881 for ; Tue, 17 Sep 2019 09:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbfIQJhm (ORCPT ); Tue, 17 Sep 2019 05:37:42 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22003 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJhl (ORCPT ); Tue, 17 Sep 2019 05:37:41 -0400 IronPort-SDR: xw17gOPBiFqvq51peR38c4D+4STpjjEzAN/q5hoJ5FjZ1ZyL8sqynAbswPqt6jd5lAjicQ9dPC 4aFIJvIWbtspflNK7PaROiR6ULWI8Idogsuj2KizvwFm4RCR/I/qeDkPGAMpYw3YBZ8gtAQYjV DSi9G3IGg1eaTv0toH/J1ZWEYTaUHwZ6T2eqAU0BsZXuoM+gKmkoTPuNo8c8tkSMO2I7FXtUNY 0wwsM5Wo3bkQsKj6C+KviOL97BxLEfot5CQDr8qe11Z57T0/cqu+AC3AsMQemjQOPkvE913A2I Fp0= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423047" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:37:41 -0800 IronPort-SDR: lZRSJXgwfl7bIR9I5AdH3O2eDjCefzPacpTx0e0QikldvRpAVOI2dnwjgKPKbz/otfK8IlAs7Z HYJ07f8SYfbX/M7dtpZIQ//okW9512EHJ7VP1smWCXIL+6XD57Xoek98L/R7VnSy98KJMCwY0H 3+AtH4TCXoL27AeSS8eTDi3udwoO1gi8CHun4OI4q167okO7TyusY5SivPU0vq11phjtjZacPf FZ3sZ38/a0nQAb5n2MGZ43gbdgFU9bsWFsUAp5nytX9dE6mue2XFd6THMI67Q80Yl36RFH4LJW NGo= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 12/49] Input: atmel_mxt_ts - add debug for T92 gesture and T93 touch seq msgs Date: Tue, 17 Sep 2019 18:36:27 +0900 Message-ID: <20190917093704.18439-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093704.18439-1-jiada_wang@mentor.com> References: <20190917093704.18439-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Karl Tsou output T92 gesture and T93 touch sequence messages. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit cb98986f8342107bf4a536aed4160b20839e97c1) Signed-off-by: George G. Davis 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 4e237209cb34..9dae1c2dd9d9 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_debug(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_debug(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 Tue Sep 17 09:36:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148399 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 93B39912 for ; Tue, 17 Sep 2019 09:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71B7121881 for ; Tue, 17 Sep 2019 09:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728231AbfIQJhp (ORCPT ); Tue, 17 Sep 2019 05:37:45 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22003 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJhp (ORCPT ); Tue, 17 Sep 2019 05:37:45 -0400 IronPort-SDR: wr18YouDz7Re/+PQopFVlU7B3QEae4tUE+bfAWs9Ef4oqrvc93dLDB+6th1TwDuM+0d40l/NSu RVhQSw1AwJfKJ1VE+Ont2dxxHMe5o7I2lcd6LBT8wFo9KmEx2N1cYsA/VVHhYdi5G1Mc6sVoRM 8RF9LAhikeR31vaukboneXl4x4Unr1bK6UHGv8euDPvIDl5ue6m7ja3YxnllhCAK9Lo2n0h7ou 0UjlfirN4Bx9Erw7CYAi06MWar7ly1vM21Ja2do9A3N8awwwUd8YuBia4fXk62ueqNtAmOUprc epA= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423049" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:37:44 -0800 IronPort-SDR: bW9zARLfC4VtpkTPsQmeYP72+/xC617BnjeNFZ7nRNio36OWLbF9n8szpuP4sBvtvoLvyS/FZu dSSAl/UjpGkI9IYs4PqZMZuvSZiafBwRJa/Y6lK4hR4G54df9aoL5aGnxLT8ltbee7pbQ0jaDc GJHP9onjJGttaLR1FdZcbW1yhTegcmt39TFEOvMfNvhm1hjPkI8xqRRj0tMaCx2Ntb5QQ0WwX0 VA9fypK5abe3NaX2fzMDXL3c5RHmzHEI0AvMNNcrvgIeUdhO/6I2nCCGL7IhVZtgCI/GsKaguJ nDQ= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 13/49] Input: atmel_mxt_ts - release touch state during suspend Date: Tue, 17 Sep 2019 18:36:28 +0900 Message-ID: <20190917093704.18439-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093704.18439-1-jiada_wang@mentor.com> References: <20190917093704.18439-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer If fingers are down as the MXT chip goes into suspend it does not send a lift message. In addition, it may not complete its final measurement cycle immediately, which means touch messages may be received by the interrupt handler after mxt_stop() has completed. So: - disable irq during suspend - flush any messages created after suspend - tell app layer that slots were released at suspend Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 26794433086dbc7dea18d2f6a1c8d61ab25bcfda) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fix from Dirk Behme: - Input: atmel_mxt_ts - remove superfluous data->suspended] Signed-off-by: Dirk Behme --- Notes: - Squash fix from Dirk Behme: + Input: atmel_mxt_ts - remove superfluous data->suspended data->suspended is already set to false in mxt_load_fw(), so it's not needed here. Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 52 ++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 9dae1c2dd9d9..062383c3616a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -372,6 +372,9 @@ struct mxt_data { unsigned int t19_num_keys; enum mxt_suspend_mode suspend_mode; + + /* Indicates whether device is in suspend */ + bool suspended; }; struct mxt_vb2_buffer { @@ -1151,10 +1154,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) mxt_proc_t42_messages(data, message); } else if (report_id == data->T48_reportid) { mxt_proc_t48_messages(data, message); - } else if (!data->input_dev) { + } else if (!data->input_dev || data->suspended) { /* - * Do not report events if input device - * is not yet registered. + * Do not report events if input device is not + * yet registered or returning from suspend */ mxt_dump_message(data, message); } else if (report_id >= data->T9_reportid_min && @@ -3135,6 +3138,11 @@ static int mxt_load_fw(struct device *dev, const char *fn) if (ret) goto release_firmware; + if (data->suspended) { + enable_irq(data->irq); + data->suspended = false; + } + if (!data->in_bootloader) { /* Change to the bootloader mode */ data->in_bootloader = true; @@ -3306,8 +3314,27 @@ static void mxt_sysfs_remove(struct mxt_data *data) sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); } +static void mxt_reset_slots(struct mxt_data *data) +{ + struct input_dev *input_dev = data->input_dev; + int id; + + if (!input_dev) + return; + + for (id = 0; id < data->num_touchids; id++) { + input_mt_slot(input_dev, id); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + } + + mxt_input_sync(data); +} + static void mxt_start(struct mxt_data *data) { + if (!data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: mxt_soft_reset(data); @@ -3320,16 +3347,29 @@ static void mxt_start(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + /* + * Discard any touch messages still in message buffer + * from before chip went to sleep + */ + mxt_process_messages_until_invalid(data); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); /* Recalibrate since chip has been in deep sleep */ mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + + mxt_acquire_irq(data); break; } + + data->suspended = false; } static void mxt_stop(struct mxt_data *data) { + if (data->suspended || data->in_bootloader) + return; + switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ @@ -3339,9 +3379,15 @@ static void mxt_stop(struct mxt_data *data) case MXT_SUSPEND_DEEP_SLEEP: default: + disable_irq(data->irq); + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + + mxt_reset_slots(data); break; } + + data->suspended = true; } static int mxt_input_open(struct input_dev *dev) From patchwork Tue Sep 17 09:36:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148401 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 89C6D14DB for ; Tue, 17 Sep 2019 09:37:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5EBA921881 for ; Tue, 17 Sep 2019 09:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728254AbfIQJht (ORCPT ); Tue, 17 Sep 2019 05:37:49 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22003 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbfIQJhs (ORCPT ); Tue, 17 Sep 2019 05:37:48 -0400 IronPort-SDR: PvXUkgwiwa2aBVLauuiU0yDI7KE2KpPqwBuQmCr/HT01JyAFJ2i7Yl7cZ+cWfUG36vzcA34fg9 A0IaWbs/jPs6V86Iq+MXL3EJZHUdEeaJOHBRN3mKa2JKpV90mo8K7UfRBGK3NCvWTIIyowOZyh zdjvkD4qyun0axMOegEN9aEv36UULmSgPUeb4bbXdgBfxyMORvxoRbUt+ja4N3QxSVmcr87np0 EUiDWjynaIpT7SZUSZPEy3LQ3vIItAx5c5uOtHQcLeLuOAV0XSJQNqi/wrJcE64uHcgazzi5DQ NcQ= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423052" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:37:47 -0800 IronPort-SDR: GAbiok28FbaVxWvhAsF7wMPn7YFM/RAn53JrMjJkPInONmls7Dk3Yc0EovTpnIvraP/kkr2vb4 LA1KvvLswuUuKjT/YgvLKn1mT6zlImwX7zk9JoJm7lSdh98iPsHz86Lokpk+C6sLpam9Me8vqt g1Rox/nVrx4Dndhg4Z2FjuIm9cWO95MNutF7Mf2+mx9m4k3wRmoz3+GZ7VW+gkUTz09TkLU6zA 2j6kl7bCR1b+aF19W6fajIs7H1gHZANVG+Sw82l8d2ncIAw2emA86aUZuW5SbGCRePcxREOIL+ GpY= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 14/49] Input: atmel_mxt_ts - add regulator control support Date: Tue, 17 Sep 2019 18:36:29 +0900 Message-ID: <20190917093704.18439-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093704.18439-1-jiada_wang@mentor.com> References: <20190917093704.18439-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-09.mgc.mentorg.com (147.34.90.209) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Allow the driver to optionally manage enabling/disable power to the touch controller itself. If the regulators are not present then use the deep sleep power mode instead. For a correct power on sequence, it is required that we have control over the RESET line. Signed-off-by: Nick Dyer Acked-by: Benson Leung Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 14052b61bb66c2f2283c00e733e131be7a9b8bfc) [gdavis: Resolve forward port conflicts due to v4.14-rc1 commmit f657b00df22e ("Input: atmel_mxt_ts - add support for reset line") and applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fixes from Dirk Behme: - Input: atmel_mxt_ts - in failure case disable the regulator - Input: atmel_mxt_ts - disable only enabled regulators - Input: atmel_mxt_ts - use devm_regulator_get()] Signed-off-by: Dirk Behme --- Notes: - Squash fixes by Dirk Behme: + Input: atmel_mxt_ts - in failure case disable the regulator If the second regulator_enable(), disable the previously enabled regulator, again. + Input: atmel_mxt_ts - disable only enabled regulators As enabling the regulators in mxt_regulator_enable() might fail, check if the regulators are really enabled and disable them only in this case. + Input: atmel_mxt_ts - use devm_regulator_get() Switch to devm_regulator_get() enabling us to drop the regulator_put() in the remove function. [jiada: Resolve forward port conflicts due to commit 5cecc2bccc03f ("Input: atmel_mxt_ts - fix -Wunused-const-variable")] Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 6 + MAINTAINERS | 1 + drivers/input/touchscreen/atmel_mxt_ts.c | 129 ++++++++++++++++-- include/dt-bindings/input/atmel_mxt_ts.h | 22 +++ 4 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 include/dt-bindings/input/atmel_mxt_ts.h diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index c88919480d37..e28139ce3cae 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -31,6 +31,12 @@ Optional properties for main touchpad device: - reset-gpios: GPIO specifier for the touchscreen's reset pin (active low) +- atmel,suspend-mode: Select method used to suspend: + MXT_SUSPEND_DEEP_SLEEP - use T7 to suspend the device into deep sleep + MXT_SUSPEND_T9_CTRL - use T9.CTRL to turn off touch processing + MXT_SUSPEND_REGULATOR - use regulators to power down device during suspend + Definitions are in . + Example: touch@4b { diff --git a/MAINTAINERS b/MAINTAINERS index 47800d32cfbc..1509bb9072fc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2777,6 +2777,7 @@ T: git git://github.com/ndyer/linux.git S: Maintained F: Documentation/devicetree/bindings/input/atmel,maxtouch.txt F: drivers/input/touchscreen/atmel_mxt_ts.c +F: include/dt-bindings/input/atmel_mxt_ts.h ATMEL WIRELESS DRIVER M: Simon Kelley diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 062383c3616a..25ac42967bc7 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); @@ -3470,6 +3576,7 @@ static int mxt_parse_device_properties(struct mxt_data *data) data->t15_num_keys = n_keys; } + device_property_read_u32(dev, "atmel,suspend-mode", &data->suspend_mode); return 0; } @@ -3556,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; diff --git a/include/dt-bindings/input/atmel_mxt_ts.h b/include/dt-bindings/input/atmel_mxt_ts.h new file mode 100644 index 000000000000..e4c4c0f6fa37 --- /dev/null +++ b/include/dt-bindings/input/atmel_mxt_ts.h @@ -0,0 +1,22 @@ +/* + * Atmel maXTouch Touchscreen driver + * + * Copyright (C) 2015 Atmel Corporation + * Author: Nick Dyer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#ifndef __DT_BINDINGS_ATMEL_MXT_TS_H +#define __DT_BINDINGS_ATMEL_MXT_TS_H + +enum mxt_suspend_mode { + MXT_SUSPEND_DEEP_SLEEP = 0, + MXT_SUSPEND_T9_CTRL = 1, + MXT_SUSPEND_REGULATOR = 2, +}; + +#endif /* __DT_BINDINGS_ATMEL_MXT_TS_H */ From patchwork Tue Sep 17 09:37:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148413 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 D3A9914DB for ; Tue, 17 Sep 2019 09:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC6232189D for ; Tue, 17 Sep 2019 09:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbfIQJiw (ORCPT ); Tue, 17 Sep 2019 05:38:52 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59351 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726250AbfIQJiw (ORCPT ); Tue, 17 Sep 2019 05:38:52 -0400 IronPort-SDR: aSRxolACfm3VuJWVLSNYsRHYqp6PgPBA3gWRRUXtGy8xEc+qPLU2AKFxC5LyQG68+h60C6WMYO 39T5PRdQNCuzBfaEB32Tt3bIWsXAqNL2Bv0NXxIJEmifV3ru3hi34kj1Te6ViUsZI0DwQn9Alv bG+m8ap1AHiM/VRYyxKFfzbjs7F/ZvuPRkwJLK0IhlP5WLddiraiLY0qRJ3JksSaojq/ACKNKL wKAuYuvuUobnpx15qxKgUGMT6hEcgcs0bM1ZonfwOCrEoPVx6hbafEPcSv4ITMMu68UzAbFtGN JEw= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223063" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:38:50 -0800 IronPort-SDR: nhOAf4W6trN3hckbU1s1OdvyB4LlMTntwmC1h2i5OTcrr5TmMlSTLY3S7nd8Hehcz3gdegFwb7 Chzk9mHZMJq8FhTDcgd/MryDLdFjXu8WQMZwOfltps3z4Q32jeHSkkXNwAdlUPalRSPC3WIP1E WBeHnGbTAigiElPkbxEw2VSY2jFOiadgXZsMAI5AIenr/rU4i0UDbaT/98xyFHbLBzImfNPNyZ pmREYPYuFoKDmN9ZUQq4JW1GhI3DvNA0zv6wqbeUpWxfngFHaldn6IQKrrfka/S941zDMbAwfK 0jM= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 15/49] Input: atmel_mxt_ts - report failures in suspend/resume Date: Tue, 17 Sep 2019 18:37:32 +0900 Message-ID: <20190917093806.18538-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 93a57575403de4dd07cd64807d3c2ed7f2cca262) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Fix compilation warning] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 51 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 25ac42967bc7..4615e1591af4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3425,10 +3425,12 @@ static void mxt_reset_slots(struct mxt_data *data) mxt_input_sync(data); } -static void mxt_start(struct mxt_data *data) +static int mxt_start(struct mxt_data *data) { + int ret = 0; + if (!data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -3453,28 +3455,42 @@ static void mxt_start(struct mxt_data *data) */ mxt_process_messages_until_invalid(data); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + if (ret) + return ret; /* Recalibrate since chip has been in deep sleep */ - mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + ret = mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); + if (ret) + return ret; + + ret = mxt_acquire_irq(data); + if (ret) + return ret; - mxt_acquire_irq(data); break; } data->suspended = false; + + return 0; } -static void mxt_stop(struct mxt_data *data) +static int mxt_stop(struct mxt_data *data) { + int ret; + if (data->suspended || data->in_bootloader) - return; + return 0; switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: /* Touch disable */ - mxt_write_object(data, + ret = mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0); + if (ret) + return ret; + break; case MXT_SUSPEND_REGULATOR: @@ -3487,29 +3503,40 @@ static void mxt_stop(struct mxt_data *data) default: disable_irq(data->irq); - mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_DEEPSLEEP); + if (ret) + return ret; mxt_reset_slots(data); break; } data->suspended = true; + return 0; } static int mxt_input_open(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_start(data); + ret = mxt_start(data); - return 0; + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); + + return ret; } static void mxt_input_close(struct input_dev *dev) { struct mxt_data *data = input_get_drvdata(dev); + int ret; - mxt_stop(data); + ret = mxt_stop(data); + + if (ret) + dev_err(&data->client->dev, "%s failed rc=%d\n", __func__, ret); } static int mxt_parse_device_properties(struct mxt_data *data) From patchwork Tue Sep 17 09:37:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148405 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 442C7912 for ; Tue, 17 Sep 2019 09:39:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C16821897 for ; Tue, 17 Sep 2019 09:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728380AbfIQJiz (ORCPT ); Tue, 17 Sep 2019 05:38:55 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59351 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbfIQJiy (ORCPT ); Tue, 17 Sep 2019 05:38:54 -0400 IronPort-SDR: 1v/SOyKWouEet+j1RHHuwTvyJ5OHSPCJgF9bzA/h32igYmWg4ksfkwM1GL8YCOS9ZpQ/ghrccX VjmdWInMT/Qc2dfCIAPMajrYy9h8BbEfeZd3Nd4r347XeWkBcTVctw3qSULJbc8KH1Nj8uxu6Y bZ6Nu3rtZeXjv05rhCIcfn9pwSgkCS1YsKKHaZcsJkeN4L8V1G+e7hcif2//3JzFbwTES3d4Q7 Xhrd612PB+xOW9LzgdIYUU0rPB1/4W2jIIu4FVaCTEjYIyfn5wkqs7I13aV/bEj8IjJwrDRcPU BTI= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223066" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:38:52 -0800 IronPort-SDR: 8Ovh2+BVe04+1OF6RsHNcPKmu6SSg7yaL2vQO/8w51ESltC6jxEix6KyDO9pInSyXFt60grZyr r5CcTsqEDz43TfNPh45oHYfQ9XXEu+9056HFKfxXEjHWNyX6GvS5283KES5VwQLloPip7pkmBb ZVt3pZIbutGpcvacyr4hv1xRSJyf6KSLUxA+P8o/YPTMWHfoKss97TJVDAcu9/chfcuWM9haa/ 1HeBNZQmxjomPks4KZwy+7bXQ7Y2zV7zg0lz+j0n1ClF0PkyQkbL1TrNF+dx+YuwXVMy6rtH8c fmY= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 16/49] Input: atmel_mxt_ts - allow specification of firmware file name Date: Tue, 17 Sep 2019 18:37:33 +0900 Message-ID: <20190917093806.18538-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093806.18538-1-jiada_wang@mentor.com> References: <20190917093806.18538-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer On 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 4615e1591af4..8d898855923e 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 Tue Sep 17 09:37:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148411 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 DD687912 for ; Tue, 17 Sep 2019 09:39:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA7DF2189D for ; Tue, 17 Sep 2019 09:39:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727358AbfIQJi7 (ORCPT ); Tue, 17 Sep 2019 05:38:59 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59351 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbfIQJi6 (ORCPT ); Tue, 17 Sep 2019 05:38:58 -0400 IronPort-SDR: jeOSbVjPysXBgAy0Wb/G4l+fzIuyLOmW1mALhP4phJQgvGyAuqVcGIozyKNwxtvOQunfg0g/wP xbCtARFdkAbQlx5decGM+6uv+LuiZGuJYDJYMlhV3QLwyBX9ZAy3od060fQ7JE9Uf6DhoCNNiH nhkfXDyNReQteB+PE/2h2cJrzZiFVDpbYlfO7uMC28BGJtI9lciAbOzu5v3Kf8CCCk9xt41nxQ 5e7qiFfLV00ua/itLv6RlEsdyxcYsVA7clpWLF3HaiQ500TffWO6ArY4/vSOhdXD8QNG7ZM111 ENI= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223071" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:38:57 -0800 IronPort-SDR: pMsnnNzEHzuvSq8OmfGqWqnOptjaPjWSuft3A1upUsNolAlUFKjZS34fC+nQZj04btSJdh3ntP uRBZQCloLcspeySVGgG824b2HfR+g9o+2WKz5J5TDdA9OgzOZICfbnchFF+BSfwkmXOW/pjZWG hny8AftLQRWjp0TB169Wwbot4z+9PtIWuRddWigdqsuecgD0Q21BovlYuIuYYD2Oq1oBbacVR+ +pLnmxlRiEqHsQ3g3Z4D48zkDzGRfKSYYzW2hMA8OCwuUE+jeId+mWOnk0pRd8Ht/1O5N4HsPJ ZEo= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 17/49] Input: atmel_mxt_ts - handle cfg filename via pdata/sysfs Date: Tue, 17 Sep 2019 18:37:34 +0900 Message-ID: <20190917093806.18538-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093806.18538-1-jiada_wang@mentor.com> References: <20190917093806.18538-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer There may be multiple maXTouch chips on a single device which will require different configuration files. Add a platform data value for the configuration filename. Add sysfs entry to write configuration file if the platform data is not set. Split out the object initialisation code from mxt_initialize() into mxt_configure_objects() to allow this. Signed-off-by: Nick Dyer Acked-by: Yufeng Shen (cherry picked from ndyer/linux/for-upstream commit 71a2a4d1954460b949a16b607f72bafab294ca79) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [gdavis: Squash fix from Vladimir Zapolskiy: - Input: atmel_mxt_ts - fix error paths in mxt_configure_objects()] Signed-off-by: Vladimir Zapolskiy --- Notes: - Squash fix from Vladimir Zapolskiy: + Input: atmel_mxt_ts - fix error paths in mxt_configure_objects() Fail in mxt_update_cfg() is critical, because the driver state machine is broken and it can not be safely used afterwards. [jiada: Squash fix from ndyer/linux/for-upstream commit c909ada856861f305653b127db3ea0fa60264331 - Input: atmel_mxt_ts - check data->input_dev is not null in mxt_input_sync()] Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 3 + drivers/input/touchscreen/atmel_mxt_ts.c | 109 +++++++++++++++--- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index e28139ce3cae..713ce870805c 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -37,6 +37,9 @@ Optional properties for main touchpad device: MXT_SUSPEND_REGULATOR - use regulators to power down device during suspend Definitions are in . +- atmel,cfg_name: Provide name of configuration file in OBP_RAW format. This + will be downloaded from the firmware loader on probe to the device. + Example: touch@4b { diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 8d898855923e..c09ef7689f6a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -34,7 +34,6 @@ #include /* Configuration file */ -#define MXT_CFG_NAME "maxtouch.cfg" #define MXT_CFG_MAGIC "OBP_RAW V1" /* Registers */ @@ -335,6 +334,8 @@ struct mxt_data { struct regulator *reg_vdd; struct regulator *reg_avdd; char *fw_name; + char *cfg_name; + const char *pcfg_name; /* Cached parameters from object table */ u16 T5_address; @@ -377,6 +378,9 @@ struct mxt_data { /* Indicates whether device is in suspend */ bool suspended; + + /* Indicates whether device is updating configuration */ + bool updating_config; }; struct mxt_vb2_buffer { @@ -833,9 +837,11 @@ static void mxt_input_button(struct mxt_data *data, u8 *message) static void mxt_input_sync(struct mxt_data *data) { - input_mt_report_pointer_emulation(data->input_dev, - data->t19_num_keys); - input_sync(data->input_dev); + if (data->input_dev) { + input_mt_report_pointer_emulation(data->input_dev, + data->t19_num_keys); + input_sync(data->input_dev); + } } static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) @@ -2578,13 +2584,21 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; - error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, - &client->dev, GFP_KERNEL, data, - mxt_config_cb); - if (error) { - dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", - error); - goto err_free_sysfs; + if (data->cfg_name) { + error = request_firmware_nowait(THIS_MODULE, true, + data->cfg_name, + &client->dev, + GFP_KERNEL, data, + mxt_config_cb); + if (error) { + dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", + error); + goto err_free_sysfs; + } + } else { + error = mxt_configure_objects(data, NULL); + if (error) + goto err_free_sysfs; } return 0; @@ -3081,19 +3095,21 @@ static int mxt_configure_objects(struct mxt_data *data, error = mxt_init_t7_power_cfg(data); if (error) { dev_err(dev, "Failed to initialize power cfg\n"); - return error; + goto err_free_object_table; } if (cfg) { error = mxt_update_cfg(data, cfg); - if (error) + if (error) { dev_warn(dev, "Error %d updating config\n", error); + goto err_free_object_table; + } } if (data->multitouch) { error = mxt_initialize_input_device(data); if (error) - return error; + goto err_free_object_table; } else { dev_warn(dev, "No touch object detected\n"); } @@ -3101,6 +3117,10 @@ static int mxt_configure_objects(struct mxt_data *data, mxt_debug_init(data); return 0; + +err_free_object_table: + mxt_free_object_table(data); + return error; } /* Firmware Version is returned as Major.Minor.Build */ @@ -3392,6 +3412,55 @@ static ssize_t mxt_update_fw_store(struct device *dev, return count; } +static ssize_t mxt_update_cfg_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + const struct firmware *cfg; + int ret; + + ret = mxt_update_file_name(dev, &data->cfg_name, buf, count); + if (ret) + return ret; + + ret = request_firmware(&cfg, data->cfg_name, dev); + if (ret < 0) { + dev_err(dev, "Failure to request config file %s\n", + data->cfg_name); + ret = -ENOENT; + goto out; + } + + data->updating_config = true; + + mxt_free_input_device(data); + + if (data->suspended) { + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + enable_irq(data->irq); + mxt_regulator_enable(data); + } else if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) { + mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); + mxt_acquire_irq(data); + } + + data->suspended = false; + } + + ret = mxt_configure_objects(data, cfg); + if (ret) + goto release; + + ret = count; + +release: + release_firmware(cfg); +out: + data->updating_config = false; + return ret; +} + static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3406,11 +3475,13 @@ static const struct attribute_group mxt_fw_attr_group = { static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); +static DEVICE_ATTR(update_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, + &dev_attr_update_cfg.attr, NULL }; @@ -3511,7 +3582,7 @@ static int mxt_stop(struct mxt_data *data) { int ret; - if (data->suspended || data->in_bootloader) + if (data->suspended || data->in_bootloader || data->updating_config) return 0; switch (data->suspend_mode) { @@ -3580,6 +3651,8 @@ static int mxt_parse_device_properties(struct mxt_data *data) int n_keys; int error; + device_property_read_string(dev, "atmel,cfg_name", &data->pcfg_name); + if (device_property_present(dev, keymap_property)) { n_keys = device_property_read_u32_array(dev, keymap_property, NULL, 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 Tue Sep 17 09:37:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148407 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 52B7814DB for ; Tue, 17 Sep 2019 09:39:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A1272189D for ; Tue, 17 Sep 2019 09:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbfIQJjD (ORCPT ); Tue, 17 Sep 2019 05:39:03 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59351 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbfIQJjB (ORCPT ); Tue, 17 Sep 2019 05:39:01 -0400 IronPort-SDR: qDt9WARS/bvl2fdcGdSTP8aRHCGKJ0Chl4bOIsPltWJmwZfA15obywX0a67I+nbeK+3Uv/aVqN 9HAs54b9qis8/LUGmhbzbkIHzJ1fpoxa/H+Fp+fpf3fO4hDdRMYNuWIAYLVWvrYHvdxmhQ7tov RiZt8LK5j38Wlt8jun/DHhnzBl0BXcRM/vlaZqb6Bd0jvBKLDg3YAkOc/WMZ/WnKVM0eyoZE/i u3WZXPHuiy80JPqsgT1GXyssC5jgjBssDxwxNMyQf2BjzKOn1W0dqKvlGR2GDHltr0oiKrlRlX gHw= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223072" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:00 -0800 IronPort-SDR: 3f/shU3LjsDbKvGCGlak+XAXmm9rjJUsTrDisDxwOkXDmsomR9k92YnxYxPG3gE/t9Qf4oFQIu jfukQW1YOHT4YMOw2cEt3hZIobTJtlSxdZu/RMxYgJYIJvu25cZcWzGncUg1kczszTR9aQ8P+H K1w+0btrefX8xDqjQ2oZAEOo7/+sftf71XF/Q/oXXP1Lkwzj4NjqSaKrJHMGgnupFEAAoMh0tj 7d+2wofpDDvxnISu/aEuilEO68Z/iJVoibOlCXNlKqCj+rhfPDku0yK8h1rshHha/cCaf8Q/t6 cYE= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 18/49] Input: atmel_mxt_ts - allow input name to be specified in platform data Date: Tue, 17 Sep 2019 18:37:35 +0900 Message-ID: <20190917093806.18538-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093806.18538-1-jiada_wang@mentor.com> References: <20190917093806.18538-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Android systems identify the input device and map to IDC file by using the input device name. To avoid unnecessary deltas to the driver file, allow this to be set from the platform data. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit cbf94a7bda754d2e1899d9f50313a0bccc91422d) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- .../devicetree/bindings/input/atmel,maxtouch.txt | 2 ++ drivers/input/touchscreen/atmel_mxt_ts.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index 713ce870805c..d7db16920083 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -40,6 +40,8 @@ Optional properties for main touchpad device: - atmel,cfg_name: Provide name of configuration file in OBP_RAW format. This will be downloaded from the firmware loader on probe to the device. +- atmel,input_name: Override name of input device from the default. + Example: touch@4b { diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index c09ef7689f6a..f0522f4416dc 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_read_u32_array(dev, keymap_property, NULL, 0); From patchwork Tue Sep 17 09:37:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148409 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 6ED5C14DB for ; Tue, 17 Sep 2019 09:39:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 577BA2189D for ; Tue, 17 Sep 2019 09:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728493AbfIQJjG (ORCPT ); Tue, 17 Sep 2019 05:39:06 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59351 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728479AbfIQJjF (ORCPT ); Tue, 17 Sep 2019 05:39:05 -0400 IronPort-SDR: /+XDldrwZK1RVt2U20CTYZLEM+oVy8eAq/caijhHeq5DTlBoawQRxl/Ozc24Hb0l5mmKiblJdR 4KFctO07X1dIQ79YrLMlS7F0aMAf4OqHagYOx+7LAN7wtwR7AwX8xyrgBEp0hPOf768zDKUV2U aGHgM9EW/Zvd1RVYRXsM6CaoFgeBRXQ0YrSlk1ADMj1iQ+4VJTPjwz38Cxlllnj4LAozR6lvoV NgnFie+6eKfS7JfgIfjwdYBDBvcAmMsfiYdcyI8KCbc2Mi4QkCw2ug/VFRuJpZREQRzmJY79ZE RHs= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223077" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:04 -0800 IronPort-SDR: 4fzFS0XbHp5G00Lmy9BfjSjOiGQ9SpFgsLYHI17m6lEWNM65EDZfni4NpyQGisu3AwFYlr2qIL rTJLwoaHpBfvLkGSverp3B179NGHJgt11A3z0yKwe9lVNgT5QCHc564ykXmq1bG5rpLeYtO9eK 3d0OdD0U9dqh1VBn7aw6x2Sut9dr+Ebc5sx9JTpVVMY59bRLWjRYDyQ/ePj8zchZ2Ph1dPXDfe 8VNT6Rq0X5fGK9BcX3SpErp8eCJSrTc2zAMCVZyxNHADWfPe0gWylWYnQDuFlcxK7BzoVVWDp0 Wr4= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 19/49] Input: atmel_mxt_ts - add config checksum attribute to sysfs Date: Tue, 17 Sep 2019 18:37:36 +0900 Message-ID: <20190917093806.18538-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093806.18538-1-jiada_wang@mentor.com> References: <20190917093806.18538-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-08.mgc.mentorg.com (147.34.90.208) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: karl tsou Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 03477477ddbe5dcad42853ab3f84166a8f807acf) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index f0522f4416dc..69e34294688c 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3128,6 +3128,15 @@ static int mxt_configure_objects(struct mxt_data *data, return error; } +/* Configuration crc check sum is returned as hex xxxxxx */ +static ssize_t mxt_config_crc_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + + return scnprintf(buf, PAGE_SIZE, "%06x\n", data->config_crc); +} + /* Firmware Version is returned as Major.Minor.Build */ static ssize_t mxt_fw_version_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -3481,12 +3490,14 @@ static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); static DEVICE_ATTR(update_cfg, S_IWUSR, NULL, mxt_update_cfg_store); +static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, &dev_attr_hw_version.attr, &dev_attr_object.attr, &dev_attr_update_cfg.attr, + &dev_attr_config_crc.attr, NULL }; From patchwork Tue Sep 17 09:38:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148415 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 2404514DB for ; Tue, 17 Sep 2019 09:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C24320862 for ; Tue, 17 Sep 2019 09:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728551AbfIQJjl (ORCPT ); Tue, 17 Sep 2019 05:39:41 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfIQJjl (ORCPT ); Tue, 17 Sep 2019 05:39:41 -0400 IronPort-SDR: Lni6NxtCmo3XUgNWu0s7s3K8WMUWbll/0+qxCpv22BuidX5/O7W+cLHyNAw7FK9wpF9SCAgKQv ohZSZJZFojtjC/0/ZlnZhOeDI76LCuD2loRtUVXoc6sKqs94g3odCd2F44JezBFdHt2LGAMqOc tfkRGA2880XsjodZmOIiqnle8CWdx4p6w7Pou4DLAa3FIItOoKM9SMRfBy5Qt0AFVSHNBQwEU2 NovLhmM69xjXhA3vZtpuY/TwvejCU7ALah24CX6ap4Y8wtwdPSEMS3E0Y+Ej8yxztxiZTB4pLP AFM= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416503" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:39 -0800 IronPort-SDR: O6DOm3rwB3wfepOQeSrCnDEl28Fri9eLU6sWzk+Bp3L9ppkxy7mlcYQlUREBct0y+3jw5IcJxz PYWu4mckamso+7CoScdNsUYvWtK/yg67hTIAbJo0plvGmWhZ7MDzv6M5CWMdQdiccV7YlFZfCe +51TIyu/DcCl4d4CR59kUE1MYxkBpmtyBEbRbLml3qnalTM1WbG6sg8UIgtDE2y0SZRJlGmwu/ utupXLYWhBqm2/cxHnKzZW03vBDPDUmTBnY4E91poDAfU0b1UVk1vNtkQ+NrbX2sb1VvlWH0Sf GPE= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 20/49] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Tue, 17 Sep 2019 18:38:46 +0900 Message-ID: <20190917093915.18645-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 1bbe20ff3dcd6612e7942c495929eae5c138ece2) Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 +++++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 69e34294688c..711ce39f38ca 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -291,6 +291,22 @@ struct mxt_cfg { struct mxt_info info; }; +/* Firmware frame structure */ +struct mxt_fw_frame { + __be16 size; + u8 data[]; +}; + +/* Firmware update context */ +struct mxt_flash { + const struct firmware *fw; + struct mxt_fw_frame *frame; + loff_t pos; + size_t frame_size; + unsigned int count; + unsigned int retry; +}; + /* Each client has this additional data */ struct mxt_data { struct i2c_client *client; @@ -3244,21 +3260,17 @@ static int mxt_check_firmware_format(struct device *dev, static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - const struct firmware *fw = NULL; - unsigned int frame_size; - unsigned int pos = 0; - unsigned int retry = 0; - unsigned int frame = 0; + struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&fw, data->fw_name, dev); + ret = request_firmware(&f.fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); return ret; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, fw); + ret = mxt_check_firmware_format(dev, f.fw); if (ret) goto release_firmware; @@ -3312,41 +3324,42 @@ static int mxt_load_fw(struct device *dev) goto disable_irq; } - while (pos < fw->size) { + while (f.pos < f.fw->size) { + f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); + ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); if (ret) goto disable_irq; - frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); - /* Take account of CRC bytes */ - frame_size += 2; + f.frame_size = __be16_to_cpu(f.frame->size) + 2U; /* Write one frame to device */ - ret = mxt_bootloader_write(data, fw->data + pos, frame_size); + ret = mxt_bootloader_write(data, f.fw->data + f.pos, + f.frame_size); if (ret) goto disable_irq; ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); if (ret) { - retry++; + f.retry++; /* Back off by 20ms per retry */ - msleep(retry * 20); + msleep(f.retry * 20); - if (retry > 20) { + if (f.retry > 20) { dev_err(dev, "Retry count exceeded\n"); goto disable_irq; } } else { - retry = 0; - pos += frame_size; - frame++; + f.retry = 0; + f.pos += f.frame_size; + f.count++; } - if (frame % 50 == 0) - dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n", - frame, pos, fw->size); + if (f.count % 50 == 0) + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f.count, f.pos, f.fw->size); } /* Wait for flash. */ @@ -3355,7 +3368,7 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos); + dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3369,7 +3382,7 @@ static int mxt_load_fw(struct device *dev) disable_irq: disable_irq(data->irq); release_firmware: - release_firmware(fw); + release_firmware(f.fw); return ret; } From patchwork Tue Sep 17 09:38:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148417 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 0E83E912 for ; Tue, 17 Sep 2019 09:39:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC03A20862 for ; Tue, 17 Sep 2019 09:39:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbfIQJjo (ORCPT ); Tue, 17 Sep 2019 05:39:44 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfIQJjn (ORCPT ); Tue, 17 Sep 2019 05:39:43 -0400 IronPort-SDR: daOkxq2KT7eN9SBZHbi1GGcU+V3+fdW3svHMmwRk1SS2rvjcD8m/n63eEm6ztKqlLYXFlzcEmH glzefCkWdR7x3OtA15KKlRGM32KopNU7yOnS6MzswxR1WRTxIx0ObrBFC7Slw5fgBitQXlrMqo u6vYPMY6muThnuzCmLYOZ2AZZGqcX0mXboHqhWG7/JcjO/jDb2g190CMYdGD8Z1iv6CSCZ4Ifg jJzihmIVQ+AayLunnrY8eO5lnFhZJxxMF8LfeI7zgpevEkrWN+9liVqH2r9YjD8RpEdvmdvz1x NwI= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416508" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:43 -0800 IronPort-SDR: sQpZMFVbuTGk0xlmVSatapakYQarttkTxzQnBYHuekTeUnG2rjwn90eVrGZue88wHnGt2MkGBj rGiypYZPyNhNaDgTbsc09HYWsDKNcYGZSYYsbvX510TYXgD434RXmoYh5yWIuWByye6Qeol9UT hOOnt/PHxTXuGa1adCHxu7D/UGaPPaRBMERMjSxouKCbwlI/EEodq+LWXLBUS6eZLBzuD+Zlm+ +W+4C1SIX1IMr2r1DtN1EZigA96BN29RUJBJMZUZOgHlVPyDZJTZriln3Jj4/FHTOD8hKeZKhe 0EE= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 21/49] Input: atmel_mxt_ts - refactor code to enter bootloader into separate func Date: Tue, 17 Sep 2019 18:38:47 +0900 Message-ID: <20190917093915.18645-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit bedd706a32522b946467e15f4f4f24de86a1b4d7) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: Squash change from ndyer/linux/for-upstream commit d691d3ee6c6de84b38464a42 3207b3e23cb9dc3a - Input: atmel_mxt_ts - check firmware format before entering bootloader] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 43 +++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 711ce39f38ca..ca56122550eb 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 Tue Sep 17 09:38:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148419 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 6F0ED912 for ; Tue, 17 Sep 2019 09:39:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 533A920862 for ; Tue, 17 Sep 2019 09:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728596AbfIQJjr (ORCPT ); Tue, 17 Sep 2019 05:39:47 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfIQJjq (ORCPT ); Tue, 17 Sep 2019 05:39:46 -0400 IronPort-SDR: CXDpn/tCqI2BoSIIUjjWS79zweBsl+lro7NC5MAwhLz7ThXWXlrr0PGP3OYOM3MDzBrscrsxA3 ZSwzYUD2fwf7/RLlO5ncjRq7skJetivSEJSq71zvDhVVwB5dcH/3+jS5AWYMJOz2AaiiD6Yc2H W/LxrplIIXwnffilh4VZ54I9GsRh+doJ4xkMEnTVR/SyhDEi3CclSM6BTYjnO5zpFIC1phLBu5 xyMbI0CHQffn8KLshyjqbuOfbZ1IxdQ+9chQn2euIZvjhkSDzOuzm+48kimvJhfIN4bB2L/qCD JTw= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416516" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:46 -0800 IronPort-SDR: gJbr6gCuJwYq+MOL2P5/5wkBGJxXv1REavWwD/+k4+76/xxiuFqyVqjikUO8nO43P5h+2jP6ey iVv4Qsw672N4Qd6yHfbX4y9qOpjTPXVBXXX39g8U8zBspCPLca+d8Fbaqe0K/AVQNaFEsXTxlS m6i6mYtvZQACGBY/rkGbGAWTyjYMEhgmS7x/FzVOc6ZDo4EnXkQo5qTyY/++e08Gq9rQW3cImK YwOQa8QpDs9WovM3xlsu7pAdDWrDbRoyTc1PuoZDknv4jD/ty1UKXSSWVXRovfwuQNNghf0YeM 8PA= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 22/49] Input: atmel_mxt_ts - combine bootloader version query with probe Date: Tue, 17 Sep 2019 18:38:48 +0900 Message-ID: <20190917093915.18645-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 ca56122550eb..b4cb426e7890 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -558,47 +558,31 @@ static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) { struct device *dev = &data->client->dev; int error; - u8 val; - bool crc_failure; + u8 buf[3]; + bool crc_failure, extended_id; error = mxt_lookup_bootloader_address(data, alt_address); if (error) return error; - error = mxt_bootloader_read(data, &val, 1); + /* Check bootloader status and version information */ + error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) return error; - /* Check app crc fail mode */ - crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; + crc_failure = (buf[0] & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; + extended_id = buf[0] & MXT_BOOT_EXTENDED_ID; - dev_err(dev, "Detected bootloader, status:%02X%s\n", - val, crc_failure ? ", APP_CRC_FAIL" : ""); + dev_info(dev, "Found bootloader addr:%02x ID:%u%s%u%s\n", + data->bootloader_addr, + extended_id ? (buf[1] & MXT_BOOT_ID_MASK) : buf[0], + extended_id ? " version:" : "", + extended_id ? buf[2] : 0, + crc_failure ? ", APP_CRC_FAIL" : ""); return 0; } -static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val) -{ - struct device *dev = &data->client->dev; - u8 buf[3]; - - if (val & MXT_BOOT_EXTENDED_ID) { - if (mxt_bootloader_read(data, &buf[0], 3) != 0) { - dev_err(dev, "%s: i2c failure\n", __func__); - return val; - } - - dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]); - - return buf[0]; - } else { - dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK); - - return val; - } -} - static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, bool wait) { @@ -632,9 +616,6 @@ static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, if (ret) return ret; - if (state == MXT_WAITING_BOOTLOAD_CMD) - val = mxt_get_bootloader_version(data, val); - switch (state) { case MXT_WAITING_BOOTLOAD_CMD: case MXT_WAITING_FRAME_DATA: @@ -3283,7 +3264,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); /* Do not need to scan since we know family ID */ - ret = mxt_lookup_bootloader_address(data, 0); + ret = mxt_probe_bootloader(data, 0); if (ret) return ret; From patchwork Tue Sep 17 09:38:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148421 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 8E04017E6 for ; Tue, 17 Sep 2019 09:39:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D8D320862 for ; Tue, 17 Sep 2019 09:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728639AbfIQJjw (ORCPT ); Tue, 17 Sep 2019 05:39:52 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfIQJjw (ORCPT ); Tue, 17 Sep 2019 05:39:52 -0400 IronPort-SDR: uM26IYZm175N7dX/60L7CYzhpLcmureoXuzavrJu7uXhv1SwPTjooceqRM8b6+PUKUP3ABr4U3 FLvZ6D+9kSvJ5DjYxhDD73uH1ZqInKvrhAk58L5JExw83JqWrTMzXxf0/yBCDRtfs9f0c3vjjZ 9vimAvR0voTaekKD8525W9dA7UIvHYtlU2tXq2vCNghBOs2pTeMarHjDF0BGt5CQoQrmV0W1p3 uFOhvsCiGYI6YvaKglYlKniHKaw/3xcrcY1ruHtJxkNr/tYFaOG1IqIpioWaFiWd6gWAl8G9ko rbY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416518" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:50 -0800 IronPort-SDR: Slrekyt5L65NzItXBmnzVIXx+9vw3KpbRUjRu7qzIYvmNp6rTgcM3kGXroV1P/JYYl8FUVUCNN Yk/b1jWUadObdqCgGJLDE9Y65EXpvh7KUiiud2UQmGOLZL3vV9mVGlhQpr0pVTq87JPcLxei5P 2QCaLpl2uaJLogyHF7Xayh8Aqy9K+FgWTOyr3u9PnA+E72FO3u+uOLevm3hbrG0CiYZ7pp2L61 4UGLBa2Hfb7kqFbF/u4Fv2FuW/cjQNQFh6RXpffxl9ljbCyqTi7w4H1i2ReMFFhU66c7XGnpaA hDU= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 23/49] Input: atmel_mxt_ts - improve bootloader state machine handling Date: Tue, 17 Sep 2019 18:38:49 +0900 Message-ID: <20190917093915.18645-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer The code is much clearer if we switch on the actual state the bootloader is in, rather than the state we want it to be in, and allows the removal of a goto retry tangle. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 463e15ee95ee6e6274017ff645839dbe34d75c99) [gdavis: Squash fix from George G. Davis: - input: atmel_mxt_ts - Fix 'mxt_send_bootloader_cmd' was not declared warning] Signed-off-by: George G. Davis --- Notes: - Squash fix from George G. Davis: + input: atmel_mxt_ts - Fix 'mxt_send_bootloader_cmd' was not declared warning The following sparse warning was introduced by ndyer/linux/for-upstream commit 463e15ee95ee ("Input: atmel_mxt_ts - improve bootloader state machine handling"): drivers/input/touchscreen/atmel_mxt_ts.c:888:5: warning: symbol 'mxt_send_bootloader_cmd' was not declared. Should it be static? Fix the above sparse warning by restoring the 'mxt_send_bootloader_cmd' static declaration which was errantly removed by ndyer/linux/for-upstream commit 463e15ee95ee ("Input: atmel_mxt_ts - improve bootloader state machine handling"). Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 183 ++++++++++++----------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index b4cb426e7890..65d587badf6a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -305,6 +305,8 @@ struct mxt_flash { size_t frame_size; unsigned int count; unsigned int retry; + u8 previous; + bool complete; }; /* Each client has this additional data */ @@ -583,64 +585,121 @@ static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) return 0; } -static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, - bool wait) +static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock); + +static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) +{ + f->frame = (struct mxt_fw_frame *)(f->fw->data + f->pos); + + /* Take account of CRC bytes */ + f->frame_size = __be16_to_cpu(f->frame->size) + 2U; + + /* Write one frame to device */ + return mxt_bootloader_write(data, f->fw->data + f->pos, + f->frame_size); +} + +static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) { struct device *dev = &data->client->dev; - u8 val; + u8 state; int ret; -recheck: - if (wait) { + /* + * In application update mode, the interrupt + * line signals state transitions. We must wait for the + * CHG assertion before reading the status byte. + * Once the status byte has been read, the line is deasserted. + */ + ret = mxt_wait_for_completion(data, &data->bl_completion, + MXT_FW_CHG_TIMEOUT); + if (ret) { /* - * In application update mode, the interrupt - * line signals state transitions. We must wait for the - * CHG assertion before reading the status byte. - * Once the status byte has been read, the line is deasserted. + * TODO: handle -ERESTARTSYS better by terminating + * fw update process before returning to userspace + * by writing length 0x000 to device (iff we are in + * WAITING_FRAME_DATA state). */ - ret = mxt_wait_for_completion(data, &data->bl_completion, - MXT_FW_CHG_TIMEOUT); - if (ret) { - /* - * TODO: handle -ERESTARTSYS better by terminating - * fw update process before returning to userspace - * by writing length 0x000 to device (iff we are in - * WAITING_FRAME_DATA state). - */ - dev_err(dev, "Update wait error %d\n", ret); - return ret; - } + dev_warn(dev, "Update wait error %d\n", ret); } - ret = mxt_bootloader_read(data, &val, 1); + ret = mxt_bootloader_read(data, &state, 1); if (ret) return ret; + /* Remove don't care bits */ + if (state & ~MXT_BOOT_STATUS_MASK) + state &= ~MXT_BOOT_STATUS_MASK; + switch (state) { case MXT_WAITING_BOOTLOAD_CMD: + dev_info(dev, "Unlocking bootloader\n"); + ret = mxt_send_bootloader_cmd(data, true); + if (ret) + return ret; + + break; + case MXT_WAITING_FRAME_DATA: - case MXT_APP_CRC_FAIL: - val &= ~MXT_BOOT_STATUS_MASK; + if ((f->previous != MXT_WAITING_BOOTLOAD_CMD) + && (f->previous != MXT_FRAME_CRC_PASS) + && (f->previous != MXT_FRAME_CRC_FAIL)) + goto unexpected; + + ret = mxt_write_firmware_frame(data, f); + if (ret) + return ret; + + break; + + case MXT_FRAME_CRC_CHECK: + if (f->previous != MXT_WAITING_FRAME_DATA) + goto unexpected; break; + case MXT_FRAME_CRC_PASS: - if (val == MXT_FRAME_CRC_CHECK) { - goto recheck; - } else if (val == MXT_FRAME_CRC_FAIL) { - dev_err(dev, "Bootloader CRC fail\n"); - return -EINVAL; + if (f->previous != MXT_FRAME_CRC_CHECK) + goto unexpected; + + /* Next frame */ + f->retry = 0; + f->pos += f->frame_size; + f->count++; + + if (f->pos >= f->fw->size) { + f->complete = true; + dev_info(dev, "Sent %u frames, %zu bytes\n", + f->count, f->fw->size); + } else if (f->count % 50 == 0) { + dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", + f->count, f->pos, f->fw->size); } + + break; + + case MXT_FRAME_CRC_FAIL: + if (f->retry > 20) { + dev_err(dev, "Retry count exceeded\n"); + return -EIO; + } + + /* Back off by 20ms per retry */ + dev_dbg(dev, "Bootloader frame CRC failure\n"); + f->retry++; + msleep(f->retry * 20); break; + default: return -EINVAL; } - if (val != state) { - dev_err(dev, "Invalid bootloader state %02X != %02X\n", - val, state); - return -EINVAL; - } + f->previous = state; return 0; + +unexpected: + dev_err(dev, "Unexpected state transition\n"); + return -EINVAL; } static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) @@ -3301,57 +3360,13 @@ static int mxt_load_fw(struct device *dev) if (ret) goto release_firmware; - ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); - if (ret) { - /* Bootloader may still be unlocked from previous attempt */ - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false); - if (ret) - goto disable_irq; - } else { - dev_info(dev, "Unlocking bootloader\n"); - - /* Unlock bootloader */ - ret = mxt_send_bootloader_cmd(data, true); + while (true) { + ret = mxt_check_bootloader(data, &f); if (ret) - goto disable_irq; - } - - while (f.pos < f.fw->size) { - f.frame = (struct mxt_fw_frame *)(f.fw->data + f.pos); - - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); - if (ret) - goto disable_irq; - - /* Take account of CRC bytes */ - f.frame_size = __be16_to_cpu(f.frame->size) + 2U; - - /* Write one frame to device */ - ret = mxt_bootloader_write(data, f.fw->data + f.pos, - f.frame_size); - if (ret) - goto disable_irq; - - ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); - if (ret) { - f.retry++; - - /* Back off by 20ms per retry */ - msleep(f.retry * 20); - - if (f.retry > 20) { - dev_err(dev, "Retry count exceeded\n"); - goto disable_irq; - } - } else { - f.retry = 0; - f.pos += f.frame_size; - f.count++; - } + return ret; - if (f.count % 50 == 0) - dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", - f.count, f.pos, f.fw->size); + if (f.complete) + break; } /* Wait for flash. */ @@ -3360,7 +3375,6 @@ static int mxt_load_fw(struct device *dev) if (ret) goto disable_irq; - dev_dbg(dev, "Sent %u frames, %lld bytes\n", f.count, f.pos); /* * Wait for device to reset. Some bootloader versions do not assert @@ -3370,7 +3384,6 @@ static int mxt_load_fw(struct device *dev) mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); data->in_bootloader = false; - disable_irq: disable_irq(data->irq); release_firmware: From patchwork Tue Sep 17 09:38:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148423 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 3E92A14DB for ; Tue, 17 Sep 2019 09:39:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 241BA21881 for ; Tue, 17 Sep 2019 09:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728665AbfIQJjy (ORCPT ); Tue, 17 Sep 2019 05:39:54 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728319AbfIQJjy (ORCPT ); Tue, 17 Sep 2019 05:39:54 -0400 IronPort-SDR: D8163l2u0H1sMk+65Kh7wYSEJxGHvbUdDB01yHDxmZijAewjpf41M6b1T8/Dc0P1X+9NBprOnQ 6ZC0xqCJBcqiRypHJkba8moaBZsooMVnRCoWUpj+eh014wQN+Z4Kow9pJeE+2MjHsZ75UyR6Hm RBuYwOxOlRMjHpLnM94TaabLjsbsDJX+AIlMzhX3tdsw51OqKtbut8qwMD7LeooQfQi4z1o+FF 4jyHhmpHwTGnMvzCl0KiqtZ1DUS7WHhdeHU6Se0e5dps637kdvrPq4ojO3pjwSBs1npktOygqA x8o= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416525" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:53 -0800 IronPort-SDR: QahvdR0bdUS7VCop1W6UESzY3UUmS5qkDvzHrqVPkPXMpbSIfqxYiJ+D+EN6akRnrFk81FH2Xe d6ehyBZG1gAkJPiOIkgqnlIzh5DFJyyQzmVfJkPXpITxxhRwqtDhu9f+Jpdxk00iPIIb/OLl9M Ub5e84pUdARGIttceD1OlFzXmtJY8g+WywdEk5ot6G4uOl81phw2BzgqR4L+UmqBo8aLN5JmjZ 4Fk1ai+0/0LrjbiyjO1uGAnjNIRmUVixpPqxXYdu3cnzlnojKHah91E9auJquRDFOMoO8XHq5n 19A= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 24/49] Input: atmel_mxt_ts - rename bl_completion to chg_completion Date: Tue, 17 Sep 2019 18:38:50 +0900 Message-ID: <20190917093915.18645-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit dda8453bfb44216645ede798918a314d4fca2481) [gdavis: Resolve forward port conflicts due to applying upstream commit 96a938aa214e ("Input: atmel_mxt_ts - remove platform data support").] Signed-off-by: George G. Davis [jiada: call complete(&data->chg_completion) only when in_bootloader is TRUE] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 65d587badf6a..dfbdf6cf5c54 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -381,9 +381,6 @@ struct mxt_data { u8 T100_reportid_max; u16 T107_address; - /* for fw update in bootloader */ - struct completion bl_completion; - /* for reset handling */ struct completion reset_completion; @@ -395,6 +392,9 @@ struct mxt_data { enum mxt_suspend_mode suspend_mode; + /* for power up handling */ + struct completion chg_completion; + /* Indicates whether device is in suspend */ bool suspended; @@ -611,7 +611,7 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) * CHG assertion before reading the status byte. * Once the status byte has been read, the line is deasserted. */ - ret = mxt_wait_for_completion(data, &data->bl_completion, + ret = mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_CHG_TIMEOUT); if (ret) { /* @@ -1402,8 +1402,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) struct mxt_data *data = dev_id; if (data->in_bootloader) { - /* bootloader state transition completion */ - complete(&data->bl_completion); + complete(&data->chg_completion); return IRQ_HANDLED; } @@ -2167,9 +2166,9 @@ static void mxt_regulator_enable(struct mxt_data *data) msleep(MXT_CHG_DELAY); retry_wait: - reinit_completion(&data->bl_completion); + reinit_completion(&data->chg_completion); data->in_bootloader = true; - error = mxt_wait_for_completion(data, &data->bl_completion, + error = mxt_wait_for_completion(data, &data->chg_completion, MXT_POWERON_DELAY); if (error == -EINTR) goto retry_wait; @@ -3334,7 +3333,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) enable_irq(data->irq); } - reinit_completion(&data->bl_completion); + reinit_completion(&data->chg_completion); return 0; } @@ -3370,7 +3369,7 @@ static int mxt_load_fw(struct device *dev) } /* Wait for flash. */ - ret = mxt_wait_for_completion(data, &data->bl_completion, + ret = mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); if (ret) goto disable_irq; @@ -3381,7 +3380,7 @@ static int mxt_load_fw(struct device *dev) * the CHG line after bootloading has finished, so ignore potential * errors. */ - mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); + mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); data->in_bootloader = false; disable_irq: @@ -3803,7 +3802,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 Tue Sep 17 09:38:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148425 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 8DA5314DB for ; Tue, 17 Sep 2019 09:40:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69B5621897 for ; Tue, 17 Sep 2019 09:40:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbfIQJj6 (ORCPT ); Tue, 17 Sep 2019 05:39:58 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20501 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfIQJj6 (ORCPT ); Tue, 17 Sep 2019 05:39:58 -0400 IronPort-SDR: jGT7sOFBgqU8CzoWizuywFGtrrG5t5ME9buqUn68lCuB0XwLEKaUnMVC8LAUEFIIbmkz+nF9PQ ysJgqEtI2kzZKc1h+Oh5M4UaWE54Pl0/DfJ6ROeJ3S+Vx5r5qRVNnJmWxBbVqBwArdLB5EIV2b mMdjCvMB8UcJlEfhGinn2mJbeLl+y6Zd9iVH556L9tbOr1Hgn/ZXlJNSklbXhXNg4FXIy3LiES GscUSEENvJQmQvLyIDzRVmriA2vXVwW2G0A0hHOJ6Bf4ljA+iFz1KWjzu2xOD7kv9mDBSi9J6D Gzc= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416530" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:39:56 -0800 IronPort-SDR: ZHVJQqgY2ACvH/XbCuMs9F9Q+ytF+ex/51gxlMqdxCWYI8gXFp+DsBUJlLNA47QB9ScGRvhhug fUDiq5uzxD7tkBKt+eOQbiUPeizrqmZLKjMXBFOyk/yaXu8ypEIIQVVF3+hemISSMuVOZTI0qK laus4q7cCPowEdrcjpY6TcFKMSnzWUmoZoJNEuhmYZ1IM0Pclwxq3uowvB8OVRFo2BecYx8tGH nS7KTNSuxFMEnpJ5UelK2rmugP0Vyob2Xhs0xd3iTynLuyoKh6Y4CvfbgfmJLvPgFICPpUDS6J jdc= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 25/49] Input: atmel_mxt_ts - make bootloader interrupt driven Date: Tue, 17 Sep 2019 18:38:51 +0900 Message-ID: <20190917093915.18645-6-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 118 ++++++++++++----------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index dfbdf6cf5c54..49d06eb0c6ee 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,7 @@ enum t100_type { #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ +#define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -299,6 +301,7 @@ struct mxt_fw_frame { /* Firmware update context */ struct mxt_flash { + struct mxt_data *data; const struct firmware *fw; struct mxt_fw_frame *frame; loff_t pos; @@ -306,7 +309,8 @@ struct mxt_flash { unsigned int count; unsigned int retry; u8 previous; - bool complete; + struct completion flash_completion; + struct delayed_work work; }; /* Each client has this additional data */ @@ -355,6 +359,7 @@ struct mxt_data { char *cfg_name; const char *pcfg_name; const char *input_name; + struct mxt_flash *flash; /* Cached parameters from object table */ u16 T5_address; @@ -599,28 +604,17 @@ static int mxt_write_firmware_frame(struct mxt_data *data, struct mxt_flash *f) f->frame_size); } -static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) +static int mxt_check_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; + struct mxt_flash *f = data->flash; u8 state; int ret; - /* - * In application update mode, the interrupt - * line signals state transitions. We must wait for the - * CHG assertion before reading the status byte. - * Once the status byte has been read, the line is deasserted. - */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_CHG_TIMEOUT); - if (ret) { - /* - * TODO: handle -ERESTARTSYS better by terminating - * fw update process before returning to userspace - * by writing length 0x000 to device (iff we are in - * WAITING_FRAME_DATA state). - */ - dev_warn(dev, "Update wait error %d\n", ret); + /* Handle interrupt after download/flash process */ + if (f->pos >= f->fw->size) { + complete(&f->flash_completion); + return 0; } ret = mxt_bootloader_read(data, &state, 1); @@ -666,14 +660,12 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->pos += f->frame_size; f->count++; - if (f->pos >= f->fw->size) { - f->complete = true; + if (f->pos >= f->fw->size) dev_info(dev, "Sent %u frames, %zu bytes\n", f->count, f->fw->size); - } else if (f->count % 50 == 0) { + else if (f->count % 50 == 0) dev_dbg(dev, "Sent %u frames, %lld/%zu bytes\n", f->count, f->pos, f->fw->size); - } break; @@ -695,6 +687,9 @@ static int mxt_check_bootloader(struct mxt_data *data, struct mxt_flash *f) f->previous = state; + /* Poll after 0.1s if no interrupt received */ + schedule_delayed_work(&f->work, msecs_to_jiffies(100)); + return 0; unexpected: @@ -1403,7 +1398,11 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->in_bootloader) { complete(&data->chg_completion); - return IRQ_HANDLED; + + if (data->flash && &data->flash->work) + cancel_delayed_work_sync(&data->flash->work); + + return IRQ_RETVAL(mxt_check_bootloader(data)); } if (!data->object_table) @@ -3304,16 +3303,13 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (data->suspend_mode == MXT_SUSPEND_REGULATOR) mxt_regulator_enable(data); - if (data->suspend_mode == MXT_SUSPEND_DEEP_SLEEP) - enable_irq(data->irq); - data->suspended = false; } if (!data->in_bootloader) { - /* Change to the bootloader mode */ - data->in_bootloader = true; + disable_irq(data->irq); + /* Change to the bootloader mode */ ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); if (ret) @@ -3326,67 +3322,73 @@ static int mxt_enter_bootloader(struct mxt_data *data) if (ret) return ret; + data->in_bootloader = true; mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); - } else { - enable_irq(data->irq); } - reinit_completion(&data->chg_completion); + dev_dbg(&data->client->dev, "Entered bootloader\n"); return 0; } +static void mxt_fw_work(struct work_struct *work) +{ + struct mxt_flash *f = + container_of(work, struct mxt_flash, work.work); + + mxt_check_bootloader(f->data); +} + static int mxt_load_fw(struct device *dev) { struct mxt_data *data = dev_get_drvdata(dev); - struct mxt_flash f = { 0, }; int ret; - ret = request_firmware(&f.fw, data->fw_name, dev); + data->flash = devm_kzalloc(dev, sizeof(struct mxt_flash), GFP_KERNEL); + if (!data->flash) + return -ENOMEM; + + data->flash->data = data; + + ret = request_firmware(&data->flash->fw, data->fw_name, dev); if (ret) { dev_err(dev, "Unable to open firmware %s\n", data->fw_name); - return ret; + goto free; } /* Check for incorrect enc file */ - ret = mxt_check_firmware_format(dev, f.fw); + ret = mxt_check_firmware_format(dev, data->flash->fw); if (ret) goto release_firmware; - ret = mxt_enter_bootloader(data); - if (ret) - goto release_firmware; + init_completion(&data->flash->flash_completion); + INIT_DELAYED_WORK(&data->flash->work, mxt_fw_work); + reinit_completion(&data->flash->flash_completion); - while (true) { - ret = mxt_check_bootloader(data, &f); + if (!data->in_bootloader) { + ret = mxt_enter_bootloader(data); if (ret) - return ret; - - if (f.complete) - break; + goto release_firmware; } - /* Wait for flash. */ - ret = mxt_wait_for_completion(data, &data->chg_completion, - MXT_FW_RESET_TIME); - if (ret) - goto disable_irq; + enable_irq(data->irq); + /* Poll after 0.1s if no interrupt received */ + schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); - /* - * Wait for device to reset. Some bootloader versions do not assert - * the CHG line after bootloading has finished, so ignore potential - * errors. - */ - mxt_wait_for_completion(data, &data->chg_completion, MXT_FW_RESET_TIME); + /* Wait for flash. */ + ret = mxt_wait_for_completion(data, &data->flash->flash_completion, + MXT_BOOTLOADER_WAIT); - data->in_bootloader = false; -disable_irq: disable_irq(data->irq); + cancel_delayed_work_sync(&data->flash->work); + data->in_bootloader = false; release_firmware: - release_firmware(f.fw); + release_firmware(data->flash->fw); +free: + devm_kfree(dev, data->flash); return ret; } From patchwork Tue Sep 17 09:38:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148427 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 C866B14DB for ; Tue, 17 Sep 2019 09:40:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0F8A218AE for ; Tue, 17 Sep 2019 09:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728718AbfIQJkU (ORCPT ); Tue, 17 Sep 2019 05:40:20 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20545 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727534AbfIQJkU (ORCPT ); Tue, 17 Sep 2019 05:40:20 -0400 IronPort-SDR: Ekppn3Ko7y0Kqrzl3fNcHN/RpWG2fAkT33rMW6rbj+4zuUvY6oFBJM6bbmLei08UR4pBlPwqCl 0KgMHEtfkvaBT0pCj7GjvbhgmtUFH40etKnnsNkgK6xHDTbWmt8MEGm4C51y+7RXyygHZixDgV cdWesKTHmAIzwjn/0R7MwGNVa/KWJjh2c+GAcB648v882CSwkqhz+HKOIe1X3MmTmxtotx7roW E0Tg+yESrjRI3rqSibWvIVO6b8EXOVIjKaRKZ/pyYjagPe4ilBHw2Hv40oPxG8VCv6WKrzFCfi 5ow= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416536" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:40:00 -0800 IronPort-SDR: NxQL+RykyzPw+QJPCKBXk1uLYhYC40gcDKfTFHNtO9QEU8lOWiMyIZqW3ilGaHMY7kSTkm+2Sa FqiItPs6pBmbaNFSgV2LqM8Wl2sTOsPcbvBRk5gT7a8dBPEgGoPgnRLeXISA3hOUIO22gnjGGq uIHGi9cWNH1WlqESalhWeFnjYn48QuGnyG9hE41p+ZgZqzd6r4ZzSvkQQxyJgb3XH/E6q8S4t+ 3uY0diyeZraPYxJGbJ+EVBjASNqtwadnUmRY1GwatmvGRrzPONWX1qh2JL5JQ4SegY30QHe06/ Q0Y= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 26/49] Input: atmel_mxt_ts - delay enabling IRQ when not using regulators Date: Tue, 17 Sep 2019 18:38:52 +0900 Message-ID: <20190917093915.18645-7-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 49d06eb0c6ee..0ff144529eda 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1451,9 +1451,24 @@ static int mxt_acquire_irq(struct mxt_data *data) { int error; - enable_irq(data->irq); + if (!data->irq) { + error = devm_request_threaded_irq(&data->client->dev, + data->client->irq, + NULL, mxt_interrupt, + IRQF_ONESHOT, + data->client->name, data); + if (error) { + dev_err(&data->client->dev, "Error requesting irq\n"); + return error; + } + + /* Presence of data->irq means IRQ initialised */ + data->irq = data->client->irq; + } else { + enable_irq(data->irq); + } - if (data->use_retrigen_workaround) { + if (data->object_table && data->use_retrigen_workaround) { error = mxt_process_messages_until_invalid(data); if (error) return error; @@ -3373,7 +3388,9 @@ static int mxt_load_fw(struct device *dev) goto release_firmware; } - enable_irq(data->irq); + ret = mxt_acquire_irq(data); + if (ret) + goto release_firmware; /* Poll after 0.1s if no interrupt received */ schedule_delayed_work(&data->flash->work, msecs_to_jiffies(100)); @@ -3801,7 +3818,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); @@ -3829,26 +3845,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, - NULL, mxt_interrupt, IRQF_ONESHOT, - client->name, data); - if (error) { - dev_err(&client->dev, "Failed to register interrupt\n"); - return error; - } - if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { + error = mxt_acquire_irq(data); + if (error) + return error; + error = mxt_probe_regulators(data); if (error) return error; + + disable_irq(data->irq); } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } - disable_irq(data->irq); - error = mxt_initialize(data); if (error) return error; From patchwork Tue Sep 17 09:38:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148429 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 A221F912 for ; Tue, 17 Sep 2019 09:40:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89A7220862 for ; Tue, 17 Sep 2019 09:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbfIQJkY (ORCPT ); Tue, 17 Sep 2019 05:40:24 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20545 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727534AbfIQJkV (ORCPT ); Tue, 17 Sep 2019 05:40:21 -0400 IronPort-SDR: CvEK2THQ7Sa7hj2uHH8yuDJRM97oYITtAE0+aXTb0xY11p1Wh57jcfCrk4f5V43Dwo2vLD2FfY odzdJAVknnXeK8lbPeARuS4Si0tcWE8pHFsk5GoiFsGI1dFuFgj6bac1JaecpWXCNa2IRZwPYZ AV1Qc6TPtQ7QQcxj2dBeOpBgOGgHJzT7Fn6stgImXs0qZWhGu1XmFhUL3bIspLbzHPe0SegtiM o582M+BYKCZSZ1MSUmhyUKUZ+0umEEfxwdXULe9E/iw9ZKlqlRUygqURv1fLcLeusUxbTsZhw1 Geg= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416543" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:40:03 -0800 IronPort-SDR: A7+iHF8M/KEwpBF4bfWSfnjmnxKU9q0UeoG5X4YNuzzZyX7IakxHF393YMZepWPHAQX6D1PW2t UlaXPNrLWlg1dyzgn1BNqHwkTzj8RuIVRrP60Xv0DRF6+UxnapJR5ZF9c1ZpAPCWIrqz2/y9O0 Td5TsEIYvWBW3dEHiBEy9mvckfJQ/kyX0AMEC3mNhRazO21JkPsSPcBJrWyXJZjNMX1mVt+pGB 7uWcQ8XGDnE5s72YMOdF+bP4GjYlwAH1tfx5HnmsB4Q/4Dn1VxQ3tor3x76syBnpn1iJsJ6og2 Mik= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 27/49] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 17 Sep 2019 18:38:53 +0900 Message-ID: <20190917093915.18645-8-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 0ff144529eda..cf77f46dd08d 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -216,6 +216,7 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_WAKEUP_TIME 25 /* msec */ #define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ @@ -723,6 +724,7 @@ static int __mxt_read_chunk(struct i2c_client *client, struct i2c_msg xfer[2]; u8 buf[2]; int ret; + bool retry = false; buf[0] = reg & 0xff; buf[1] = (reg >> 8) & 0xff; @@ -739,17 +741,22 @@ static int __mxt_read_chunk(struct i2c_client *client, xfer[1].len = len; xfer[1].buf = val; - ret = i2c_transfer(client->adapter, xfer, 2); - if (ret == 2) { - ret = 0; - } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", - __func__, ret); +retry_read: + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); + if (ret != ARRAY_SIZE(xfer)) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_read; + } else { + dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return -EIO; + } } - return ret; + return 0; } static int __mxt_read_reg(struct i2c_client *client, @@ -780,6 +787,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, u8 *buf; size_t count; int ret; + bool retry = false; count = len + 2; buf = kmalloc(count, GFP_KERNEL); @@ -790,14 +798,21 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, buf[1] = (reg >> 8) & 0xff; memcpy(&buf[2], val, len); +retry_write: ret = i2c_master_send(client, buf, count); - if (ret == count) { - ret = 0; - } else { - if (ret >= 0) + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + } + } else { + ret = 0; } kfree(buf); From patchwork Tue Sep 17 09:38:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148431 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 EF95B17E6 for ; Tue, 17 Sep 2019 09:40:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE6CF20862 for ; Tue, 17 Sep 2019 09:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728742AbfIQJkV (ORCPT ); Tue, 17 Sep 2019 05:40:21 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:20545 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfIQJkU (ORCPT ); Tue, 17 Sep 2019 05:40:20 -0400 IronPort-SDR: MB+HfJsILYF2LxIpWnkQxpmzquqr4a7TB3NboF0+q04Q0sCfZoAbZO4DdA79y4W6yyuTtx6x0O vjYZc2EU6gIPHlqEMbtXAQlMH/84mCAosRuuZtBfIqOZb6NmGzqRqYZimHAv3CevXBqxjMnGXK SPwjGjPBe4OvvEqM7JnuvfQ7UgGYpPHr4ldlBdZIE0Ivjs8s1w57OhzwqQlvWHqvAaxrgbUOSR I3THSOY25Io8vfmwf3lLCY848YvMHczaWfw2iCLPLwz+udHxTchgCkqqqvgdI+Y23NSigfEsxy dZ8= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41416551" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:40:07 -0800 IronPort-SDR: IiqBV6rRLBISyheVkTJnmfnOdWAhT7b4xXxtA4E6S1EZqoDxQWBMncstf0kOk8TC0eoqcSiMk0 LHM0mXT8p4kfg/2YDgRYcWLMyejnHGfILug+mPDWH1dYLlrbbNtwu/AuT/J1JOuvoVwD9yKl+z fKVRdLAB9uQd8lfYENQcmkKe1qlSUc9FLlNK+r8i9mCFoLOGrGZBR5UAfBbcVgChvU1p4GUTXy fCcYaH9DHCSlJlTo+83XPJs74sZaR44Q6II1EN8+/Lq5pfGtX03YmZW9JZKQLfMtuiK4AzFOGT cXg= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 28/49] Input: atmel_mxt_ts - orientation is not present in hover Date: Tue, 17 Sep 2019 18:38:54 +0900 Message-ID: <20190917093915.18645-9-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917093915.18645-1-jiada_wang@mentor.com> References: <20190917093915.18645-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer 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 cf77f46dd08d..570001131a65 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1029,10 +1029,6 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message) distance = MXT_DISTANCE_HOVERING; hover = true; active = true; - - if (data->t100_aux_vect) - orientation = message[data->t100_aux_vect]; - break; case MXT_T100_TYPE_FINGER: From patchwork Tue Sep 17 09:40:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148433 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 44C5E14DB for ; Tue, 17 Sep 2019 09:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2CA7B20862 for ; Tue, 17 Sep 2019 09:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727540AbfIQJlF (ORCPT ); Tue, 17 Sep 2019 05:41:05 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:19904 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727534AbfIQJlF (ORCPT ); Tue, 17 Sep 2019 05:41:05 -0400 IronPort-SDR: woX6AfIP+pOEdLw4/iWRL6dF1UtUhMk0mBIhCAokET67snKFy0tqnD5CccV3OEu5TckHGN33Dq m18TlwgrB/Qtg0BjaMlqTNkHCdeexYFSP6onQ0vV2VGIxeps6AgAwZRafrwg2d8U2D4hZD1Qt/ 0iYRVS3bDCkUBxCZgTStzDR1Ny6jDwarvf3eVmNSwT0s8i4rWIrmjLcUkAu982Rr6YjJVpDE5u QMSYPjQ8HjldraDEOjYOBE4EcHR4VPzxWPqYed7XdVHCziZBgGT8RHY5ovVpLvfm4g5Fn3Ik2G vKs= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41374162" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:03 -0800 IronPort-SDR: BO6LPUoRIqQiYTOUCPj362zQEXuz8NZB94m6tkr/HEGyKgWMhP5SGjOmPG/wspiY4QvWOG/FAu UIzhxcze3GoWYpPoerAw3n7sEoBTLka4Uk5kKLI+iaTUhj8R2qnIfsu3cyUwIvRVvOdb9IUCPz uG9mEqadfaBy/3NqzyDpMZa9M07GLPQKHR9jwTyOcVRZFkgVkWwMaGNyEUYT2CcoB2AGJjWlz6 kI/2+4fXvHEV4pIFDT0C8b7+F6zB3UMn6O8AyuqimihAZCrtvakAN/6i3ZrldQHJwz5AfhWmo4 BcM= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 29/49] Input: atmel_mxt_ts - implement debug output for messages Date: Tue, 17 Sep 2019 18:40:30 +0900 Message-ID: <20190917094050.18771-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Add a debug switch which causes all messages from the touch controller to be dumped to the dmesg log with a set prefix "MXT MSG:". This is used by Atmel user-space utilities to debug touch operation. Enabling this output does impact touch performance. Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 3c3fcfdd4889dfeb1c80ae8cd94a622c6342b06a) [gdavis: Forward port and fix conflicts.] Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 47 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 570001131a65..7cc127a529fc 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -335,6 +335,7 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + bool debug_enabled; u8 max_reportid; u32 config_crc; u32 info_crc; @@ -460,8 +461,11 @@ static bool mxt_object_readable(unsigned int type) static void mxt_dump_message(struct mxt_data *data, u8 *message) { - dev_dbg(&data->client->dev, "message: %*ph\n", - data->T5_msg_size, message); + /* debug message with prefix 'MXT MSG:' used by + * Atmel user-space utilities to debug touch operation + */ + dev_dbg(&data->client->dev, "MXT MSG: %*ph\n", + data->T5_msg_size, message); } static int mxt_wait_for_completion(struct mxt_data *data, @@ -1214,6 +1218,7 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; + bool dump = data->debug_enabled; if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1248,9 +1253,12 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T93_reportid) { mxt_proc_t93_messages(data, message); } else { - mxt_dump_message(data, message); + dump = true; } + if (dump) + mxt_dump_message(data, message); + return 1; } @@ -3522,6 +3530,36 @@ static ssize_t mxt_update_cfg_store(struct device *dev, return ret; } +static ssize_t mxt_debug_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + char c; + + c = data->debug_enabled ? '1' : '0'; + return scnprintf(buf, PAGE_SIZE, "%c\n", c); +} + +static ssize_t mxt_debug_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + data->debug_enabled = (i == 1); + + dev_dbg(dev, "%s\n", i ? "debug enabled" : "debug disabled"); + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3538,6 +3576,8 @@ static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); static DEVICE_ATTR(update_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); +static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, + mxt_debug_enable_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3545,6 +3585,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_object.attr, &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, + &dev_attr_debug_enable.attr, NULL }; From patchwork Tue Sep 17 09:40:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148441 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 CF15414DB for ; Tue, 17 Sep 2019 09:41:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD3C821881 for ; Tue, 17 Sep 2019 09:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728853AbfIQJlI (ORCPT ); Tue, 17 Sep 2019 05:41:08 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:19904 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728852AbfIQJlH (ORCPT ); Tue, 17 Sep 2019 05:41:07 -0400 IronPort-SDR: 34mWLzhuD9S6jHqyRrPy0ZvJIJ9AJ63k+vtDlwCxE9J1yFy2OZZ2h4Y1QW58zw1WkpKLgCQ4sK gBKQoJYWHzJcRy3UwpDjNSqnu+TWfuF7pQM2sMjSE96U7npnrAW8FFZftaGzqzHP6blLOf+Uim koWI7Tihgyrc0lfwDLgwpiHALXIvUrujbbgC9AYl4l0PQ8HOkSGMxuTTmnqredlJihwQ74WslS TQQNfNHvX5QtJZ3oft/hFPZRNshNbP1hMhy1QbOqBM8ZgdctKY+2RynFAeE0iEJFisXtuQvZf5 QVM= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41374165" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:06 -0800 IronPort-SDR: 5QItbxhvx5wc/UJ617gj5cbXwybEjc9mAKO6JYakRTd8kfNBlE1s1gCPTU3wUyXEp5iB68+wcz +5voI7xxUtfeZmxbvfH6HyhL3Ys7ytzm65Au8Kp4NB8McCUgvdYz9psMeefP67SNRcexy59S+u T4UO/he6BOaaSll2lSlMei5TDtH21JpTQlP0GlCxDK9jd/gJyKUlHQJfZi2cRXdWYZA+EM3Qm/ f2gcYGifgjlQAwhgNLq41f7g2ovoJqIV8CkCFnKQ2Ms0eW+khIfALtmbaQoVTaF2xV4bnC/Y0z 77E= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 30/49] Input: atmel_mxt_ts - implement improved debug message interface Date: Tue, 17 Sep 2019 18:40:31 +0900 Message-ID: <20190917094050.18771-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094050.18771-1-jiada_wang@mentor.com> References: <20190917094050.18771-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nick Dyer Signed-off-by: Nick Dyer (cherry picked from ndyer/linux/for-upstream commit 078569c13c88dcb6f8d882bfe17168587712df7d) [gdavis: Resolve forward port conflicts due to v4.14.51 commit 960fe000b1d3 ("Input: atmel_mxt_ts - fix the firmware update").] Signed-off-by: George G. Davis [gdavis: Squash fixes from Dirk Behme: - Input: atmel_mxt_ts - add missing unlock in error path - Input: atmel_mxt_ts - add missing unlock in error path - Input: atmel_mxt_ts - call mxt_debug_msg_remove() in error path - Input: atmel_mxt_ts - protect debug_v2_enabled by mutex Signed-off-by: Dirk Behme [gdavis: Squash fix from Vladimir Zapolskiy: - Input: atmel_mxt_ts - simplify debug_msg binary attribute handling] Signed-off-by: Vladimir Zapolskiy --- Notes: - Squash fixes from Dirk Behme: + Input: atmel_mxt_ts - add missing unlock in error path Unlock the mutex in case the function is exited in the error case. + Input: atmel_mxt_ts - add missing unlock in error path + Input: atmel_mxt_ts - protect debug_v2_enabled by mutex Put the modification of debug_v2_enabled into the protected section. Same as in mxt_debug_msg_enable(). + Input: atmel_mxt_ts - call mxt_debug_msg_remove() in error path Add the missing mxt_debug_msg_remove() to the error path. - Squash fix from Vladimir Zapolskiy: + Input: atmel_mxt_ts - simplify debug_msg binary attribute handling The change introduces several updates, but all of them are related to "debug_msg" binary attribute: * removed dynamic initialization of data->debug_msg_attr * removed mxt_debug_msg_write callback * removed wrong check in mxt_debug_msg_remove() * mxt_debug_msg_remove() now is not called from mxt_free_object_table() avoiding multiple double deallocations. [jiada: Add NULL check for sysfs attribute debug_msg_attr] Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 194 ++++++++++++++++++++++- 1 file changed, 192 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 7cc127a529fc..b3152aaaed63 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -242,6 +242,8 @@ enum t100_type { #define MXT_PIXELS_PER_MM 20 +#define DEBUG_MSG_MAX 200 + struct mxt_info { u8 family_id; u8 variant_id; @@ -336,6 +338,11 @@ struct mxt_data { u8 t100_aux_area; u8 t100_aux_vect; bool debug_enabled; + bool debug_v2_enabled; + u8 *debug_msg_data; + u16 debug_msg_count; + struct bin_attribute *debug_msg_attr; + struct mutex debug_msg_lock; u8 max_reportid; u32 config_crc; u32 info_crc; @@ -468,6 +475,144 @@ static void mxt_dump_message(struct mxt_data *data, u8 *message) data->T5_msg_size, message); } +static void mxt_debug_msg_enable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_msg_data = kcalloc(DEBUG_MSG_MAX, + data->T5_msg_size, GFP_KERNEL); + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + return; + } + + data->debug_v2_enabled = true; + mutex_unlock(&data->debug_msg_lock); + + dev_dbg(dev, "Enabled message output\n"); +} + +static void mxt_debug_msg_disable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (!data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_v2_enabled = false; + + kfree(data->debug_msg_data); + data->debug_msg_data = NULL; + data->debug_msg_count = 0; + mutex_unlock(&data->debug_msg_lock); + dev_dbg(dev, "Disabled message output\n"); +} + +static void mxt_debug_msg_add(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + mutex_lock(&data->debug_msg_lock); + + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + dev_err(dev, "No buffer!\n"); + return; + } + + if (data->debug_msg_count < DEBUG_MSG_MAX) { + memcpy(data->debug_msg_data + + data->debug_msg_count * data->T5_msg_size, + msg, + data->T5_msg_size); + data->debug_msg_count++; + } else { + dev_dbg(dev, "Discarding %u messages\n", data->debug_msg_count); + data->debug_msg_count = 0; + } + + mutex_unlock(&data->debug_msg_lock); + + sysfs_notify(&data->client->dev.kobj, NULL, "debug_notify"); +} + +static ssize_t mxt_debug_msg_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, size_t bytes) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct mxt_data *data = dev_get_drvdata(dev); + int count; + size_t bytes_read; + + if (!data->debug_msg_data) { + dev_err(dev, "No buffer!\n"); + return 0; + } + + count = bytes / data->T5_msg_size; + + if (count > DEBUG_MSG_MAX) + count = DEBUG_MSG_MAX; + + mutex_lock(&data->debug_msg_lock); + + if (count > data->debug_msg_count) + count = data->debug_msg_count; + + bytes_read = count * data->T5_msg_size; + + memcpy(buf, data->debug_msg_data, bytes_read); + data->debug_msg_count = 0; + + mutex_unlock(&data->debug_msg_lock); + + return bytes_read; +} + +static struct bin_attribute debug_msg_attr = { + .attr = { + .name = "debug_msg", + .mode = 0444, + }, + .read = mxt_debug_msg_read, +}; + +static int mxt_debug_msg_init(struct mxt_data *data) +{ + /* + * Binary attribute is not used in callback, removal is done by name, + * so it is safe to update a single struct bin_attribute entity + */ + debug_msg_attr.size = data->T5_msg_size * DEBUG_MSG_MAX; + + if (sysfs_create_bin_file(&data->client->dev.kobj, + &debug_msg_attr) < 0) { + dev_err(&data->client->dev, "Failed to create %s\n", + debug_msg_attr.attr.name); + return -EINVAL; + } + + data->debug_msg_attr = &debug_msg_attr; + + return 0; +} + +static void mxt_debug_msg_remove(struct mxt_data *data) +{ + if (data->debug_msg_attr) { + sysfs_remove_bin_file(&data->client->dev.kobj, + data->debug_msg_attr); + data->debug_msg_attr = NULL; + } +} + static int mxt_wait_for_completion(struct mxt_data *data, struct completion *comp, unsigned int timeout_ms) @@ -1259,6 +1404,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (dump) mxt_dump_message(data, message); + if (data->debug_v2_enabled) + mxt_debug_msg_add(data, message); + return 1; } @@ -2677,6 +2825,10 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_debug_msg_init(data); + if (error) + goto err_free_sysfs; + if (data->cfg_name) { error = request_firmware_nowait(THIS_MODULE, true, data->cfg_name, @@ -2686,16 +2838,18 @@ static int mxt_initialize(struct mxt_data *data) if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - goto err_free_sysfs; + goto err_free_dbg_msg; } } else { error = mxt_configure_objects(data, NULL); if (error) - goto err_free_sysfs; + goto err_free_dbg_msg; } return 0; +err_free_dbg_msg: + mxt_debug_msg_remove(data); err_free_sysfs: mxt_sysfs_remove(data); return error; @@ -3357,6 +3511,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) return ret; data->in_bootloader = true; + mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); @@ -3540,6 +3695,34 @@ static ssize_t mxt_debug_enable_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%c\n", c); } +static ssize_t mxt_debug_notify_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "0\n"); +} + +static ssize_t mxt_debug_v2_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + if (i == 1) + mxt_debug_msg_enable(data); + else + mxt_debug_msg_disable(data); + + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static ssize_t mxt_debug_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -3578,6 +3761,9 @@ static DEVICE_ATTR(update_cfg, S_IWUSR, NULL, mxt_update_cfg_store); static DEVICE_ATTR(config_crc, S_IRUGO, mxt_config_crc_show, NULL); static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, mxt_debug_enable_store); +static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, + mxt_debug_v2_enable_store); +static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3586,6 +3772,8 @@ static struct attribute *mxt_attrs[] = { &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, &dev_attr_debug_enable.attr, + &dev_attr_debug_v2_enable.attr, + &dev_attr_debug_notify.attr, NULL }; @@ -3875,6 +4063,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; @@ -3933,6 +4122,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 Tue Sep 17 09:40:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148435 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 E4595912 for ; Tue, 17 Sep 2019 09:41:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCDC520862 for ; Tue, 17 Sep 2019 09:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728888AbfIQJlL (ORCPT ); Tue, 17 Sep 2019 05:41:11 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:19904 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728852AbfIQJlK (ORCPT ); Tue, 17 Sep 2019 05:41:10 -0400 IronPort-SDR: t8jIqH9+LgaP2qLBioki9Sx3S2LEwlOJe01YKklO9kl6vYK1GEV7q55cuEmNTx+n0sqkhAHQI0 1+3NtV0SvdvNqYyxXDh03jmCke6ntRXNI7c5Ge7xMJ+WWy1ZN+zeetmTM0M4KqoqNse1OzQbr5 hIrjMKSXYPkprTxPo9KDmddth8xNIjN+r/5TLLrAQF9KW2tSpcwhowEGQLs6TWF4t+xybDOKM/ l4s5iapRj0ot6sdpSh5WqpTapHROwnDAFUJaIi81LKkEx4daLVKpypVHWZAa0tx1+SZ3p2JLW6 uO4= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41374169" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:10 -0800 IronPort-SDR: KUBxps6UohzZXT09EzcIO6hlGGywFtqNXSYyXQjwXhdKYnddNXegeBiUv4yygp1gyRKILgKaSR Wy1z6l1n/Wri9nsucLG1VoPcj3ddRo6me9Mg9W3gKZNTIfU8B7NIE1eh+lF2p7OrRVjHV/ct1+ L3Am6QuxNG0KnbIJvJE/4PjeZ5eVNZTBYxbnCPhhEqTJR0IKNl5B1e10HV/zGh3bkbOz/7qcf0 tKnZgX3CJyWzbJ4CdaGatwLR0q87ycQ1VtATNPK9ddrdcNWpTbcOurCcln/Qd7dO+CTe0DtGRw 3Nc= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 31/49] Input: atmel_mxt_ts - eliminate data->raw_info_block Date: Tue, 17 Sep 2019 18:40:32 +0900 Message-ID: <20190917094050.18771-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094050.18771-1-jiada_wang@mentor.com> References: <20190917094050.18771-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 b3152aaaed63..560fe8a3bf62 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -323,7 +323,6 @@ struct mxt_data { char phys[64]; /* device physical location */ struct mxt_object *object_table; struct mxt_info *info; - void *raw_info_block; unsigned int irq; unsigned int max_x; unsigned int max_y; @@ -2070,9 +2069,8 @@ static void mxt_free_object_table(struct mxt_data *data) v4l2_device_unregister(&data->dbg.v4l2); #endif data->object_table = NULL; + kfree(data->info); data->info = NULL; - kfree(data->raw_info_block); - data->raw_info_block = NULL; kfree(data->msg_buf); data->msg_buf = NULL; data->T5_address = 0; @@ -2241,7 +2239,7 @@ static int mxt_read_info_block(struct mxt_data *data) u8 *crc_ptr; /* If info block already allocated, free it */ - if (data->raw_info_block) + if (data->info) mxt_free_object_table(data); /* Read 7-byte ID information block starting at address 0 */ @@ -2292,7 +2290,6 @@ static int mxt_read_info_block(struct mxt_data *data) goto err_free_mem; } - data->raw_info_block = id_buf; data->info = (struct mxt_info *)id_buf; dev_info(&client->dev, From patchwork Tue Sep 17 09:40:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148437 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 9959E912 for ; Tue, 17 Sep 2019 09:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FF1C20862 for ; Tue, 17 Sep 2019 09:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728852AbfIQJlO (ORCPT ); Tue, 17 Sep 2019 05:41:14 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:19904 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbfIQJlN (ORCPT ); Tue, 17 Sep 2019 05:41:13 -0400 IronPort-SDR: 7VmPV8HDN59+teplCLJ81bLqsC9ive63rpjybI75YFpnYc6yc8JKZGm+zctGNLKE40uaBemzq6 EGRKyqfXdimW3NaPPVVmv3sqkvAAZvLaqnDtlhxCXCpJ/VQF2AV7Uu/ucm3JTeS8zW6HRDu+fD /eiwckeGGhRPWx4Gvb8KJtf6X9FPOUPZm7oIXbbNUcc8+E+bJGu6JK/UqbCtXCVR2QZDzwfcjN F4oMOrIAxoD7dcL0byOEP6LLjFOGjOSrN8TsL7JwXhVgUfGmam6BSoZMH5Vye000Nqxrw4DRro Y4Y= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41374173" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:13 -0800 IronPort-SDR: 9W69aUxy6R+McONLr2BNHxRXhOEL3y4cLV9jEV7pMY/DEy1EfWGjeu8QkO4V4JlLQhhNqMlAjX NaHH3sIgb4qfwDPJjEiFaSa/Ys3yP/npfggM9ywoorggt9R9mTW67b22MSp4NpFBP+z3M0cvrF 7qbkGchS+y1kI2G65MWadtgQF/qin5XwlAqRF1iR/kXcTLNa97BqrftTX+Rij99wtVWb0MU7nq c3RpyQ+Tyi69HQN3mV6LvVvujZcSCy0HYk4DnQxqb97vn499mY2htPUnvNzMBg835SUTBTNmq8 7YY= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 32/49] Input: atmel_mxt_ts - Change call-points of mxt_free_* functions Date: Tue, 17 Sep 2019 18:40:33 +0900 Message-ID: <20190917094050.18771-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094050.18771-1-jiada_wang@mentor.com> References: <20190917094050.18771-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 560fe8a3bf62..e441eab8b201 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3339,21 +3339,21 @@ static int mxt_configure_objects(struct mxt_data *data, error = mxt_init_t7_power_cfg(data); if (error) { dev_err(dev, "Failed to initialize power cfg\n"); - goto err_free_object_table; + return error; } if (cfg) { error = mxt_update_cfg(data, cfg); if (error) { dev_warn(dev, "Error %d updating config\n", error); - goto err_free_object_table; + return error; } } if (data->multitouch) { error = mxt_initialize_input_device(data); if (error) - goto err_free_object_table; + return error; } else { dev_warn(dev, "No touch object detected\n"); } @@ -3361,10 +3361,6 @@ static int mxt_configure_objects(struct mxt_data *data, mxt_debug_init(data); return 0; - -err_free_object_table: - mxt_free_object_table(data); - return error; } /* Configuration crc check sum is returned as hex xxxxxx */ @@ -4101,16 +4097,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 Tue Sep 17 09:40:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148439 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 8299B912 for ; Tue, 17 Sep 2019 09:41:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6ADC321881 for ; Tue, 17 Sep 2019 09:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbfIQJlT (ORCPT ); Tue, 17 Sep 2019 05:41:19 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:19904 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728948AbfIQJlS (ORCPT ); Tue, 17 Sep 2019 05:41:18 -0400 IronPort-SDR: M3VhhbSbFUCyp1lgxU4CZfFy788+72kUpJvEeWC51qjo/mePgPnJuhAi6vHyWkjGM6p8NTlhNF EbIrJ09ucrk0F45Dqskl1qoABakv9oc33nvvgYfov46Jx8zPNsWNdZdX+hVhCMA/6cDOk9AwAt mPQxdqMX3zSoz4eSBqQXjOLBNehCky2d1XVjXyDBqiUx23l62p+qhQ3n2YNIpttOqusR9DLiDj nppMl2lfACVMhvcEu/JoahNQT/ycBVmkRaZMniE5zgNVhFDA45v5VFRPen0YT8oGjFAx9AMSIV 0ks= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41374178" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:17 -0800 IronPort-SDR: uJnljcZ5Ph43tVqTL3BUWKZYpcLioibu3z/ntlshIPj4tgPouHl/OHqYENiwiAiTAjaikbTXEh S1oo09m/wGH+y0ou8XjmWjt32u2Ag7gltbMPk+rxhU3g5rX0JsR9rHEk6Tsd2aBgvZhtIGlmvc BGiwU1rQwxCJ8gOmdzH3aYDzGYaE+iA/GCKDdk0pTietbr9u91g+pH+SugDnnsJhriMmHK9906 2jEER4ZNojrmOTOWJ0IUN+uXlX3g6jpNg3gvrNrglDaQQD7482ldBsMFTRnsXLNB5I3uVj9pFz ajk= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 33/49] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Tue, 17 Sep 2019 18:40:34 +0900 Message-ID: <20190917094050.18771-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094050.18771-1-jiada_wang@mentor.com> References: <20190917094050.18771-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 e441eab8b201..bdc5088baea8 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1908,7 +1908,7 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) int ret; int offset; int i; - u32 info_crc, config_crc, calculated_crc; + u32 info_crc, config_crc, calculated_crc = 0; u16 crc_start = 0; /* Make zero terminated copy of the OBP_RAW file */ @@ -1971,30 +1971,6 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) } cfg.raw_pos += offset; - /* - * The Info Block CRC is calculated over mxt_info and the object - * table. If it does not match then we are trying to load the - * configuration from a different chip or firmware version, so - * the configuration CRC is invalid anyway. - */ - if (info_crc == data->info_crc) { - if (config_crc == 0 || data->config_crc == 0) { - dev_info(dev, "CRC zero, attempting to apply config\n"); - } else if (config_crc == data->config_crc) { - dev_dbg(dev, "Config CRC 0x%06X: OK\n", - data->config_crc); - ret = 0; - goto release_raw; - } else { - dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", - data->config_crc, config_crc); - } - } else { - dev_warn(dev, - "Warning: Info CRC error - device=0x%06X file=0x%06X\n", - data->info_crc, info_crc); - } - /* Malloc memory to store configuration */ cfg.start_ofs = MXT_OBJECT_START + data->info->object_num * sizeof(struct mxt_object) + @@ -2018,14 +1994,45 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) else dev_warn(dev, "Could not find CRC start\n"); - if (crc_start > cfg.start_ofs) { + if (crc_start > cfg.start_ofs) calculated_crc = mxt_calculate_crc(cfg.mem, crc_start - cfg.start_ofs, cfg.mem_size); - if (config_crc > 0 && config_crc != calculated_crc) - dev_warn(dev, "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", - calculated_crc, config_crc); + /* If the CRC stored in the file is not the same as what + * was calculated by mxt_calculate_crc, this means we + * have to refuse the config file and abort download. + */ + if (config_crc != calculated_crc) { + dev_warn(dev, + "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", + calculated_crc, config_crc); + ret = 0; + goto release_mem; + } + + /* + * The Info Block CRC is calculated over mxt_info and the object + * table. If it does not match then we are trying to load the + * configuration from a different chip or firmware version, so + * the configuration CRC is invalid anyway. + */ + if (info_crc == data->info_crc) { + if (config_crc == 0 || data->config_crc == 0) { + dev_info(dev, "CRC zero, attempting to apply config\n"); + } else if (config_crc == data->config_crc) { + dev_dbg(dev, "Config CRC 0x%06X: OK\n", + data->config_crc); + ret = 0; + goto release_mem; + } else { + dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", + data->config_crc, config_crc); + } + } else { + dev_warn(dev, + "Warning: Info CRC error - device=0x%06X file=0x%06X\n", + data->info_crc, info_crc); } ret = mxt_upload_cfg_mem(data, &cfg); From patchwork Tue Sep 17 09:41:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148443 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 337E3912 for ; Tue, 17 Sep 2019 09:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B96621881 for ; Tue, 17 Sep 2019 09:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728948AbfIQJlw (ORCPT ); Tue, 17 Sep 2019 05:41:52 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59521 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfIQJlw (ORCPT ); Tue, 17 Sep 2019 05:41:52 -0400 IronPort-SDR: S/2BoUMvGFoMuNLWaaxaR3Z/rrCThOn02QPpez5DVcRn6HHoNfSTYEVDH9kl3OPS+yj3OBZtgU lYYG5v7y4phQF+vIaNPnEOOZOr3zYNDVvB0Hj7/nT4k8VcDw+VSN58aaqBWS91iut0fU0opdvS DELnrDjD5VOPyOBl5HVMIFl+P1kc+LiHcWXSe4KxGkaq25CfU43yNFQZbKeovKYPXAyQBBtz9F h4orcRVOiIDrZFk3bR9E+Sk5pS+TsSseGjcxO/TnUQsCZIb2zy/YjoAOqWNETO/LI7E6IRj/K7 tKc= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223200" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:51 -0800 IronPort-SDR: rFfvGxdoeiV7Af0Kjqe+ephBZFvYLx+QNORmL/+6EUNouKSyjbAKBdLRAk9Spk0OYfT3ng8YPa TT+UuKYTImreUD9cUkTsWOG9ekrvZGCVqSVo5h6jiaDXqLqcrGZRcpfbpuvsMDnQMWSo6vSeuU IJvBN8NRoMXFdTMX1kMF8NVkhueGU7YMvC+DjaHMn8BDSlMvpDPwFmZz4KAeqpt3+D9afOMasA LeACRw1aCe9ECtBOQ44GPipy+qV6SDD93r0Yh7HAZ50+Kp8MMSTXedGDCsHENoh17vUfKz/4ri yMo= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 34/49] input: atmel_mxt_ts: export GPIO reset line via sysfs Date: Tue, 17 Sep 2019 18:41:22 +0900 Message-ID: <20190917094137.18851-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: "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 bdc5088baea8..4670880e52a2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4086,6 +4086,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) @@ -4118,6 +4131,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; } @@ -4127,6 +4144,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 Tue Sep 17 09:41:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148445 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 729BF14DB for ; Tue, 17 Sep 2019 09:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B70F20862 for ; Tue, 17 Sep 2019 09:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbfIQJlz (ORCPT ); Tue, 17 Sep 2019 05:41:55 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59521 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfIQJlz (ORCPT ); Tue, 17 Sep 2019 05:41:55 -0400 IronPort-SDR: h+f8eAdXMEpt3M/xWQI43brTxySYkFPubScoLZAnapYvkjDLW05KIw6UrVSuCfZrlcgZBs6JBf Nmxv72na5ahAzQU0XOT3aJtJDaf8kqEqeo1Zrh3TQmj/ji6gFttjFBDDTw5iCF9nIEHXBwa1i1 61B+zYMfwtSdwN1Vm+YiNlkaamiz5CTZMvHtY0UScm1tOgk2WbzMquTpkc1i0deHIN+fRoczBP b8Fw9SqgRaXd4LQ4pPm44PJeR9j5yknLrInyIZ5aSH1jWjJrgdWp3I3DVbQPTxkHeUmuht78MS ycw= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223206" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:54 -0800 IronPort-SDR: 13LxyqrJqej512kgfwMyxMFbe+/u+fp7/vyeuVHsibgEDnmBI57oXqX9K9K55DxzCukrUoKTyR 71lK/PWPQs4R7L3pzC8Ud5LGC+fS643FCP0CoWS0Ft9Y95MHSJAfg4mijXVN+T3Rz0XQT40wBf rxTWj+dKsoznfTwCcQuBaFuyDphi/r2PtVkLQdkm7uZ2uGkOmYYo6ODVJBk6Uxp2w9IdOKJW1g zVl3e5hWWT4VCT1mPimkcfYVhxGZQOGBHi/8VBxQ4+LK5IoIVZE5EDaNAlpSJOuBmnOmgDVRiM XQo= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 35/49] input: atmel_mxt_ts: Add Missing Delay for reset handling of Atmel touch panel controller in detachable displays. Date: Tue, 17 Sep 2019 18:41:23 +0900 Message-ID: <20190917094137.18851-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094137.18851-1-jiada_wang@mentor.com> References: <20190917094137.18851-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 4670880e52a2..4fa27e2f7163 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4113,6 +4113,10 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); + } else { + dev_dbg(&client->dev, + "atmel reset pin not found in device tree"); + msleep(MXT_RESET_TIME); } error = mxt_initialize(data); From patchwork Tue Sep 17 09:41:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148447 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 F24B817E6 for ; Tue, 17 Sep 2019 09:42:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDFEA20862 for ; Tue, 17 Sep 2019 09:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729032AbfIQJl6 (ORCPT ); Tue, 17 Sep 2019 05:41:58 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59521 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfIQJl6 (ORCPT ); Tue, 17 Sep 2019 05:41:58 -0400 IronPort-SDR: 21VfGCOQRRjKaRb2G9hJmkqqYdkoIoVkXmzWLbuTp6eLzU8mTlLr5WW35kNo3yoBEElfVy1Szt qFPSyBi8NA6b+W5BpUQxBDV142BEOiXguOj7/IFSCJxmfYtcX0O9Yd3JlMwGkWEY877ksv2ZRq 5j2zQQOFXRvUiTpYbf2J2aOu+fWXe+Y2UCvuvzxiXYqWXxsq3aFLpHlmzmbfEo3VvwvcCaDvm7 J+Cg6nvSYnzhNYl1VRGO1dchzAm27mImoq1Ph0MYgQBWMX4MLtFdFdrcmCJqqLjX1QmqSedOqk w1c= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223217" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:41:58 -0800 IronPort-SDR: 3/FSIpzBbzKqftZOSjx5GoB4F72HmmUrLbu8ONhExeq2pEWLKb+C8XC7mwuWiApIe3Tr42R5dE hEy+8uNWkaFcIguewz8cGOIfHmvR09TPKFEPTHehzUno1Ejn11nAnloW0QwtmSHZ0HRXEe7IQt ILQV1Sj1CKvnKK0hRhbcqFNL7rDcTxhAJ9EmWWSJDocY8jQ36lxgDcP7TxbIX6bhz6stb03JL9 NuBk7PNyaxL+tBiGYyxhGiZ0Hdwnn/RJYuMPZ7eUy1cJmEUZlfCaRZyYNTsDmUgeppe9X7QG1F m4Y= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 36/49] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Tue, 17 Sep 2019 18:41:24 +0900 Message-ID: <20190917094137.18851-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094137.18851-1-jiada_wang@mentor.com> References: <20190917094137.18851-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Nikhil Ravindran The self test object T25 runs self test routines in device to find faults Sysfs entry add to start self test routine and read back the test results for atmel touchcontrollers.The feature will be used for A-IVI and CAF projects. Signed-off-by: Nikhil Ravindran Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 4fa27e2f7163..183832e3bd71 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,9 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + u16 T25_address; + u8 T25_reportid; + u8 t25_msg[6]; bool debug_enabled; bool debug_v2_enabled; u8 *debug_msg_data; @@ -413,6 +416,8 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + + bool t25_status; }; struct mxt_vb2_buffer { @@ -1359,6 +1364,24 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) dev_debug(dev, "T93 report double tap %d\n", status); } +static void mxt_proc_t25_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + /* Output debug if status has changed */ + dev_dbg(dev, "T25 Status 0x%x Info: %x %x %x %x %x\n", + msg[1], + msg[2], + msg[3], + msg[4], + msg[5], + msg[6]); + + /* Save current status */ + memcpy(&data->t25_msg[0], &msg[1], sizeof(data->t25_msg)); + data->t25_status = false; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1389,6 +1412,8 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T19_reportid) { mxt_input_button(data, message); data->update_input = true; + } else if (report_id == data->T25_reportid) { + mxt_proc_t25_messages(data, message); } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); @@ -1613,6 +1638,84 @@ static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, return 0; } +static int mxt_t25_command(struct mxt_data *data, u8 cmd, bool wait) +{ + u16 reg; + int timeout_counter = 0; + int ret; + u8 val[2]; + + reg = data->T25_address; + val[0] = 0x3; + val[1] = cmd; + + data->t25_status = true; + ret = __mxt_write_reg(data->client, reg, sizeof(val), val); + if (ret) { + data->t25_status = false; + return ret; + } + + if (!wait) + return 0; + + do { + msleep(MXT_WAKEUP_TIME); + ret = __mxt_read_reg(data->client, reg + 1, 1, &val[1]); + if (ret) + return ret; + } while ((val[1] != 0) && (timeout_counter++ <= 100)); + + if (timeout_counter > 100) { + dev_err(&data->client->dev, "Command failed!\n"); + data->t25_status = false; + return -EIO; + } + return 0; +} + +/* Firmware Version is returned as Major.Minor.Build */ +static ssize_t mxt_t25_selftest_show(struct device *dev, struct + device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + ssize_t offset = 0; + + if (data->t25_status) + return -EAGAIN; + + if (data->t25_msg[0] == 0xFE) + offset += scnprintf(buf, PAGE_SIZE, "PASS\n"); + else + offset += scnprintf(buf, PAGE_SIZE, "FAILED\n"); + + offset += scnprintf(buf + offset, PAGE_SIZE, "%x %x %x %x %x %x\n", + data->t25_msg[0], + data->t25_msg[1], + data->t25_msg[2], + data->t25_msg[3], + data->t25_msg[4], + data->t25_msg[5]); + return offset; +} + +static ssize_t mxt_t25_selftest_store(struct device *dev, struct + device_attribute *attr, const char *buf, + size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u32 cmd; + + if (sscanf(buf, "%x", &cmd) == 1) { + if (mxt_t25_command(data, (u8)cmd, 1) == 0) + return count; + + dev_dbg(dev, "mxt_t25_cmd_store write cmd %x error\n", cmd); + return -EINVAL; + } + return 0; +} + static int mxt_acquire_irq(struct mxt_data *data) { int error; @@ -2091,6 +2194,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T25_address = 0; + data->T25_reportid = 0; data->T42_reportid_min = 0; data->T42_reportid_max = 0; data->T44_address = 0; @@ -2178,6 +2283,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_SPT_SELFTEST_T25: + data->T25_address = object->start_address; + data->T25_reportid = min_id; + break; case MXT_PROCI_TOUCHSUPPRESSION_T42: data->T42_reportid_min = min_id; data->T42_reportid_max = max_id; @@ -3764,6 +3873,7 @@ static DEVICE_ATTR(debug_enable, S_IWUSR | S_IRUSR, mxt_debug_enable_show, static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); +static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3774,6 +3884,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_enable.attr, &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, + &dev_attr_t25.attr, NULL }; From patchwork Tue Sep 17 09:41:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148449 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 0C894912 for ; Tue, 17 Sep 2019 09:42:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD61620862 for ; Tue, 17 Sep 2019 09:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729073AbfIQJmD (ORCPT ); Tue, 17 Sep 2019 05:42:03 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59521 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726953AbfIQJmD (ORCPT ); Tue, 17 Sep 2019 05:42:03 -0400 IronPort-SDR: iVsaakv/HXwLs782STA4VMsqpP84zP+PBPa5thHeH2EEgvf2uXF9GahOnfomfQlsGFI9JbktHW xx/70F7jGHnVgX3UzNG+72CT4FQ4PhwnWDHytvGZqs3PjNRYBcn+CTxBic/X3ZitLBwcGgDIOu OTL7wHkgpWvCKySxB7uUJ14oOeZs/oFWn2QtAUNAtEXoux4P/FTf+NLEd0Oq/4Br36fzIC9c23 EBAnhRITtgtJa0LntqAXOk79xIc9ihTMLrgxvRD8a69x73rxqdsMXuB6rOI7wE3tROuZA0ilZ+ TZY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223222" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:01 -0800 IronPort-SDR: NKSuicR6ELrmb3gdgOIIPSxlnSHmxU4URFsZu8foRbclL3j/DiVwbzxVbl8/Hfo17jcYiSoomY 09EwJ8qL/bLkBOO1fH27Dv8EdKUcmozwLSBL+6GH82UtvrUBrRoXazzEi/DO/CuSUZwMsWC/yv UV/0Xzux4QJn+0rXKBwfQtJpQEXhsZ0BW9noXq2k4BQ5qK0i/0MslMQYsSi+n87jYhysVXYK90 wRpRFso77USAriyrWqsDlsC8JT/72WE4P7L8Gx7FdJhL3/IWwPKqEk6sdhtCocfyoRGn/+p1Yv Jl0= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 37/49] Input: atmel_mxt_ts: Limit the max bytes transferred in an i2c transaction Date: Tue, 17 Sep 2019 18:41:25 +0900 Message-ID: <20190917094137.18851-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094137.18851-1-jiada_wang@mentor.com> References: <20190917094137.18851-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Balasubramani Vivekanandan In mxt_process_messages_until_invalid() function, driver tries to read all possible reportid in a single i2c transaction. Number of bytes read is limited by the max_reportid parameter. If the max_reportid is a very large value, then a large chunk of bytes will be requested from the controller in a single i2c transaction. This transaction can fail due to timeout. This is visible when the Atmel controller is connected to the SOC via a i2c mux hardware. mxt_process_messages_t44() reads the T44 message which contains the pending T5 message count. If the number of pending T5 messages returned by T44 message is too high then there is a risk of i2c transaction timeout while reading T5 messages in mxt_process_messages_t44(). New property 'atmel,mtu' is created. This property limits the maximum number of bytes that can read/transferred in an i2c transcation Signed-off-by: Balasubramani Vivekanandan Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- .../bindings/input/atmel,maxtouch.txt | 3 + drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++++---- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt index d7db16920083..62c93d94bc5d 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt @@ -42,6 +42,8 @@ Optional properties for main touchpad device: - atmel,input_name: Override name of input device from the default. +- atmel,mtu: Maximum number of bytes that can read/transferred in an i2c transaction + Example: touch@4b { @@ -49,4 +51,5 @@ Example: reg = <0x4b>; interrupt-parent = <&gpio>; interrupts = ; + atmel,mtu = <200> }; diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 183832e3bd71..5a31c1f50376 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -417,6 +417,7 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + unsigned int mtu; bool t25_status; }; @@ -1465,11 +1466,32 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) return num_valid; } +static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) +{ + u8 T5_msg_count_limit = data->mtu / data->T5_msg_size; + + if (!data->mtu) + return max_T5_msg_count; + + if (data->mtu < data->T5_msg_size) { + WARN(1, "mtu set is lesser than the T5 message size\n"); + /* Return count of 1, as fallback */ + return 1; + } + /* + * Return maximum number of T5 messages in single i2c transaction + * based on "atmel,mtu" property. + */ + return min(T5_msg_count_limit, max_T5_msg_count); +} + static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; - u8 count, num_left; + u8 T5_msg_count, total_pending; + u8 total_processed = 0; + u8 processed_valid = 0; /* Read T44 and T5 together */ ret = __mxt_read_reg(data->client, data->T44_address, @@ -1479,18 +1501,19 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - count = data->msg_buf[0]; + T5_msg_count = data->msg_buf[0]; /* * This condition may be caused by the CHG line being configured in * Mode 0. It results in unnecessary I2C operations but it is benign. */ - if (count == 0) + if (!T5_msg_count) return IRQ_NONE; - if (count > data->max_reportid) { - dev_warn(dev, "T44 count %d exceeded max report id\n", count); - count = data->max_reportid; + if (T5_msg_count > data->max_reportid) { + dev_warn(dev, "T44 count %d exceeded max report id\n", + T5_msg_count); + T5_msg_count = data->max_reportid; } /* Process first message */ @@ -1500,16 +1523,25 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - num_left = count - 1; + total_pending = T5_msg_count - 1; + if (!total_pending) + goto end; /* Process remaining messages if necessary */ - if (num_left) { - ret = mxt_read_and_process_messages(data, num_left); + T5_msg_count = mxt_max_msg_read_count(data, total_pending); + + do { + if ((total_pending - total_processed) < T5_msg_count) + T5_msg_count = total_pending - total_processed; + ret = mxt_read_and_process_messages(data, T5_msg_count); if (ret < 0) goto end; - else if (ret != num_left) - dev_warn(dev, "Unexpected invalid message\n"); - } + total_processed += T5_msg_count; + processed_valid += ret; + } while (total_processed < total_pending); + + if (processed_valid != total_pending) + dev_warn(dev, "Unexpected invalid message\n"); end: if (data->update_input) { @@ -1524,9 +1556,10 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) { struct device *dev = &data->client->dev; int count, read; - u8 tries = 2; + int tries; - count = data->max_reportid; + count = mxt_max_msg_read_count(data, data->max_reportid); + tries = (data->max_reportid / count) + 1; /* Read messages until we force an invalid */ do { @@ -4113,6 +4146,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 Tue Sep 17 09:41:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148451 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 3082E14DB for ; Tue, 17 Sep 2019 09:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 19D4520862 for ; Tue, 17 Sep 2019 09:42:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbfIQJmG (ORCPT ); Tue, 17 Sep 2019 05:42:06 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:59521 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729106AbfIQJmF (ORCPT ); Tue, 17 Sep 2019 05:42:05 -0400 IronPort-SDR: e2JwyG3KC32Nj3mjx8LWFGVrxsnheeSzU/0jlHsLhz8ctTBmd13zvgnJghCL8/souVH7vkjY8Q 1p0xdSJBHGiH+D2UsEfl0ct7O/8D/hRl6pfZABW/JqliG4sBhplzFCL35p+HMPmxCLVMoNLlVc Me8/HYDz+446GVBjS2co5BeZFKGNUskDlbRDyrMkNHXOVT1heyT1wRV1s1stwPdT2QI7Tp8RhF Rto2iyNEcu/GNwroeAFy7MeMdLkrOcGdFVU9YsOPClTD+23apfJtZsK9yyG/DUOmvshdHa1xFN hNE= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="43223227" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:04 -0800 IronPort-SDR: YOWbk8UlO0ninB242fZykyOir10Jt+ZF/BxRts2ZRD8BYOZqs7fwPzXkeO7tSMJ5ej778EUJLY hc1xW/qeWCKKXm0qjSdXS/aSOuWz2tbVYtK5f4TXkOEcOqhbPcc7mY35i/R2ci94XFZFkrP0J6 r6E0jThO5V94TRU75IocTe+zAcncLht2B+DBW9kZPpFmpHIRE+gcJMP5yaTpRQGARixhq1jTD3 W1wexbv5/8n3fZF++7giiXKGQwgvcBMK6Fx47c8PzqI6J4Jmy+HU8NVYp3Fxzv+nQD6XB1uL+p cKw= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 38/49] Input: atmel_mxt_ts: return error from mxt_process_messages_until_invalid() Date: Tue, 17 Sep 2019 18:41:26 +0900 Message-ID: <20190917094137.18851-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094137.18851-1-jiada_wang@mentor.com> References: <20190917094137.18851-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 5a31c1f50376..f2fa62289577 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1564,6 +1564,8 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) /* Read messages until we force an invalid */ do { read = mxt_read_and_process_messages(data, count); + if (read < 0) + return read; if (read < count) return 0; } while (--tries); From patchwork Tue Sep 17 09:42:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148453 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 89E7114DB for ; Tue, 17 Sep 2019 09:42:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71BC120862 for ; Tue, 17 Sep 2019 09:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbfIQJmk (ORCPT ); Tue, 17 Sep 2019 05:42:40 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22250 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729031AbfIQJmj (ORCPT ); Tue, 17 Sep 2019 05:42:39 -0400 IronPort-SDR: oO8viVRlg6tcSdGEsphuqyWao532FBUR3ib9iZ8iM7rS+miBZ2Eq52SjtLDiUcNMlJzNqkZ1K1 ENySNEstwLGkWlnvofBHLeKnv/pvWfE+LnLpXNg0rYRilBlatZy4DZ429lLWgrTJjHCfIcfgbo B6RwC3fVIWYnl42l2trVvL0mHaAxQKc70dVSESqYPLSkynjViYc5/Z4JFatbw7YhHNNQSwaYNh lm6dk2fEt/RloqtFXShiBaXTZ8x3vwuSmmOkwpBDBfJd/K4sFwVe1xszZY1d8N/mPIKl+c4Dvv /cg= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423272" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:39 -0800 IronPort-SDR: AsbjNxVso8FFMfLC+WHo9qWjZOwBZ8clKMGJDllOAn59SsGo0OMhaDYqaHly49bdJszKGhY8mG K/BTYD1aWU2nxXOclxioC45B85Crlr3f9k9NNgierjy91NNVKD7t/29qhvaZPwNa1+Dq1rc5RY 15YI15yuUH8KBK/yaPlKQxMRPaKCiiD0cmvnPPXH1JsH/+tDHz0W4aepKYYLeOp0Bn7qNSXK3N 8FHsFukqPe+TSTTEo6o6kfLBlo6DWedEa1idF3PXXovvdnUAQy3jko18o6c/6NQxVX9BWeNvhl 3k0= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 39/49] Input: Atmel: improve error handling in mxt_start() Date: Tue, 17 Sep 2019 18:42:15 +0900 Message-ID: <20190917094225.18927-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 f2fa62289577..2fac43da0a2b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3974,12 +3974,13 @@ static int mxt_start(struct mxt_data *data) switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: - mxt_soft_reset(data); - + ret = mxt_soft_reset(data); + if (ret) + break; /* Touch enable */ /* 0x83 = SCANEN | RPTEN | ENABLE */ - mxt_write_object(data, - MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); + ret = mxt_write_object(data, + MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); break; case MXT_SUSPEND_REGULATOR: @@ -3993,27 +3994,26 @@ static int mxt_start(struct mxt_data *data) * Discard any touch messages still in message buffer * from before chip went to sleep */ - mxt_process_messages_until_invalid(data); + ret = mxt_process_messages_until_invalid(data); + if (ret) + break; ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); if (ret) - return ret; + break; /* Recalibrate since chip has been in deep sleep */ ret = mxt_t6_command(data, MXT_COMMAND_CALIBRATE, 1, false); if (ret) - return ret; + break; ret = mxt_acquire_irq(data); - if (ret) - return ret; - - break; } - data->suspended = false; + if (!ret) + data->suspended = false; - return 0; + return ret; } static int mxt_stop(struct mxt_data *data) @@ -4334,6 +4334,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; @@ -4341,11 +4342,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 Tue Sep 17 09:42:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148455 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 593B414DB for ; Tue, 17 Sep 2019 09:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4185820862 for ; Tue, 17 Sep 2019 09:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbfIQJmn (ORCPT ); Tue, 17 Sep 2019 05:42:43 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22250 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729031AbfIQJmn (ORCPT ); Tue, 17 Sep 2019 05:42:43 -0400 IronPort-SDR: Id2txxyCopHDcIPsZIgMZ2m684nTqH07pICo5sZkrCEPazxB9tIBCg90EdDW81fZAqkfS6nnXE Hb9SWzX3E7Of08PDN33z6SAGJOKTkPaqkhInM8tu7GI0pAKVNLiTt6Cu0qVtwL4RjLERfNsHBS EPI8ASFqrTS4733HoynXxYY/jT+kQVju3shoVMFC7DwfN53MHHUdqsIK8yyA98u6PHG094WC80 8XO9AYEsAASrTH3Zu/tbYTsCz1vIBg403tYKZn5yPTVw3qbF1Z3bKKUFkVBBmAkI5DqrArmhAT QD4= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423274" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:42 -0800 IronPort-SDR: zzd8K7Fy7QSIx2Z46kbdqOJcQWBD9XpjfiZjtKNEiZsal5atj9+QN5+iceochZhnbLIItvdoBK iFWXDeyGy+zZG0KUlzgw+KxGqZK1tkuDkOQTZwCe9Wti6Intf3aHK6dGNxZr1FPeZYJ16JeulY pSznt2I7blYX1f86FwkA8EnfhtgXJgwnficLUWS27ETD9uGTV15SyZsepyjn99pwCEt+IawtTJ kHZtAzHcM9LFEgTs0cImaW0RZnJcneSZbNfSZa5JXjzZ/+E/aNLeOzr632jHO/xPzyCJAtY5QI hKw= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 40/49] Input: Atmel: improve error handling in mxt_initialize() Date: Tue, 17 Sep 2019 18:42:16 +0900 Message-ID: <20190917094225.18927-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094225.18927-1-jiada_wang@mentor.com> References: <20190917094225.18927-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 2fac43da0a2b..b260ac155b5e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -716,17 +716,13 @@ static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) return 0; } -static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) +static int mxt_probe_bootloader(struct mxt_data *data) { struct device *dev = &data->client->dev; int error; u8 buf[3]; bool crc_failure, extended_id; - error = mxt_lookup_bootloader_address(data, alt_address); - if (error) - return error; - /* Check bootloader status and version information */ error = mxt_bootloader_read(data, buf, sizeof(buf)); if (error) @@ -2923,6 +2919,32 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) release_firmware(cfg); } +static int mxt_bootloader_status(struct mxt_data *data) +{ + struct i2c_client *client = data->client; + int error; + + error = mxt_lookup_bootloader_address(data, false); + if (error) { + dev_info(&client->dev, + "Bootloader address is not specified\n"); + return error; + } + /* Check bootloader state */ + error = mxt_probe_bootloader(data); + if (error) { + dev_info(&client->dev, "Trying alternate bootloader address\n"); + mxt_lookup_bootloader_address(data, true); + error = mxt_probe_bootloader(data); + if (error) { + dev_err(&client->dev, + "Chip is not in appmode or bootloader mode\n"); + return error; + } + } + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2934,16 +2956,13 @@ static int mxt_initialize(struct mxt_data *data) if (!error) break; - /* Check bootloader state */ - error = mxt_probe_bootloader(data, false); - if (error) { - dev_info(&client->dev, "Trying alternate bootloader address\n"); - error = mxt_probe_bootloader(data, true); - if (error) { - /* Chip is not in appmode or bootloader mode */ - return error; - } - } + dev_info(&client->dev, + "info block read failed (%d), so try bootloader method\n", + error); + + error = mxt_bootloader_status(data); + if (error) + return error; /* OK, we are in bootloader, see if we can recover */ if (++recovery_attempts > 1) { @@ -2957,7 +2976,9 @@ static int mxt_initialize(struct mxt_data *data) } /* Attempt to exit bootloader into app mode */ - mxt_send_bootloader_cmd(data, false); + error = mxt_send_bootloader_cmd(data, false); + if (error) + return error; msleep(MXT_FW_RESET_TIME); } @@ -3649,8 +3670,11 @@ static int mxt_enter_bootloader(struct mxt_data *data) msleep(MXT_RESET_TIME); + ret = mxt_lookup_bootloader_address(data, false); + if (ret) + return ret; /* Do not need to scan since we know family ID */ - ret = mxt_probe_bootloader(data, 0); + ret = mxt_probe_bootloader(data); if (ret) return ret; From patchwork Tue Sep 17 09:42:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148457 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 1C48D912 for ; Tue, 17 Sep 2019 09:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04B0B20862 for ; Tue, 17 Sep 2019 09:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729184AbfIQJmr (ORCPT ); Tue, 17 Sep 2019 05:42:47 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22250 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727126AbfIQJmr (ORCPT ); Tue, 17 Sep 2019 05:42:47 -0400 IronPort-SDR: Uz7Uoz+HXUqceR0YYNkhUQfSmB7AmvXHyT3xbDfkYlTTu469tbHe2co7RXWMPWTUlcmKd/V08y Fa6Su33DVf9Y/rwDVBZPOIjWpZB4eR1ZktdoSOdYu7p5rjUqLbiUVVI8SfExt9jRD6dUGctYmD cdP92C8J87Ksol1wc7TDIoOMOOQD0nzdTi6FNubA8xTWYcQ2zFw098lMhej+WXF00DcIjqtUfb po+7NcMJ7H99z+IJRGrkkB3bDKTeL/DXe+b/9xW5yxv0ZHjLz2NhM/tvE9LCan4YyysRGDooSo AVA= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423280" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:46 -0800 IronPort-SDR: IPTI1h5A/nplM2DvMGSKGMVbgFaOKa05XvLoCC5ZmUXSNnCwje97w/KBtm2BvuPsx/4obMoMxt fIEqIRDPntkFmGDdYvxdTVaDb7NifX5rDRQhgSp56nf4Q+g+KPu68lXni81yVL2vcdNRrg9B17 4VP8mToMqmuj2fKxDMjiZjA2DxoOSe4iToyau5AiIFUr+GGVOxo2ZMCzkcdfbz+8Pk/a6CjvIK CDg5y2IyOWR90cy7oS03ed4lbScNdl7F3g+iyT2qIA8SpQheCaG9+YiYcsAMD6+5fmdY+PIvwK yzc= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 41/49] Input: Atmel: improve error handling in mxt_update_cfg() Date: Tue, 17 Sep 2019 18:42:17 +0900 Message-ID: <20190917094225.18927-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094225.18927-1-jiada_wang@mentor.com> References: <20190917094225.18927-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 b260ac155b5e..6198149438c3 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2186,7 +2186,9 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) dev_info(dev, "Config successfully updated\n"); /* T7 config may have changed */ - mxt_init_t7_power_cfg(data); + ret = mxt_init_t7_power_cfg(data); + if (ret) + dev_warn(dev, "Power Config failed to update\n"); release_mem: kfree(cfg.mem); From patchwork Tue Sep 17 09:42:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148459 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 D8487912 for ; Tue, 17 Sep 2019 09:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFFA720862 for ; Tue, 17 Sep 2019 09:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729206AbfIQJmu (ORCPT ); Tue, 17 Sep 2019 05:42:50 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22250 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727126AbfIQJmt (ORCPT ); Tue, 17 Sep 2019 05:42:49 -0400 IronPort-SDR: fRZZqrZCRodXqAM5cnC23sfJMVaZmGlwASW3CjsICPP1Mu01k2AdqvX03nAX+R3PuxYSWGHGYW 9nSMdf4RXo1WGIov9T3eSmY2WmRFbGdBs1mMItcasoqjFZt8Vas+jJYcxO51uecjmlQjAdUn8h zHrjXSwYm+GslEl5w7X8L2ICLHYkEPszAkqdevZ/gLs23/ruOXb6SS9SdImDdp1Trkcq4doZ2E XXF2ThiCsbzUJ6uzI5MDHBJpT0RKtJURCydlQ5HE1/l8du/0Pjo2hUwK5Jx/m4NO8Sv4GiYXPe qKY= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423282" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:49 -0800 IronPort-SDR: hP6tF02fU9FRyHRWqoIqutEKQ+wUsaFjQKcE5f5CeOi6PiHhv9PfjrXaRTloX9S7/Zw6z1crQU yaGXZjDtY37hqEr6yDhiNSADxeHQSpdC/aOm3Jf4MX1xeqfz4veSd2p7fkihn+X0pDVNQJKitt QBDSQGOeT697Rrr6Ibv7EJyhxhVYyElQcBD9t6/t53xSVUz/HTUNmcb4YUEQ5T82AItre0yQxa k3ix2hs0u8FBTQAJYd0HAusy+rRV/8orbLxIZaCMJhUjZIhKF70GfBXh7XijvL53/LFMsC5XYx hAI= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 42/49] Input: Atmel: Improve error handling in mxt_initialize_input_device() Date: Tue, 17 Sep 2019 18:42:18 +0900 Message-ID: <20190917094225.18927-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094225.18927-1-jiada_wang@mentor.com> References: <20190917094225.18927-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 6198149438c3..a13d6938de1e 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2762,15 +2762,19 @@ static int mxt_initialize_input_device(struct mxt_data *data) case MXT_TOUCH_MULTI_T9: num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; error = mxt_read_t9_resolution(data); - if (error) - dev_warn(dev, "Failed to initialize T9 resolution\n"); + if (error) { + dev_err(dev, "Failed to initialize T9 resolution\n"); + return error; + } break; case MXT_TOUCH_MULTITOUCHSCREEN_T100: num_mt_slots = data->num_touchids; error = mxt_read_t100_config(data); - if (error) - dev_warn(dev, "Failed to read T100 config\n"); + if (error) { + dev_err(dev, "Failed to read T100 config\n"); + return error; + } break; default: From patchwork Tue Sep 17 09:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11148461 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 73C3B14DB for ; Tue, 17 Sep 2019 09:42:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C7A021881 for ; Tue, 17 Sep 2019 09:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729255AbfIQJmy (ORCPT ); Tue, 17 Sep 2019 05:42:54 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:22250 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727126AbfIQJmx (ORCPT ); Tue, 17 Sep 2019 05:42:53 -0400 IronPort-SDR: JTIjc3XrehbU7QSLvG2j9/NVPz8KVK5ARLoIvH0vQiHl0hBnBHXLWxynATDMavAr8MvNsYN5Vj AYEeVZIJUuBuiwxS/PrEwfSqHW21UTrPSn3XSlJ2tumD7IEtaFm4XpHTergqS+AIVQQUjRAs1S Kt2jUgsX8x2ceJTegL99NyAIkfAlBhaBxbLmaWzsWbTKQULrUvkKo69OgdYA+55jVJN8xM44ja 7NwM+HJ36awE1VCfEAh2CL1Yj3EBnMiK0tDOgLcDzvTgy2jWbJ0nssgzRuIW5hYGaHGcFDhWjx iYQ= X-IronPort-AV: E=Sophos;i="5.64,515,1559548800"; d="scan'208";a="41423284" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 17 Sep 2019 01:42:52 -0800 IronPort-SDR: Dlt9K7ao993RuUoAbQZUryvhS5kLHm9AFXEYFCssWsMmTenSHSanH1Y3UDCw142zf2Lxy8jjst vLSVoRA3loEaIcFmBCBg1P2HFvCaPnzwemjdK8vFKT8nIHJoeg9yBUfdtfidNmgD+jQ+i9bhHx m+wDdrZZT2BezK6DECfApBwQiZ61E5Aul814DSrxpGvOu26CjDdJgUM9dUAeES1R2nbU8qioeg AAYDI1SPfRprvYJRTpeknby2zd///Pbk+BvoT/uY9zqNbihLYurN2DfE5+fKXGSM/Dpb166EQ4 oHs= From: Jiada Wang To: , , , , CC: , , Subject: [PATCH v3 43/49] Input: Atmel: handle ReportID "0x00" while processing T5 messages Date: Tue, 17 Sep 2019 18:42:19 +0900 Message-ID: <20190917094225.18927-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190917094225.18927-1-jiada_wang@mentor.com> References: <20190917094225.18927-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: 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 a13d6938de1e..93bb19cad7e1 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -76,6 +76,7 @@ #define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 +#define MXT_RPTID_RESERVED 0 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -1384,6 +1385,11 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) u8 report_id = message[0]; bool dump = data->debug_enabled; + if (report_id == MXT_RPTID_RESERVED) { + dev_err(&data->client->dev, + "Received Reserved ReportID 0x00\n"); + return -EINVAL; + } if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1454,6 +1460,8 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) ret = mxt_proc_message(data, data->msg_buf + data->T5_msg_size * i); + if (ret < 0) + return ret; if (ret == 1) num_valid++; }