From patchwork Tue Aug 27 06:25: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: 11116109 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 5CD251395 for ; Tue, 27 Aug 2019 06:26:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BA2120828 for ; Tue, 27 Aug 2019 06:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbfH0G0C (ORCPT ); Tue, 27 Aug 2019 02:26:02 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:14029 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G0C (ORCPT ); Tue, 27 Aug 2019 02:26:02 -0400 IronPort-SDR: aR5w3BRiRI7SAbQvuC0UCAz+8e6DvTewUyMAhZqKC4sjgBZaoGL+XrcoJbboqCMtfhp+61s/XP Qnf3kfOpbMp6IjekouCzQn/lkOB8NeDFg9CUMwEZfyy41X5Arq7LbzUW8o+ks1aAXa2j5YKpNV PHfv21O5hhMmAjbcBHSzpxAHzNlvBOAMr11wFPZoE07epLlWMD8zwtNSP1sQGZJn4e7pZ3RTs1 kDVViyITXfmlZCxlXZi1pRwy1ynMNofav6AT40KvBifGuQYyv6jUouLW5OxYTTQez0OMyZaNCA ojk= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40792612" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:26:01 -0800 IronPort-SDR: xDtgyR9A32fMgh0+uiXL5P6hEYnF43yRB2si8FMF0+TY0d2IcSYkhpXo1guINfSti7LELLaqB4 QgOXttoj0fiFd+LC/7uXnBomu3dDvlr/9bySVPJbrFV9XSXGoUTOrCyEiuC/NCSyy+4oUQCGxf jloIUF+gjLuTHIa60DKqtfOzo3Z3+E+r98xYao+GFwNrMiRPXqfReCzDaiYX9tRkUpRwyCbnhk B06CLjlgJmhjFCv3CqW1vw9MG9Mg1DZRlztTv4PaENSuYKAX/R/SSFjLaPpc5A9SSrEAAKlTiZ vpk= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 01/49] Input: switch to use return value of input_mt_report_slot_state Date: Tue, 27 Aug 2019 15:25:19 +0900 Message-ID: <20190827062607.19839-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062607.19839-1-jiada_wang@mentor.com> References: <20190827062607.19839-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 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 Aug 27 06:25:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116115 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 D3EED112C for ; Tue, 27 Aug 2019 06:26:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2AA320828 for ; Tue, 27 Aug 2019 06:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725890AbfH0G0G (ORCPT ); Tue, 27 Aug 2019 02:26:06 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:14029 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G0F (ORCPT ); Tue, 27 Aug 2019 02:26:05 -0400 IronPort-SDR: 4gri3ZyLokRzBJ4gMKCHC1VRf8ngKV08l562SiSNPA0CqASq5PEyw1veZyw8SA/aik0HPHOtoc aJtcRy5xS+HicSO70DOx8ReOcybKnt0sq1cJO8YGKJQCzPINj8pq2IXPj/8aJdGlt+7J0PliYJ rNG3SmzuX4Y0jcv4uSjo5+gTHybDPC8EAvql27uaYxiOSZyHI5vle8emrce07ptrwUEZGpoNtF TQTSqkx9kj+OMK8haRot4dvPhwdjtO/C+x8jEFaW7xUUAAFVqpf2dcC7a2PLtAAPlNV1ANTz04 4QQ= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40792615" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:26:04 -0800 IronPort-SDR: l2ZkHs+7d89GOlRGWjiPYtXtHuCLj2MGy5a8Hi4ogBuZJ6tL7lXkgiwFX/JpTPS8DEZgSi4LMX 6ldmwOOHd7P+Z776Gl2kqJwq4gP0e6rvNevnAgVXvzbs7TKHJhPdyCstoRaPed/qu+OtHCt4HX zFIrkSVPRsWeitnBmrPh/YTGQbGtoUq7tXZuW9nxEMPXopvwn6D0IKh57IogPIdtwwh8Agow2i xKkMWlvIRnnYIUswNUp9iKT3xmAg0ulnSmXDrMOulOyaFJwpJuSVtsS+h0KGA44e71O2htqsSb GRQ= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 02/49] Input: introduce input_mt_report_slot_inactive Date: Tue, 27 Aug 2019 15:25:20 +0900 Message-ID: <20190827062607.19839-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062607.19839-1-jiada_wang@mentor.com> References: <20190827062607.19839-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 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 Aug 27 06:25:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116111 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 E9629112C for ; Tue, 27 Aug 2019 06:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7D6420828 for ; Tue, 27 Aug 2019 06:26:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728547AbfH0G0I (ORCPT ); Tue, 27 Aug 2019 02:26:08 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:14029 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G0I (ORCPT ); Tue, 27 Aug 2019 02:26:08 -0400 IronPort-SDR: YFbD/W3whmblmFnXfeSiyExE0rlF4r84O+0hApTSXNe5+BpBmRoYGzooDubESeH2Zmgehu83/X VdStvtGHngwluHVldKAVVpzm3/0yGYSMsXh2G32sFOIRhD5lPhDNe8Ezc1g+Ox91xT0JTlQeMT qsQr/1zaMLxdBgkYsuSUNjZum9Gt+KxWAshQ0uFUkO8h3xawdvwlYv6CF9LE0EiP82urAHiUOp JK8HZhPP2yFSsPje/6Xi8iJJKr++EtxT75uAjQM6TDlWFrFkKUVd51Whi4pUVRW1/NKYlA+GrT LXA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40792616" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:26:07 -0800 IronPort-SDR: h6OMu8gJRaS7P8DUyQJtpwTPZV5SZDo6C6imJTY1PxeKitl/BAOamxORdRnju0foaQ9d5eaFUZ OZphlPU3jGfC85+dA2WZsY/D6QPH/x5Gy6Ml+seIBRc01ACNFJkQVlrDXCJvM1ODF/atBKthn9 a5Zpn/eRIxMYBbVlsKwdMv2WnrVEllZ50OLiWqkLZXooJjBT68EmhAnSZU7CbNjEkmXjuDr2xQ dfPegqLb+hXmjqiEaRIBwyixFPvXnP33GuyPki6D/jDyKSkWGWawzitwOcLYhXKqO1CvmYr5Lq 9q8= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 03/49] Input: atmel_mxt_ts - rework sysfs init/remove Date: Tue, 27 Aug 2019 15:25:21 +0900 Message-ID: <20190827062607.19839-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062607.19839-1-jiada_wang@mentor.com> References: <20190827062607.19839-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 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 Aug 27 06:25: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: 11116113 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 C40B9112C for ; Tue, 27 Aug 2019 06:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A279F20828 for ; Tue, 27 Aug 2019 06:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbfH0G0M (ORCPT ); Tue, 27 Aug 2019 02:26:12 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:14029 "EHLO esa4.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G0L (ORCPT ); Tue, 27 Aug 2019 02:26:11 -0400 IronPort-SDR: deMaSU823dgBoQNySzysGa751xMGdHKj/3jhFyfMZiHm6Kho61eieZ50z/YROHYnzZOXNFSNQ+ FdJAIkHzEliyxu8Dh21nHsfCQPGW22sNvUGIy4nPzw7RP+kBRnMCVofhbBCH1YRBXAQW+r2/IC HqptOmG1gUEOS2IMt8K+YemyrCtNGQqifw82o2ZY5kgZZNHijaUgZfDshd7lHxtfTmOsoj86Qi 5A1GpwULyU3YPYXKu+Y6RnPQjEALPmh0d6GkEq3xXL0ETiRjFZ6KMlLF1NSgvzv99Dc62VS5O5 0Iw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40792617" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:26:10 -0800 IronPort-SDR: Km58M5GVqQtlK//EYC7fR2bF56/dd/zb9xmeehTd9GxrmA9aoBR44nZLmmBQZnTrpcAW2wut01 GLwVnUqQDJ3qp4vyH1FX+nfqd7QXQBQ/CxQnBiP5WqYK9o/XanaMGYt1iQum/v5mANGGYpbyIh h2oAvWQnKpdphVkyM1Y4SR4Hr24dRBtVcg1lTcN3aCj138UWXa5muzzlb7+8CZdBrLtcHXZs9R YVRQlzXR9QH/jgq8cStdusx/oeMQoRVj3hOtEbT91tgymyAw5eA6jpiQv5IUEyGSgpUmWGp74b j7E= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 04/49] Input: atmel_mxt_ts - only read messages in mxt_acquire_irq() when necessary Date: Tue, 27 Aug 2019 15:25:22 +0900 Message-ID: <20190827062607.19839-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062607.19839-1-jiada_wang@mentor.com> References: <20190827062607.19839-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 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 Aug 27 06:26: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: 11116119 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 43EE9112C for ; Tue, 27 Aug 2019 06:27:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C15620828 for ; Tue, 27 Aug 2019 06:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725860AbfH0G1I (ORCPT ); Tue, 27 Aug 2019 02:27:08 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G1I (ORCPT ); Tue, 27 Aug 2019 02:27:08 -0400 IronPort-SDR: Vwo1SmWntcc2XD0RzxL8LM2B6x8zWC8cyzvLhQzoX/97r6ceUClZOqQGkM2rbfpx5AdXi4JN8Q udiQIzRpEjIoaUkBR1YpqnzNOvXwxyA9yiIeQkaTOpSPRdMODvoR/aaUXTdEhmcQMeGbna7d6s /mqL+EFJGZWAsPqj+JkBtn9g9u4ZX2pxC9T2+Wp/nqJ/T7cNIRyPegHZ5mt3XkE3LHwmlCQpT8 X4Oayn1CSkCnxAYyg6xu2UL8cjUfaqgbEuRJq8STpK+zhgWZPs1fAt+fHnH/V8NBIb5ZVLUTzW +uw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784445" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:07 -0800 IronPort-SDR: FFTRG1H3H1NsBhx2NcIrn8yJ/CgbRqxnmgbR4z49ED/mZJf5F7OCMl+WmfM80kBAIJV7W85dgR 9FMNgic3TdLS+wi1oPzDUiXGfU7upA+j+OV9RQlZgWIbLrx1n01V06/lOD1tUtkFVVuQ47eYAE WwN/b113oW6K2fldhhb+mOJcjrcd7CIfoSMuNQUtX7WaoRlV6bogo7xaIhHD7EGZv987h6vSS0 EJt5SOVyGR0GSJQvR0uWrldQ1P6ta4jx31TgHb3W40WFuNJUHsyZM1vzCtHFHRDT7OThNig61z glo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 05/49] Input: atmel_mxt_ts - split large i2c transfers into blocks Date: Tue, 27 Aug 2019 15:26:30 +0900 Message-ID: <20190827062714.20266-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 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 Aug 27 06:26: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: 11116121 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 6762A112C for ; Tue, 27 Aug 2019 06:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EE5C20828 for ; Tue, 27 Aug 2019 06:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727138AbfH0G1M (ORCPT ); Tue, 27 Aug 2019 02:27:12 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G1L (ORCPT ); Tue, 27 Aug 2019 02:27:11 -0400 IronPort-SDR: 0y3yOsApq7dTo5yva1IhMsJGysVUI9xVtaOt23t1hvrxIyikGvldPKuzk9TcMzMrJEKTgjzT3v hiw1hT5JHwo9eFH5ccBD3yXFThVzSQPFxhFNRYD6QNDajRyv0J9q977f9ob6JWP2vS+iKwP1/4 NXIGGo9kyR0NVdRRT8UxGCMHr8QHQhKo2FLY4T2lq5dykExJ8/3IwCLeeeK2LuLZ9qIEjQSCeD DAVesrlPMs0p4QUkr3eSEvv1tGRZZugS6BbIXzaJBR1NzlLU3kwr68WKRV1E2k5YARA/NbxzJH OuQ= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784452" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:10 -0800 IronPort-SDR: dxABODJawA1xY60rMequbA8J5j6uY0DGfnQP+dDyXqQmw1TPzTiz1GmRLxqugOJ8yWSFLEiwTt gbFCMjadasw6Cay6OxriNMHd/20Dpc3JY8U4uYbswLu5PcRm6kgJgQBPwaHyn9i17cuO7/37fr a5eIGRHuL9PDFPBkq+fEcVKQm10XwZVnTXxE8gVJxD2kgYNpjtl18RUyMOa7fIftcVDzIfYN4C NdPEEZPZZrta7ZAk2h1FlMvQ+g18SMvLNAeFZCwc/4PE4ia046EocsSmeePC6lgNFZuiRp4Wyl gZY= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 06/49] Input: atmel_mxt_ts - output status from T48 Noise Supression Date: Tue, 27 Aug 2019 15:26:31 +0900 Message-ID: <20190827062714.20266-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062714.20266-1-jiada_wang@mentor.com> References: <20190827062714.20266-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 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 Aug 27 06:26: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: 11116123 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 CE65D13B1 for ; Tue, 27 Aug 2019 06:27:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B731420828 for ; Tue, 27 Aug 2019 06:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbfH0G1Q (ORCPT ); Tue, 27 Aug 2019 02:27:16 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0G1P (ORCPT ); Tue, 27 Aug 2019 02:27:15 -0400 IronPort-SDR: g2YduF0gjitfvOyG2ay52WuErGRPkR3oz9HErhZDvw9K1FVovhPJPhZ7JP7WKx8Sxith6D+M5c 5vIgGFK0qfal17dYDUBcB2iTMVflYDLPSGWdEs6LesZ7pa5tx3cA4rOK8ta3E2Ta0od+0jNx7l QCLCAeLykwfrF/ldwW+ggUo8sgrpJZbfHubTljlqeSRaafRokVbsmPrmK4QNfobWZUEcbb9b13 GY+x3PLaLFmSGsjysgceJ1BeY6CRZi0HTFnxHoTQ3YOzCvoRansto1b2gEOx9ddRZMbeqnZg5O Wm4= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784456" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:13 -0800 IronPort-SDR: n2mKXPcs6M0YVvFT/PI1FUZ96FSgN13cAxCZ7nBmy81CAwk3cR9gmDE84FQS3q0p02DQMwadhn RCqYLo/MBTvFOb2YjXbtZpkWeAy1xGtzQ5svOgG8Fucu+KykIwZSPh3QS2Bo7wz0X7ukJCyvv/ RGvwvYTXbJya0qsy4V/8PZff7LVVMm4uWdczFL/Vzwt7O07HyVVgZ0BcEwlkFRiix8eitvztGC 9m2oWrKOBCtH/Qij2nPYyd2RdZsz4Ai1Jof0Omh/TmWQxhbLt3aLbSoKAm2xO3N6C1jkttS4ex qrc= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 07/49] Input: atmel_mxt_ts - output status from T42 Touch Suppression Date: Tue, 27 Aug 2019 15:26:32 +0900 Message-ID: <20190827062714.20266-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062714.20266-1-jiada_wang@mentor.com> References: <20190827062714.20266-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 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 Aug 27 06:26: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: 11116125 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 80D2C112C for ; Tue, 27 Aug 2019 06:27:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68CA120828 for ; Tue, 27 Aug 2019 06:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725825AbfH0G1S (ORCPT ); Tue, 27 Aug 2019 02:27:18 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728680AbfH0G1R (ORCPT ); Tue, 27 Aug 2019 02:27:17 -0400 IronPort-SDR: orlQHwcq1zVCudeQOtxMu3EkUBpXbvnEegaTR2mqejmzXN7tQJN82VyK3JWxJGuwZEQs9uiXt/ fe2wPJ+wK9Llik0PkulUs9HhEP1gK4MmjOvMl/lFOa2M4FXrYiMg8sppJ/GLcO6QSRseJi+Zu9 SyAeUjVP44bjSXdu63lsiP7A73J5p0mw4ayix7+WCVRTbFjCNuQhM8B4xyVR35+jxHhcWgX/MR sSPSOo69Epz98h9+baWygh8FY7MwlF84r/jbFkWnSt450U/Zz+eL6vQ7nAVbqefU+0NzsUCJTY 9ng= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784458" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:16 -0800 IronPort-SDR: QlUlGzlYXEXcpn7lTxRNECzUmFdHvGMB4gdRG5QzXEqM+uwgFxphh6l4VlFSBxHELV3e3K4OAD gTWBaGROY1Pd6kpFxS3zfCyIb1WRNNZCighTFrbduU6Sfn6jeIauV+qCHWhaeaG7HHy31uqPcl KLW2SLvvfSOb46y2jknKSHQH56eQGKFyH+eLpiVY618wMnD5sX/iJSMfvRfHu5geaR0m66IEe7 gWfsj1SHcDCov2EeTBCpR9S66OEzohxAZr55lmCPmy0C7aH1/VNv1gE0k0nKo+7Z1DDwFHri9V CbI= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 08/49] Input: atmel_mxt_ts - implement T9 vector/orientation support Date: Tue, 27 Aug 2019 15:26:33 +0900 Message-ID: <20190827062714.20266-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062714.20266-1-jiada_wang@mentor.com> References: <20190827062714.20266-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 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 Aug 27 06:26: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: 11116129 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 536751395 for ; Tue, 27 Aug 2019 06:27:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31DB720828 for ; Tue, 27 Aug 2019 06:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728723AbfH0G1V (ORCPT ); Tue, 27 Aug 2019 02:27:21 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48109 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfH0G1U (ORCPT ); Tue, 27 Aug 2019 02:27:20 -0400 IronPort-SDR: CdOlqr/wnDPhHmYW9LnMUI5kmHQ5kreEhEwigORo3SbGBKAYgHMUlS/u9KiF7mZ3CwdjynRDin uw9qzgm+t4MACW5bfWBwW+gSp8ORAB5fq6ROx3mkyKXDxKpc1uhEbXqA/YNEqJN3IsXsd3CJGR KBk/X9eEVmX51bBeOojqb3/n5UULf4oTweDORofsCnQOlKusTom9l2/5neRIvKDBc0F6IJyeFJ 1PakDHpRWcAoQz5Tl2fkvs6dNvm/LHgvSHhnY+LBLs0O/An96WPjVKF0jPnZ9YFXzoppD/pKMJ CNY= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784459" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:19 -0800 IronPort-SDR: 1YW/eCEGr+wlaTk2E7CAXpjjatmjsCfQTYRaI04iAy07cNlQWk2bYVNEwVHwi+XBajNcf0Qv65 EDEag8ACvrV4jAWaJBo5g30DybFJgXOL7QEmTxnLcX4O/xUd4b2BUj6GTlljhsUZpi6UN1Ze5r pvP6pVxlNhtAKDFyc8La8aaZMEMB2q9JS9ESN6t8Zeh9rKkzId9iifLcfD2+0Ai7+BkGqxY3jU Vvv0CGK48XjGUMewwLfYBo3UmVyc4pKNvmtKJTrZAgt7dE2lno0OFz0TUNcIK2jpKBbw0N2h3g FnI= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 09/49] Input: atmel_mxt_ts - implement T15 Key Array support Date: Tue, 27 Aug 2019 15:26:34 +0900 Message-ID: <20190827062714.20266-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062714.20266-1-jiada_wang@mentor.com> References: <20190827062714.20266-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 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 Aug 27 06:27: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: 11116131 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 A99F5112C for ; Tue, 27 Aug 2019 06:27:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9164820828 for ; Tue, 27 Aug 2019 06:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726278AbfH0G1r (ORCPT ); Tue, 27 Aug 2019 02:27:47 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11303 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfH0G1q (ORCPT ); Tue, 27 Aug 2019 02:27:46 -0400 IronPort-SDR: POiWoD+fjQW1h/3uoVqtOhoRqHREnd7dpebxzHin3cleGS0Loarz4sOrO5dPMXHXcHeY6G/w4G YeFYSHBxn09Sk1OYK0ITupVmuzWbmRMMqAOi67CoBRir/4HGjEM9ojgPL35xQsCiMJkDMmk70n XDNM7kUogt1+cX1AO5Lkqj7VccpzAPcaq/Uz8b6Fb5G3ANfMd1yoQvJZdHCUF/cz68hX6EImlX 61xPJVt7bHb7SLuuPeq7vhlZyF4ZecU2rg830qiL949WOS10je3hBaHqjWeSeDNdZzdWGFhgaG Y0Q= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589343" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:45 -0800 IronPort-SDR: S2IbBDh9nCtZwB1J0w2uGhbIH2yOm+9Fpb2dzAXHP+r27qHvwY7fUoWGHEJrrBCY2UnPpkW8sO BfHxqCUVPCn3jpEscZWROaB6cIXy6LQVtGZeEcUGwCfWHcOBsrdUt/H7dYO7a8manjgEqLKutR 9Z4flUOQIHG2NBXg1WT3fgKCFLyOzOqR0EtvC/MB3Bgyd51sU4+g/BLoGxTs0ObUgte12H+QgI Of89BxN3dpIJZIXh2dn01qLnHLM6h2mMZKzvFr7Am0aHNINovnT++Fd/QR2kVQsS9veIeNybp1 X0g= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 10/49] Input: atmel_mxt_ts - handle reports from T47 Stylus object Date: Tue, 27 Aug 2019 15:27:17 +0900 Message-ID: <20190827062756.20380-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 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 Aug 27 06:27: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: 11116133 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 6A651112C for ; Tue, 27 Aug 2019 06:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47E7120828 for ; Tue, 27 Aug 2019 06:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728579AbfH0G1u (ORCPT ); Tue, 27 Aug 2019 02:27:50 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11303 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfH0G1u (ORCPT ); Tue, 27 Aug 2019 02:27:50 -0400 IronPort-SDR: CQDC/9Vjz/ACrkjiuBR2blqmGODTqaGoH9w0yMBeyEe/cjLSYkPWO8PMcUkZHsY2mKI5+Ff5JW P0aJRy61/kJf0FhtkgFEXFD2jFVf/FurTZu3DYZJw6dc+h5sEPjwUwmRLOZ238vTw7voO4xnRv kn+4SO/56j+tB1gtYhLngkDnRxPtJGb5PvoQDUGEriT3wDh7qzFV0Ebx8bHBnftshE0E6vyk6h 3MGjcZo8dApAT2/SFbW/YXZle6am83tZMqHakntzjlzQxRM2e9tfBN4qpuq7YNdX+EQelp/qas 6CE= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589345" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:48 -0800 IronPort-SDR: pl92nfEN1dMVXdqEc2pd06iMZgPwfyTtxxJ134ZabZTF3P6czjjnAvEzDnKf0JbcWtsF2CFa+M MtnEF8mUTYS3UNJ6BbMys22SxkLIdXLxxGq8JNEmU7m1lNgc4pXGpl4ZKqc4frPzYlnx3L2MzW sa3GC+R0we8dMBceee+ZqOBl464JtkG1VkC8XpavKxQsVtfvv4oqNR6sw3Lyy+Tp1A4U5rQLd5 XV1U0VesYh1uhF35IdH6k3Eg6sjzeQilHYbyMA3DaepT1kL7J9cgOZ+ujo8NIymmVXQEKihNyM ZPo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 11/49] Input: atmel_mxt_ts - implement support for T107 active stylus Date: Tue, 27 Aug 2019 15:27:18 +0900 Message-ID: <20190827062756.20380-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062756.20380-1-jiada_wang@mentor.com> References: <20190827062756.20380-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 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 Aug 27 06:27: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: 11116135 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 329A6112C for ; Tue, 27 Aug 2019 06:27:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AD8D20828 for ; Tue, 27 Aug 2019 06:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728792AbfH0G1w (ORCPT ); Tue, 27 Aug 2019 02:27:52 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11303 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfH0G1w (ORCPT ); Tue, 27 Aug 2019 02:27:52 -0400 IronPort-SDR: 8L/n9om6DQj2ZhU9Q5nY0XiHx6cBPpTei2q8sOJubxsYAdUEVbfh7ajrJtu2OQ3tf4WyVCHzjl /GpJvQoiJ3tsBuuJOpwcVn0J8XOUgFPkRhdxxK62kKExvErr//Hr7JFcnasrreV/hJEzmKmPXd tbIxgyQZSVkHtBu8IdoppOYJZoQwvH/UcqyxrufKO0npcosbheHK2EvI0rV3x8e/g1FVmwF2Sk YSA6b3Z9eNwtBIoSTdf41mNTI3rnD9fqmgP0viaB09cgBK8kiGYdDUgUz1elcCke18BmnF3cyb ZuQ= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589347" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:51 -0800 IronPort-SDR: b05IUv7Tc4c9Z0TaATr5D0m8ntk56jXCqWK4KpQw9FI9k/QSGLw7QjVZ7j8WcfhNPAzsG7u1T5 fbEevv5T0QoLarWUN8SkCr2jA6O4KkL/Tl4csw5/Qd9L1JFMo5jL7IHOtnGWCODtjhVRqiIuMv ijPxytUXASE+eRtjCJUbCaHy2SKdbH8R/K1ml+jx0F1aVTe11JSFkhz2dcWL41WL9lCb65csMY pW3PFDesSHcj/zPosiB0C6FPqolqkX8Pz5Kib9YR9/rYy19wKiunU3UmnG/lEyMdwFwEPrSVkJ 13g= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 12/49] Input: atmel_mxt_ts - add debug for T92 gesture and T93 touch seq msgs Date: Tue, 27 Aug 2019 15:27:19 +0900 Message-ID: <20190827062756.20380-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062756.20380-1-jiada_wang@mentor.com> References: <20190827062756.20380-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 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..26861252c088 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -71,6 +71,8 @@ #define MXT_SPT_MESSAGECOUNT_T44 44 #define MXT_SPT_CTECONFIG_T46 46 #define MXT_SPT_DYNAMICCONFIGURATIONCONTAINER_T71 71 +#define MXT_PROCI_SYMBOLGESTUREPROCESSOR 92 +#define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 @@ -349,6 +351,10 @@ struct mxt_data { u8 T42_reportid_max; u16 T44_address; u8 T48_reportid; + u16 T92_address; + u8 T92_reportid; + u16 T93_address; + u8 T93_reportid; u8 T100_reportid_min; u8 T100_reportid_max; u16 T107_address; @@ -1113,6 +1119,24 @@ static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg) return 0; } +static void mxt_proc_t92_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + dev_info(dev, "T92 long stroke LSTR=%d %d\n", + (status & 0x80) ? 1 : 0, + status & 0x0F); +} + +static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + + dev_info(dev, "T93 report double tap %d\n", status); +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1145,6 +1169,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); + } else if (report_id == data->T92_reportid) { + mxt_proc_t92_messages(data, message); + } else if (report_id == data->T93_reportid) { + mxt_proc_t93_messages(data, message); } else { mxt_dump_message(data, message); } @@ -1814,6 +1842,10 @@ static void mxt_free_object_table(struct mxt_data *data) data->T42_reportid_max = 0; data->T44_address = 0; data->T48_reportid = 0; + data->T92_reportid = 0; + data->T92_address = 0; + data->T93_reportid = 0; + data->T93_address = 0; data->T100_reportid_min = 0; data->T100_reportid_max = 0; data->max_reportid = 0; @@ -1906,6 +1938,14 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_PROCG_NOISESUPPRESSION_T48: data->T48_reportid = min_id; break; + case MXT_PROCI_SYMBOLGESTUREPROCESSOR: + data->T92_reportid = min_id; + data->T92_address = object->start_address; + break; + case MXT_PROCI_TOUCHSEQUENCELOGGER: + data->T93_reportid = min_id; + data->T93_address = object->start_address; + break; case MXT_TOUCH_MULTITOUCHSCREEN_T100: data->multitouch = MXT_TOUCH_MULTITOUCHSCREEN_T100; data->T100_reportid_min = min_id; From patchwork Tue Aug 27 06:27:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116139 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 A9138112C for ; Tue, 27 Aug 2019 06:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9187D2184D for ; Tue, 27 Aug 2019 06:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbfH0G15 (ORCPT ); Tue, 27 Aug 2019 02:27:57 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11303 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfH0G1z (ORCPT ); Tue, 27 Aug 2019 02:27:55 -0400 IronPort-SDR: Pf1Z3TGykqhaR529ZsyhGBC+Fgi26M4TL+rCfu+7aRh9WM5yHTXMYmFjfxHfZzHCqoGdbTUmcB b38D/MWjRqTay9RMahEWlYwJUg+saYXJJc1f41YyuYH9M2cvSBoTJuWdTVPRyGpdEnTw0Y75QF 2GUHAnL1WNq5g7zjE2Uo9MWnEUqMzwIxzQfO6CdocVt2ntBnbiUaG9jsYRvJT2bzTtHBpaAJt6 NSbhxYkuavj69HdPkJ3TTmYFcwez5/Tjq4AUSr23GlfJgi2sNMCB3L1TmGBt6tBnlkOK1SVoZQ QjA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589349" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:55 -0800 IronPort-SDR: 6UVFIl3CEmN1jkJ6tBLgiAZZ0MVWjCaEHmBwLsZDFz1LG9D7c1BK9/nvlRT89D2YC+m5wMt4YC Z8BVRJUsdxdkDtHcdpqWAL4BrWiccWouOd/1JlJCCq8t5bp1W0XsvlzqFPm8A3dzJx7c0K63Q5 4NBWzrGI8O87YPPvPm09n7iiK8vH7T54Bz1vXaZFUDcsKWMqIeQ6O6DH1IYqJ2ag3sQ1iDFmUn 7+cdGThhFeGf1Tk0OPKFWSXAM2IYZWxvLd/5OXcVc+xzVy5vl9GSnPvwczw/Oc00dwOlDSolbw FoI= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 13/49] Input: atmel_mxt_ts - release touch state during suspend Date: Tue, 27 Aug 2019 15:27:20 +0900 Message-ID: <20190827062756.20380-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062756.20380-1-jiada_wang@mentor.com> References: <20190827062756.20380-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 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 26861252c088..4d28b30c4f76 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 Aug 27 06:27:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116137 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 4BE711395 for ; Tue, 27 Aug 2019 06:28:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20D7D20828 for ; Tue, 27 Aug 2019 06:28:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726125AbfH0G17 (ORCPT ); Tue, 27 Aug 2019 02:27:59 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11303 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728834AbfH0G17 (ORCPT ); Tue, 27 Aug 2019 02:27:59 -0400 IronPort-SDR: snigPwSMN9jwyYolbOC9gNnOzhXbWtPrPZrVDdg1emj0G/ONoNWY8Mu4xmMstF0wSbcD1j2KDV /G1NJ7KSGo+p+Ul2I9tRJidwEjEAHbDkhq3+2ZyKNtdSYp8PTOjtAc3G79mThuFH8Lf9EhA3fk DKtJWregEmbyPN+AIa5I4TemlseV9l098mX9dlTFBtHk7ymoOPNM2HV9QB4ESPcJkhN9puBrwe yU0GJt+6iNNLCw8ra5Hvs9YZqbCRbJbCG6t6Y2nQSCTVQJHfYEtzJ/+W5fwbt1+ytAEAvdMat0 Y5g= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589350" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:27:58 -0800 IronPort-SDR: mCPbAcANJvlSJ3m48T9pgunSr3I7uCecqrqe3WPW+yk1clHCgV3ciG6Fh41vqy0xkhrDxajoVW kMQv1XK3qUAiAwL4nLPPFlGsiLZLaZWG8moNMmZS2+yWCwpsO1yi+VFkoTeIxdvy/VJpmPDlhG K1UHMQbvD1LR9Nobfz8DMgxdR1PzfpA88b3VdK7FK4mJUDSDxwSc0wbE8j+vPaZFWJMvWXM50v 0skUA4IVXMfHJ2sBqE6m599mYCH/vASnFe/AYCNpo4B09Xk+/MDLoLS1ErZ3p3FwR7mntwF9Bw ZsQ= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 14/49] Input: atmel_mxt_ts - add regulator control support Date: Tue, 27 Aug 2019 15:27:21 +0900 Message-ID: <20190827062756.20380-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062756.20380-1-jiada_wang@mentor.com> References: <20190827062756.20380-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 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 4d28b30c4f76..83ac2f1ba3be 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 Aug 27 06:28:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116141 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 94F6C112C for ; Tue, 27 Aug 2019 06:28:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C7DD20828 for ; Tue, 27 Aug 2019 06:28:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728547AbfH0G23 (ORCPT ); Tue, 27 Aug 2019 02:28:29 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48162 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbfH0G22 (ORCPT ); Tue, 27 Aug 2019 02:28:28 -0400 IronPort-SDR: v0Y50xQ2vwMJmgTtENHtrkMLPpQOPnl9v21c9W+mVYALVdBb4U7BVfTpfoHrj1nKHqEXEQzJAj WNJ7TUk2Ie0AHRJJlDfjSE2HVDmD68xPs3SKCiSlRN+c2v35fruG8H7T4pXAHNqbEpgPlJSOKl qEnl0UEhihZHRMkGNj8PsPmxYfgWAsNQ8KTOVE410X37xPC6SxwNFBmlXH7C3/dXazFPJ9LLCt 5wT3F4Zh2OhRU1mY9I0ZgVNpaVS7iKKmccJUzHpkI8wGIJjMlYf3MeTecE3/d2jkcf42mk5moO ems= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784482" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:27 -0800 IronPort-SDR: S8TrJ10HVU9kf0C3t4bwfEnji6C2Z+7AiQ0ZUQNmc6oiL3IwKQTnkKRsFlH9XG6fi4vtWPWeqr ZBrMsw+19xnMvsyuIJpFLdAadlbCWaREzg+RUhGIBwT1cU2l7OIAUiiAy7wg5zhbQQ7JS4YSwF YqAvDTDcNABjyQfLjeMpqoWNp1GSaGBEMMnlyGluwxBOmz4vTyB9OzLzcwhxxzo7IBx24ureZX DkuEYhrj/4jdzkbwgKYRqlQpQ7M4iUAr3ziiGTYYEJfSitZbJhwB2+nJo4M7qSud6I8eXaSyE7 YcY= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 15/49] Input: atmel_mxt_ts - report failures in suspend/resume Date: Tue, 27 Aug 2019 15:28:00 +0900 Message-ID: <20190827062834.20494-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: 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 83ac2f1ba3be..641dd14489e1 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 Aug 27 06:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116149 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 C761C1395 for ; Tue, 27 Aug 2019 06:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFAD420828 for ; Tue, 27 Aug 2019 06:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725943AbfH0G2c (ORCPT ); Tue, 27 Aug 2019 02:28:32 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48162 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbfH0G2b (ORCPT ); Tue, 27 Aug 2019 02:28:31 -0400 IronPort-SDR: JXIAVBRHAW0GgVNAinAQpNWbGD+SN+1brfcAjR+orz81eiyYKKJSFi+MIgF9DL9DL0qak6J6Z2 An7m0MvqF7DHhgVRxy871HbzOAdLUIxyHmUmZ/Tby5fDDGW8SX829PEzj+s0GjqceOKRx5rx+S J8AUQywWizY2nhI7Q3NFsQ8jvxIurqlNtbC27T1Xn1XJ31bA4lcL4Ujefig1Khhe72LHWr46D6 HvylFNWeBaZ4O/B7IlpdWTWM7w6be/SlwNslMKMNvF2eMBpYIjlk/gyM4hFJ3Qgu0+kzaUNPCP YK4= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784486" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:30 -0800 IronPort-SDR: dQLbG/I+OwHJJPqR0Y3MR7o3kMP9Kk7XMZoUgaWkd9YbMEpgxmHGIpCaZLfYLJNrDjY4YmuIoA NZcxQ9SQw/3f6qUmZFnHKpMjpFzQ26cJL5kxN0xIBVcds9HholsWM0DXD4sdxPSXTkiCMv9eTN fyKyUqt00tMIounH1xq1hJDssZnV8JAjugCI827kA3JL0Tp4w/1vqeausY/NT9AbJpG+uJIAAB 9r46LfzO2VekaxaLXVAKR2VbhHUj4foi2uIiuKVrCG+AfnodhXpgdlfASeCLTsfwHSGc6eAJad j9k= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 16/49] Input: atmel_mxt_ts - allow specification of firmware file name Date: Tue, 27 Aug 2019 15:28:01 +0900 Message-ID: <20190827062834.20494-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062834.20494-1-jiada_wang@mentor.com> References: <20190827062834.20494-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 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 641dd14489e1..14f665f12778 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 Aug 27 06:28:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116147 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 70203112C for ; Tue, 27 Aug 2019 06:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E4D120828 for ; Tue, 27 Aug 2019 06:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728988AbfH0G2f (ORCPT ); Tue, 27 Aug 2019 02:28:35 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48162 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbfH0G2e (ORCPT ); Tue, 27 Aug 2019 02:28:34 -0400 IronPort-SDR: 2CMj6qdDODsqFWjidZR25GRPs6x4bN/YaSdpn228DHTgsGfUHSvglK774+6TaILCdWJT5zyrFW abKC67kPWCrSNMAEYsXzSl2MOMGgbmw8z2GMivBD+Kyvpc/yQIQFIlbWURMTjnLKB8Txjo5dBS Y22EaFN+XF8aJf7gy6RVjJNneeNHvvsSKOE3crLwHjxVVPSIEm4ZuGcDj+00+bXGjVujSN+UcO HvgQKVgQU5FPchoctwIb2BhacJgrFxFXxXvaTyAICrFO0OYnR/9GfQs4kHlL/gW0tNKNb+iYd1 nv4= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784491" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:33 -0800 IronPort-SDR: tblcGJ+R1mnFYYCm2JkBz+DWFHjQQ4KsQrrW8sRwhr67p8G/2KAcxCrZzVr2WSKDzHOVucjFR9 83wyERKMVpwby7n6/p94JNgH3fs/aDgFRDK8XS2/FCBzDgfU9E8izzq8Pmdd3kSV1Abr3sw+pw 10yCosnV9g3kNhgN+M313voRGQ7SEB3qyHXfvuor3VgDa3bw93vYk1uNNNsyCOf9n+qw58yklb 45bII+wVKI5RLwm7gqAizk93csn7lB1si/TeaQNkeaqh5ZVXwsXootqw99Xdu8eTk4VDn3iS3O Y+A= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 17/49] Input: atmel_mxt_ts - handle cfg filename via pdata/sysfs Date: Tue, 27 Aug 2019 15:28:02 +0900 Message-ID: <20190827062834.20494-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062834.20494-1-jiada_wang@mentor.com> References: <20190827062834.20494-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 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 14f665f12778..c6be716a974c 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 Aug 27 06:28:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116145 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 099471395 for ; Tue, 27 Aug 2019 06:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E615620828 for ; Tue, 27 Aug 2019 06:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727251AbfH0G2i (ORCPT ); Tue, 27 Aug 2019 02:28:38 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48162 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbfH0G2i (ORCPT ); Tue, 27 Aug 2019 02:28:38 -0400 IronPort-SDR: AV0GKLhYxaGjXw7K/fdDDhHtc+625recBxE3ZYKo7GOSMBiAp62Aifkgu9buzWHar2gQ5ZU2p6 bGxbqBSKsQHvL4hyNk+lEQG0vFzoou2F3Cr2ADTi923Pwo24wIx7VdffYSy9lNM15GUOjGRtAq hZtqbuUGpZTdj33j/HKEw+3U8dGtLEXZrMgaFVhBJg9Ho48aheF4kUHs7aLM9AI8VMvP2/++6a 8/AqKXOayF5ogHLMmREWgXP1ZWxKQuSulhaP5dAsuYt7H+C1gI19sKl7K8tfX5sT8IOhszt134 IYQ= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784496" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:36 -0800 IronPort-SDR: ciZzcER6kf8kpvyIWgKb0EHfL/U//fKFphmvhFWNrJtSDo+CicTU9uGF5o153370smZSGc5bZx 8rd1I5KdVoCjrCH5q00WiZsDWUOMp3Z+nAIsoHbzjwiNSFe3HB4ral1UslJSeo3yIM0SLS0SRQ MoZVUPDzON/adFy7crD58itNiOdl6N7uiTRel6QCDHztgk+8uhhlRglRcW5w8ML4EG4bA+0lKQ ZfZRhJ3oIyFW6NYpcv3WWur/UG/VDWeCuKI47Jqsnh9eZOo8wUDVn3a7hczEWbHdCz8CaDHYsP GQk= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 18/49] Input: atmel_mxt_ts - allow input name to be specified in platform data Date: Tue, 27 Aug 2019 15:28:03 +0900 Message-ID: <20190827062834.20494-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062834.20494-1-jiada_wang@mentor.com> References: <20190827062834.20494-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 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 c6be716a974c..923ceb5118c5 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 Aug 27 06:28:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116143 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 A5D101395 for ; Tue, 27 Aug 2019 06:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D3BE20828 for ; Tue, 27 Aug 2019 06:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729056AbfH0G2k (ORCPT ); Tue, 27 Aug 2019 02:28:40 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48162 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbfH0G2k (ORCPT ); Tue, 27 Aug 2019 02:28:40 -0400 IronPort-SDR: ioR+ZrJCfe0zbw+l/u/05zOjEbXdJ3aJe25sKtM4UuJIX+pXt2SREEvtcXorvP0Xe9HX65MpgN roIjOOSkAy2o9kgHdnluzZoWPjHPZFq9kQ3bauwwO2WHeNFIy8zKkm2wsAGhz8isHq2eaQt7hc sZUNqhNpnwGNHJpziSs1Xt7+xy8ZXutCL23taO4GXYLEidCOqs2bCnt0OtJP8GXE/PA7arTUz3 wdjRgfWKVq60JkoKlgAsnQjIqPT7Tje8ySh/FA7XPewuDSVmdTEc6oeUD9R2bdzgIycBSZRDSp eJc= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784498" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:39 -0800 IronPort-SDR: deRt5p8R+EhP9FcgwUknmCS13pQ4lQUr/3axRNuD/7FtvPh0ScQFKf+Qv1jo5U6PI67OygTIup KSF6JGzRcNKYMSMRjoqzKVixnd2HLCLdZ8lBxM5ui+726RXknJ6QSuXL/2pJZi1g69lqdGvktl XtYX5xqgDaT+P5NTK9MPn5qLqKIwvab8tiPjesOOKRuBGtY8Z4FlWE9Yuz/MLHbi4LMovBoFgF nfM7QWWRRl2z4q7CfWaBTWIeeWolXRuCDHQwpIRWP95i4qXlTyg7lwY+aDKIOcJLgovrM/suTZ hKo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 19/49] Input: atmel_mxt_ts - add config checksum attribute to sysfs Date: Tue, 27 Aug 2019 15:28:04 +0900 Message-ID: <20190827062834.20494-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062834.20494-1-jiada_wang@mentor.com> References: <20190827062834.20494-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: 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 923ceb5118c5..77a1f8209cee 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 Aug 27 06:28:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116151 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 A408B112C for ; Tue, 27 Aug 2019 06:29:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C22720828 for ; Tue, 27 Aug 2019 06:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728437AbfH0G3A (ORCPT ); Tue, 27 Aug 2019 02:29:00 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11340 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfH0G3A (ORCPT ); Tue, 27 Aug 2019 02:29:00 -0400 IronPort-SDR: bJMeo/cyL1kkYW4qL0Bwg6g5CBykZxIULaec4dmbkVgcMDgc/9cfeRHin51AMafOSEXsIGt8HO 82AjW5Im6Gl32SZVtp0//5yE+LzpQWp2HnF3aJaAKNCE6ZVIEixnCEmhjrLAxNKkx/vddd79By bw759vjh8W/ZHz6KwU3V8Z5favB4kah7OLwbjswujHV55MzbER+ltOw+nMurz4eogcYNxvoV4u gzmmBRnnwJGQRiE0wsGgwiXI52hKWnQ7Gcg8WqapbC4rulHrWG5+6BQJu3HUamdieTZT+CrUXx qgg= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589365" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:28:59 -0800 IronPort-SDR: IPca5zCPhDiUFI4If+/sfM+/oRfFCNOian34DPOfeEXW9tlqb1vuZ7PHBFDpIMe1Rtvn9waY5A oH7BJ4kXN/hmnvMFA7b3hjvsSY/vAxFtgSD4GfYISnriqUaYc6Qr9AwN4YLuyMeT8aoXWjwXeT PIy1O53+mbZjZH8pRIwRNbNeuek32voVnNTbD7/o4KkFnkFhK8k87pT3SlBj8wwWknxeSWbBgX Aubtyw2/fTCcT6AClvFBCPK7Ziq74NqeurC54WQyVhfgeIwxoMudpxfu8I/ybRMZVhWRz1xpSt zWs= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 20/49] Input: atmel_mxt_ts - refactor firmware flash to extract context into struct Date: Tue, 27 Aug 2019 15:28:41 +0900 Message-ID: <20190827062910.20598-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 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 77a1f8209cee..85eefd4fbc9a 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 Aug 27 06:28:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116153 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 DFDC1112C for ; Tue, 27 Aug 2019 06:29:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6A1F20828 for ; Tue, 27 Aug 2019 06:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728600AbfH0G3D (ORCPT ); Tue, 27 Aug 2019 02:29:03 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11340 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfH0G3D (ORCPT ); Tue, 27 Aug 2019 02:29:03 -0400 IronPort-SDR: uUhYk8Or9IJDFgy1XDyR4AFljQXdGKE/Ma18wPqfFcGv7v7oNgSWa3MI+mNS6apPSf4zzkyQkO FFi8apyoR0xmf7Sj8b9iIvnKsUSUdBtap5ljNBHlJ/KfrJN9s15S8hKN5V88afkA/M40ew1P/u 8YMNr+bL4t/j9YtsJVbJQDTHBX1Pz9HbKFsnj13QoUNsf9Dk54oN0ne4Dy7TcX+GUOAg7ym8Az Q53qOkKuUjeipIbMzrGSY2/Guldopy+4IXg9Z6CAv/kZX9wAPjb5gBL2iRYmN/OsK3qNJH259b xmw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589366" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:02 -0800 IronPort-SDR: 0GbC0Rs6HBSQ2jVG4I3thTbUcMEKtSg+YAuHb4NLaIBHgswwbAQ/rMPM7ZLqX0ujwZCAg+SLxS iprxpB+oiR18sb0eC8PzY/p2hwqFtAK+s+nUeXRl/43CtT+VXbO2Nb3pz6YKYFRO1ujd5Aovsm jbF3fyFdM2vpGVuPjfSZvICMzvzU5JFxbYQa2+S4WuQQ+RZG/re9RtemWE0hweNYse8VIW09eq VOYKXRWuTDcGDCfGa9+5Gn6OqMj76IsdAiS+ZYS0Tpa/I0+TGljA1T7gMldK/uPa6FdTCvJpYX mj0= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 21/49] Input: atmel_mxt_ts - refactor code to enter bootloader into separate func Date: Tue, 27 Aug 2019 15:28:42 +0900 Message-ID: <20190827062910.20598-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062910.20598-1-jiada_wang@mentor.com> References: <20190827062910.20598-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 (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 85eefd4fbc9a..3da3f27ed580 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 Aug 27 06:28:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116155 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 E8A92112C for ; Tue, 27 Aug 2019 06:29:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D081720828 for ; Tue, 27 Aug 2019 06:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729162AbfH0G3H (ORCPT ); Tue, 27 Aug 2019 02:29:07 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11340 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfH0G3G (ORCPT ); Tue, 27 Aug 2019 02:29:06 -0400 IronPort-SDR: AqZH2f7hUvhZiK2npLiW5MhuWI9tR6aik32t4yvOOeZKAXu6gkCIKvBqgM9EN18TzyWuXq5u0X tDNYDSPujKz4ghBvzU+PcHX5siynuY1G9CX751N3l3LIvZBhgTVRTLgSqlHsevRhEHBXku1U6F zR/odrDyG06Wv2f5rqaGWxXTJAWu/o/3sRdSfRAfnyR7qo/+3KUjHa9aIT7XfgxZiqyQ6OlTKW 5mKfozWUNVkvVWS5YISsuX7ZoV5WjA8XpiH9BXSLEm3MpR4xslqctdZAbQsJ/r4tJumn5aoRjG lN4= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589369" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:05 -0800 IronPort-SDR: yucqM13GL0kS5XKwF9U0ZQvIlTO86A4z/O4d2//2jWKo74nYZYUniO4bN5JXm8zsxs8jZm5nDu 1cBSKhp5+2BQrFdAWFxaG8SXB9vZ+doToxrYRetPLVK++viPPa80rj1vW9KbObDcHAiu4gw8/q q8+2RNGR/VHJQew6Y0FKX5KAItz2sVHW31nKRTLlM8E4maZiSlO8JtIJ1iHHgdA8m8RlUd4Dyb LMwvVozSjFxahrWB2j9shWMPJiCZMivlSPZJ8QA8Zw/rHEGyVFdoHaExqlRMUHO91x3kX29CJG S28= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 22/49] Input: atmel_mxt_ts - combine bootloader version query with probe Date: Tue, 27 Aug 2019 15:28:43 +0900 Message-ID: <20190827062910.20598-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062910.20598-1-jiada_wang@mentor.com> References: <20190827062910.20598-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 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 3da3f27ed580..4ec28b73ee83 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 Aug 27 06:28:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116159 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 B4ABC13B1 for ; Tue, 27 Aug 2019 06:29:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CFDA2184D for ; Tue, 27 Aug 2019 06:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728704AbfH0G3K (ORCPT ); Tue, 27 Aug 2019 02:29:10 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11340 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfH0G3K (ORCPT ); Tue, 27 Aug 2019 02:29:10 -0400 IronPort-SDR: 9tqsRMUdudZOn2GBtziTrmcmna3pO0jIATlQY1UhMZOVa/LjJaSq3w4aJsQso5cbBF8WbUk4EF hoOvCx1SBSOSyNLaCUhoSFioQYVEkGzqPdoA2nh+hmb9Bmo1WOUhzI0QiY8gQDlaQ9bmJZFe+J NMicRNe9rKx6bEZCbosGj2abGzYAm1Z9xFZI5zfG2T4hkt8wn8A1/jDxTBp4E46VpuCMzJmVAQ qO3TNvGfID76nFmOU1mHvdpveRBgioZwoLwtgnkQvzrZbneri788OFBMLMSOgGb0mk9stgsVgU +fI= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589374" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:09 -0800 IronPort-SDR: uZ0jhtJEwzj9QmdzXGlHP7H74fO/D5wznZDrbHLFApFEVfLC3bUHcD+XCDn6yJtZGR1eFfNAlm 4KfbdaSxSBLg5m2tyGdKUInrr0BfmLQFC8N1fB2/8HWsOneGYaVklcbhT3IzlAIpjIVBPC/0n9 ycVTPE1aL2juwBSx8PiSTN0QvDP3Izp82HHUfP7itJ93VSitVGFA829SI5lBZSQHNPKwvgTjQp Uy0Mm91Qvgv9Ak/2DXNzll570kYmcf60DldRrPe680ltbHjx8Uj0aS+oUk3iqeyONJaacnKoC6 pbk= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 23/49] Input: atmel_mxt_ts - improve bootloader state machine handling Date: Tue, 27 Aug 2019 15:28:44 +0900 Message-ID: <20190827062910.20598-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062910.20598-1-jiada_wang@mentor.com> References: <20190827062910.20598-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 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 4ec28b73ee83..4e7f82e2fc0c 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 Aug 27 06:28:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116157 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 839F61395 for ; Tue, 27 Aug 2019 06:29:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B8282184D for ; Tue, 27 Aug 2019 06:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727455AbfH0G3N (ORCPT ); Tue, 27 Aug 2019 02:29:13 -0400 Received: from esa1.mentor.iphmx.com ([68.232.129.153]:11340 "EHLO esa1.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbfH0G3N (ORCPT ); Tue, 27 Aug 2019 02:29:13 -0400 IronPort-SDR: flWKIDMXFq6+QFhaQ7qLcnRK7Qf5RwK7YrKJKT2nORzeNjPROy0bKcL0WTBX2rGFg8piTGzPD3 I+HHesE/FLnlWgF4Bh57RZMj/AVFMFP5uw8Lw5Z9hsk5tlUIvrSL2BA7TTaeigMJ+bCboHShFO ceeC8EWIv/7ne5HzENzcvbDtX60xcekUXKlxjOOUJNPxrMEFAKP4nm3sJo0PT+xMu9hjhxNVSM vHa3WLbIaIvxIlr1w4nsbAvYvIur3ukebHaxij1JBjdbIjxL+fKRCfVl8NE8/2QMqgqAqMr7bC 20Q= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="42589375" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:12 -0800 IronPort-SDR: ZK+TJDo2r0qaqxbC2ZamdU7mCh3TT5Qec7CyQStItXMx8Wyj20sKOfoz0N1aFyHmO/TgEc2MRi +6/IpBc728FtlbQ52HX20BJ8ocTca+M2oHc+MSUeJrgYHXIEHDR2Yt5D2M0bQ9NmgBJjXlZE6e 9dzilqERo94yZl00PLjll2UmCod28XM8yD8SbICSmuA0VY82wwQlYn4cNWczXmijAuR5jtd6Sm x8P+G83PguvXpyDLqReJmH3pjv04N4gaT24sxzW95SZZsbGq2tRYP3WdefRdNHFQgnLv1gntJS N+s= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 24/49] Input: atmel_mxt_ts - rename bl_completion to chg_completion Date: Tue, 27 Aug 2019 15:28:45 +0900 Message-ID: <20190827062910.20598-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062910.20598-1-jiada_wang@mentor.com> References: <20190827062910.20598-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 (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 4e7f82e2fc0c..e5843cb9a35e 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 Aug 27 06:29: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: 11116161 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 BDCA8112C for ; Tue, 27 Aug 2019 06:29:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BF7720828 for ; Tue, 27 Aug 2019 06:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725860AbfH0G3e (ORCPT ); Tue, 27 Aug 2019 02:29:34 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47201 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0G3e (ORCPT ); Tue, 27 Aug 2019 02:29:34 -0400 IronPort-SDR: R75G1T0UypaAXCpIR0vplAAd16xvzsBUA6rO1BlKF+eHrumGNiMouyHVNw2pF/fFkDIOXUj7CI V5nzuoXp/Yy0Hp/YwGnWAOmGODsCYg2PFHhO2pH+HoVvrWm4kGum/QMrCoDstcRCj/DbmYkyfl ha6vfjwCs2ntERL4q72QuI1TQCNrHVXr37gGqQeBDzcCmiWEID8Zap+2Ld/f9JLmVSDavsM91Q NEod1p9gwG0O/dG0VJZQBqe9U5MruhdVqTFZk9VUrAheU5qI1CU5hO3aWwUBQlcwv8bl5I5EQv 0A8= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754976" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:33 -0800 IronPort-SDR: B0HeD9tgOqEtTqqMtB4LUbSgsRg+jiYfq4Gehm7bWM67hvpZDndvJHeIdEYoXMbcW7PZAuNZQS 3wpsveiUzwIJ/w82QkA677IvzvlVwJ7qsKgerd/gbAku76ApHCodb0z6kQ5XFUcNFr/4Fy8xUF vrwgeEjNfu//eOp+t15dCJMKCZnWICI/koR9TcCVs1ArCBnnl2J0rh36doaYLc8ck30hAe7Lmj ua47Ua9vPKw7ybb+eZjPn61b6R8Ych9wXxf1i5CgjR+U93D0B50Bfu2CwOS9UJWK9Ou3o6e7rV G5k= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 25/49] Input: atmel_mxt_ts - make bootloader interrupt driven Date: Tue, 27 Aug 2019 15:29:19 +0900 Message-ID: <20190827062943.20698-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: 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 e5843cb9a35e..cfc84f3b5a9e 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 Aug 27 06:29:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116165 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 946DA13B1 for ; Tue, 27 Aug 2019 06:29:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D0DE20828 for ; Tue, 27 Aug 2019 06:29:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725825AbfH0G3h (ORCPT ); Tue, 27 Aug 2019 02:29:37 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47201 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0G3g (ORCPT ); Tue, 27 Aug 2019 02:29:36 -0400 IronPort-SDR: 9A+AjCKfagAVucyq6KgxEi+hsm2TUI6BMRFX+ur8b3BB58uAfQT+wfPJawMRh8/OYh6S2rg95K zFPOkuxp+DUfwo9uoEOibg1Jk+FuetNE3CprG+EDrAVL8D+sgtDPju4FSxfaTiCzBzrxWI/o9o iypJC4mbPpC1CnO41lY20gUBU13qrtOKevKnB16EK1VyE1ZnuYFTcMhDgF2rmpx0oUu8CkH281 yTn2lN/rpq4RYd90vLzLYextgvaIJdYVE09VC4jXoZ/APnODBRypORqMcnrCg8401AdiFe3SbY Elk= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754977" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:35 -0800 IronPort-SDR: u94K6cX4661u8L/i4XD47u4KIAnhy2Y+wxREjQ0Rs0jGs9EfZwKmN1HR0tG7MfjGAa2TuUtesQ s+l+q8UNhRMmY/mpVaKH4Q3H+6jS0avbV4RCcsR/bJGCVvwgGiIxpoc6erdp7D4Q5vBB3aGNUW WqY25Y+BkudeVcuE5wNfDVTjRWHQvrjqrkWW/zi0DhyESgZtlsF5+rqY1cbJwYFBZ8lGDnuj5e oMHcDblm+wZU6qySsErYM7wjrAoZVqhUO0W0bM06moaHw5rYvfZ4rCrQN0ZICaAtitipEbjkLp JhQ= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 26/49] Input: atmel_mxt_ts - delay enabling IRQ when not using regulators Date: Tue, 27 Aug 2019 15:29:20 +0900 Message-ID: <20190827062943.20698-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062943.20698-1-jiada_wang@mentor.com> References: <20190827062943.20698-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: 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 cfc84f3b5a9e..daf119c2957d 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 Aug 27 06:29:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116163 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 484BA1395 for ; Tue, 27 Aug 2019 06:29:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3022D20828 for ; Tue, 27 Aug 2019 06:29:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728810AbfH0G3k (ORCPT ); Tue, 27 Aug 2019 02:29:40 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47201 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0G3j (ORCPT ); Tue, 27 Aug 2019 02:29:39 -0400 IronPort-SDR: ek1sMtJ9KaWWV9ABSeQKrvqTBenSfhSjZs2FMpbuAKP/fxCfitXEW2CSqaN8eLpBSvK55+wJ7p 2tZQ5FKYBBBh8BT3RgzZIwiXIxuHRJic5iyajXXxGVOVVj6u7rs4f3QTM/WkIB+DDSHlLTgWqg EjgoYcWrtRnl72BQcTizmDfx08Tyr0yqNUr+6Sq7uJj3ux8x7ilftp0iOsmTNuuqeYCwvPL+pk VEw0kYVgnFbAhOy2510zGGvB5umSBxUjdn+PWz23VO8TLKiqPSMOmr/C4Tq1SwJihxVzLMuqyx ArA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754979" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:38 -0800 IronPort-SDR: 0cy/XRMIk7qQijTRjn+mpOZ41vKR85yEC5E++F8SfhVQ3aD04d9QMZtwP7o48nfbAKfqoe15CM gFXv670RxfRVbcEzEh5wV5AKqgM1jM3qFg8k3UmYeHD+QTNUsiZSQElEIINvg2dSRP+L+VWN0w 9WGJ/12MaMNlYkDICJTMA+Z5+zRrzabWGlXfOoM2BQ4KUtQmKlwxLFb6GGWgWjNiJ4ZfLWGZIS gew2hxFPVzv4tYgO+vH0aSw1udQRy4PkScBI9RIQGvB9JA766oTkdYBdiaPEvICc770o/EShIE sEU= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 27/49] Input: atmel_mxt_ts - implement I2C retries Date: Tue, 27 Aug 2019 15:29:21 +0900 Message-ID: <20190827062943.20698-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062943.20698-1-jiada_wang@mentor.com> References: <20190827062943.20698-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: 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 daf119c2957d..5b7ab798f27d 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 Aug 27 06:29: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: 11116167 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 7195013B1 for ; Tue, 27 Aug 2019 06:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ED1820828 for ; Tue, 27 Aug 2019 06:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726833AbfH0GaD (ORCPT ); Tue, 27 Aug 2019 02:30:03 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47224 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0GaD (ORCPT ); Tue, 27 Aug 2019 02:30:03 -0400 IronPort-SDR: ZxfpUv83UhlQYahbqqwG8bIRLyM/GYbjs6hjwrEj6NLU+TGDzwIht4UXxfR6SX1tqXYDK5xt0j SZAFCQcry9j3vwu5RsgZTISeXxekADDbOJDKSyRo0L+c2MXnxJ6dRyMVoJ2blBmq/jNAioGchw 3X3ucoviIF81cRybFOCBNOPkmyaCfGZ+p8hbWOYciILNm7dL5c2sTNivtjODH7VHVrBRHwZSS8 Pt9Rmbo0lQSCi5SfLoYNAWWfW7HIeVdo8Nc6eTjucOE/roCWsMUnVWmbS+ZBrQxcR3tfTOu5xS z7c= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754981" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:41 -0800 IronPort-SDR: 9dn4dml8aS7kU8rlj6A2Tglc9v7H3EAykMRBbOBb2ibjT1F2kWHi64GtUFDGHNrvbK1pzZq/+O EnJjL+bLFMI0X1M6hD6qIl1i6wq0t5KP35Sva6E2PJ95uTD+AWBpMpn6D9UbjikuaMSe0tTHRg 8j3l3RlUw2f1RO5cGjBUX75rGrOnuA4aOE3ivOAuteFzDpVcAM71VDluea1Z0GNSqn+GHn8hEQ Md63QsOPOl6t2hPtBR39cHW0qIE0Dsy6s7wthBrd55MhwvOrWAZtht4bSQBZbjb/6XOS+9sTQP 8qc= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 28/49] Input: atmel_mxt_ts - orientation is not present in hover Date: Tue, 27 Aug 2019 15:29:22 +0900 Message-ID: <20190827062943.20698-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062943.20698-1-jiada_wang@mentor.com> References: <20190827062943.20698-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: 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 5b7ab798f27d..2d2e8ea30547 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 Aug 27 06:29: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: 11116169 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 9A07E112C for ; Tue, 27 Aug 2019 06:30:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 824D62184D for ; Tue, 27 Aug 2019 06:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725811AbfH0GaE (ORCPT ); Tue, 27 Aug 2019 02:30:04 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:47224 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbfH0GaE (ORCPT ); Tue, 27 Aug 2019 02:30:04 -0400 IronPort-SDR: AtkyrQAfXNNMzeFgqFacbylhGoxgsZXZCPzfXqbBJvWKEjtGVnhDYWXOd6r68bUm0OX3FZ1Lto LvAkk8jq0IZ087bK1VaK93SIyBQq5xRn+VaUEf3yxch7GX+aIrrs4xvxkrj+E5eRyuM/iQ7Ur4 6WvhrvDfwTe0Nfj6XY7sD7jrJm6GoeIDeqxUHOqb9WzapsX+MQNOTnUlGUGogKtepPQeoJrWUh 2Yc5QA7jMbs1Dv4Kmo19bnmSDA8Le1QRoJ1w4DvBh5djsvGRnUaxHFgOTZAuU1ZZ9gSXoVmgUS apU= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40754982" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:29:44 -0800 IronPort-SDR: oicrKId1jb8JE87FxkfLHAIQZL7ACx3VigWnci5yjUP/WR9CMSO7quIVK+B/fuEXTYYY+9LkY2 CA5+zXPWlKMafVLtM5qOj6hlEaFppo4UrO5Jf9/J0UeCMl168UkKMyId/qItMLaOpZLv06DzKt rUy7kfZi4/YWQxm+e8e9H+e/apaFVTWNASo9MtryNtZC4mNn6U4yKQyKOWF2pRbGHqZ16bM2F5 q6ghhyAXAFyzWmP3Ap2JkRKjx358ndqBbPXgaRuVI2t8lqSy2LxvbN7cTdFyST7KnLlhli1BCp Wgg= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 29/49] Input: atmel_mxt_ts - implement debug output for messages Date: Tue, 27 Aug 2019 15:29:23 +0900 Message-ID: <20190827062943.20698-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827062943.20698-1-jiada_wang@mentor.com> References: <20190827062943.20698-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: 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 | 44 ++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 2d2e8ea30547..941c6970cb70 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,8 @@ 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); + 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 +1215,7 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; + bool dump = data->debug_enabled; if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1248,9 +1250,12 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T93_reportid) { mxt_proc_t93_messages(data, message); } else { - mxt_dump_message(data, message); + dump = true; } + if (dump) + mxt_dump_message(data, message); + return 1; } @@ -3522,6 +3527,36 @@ static ssize_t mxt_update_cfg_store(struct device *dev, return ret; } +static ssize_t mxt_debug_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + char c; + + c = data->debug_enabled ? '1' : '0'; + return scnprintf(buf, PAGE_SIZE, "%c\n", c); +} + +static ssize_t mxt_debug_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + data->debug_enabled = (i == 1); + + dev_dbg(dev, "%s\n", i ? "debug enabled" : "debug disabled"); + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); static struct attribute *mxt_fw_attrs[] = { @@ -3538,6 +3573,8 @@ static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); static DEVICE_ATTR(update_cfg, 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 +3582,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_object.attr, &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, + &dev_attr_debug_enable.attr, NULL }; From patchwork Tue Aug 27 06:29:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116171 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 A220213B1 for ; Tue, 27 Aug 2019 06:30:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76F622186A for ; Tue, 27 Aug 2019 06:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726333AbfH0GaG (ORCPT ); Tue, 27 Aug 2019 02:30:06 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48242 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729315AbfH0GaG (ORCPT ); Tue, 27 Aug 2019 02:30:06 -0400 IronPort-SDR: NsRL2B1PXxnWzm7n5GH5b7SZxetUdyN4IbYdNuMo8lTGBv3TnSyn+5JJsV1XKAy8BA02ZmoZ2S 6aXW2v58i7yo0D2qjnY4Byw8+JAFBawn+XQzaqjnC2tWCvnu52o1Q/oa9IzrbyYE6Y9zzYvV2r bqTha+N8qn+Wevl0a0qDZJTKtlQnOqUza7NB0SEi1A2G3wLyKMoZgFts6Xn4Zf8OJXkBR1583k 8FQ2UN/1xm/NnbS709oH7eu8VmJ4/AXmkwwoLnXyJ2nR4tB0E2NXNxaRQYd/WrU3iIMzCN02HD 0PA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784555" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:05 -0800 IronPort-SDR: 2qR3VtRmc4t2z1Av1ZHpGUQ+kQKBXutvd6Vhu5VskftLrP7X8xncgnhsMcd9MD29VRxZ6zy1WZ HAK2R8myjf8IX6MmfAxbCmyfcPEAq3Uv+ItLfl9rfoNkSEI+xaW2h00WsoIOKf1MInlepxxs8O NBkvwXPAX/K6e/mtjnEPSKjHmDw99V1ZgcJDKp+x6T+H72FWx99tga+Q3JA1BnDQzD/HcWiwA0 UKDQzGsJ3v/X9uF7K9y3D97SB/zci1WLsO8OBWARqX99wn+Qx6g7tfcB1T6AfIm/xiygMBbjSY eDs= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 30/49] Input: atmel_mxt_ts - implement improved debug message interface Date: Tue, 27 Aug 2019 15:29:56 +0900 Message-ID: <20190827063015.20794-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 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 941c6970cb70..2d9d2c1e39dd 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; @@ -465,6 +472,144 @@ static void mxt_dump_message(struct mxt_data *data, u8 *message) data->T5_msg_size, message); } +static void mxt_debug_msg_enable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_msg_data = kcalloc(DEBUG_MSG_MAX, + data->T5_msg_size, GFP_KERNEL); + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + return; + } + + data->debug_v2_enabled = true; + mutex_unlock(&data->debug_msg_lock); + + dev_dbg(dev, "Enabled message output\n"); +} + +static void mxt_debug_msg_disable(struct mxt_data *data) +{ + struct device *dev = &data->client->dev; + + if (!data->debug_v2_enabled) + return; + + mutex_lock(&data->debug_msg_lock); + + data->debug_v2_enabled = false; + + kfree(data->debug_msg_data); + data->debug_msg_data = NULL; + data->debug_msg_count = 0; + mutex_unlock(&data->debug_msg_lock); + dev_dbg(dev, "Disabled message output\n"); +} + +static void mxt_debug_msg_add(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + mutex_lock(&data->debug_msg_lock); + + if (!data->debug_msg_data) { + mutex_unlock(&data->debug_msg_lock); + dev_err(dev, "No buffer!\n"); + return; + } + + if (data->debug_msg_count < DEBUG_MSG_MAX) { + memcpy(data->debug_msg_data + + data->debug_msg_count * data->T5_msg_size, + msg, + data->T5_msg_size); + data->debug_msg_count++; + } else { + dev_dbg(dev, "Discarding %u messages\n", data->debug_msg_count); + data->debug_msg_count = 0; + } + + mutex_unlock(&data->debug_msg_lock); + + sysfs_notify(&data->client->dev.kobj, NULL, "debug_notify"); +} + +static ssize_t mxt_debug_msg_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, size_t bytes) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct mxt_data *data = dev_get_drvdata(dev); + int count; + size_t bytes_read; + + if (!data->debug_msg_data) { + dev_err(dev, "No buffer!\n"); + return 0; + } + + count = bytes / data->T5_msg_size; + + if (count > DEBUG_MSG_MAX) + count = DEBUG_MSG_MAX; + + mutex_lock(&data->debug_msg_lock); + + if (count > data->debug_msg_count) + count = data->debug_msg_count; + + bytes_read = count * data->T5_msg_size; + + memcpy(buf, data->debug_msg_data, bytes_read); + data->debug_msg_count = 0; + + mutex_unlock(&data->debug_msg_lock); + + return bytes_read; +} + +static struct bin_attribute debug_msg_attr = { + .attr = { + .name = "debug_msg", + .mode = 0444, + }, + .read = mxt_debug_msg_read, +}; + +static int mxt_debug_msg_init(struct mxt_data *data) +{ + /* + * Binary attribute is not used in callback, removal is done by name, + * so it is safe to update a single struct bin_attribute entity + */ + debug_msg_attr.size = data->T5_msg_size * DEBUG_MSG_MAX; + + if (sysfs_create_bin_file(&data->client->dev.kobj, + &debug_msg_attr) < 0) { + dev_err(&data->client->dev, "Failed to create %s\n", + debug_msg_attr.attr.name); + return -EINVAL; + } + + data->debug_msg_attr = &debug_msg_attr; + + return 0; +} + +static void mxt_debug_msg_remove(struct mxt_data *data) +{ + if (data->debug_msg_attr) { + sysfs_remove_bin_file(&data->client->dev.kobj, + data->debug_msg_attr); + data->debug_msg_attr = NULL; + } +} + static int mxt_wait_for_completion(struct mxt_data *data, struct completion *comp, unsigned int timeout_ms) @@ -1256,6 +1401,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) if (dump) mxt_dump_message(data, message); + if (data->debug_v2_enabled) + mxt_debug_msg_add(data, message); + return 1; } @@ -2674,6 +2822,10 @@ static int mxt_initialize(struct mxt_data *data) if (error) return error; + error = mxt_debug_msg_init(data); + if (error) + goto err_free_sysfs; + if (data->cfg_name) { error = request_firmware_nowait(THIS_MODULE, true, data->cfg_name, @@ -2683,16 +2835,18 @@ static int mxt_initialize(struct mxt_data *data) if (error) { dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - goto err_free_sysfs; + goto err_free_dbg_msg; } } else { error = mxt_configure_objects(data, NULL); if (error) - goto err_free_sysfs; + goto err_free_dbg_msg; } return 0; +err_free_dbg_msg: + mxt_debug_msg_remove(data); err_free_sysfs: mxt_sysfs_remove(data); return error; @@ -3354,6 +3508,7 @@ static int mxt_enter_bootloader(struct mxt_data *data) return ret; data->in_bootloader = true; + mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); @@ -3537,6 +3692,34 @@ static ssize_t mxt_debug_enable_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%c\n", c); } +static ssize_t mxt_debug_notify_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "0\n"); +} + +static ssize_t mxt_debug_v2_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + u8 i; + ssize_t ret; + + if (kstrtou8(buf, 0, &i) == 0 && i < 2) { + if (i == 1) + mxt_debug_msg_enable(data); + else + mxt_debug_msg_disable(data); + + ret = count; + } else { + dev_dbg(dev, "debug_enabled write error\n"); + ret = -EINVAL; + } + + return ret; +} + static ssize_t mxt_debug_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -3575,6 +3758,9 @@ static DEVICE_ATTR(update_cfg, 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, @@ -3583,6 +3769,8 @@ static struct attribute *mxt_attrs[] = { &dev_attr_update_cfg.attr, &dev_attr_config_crc.attr, &dev_attr_debug_enable.attr, + &dev_attr_debug_v2_enable.attr, + &dev_attr_debug_notify.attr, NULL }; @@ -3872,6 +4060,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) init_completion(&data->chg_completion); init_completion(&data->reset_completion); init_completion(&data->crc_completion); + mutex_init(&data->debug_msg_lock); data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ? MXT_SUSPEND_T9_CTRL : MXT_SUSPEND_DEEP_SLEEP; @@ -3930,6 +4119,7 @@ static int mxt_remove(struct i2c_client *client) disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); mxt_free_object_table(data); From patchwork Tue Aug 27 06:29:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116179 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 E807A112C for ; Tue, 27 Aug 2019 06:30:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D01D62186A for ; Tue, 27 Aug 2019 06:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbfH0GaK (ORCPT ); Tue, 27 Aug 2019 02:30:10 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48242 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728711AbfH0GaI (ORCPT ); Tue, 27 Aug 2019 02:30:08 -0400 IronPort-SDR: +oekr0JulOFpes2ePCKH0YjDmtqhqD0c6QZk5shLwlSBQnx92chAKGQKEJpu6RsK1dbQntzdwU UKVwfpwXwlsSLQHbR2S1LCntbu0BuTY0Dzk2AxqdKBETswzd19jlICPlINg/ngAsu2WdEmEZhy hgsXqMEMJfMHfwSmI6ZZytUhlfvk25zRhimQs+BO0EsfKskT9DwKmHY8xJO6pVV7jtjIXJSPRH /krtJsaJGI3Dv056LDqQHpgOvWiPo3DmIt5kSDnf5xbdQWuVrqOgOZqe61Q7ayLlUsoerRrlsz JcY= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784570" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:07 -0800 IronPort-SDR: 8g7fxdg565sJYW3F5YUXm4bpz1G11DH6wdG1q/PjK/A/sc+SjYXyVcAYdV4oUQ+SYt8F3zKUXp DbBq8uh0HB4ENum5CuIZtk1Yo8Du2K25ETirsT8St6RBudihkYKmr4hThnO6+zLAjpMaTTKDSF aTK/De3n8sFDrYlSYa/nH0Y4e/S/XE7hQmXiTGrsWrBEKNHpGpqhYnaCXmnNGSixVdmfmGFfJb eQiQFdYYOISYgwf+6q+NBaQ6S1fGrtcVP18QTfEXuQvw+LAANBJ6pTPVobQvRew4xeP5a83Qwb x4Y= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 31/49] Input: atmel_mxt_ts - eliminate data->raw_info_block Date: Tue, 27 Aug 2019 15:29:57 +0900 Message-ID: <20190827063015.20794-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063015.20794-1-jiada_wang@mentor.com> References: <20190827063015.20794-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 2d9d2c1e39dd..f6d65930885a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -323,7 +323,6 @@ struct mxt_data { char phys[64]; /* device physical location */ struct mxt_object *object_table; struct mxt_info *info; - void *raw_info_block; unsigned int irq; unsigned int max_x; unsigned int max_y; @@ -2067,9 +2066,8 @@ static void mxt_free_object_table(struct mxt_data *data) v4l2_device_unregister(&data->dbg.v4l2); #endif data->object_table = NULL; + kfree(data->info); data->info = NULL; - kfree(data->raw_info_block); - data->raw_info_block = NULL; kfree(data->msg_buf); data->msg_buf = NULL; data->T5_address = 0; @@ -2238,7 +2236,7 @@ static int mxt_read_info_block(struct mxt_data *data) u8 *crc_ptr; /* If info block already allocated, free it */ - if (data->raw_info_block) + if (data->info) mxt_free_object_table(data); /* Read 7-byte ID information block starting at address 0 */ @@ -2289,7 +2287,6 @@ static int mxt_read_info_block(struct mxt_data *data) goto err_free_mem; } - data->raw_info_block = id_buf; data->info = (struct mxt_info *)id_buf; dev_info(&client->dev, From patchwork Tue Aug 27 06:29:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116177 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 248CC14D5 for ; Tue, 27 Aug 2019 06:30:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D03A2186A for ; Tue, 27 Aug 2019 06:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728345AbfH0GaX (ORCPT ); Tue, 27 Aug 2019 02:30:23 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48242 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729361AbfH0GaL (ORCPT ); Tue, 27 Aug 2019 02:30:11 -0400 IronPort-SDR: DskCI2MMW1VGmjQf83UR7m+fpv/OpYwWcAsbHZ5DWZZ72nldbTNtRLuwclUl5KmIoj+nQlAji2 7LgGEiV9QX1AXF9pNuRYccgHk5rsmowsXax6Gfa7R0mKKX5Z0BUKvNjJPl0sH/8XawumktCJSr My6D80BP5eVfG+wcbj36r7sl15i++MM5f6zMdVaotWYMrvKvqdrOA00l38ZpPl3oXLO/bu2lGj l3t2LBnaVXaYIozAL68pnlXARXsmx1RY/XHEOvstKa3qKzyGHHutKIcJF6G6wnaRIcgqLjsKjg YLg= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784581" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:10 -0800 IronPort-SDR: H/5tCJYOw5M6NKM4dpcioTEvKmfz4rVtckvmhCVPCwKIjhoiFiKxLABRwD0GOdy6DDOD+p1kST Zx6a+gk+CcyIbd3Ac5QhnNAcjFs3Ic04c6HzFpp3v/6sAoKDk30d/Q0eelZw73D9nDM5WEwWj7 4ntmZ631XDXomLX37FA9i4SWAypRr3ORmbqPdmPQXp5d8LeJ8UMuaIfUNIGViS9MjgueIfIxDy K/FFtiTwinJCU8PduvnGE0fRj+pzEUj/v/QJ2usbjef4BiRJ4hKuhYq4AxcKVd+QJnMSgK7CI0 tvM= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 32/49] Input: atmel_mxt_ts - Change call-points of mxt_free_* functions Date: Tue, 27 Aug 2019 15:29:58 +0900 Message-ID: <20190827063015.20794-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063015.20794-1-jiada_wang@mentor.com> References: <20190827063015.20794-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 f6d65930885a..f8e80471be8a 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3336,21 +3336,21 @@ static int mxt_configure_objects(struct mxt_data *data, error = mxt_init_t7_power_cfg(data); if (error) { dev_err(dev, "Failed to initialize power cfg\n"); - goto err_free_object_table; + return error; } if (cfg) { error = mxt_update_cfg(data, cfg); if (error) { dev_warn(dev, "Error %d updating config\n", error); - goto err_free_object_table; + return error; } } if (data->multitouch) { error = mxt_initialize_input_device(data); if (error) - goto err_free_object_table; + return error; } else { dev_warn(dev, "No touch object detected\n"); } @@ -3358,10 +3358,6 @@ static int mxt_configure_objects(struct mxt_data *data, mxt_debug_init(data); return 0; - -err_free_object_table: - mxt_free_object_table(data); - return error; } /* Configuration crc check sum is returned as hex xxxxxx */ @@ -4098,16 +4094,21 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) error = mxt_initialize(data); if (error) - return error; + goto err_free_object; error = sysfs_create_group(&client->dev.kobj, &mxt_fw_attr_group); if (error) { dev_err(&client->dev, "Failure %d creating fw sysfs group\n", error); - return error; + goto err_free_object; } return 0; + +err_free_object: + mxt_free_input_device(data); + mxt_free_object_table(data); + return error; } static int mxt_remove(struct i2c_client *client) From patchwork Tue Aug 27 06:29:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116175 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 AC234112C for ; Tue, 27 Aug 2019 06:30:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 944072186A for ; Tue, 27 Aug 2019 06:30:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729396AbfH0GaP (ORCPT ); Tue, 27 Aug 2019 02:30:15 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48242 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728939AbfH0GaO (ORCPT ); Tue, 27 Aug 2019 02:30:14 -0400 IronPort-SDR: daNDSYQx/lN6RtKurTQ7qBC0n+l+Wmr45tpFlTrVQvYA6osX2uoNNCZ72Yoii46MxBgzRdPV2W qdzwMyntBVfMgAhFfxX2wy+OokJUEBLnP8hWtChbSByZTi7LxgD0kIWThLSAZ+jZ7twemf6r1M ncquLWOFH0hHJr7EHgH5YdPUFiag1Ebvhng2IZ/H9sSNRo9YMdt92ZAsD9TO8TwmhGVg5waQWV olNy2+l4rL9TC37gjW3lHAfGXFNnfTCSoakkCezdMiRfUValAP3tfoOwY/c2Ly2J/tl4gX5tbR DZE= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784600" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:14 -0800 IronPort-SDR: pNa18eu/W8KCU8LAsC5+nYJ6P6ykHV5jh2j5AtDwYps+itOgDwqPnaUpTNDrblRi4THrfHygwV VXGID2ipp5yJ1t79+opjLa4mWjr3pCmbVGZtUYsPl4Xv6v4z/MJTrfHZzwxOyZ0uhG/NSQD3Tp g60wKj7dY8sm0nkqP+fxjOG/inGlLhNVqYtpx45u2zwF6lh1D4ubTWeSD77NShQJjSPAfkkNUY SbYxdHrvwUYHBdHx0j21BVavZIclShju5t3Msz+hLoq3M21b0xyrGJJzlGBu7v4Zaw+BK737Id +8A= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 33/49] Input: atmel_mxt_ts - rely on calculated_crc rather than file config_crc Date: Tue, 27 Aug 2019 15:29:59 +0900 Message-ID: <20190827063015.20794-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063015.20794-1-jiada_wang@mentor.com> References: <20190827063015.20794-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 f8e80471be8a..560d46634bae 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1905,7 +1905,7 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) int ret; int offset; int i; - u32 info_crc, config_crc, calculated_crc; + u32 info_crc, config_crc, calculated_crc = 0; u16 crc_start = 0; /* Make zero terminated copy of the OBP_RAW file */ @@ -1968,30 +1968,6 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) } cfg.raw_pos += offset; - /* - * The Info Block CRC is calculated over mxt_info and the object - * table. If it does not match then we are trying to load the - * configuration from a different chip or firmware version, so - * the configuration CRC is invalid anyway. - */ - if (info_crc == data->info_crc) { - if (config_crc == 0 || data->config_crc == 0) { - dev_info(dev, "CRC zero, attempting to apply config\n"); - } else if (config_crc == data->config_crc) { - dev_dbg(dev, "Config CRC 0x%06X: OK\n", - data->config_crc); - ret = 0; - goto release_raw; - } else { - dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", - data->config_crc, config_crc); - } - } else { - dev_warn(dev, - "Warning: Info CRC error - device=0x%06X file=0x%06X\n", - data->info_crc, info_crc); - } - /* Malloc memory to store configuration */ cfg.start_ofs = MXT_OBJECT_START + data->info->object_num * sizeof(struct mxt_object) + @@ -2015,14 +1991,45 @@ static int mxt_update_cfg(struct mxt_data *data, const struct firmware *fw) else dev_warn(dev, "Could not find CRC start\n"); - if (crc_start > cfg.start_ofs) { + if (crc_start > cfg.start_ofs) calculated_crc = mxt_calculate_crc(cfg.mem, crc_start - cfg.start_ofs, cfg.mem_size); - if (config_crc > 0 && config_crc != calculated_crc) - dev_warn(dev, "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", - calculated_crc, config_crc); + /* If the CRC stored in the file is not the same as what + * was calculated by mxt_calculate_crc, this means we + * have to refuse the config file and abort download. + */ + if (config_crc != calculated_crc) { + dev_warn(dev, + "Config CRC in file inconsistent, calculated=%06X, file=%06X\n", + calculated_crc, config_crc); + ret = 0; + goto release_mem; + } + + /* + * The Info Block CRC is calculated over mxt_info and the object + * table. If it does not match then we are trying to load the + * configuration from a different chip or firmware version, so + * the configuration CRC is invalid anyway. + */ + if (info_crc == data->info_crc) { + if (config_crc == 0 || data->config_crc == 0) { + dev_info(dev, "CRC zero, attempting to apply config\n"); + } else if (config_crc == data->config_crc) { + dev_dbg(dev, "Config CRC 0x%06X: OK\n", + data->config_crc); + ret = 0; + goto release_mem; + } else { + dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", + data->config_crc, config_crc); + } + } else { + dev_warn(dev, + "Warning: Info CRC error - device=0x%06X file=0x%06X\n", + data->info_crc, info_crc); } ret = mxt_upload_cfg_mem(data, &cfg); From patchwork Tue Aug 27 06:30:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116173 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 6D55613B1 for ; Tue, 27 Aug 2019 06:30:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 549082186A for ; Tue, 27 Aug 2019 06:30:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728965AbfH0GaS (ORCPT ); Tue, 27 Aug 2019 02:30:18 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48242 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728939AbfH0GaR (ORCPT ); Tue, 27 Aug 2019 02:30:17 -0400 IronPort-SDR: HwBritT05BXEgMVxW4Fcvbm47r95wpFbvCRWSdHon3BCN8eCPft2i+DhSAP+nvrUyVprqiybO1 unhG8ZMLIM23A+zOand/pfmG3argQ7OSz6GcKyfOnxtW79DBSm02dzFqKaciC2mVMDGr7+bMxq z41YAj2vz0AAzjbx1ln9bZAoy1vviaCdJL/UVxwsL0FE/JJVB1vC2LdG+8Zxt/+noAqjw4P10E /H8oTBZT1Pbds8RwcPi+whBe9cTMSOYcHodY6fUxQVWvSx2rxjdEEThBQJ+/kLWA104FQ2N21y 8pk= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784606" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:17 -0800 IronPort-SDR: mX0ea9I4EikrmnMVy5c2XjEbs9lxB8+p/fyIBGRTzweMG9hRbIFH8A/1acp9/XWqfKI3cNOFcP BXa0qotBEBssPQGS8n2OPXhq2W7nAAfwI/zvBsVdQ/YIdJmzbWMvngV/R120ZeUa/VhKZbS0H2 h2gc32QRhVc7mRE8qbxLRHDq5GSqNsvBmgbjR7EL3m0GJpIIk8fEtIj9a1GcG2rIYnvN4Q96pF XBrE/tMGxuvyPg0ab5iOLkhxlCPk+PGKK5jSpbSEFosE/AuD6LKmGOgNYbVD63BzNAoycvHWsC C1Y= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 34/49] input: atmel_mxt_ts: export GPIO reset line via sysfs Date: Tue, 27 Aug 2019 15:30:00 +0900 Message-ID: <20190827063015.20794-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063015.20794-1-jiada_wang@mentor.com> References: <20190827063015.20794-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: "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 560d46634bae..35f41bfa70d5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4083,6 +4083,19 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } + if (data->reset_gpio) { + error = gpiod_export(data->reset_gpio, 0); + if (error) + return error; + + error = gpiod_export_link(&client->dev, "reset", + data->reset_gpio); + if (error) { + gpiod_unexport(data->reset_gpio); + return error; + } + } + if (data->suspend_mode == MXT_SUSPEND_REGULATOR) { error = mxt_acquire_irq(data); if (error) @@ -4115,6 +4128,10 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) err_free_object: mxt_free_input_device(data); mxt_free_object_table(data); + if (data->reset_gpio) { + sysfs_remove_link(&client->dev.kobj, "reset"); + gpiod_unexport(data->reset_gpio); + } return error; } @@ -4124,6 +4141,10 @@ static int mxt_remove(struct i2c_client *client) disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); + if (data->reset_gpio) { + sysfs_remove_link(&client->dev.kobj, "reset"); + gpiod_unexport(data->reset_gpio); + } mxt_debug_msg_remove(data); mxt_sysfs_remove(data); mxt_free_input_device(data); From patchwork Tue Aug 27 06:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116181 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 57FB3112C for ; Tue, 27 Aug 2019 06:30:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35CF420828 for ; Tue, 27 Aug 2019 06:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726037AbfH0Gao (ORCPT ); Tue, 27 Aug 2019 02:30:44 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48270 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gao (ORCPT ); Tue, 27 Aug 2019 02:30:44 -0400 IronPort-SDR: IVq4+vL0g27g7eHTWppHhllu89hc58PzILx9e8Bp8/FcMycz0impvt4j1IUR1/KHdFW0aIdvwd 9oPJ2WCQf6QTTyRA+MBrN3qyaaPH4FqW0s5hYdRtVnOZctUwmpGlLQhQXkaEM/7PMafB9kfGZS XZN61jkp526CYJQZdchTDoXEdtbu2AcVS8J4YMqGD3xkFivFzSGl91Oe4f9QydjOlldF9KCIMb 6J4KS+Xux1SMmFXmzW//7nfDxgf0H9OfLbI+O+3RB/akS4O9l59G3v+4G7usZZbS07slYQg/Om LQw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784625" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:43 -0800 IronPort-SDR: ok9gt8NT1LNLyxrO9DC4XsXUqCJTjCfNVGCXyB4e0D0lNG7xsOdhXjKbogfShNUFt4QKFGkEV8 9GraVNv+BgB95ISZvBlCE70681tIq+bLARbvwWR2ZKv+49Tjh1NcjHQU4b/AjqTiPeC0Qx6rRq Qf3mCHX6aAhC+bt8SZO7+C4b6Lozfruff4QhXexnBieaGdwPnpY1jsBIfqQ28ECzX/M5mzig1T UDPvB+Q+14Ui3Yz83sT/H55mGBoUjxL0fHRodhKjGKoq6zw0QNXQzCifWJCeojs1ni5usZYEtt /tg= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 35/49] input: atmel_mxt_ts: Add Missing Delay for reset handling of Atmel touch panel controller in detachable displays. Date: Tue, 27 Aug 2019 15:30:40 +0900 Message-ID: <20190827063054.20883-1-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) 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 35f41bfa70d5..192cf47ff5f4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4110,6 +4110,10 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_GPIO_TIME); gpiod_set_value(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); + } else { + dev_dbg(&client->dev, + "atmel reset pin not found in device tree"); + msleep(MXT_RESET_TIME); } error = mxt_initialize(data); From patchwork Tue Aug 27 06:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116189 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 0558513B1 for ; Tue, 27 Aug 2019 06:31:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1D8220828 for ; Tue, 27 Aug 2019 06:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728579AbfH0Gar (ORCPT ); Tue, 27 Aug 2019 02:30:47 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48270 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gar (ORCPT ); Tue, 27 Aug 2019 02:30:47 -0400 IronPort-SDR: lyYn2mWAswoyCeZ/k2sY743ya0vbi4Pcfyy102u1QafuVnaqDnsDIzdXh9YSvhiDXBm3TlmKh6 NK5WbwhI6FZhyyYnP9eGHfGOAAOmUrgUQJm8HbpfCrflZCwOuWbdNwS9zwhYmeuRmfjHOP0Kxd 0EJSyH61l+sTUJXLY+IXyNxHpLwNIya9ljL/LRulJHKz94TCRn3XBlwS8WIYZwnFFBHAkg1Ob7 CfCsOVHg25/5UbirzuBcsgNBmNk+l6mMU1sFCdqzRlDjFH4P5Bk31i+iDXi7OAJNP73SAnaMxr gco= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784627" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:46 -0800 IronPort-SDR: GNyBpd5E47An3v94sxDuNnmGCzKoHBwNvFnJ4haphbqqh3TbqBPLZn9y4EhtkPqBBLkKqHfIMF cKVCWs8WOFAE+0Nj6IryZ1LngXhlC8wjHzmI29T8k3UdYgDgRTGFFkcAELmGOE3eJWelBnSoTT 6z3bhSBLtFTIn2HQNKWtnmJiCnnYv8aOeCif62gYPSkcLYeQwGX5iGlqMxmhSW2FHC7U5zrfrC y41ifiQ36kzVEFpikoaQezX2B76AVIF3or22o/bToSF05p7/24x9qS0pLRt+RJ0IAG8X9+CctW wOA= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 36/49] Input: atmel_mxt_ts: Add support for run self-test routine. Date: Tue, 27 Aug 2019 15:30:41 +0900 Message-ID: <20190827063054.20883-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063054.20883-1-jiada_wang@mentor.com> References: <20190827063054.20883-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) 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 192cf47ff5f4..aa33962ed1dc 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -336,6 +336,9 @@ struct mxt_data { u8 t100_aux_ampl; u8 t100_aux_area; u8 t100_aux_vect; + u16 T25_address; + u8 T25_reportid; + u8 t25_msg[6]; bool debug_enabled; bool debug_v2_enabled; u8 *debug_msg_data; @@ -413,6 +416,8 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + + bool t25_status; }; struct mxt_vb2_buffer { @@ -1356,6 +1361,24 @@ static void mxt_proc_t93_messages(struct mxt_data *data, u8 *msg) dev_info(dev, "T93 report double tap %d\n", status); } +static void mxt_proc_t25_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + + /* Output debug if status has changed */ + dev_dbg(dev, "T25 Status 0x%x Info: %x %x %x %x %x\n", + msg[1], + msg[2], + msg[3], + msg[4], + msg[5], + msg[6]); + + /* Save current status */ + memcpy(&data->t25_msg[0], &msg[1], sizeof(data->t25_msg)); + data->t25_status = false; +} + static int mxt_proc_message(struct mxt_data *data, u8 *message) { u8 report_id = message[0]; @@ -1386,6 +1409,8 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) } else if (report_id == data->T19_reportid) { mxt_input_button(data, message); data->update_input = true; + } else if (report_id == data->T25_reportid) { + mxt_proc_t25_messages(data, message); } else if (report_id >= data->T15_reportid_min && report_id <= data->T15_reportid_max) { mxt_proc_t15_messages(data, message); @@ -1610,6 +1635,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; @@ -2088,6 +2191,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T15_reportid_max = 0; data->T18_address = 0; data->T19_reportid = 0; + data->T25_address = 0; + data->T25_reportid = 0; data->T42_reportid_min = 0; data->T42_reportid_max = 0; data->T44_address = 0; @@ -2175,6 +2280,10 @@ static int mxt_parse_object_table(struct mxt_data *data, case MXT_SPT_COMMSCONFIG_T18: data->T18_address = object->start_address; break; + case MXT_SPT_SELFTEST_T25: + data->T25_address = object->start_address; + data->T25_reportid = min_id; + break; case MXT_PROCI_TOUCHSUPPRESSION_T42: data->T42_reportid_min = min_id; data->T42_reportid_max = max_id; @@ -3761,6 +3870,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, @@ -3771,6 +3881,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 Aug 27 06:30:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116187 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 04247112C for ; Tue, 27 Aug 2019 06:31:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6A4020828 for ; Tue, 27 Aug 2019 06:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728620AbfH0Gav (ORCPT ); Tue, 27 Aug 2019 02:30:51 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48270 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gau (ORCPT ); Tue, 27 Aug 2019 02:30:50 -0400 IronPort-SDR: 0hKLT7GkaqJatTwPjbvmMiWeAm+JAcKA2aZqZHwDJly43OjLFk3QPiMgUany2r/coji2XirePm vUacUP/d+MIvoQ3eEEdkzAgeFtTg7IFCxaMT5WasHfr4heDpQBGJPz2rcJTFfF6RjJdk2oSN+x U5jfUEsdx8h1V+rPb9uacoctzvJ+vLHeIoIcdcaHeP2e3ASrTnUJxRCC+D1LoDw3OU5a5VzsAs 33PglOoYWaPQ92sgV6Ch1HTmvl+BHDFumcvIANSalKLt9DZPR/l14/fVywK4mi0nbMACDDk1L5 wJ4= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784630" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:49 -0800 IronPort-SDR: yFdcudLVvhVC7w0ygQKh7lRGHrv0a6f8/7w/IIAtHnEfxKzvdSsLTyclupm+1kO3CbMFsyQ0a1 1XP/hl2sdW2GLMNHumU2gX83SZxLzRA8d3cEVvf0ruOzOc/UykPxUU2D9bk5vDWCbsNStgzZ0c EOuZNT78X3FMDMCrkiTwEzLYbm1Y/OTBU8XY67JckunZX3fRhvHwFEp/m2BvRpfjx3fa7bYY6M eknKSrSHgwi+G8i7DcvQVX03OQ7YM3uAahJdzp+FzvxMmRKjsonqYIXh/RuuWRugWHm9BhrALM RQg= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 37/49] Input: atmel_mxt_ts: Limit the max bytes transferred in an i2c transaction Date: Tue, 27 Aug 2019 15:30:42 +0900 Message-ID: <20190827063054.20883-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063054.20883-1-jiada_wang@mentor.com> References: <20190827063054.20883-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) 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 aa33962ed1dc..169107413823 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -417,6 +417,7 @@ struct mxt_data { /* Indicates whether device is updating configuration */ bool updating_config; + unsigned int mtu; bool t25_status; }; @@ -1462,11 +1463,32 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) return num_valid; } +static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) +{ + u8 T5_msg_count_limit = data->mtu / data->T5_msg_size; + + if (!data->mtu) + return max_T5_msg_count; + + if (data->mtu < data->T5_msg_size) { + WARN(1, "mtu set is lesser than the T5 message size\n"); + /* Return count of 1, as fallback */ + return 1; + } + /* + * Return maximum number of T5 messages in single i2c transaction + * based on "atmel,mtu" property. + */ + return min(T5_msg_count_limit, max_T5_msg_count); +} + static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; - u8 count, num_left; + u8 T5_msg_count, total_pending; + u8 total_processed = 0; + u8 processed_valid = 0; /* Read T44 and T5 together */ ret = __mxt_read_reg(data->client, data->T44_address, @@ -1476,18 +1498,19 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - count = data->msg_buf[0]; + T5_msg_count = data->msg_buf[0]; /* * This condition may be caused by the CHG line being configured in * Mode 0. It results in unnecessary I2C operations but it is benign. */ - if (count == 0) + if (!T5_msg_count) return IRQ_NONE; - if (count > data->max_reportid) { - dev_warn(dev, "T44 count %d exceeded max report id\n", count); - count = data->max_reportid; + if (T5_msg_count > data->max_reportid) { + dev_warn(dev, "T44 count %d exceeded max report id\n", + T5_msg_count); + T5_msg_count = data->max_reportid; } /* Process first message */ @@ -1497,16 +1520,25 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) return IRQ_NONE; } - num_left = count - 1; + total_pending = T5_msg_count - 1; + if (!total_pending) + goto end; /* Process remaining messages if necessary */ - if (num_left) { - ret = mxt_read_and_process_messages(data, num_left); + T5_msg_count = mxt_max_msg_read_count(data, total_pending); + + do { + if ((total_pending - total_processed) < T5_msg_count) + T5_msg_count = total_pending - total_processed; + ret = mxt_read_and_process_messages(data, T5_msg_count); if (ret < 0) goto end; - else if (ret != num_left) - dev_warn(dev, "Unexpected invalid message\n"); - } + total_processed += T5_msg_count; + processed_valid += ret; + } while (total_processed < total_pending); + + if (processed_valid != total_pending) + dev_warn(dev, "Unexpected invalid message\n"); end: if (data->update_input) { @@ -1521,9 +1553,10 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) { struct device *dev = &data->client->dev; int count, read; - u8 tries = 2; + int tries; - count = data->max_reportid; + count = mxt_max_msg_read_count(data, data->max_reportid); + tries = (data->max_reportid / count) + 1; /* Read messages until we force an invalid */ do { @@ -4110,6 +4143,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 Aug 27 06:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116183 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 BC4B7112C for ; Tue, 27 Aug 2019 06:30:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A494520828 for ; Tue, 27 Aug 2019 06:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729139AbfH0Gax (ORCPT ); Tue, 27 Aug 2019 02:30:53 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48270 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gax (ORCPT ); Tue, 27 Aug 2019 02:30:53 -0400 IronPort-SDR: YBEPAir3ElVIEgqGKWe5QdFKEtdVYhdYJ7gofQpPn3A0YWYwFg/nsVJcMZP0pRgYcjFg/vbUL1 MoTLDf9Bh3HdwhF58MGhUlaSwLN8CRH/kzydopGZzv8F81W4XfjZYDkMAyS982Hh0e15zPWRJo 3EhqisxxipVed93eaf+Uzrz+aZGUuXw8LKJApU2CDJtGy01M5GxzIwCdsX+x6jqZi3c7RmF5xG g9poifMqD7BPqrO8XpQcVvKOVaXMHiQAK/naqvCMWIMpQg7k+g2RQNF1Nc4Oxdu8eNTUzV8Ohz Jl8= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784631" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:52 -0800 IronPort-SDR: GY7yAxJI/h8zxi+ANY1TOggqq0DcRPA3fB1gVd5AngkTEGZMylFrlfcZI9eKXtOhIQp6yN5XCo NYtE6qy9C/f5OOdjzqWaV5QxumGLzS78FywvgLH9LuHL/4lA5rIazKStf7IrBo6YblgrD+JY9G w9a609WAShpULm5ppUJRSq23t9b78tyqlFES5e+rNFlQctkVEGHpy0SUU6fzjCuCfFUieBnrBT wCh6WdeId27tj1v14yb4zq+d+0ijJiz3CU/13JEjhZvMXicoAQUQXHpDaXIz221RRrY66CL3pa UBw= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 38/49] Input: atmel_mxt_ts: return error from mxt_process_messages_until_invalid() Date: Tue, 27 Aug 2019 15:30:43 +0900 Message-ID: <20190827063054.20883-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063054.20883-1-jiada_wang@mentor.com> References: <20190827063054.20883-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) 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 169107413823..e9a895473ed8 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1561,6 +1561,8 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) /* Read messages until we force an invalid */ do { read = mxt_read_and_process_messages(data, count); + if (read < 0) + return read; if (read < count) return 0; } while (--tries); From patchwork Tue Aug 27 06:30:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116185 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 1F36614D5 for ; Tue, 27 Aug 2019 06:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06D3E20828 for ; Tue, 27 Aug 2019 06:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728928AbfH0Ga4 (ORCPT ); Tue, 27 Aug 2019 02:30:56 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48270 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Ga4 (ORCPT ); Tue, 27 Aug 2019 02:30:56 -0400 IronPort-SDR: RWaRv887OGd4N7Bx1ydYwH29Anzm0vj6i+1Pf8ypITC4BpJJkFNb56pip4BulBjOFOGPnaacZZ MT2Gzgpj+nQs+Rj0VvUimb6uFbNI6L/QR+Why5wFkwaWfQ5VPRtEchkqJrKcq1TXjSNMukVOxL zCs6pcKKboUPpsfTSU5+ufJpMTSZ2mHyuinJTeWijJcJBdpYR7AwQCA35rAFERh4e+3WFxRJ3A 3IpbPJN7BTpXnWqG+03C7+nkRB/h4U0eDQhdRqNrVk4s83WU9cGUGgjyIzGDvZGR/1BL8oWWWH QhI= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784633" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:30:55 -0800 IronPort-SDR: udTi8abBojH8yoHsR9OzkH4HGD5+LXST8xhaI7UXSI9uWbC3UBXMRpGFtfzfr2jAyJCB5tYHeZ c/GKNe+pmI142jlA85dquSb/P43ByF0DSB7ohC7aek3W23V5lKeTRsGQaf14kGiwtkUzn6DGgb 6x4nhISgO1E2rqjC87IlzDv7rVEfX7duwFa4FLoyBgVS+HM3ebwqAMqSiDYAEz8MusY4y6M+lW /ia+s+2Q2cSug3lkMSAE3t2acncr6ModFrd8URqGi4YOM9LUZmbxupyLfWhIwFjBxmymqmUZO4 IaY= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 39/49] Input: Atmel: improve error handling in mxt_start() Date: Tue, 27 Aug 2019 15:30:44 +0900 Message-ID: <20190827063054.20883-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063054.20883-1-jiada_wang@mentor.com> References: <20190827063054.20883-1-jiada_wang@mentor.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-02.mgc.mentorg.com (147.34.90.202) 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 e9a895473ed8..dd70f3b9678f 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -3971,12 +3971,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: @@ -3990,27 +3991,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) @@ -4331,6 +4331,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; @@ -4338,11 +4339,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 Aug 27 06:31:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116191 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 AA009112C for ; Tue, 27 Aug 2019 06:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 921AC20828 for ; Tue, 27 Aug 2019 06:31:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725920AbfH0GbV (ORCPT ); Tue, 27 Aug 2019 02:31:21 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48284 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0GbU (ORCPT ); Tue, 27 Aug 2019 02:31:20 -0400 IronPort-SDR: 8LU7l2ugKmXblzle/+B68v/RC7yfMt9WnDC9kU6+CDC0ieMnzsr7/AvrB2wvNJC1moZo1aj+I2 Dee/HXubLsGlrD9rl+GGtU1VA6cxkvjEsNZmDggb/AZrkbY/P3pn00xZTnAAF8cfHmUjifA/a9 BFQckEJPeiO5ZGZqBxHAX+CL2JjhF70Cn9l+BqRcEq8xcUXetCbauiFmOLBRTs/qXS9VTejvSq aowR+R2Y9yFTnJb8D/Pv04fYk4KzgiIJsV3awG+2q4HjJh3JHAklejTX3ykuWIdl2OTXS4VQXn O+w= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784640" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:20 -0800 IronPort-SDR: oRcrTBRWaKRVnUESmzR/qxENXo1iMCjpOOvssuRMTDUkcpIR9nLlpL4NC/LmHqemkIVc8y+eEe z9GRgnRI2BInsLjUxCFTET0NNWehX/HUc11yoaJDi6EJlY8aWjcMamgLttl4DHs6rFzXM3fEZo wdOgGfHk0nxb5eQwWVpbm7DZhXH0XE52o5LNSPsC37LIoCd3Zb9Uabz404CRzlVkQX4OtlgZSz wnLH/l5SIkw/HaWvO6P4jYDe8kxQr0+FxyZznWm2EPGaZdNPFPgJwj8paVjH1JyTr/B6LFqfsj wBI= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 40/49] Input: Atmel: improve error handling in mxt_initialize() Date: Tue, 27 Aug 2019 15:31:21 +0900 Message-ID: <20190827063130.20969-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: 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 dd70f3b9678f..59533753a431 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -713,17 +713,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) @@ -2920,6 +2916,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; @@ -2931,16 +2953,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) { @@ -2954,7 +2973,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); } @@ -3646,8 +3667,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 Aug 27 06:31: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: 11116193 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 5AADE112C for ; Tue, 27 Aug 2019 06:31:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 432552184D for ; Tue, 27 Aug 2019 06:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728964AbfH0GbX (ORCPT ); Tue, 27 Aug 2019 02:31:23 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48284 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0GbX (ORCPT ); Tue, 27 Aug 2019 02:31:23 -0400 IronPort-SDR: koe654zV2us8Fq+4v0e+5o2AXVLN6ncxJs2tcCSFznxhMwagur02ppjBR+9jUngBShytyhV16c G+JlTAh/oyhQi/G2vu1Xr/ElRJmrsLM3s5hXMmKG/WkxxpIseCeudfzKZLrQGsSkxr5I7LNBFD sqQAb1jHIJBQMKXPt8W5iOHMOb0CWImtMPOnh/a/vIpZQC/m9pXiOdowRjMX+HN6Hz68rJcPD9 KK5cxgRyjj8INSJraiNFJ06/3UnXzmHXI7crNfe4W/diry1dqc+Ly4NNTchbAwhea6MiJ6TZ+5 tyw= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784644" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:22 -0800 IronPort-SDR: VjYOOVeV3ar3cLY+iZ6nEMyZTPscW6FYwNSCsGRafIYMvc1eN35xJ/WA4R6+UejQ8kX5NdmEGP 9UM0b8kC47os6o3DnHZxH/MSW8io9BFjN7QsZo7J8YIJenjD0RBKfBWm8cRJoehGVqfm5NPQfw sxOHf/qyz+8H0PW6h3DftWxTvxnpSxFd4Jd1ENUPfcxxoAKCPAI+RmASJYEaZY0J1JYTHvrV1Z hq5YN5x4F/Gv+5sPGlXOt6j+Y03iTgaEIKCsfRq7amJm1CWSNK0gOV/GMAV9Fi9WoiBlDI4RHX hko= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 41/49] Input: Atmel: improve error handling in mxt_update_cfg() Date: Tue, 27 Aug 2019 15:31:22 +0900 Message-ID: <20190827063130.20969-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063130.20969-1-jiada_wang@mentor.com> References: <20190827063130.20969-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: 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 59533753a431..716b91e6fd66 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2183,7 +2183,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 Aug 27 06:31: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: 11116195 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 10FAC14DB for ; Tue, 27 Aug 2019 06:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED1502184D for ; Tue, 27 Aug 2019 06:31:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729220AbfH0Gb1 (ORCPT ); Tue, 27 Aug 2019 02:31:27 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48284 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gb0 (ORCPT ); Tue, 27 Aug 2019 02:31:26 -0400 IronPort-SDR: M46BNPfhmQVo/DIjkipkD6xkMVnF8+yu9iCR3A/TnYwm9EBXhKgsLXdfBXu/+nJV9VBzuxCNU3 +8++P+dzgoaGNzUgMZN4JV2OP4a3It9qbBMohURbSHSQ5ECMwG6c7IO22fXwQLMqCty1ysfWuJ F89ABq7kqOM/oB4cSIbRVTycH+NxgsmqNpj9k+BE/O5UKdTkl55UZBLxdEFmuuew1tu+3bxvci 3mwh1Vts53LfSNG0TM9M6rURSNhr2afVagOKtEeMLn2gp/l2sGoN/KZ44tE2n2Azkm32U62OOj TFo= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784645" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:25 -0800 IronPort-SDR: 0XSlNpYrWOeJVL5VSUp8TlgYTJgI6Ssqp2P2P3BgNkuFAOpeFzQX6yfy7AWgPjfapZk5fMgtq0 dxnY5RCrKNargebFI52OhuE4YFHeTPvNc2XtWj9mADc8qMRBKqONGmAh+P9Vjblrlfg1RRxKE9 ewLtpfuY+wFauA97JrpyuwVt1xMOs8F2zW3nSc4CSZAzNnWf7TB4KmY3lkKIUVjmHWc3l4a6hL A8xcTBdaZdO50MX2Tnp1+9sp6kW2WcFYiwvehxl0+9MeXUiWBKpi4Wt6UfNT2/7oFmwS5mTzPR 4Zo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 42/49] Input: Atmel: Improve error handling in mxt_initialize_input_device() Date: Tue, 27 Aug 2019 15:31:23 +0900 Message-ID: <20190827063130.20969-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063130.20969-1-jiada_wang@mentor.com> References: <20190827063130.20969-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: 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 716b91e6fd66..41d92d765aa2 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2759,15 +2759,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 Aug 27 06:31: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: 11116197 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 5D87914D5 for ; Tue, 27 Aug 2019 06:31:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 45D7621881 for ; Tue, 27 Aug 2019 06:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728733AbfH0Gbc (ORCPT ); Tue, 27 Aug 2019 02:31:32 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48284 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfH0Gb3 (ORCPT ); Tue, 27 Aug 2019 02:31:29 -0400 IronPort-SDR: kJg/PeYwtuRp9P8WJixfLshCUcI97NAVanBRp/46Zt0iu3mVKOMk32vnR8LY6mmtzoJU9M80R+ Z+7hgmFYdLAQkAv8TXJcIy01L+LcR+q9Y11bd2HWwAW701kI/uJr3wZiXiEM3mNFYMc90Hs4i9 kHnHS79QBSp+KcZ3zkX2K7NUz8sumwCsCGkq+/lbP9n4a3bvr+JaXmBX3+AGt9jdJdt2nHQiXx prcW0FsQ99ZPbpyCpctQT0U5K/NcEtje4Sgm78ENj2om4KnmyGTioj3G0p2TrB4AuOgh6OwoIH xwo= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784646" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:28 -0800 IronPort-SDR: 51GY4Hsbt/sz/lnFakBoTsV/6LMxA0DvbIlDjdkZSx8/YCuOLTS6qc/ocoIO46sqFf04YJzin2 6ICY8iFcfe4sHTKGv8z9rCpUs7l67T/VX/7f4iVERW+Ze7WswGsnitIaMB3dn7Z3z5y2mHJ6u2 GfLRmY5RLxkcRFRQd2UsmIHwl8XHygJb/pxN0KdPXiMSJGqZ/81k6RnSWv14p/+tuj1KX5oUA8 CYwz59wbrvN66wUKee3g15yUu8xfHNqN7V9sbf9sbzHGKKxJESKjV9GzzZwYnpr4LyhlC93Xvy fdE= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 43/49] Input: Atmel: handle ReportID "0x00" while processing T5 messages Date: Tue, 27 Aug 2019 15:31:24 +0900 Message-ID: <20190827063130.20969-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063130.20969-1-jiada_wang@mentor.com> References: <20190827063130.20969-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: 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 41d92d765aa2..b6f50fee3695 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -76,6 +76,7 @@ #define MXT_PROCI_TOUCHSEQUENCELOGGER 93 #define MXT_TOUCH_MULTITOUCHSCREEN_T100 100 #define MXT_PROCI_ACTIVESTYLUS_T107 107 +#define MXT_RPTID_RESERVED 0 /* MXT_GEN_MESSAGE_T5 object */ #define MXT_RPTID_NOMSG 0xff @@ -1381,6 +1382,11 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message) u8 report_id = message[0]; bool dump = data->debug_enabled; + if (report_id == MXT_RPTID_RESERVED) { + dev_err(&data->client->dev, + "Received Reserved ReportID 0x00\n"); + return -EINVAL; + } if (report_id == MXT_RPTID_NOMSG) return 0; @@ -1451,6 +1457,8 @@ static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) ret = mxt_proc_message(data, data->msg_buf + data->T5_msg_size * i); + if (ret < 0) + return ret; if (ret == 1) num_valid++; } From patchwork Tue Aug 27 06:31: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: 11116199 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 0089914D5 for ; Tue, 27 Aug 2019 06:31:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D308B2184D for ; Tue, 27 Aug 2019 06:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725874AbfH0Gbg (ORCPT ); Tue, 27 Aug 2019 02:31:36 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:48291 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728490AbfH0Gbc (ORCPT ); Tue, 27 Aug 2019 02:31:32 -0400 IronPort-SDR: EEOWEAhF8Tz+4xsocjXZxObBJMhC1juwF7w8Y8BX5zbbWpeqtkTVxdxoEZhaxmtAljx+PhAB4t w3WZsHsHVWgT7WIRaUQJN4StDfrg0gfJdsWzMSoXZQDmg+pBdMrn9ZbGWzt9bmhMTW0IM9ULGh j9JK85OVEp74YxzOqOcIxAV9Dh4ZpH+5EcPPI5s0x6kUZxY1OdbW8epXaqBhXuSEQYcvXkeT9+ aYcyuqBkW46kjHYn9clTrIgLnivR9/QnXWboA/QF38hJ5VoOBebwL5tJRgeG1aDxUk1HR15ob+ bCo= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40784649" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:31 -0800 IronPort-SDR: QHAUXMWDp/WUtbslHI+JxrxNvt5oCb4sTZQJa/PL24TiEF/5wMJku4CtF263hTUnvlqtVcfEWJ TE54F+xojfHJu4rxvw91+LgUus4NJc5QoCeqpqD2ZnXM8yyvjWJKZeUXIWk5qJbbm4YIKTzhUw TPuMHnk5+A38qNACpA+/bfBqvfpVV3zYFJlKSjY069vloI9joIfFv4O2IppQPQxDwiKSlVsA9W L2lG0QaskE7PvQuxKae3sic+wwah2bv4vsgt3AUSe8hnJuP7kvmrvzFbjIDKB09Wq0t+qET6Ru 4no= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 44/49] Input: Atmel: use T44 object to process T5 messages Date: Tue, 27 Aug 2019 15:31:25 +0900 Message-ID: <20190827063130.20969-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063130.20969-1-jiada_wang@mentor.com> References: <20190827063130.20969-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: Deepak Das T44 object returns the count of valid T5 messages in the buffer. According to atmel, this count should be the main criteria to read the number of T5 messages. Following is the statement from atmel confirming the same :- "For the readout of messages we recommend to stop after the last message is read out from the buffer. One way to identify the amount of new messages is to read T44. The other way is to monitor the /CHG line which indicates independent of mode 0 or mode 1 if there are still data in the buffer. 0xFF indicates that there is no message pending anymore, but it is not recommended to use this as the main criteria to control the data transfer." This commit modifies the logic to readout the T5 messages on the basis of T44 object. Signed-off-by: Deepak Das Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index b6f50fee3695..58e54eb45cf0 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1486,7 +1486,7 @@ static u8 mxt_max_msg_read_count(struct mxt_data *data, u8 max_T5_msg_count) return min(T5_msg_count_limit, max_T5_msg_count); } -static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) +static int mxt_process_messages_t44(struct mxt_data *data) { struct device *dev = &data->client->dev; int ret; @@ -1499,7 +1499,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->T5_msg_size + 1, data->msg_buf); if (ret) { dev_err(dev, "Failed to read T44 and T5 (%d)\n", ret); - return IRQ_NONE; + return ret; } T5_msg_count = data->msg_buf[0]; @@ -1509,7 +1509,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) * Mode 0. It results in unnecessary I2C operations but it is benign. */ if (!T5_msg_count) - return IRQ_NONE; + return processed_valid; if (T5_msg_count > data->max_reportid) { dev_warn(dev, "T44 count %d exceeded max report id\n", @@ -1521,12 +1521,14 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) ret = mxt_proc_message(data, data->msg_buf + 1); if (ret < 0) { dev_warn(dev, "Unexpected invalid message\n"); - return IRQ_NONE; + return ret; } total_pending = T5_msg_count - 1; - if (!total_pending) + if (!total_pending) { + processed_valid = 1; goto end; + } /* Process remaining messages if necessary */ T5_msg_count = mxt_max_msg_read_count(data, total_pending); @@ -1550,7 +1552,7 @@ static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return processed_valid; } static int mxt_process_messages_until_invalid(struct mxt_data *data) @@ -1580,7 +1582,7 @@ static int mxt_process_messages_until_invalid(struct mxt_data *data) return -EBUSY; } -static irqreturn_t mxt_process_messages(struct mxt_data *data) +static int mxt_process_messages(struct mxt_data *data) { int total_handled, num_handled; u8 count = data->last_message_count; @@ -1591,7 +1593,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) /* include final invalid message */ total_handled = mxt_read_and_process_messages(data, count + 1); if (total_handled < 0) - return IRQ_NONE; + return total_handled; /* if there were invalid messages, then we are done */ else if (total_handled <= count) goto update_count; @@ -1600,7 +1602,7 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) do { num_handled = mxt_read_and_process_messages(data, 2); if (num_handled < 0) - return IRQ_NONE; + return num_handled; total_handled += num_handled; @@ -1616,12 +1618,13 @@ static irqreturn_t mxt_process_messages(struct mxt_data *data) data->update_input = false; } - return IRQ_HANDLED; + return total_handled; } static irqreturn_t mxt_interrupt(int irq, void *dev_id) { struct mxt_data *data = dev_id; + int ret; if (data->in_bootloader) { complete(&data->chg_completion); @@ -1629,17 +1632,22 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) if (data->flash && &data->flash->work) cancel_delayed_work_sync(&data->flash->work); - return IRQ_RETVAL(mxt_check_bootloader(data)); + ret = mxt_check_bootloader(data); + return IRQ_RETVAL(ret); } if (!data->object_table) return IRQ_HANDLED; - if (data->T44_address) { - return mxt_process_messages_t44(data); - } else { - return mxt_process_messages(data); - } + if (data->T44_address) + ret = mxt_process_messages_t44(data); + else + ret = mxt_process_messages(data); + + if (ret <= 0) + return IRQ_NONE; + else + return IRQ_HANDLED; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -1774,8 +1782,11 @@ static int mxt_acquire_irq(struct mxt_data *data) } if (data->object_table && data->use_retrigen_workaround) { - error = mxt_process_messages_until_invalid(data); - if (error) + if (data->T44_address) + error = mxt_process_messages_t44(data); + else + error = mxt_process_messages_until_invalid(data); + if (error < 0) return error; } @@ -4029,8 +4040,12 @@ static int mxt_start(struct mxt_data *data) * Discard any touch messages still in message buffer * from before chip went to sleep */ - ret = mxt_process_messages_until_invalid(data); - if (ret) + + if (data->T44_address) + ret = mxt_process_messages_t44(data); + else + ret = mxt_process_messages_until_invalid(data); + if (ret < 0) break; ret = mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); From patchwork Tue Aug 27 06:31:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116201 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 E16BB14D5 for ; Tue, 27 Aug 2019 06:31:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8BD32184D for ; Tue, 27 Aug 2019 06:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726392AbfH0Gbw (ORCPT ); Tue, 27 Aug 2019 02:31:52 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:23260 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfH0Gbv (ORCPT ); Tue, 27 Aug 2019 02:31:51 -0400 IronPort-SDR: rM8szdnqnpdowMRASMiT7GiozovzTuVkyrDnTskxcc9qXdA46jMhm2Q8cvvl8mnTT9ErsFsDOK wq+Ggbc1C8kPtO4cqRZKg1zLktj5K9XQnPcCEgr3YhNEVZTBv2qQJTM43F02a4PNOs/6PbEmuQ znAPVol9zeYiy0yE6yHSCRAf6ak+WL1fzefJvTK4HTOyY8KH8XtB+eKN1UdTsjYlz8jmGq0Mlb uDhykvRoLFDY/0cnAvtaGtAgr3euuXb2Co3QiCAwN+PptSsTlQ2Akxg4xOfahsg9Kmnqjrl2Cx wUA= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40755047" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:51 -0800 IronPort-SDR: obwh3dAek/mN4gfNTNS2gwva+G7gZsieakaFMHum431ICRCuYJ4WPsdYg9t7fKjYmZlhSIj9qL Y9cLBqpC+cxehAukCdbKdY5dT9zQq59ZjobGnDAIo98NwzQ6GIzNe2JQaVmN5UoBW+PHbIZs1r svrsmQLgzWnyFwpsa2l+3FoyZtBRVXabnziwEimYR5j85xynVZJjDx0f053MeIFjMhKLWewDeY 88pGEZzryTWiiRWyYhAjjhsJl+XygcwnFSyn7srb7P9fI8+rFi/9nmG+vVaCIp62M0+mkFER0q 8OQ= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 45/49] Input: atmel_mxt_ts: use gpiod_set_value_cansleep for reset pin Date: Tue, 27 Aug 2019 15:31:57 +0900 Message-ID: <20190827063201.21048-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: Balasubramani Vivekanandan In case of remote display, touch controller will be also remote. In such cases, the reset pin of the touch controller will be controlled through bridging ICs like Deserilizer and Serializer. Therefore accessing the gpio pins require transactions with the external IC. Using the function gpiod_set_value will print a warning like below WARNING: CPU: 0 PID: 576 at drivers/gpio/gpiolib.c:1441 gpiod_set_value+0x34/0x60() CPU: 0 PID: 576 Comm: modprobe Not tainted 3.14.79-08377-g84ea22f-dirty #4 Backtrace: [<80011c58>] (dump_backtrace) from [<80011e60>] (show_stack+0x18/0x1c) [<80011e48>] (show_stack) from [<8052d7ac>] (dump_stack+0x7c/0x9c) [<8052d730>] (dump_stack) from [<800241bc>] (warn_slowpath_common+0x74/0x9c) [<80024148>] (warn_slowpath_common) from [<80024288>] (warn_slowpath_null+0x24/0x2c) [<80024264>] (warn_slowpath_null) from [<8029e070>] (gpiod_set_value+0x34/0x60) [<8029e03c>] (gpiod_set_value) from [<7f492e98>] (mxt_probe+0x1e0/0x718 [atmel_mxt_ts]) [<7f492cb8>] (mxt_probe [atmel_mxt_ts]) from [<803c4d34>] (i2c_device_probe+0xcc/0xec) [<803c4c68>] (i2c_device_probe) from [<803252a0>] (driver_probe_device+0xc0/0x200) Signed-off-by: Balasubramani Vivekanandan Signed-off-by: Vladimir Zapolskiy Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 58e54eb45cf0..1187e21a67e4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2487,7 +2487,7 @@ static void mxt_regulator_enable(struct mxt_data *data) if (!data->reg_vdd || !data->reg_avdd) return; - gpiod_set_value(data->reset_gpio, 0); + gpiod_set_value_cansleep(data->reset_gpio, 0); error = regulator_enable(data->reg_vdd); if (error) @@ -2505,7 +2505,7 @@ static void mxt_regulator_enable(struct mxt_data *data) * voltage */ msleep(MXT_REGULATOR_DELAY); - gpiod_set_value(data->reset_gpio, 1); + gpiod_set_value_cansleep(data->reset_gpio, 1); msleep(MXT_CHG_DELAY); retry_wait: @@ -4311,7 +4311,7 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) disable_irq(data->irq); } else if (data->reset_gpio) { msleep(MXT_RESET_GPIO_TIME); - gpiod_set_value(data->reset_gpio, 1); + gpiod_set_value_cansleep(data->reset_gpio, 1); msleep(MXT_RESET_INVALID_CHG); } else { dev_dbg(&client->dev, From patchwork Tue Aug 27 06:31:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116203 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 7F09414D5 for ; Tue, 27 Aug 2019 06:31:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DAB220828 for ; Tue, 27 Aug 2019 06:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729031AbfH0Gbz (ORCPT ); Tue, 27 Aug 2019 02:31:55 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:23260 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfH0Gbz (ORCPT ); Tue, 27 Aug 2019 02:31:55 -0400 IronPort-SDR: q8rVSBY2LEBHMfdPVnTSdy/7qwHjkJVg/ahGGLgBThYuTOKMG1usXiL5S8hls6blXjcJSwKdaE vJePg9ec+DPWBmHhGNPUbJHJF5ilXnHNofpSoGsSmAXuWWlFT2bZqC5yHCtIBnjCQmHUmzdXBE UGmRVsf5ELfKAHlSzwfRjaB/rMpxQ/gx2YJIU/IicfIM+2MAeHYqJk4Ze65Pbnyubddq0el4KZ xJoIW9ucsXjvJpogyMNPcr5upeSI8SAiq6UU5/+udWs35E1EShLtKgkIUAKXt7vTm0v1pJUVk5 jAI= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40755048" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:54 -0800 IronPort-SDR: 3iTZpxeB9MhSFq87ZJLQTALl+uDlXYOVXwl1QEHEvQrFqheqO5oF1K6uymuVshLG1e1AGoNglo ZEDYPh7aqL3royCd12bfHrHUMypOOdAgQRnr5vC7QQYce/njI4Dv79bUVXmspVUfOE7B7p9lQn ItHLzEzX/jBe09hbIL9jG56bCyGgkpBGWWnL74Q/8ziJPlVlUtDto5icMOZBDd+EG39mmbgr+Q etdMpr43mjzANALKW4ODALhfsHdGWSZWKgrqK8LXkQy1mwTyXsn7lgjCubiX9dmUXVKscUKSz3 JUA= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 46/49] input: touchscreen: atmel_mxt_ts: Added sysfs entry for touchscreen status Date: Tue, 27 Aug 2019 15:31:58 +0900 Message-ID: <20190827063201.21048-2-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063201.21048-1-jiada_wang@mentor.com> References: <20190827063201.21048-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: Naveen Chakka To know the current communication status of the touch controller during runtime, sysfs interface is added sysfs interface: /sys/class/i2c-dev/i2c-*/device/*/touch_dev_stat Executing the above sysfs interface provides two output values 1)Status of the touch device value 0 represents device is inactive value 1 represents device is active 2)Error counter value represents the number of times device in inactive since last read Signed-off-by: Naveen Chakka Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 109 +++++++++++++++++++++-- 1 file changed, 102 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 1187e21a67e4..5a112dfe30e4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -222,6 +223,7 @@ enum t100_type { #define MXT_CHG_DELAY 100 /* msec */ #define MXT_POWERON_DELAY 150 /* msec */ #define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ +#define MXT_WATCHDOG_TIMEOUT 1000 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -317,6 +319,12 @@ struct mxt_flash { struct delayed_work work; }; +struct mxt_statusinfo { + bool dev_status; + bool intp_triggered; + u32 error_count; +}; + /* Each client has this additional data */ struct mxt_data { struct i2c_client *client; @@ -372,6 +380,9 @@ struct mxt_data { const char *pcfg_name; const char *input_name; struct mxt_flash *flash; + struct work_struct watchdog_work; + struct timer_list watchdog_timer; + struct mxt_statusinfo mxt_status; /* Cached parameters from object table */ u16 T5_address; @@ -1621,11 +1632,30 @@ static int mxt_process_messages(struct mxt_data *data) return total_handled; } +static void mxt_start_wd_timer(struct mxt_data *data) +{ + mod_timer(&data->watchdog_timer, jiffies + + msecs_to_jiffies(MXT_WATCHDOG_TIMEOUT)); +} + +static void mxt_stop_wd_timer(struct mxt_data *data) +{ + /* + * Ensure we wait until the watchdog timer + * running on a different CPU finishes + */ + del_timer_sync(&data->watchdog_timer); + cancel_work_sync(&data->watchdog_work); + del_timer_sync(&data->watchdog_timer); +} + static irqreturn_t mxt_interrupt(int irq, void *dev_id) { struct mxt_data *data = dev_id; int ret; + data->mxt_status.intp_triggered = true; + if (data->in_bootloader) { complete(&data->chg_completion); @@ -1633,21 +1663,25 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) cancel_delayed_work_sync(&data->flash->work); ret = mxt_check_bootloader(data); - return IRQ_RETVAL(ret); + ret = IRQ_RETVAL(ret); + goto exit; } - if (!data->object_table) - return IRQ_HANDLED; + if (!data->object_table) { + ret = IRQ_HANDLED; + goto exit; + } if (data->T44_address) ret = mxt_process_messages_t44(data); else ret = mxt_process_messages(data); - if (ret <= 0) - return IRQ_NONE; - else - return IRQ_HANDLED; + ret = (ret <= 0) ? IRQ_NONE : IRQ_HANDLED; + +exit: + data->mxt_status.intp_triggered = false; + return ret; } static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, @@ -2967,6 +3001,36 @@ static int mxt_bootloader_status(struct mxt_data *data) return 0; } +static void mxt_watchdog_timer(struct timer_list *t) +{ + struct mxt_data *data = from_timer(data, t, watchdog_timer); + + if (!work_pending(&data->watchdog_work)) { + if (!data->mxt_status.intp_triggered) + schedule_work(&data->watchdog_work); + } + + mxt_start_wd_timer(data); +} + +static void mxt_watchdog_work(struct work_struct *work) +{ + struct mxt_data *data = + container_of(work, struct mxt_data, watchdog_work); + u16 info_buf; + int ret = 0; + u8 size = 2; + + ret = __mxt_read_reg(data->client, 0, size, &info_buf); + + if (ret) { + data->mxt_status.error_count++; + data->mxt_status.dev_status = false; + } else { + data->mxt_status.dev_status = true; + } +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -3944,6 +4008,22 @@ static const struct attribute_group mxt_fw_attr_group = { .attrs = mxt_fw_attrs, }; +static ssize_t mxt_touch_device_status(struct device *dev, struct + device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + int ret = 0; + + if (data->mxt_status.dev_status) + data->mxt_status.error_count = 0; + + ret = snprintf(buf, PAGE_SIZE, "%d %d\n", data->mxt_status.dev_status, + data->mxt_status.error_count); + /* clear the error counter once it is read */ + data->mxt_status.error_count = 0; + return ret; +} + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); @@ -3955,6 +4035,7 @@ static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, mxt_debug_v2_enable_store); static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); +static DEVICE_ATTR(touch_dev_stat, 0444, mxt_touch_device_status, NULL); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -3966,6 +4047,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_v2_enable.attr, &dev_attr_debug_notify.attr, &dev_attr_t25.attr, + &dev_attr_touch_dev_stat.attr, NULL }; @@ -4319,6 +4401,13 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_TIME); } + INIT_WORK(&data->watchdog_work, mxt_watchdog_work); + + /* setup watchdog timer */ + timer_setup(&data->watchdog_timer, mxt_watchdog_timer, 0); + + mxt_start_wd_timer(data); + error = mxt_initialize(data); if (error) goto err_free_object; @@ -4333,8 +4422,11 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return 0; err_free_object: + cancel_work_sync(&data->watchdog_work); + mxt_stop_wd_timer(data); mxt_free_input_device(data); mxt_free_object_table(data); + del_timer(&data->watchdog_timer); if (data->reset_gpio) { sysfs_remove_link(&client->dev.kobj, "reset"); gpiod_unexport(data->reset_gpio); @@ -4357,6 +4449,9 @@ static int mxt_remove(struct i2c_client *client) mxt_free_input_device(data); mxt_free_object_table(data); + cancel_work_sync(&data->watchdog_work); + mxt_stop_wd_timer(data); + return 0; } From patchwork Tue Aug 27 06:31:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116205 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 BCDAD14DE for ; Tue, 27 Aug 2019 06:31:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A32B720828 for ; Tue, 27 Aug 2019 06:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729364AbfH0Gb6 (ORCPT ); Tue, 27 Aug 2019 02:31:58 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:23260 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfH0Gb6 (ORCPT ); Tue, 27 Aug 2019 02:31:58 -0400 IronPort-SDR: 9Jl44zLYXnNrhQozTl29lAd90yIA3x9B7daVZtGvm2MsSJBID7Ax6O+3FpjRA7p9NNKEzZvKB0 IEJS7dcz1jkxcOQnkjP+aWriIApLChGZDdYqs3KN8Gg8rt5v44aQTz6srkAVPAj4hxeo9Xy/EB 7qncVWu5u7lgebocdRdAM91/0z3wjCcmeeL9TmrL+gUwPHEKt/EnALwS0tgiJ20ITB0MVsVchY +Re8vqsJgTsjYdlh6NhJcTnncuJES50PcpyNOsARUvJe61PWJZK2BWENrj4zyvHGIw8im20UH2 1iI= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40755049" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:31:57 -0800 IronPort-SDR: BJKMP0oi5ghNYneHeMIISc/oaQ2T6/rwuqUz8fXLn+syB/vfEnaPAowc+kdxw2TiuInDnj2IZv t4v4XIzyGJP7rtVEEJyKdk6mil1SI42Cq+ip5wHeU78CDDxESxW2HbmwhmItpdSRqO2af72Mun aw3u+pMRmijD221Gt1ylsQBDbz+e194VOuE+Uoy6qEGF9seZ7mZABNy7ZSbkxfAMA09IAEb3YZ JsObJszDfk/9l+gNr90xcG/xYMN/G2kRelhOXHRvIOcuWypwBm2tNo7wR3xE0/gXNmmPD909dX jCA= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 47/49] input: atmel_mxt_ts: added sysfs interface to update atmel T38 data Date: Tue, 27 Aug 2019 15:31:59 +0900 Message-ID: <20190827063201.21048-3-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063201.21048-1-jiada_wang@mentor.com> References: <20190827063201.21048-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: Naveen Chakka Atmel touch controller contains T38 object where a user can store its own data of length 64 bytes. T38 data will not be part of checksum calculation on executing T6 BACKUP command. format used to update the T38 data is given below: offset: offset address of the data to be written in the t38 object (in decimal) length: length of the data to be written into the t38 object(in decimal) data: actual data bytes to be written into the t38 object (values should be in hex) Ex: 1. 0 2 10 20 updates first two bytes of the t38 data with values 10 and 20 2. 19 6 10 2f 30 4a 50 60 updates 6 bytes of t38 data from the index 19-24 with hex values Signed-off-by: Naveen Chakka Signed-off-by: Sanjeev Chugh Signed-off-by: George G. Davis Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 5a112dfe30e4..63ff8a211a90 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -4024,6 +4024,106 @@ static ssize_t mxt_touch_device_status(struct device *dev, struct return ret; } +static ssize_t mxt_t38_data_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mxt_data *data = dev_get_drvdata(dev); + struct mxt_object *object; + size_t count = 0, size; + u8 i, *t38_buf; + + if (!data->object_table) + return -ENXIO; + + object = mxt_get_object(data, MXT_SPT_USERDATA_T38); + size = mxt_obj_size(object); + + /* Pre-allocate buffer large enough to hold max size of t38 object.*/ + t38_buf = kmalloc(size, GFP_KERNEL); + if (!t38_buf) + return -ENOMEM; + + count = __mxt_read_reg(data->client, object->start_address, + size, t38_buf); + if (count) + goto end; + + for (i = 0; i < size; i++) + count += scnprintf(buf + count, PAGE_SIZE - count, + "[%2u]: %02x\n", i, t38_buf[i]); + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); +end: + kfree(t38_buf); + return count; +} + +static ssize_t mxt_t38_data_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mxt_data *data = dev_get_drvdata(dev); + struct mxt_object *object; + ssize_t ret = 0, pos, offset; + unsigned int i, len, index; + u8 *t38_buf; + + if (!data->object_table) + return -ENXIO; + + object = mxt_get_object(data, MXT_SPT_USERDATA_T38); + + /* Pre-allocate buffer large enough to hold max size of t38 object.*/ + t38_buf = kmalloc(mxt_obj_size(object), GFP_KERNEL); + if (!t38_buf) + return -ENOMEM; + + ret = sscanf(buf, "%zd %d%zd", &offset, &len, &pos); + if (ret != 2) { + dev_err(dev, "Bad format: Invalid parameter to update t38\n"); + ret = -EINVAL; + goto end; + } + + if (len == 0) { + dev_err(dev, + "Bad format: Data length should not be equal to 0\n"); + ret = -EINVAL; + goto end; + } + + if (offset < 0 || ((offset + len) > 64)) { + dev_err(dev, "Invalid offset value to update t38\n"); + ret = -EINVAL; + goto end; + } + + index = pos; + for (i = 0; i < len; i++) { + ret = sscanf(buf + index, "%hhx%zd", t38_buf + i, &pos); + if (ret != 1) { + dev_err(dev, "Bad format: Invalid Data\n"); + ret = -EINVAL; + goto end; + } + index += pos; + } + + ret = __mxt_write_reg(data->client, object->start_address + offset, + len, t38_buf); + if (ret) + goto end; + + ret = mxt_t6_command(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE, + true); + if (ret) + dev_err(dev, "backup command failed\n"); + else + ret = count; +end: + kfree(t38_buf); + return ret; +} + static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); @@ -4036,6 +4136,7 @@ static DEVICE_ATTR(debug_v2_enable, S_IWUSR | S_IRUSR, NULL, static DEVICE_ATTR(debug_notify, S_IRUGO, mxt_debug_notify_show, NULL); static DEVICE_ATTR(t25, 0600, mxt_t25_selftest_show, mxt_t25_selftest_store); static DEVICE_ATTR(touch_dev_stat, 0444, mxt_touch_device_status, NULL); +static DEVICE_ATTR(t38_data, 0600, mxt_t38_data_show, mxt_t38_data_store); static struct attribute *mxt_attrs[] = { &dev_attr_fw_version.attr, @@ -4048,6 +4149,7 @@ static struct attribute *mxt_attrs[] = { &dev_attr_debug_notify.attr, &dev_attr_t25.attr, &dev_attr_touch_dev_stat.attr, + &dev_attr_t38_data.attr, NULL }; From patchwork Tue Aug 27 06:32:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116209 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 58B3014DB for ; Tue, 27 Aug 2019 06:32:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D70620828 for ; Tue, 27 Aug 2019 06:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbfH0GcC (ORCPT ); Tue, 27 Aug 2019 02:32:02 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:23260 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfH0GcB (ORCPT ); Tue, 27 Aug 2019 02:32:01 -0400 IronPort-SDR: gC4JlNbo+tdAhAGXbi8uYTLGaV501ujLCBm8KnAuoNYyxjO2LOQOQZ6N+GhISmlVwLQDY6oNKA pMhIzOvmynpbjUFsDIxWiYYA7DYzoclCn2fWFiGsviCCAD/Sd4ZIRdLgbDtk+SibfL05N3bOML 2sjF4i/RhXRlQApND2EHfiTbjeYQY5hsO5Y7S6cice1l4uCVoj7aI3w5CHcwcodH4moitqq2Qf +hpAzNsa/sJvMjYPizBEl5O08cAbma7n0mEjZICPk0ak7MMd64YnMhL9VI31aoSZue+ZkS3qOW Lak= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40755053" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:32:00 -0800 IronPort-SDR: OdbqDyCshBTNiW+SneM3EbWhUWHPNkuB+XSkUBg7zQk6pAc8FxyUkiDvWRt1wnurxrYXlSyOUj Ih9s9QuzVFoK8Z1/h2pOh46l3I/B2IHofnwpm9T2a8QgxiTdCWoiV8edf6OmYJc7KTT7gSJFCO TAS+pDv92uca5q42KDPPWQff0CJT8vv3/gw+KSv+Ez8D3TLgnZ5V5ZOAPWQm03nEm3pKLYCkEI 2ZyUgKniLj4TCfVzCf0LSVPZtnIL9ZkKRhWSrS6+tm9n2tEtUg7ncrJU41QDBvsB1w/sCi4oiu eOQ= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 48/49] Input: atmel_mxt_ts: Implement synchronization during various operation Date: Tue, 27 Aug 2019 15:32:00 +0900 Message-ID: <20190827063201.21048-4-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063201.21048-1-jiada_wang@mentor.com> References: <20190827063201.21048-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: Sanjeev Chugh There could be scope of race conditions when sysfs is being handled and at the same time, device removal is occurring. For example, we don't want the device removal to begin if the Atmel device cfg update is going on or firmware update is going on. In such cases, wait for device update to be completed before the removal continues. Thread Thread 2: ========================= ========================= mxt_update_fw_store() mxt_remove() mutex_lock(&data->lock) ... mxt_initialize() //Tries to acquire lock request_firmware_nowait() mutex_lock(&data->lock) ... ==>waits for lock() ... . ... . mutex_unlock(&data->lock) . //Gets lock and proceeds mxt_free_input_device(); ... mutex_unlock(&data->lock) //Frees atmel driver data kfree(data) If the request_firmware_nowait() completes after the driver removal, and callback is triggered. But kernel crashes since the module is already removed. This commit adds state machine to serialize such scenarios. Signed-off-by: Sanjeev Chugh Signed-off-by: Bhuvanesh Surachari Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 222 ++++++++++++++++++++--- 1 file changed, 196 insertions(+), 26 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 63ff8a211a90..a461220cd336 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -224,6 +224,7 @@ enum t100_type { #define MXT_POWERON_DELAY 150 /* msec */ #define MXT_BOOTLOADER_WAIT 36E5 /* 1 minute */ #define MXT_WATCHDOG_TIMEOUT 1000 /* msec */ +#define MXT_CONFIG_TIMEOUT 1000 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -247,6 +248,20 @@ enum t100_type { #define DEBUG_MSG_MAX 200 +enum device_state { + MXT_STATE_READY, + MXT_STATE_UPDATING_CONFIG, + MXT_STATE_UPDATING_CONFIG_ASYNC, + MXT_STATE_START, + MXT_STATE_STOP, + MXT_STATE_GOING_AWAY +}; + +enum mxt_cmd { + UPDATE_CFG, + UPDATE_FW +}; + struct mxt_info { u8 family_id; u8 variant_id; @@ -426,11 +441,15 @@ struct mxt_data { /* Indicates whether device is in suspend */ bool suspended; - /* Indicates whether device is updating configuration */ - bool updating_config; + struct mutex lock; unsigned int mtu; bool t25_status; + + /* State handling for probe/remove, open/close and config update */ + enum device_state e_state; + + struct completion update_cfg_completion; }; struct mxt_vb2_buffer { @@ -1654,6 +1673,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) struct mxt_data *data = dev_id; int ret; + mutex_lock(&data->lock); data->mxt_status.intp_triggered = true; if (data->in_bootloader) { @@ -1681,6 +1701,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) exit: data->mxt_status.intp_triggered = false; + mutex_unlock(&data->lock); + return ret; } @@ -2261,6 +2283,8 @@ static void mxt_free_object_table(struct mxt_data *data) video_unregister_device(&data->dbg.vdev); v4l2_device_unregister(&data->dbg.v4l2); #endif + mutex_lock(&data->lock); + data->object_table = NULL; kfree(data->info); data->info = NULL; @@ -2290,6 +2314,8 @@ static void mxt_free_object_table(struct mxt_data *data) data->T100_reportid_min = 0; data->T100_reportid_max = 0; data->max_reportid = 0; + + mutex_unlock(&data->lock); } static int mxt_parse_object_table(struct mxt_data *data, @@ -2971,8 +2997,15 @@ static int mxt_configure_objects(struct mxt_data *data, static void mxt_config_cb(const struct firmware *cfg, void *ctx) { + struct mxt_data *data = ctx; + mxt_configure_objects(ctx, cfg); release_firmware(cfg); + complete(&data->update_cfg_completion); + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); } static int mxt_bootloader_status(struct mxt_data *data) @@ -3085,6 +3118,15 @@ static int mxt_initialize(struct mxt_data *data) goto err_free_sysfs; if (data->cfg_name) { + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_GOING_AWAY) { + data->e_state = MXT_STATE_UPDATING_CONFIG_ASYNC; + } else { + mutex_unlock(&data->lock); + return -EBUSY; + } + reinit_completion(&data->update_cfg_completion); + mutex_unlock(&data->lock); error = request_firmware_nowait(THIS_MODULE, true, data->cfg_name, &client->dev, @@ -3864,30 +3906,58 @@ static int mxt_update_file_name(struct device *dev, char **file_name, return 0; } +static int mxt_process_operation(struct mxt_data *data, + enum mxt_cmd cmd, + void *cmd_data); + static ssize_t mxt_update_fw_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { struct mxt_data *data = dev_get_drvdata(dev); + char *filename = NULL; + int ret; + + ret = mxt_update_file_name(dev, &filename, buf, count); + if (ret) + goto out; + + ret = mxt_process_operation(data, UPDATE_FW, filename); + kfree(filename); + + if (ret) + goto out; + + return count; +out: + return ret; +} + +static int mxt_fw_update(struct mxt_data *data, + const char *filename) +{ + struct device *dev = &data->client->dev; + unsigned int len = 0; int error; - error = mxt_update_file_name(dev, &data->fw_name, buf, count); + len = strlen(filename); + error = mxt_update_file_name(dev, &data->fw_name, filename, len); if (error) return error; error = mxt_load_fw(dev); if (error) { dev_err(dev, "The firmware update failed(%d)\n", error); - count = error; - } else { - dev_info(dev, "The firmware update succeeded\n"); - - error = mxt_initialize(data); - if (error) - return error; + return error; } - return count; + error = mxt_initialize(data); + if (error) + return error; + + dev_info(dev, "The firmware update succeeded\n"); + + return error; } static ssize_t mxt_update_cfg_store(struct device *dev, @@ -3895,14 +3965,38 @@ static ssize_t mxt_update_cfg_store(struct device *dev, const char *buf, size_t count) { struct mxt_data *data = dev_get_drvdata(dev); + char *filename = NULL; + int ret; + + ret = mxt_update_file_name(dev, &filename, buf, count); + if (ret) + goto out; + + ret = mxt_process_operation(data, UPDATE_CFG, filename); + kfree(filename); + + if (ret) + goto out; + + return count; +out: + return ret; +} + +static int mxt_cfg_update(struct mxt_data *data, + char *filename) +{ + struct device *dev = &data->client->dev; const struct firmware *cfg; + unsigned int len = 0; int ret; - ret = mxt_update_file_name(dev, &data->cfg_name, buf, count); + len = strlen(filename); + ret = mxt_update_file_name(dev, &data->cfg_name, filename, len); if (ret) return ret; - ret = request_firmware(&cfg, data->cfg_name, dev); + ret = request_firmware(&cfg, data->cfg_name, &data->client->dev); if (ret < 0) { dev_err(dev, "Failure to request config file %s\n", data->cfg_name); @@ -3910,8 +4004,6 @@ static ssize_t mxt_update_cfg_store(struct device *dev, goto out; } - data->updating_config = true; - mxt_free_input_device(data); if (data->suspended) { @@ -3927,15 +4019,8 @@ static ssize_t mxt_update_cfg_store(struct device *dev, } ret = mxt_configure_objects(data, cfg); - if (ret) - goto release; - - ret = count; - -release: release_firmware(cfg); out: - data->updating_config = false; return ret; } @@ -4199,8 +4284,17 @@ static int mxt_start(struct mxt_data *data) { int ret = 0; - if (!data->suspended || data->in_bootloader) + mutex_lock(&data->lock); + if (!data->suspended) { + mutex_unlock(&data->lock); return 0; + } + if (data->in_bootloader || data->e_state != MXT_STATE_READY) { + mutex_unlock(&data->lock); + return -EBUSY; + } + data->e_state = MXT_STATE_START; + mutex_unlock(&data->lock); switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -4244,8 +4338,12 @@ static int mxt_start(struct mxt_data *data) ret = mxt_acquire_irq(data); } + mutex_lock(&data->lock); if (!ret) data->suspended = false; + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); return ret; } @@ -4254,8 +4352,19 @@ static int mxt_stop(struct mxt_data *data) { int ret; - if (data->suspended || data->in_bootloader || data->updating_config) + mutex_lock(&data->lock); + if (data->suspended) { + mutex_unlock(&data->lock); return 0; + } + if (data->in_bootloader || (data->e_state != MXT_STATE_READY && + data->e_state != MXT_STATE_GOING_AWAY)) { + mutex_unlock(&data->lock); + return -EBUSY; + } + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_STOP; + mutex_unlock(&data->lock); switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -4285,8 +4394,15 @@ static int mxt_stop(struct mxt_data *data) break; } + mutex_lock(&data->lock); data->suspended = true; + + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + mutex_unlock(&data->lock); + return 0; + } static int mxt_input_open(struct input_dev *dev) @@ -4441,12 +4557,15 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", client->adapter->nr, client->addr); + mutex_init(&data->lock); + data->client = client; i2c_set_clientdata(client, data); init_completion(&data->chg_completion); init_completion(&data->reset_completion); init_completion(&data->crc_completion); + init_completion(&data->update_cfg_completion); mutex_init(&data->debug_msg_lock); data->suspend_mode = dmi_check_system(chromebook_T9_suspend_dmi) ? @@ -4540,6 +4659,18 @@ static int mxt_remove(struct i2c_client *client) { struct mxt_data *data = i2c_get_clientdata(client); + mutex_lock(&data->lock); + if (data->e_state == MXT_STATE_UPDATING_CONFIG_ASYNC || + data->e_state == MXT_STATE_UPDATING_CONFIG) { + data->e_state = MXT_STATE_GOING_AWAY; + mutex_unlock(&data->lock); + mxt_wait_for_completion(data, &data->update_cfg_completion, + MXT_CONFIG_TIMEOUT); + } else { + data->e_state = MXT_STATE_GOING_AWAY; + mutex_unlock(&data->lock); + } + disable_irq(data->irq); sysfs_remove_group(&client->dev.kobj, &mxt_fw_attr_group); if (data->reset_gpio) { @@ -4596,6 +4727,45 @@ static int __maybe_unused mxt_resume(struct device *dev) return ret; } +static int mxt_process_operation(struct mxt_data *data, + enum mxt_cmd cmd, + void *cmd_data) +{ + int ret = 0; + + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_READY) { + mutex_unlock(&data->lock); + dev_err(&data->client->dev, "Atmel touch device is shutting down\n"); + return -EBUSY; + } + data->e_state = MXT_STATE_UPDATING_CONFIG; + reinit_completion(&data->update_cfg_completion); + mutex_unlock(&data->lock); + + switch (cmd) { + case UPDATE_CFG: + case UPDATE_FW: + if (cmd == UPDATE_CFG) + ret = mxt_cfg_update(data, (char *)cmd_data); + else + ret = mxt_fw_update(data, (char *)cmd_data); + break; + + default: + break; + } + mutex_lock(&data->lock); + if (data->e_state != MXT_STATE_UPDATING_CONFIG_ASYNC) { + complete(&data->update_cfg_completion); + if (data->e_state != MXT_STATE_GOING_AWAY) + data->e_state = MXT_STATE_READY; + } + mutex_unlock(&data->lock); + + return ret; +} + static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); static const struct of_device_id mxt_of_match[] = { From patchwork Tue Aug 27 06:32:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 11116207 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 CAF1F14DB for ; Tue, 27 Aug 2019 06:32:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B33A220828 for ; Tue, 27 Aug 2019 06:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729149AbfH0GcE (ORCPT ); Tue, 27 Aug 2019 02:32:04 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:23260 "EHLO esa2.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729545AbfH0GcE (ORCPT ); Tue, 27 Aug 2019 02:32:04 -0400 IronPort-SDR: AcdhZaMJwmtTUk+IqeN3rqsH6IHGCuWB068rm643HJ8pXx4bMGUE9DMgTrkKfer+f2OER9iz5f mHrF2mN8Lzu3vs5Z+P0js7jXiUF1ZQC+lnIea6dVmMul5DWfgXYzocFvHMSn4v/GkTwiFwbqtw /ie/v9dpIqPxi8u/6B0rhhXv6ArbhjObkA/99u7RtdDcXuDhx82HBP2OXzCYipCEV/s5h2x4eY asQGcRq3a28uhs4PRKNkUaAEyY/g4GXbjtjizqjwCvh8BeHgqmIxgtn12daFoHlUWqI2/cNOvT khI= X-IronPort-AV: E=Sophos;i="5.64,436,1559548800"; d="scan'208";a="40755058" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 26 Aug 2019 22:32:03 -0800 IronPort-SDR: mIHUgKsrd+kLjnVFW+oAZWuv2w6FEzx5ir6k+10stDNQcNVFoxS5523zlZkT+vLUMdgLphB32M OsXxwLHNza26T7VoZ7LxW03emG9simoqOWbz63o8f9XuvyqWMu1+tiU9sul29MVXtHWkBeoy3z UbzwCBUqEkWfHCfMnqGSLeSsLF3ug31QfyhRL2Ni/BS7L73bIv2UkfasbfXYa+9zt2TzXSw+e2 nYCCGTLctwd/GllnXUOdRXk/IPnXhkS2eXmPCF+cLpvbhtXqCANyEfy//bQGV2rEAnQoHZtBT6 JTo= From: Jiada Wang To: , CC: , , , Subject: [PATCH v2 49/49] Input: atmel_mxt_ts - Fix compilation warning Date: Tue, 27 Aug 2019 15:32:01 +0900 Message-ID: <20190827063201.21048-5-jiada_wang@mentor.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190827063201.21048-1-jiada_wang@mentor.com> References: <20190827063201.21048-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 fix "make W=1" compilation warnings from Atmel driver as per the compilation logs. Signed-off-by: Jiada Wang --- drivers/input/touchscreen/atmel_mxt_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index a461220cd336..115c94d3f0d4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2046,7 +2046,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg) byte_offset = reg + i - cfg->start_ofs; - if (byte_offset >= 0 && byte_offset < cfg->mem_size) { + if (byte_offset < cfg->mem_size) { *(cfg->mem + byte_offset) = val; } else { dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",