From patchwork Fri May 12 14:23:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9724349 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 B8F5860382 for ; Fri, 12 May 2017 14:23:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B475C28829 for ; Fri, 12 May 2017 14:23:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A89E72882F; Fri, 12 May 2017 14:23:17 +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 8ED6528829 for ; Fri, 12 May 2017 14:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754462AbdELOXP (ORCPT ); Fri, 12 May 2017 10:23:15 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35103 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbdELOXO (ORCPT ); Fri, 12 May 2017 10:23:14 -0400 Received: by mail-wr0-f194.google.com with SMTP id g12so7821945wrg.2 for ; Fri, 12 May 2017 07:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Sehsb9aRLxS16qDMKfjBV5ys8pRdO7P6eDqotzTEyFU=; b=ivT4xPC67bNxQ16oHTbsF0+qulBrek4/Zga/qWgMQ0IBOIufHjIoDG6v5Uk+GXtRsK 2oHmhaUinkiB1B9CBEzLoAKEKLMIYEbaeCixSKSmfJ7uWHmWoKc7uNCHcYOAA0Kpou4T xnaIPB4+qo9F7wpnJQZeAj+ogPkIs37og+BOAok8A1UgJjGuKLgtgWlkvwC6tVXm495k /afFWp8wLnBJ6e9iSt8CTDxg5pa/zOAZGdjwHDQfC8xoZW2xUpq8v6MuCmOBzrzfMbK9 dZLwuclm1xi2Cs+ajV2V7vJe8XpE17QVDwA0vlhmn37ZOk1caoHdggxH1PDhcQHIUdiM W/uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Sehsb9aRLxS16qDMKfjBV5ys8pRdO7P6eDqotzTEyFU=; b=RBlvYEu9FQ43H7LmRvAVlU1MEYK77exKx7j/NJakfsNmapYPBrXd6fdVyk2l90ZDgQ aR7Fd94wS9SffbcB5tP1f+KdnZEYrrWdDDKyAE2aE4YfEnOTk7RQKunZre6NlqkPmF7L sTp9y+WTzHEN7WQ3RPDN6l6XE3CaieTajM5wcIPiug2AKcEEgMcTN3Ms4c25VVz72Cbh 8crlvqdSsOd/BLvfMzIcLiPPduD4rL1u/qJxn4ifGAMYb9eSxawDbTCqiEqxuyqtmWUj qZCXpJSj5gxeVg/trW2rCl/I6bxH1Ofu0Z8haiR/8gTCHXl5qtx/ea5/TQZRat/kP381 QTKw== X-Gm-Message-State: AODbwcDZMQjkuFbuZMmlSc/5zRdC6rNTOfDhFUiV+n+ilVbYosyqS3gH U3j+fKvJOuTL2g== X-Received: by 10.223.154.226 with SMTP id a89mr3286684wrc.192.1494598992806; Fri, 12 May 2017 07:23:12 -0700 (PDT) Received: from plouf.banquise.eu (gra33-3-88-180-253-3.fbx.proxad.net. [88.180.253.3]) by smtp.googlemail.com with ESMTPSA id i3sm3652791wmb.13.2017.05.12.07.23.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2017 07:23:11 -0700 (PDT) Subject: Re: Missing release event for Synaptics touchscreen To: Arek Burdach Cc: Martin Kepplinger , Andrew Duggan , =?UTF-8?Q?St=c3=a9phane_Chatty?= , linux-input References: <708339c2-2b70-81ae-a939-ac122e5fd6f2@gmail.com> <1f16ba27-99cd-d16d-f09f-97dcda1bd358@gmail.com> <03d13b14-1f97-eee7-4131-60ef014cbf50@gmail.com> <8c492623-d37c-e8e1-2445-cf86109dad44@ginzinger.com> <9e370d9b-a2d4-9fcd-9b0d-2d97e225188a@ginzinger.com> <8566ae03-faad-a1ee-2156-db49d36cea71@ginzinger.com> <540cd246-d72f-a9eb-9618-ff2449384a21@ginzinger.com> <8d690a3d-88f6-cef9-b271-da5dcc87741b@gmail.com> <12ac2e90-ba7b-8a29-bb35-40d50841a63b@ginzinger.com> <27a556e7-2045-2d6a-3b13-287d314375d5@gmail.com> From: Benjamin Tissoires Message-ID: Date: Fri, 12 May 2017 16:23:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US 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 On 05/12/2017 09:57 AM, Arek Burdach wrote: > > > On 12.05.2017 09:39, Benjamin Tissoires wrote: >> On Fri, May 12, 2017 at 9:25 AM, Arek Burdach >> wrote: >>> >>> On 12.05.2017 08:56, Martin Kepplinger wrote: >>>>>>>>> No, you won't have "move after hold>5s" broken. Because at the HID >>>>>>>>> level, the device is supposed to send an update on every touch >>>>>>>>> when >>>>>>>>> reporting a touch (for Windows 8 devices). So if there are tiny >>>>>>>>> movements filtered at the input level in the kernel, we will get >>>>>>>>> those >>>>>>>>> and I suspect the timeout will only appear when the finger actual >>>>>>>>> leaves the surface. >>>>>>>> ok. sounds a little more like a solution in the kernel would be >>>>>>>> justified. Isn't it? It still feels dangerously ugly. >>>>>>>> >>>>>>>> Mainly I wanted to point out that if you somehow have to stay with >>>>>>>> "no" >>>>>>>> for such broken devices, tslib would be a garbage can for userspace >>>>>>>> workarounds. (in this case, most probably a new device-specific >>>>>>>> hidraw >>>>>>>> based module). >>>> (...) >>>> >>>>> Thank you for clarification. So do someone have an idea how it is >>>>> possible that Windows manages this? From my point of view, they can't >>>>> rely on timeouts because effect is visible immediately after releasing >>>>> finger. Is it possible that they use other protocol for communication >>>>> with device then we do? Because beside that, I don't see any other >>>>> option - there is too few information from device to correctly handle >>>>> this situation. >>>> hey, Benjamin explained what most probably is going on, see above, so: >>>> >>>> 1. convice yourself that microsoft isn't using out-of-band data by >>>> sniffing the connection. >>> Touchscreen is communicating via i2c - am i right? Can you recommend >>> some >>> i2c sniffer for windows? >> I wrote something few months ago: >> https://github.com/bentiss/SimplePeripheralBusProbe >> But it requires you to have confidence in not breaking your EFI :) >> >> I can help you setting the bits up if you want. >> >>>> 2. if not, and Benjamin is right, come up with a timer- and hidraw >>>> based >>>> solution (I guess) and convince him and Dmitry to take it. >>>> >>>> 3. if they don't see any chance to support such broken behaviour in the >>>> kernel, which could as well be and also has it's benefits in some way, >>>> you write the thing in userspace (a tslib raw module is only one >>>> example >>>> that would make it easy for you). >>>> >>>> Even *if* Synaptics would come up with a firmware update: >>>> 1. the current firmware is already out there in the wild; >>>> 2. it takes time and work to get people to update >>>> >>>> so, if I had the device, I'd write a workaround. >>> It is reasonable what you've wrote. The only blocker for me is that I >>> have >>> almost zero-experience in low level programming. I'm from java world >>> :-) It >>> is why I was looking for some low entry level solution. I'll do my >>> best but >>> every helping hand will be appreciated. >> I am currently checking the requirements for the devices to be >> validated by Microsoft: >> https://msdn.microsoft.com/en-us/windows/hardware/commercialize/design/compatibility/1703/device-input-digitizer >> >> >> I would believe that the Latency and ReportRate requirements mean that >> as long as a finger is there, it should be reported at at least 60Hz, >> meaning that if there are no input reports for more than 16 ms, all >> fingers should be lifted. I think we can work something like that >> (taking an arbitrary multiple of 60 Hz would prevent any system lag), >> and release the touches if nothing comes in for, lets say, 250ms. > > Thank you Benjamin, it is significant brick for building knowledge how > this devices are handled in Windows. I will take a look in our drivers > and will try to understand the code and find the way how to handle it. > >> >> I should be able to work on that for Win8 devices. Win7 devices are a >> different beast, but hopefully they are nearly extinct or at least >> quirked in the kernel for them to be working. >> I have something which seems to compile, but for various reasons I haven't tested it (yet): --- (the (1 << X) -> BIT(X) conversion needs to be done in a separate patch). From what I can read in the documentation, this might be enough. However, I wouldn't be surprised if this segfaults for whatever reasons. Also note that there is no guards between the execution of the release and the incoming events. So if you wait around 250 ms between 2 touches, nothing prevents a race between the timeout previously started and the actual true touches. But it might be enough to have a good test case and see if this works well in your case and in most Win8 devices. Cheers, Benjamin -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 24d5b6d..2ce0e96 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -44,6 +44,7 @@ #include #include #include +#include MODULE_AUTHOR("Stephane Chatty "); @@ -54,22 +55,23 @@ MODULE_LICENSE("GPL"); #include "hid-ids.h" /* quirks to control the device */ -#define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0) -#define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1) -#define MT_QUIRK_CYPRESS (1 << 2) -#define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3) -#define MT_QUIRK_ALWAYS_VALID (1 << 4) -#define MT_QUIRK_VALID_IS_INRANGE (1 << 5) -#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) -#define MT_QUIRK_CONFIDENCE (1 << 7) -#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) -#define MT_QUIRK_NO_AREA (1 << 9) -#define MT_QUIRK_IGNORE_DUPLICATES (1 << 10) -#define MT_QUIRK_HOVERING (1 << 11) -#define MT_QUIRK_CONTACT_CNT_ACCURATE (1 << 12) -#define MT_QUIRK_FORCE_GET_FEATURE (1 << 13) -#define MT_QUIRK_FIX_CONST_CONTACT_ID (1 << 14) -#define MT_QUIRK_TOUCH_SIZE_SCALING (1 << 15) +#define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0) +#define MT_QUIRK_SLOT_IS_CONTACTID BIT(1) +#define MT_QUIRK_CYPRESS BIT(2) +#define MT_QUIRK_SLOT_IS_CONTACTNUMBER BIT(3) +#define MT_QUIRK_ALWAYS_VALID BIT(4) +#define MT_QUIRK_VALID_IS_INRANGE BIT(5) +#define MT_QUIRK_VALID_IS_CONFIDENCE BIT(6) +#define MT_QUIRK_CONFIDENCE BIT(7) +#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE BIT(8) +#define MT_QUIRK_NO_AREA BIT(9) +#define MT_QUIRK_IGNORE_DUPLICATES BIT(10) +#define MT_QUIRK_HOVERING BIT(11) +#define MT_QUIRK_CONTACT_CNT_ACCURATE BIT(12) +#define MT_QUIRK_FORCE_GET_FEATURE BIT(13) +#define MT_QUIRK_FIX_CONST_CONTACT_ID BIT(14) +#define MT_QUIRK_TOUCH_SIZE_SCALING BIT(15) +#define MT_QUIRK_STICKY_FINGERS BIT(16) #define MT_INPUTMODE_TOUCHSCREEN 0x02 #define MT_INPUTMODE_TOUCHPAD 0x03 @@ -104,6 +106,7 @@ struct mt_fields { struct mt_device { struct mt_slot curdata; /* placeholder of incoming data */ struct mt_class mtclass; /* our mt device class */ + struct timer_list release_timer; /* to release sticky fingers */ struct mt_fields *fields; /* temporary placeholder for storing the multitouch fields */ int cc_index; /* contact count field index in the report */ @@ -212,7 +215,8 @@ static struct mt_class mt_classes[] = { .quirks = MT_QUIRK_ALWAYS_VALID | MT_QUIRK_IGNORE_DUPLICATES | MT_QUIRK_HOVERING | - MT_QUIRK_CONTACT_CNT_ACCURATE }, + MT_QUIRK_CONTACT_CNT_ACCURATE | + MT_QUIRK_STICKY_FINGERS }, { .name = MT_CLS_EXPORT_ALL_INPUTS, .quirks = MT_QUIRK_ALWAYS_VALID | MT_QUIRK_CONTACT_CNT_ACCURATE, @@ -813,6 +817,9 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) if (td->num_received >= td->num_expected) mt_sync_frame(td, report->field[0]->hidinput->input); + + if (td->mtclass.quirks & MT_QUIRK_STICKY_FINGERS) + mod_timer(&td->release_timer, msecs_to_jiffies(250)); } static int mt_touch_input_configured(struct hid_device *hdev, @@ -1124,6 +1131,35 @@ static void mt_fix_const_fields(struct hid_device *hdev, unsigned int usage) } } +static void mt_release_contacts(struct hid_device *hid) +{ + struct hid_input *hidinput; + + list_for_each_entry(hidinput, &hid->inputs, list) { + struct input_dev *input_dev = hidinput->input; + struct input_mt *mt = input_dev->mt; + int i; + + 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_sync_frame(input_dev); + input_sync(input_dev); + } + } +} + +static void mt_expired_timeout(unsigned long arg) +{ + struct hid_device *hdev = (void*)arg; + + mt_release_contacts(hdev); +} + static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret, i; @@ -1193,6 +1229,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) */ hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; + setup_timer(&td->release_timer, mt_expired_timeout, (long)hdev); + ret = hid_parse(hdev); if (ret != 0) return ret; @@ -1220,28 +1258,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) } #ifdef CONFIG_PM -static void mt_release_contacts(struct hid_device *hid) -{ - struct hid_input *hidinput; - - list_for_each_entry(hidinput, &hid->inputs, list) { - struct input_dev *input_dev = hidinput->input; - struct input_mt *mt = input_dev->mt; - int i; - - 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_sync_frame(input_dev); - input_sync(input_dev); - } - } -} - static int mt_reset_resume(struct hid_device *hdev) { mt_release_contacts(hdev); @@ -1266,6 +1282,8 @@ static void mt_remove(struct hid_device *hdev) { struct mt_device *td = hid_get_drvdata(hdev); + del_timer_sync(&mt->release_timer); + sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); hid_hw_stop(hdev); hdev->quirks = td->initial_quirks;