Message ID | 20221213010112.3394537-1-ballway@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2560566wrr; Mon, 12 Dec 2022 17:04:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7L00fH6H22T5VLymSl3k3rAnkh8CvU93pQDBYZ6G7Jo8YbAH2SH8yfF6zfp1PtrPPXxKoS X-Received: by 2002:aa7:9627:0:b0:578:5e94:22d0 with SMTP id r7-20020aa79627000000b005785e9422d0mr8937003pfg.19.1670893459072; Mon, 12 Dec 2022 17:04:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670893459; cv=none; d=google.com; s=arc-20160816; b=UTuPui83J2AowyFobuHidTDKH0Y1BD7Ohh2dv/9WOVOPLigw6lMigQYbKglJWKzmt8 cyt3OvU6Ur6LHXa/iMcC6vA1JOx8kEIHGPqD7+lkW19IsSQMYO8c7N5tjpqtUHA9z0lk HZ6cZqMH2iPLPjvZt7vQ89pNkk/vSb/SoYMCn59+TvL5taZt8OT5HjmuhbaxTCulDTTf 3BDTQgIa6lYx56gdWNUA1T1dYv3vjYxq2XCG2e+ZHyldXytjvAu5D2EkJ2g7FuZmTd7S XaNlz1P61X3D5pS4QKbV4Xsi2DRPF+v5DE+t5ktBMWk6OdE+/Fs2ps+6fdQ1wMCqIDpq Ir0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0XnFLNyU+f87H6FII1iBQ7OGHIR5aH7bhoxNua0BSvc=; b=hZCg+AVV9yIArovh9ac6ZXCMo144qg48sAYwsHkYr0+TzrCWuYxpIillLC7cf8cHvU zi5zBhV1xZBNI8aFQLEGHp3PudIeL3OxyQ/nsBEuRLxBvFv42zmNB+vbOz5PyLVsCy1B 7vE4Zj7cRgUUCOLQ/wdGhNvRGO8dOAlXJc26uoZb5nycLU4dMoxdFhXMRTFFMPbyCngE r7p6Z4tv4v9Ua/geI+nFzUfb113i8L2FCyyUwJIxJ5QRY83A5rgYHSVFFjVFs5c4LYM6 WGTj0dHXHXmUEOz1hU94QhvU8E1aiYZd55AivCv9UzVXW94+ge1oyYKjD6hChKQWtYhf JZ9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IEwsHkAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a056a000b9000b005783f1bf8dasi6912775pfj.95.2022.12.12.17.04.05; Mon, 12 Dec 2022 17:04:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IEwsHkAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233758AbiLMBBj (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Mon, 12 Dec 2022 20:01:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233100AbiLMBBf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 12 Dec 2022 20:01:35 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C66161115 for <linux-kernel@vger.kernel.org>; Mon, 12 Dec 2022 17:01:32 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id s7so13924435plk.5 for <linux-kernel@vger.kernel.org>; Mon, 12 Dec 2022 17:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0XnFLNyU+f87H6FII1iBQ7OGHIR5aH7bhoxNua0BSvc=; b=IEwsHkAMSvqwSKxJanDbH1FYkNgyVXROZc1wRHuqToUiP44PQW0PnNv7/fXGFhndr4 z4hWVzHYSHqoIApOgZFXypROlR7Xs5kvHF7CCJ+aUBdHgIqmZC+9+J7z+tr4xiBhK/EL 4TTEG4IOlEYxqjgyl4Hu6orngOL+oEQlHuqGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0XnFLNyU+f87H6FII1iBQ7OGHIR5aH7bhoxNua0BSvc=; b=d6CBekeGxKrb6aV3zEYG+ckBo9RF+UF+5Ei+cRJL0gRSx7MiUAzc+g+fpGgLNw2jaj wJOJga4/lD6Vp0EvW0tB9emvXvIqNn84bCzl6+W3Lc9KtdBqOdNLJR11qTl+2iGrJ2mo qBPemCG636v3LrAyg0/BadrTprVdEg7owsLm565Stg3TImbaNYNlppyrw6Ay0Hs8HG1s jVRDpaKy9SxKTbO+s3avlZFaZ62ezPsHHhSgxKhSut7fLF1jkOVU70jo//7gZvlia9uD Jleuq1YyWn3tjCKysL1v3OOq8RocnfRTKEgVtf8D3zQzJ05z0Z7RrnpJySzkOzwkoHdZ xl+g== X-Gm-Message-State: ANoB5pl3n4FPUSr1Ufd1L6w+PavrltRJG4VcD3R/Y54nvU40K+bPR2ZA 1ImuRh83p3idKcxXclVNDRdGrQ== X-Received: by 2002:a05:6a20:28a0:b0:ad:58d4:2a7a with SMTP id q32-20020a056a2028a000b000ad58d42a7amr11270896pzf.22.1670893292214; Mon, 12 Dec 2022 17:01:32 -0800 (PST) Received: from ballway1.c.googlers.com.com (97.173.125.34.bc.googleusercontent.com. [34.125.173.97]) by smtp.gmail.com with ESMTPSA id jh1-20020a170903328100b00186a2274382sm7022104plb.76.2022.12.12.17.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 17:01:31 -0800 (PST) From: Allen Ballway <ballway@chromium.org> To: dmitry.torokhov@gmail.com Cc: ballway@chromium.org, benjamin.tissoires@redhat.com, dtor@chromium.org, jikos@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, rydberg@bitmath.org Subject: [PATCH v3] HID: multitouch: Add quirks for flipped axes Date: Tue, 13 Dec 2022 01:01:12 +0000 Message-Id: <20221213010112.3394537-1-ballway@chromium.org> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <Y5d29JwIxku9ubVb@google.com> References: <Y5d29JwIxku9ubVb@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751487409742814971?= X-GMAIL-MSGID: =?utf-8?q?1752058780019885573?= |
Series |
[v3] HID: multitouch: Add quirks for flipped axes
|
|
Commit Message
Allen Ballway
Dec. 13, 2022, 1:01 a.m. UTC
Certain touchscreen devices, such as the ELAN9034, are oriented
incorrectly and report touches on opposite points on the X and Y axes.
For example, a 100x200 screen touched at (10,20) would report (90, 180)
and vice versa.
This changed fixes the issue by adding device quirks to transform
the touch points into the correct spaces, from X -> MAX(X) - X,
and Y -> MAX(Y) - Y. These quirks are added in hid-quirks checking
both DMI information and device vendor and product IDs. The quirk
is handled in hid-multitouch to do the actual transformation.
Signed-off-by: Allen Ballway <ballway@chromium.org>
---
V2 -> V3: Use existing HID_QUIRK_*_INVERT and match the quirk in
hid-quirk, passing down to hid-multitouch through the hid device.
V1 -> V2: Address review comments, change to use DMI match. Confirmed
MT_TOOL_X/Y require transformation and update orientation based on
flipped axes.
drivers/hid/hid-multitouch.c | 43 ++++++++++++++++++++++++++++++++----
drivers/hid/hid-quirks.c | 33 +++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 4 deletions(-)
--
2.39.0.rc1.256.g54fd8350bd-goog
Comments
On Tue, Dec 13, 2022 at 2:01 AM Allen Ballway <ballway@chromium.org> wrote: > > Certain touchscreen devices, such as the ELAN9034, are oriented > incorrectly and report touches on opposite points on the X and Y axes. > For example, a 100x200 screen touched at (10,20) would report (90, 180) > and vice versa. > > This changed fixes the issue by adding device quirks to transform > the touch points into the correct spaces, from X -> MAX(X) - X, > and Y -> MAX(Y) - Y. These quirks are added in hid-quirks checking > both DMI information and device vendor and product IDs. The quirk > is handled in hid-multitouch to do the actual transformation. > > Signed-off-by: Allen Ballway <ballway@chromium.org> > --- > V2 -> V3: Use existing HID_QUIRK_*_INVERT and match the quirk in > hid-quirk, passing down to hid-multitouch through the hid device. > > V1 -> V2: Address review comments, change to use DMI match. Confirmed > MT_TOOL_X/Y require transformation and update orientation based on > flipped axes. > > > drivers/hid/hid-multitouch.c | 43 ++++++++++++++++++++++++++++++++---- > drivers/hid/hid-quirks.c | 33 +++++++++++++++++++++++++++ > 2 files changed, 72 insertions(+), 4 deletions(-) > > diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c > index 91a4d3fc30e08..1f4c2aa511359 100644 > --- a/drivers/hid/hid-multitouch.c > +++ b/drivers/hid/hid-multitouch.c > @@ -71,6 +71,8 @@ MODULE_LICENSE("GPL"); > #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19) > #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) > #define MT_QUIRK_DISABLE_WAKEUP BIT(21) > +#define MT_QUIRK_X_INVERT BIT(22) > +#define MT_QUIRK_Y_INVERT BIT(23) Why duplicate the already available quirks in struct hid_device? > > #define MT_INPUTMODE_TOUCHSCREEN 0x02 > #define MT_INPUTMODE_TOUCHPAD 0x03 > @@ -1086,6 +1088,10 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > int orientation = wide; > int max_azimuth; > int azimuth; > + int x; > + int y; > + int cx; > + int cy; > > if (slot->a != DEFAULT_ZERO) { > /* > @@ -1104,6 +1110,16 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > if (azimuth > max_azimuth * 2) > azimuth -= max_azimuth * 4; > orientation = -azimuth; > + > + /* Orientation is inverted if the X or Y axes are > + * flipped, but normalized if both are inverted. > + */ > + if (quirks & (MT_QUIRK_X_INVERT | MT_QUIRK_Y_INVERT) && > + !((quirks & MT_QUIRK_X_INVERT) > + && (quirks & MT_QUIRK_Y_INVERT))) { This is done in every finger slot in every report. We should probably cache that information somewhere. > + orientation = -orientation; > + } > + > } > > if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { > @@ -1115,10 +1131,23 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > minor = minor >> 1; > } > > - input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); > - input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); > - input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); > - input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); > + x = quirks & MT_QUIRK_X_INVERT ? > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x : > + *slot->x; > + y = quirks & MT_QUIRK_Y_INVERT ? > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y : > + *slot->y; > + cx = quirks & MT_QUIRK_X_INVERT ? > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx : > + *slot->cx; > + cy = quirks & MT_QUIRK_Y_INVERT ? > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->cy : > + *slot->cy; I can't help but think that there must be a better way of doing that. If I didn't postpone HID-BPF to 6.3 I would have asked you to do this as a BPF program. Still, the whole point of the slot pointers was to remove the data copy everywhere, and you are adding it back. Not to mention that the same tests and accesses to variables are called multiple times. > + > + input_event(input, EV_ABS, ABS_MT_POSITION_X, x); > + input_event(input, EV_ABS, ABS_MT_POSITION_Y, y); > + input_event(input, EV_ABS, ABS_MT_TOOL_X, cx); > + input_event(input, EV_ABS, ABS_MT_TOOL_Y, cy); > input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); > input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); > input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); > @@ -1735,6 +1764,12 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) > if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) > td->serial_maybe = true; > > + if (hdev->quirks & HID_QUIRK_X_INVERT) > + td->mtclass.quirks |= MT_QUIRK_X_INVERT; > + > + if (hdev->quirks & HID_QUIRK_Y_INVERT) > + td->mtclass.quirks |= MT_QUIRK_Y_INVERT; As mentioned above, I don't see the point in doing that duplication of quirks. > + > /* This allows the driver to correctly support devices > * that emit events over several HID messages. > */ > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c AFAICT, Dmitry told you twice to use i2c-hid, not hid-quirks.c. We already have i2c-hid-dmi-quirks.c that you could extend. The rationale is that this way, the dmi check will be done only for internal peripherals, leaving aside the USB ones. Cheers, Benjamin > index 0e9702c7f7d6c..47c6cd62f019a 100644 > --- a/drivers/hid/hid-quirks.c > +++ b/drivers/hid/hid-quirks.c > @@ -16,6 +16,7 @@ > #include <linux/export.h> > #include <linux/slab.h> > #include <linux/mutex.h> > +#include <linux/dmi.h> > #include <linux/input/elan-i2c-ids.h> > > #include "hid-ids.h" > @@ -957,6 +958,29 @@ static const struct hid_device_id hid_mouse_ignore_list[] = { > { } > }; > > +static const struct hid_device_id elan_flipped_quirks[] = { > + { HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_ELAN, 0x2dcd), > + HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT }, > + { } > +}; > + > +/* > + * This list contains devices which have specific issues based on the system > + * they're on and not just the device itself. The driver_data will have a > + * specific hid device to match against. > + */ > +static const struct dmi_system_id dmi_override_table[] = { > + { > + .ident = "DynaBook K50/FR", > + .matches = { > + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dynabook Inc."), > + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "dynabook K50/FR"), > + }, > + .driver_data = (void *)elan_flipped_quirks, > + }, > + { } /* Terminate list */ > +}; > + > bool hid_ignore(struct hid_device *hdev) > { > int i; > @@ -1238,6 +1262,7 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > { > const struct hid_device_id *bl_entry; > unsigned long quirks = 0; > + const struct dmi_system_id *system_id; > > if (hid_match_id(hdev, hid_ignore_list)) > quirks |= HID_QUIRK_IGNORE; > @@ -1249,6 +1274,14 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > if (bl_entry != NULL) > quirks |= bl_entry->driver_data; > > + system_id = dmi_first_match(dmi_override_table); > + if (system_id != NULL) { > + bl_entry = hid_match_id(hdev, system_id->driver_data); > + if (bl_entry != NULL) > + quirks |= bl_entry->driver_data; > + } > + > + > if (quirks) > dbg_hid("Found squirk 0x%lx for HID device 0x%04x:0x%04x\n", > quirks, hdev->vendor, hdev->product); > -- > 2.39.0.rc1.256.g54fd8350bd-goog >
On Tue, Dec 13, 2022 at 1:19 AM Benjamin Tissoires <benjamin.tissoires@redhat.com> wrote: > > On Tue, Dec 13, 2022 at 2:01 AM Allen Ballway <ballway@chromium.org> wrote: > > > > Certain touchscreen devices, such as the ELAN9034, are oriented > > incorrectly and report touches on opposite points on the X and Y axes. > > For example, a 100x200 screen touched at (10,20) would report (90, 180) > > and vice versa. > > > > This changed fixes the issue by adding device quirks to transform > > the touch points into the correct spaces, from X -> MAX(X) - X, > > and Y -> MAX(Y) - Y. These quirks are added in hid-quirks checking > > both DMI information and device vendor and product IDs. The quirk > > is handled in hid-multitouch to do the actual transformation. > > > > Signed-off-by: Allen Ballway <ballway@chromium.org> > > --- > > V2 -> V3: Use existing HID_QUIRK_*_INVERT and match the quirk in > > hid-quirk, passing down to hid-multitouch through the hid device. > > > > V1 -> V2: Address review comments, change to use DMI match. Confirmed > > MT_TOOL_X/Y require transformation and update orientation based on > > flipped axes. > > > > > > drivers/hid/hid-multitouch.c | 43 ++++++++++++++++++++++++++++++++---- > > drivers/hid/hid-quirks.c | 33 +++++++++++++++++++++++++++ > > 2 files changed, 72 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c > > index 91a4d3fc30e08..1f4c2aa511359 100644 > > --- a/drivers/hid/hid-multitouch.c > > +++ b/drivers/hid/hid-multitouch.c > > @@ -71,6 +71,8 @@ MODULE_LICENSE("GPL"); > > #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19) > > #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) > > #define MT_QUIRK_DISABLE_WAKEUP BIT(21) > > +#define MT_QUIRK_X_INVERT BIT(22) > > +#define MT_QUIRK_Y_INVERT BIT(23) > > Why duplicate the already available quirks in struct hid_device? This no longer seems necessary, and will be removed. > > > > > #define MT_INPUTMODE_TOUCHSCREEN 0x02 > > #define MT_INPUTMODE_TOUCHPAD 0x03 > > @@ -1086,6 +1088,10 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > int orientation = wide; > > int max_azimuth; > > int azimuth; > > + int x; > > + int y; > > + int cx; > > + int cy; > > > > if (slot->a != DEFAULT_ZERO) { > > /* > > @@ -1104,6 +1110,16 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > if (azimuth > max_azimuth * 2) > > azimuth -= max_azimuth * 4; > > orientation = -azimuth; > > + > > + /* Orientation is inverted if the X or Y axes are > > + * flipped, but normalized if both are inverted. > > + */ > > + if (quirks & (MT_QUIRK_X_INVERT | MT_QUIRK_Y_INVERT) && > > + !((quirks & MT_QUIRK_X_INVERT) > > + && (quirks & MT_QUIRK_Y_INVERT))) { > > This is done in every finger slot in every report. We should probably > cache that information somewhere. I can do this once in mt_probe and keep it saved as its own quirk. > > > + orientation = -orientation; > > + } > > + > > } > > > > if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { > > @@ -1115,10 +1131,23 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > minor = minor >> 1; > > } > > > > - input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); > > - input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); > > - input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); > > - input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); > > + x = quirks & MT_QUIRK_X_INVERT ? > > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x : > > + *slot->x; > > + y = quirks & MT_QUIRK_Y_INVERT ? > > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y : > > + *slot->y; > > + cx = quirks & MT_QUIRK_X_INVERT ? > > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx : > > + *slot->cx; > > + cy = quirks & MT_QUIRK_Y_INVERT ? > > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->cy : > > + *slot->cy; > > I can't help but think that there must be a better way of doing that. > If I didn't postpone HID-BPF to 6.3 I would have asked you to do this > as a BPF program. > > Still, the whole point of the slot pointers was to remove the data > copy everywhere, and you are adding it back. Not to mention that the > same tests and accesses to variables are called multiple times. I can move the transformation to mt_touch_input_mapping which has easier access to the quirks coming from hid_device rather than using duplicated quirks for mt_application/class. > > > + > > + input_event(input, EV_ABS, ABS_MT_POSITION_X, x); > > + input_event(input, EV_ABS, ABS_MT_POSITION_Y, y); > > + input_event(input, EV_ABS, ABS_MT_TOOL_X, cx); > > + input_event(input, EV_ABS, ABS_MT_TOOL_Y, cy); > > input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); > > input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); > > input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); > > @@ -1735,6 +1764,12 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) > > if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) > > td->serial_maybe = true; > > > > + if (hdev->quirks & HID_QUIRK_X_INVERT) > > + td->mtclass.quirks |= MT_QUIRK_X_INVERT; > > + > > + if (hdev->quirks & HID_QUIRK_Y_INVERT) > > + td->mtclass.quirks |= MT_QUIRK_Y_INVERT; > > As mentioned above, I don't see the point in doing that duplication of quirks. Will remove > > > + > > /* This allows the driver to correctly support devices > > * that emit events over several HID messages. > > */ > > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c > > AFAICT, Dmitry told you twice to use i2c-hid, not hid-quirks.c. > > We already have i2c-hid-dmi-quirks.c that you could extend. The > rationale is that this way, the dmi check will be done only for > internal peripherals, leaving aside the USB ones. I had added the quirks to hid_device to i2c-hid-dmi-quirks before trying this but they were getting stomped by the quirks coming from hid-quirks. I will move these back to i2c-hid-dmi-quirks and change hid-device to add them to whatever quirks come from hid-quirks. > > Cheers, > Benjamin > > > index 0e9702c7f7d6c..47c6cd62f019a 100644 > > --- a/drivers/hid/hid-quirks.c > > +++ b/drivers/hid/hid-quirks.c > > @@ -16,6 +16,7 @@ > > #include <linux/export.h> > > #include <linux/slab.h> > > #include <linux/mutex.h> > > +#include <linux/dmi.h> > > #include <linux/input/elan-i2c-ids.h> > > > > #include "hid-ids.h" > > @@ -957,6 +958,29 @@ static const struct hid_device_id hid_mouse_ignore_list[] = { > > { } > > }; > > > > +static const struct hid_device_id elan_flipped_quirks[] = { > > + { HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_ELAN, 0x2dcd), > > + HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT }, > > + { } > > +}; > > + > > +/* > > + * This list contains devices which have specific issues based on the system > > + * they're on and not just the device itself. The driver_data will have a > > + * specific hid device to match against. > > + */ > > +static const struct dmi_system_id dmi_override_table[] = { > > + { > > + .ident = "DynaBook K50/FR", > > + .matches = { > > + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dynabook Inc."), > > + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "dynabook K50/FR"), > > + }, > > + .driver_data = (void *)elan_flipped_quirks, > > + }, > > + { } /* Terminate list */ > > +}; > > + > > bool hid_ignore(struct hid_device *hdev) > > { > > int i; > > @@ -1238,6 +1262,7 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > > { > > const struct hid_device_id *bl_entry; > > unsigned long quirks = 0; > > + const struct dmi_system_id *system_id; > > > > if (hid_match_id(hdev, hid_ignore_list)) > > quirks |= HID_QUIRK_IGNORE; > > @@ -1249,6 +1274,14 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > > if (bl_entry != NULL) > > quirks |= bl_entry->driver_data; > > > > + system_id = dmi_first_match(dmi_override_table); > > + if (system_id != NULL) { > > + bl_entry = hid_match_id(hdev, system_id->driver_data); > > + if (bl_entry != NULL) > > + quirks |= bl_entry->driver_data; > > + } > > + > > + > > if (quirks) > > dbg_hid("Found squirk 0x%lx for HID device 0x%04x:0x%04x\n", > > quirks, hdev->vendor, hdev->product); > > -- > > 2.39.0.rc1.256.g54fd8350bd-goog > > > Thanks for the comments, Allen
On Tue, Dec 13, 2022 at 8:45 AM Allen Ballway <ballway@chromium.org> wrote: > > On Tue, Dec 13, 2022 at 1:19 AM Benjamin Tissoires > <benjamin.tissoires@redhat.com> wrote: > > > > On Tue, Dec 13, 2022 at 2:01 AM Allen Ballway <ballway@chromium.org> wrote: > > > > > > Certain touchscreen devices, such as the ELAN9034, are oriented > > > incorrectly and report touches on opposite points on the X and Y axes. > > > For example, a 100x200 screen touched at (10,20) would report (90, 180) > > > and vice versa. > > > > > > This changed fixes the issue by adding device quirks to transform > > > the touch points into the correct spaces, from X -> MAX(X) - X, > > > and Y -> MAX(Y) - Y. These quirks are added in hid-quirks checking > > > both DMI information and device vendor and product IDs. The quirk > > > is handled in hid-multitouch to do the actual transformation. > > > > > > Signed-off-by: Allen Ballway <ballway@chromium.org> > > > --- > > > V2 -> V3: Use existing HID_QUIRK_*_INVERT and match the quirk in > > > hid-quirk, passing down to hid-multitouch through the hid device. > > > > > > V1 -> V2: Address review comments, change to use DMI match. Confirmed > > > MT_TOOL_X/Y require transformation and update orientation based on > > > flipped axes. > > > > > > > > > drivers/hid/hid-multitouch.c | 43 ++++++++++++++++++++++++++++++++---- > > > drivers/hid/hid-quirks.c | 33 +++++++++++++++++++++++++++ > > > 2 files changed, 72 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c > > > index 91a4d3fc30e08..1f4c2aa511359 100644 > > > --- a/drivers/hid/hid-multitouch.c > > > +++ b/drivers/hid/hid-multitouch.c > > > @@ -71,6 +71,8 @@ MODULE_LICENSE("GPL"); > > > #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19) > > > #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) > > > #define MT_QUIRK_DISABLE_WAKEUP BIT(21) > > > +#define MT_QUIRK_X_INVERT BIT(22) > > > +#define MT_QUIRK_Y_INVERT BIT(23) > > > > Why duplicate the already available quirks in struct hid_device? > > This no longer seems necessary, and will be removed. > > > > > > > > > #define MT_INPUTMODE_TOUCHSCREEN 0x02 > > > #define MT_INPUTMODE_TOUCHPAD 0x03 > > > @@ -1086,6 +1088,10 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > > int orientation = wide; > > > int max_azimuth; > > > int azimuth; > > > + int x; > > > + int y; > > > + int cx; > > > + int cy; > > > > > > if (slot->a != DEFAULT_ZERO) { > > > /* > > > @@ -1104,6 +1110,16 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > > if (azimuth > max_azimuth * 2) > > > azimuth -= max_azimuth * 4; > > > orientation = -azimuth; > > > + > > > + /* Orientation is inverted if the X or Y axes are > > > + * flipped, but normalized if both are inverted. > > > + */ > > > + if (quirks & (MT_QUIRK_X_INVERT | MT_QUIRK_Y_INVERT) && > > > + !((quirks & MT_QUIRK_X_INVERT) > > > + && (quirks & MT_QUIRK_Y_INVERT))) { > > > > This is done in every finger slot in every report. We should probably > > cache that information somewhere. > > I can do this once in mt_probe and keep it saved as its own quirk. > > > > > > + orientation = -orientation; > > > + } > > > + > > > } > > > > > > if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { > > > @@ -1115,10 +1131,23 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, > > > minor = minor >> 1; > > > } > > > > > > - input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); > > > - input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); > > > - input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); > > > - input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); > > > + x = quirks & MT_QUIRK_X_INVERT ? > > > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x : > > > + *slot->x; > > > + y = quirks & MT_QUIRK_Y_INVERT ? > > > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y : > > > + *slot->y; > > > + cx = quirks & MT_QUIRK_X_INVERT ? > > > + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx : > > > + *slot->cx; > > > + cy = quirks & MT_QUIRK_Y_INVERT ? > > > + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->cy : > > > + *slot->cy; > > > > I can't help but think that there must be a better way of doing that. > > If I didn't postpone HID-BPF to 6.3 I would have asked you to do this > > as a BPF program. > > > > Still, the whole point of the slot pointers was to remove the data > > copy everywhere, and you are adding it back. Not to mention that the > > same tests and accesses to variables are called multiple times. > > I can move the transformation to mt_touch_input_mapping which has easier access > to the quirks coming from hid_device rather than using duplicated quirks for > mt_application/class. It looks like I won't be able to make the change in mt_touch_input_mapping because the slot values I need to transform are pointers into the hid_report coming through the device. The other use of HID_QUIRK_*_INVERT is in hid-input.c and is transforming the value before calling input_event. I see some changes to the field values happening in mt_need_to_apply_feature and doing a hid_hw_raw_request, but those seem to happen once with a fixed value and seems more expensive than just doing the transform every time, if that would even work for this. > > > > > > + > > > + input_event(input, EV_ABS, ABS_MT_POSITION_X, x); > > > + input_event(input, EV_ABS, ABS_MT_POSITION_Y, y); > > > + input_event(input, EV_ABS, ABS_MT_TOOL_X, cx); > > > + input_event(input, EV_ABS, ABS_MT_TOOL_Y, cy); > > > input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); > > > input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); > > > input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); > > > @@ -1735,6 +1764,12 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) > > > if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) > > > td->serial_maybe = true; > > > > > > + if (hdev->quirks & HID_QUIRK_X_INVERT) > > > + td->mtclass.quirks |= MT_QUIRK_X_INVERT; > > > + > > > + if (hdev->quirks & HID_QUIRK_Y_INVERT) > > > + td->mtclass.quirks |= MT_QUIRK_Y_INVERT; > > > > As mentioned above, I don't see the point in doing that duplication of quirks. > > Will remove > > > > > > + > > > /* This allows the driver to correctly support devices > > > * that emit events over several HID messages. > > > */ > > > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c > > > > AFAICT, Dmitry told you twice to use i2c-hid, not hid-quirks.c. > > > > We already have i2c-hid-dmi-quirks.c that you could extend. The > > rationale is that this way, the dmi check will be done only for > > internal peripherals, leaving aside the USB ones. > > I had added the quirks to hid_device to i2c-hid-dmi-quirks before > trying this but they were getting stomped by the quirks coming from > hid-quirks. I will move these back to i2c-hid-dmi-quirks and change > hid-device to add them to whatever quirks come from hid-quirks. I can get the quirks to come from i2c-hid-dmi-quirks.c, but the hid_device quirks reset on probe so I will need to get them again in hid_lookup_quirk. I can at least put it behind an if (bus == I2C) to keep the DMI checks to a minimum but I don't see a way to get the quirk from i2c-hid-dmi-quirks without going through hid-quirks. > > > > > Cheers, > > Benjamin > > > > > index 0e9702c7f7d6c..47c6cd62f019a 100644 > > > --- a/drivers/hid/hid-quirks.c > > > +++ b/drivers/hid/hid-quirks.c > > > @@ -16,6 +16,7 @@ > > > #include <linux/export.h> > > > #include <linux/slab.h> > > > #include <linux/mutex.h> > > > +#include <linux/dmi.h> > > > #include <linux/input/elan-i2c-ids.h> > > > > > > #include "hid-ids.h" > > > @@ -957,6 +958,29 @@ static const struct hid_device_id hid_mouse_ignore_list[] = { > > > { } > > > }; > > > > > > +static const struct hid_device_id elan_flipped_quirks[] = { > > > + { HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_ELAN, 0x2dcd), > > > + HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT }, > > > + { } > > > +}; > > > + > > > +/* > > > + * This list contains devices which have specific issues based on the system > > > + * they're on and not just the device itself. The driver_data will have a > > > + * specific hid device to match against. > > > + */ > > > +static const struct dmi_system_id dmi_override_table[] = { > > > + { > > > + .ident = "DynaBook K50/FR", > > > + .matches = { > > > + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dynabook Inc."), > > > + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "dynabook K50/FR"), > > > + }, > > > + .driver_data = (void *)elan_flipped_quirks, > > > + }, > > > + { } /* Terminate list */ > > > +}; > > > + > > > bool hid_ignore(struct hid_device *hdev) > > > { > > > int i; > > > @@ -1238,6 +1262,7 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > > > { > > > const struct hid_device_id *bl_entry; > > > unsigned long quirks = 0; > > > + const struct dmi_system_id *system_id; > > > > > > if (hid_match_id(hdev, hid_ignore_list)) > > > quirks |= HID_QUIRK_IGNORE;are > > > @@ -1249,6 +1274,14 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) > > > if (bl_entry != NULL) > > > quirks |= bl_entry->driver_data; > > > > > > + system_id = dmi_first_match(dmi_override_table); > > > + if (system_id != NULL) { > > > + bl_entry = hid_match_id(hdev, system_id->driver_data); > > > + if (bl_entry != NULL) > > > + quirks |= bl_entry->driver_data; > > > + } > > > + > > > + > > > if (quirks) > > > dbg_hid("Found squirk 0x%lx for HID device 0x%04x:0x%04x\n", > > > quirks, hdev->vendor, hdev->product); > > > -- > > > 2.39.0.rc1.256.g54fd8350bd-goog > > > > > > > Thanks for the comments, > Allen Thanks, Allen
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 91a4d3fc30e08..1f4c2aa511359 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -71,6 +71,8 @@ MODULE_LICENSE("GPL"); #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19) #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) #define MT_QUIRK_DISABLE_WAKEUP BIT(21) +#define MT_QUIRK_X_INVERT BIT(22) +#define MT_QUIRK_Y_INVERT BIT(23) #define MT_INPUTMODE_TOUCHSCREEN 0x02 #define MT_INPUTMODE_TOUCHPAD 0x03 @@ -1086,6 +1088,10 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, int orientation = wide; int max_azimuth; int azimuth; + int x; + int y; + int cx; + int cy; if (slot->a != DEFAULT_ZERO) { /* @@ -1104,6 +1110,16 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, if (azimuth > max_azimuth * 2) azimuth -= max_azimuth * 4; orientation = -azimuth; + + /* Orientation is inverted if the X or Y axes are + * flipped, but normalized if both are inverted. + */ + if (quirks & (MT_QUIRK_X_INVERT | MT_QUIRK_Y_INVERT) && + !((quirks & MT_QUIRK_X_INVERT) + && (quirks & MT_QUIRK_Y_INVERT))) { + orientation = -orientation; + } + } if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { @@ -1115,10 +1131,23 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, minor = minor >> 1; } - input_event(input, EV_ABS, ABS_MT_POSITION_X, *slot->x); - input_event(input, EV_ABS, ABS_MT_POSITION_Y, *slot->y); - input_event(input, EV_ABS, ABS_MT_TOOL_X, *slot->cx); - input_event(input, EV_ABS, ABS_MT_TOOL_Y, *slot->cy); + x = quirks & MT_QUIRK_X_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x : + *slot->x; + y = quirks & MT_QUIRK_Y_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y : + *slot->y; + cx = quirks & MT_QUIRK_X_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx : + *slot->cx; + cy = quirks & MT_QUIRK_Y_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->cy : + *slot->cy; + + input_event(input, EV_ABS, ABS_MT_POSITION_X, x); + input_event(input, EV_ABS, ABS_MT_POSITION_Y, y); + input_event(input, EV_ABS, ABS_MT_TOOL_X, cx); + input_event(input, EV_ABS, ABS_MT_TOOL_Y, cy); input_event(input, EV_ABS, ABS_MT_DISTANCE, !*slot->tip_state); input_event(input, EV_ABS, ABS_MT_ORIENTATION, orientation); input_event(input, EV_ABS, ABS_MT_PRESSURE, *slot->p); @@ -1735,6 +1764,12 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) td->serial_maybe = true; + if (hdev->quirks & HID_QUIRK_X_INVERT) + td->mtclass.quirks |= MT_QUIRK_X_INVERT; + + if (hdev->quirks & HID_QUIRK_Y_INVERT) + td->mtclass.quirks |= MT_QUIRK_Y_INVERT; + /* This allows the driver to correctly support devices * that emit events over several HID messages. */ diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index 0e9702c7f7d6c..47c6cd62f019a 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -16,6 +16,7 @@ #include <linux/export.h> #include <linux/slab.h> #include <linux/mutex.h> +#include <linux/dmi.h> #include <linux/input/elan-i2c-ids.h> #include "hid-ids.h" @@ -957,6 +958,29 @@ static const struct hid_device_id hid_mouse_ignore_list[] = { { } }; +static const struct hid_device_id elan_flipped_quirks[] = { + { HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_ELAN, 0x2dcd), + HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT }, + { } +}; + +/* + * This list contains devices which have specific issues based on the system + * they're on and not just the device itself. The driver_data will have a + * specific hid device to match against. + */ +static const struct dmi_system_id dmi_override_table[] = { + { + .ident = "DynaBook K50/FR", + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dynabook Inc."), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "dynabook K50/FR"), + }, + .driver_data = (void *)elan_flipped_quirks, + }, + { } /* Terminate list */ +}; + bool hid_ignore(struct hid_device *hdev) { int i; @@ -1238,6 +1262,7 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) { const struct hid_device_id *bl_entry; unsigned long quirks = 0; + const struct dmi_system_id *system_id; if (hid_match_id(hdev, hid_ignore_list)) quirks |= HID_QUIRK_IGNORE; @@ -1249,6 +1274,14 @@ static unsigned long hid_gets_squirk(const struct hid_device *hdev) if (bl_entry != NULL) quirks |= bl_entry->driver_data; + system_id = dmi_first_match(dmi_override_table); + if (system_id != NULL) { + bl_entry = hid_match_id(hdev, system_id->driver_data); + if (bl_entry != NULL) + quirks |= bl_entry->driver_data; + } + + if (quirks) dbg_hid("Found squirk 0x%lx for HID device 0x%04x:0x%04x\n", quirks, hdev->vendor, hdev->product);