Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8364507rwl; Tue, 10 Jan 2023 12:29:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXtqLmngb8d8Uhm0V3uC2VSv86N84CO9Bcqdfr7lTWC1cAJPm9jvjkvBhC3HAMW4bluGl80S X-Received: by 2002:a05:6402:6d8:b0:462:6e5e:329a with SMTP id n24-20020a05640206d800b004626e5e329amr61234295edy.8.1673382586551; Tue, 10 Jan 2023 12:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673382586; cv=none; d=google.com; s=arc-20160816; b=HvNGi+ECHDZBVZ0QT6LCsHSlcvQYctDYtSCQruHlbH3NqPRbMhJ+Pzwaohj6JNlhfK E6lcmRDB7JUTqlfg0vqFQWQXOgVw0uwaIkHjb0HwGwDlaoaXmDhyRxJ9PMRflmUaUqE1 gPjpsyTYvUhW0mO875719olpijkKJmP5wuT3YAvn+mLBdNs6b3ORZaWmg1x73az/PQJ8 Knv8ytToXG3c92nMf0pnqxlwat6FMiKWMpsxA6hCJR8NJYapX/z8iqpI/icQ+oOq+nbD ZusZ+ehB1LqQGZbw8Q0hkUd621WIHUX2yRxHb1UTHycHBSNBzl5jGWYFuxTM02Dlzqmo tEbg== 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=ZZtOedLV/QlyXTghqPz+ASgSdVaeqyqAQ4U3JRPc5GU=; b=hOWgKBHzuNBOcmGzOjGlXDYY/92HoInduZTHi6YSG5/lpyJ7Fa2eyMMLuWBw6wNaFR DQcK8otODayiMjwMj/XamhjjSD2CGwYgDZfvlKDfhQPLbufz5c2fu0RfNnQXjLBzWJti sciO8973N/FcE+uJZL1TNlsqvrUeLNvh0nrf86om0NOlxFG/rTs8rnm0SJ8hOH80l+Q5 mUDS+NA9SGJMWeulyawoA3hC+g8QxA+zQBPSIhOFwjMctl3FNDRh1LpdseQomWvktQu8 idOHA3y5zM1zU9IiigEfkn6ysUy/ErmpTWEo3A6gA05czCV+pxOnxx7Lb+31b5jmW8jG 3zIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DAMYgjxM; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a056402278800b0046c3b3aa791si15270401ede.477.2023.01.10.12.29.33; Tue, 10 Jan 2023 12:29:46 -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=DAMYgjxM; 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 S232960AbjAJU0a (ORCPT + 53 others); Tue, 10 Jan 2023 15:26:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbjAJU0M (ORCPT ); Tue, 10 Jan 2023 15:26:12 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2208B5CF94 for ; Tue, 10 Jan 2023 12:26:11 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id z9-20020a17090a468900b00226b6e7aeeaso14784734pjf.1 for ; Tue, 10 Jan 2023 12:26:11 -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=ZZtOedLV/QlyXTghqPz+ASgSdVaeqyqAQ4U3JRPc5GU=; b=DAMYgjxMDkCD69f8legiSoDZJOGyrRXqCxPk5q0pOAfmRuhQS62TzCdsiKh0y8aw1A ct0dMlWRQwSwDm6ZgJJ1icWfUuddL4ibRv6uU/aE7pf9Px8YwwqvzzAzMOYFnhk6TzrZ VEC9fJ6YbXRfMAah2kXvxeFvw4zWEdlWyEmgY= 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=ZZtOedLV/QlyXTghqPz+ASgSdVaeqyqAQ4U3JRPc5GU=; b=kLPsADB2hzTo33A1HcMbch/GfhSuUi/k71yJK19IPsxcUY/GuhokzYHIcCQAcxmmSm /mD+pZYKaUkexf5NHDN/t1U802vehI9Pvz+P+qXJCO77JiEWRQvspk0UnAjrjsdAh5Ia 91zo2gT0NvAbXVxinESpYLCIrD50u8JkSr/mM4v+fMbsBPybJx8vUKWJ8QmLIdBLMu5C 8YVxVqYfeEVBxVO2JBfxXCCbd8L0tU2oYAJwNRWk/xiZBClNaZr2/TDc88v7KLEMWc/w 53rbfz2Jod2+AAql0L3rAblc9lmRpCLYMF1tchxDvogm/AtcfvF/A/5o1Pt3ovDQTrce abJw== X-Gm-Message-State: AFqh2kplNNuSyrdMyocISp1pRcqGETVMP+n43LBGSqwQhht1gHBbKwf2 PaX5QC3jEzH/ZcvEp3HGJiu03xPcTj2DSzQg X-Received: by 2002:a17:902:cf41:b0:192:dd42:9e66 with SMTP id e1-20020a170902cf4100b00192dd429e66mr17743867plg.12.1673382370598; Tue, 10 Jan 2023 12:26:10 -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 d17-20020a170902ced100b00168dadc7354sm8578408plg.78.2023.01.10.12.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 12:26:10 -0800 (PST) From: Allen Ballway To: ballway@chromium.org Cc: benjamin.tissoires@redhat.com, dmitry.torokhov@gmail.com, dtor@chromium.org, jikos@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, rydberg@bitmath.org Subject: [PATCH v6 RESEND] HID: multitouch: Add quirks for flipped axes Date: Tue, 10 Jan 2023 20:25:50 +0000 Message-Id: <20230110202550.651091-1-ballway@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221215172644.688044-1-ballway@chromium.org> References: <20221215172644.688044-1-ballway@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 is fixed by adding device quirks to transform the touch points into the correct spaces, from X -> MAX(X) - X, and Y -> MAX(Y) - Y. Signed-off-by: Allen Ballway --- V5 -> V6: Add another IS_ENABLED check for CONFIG_I2C_DMI_CORE because the module may not be there at all. V4 -> V5: Add IS_ENABLED check for CONFIG_DMI to prevent linker error. V3 -> V4: Move quirk logic to i2c_hid_get_dmi_quirks and remove duplicate quirks from hid-multitouch. 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 | 39 ++++++++++++++++++--- drivers/hid/hid-quirks.c | 6 ++++ drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c | 43 ++++++++++++++++++++++++ drivers/hid/i2c-hid/i2c-hid.h | 3 ++ 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 91a4d3fc30e08..622fe6928104c 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -71,6 +71,7 @@ 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_ORIENTATION_INVERT BIT(22) #define MT_INPUTMODE_TOUCHSCREEN 0x02 #define MT_INPUTMODE_TOUCHPAD 0x03 @@ -1009,6 +1010,7 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, struct mt_usages *slot) { struct input_mt *mt = input->mt; + struct hid_device *hdev = td->hdev; __s32 quirks = app->quirks; bool valid = true; bool confidence_state = true; @@ -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,9 @@ static int mt_process_slot(struct mt_device *td, struct input_dev *input, if (azimuth > max_azimuth * 2) azimuth -= max_azimuth * 4; orientation = -azimuth; + if (quirks & MT_QUIRK_ORIENTATION_INVERT) + orientation = -orientation; + } if (quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { @@ -1115,10 +1124,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 = hdev->quirks & HID_QUIRK_X_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->x : + *slot->x; + y = hdev->quirks & HID_QUIRK_Y_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_Y) - *slot->y : + *slot->y; + cx = hdev->quirks & HID_QUIRK_X_INVERT ? + input_abs_get_max(input, ABS_MT_POSITION_X) - *slot->cx : + *slot->cx; + cy = hdev->quirks & HID_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 +1757,15 @@ 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; + + /* Orientation is inverted if the X or Y axes are + * flipped, but normalized if both are inverted. + */ + if (hdev->quirks & (HID_QUIRK_X_INVERT | HID_QUIRK_Y_INVERT) && + !((hdev->quirks & HID_QUIRK_X_INVERT) + && (hdev->quirks & HID_QUIRK_Y_INVERT))) + td->mtclass.quirks = MT_QUIRK_ORIENTATION_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..78452faf3c9b4 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -19,6 +19,7 @@ #include #include "hid-ids.h" +#include "i2c-hid/i2c-hid.h" /* * Alphabetically sorted by vendor then product. @@ -1298,6 +1299,11 @@ unsigned long hid_lookup_quirk(const struct hid_device *hdev) quirks = hid_gets_squirk(hdev); mutex_unlock(&dquirks_lock); + /* Get quirks specific to I2C devices */ + if (IS_ENABLED(CONFIG_I2C_DMI_CORE) && IS_ENABLED(CONFIG_DMI) && + hdev->bus == BUS_I2C) + quirks |= i2c_hid_get_dmi_quirks(hdev->vendor, hdev->product); + return quirks; } EXPORT_SYMBOL_GPL(hid_lookup_quirk); diff --git a/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c index 8e0f67455c098..554a7dc285365 100644 --- a/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c +++ b/drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c @@ -10,8 +10,10 @@ #include #include #include +#include #include "i2c-hid.h" +#include "../hid-ids.h" struct i2c_hid_desc_override { @@ -416,6 +418,28 @@ static const struct dmi_system_id i2c_hid_dmi_desc_override_table[] = { { } /* Terminate list */ }; +static const struct hid_device_id i2c_hid_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 i2c_hid_dmi_quirk_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 *)&i2c_hid_elan_flipped_quirks, + }, + { } /* Terminate list */ +}; + struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name) { @@ -450,3 +474,22 @@ char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, *size = override->hid_report_desc_size; return override->hid_report_desc; } + +u32 i2c_hid_get_dmi_quirks(const u16 vendor, const u16 product) +{ + u32 quirks = 0; + const struct dmi_system_id *system_id = + dmi_first_match(i2c_hid_dmi_quirk_table); + + if (system_id) { + const struct hid_device_id *device_id = + (struct hid_device_id *)(system_id->driver_data); + + if (device_id && device_id->vendor == vendor && + device_id->product == product) + quirks = device_id->driver_data; + } + + return quirks; +} +EXPORT_SYMBOL_GPL(i2c_hid_get_dmi_quirks); diff --git a/drivers/hid/i2c-hid/i2c-hid.h b/drivers/hid/i2c-hid/i2c-hid.h index 96c75510ad3f1..2c7b66d5caa0f 100644 --- a/drivers/hid/i2c-hid/i2c-hid.h +++ b/drivers/hid/i2c-hid/i2c-hid.h @@ -9,6 +9,7 @@ struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name); char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, unsigned int *size); +u32 i2c_hid_get_dmi_quirks(const u16 vendor, const u16 product); #else static inline struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name) @@ -16,6 +17,8 @@ static inline struct i2c_hid_desc static inline char *i2c_hid_get_dmi_hid_report_desc_override(uint8_t *i2c_name, unsigned int *size) { return NULL; } +static inline u32 i2c_hid_get_dmi_quirks(const u16 vendor, const u16 product) +{ return 0; } #endif /** -- 2.39.0.rc1.256.g54fd8350bd-goog