From patchwork Thu Aug 8 12:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 818334 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2029.outbound.protection.outlook.com [40.92.102.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C985418C32B; Thu, 8 Aug 2024 12:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118854; cv=fail; b=cHYN7cFPhFUboA6xINbukWeIpJ817klZ6JjJyFa8wWZ7bLsY6dbDtOiHWgS0mW4FIZsSEPtE2jgWFblZ9FAWcaqnBJq35cV41J4FggC3FGbDeY+zCr3rQItwRam2p3UfdwAKVAZzS51KNp2CRN9dvjKZ+dZdgJeq93M+so5MD1Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118854; c=relaxed/simple; bh=Akx0MrXpd+JVj1ZDV4IdDdBaVXlyzdtgQ3clE80/1X4=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=bB0juI1maysrdlZ2b8O7D4e10agsc5ReFZ39iZTU9ejqzZb//p2bokce4sjKGayK3LBSNk0ihNiHChrtbU/YLeCD3UPGdzNeRseihXoNdI7H9iCdoFBnzW7naHx2B2jnYzo7rtEVdKU0n4a2fS0MAPb72xSxHYFCK+hATkf8tC8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=sSexBAJ7; arc=fail smtp.client-ip=40.92.102.29 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="sSexBAJ7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JN5hBrVwrBGNUKqhu7vqTNmZ4sRWxH49ATp31uw6hiSYHocJBlFGl5QzS2clijqrlDigtqGEf6I6VUDgxhvAaw3MF2Jt8OK1Wv6SH7WzAtwxAXIASCncN9Hi/vw1Sw70wrhftkACNVk1dMTTEqq8/wB/opPnQh7EL2pcvzLFiDxM6DrscVbFwsWv4olA4Q/Fqs1LQarexWzLQX7WX++PFq+TR0KmVjK03hNACarhfDVkU8jW9a0izjh4yVB9blmntBXOn3xTjsSEsB68YDl9bgzEZpjqFkbCFi7ccrDZUZdwOnGsFaVqytZ0mLsNTsD2FXaBNd39a4Rcw2WkclC+Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Akx0MrXpd+JVj1ZDV4IdDdBaVXlyzdtgQ3clE80/1X4=; b=hW69tmMsmxl41Y893qghhIsWKIKSeAhb+4qDTH4BZWaI121I1oIBFYx2EAhaINIH3bnYfBWWSBg1rF2MeN8tY/EI2DcqfblML8j5AlWFLHQmFz4ha1at+5jKNqiJoBL0G3W3/lcB405MjPKr/+l/isp5bezJlpk5dUbpDQNfcqtawW6Bw9kKTjTgv1U+INmFNvIOkbiuyjMrkcbHBFOZOsdFIRL4B3Awq5Ss4KgFAE9FmSNrTlscMAfNQ5tS3c6ZxGaVU3DwsVpI5OywVPWyU4/iHxndFWky66qsvYaPZ3bKbf7zsgHFlumGL7FEb0tY3xoXwmJgONkDUAd9+aiv5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Akx0MrXpd+JVj1ZDV4IdDdBaVXlyzdtgQ3clE80/1X4=; b=sSexBAJ7nyyUfEFM6L32I6Uvke7ddP7M9vJPJEK2Euh9TVnNbVjJxXKv1jQfI6WmBjUrSrtdil0fPIblXtqvWSGY4G+4ZEg09xovPx6vJWLeUaZ5u/bSUcc8gcaoOoQXsC3jGQgLrEDHQ703CuDwxyUoUfqRps4CF9RKhlW/y1xZFlI/qMskxNuLzHOgJvhhTyBiXxF69AV6/PGhAZr5If5CauKArFmhRJg8DdA/06kNZbHVG9P2CBldt2bWG2fCDoiejSbyUAl+vVEbSkeewbfYAUyi4AhAH9c9VK9QHprFp+KlP8r0F7s6qgokyhT09B1GEqbq/1XmavlvMez4tQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB1715.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:18a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 12:07:16 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:07:16 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH RESEND v2 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHa6YuC5IPUsnXZekKbwyV8lGjPIQ== Date: Thu, 8 Aug 2024 12:07:16 +0000 Message-ID: <609161BA-599E-4645-80E5-C698C17CD646@live.com> References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [A7If//+lIjMaR4xDVvuUYc/d/yD2GhnHS3h+YFjW0AM2apUsNy4KjRrt6D/zOxxTTSMKuINyRDU=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB1715:EE_ x-ms-office365-filtering-correlation-id: f1d50f99-6e69-4087-c116-08dcb7a2a55a x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: B+fzerewJsnAam07YMzvdUVsJ3GBZMo4ms9OAftkuqOKf+Aa+Pv10P78f9zXf+q5s/dM6wAkv7zQDpfLQuVlQ4wL0Ltkdwri4THrpzq7u3YJaHPerJe3I2zG9RTznn9WVL636vmdW20NEC4KVrsvcpXjJ4+Am4i/nbzfbGSf4xSoxEHXtsG8GQTf0YuO99ilrY/tb8sB7cejEWUDzZbJd4NdQb5pCU16fsEbYlDUPJUTaQYf+GWhiQU0t4G3KC5+tCcHzaYy7nEoncT0xBde1++oEvWXJKoEOHUJYanuEKrp878e0GJqsOryL8xBe4X9B41lGA7hWYs/UhJNiF6fz5t0P1AxEd3KMmljLqhqWItRPdKgRAY4UeCwavHvCw/L00vXsBJsVj/QCwSLMrejadqjo8+iMWukSjTbj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W4T0FHHRWfz4QqZsVUXZEV9Dh4rZD5Pgyo/Jy/ZyScwkZR9pOgJrVCtQaHluCW1?= =?utf-8?q?F3EAfQ/99cd3/xEJOHy8yk5RijYFT33GG+Aej6WeLCwnPChGKYpkFBdq7xbc6MjVF?= =?utf-8?q?LHpC5MIxrx0V+258nKBYaPPEZf+7B0kQE5Tyc/LHePfwfJeSmxhMzktGh5Fw/ZuQf?= =?utf-8?q?uzToTSjhvR2bxXMkUEOEouXP6v/uMp9Cfy+UMQMUby3l+ru0PRNp4H4UfDhnT8bcG?= =?utf-8?q?aBxXDyKTDU7qR1uS2MRzwWq6SL1Tos9niG6LDKn1taVL6sJZO4Ix6oOLcptB9QL5M?= =?utf-8?q?XeZh8aYdcr/h8G5gYfBizRnGgU5E4TdNbfR3KK4z5+wtju6rduC5rqNipoqw8yOMO?= =?utf-8?q?RK0sBmDAzOi5WA1/mc4DZjX9IH/TPCBeCYyIqKCbHIx+FLYoTcOrv3bG3Wj6/SKWH?= =?utf-8?q?lXFIvma7DQ6wSTbxVWdoa1Je6gPZPW7qwuWnhKlipw7uYkA+oazAjkS4y0YEQCXAf?= =?utf-8?q?JBOkWumJG0NmjJJBFKeK3WBPSGR/l0tDiNqxQagt8TqQj+XSxy4jFh7boIS9DbJnr?= =?utf-8?q?JnMnC71j+XCINnLZOXmV1un3GudMVPTFLPjvoN+8gFcSxXAY2QFwvaFSwbR7QeLFJ?= =?utf-8?q?6uOp5E4p6nxczHgfRZYJT7riITpgYqc1/hAF2GR98iPe81H6x2tj2US0QPWg30nGt?= =?utf-8?q?h5eR4DivCJ/5xJ05?= Content-ID: Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: f1d50f99-6e69-4087-c116-08dcb7a2a55a X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:07:16.6160 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB1715 From: Kerem Karabay This commit adds a driver for the backlight of Apple Touch Bars on x86 Macs. Note that currently only T2 Macs are supported. This driver is based on previous work done by Ronald Tschalär . Signed-off-by: Kerem Karabay Co-developed-by: Aditya Garg Signed-off-by: Aditya Garg --- MAINTAINERS | 6 + drivers/hid/Kconfig | 10 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-appletb-bl.c | 206 +++++++++++++++++++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 5 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 drivers/hid/hid-appletb-bl.c diff --git a/MAINTAINERS b/MAINTAINERS index 8766f3e5e..ac27f41d4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9931,6 +9931,12 @@ F: include/linux/pm.h F: include/linux/suspend.h F: kernel/power/ +HID APPLE TOUCH BAR DRIVERS +M: Kerem Karabay +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/hid/hid-appletb-* + HID CORE LAYER M: Jiri Kosina M: Benjamin Tissoires diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 08446c89e..4988c1fb2 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -148,6 +148,16 @@ config HID_APPLEIR Say Y here if you want support for Apple infrared remote control. +config HID_APPLETB_BL + tristate "Apple Touch Bar Backlight" + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y here if you want support for the backlight of Touch Bars on x86 + MacBook Pros. + + To compile this driver as a module, choose M here: the + module will be called hid-appletb-bl. + config HID_ASUS tristate "Asus" depends on USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index e40f1ddeb..1d825a474 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_HID_ALPS) += hid-alps.o obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o +obj-$(CONFIG_HID_APPLETB_BL) += hid-appletb-bl.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o obj-$(CONFIG_HID_AUREAL) += hid-aureal.o diff --git a/drivers/hid/hid-appletb-bl.c b/drivers/hid/hid-appletb-bl.c new file mode 100644 index 000000000..00bbe45df --- /dev/null +++ b/drivers/hid/hid-appletb-bl.c @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Apple Touch Bar Backlight Driver + * + * Copyright (c) 2017-2018 Ronald Tschalär + * Copyright (c) 2022-2023 Kerem Karabay + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#include "hid-ids.h" + +#define APPLETB_BL_ON 1 +#define APPLETB_BL_DIM 3 +#define APPLETB_BL_OFF 4 + +#define HID_UP_APPLEVENDOR_TB_BL 0xff120000 + +#define HID_VD_APPLE_TB_BRIGHTNESS 0xff120001 +#define HID_USAGE_AUX1 0xff120020 +#define HID_USAGE_BRIGHTNESS 0xff120021 + +static int appletb_bl_def_brightness = 2; +module_param_named(brightness, appletb_bl_def_brightness, int, 0444); +MODULE_PARM_DESC(brightness, "Default brightness:\n" + " 0 - Touchbar is off\n" + " 1 - Dim brightness\n" + " [2] - Full brightness"); + +struct appletb_bl { + struct hid_field *aux1_field, *brightness_field; + struct backlight_device *bdev; + + bool full_on; +}; + +const u8 appletb_bl_brightness_map[] = { + APPLETB_BL_OFF, + APPLETB_BL_DIM, + APPLETB_BL_ON +}; + +static int appletb_bl_set_brightness(struct appletb_bl *bl, u8 brightness) +{ + struct hid_report *report = bl->brightness_field->report; + struct hid_device *hdev = report->device; + int ret; + + ret = hid_set_field(bl->aux1_field, 0, 1); + if (ret) { + hid_err(hdev, "Failed to set auxiliary field (%pe)\n", ERR_PTR(ret)); + return ret; + } + + ret = hid_set_field(bl->brightness_field, 0, brightness); + if (ret) { + hid_err(hdev, "Failed to set brightness field (%pe)\n", ERR_PTR(ret)); + return ret; + } + + if (!bl->full_on) { + ret = hid_hw_power(hdev, PM_HINT_FULLON); + if (ret < 0) { + hid_err(hdev, "Device didn't power on (%pe)\n", ERR_PTR(ret)); + return ret; + } + + bl->full_on = true; + } + + hid_hw_request(hdev, report, HID_REQ_SET_REPORT); + + if (brightness == APPLETB_BL_OFF) { + hid_hw_power(hdev, PM_HINT_NORMAL); + bl->full_on = false; + } + + return 0; +} + +static int appletb_bl_update_status(struct backlight_device *bdev) +{ + struct appletb_bl *bl = bl_get_data(bdev); + u16 brightness; + + if (bdev->props.state & BL_CORE_SUSPENDED) + brightness = 0; + else + brightness = backlight_get_brightness(bdev); + + return appletb_bl_set_brightness(bl, appletb_bl_brightness_map[brightness]); +} + +static const struct backlight_ops appletb_bl_backlight_ops = { + .options = BL_CORE_SUSPENDRESUME, + .update_status = appletb_bl_update_status, +}; + +static int appletb_bl_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + struct hid_field *aux1_field, *brightness_field; + struct backlight_properties bl_props = { 0 }; + struct device *dev = &hdev->dev; + struct appletb_bl *bl; + int ret; + + ret = hid_parse(hdev); + if (ret) + return dev_err_probe(dev, ret, "HID parse failed\n"); + + aux1_field = hid_find_field(hdev, HID_FEATURE_REPORT, + HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_AUX1); + + brightness_field = hid_find_field(hdev, HID_FEATURE_REPORT, + HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_BRIGHTNESS); + + if (!aux1_field || !brightness_field) + return -ENODEV; + + if (aux1_field->report != brightness_field->report) + return dev_err_probe(dev, -ENODEV, "Encountered unexpected report structure\n"); + + bl = devm_kzalloc(dev, sizeof(*bl), GFP_KERNEL); + if (!bl) + return -ENOMEM; + + ret = hid_hw_start(hdev, HID_CONNECT_DRIVER); + if (ret) + return dev_err_probe(dev, ret, "HID hardware start failed\n"); + + ret = hid_hw_open(hdev); + if (ret) { + dev_err_probe(dev, ret, "HID hardware open failed\n"); + goto stop_hw; + } + + bl->aux1_field = aux1_field; + bl->brightness_field = brightness_field; + + if (appletb_bl_def_brightness == 0) + ret = appletb_bl_set_brightness(bl, APPLETB_BL_OFF); + else if (appletb_bl_def_brightness == 1) + ret = appletb_bl_set_brightness(bl, APPLETB_BL_DIM); + else + ret = appletb_bl_set_brightness(bl, APPLETB_BL_ON); + + if (ret) { + dev_err_probe(dev, ret, "Failed to set touch bar brightness to off\n"); + goto close_hw; + } + + bl_props.type = BACKLIGHT_RAW; + bl_props.max_brightness = ARRAY_SIZE(appletb_bl_brightness_map) - 1; + + bl->bdev = devm_backlight_device_register(dev, "appletb_backlight", dev, bl, + &appletb_bl_backlight_ops, &bl_props); + if (IS_ERR(bl->bdev)) { + ret = PTR_ERR(bl->bdev); + dev_err_probe(dev, ret, "Failed to register backlight device\n"); + goto close_hw; + } + + hid_set_drvdata(hdev, bl); + + return 0; + +close_hw: + hid_hw_close(hdev); +stop_hw: + hid_hw_stop(hdev); + + return ret; +} + +static void appletb_bl_remove(struct hid_device *hdev) +{ + struct appletb_bl *bl = hid_get_drvdata(hdev); + + appletb_bl_set_brightness(bl, APPLETB_BL_OFF); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +static const struct hid_device_id appletb_bl_hid_ids[] = { + /* MacBook Pro's 2018, 2019, with T2 chip: iBridge DFR Brightness */ + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, + { } +}; +MODULE_DEVICE_TABLE(hid, appletb_bl_hid_ids); + +static struct hid_driver appletb_bl_hid_driver = { + .name = "hid-appletb-bl", + .id_table = appletb_bl_hid_ids, + .probe = appletb_bl_probe, + .remove = appletb_bl_remove, +}; +module_hid_driver(appletb_bl_hid_driver); + +MODULE_AUTHOR("Ronald Tschalär"); +MODULE_AUTHOR("Kerem Karabay "); +MODULE_DESCRIPTION("MacBookPro Touch Bar Backlight Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index e0bbf0c63..818d41a35 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -328,7 +328,6 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021) }, - { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, #endif #if IS_ENABLED(CONFIG_HID_APPLEIR) @@ -338,6 +337,9 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) }, #endif +#if IS_ENABLED(CONFIG_HID_APPLETB_BL) + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, +#endif #if IS_ENABLED(CONFIG_HID_ASUS) { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) }, { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) }, From patchwork Thu Aug 8 12:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 817796 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2107.outbound.protection.outlook.com [40.92.102.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C99518C32B; Thu, 8 Aug 2024 12:08:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.107 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118900; cv=fail; b=PmMT6oTpmrvYZREAB/bJMeJ5surlEe6jcD3sk1cbnTbKp+y0EvsIgc3KMNV6ELqtGCY8INUVzBB1m5ay9apTCyNVSqnF6X0zxOhjAO3HMes+7I/y4Hf2EyPC/eBZiBEHCoagRHaNfnSNn5cvwaaMgMW6NwY8dJwQ1pAeF1EZI+o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118900; c=relaxed/simple; bh=Ga/M1/3AQHeq+4L170paz3HOKdDlLhcATXvdBhfkEks=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=OA/payRR6hmQZ8osn7feqcyJ6Fl3Hy/TKXe69Mdkcp0Uxo8YuYip9qaPUIG/ORsfvZgPRQVwbLcY/gcQa3+2Bz9z06C8LXJefFR+oSlbruFAGwU7u7VQme1YSPKzr4RnHwuknDT5azPNZXAPYlVQQGJJJqwm754SmUKI2cp4IsA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=u3FS+7M4; arc=fail smtp.client-ip=40.92.102.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="u3FS+7M4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pCTr5im2/kXCcXWvLu+Id8g8j0hgDm0VBaCuGJmml0YMiGZlGc1eLzEQadfoWUwESQMEYFUe+O2w7Dj0y7NDHaPURZ3AEZU90rMdqCOVL3q95Z8Ac1h9t+Yw0x8TjcE+pp7h1Z3B9/iwjK180y7zp6ezETk6EoxF4X9fK2R85YCQGMeFLfAo5XMRCzaPMnDfquOKwMo9YIsS33N91TneQRZw/UG8/I6xv0GNBzetqgTeTCAEgh95vigAH8RNKIfQEM59uXnfY5F9nrsLY+d5ZVLL1HjIyKzwjKQKHl+3+KOnvMZypfUZJjepzIYirdLMPyOaY8KAkHe++6PrTp+FDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ga/M1/3AQHeq+4L170paz3HOKdDlLhcATXvdBhfkEks=; b=NQQK9JjyUqQkWls1ZtNFLZNiDq4Zgtldy0fQnPD/pp5EDOWpHdSub1azdmmoS75WIR/K6dqPtDX5pkLcqaGzhWP1QxCEiaaH2xqy3RZiLDXfaLuq4XLR5IpE6B2EdFy+xdTAVbD8WpsrvMgv0ZfiSIKkac2ho3I2ZYMaihPXgqVzsmTSgd8Dsw+SEd8t2KQZuBu+X7Oju6YEnJXPxy+oKpjteqbC0L1sEpv1cx4epsdDEaxzj5RUr2Z2p1yDxynYF1HS1s9rTGIz8Q7JepH/6SjlbgCOSzTMpuVBmomQ+77WqnGJRG5/iVyxuO/fIKTtRs/l38d7kfdj/RxVVGCFwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ga/M1/3AQHeq+4L170paz3HOKdDlLhcATXvdBhfkEks=; b=u3FS+7M4HTFlPI+VTTJwIletmiBg6O2BC8HHTaNOatzx8XA3+WNx8mLqwtKtVJ8KYjTTcrXorF5OZoBzZ0ev1UF6XZfiBBK49/iZLCwkV9eZzKFMvAaDvOXCYReq0HSepbcYMrmYF+JD5wE3ZZRbUid8aa5dluK2UfeNbK2BNukzmE+PTYQ6JYyP3adk9Pc6g2L+Kfp06p9Wm1aCDwHmtshEgnNGd1QW6QeOOXj2JJujAofm9ozB4s3f+YiQjK0ft1oDy7ARi8yM0qz859NZdsj1HFCmff827PTG1kwLQTtZoEcyXCFZi0biLwQUOHbkoeQAlADZ+EinoE1/EcdxAQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB1715.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:18a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 12:08:11 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:08:11 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode of Apple Touch Bars Thread-Topic: [PATCH RESEND v2 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode of Apple Touch Bars Thread-Index: AQHa6YujF+uxoOhCKkG6z2qpy9Z2/w== Date: Thu, 8 Aug 2024 12:08:11 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [+4SJvMX/OKF0gfYC2N/Sy7og+IDQnSGnLkZHX/HVEsvLiX6WkDoAA3iXv/SS2F776fdbzjAKnBw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB1715:EE_ x-ms-office365-filtering-correlation-id: e6f9b903-385e-47ad-4357-08dcb7a2c617 x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: M7KOWfROYO2XpTCQfyHHvhly/+o7MrkeEOmktwJWcmDiSGy1NpXzMD+FrZHRWg/TWVhqgrWu9TmVO7houGlhCsv8L/DScsFrFiLz27NSTv4UIhAl6YQFQeFW6uvCAx2dRPhrBRvO1kOxjHFee2usqVs0PJrhxz2HCT+ug39s7ixE/5wmKcBaPMcf+5bcJSOUGycSu8fXSIp+RHe35RpDC3NUHouEhFhADC44Awr8567PCI2WpFqiqtYI8EpsSQKfc2TfOVMXr41tD4uCTqVNc4ac63qLe3YiZehSvErzuI7n6Kuf/4tW0GdmZz1s+mcqawgtZ0+Q87PjlPmKSh957wk2dLsdBEElSb9VIb2psigio+xREMq+ntfcZI0dU1NtxUR4ETnGCyWtaZDHKWNR739yNi41wS+p3PDmkg4u0haE63pp7iUaBKiaBkNkRfY6cc0i79qHUPjK522SxPULh5l92BK+8C/W5kK9sodWwux6pCqjpjMX1gx9dheyDgii3qQfxGIcihIBSr4jVRsBTMXhKKZ47kVM7M2Xd2mFzV6OkxZN5oEz0a3FWvvFdGOzq6vs75qLs7S8Zt3sfpBs638n17+Z6STNbylaPw1z2xGH3ytsdz6E2YQ4R49gzFHnsF0r5NTibHf3A6gwh5k8Rs4OIozN+/6vJNeavX+8GhK0WI0kzstMggfG+UYXUghU x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?2aMzrzN+d7tDLxZoTBaAbTxuqymm?= =?utf-8?q?9Laj3laP22eKd25Vj5B6DxguawDwtDDtB9Gj+HaxEMdusJw1iGXf6bcDNrWz3lAWe?= =?utf-8?q?MtQONWniMOu13BcZktANNxAlXjXk8u+cNVLnWmMoBZ99y+aC99isBT4nXgyZ8Vt7v?= =?utf-8?q?M4Q3SEyF7/dINkErMFZwh8LrJIN4z2yneXhEKjcV6uw/+0i0DRdee6JcqkO0bKQKD?= =?utf-8?q?/u9yFxx9pWN870TwlihxDyh9HpwHZs4irPB1Z7Ncwl3Uj5kY3mJrepwwFTwzVWk6p?= =?utf-8?q?kjkF8cdR2jE7UNVI8ohI3ljgbjesljvh0FBmSdzNIEs9Rl9upfPQCDocXM+h3JmiT?= =?utf-8?q?GysB25Qx8Fnr8y8B2unD8Xwjjxq6pSmrr8mr4ndGsvUNwJkf4yiVZsP/YK7UrgmNi?= =?utf-8?q?L7AwZ54oE3WdJiyXGOiId7TQVLiOFAMkWbWfN1Q5rKHGEENYuFAzfmoE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B@INDP287.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: e6f9b903-385e-47ad-4357-08dcb7a2c617 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:08:11.5643 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB1715 From: Kerem Karabay The Touch Bars found on x86 Macs support two USB configurations: one where the device presents itself as a HID keyboard and can display predefined sets of keys, and one where the operating system has full control over what is displayed. This commit adds a driver for the display functionality of the first configuration. Note that currently only T2 Macs are supported. This driver is based on previous work done by Ronald Tschalär . Signed-off-by: Kerem Karabay Co-developed-by: Aditya Garg Signed-off-by: Aditya Garg --- .../ABI/testing/sysfs-driver-hid-appletb-kbd | 13 + drivers/hid/Kconfig | 11 + drivers/hid/Makefile | 1 + drivers/hid/hid-appletb-kbd.c | 303 ++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 5 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-appletb-kbd create mode 100644 drivers/hid/hid-appletb-kbd.c diff --git a/Documentation/ABI/testing/sysfs-driver-hid-appletb-kbd b/Documentation/ABI/testing/sysfs-driver-hid-appletb-kbd new file mode 100644 index 000000000..2a19584d0 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-hid-appletb-kbd @@ -0,0 +1,13 @@ +What: /sys/bus/hid/drivers/hid-appletb-kbd//mode +Date: September, 2023 +KernelVersion: 6.5 +Contact: linux-input@vger.kernel.org +Description: + The set of keys displayed on the Touch Bar. + Valid values are: + == ================= + 0 Escape key only + 1 Function keys + 2 Media/brightness keys + 3 None + == ================= diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 4988c1fb2..72b665eda 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -158,6 +158,17 @@ config HID_APPLETB_BL To compile this driver as a module, choose M here: the module will be called hid-appletb-bl. +config HID_APPLETB_KBD + tristate "Apple Touch Bar Keyboard Mode" + depends on USB_HID + help + Say Y here if you want support for the keyboard mode (escape, + function, media and brightness keys) of Touch Bars on x86 MacBook + Pros. + + To compile this driver as a module, choose M here: the + module will be called hid-appletb-kbd. + config HID_ASUS tristate "Asus" depends on USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 1d825a474..d903c9a26 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o obj-$(CONFIG_HID_APPLETB_BL) += hid-appletb-bl.o +obj-$(CONFIG_HID_APPLETB_KBD) += hid-appletb-kbd.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o obj-$(CONFIG_HID_AUREAL) += hid-aureal.o diff --git a/drivers/hid/hid-appletb-kbd.c b/drivers/hid/hid-appletb-kbd.c new file mode 100644 index 000000000..0b6ac8c59 --- /dev/null +++ b/drivers/hid/hid-appletb-kbd.c @@ -0,0 +1,303 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Apple Touch Bar Keyboard Mode Driver + * + * Copyright (c) 2017-2018 Ronald Tschalär + * Copyright (c) 2022-2023 Kerem Karabay + * Copyright (c) 2024 Aditya Garg + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hid-ids.h" + +#define APPLETB_KBD_MODE_ESC 0 +#define APPLETB_KBD_MODE_FN 1 +#define APPLETB_KBD_MODE_SPCL 2 +#define APPLETB_KBD_MODE_OFF 3 +#define APPLETB_KBD_MODE_MAX APPLETB_KBD_MODE_OFF + +#define HID_USAGE_MODE 0x00ff0004 + +static int appletb_tb_def_mode = APPLETB_KBD_MODE_FN; +module_param_named(mode, appletb_tb_def_mode, int, 0444); +MODULE_PARM_DESC(mode, "Default touchbar mode:\n" + " 0 - escape key only\n" + " [1] - function-keys only\n" + " 2 - special keys only"); + +struct appletb_kbd { + struct hid_field *mode_field; + + u8 saved_mode; + u8 current_mode; +}; + +static const struct key_entry appletb_kbd_keymap_spcl[] = { + { KE_KEY, KEY_ESC, { KEY_ESC } }, + { KE_KEY, KEY_F1, { KEY_BRIGHTNESSDOWN } }, + { KE_KEY, KEY_F2, { KEY_BRIGHTNESSUP } }, + { KE_KEY, KEY_F3, { KEY_RESERVED } }, + { KE_KEY, KEY_F4, { KEY_RESERVED } }, + { KE_KEY, KEY_F5, { KEY_KBDILLUMDOWN } }, + { KE_KEY, KEY_F6, { KEY_KBDILLUMUP } }, + { KE_KEY, KEY_F7, { KEY_PREVIOUSSONG } }, + { KE_KEY, KEY_F8, { KEY_PLAYPAUSE } }, + { KE_KEY, KEY_F9, { KEY_NEXTSONG } }, + { KE_KEY, KEY_F10, { KEY_MUTE } }, + { KE_KEY, KEY_F11, { KEY_VOLUMEDOWN } }, + { KE_KEY, KEY_F12, { KEY_VOLUMEUP } }, + { KE_END, 0 } +}; + +static int appletb_kbd_set_mode(struct appletb_kbd *kbd, u8 mode) +{ + struct hid_report *report = kbd->mode_field->report; + struct hid_device *hdev = report->device; + int ret; + + ret = hid_hw_power(hdev, PM_HINT_FULLON); + if (ret) { + hid_err(hdev, "Device didn't resume (%pe)\n", ERR_PTR(ret)); + return ret; + } + + ret = hid_set_field(kbd->mode_field, 0, mode); + if (ret) { + hid_err(hdev, "Failed to set mode field to %u (%pe)\n", mode, ERR_PTR(ret)); + goto power_normal; + } + + hid_hw_request(hdev, report, HID_REQ_SET_REPORT); + + kbd->current_mode = mode; + +power_normal: + hid_hw_power(hdev, PM_HINT_NORMAL); + + return ret; +} + +static ssize_t mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct appletb_kbd *kbd = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", kbd->current_mode); +} + +static ssize_t mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct appletb_kbd *kbd = dev_get_drvdata(dev); + u8 mode; + int ret; + + ret = kstrtou8(buf, 0, &mode); + if (ret) + return ret; + + if (mode > APPLETB_KBD_MODE_MAX) + return -EINVAL; + + ret = appletb_kbd_set_mode(kbd, mode); + + return ret < 0 ? ret : size; +} +static DEVICE_ATTR_RW(mode); + +struct attribute *appletb_kbd_attrs[] = { + &dev_attr_mode.attr, + NULL +}; +ATTRIBUTE_GROUPS(appletb_kbd); + +static int appletb_tb_key_to_slot(unsigned int code) +{ + switch (code) { + case KEY_ESC: + return 0; + case KEY_F1 ... KEY_F10: + return code - KEY_F1 + 1; + case KEY_F11 ... KEY_F12: + return code - KEY_F11 + 11; + + default: + return -EINVAL; + } +} + +static int appletb_kbd_hid_event(struct hid_device *hdev, struct hid_field *field, + struct hid_usage *usage, __s32 value) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + struct key_entry *translation; + struct input_dev *input; + int slot; + + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_KEYBOARD || usage->type != EV_KEY) + return 0; + + input = field->hidinput->input; + + /* + * Skip non-touch-bar keys. + * + * Either the touch bar itself or usbhid generate a slew of key-down + * events for all the meta keys. None of which we're at all interested + * in. + */ + slot = appletb_tb_key_to_slot(usage->code); + if (slot < 0) + return 0; + + translation = sparse_keymap_entry_from_scancode(input, usage->code); + + if (translation && kbd->current_mode == APPLETB_KBD_MODE_SPCL) { + input_event(input, usage->type, translation->keycode, value); + + return 1; + } + + return kbd->current_mode == APPLETB_KBD_MODE_OFF; +} + +static int appletb_kbd_input_configured(struct hid_device *hdev, struct hid_input *hidinput) +{ + struct input_dev *input = hidinput->input; + + /* + * Clear various input capabilities that are blindly set by the hid + * driver (usbkbd.c) + */ + memset(input->evbit, 0, sizeof(input->evbit)); + memset(input->keybit, 0, sizeof(input->keybit)); + memset(input->ledbit, 0, sizeof(input->ledbit)); + + __set_bit(EV_REP, input->evbit); + + sparse_keymap_setup(input, appletb_kbd_keymap_spcl, NULL); + + for (int i = KEY_F1; i <= KEY_F12; i++) { + input_set_capability(input, EV_KEY, i); + } + + return 0; +} + +static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + struct appletb_kbd *kbd; + struct device *dev = &hdev->dev; + struct hid_field *mode_field; + int ret; + + ret = hid_parse(hdev); + if (ret) + return dev_err_probe(dev, ret, "HID parse failed\n"); + + mode_field = hid_find_field(hdev, HID_OUTPUT_REPORT, + HID_GD_KEYBOARD, HID_USAGE_MODE); + if (!mode_field) + return -ENODEV; + + kbd = devm_kzalloc(dev, sizeof(*kbd), GFP_KERNEL); + if (!kbd) + return -ENOMEM; + + kbd->mode_field = mode_field; + + ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT); + if (ret) + return dev_err_probe(dev, ret, "HID hw start failed\n"); + + ret = hid_hw_open(hdev); + if (ret) { + dev_err_probe(dev, ret, "HID hw open failed\n"); + goto stop_hw; + } + + ret = appletb_kbd_set_mode(kbd, appletb_tb_def_mode); + if (ret) { + dev_err_probe(dev, ret, "Failed to set touchbar mode\n"); + goto close_hw; + } + + hid_set_drvdata(hdev, kbd); + + return 0; + +close_hw: + hid_hw_close(hdev); +stop_hw: + hid_hw_stop(hdev); + return ret; +} + +static void appletb_kbd_remove(struct hid_device *hdev) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_OFF); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +#ifdef CONFIG_PM +static int appletb_kbd_suspend(struct hid_device *hdev, pm_message_t msg) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + kbd->saved_mode = kbd->current_mode; + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_OFF); + + return 0; +} + +static int appletb_kbd_reset_resume(struct hid_device *hdev) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + appletb_kbd_set_mode(kbd, kbd->saved_mode); + + return 0; +} +#endif + +static const struct hid_device_id appletb_kbd_hid_ids[] = { + /* MacBook Pro's 2018, 2019, with T2 chip: iBridge Display */ + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, + { } +}; +MODULE_DEVICE_TABLE(hid, appletb_kbd_hid_ids); + +static struct hid_driver appletb_kbd_hid_driver = { + .name = "hid-appletb-kbd", + .id_table = appletb_kbd_hid_ids, + .probe = appletb_kbd_probe, + .remove = appletb_kbd_remove, + .event = appletb_kbd_hid_event, + .input_configured = appletb_kbd_input_configured, +#ifdef CONFIG_PM + .suspend = appletb_kbd_suspend, + .reset_resume = appletb_kbd_reset_resume, +#endif + .driver.dev_groups = appletb_kbd_groups, +}; +module_hid_driver(appletb_kbd_hid_driver); + +MODULE_AUTHOR("Ronald Tschalär"); +MODULE_AUTHOR("Kerem Karabay "); +MODULE_DESCRIPTION("MacBookPro Touch Bar Keyboard Mode Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index 818d41a35..7c576d654 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -328,7 +328,6 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021) }, - { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, #endif #if IS_ENABLED(CONFIG_HID_APPLEIR) { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, @@ -340,6 +339,9 @@ static const struct hid_device_id hid_have_special_driver[] = { #if IS_ENABLED(CONFIG_HID_APPLETB_BL) { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, #endif +#if IS_ENABLED(CONFIG_HID_APPLETB_KBD) + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, +#endif #if IS_ENABLED(CONFIG_HID_ASUS) { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) }, { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) }, From patchwork Thu Aug 8 12:09:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 818333 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2099.outbound.protection.outlook.com [40.92.103.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA259126F1E; Thu, 8 Aug 2024 12:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.99 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118961; cv=fail; b=uF+YwlxxPDTqgvkRQh2kYWQdxxdFH2K45dLCDcqYGIPlDUhMqrwrEbVlWpymNNf9K4PTDcmXzSosAK08PaVlw3YAXmXzDlMwP8ThbZC2Hge04jAREqdI/CdjGkOxkWtHkdR5rRa193WMc6HY1NlI7HqDqRtH+zUkwsX53QlNgDs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118961; c=relaxed/simple; bh=JSkjijAYgzH7WQ3jUUHmHMdD6vO8+MXa8Wh7CpofDLY=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=BCpL6/rBs1mIFe4pn2T+5GRr0umJkzTdnIukOmx2V5DgJhWb/1hVtZG6WlkOBIjpdr2DlKwXDOlve6jsKDliGdyOnCfqpVNF7qmC10WJHwMeM8PFC5Rzw0HvPhBPlf2bzWRM0HG3R3jGD61yiuQr46zbwiNpYnn7Dbl/Jop5OkA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=kcCFuYxU; arc=fail smtp.client-ip=40.92.103.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="kcCFuYxU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=o7P51e6IbkkFMY8DREFPN5VEu/2zWN/QNK3BHwQ9qfgGmqpqMWPW9L0dsIHJJSOF5d4NHVYbDgF2+RhgHB2batl+CIZSzAqsLXoTeP3OX/t9d47utUHFaAF21lqKpbA9rgU7nYDEK2gYBsSVl4PBfIdwPyFejk/397DJh5R+zOKi1uNzZ6jtEQ8XjpXxW/EU+NxzYel+kD10nRovZsRpyCbnv6jKow8S/XXoyf/dX+UN1/dEmOV3P1kBBz3L+/b4FRfP9FO8qpMGwXzCQ/WEDkbmz11agNoZ8xQJ91Q8VNioYDlMf4eJANhagi/xvc6jaawpMHu7e2TTlT5e4RMQjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p4PHen4032PcthKi8HoFeGPNif8f7CRd94d/mUAn2RY=; b=I5N9+OOzPd6cQ2Na46LKt2f5IwteyZxoswNlQgpCxtTzXuIbMkJMfGXAK+TIqgaZfIq88g4jlkRBudaV2xoqlVUZJrS1Q2Ej0Lkp8ndyz9HNtz+J4dMRNTO/fSfX8giFy2LpO3eyOFgbJT2LckBnUGmVpID8lRcgTsKomCnoaAWEDG72kMxVJE4O/+aMQN1ycph30zMQ9lkfPGmS6eccB+AZJrNNf4aHzDPJaFle0m6/pQAx5TooMJDvXGj3o6wda+xrQojJw5DZ69qdG8QPH7xhWoLcFqspgPn5KwCEONzP9mdfZUZacTuhAljK5xtBvd7CziImJpnWnHTVevP7HQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p4PHen4032PcthKi8HoFeGPNif8f7CRd94d/mUAn2RY=; b=kcCFuYxUIzitqB7F/oT9D/53h2ZP+qvwoA/g0OY2reH6xHbeAnriO6MFxHvE+G8tZlrasC7VwMqs2MithnZd2eyFTGLJAQjk8skHLoR3JlU7ET+ScqN3vzxkNeeQcTBaT6Lr+GBGjuSSf65Xr6T2Wsit+HXFjavwyF08fjeH806kSzof3jVKuQpTV9Lhd5CnbzSEQR2i0v2g+UF8n5e77bTqsHkIObroSky9cgA90MeAGNL4I5g+PwnLPxmPw9umLigpIwHNdFDw40xroGB2aK10BEVvqxZmjCvrBYqjRIdDzVj/tjwARiJDQAKyGkdmWusdASsNl7SSYE1NtRsV2w== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2144.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:09:10 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:09:09 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Topic: [PATCH RESEND v2 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Index: AQHa6YvGyLS82XPhJESTQJ7WrLbR/w== Date: Thu, 8 Aug 2024 12:09:09 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [/oYVw1fWkOjP0WAYdqps6qtWWrJlP07nxycMT/lSsd/QTUU3Dl7F1pdshWxUJf0K4oJtcJC7l7I=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2144:EE_ x-ms-office365-filtering-correlation-id: 0deab4ed-79f1-4080-b325-08dcb7a2e8a4 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|19110799003|8060799006|102099032|3412199025|440099028; x-microsoft-antispam-message-info: mlBy5ckzbJF/XwMwm+Hm9y0FL03AG4EGcQ39vypmvC0l51QnHvsP3TgV0UMMrKTJs9dh/y9kAx6r+DVpnzj6GGqmIZ5VZdSV0FF0d0Pwu28pXTzJ9Dbi3+SLo8TcNO6HUwkJV5xaxrdIxY/6igQcJnqdsJF9XGrrdpG5+wIzT5NMKK8sie9bIMg50advlsFqaKQRqMvEzOA/XUC43GD6idnS/iZPKGBTslqHxEDmnbyKFtcYIkVqg1GVpCdvCxtFbOS6WkxV4X1g50fE+u3d0bDIkyDAdvCRgsqQHPUJGGjw14FOFUZLZJDqehu7IxEOHO7qjJeJdEeKfxEiwJe62j/AW8ogINfoqmHE9BhlevE4Q/uhNdV6PeCSj9gs1602fIMPGgQGgwpR9wH3kd/bgbU4U4s6jLV0sWWHOY51QI/8IwPZTvCT5otHNMOW/Z5qGONjwUFIjlAHT/1BgwirBMNJTwct+2d0MeSwFAL8Xiry7MMWMgSw1OQdoQoZh8wTVbfX+Ml30CIkSzUp5TdZTbIsrtrz2iC/w/6skX3mgFVtvcjoCok7y+iAgctUNx1ah6vZKyhxtloD+HbYHLrxwWin8p5/XPc0nJ7oIz9hcw99ij9mrtqOtDwfqWJgng3w+iFKGAZb/n0vueAwyIU09XcWGO76FnqfnPX0iiyH6pbsZeX9H89LgrPGYbR+rhTr x-ms-exchange-antispam-messagedata-chunkcount: 1 x-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5O5g81sq3gflqYuJS8ph/7Hwn3Vpa+oJjrLwrkhG6KEsVI9SLf4BUN5+Bz3o95Ec+yuh/5AsDxACHhG4xfu/GvfW1F4X/KnZsM2Z6AH3nqTgwTjWKwWO1bD4h99busHjMzBjrn3d94kwCMK0u1VffFaIayDGr2yp2EsBgvsrtTF7mepO5yWQLJ9wdowphNk9E8A7J1CtWCTv94yrvi4IJcR254XeJAQoPE08A5FKZ7N0Qc84FDvO93qavcwFE1M0C67XBZtKHfgA7jRRKNkuB Content-ID: Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0deab4ed-79f1-4080-b325-08dcb7a2e8a4 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:09:09.5165 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2144 From: Kerem Karabay This is needed to support Apple Touch Bars, where the contact ID is contained in fields with the HID_DG_TRANSDUCER_INDEX usage. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 56fc78841..3e92789ed 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -635,7 +635,9 @@ static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, if (field->logical == HID_DG_FINGER || td->hdev->group != HID_GROUP_MULTITOUCH_WIN_8) { for (n = 0; n < field->report_count; n++) { - if (field->usage[n].hid == HID_DG_CONTACTID) { + unsigned int hid = field->usage[n].hid; + + if (hid == HID_DG_CONTACTID || hid == HID_DG_TRANSDUCER_INDEX) { rdata->is_mt_collection = true; break; } @@ -814,6 +816,7 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, MT_STORE_FIELD(tip_state); return 1; case HID_DG_CONTACTID: + case HID_DG_TRANSDUCER_INDEX: MT_STORE_FIELD(contactid); app->touches_by_report++; return 1; From patchwork Thu Aug 8 12:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 817795 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2064.outbound.protection.outlook.com [40.92.103.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D563E18C32C; Thu, 8 Aug 2024 12:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118990; cv=fail; b=YkrnA0RM5wIerrB1M7PNtktk/f2uyRcFfLCEmuIviMikKtiKan8L3KXNRT/3HVGucfjdQDMhvAng7Dorgo0yb2A64O0ESQVAIN9Xpfqwn2BoErXHRMKnj3QJt9s0E4TxXFhFx9YOfh5gznlZ27IMpiAzyRjNBReOTuYysHEcOTY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723118990; c=relaxed/simple; bh=q2zbI6iA4WSAgEi8Mnhut1ZJDb4ZdB1DAdsFrr6ISB8=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=EOhqE+YSJs+atvuVNLvJ6h0IK77rVIN3d9s6uEo/lJuVYWqW96GMbdhEo8BVxFquxIJMx2wNjCp3HcYrpSX1RuqU5B5pEiog8I/bG3zGHwOks6fTlkPeqNPNYK2zM3PKKqX1BGxFvTAFcjADx8eIRkK5qvq3EcfEtP0gnm+kENI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=josGdWAy; arc=fail smtp.client-ip=40.92.103.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="josGdWAy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LK1Ee+mWv2GxyaB6mwFQU54L/Gv88ZP1I0Cc+fwWoxsRdQ57/yKSVXBhRWnu1Dlt2iawWnXc9vUs+TFO+uLNj5fjOQ7c561W2T3zKieBSQipbfUD3hIfDdUb78zgcyJDHzcqh2DtM5A+Qm33iSTPfjrJCsr0nJOjzpRUwXYVVarVaAzGN8ETl9xBnyIYGjtWDKqSEDFIedqc10Eo8kawG+7YMQK/65wH6Ys+XybEPIvaj7HfRjoluMRCHpG9fnjHgA17J+/1AGKIHkuIKMlAn8888usyK6juC1qThvdEvoRwBQ1z3l9zJ+kwIYqlZ/Jf9K5UeS5/nJwdtnqwpVMNXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XbtXp3cnpQpbYNXYGShy2lxXGof4j5KkulzUYghWbSI=; b=dAuNqWXFVl7EPcdWYiFBIR1fDwa8dbil8aw7IKtC3TTcxFOUVlKDthLyo0eq3C4VjIXw22p1rDT15AzUIKHSfqade1cF7Pse5EIK8CO1wkWT+/8sBqxruXBjAt+g2RK5IskfDeVVDA0ICbKsSPjEvt+npY85v9WMNNrL7JaDX5+jtVZ2FQJWWZiiooLx0V9cTj2eaZ/6lUGhUFxcf5+whk9PYTpVb/dJF1pP6zQ8GzF1JmhPdJA2fyrnduOCzgTCRNDyeyAn/ZhAo12j/1IGUQroSFTPWTyFA/5BSnQ6LBSLIA41xBIX/7GLJRtnAKrsw4TMQ9CZVk9XTEZxcPl/Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XbtXp3cnpQpbYNXYGShy2lxXGof4j5KkulzUYghWbSI=; b=josGdWAy9ICYh7zH8d6RhQbRrzn4wY17xC9apMT+njbVEnReqDlF3n4/qAHubEIi3taBZmC/a1KFI+b8fPX1XY6HNWDxlb2Uc5kEBaR2JcNRxyDik37ZnHv4NpXbg+jqI1VvdUyGC0clsGtPWy6+tKxPILm3ezhiUZdT/cv/B6qeFZ+bOG19gZy9mnGyUbkryo5RNyqIfQU34xdZv6CD9y2Yc+mHw3of/mmb2A+ZTkWV1HrGHIN62ewWNj5EFNkOjSArDS5HlNGzQJzgJV0IijqhXrksXI/HsM1puI8Rk8YoFol/vmbFlU+Z39UvW2c/o6Xj8T2DjfsZnydtlxip/w== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB0723.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:fe::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:09:42 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:09:42 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Topic: [PATCH RESEND v2 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Index: AQHa6YvZBfM0fkvEq0WSGasDv2LTRQ== Date: Thu, 8 Aug 2024 12:09:42 +0000 Message-ID: <8495C8A9-5B99-45A8-95CB-623682BF8982@live.com> References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [PrMlMro3hKQmDV4s6o8FXUQDPyBCKyPtFZ1HHhXgtv1hZ5zHdroVD2s07llcxw4t] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB0723:EE_ x-ms-office365-filtering-correlation-id: 505764c8-5f3e-443f-f2cb-08dcb7a2fc67 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: noS7ZKZ/xI+7pPG/RL+UUgygnnrmF+odQqq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input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 505764c8-5f3e-443f-f2cb-08dcb7a2fc67 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:09:42.7005 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB0723 From: Kerem Karabay This is necessary on Apple Touch Bars, where the tip state is contained in fields with the HID_DG_TOUCH usage. This feature is gated by a quirk in order to prevent breaking other devices, see commit c2ef8f21ea8f ("HID: multitouch: add support for trackpads"). Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3e92789ed..571435da5 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -72,6 +72,7 @@ MODULE_LICENSE("GPL"); #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) #define MT_QUIRK_DISABLE_WAKEUP BIT(21) #define MT_QUIRK_ORIENTATION_INVERT BIT(22) +#define MT_QUIRK_TOUCH_IS_TIPSTATE BIT(23) #define MT_INPUTMODE_TOUCHSCREEN 0x02 #define MT_INPUTMODE_TOUCHPAD 0x03 @@ -809,6 +810,15 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, MT_STORE_FIELD(confidence_state); return 1; + case HID_DG_TOUCH: + /* + * Legacy devices use TIPSWITCH and not TOUCH. + * Let's just ignore this field unless the quirk is set. + */ + if (!(cls->quirks & MT_QUIRK_TOUCH_IS_TIPSTATE)) + return -1; + + fallthrough; case HID_DG_TIPSWITCH: if (field->application != HID_GD_SYSTEM_MULTIAXIS) input_set_capability(hi->input, @@ -872,10 +882,6 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_DG_CONTACTMAX: /* contact max are global to the report */ return -1; - case HID_DG_TOUCH: - /* Legacy devices use TIPSWITCH and not TOUCH. - * Let's just ignore this field. */ - return -1; } /* let hid-input decide for the others */ return 0; From patchwork Thu Aug 8 12:10:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 818332 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2100.outbound.protection.outlook.com [40.92.102.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CE7418C906; Thu, 8 Aug 2024 12:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.100 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119051; cv=fail; b=AAKyniL+zgOmT/diFJOC1XDo30mM2pZ6Xn0muyOU9nGu0BJ9cnlturgKxLeJrvY2TOT9w5JX/LFl+0a5NMA1joyWkDnXuYhiyZ8OMtNK2KnLVl14kCObWzyn7Lqz7+dlQZPmTGqIE5R2ExFTwiTRdw76kClQyImRzm6qr/0VEMk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119051; c=relaxed/simple; bh=vRQ56ui35j7gSUDh6/aC8rAWi07FjxWDnMNCtBkWUOY=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=peFbZ3GZ+z+Iztizgg194y3DUz6mQK17AoD2+A4cGqyZYNloHPSB1S5cfNdduZkf+CxvpBsRYfSGT1YAfT8HR9rvphShadYBADK5L4wNMn/hsLN8S2wyLLr53KPwiHQ7Ylo0rkyT24MWTogBjU7bedV6Wjv5IjI0KQxj2gcjmOw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=Sj8DVxCW; arc=fail smtp.client-ip=40.92.102.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="Sj8DVxCW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VJcyVsSkETCZpjSABTM4gaTL+vOlmJLQgrOkl3aWo36IKIOKQLczCybYDgoy6BWMQUp0Kg1u6AcKyAC2OZHTiUnt7JtcXFFcteBUCVdyb6j+6b5fbAvuC5PEzjBN/k41mshqiGRXh1EWBdEtqYlNTtGrIGviur/lpEVny7EC468SQ7rUzTuglSqhg+iVHhKKm+XFOfqblCN7LTNo2MUH9ZdDgb2OVraAIODZtzLpxKWB48Ss2GZ4bzcqKHJ7IAxuLs3kOXvXYfKVqQDjgrCokDR38gJS8RqdqfOepR4oG4B4QM+D14I3Aw3mxrg0YZcUj5vDYkqVC4FFdd03KzqhtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cIBzWghiSd/94g2S+ca6KQlE54fye1PXtvDLmTaqqw4=; b=I7UXlyIhNcvLQouULG4h10m2bxg5yTVBuR1KqgxR8ryFiUxDxrp4wz2eiftY6WgDO4XChUcMvk4OBP1c54+EYPPSY5VDJ4zpjh7TAcpIlY7hwNwe79lE1qKgPJ/pn7/ukG/nhIHJ7/SwJDUub2hl4JcWJujZdmUO6zv5mVcLNdhSCkw0zZt25q2Se3uLzlUhxXSLx+my3XaQV1DuAeKfEC0x1YId7EGXGXCoqv58dcoe1g1DxVVrGCj2UpLND0qDkfgKqVaBXg5pRdA+D2GD+3A5nAQQjK0b/NHbft2C9Kd1lbPmpjMR/yu3vMEsCgAAyqqVmaraLfLa7GDJbowMRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cIBzWghiSd/94g2S+ca6KQlE54fye1PXtvDLmTaqqw4=; b=Sj8DVxCWIFsecmhmnClZQ5u0d/Viqk0DDAqYtTUZYC0/YR8xgSPLCjEaqkvFttdgAFoPw+veCoD7nFypAmHQxl7TuE7KBY6gf0sKs8Rqyy/z9hE3snu8w2/bZCyR7DvKpTX79YMRSYllLWZnjdjmPerTfcmsQRdbe5xczMuCTUKQvA+XoAp5CDe6rwj1NvgM7uXwnDggPEolHUIC47LWA8mx8mZfyblYwPZ4Auwue4fN9u63BtYN7RMtG8I1h+6Fy9o0AM7GQNEaLahhwkSW7BFvNwKvKIOpLtiixm9f1bWemp1sO5TRDx8BaJfUCJmHNGY5oSkWJCCp9A3UaEeRMw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB0723.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:fe::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:10:43 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:10:43 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Topic: [PATCH RESEND v2 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Index: AQHa6Yv+ROpT31L5LkWmC+xCy7IhrQ== Date: Thu, 8 Aug 2024 12:10:43 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> <8495C8A9-5B99-45A8-95CB-623682BF8982@live.com> In-Reply-To: <8495C8A9-5B99-45A8-95CB-623682BF8982@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [rytfL9Ga7Q13BNyB3Du2F8eb7Iw+TOVRhwqKo7jll6LvyPNAzeFweUyof7YPOyB/V2x+JANQpGg=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB0723:EE_ x-ms-office365-filtering-correlation-id: 2fa9b8de-1c87-421e-3603-08dcb7a320a0 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: YPG4ktB9iyCQebyo7cm9xBfbom19s4nZWgGDosAqzHNOOVGZhPo/FNdIu2gGoYXsulX0pqsa8WuHfrf4z7cdfOIRc7CtBKf7OjYiMnXrCfFsu6yH2Ww3rCvJ5yGHB0hnLRogXEXXMB8hO67j6MVw/3JC+aGPOQjIfcSzW3zy+hX4XqOj/u1HqkOGxQKAfXdr7CxMBF5rFoJh62gPyoDZI+vucL04bAwg/JOnwVBhQ/hdYthyJrVmGRo77l3tJioD4j6wkrv+Oh+Z2KFJogiFv4dmlqdEVbCx+Yb001dd22lUSgO+qag0PpwqHqJcxb87XAAryY73LijjG/PgGlIaoaEDgdU0BHB7m7i/4zeAZBh1bDkwAftbTQYgwEzAV9pw1x4XgF0cKqCluj9+zq/G9bSaJ7DxmhJfdpzQPoIVyoeYAbqV0xJXFZMJoZEEZ828agH4dLXsW6Q91Ri0t+38v5/KFARr15ByPpaegoPxSX3WnipzB7HiOHC6Y9O2m9Cra2B+WrHtez2lnXC31utEdowOBzyyO7sYhDOW1JenKaRqtMJB6uD385mnYJeFQzdGeimqWQaPxW3gyj1af3hjJ4XVH+pLpNo0uJSKVdSG3oN3VUzHCWLdpd37yS3kUtD9Hv2Qd5snfv61dFi46qVYw8YJFZjjvBjuVVLonGQ0xJhBFDvhZlhvCBFc9al+OnVD x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: WwNcCVRJJ29rtgloTWZch/jylDdU5sI6M0DqjbaCO4IRrdmytC19bL/74UbHPBvfiH4SgEq05OD1OkzYkmKEc477NDhPNMFDmAGE2BLS706imXWklxcKmkc1a1fWvfn3ImG/BZYcFvnVN3DdGiDYm94TI9ywk+H4K0/uLg129/dEAxBJJ8kxXBrW9vS851Y3IMuelpMprLAengDnCykkq2GwpJh72HFPh39QIgOqlt8bbM5imBl8Zt76/g39VLx1qf6VFcEgRqZEYJ9A2b8rQb1O/WXLOQMyYKkoELc0C2QMRR5Aon6jsKGvit5JUpnZhDBTrZSiSJLym0lnHPfGjMCE+Afllmu3Z+BMxrXgnRD2tvlZh0xHqvBQWYCdpFHdAB41BSt2MNArCVb7FmjZjyFxbFI0cvzHxllRQ+Kly0Ri/SBMOqDLKiELgHckS1+k2LJcJacLAE13Bf/3yCOgmnptgXTOzzBwxm0Qu4g//LhIiyuAeYN4wohZ6xRbaUXs3n58xH4hCbBCMnzvlN7VWREEKHnhQG2+x/uEagtr7U0r8aT1M05kea03DxXX9CqjmFvuvPyK17pFIWg89evSvdOBCl0kNXGJobFtoa+CKCdvh+zKEbRszU3ErvMqFZCUkv6Gju5D/k039pikTrivyRLNPmOxQ5i4ftHKs9QcTrRcogdKlZNHbdcalcXpQ4wCtTrqPPBUHLhCs84YK8fliZdcPwFs1Jo4jgBKsMg260GPJPdrZfOUIgyXXzpWVEAOUV8NpEIeXj8tYd9va+L9c3cTuIlUjQiEZIeohF3vUKhOeCgGUDQwNiTa2jlKwultsk88FB8BAwkq6iSo5S+Bs/XDXT2HDjFCuY8JwUL4QcLvZ41zpV4MX+5+4eE23j3Gwe7AY87p6vwVtx29DadIaoP0sfP5yTRX6tiQqr1/bpwBtY0lyyZGfXR9I4Vp0coAAhPR7aKmSOWJO0B7nLMqK9V9vQs4s/FWx2euz3L2srkRN1ZLiQZp/H8U3SqngsLsy/759RAofnoQpaU9GTAfzI/6gfo9ijXxIT6BR1pXfy8EdgwgZqoPblNgb6yXv7NFzSz8ri7jvwAJzYJ/BAMJgfZPRqXb7+gSYh7asD4+jVsjxaEUoXpk8SrLivI2n3L3gFf/BpTXC04KL+MwFt3b+rk5B8vbM6HY4EKI18lDx1of38cjTBKDD4yGzI/wceEwyFlL+Ddpkh+xGA1VLOy68xeE8k4OZfuXF0x+mKKMO/hkTxwO7e/iffQzucoOuB5L1vK3xIzzTCLPJZ8r17xADxNBsd7oJmo/BS2fPPctTr/qjiiynLjfAetav50ZH+yz Content-ID: Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 2fa9b8de-1c87-421e-3603-08dcb7a320a0 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:10:43.4187 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB0723 From: Kerem Karabay This is needed for Apple Touch Bars, where no HID_DG_CONTACTMAX field is present and the maximum contact count is greater than the default. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 571435da5..60b675cd1 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -490,9 +490,6 @@ static void mt_feature_mapping(struct hid_device *hdev, if (!td->maxcontacts && field->logical_maximum <= MT_MAX_MAXCONTACT) td->maxcontacts = field->logical_maximum; - if (td->mtclass.maxcontacts) - /* check if the maxcontacts is given by the class */ - td->maxcontacts = td->mtclass.maxcontacts; break; case HID_DG_BUTTONTYPE: @@ -1309,6 +1306,10 @@ static int mt_touch_input_configured(struct hid_device *hdev, struct input_dev *input = hi->input; int ret; + /* check if the maxcontacts is given by the class */ + if (cls->maxcontacts) + td->maxcontacts = cls->maxcontacts; + if (!td->maxcontacts) td->maxcontacts = MT_DEFAULT_MAXCONTACT; From patchwork Thu Aug 8 12:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 817794 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2104.outbound.protection.outlook.com [40.92.103.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 788EB18A956; Thu, 8 Aug 2024 12:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.104 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119109; cv=fail; b=BJPYgMNVDVbSWX31eNc0CxhOLJHoeG3KjNc/DtOLVCUkk+Y1fId9Im+aTpi3Xfu8gGf2XPvZdD+CG1v6herZ2fZbAV6R9YPenAvoSJLuZAf//gp8J1FKFc9aUTOcVPYzzWni/0VqVaEV3xgQY3bdaFYs9EiyFj356wX2l9PR/ZY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119109; c=relaxed/simple; bh=CG+RvCJbU5YuQi5CqKwWSCmUDgAhpUXoQBcqo8GokC4=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=k+x4ATyJUYtVDhuvZB2pNLLnTSllHITrJiu8k9LGSSrHhqVyTK+S+2xmVkyvfjOV6fQzb8Ktf12em3EhPwowEgRGWIoZ7YIiSUvRvDL0ApzIxZUCxLAv2qLi28ohjIDcVLrrr+0f0Gfb5xcT7qsQW1WT1eeIyqXNhFP+ePCIJNw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=UQvV6TfI; arc=fail smtp.client-ip=40.92.103.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="UQvV6TfI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Pc0zRDuy0jkOHT5+dfJ6FsApGnvup/p6WVhoEtzueUPRk1WLDBmpf83XmuslLTDXMIDRIUSeHO84mrjKy8h37+bmovm/TjU5uJBgNhNmKj93enYRTWq+TWZyRm8edaRTxOHaktGHjHDOfJR6WT+1rCQXPVQvb5ul66ppvOdKyDvuRzun6u8ZUuovudTl7W3YOh4GNHjMEXquXJCjpNJD3+ssrBcekSZrPBxQ0Yk3PsTFuhqLlUq+y6E3wSyvCK3Sy8ldhRPPIVyFs4j5sIRWY572UkAcYLzxGUAexmJNxN7dm1lXMcPRAaCTXt6HFlJnWhe4M30uyYHEbYxJMAHnpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oXj5HFioyjIOLcAdy/oXSpQUwhLoR7Iglk2c3NpVYu8=; b=lW20K36umvydOG3eRNZVbPUpTmjhxuVMJe0IqLS077SlZtJ1Ff9zsTX2xi/UDTAXLMAYaigYTYRw5RyFjmxivIckLVJjYq/DJTTBiinXGkY03oYalt/9+LWmWov24wMeX9moTRjO6hDwJ5/DH8RexPDwyo3Y2fReh1NjtVxoDJOGb/8HNTB9+7ACX+3R7bcvUz2nBuAId3zQpg8bLUep96x6X8JP3wFlTOci3o0wOK2Wvjc9BeLh34+HqbEHkDfIBnJVp56ZBahma1YPTVIJJ4f+017QeW7eOIg+5e2YlBHyAisV9+hiaeXHQFCRmfvVhGNCOomM3IscWCCA9BltaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oXj5HFioyjIOLcAdy/oXSpQUwhLoR7Iglk2c3NpVYu8=; b=UQvV6TfI3tTC4Gc6OW7a3RzR8twOikLnCPlM15axNT4xP9elECOiarK1GQd9JVP9CmD1xp/A6QVZbU8uRUMMltoo5qoUDa7o6MhAZGFabjThiyyDCO9g8edefl3JPE/J+Be0xioPqnM8uAmBk5sGmBCK9YGvlgw2IaOe3mT3Ws0ViZFd8lunJoppGqLV48436ciPb9C6HNlLVCPPqXFbLrP6s1RMXbx5VN0H8uYuISDfDSUH7gXX0sIWVigSGd3NdcdPoY8yWpZ1jVQf9BEEY6LNVD/gEWeowyjylGRcBYKbAl073He2KU1wyrJSw9ifh/SvFGf881Ai1E8aMaa0wg== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB0723.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:fe::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:11:41 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:11:41 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Topic: [PATCH RESEND v2 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Index: AQHa6YwgQh8KY2FzhEu4GvVwCf7kzQ== Date: Thu, 8 Aug 2024 12:11:40 +0000 Message-ID: <69728A02-3A4B-430B-9DAA-CCD6EAE82F45@live.com> References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Vt8IURprjHQ1NpaHMEtMQlccoR6TICAPrFFQv3MyQtGJ4rg50sFdgv2NAyaZzEUSlpKNKoloreM=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB0723:EE_ x-ms-office365-filtering-correlation-id: ef3b2292-7db3-452e-a2e6-08dcb7a342ef x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: Ai7EcZHaUlQrta1587kK3oHevRemUronuDch+K/1NVswWJp5prRbQkKSzU0Q5qLulqJWVreaEzKqmBzDICtEUQYNShIbEry+574+vwTvkuSRjAVCeUoN7IhOyhy8AV/uHOrHTNfDVq60birfIc9k64iNa1hHQbzNfMEZCbTbMg8TtaWZhs1Uj9DlCAGx2KDFy1Mf+0f92zbVad7U778c/9WImeEF2atE2u8dlCgqbnsrA8C1zNOU6tfAZvmMWlb3YSgCGYBpwrawOoxLNqQHjKImIgK/CLpj5uUULY0iizoXsgn9W6NVSEG7JWQFrit7qYxz/n3qTIoyMbTJmvHNXsCIsVuhMaHL7DFf3u2aOQ21kILt6LjGjch6UFXRMBDWlSvXHyUUlvGshY/9CvNL+IKTaMNrB+OAjmYsYgOVJUz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yv2R2ZM8cEYsvRWb2Q6NasBLbIII1eA7zO9iVIsyDAShHxZ6oB1R8eS3C46Gg7wFoj+PXzBpFaeY1mqIyK3S8g4nCyyPN3XG6WB3C/3dEDe7SLHNxLvmFSl98Pz11L/XBDoheaOQbiK2fy8Blz9rhJU5bILrY+e9sn9txwSpXytWblrxXsj4VMLgVWCQlQsZQcj8pkWPy2ZYbRu7FF0pGQi8Ju7v+CnDzNOyXnli4MlsYxb7ZrGq30H9aeBdujx8b+FGoZ27BC0bbgJV2Fc0Yg9ZzMsGX4vMmNh3Taisa/3AdqxRydbp78ixQKHpbkmQIx8gPmumW3nTfrlFTS0qPl0wpZGv77ZpzmbxjaywZFR7mrfg50Ng3hzuaTw4nzF/JgqidnLRkHaO1Y/gHdj5y/SV/wW1YNwJdlIEcjcuxIXbypP7tsyszqDVgel7nnsXVXKcgT+6R4+6oZw6ZIWJrXjr+HDnKbbpcAb7WRw+/If6nvSvQOfwDK0FIwNInleInUUW4EBWb79XyThByLvpUnBFOx3otfImMWqNg+y6g8jJkbLjYPYkTlGg8vhQm2FeIl5NoM8968sDbG0pU+OZIleGryL/hoqLG1ZgeQR Content-ID: <416F035C40A49447B895812C86A7AD5D@INDP287.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ef3b2292-7db3-452e-a2e6-08dcb7a342ef X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:11:40.9761 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB0723 From: Kerem Karabay Currently the driver determines the device type based on the application, but this value is not reliable on Apple Touch Bars, where the application is HID_DG_TOUCHPAD even though the devices are direct, so allow setting it in classes. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 60b675cd1..2948fbcbc 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -146,6 +146,7 @@ struct mt_class { __s32 sn_height; /* Signal/noise ratio for height events */ __s32 sn_pressure; /* Signal/noise ratio for pressure events */ __u8 maxcontacts; + bool is_direct; /* true for touchscreens */ bool is_indirect; /* true for touchpads */ bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ }; @@ -563,13 +564,13 @@ static struct mt_application *mt_allocate_application(struct mt_device *td, mt_application->application = application; INIT_LIST_HEAD(&mt_application->mt_usages); - if (application == HID_DG_TOUCHSCREEN) + if (application == HID_DG_TOUCHSCREEN && !td->mtclass.is_indirect) mt_application->mt_flags |= INPUT_MT_DIRECT; /* * Model touchscreens providing buttons as touchpads. */ - if (application == HID_DG_TOUCHPAD) { + if (application == HID_DG_TOUCHPAD && !td->mtclass.is_direct) { mt_application->mt_flags |= INPUT_MT_POINTER; td->inputmode_value = MT_INPUTMODE_TOUCHPAD; } @@ -1317,6 +1318,9 @@ static int mt_touch_input_configured(struct hid_device *hdev, if (td->serial_maybe) mt_post_parse_default_settings(td, app); + if (cls->is_direct) + app->mt_flags |= INPUT_MT_DIRECT; + if (cls->is_indirect) app->mt_flags |= INPUT_MT_POINTER; From patchwork Thu Aug 8 12:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 818331 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2040.outbound.protection.outlook.com [40.92.103.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 606711487C8; Thu, 8 Aug 2024 12:12:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119152; cv=fail; b=B1o2Wsw1it3672nYAMzZCJneHSnQuozxQytNLdUPWmIpRzBo57OTTsD49e7opU6aN0/KretrwayIXRwOyaf+jtCxTuKbNm0FH+JwZAahdlrUIcV5USIAyiH4801vC1jV1eK7JW+b3Fmu0uPoOJbOrHMDUeI6VxrI3iJ6B1qab+M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119152; c=relaxed/simple; bh=Epig5QAHDBVwrNvDZkDXr7kWymX9dQP5FAfFEisSWhU=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=C9CCrg/tgZn2OK9X3zDeclecDgElmjFg7pYF9ya7CG0C6evfzj2dILVlgGNhmrlJtrBwa786LncSp0s0uwmDhYKZvlBYQF+178kpkYfSi9ay/U3BL0KGMH0DLxAR+gKOXfPFXSANHqb2VC9Ak3x42kyFSPEPTnztfIvOtkstqLE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=PFHzse5n; arc=fail smtp.client-ip=40.92.103.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="PFHzse5n" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=n0fbKWgUH4jIJJrp9hTB0CKbpQJ2Kll48TZrocYNppn45pzKGr1nR6erEW3RIC4Z9iIb9HCTW09TjbeFf4dvGIDGZ38G2p9idTzzVQ4DWMVxydwDGImgPHbhyubUoPjv4zdb1G1oW92GNRaACP2huA20L21shk+007GVPDaKBODcTuRBdVUmnlfuMPCiGquZfrglVLSP6BdAp6Z9dTkqz0bHoCMwe3nN1u1XGaLMnOh44cf+Gak0QvZfZEMpmUm/v786g6/34Ha00BeZPVMX2t8fuGbaTTqi7S3nFWhJ4er1l2iVOnoRPd0z4HzbRL9bM57FUiqMdIOgM+1pmcvujQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iRg9eJxDc4ARlekO+g7uV6lPG0TkCEJFMy6dAol1E7M=; b=AfY4XZMQwrpnR6dmgb9FptthYjO5NV3WJAltlG8Om9Sb50+ClXWxPbtwNIVAOyqlp3bqbsdNBDXu4Z/Nk6X/oTV2w61U2sTAqT/Jyuo73jdwWHVthnqNRo9h7pssv3WBHGqYXLLzdnuSyC75ATb8VRl1VwnQS2poMFh3YHFMqsSbwIC+igCgKrUej7RRqYdcvmvLATlvKK0GiHoVrYmPB9tZmAoqw9bX7bMpT2zRpZx39/pSrScAut5+gOGu3UIDCMPQYKy4sR1ka44r9Sb0V+kxyJQtJGzVXdHFHSDBnW7WqWRv7Q8KBUgtp0/4JIW567iSZUWftcmBUOHW9pewZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iRg9eJxDc4ARlekO+g7uV6lPG0TkCEJFMy6dAol1E7M=; b=PFHzse5ncBQsmwX+kMSksVjtRFvlp6bFy4qBMsVimARr/TFO9iIzPdVlFiYkUanUb+ckjN37zrde64IHJeRctobNf/N+EBg0YPLzdWfNp4ZBjAT1e2RsUaetg3z6hcsT+Zr0XYArTAIVZCX3FXpVV4I86aZG7VPXHM6Qqwt6IY3EWbvNL7n0YXsoZO5qtGowWgdCq5qaKy/hfTvUBd3U5/RgKjR5GqqPBxZzwqsdFJ78JEXdQVE7KeazJaWML1MTfjJ8c747p9lBzxDNEC3uiruCucWTaMsKjFY7wNffGvtX3ZXiQo1pkuZZupcXii4KyiVV6SARUTKEw2CkoBG6hQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB0723.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:fe::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:12:24 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:12:24 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Topic: [PATCH RESEND v2 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Index: AQHa6Yw6oVqu/SRLokKwJGqKsMVRAA== Date: Thu, 8 Aug 2024 12:12:24 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [H71tbL8xC4Io0L9iPIB0J22czkvHcZTE8nvvAsWsSZXab7EwWyGqlJpVLYDUHpZ5Y/ryA5R3N9o=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB0723:EE_ x-ms-office365-filtering-correlation-id: 2220d481-594c-4472-6194-08dcb7a35cb2 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: fm1xc/j/Q4SDD0eIArBudSTwckqDfuNsLmLFWiZE80sZqgTlWOvt1aeE3XDpcYWbYFMAi4S/Q2uySvoSSOB/0Fl7efMZnKPjVK7UXnGeTFXOD4UuUea7d/vgcQSHZkYWZfxmknhpy+BEIrWc9+GMF+msbHcb5AHw5Gqx+EYhd0QDfsAQCpI4RQ+sOsQpZEwOezSBnfWe0CvR8SyEODIPeJk/pcICzcMPGSLjD6Pn/9gk5wBeeqewdSknGfO4IjMnAkp7XonAcP2Cmnnv+eXiYM3y8S014drEjegNON8hnZ+R7D5aRXHJ+os/7bZ2CGfBuMABz6BEjmhByIvF+s+NuhcLqctfKtyxD66VpJdcks9Y36tNCCOs51N3QtTM9OpfQ6rfKwqg3ROTZyQ7uBtsaeeO6OX7/z6Htc0gCXPk/n94ASuJTEe12kLMharORxiWah7gGGYScWHSKZ3JL5vgFpdhASdk/Gx88Cc2DQGNhd+zdyEoPKznU2YlgV8rD8sLv/KqTGJawCDyW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d+34dE094S8RmvJuhLdS0B8UTzwvgNzbGprdZzSxzHVw/HQeHUqERYEkl2fJxcQy/4/2IehYaaGb6zXljEQwRgTQe/yNX8vN1iTKMOWUrHA4e1aqCHfwBrfaILfMZvRh48IvobxTvHHlqRvt7DZHdBzQdYNkWEpf8rjoLhBgOkJlDSBRZURZ5pRi2AU7Al2CnW+gkfop0VDR6NnX4ImTfcuajrc6BRQW5sj13pLPcc0T6GksCwxQs94fjQoXsueb3maFQM+qnusAEiRkc4N+teVz1J7La5eDLjQmgD8r9+DWPYywmaim3fHcEA3u4kQ8Atl2R5DLfL1/2x8PP2pTA9E4wUtNU8U58jOOgZJOvOfwSRcrlCnesHqDHhbqBKPAZGc/BhMim5hbAq7DcgMRMhpbiMs4SsVF+EoUXZx8EVm8hYvKjL+rDAkDG0Sxdqm0HDHF+vbJi7ZX6zZ2gQCCSEflpsGKxsScJcjUxg0iElH8k3KN5OSybCDE Content-ID: <29891688A8B42047888F37B406E50214@INDP287.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 2220d481-594c-4472-6194-08dcb7a35cb2 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:12:24.2096 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB0723 From: Kerem Karabay Note that this is device ID is for T2 Macs. Testing on T1 Macs would be appreciated. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/Kconfig | 1 + drivers/hid/hid-multitouch.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 72b665eda..35ef5d4ef 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -744,6 +744,7 @@ config HID_MULTITOUCH Say Y here if you have one of the following devices: - 3M PCT touch screens - ActionStar dual touch panels + - Touch Bars on x86 MacBook Pros - Atmel panels - Cando dual touch panels - Chunghwa panels diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 2948fbcbc..0fed95536 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -214,6 +214,7 @@ static void mt_post_parse(struct mt_device *td, struct mt_application *app); #define MT_CLS_GOOGLE 0x0111 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112 #define MT_CLS_SMART_TECH 0x0113 +#define MT_CLS_APPLE_TOUCHBAR 0x0114 #define MT_DEFAULT_MAXCONTACT 10 #define MT_MAX_MAXCONTACT 250 @@ -398,6 +399,13 @@ static const struct mt_class mt_classes[] = { MT_QUIRK_CONTACT_CNT_ACCURATE | MT_QUIRK_SEPARATE_APP_REPORT, }, + { .name = MT_CLS_APPLE_TOUCHBAR, + .quirks = MT_QUIRK_HOVERING | + MT_QUIRK_TOUCH_IS_TIPSTATE | + MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE, + .is_direct = true, + .maxcontacts = 11, + }, { } }; @@ -1747,6 +1755,15 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) } } + ret = hid_parse(hdev); + if (ret != 0) + return ret; + + if (mtclass->name == MT_CLS_APPLE_TOUCHBAR && + !hid_find_field(hdev, HID_INPUT_REPORT, + HID_DG_TOUCHPAD, HID_DG_TRANSDUCER_INDEX)) + return -ENODEV; + td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); if (!td) { dev_err(&hdev->dev, "cannot allocate multitouch data\n"); @@ -1794,10 +1811,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) timer_setup(&td->release_timer, mt_expired_timeout, 0); - ret = hid_parse(hdev); - if (ret != 0) - return ret; - if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID) mt_fix_const_fields(hdev, HID_DG_CONTACTID); @@ -2249,6 +2262,11 @@ static const struct hid_device_id mt_devices[] = { MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) }, + /* Apple Touch Bars */ + { .driver_data = MT_CLS_APPLE_TOUCHBAR, + HID_USB_DEVICE(USB_VENDOR_ID_APPLE, + USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, + /* Google MT devices */ { .driver_data = MT_CLS_GOOGLE, HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE, From patchwork Thu Aug 8 12:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 817793 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2010.outbound.protection.outlook.com [40.92.103.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6263918A956; Thu, 8 Aug 2024 12:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119201; cv=fail; b=mQrlnNJPsM/dbSyok4WP8xovjQJhjcQJPwWS5Gph9vgMyQyKgKdoLHQj66vuljHPbrANr2S4rEBUFpQmmPaphgTOYA4ZiRr8uWdEhUGAzoXyry/Wg3TuJ+D+oACg3gvNEkXZzxOSxoSGkS95TG3kp99cuG1qV5YyAAiaRD9WB8o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119201; c=relaxed/simple; bh=k2qTvJJuKQ9yjna5tCPRpIpR+Mhe7F9Wvq5AaQD3p4o=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=Xi06Rqf9VlIl4E1gMsP2rAEhpgHZ9BLU5EeFGQwJ/cDknbtAh10UOR6EsHbgCaQHBQoX1cEDI9WHCWV7SPAIxw4ZTg0FiC0V3T0G+Ss01lzYRwzDzPtvJDoIzbQMLQKV7i91eXCwkzHN/Lv59RlfQ1eZT639AaUoflSBxtF4gLo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=Kp2BFGt+; arc=fail smtp.client-ip=40.92.103.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="Kp2BFGt+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VaS7CIuUqsgsvdFlSly2s5mQOokWhHD2qYsE2L5KyB34OSmidsFOFnnOemIp839inAgJBHOeYNotD8uUYMNfuQqffsMIxbGQSmYidf/K9qmbYZvKulTvr9Bv0tHAdcO85DTMH6c460zYgrDS86g6DQ2EoWF+0t7pUYmmgtBuyZnzWFQc+G1W/jBakyXQT4/jyRTb87OiO3zldgT6jguHJi/d/exIvPDNbG7PtB3yyxkUDURSbq+MqfB/41zDPaMb+msuJDRSPZWyjPy101tYlNdwR4i6UKlHjPa3+Q8AJ1jvMMbzCAqfNejco5v+dfrcUmndau5+1uGFab14grVsUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OtdQ3/r+0UdrKlCuSHzXkJk1YWEEi4Wt1GXubHNHEfc=; b=cH/bdha/X6Ds49K2JONPB4GsjgabJZFYsVGJXs0SYPPIjmk9VWPbh3GLpPUlZXUVFBkb/QevXBIUDKmZcXXG39IWnaUruh1bLosy/LdjxzT+zu9sHg/v787ok5OwHyCb1f6L3OaI3ZnsNigSAthrXcv8gdA00R7ZLVFEpiluDuc8r2nc6bUXaP5J0nAcwc5zQkcZSfa2J9eNIlFCBH336x2mh1FgNRqwsiKwJNvitA88N1oMS42hu9bNKwKy1v6cGpCBcVbMhmo7oICOcFOB38Z/47aFu91Vyr3C1/R/M//OjcnMcZcfDmXcadWdimxvfi+1vZSDJp2kUWqFR5ifIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OtdQ3/r+0UdrKlCuSHzXkJk1YWEEi4Wt1GXubHNHEfc=; b=Kp2BFGt+6K3aDhsw8wjKURZZ6fkpcmvkgWDwBPQd45m/rMPH1CbucjJplPvJeYeoDeg/vOLUNuFwUALPOdfMp4Bdog1RQUE0VI1r9Hk0S57uV6Y+J7kEdhNG5xD2H/d/KTNzCYFlJb51meyWGVRp3BwFMIScoexS570B34L470MU0m/bH/PrFPM4MqboZODvAiFsVJ8kWHM3zL2Iup8D4blCG0ULVxcfP3qKtce9/sQcX1wV9MoeMIQ5jhIiG1c1J42YwZHp9YANshqMbqnC1/7vBZCuQdYdyH2LpsMCSyxRYVquzVncwaKaFiFPZiaRPJy5lNJ9w1Y0c2Q5lLgCAA== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2144.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:13:10 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:13:10 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 8/9] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Topic: [PATCH RESEND v2 8/9] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Index: AQHa6YxVlajliY3BmUmFXaQEzoUoow== Date: Thu, 8 Aug 2024 12:13:10 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [UeTAULfIFEQ45uuhlBBtcqYHGJOhzlOrWc2cdcNz2qrLsZN06MQTm7L7r7B7/Bd8njuN8jO6+Fw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2144:EE_ x-ms-office365-filtering-correlation-id: b873eca1-6da0-4086-a5db-08dcb7a37824 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|19110799003|8060799006|102099032|3412199025|440099028; x-microsoft-antispam-message-info: VRgWMOV6UKEebcoMBjROchWKDslqvT1MT1FXNAVqTuzNpJMAKqbOI/keUAhr1ll8qEUfldgnkH3hqezR5nbZ2ARDyW8kazA+NQJZ3jUSaqZsD04Fhk3ixmq7zo4zsnsbaxnV5ZzDrijmhd0KjYka6KcfR/N8/i2nBWc2NVJDafwzyX2Z5wsYAihRIXP0uJt6YhGVQ9O0qT4E+aijul3LiC3KIzVS3N69kmoZvlyJxQ5cDpwu0R7Z4spMn/CsXDSO4JElo2tx7TB/crxgPzUQc35b82fHV1nj94nuMXagIViBndWNkfrHGGlvO9GYW5NbAZ4h9Na6Rvel8jvXOOAYt1gEJokGacIaY6gXTaqiOejTL3+hedM2mwZQsrBWmiTEq8jM43wELFD+FpTwUPImOd7Bin7kR1OCG8rUihCjRStEOivPH3bYBbpaHRSINApMY2FyXQhCaQOjlNNNYu/ynvpwvIKWJC58Qals3V5QQNkbxOOXVUGjgkopNsMvMKHqNs6gErxt0VxdzZqtS4SKV22XrF8Js1QZGeKwM/oIDjheLgQd9VUDWHGNEIeJQdsfxd7FYixatXTS11mvHe6agy3js0qkMeq5e5KUwsHntLX6pGIxlLj/ViG5zeBCQ0cbCH3tRqMDFpZXHXIQDmW1WZsvh/Wlb4mFo8pxlVFgDk0= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: iCrwHF6JEoV8jV2BShdvU6A4n+rqJKZNEMMO+0PtU0SP5D8YuGPRQCXW7LXsO+7/wHVQ//O8e1vvPtI88l/sdQk+RICop826qo/IMxHEiDiV3aKlh6ypK4/Bn5o4JsCGf80CxYfV52eDCjnxAmRBM0srwQ5vM/+BH0iQYBL31cfrHRR+H40mAWMo3mT5u0rohPDfaraJ4RskIDmqyxPYD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2UKPBYlr+JAX0Xu/GIfpSO8q9QMEuDWa3DfNe2BOLaQhiIAopVBiukm6NBO Content-ID: Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: b873eca1-6da0-4086-a5db-08dcb7a37824 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:13:10.2607 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2144 From: Kerem Karabay Add XRGB8888 emulation helper for devices that only support BGR888. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/gpu/drm/drm_format_helper.c | 54 +++++++++++++ .../gpu/drm/tests/drm_format_helper_test.c | 81 +++++++++++++++++++ include/drm/drm_format_helper.h | 3 + 3 files changed, 138 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index b1be458ed..28c0e76a1 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -702,6 +702,57 @@ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pi } EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888); +static void drm_fb_xrgb8888_to_bgr888_line(void *dbuf, const void *sbuf, unsigned int pixels) +{ + u8 *dbuf8 = dbuf; + const __le32 *sbuf32 = sbuf; + unsigned int x; + u32 pix; + + for (x = 0; x < pixels; x++) { + pix = le32_to_cpu(sbuf32[x]); + /* write red-green-blue to output in little endianness */ + *dbuf8++ = (pix & 0x00FF0000) >> 16; + *dbuf8++ = (pix & 0x0000FF00) >> 8; + *dbuf8++ = (pix & 0x000000FF) >> 0; + } +} + +/** + * drm_fb_xrgb8888_to_bgr888 - Convert XRGB8888 to BGR888 clip buffer + * @dst: Array of BGR888 destination buffers + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines + * within @dst; can be NULL if scanlines are stored next to each other. + * @src: Array of XRGB8888 source buffers + * @fb: DRM framebuffer + * @clip: Clip rectangle area to copy + * @state: Transform and conversion state + * + * This function copies parts of a framebuffer to display memory and converts the + * color format during the process. Destination and framebuffer formats must match. The + * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at + * least as many entries as there are planes in @fb's format. Each entry stores the + * value for the format's respective color plane at the same index. + * + * This function does not apply clipping on @dst (i.e. the destination is at the + * top-left corner). + * + * Drivers can use this function for BGR888 devices that don't natively + * support XRGB8888. + */ +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state) +{ + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { + 3, + }; + + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state, + drm_fb_xrgb8888_to_bgr888_line); +} +EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgr888); + static void drm_fb_xrgb8888_to_argb8888_line(void *dbuf, const void *sbuf, unsigned int pixels) { __le32 *dbuf32 = dbuf; @@ -1035,6 +1086,9 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t d } else if (dst_format == DRM_FORMAT_RGB888) { drm_fb_xrgb8888_to_rgb888(dst, dst_pitch, src, fb, clip, state); return 0; + } else if (dst_format == DRM_FORMAT_BGR888) { + drm_fb_xrgb8888_to_bgr888(dst, dst_pitch, src, fb, clip, state); + return 0; } else if (dst_format == DRM_FORMAT_ARGB8888) { drm_fb_xrgb8888_to_argb8888(dst, dst_pitch, src, fb, clip, state); return 0; diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08992636e..35cd3405d 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -60,6 +60,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_bgr888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_to_argb8888_result { unsigned int dst_pitch; const u32 expected[TEST_BUF_SIZE]; @@ -107,6 +112,7 @@ struct convert_xrgb8888_case { struct convert_to_argb1555_result argb1555_result; struct convert_to_rgba5551_result rgba5551_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_bgr888_result bgr888_result; struct convert_to_argb8888_result argb8888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; struct convert_to_argb2101010_result argb2101010_result; @@ -151,6 +157,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0xFF, 0x00, 0x00 }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFFFF0000 }, @@ -217,6 +227,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0xFF, 0x00, 0x00 }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFFFF0000 }, @@ -330,6 +344,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, + }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { @@ -468,6 +491,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .bgr888_result = { + .dst_pitch = 15, + .expected = { + 0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05, 0xA8, 0xF3, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xA8, 0x03, 0x03, 0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, .argb8888_result = { .dst_pitch = 20, .expected = { @@ -914,6 +948,52 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); } +static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test) +{ + const struct convert_xrgb8888_case *params = test->param_value; + const struct convert_to_bgr888_result *result = ¶ms->bgr888_result; + size_t dst_size; + u8 *buf = NULL; + __le32 *xrgb8888 = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_BGR888, result->dst_pitch, + ¶ms->clip, 0); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(&dst, buf); + + xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888); + iosys_map_set_vaddr(&src, xrgb8888); + + /* + * BGR888 expected results are already in little-endian + * order, so there's no need to convert the test output. + */ + drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, + &fmtcnv_state); + KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); + + buf = dst.vaddr; /* restore original value of buf */ + memset(buf, 0, dst_size); + + int blit_result = 0; + + blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, ¶ms->clip, + &fmtcnv_state); + + KUNIT_EXPECT_FALSE(test, blit_result); + KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); +} + static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test) { const struct convert_xrgb8888_case *params = test->param_value; @@ -1851,6 +1931,7 @@ static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_bgr888, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params), diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h index 428d81afe..aa1604d92 100644 --- a/include/drm/drm_format_helper.h +++ b/include/drm/drm_format_helper.h @@ -96,6 +96,9 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip, struct drm_format_conv_state *state); +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state); void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip, struct drm_format_conv_state *state); From patchwork Thu Aug 8 12:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 818330 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2084.outbound.protection.outlook.com [40.92.103.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CF9B18C344; Thu, 8 Aug 2024 12:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119245; cv=fail; b=HxHDLDnXaui3yGwjfrFjdSJtWR2+vycczvyc7Eauc2qrT36UJy1mUfatJHhvLqMF7Fsk0LoSuph7ermXP5zB97xBQyDKSS/yvhCas6MQKoV0QS9WK+T50r0UNOneDCTKG4eMQB6PKGQgy0BYsBENtkixaEfjCCkZrxbAR40Ew3E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723119245; c=relaxed/simple; bh=ZRbju26fJKy+jA89ybMXYZptYUcLwTgfKAd/2+LRoQU=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=lutX1Hkm3OlRibq6OK7BGIbzPYIXnYYFYxZ1Hv9xuqas0xqOTenRZHrxflrR7WisDaW5TmUuPWF+/5ivNIKFNRR/pdaJbQBBRhJ+S+rtC8MAookpsPPbGXBVGHg61W8gdhteHQJ1E/so2t/KuoeVdVlraTVkUdMOsbpo4qHQj1c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=lm6Nz8iV; arc=fail smtp.client-ip=40.92.103.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="lm6Nz8iV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Imlhd97223fq3mxjejl3LAukiIqI/kGbrMxnc2BEOM4W/R/BiqG90QabN8bJFfZWS2wvIDr0uaOMc3ufQSYkhYXUcM/1xlMJIj17tnqMispG5tg8NUXNaFzekhey3ZTZI0gRTkjkeGi+wb19vaNBVU9DGyNd/SVAMWD3/p0ulF+zzvqATf/murFgEvNsXzaFLDupfXCGh7bsXPi9bCnvaQyNNdJ9dbSzJ+YXTiTla9N2qsERGXRE+PVUOg12zaPT8Pauo5K2++OhpWABtbNrDDMEoHlNgSIl8RTKZW27+lKLbgrzhsCBnqCgl1KwS8z5uXKrbtPiYVV7HjtiVqLR6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pB6NmUDLnU/Yj4gQeyhxMJ0YQpmjzKnwyNDwR3xwWOE=; b=VanHU8GRj1WUZ0QI0H2MCtDQYY4Yy0+4SdlO6hLzOE8yaTBRRYCp2Q35n+/6xOuszpHhn4tkssf/IQOINK0XmM89CVVNHsc4u152lI/tomQfgUs1FWRCQ+F1WiVP86aSP4e61Q83QI2WDQ+TTd0K+mohtAXdw/JN3/I6Q7O3Mxu3Yn0jTMtA3wRsHLNb58P+C2630308ykEgk6u29bSal7y/C6e1+acUu/Ht6wj67cTu+3b7XstsoKjeHfH7ePVXyuVvfpFJYmThDjhB3nZoqq6vhjRLUHckHcxrSjkcHuQnDzgkeFWLDP76LIOHGag0dpoCTNfRO3kkn/beAP1dog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pB6NmUDLnU/Yj4gQeyhxMJ0YQpmjzKnwyNDwR3xwWOE=; b=lm6Nz8iVN604t2eUy9evhnZSi4x+bOw+kP9d4sR09UFq07t4ZnUv2N/NAvEgtmY0USJhYBqgVd49mQEpe7ZukdFbU+7mYpO1rnGqNfYlon8Vq+P48kmh1W+2fcGU0qhPW7V+jz+lzFaQIPP36PUa9y9MaZ8jz4ajpJq9dvKIlfBoSseeDgQxXC+1l2jGUqdnj2h/Mw87v5qQiKIlw9+ldYyI8Evogwg/73AN9zp3aPe4rhAJNs/qOB09fbqcJCpKTpS9hg5kVcAC8XOa98IBLvLs4sOXqGzmWlExgJD/0HMicndACIqASfepcm/Iog6Ed6LNZ3boNB3GvAG9d+oOYw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2144.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 12:13:56 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 12:13:55 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH RESEND v2 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Topic: [PATCH RESEND v2 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Index: AQHa6YxwQ/Ycfue6lEWHcZCiKiOHaQ== Date: Thu, 8 Aug 2024 12:13:55 +0000 Message-ID: References: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> In-Reply-To: <752D8EEA-EE3B-4854-9B5E-F412AFA20048@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [zH9HuaVffgNquCA+JPMZtChnEaH8eg/gI838YTpz9DOLVj0EFSEmX5E5mfT03Hsx3G5PQxHParU=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2144:EE_ x-ms-office365-filtering-correlation-id: 744a02a6-7a24-42fc-156e-08dcb7a3934d x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|19110799003|8060799006|102099032|4302099013|3412199025|440099028|1602099012; x-microsoft-antispam-message-info: xvj1DWv/pxuikC1XmpczFon8WeuWhHiqx84XehdXc+TIsNNrwSbaWR2b52DufXDjhcNI0k5MZXOWU/dH1PJvzUgrPKb/uXMvCnth1/Ix/3931dCDCWKYN1FBb8C20IOKAlowZWVUasc8P85n5DsvVUG8EL13+Mc7RIjdnc6R+t/tcJ7lmYGA9UgsutU1Ftcrg0o4f2liO+l0TjUsYKWh4EsjJjveYfkdI+enJrVMmaplsJ4QJBnGos67TBy8EzMpwDjTqix3xF8wWv5NVv6qZT838T+STEdE/SVSHWVgHiO/Q3HhAk7XMhN/kfkKEWOaSvMTFbb5sZrLhsbmWK7UWMrNWTioVvYaZoPA+cvEaCoSNwr72KWdrBC2PKK9LIXL0FJUdRgNxYNp6JYIdbIayslSjlVRocFBFZGGtfVa7JoRyHnnWVCvRcj9rLUf3g4q7sCA4QGIotBVIJdpMY10LoG/Muoo26/MiXh57NyC+TbWVttgWqzlfGiUP5nltxk3wUI6VCd9Z1V1EUtMnYdcaBmm6w0vZLeJ030OyO8bsf8V5DTJC7OEB3wmraH+sYuG0ytbldYkwp9+aMASLANQFKCurpPjkzV5yF9K1phPzGGsi5Q2Zt3I7pFhRjEWi4KgBgdJq6YhnyI72REkoXyIsHNsuGCJYqJ1eo23G7XW3yCWfOcpCxZMMRv3mYh4r/flhNZUyHF7iQZtlpBnd9QlKc7vW2FtVOBK5jiRmZ5bSrI0eAZ74CcAFeBfLP3zDWvyH+g3et5qBte5V1zsyG18UZqfOZzXNqDVlseRPvmkaVw= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: XdUdfR1Rebw8O+HudfO3IT7sonV7xiXUUHosS4Af0o1oF2M0DOgm86RQf+wFyudwjQVvIYsXFjuJA/16KH7hUW9uVD9tM+E7yxgzT/cViYOGULkyweO4BtPXAyrOnm9X7yEZb/aPNDDWpil33VTs+asE6hFAcJN+cR7HoziiVdKguNrJzvD5Ryn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u8zidHCgTA1klqTqBWbRsJkxhZhj2UwSX1GoJphFuxNz6LwArAaYKPs8Rdxd/Me9bR Content-ID: <03A69239287D2D4A8CAED462FB70281B@INDP287.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 744a02a6-7a24-42fc-156e-08dcb7a3934d X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 12:13:55.8251 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2144 From: Kerem Karabay The Touch Bars found on x86 Macs support two USB configurations: one where the device presents itself as a HID keyboard and can display predefined sets of keys, and one where the operating system has full control over what is displayed. This commit adds support for the display functionality of the second configuration. Note that this driver has only been tested on T2 Macs, and only includes the USB device ID for these devices. Testing on T1 Macs would be appreciated. Credit goes to @imbushuo on GitHub for reverse engineering most of the protocol. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- MAINTAINERS | 6 + drivers/gpu/drm/tiny/Kconfig | 12 + drivers/gpu/drm/tiny/Makefile | 1 + drivers/gpu/drm/tiny/appletbdrm.c | 624 ++++++++++++++++++++++++++++++ 4 files changed, 643 insertions(+) create mode 100644 drivers/gpu/drm/tiny/appletbdrm.c diff --git a/MAINTAINERS b/MAINTAINERS index ac27f41d4..f2c227150 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6889,6 +6889,12 @@ S: Supported T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: drivers/gpu/drm/sun4i/sun8i* +DRM DRIVER FOR APPLE TOUCH BARS +M: Kerem Karabay +L: dri-devel@lists.freedesktop.org +S: Maintained +F: drivers/gpu/drm/tiny/appletbdrm.c + DRM DRIVER FOR ARM PL111 CLCD S: Orphan T: git https://gitlab.freedesktop.org/drm/misc/kernel.git diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig index f6889f649..559a97bce 100644 --- a/drivers/gpu/drm/tiny/Kconfig +++ b/drivers/gpu/drm/tiny/Kconfig @@ -1,5 +1,17 @@ # SPDX-License-Identifier: GPL-2.0-only +config DRM_APPLETBDRM + tristate "DRM support for Apple Touch Bars" + depends on DRM && USB && MMU + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + help + Say Y here if you want support for the display of Touch Bars on x86 + MacBook Pros. + + To compile this driver as a module, choose M here: the + module will be called appletbdrm. + config DRM_ARCPGU tristate "ARC PGU" depends on DRM && OF diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile index 76dde89a0..9a1b412e7 100644 --- a/drivers/gpu/drm/tiny/Makefile +++ b/drivers/gpu/drm/tiny/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_DRM_APPLETBDRM) += appletbdrm.o obj-$(CONFIG_DRM_ARCPGU) += arcpgu.o obj-$(CONFIG_DRM_BOCHS) += bochs.o obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus.o diff --git a/drivers/gpu/drm/tiny/appletbdrm.c b/drivers/gpu/drm/tiny/appletbdrm.c new file mode 100644 index 000000000..b9440ce00 --- /dev/null +++ b/drivers/gpu/drm/tiny/appletbdrm.c @@ -0,0 +1,624 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Apple Touch Bar DRM Driver + * + * Copyright (c) 2023 Kerem Karabay + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define _APPLETBDRM_FOURCC(s) (((s)[0] << 24) | ((s)[1] << 16) | ((s)[2] << 8) | (s)[3]) +#define APPLETBDRM_FOURCC(s) _APPLETBDRM_FOURCC(#s) + +#define APPLETBDRM_PIXEL_FORMAT APPLETBDRM_FOURCC(RGBA) /* The actual format is BGR888 */ +#define APPLETBDRM_BITS_PER_PIXEL 24 + +#define APPLETBDRM_MSG_CLEAR_DISPLAY APPLETBDRM_FOURCC(CLRD) +#define APPLETBDRM_MSG_GET_INFORMATION APPLETBDRM_FOURCC(GINF) +#define APPLETBDRM_MSG_UPDATE_COMPLETE APPLETBDRM_FOURCC(UDCL) +#define APPLETBDRM_MSG_SIGNAL_READINESS APPLETBDRM_FOURCC(REDY) + +#define APPLETBDRM_BULK_MSG_TIMEOUT 1000 + +#define drm_to_adev(_drm) container_of(_drm, struct appletbdrm_device, drm) +#define adev_to_udev(adev) interface_to_usbdev(to_usb_interface(adev->dev)) + +struct appletbdrm_device { + struct device *dev; + + u8 in_ep; + u8 out_ep; + + u32 width; + u32 height; + + struct drm_device drm; + struct drm_display_mode mode; + struct drm_connector connector; + struct drm_simple_display_pipe pipe; + + bool readiness_signal_received; +}; + +struct appletbdrm_request_header { + __le16 unk_00; + __le16 unk_02; + __le32 unk_04; + __le32 unk_08; + __le32 size; +} __packed; + +struct appletbdrm_response_header { + u8 unk_00[16]; + u32 msg; +} __packed; + +struct appletbdrm_simple_request { + struct appletbdrm_request_header header; + u32 msg; + u8 unk_14[8]; + __le32 size; +} __packed; + +struct appletbdrm_information { + struct appletbdrm_response_header header; + u8 unk_14[12]; + __le32 width; + __le32 height; + u8 bits_per_pixel; + __le32 bytes_per_row; + __le32 orientation; + __le32 bitmap_info; + u32 pixel_format; + __le32 width_inches; /* floating point */ + __le32 height_inches; /* floating point */ +} __packed; + +struct appletbdrm_frame { + __le16 begin_x; + __le16 begin_y; + __le16 width; + __le16 height; + __le32 buf_size; + u8 buf[]; +} __packed; + +struct appletbdrm_fb_request_footer { + u8 unk_00[12]; + __le32 unk_0c; + u8 unk_10[12]; + __le32 unk_1c; + __le64 timestamp; + u8 unk_28[12]; + __le32 unk_34; + u8 unk_38[20]; + __le32 unk_4c; +} __packed; + +struct appletbdrm_fb_request { + struct appletbdrm_request_header header; + __le16 unk_10; + u8 msg_id; + u8 unk_13[29]; + /* + * Contents of `data`: + * - struct appletbdrm_frame frames[]; + * - struct appletbdrm_fb_request_footer footer; + * - padding to make the total size a multiple of 16 + */ + u8 data[]; +} __packed; + +struct appletbdrm_fb_request_response { + struct appletbdrm_response_header header; + u8 unk_14[12]; + __le64 timestamp; +} __packed; + +static int appletbdrm_send_request(struct appletbdrm_device *adev, + struct appletbdrm_request_header *request, size_t size) +{ + struct usb_device *udev = adev_to_udev(adev); + struct drm_device *drm = &adev->drm; + int ret, actual_size; + + ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, adev->out_ep), + request, size, &actual_size, APPLETBDRM_BULK_MSG_TIMEOUT); + if (ret) { + drm_err(drm, "Failed to send message (%pe)\n", ERR_PTR(ret)); + return ret; + } + + if (actual_size != size) { + drm_err(drm, "Actual size (%d) doesn't match expected size (%lu)\n", + actual_size, size); + return -EIO; + } + + return ret; +} + +static int appletbdrm_read_response(struct appletbdrm_device *adev, + struct appletbdrm_response_header *response, + size_t size, u32 expected_response) +{ + struct usb_device *udev = adev_to_udev(adev); + struct drm_device *drm = &adev->drm; + int ret, actual_size; + +retry: + ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, adev->in_ep), + response, size, &actual_size, APPLETBDRM_BULK_MSG_TIMEOUT); + if (ret) { + drm_err(drm, "Failed to read response (%pe)\n", ERR_PTR(ret)); + return ret; + } + + /* + * The device responds to the first request sent in a particular + * timeframe after the USB device configuration is set with a readiness + * signal, in which case the response should be read again + */ + if (response->msg == APPLETBDRM_MSG_SIGNAL_READINESS) { + if (!adev->readiness_signal_received) { + adev->readiness_signal_received = true; + goto retry; + } + + drm_err(drm, "Encountered unexpected readiness signal\n"); + return -EIO; + } + + if (actual_size != size) { + drm_err(drm, "Actual size (%d) doesn't match expected size (%lu)\n", + actual_size, size); + return -EIO; + } + + if (response->msg != expected_response) { + drm_err(drm, "Unexpected response from device (expected %p4ch found %p4ch)\n", + &expected_response, &response->msg); + return -EIO; + } + + return 0; +} + +static int appletbdrm_send_msg(struct appletbdrm_device *adev, u32 msg) +{ + struct appletbdrm_simple_request *request; + int ret; + + request = kzalloc(sizeof(*request), GFP_KERNEL); + if (!request) + return -ENOMEM; + + request->header.unk_00 = cpu_to_le16(2); + request->header.unk_02 = cpu_to_le16(0x1512); + request->header.size = cpu_to_le32(sizeof(*request) - sizeof(request->header)); + request->msg = msg; + request->size = request->header.size; + + ret = appletbdrm_send_request(adev, &request->header, sizeof(*request)); + + kfree(request); + + return ret; +} + +static int appletbdrm_clear_display(struct appletbdrm_device *adev) +{ + return appletbdrm_send_msg(adev, APPLETBDRM_MSG_CLEAR_DISPLAY); +} + +static int appletbdrm_signal_readiness(struct appletbdrm_device *adev) +{ + return appletbdrm_send_msg(adev, APPLETBDRM_MSG_SIGNAL_READINESS); +} + +static int appletbdrm_get_information(struct appletbdrm_device *adev) +{ + struct appletbdrm_information *info; + struct drm_device *drm = &adev->drm; + u8 bits_per_pixel; + u32 pixel_format; + int ret; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + ret = appletbdrm_send_msg(adev, APPLETBDRM_MSG_GET_INFORMATION); + if (ret) + return ret; + + ret = appletbdrm_read_response(adev, &info->header, sizeof(*info), + APPLETBDRM_MSG_GET_INFORMATION); + if (ret) + goto free_info; + + bits_per_pixel = info->bits_per_pixel; + pixel_format = get_unaligned(&info->pixel_format); + + adev->width = get_unaligned_le32(&info->width); + adev->height = get_unaligned_le32(&info->height); + + if (bits_per_pixel != APPLETBDRM_BITS_PER_PIXEL) { + drm_err(drm, "Encountered unexpected bits per pixel value (%d)\n", bits_per_pixel); + ret = -EINVAL; + goto free_info; + } + + if (pixel_format != APPLETBDRM_PIXEL_FORMAT) { + drm_err(drm, "Encountered unknown pixel format (%p4ch)\n", &pixel_format); + ret = -EINVAL; + goto free_info; + } + +free_info: + kfree(info); + + return ret; +} + +static u32 rect_size(struct drm_rect *rect) +{ + return drm_rect_width(rect) * drm_rect_height(rect) * (APPLETBDRM_BITS_PER_PIXEL / 8); +} + +static int appletbdrm_flush_damage(struct appletbdrm_device *adev, + struct drm_plane_state *old_state, + struct drm_plane_state *state) +{ + struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(state); + struct appletbdrm_fb_request_response *response; + struct appletbdrm_fb_request_footer *footer; + struct drm_atomic_helper_damage_iter iter; + struct drm_framebuffer *fb = state->fb; + struct appletbdrm_fb_request *request; + struct drm_device *drm = &adev->drm; + struct appletbdrm_frame *frame; + u64 timestamp = ktime_get_ns(); + struct drm_rect damage; + size_t frames_size = 0; + size_t request_size; + int ret; + + drm_atomic_helper_damage_iter_init(&iter, old_state, state); + drm_atomic_for_each_plane_damage(&iter, &damage) { + frames_size += struct_size(frame, buf, rect_size(&damage)); + } + + if (!frames_size) + return 0; + + request_size = ALIGN(sizeof(*request) + frames_size + sizeof(*footer), 16); + + request = kzalloc(request_size, GFP_KERNEL); + if (!request) + return -ENOMEM; + + response = kzalloc(sizeof(*response), GFP_KERNEL); + if (!response) { + ret = -ENOMEM; + goto free_request; + } + + ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) { + drm_err(drm, "Failed to start CPU framebuffer access (%pe)\n", ERR_PTR(ret)); + goto free_response; + } + + request->header.unk_00 = cpu_to_le16(2); + request->header.unk_02 = cpu_to_le16(0x12); + request->header.unk_04 = cpu_to_le32(9); + request->header.size = cpu_to_le32(request_size - sizeof(request->header)); + request->unk_10 = cpu_to_le16(1); + request->msg_id = timestamp & 0xff; + + frame = (struct appletbdrm_frame *)request->data; + + drm_atomic_helper_damage_iter_init(&iter, old_state, state); + drm_atomic_for_each_plane_damage(&iter, &damage) { + struct iosys_map dst = IOSYS_MAP_INIT_VADDR(frame->buf); + u32 buf_size = rect_size(&damage); + + /* + * The coordinates need to be translated to the coordinate + * system the device expects, see the comment in + * appletbdrm_setup_mode_config + */ + frame->begin_x = cpu_to_le16(damage.y1); + frame->begin_y = cpu_to_le16(adev->height - damage.x2); + frame->width = cpu_to_le16(drm_rect_height(&damage)); + frame->height = cpu_to_le16(drm_rect_width(&damage)); + frame->buf_size = cpu_to_le32(buf_size); + + ret = drm_fb_blit(&dst, NULL, DRM_FORMAT_BGR888, + &shadow_plane_state->data[0], fb, &damage, &shadow_plane_state->fmtcnv_state); + if (ret) { + drm_err(drm, "Failed to copy damage clip (%pe)\n", ERR_PTR(ret)); + goto end_fb_cpu_access; + } + + frame = (void *)frame + struct_size(frame, buf, buf_size); + } + + footer = (struct appletbdrm_fb_request_footer *)&request->data[frames_size]; + + footer->unk_0c = cpu_to_le32(0xfffe); + footer->unk_1c = cpu_to_le32(0x80001); + footer->unk_34 = cpu_to_le32(0x80002); + footer->unk_4c = cpu_to_le32(0xffff); + footer->timestamp = cpu_to_le64(timestamp); + + ret = appletbdrm_send_request(adev, &request->header, request_size); + if (ret) + goto end_fb_cpu_access; + + ret = appletbdrm_read_response(adev, &response->header, sizeof(*response), + APPLETBDRM_MSG_UPDATE_COMPLETE); + if (ret) + goto end_fb_cpu_access; + + if (response->timestamp != footer->timestamp) { + drm_err(drm, "Response timestamp (%llu) doesn't match request timestamp (%llu)\n", + le64_to_cpu(response->timestamp), timestamp); + goto end_fb_cpu_access; + } + +end_fb_cpu_access: + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); +free_response: + kfree(response); +free_request: + kfree(request); + + return ret; +} + +static int appletbdrm_connector_helper_get_modes(struct drm_connector *connector) +{ + struct appletbdrm_device *adev = drm_to_adev(connector->dev); + + return drm_connector_helper_get_modes_fixed(connector, &adev->mode); +} + +static enum drm_mode_status appletbdrm_pipe_mode_valid(struct drm_simple_display_pipe *pipe, + const struct drm_display_mode *mode) +{ + struct drm_crtc *crtc = &pipe->crtc; + struct appletbdrm_device *adev = drm_to_adev(crtc->dev); + + return drm_crtc_helper_mode_valid_fixed(crtc, mode, &adev->mode); +} + +static void appletbdrm_pipe_disable(struct drm_simple_display_pipe *pipe) +{ + struct appletbdrm_device *adev = drm_to_adev(pipe->crtc.dev); + int idx; + + if (!drm_dev_enter(&adev->drm, &idx)) + return; + + appletbdrm_clear_display(adev); + + drm_dev_exit(idx); +} + +static void appletbdrm_pipe_update(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *old_state) +{ + struct drm_crtc *crtc = &pipe->crtc; + struct appletbdrm_device *adev = drm_to_adev(crtc->dev); + int idx; + + if (!crtc->state->active || !drm_dev_enter(&adev->drm, &idx)) + return; + + appletbdrm_flush_damage(adev, old_state, pipe->plane.state); + + drm_dev_exit(idx); +} + +static const u32 appletbdrm_formats[] = { + DRM_FORMAT_BGR888, + DRM_FORMAT_XRGB8888, /* emulated */ +}; + +static const struct drm_mode_config_funcs appletbdrm_mode_config_funcs = { + .fb_create = drm_gem_fb_create_with_dirty, + .atomic_check = drm_atomic_helper_check, + .atomic_commit = drm_atomic_helper_commit, +}; + +static const struct drm_connector_funcs appletbdrm_connector_funcs = { + .reset = drm_atomic_helper_connector_reset, + .destroy = drm_connector_cleanup, + .fill_modes = drm_helper_probe_single_connector_modes, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, +}; + +static const struct drm_connector_helper_funcs appletbdrm_connector_helper_funcs = { + .get_modes = appletbdrm_connector_helper_get_modes, +}; + +static const struct drm_simple_display_pipe_funcs appletbdrm_pipe_funcs = { + DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, + .update = appletbdrm_pipe_update, + .disable = appletbdrm_pipe_disable, + .mode_valid = appletbdrm_pipe_mode_valid, +}; + +DEFINE_DRM_GEM_FOPS(appletbdrm_drm_fops); + +static const struct drm_driver appletbdrm_drm_driver = { + DRM_GEM_SHMEM_DRIVER_OPS, + .name = "appletbdrm", + .desc = "Apple Touch Bar DRM Driver", + .date = "20230910", + .major = 1, + .minor = 0, + .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, + .fops = &appletbdrm_drm_fops, +}; + +static int appletbdrm_setup_mode_config(struct appletbdrm_device *adev) +{ + struct drm_connector *connector = &adev->connector; + struct drm_device *drm = &adev->drm; + struct device *dev = adev->dev; + int ret; + + ret = drmm_mode_config_init(drm); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize mode configuration\n"); + + /* + * The coordinate system used by the device is different from the + * coordinate system of the framebuffer in that the x and y axes are + * swapped, and that the y axis is inverted; so what the device reports + * as the height is actually the width of the framebuffer and vice + * versa + */ + drm->mode_config.min_width = 0; + drm->mode_config.min_height = 0; + drm->mode_config.max_width = max(adev->height, DRM_SHADOW_PLANE_MAX_WIDTH); + drm->mode_config.max_height = max(adev->width, DRM_SHADOW_PLANE_MAX_HEIGHT); + drm->mode_config.preferred_depth = APPLETBDRM_BITS_PER_PIXEL; + drm->mode_config.funcs = &appletbdrm_mode_config_funcs; + + adev->mode = (struct drm_display_mode) { + DRM_MODE_INIT(60, adev->height, adev->width, + DRM_MODE_RES_MM(adev->height, 218), + DRM_MODE_RES_MM(adev->width, 218)) + }; + + ret = drm_connector_init(drm, connector, + &appletbdrm_connector_funcs, DRM_MODE_CONNECTOR_USB); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize connector\n"); + + drm_connector_helper_add(connector, &appletbdrm_connector_helper_funcs); + + ret = drm_connector_set_panel_orientation(connector, + DRM_MODE_PANEL_ORIENTATION_RIGHT_UP); + if (ret) + return dev_err_probe(dev, ret, "Failed to set panel orientation\n"); + + connector->display_info.non_desktop = true; + ret = drm_object_property_set_value(&connector->base, + drm->mode_config.non_desktop_property, true); + if (ret) + return dev_err_probe(dev, ret, "Failed to set non-desktop property\n"); + + ret = drm_simple_display_pipe_init(drm, &adev->pipe, &appletbdrm_pipe_funcs, + appletbdrm_formats, ARRAY_SIZE(appletbdrm_formats), + NULL, &adev->connector); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize simple display pipe\n"); + + drm_plane_enable_fb_damage_clips(&adev->pipe.plane); + + drm_mode_config_reset(drm); + + ret = drm_dev_register(drm, 0); + if (ret) + return dev_err_probe(dev, ret, "Failed to register DRM device\n"); + + return 0; +} + +static int appletbdrm_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + struct usb_endpoint_descriptor *bulk_in, *bulk_out; + struct device *dev = &intf->dev; + struct appletbdrm_device *adev; + int ret; + + ret = usb_find_common_endpoints(intf->cur_altsetting, &bulk_in, &bulk_out, NULL, NULL); + if (ret) + return dev_err_probe(dev, ret, "Failed to find bulk endpoints\n"); + + adev = devm_drm_dev_alloc(dev, &appletbdrm_drm_driver, struct appletbdrm_device, drm); + if (IS_ERR(adev)) + return PTR_ERR(adev); + + adev->dev = dev; + adev->in_ep = bulk_in->bEndpointAddress; + adev->out_ep = bulk_out->bEndpointAddress; + + usb_set_intfdata(intf, adev); + + ret = appletbdrm_get_information(adev); + if (ret) + return dev_err_probe(dev, ret, "Failed to get display information\n"); + + ret = appletbdrm_signal_readiness(adev); + if (ret) + return dev_err_probe(dev, ret, "Failed to signal readiness\n"); + + ret = appletbdrm_clear_display(adev); + if (ret) + return dev_err_probe(dev, ret, "Failed to clear display\n"); + + return appletbdrm_setup_mode_config(adev); +} + +static void appletbdrm_disconnect(struct usb_interface *intf) +{ + struct appletbdrm_device *adev = usb_get_intfdata(intf); + struct drm_device *drm = &adev->drm; + + drm_dev_unplug(drm); + drm_atomic_helper_shutdown(drm); +} + +static void appletbdrm_shutdown(struct usb_interface *intf) +{ + struct appletbdrm_device *adev = usb_get_intfdata(intf); + + /* + * The framebuffer needs to be cleared on shutdown since its content + * persists across boots + */ + drm_atomic_helper_shutdown(&adev->drm); +} + +static const struct usb_device_id appletbdrm_usb_id_table[] = { + { USB_DEVICE_INTERFACE_CLASS(0x05ac, 0x8302, USB_CLASS_AUDIO_VIDEO) }, + {} +}; +MODULE_DEVICE_TABLE(usb, appletbdrm_usb_id_table); + +static struct usb_driver appletbdrm_usb_driver = { + .name = "appletbdrm", + .probe = appletbdrm_probe, + .disconnect = appletbdrm_disconnect, + .shutdown = appletbdrm_shutdown, + .id_table = appletbdrm_usb_id_table, +}; +module_usb_driver(appletbdrm_usb_driver); + +MODULE_AUTHOR("Kerem Karabay "); +MODULE_DESCRIPTION("Apple Touch Bar DRM Driver"); +MODULE_LICENSE("GPL");