From patchwork Thu Aug 8 13:50:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81917C3DA4A for ; Thu, 8 Aug 2024 13:50:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF75010E738; Thu, 8 Aug 2024 13:50:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="al+nPGUr"; dkim-atps=neutral Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2095.outbound.protection.outlook.com [40.92.103.95]) by gabe.freedesktop.org (Postfix) with ESMTPS id 80A6F10E738 for ; Thu, 8 Aug 2024 13:50:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u0b+QhJLbzUjkJC9useQncxFyARKD0fmqOclqzqKBxt1Dixb9Ag4JKMnQrWPzYXAfUeb9d8v5fYrYImu20CcQHO62tiykOY2ZYLQDsTiFt1N5roIdl4zPiBiQXQqpDG5K4FmhxYY8CRmRt1YQcwLqdD6h4hBCmkReQMNlA9GWoTUESazZPuGvjfvaOSxV/dMaUUr0dSldaBc6T+99O/m05YnR/EdZ/Or4jHmHQhT77stnLVjU/Oz0QRq/dp571GnnaMOGdtKXOv9N0wbkqVCN5uWdNfPRQOZm9Sv1HYnAGbSfBreA6cmH640KL4YPqsHx7UyvH3vKR/IcIhO1dr+bg== 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=7EKteogOeesyTzxaV4DfyZtFTiETS7hlG3rkW/szOU4=; b=SwkyiRdIsOoRWbazKdhlOGQe5u+BET8OZJqZepvje57wkMyiwSThFpb/FYz18u/NEZ3EZsX9WbXvLgTdZKjAuLqMpwcB2OSahDxdMCy0GqEDPs2982Xttd5G16O+w/ogwngO/14zWTWnQpaRXjIwoW3guUkvV1r4DlxRql9Qy9xWUmymNSeeLmqtoqSitrO6UaD97hv9NKndPEjHpCSbtciA5T7jJeT0mNcI6hcTADCeE2Y7GTxjwzpPiWZIW5V2BgwYPhjGPf2IuVd8V3tHL4qSJooMcm3dW1tDrbV8a/6C/Ct2aU4dhJ8gVPfjRm20tPGyxCYPH1V+fwp7tRa0vg== 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=7EKteogOeesyTzxaV4DfyZtFTiETS7hlG3rkW/szOU4=; b=al+nPGUrqnJeMTgY20L1IJhQ0yJ8ZBQg4jN4IDJNaVDQXAVkt5KgfbjZYMMkHrJyIcjU5d0jQx3n4FylNwPU2ztC9xJk43oydv8KjHYGSX4Yl5Bc3YHaKLJ/OModda8KNSPsEj+xwoY68o9kusyzGUKkFvfD6J77eg8knvt+w5vKgv0R7YdOWxWGY551cLDzWPI6TftqaTarKfrFucutz0STfolF6XYUISqUzs/1e0aewfuLPHAS6ipD3lMMNRstEobVmCuKsuciPp7P5yuHVoqC0xHLfAlAGdgfCs+ED1Cy55/24XgwOTxnQpvsHufUCUu9AWiGADXcUmA7In6djQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1976.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:11f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 13:50:33 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:50:33 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH v3 1/9] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHa6ZnwG/WxED5nkkyW2eoHr7dbGQ== Date: Thu, 8 Aug 2024 13:50:33 +0000 Message-ID: <0DDD5C22-A42A-49F2-984C-F3595F71AB1C@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [ODLIA49k0W1Ax7ER/adytdG/QSwV/OXEazj5r9KAIjxT1d96d3z6mHeW4EY0VVxzxg1bRY2i3uI=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1976:EE_ x-ms-office365-filtering-correlation-id: 4244a65c-2058-46d8-3fd5-08dcb7b112e5 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: h4DenrEdIS/Txh8P7dUTLhQ3fq2pdXTJwQGMac+SmlzaGQ5Ks4/EzKLReyv/bbjF4gCrBZakrkH9K/kO/yDW5JQInYYvEriX3A9OWupeGxy8fTPz4p6+UMaE9FDgxTGmzyY3Pp3on6qZDAFT89YiWX09aBY5Z87U+DVrzaD1odI+sDGxwedNqFrA2AUDaNnnZ35Xa84g4Ik+PYST79w69m19ZQi3E4vgPP5jUqFFeYj8pORKM0sn1iMiwiM6AjWghB6aeWrDcK9sYQrD0N8VoLPE5JzcWR3RqyIelELO2ljDvcc8a3oHsL2O1r/QAJpJpzCxPf8x8zejhWSBXpMQyLcr13J52dJVZP/9LVRMQB6aorAd9Dhw1GaP7p6DoPu1Mwz32U6xxX2r+I/zy3CJb2dfQnMsH080f49MeKOak/EhzV2SuwBJAVp/Js/c36UskPL9CwRW5DU9OSPLDudy+UXPTmnjXX3j7bVYhrih3g5R4OzJ9othc73RFlFZFsz2xJeJvLlpGM4YMDnNem+lg7gJLVF1KFwAabsl7nbgA5vgUFksYmd2ORYXy3867v89sINr0vM7np9q2t3cOotXYoxvZ2COkshDSqhaana/Otrs4i03R6usGYZkntws8eEU6fY/yqq2q9kwuZotyqBHO6Fb7StDtH7Ef5D64IQ4Ezy+Vhq5oGwuEBGS6lBbhsul x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?Z8m0DwdwgA/9gXm2G9dnl+rCf42q?= =?utf-8?q?EXMTNeX2LeR2uRLuG1QSGi0MH5wgsc+NW13aykkF2NCPkrtX1gehoemgQQkru56fR?= =?utf-8?q?bA5jxbgd2uPxKw+sXPYJSKz3w2Q2hI49e8aporF/OcrBJIvIIASwMqE1a+VZCfxbL?= =?utf-8?q?U+R/Rgd/HStANi9FGUGcAzwBGRq/mvP26S548Cbb6BmIEaikzKtMygnYXB/SEV/4e?= =?utf-8?q?EY+QAPAWkD2CBl87FfmzmwtFg3ooqrRKOKNxOjQng51ncVHMr9yK5eaGf7LVYFG6K?= =?utf-8?q?l5VvaD3oWGQAuSjV+Udqx11H2/Rft6Uu8L9U7Ag7GJ+Lm3CwGvZcrbLxWrCf+u+fR?= =?utf-8?q?0Dz4rEuBwRCaMJrKLOCdfdIIvdL1xurc9GEFZPr3V6a/Awg3getOOJ8f28mAyf3cF?= =?utf-8?q?cfVzVbM21t2UteWmf3yHSqVXFrkMBvlU0R5yT6QyDcttN3mwsWIQOWwA/SO8iCj3c?= =?utf-8?q?/IGtI732b7HS4AZtLF8TD3Qsn7uumSPg9bRPK0Ij9EqrQxkeUQuzxpm80cBtSnW7r?= =?utf-8?q?3yGy+6ZCdGQa0W73B7BxtOOpPqFWPWwaKhzmDfxHbjdb5g4ZqSThikZ8B5R+P6AKB?= =?utf-8?q?JYRawUZwU3Z3bU+m+0s2qYi42pfmpOe1UPR1eWrKXYEtZrXVaLHkZuUTgRz01JNFE?= =?utf-8?q?anZ26nJPotK+nA4CwV+lcB8dfZD/KhlamwAsh9/LFSLK7DYb/gEQbbI2Jsi7yS3Xr?= =?utf-8?q?68cuhrpZU7BB8i09S+rxNTSuAsdGfqdN/aDmOYlN+jpwJnQGD3iltoYNBPZtXoSDD?= =?utf-8?q?GvF4h2IFGju6IQbyrNbCcAWRhkig667rdCTFk2OHxlaVRzb3SXci1HQwpS7VVb5Rf?= =?utf-8?q?V2dDaAxvXoIkfyIEYuvrxke6/v+2Wh7yxOL4vnT0L/ZmdUaSFiaiWGGfxlBj9vRA+?= =?utf-8?q?mlxYCMs8hB2ONK88Sq7p1JmicDzGS4GgHzs78FLutXwj/LRmq5pIOZ4eXFz1lZD5f?= =?utf-8?q?BfM1f5xNazeTfH5amKo9ZytzVBTChrcBLG9KaJaE0wxfcd3Wa2LvhrNnwFfAeEdWt?= =?utf-8?q?DD2Wsc/L2ZjxqZ8Hp3KTwWJJVO9RwUhBjFG7dEW3hAzg4AWwhSLWzhRidmMsvg11w?= =?utf-8?q?2KZh585D48oEl5xg1mjzUfqcSmo1zqMEb6PFkJ9l25OtM6pQCf4bGzF64NHCho92d?= =?utf-8?q?397HyBW6ihTZkY8Ka07O9MOOCIa5Akr/EJ1B06HXV9cS36Bt9g8fxSB2kzNhLOaAT?= =?utf-8?q?mq/rdsaPI7E9m0p/ovB4C5besXEQs2Kjz1Mgknc7uhmd/Q2nUOcwRjzuLRHH8pPvF?= =?utf-8?q?s+4AYqFFz8Rpqk3Z?= Content-ID: <35ECDD841152E74E890933E13F5D3D71@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 4244a65c-2058-46d8-3fd5-08dcb7b112e5 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:50:33.3639 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1976 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay This commit adds a driver for the backlight of Apple Touch Bars on x86 Macs. Note that currently only T2 Macs are supported. This driver is based on previous work done by Ronald Tschalär . Signed-off-by: Kerem Karabay Co-developed-by: Aditya Garg Signed-off-by: Aditya Garg --- MAINTAINERS | 6 + drivers/hid/Kconfig | 10 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-appletb-bl.c | 206 +++++++++++++++++++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 5 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 drivers/hid/hid-appletb-bl.c diff --git a/MAINTAINERS b/MAINTAINERS index 8766f3e5e..ac27f41d4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9931,6 +9931,12 @@ F: include/linux/pm.h F: include/linux/suspend.h F: kernel/power/ +HID APPLE TOUCH BAR DRIVERS +M: Kerem Karabay +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/hid/hid-appletb-* + HID CORE LAYER M: Jiri Kosina M: Benjamin Tissoires diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 08446c89e..4988c1fb2 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -148,6 +148,16 @@ config HID_APPLEIR Say Y here if you want support for Apple infrared remote control. +config HID_APPLETB_BL + tristate "Apple Touch Bar Backlight" + depends on BACKLIGHT_CLASS_DEVICE + help + Say Y here if you want support for the backlight of Touch Bars on x86 + MacBook Pros. + + To compile this driver as a module, choose M here: the + module will be called hid-appletb-bl. + config HID_ASUS tristate "Asus" depends on USB_HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index e40f1ddeb..1d825a474 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_HID_ALPS) += hid-alps.o obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o +obj-$(CONFIG_HID_APPLETB_BL) += hid-appletb-bl.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o obj-$(CONFIG_HID_AUREAL) += hid-aureal.o diff --git a/drivers/hid/hid-appletb-bl.c b/drivers/hid/hid-appletb-bl.c new file mode 100644 index 000000000..00bbe45df --- /dev/null +++ b/drivers/hid/hid-appletb-bl.c @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Apple Touch Bar Backlight Driver + * + * Copyright (c) 2017-2018 Ronald Tschalär + * Copyright (c) 2022-2023 Kerem Karabay + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#include "hid-ids.h" + +#define APPLETB_BL_ON 1 +#define APPLETB_BL_DIM 3 +#define APPLETB_BL_OFF 4 + +#define HID_UP_APPLEVENDOR_TB_BL 0xff120000 + +#define HID_VD_APPLE_TB_BRIGHTNESS 0xff120001 +#define HID_USAGE_AUX1 0xff120020 +#define HID_USAGE_BRIGHTNESS 0xff120021 + +static int appletb_bl_def_brightness = 2; +module_param_named(brightness, appletb_bl_def_brightness, int, 0444); +MODULE_PARM_DESC(brightness, "Default brightness:\n" + " 0 - Touchbar is off\n" + " 1 - Dim brightness\n" + " [2] - Full brightness"); + +struct appletb_bl { + struct hid_field *aux1_field, *brightness_field; + struct backlight_device *bdev; + + bool full_on; +}; + +const u8 appletb_bl_brightness_map[] = { + APPLETB_BL_OFF, + APPLETB_BL_DIM, + APPLETB_BL_ON +}; + +static int appletb_bl_set_brightness(struct appletb_bl *bl, u8 brightness) +{ + struct hid_report *report = bl->brightness_field->report; + struct hid_device *hdev = report->device; + int ret; + + ret = hid_set_field(bl->aux1_field, 0, 1); + if (ret) { + hid_err(hdev, "Failed to set auxiliary field (%pe)\n", ERR_PTR(ret)); + return ret; + } + + ret = hid_set_field(bl->brightness_field, 0, brightness); + if (ret) { + hid_err(hdev, "Failed to set brightness field (%pe)\n", ERR_PTR(ret)); + return ret; + } + + if (!bl->full_on) { + ret = hid_hw_power(hdev, PM_HINT_FULLON); + if (ret < 0) { + hid_err(hdev, "Device didn't power on (%pe)\n", ERR_PTR(ret)); + return ret; + } + + bl->full_on = true; + } + + hid_hw_request(hdev, report, HID_REQ_SET_REPORT); + + if (brightness == APPLETB_BL_OFF) { + hid_hw_power(hdev, PM_HINT_NORMAL); + bl->full_on = false; + } + + return 0; +} + +static int appletb_bl_update_status(struct backlight_device *bdev) +{ + struct appletb_bl *bl = bl_get_data(bdev); + u16 brightness; + + if (bdev->props.state & BL_CORE_SUSPENDED) + brightness = 0; + else + brightness = backlight_get_brightness(bdev); + + return appletb_bl_set_brightness(bl, appletb_bl_brightness_map[brightness]); +} + +static const struct backlight_ops appletb_bl_backlight_ops = { + .options = BL_CORE_SUSPENDRESUME, + .update_status = appletb_bl_update_status, +}; + +static int appletb_bl_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + struct hid_field *aux1_field, *brightness_field; + struct backlight_properties bl_props = { 0 }; + struct device *dev = &hdev->dev; + struct appletb_bl *bl; + int ret; + + ret = hid_parse(hdev); + if (ret) + return dev_err_probe(dev, ret, "HID parse failed\n"); + + aux1_field = hid_find_field(hdev, HID_FEATURE_REPORT, + HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_AUX1); + + brightness_field = hid_find_field(hdev, HID_FEATURE_REPORT, + HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_BRIGHTNESS); + + if (!aux1_field || !brightness_field) + return -ENODEV; + + if (aux1_field->report != brightness_field->report) + return dev_err_probe(dev, -ENODEV, "Encountered unexpected report structure\n"); + + bl = devm_kzalloc(dev, sizeof(*bl), GFP_KERNEL); + if (!bl) + return -ENOMEM; + + ret = hid_hw_start(hdev, HID_CONNECT_DRIVER); + if (ret) + return dev_err_probe(dev, ret, "HID hardware start failed\n"); + + ret = hid_hw_open(hdev); + if (ret) { + dev_err_probe(dev, ret, "HID hardware open failed\n"); + goto stop_hw; + } + + bl->aux1_field = aux1_field; + bl->brightness_field = brightness_field; + + if (appletb_bl_def_brightness == 0) + ret = appletb_bl_set_brightness(bl, APPLETB_BL_OFF); + else if (appletb_bl_def_brightness == 1) + ret = appletb_bl_set_brightness(bl, APPLETB_BL_DIM); + else + ret = appletb_bl_set_brightness(bl, APPLETB_BL_ON); + + if (ret) { + dev_err_probe(dev, ret, "Failed to set touch bar brightness to off\n"); + goto close_hw; + } + + bl_props.type = BACKLIGHT_RAW; + bl_props.max_brightness = ARRAY_SIZE(appletb_bl_brightness_map) - 1; + + bl->bdev = devm_backlight_device_register(dev, "appletb_backlight", dev, bl, + &appletb_bl_backlight_ops, &bl_props); + if (IS_ERR(bl->bdev)) { + ret = PTR_ERR(bl->bdev); + dev_err_probe(dev, ret, "Failed to register backlight device\n"); + goto close_hw; + } + + hid_set_drvdata(hdev, bl); + + return 0; + +close_hw: + hid_hw_close(hdev); +stop_hw: + hid_hw_stop(hdev); + + return ret; +} + +static void appletb_bl_remove(struct hid_device *hdev) +{ + struct appletb_bl *bl = hid_get_drvdata(hdev); + + appletb_bl_set_brightness(bl, APPLETB_BL_OFF); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +static const struct hid_device_id appletb_bl_hid_ids[] = { + /* MacBook Pro's 2018, 2019, with T2 chip: iBridge DFR Brightness */ + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, + { } +}; +MODULE_DEVICE_TABLE(hid, appletb_bl_hid_ids); + +static struct hid_driver appletb_bl_hid_driver = { + .name = "hid-appletb-bl", + .id_table = appletb_bl_hid_ids, + .probe = appletb_bl_probe, + .remove = appletb_bl_remove, +}; +module_hid_driver(appletb_bl_hid_driver); + +MODULE_AUTHOR("Ronald Tschalär"); +MODULE_AUTHOR("Kerem Karabay "); +MODULE_DESCRIPTION("MacBookPro Touch Bar Backlight Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index e0bbf0c63..818d41a35 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -328,7 +328,6 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021) }, - { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, #endif #if IS_ENABLED(CONFIG_HID_APPLEIR) @@ -338,6 +337,9 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL5) }, #endif +#if IS_ENABLED(CONFIG_HID_APPLETB_BL) + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, +#endif #if IS_ENABLED(CONFIG_HID_ASUS) { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) }, { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) }, From patchwork Thu Aug 8 13:51:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E73FEC52D6F for ; Thu, 8 Aug 2024 13:51:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5425B10E739; Thu, 8 Aug 2024 13:51:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="TZoXw0bf"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2033.outbound.protection.outlook.com [40.92.102.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 625CB10E739 for ; Thu, 8 Aug 2024 13:51:37 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kIt9plZV2LQSVQSfc907Dbq/i1iMmL+vbY1zpaAYsylslZ6s+7FhmBuj6xNUMa1Dn8kIYVk0LQQP99lfufJnockGBVpIzTf+eTH0CQEIz+Dx3809sOzA00Cv+M+yohLdYkerO8bh7b/UZYa2wf35W1JFjGWiKmlj2h2yb4ex+MyfvtdPx8cpWc2YEb9quaAXYHgYAiMyDf0QDeqKPn9FeGg25FDvVWhY87qLQ+OYwrrLUst7hBXUjAXfB3kbav8wrB/dKKQHEyQEsDBJlt2TxAGquzZQK2CooYlkYIWRHPORwB7gy+BNSLWpTbXEsSGbYpbeRDZPL72QXCPA5dOHSQ== 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=CsA1hnNTXp2yszqw6dH+qhYAVj0Ncj6wszR9ARaW9Bg=; b=EJxf2mBp5oBnK2FtVk3Vo+pqChskK8V+qN6OOLFxUcAGseDgTU01EBTpjgJ+Byje3UuHXB3O+r51OaITHfL/koEZPn6hT+0p1Q+5LDIhVY4L84iHo4NpzHNRyf/H+WVzCnw/Tzo1JAKfuokEziPnMIBaje8CWjHsAl5mQEpZk21d3+NI7T2JzYl+N77paFKatQrNFxaCRQfV2zGzg8GEiXBh+5MQc94KaM4btdjnKG2SxhggzWO+HadiXz9LLwRqPLOKlSqHIlYikEjBIfhzly5GVmIAt9GoAT4oKWCAqFvpkoj2xlq8BDwQ7LvgK3boRDH6RHuXwd91N8eH+OXI0w== 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=CsA1hnNTXp2yszqw6dH+qhYAVj0Ncj6wszR9ARaW9Bg=; b=TZoXw0bf5fPzMj0HsM2JbbJLT++FmTBGMo5F3Uob/Zu0hNyQFhFaqzEOL+OzoKVqtL1tJx8Qi9lDx9s7MYNy+YHS4bej13uuPgtgCVZIWnvn4trsOqzdK0YCi/FnmPM7KlTyIwEPYUw0PmZg0oZpEDInLjH8GrMYJSqviS47msmqnuLAW3uspb0hebaJplCp599s3ibON8ydfIh8Jr/2r0Tkk+B6t4zK9sxcpTdgpM5ffrtJyVmR8bT6NlF6Tmx+UeabJIiCzbkQK3MfsCx5IaoW8MPLI63UzgGOu9+pYJ73asijBoKKUSribA4sucBUZ8CJkhZ1E3eVBHtk2xOLpw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1976.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:11f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 13:51: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%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:51:28 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode Thread-Topic: [PATCH v3 2/9] HID: hid-appletb-kbd: add driver for the keyboard mode Thread-Index: AQHa6ZoRlngOtLuKXUS/2vc/wywlgQ== Date: Thu, 8 Aug 2024 13:51:28 +0000 Message-ID: <53B2748D-FD87-496D-A926-441356EBAD18@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [UnYFSFvv+q0Qon/HVpUcKPGEevtR/IAIjPTkfqL7kaNBrHAsWpqLZN7J43QIgxQc0MwLm0w3kMY=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1976:EE_ x-ms-office365-filtering-correlation-id: 7885be1e-aaf9-4965-2ea3-08dcb7b13398 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: uBxmaw57Lay5xVt3l2o7/EDUmU8bSVvPex4dYoi1DRq7EJQDBSq5CZDLD6vqwyD0arp9Ey0fyB+/FIyAtQvRNArnX3ZnCSMQYYEYtbze5aR5RzIY5yEoBPAesMEw9dGaPTrbAwY9aWiRX7PztsVnXAEKvLbHKrUNeieaCu6cGrF2u19iPadVjtLT2G51tTExsHFKL1bks6f36zNG4yVk5nAQtSZ7nVRZrKLUZCG20+hZU+gUOdVWq4hGgbue0hcIpFpfRNI//kbM2TV9Ld9cvmHCHfGgo8ak5uvG/IW57XZZCIIE0NruxSDFdB7wFNkZuHHO2YCnE3aUdft3efau5DIn7ITd2OqpKtIUfXnpZh4S8r56zSEFzbQHv6yUsoqIiTWEJb43cR2jguDOkOwx5Pq6v7meFEQxeIwM92P/VRpyNGUZFCmvAn0lsratGbr4+i73S1n56qLLXZq9opn3AKin6DyE9miJilYKytIdPBdRPu7XyEivLLcpcDPV7ZC93N77p+rzAuhzObnLAgjOJSjrfq8M9zZbZDx+Rf4TR+J2qkpPVDn73qg0B7lFkgPmIdrU6jaV2Dxd1BX9yzes2SuWMdHKrPCDK2dscy7G+mf1AAOzuk1HBUjmsYVn7IcXXavOnv7dt+juAK0C2Nf1r0YYlZqbeZbbZ8eWPZBTWsCvXBuGFsm9r6KgV6FvGQa9 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?mS7nDx3rGT/yAcMXOL4Z2xmqXOy0?= =?utf-8?q?hvb+unAUiAhcYBxApz5QZYHDrsS8B+HQzO1OTL2RKSM49mSBI+BiHiS5lcu554G5i?= =?utf-8?q?C2fvdZtMAK+G9zF6WcTn4XqJWQBVpPQGSCXE1dNDAavt6IE2KQ4L+UMIRnnShrmce?= =?utf-8?q?kdSgObrasQPSJtmclU1D7ZFx1kt0ZxeNHrEG0WGEz0tenM2vf7GJ9xtH4Y7ODABFC?= =?utf-8?q?wwWIrtBzOyOh9hn1YB2H9F1Tl0SY3WGbujbW0q81GdtdFX6ND7o+aVw9qT9ezatNz?= =?utf-8?q?EckSlpJi6WbRXsffH3sODUb08J2eOFSYJMKo1KGrzLa02BH7Ur0Q5xAIjOBCaIuSM?= =?utf-8?q?FH9gOwjoOwp3+c45sj0NZfTK3rEA6lscybvqTOW2/vRin/F5gtHQPECn1Bpk/OKYW?= =?utf-8?q?WFrsl73s66ch+iJTltssEKZL3pbOCnbjmx1Dho6uD3vhZAMpfdfP6NTOxDWNFgVaT?= =?utf-8?q?EL5nrGjTfY5wRbHbML3ApPBvgRrs9awiGCkZpOk4o8BTcqziDXV+6QJWRV6yWqgdC?= =?utf-8?q?Zjk+RgyLC+V1zI4uosrtggM3NlaMEiUoKNigMfCoXkjM0R8l3gwW1XE0hCZFWy/cL?= =?utf-8?q?XTKUP4PpIC8id5Fle0EK5uPn3MD4f6FLwZiewIZ9gaVHPAnUxL/ZIU6pgR0oAxf3l?= =?utf-8?q?D8kFd3Ux4TwGHFAbUyc7x4KUT9LS9ocgyfzuKY/ZlkUudaMtaXJ6ykavZRvwYYL2F?= =?utf-8?q?FTxYNFdpy8L13Z+cHmJ9BoY+tVFs6PbFFraoX4n2ZtTmYBDTI14qxTlRYWU0bPki3?= =?utf-8?q?2ZsWn547nZvdYph/NmRD3DA10TKa0kmkLWBtAqOAeCTW/Whgtga+1vgnG4WniqCEQ?= =?utf-8?q?nntpbnL0ucbc3ZgGp+75R/lHMZAA8iLO9LTOLfQn1+8o8HzTRPL/wdro5yxPQ3zaw?= =?utf-8?q?IhmRZ/3ZjLJmsi3j548V0aZgLD/g1sT5xMGlrehTbAz/sFZN1x5cjtq0cjsmH0wJe?= =?utf-8?q?hGjaD9XXFJaU6QI4NUajEtQEg2GPE/C4kFiyG/LgbW796Adc5J8jD5U3cya/TyECk?= =?utf-8?q?gEZfs5Xymk89EqpiREwO8P8kUw5b4mbQRYEJV9Rv8HmfI8IQ2S9WNFnhpeXijSQvF?= =?utf-8?q?WylAWOjT1o+zPBuwhmQ9NtkchcGZOL0uYLt3xA+Oqk2oIY+9bwzU1UTx/XFVrkJsk?= =?utf-8?q?Nau1Fb0t7ctUcvScIO8CkCFWyAMFeflK6GcZNVbDC0akXYSKOep5qyIbcEAWOGa85?= =?utf-8?q?dLYLmjE1Ri7vIhzibvv9g1I0r1Arx/vsAPMT7cTRyqQdyRjjFtNlqW72W+87wEj74?= =?utf-8?q?mWOTcah7aO4AjcRP?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 7885be1e-aaf9-4965-2ea3-08dcb7b13398 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:51:28.2165 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1976 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 | 304 ++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 5 files changed, 332 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..e07d57573 --- /dev/null +++ b/drivers/hid/hid-appletb-kbd.c @@ -0,0 +1,304 @@ +// 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[] = { + { KE_KEY, KEY_ESC, { KEY_ESC } }, + { KE_KEY, KEY_F1, { KEY_BRIGHTNESSDOWN } }, + { KE_KEY, KEY_F2, { KEY_BRIGHTNESSUP } }, + { KE_KEY, KEY_F3, { KEY_RESERVED } }, + { KE_KEY, KEY_F4, { KEY_RESERVED } }, + { KE_KEY, KEY_F5, { KEY_KBDILLUMDOWN } }, + { KE_KEY, KEY_F6, { KEY_KBDILLUMUP } }, + { KE_KEY, KEY_F7, { KEY_PREVIOUSSONG } }, + { KE_KEY, KEY_F8, { KEY_PLAYPAUSE } }, + { KE_KEY, KEY_F9, { KEY_NEXTSONG } }, + { KE_KEY, KEY_F10, { KEY_MUTE } }, + { KE_KEY, KEY_F11, { KEY_VOLUMEDOWN } }, + { KE_KEY, KEY_F12, { KEY_VOLUMEUP } }, + { KE_END, 0 } +}; + +static int appletb_kbd_set_mode(struct appletb_kbd *kbd, u8 mode) +{ + struct hid_report *report = kbd->mode_field->report; + struct hid_device *hdev = report->device; + int ret; + + ret = hid_hw_power(hdev, PM_HINT_FULLON); + if (ret) { + hid_err(hdev, "Device didn't resume (%pe)\n", ERR_PTR(ret)); + return ret; + } + + ret = hid_set_field(kbd->mode_field, 0, mode); + if (ret) { + hid_err(hdev, "Failed to set mode field to %u (%pe)\n", mode, ERR_PTR(ret)); + goto power_normal; + } + + hid_hw_request(hdev, report, HID_REQ_SET_REPORT); + + kbd->current_mode = mode; + +power_normal: + hid_hw_power(hdev, PM_HINT_NORMAL); + + return ret; +} + +static ssize_t mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct appletb_kbd *kbd = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", kbd->current_mode); +} + +static ssize_t mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct appletb_kbd *kbd = dev_get_drvdata(dev); + u8 mode; + int ret; + + ret = kstrtou8(buf, 0, &mode); + if (ret) + return ret; + + if (mode > APPLETB_KBD_MODE_MAX) + return -EINVAL; + + ret = appletb_kbd_set_mode(kbd, mode); + + return ret < 0 ? ret : size; +} +static DEVICE_ATTR_RW(mode); + +struct attribute *appletb_kbd_attrs[] = { + &dev_attr_mode.attr, + NULL +}; +ATTRIBUTE_GROUPS(appletb_kbd); + +static int appletb_tb_key_to_slot(unsigned int code) +{ + switch (code) { + case KEY_ESC: + return 0; + case KEY_F1 ... KEY_F10: + return code - KEY_F1 + 1; + case KEY_F11 ... KEY_F12: + return code - KEY_F11 + 11; + + default: + return -EINVAL; + } +} + +static int appletb_kbd_hid_event(struct hid_device *hdev, struct hid_field *field, + struct hid_usage *usage, __s32 value) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + struct key_entry *translation; + struct input_dev *input; + int slot; + + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_KEYBOARD || usage->type != EV_KEY) + return 0; + + input = field->hidinput->input; + + /* + * Skip non-touch-bar keys. + * + * Either the touch bar itself or usbhid generate a slew of key-down + * events for all the meta keys. None of which we're at all interested + * in. + */ + slot = appletb_tb_key_to_slot(usage->code); + if (slot < 0) + return 0; + + translation = sparse_keymap_entry_from_scancode(input, usage->code); + + if (translation && kbd->current_mode == APPLETB_KBD_MODE_SPCL) { + input_event(input, usage->type, translation->keycode, value); + + return 1; + } + + return kbd->current_mode == APPLETB_KBD_MODE_OFF; +} + +static int appletb_kbd_input_configured(struct hid_device *hdev, struct hid_input *hidinput) +{ + int idx; + 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, NULL); + + for (idx = 0; appletb_kbd_keymap[idx].type != KE_END; idx++) { + input_set_capability(input, EV_KEY, appletb_kbd_keymap[idx].code); + } + + return 0; +} + +static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + struct appletb_kbd *kbd; + struct device *dev = &hdev->dev; + struct hid_field *mode_field; + int ret; + + ret = hid_parse(hdev); + if (ret) + return dev_err_probe(dev, ret, "HID parse failed\n"); + + mode_field = hid_find_field(hdev, HID_OUTPUT_REPORT, + HID_GD_KEYBOARD, HID_USAGE_MODE); + if (!mode_field) + return -ENODEV; + + kbd = devm_kzalloc(dev, sizeof(*kbd), GFP_KERNEL); + if (!kbd) + return -ENOMEM; + + kbd->mode_field = mode_field; + + ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT); + if (ret) + return dev_err_probe(dev, ret, "HID hw start failed\n"); + + ret = hid_hw_open(hdev); + if (ret) { + dev_err_probe(dev, ret, "HID hw open failed\n"); + goto stop_hw; + } + + ret = appletb_kbd_set_mode(kbd, appletb_tb_def_mode); + if (ret) { + dev_err_probe(dev, ret, "Failed to set touchbar mode\n"); + goto close_hw; + } + + hid_set_drvdata(hdev, kbd); + + return 0; + +close_hw: + hid_hw_close(hdev); +stop_hw: + hid_hw_stop(hdev); + return ret; +} + +static void appletb_kbd_remove(struct hid_device *hdev) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_OFF); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + +#ifdef CONFIG_PM +static int appletb_kbd_suspend(struct hid_device *hdev, pm_message_t msg) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + kbd->saved_mode = kbd->current_mode; + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_OFF); + + return 0; +} + +static int appletb_kbd_reset_resume(struct hid_device *hdev) +{ + struct appletb_kbd *kbd = hid_get_drvdata(hdev); + + appletb_kbd_set_mode(kbd, kbd->saved_mode); + + return 0; +} +#endif + +static const struct hid_device_id appletb_kbd_hid_ids[] = { + /* MacBook Pro's 2018, 2019, with T2 chip: iBridge Display */ + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, + { } +}; +MODULE_DEVICE_TABLE(hid, appletb_kbd_hid_ids); + +static struct hid_driver appletb_kbd_hid_driver = { + .name = "hid-appletb-kbd", + .id_table = appletb_kbd_hid_ids, + .probe = appletb_kbd_probe, + .remove = appletb_kbd_remove, + .event = appletb_kbd_hid_event, + .input_configured = appletb_kbd_input_configured, +#ifdef CONFIG_PM + .suspend = appletb_kbd_suspend, + .reset_resume = appletb_kbd_reset_resume, +#endif + .driver.dev_groups = appletb_kbd_groups, +}; +module_hid_driver(appletb_kbd_hid_driver); + +MODULE_AUTHOR("Ronald Tschalär"); +MODULE_AUTHOR("Kerem Karabay "); +MODULE_DESCRIPTION("MacBookPro Touch Bar Keyboard Mode Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index 818d41a35..7c576d654 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -328,7 +328,6 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021) }, - { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, #endif #if IS_ENABLED(CONFIG_HID_APPLEIR) { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, @@ -340,6 +339,9 @@ static const struct hid_device_id hid_have_special_driver[] = { #if IS_ENABLED(CONFIG_HID_APPLETB_BL) { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, #endif +#if IS_ENABLED(CONFIG_HID_APPLETB_KBD) + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, +#endif #if IS_ENABLED(CONFIG_HID_ASUS) { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD) }, { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD) }, From patchwork Thu Aug 8 13:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757496 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FB3DC3DA4A for ; Thu, 8 Aug 2024 13:52:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B2E6C10E73D; Thu, 8 Aug 2024 13:52:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="fPKygb4p"; dkim-atps=neutral Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2094.outbound.protection.outlook.com [40.92.103.94]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7568010E73F for ; Thu, 8 Aug 2024 13:52:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vV+llHRNt5/U9lnnRfBqlGJxAjxNtbn767cgw0PvDH+KYsPTYgsSTrRma0oFUCrQobOTJM/xE0jVxiKIkXinxs2+PHHnMisgSRmrewTeWndxPuX8MI81Hog6P8iDElqVMRupPLFpC9GJxltN1ZqrhhNbFP9VrWKfXYqfVCGjXtFrRqvHLw6gyAi6fjtqBsMGYLKfZBY5rkxxtYQftv7rGV5GGwNKXGqDJ4C4vYYm8GTxqAbICXZy/EN9Ezw7xbYRK6vwcMJq43GvsJ9VHQbgm8oAso+OMZ9JbwB3Om6CwUsvfowLKce/wEs5GxYHrsPjV18yBMwUIe4089zQhpokiA== 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=bzJQNbir3aksonInPunSVUKKA+KLTVCBzdPlbfwum3A=; b=NzRcxtHm1G7Yxal3JfSbuA8cNQR6xCO1aCjZVYf6ZYNPhs5TPlSgnV7XtPLFdKAB5y/CiOuWoUsLaL+aH3PS1s7m35CMggeWBIBUNFQwUKMIlyn8kKFmyfKHngAf0P1n1+bxsCG1Y0m/f+WkIczehK23tuHT6ZJJGaLTtQDyvXisKckGlS4/E8CRIMGNO8V4HEZUxcsXxSgIWVE5dVJgki8mURyjL0b++zij4BJPOWguvCXLIvNW6XdcJSXnFTTR0FPVVfZIsyDknzLZUAUUfdWRUFQdX9H/16izjvNL9YseaFLjeiyiZF8qSwywcHEzBvbcWCu8QsVBVc6Axgf1jA== 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=bzJQNbir3aksonInPunSVUKKA+KLTVCBzdPlbfwum3A=; b=fPKygb4pH1bsUAroDwYrrlcpEpyXfxPUl0tGb+Ryq62nnPwkWVRTtekUzcDfqBZxDeJsEOq0dHnsl4/eAZJ56zbzBMBzFjeA8YZ7UX3OzeYkK3QfkIwxI2Uu2PQ9coobcBxdaQNDDbVU3zYh5zXcZZFL1eQKLA4o+yRFIUDAgn7YoUOI4rLgRDlGh+0z+piXf5bwxdMf2E5OuXkgckhr87BpJ20CitCccDd6GUmquLnAIPdRDnn2X3sEVFQDvzLuyQzYEEhtib7W9ONz8ODFG5Pu0LyWQsfRFMnercqnRsSd1YOzTxDuELCGtWolp40q6fsgV28jqNCQ6wiO5s++tQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by MA0P287MB1976.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:11f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13; Thu, 8 Aug 2024 13:52:14 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:52:14 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Topic: [PATCH v3 3/9] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Index: AQHa6ZosbH7BEGdHFU+LQ2KDcb73fw== Date: Thu, 8 Aug 2024 13:52:14 +0000 Message-ID: <949B2D47-5E20-4B0B-9441-5B41610AAE64@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [Rv2nliO8yvlGTGaj9NH4hhG3ufImDZ4F+yHiEDW/GIrEKPCQBosZgV65ZoEvep3Jvksfc/g3qnw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|MA0P287MB1976:EE_ x-ms-office365-filtering-correlation-id: 18d06f78-6ad5-43b9-0f5e-08dcb7b14f08 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|102099032|3412199025|440099028; x-microsoft-antispam-message-info: a1HF8TCa1+FoSPJ8ftTcEAIs4U++FZmyiZltWgzFY9VlFfzoel7jgXX5PYHbh985qhLfO90T66aHL3izYt8faHgsrL9syroS/c5AWGGoZ91jRWVYhFVcyluh4K338z8PYlEdLR/6Lmbr5cO5hP+f7ipfn04mocRInbvb79QmZ023ml2pnqaUz4ZsB/jJxjht8TxmuNVJpl+flA/JC0MjgxH5rKhgw3VD98ra88LXxho2TZybLbT50IajlPU4uS6D+/+JoeAOz3DQdg/7h6D7Y08upZfQTN9bdR0h2BExdGuckQkmpMLDu7ttz3nJ2FiFuFNG7dkW2wQ83IUdBAN4v+NJ3vgtMmqplb8kZoBMnak5xsGLX/q67m1+0oFhCbRUOUrJSmqI8U1rqvx2agIFaTb3KU5wHp/dmX3Igoq/A1CDCCmTS91UfvA4W05QzJ7XKUaMzqdw4sQK8x1dArQaiuSB93z/Ui3IzHqlctrZ1pu6K1Xgh0qToa9JS8c9bicP0aE1LiQ+9UGPA+kYeXhdv6AH71lq8h5nvSXcRug+Xe87YNdu022tzFbrzbUfvXt8KwPJxr55u2/S/zV+mzzqR+X4BIum/tBVWcmdYN9vaY27MB0oj1HoQzNeFx0ZlB8pDGLEs+u47HkuX/ePG2qNaSbv76/jtPAXgPZG55bTFtZ7YGGKaf9371zI72tkYQ+d x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: nC8h7o0nP6RQFBWg3poWAvvZzNVfB/hnkhoTA+eXw1cu9IiiE2veXRa4fbT9GvPQMHq93FkOj04PeXagjoZqDw5hFBSPDj+ZvGB1MnR26zwwtNl4gafMro+9a7+qDsnmxIaDGIt/WxArpcIf8rejZnZBJ2YC6OvJX9V8RI0jA593U5h0DjuAsxxdGf8+Hg6GXcGfp1PB4fPSroaeiHBjH6QXE4vhiw7WFDigFc/pz8POAPeMnM3zgzY59b34FQiN2dhCVQPMkSMnhlD8jbP7Qku9+yCnEA6EncTAfCnnJGwy86i732lkPPCfhgQbaKKhO3VftMSn3O3JTsQBsJH4Kr7t+PuDsJniSsdk+KPQSOxt2n0khQxA5X+z0hcJqwRje6x92I8ZcnisjN6opo4cao53aMlu4+7aVPNmsIfuHv5olmw1O6c9VsMZ01FLTuCE4EP6GzqjRQlYNeCxPpQRNVqvh8oQz0+bIp5GY47XpM8PPxfQBAJdcTOi4bbltLM+5pCPSRYZW5EbG5K8W0Sp1MwMjUPgcb4oyKWyJhT8vaYa1XRnuJezCye1454m3LODRQA0H8q1AjyJ02CYqqnCTpw8Q2svAgVUcJKlmk+sY20EnRDm/pMOPlZn6Swg0nD+kKkAMcR7pPGqqGcIYHLBGlSDEGsdJBKBjB/J5IhxklmwImYBtFkfrhzOgt14EF4rKpbMaggxiIizERb7oJ3x76jFBKVzWbw3Me+1+bb281QcKMJ8pgdeWA0DIPPg6JArHy27+gaSrhXqCGTJPjTW92Z4z7wAAMQYL3gX0d/efa9x2foxtsfpUK4ytgEzf6MEuDDbP1Ija3ZApbygTeSlweZ7EH7ZBuPzD7vv1Gk+Qwx0gazVaQ3VVsvYH1ZT22XHtjs930GFfXz0LfQ7D6Lkg0FIs6ysZYEaVVqurMf77r9hPX+xGYMgVrju1Fy2kYmEQowLA/yxY1W3KgjS2fO+Z++T9KoAtOcmvwechpDNIx+mHN4l7CcNBarKFkd54gHamYPYBFyQa4F6pzm+E7cRkcDKttbVKlpZ2zjDXECRBKzwJwPWHq5WEZfqJAKcS36lJJMwT4DhRltBF+ON0T7cZIWbwAEkfUBd3OeNzxRmGuBAtobJdPrmGYD9jFeoNppf1ygqYEwJyhhuNvVj6U3BsksYrNM+ThFpPnHXJBXs+pbVv+Qr8UhOJqWEgyukrVlUKSNljAaY15fzAoHGwfyoAlbG/AsItdLry9BzEhmtqzi+xG5YfjAYpLsOJggI6nNT+rUON1ftI4VxziJQ/vPDGfySYdnKxIcUuUBmp3CHIQNOcanB9ijU+VwSofmrR1QK Content-ID: <4AC668852276794088C2EFC0245F1E30@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 18d06f78-6ad5-43b9-0f5e-08dcb7b14f08 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:52:14.2733 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1976 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay This is needed to support Apple Touch Bars, where the contact ID is contained in fields with the HID_DG_TRANSDUCER_INDEX usage. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 56fc78841..3e92789ed 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -635,7 +635,9 @@ static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, if (field->logical == HID_DG_FINGER || td->hdev->group != HID_GROUP_MULTITOUCH_WIN_8) { for (n = 0; n < field->report_count; n++) { - if (field->usage[n].hid == HID_DG_CONTACTID) { + unsigned int hid = field->usage[n].hid; + + if (hid == HID_DG_CONTACTID || hid == HID_DG_TRANSDUCER_INDEX) { rdata->is_mt_collection = true; break; } @@ -814,6 +816,7 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, MT_STORE_FIELD(tip_state); return 1; case HID_DG_CONTACTID: + case HID_DG_TRANSDUCER_INDEX: MT_STORE_FIELD(contactid); app->touches_by_report++; return 1; From patchwork Thu Aug 8 13:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0710CC52D6F for ; Thu, 8 Aug 2024 13:53:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8060610E73F; Thu, 8 Aug 2024 13:53:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="RjPwogfC"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2066.outbound.protection.outlook.com [40.92.102.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D95910E73F for ; Thu, 8 Aug 2024 13:53:12 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UejA/jTKEO0VX50wtMXI1ua4A4nzfi5tD8jGMVrUA+1goXcTtZ/UevVVxEWylLblNYi5lAckQa3rtDob65cPy4lKuMLKaZp0+YIUaNgq+bjleDY0WmlYcPtFwPIMtMsRQEFPCS+634lZ0+9vCIYtFSFgozQMUYjbmL0MsrF7tzuz/+u+4rZLSOHZhsKw8PyfsHFAO5ZPCnRqXhCO+rnfU9tnCqtFO+aeRqF8WKmBliF0urMZDjoPUjyGaP//3BLsY5JVxG6aNrhMmkpCrH4CzLAz0/DNmMKMbRGtRtdldFRr/7z8QSqOSzaND/APcn9Q0Ra+KvtIVFb/JsTARgX6+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=h/M4++iAmn1Gaoqm3MUsaJ8DQ9c9IraC/WVg+YJZvGzNgPUEEZQ/ZAJyPlp2UYcK9uGRWt92yI01k+KeddfJWL5pt/N1/4Yfd1d4BArZ4Xgn7+3njw5Xr3cRpLfZBV42akDYlGTlY+xpO9HTJ/EVuiLxT1u4X9EAVZqR5JbBpP6rQxi5bOKKWtdCpiQWNXTLk+m1AjwM9TZwmEpsAf2ocoe5mlftEr1dx6agOz7AgcZ+SahtcUFoEjXfOEWo+XbbJcvsDHstK/KRXr/9p/80sIrl+x9oh/y29SMZmzaTwAVOgDTFlKXbzO19XaJoTOJnH3LL28mNuSblvjk1juKVHA== 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=RjPwogfCBDle2MYcRVhRPP8C+4ir/iaq5i+MGqbvfAsN9V5b/EKyKosxXnDPo2EqU0wmxFkK2HXAph5iw1vcgRmjS2aU5s/yM2PqqdqJmnQmmoBHHD2fI5j3otxnILd3bwxgb/7WI5PeDTttn+IIoBi0PQvdAjpbRnVeJ48KnhFHou4AKWXwH2OzO0dyeu0zQNAUEuqa5VOOcbc878ZUH7fKd5cJcYYADQvw14SXIsRF6NhZqMOgIweZQWkcJn6jxGYJbPwL11cdLKJmWH8+rbY3B5FtT2gKQBN8kBEqMXYZxGekSSw9A7d4CxvcueKWjLYxxO3sZ12L6arKKlQcLg== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:53:02 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:53:02 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Topic: [PATCH v3 4/9] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Index: AQHa6ZpJi1XsIfPSFEmTHJbeKBGApg== Date: Thu, 8 Aug 2024 13:53:02 +0000 Message-ID: <7EF8DEE8-61F5-4BF7-875D-FB71B97D8BD2@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [Y7GMhV0wAi5NTFmeaZWGqNPbgNhmc+xeMJG8KyuvviJBtulQAGwaCptFrI0Y3X0Uh1y7OFdFDy8=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: b6248076-4704-4dc9-6736-08dcb7b16ba4 x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: 5AOtTEaCJFC57aaw5nR4mcbUkFg1FGsK7ROM+G3UBmPAPEh00r41DEBYpm8zayvbssKEhI7hDcmR3W8RcvvpwsNC42DKy60av6JV0DFy14OwZZBSd0t607MeOzdrankpVO+nwuOogOO0CGGZ+Al9jIIfMRc0+4SKWejPyUQgW40a9WXFriR//fdHyAuvP4iwlkMHhmqJ66VDnLGOK80Vik4n3yXsfZB4vWI2cxVuvH1xXWo0JBCbqqTE9AufJMqAEay93JxBuDeEamiUkbbQCD+CUVnGZA5XxuSgF1E9UqIpZxF2B4nGbVAvsMJiBMZ94Jhgj+xJEqDV7tumrQna4/FKcQMVhAZ6T0Yyq0tCsm2Rs+vW3gMa6WJaUGvAfZsm1O2rL2kj4RgAGpRp3IH3ogDo2M77oVG/pQ0GIOqVFGbXNFtbZhUTILUG1fuiTmsywP8oCweqqmhvbSG3vckERYC1rsb2CD8HLNEYp0brODyoEeCcBjOp5vVrFHDr6vaICNEhGVjnvIRnVNl6vgEXzWs81C9eucVLkyEswT1EpIEN1S9lG4lWmWzh42a6+C4bj6BMdT1RYy2BJ6QP9/V7jg8gLZlmR5SlUv2h4yLOP40ULuGV4eiUJTH7fT4CjZ7ChRoY/BAZa0LRtYPuDP0zr1XR46s4jFe7UV+CaQYo3BuMCfUgwicF8OJb/RT23iSr x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: Bk6byxcV5c6m3z4cGiYYXEXxkP4C3cDRc8h1C+aeampaX6Dyg+QOzyNBEvDSwS1lYHJxw+a2vmZToJV+9zvb7lZiYUCRv6FOo+opHBY3T5y1OFC4Xhc9AyufZhUDD5vx0LN8IcL5rumlSX2OvS8HhKsQ3L84i8h6zS9qBwyW5GvE94tN2Eo5m5pTJ46XmGLrTj2IDL7JlAiziWRWJO4hZLLU/TVZ03ZhIMbNZejnadAgnp8tvfYJFwomXNlKy8SUN3jSjkJTHse2zrSUkCqMsvGdIvd9/9D0heLRRbsMUIvParZdqD/+P6lee7wNObyUXlvxqa3nKS54nd1fhfGIftA4l2wjf3Dipcf0yQOZBZRX9sXTeaqTzkBPY0eF6Wlfx8Lo7hDbaQ6lVFT7U1ApVS6D4w0glRyvo/Gzzsf+cFbn+xnAZ83GsDvzTObmO2en8VXFUSTWraOIZ5f2N1opCDg//oFa49X2DB1YVegMdGrkYc31bqYuKKd7HR7WytKgjoTLKDM0GfIgqCif3X15nkUSograJ4lZN+Z3pOY3rTG35F7/jZYc7x/ugegzuos6TMvtNM4lX+8vEmqsF4HA5cZyqmehCbJp9OlnZH4yoGsx+oLsu2GoJG09TNzgfg7q8SCpKyG3CPzawjrVmtdxaiE0FTMrhwE8Egt2W2jZns0MmRbXjvRLWdUrLxMJL7R5m1EpHw84t/AGAAcFmDDtLVStPvW7XtzflBf9sYDWjz5c+G05mq6ByWNohnKKmwUoMoe8pNeO/xHxbZWi6VhEOC+Lp9O72Qqr6NoEo8YJg9Sx+3uIzHkhMTPOmrejeZHdQjxO8gpy7CfWhKxukVvfWMcIeKgcdn08r36Ac0LnQPKzT0Wd94f0Pa/9KdO9n1n/LFH5hVmwQ11sMsdXuNxNuOKPyY6sWRykoBR0Tm7DeRAM482WNuAoD2wUjZgPhzyTiIhz9tsxF+hchniHHwVMI6Q36/B+f23eDPWo2cJou+mgsq3Q6gzIAlNMqysbjM+VErDHzE4/fJc2Yqt+afCdtpfuZ8dHh7ZGX5UMUdotIK/mu0FPELHIUCFSxIBl6E/hRqa8bkjSrKhmYECquLPAPZnrk7b3C53mL8Ss+xPHbS2ff0M3QR6YDLJW83QjqwAcN2KSRrHGZrBGlapQnbxP0++wZ1XnELh6j769dIdijyZFEAKUXKoz3zY77v5sR7e+IPV7qmsPwoh2X3XsOKcsqyIkj0cWb3A4G+635lus3+I46ctiVY/adiI3j1Rw7RPu8tPCahw9FDmLJJYdSXtJ9IrVUB3x21j0OcpeNrxg4UhIFNWpQcWwZV4tYqtWw9dJ Content-ID: <1FC39766D3F9F9478B80AF62C779BB21@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: b6248076-4704-4dc9-6736-08dcb7b16ba4 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:53:02.2451 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay This is necessary on Apple Touch Bars, where the tip state is contained in fields with the HID_DG_TOUCH usage. This feature is gated by a quirk in order to prevent breaking other devices, see commit c2ef8f21ea8f ("HID: multitouch: add support for trackpads"). Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3e92789ed..571435da5 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -72,6 +72,7 @@ MODULE_LICENSE("GPL"); #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) #define MT_QUIRK_DISABLE_WAKEUP BIT(21) #define MT_QUIRK_ORIENTATION_INVERT BIT(22) +#define MT_QUIRK_TOUCH_IS_TIPSTATE BIT(23) #define MT_INPUTMODE_TOUCHSCREEN 0x02 #define MT_INPUTMODE_TOUCHPAD 0x03 @@ -809,6 +810,15 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, MT_STORE_FIELD(confidence_state); return 1; + case HID_DG_TOUCH: + /* + * Legacy devices use TIPSWITCH and not TOUCH. + * Let's just ignore this field unless the quirk is set. + */ + if (!(cls->quirks & MT_QUIRK_TOUCH_IS_TIPSTATE)) + return -1; + + fallthrough; case HID_DG_TIPSWITCH: if (field->application != HID_GD_SYSTEM_MULTIAXIS) input_set_capability(hi->input, @@ -872,10 +882,6 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_DG_CONTACTMAX: /* contact max are global to the report */ return -1; - case HID_DG_TOUCH: - /* Legacy devices use TIPSWITCH and not TOUCH. - * Let's just ignore this field. */ - return -1; } /* let hid-input decide for the others */ return 0; From patchwork Thu Aug 8 13:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F394C3DA4A for ; Thu, 8 Aug 2024 13:54:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8006010E740; Thu, 8 Aug 2024 13:54:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="PLl24Ph/"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2028.outbound.protection.outlook.com [40.92.102.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id E035110E740 for ; Thu, 8 Aug 2024 13:54:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tmAFzKTRsy8HI9OqVMwMkjT7VBoBj88aavQBCbTam0za7FB1e1nGFtXEu2VWdRgs212runwJ7RksfaoWPdvqNL8fu/ntOT0q2GVdNm4sJtTtiEBdyZBsqG1zB0AKWw0sLgfDwyZyQkLKfCKRnBIEkzJnkv9GAO4CiWlh4qDHIAkVl0vIfubFGXKud2Q6eldd4GwPryfX8+xz+5TQ5AYxaTACv9VOnTrAkmeXw6QoazLyuZZo8orA4OrJ1EneAlo5os0IWriApw/RBH7E88EJ8/i7/HwXdkbI1K8v27xbiTQ+FGNvlWp3kzwgIzuEC06tC9kRhTKG7in+2FtnXV//NQ== 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=BxS+myg+Qs1GLNMV47tojJKJV1LM/ET1FuS59bD6j6Tf1E9dTwMv2Pi/5kMgRqdNh6i7LHvBaqS9QS/R16DsaUqV/ucTjtgWf+qOb7TqlWCS/sy7FDhfVuNovLLYoWoLaXFMxoNr47kMzp5o96bIn7d0NXPN7w2vDleUCy6pcRJnKKqbpV6+JoH37p0gopUdEgkkgkcy1C+SLga6MEWjHBwigyyMyRErFKvGFhvesShr6GQB2AvA5nV4FRH1Li/mxsUcNUlfdCXOj9/9mg0HeNPHWmauERFe1LGgcg7IV57ittogfp0vnn+b8E6uBnWiBDaBVKlzFjNy5brQ1U1IjA== 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=PLl24Ph/w19a1lPybksVkQ0z4CGUNieeOJgXORz89P5E3BqxWajQRV+FilfxRz5pusc3XQ+Sl0N7BnVMSwo3gu4XA52wH46DRTt4JNcztk1FC6jPPyQwD1scildqg6oqlmeyJ+TwE8yHCrx4wOEy2e4VlYoUFEKFN8gQq/NibvPHbNaXi9BNS0Hj1HXPIfPBJ2epXYYhFYN89sNtxC2MpTuqHdnoCssNyoe59mQHxooMffiHtN4cwmtylsxxtFmbCenyhz5OAvw4cEeJ+te7p1A6SqSmXhFp2g5Bs+ScIpy6NFnNUJNv+clI9GixnwIsczwTKjuQIfThp66G+2OMWA== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:53:59 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:53:59 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Topic: [PATCH v3 5/9] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Index: AQHa6Zprf/sbSFQWgEWmZyYz9HpMNQ== Date: Thu, 8 Aug 2024 13:53:59 +0000 Message-ID: <025E5723-E8D8-41CA-A431-5981D86D3753@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [IDREavt4XEwHQtTQfXnhH2MSguojEE4OdyPIHHgbj7SJ/DH1zOpg9btEVZvK1wsOvP9ogL2Nspo=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: c966a232-efa5-4c05-b182-08dcb7b18dec x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: fVuXGkS7Bw05wlUa5/VkD3c3xYSlYgzj4F1A6uIUdmrynANnnmfnAjAoq9PvkERo+o1AVoolbU3q12i8t2b/5MTqB6feXHPeGgBy3Oq2c1lahvoYOeiufC22Z4A+F83qylxdWelt3emmljMO1AEn0/c+zZ7I09tS4b+w6ThmQK9lAiHKI0LueBRY7QsCsLrmizLMd2EePpTX08QT9qf0HVINXUU9///JiJLjqI5c7aI+KW2Fg0Xc5MZJTVKzDVtbPXIqA05lcf1BVbWUI3VjE4I9P0N3SK9w1hJAJjrKLwsr5Z8zKyyB3V/oupDyweIWUeiy+q6RYUzi7oMQ9qfpug4Y8hVK/c4ZF4JpLl+ZPQ7PFE5bot3B+K/odFinSU5K6B4IY24VUOLiRhidxep532feT2nwC6rfi6Yc1Nl/RCX7tZMIc5OHX59+fpI6SZqOINu4Q764SvNWpUt1nrfegpSlNTvop2/eGb2E8P+h8bkWQlR4VWj+hZg9Z4Vj+cKmlC0swdZxM+ML78e5BPlfGgEqKvQMC2DklCw4fK0UJ/HwGrWx/T+Qn2TJVsrNCG2UcbTt4ehEMaU0PXRGul9IEhMtGQ0cM87ZaCm+PLkdhcxsnCfmwSTAIKzHS6LSKc8mcb2Iq/BB1+J5Q6ELBkkY0OrIXUPjq/p5s5K9AODROzvTmAFA4+3FgerUUk/gbGA9 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 43sZfU+vH6K1X4D5IFF1GADeCjQmuZVkkAc6zlbG3wmSuGR9qSJIcVBmipNUbsU9z1hctznzvKRvJUcLaK2hMzhNEmFBIYVKzbhcg4cwSWZ0tpamhgqr6mPx7pumzEf1cedTIp2FubmhK9UsHB+SeFmUplCluNxC3phvNLcfJd92g4SH6PjAoqgp+P0R+zvwIFLPmUP1QJKrvJirRC8D/au3bum2Do+EBvXS9R7Oej8/qUSGbEsQApXpKSv0PCWFN7FKgUnwDrC3cb9/FRAhIMCApikT9c3R+Yd4UsLmQcEIogwzzbgmtXRYjC1TQYB0PM/s8s9rmmnP1v9S1O+WrltyeQ+xPo0tSvtLyCs/In+WJwB4eGPv01Oih2d8zgaHXPmy8ZpCqTDYob36bmo+xIbL20Fh44BnVmfX2I5p7Wk10ruizx4OqCD2E6UObcr3QTwQVLYe3K13zdbnmdByC8iGznDqnIWTQRB6tNXmUAcO0hGKaesBS2JK0Q94XFZ+qxveqJO5t+SmtABaFduVR2ie/JC2AyLyJSSTkvIJoGCIMBVh0owVVIGlKuxSLXMbEQ61PcaKlc+2pe+G5p0dtOb12XvFOTl7KEsPHeKaQhm+NN0DZlXB5PrOyk2dlxPzhtYCrR/zb7GN6KHULYz4tCRaaF4OYrcqnhmxGNkLRerZeiQhMrP+J5LtH+2jQfACpexRkPd7VCSEhvkUXegwrP8RoUIst+5/2uyPNAV3Tq4v3TOXlwlbZS/2atxSisXhT7un2e3YDfqV7OpuEjL4Y61YQla1lTrYPv8P8c1Zw7JZxth5sAsJq9GQK6TLxAEvshSm+Ak1O3i1v8e4zmbdOn0RXv8odTp4pVrwr8J9P2rWIzaGZG12e0XNIwbRJMcUYSALWybzmthyTRtFSv3ZPYutmFJeEnaOOIlHDLyaixFnD6FoAKvyLzp0WA/awqOk8X1fuur0d05pxazGPKxMSga9jbkRbQN83mtBnhBHRMTwwyK9yU78zUESwTCKSTD1wXZSJ/uKb1WpwUOJUtCsxcQ4ljKJD31dooLnGk6BQwGWVENT/0V+K1J6gvlaQudXI9d5BCGxXPdD/PMFt7Rb+IbZ1ZDb89606jlQyKy7IhFxoTgTPcEz/Wv7sDNV9O4FjNUhHFvwd7xxW7PU/gWAwj2OWWifPIxF5UPZll9V4DGyL8HQtR5YRHs7DN6TjHoTEvf0cd52wnKiQ98MBJi78mbJayGvd9xmNpZd4c6F+FZW8mmfwL11oZ5I2joN+NdLZPwc1JFBAKgW3o7DVZYO3NxFwYrACkDVuSXGEfX0TuqGaLmenzu+/Ndwew5ow0zg Content-ID: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: c966a232-efa5-4c05-b182-08dcb7b18dec X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:53:59.7770 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay This is needed for Apple Touch Bars, where no HID_DG_CONTACTMAX field is present and the maximum contact count is greater than the default. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 571435da5..60b675cd1 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -490,9 +490,6 @@ static void mt_feature_mapping(struct hid_device *hdev, if (!td->maxcontacts && field->logical_maximum <= MT_MAX_MAXCONTACT) td->maxcontacts = field->logical_maximum; - if (td->mtclass.maxcontacts) - /* check if the maxcontacts is given by the class */ - td->maxcontacts = td->mtclass.maxcontacts; break; case HID_DG_BUTTONTYPE: @@ -1309,6 +1306,10 @@ static int mt_touch_input_configured(struct hid_device *hdev, struct input_dev *input = hi->input; int ret; + /* check if the maxcontacts is given by the class */ + if (cls->maxcontacts) + td->maxcontacts = cls->maxcontacts; + if (!td->maxcontacts) td->maxcontacts = MT_DEFAULT_MAXCONTACT; From patchwork Thu Aug 8 13:54:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83403C52D6F for ; Thu, 8 Aug 2024 13:55:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A3EF10E741; Thu, 8 Aug 2024 13:55:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="URiY47KC"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2040.outbound.protection.outlook.com [40.92.102.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA23F10E741 for ; Thu, 8 Aug 2024 13:55:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kb/+04GPFMvMFB/VNyTCVHuLjSe3uOFiXt7SJkyKKEWAeStjmFLrbPQG5/B71gnGYlwOTLo2AEXrTxekS48/0gbTdFGPLcLosxaCnzPp1x2K0/3a6nTJcCao7lCEK07mFcFIiVuFDv/QNSZofhH7bYqnNsZSg4iS7EPtSw2IGK+XwsJ41DE2JuGLlMy4lP4T/Q/TZNJXjQVZRJftVvEVILB5on1SRB6JZ0iZ6TG5+Fks2ekjfJieTzCIIB2eW1/oHKGndetKk4KwHwyLjWZv7VBn51LE9aXnEGfsw0cG+q3ZN7ca7wEW+0/5BCJt364lTcOz4rHKDErJf1ZPjWsMrw== 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=YzvPyf3acn3ToxTvwlo7uv4aQFx2i6qytYiDZzYO9S1d8OoxiEZABY1SmjXVwNEPu6K+iua/bqNCoYzCVNSH0cJpXvyiMdRXOTHLk1Rhau5a+OhKVCZwzqUgciFMedqqCuE/kOFF9f8nDl3Z2se1AZMkiLBJXD/gJV++4qo6alWNF/wJzRdXCalqg+IzE6FOvFgYxrbcEyFwfpSK6Eqx7lPunWt8PJ2eZHxR8NoYXsvwcdrcMAbOZJVvP/v91t9xpNiWe7+cm2p+9ULYcYkLMbcTtSGsk9x0dNqMgnhWVW875ANxeTDTjeM/idIL0BjN/8KUswsM7LEJ2KX/vZ8s7A== 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=URiY47KCB0u6jM9Ol74gNqQxFFISSwnulZ4/djCgbWksXhZX8E7tzDxawT3vRnIuBhjy93GTEA5pnhmyDYh8aPI3OEK1E+JXRC9SJCIkwtLthWj/iJkY1LnRCxyTTSBn97+DPVMsqTTFrsvXRyg15VzPvS3oiFNs+CTZ0Ji3XIhAh63UaeF+ywfxpeBy8AzfE1mJduGRvrYPTSzUiZXSGV6BjqdwQG24YGlm3G6/ojHSjTq9xZiqUqI/lwhxT1UukUWUx8BekElxG8LvEf8ifdzrdluh/pHf5Y4phIcvxNhb424HTTjvfbIJe5GBDa7X3RnUuTwYqNGB5ewyE3BIxg== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:54:55 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:54:55 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Topic: [PATCH v3 6/9] HID: multitouch: allow specifying if a device is direct in a class Thread-Index: AQHa6ZqMeCTzUt83jEWlknyG6D0ACg== Date: Thu, 8 Aug 2024 13:54:55 +0000 Message-ID: References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [8hwJzuxZ51yB2GXKxFDo/UrgEegkZVJ9BEs6Ml1Uev0evDfvbdqh8FCJiJ/9tOrpVSE62X8aBig=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: 1eb8c401-8dfc-4fc4-e546-08dcb7b1aef7 x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: BudKZYsaJTagZyLvbaTZ8ofW/g7pmhS+P1JG2fRT0LZFGEC4s2Ef75IR2bzDNf1MREor4/wFK1a6q4kC5w3SCDX7twrzIyY+xezE6tRZQMd1YRUgm9hLDDdK9M5KKjOyPUi9IygcXVx4LdFDgRwSF9+CpB7H6AjWtXmwSOAmtsgw7X1W9ApOWj9YY9tDV81V0p2qe3TRQfXUeFptvvKGpiwpO7KW7OhS0ddVdz0gZz1g+YAGdALujIi1vX1ds3k6xflfqX74Nzo0dnuOJSUCnhUD5gjfQMSIaehz8FwKqpYP2F03H4cHWc8gZwYGfrCxKkxp42At/20JIsGPDsPaPAB0POhGWXnoe+gbNROQ7TXiSR3BtPh0E3S/OanWN17i96P3DG0odWP8lSz+SBpmil4wYt4SvSiK4zaL0tsZEdpSn9z9ZpnqzlpSr3NxfEMMxp1CCoGOe53eNlJzkH6gfj+s2rTEymKz3ePownqBAS6ODvyLHyreEwx7eV/mzlgWNbF56cyqFQH//uV3kjic+Er4DKKE12RN6ExampAD1ASDfds8N9CqNLbYeA7epYHWQNHxubVaZMLZGG4eB+udFqvQSCHPO4HjjuJ6Km7TrmBl1sEGb2QxbJhdLa08DZLEnFd/UZ8Z7C2i6WW3aJoKfWXwZ4SJ3dugih/6ufRGfOQiexm/3x/WC9nVofp2VO1q x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 7Jn9CnhhhhulgceGFIftbjEIUqVPlkaqloKYj2Yvc6RqflLJzTVBh6hccY98S8EOvn0vNY8awOEgEO4W6GcwdkvzJCtZIZJw1ERrAYJ6CavmymF4zciqT6dvwuDd0fLbXRAZp/Idg+a3B8ddDK57K+u203bk1WrmfMez0+KC1U64E3SMyOATjhXOQ/iqokEL69BuqadHpe1yKCSKae8gZxwSNhPGMgVryVaMVTHo9m0oEIC8NThfMMRy8+6vO9Grrd44lQRD6QVQL0oAktdu/Bkskbka6IIOPF/Oh3V8zmkucsOPzC7f4+DBuONqv2o2TDtIB9Gsqfb5hO0bd+DMPLQN8bqBhySSkFqQFk74Iuoq4HOcJ51fyFQMv9rG8KTd4ilTVdAomCprmNGvKQdgItdp6JzKnPMKD2cbvATa5a5lera5UXjlM9o/Qyd2C/zD4VlJwd+v+5H8GQ3Qk1IANPAH+KJsCHxPPR9WeTbDA7+C6jsvD4mzPOqPgMgfS9O2f8/MoHqOBNJamqUyElN+vT/9lyNcE92xge+cfNdGiy9omSNkfIm1NWsh6jNkBURkfjARj3ZeGVdDxHd/Eqrj4Oo0DiVeyqWw3c0IsKEJSDLKrD0FM2sdJh22B/MojBep59aMZjdw9Ze7RERUJaRymV1IO030zey46sCgcij5ZtxWDUUL9jqQcUiH7jSXQHSY0E5qiWc4vNSQeSISaYRk4SeDeSEhCGJ57sXuA5UQzUT6QgpTfjUq8EEUY0Iq9CgCpqOw7g1iiQaA68agloJO5c/puiKazbszjBqmHQPlO8hgYSYkxDVNvHOnSBa0SKNPMJjrKKjA0BIPT+zOY8iKiD57ynfHF4HwnkQCxuWwpZwkE+vk8tSB5tbzxuZ6EBJSNQu7kzZvDk6mabTuU3EkbUCQIdGiotwVO78wWSD0loXAuSfxon1DE0cvrnNvjo3JCCEuAvvnfEm62LJDmqjKs7vm0LQlDz/5E1BzadiJZirVL5Z8MjoHDiA+yeSA35N9FabWCeeiVUqvcKMosfzWPm26CprhPJ3nNWKiLLQ8nco1U9+nL/lhuVAknbrZkPwi5PjYSdbqeX0xMx9SFb+vUFKqwUPed2dmCePGRyO/Q/aGm5NNJIV3RipUAADLkZHeWSgmvumUs3rvyLlczr18WkTvMOTpCkEjqW8KPdLWGvPaM9a8tmxc+R7YctAvwPwH88GtTACRsUTOoJAXpOTeM5uyAZ7+yIqPVVkYk6FbV6aS+y7Y2f0xWrUv4zAuJ6UqOQjfVT1pD++/9flU2oT20iRBbCCjSg1JwrBqcPNz6QA5e/SzaB1nJAOcFbQeLLv2 Content-ID: <1917D30B77C1804EB98DA9A500D26A51@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 1eb8c401-8dfc-4fc4-e546-08dcb7b1aef7 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:54:55.1794 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay Currently the driver determines the device type based on the application, but this value is not reliable on Apple Touch Bars, where the application is HID_DG_TOUCHPAD even though the devices are direct, so allow setting it in classes. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/hid-multitouch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 60b675cd1..2948fbcbc 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -146,6 +146,7 @@ struct mt_class { __s32 sn_height; /* Signal/noise ratio for height events */ __s32 sn_pressure; /* Signal/noise ratio for pressure events */ __u8 maxcontacts; + bool is_direct; /* true for touchscreens */ bool is_indirect; /* true for touchpads */ bool export_all_inputs; /* do not ignore mouse, keyboards, etc... */ }; @@ -563,13 +564,13 @@ static struct mt_application *mt_allocate_application(struct mt_device *td, mt_application->application = application; INIT_LIST_HEAD(&mt_application->mt_usages); - if (application == HID_DG_TOUCHSCREEN) + if (application == HID_DG_TOUCHSCREEN && !td->mtclass.is_indirect) mt_application->mt_flags |= INPUT_MT_DIRECT; /* * Model touchscreens providing buttons as touchpads. */ - if (application == HID_DG_TOUCHPAD) { + if (application == HID_DG_TOUCHPAD && !td->mtclass.is_direct) { mt_application->mt_flags |= INPUT_MT_POINTER; td->inputmode_value = MT_INPUTMODE_TOUCHPAD; } @@ -1317,6 +1318,9 @@ static int mt_touch_input_configured(struct hid_device *hdev, if (td->serial_maybe) mt_post_parse_default_settings(td, app); + if (cls->is_direct) + app->mt_flags |= INPUT_MT_DIRECT; + if (cls->is_indirect) app->mt_flags |= INPUT_MT_POINTER; From patchwork Thu Aug 8 13:55:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A93B5C52D73 for ; Thu, 8 Aug 2024 13:55:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2531110E745; Thu, 8 Aug 2024 13:55:53 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="nTuftBjc"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2041.outbound.protection.outlook.com [40.92.102.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id AE46B10E743 for ; Thu, 8 Aug 2024 13:55:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b3rNarX/MWZ6vO1wiam6svUHzc8fVVF1J0V1qc0MXNqynhkzvoPg1/+dYQfGL1aINPcWQa7P0TbJOp+wMjFpTYogUd2ZuAhyZkHcwL2s6KiLEZN8ms3uVwqIYVvJptTXuaEsAuHi7ztyiYkz0TLf3looiJZMjSfi8FdGZwZMdgrdSkG6FJ3nlfyKao9V1sF/2mkO3Yoac9xSJn47n6c7M8KT1Y/u5Z5NaZveH1SbTTxRdnRnmvBV95DfzrAL+Bz/AhAnS/+u5ecbhuskZonrjQe3HxvW6/jXMnsnAoV0sUehzgDijkVLkO85227RcOu7EDSuujuHf3r3356514OhOA== 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=qxPAHKtfBPTp/Gciy6/M7dPt6mjZ5IKninda91649yMpnzq2Neg/xfUV1Rg81M2qAgYIc0Jj+ckZ9a7IkZb/GMdAZ2i1biDs06n+/KXZu4PzH8sO/RMio4vk0PR8N75rLMsMJE60nerlk6NFa+cio0OcGkTZTfa5ZfH/AOtGfqGTvbBsK8iitzeWMvIbV7EZhNp/1jopBmfJQRST9ikBGAKK9foC4cCrQSfaMiA07Okpif/XIF4HGgYUh4dcl4RfjPXaWBALfWr2Sasz/3Lo3utLbUbwIAp309T292XN8AkUD/TlYBQ3W2rZ7XPnrY5yizabvQs8E0GXvEYjFAyNXQ== 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=nTuftBjcaZ9s3UaAVQVpsbBn5KVgyUmGGuoPvRdNin5EZ7FbbxPiUAswwiCxl1hyyKv4gocGsB6fMk26t443qDiTt01QBTIzfwsXG5G7bG9VjpYdceZK/A6QkMg2zgCHqn1475aOla5+qGMX+xTZ7gF2XHL8WZG/po2Jk5gdoE7xZGvmhwlxAoaQx73K2/DtyNwjWGlVcXOjF7HlB7QSYtD/js6vyaXUCtHmm+DYHqW3dZFhMmPjZyNLADI/AOAgbq1YsoDuM64g/djj4iYsy6jiig3JAxfs3GyIx1aMy0anfxFbAmgauXd/iMUHMEtY5khNnI/lcVjwyQbMHsqF3g== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:55:42 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:55:42 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Topic: [PATCH v3 7/9] HID: multitouch: add device ID for Apple Touch Bars Thread-Index: AQHa6ZqoKS0lNEgwgkOWtDaddXUfEg== Date: Thu, 8 Aug 2024 13:55:42 +0000 Message-ID: <34127221-073B-43A4-91BB-9637F96B99C5@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [GzdbJfBE/UHHQd0m1xcZ0ULQvuqXOYWHavNSEuvM0w3NpcZXw6Dh+EisFF3z7OOXi4QLNa8a+18=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: c1600182-18db-4efa-e865-08dcb7b1caef x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: c6lH75XOu+NKsCG2c7rPe6mKWJEdrKvEei3cdOXR6SlFH2/pXOffU2OLR2Ke9yJn6xeJwo/GM1nNCcA/V3PFwdiK0rNn8ALLEPtacE66QZEzr+WUBGfq+Ym9N7MkcktO1e2druydC5NAYpF/YXk3QTZMXAxzKDtYXAw/RDdQ8uY3SfPTaqdcUkvSDgy348fyCyaRRO6YiCzYZFRHV0l765R86oy0MRM6T9+ABsIFBSmKr40Nj0jhH2nztIUUHpSvfOXX5sO4nSDNxzuwCazuI/tDlejsjmKoLOT7NBUu0kh0ve2DF3tChKcgCqfIS4DjDtAeeZBNN6Q6LkS627E8TN73gTMbbyZdFCCI24IcU6MDSvWl/dPbNJ8QgrVzWyU0xPtmtiEDgxsMDq+wOFgBdmLjd43TpSeNVRV6Ck4C2lnHiBtUh8XTPZO2WFadTFDCxg/bpBUuFWmkbh0WUIW1Cuv0uk+/Tq5O6huEGgziYp0CptGRRiXYl+FADdZfGga8a3UDIT3eaurOmby55TCaLbJj5OXKSpVFSQB759qM5dw1I2vbh8ANtSZVTf4X81x/DbE18ppQBhw8gSJo73C7SnZEVdg2LxwgfJgfpHg2ZL6iyYh23RlSCarXMYHunPGIWEOi5hE4Szufrf2bOJQjNow1C1vv7aY7BpJBm0PxNGIqi2U1IdN4IoiON9CqKAUm x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: wrmtEN3HuoBEUS2FaO97P96QJxo30NNN/xlRXN4n1hYw2UZtqZRkujIa4HKWKnCFvh9oCEsg3GfuTX+obcQpH1it0k542WH8UxHFsWX4MHu8Ycoz6ETMXNDogS/EEOyMQ1MAm5QtikD7Vel8RAepIVMbP3P2bTBg1NMGue7mCOsXW+ERWOSl3UEDgq6jwLzJmZy76ujvQkvlj/S2yQ+47Jq9QbAYXKBe9z5qVb1e2rtO0fHPnNJtvG+xTjU/YNheHvyZWTonqf6shCoN9Dn+o8dFW4Bx5kA3tbJGya+MuVvICkjBazswTAgh7hnrji49YmmyxcDGPLLKwTWcK1iRSvrXUu7/H5GamNMeX/uLhO9PdZWRtfnmpy3c+coQ9oVoYW4KEcsx5LI+w9wSWMKRVfJ4JhNwroHnYJSdKvPUodqImnRiSuSMC1HdUhOGBDerr2iINLL6Ia/L/mIfB83ez3bzhLERmVeKBaBy770IFtpfyxshUj9oUb+hsRB12kEKCt80KxJFZYQOzB6WQw5gHn1fKsJ8nf+BVKJa+lEY3M6HJJC1FRlNheGtMwsbPJmY4S59dBGuzF4k0+ORdWNpk3SqggFdXknCdWRAttlVA1XtjrpkXlCWiw5djETf2y93y1skmGkmALPbxfYg0sLcA2dcrAyON2ftveVd/D/LPFoM+G+GES7AbBjGxb1MAZ5d+H/etfF1IzOR1+26+xiaEHlYaY3UlFTr4OMq4EM+hHV7I0/mZHGESrukSjAnn0hAD3wi4xImZzHZf9WD/ma58SkDwKugUL4ovXZYGGRU0tCAgcc/lRZU9CpQmXwZXhXxGsZj9c8gCiMeAYwhoAnjDSAA1P5gSlWxD2YVc0h93ZhxY6dP1pdWbVLMwkdqFueoGsO6PXDMyPwe8xWe4aR8P3u1TWxVV/t8cIw2+ahylH9cuwwLvvscMIFoYbUG4/Dpl/jh+jpB+LX73Lh9VJ0iCQf5TuIH+BuDRcTJi97bN2tooKSpRHGZTKaxLVtZxuNCIwd7kuTNQS+xYFmdup//r4sS/QqJRqvXBTNdcmxes80nQZx/0wf+7pq38Uw6v70ggYAluulc0Fr3SHtNvrHssLjKqAWvEWexknMtOmOfzCmg+D34pFd69qnLBn3LL/e19Uw05ngqSnMfNqiBmx1RuzTGBHvcni0KozpH3WptHrR0oR2K/CD0KdwrTDCwY1VK6evewdqP8Kli2WhV8vTF36J566WpOlmguDvStRy6/CyRqB1knbmYiHUTb4qrbgqlxzCPqxyod3bXvsM8g5HbDAunFbQH17NzuS4A01yh1BA9a7xO3bbVkSWPkZSpzX2e Content-ID: <589FD4482AC496439F18665D09E19EA2@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: c1600182-18db-4efa-e865-08dcb7b1caef X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:55:42.1250 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay Note that this is device ID is for T2 Macs. Testing on T1 Macs would be appreciated. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/hid/Kconfig | 1 + drivers/hid/hid-multitouch.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 72b665eda..35ef5d4ef 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -744,6 +744,7 @@ config HID_MULTITOUCH Say Y here if you have one of the following devices: - 3M PCT touch screens - ActionStar dual touch panels + - Touch Bars on x86 MacBook Pros - Atmel panels - Cando dual touch panels - Chunghwa panels diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 2948fbcbc..0fed95536 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -214,6 +214,7 @@ static void mt_post_parse(struct mt_device *td, struct mt_application *app); #define MT_CLS_GOOGLE 0x0111 #define MT_CLS_RAZER_BLADE_STEALTH 0x0112 #define MT_CLS_SMART_TECH 0x0113 +#define MT_CLS_APPLE_TOUCHBAR 0x0114 #define MT_DEFAULT_MAXCONTACT 10 #define MT_MAX_MAXCONTACT 250 @@ -398,6 +399,13 @@ static const struct mt_class mt_classes[] = { MT_QUIRK_CONTACT_CNT_ACCURATE | MT_QUIRK_SEPARATE_APP_REPORT, }, + { .name = MT_CLS_APPLE_TOUCHBAR, + .quirks = MT_QUIRK_HOVERING | + MT_QUIRK_TOUCH_IS_TIPSTATE | + MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE, + .is_direct = true, + .maxcontacts = 11, + }, { } }; @@ -1747,6 +1755,15 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) } } + ret = hid_parse(hdev); + if (ret != 0) + return ret; + + if (mtclass->name == MT_CLS_APPLE_TOUCHBAR && + !hid_find_field(hdev, HID_INPUT_REPORT, + HID_DG_TOUCHPAD, HID_DG_TRANSDUCER_INDEX)) + return -ENODEV; + td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); if (!td) { dev_err(&hdev->dev, "cannot allocate multitouch data\n"); @@ -1794,10 +1811,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) timer_setup(&td->release_timer, mt_expired_timeout, 0); - ret = hid_parse(hdev); - if (ret != 0) - return ret; - if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID) mt_fix_const_fields(hdev, HID_DG_CONTACTID); @@ -2249,6 +2262,11 @@ static const struct hid_device_id mt_devices[] = { MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) }, + /* Apple Touch Bars */ + { .driver_data = MT_CLS_APPLE_TOUCHBAR, + HID_USB_DEVICE(USB_VENDOR_ID_APPLE, + USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) }, + /* Google MT devices */ { .driver_data = MT_CLS_GOOGLE, HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE, From patchwork Thu Aug 8 13:56:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D322C52D6F for ; Thu, 8 Aug 2024 13:56:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ECCB110E746; Thu, 8 Aug 2024 13:56:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="ZGooGa1g"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2066.outbound.protection.outlook.com [40.92.102.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5891210E743 for ; Thu, 8 Aug 2024 13:56:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QNUg4W1GCUFz+4lbziPRb2r1jtqQ8CkyUENEEAWkkeNasH61g8IeLJbQ2ibIRBvkymDK6fl5WvUAcHgk4c+zcg3QYhHueXvS60No8mpe5u+M2NajUjRtMC8UT37d3ZvyWrZAPpBL00seWgBQUF17Xs+y12h+NaQPhY0VhTEVOyNjn1n1LU+Xo7CHoSLqcO4nDSwJTQcNHN3oFwUjR1kQVBQRlzfWNUjcQv1jibmi4izEFDwCTBJvKVezFjGSVFphOdGT02Gp2NEp8vUKwvpjwlIVaO7EZIX9C6be0hiXJlG37IpA1YgykdsoGVhTrN/MKt+CWL2uyIn3XMpWNd7s1A== 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=GY1tz482OsDB6RE5F6kIcJsMRV3xEpEPu9TyGfubgQ7n3cwdVUHLZP+82Lhg1fn3WXKypxg9GhsedEbzC0HwkN2sGsa7lus9Gkg108IFoSxRad5uvv14Lq1f/CxV/oykwRkgLXFuiuTKeNE7h/hNUNHaGkv0Qj1MYigfvlok6jY0CebIVEZiIMyFC9olVKGbw1ZAY34GiXxBH0neIJKp9gq/a0wW3e+0tMTN3U2zLaxgzdHhKqS2/9sirDrNQSjoYjrFNWG0OS2nbQm7eRPaoH9SNo3BBjFYyGeqEyOsknkPFkZK1Jd31VANxzMk5e276nx/ZM4gss3SJLTJ/LjuRA== 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=ZGooGa1gLyEqf2GTcfDmatLxL9Na93eBMQNjifez9ww8q+1HtV5jVRZsLowkznCrghY+AXyyjnmEtJrT+2EDfUIWvtmbATs1EbOsdXcQ9TMuaey/CjQwrEMPF3hOWABg3KVVpC4i6lWa85eW3ifIGgyinJqxHJ1u2ISpOqsJbHSgkecvi/no5yA6XyjcHfl+n+dW+Tgxvd4dMCAFYPX8h8bzdM5lmuG5jtOus41MUnh9pusm3rcQozbVIY63jmazG7pq6s31/JxGWDXC9PRBy3D8YR5vsX5hp2fvnSP5Cn5mxLB9YL5QP/3x0Cz5Pf+BVHxCu8Mmj2kSLFwla/xxrQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:56:40 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:56:40 +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: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 8/9] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Topic: [PATCH v3 8/9] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Index: AQHa6ZrK6g20cjdVoUSll6vOyi0YUA== Date: Thu, 8 Aug 2024 13:56:39 +0000 Message-ID: <95B6A54B-E2D3-47F0-8055-E0DB31F951C3@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [DVrbohJuur7GtwCx+exGsk1oL2GNCsf8aly4hNVnXOJmbCdxh+HX7Ww1TDqYRn4ZQJEJYhDdhWw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: f7ddf7ae-cc8f-486f-3b9d-08dcb7b1ed6f x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: VZ2XSMpnhj5aHSw/g2lbzlTSGXj8M//NRSlRZqj0NP40hcajHJXjgKPjnkR1offXzafCQnk63Rx2zckqOynAaiVYah3tQRQXtmWKKwYsfaiDupyyWxkr6A0p2X7LoimNL0ox+4owmqSJVogdh12N5X1fn9xejZMN8RAAgruQRntzijp+nxJMKAzfOTdIIFa7BLcKWCPVAdNmbhkZEfS6A6P9GZIZBBPq996dcXZnGJNf6rJFv31saQ6QCt18UcVrFFQ81Z6T0SZcpwFG9/zDKyqlCE/xb/kBcVTL2uTeoumaw8Hx0m3JU5Q0i/D919MfLTfuz0S9N+XxoWkzFH2NTdT54hYClrupxC6nG8rxnCS/nCVBDuXZVKrgw/FOypnN4VSqGK7W2YqbyIswxcCF+TvVWidVuRn3veb9edgjYxQnWyLkMQetJ5BrstAzhzPo9w+LJWKyYxZc+1T63oWH27FGV+uvbcLCcqLbsu3EnkG8J7O+gflU6tY1r1iM2KBb0LbG9OXdserAjsnYrZkJdPdr8AovmWm39qQ6cr4S8+7aCS7+k252vCRCrDLyp1w4nEm8CxEOqlx31t9I1pydb2b89TuYwVmMm07ENSg18zOe+juxVswHG4mCHXz5ZdoHbdwKFLVzuewbH8X9ilDhvsyk+y2QGxN8hlBM71fmJuo= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 1qY1zMHD0iQimpV1NApTrZpai6WjyVY1WAPwP8QxInyXe9Em2ov/wOB0/UUsoZZWS08bVqJln2EWIezv/GVVVukpDik4KvPBgI3Vx4xkC31vmPwmLR6ZIkzXExkozZuSc1SaNhXqNLbPCNvszdw3K/5S03yMKY++Ojqk9WrK8DA/uqUCmuI59+NRFDO3DmSaVVPXA+QQhSSx9064ntkb7xKC4qANUjPDUqfdn0zUf9/niB2Q2YZWqRiU301ImtXmNRpIkgIoa5TCCUD8q+37z6rAHtx/P4gG/Qq2xqkocCnTzoojYJ2hInmj+AsY1WBtxQHZdsQAclU0FpCuJhMT+lTku53gQpqkUPblVl5hH8SKgIQ2b8nS2zV2JvgirpADHrsyfEk108GYiJhmtdds/3n9K6DXJKU8Lt6ImDML1B5YK/+3se2QMAHxB3VvLwThqy0MgqoehZVI+UwHOmpXVkw5DiRin6+GGPQyGDKOV8HY+EDSoA2kneVTji+p89rAegU44V2NY2G+UHfnK2m+JuxEtMZZc2qOPqeTHbefDesq+QGCjAvk+yTwr9577ypuCWJgc7fdJMPMjw12s7FJ227qGLBNDOL0b8kdbE+1U+uN4gextTafCytjITuSZNDGiObKE8e5nCJnpzPkdw/h1ueDht8kkVL2vU8J9aLCP4fbtrr7cWGAFncPA8qXXEAL4hveOHz78Jhbs3CgQHVMckSJfefHwx21y1q9P71LcXDVH9QZ2HWlyAqXkdFTGpVTujxcQceBQ91Cu9HEUGWGSZ37AyIMF6hrubi7yuHmAS58OUqappnPAOOCVgRZ2pBxgRh70yZxhwYpL3W1HIkcbwDsOcjtYJT9IJjxP29c76yMV5tpCLplzKB7C+cvrBoISi+NsaQH/q5mtSa1ZUtFKRWavReOjjoPo+aJyFmvMfxz0RIoYyKdXvLs/iAElbkLir3E81yb7bE7Nq9QSFKxG5no+W0l/tWIKd6Kb+w+RBt956gmGiBHRP1fQ0arbKYqyLtFvyHOaYG/C50im9aZQWPYwWZ7yhHsNOuoI15Ym5Jq6jUxUQDFr46EvPUqi65Le0QUh6UqaUtBwJT3boXRTjmNruh9VDMIvI4FoIq+xOxd3R8m6Mc9OWAZ48ZktJLrOrhFv3D8z+a4+W/pqMLsS1c1S7Kys9JMaXZppnSc5tQjCFaxJOA1lGZz8V6loqm5J0p5ej1dgKKymvwKKScW4roA0U7daENYu3WNx++mCaRXRniPP4YUFbEdULlp6cCqukGTCbVEuq3n1G/vYIB46z1geDGFQeMnGo6bdhJkT3Q8B3UHFq+ej7jX9AryuGNr Content-ID: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: f7ddf7ae-cc8f-486f-3b9d-08dcb7b1ed6f X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:56:39.9749 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Kerem Karabay Add XRGB8888 emulation helper for devices that only support BGR888. Signed-off-by: Kerem Karabay Signed-off-by: Aditya Garg --- drivers/gpu/drm/drm_format_helper.c | 54 +++++++++++++ .../gpu/drm/tests/drm_format_helper_test.c | 81 +++++++++++++++++++ include/drm/drm_format_helper.h | 3 + 3 files changed, 138 insertions(+) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index b1be458ed..28c0e76a1 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -702,6 +702,57 @@ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pi } EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888); +static void drm_fb_xrgb8888_to_bgr888_line(void *dbuf, const void *sbuf, unsigned int pixels) +{ + u8 *dbuf8 = dbuf; + const __le32 *sbuf32 = sbuf; + unsigned int x; + u32 pix; + + for (x = 0; x < pixels; x++) { + pix = le32_to_cpu(sbuf32[x]); + /* write red-green-blue to output in little endianness */ + *dbuf8++ = (pix & 0x00FF0000) >> 16; + *dbuf8++ = (pix & 0x0000FF00) >> 8; + *dbuf8++ = (pix & 0x000000FF) >> 0; + } +} + +/** + * drm_fb_xrgb8888_to_bgr888 - Convert XRGB8888 to BGR888 clip buffer + * @dst: Array of BGR888 destination buffers + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines + * within @dst; can be NULL if scanlines are stored next to each other. + * @src: Array of XRGB8888 source buffers + * @fb: DRM framebuffer + * @clip: Clip rectangle area to copy + * @state: Transform and conversion state + * + * This function copies parts of a framebuffer to display memory and converts the + * color format during the process. Destination and framebuffer formats must match. The + * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at + * least as many entries as there are planes in @fb's format. Each entry stores the + * value for the format's respective color plane at the same index. + * + * This function does not apply clipping on @dst (i.e. the destination is at the + * top-left corner). + * + * Drivers can use this function for BGR888 devices that don't natively + * support XRGB8888. + */ +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state) +{ + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { + 3, + }; + + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state, + drm_fb_xrgb8888_to_bgr888_line); +} +EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgr888); + static void drm_fb_xrgb8888_to_argb8888_line(void *dbuf, const void *sbuf, unsigned int pixels) { __le32 *dbuf32 = dbuf; @@ -1035,6 +1086,9 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t d } else if (dst_format == DRM_FORMAT_RGB888) { drm_fb_xrgb8888_to_rgb888(dst, dst_pitch, src, fb, clip, state); return 0; + } else if (dst_format == DRM_FORMAT_BGR888) { + drm_fb_xrgb8888_to_bgr888(dst, dst_pitch, src, fb, clip, state); + return 0; } else if (dst_format == DRM_FORMAT_ARGB8888) { drm_fb_xrgb8888_to_argb8888(dst, dst_pitch, src, fb, clip, state); return 0; diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 08992636e..35cd3405d 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -60,6 +60,11 @@ struct convert_to_rgb888_result { const u8 expected[TEST_BUF_SIZE]; }; +struct convert_to_bgr888_result { + unsigned int dst_pitch; + const u8 expected[TEST_BUF_SIZE]; +}; + struct convert_to_argb8888_result { unsigned int dst_pitch; const u32 expected[TEST_BUF_SIZE]; @@ -107,6 +112,7 @@ struct convert_xrgb8888_case { struct convert_to_argb1555_result argb1555_result; struct convert_to_rgba5551_result rgba5551_result; struct convert_to_rgb888_result rgb888_result; + struct convert_to_bgr888_result bgr888_result; struct convert_to_argb8888_result argb8888_result; struct convert_to_xrgb2101010_result xrgb2101010_result; struct convert_to_argb2101010_result argb2101010_result; @@ -151,6 +157,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0xFF, 0x00, 0x00 }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFFFF0000 }, @@ -217,6 +227,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0x00, 0x00, 0xFF }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { 0xFF, 0x00, 0x00 }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { 0xFFFF0000 }, @@ -330,6 +344,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, }, }, + .bgr888_result = { + .dst_pitch = TEST_USE_DEFAULT_PITCH, + .expected = { + 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, + }, + }, .argb8888_result = { .dst_pitch = TEST_USE_DEFAULT_PITCH, .expected = { @@ -468,6 +491,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, }, + .bgr888_result = { + .dst_pitch = 15, + .expected = { + 0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05, 0xA8, 0xF3, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xA8, 0x03, 0x03, 0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, .argb8888_result = { .dst_pitch = 20, .expected = { @@ -914,6 +948,52 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); } +static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test) +{ + const struct convert_xrgb8888_case *params = test->param_value; + const struct convert_to_bgr888_result *result = ¶ms->bgr888_result; + size_t dst_size; + u8 *buf = NULL; + __le32 *xrgb8888 = NULL; + struct iosys_map dst, src; + + struct drm_framebuffer fb = { + .format = drm_format_info(DRM_FORMAT_XRGB8888), + .pitches = { params->pitch, 0, 0 }, + }; + + dst_size = conversion_buf_size(DRM_FORMAT_BGR888, result->dst_pitch, + ¶ms->clip, 0); + KUNIT_ASSERT_GT(test, dst_size, 0); + + buf = kunit_kzalloc(test, dst_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + iosys_map_set_vaddr(&dst, buf); + + xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888); + iosys_map_set_vaddr(&src, xrgb8888); + + /* + * BGR888 expected results are already in little-endian + * order, so there's no need to convert the test output. + */ + drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, ¶ms->clip, + &fmtcnv_state); + KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); + + buf = dst.vaddr; /* restore original value of buf */ + memset(buf, 0, dst_size); + + int blit_result = 0; + + blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, ¶ms->clip, + &fmtcnv_state); + + KUNIT_EXPECT_FALSE(test, blit_result); + KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size); +} + static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test) { const struct convert_xrgb8888_case *params = test->param_value; @@ -1851,6 +1931,7 @@ static struct kunit_case drm_format_helper_test_cases[] = { KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params), + KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_bgr888, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params), KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params), diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h index 428d81afe..aa1604d92 100644 --- a/include/drm/drm_format_helper.h +++ b/include/drm/drm_format_helper.h @@ -96,6 +96,9 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip, struct drm_format_conv_state *state); +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch, + const struct iosys_map *src, const struct drm_framebuffer *fb, + const struct drm_rect *clip, struct drm_format_conv_state *state); void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip, struct drm_format_conv_state *state); From patchwork Thu Aug 8 13:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13757507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2D13C52D6F for ; Thu, 8 Aug 2024 13:57:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BEFA10E754; Thu, 8 Aug 2024 13:57:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="udTQ15Fp"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2058.outbound.protection.outlook.com [40.92.102.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id 411AC10E743 for ; Thu, 8 Aug 2024 13:57:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JTibecRSk4YTi5tjUqP6Vb2WL8tHZ6BEJ5iy9nbyy56PriZMboB4cGGP7lm+eFqqcfuIlvkXX1BbOzNLy1Vxflumts64XHMpAY7RGWYnn8UILS5zQOQYAsoZ9L5FkBxuKpPSjjLWaASM5Lp3T20VeAp1UvUg0LNs3A3q1/NVMDt58u14JCy003a7LXLUzLt15IXu6kHQl9GFHhCcUgTEX8bhyGV3wWgHet8/NYWm4UcHLgR6D+skC5mfBSTuY8DxxoLJoh160YyCfL+++bwML0jVTfm4IG3O4NGZr1ccSwCb+7d5erP0PoSe0SLj+WiWE0TDMSt/eRjYXtoSoB/1LA== 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=MO9VN6jW+wc+6wTdtfKdC7HcxVt0Mpqcga5jTsMg87AKLLp1MFGTKjgj/1chCjiPzQIxkXuRjhcVZWmi/DVMXb291jY5xr+24wGDp1Pj1pl5ZmAGhuV8nzAZDfVypNJgzVP/wCoGIbMjFrJS8kMKpLhuGr3XjkeKrpLURz3LdR7MPUr6ih3KXvGFWW9iV0NILtcpqWshb/kfWb9j0L19hMCl8UVYL6Fbtg9CFNu+9noJagpCbY6GxInSAlyymBMYnSOVetkAsuV5XX9xBSjkDpi0vtpW8cIF4hTFCcntcCBOYgHzy8/u+hDvAHrfa4kbVqFApcm6TqsIXtlBFgZ/Jg== 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=udTQ15FpM2HaeTzDEbV/h/o0QF333aJxu/P7VdziCXbBdDcPXljwkbx/QJDsDDF9oMCDX1PgXbwW9Wr8WHhe5DbNNmcm4n3WswZq4R/ZovM49/LsOLJNRT6qeiqnSVjWuh2xJc9UjskDfnpKGlRr8DOxIhZ5K//6L5kMGlRKhkfFZtGc/AMqLufMNXdzr1DUGe+3TzNXGGPW7xGffGu/sy5pgjdWLyZwW1nJ813q4h8TkjOUjhwmQSTSDsk5D7D18tpiHkJ7fSpmdrvXh4CvYgq+CDamwqB1eOYDc07F1EAAQ5+xnAvpBAcHxL4H1QFYeWGPeegAN2powLBa4Ou4xw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN2P287MB2013.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Thu, 8 Aug 2024 13:57:24 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%5]) with mapi id 15.20.7849.013; Thu, 8 Aug 2024 13:57:24 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v3 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Topic: [PATCH v3 9/9] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Index: AQHa6ZrlyQ8jDqn6RUiGjvYdsNrbkw== Date: Thu, 8 Aug 2024 13:57:24 +0000 Message-ID: <4F73F4DF-6E38-4BAF-92B7-20EE7370144F@live.com> References: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@live.com> In-Reply-To: <1368FEE8-58BB-41C9-B9AD-7F2F68FF1D53@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: [Y8+X7U+mgT6D6ktReKHzRpwWjU+lodWwS4Jl1DdZ8T5MqZ+IaUA6/S2LQeslju0JU/B06GXzbtY=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN2P287MB2013:EE_ x-ms-office365-filtering-correlation-id: 99e8f1be-c893-4877-167e-08dcb7b207ba x-microsoft-antispam: BCL:0; ARA:14566002|15080799003|461199028|8060799006|19110799003|4302099013|3412199025|440099028|102099032|1602099012; x-microsoft-antispam-message-info: oQ7VwnQuAFtotRrvs+Kzju9Y9h9RsigNoBGM0Jv9x5D3vSuJYTs9hhI9yaBe0QsoDbLcdD5pHffoLKAo+M8r2reeaCzJJM6kwU8jApdeHqFKWyzNyefiJv6khVTVsRphrZtzeHQGWOcR7g2zQnP7PIKDw1KMrvVassz/2r4NrH2wQ5dn4E5tP/QQ2tDTrRdbhNEpO63mVNhpfbuaHjZtgr2U7ACw2jmOjqaO/1xwp0mfEIj4LbTByjiMmU+ponCs6f+uYQI3oseopq/4f5QHZLKyKPFzEnAzJLIJaLmISukDv8Qu5ZNZjpeOkgYi7w34+2Mya7BYhGjfbE/9M7V2OtoAeNEGtRz5gwfxxd4IC9Wq+dnzlgglWO+B9XmFkpTgOVMCOyuVmwXcF2wvvFPZ8UODpUGrlndwX7n6bHek3I+SHYPqb38vy7hfqZ02KDru0IktOuLlKiwWUUs6rYHQmXMjg8QdNPfp6pBPnrxCohFp77S+pCEjc7LvWwkhDopWqJ6DTuWI6xGjBYoc7W+XD/KVLaxvgYRqp58RnyddV1BN2NGGTz8O6FlMIkVOA0enyGIItGStWs6TV3WubgVv4PvW+EiT4drgUL+ttEz38fhIT+yyqF353NkbncGQeP+Ky5tcldQAOqf8bzxFqcmMJNJz+rMoBLX8dqvKRuKRXuXAUnzPtOYjUg3zkwvxKeiLEYOGyHrds3WDftiJksoqk96gL8rXJF0YB+cmrOF+JttgAFMsoChVGH9lgh9OMK+zQap6Rs96XKDCl5SlWt1UE1NqwdYD99D+t7BAP4cPz10= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: X4Jea0n7QM7pdZ+0ueaPUBw6LT7Qz11mvEfdAQ/0pFa8KHqDdoZrlFzyDDbQVXyazFFNqBXu57lx76RFqu3tUqJbGcQIJz9zFODVUWoJyYG6vVAfJd6AN6PuPyMj3CrphR+Je54z9c/GGJBcpnHghZdj/BSRWhiUx4nKen4m/G3Nb3jFHicn4TJp6TK+1AMjw7Vfcl1B5JKhHv0aVdEZGWtPgdr6+9qUmOUMgFai+uNqa6MCTxb00IXYgne9r9Jg+o5zJON5Uwh53moLsZoPN/4sNrmCrqmxtvVTID98GFbVysfKfTEq6mOj2fxw1q1JOiVK7TWbC5f60CIi7jZXDLicfJhtI4EZU3u10x8CRHLmu+jJG96/99Uw3cFkDXmFmwXg7Xh3mKKJNNr7uWHY6XcQoDtaIJ2mJ1tiznWHqBxha9fL4zMfX5OjS/jVk6aXFH9d+rotUAw/EaQzGNb4GpmuP0EgeH7dbam0aNGwXt3gLQ8eGe9RCChAKTX8P6fqTKEMV9+teUsxlvOcrh11enkKWCceRX9tI2pxjBv28rWbcjq29mEyW6oPRKWUGINTe0bS1JElhKHwx0/4Qx4CDYIGT4lzrNhMfUR7yc5S6/Kn3xBBRh36BLEK/d7AHSQzDCPaak+R0ek++JinuxxF41ByME0ehX7xPLArCy8ubqpqHbChnoBdArCDuBkGFZCsa88+rSGka2A4do68ubFExAwo2vtEgfFdZ+rwDJiRwWM0TUrwSPxEYimn7Kxa6VU0eG0AIq0kpjfqFGqKadXW424otOfpIHYzVofu1LVCyieXZY97BXxVZJCljWmq9dGXeZvQXZmZfhnbgCy9Cz/wFhFy5my6PQItpUAdSF/kVJUPME8QkMkj2fTOVIOfMKvQDz/DxIMoPakirC0sPiobzQjoOKC3ldyzP+fBVyvcHirE8/9HjqFY4AgwC2VNe1EE88QdbLSO357j3pLrr/kT68hiK4YfGRLysLdkCF2MSaZZM3DR8F8VRkW0fE4/3CsvIosKTyQYtzCtSLoJ1V9QQDXZKKvN9ie9NgSGvmDcUa2+Rl5Wj/bVTqyH/4Q5+8QnBlf0GHiac5wC62eju70MV0hl8JOxPEWEg8+ORZ9H18nVw2r4rQ4mv+/SOcT2w/9fIY5JHpajmhLThcERmpAu8ZpBfoeiLOy9hpHwqnJv6+88QHGgq/JNfl5SuA4TXncInmsbV/k6Lbma/f0cBe+tVIOoKovXKWo2qXWhqjzs2zJNLwzelsHQv2G3FdCRG3fpjUW4urRf+ImHOXY4Rtc/pvxdJRGtqmnCLbIcM5FJQ2YGPlNpgVDX2bRhEyhxSxXn Content-ID: <861286640D222B43ABC7A9D6F0B8634B@INDP287.PROD.OUTLOOK.COM> MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-24072.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB0217.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 99e8f1be-c893-4877-167e-08dcb7b207ba X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Aug 2024 13:57:24.0935 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN2P287MB2013 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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");