From patchwork Tue Aug 6 13:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754964 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2091.outbound.protection.outlook.com [40.92.102.91]) (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 43D161D47AA; Tue, 6 Aug 2024 13:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.91 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952075; cv=fail; b=aqp7oNNh63VtOj2QkvCzB5RM2hDYZxtERC89VKKf2MK4VhWgsf3lhVSGQ+YZseof9v4LYrTOW47b0ysYxgvERi5WrbVneWskNbUp21ZaFt8jBKPQMKrFeXBfg3F0vG4vYqgRVWktuhvcx+7fjFl/n+SaJZNBkaBAnf7JPilSAJY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952075; c=relaxed/simple; bh=D0qLwSFECv9OWQd4m9QpT07h/bWMht6DoLCCCfEudIo=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=W0ULRAA2xUliZeG6a74U+57ugY/228r9sPfIur0N+oWQIQmhk+ThWsadwbPq3ON7EI5T9Q/xqHM98P75UVrhlbMf1nD7feV2BDLYOuyNIIzD/Furfs43ORqceIQQER81gtJ974wGBArgMU3ncpjQWjfnH0LE5JX8J46etKdsfI8= 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=jQFILm4O; arc=fail smtp.client-ip=40.92.102.91 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="jQFILm4O" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SfLffjqrs7SUdsM/uzeSfeH3zzgDv/kn+ZfyUSD1HdquZZqD6Fd6exyN5twjx4C5exC5DydXuJu4fKWDoWFZFPc1Idy1Cms41x4RI4T8GLBTNNpwtetDpNHILzzln7YWv4nDHPRRFn0JOWRd5cGzJrkolMFrwrp3AB/3zu9YhqLM5COhqK0PeWqixM8uXTM2C/M9EtYJ8Pzt+6NP33chyToQLuNGoBlxXGy6Xv0BgqFPNdSAEwqOHOzJrpvSHkxVVfyAOidZgT5JYhypPi0jpeQBqd/0keBsYO839sMDQcRzw158iBLWEm3fhEmAOpTVgvpfzkwy/NjoMIuB9bhIDw== 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=D0qLwSFECv9OWQd4m9QpT07h/bWMht6DoLCCCfEudIo=; b=JDNoe9ApzXjDE/513IwTaKZaktT/+BXWkSwPqN1b1++IhR8r4DVAuuvv9rYWh+50TjMkGUJSSQT83hOjw5vMZy1lj989WDnu7Gme95wLOKtzM6Yb3t+jWdGE7X9TWlw4zd4Fpx4qspem8XhnWmKFFcNmsk5QwUKFXnUbJrfHjvOS0dbAw9nvyhTPf8yumxLKp1MTArpRiqkNQz/IiWCOUSkpS1+PLpIeN1+IwgqVKjNlBKoHpQOqtbCnwM++sGlLWfRDty4mJixr1BEFUH9k3KW3DVdw2jnOGbHfXLnDyuXaFF+661iT0tfNh7Q1bHQNN5O7R+pRNbstj1T2liayEg== 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=D0qLwSFECv9OWQd4m9QpT07h/bWMht6DoLCCCfEudIo=; b=jQFILm4O684X20plKXTVhGQth+resJwDy+dSmPNtJCZmqyyKEBYCjYme7taOKd1/9rDbAjHB+G/VhirYHJeI2dC08BBhwvOSYxvn+y9ZA8euBc6DDEQNAbxzO/gxIpYQSdNQSqXdQQbHDXsS3h3CjhT6khb9ZkERTJ24s+V1zc48xw4o7ec8XXrfLS2eoqhhxK6OpcQmJmlZcBT0OEWHOQtZIU9l3T94D+uDcpS+ZYGLf194DMdWmDbgnjIUTZN3SFsfEkh4h3VEqVnq3qkZs7TV/tWiQ7JQ/r5ieI6Of4vcwm2Zt6hvxf7c7xyHOWsdGGB+AaYM82bhw8nP0CwTbQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB2100.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1bd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 13:47:47 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:47:47 +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 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHa6Ac4UNDG/AUcD0C1tqLHK7a9LA== Date: Tue, 6 Aug 2024 13:47:47 +0000 Message-ID: References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> In-Reply-To: <021EE0BF-93CA-4A37-863F-851078A0EFB7@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: [2zUQohJ4MxBHBE9+g8CYoYs4EIZ9Xfc0ki+t5l2Bw/SSgkJdUZypuKaayXR+y4n9VyfE9arLOzA=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB2100:EE_ x-ms-office365-filtering-correlation-id: df498a4e-873e-4fb9-f666-08dcb61e5b0e x-microsoft-antispam: BCL:0;ARA:14566002|19110799003|461199028|8060799006|102099032|3412199025|440099028; x-microsoft-antispam-message-info: K8FPzg8/28ktIIUtNm4dIGWjw83RIz5S4ttrfWrNe9siWOYZRTnGOUksOk2Fr5C6iso86b7ODQjE7Wk1p9inYuTtPcPP1ddvp6cl0JCibgGIgxagNMj56LGKadJBDtaf/kE6qxC5TEzTRxWoBS9MteLMUY/Fh4NK7iPHte2Qjww7u8tmG00AD9FLMxxs/3rxheEp3u3WpHSXxcJq8csnL6xPchK737XJjbX6HqzIZL2hGhmC8jx/KitKcCyC/Uddr0cFCr8rKFhHgH9rWG0raqumUgyfy4jTuCGLC5Hie2y7mpK4+AJRZTbvSCl8qXUx5z9pin88ckX25lzQGQoIMRhGHtIR7gHUfhTqAvXyJhkBncgi9mW6ITjGRG9qoeUzmnvRH0IkIRraqLw2rsZaa18VcSB/MCkHteqEJOOnm8LmgfDlRejXfKNC9/GPKm7BtFLj68q197X3dSVXHA/439hs5ZsBtbdoDNHEO7Qk4Jx4EHCn+LMoj4cpMzAwfbFQinl9lM4AqjMyafUW8GsvnHz2RRTZyzoNMA5hxqk3jex7hDvo6ByzMYONuMDAnSki+DV3gu71Hv6gW3xSeu9WObrXPdaXvJRhc/sfayCQCKpNBxXDROtkpjCHfvJ2rCKZSiu+Y/r+e4BRCDSccwmdnQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?T3bTlAI99p0xXuVI0tDDe3URGsvF?= =?utf-8?q?TFQ2Q9RlNcaMSITUHQQyv9jItnCE6NMtn6vkTPKkusFI+yjfvexbGvXEJ06l+r03z?= =?utf-8?q?GLedVw5wGkeQzCJYGKeRfsbzjP+bQFvbsiu1ZvOhkq9atqDzrMyb6+vzh2kyQ4Etq?= =?utf-8?q?lfy/V565raGBdpWz03AqnGULNHzhF6uY/iWX0ifin7l6mSmhFgViP4NRrv8GKQOIg?= =?utf-8?q?PD13rogWj8EWsbM5NAJ43brPrJ5kmjdNzAttkIoyo7dnj5ih3BrZ0rEBNePOH+hxC?= =?utf-8?q?CdqcnePGOFi1ubdJreKJXETSREfZaDiaHOKzA/0Ah1crnXwqycdbDs61P7K9PTNBk?= =?utf-8?q?rZhBe9Iny0tuPxKZIfoVDgSTez8CqEXMicx2/DmkG47k5flqc6l8yuhqmXVqlWIYt?= =?utf-8?q?FLDxpoTSMDT85swh+dFMrZ90QF6hQ7jy/pNtSsbr3Y6rFPvnnvVmd8QKQiDx5MNP4?= =?utf-8?q?gKI4UNtHDvmIMxNrhbW4ID9HICM7fL8PxGAMI/5q/DMvR1lVSMMnwvWlyV3+Bjoqg?= =?utf-8?q?jH6kTL7uAerqHHTIo/+LDR3JtHPJdSB1cFcoFNCLMvAKNwX1hZeYfeDVF09dpcB6k?= =?utf-8?q?BeAX3YbF3AnyWa2C+UasCXeRZNmms+36DZD4RRBx6rx+lYh3RsLbvv7WHafc/K9YL?= =?utf-8?q?WiUI27OE8UTVd+cDeX5NhtOY78Pfq35XUfzINBzPM4j+kFPNzT6jGYe1Pd96igvRn?= =?utf-8?q?nuh9mVkuTLMVVfPy6NclbVg0Ya2CJSVA8ucrIBdnrW9Sa7Y/+I2Rjoo/z/Dey6EM2?= =?utf-8?q?gqeNhRCQMHOys+djiUzRKd9pQhLsftjvwAxn5uZHWryrnkQuoRUYQ7hVe+DIMQ+3Z?= =?utf-8?q?jX8FjgsZc9cgq0CyU/dt4BYYc19YxFK3jdFmLua03PFyxCz1+EF+/iMfM96E57W9g?= =?utf-8?q?6XNFH4KsvfwWGEGmwJSHiAnZCUqX20yYGCBtMOQEQwXPNUL0x/t1oUsnMFR/+5c83?= =?utf-8?q?oWziHmzL07ewy1qa9ZsLd8zW3ZlswGppcngTrJJLg82LRChT0BffPrGTRpqa5Rvxu?= =?utf-8?q?2Dq18/GZL3dsPISSKYOh2k7jx/wBYwlAXSvzKBqIW0Th9KaT7bP1huSe2pK6/xfsK?= =?utf-8?q?mBhGVVPMgnvVm+ikZL+j69IxANa3/3s2d+hMKvIW9eT7/Pg91zfRBfIuu5WCs54BE?= =?utf-8?q?5Iokzn9nnpkKXdoP6YphXtbv5YI4Mh5btSgf4qwt9FVL7PaqD9Ti8yjlEl8dH8GhI?= =?utf-8?q?g8TlVsr6nyva/VVbb23r4hhN7NWIHbEwXyVtGhdT8En8xqwmWc1jrsTDfXhaUpwKf?= =?utf-8?q?lPnwOnCEIe6jFrzw?= Content-ID: <05972F7C98F80B429D4B08D13A95A251@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-4755-11-msonline-outlook-bafef.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: df498a4e-873e-4fb9-f666-08dcb61e5b0e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:47:47.2364 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB2100 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 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 Tue Aug 6 13:48:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754965 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2020.outbound.protection.outlook.com [40.92.103.20]) (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 AFACB1D47AD; Tue, 6 Aug 2024 13:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952121; cv=fail; b=EnqdOPu7kS9XcoPskzBJIZxAATjvaLxKTMgnRkAPRCxKoSKiiq9nPHwF383suPW/fOMArfsf4Xi33RMHVhNMQi0BQQZPAp8ZMI4Yw9d+vMumEYWJCUqFvsm7gLDduqhIsZruIk+4UfIIXmiJUHDSHUEUZpC3L0qehpJe6GFbjgk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952121; c=relaxed/simple; bh=HG++wVtj476OCPCePWPcbrLd5qAedkg3MeucG4l49xY=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=j+nddFSqxUCzmPS1a3Cazi7hLg2ujoXe1ydWBE/RLaLg3p8A/e5bq35Q/c3BahgeiLaQzq0hxyZ5w3mMibr44RlZDesWEfatGZjWi7x0MBsTy1v2xJMKAH15izRciVp5goobF6AbEMesaKPGPGjE3A+La83m9zedMQ/9x3u/xFM= 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=N6U3HYQg; arc=fail smtp.client-ip=40.92.103.20 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="N6U3HYQg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vykDZ0RHxpANR7M6TLrkp4m9pyfvMzMfAec0WorTyrXNo+fEyjeyKimlmaG+cMU4hOjvfNFgPMvPG0oxa1kiT4fBtISxpwJvhrENHYNpIUfTPdGTP8Y63fmjJy/Ba4qopMh0eDioWpzEwjUQTo6ZX3MOpfpsCSvP6YxgG21qO6b59IQnEYcJcu6RHelk+RLOB3DUsT+RBRqqFOcS1b1IKGLbVNAsSHxI1k4prtD5P1nLl8ePXHYZlkeqaULYYp2RJ5vl1FZ8m+MvTmaNyMqJpfmaOI6mneHAOJ5JG5KE4PsU3uxKCwfAZFpGQDETJkOStaEgn54Kl/DyRCgjPWHymA== 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=HG++wVtj476OCPCePWPcbrLd5qAedkg3MeucG4l49xY=; b=Go4EK8IfLmm1UbyMxITI+tCdqWKzyCIAyT3+Ykk+LNhqRAC+PoCAYNZhQOuGuJnsKj+w5PUuAG0baohq99hZHEzpSmDw3ub5XFZP2wcyBTT/Ag5pLiRqaTPNY7CyKpfog6hko2/BkY4vY8C0ycgmuWnLQs4MiJHXagyQYQfbRr9zU2UMyAN0Oq4HSgHfZC1tVfH93vr/EGYP02HOJFFwwGYl10LNH38yvCaHBOXelDZwPASgfu9YyDV5XL4nd3VbxSZ+TPydivO7TaKaWBj4dO4FVJIVUjG/dTdUTN6DrPnXlFrVWCNx+5O+h/6lvi3Kw3vNrV/b9FBW6NQCWTN6BA== 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=HG++wVtj476OCPCePWPcbrLd5qAedkg3MeucG4l49xY=; b=N6U3HYQgBmItxUVWMZnQG2B/dz4BRmgvbEwvgyz7z3AiOo1J2EXzMN/HwqDeRm+6bSP3xhEft4vMaIIOfk6GVIvJk3ah2pLBY0/eshXjZ9wZHJOkbyhbZ4OFdoDi7elNtD39QkWZYv76ktq46etNgmtNngY+iHF9K/taj9EmiZASvsIMMkqC/gCAqDor0pI7txhdhFi9Cj/MXfKR6Z6TdhGxW+AOZ6b0q/sooWwKnAbnhmBisfMbNVOUqU2LbJwwtagd+KZMP1ki/mtZRtMYHdRA8HAKgnsmiygBb/f+sOQF05aV0wjLUAWcSeKSfbAhml+GX3oxw8ozkqX1OD6aKw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB2100.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1bd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.27; Tue, 6 Aug 2024 13:48:29 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:48:29 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode of Apple Touch Bars Thread-Topic: [PATCH 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode of Apple Touch Bars Thread-Index: AQHa6AdRwVs1e1moeUWOBwJtJvK1KQ== Date: Tue, 6 Aug 2024 13:48:29 +0000 Message-ID: References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> In-Reply-To: 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: [WqQ/kCvcNTSp3KOdrNDhkim9o+QlbQpKE8vU7mK7VBsVL+HKw05zObbuLRfzX0rfWa21lZgxkx8=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB2100:EE_ x-ms-office365-filtering-correlation-id: c8e9bb38-13bc-4392-48a6-08dcb61e7421 x-microsoft-antispam: BCL:0;ARA:14566002|19110799003|461199028|8060799006|102099032|3412199025|440099028|1710799026; x-microsoft-antispam-message-info: zFDR/PuiAZ2ffT9srWxpTtS3Fn/gWYvPftpHEqsCd6ERxd4u68/fE+yT4ncD/avbb1sAGOZtuMgTVZ6oVt9YCwoIKGtfrj6jvSPk334Pqlve6ku3fRep0yYN8J6vz22/EHrhH9tI/NxSHXn2TehgKNAq+Bh8CcSifCrceDcM1klciGaCQGy8L0eIyP/nYpe+cYEGgw01WgcYVsluuAlSFi36wiwjvBqU1o1egARaVgXKEBlDrGkhrNJX0t/qtTtUkdYwqOMXxmCFxELQQCJdcr92IOFr3VrlyLpcSu/EeF+O6M4OAoyPUDIM4w+NUaOwBM9YCcZ2CqvoXI9eJbXeEq485Al4Lnh28bs5Zb1aepkswS8jzMPao6QJemhOWg3UlU5PRh7U+SGn+0t9kU9WY1fbp21p+tid7NPi/MqCzG565ilS1RwCJlRxu+Obf11GE1yxXN5gYN9o3eTtLKzqAMSGHDUoMBRICjFE2dhvlHyeN7Pnhf9Mih3pCpsyonKm8pMUBNveCoP8AITQJ3BIMx2WWgEzG9AFu2FdYQssWoibX8wg0sm1RIY6cOpbJRlfVShQ7VGlCPelOABF5keETKe/zH8yCzIJx7jVnbmcYb7G/OiT8/8ouu1Bz5MfeN+pCcyigwW16ZYiR5qwbHfO9TG1R7y8OeOkGnZMexa2wbQ= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?dSbxl46keGI9gvXtUjFebI+yvtJF?= =?utf-8?q?00Gc8wO0Bz9kCsg5okTw8CusHDPlbwKh3WeHAluYOGGGIQp+wRMI/Xexe1PLkKsg5?= =?utf-8?q?MM/GAdJImzs2xVSOUNuxW+vOJcggG+4q9SJLsPs6W113kpeqbpPrLQ1vBIcysyHIj?= =?utf-8?q?5dCGxRaae45Fl3+ENYL1pjl1/Y9ldvYI82TnvUYdZ5Y+4qWyGZpP3NFlrOQ6jlab6?= =?utf-8?q?3bbX+GrouWhaUaO3WITsLjA/QBEvkzcrRSVrJ+39qlleKMoY0zUu1k5PdFfK+P2qv?= =?utf-8?q?0x4vIr696ELOp4cvxrYyhnw2YEOay4pxtz0FnyOD+jXeMrISQ0e4clNg9baknqWkK?= =?utf-8?q?4iQBCE4lGyZ2ZPoLui1Ua5yFZBWsHPbgixr37YkDrNeHXJ4V7tTuoDlu5wK9fNckf?= =?utf-8?q?Tf5T7PruZy5cTvVc8jKOcbY/mWQszTfOulBUaEWMs6xegonoSXG2YSHy79hvlYdRy?= =?utf-8?q?a761jIof0JwudtuBxpyjqYa5LHT2RvwpUGnkBTsIPxcHHBQaLnzIpDwMm3SOvnDnP?= =?utf-8?q?GrWfcIpmk/9zjF5VhjzGcEDmxbCH73JK1z3XCk2BQyvCNZP1Md2SYUbPOzljX6sqd?= =?utf-8?q?KRDnmd5ooIZ4CosfOOl4pTZ4p2rUNmv8S+GCF+fbUbt6ZI+vpZKBn0FxgxQGAzRL0?= =?utf-8?q?ShzhQ2LjwsBfxvPdJNo332kBiTZaaFEkSIlRC0uvScvAyzTr3661sGwb/+Q41lcP5?= =?utf-8?q?lPttZbAmBtp+swhiJs1JjgRkYr8SKI2ZcmXf3RAXk5Floh3O6QMZp8Fy+UCiNOc8i?= =?utf-8?q?LMoHGXAZVNBvaATTqN5Ax4+1XAQvoHmhQfiQ8lhugj9kfwg3MMi0ULSQv3kI7/wtI?= =?utf-8?q?/ONix0AizC9ioTkJ0PkYm9j4Z3YrTL2C2g9LZ71THXtCO3zpz9C8upeTUwYpSFTYi?= =?utf-8?q?b8b/8GAXV5MsoRQbNyoWlPCUxEQo+j8Rd8TCPewGfkdcK5NKNdn0s/IERH5i4n3Qe?= =?utf-8?q?pfFQMQ1eEqYekOJMplljNPvOFraAtLtv9sefSpNrWoOrbKc19Q5uFBMesJIqjieT0?= =?utf-8?q?wmUxkGso5Ysp9GJfOl/yh+33tcr5/TnFjpzI+N/Bt/cxaAFDVJ/KLhIJUD6kJyq2o?= =?utf-8?q?hif6WbN8nyLxDGdvPWEYnQGVf8OdFlifHNjjbyheJHOBPlTLqk+vvP8a32xwBiwl8?= =?utf-8?q?GI0u1k3jaYDdeK/rN2lTnFZuTawe/MV8Yig5D1zN2a/sY1VAUAXR0et1OWpjChgcW?= =?utf-8?q?aDczZwHNjrKj1JLKmzGsESBIUu4GMvBRSNfaeuyHrMHnwE2bjdGFj6aUdiLj8BC+r?= =?utf-8?q?DiV8T/G0nT6d5uMI?= Content-ID: <0CFAD6A09D42CD45A7E9C6B16F5C79B4@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-4755-11-msonline-outlook-bafef.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: c8e9bb38-13bc-4392-48a6-08dcb61e7421 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:48:29.3281 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB2100 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 | 316 ++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 5 files changed, 344 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..453d5c7e1 --- /dev/null +++ b/drivers/hid/hid-appletb-kbd.c @@ -0,0 +1,316 @@ +// 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 const struct key_entry appletb_kbd_keymap_fn[] = { + { KE_KEY, KEY_ESC, { KEY_ESC } }, + { KE_KEY, KEY_F1, { KEY_F1 } }, + { KE_KEY, KEY_F2, { KEY_F2 } }, + { KE_KEY, KEY_F3, { KEY_F3 } }, + { KE_KEY, KEY_F4, { KEY_F4 } }, + { KE_KEY, KEY_F5, { KEY_F5 } }, + { KE_KEY, KEY_F6, { KEY_F6 } }, + { KE_KEY, KEY_F7, { KEY_F7 } }, + { KE_KEY, KEY_F8, { KEY_F8 } }, + { KE_KEY, KEY_F9, { KEY_F9 } }, + { KE_KEY, KEY_F10, { KEY_F10 } }, + { KE_KEY, KEY_F11, { KEY_F11 } }, + { KE_KEY, KEY_F12, { KEY_F12 } }, + { 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_fn, NULL); + sparse_keymap_setup(input, appletb_kbd_keymap_spcl, NULL); + 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 Tue Aug 6 13:49: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: 13754966 X-Patchwork-Delegate: jikos@jikos.cz Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2036.outbound.protection.outlook.com [40.92.103.36]) (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 7876A1D47A2; Tue, 6 Aug 2024 13:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952192; cv=fail; b=VdIUSpP/Cz1EH8+QvQbJ1dJupSRaJwr/hUs0Wu5srTDUlxS2BYfcz12uv6t2ZgT3Js+wryuj9ieOvikr0TjqeQWVHDTdsMVUfSU/e9BtV48z2AHPVxHY3MYuosXxSRdOAGLmJM+dhuF7RDxNYHgxCTxgEXz6ZOutJvLU4NeKnGQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952192; c=relaxed/simple; bh=D00Gce7316VLUbOKRXehS00hoLKGw4I/91lXDdj9C+k=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=YhIxee3Fa1gKik6Osn00IJZSw/bqerKSiXFwSopSzvoT+PYXIsjLMlnFoEHjdfn+DTMLxW3m7upNw2yCox/LxzpRvpb4A1tnY3ECbVtW3MQ63oLLHFCMUNMNGDSMXOsKj2lUJ9J0/fpjsoMp5TTt+6/DpjeqevzuTHRrIVYAZOo= 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=Mi3ovq96; arc=fail smtp.client-ip=40.92.103.36 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="Mi3ovq96" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NnPSWbUV0hszmPk9CA2LxTakjKCbLJ/mYEaUem6qwY/Kuj5elLNHFMWeo3AKBQN1U3ydAb8/6npRSeaVXiwvi5zmxQcHrgg+cIxXw1NXcUREtcWLcEDQxXjWpbomw3ewbjZQlRA9OD9tW2YdpRjSKw1TwrybmW71FsCH6eRM3lb8+f8sitHVA6XiE2X9IhgBXR6Qb7G8pY7ySuWXjhLYYf0VJzzpsld7wyaUlG8c3syYPw8wvfi5S2i6w6PYv4Q5XtNBjaannebsr3LKZhaL3Af8xDMM7HwMk9w/1yGnkFsPkxyeFdGjQlqGwHv8I39qOA5oj8O8/9GwUj7efflY7w== 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=LYljV6lQyR/DvSjvEVVSS69P9uNf1effmU5txH9sWMA=; b=g7Z22adZLB1R6S+CxSuRcFhb4k47dSGND8kn0Dj9DzKq8QNguFBsN57KtJjAZ0wmeTv7dqJPks2LIczszp25lHGyxd1pVR22OAGFPzkNGztjUqlNrWsHK6soKoj6oPouZvjuvwmJ+AuAabDCAR/LpSk1eXyUa3CyCVYvH07EPKnWOM6PyCWtufgywPGks1tmXqn13D+2ZTtprfHZceLkGKlJKGUXIYjCU75iUiC/UOBf9dcQVYUvMu3ZwRBVZZ0s81DHxEDxpnuj6B28EPvt6gP2aeHMft+ui4GLUbKNIOqj/8GfngpQPIvwiMLOmWBZhWGK0cMEKOQdd2/DuNMTdw== 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=LYljV6lQyR/DvSjvEVVSS69P9uNf1effmU5txH9sWMA=; b=Mi3ovq96UklNGgqpKoRgL88P/WcedwkU3LDdXGEsC0+hS9QKaRvkQd8K2mX+zYkzuWX9GayEC75FN83Vn4UJuK0sRksL/CoK1tsmtk1byuYed2wUqMO/HPBuaq0LI6/7snCij0adD320fT9eR0WVkoXxClyaddytoCEzHjWZ/jmOaR4nLPKXnUo1/8HEUBrvVszbVqk2wtO2IhyHorJKvtTWTHL8GFFrJr9CBolAOUABVM9BdJrcfGKehTlnUgHoCuxTvkeTu/8XuCuhMB4+7RudfpejzpcsYzcKk5eF9CoG7azXzCoJsSR+J6t1xk+Q29X0A7A/HMjl0JarcIPp/A== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1708.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:fe::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:49: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%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:49:43 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Topic: [PATCH 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Index: AQHa6Ad9lUj4/NPxr0mlo/9wuQYrdg== Date: Tue, 6 Aug 2024 13:49:43 +0000 Message-ID: <9223E804-286F-4692-9726-2306361F1909@live.com> References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> In-Reply-To: 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: [j8b33ClWdm9egTSHGKFdho7XMt/KZVoeZDo1B9PP/inH5Nn2V+HlAHPqBHYApBkd7NTQXlYBs5M=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1708:EE_ x-ms-office365-filtering-correlation-id: 264465bc-39df-4923-5541-08dcb61ea04b x-microsoft-antispam: BCL:0;ARA:14566002|8060799006|461199028|19110799003|3412199025|440099028|102099032|1710799026; x-microsoft-antispam-message-info: FRAdsXC38QTpjeKtv04dEdLr4mEATh4Ij2CUm6tKJoaLJ31Mut0DVcC8xb9OR1bUPUK026gnX4Bl/IEigkyPKaShY9HB5b2P/QT2K72vAfn8XMil16qao3r1IWmUIp7+lOJzPwZAmTHlQJ9sM94UXSrdaOMwxCU/XNcSMP8kiz/NFQILB9B1EvUJ6KaoldW5vZ5vT7F9IykFN8HHisnGa9/PVff7c4AnEbJQz+ahyDia2w8Cittb/IF570xevP8s5URfYsDoBDgTAN2HF7PsoiWfNvBJiIeeAmhvOD0SRhw3GjqIu2aeWZVPwfbDmOxd6Ahu0fOHX/Nkxs60HqDqCMZfkqfQl00+Dr0y2M8ZaKPk56HkpoCVpKVJDQk9kiia/0Rgfs4hozGGZhi5e5mg2Y8grFfRGaWAX2eiZGko0cLUg+DMY6SyscZooF6NsFz5OMWvORI3z9KrO3jWdI6Hs7G4JAWlDyP3udoBQpQ4YQnjwnS+1Mi9oC15xmxduNhLDOeD06JeTB6OyDVfRqCs0uP92cOHG2+1W3FWGuxzp8n0zEPHz7UDF2QT7Y48TIQI16OkOiIKTg8GdhrJVpoQTnN2MBjLTPkri2ylCqAjWE+gkfZggh5m7B6o9AAytyIkZkrf2JwVtieV0AXtHGeMU2iCYQMLeVOVrS1gMY48vR0OuweGcQvpKLLQUNj0vIeH x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: mTx35u3Qj33nVNaf2sigmKnOoGZXPmQX48rLVH3AC7KHrpMIwK+MJOcTXxfz/+6UjwBrpK0w+OgCUJ8U7qpfLhylSz/SEj8BOZvpVIn2BnHRcjscjUFiUfoY/qN+xHRcpfsPU5IuY2oVuiB7wiBL+zk0nk7MrHZOWrXUKtQ5ryfj6tU5GteNZLu11/gNOtHX5KiOeKhfnfXxl/gQh69tFeMSkkLnj930DKDglHLSBt8XZdH97q8Y1Gat1ilLePnSI+wG65SfuvFjZP83CvTgfDKY1NbspF183YlGl3hrzX4LaQkUv8TCdFR1G2Zq1OkUEciCGsBUZZY88VRlKRFwhRRVFy52SIPPOxEp7mHC9X/lYSNqcFf1h59u3afyOdcvSeJRO7JxIEjxS0qm6+eBUSISmVpxI1VmovmHRDpiq2mtBh4mx7AHJ0pgFXAOlsaoUDCFhkGKQisXMkuaBPBlyhySRrOIh9hhttC/8/8mr/8ZpdsuLL7hNx7CYUJBQdb2VLWBdCtOVmtUQyjTXSNNr511qYPaEhKrC5VanYVds5+RoSGtLouDcDEAsgN/HxL8Uo+YMcYJUN37cUh7A+8KnGtWPCU3zx0vBKiyHIdC4QRbp7howYu3NqzgZNIeKfNV9nXxH0ZiI5ZO0KLkz4lebznDENfXa1s/H7PMgM+/I3O6XdDG7LyoZqeZsrxm5w3VMasiCB1nu4ncToZmG4661n4AhNNoHuYkgMDVdN/OYMk0BNUDOmrtNLO2/hwGCVboC9BS1KPryywS9g6qlohVJdYhy9khuHiAqmdoJYvQJP07WTiSGVhuEus6xtk56MDs3DiZBCkZQFJ433AdBv4GCA/pDOUIALKVfcDOrgDy6humTR6EB0yIZosEjlkc7ylQ7P5PXzi41ywsjUh2+i7QWaj7qkLl4pR0Alg13/KlnUalwsQc1fBHa2mg6Vy3EHGNG+8pdm1ckrZy71znmMGQK7pl2GLTAuDwCthQAYsmzX1uON+7Lbs9ALMzeu934FNoHFBM+Iu1eQDUot/qtrYyRQEqpPSRoZgs0qp7YYNBCcZMKSmnCI+KcPpkYkwPZJ8/BBJAb/I3x4rT96gqshAJirUkbyApQE79swccbjeT6FHsoNvOUt0y/HU4+aPtH16v8YBHLzRW11QO5DcbhkNTax3XYpgGwHp21IJVS3wd8241ou5gH9vdZFRhF9vGpPG/ZRt8iSGxNYPujdLxBl8i2KUQx6K3Lt+mNg8Kqha7tPWUoBDsGu3L7+5f/+tifgsPD4iiRuS/8Q4fdgk7/SxV985gcWIk5E5xpDTwNmPvwcJrYGz3cAGaZyoEs4XHlre3 Content-ID: <1B5FF40860AF644C95C402CBE841999D@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-4755-11-msonline-outlook-bafef.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: 264465bc-39df-4923-5541-08dcb61ea04b X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:49:43.4208 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1708 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 Co-developed-by: Aditya Garg 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 Tue Aug 6 13:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754967 X-Patchwork-Delegate: jikos@jikos.cz Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2039.outbound.protection.outlook.com [40.92.103.39]) (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 D7D281D2F40; Tue, 6 Aug 2024 13:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952254; cv=fail; b=MMmUHFEQGGkFaSGsUTWqj5GWDsnrylCBP8dtpcAy2SDMnK7fLM8PNNngkCUntz0lCJcl7i6rs0oJ4oCLNX0Sd2ds+fkr63MnbCIYrOPeufRzeH7E2UsTgqQfIuncCjkCfG7HmKX2YZBUoCMiO/iUtRCnLapdDbP5pTfKjnQbW+A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952254; c=relaxed/simple; bh=Dh7ljb8d1FIk9yN7/+oa+AyXM21NVwE0NDEBbkhNouk=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=rWUo9uL/Qlf4R97roL3PWvEL9a/D2qqtYcnBcODjS13hWOMXWqj4FSrx1a4UR0LQqipGjoG5WjRlvcbBPNyG9iqrN1PpvDa5NsQ/f+f29u2WhPSyDQvTB9jalWyf8OIRbo8MacXPon8pUR+1KTrxnVQHijxqRqRtnQsTjLimv8o= 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=aAwZHa9r; arc=fail smtp.client-ip=40.92.103.39 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="aAwZHa9r" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pq+DobrnypoU1Vm3TtAq5RxG4gzboeGyJNTcdxXZXB5KahsmWNLsEOsmJrS203ZG15xooSOxXmHlOZSD+gmonpNV4TLg+70OXy7JrV/CSYohrP85cRjRYL29be2YrGtUYJGLp5nml66LTk9RMqFWDEMcKirAncflnqlWSg+283scM3w9OIQhvKelO9AojsDJb3iUyMtXuIpVk+l1IiHYNPAHaulcByaJ459E1SQhIiBuZjlLtKm62skyb/kEQbc0Yd0M+Gue5b5ROd3vQ2ZEboCCQBRVhe/dFZNX/PiM9zlpYxzxCpFpZhJ54BFB+jOYd2M1zH1U47GA/xQg4PdA+w== 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=RoSZyiqImFZSicR28oGP/RkEpGdNrnqOstKFEqFyhjY=; b=HcOxzZNMjDTq850ysVToAjfbnz4Q+AWhznO8SXtQaO0DfmTKOFntkALJX/ch4qNsHWKnYsQAdqPcfJSrnL+kG2HZurWAfhniY1gx/Tm5V6caweSwY/+PPAFbkYq1n06H23x14RgLc197WcM6bVYoNk2Yp+SXu4EFMmz4kvNO0/dZV+zoyVsXokDj9EjZewS7yFD7M7gxUZQ3xDsrHzG+A9OOCVrCBOn4KzdPuTnk/pR7kN6n1TquJmtEn04t02iYtzqkj5XMwzCDGD+Erit3s4o2Z6CixnfdWjKadpJuvpidpAKdTf+IT2qjecDqDSHTImEgSynWbhZcF8KWdSZ7rw== 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=RoSZyiqImFZSicR28oGP/RkEpGdNrnqOstKFEqFyhjY=; b=aAwZHa9ri5yjwbIN0QN57nJX6tGycmOqlXvXcxR3RtODt931l1NtiJo6v79TtVlYOnFSmnwKvKBGz+8sWFNhqWXVCcedItnJKsGAJntnmGMGbmhkbNQGbkl44A4ztzn9qOzeeaxztvS2DZ2I34Ys35xyTazV0NZUcHgVCE1fH/streCWbxW0v/CTuGuxS2qiG4PA0/79Kfxj1Pu60DdCQRUF9PX2Att/20S254fLOI+dCSQ71fRJbYLbCRYadfOjSGHu5LK1sh1FaEFTHG9m34fpDkSAMJc1OEApPBqM2QeLyGXVFHbsZ9nY/jraTSMrU7xy3f1XiOqJd11lPT8q5w== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1708.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:fe::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:50:39 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:50:38 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Topic: [PATCH 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Index: AQHa6AeeXBJahpnuhEq1a4HCAw3vOQ== Date: Tue, 6 Aug 2024 13:50:38 +0000 Message-ID: References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> In-Reply-To: <9223E804-286F-4692-9726-2306361F1909@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: [qBoi9aXREk8BqN3mMR8yQAuXg6RcGVtmUftgrMebj8ejW3s2q5732i5P+hSox22rDrvg2eywggo=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1708:EE_ x-ms-office365-filtering-correlation-id: 8523e7e6-eacc-49dd-3a87-08dcb61ec154 x-microsoft-antispam: BCL:0;ARA:14566002|8060799006|461199028|19110799003|3412199025|440099028|102099032|1710799026; x-microsoft-antispam-message-info: IXBBw4NinoBT8kVU50EdQVQebVTHP7ircpVolXnjT0orzeTWKiKCQo1ratFDUiVNdizOnNNYnvK8X94ExooNG8tZsW/C8WJHoTf3sDbnLfSkV2hJPk/npa0i+frnitS3OOcGSYpWhVstbSLTGUeNHLJry8wwxXwQTwaBKKwuSnluG8jVwctqZoKgkFeW5ZgvEjNHbB56dY2+dxCyK6bKBnsqqRQLnC72mzZLC9/AUAKGVHtkBX9GEX4qqleo8zp0rpkFetokjBT8lYdNS8HWIrkG6JSwyskJx9ilps4K2OC4p1n6E2blQNKNG9leqmhVXjSbCtXKaiMsh+uyIMpMsSavzbIhQFzaV30+HVH55P3vCplt4vpbv+5wfGLbMGaDMSJnn6HowWrzeQk/hsdoJI9gUaIM5SrZTrXJ+Ufa0xZamxPJ+2aVeDt4z6k4ObbL05uK6iFljj21XkBgBrAP3giojVxG+M+B7Z13O9GTkuoipGHkI54PGN8ZC2YRb3q2uL1tCRwPUFLQ3cUyQygKEhU4X6Gvqu/pzf++EHKxY14NGFFD4eqFn6Xh/33qAyVuKktDAsdjYKA1T1Yt2VDRHP68CSKALIH2UtQx2WKfjzBIhSdEdckEW+EDK/aGphgmTGZlJeUNJh8xhsI70JrFPDDl/CoTBWQLLrd/LXX0VshComYZY/rCLZ/fnouu0oJ8 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 60E6KDhPygqBGbIfckeL2cmCCYBkDY7pQPvsOQ5AzjU8bp1V1ZXngklfQjjfXrgsE0YdlQt2tRVnJs93hQPMPm89c4MhfUl7LRmHJmESzvM0JIjnAEg8RDy75DoXLI5xKTnON+bBwQf7VDZspILljxeg/zaeXmllD8areVVo7L5RoEef55xcpijbkqihhxEQ6KW7ld06biygCddEulJp4unrFCRiNPZ18VQrioxsLEN5+sOsYPwyRKXg9+1JH7/aQRTbbxEZxyV+rZOwT/+HbZDLtyFn0bswKZpNIeLtRa05VMQzb279Qf1qbbz3BgJXLA+Ulhltv36w48rq6L3xyVJZraTBmqUpZa6wJBQsE57cGPdBHjFepsuofGEM8cApld7/90v+4euJqWxYeaz5/NUx1VqY9RFUp2nyp1nNTDL6VbWat/1eZIsIZTJY4zU4hKy/3fErnSTnMZvBuKDmjyWZd6E8LWXkpW5DsSpnkioihJL7i1s3ZjeZrhtJ8IACciVbfVYQAkEe5GK9ZA/M+QWtrUlyH8jEGX0WuZ9xFoxDYpzVHLPzQcfYlUx7OaKcrLwq3zQr6JMyyXCBqKs3VZlIR3dINddhIzgbbgNnPi7C5dNMoBfF6CJPcg79nlSPUK5hEjPhivtDBZTnQHsUfbTwiHexKzwfopPWfUSh2hruCKqt3gR2xfmjwcnnVZvsnwyPFzvq/DlPfR/mf4TrZgtnDpSvpYQNUJMorBzz7hAw8cynWQoecX99s1e6yUWiTYmfsShaWE5hiot3g0h0GXL1VV8erl4ELIfZHx7VCVrqPnCgD/wcb0PZeClxWKeJtGaGytGDKL2avlhFQ07EnVAJ7RfD6lg9co6cg6eJtHI+qOSpeB2C/5oSlFDiWoc7VgzHoOmdEOE6wofyIqwIdPhWqDcRFO66H9cm59gVjaHy9OUeV1HsM7pHV+6MUK3ZZxhtXlMWAsAOixgOyIdGRAEMesOx/xACPK2N19NIhzfgthcCoGfqwEiPsHJ0G1ng1PRTgSGaio9dmBGMbVCAH4qVlekBPALyCg8qU/yCLVsoWexGYzGWWZhbcrbTMERmb/FCArvF25Vl4AT/73PLywLEnJcprsCZOsNvQazw4hizP8Qxl2+YPgAgFnKw8oFkukF7n4wBfnAPE/mIMSGolkV5425YyoQuwY+l0iy6NRwzHiJp2S79iDKVEp0IqJSXC5V2uClSMBDJK1r2DLttF8md/jHZ5y3xJNwliAmsoA4bBdRxzUExL+IKxjkyTk8UkToAllma4omGIq3Qw8urgG57l/wCeA8lIKDrDbqDPtFfKBto0DLdwYTOadNuNv9a 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-4755-11-msonline-outlook-bafef.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: 8523e7e6-eacc-49dd-3a87-08dcb61ec154 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:50:38.8527 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1708 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 Tue Aug 6 13:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754968 X-Patchwork-Delegate: jikos@jikos.cz Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2102.outbound.protection.outlook.com [40.92.102.102]) (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 741D81D47C5; Tue, 6 Aug 2024 13:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.102 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952298; cv=fail; b=lZhGlzRzs3/ui16akFSsU8LZAtgTZIWp5nArq8fPHToWX+iltlplSFXLLncB5wrA5Z7DulSAbAyBnjQPhuwQHoXE8p4hqCiqiBYIdCe8VOHwEYc2oZzBke/I504i5yWoswCXT0rJcENq+NrOcIODodXgjyahkJOGpzJcKUUZsQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952298; c=relaxed/simple; bh=DSIn0rCuzaMxDHKXX705h12J8fR+BBIGU0iKhvR3YOs=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=jFCipF4d7pcsk+Kcl2bdMTxRcwgNUzPfJ/udOy7qYKglsGwM0UcW84JTja/w+m3ZzscVn4l/E7R4BqfKkszOWPta28EAPBKmcfM5duihAnJbJX4qvscl5Rl3atEZjo+VD3d+SCZQfuAMiXCm9ycLb3w7XEu0sXgH55h7EEJdpYU= 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=ZQiHBpfy; arc=fail smtp.client-ip=40.92.102.102 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="ZQiHBpfy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uBaZfmIhAfOlnH28Pme6QwttPvaxeHE/jhC20Bz4VhUvDb2T+FzYIHZJi9ASPHutvh2djrMVt5i1ZmKJrDMop99c8QtgeIQEucgCS00cTRxoBc9w+g73/ImCTnAerxB1RfGe2/PqNpd+Ii5UlJ4fyAF2LRt8e2Ffko8o8AOB+c3/3+ytFe0l2Tf3GPvHouddsYjiL9lsy4mUjzD7OvipjOM7LGaKtjnbXYIsWPza6wi9qRRmtBlZ57N5q0PuTnhrKNev5+eTWPTc8Vp3KjX2+0Y0PetfHIaP4ZUM0um06LBp3JnvtJKI1AE902nMsdLpfsiC0p3OgzZEqOXPkZvTrQ== 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=myY17nFmSwRYTFKqjQNWGfiM/kNxDYUsRpGSdEJLqhY=; b=J3H+1PAelmH3RLaDFEuokOKQkF48/Q2pHWa8NO4F34nXcdRB8JAq47K/91l6V0133dbXVqXVNvu+WJC+QBY7sYwLOKP3ppxMZ/zyLtch8GqNG06KF8t7D5zglNBj7BiF/sTHjPMWrDaH2ABBvkBc9ZaWx06fiTLAG0w6i8MtKKYDVKz2NhEUOc/DXXH4Xakb1T34e2j9n65QcH9nNwRNSthO7xKQIiaUhr2wtnBuqpsIYTA30FyIDlJNFuXbow/LiMvkisAA44Ecp5VOgC6l639HNTa5lcvg18Bxg9hCMDgbOTvZFFVP1Ft4SoLGbzBNebLPmUKpWoLMAxaHKu9H5Q== 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=myY17nFmSwRYTFKqjQNWGfiM/kNxDYUsRpGSdEJLqhY=; b=ZQiHBpfyi2EzFF3N83nlXJE0SydzK1od/cYDIjoHADui3Dh8E4FUwyNNCO66NqMFmi2dnYsaFZMJ43QCNrjhZM/PexGE7dNXXJdD5hRRZorZ5zQl8PGeZtdBOk1K9RcM4JfAXUn1ilO5S4CYcyJVlraMqRoVvvs7V1ULV86wfFGXkLTcwJTmiK3vNzpBwcsL4LJG/Smml4QffNmEz2elJ8UHkj5vC63yquF163VuTc9iGvTDd9cUkFayxqIKWPYRD1OLZ6KvHJsABkjWerfKit53qvdZmhBvEq1ETnBNVVJ62pv6Z+OmSCv6DofuivGj0IPBsqd5AFoF1qs72o+QlQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB1046.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:139::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:51:30 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:51:30 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Topic: [PATCH 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Index: AQHa6Ae9lThwy2qR6ES/p9QYwNVDxw== Date: Tue, 6 Aug 2024 13:51:30 +0000 Message-ID: References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> In-Reply-To: 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: [ME6FHIqE93f3ulqQe1URnSohVGDukH1UIXhoGLEliZfxBIWzYIwlKSobRwdfpNU/bjO7uj9axPw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB1046:EE_ x-ms-office365-filtering-correlation-id: 4efbd294-8adb-4a40-f1e8-08dcb61edff5 x-microsoft-antispam: BCL:0;ARA:14566002|19110799003|461199028|8060799006|102099032|3412199025|440099028|1710799026; x-microsoft-antispam-message-info: LYS2b7Yza0fDIyz7thDkNSiKAOFWevibpyg4qa5yOqsdRoksS78Ba17s7dOuWcK0fiSVC1mQGNFQ07zY68eM3WZfqidCLdZnP1KK2JYZE3SSOAJ7A4QrQhIhVrY0Z4toU1TJTI0+eqTkN3vwZ9UVjawDYLlcIkACCP/6KPZSTku9QHLpO2JeweuEwG6nQgCMayqdex4lYRokGhiciIyjHApJXXP6iwXOExwwfADcqDg1pechm3A00nmqAo36ttUMJ581vl9mQT0PszaDNpQQGl1RfxXVEmLNhYRxBiWvHTSUAseyZJs91lUuV4ZVmeId714QksgmY1m8pTB3o96/lSkM/qJhJvU6/fs8jxZhMamvrNfVN6nRRuORZK1SVYDdYEEYIxMbJRrTSMGLRTVbphVzSrms7DPz3daljEU29SU4sANnur4j0msAA3lmOXKfDzH87oy8tfL7R21SFKFXhPDOMYWsvnpwIK3Tk8fPO4Xgh0KCj/MmLCvACGaHszuzXwPMA0j4kQ5ALpLJg1n6noW4cP5Rc73E60kEG55mX1h04vULbapcTrecEQCM6l7znmDDL5qDKsPqcBjE8aEBm2qrU1/PX7nTMxg1kXrlUAUdxtY1kPL5cz1jwaZqfZdsE0kDe50SMHlgIMRmcfqzG8z4fbKOrdi+gaHhMWN4iZDJSR+XjQNNqjhVr26p6oyl x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: OQ8nq2jyO+IZipT3jX4HYaoScS6RkzhycgbT5knfy5487g9y5PquPEfFbBRWzgRYvpQq5BQrOxwcOkz9p70eqzqSR9+s6qmVf6pWkmiOLoZ0JnCa8/HBs1FipEkAr/WViUk0/btHPkr7eaexuKD97d74pAj4pYqDXHlWNrhviVHbFsOKVv/6o2zWiXNe6VwPfgfC17lai7iziFpVEDgimaZRm0o4KL6rIoJ4EM5CErh5ejsfvwd7NCgvhzj7G7p/AUY1hkNSHKAd8cMFHPFhyyeFY1r+6/KnUl3kq3NqeyTJNNo0/bJdNZeb5nS6vOWogxdc6n5zE02yLPO2r68ZNzzoYFhJeDFDjA0XutI3s67PhuXh5ym5lGRkUQBkEKpRNae6tXRethA5v/i6ipJJp/ZeZNqrXZK8kOj2mmjB7Xnk2GrfC5kKFRDIu9/C2OaSBKC51VU0XirLDN9SXsaAJt74sLJiLBgImx/THGDb1GfaYoP+G6QD9d5w3NVJncBN/BtZIy/byNkwsv1uJczZPmKRaJTSgvEH4Q+unKQeahhtTlQVSwUtLm3DpklsaJe1ExD8Fk1ide85dMy8Qq3xJ275ln6F0UnI9Q5hFhMtYXt9GL8b8vCKKBeeMxZobe3BW8Gm4sNEc3s+UEQSEu76cZLEhDQaa1GPQqZqk/y6dW9CucgbKRpBUi8R/Ga5LPIUfZgFqWxjzuf4LHNz7aGwk1hNgcW3LsJKYYwK58A/+j2uSF/HCzO/s5d0ew7p7c9zBH7tIjRRCFveMhc4cG5vg5hpqLrmOpx+bF9pqpcNlv62MelI3Jg5lYeBe3KvkQk8ApY8lNU+C14L4McqHbpDWcEgOR7qskiI4WL916qvKamQxVUeZisZb+rkAy5TJ6JQmA4zcT+FgXcf6UYUozwJhdN0L7Tz5kTRSyPdfDRYZ59epnyqMjfIzmez6xgvxArTCO7nUtViq5dt4eviTsxmJghDT33eyxJHbst07IKHZ1oGALBuiE4idnQkNuvwUHEOVOGesGAx17fILqRvWM3HfFcWKcjXJ47iN51B3eUqEFa4S2xzaJa07+Vdofjb+ajo8Mb6x8Ana+4klSMSTWPMh3uwWNj+DJdDOBFl2nR+9N4a93CdcqixRfSOmNhdby+VRV3nvdAANr+FvpAXcXA/y2EXMKGxC6nUICLP8RHfGzemsLOD9LKFkyFVeNWcoSVhh+CgBgz9Gandokhq0Ugj3zbmMmur0TxJXag6dkadBF5VPBCF9mr49AmO5gs+a4vD5bR694oGJe86G+NO7Je1B3QZJuk6UBbzaVICe6enqMvphpMEW8JOqXlgZXlvrBt1 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-4755-11-msonline-outlook-bafef.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: 4efbd294-8adb-4a40-f1e8-08dcb61edff5 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:51:30.2334 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB1046 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 Tue Aug 6 13:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754969 X-Patchwork-Delegate: jikos@jikos.cz Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2065.outbound.protection.outlook.com [40.92.102.65]) (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 7EA131C579D; Tue, 6 Aug 2024 13:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952335; cv=fail; b=Q1v/UdB21G2DDIDzfR1DpO8BUqGyUhNJd2L/bFR6iYN+4EYtgbGgrk1KQlqgzJ8FG/NZHCCFiUcwRW0Kg6IAg1XU68QXbihaadza3vLk7CDwQnsv8GsWxo16G6R6QqKQqa8id6BmRgso2S/XMLjsJ2BP+/1U6bc3J9K234zVT9c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952335; c=relaxed/simple; bh=jCr6GauCRcC/9iluikBIxt/ItT4hMTWA3erT2d8Q39Q=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=XpU1B83KKJoVUT6gFS9xrzAdcyRU2D5VdAygwOS0fjqMtQAwC545QzpexiRkxDeyoDE5AXWfGUufhkIqV6CsKn7UxzgWQ5dJJLlUgU1HjjIDzVm9xgU+5Awj7O7XJW/ZOfGqck8xmrVIKT6hk/zNX++irIbLiJp+hfpGrpIzsWI= 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=MIaZ8EJB; arc=fail smtp.client-ip=40.92.102.65 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="MIaZ8EJB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Nww0OtRcTbev+JQoG9qsmSyKaklPeQ72le/+FJ5nqlq3PjWe56QhbW+LBgLFaHfTUbYWsbFEvX8V+901JSr+mcXR05BZt4wsbQEaHosMyH6SxtWoqRZ9LkJ8N8WLicpqM0ZSAp8+okilFzbC/7deEemb5tQ1wGPJEfMOiTJRCYsA9Np8MJzm6LhmymGmVXtl7ZZk1qCooLE/7ua7gVeuoHXmRzQVUvDAp8VpKPwNSYC6dJp08yNSiCr6TTFZ0evzzvHuKh3gpcGvmbuXUTQ6ZAOzDtN7oj+RQ2PqRyIepZ1Gzc6oEhED5Uc0A0MvtVP84KE3u1Nq30w7YXzHdmRMvA== 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=4bYZgdqTMzmRFsyXfpaWbc4sii2G3oKwpGMkDDNkMys=; b=X4RWWXNgsK5hQ61rrNCEW+nC3YUPauLl/W5tzO5gUb7Aw2YM3sM0s6pUpsqHlrKoWOJ9/wFUIiZLmQ2rK68PmlQyxLDw8gL3RvsOYiEmXFkh0wx0xZpyDP/6U2IplVrEItVRVbwaGJINl35NMbVaW4h3u3MxZlDyu16p9e9rxZcIVRKxdHbdbmQIyTnmtzjvDAleUehZOXMiBU9MVT7+Qw+czZx+xU0cdVJkQMWjgm2ATJVPuNXJiNU/5FYd7EuUowM1x02hkhRoDM1mC1F5OTAo9KjJUTBsCC1e1x7DEqFgOQcHEJwvJzmsM3Hh2ue7gBta8ZPYE43+MeX20ZR++A== 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=4bYZgdqTMzmRFsyXfpaWbc4sii2G3oKwpGMkDDNkMys=; b=MIaZ8EJB1sUKqhEjG+rvtN5FTkeWaIzbs6RjkOI/ccSnhlfW4IU5fpUTxX9sCfx10DNuM/n19JMiWMERPojMMA77L69KfYfddYRoMM1SrO6Auq+sh6nPjFmWQuyYN1IVkShX7tGsWiMmwhQwnGIjvjCoj2q14QNNQZVZcPecrZ8AyjQX1asS1NCbGuZC8nsUTBbyuYw2JdQOUV7Wy89PoNq61D9mdlFaSb/cLP/bpZCgMWaKOE5le8IXhrQ63ScSJmkgEoFcaF7EFzJNEFcFM+km+F73JAikKvrnWb1/jSqA+hoEURtZ3UdAr7o/CiL+/AE71gpgm5k8kZgbxqaUmg== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB1046.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:139::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:52:07 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:52:07 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Topic: [PATCH 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Index: AQHa6AfTXzzJ/JF6skiWN3sUlqa+rA== Date: Tue, 6 Aug 2024 13:52:07 +0000 Message-ID: <708F206D-3571-42E2-BA6B-5AD9EEF66073@live.com> References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> In-Reply-To: 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: [1rXyefyAd4du6axD4T4TI6TaWAibKUOqrTVFNx349dzHl1wc/h/ohhBxEwOZTVwfZ7MYF4DUgM4=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB1046:EE_ x-ms-office365-filtering-correlation-id: 0e9829c1-55ad-455b-bb9b-08dcb61ef61b x-microsoft-antispam: BCL:0;ARA:14566002|19110799003|461199028|8060799006|102099032|3412199025|440099028|1710799026; x-microsoft-antispam-message-info: afzkGsFwFavMgQjrTREFy/7q0uj/qpJvL2Q5dFvlE9DtLgnIl5c3BLm/oF7i/8KRwHe+Zlr0b4z46hDmxDwPMYkca8y6x2Er0KH/KPzyYQdOLTCiGV5iyMIkuvuV3x55ELqyHV+7uMvv/4eMqOTK9MLk6CoexKVKhA5p0OraQWObv9vnimK6j3gkoeHPz4twjdEnSOaro0rpkd00GuMLKnOgKmOe/271WE0MAukjF4vJ9V8OfpV3qQ0hlOAP5r2qa7eaccFOGc0kQZa6euamGmYyNFgYBa7uBjMHeAHFjoqkrgZNSbapZiDDh9of+umnWJFEFFSoUqZWg3T9hW6LAFKJ0NAfpnmQqm2l2pTuZMYxuRanqdXNNRyLj/UzpiA4ANsJC9CyaNgXaVah4zLXmS96xCbkyx2mZTW/eBkwH0wOrmlzU9pona+m245e5p6w//RrpP49aLTPyeleO5o2VI4F+CNn0Rcb4eUvaYGJ52qSUwB+R/ZhwmmlbDiFIbnR5V4LUOqbagScqmcHwvGypfkPbuPcwtnKZIuljKG16aRW5E/y94Zl85FD0zFt0R2rPtyYbyzBbXu/mfcyEvcOuTby8Ib8YPM8rVWEW+7B85W3rKLXaBDYlHtcwW9yRlQXTqfvrSGG8jNob0B9BK65viohYH5RCW5wl9PcqugphmG/DlSS27kmHHg52ISlYjkJ x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 96Q83/xG935NrOS/indTqt9QYGd2BFOJotyl584av3ZRz5NycgzLJ/3vFPtuvI+xMSWyxmkuHmMCNG0xgk+Njnpm6D/CRw+sz3+I+5TIH9yDtlfq6PZ8Ic0Tfozte3uQUUiYR+dObhrJ6J0JdjAqw0MyNxaBt+f83U7YMpaWD3xAAYjyYHidZgBDJauFcPy+4qG/sXD/poF4Bmr1RbmN1qJegwCZeB09JKLavdg/emrCh0vfqXX8nWZHN3joJSsSIOwyntQxi1z8P5Y8cyLehaW6ua+JCrBfXQSRDoXEsb65PPQe5522lRBj9H6ThcrdwBqBacyIuC6/ILFCyR/5nRIs/HrZJPHEbTmsSSP+WHS0Ic0IZTHlcqr4P3mfGC1FUsEy0f1Ym8QjquwCWGj9+RL8I2fkNfE7Mm3P+irjFZr0BE1PBIhkuBc5dMBYt2VywbsiGY23v4obS92pvtXtE1Ug/RqcUrupWIsiCQWy0E0gTY/cRErsqJtA9ggDZE2LzOvHMfM1cv8TX7zqxRNsrUNfi8qaItDqMSymGM7DfxSS2gtaHcX+kjYCSfNQi9eZhklbrJ2doYNSVWdnzY/XCz2Y9rCuXxuBbVvksq7+m5kToMv7S9D3upU0GY08HwH5Hr7zOzyTc0Q0vU4UN6KcMiCW42qmD8f68QPSUWXLEsx/QkslZFVCPnMExqx0SPmOdwpRb9KxxDjp+bwdjedgfZL9tGyRYLBtGV6no2mN9noKrr6CdwjBAkSwICNMnXtbmY82qVKtGOTCUlP4+Evc4Zwcz1Pyl+T+2lbVDDkbmZ356Fw+N4qT0ceB72uQxtDaBjjD5Nf6aSRet7YdHO+2OkiJVByD2+b05zcFlsLH6glk+YgKjvQbLBxZ9JVrZQmnJoQG9krqwSCq+YT/N3WqypNSQkRmNDLKywjj1ZkXVmKBmoqie+gfWiJ0V9XMND6i8lJIV3vc11MJhTci0CLOcYJx3XYyInWqrHprmpes7MA2ZGqXBqjQlqG01fkfZyvmvPiEgEoprqV3Pg4LATOyTe2v9pQ2xRuTE2kAGlYQmUQcZ7XF3a9meplC+y2qrt3nyiCnCRGAJcCZ62bVqlydE7Xd6w/wkrgGzxUx5jcjoWoJOPHM9A39s7eUcRCxc+ohdwPd3WG4bzjoRNLNMBY5xp2DOR4HvJeCLN0QAFUBNZJQ1rdWT7tXiJzUYVerixf8vhCfMtXQZsGUDgmnTSST7P524osd8vxuZJ0BEPGIIVahwdswcvBkAOWl44LJPYDBu/yFF1igSMM2BMDhmTwMsdUaSDkwDAlEf95lVRp6O1JCaD5ZY3ZriOUxoZJiz/1C Content-ID: <9DFCC3DA2F08DD44B5BE816CAB7EDC9D@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-4755-11-msonline-outlook-bafef.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: 0e9829c1-55ad-455b-bb9b-08dcb61ef61b X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:52:07.3500 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB1046 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 Tue Aug 6 13:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754970 X-Patchwork-Delegate: jikos@jikos.cz Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2054.outbound.protection.outlook.com [40.92.102.54]) (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 714601EA0BD; Tue, 6 Aug 2024 13:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952382; cv=fail; b=Oi6fv9ZMgiOewyNztxF26Y22tqyverOGXjQBdt7/QwGzZraFD42BOHF75a0wnl3Qwtubr2XYj41UCZm/Nv3ot2eN2LVhD9Wu+utlT09ExOL6biMhXi+xzXmQkl0MziNxuL1tiLTKDlDAdf+knYD8H3Q+T0hmzI3rzAMgyjwrsws= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952382; c=relaxed/simple; bh=wM5lJQU/XTPlSQMc3tjBBPl998jaf/IPW5DbGJ2A6IA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=oKYvoTHJArISoNAo5xkTJithT/zZvonwKp7a+LRM2fNMK6Rs4yqN44QlTGoG2haLJcjMpKDPp5qhVJAjiTmd+VAAVl40G08XIy98YWxzMkGzUTR174p3TYy9S7M4DrkXHnk0YX7HqhStK6ILviWcCYnIlPeCh1Ej8fvdpzYJtDY= 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=rqDaIoXl; arc=fail smtp.client-ip=40.92.102.54 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="rqDaIoXl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KC7BJPnHxJk3inQkFZuTHr33Uyt17QWwb5Afhn9eZrbm2TBbl2Ijd2QJ9VV7M9Zmlr5xh9N2b9sP9/opQ3HmmNYDd8IqF2GoxtDr3+y64nGORMDFUDwMjhzuRT5ggWl1E3rm5Pbissif0Bw1AWfue85sZasOVNP2Pm96xM2GxoI26o7FKYRk3qnIZ+My8e4JhNIU5Cc5LtMlUW5r7mdr6MHoF6nP8KpGj4THgpP5xpUZD3s5W07LyatWZEJDziwe2iymjFtsDDIXmTl4VjoFDoo+Z5zRQ8nBQALLSSC0RB0h6s4pDb3+oBdrwNC60Tk76/DK1tIbxCTh7/DtTH+Izg== 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=WFlmNon3cxCsrA/dn65ztpfF+V3XRcHR23mKlXxL7g4=; b=Hm+fTj7azRnRda/yjkYA5/RbC8yramoGYgwObEoKh1WulhOnyv5G+GrFfxqlkJohmdyP+IRgUZZsKYpfbjWfK+rSCApJvO65eaDLhP7w4SAyyRx5zhsj/9DwBzkI9X0qcASG9Vbw7Zw2EgHQSmRwPBnVwjMpxpBzOXsRIcIDByQPVAB9mbDHpCBCal5VjQZl5InHl7cAfyuoyZM++dqd4aU2TMfaaQuWMJ7GY+A8PbfnCCQSspvDRXMrqZ+gIB7aH1RUwyIt9iNaCU629SHKrBtSYH9Ax+ZFjx7RjJ1s3bOnKfmq91vuzoCosZSrZL7GmFW88jCEYHq1TY7SbJR+kA== 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=WFlmNon3cxCsrA/dn65ztpfF+V3XRcHR23mKlXxL7g4=; b=rqDaIoXlUSPM0Ip3SFDNBOOVW9uK9cljHNfuKAyGjUYywKwe1H4gaDGMZT7vs00eazkPoIwhuQL7XIxslVXMt7p/rj6X1/cgvVaD0QdTOG78gLZ8zJkC5o94pW7Cyc5t7py7/wJ/Y77N4mpl+mc6df9oh9sZUjR06pfKTd+TAJh6wutwDLkV2KlyjFPd29DzbgDRXPjOoYHsiE6HYxXd50PUPyBmXSn8rZENVrsKGIe05txXTt5s6FujK4Yea9Cyc1hjwGUFJ2HHlbQxQRTWbDRmF4j+qkpflqdvjpEQF7W+LMJs+nJhzI2fib24Ms6ujEbRNQlHObHnixdKODAung== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1708.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:fe::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:52:46 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:52:46 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Topic: [PATCH 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Index: AQHa6AfrYQfNORX0kUmVQmeA7FLxkA== Date: Tue, 6 Aug 2024 13:52:46 +0000 Message-ID: <4BB7CA6D-1554-4784-9F7E-BFDBCD9D8B5A@live.com> References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> <708F206D-3571-42E2-BA6B-5AD9EEF66073@live.com> In-Reply-To: <708F206D-3571-42E2-BA6B-5AD9EEF66073@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: [YCaoMJIq9VaYdbccaFPuAV4fufHF45NGgAyQLik22ZYRlcAAXGT1ArLGcdN7mjWp8MniL5IZ6yw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1708:EE_ x-ms-office365-filtering-correlation-id: f4c3c476-067f-411f-4476-08dcb61f0da2 x-microsoft-antispam: BCL:0;ARA:14566002|8060799006|461199028|19110799003|3412199025|440099028|102099032|1710799026; x-microsoft-antispam-message-info: 5MX1fzMAZ6gRNqtwKjoIbwcKRzddUqXBbW0lrlzdb2q0a1SuUxWyj4CVVVpB/x6ym3Z2jpvMGPb3/jvOJQHeX1IrnlCxKVCnjmbNm66+uy8dyskBV+0jeZW0U4zaYfaii3/sK6g36smW6zLr455z5WYE2U12UmVwzamlJ8kv9HEWjk7P11SoWho9R/DIbgl5ZdiNWCU4nUJAM1R4clPnZ5BX0rDqtQHvaVGZOWtGMT3Tx4MkUsHF90DJiSzahyQ0LncKsKgZe5PzgBMwWt/qfENErSqMEDmLOfMiDIpeWXOIWOa2Ul5LbQSv2uesyrve0A4s7EpqllUxUqhLaHqvY13ia4eMhjDax+OHHAZcOiG/H+NqA+xehAkcn71vnOONXOebfIxClLOaq+rTj6yRRxoEI8ibeO07uK3LRNAgR6f4OQZYmcXfziefWe7teVF7mAcGKd1V52IfDUnjA1ICUTPhW/KZ864Wxr5EW9Lvlz5W2UDSuzzeTfdq1H67DKZl0ntsoF5doPbSaeLZHdXLo1OtyIkHmqG3DMaHppzoo8Bp9jZPSLuaJNZS8fzX7Kg3YL8WVM3vxVh02jCW/OQdSGFMJ5WqDT1qYq5OLrQPa+zGPSkrC5i+czRbANBtvfMY1SYF10rwbPSsxBSyjJYazFFuoToLlJvBRsqzcbFxqn1doooYTzdSIKCBeOWZVmUs x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: yzzQm2EqQ1A5m5va5l5FhF8MpeajYsixtuBU42sPASbIqmLk97VjyjiE/WLJzpPt70JhoDJwKx/1tbf6FM6LAZLJJbgnjpxI1E+H6xikq7VEyIeUQ1w6tPKJhnN48SpWtgDKp4e5p45BKFozuSQZrEr0Vxq0pOhOJ6w9gZSG5lmjGIQAAIBcGqA134q0+AZeBwVAhpKBk4fs0XBXypQ5vwWEUDOcat4PFDIaw93CkTbn/FqyWNWbpztQxdy2SV3y3fm0ehAxnjSXYTk0fCO2ubsQQ5x4/UlQ3S9txi/wrFqkefNSLrrvi37J+zofIry3EWjSVg5EZbJRqgvX/vRoSegMB2lg9vv7P3b7smE1sUHCGxP8Fa6QzHoYokH1lGswx8tKb0Vni/Ek4U5waq0IUGnUzsrw47HdKbvo9DV2ujglAU503YsFspvi/lyg3OwIK16OkJeUl1DGdAPxxqO3UbEWJ1Y4ptLLVbyiJDbgPYCDFITlIboCeE45V1e3D0Fu6nDHsnzyJ6ObULbJ/sCzdOEem5LHZUwGH/4oKs5fZ23T6TNzu6BJXzvURCc0bX24vcRoUs80EjxUbqhe8yHwZVJhJJzSiKqiMwAfTU5k51AglogDGf0gjvLdtv4h+Gj0uDJzfc1/g1VHGNp1kjdgciBas5O8KbjvgC1peZGauXDfGlWYpMAJssFYIRgNKvuvYM2BcFYqgjwlYI5zjuACGTuUIlLtdC9iiCf32+SjxLOga42+I17tLLyBF1IAKj6I8O3z4J3AGQTWbvuhAeZjdFssRmoHTCRg0UWC2wlrQzG1g6dA+cBKElPF0LWTSy1dHJCB3ophh7xJezbdfhKTNxvKX+zlGtuY7psIp4hPkEPTL0kguY752GKMl1h3cdKuZuuJh3+C7J/mWTHfby2wbgI4umiXAWwZ1Xkz+mgyO/4Y5V4Npx7OPKY8R79b6YwLD/IQgs68nlgW7Xeq87W6s68z7RapHE1eC+Rg/gpIg2zj7C1sc3gcigG40xhcRNwYKvZ/6cQyblDtUMH2EjV7G618p/vwN4pnRHOnbxGew8O8MDntCjvh+3sGZTe+0LWCTaFzkt0MLazw8P8foS8m50H1uPr3wHUNNJu2WDkJJ/FI6a6/n1xHwb8w0b3ty7gHExOyK+2qaGSofwJZ0/YUZe7I2dJj0ghdn5hjKUM0T4obOLup40sUfknA3RXC/XLYx7iP/4333q3Urq5V82DpD3/vP/HzCfDJ/ZxKMq3NFlLggX89CnpLid6IjJljV+wRNkm8F+jcalrBHz6bz2HDL/4EfQ4T9CsOAMMAeFcxicmkxZbnzpx1Wecax+ulakqt Content-ID: <95EE09D02FDC9742B58E4500BDEC44A5@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-4755-11-msonline-outlook-bafef.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: f4c3c476-067f-411f-4476-08dcb61f0da2 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:52:46.8230 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1708 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 Tue Aug 6 13:53:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754971 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2058.outbound.protection.outlook.com [40.92.102.58]) (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 C77061D2F7A; Tue, 6 Aug 2024 13:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952426; cv=fail; b=MIVJ5nulNiG7JLq/+iBWyvq3Y6n1FwgH5TQDeP/ZhAXkmdJcuC20B11h1UjNz1fL13l0hgv/77ApY2LcQ81m/aTVzEql3m0SXBC7AHWNs6XPbMDX/A51JZN/CMU4S7C+w8oDRztkJw0unSjvDldTLyDn0QiZmHqAXtGLbgz9akA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952426; c=relaxed/simple; bh=WWt522Wy8+fxjeO7Sxe6BAeCfJgYdrRui5FfQ946+vc=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=JIso5E3x8lLJ2TXJfvwqk4j8QRU0bEF2pZrt+jBQ+JLYbwCUIpMqouriIwfr493BC3/bajLif/dV2qdCNy2b7lfudlK8Y1fr/7KMr6kmrUiG1/UnLmden1oINWuK4i52h5fYfkBF9eGAXauyt4Ubmhyx7AVbmq66AcpvfaQXE5g= 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=rU//rA0B; arc=fail smtp.client-ip=40.92.102.58 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="rU//rA0B" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SkV/nDkWjlpDd6hw9RJZR4vaYZqlxj1Yni2QoUm/UHwBYfsaT1GvP8xUXlTo+JTdh34wtKo5u9ECe13S5HVwYFVGqy/DesXMtfTv5uaVTCI/bsg7Se1YI/5Ly3qrcHtyTBS7lyyRBoaGN+JL9ujH6NwMWBbJJeAxI8x7j1tKvQ43JLjPTFjQCfQRcWteuLg+/QF4SDoR1Od9jhiflqUdmjUtHZiKsBz0z43kDEZbTiLQ8GQijRUh/3Mg4YfaMASTytEvyw7bJDMOmT5nIZQ0nFaGfKYbdyKEDvv7bLNgOvJL8OPa4Ev+NOQ79GuPDE8X+Shh/kc5SiplttwGHV52qw== 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=1YKvWjMS/3d5yhekXwRD9oNba+UDTt190X8eov0k1HE=; b=GtgYO83F15gmP3wnjrOCsg52N+PnLFe82NhcpqVlGQxpJCMC797F1yNyRmpA7BxUjLD8FeWM5raknW1H2bi2toBUAlQ0k0X3NZYrr6j6aQ3x4/t3ygCDp0bDE/44E3t5zxU0iz+g2zPXI9F3emZi+Og3OPkuFCXrSPg9/R7TvPvn/Sr747Md3PNs3+uM2Zz44z4p5cnyZTjni1PF4HOZXDe2tczAp/2krwLVVgCXuDDCNyVH1uoCaJKFLRXz7NBIK/iD5KZLELjgq3N/8Fcl3UPNEgMx4N7WpjdjIEAVc9eU2CqfiuWfenEGqAoenficJgOvLiPvnoqnTHqZC4FTdg== 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=1YKvWjMS/3d5yhekXwRD9oNba+UDTt190X8eov0k1HE=; b=rU//rA0ByWKSC9XFKEynGZJwiCkFOA6blyF1LWGy7zvlV/hYuXX9/nC4acDuoyrCUXyjkyOW7LbFpW9IexrRUWV782YtTGpvWM0/Psug11qU0+JRXRTyfuIUNCbIGfId5W4wINxc2rX/FghX+cz0J458GtsBNunJzUCZerdF7LYHJuMa3cGKEvMAqJwRK+OLSjEWlUX/yfiHqxgllwcixTsHu3kxWi3jBWSluXzKCK2MDJ1Rg1jCgreTp6UwbOzBpxvkw2LzrXsO9huWyrZLURRY41/9t/goEFBb3D6inQwRH2V2ok62bW/fdWJ70z609pGEAZ1bY5+y7/lXOl+f2A== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1708.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:fe::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:53:28 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:53:28 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 8/9] drm/format-helper: add helper for BGR888 to XRGB8888 conversion Thread-Topic: [PATCH 8/9] drm/format-helper: add helper for BGR888 to XRGB8888 conversion Thread-Index: AQHa6AgDTZhoiVxMIE++l+iOjtd1ZA== Date: Tue, 6 Aug 2024 13:53:28 +0000 Message-ID: <9B1AD5F1-4539-409C-BC34-DF9E196DE6DA@live.com> References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> <708F206D-3571-42E2-BA6B-5AD9EEF66073@live.com> <4BB7CA6D-1554-4784-9F7E-BFDBCD9D8B5A@live.com> In-Reply-To: <4BB7CA6D-1554-4784-9F7E-BFDBCD9D8B5A@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: [4Ph7+QV4JmbJr6ZfIsb5vs605nBYE7BAunad3a05q4UClP+d0L+EYqGgcqYt3afPhyrLXKhJ0wU=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1708:EE_ x-ms-office365-filtering-correlation-id: 964576ec-f6e8-404f-2b97-08dcb61f2642 x-microsoft-antispam: BCL:0;ARA:14566002|8060799006|461199028|19110799003|3412199025|440099028|102099032|1710799026; x-microsoft-antispam-message-info: yHeSL+GszHGZz25s1cfhm8bkClnqeb6uWYr/fjHQ/n5LIZiAOMBUMKf50ING+7k/L3MDSnMqlV4AAbJke7sttlmEX5OlH6KrDpbsYfcUajxNTy/OfDjHQ7Pe73IsJSeJTYK3w09AosVM2VbjYUK2GB6Q+D62LQ6waZN7SPxbM/z8oWYdEz3PWmPwvcXVXyS9itpiHux9rJXtnLfy7/5BktK/3rqcqWT32tOFMxCQVFE6UvJnKRzK7Iy9pWzAMuO2aL6uZQqkT4BGZk4bPMRxSWCUQeGaH9ZZKlb6LEzT59KilN9uOzoLWK9jDiB5ls87+3q7H1OKO2xNoIoP/DA8kGagj/dnvn6EHjKTas/mV3nzDvpYGC4ZYjlEQCfQCD6P8QxEWoqFx4holirIAi1MNkRA66XSJv/p2gvaCkY8oPvDb12lIoGpB3dYvJF6rHdXRsKDvR+MAN8ZX4e+btQpSizs5SDyp27Pfqiq/reJ26rH79jMh0u1scSTvwiulVcgP8hlbwX1LwMtAxCuZ3i3hYRjT6T6ufyg+wFBWGGT7h+QBzLWtlIINO+8bS2CBzJwutI4FAVjKZ1S6/WOiaC7gCJ+1072yQRKbe8osbPMf8aGa3taHRPCu1HYmbcb6dOdvixtkiRmGm6NIfFJx6quDEQqBG2hp/IBpHZPoV47ySA= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: BI3h8Xy+8YOmtoPeK9OST9ZGBoA05F+KcFO+B0r19GPACaXe5624U72dYY/RFECzJYUahJ94W+VBp5VJqF9cbEmcgitXqDv53zbwbRaaI/2/NGXEY2vuBrfqA3MripAH+zjUInUyag68C3oV8M8DAhOilUNyEex++5Gr5TxrUCim/jrPs5CfYHfaE5zdYbgbfi5wceEaLY+jXoG6bKxh7kois3jXYqEJefj7ygWSUUWjEk/wWgRfBo2VjzZV/gTUrhyZYz1Rl2AVbjpE7RYhKA1tfckpih/Oxi3rwme2cHTX7HOmQurIdNE4zhWUIgGfLoqu7Wkwb6k59/A1AlEVgwUxZhwHSmJ07sDELxy0jpK0jKk7SOjDuGYc9gMGPqQgtaReBgjfzCOACF2egwTevQzvbaVBV3xekmsY/FXSjrwIL1zAOL11zr1Xn+dOboGSKmNp0E1JyHzsot9JxpDDNWgMUuO02GJja4mkiDhaB8kuFKu5zJpDli/5f+9HaWmkb0oNUjQysw5GbNA/eBnkr8LEy0AjRzvKGLiH9f37I2UT2K8QUYMYQYvSsq8dFhYojJrisXhhLGn0unwZKYAtee7xh2LI0OQ1K+hwQZj4pSExDOo7Mec0E3FRSLOAZ3/bv79XvAZoSUstpTlcGs1xNjx+W60viI7yAwKiftI1PWDTOGWAwx7wzu16TqRaL6Ay/HkCE0SbCc4K0yWXDaaYuo6qfrnKo8RmgBFfBKu7wI75vvQBAvkIzdJWJOzj/0jgBBTC+vY+ql8cBJGItRrwC/a+2oiiWHCdcrUI14NPq5arFd9AwM4ctdYIjsZW8MMZipiiDqN69Xndh1MDKq4nBiXDZmIsZHaWq453CGK7/eBEFoSKnXC7vGZWpI1Va2lb6PFxZvXPNw82pBlzOFAF44wKDKF5qNBtIndHjXK1nhkOq/ebLVUaz3hvv4txH5HA1szQq4pU4IK0PZBWujgLRTMi1kMLYtq3g5Oh3dT0P1CmdTzuFzQGZ4JhmfwFnNnl+ykDcMmg7P/5HaJXHr30Nv6Qowgp3pBEmFx/0WM/AQhtLCkybHY3tDCNANjf8gyEgpz+R3PlgnNZXdWVMYDp+4mdJ3UYIcX9GA7hXhcv1s0UCtwW2f1PzoalMXQdgAzyx8by7wiau5rOEsbpleEzXJMD4NmHPJKSis+wspRYz/Tql47OcJif3vhhYC/uYVpzybsTulYrgH05bwB3FdL4P/KYJEnOv7SM8QG4xdu5/Ao/k5BjpEIY9av8qtnN3EBXQOHGF6X6Zk+pQT4Zukhy1MhvEeKtO9wuIBIfjRzeFcbFGc3D1/ddgp6EOccZssde Content-ID: <1F2EB4661E3E0A4993085A7714691867@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-4755-11-msonline-outlook-bafef.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: 964576ec-f6e8-404f-2b97-08dcb61f2642 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:53:28.1511 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1708 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 Tue Aug 6 13:54:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13754972 Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2059.outbound.protection.outlook.com [40.92.103.59]) (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 742CA1BE875; Tue, 6 Aug 2024 13:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.103.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952465; cv=fail; b=O5jdOwSfBAKUkTM/yihJs5lOmm2zTIDrEaoFBbd4G7jW6SUTT/M74YnHS1NFu4dntmK8X7eZAbfGtzIvUU3P2QxTwHZu77PvTwhABnEVr1Dn5aFhoP504/eYqm7CBTF3EksN2KPaAewncbrYgk+jx9l+i9hCCSC4NX5puVvsVGM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722952465; c=relaxed/simple; bh=BOKcrzws1gRRCNSz6MMLGW80PrRYkGrpZV0GJ/dptVA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=Z78NAkxOrbfVdNSGXsS8vbDKET3JKd3dU8GXndDTZVvcna66ikGsjCJIKw/TvX+CqHH+3ylGrkrksW6KyjohVyqfN6v/zZTGWoi3YLb33wvT/EfTAYZBGHS41Fn3KqcHczRse1JsxZn+GQJHcB72UNOLJCm6FMeXuld4t2uIMbU= 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=lDUdR0aK; arc=fail smtp.client-ip=40.92.103.59 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="lDUdR0aK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q9dVEyBkzYoaaiE/Rvqnp6wamcpH80J9WdsF9lF/qiPzXgHYn4rrb7wHDqcWAOncW7neObTR/dJNf8825hzaFOdmkhx94eddxqzrvswuREEfCMlYPve3471YwikuIF+v+MqaHBtJpD3TvwT6b3/Dg/A+Lzb5CYPAFEulxJUAN6v2gw5PTG6NhBH/dBNzXtGAVg6lgvrwEtqfcehRX0tw9m3PPRQc5zHBAOxm8APdrf4+onjOP5KaXlkZscZ5tDdCE1jeaJQ6+B8ldvxFZxfYZTlf6HBtDcB8Bhi/tWl7F23jXCYIzmAs3Y6Dlnwik9dQEpBPOC2lb2M8KhTnqgnPNA== 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=oPKevwU2AhbS6EwxJaEgzNZiFOPvqMaW+nyARf+1iBY=; b=pIvscQG+AoS2m5jSfiKCsQvcHQFPO/5X2FpKHFrAhZpE2Ut+v4koRAuZHuDixt5YEexzSPaw7qTtcm59h8X5BUPAszpOHtqJqU4Y4Ee+qICVyxQvzqToPtA6mRpKivfeK7szJGWoye8ZNtCW9BZfK7LRLqR7mebDJ4jpTeuCMNsZQSIy6P7Cw1MAHPhQrIuBoHJrThhmmvmvJuuC1uWUEyJKupMYEqcp+q72mC44VQv0IHVraV7IA91GvX0CnIowDF6ary6fqu7/NQuhzXPwUu6W6ThrlmKY4RPn/C8t0cJ6EWK+Dl09OJQ8WLRQY/MifXd/OgRBxyX6CX/M1PKE+Q== 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=oPKevwU2AhbS6EwxJaEgzNZiFOPvqMaW+nyARf+1iBY=; b=lDUdR0aKugXpec+gsw3fiEvGnyVxgwGiTfjlYFdsqxehJsJ7YneQlh+P9EImV4e0l7ieXbp9hllDkN8LVWwSaShrwy6Ewbrkzn+uN2Xnk+bNI5zsVPPpUJfI5gYqjf60P+PyYfTgsRDfnhCuoWyrP1SrFbHw5y/92a3cyI4ygN4LuEFJRNvbcmOtHsD1OBfz1EJ/RXf6bBCEgG/1J0UlCKC2EAFGnrc6N0ybUwiMhUA8kD3jbiCqelixa7DlN2p7bp8HlH7a1V3uCUkQwtedDzp6jsqhH8UsljahUcm93cJkk2Psan9UXyFvKfFlT+zwbBxzRek6KgoEWzrVJCevWw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB1046.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:139::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 13:54:15 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%4]) with mapi id 15.20.7828.023; Tue, 6 Aug 2024 13:54:15 +0000 From: Aditya Garg To: Aditya Garg CC: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , Kerem Karabay , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-input@vger.kernel.org" , Orlando Chamberlain Subject: [PATCH 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Topic: [PATCH 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Index: AQHa6Agfo4g8vSzFf0uSSBYcpgXCgA== Date: Tue, 6 Aug 2024 13:54:15 +0000 Message-ID: <440B8E61-2224-4B3C-9B55-69201D736AF4@live.com> References: <021EE0BF-93CA-4A37-863F-851078A0EFB7@live.com> <9223E804-286F-4692-9726-2306361F1909@live.com> <708F206D-3571-42E2-BA6B-5AD9EEF66073@live.com> <4BB7CA6D-1554-4784-9F7E-BFDBCD9D8B5A@live.com> <9B1AD5F1-4539-409C-BC34-DF9E196DE6DA@live.com> In-Reply-To: <9B1AD5F1-4539-409C-BC34-DF9E196DE6DA@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: [siNOzO+K1UHMGbQTQn9amznBz4HXigcyhV/5OQV0O0+EHaXzWub/MqS4DXL/PlDDbmo/8e75NHQ=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB1046:EE_ x-ms-office365-filtering-correlation-id: 2c4e261e-831d-4c19-e4cd-08dcb61f4270 x-microsoft-antispam: BCL:0;ARA:14566002|19110799003|461199028|8060799006|102099032|3412199025|440099028|4302099013|1602099012|1710799026; x-microsoft-antispam-message-info: 87AiB27Hz7Uiljja3iedzKNumt3M/CEopgRH0ENwFZsAMpRcoz9QofUVMYPaSV23O1FwjVJMdI9LTirHmZjOEtd3v3WJoK0kDxTSMhMUkGY/jk6IpagQSuxSNDhpdofbjQLx3kwpuDYy0/v5jwAMHCPJQQUBGgAVZ9Q2h5zELk/7EU6JBrFIGsB2ABDJuHq+glr6eOVz8hm87SLo060IxoJdBYTFNT4uuM0UlNQnJJc95P5Lv+IGSjfmxh8CxSfkEGdIJEC2K5NLoWy472ko7cRP9/L14wkuybv05P4TGaPZjMoHBg7PQ1e8ZhnHVHeF2o/P2eN9nos92ZuNokebFryncMXGJC/GyNa+KSxPqahpPW7w4+dS6Zgr5tLgY1+hMXbd+S+Rt20mGpAbLTjRaKPo/ZMgbAB1pKXSOW3Msx3/iCZtdHfihxiE1CQlK9ucZy5x+1wlbJrnG7w5pvI46OW/3hwfeE7lz3ZoH47RPL7Nb4uU3kzlpivBGzLCAnV6iZwKoXib00LX5wgB+8eI6JT8zBpfD9JHokwY9dg8gszrEsI6uKZmOX6vAmcEx7hYA93v7ICFoklMk/3NcvzXkLx/1jRiVbl7V32LhOvV/aBU4U04kel76DLl2Bgm2W3AqhydkMcpFJrKkpqN92yIroRQOx5n41DFEK6eCkCi0rk8CVv9S+wD6ZQ8K03ZUazl5QQSjY5gSkgNiS8REjwGNPEvfHiJ3bRySpKTB9zSr6ElPqVDkSt7I0VjIANWN7mzF0UpaBReoWmBJqLGmvL5dPYLX4q7sLusS7Nsrk99BZQ= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: FfxTuZYvQ8RK0IIBf2opIwTTkBDG9sLj4eF/XxmiqqZ/VMzynlUqjoQzmiqmiZ37fMiyqnHJsB5gvNibG+/yymy5gAhvAVLBZrIz2+PGE5vsrQo1RLFOBukMg/H70a8gwq29KQWSFQ+in4OCbHmYZX8LIYlz7s6d9dq3nF6CefFMFbnNtKx7XyZR6xjbtLWChB24MqMqVh6claSKHjCI4FhzgcdR9KwpmcKSwSA/mIk1hsuDYnoFSOQEFM6xV7Tdg2WoE+iA8SQXTrbzwuCQgC5T76UWKgW0hpHxZ0wzcxTTU00YUvz7q11+HYVASwMro6dm5gw0cM8xG4ekXlf0wjtZeWgmD8S78gWJXRtUwiLYgBSm7CCxb3aLgZ/iO+dc3jYFdrgWICMTTjAJvQGJlheWULNI33QLP+eLkwnWC9SGBV5yaLKQ8BCf7fU4ZkUOjhD92v4EJ5G+VBxl/AcXqNqiCe48/C7Csu0HpG/yCZeqr61tCA7NdEKspZXm3fuafs6cC6X1fSAFtzWUW+PNibwpSsYt6QUeD1uiWzNcjGaLmOGwtEh/URX6qz6bt+MF6VPTVBDiAr+lbJvGpqydJkIczonpcGl5kfzZ9CCMOAKQ4hMpSJTXTA+6ZltyDIPYJnsfADFaw45uN3UN71fecazAstENCLL7KVmrUgKXkFMpq7bFDcjBo1BHdzuquNFrRrJmC9kWYF+RyUpzuKGfibEOea1Y9JjTy23wo9cn4kp7zEatvdY+44u8eW+6VILigIGfxLwu3R4ubYpYjyLhTG7PAY6drTdU+dnjSOmPCemVXtsHvSmDKDb+dqE7aPKEVqr0b+48+F5Sbcxwpo5Mbr5R+CRaVAXncQ5SIff7ToZobZauKXHKuY0I4zqiMJ7mTMI2qshSGiSCuY2jW2cYpcAJZxLSV1r8ExbphAXhyNh1WWMQHz+FJOon0DgOqSXJWnXpNCogxaoEWIlR1AiVZWA/VhOY9J+Ulff1ZRqWvccaDix4ewSWPNro3laslz9S4wDpXBOhdMu1iSeruB67WBKvWnOXfUeYVbs/yTUNSvkcpZbVkroA/LO/6r5yATStIn2ZuiZiyr3evEV2+riu5HbOH93QZDk6GAZxuL/kXqjj2MiAAePj4JjmV0HWl7wTC40I2QB9XSjMMP/7xeeMUurGzS42d4ll6+csJl5D9V/oVYr5CLKA7zOucDRBPcAJweCmHl4RnXnUIhfAovpRGtPJFD4dprZ+PBLcat/ztBrrIkPdGHO4r3/RBxYo3Nfv0vdlEgCOkLjAephllCDA+Y3fDWL1x8hftOgPnYHJMlIE5ehQzCUxmCMjfe/XK7cb Content-ID: <62383773573EB048AE458211A920FCB7@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-4755-11-msonline-outlook-bafef.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: 2c4e261e-831d-4c19-e4cd-08dcb61f4270 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Aug 2024 13:54:15.4324 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB1046 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");