From patchwork Fri Aug 11 00:44:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9894797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FB5B60352 for ; Fri, 11 Aug 2017 00:45:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A3928BCB for ; Fri, 11 Aug 2017 00:45:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ABCB28BDF; Fri, 11 Aug 2017 00:45:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A160E28BCB for ; Fri, 11 Aug 2017 00:45:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751602AbdHKApE (ORCPT ); Thu, 10 Aug 2017 20:45:04 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:37749 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbdHKApD (ORCPT ); Thu, 10 Aug 2017 20:45:03 -0400 Received: by mail-pg0-f66.google.com with SMTP id 83so1821861pgb.4; Thu, 10 Aug 2017 17:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mb5V/BcjrUBynvczvQXL2jBA6eHPunTkIXyQyk6MlSU=; b=easz2JPTGVWMCZCXauddfebm5Tku6560PHh4iDhef1rViM9AoC4Q5wS2cALnFiRJQ6 4LylKV+TUeQCgt4+Vq1bT/vR6/+oJgnbHOfVK6yKJcVyuAudA7Kh8Lcr/Jj0qojaAHoF FfXgfrWUKOtU3OnLzck0yqMtSuMsDlYS7QRES3YoLC3aIG4C96NmGLlzBaLtdEb5KMUY k2eSv3MASiL2csXsILv1CAtfhvkUvNRpkt/RBmJ7DlcXV5CglfB8tXEeHqGDkmdPdAQY 8xxVjaZfxIZjb9qEwV1NYBt6zP9xxvhzRwBvq/D6tsYa9Ibbyb54c3Pdei8vyuXKCaer hTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mb5V/BcjrUBynvczvQXL2jBA6eHPunTkIXyQyk6MlSU=; b=hyPi3hBBwN7SCe9aa5lHI+LhSy/pZ6g6YMkT8E96Lnfbemnzwy6Xhk3ZJkB2Yex6cj kemheP+0lZi2qDE/g7ZBR5duPqT2coFrajMDFOOTfTqAMPn4oAsaVd/oY/M/sF2SJo0g FepaZv8M7UeNJZyTb3hAEKh3bKOS0YWavxmo8BrdSzy1jhDiX+fzwxVof2fSMd84pv0/ B/YPIOUyjxy6thwojMKqR1FJm8nwVM1zdJ+O9/DPZYPKWyDCfrCu3JvN82pNIauCnGdU Fz7ldvXxzOw1ojVAe6mU+PuiLU1oTLFOCcfuTGLfdK2aggP3rwnBHAOat0I2A89cy1cb iWPw== X-Gm-Message-State: AHYfb5gIITsY1LQu+uedmEkE4UwKjlsJCnD6keoTvX2n4vljvkJz57i3 XSzXKyuplOGg4w== X-Received: by 10.98.139.131 with SMTP id e3mr14678401pfl.274.1502412302657; Thu, 10 Aug 2017 17:45:02 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([100.98.112.61]) by smtp.gmail.com with ESMTPSA id 133sm12722489pge.29.2017.08.10.17.45.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Aug 2017 17:45:02 -0700 (PDT) From: Dmitry Torokhov To: Jiri Kosina Cc: Benjamin Tissoires , Henrik Rydberg , Jason Gerecke , Dennis Kempin , Andrew de los Reyes , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] HID: multitouch: report MT_TOOL_PALM for non-confident touches Date: Thu, 10 Aug 2017 17:44:59 -0700 Message-Id: <20170811004500.13740-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.14.0.434.g98096fd7a8-goog Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to Microsoft specification [1] for Precision Touchpads (and Touchscreens) the devices use "confidence" reports to signal accidental touches, or contacts that are "too large to be a finger". Instead of simply marking contact inactive in this case (which causes issues if contact was originally proper and we lost confidence in it later, as this results in accidental clicks, drags, etc), let's report such contacts as MT_TOOL_PALM and let userspace decide what to do. Additionally, let's report contact size for such touches as maximum allowed for major/minor, which should help userspace that is not yet aware of MT_TOOL_PALM to still perform palm rejection. An additional complication, is that some firmwares do not report non-confident touches as active. To cope with this we delay release of such contact (i.e. if contact was active we first report it as still active MT+TOOL_PALM and then synthesize the release event in a separate frame). [1] https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/touchpad-windows-precision-touchpad-collection Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-multitouch.c | 86 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 9 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 440b999304a5..c28defe50a10 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -114,6 +114,8 @@ struct mt_device { struct timer_list release_timer; /* to release sticky fingers */ struct mt_fields *fields; /* temporary placeholder for storing the multitouch fields */ + unsigned long *pending_palm_slots; /* slots where we reported palm + and need to release */ unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ int cc_index; /* contact count field index in the report */ int cc_value_index; /* contact count value index in the field */ @@ -543,8 +545,12 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_DG_CONFIDENCE: if ((cls->name == MT_CLS_WIN_8 || cls->name == MT_CLS_WIN_8_DUAL) && - field->application == HID_DG_TOUCHPAD) + field->application == HID_DG_TOUCHPAD) { cls->quirks |= MT_QUIRK_CONFIDENCE; + input_set_abs_params(hi->input, + ABS_MT_TOOL_TYPE, + MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0); + } mt_store_field(usage, td, hi); return 1; case HID_DG_TIPSWITCH: @@ -657,6 +663,7 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { int active; + int tool; int slotnum = mt_compute_slot(td, input); struct mt_slot *s = &td->curdata; struct input_mt *mt = input->mt; @@ -671,24 +678,56 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) return; } + active = s->touch_state || s->inrange_state; + if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) s->confidence_state = 1; - active = (s->touch_state || s->inrange_state) && - s->confidence_state; + + if (likely(s->confidence_state)) { + tool = MT_TOOL_FINGER; + } else { + tool = MT_TOOL_PALM; + if (!active && + input_mt_is_active(&mt->slots[slotnum])) { + /* + * The non-confidence was reported for + * previously valid contact that is also no + * longer valid. We can't simply report + * lift-off as userspace will not be aware + * of non-confidence, so we need to split + * it into 2 events: active MT_TOOL_PALM + * and a separate liftoff. + */ + active = true; + set_bit(slotnum, td->pending_palm_slots); + } + } input_mt_slot(input, slotnum); - input_mt_report_slot_state(input, MT_TOOL_FINGER, active); + input_mt_report_slot_state(input, tool, active); if (active) { /* this finger is in proximity of the sensor */ int wide = (s->w > s->h); int major = max(s->w, s->h); int minor = min(s->w, s->h); - /* - * divided by two to match visual scale of touch - * for devices with this quirk - */ - if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { + if (unlikely(!s->confidence_state)) { + /* + * When reporting palm, set contact to maximum + * size to help userspace that does not + * recognize MT_TOOL_PALM to reject contacts + * that are too large. + */ + major = input_abs_get_max(input, + ABS_MT_TOUCH_MAJOR); + minor = input_abs_get_max(input, + ABS_MT_TOUCH_MINOR); + } else if (td->mtclass.quirks & + MT_QUIRK_TOUCH_SIZE_SCALING) { + /* + * divided by two to match visual scale of touch + * for devices with this quirk + */ major = major >> 1; minor = minor >> 1; } @@ -711,6 +750,25 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) td->num_received++; } +static void mt_release_pending_palms(struct mt_device *td, + struct input_dev *input) +{ + int slotnum; + bool need_sync = false; + + for_each_set_bit(slotnum, td->pending_palm_slots, td->maxcontacts) { + clear_bit(slotnum, td->pending_palm_slots); + + input_mt_slot(input, slotnum); + input_mt_report_slot_state(input, MT_TOOL_PALM, false); + + need_sync = true; + } + + if (need_sync) + input_sync(input); +} + /* * this function is called when a whole packet has been received and processed, * so that it can decide what to send to the input layer. @@ -719,6 +777,9 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input) { input_mt_sync_frame(input); input_sync(input); + + mt_release_pending_palms(td, input); + td->num_received = 0; if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); @@ -903,6 +964,13 @@ static int mt_touch_input_configured(struct hid_device *hdev, if (td->is_buttonpad) __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); + td->pending_palm_slots = devm_kcalloc(&hi->input->dev, + BITS_TO_LONGS(td->maxcontacts), + sizeof(long), + GFP_KERNEL); + if (!td->pending_palm_slots) + return -ENOMEM; + ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); if (ret) return ret;