From patchwork Sat Aug 17 11:45:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767160 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 0B217C52D7F for ; Sat, 17 Aug 2024 11:46:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A1F510E08A; Sat, 17 Aug 2024 11:46:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="EjDx1ql9"; dkim-atps=neutral Received: from IND01-BMX-obe.outbound.protection.outlook.com (mail-bmxind01olkn2102.outbound.protection.outlook.com [40.92.103.102]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EDFB10E08A for ; Sat, 17 Aug 2024 11:46:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cIoJcUGbBoj8l+xUvFN/PbBBUL1Vst69WDcvE5kLQXBjjvwzo6eRttVrJjURnWLb1Uvzhyju5xyDeyfXt/Bpqn/ksdYB/d+HgmPH/EoaPsJg1X2H8hO6cxoQli61OKf+bDlnfGqR3/dnTt9vN45duLV2QvvYox5bwHbjzbSRL1pCRZog1twwyAYL7ilkXDZNPYBr+vs6/5gBkoEdH75yudVm427rF5qez6g9vO+5ak33QS13va793I0p92+Kycyt0zCcDTRoVu6FYymDTDyGxO5e8+E4H8YdMngkAwvA0VjCZ5bkxAg6y0l87lt0zybAF+wON54rjyPh611h6uopdQ== 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=XINHJZ669k1kZJCm4iIwu6HrdmkZQEmoCqJgIG1jrWs=; b=tT7cP5FdMWVe23T/RwJp+m9wTBDEv9J/ADSU4YzIng+U3AXofSIqSAzOvNMxUl5LJvsRrlMxfYiMnleQxIttvOdf6Titbzi3YqBwVda8CK0v3gShmU9isz5WOX+Xz/lhtXHc/x+I4INqGWbc6t7RNUIMcZRnvOJObrjef+bBmbylzx+eWbViF7yj1j+XbRgK2jrg7vCHH6apA6guDVuPtyeQBJY0g9tXBIP+dmhOcmYQ24CSWncYuLcBoCJeCQnIxG3vr1Fh2uKoaRsUzjMTeE4MvGoBxn58EKRSUavC32+LH4+r7KqIkOSr6IVr3u54y4sKkcja/eLpxUD6/p95sA== 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=XINHJZ669k1kZJCm4iIwu6HrdmkZQEmoCqJgIG1jrWs=; b=EjDx1ql9ELa4pJ0Y/tQgSJWgEjrXo3uYKYS/mLtKyLm3qNzQPrHC6L9+wa4KEy5u+Ms1f/U/H5eUSoBFZ7fgf5MHTbk7gLTZgjnR1Odx3sP5fRxR3P0onSHPmIu63w66x+x5EcasB5HteUSIsdvETA17SLAYTdrD4Uc8M7gmDZxum0A+B20tOzC6L4BzE8rVfpQ0z9Xok2Kss3JoFTG7ijpJASEHrrZ3Nwiu9Mv8zbgrdmmwhoHON8bNvabh0yDBZWYcQ5+puv65MZGK56bUFD/9uHCocC6LxncW+KRdbbROk/uj6l63MPXYnLmvjQnLSIR/aPeiI7G4W48oo3lUyA== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:45: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%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:45: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" , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 1/10] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH v5 1/10] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHa8JsF83YbRhsklUG3gMBE1GAA6w== Date: Sat, 17 Aug 2024 11:45:55 +0000 Message-ID: <8D04A2BD-7854-49E7-A0AA-DEAAB537F1DC@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [a+QqwrX4jBFXAe5AcByVf2E2/IC8Jiy6bN8ynl2OvQObASb6qKvo8Q4f7iAbqr3BV2/C6I4TrFk=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: 2c3b28e4-12db-4e23-7925-08dcbeb22784 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: MJ3jlGqkI2NLwFkOc65wJB+iyN1COyppNlQ6E5H2PSPsj3XRQOkoZbV8wS4UxRpx3zmcMJWA6bnMvQ+qXbjDQ5OnX7an9I/P+2rrJ1REnrShtD6lu44P7W+XVmmuX8ihMSbASu/URlhb3Ezex1i1csCaanO4H9sMLUTl9nrBY3fsSR+z6QdM9gP/c5m9lprEA6a6r5ev06rcAMMrvaVC25+GIgKCLiNK5fJbi//Rt16J2rPFLR06K9mPO+0GTfDHdowe/k3WBmP5A9JYcvNGyl+b5kzvNXa5MIKwUX2qLMyqsTaSQOsGZeO7Bjjo5EXSaKYF5x62tIjBjVaidVAFNoYb30SThfVPTWN/ukcjwbXvLDcSS5uV0aGz8up609M1mDArzeKJNWGePM1p14aqV5cfFYE6KHwbHFNvVd7m36t1UKci/k8+to0e4nB4VezNwLN4GfgdJMeZneVbYILDTiKHQYg7ZuTpIKzXitQfrsJqaPFOeZdxEV+3nYOVggIvJ7BQ8SHjLGAI/dfE+joHSojgrc9rBfn7O3zwBPPNTsGqobtdW8Qn61ObCNFGpml3JEd89Gi+YS1AiuQ6B2+GK+x/zpt5iKTakwC8XNb80lOQ729M6JpmRLbcvK/JN/Bk7pyJIDwzHIYIjoVUDfQzYNn2zQfjOnHVJrcFvLeYnuLRhc+yrN22PTiuUMQI7SCh x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?ry2j3oDq+c1RYsBV/vwKAN35edNR?= =?utf-8?q?QTRAHznHmt8HiGo0AwWxKh1cSisqngfQYieMAptmVyzLMTc0xGb+jJyqlXKmjXaro?= =?utf-8?q?KeRciUJx6wwME1/qJeTr0PH79a7iTejVlPIYuK2f5PqLlIUvDXxZPkcHsnzE8h8QI?= =?utf-8?q?0/shdrk+3orFAxJCpdXVhObjM//AlPrP/c2AeQGOVI4lfqbD3pmZzpXg4JRdODQfC?= =?utf-8?q?FxxU7F6rIjqj4YbT4o8v7CHChkHr5Qmqu4v7Iqke1yjuXRGijLQ0bUPvfO5ZbMWea?= =?utf-8?q?MEewP2OaA2wtecSkVBZNXmhVdj1PzgmsPVCtGVe+zfKhZRtsARw0PQfD36FiY0dB2?= =?utf-8?q?EObz+ReqQKIriXiL5m69N7Hi2i/5U9PUFoe4/uFFuuJG8wDZ5id2u7ZQuIwf6SMRo?= =?utf-8?q?fFIzxnaUoYpG/Na9fn1md5cRnwWyNEBZT06ZHX+NVgltCPqGnHc7OGy8rXz4/NMmh?= =?utf-8?q?242xh794YrKISc+kbmP0pijAZhUQVxqfLpM0jRY63gRbPpQIZsyCO52gfqvEs5Nx8?= =?utf-8?q?6ErH4lIFzC4gM6NX+VOgfxRpTH/l/QQcLlc+Xco1HUa5HomHDFicA2xYjdOcOFPw6?= =?utf-8?q?xgCVTU2BQh3L8b9tMs/ZfAMPaag372vVM2SVhTbKNsB+90VMh9hSbr6hxOkTbpAej?= =?utf-8?q?QlYfOhz+BFp68vkClIF8obKR/4dUkUuioofcQRt0YsbEnnpENPKCE1zdZxknhhg5h?= =?utf-8?q?CDraQyUII6EN/GlkaXWzAxg+TO1WOKACdAvLJCL9m/XGkjbq4L+bgcVKn2zbtP533?= =?utf-8?q?A+EB1hGE4PjvjZC3IOHH2b7tR5UZEDOquaybXEdjZrQHomeiv8NteuUqJGTUuD/HF?= =?utf-8?q?kAKYQ8S3celtEHio/u9djXPI6u/3m3rg09LigyXflRaEg8nIm9UM6AJRe3Khkw4so?= =?utf-8?q?WWSRt6LnHglqbmvaRlBrXDjae5SFCWZnJLskYcJfIFONI7N0QRpPULHEQgTA9ZPL+?= =?utf-8?q?sAPZGrMUYQfAQ2/V6abpS8o9xrtwTLl42VIdI+R8OAF5n2YeWdDcM1xGtIg/PJp5M?= =?utf-8?q?bZ5oPZ4I5P0H2BEz7ijbIixrn8rz9kRFZk/DGPmkuvupp/yPAZnz34eq2MfMj9Btp?= =?utf-8?q?jpBkkVN6onv3bQPGPtRCly6jT415O5v1IYuj81zdD8d5au3AjcJdxsUvrx8sXf/Wx?= =?utf-8?q?OPbQs4SimC4a2bE+3IBVSxoQ9XPCDQEPH8FnukqNuEC6lCVwOKCV7S1QZEYW1H/Ff?= =?utf-8?q?XpFhiwdNBO9Ba7E3L6yK3RKKRkwaigGUdO8GYoDorsb8PQXWwbyZg58Ogh8akRX0B?= =?utf-8?q?0v/qpMjykQ3HcHcW?= Content-ID: <4B7BD82D27AB7B46B028F174162E5D2A@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: 2c3b28e4-12db-4e23-7925-08dcbeb22784 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:45:55.6085 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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 --- drivers/hid/Kconfig | 10 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-appletb-bl.c | 207 +++++++++++++++++++++++++++++++++++ drivers/hid/hid-quirks.c | 4 +- 4 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 drivers/hid/hid-appletb-bl.c 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..819157686 --- /dev/null +++ b/drivers/hid/hid-appletb-bl.c @@ -0,0 +1,207 @@ +// 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 + +#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; +}; + +static 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); + u8 brightness; + + if (backlight_is_blank(bdev)) + brightness = APPLETB_BL_OFF; + else + brightness = appletb_bl_brightness_map[backlight_get_brightness(bdev)]; + + return appletb_bl_set_brightness(bl, 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 Sat Aug 17 11:46:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767168 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 22BC5C52D7D for ; Sat, 17 Aug 2024 11:47:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 936A110E08D; Sat, 17 Aug 2024 11:47:01 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="YDa6Y2R/"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2061.outbound.protection.outlook.com [40.92.102.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id A1FA110E08D for ; Sat, 17 Aug 2024 11:46:59 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tF228ir6rJ1KjvEh2zjLPyzknHcWtbj89ZAAbEwPSMWP5Sozx6WhY/5hQqGvN4BWmh31eMSxPIuZ8cHwgekK0fSomMYKStK1Vrv9yuwoWI2ZOa10wE9ELVswfhFZ1JU/ZeAAzNM8t4qtkdf7y18Cr41svzCYMAZnR24GGU+Qr+rZizv1WI/Fan37Mhh1xUG1DUXYyYKm/KVHgYNm/vcrAgiS9SKCQfl6sA1px/gsbiw98U+xQVTn3VWcvgRw9X1C5vVPBDHoEb/0/OpW7eO5xgT6LvRGIguMkzCVs4eD5yXlgYv189BIoAIJeH4/ZQBRUz1qYL6JBoUCZKWCXeAWUw== 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=gAzRv4angoY9W7kjB4Ys1D/UfSSDoHTJa292p/uqW8Q=; b=ObUgzuIGf8yn1cKBBkrFwcBqoJ82FhQ5pOQBgn1oGLnDW9ozK1Yvn1CbFCYAWenMe4bx7wTfKmVB4Ce+C3qed8GCwBzQ8O9zv2KdWCHY4MTbER1BQhMj+c6hjnbeT4OPqsd8M1EIFgoF923n1NkrNpPJpjLSGZyfe5IDQ4fz1e7XiUoMGmldYhua8DgIH6PlDucfl5YvjJByNhnOIMBuWINeINu5s0JcxUJ+8pQgXkABz/sLt92J8MaHVxxeAThPO6vQNKM9XhwST90MZGJ6xHmkHEf/Zk/QbKWgJ5qwO+6C4LZuCkoPFt65jAtQ2WykGGlaJ50DTSRXhIXfHEXi7g== 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=gAzRv4angoY9W7kjB4Ys1D/UfSSDoHTJa292p/uqW8Q=; b=YDa6Y2R/WlDammQJCLEN8p+oNToiiRbCLmIfvv7CGE+YyhE18OZMk61eXBDIo5u+Df5KtgUDJN8a4hMl/7H6WoWpwNce0M4+riGHusE44QuUk53JgYzU9YoocnVsKRs7uCLYM1WOTzxIm6tZGsKglUEoefe2cWSouZQpg6Ky+/wit/0HuHZDJM3T2PK1QTAYu29tAqdS+1nft12v+p28SVzsvIyc+ft+OXUn6c98R/jH6uuz8/BMuJiT5NfsAa7HzH8rJkAciccqBehPHAMEITk9CNwNKEXryQtEFkoyiW7n54ca0ngjnN5ylU5D+lNdF7eH3eE8oCwEuaLoRpWgQw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:46:47 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:46:47 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 2/10] HID: hid-appletb-kbd: add driver for the keyboard mode Thread-Topic: [PATCH v5 2/10] HID: hid-appletb-kbd: add driver for the keyboard mode Thread-Index: AQHa8JsjpSogBIImykuNMN0RuvCLdg== Date: Sat, 17 Aug 2024 11:46:47 +0000 Message-ID: <0B505E00-A1D6-4D0E-BE04-311E231874C5@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ZF2ZqM3qYjTJg8io+3BzMQq+zUDbRw1Fixsy1pgPnWQafElTb9f/MPTzeo7Zz/zLT/A2Fu8rdBc=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: 2c4d06c1-5ff3-4aab-9cb9-08dcbeb24647 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: KQgPEox5ljSQ6S14BXtzd8aa8L+bo904wuSy1Qc9j2jUbSOr12AEdSX9PCV27PPYf3/VwXC0+I8L3NQMN1vzHeRRfnEQbyzyVdWyLG8Ozg/gi01Ibp5GEUhJBNk3rUluSaigShzszJ8qasHUe2+QGziV/ei3QU5rNQ4QDlFlt3FmL/1XQ5NGs9TW+p11T+cy1Fr5dLoLyp+3Z+mZQ8uXFq/bpypGtoqTFagMOmLFyCw/X02sDKpN2lIXl/XTgSAy/cbV1EO7LHKlOf2g8R9Ro6dhpK4jTNXYxAN6r+qhFbr+eE+Wz00K2kOMaAhtzfY/Q/7hak8eeYF1YKtDh2zxqUEECq4/3gpatkUzyY1/S9/8kkYoX3HeepSGao5/8+bS83lA5002QdDNUCFIQ3W0oPut/8bZ45E74ID11gyagIwQ0613Nv35slqKm7FDiOQyzkjNmngDZ6qC1Q8zeFcAdRTxgOPt3eSHrsE9PS2idTuQ44+B+eU9cP78YKxz1MTt2DoJBHkObQd47aYNwv0wIKT1LQcW3/cNEyvUmiu4JJCQ0bpFslbZgY8AGAo2W/Sm7yuAZJVeuDTcDU7ByX4LDbF3/H/0zI4CpWm7XYAsMOgh9yVL6K7kHOkCAM6Mci00vVrB9HhzlQuF5+lIx71WaFhT16wn8KLjLNNwDIXh0VYRUkGxFfdb4Syh6ZnXxYhF x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?EeXj9R64k8bpy0beZnr0ryjnNi8k?= =?utf-8?q?yGy7bMIPgnSp2tBNuHRIZk0pevKFM9PbqhaETcpAbNjGvJu55V1HAmJnB+wI1g6X8?= =?utf-8?q?tVo1ueVe6Whl7HcBRaEkTag3oqFvIMQ/vn0xhJUphBk7/ZFjOg7pyX7ouYu0kZ7rl?= =?utf-8?q?emdQ5L2QIY4uh8GAMUPVCwPbfSwxdUYdfE6m45bq+K111PGWwtG4Ozx+fZxknWfLj?= =?utf-8?q?s1gUDAwmCqCPXSLg5dmd51HiUPp8AGN7OADeSNufKV2hhksvH/PvpDDKxXSOgZopj?= =?utf-8?q?8RrN1EHbCjBDful6JsWH2NyxTKXG+MYe43YLHnux+UvwQegMeOpGL4yU5VKQNpfb6?= =?utf-8?q?Eu5xi3Nl52kuGH9ZokO4jgQVopjYwtg3ocjkuZbhw+oUjRwrWna3WfWcybeiVCLrC?= =?utf-8?q?9PT+YnwPSJajCoAjBWoEgQwsqNUv0ZbascHnPa80wZTdJ/knChlZMDcJ3kmUN583z?= =?utf-8?q?TSH9nWBSzpDBKf+mTohJEw/zvAriKqlIkrw9oPvU5i97XnrUbO0oIQYdK+llrLNUr?= =?utf-8?q?79Gw9g+7UjyMVEPaotDFGCYx93vzA56lus4RIrSBfkWxdIRCOtzVyeFUYuXRuOz+5?= =?utf-8?q?OsZMRkPjfH2sh1ltOLUU9gCK6wAess7p4JSeF4xRTVow/MeIDS8YVcRLYTD5yCS5r?= =?utf-8?q?5t5sRvthKS0TTYD/XwZElw8Wqr/z7PAd4bXtrLr7tZmKFeq4/IkVKHrbxXPisPsm1?= =?utf-8?q?ITcijU2vOEwEGHP7CCfagrf+zKu6BIyuAX9FwN2qP9XXkaDdS/u7RCdOptni8BCdU?= =?utf-8?q?g1WwRQKqjpliKkNRfX874KVnNTG9W9waOFBfZ1AG/rLiBG+UXTa0+tIfml6y1av+V?= =?utf-8?q?enCMTzyop3tk/96jX78dfliFicLF51/ar4twJFaAu1zuei7cCMrY8HGFVDHJ0Mmb2?= =?utf-8?q?xzBSjGAunz0b0YbxOcm6rDvUruRle6ZO+TgO9+n5gD+XDMDSRIccW+m+QwF75F7j1?= =?utf-8?q?n3gWiHrMlHSxgaqGNyRCzgFZFngTBVIGT7XU/7K3e/3RhBWQqRaCT+Wk+aGnGuHzQ?= =?utf-8?q?VjX1dh1ylVVaYwGwrMwPdrryQnH/1x7a6GjPxbXxTlzkxJ7HQTFDnOPVDmYJMNlzB?= =?utf-8?q?2ehFHw1DkmQQiaxTpdqrOpiMEWISABxBU3eMwaoVSA2X+PPUy+ho4Rjd/eeWJa0kr?= =?utf-8?q?cd8Xqa9gLwR21eA/d1JvKdLskDd6wpxMqmzAMTGCreistO33+tbvJ+RnYzwt8XCce?= =?utf-8?q?Q0kp1WYNz6w8bqPJQ6q46tuvDBdGTijGF+9Gva6zkSId3JgBagJvBbrmXh/zTw4/N?= =?utf-8?q?TyksV5frIoNuOqsV?= Content-ID: <1D45754A28ABFF4FBD64BB3D862D1E65@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: 2c4d06c1-5ff3-4aab-9cb9-08dcbeb24647 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:46:47.2198 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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..ecac68fc7 --- /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_SPCL; +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\n" + " [2] - special keys"); + +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 Sat Aug 17 11:47:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767169 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 5E98AC52D7F for ; Sat, 17 Aug 2024 11:47:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D13AA10E08E; Sat, 17 Aug 2024 11:47:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="d/W5kU1K"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2011.outbound.protection.outlook.com [40.92.102.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9026410E08E for ; Sat, 17 Aug 2024 11:47:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OpQnoYk1AY3wRIJOazhxvEIwfSZIBxhGPw9f7BjpxHoqFFQPU/Q75iWY+bjnr4AbosNJyOjYdW0r2FOAPeg8F18G8x5oJ+gUH/vnFjvj7n4W95ZgOSHqBDE/pDNUhUhYTXTfrCfrjROHhn8+CgJ17brUPIMGOv415adF8TGU1evj2/GFLWd7AQR1tx0nmx5PIP+gTp5M8Kqvx93SSvYOI8PI757GOFclwmaG+exMm6XFVCiC4Bism2JQi1TnZgYxW3sWbzBnWEaq3SvfNz4zbtrUzbOEGSGMtPO7n+mrjtVg4YgARVTzt1YZ8KwiSZqyNTW967F4Q8OTvtD7dSZ3yw== 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=rksG0PShVf77+ncLm+Y6Lr8HDvgrVuZIjwB0qkcNqfw=; b=db1v7Vi4WksyyMPh4T2lz1qtNQ9z4INiavW1mBPELtw15UOZ1Yc2XoVuOkqN6PoEpgENeQ5oP/2/PhwWMFUR2KgLR3KPI/4cimRwozHthQPTEXng2mTE+JU1i1BjgnuawsV5hWyQwq60f75ZSHrrGcYcDUtmypG/AF/IdxVTIWYKAbiDIGwitn7pqu6S3OzEr03/vKWhRloftAb2sJQfzrkGiVQEpcQyYdwnHw8tpMQfI/hLV6kcKPOoCDgZllZXX3yp0JyBsKKSUrguC+7eYhL6W+hjl3LZoiOjK+qFpRml5Kvsca9nwpagpAwKQh7T+S2b3+P9fdkaShVy2Oq+Lg== 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=rksG0PShVf77+ncLm+Y6Lr8HDvgrVuZIjwB0qkcNqfw=; b=d/W5kU1KexMyw8Uq4EkqbjHdXIqZ7HBN65ewNzVpCenUyLmKmx5nXBQzN+MGuTtcZ0HonbxnNMzwV66Lt5qb/tDN0Acq40XC6ZWEYv6O+QZK6RLNjsgKU83Rkr+OZeWQQa4sSqiS+cWk91B+QtV0pDZ7lFEN3cFfaMg17Ui+RnbNaKocA+/GHH5gMGTU/sQfARj/S6QGi0vNwmnjVjMkbs49mxMUvMrZrf4xDCar77h0cG89VjyPWaDrGm6t0V+GaHK72nFEakQ1BqCA4/igUXp0bn1UKuXqF4y+uocuwvi4QpVUIw7vFtM3R0veezwYjh7ZOWpVzL/L4JpPtgloLQ== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:47:29 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:47:29 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 3/10] HID: hid-appletb-kbd: add support for fn toggle between media and function mode Thread-Topic: [PATCH v5 3/10] HID: hid-appletb-kbd: add support for fn toggle between media and function mode Thread-Index: AQHa8Js8PQ8afFSH10idm9Ss908Y+A== Date: Sat, 17 Aug 2024 11:47:29 +0000 Message-ID: <022CB692-B465-4485-B7F3-31F965B3963D@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [AK+2/Nm9UfrWAFgU/yO+MA8I/IAN6YeuAQBLy9m8P8DZv8uJ5si7WWq6/aVRSxD1XUVI94FsOCo=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: 38867387-a24d-456d-11be-08dcbeb25f4e x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: lrGuntFIOwp4/UkAnoQA81QJlvY57/nMCx33w8dF9MFF9kFqw8II8OwZ9yUAi6v1FoLsZXyoGOePsSzAlwl2a+Ia4x2AIfhYOsAHbRX0qFf6HYoT4yfK4lWDfYptav9LqyUu/nJfGT/fSKENU7i7yAeSFSapeJXZBzYwQiUpx/ejCMPLm2cCmg213mJb0MWKMhkuX/ixmubYNs8BVDOmfHj+uF7KjuNW0eWEd3aYFOKB4GDmLqyFpggHzhluwyiCXNX9Xrg/lfDXTrAvVbExr5RSZgI99d3o+qx2gImZAdP1+jLPXlLZp4EtyuDOx5Quxbtv3rJkiIdSt8dWgsdX1r2Q6mmuj+eC4csXFfKMaS6ZmbkWgjfSv9E3p5OJVVNaxIHTHP9xc1Squ85ffdALv3W4wgp01BTMZPhO0B+vH3f7BudxMXWapw6+ZtLueVnqAmzEII1ODN/+fKoC1hpKVCzHvDChCTtl1gRJCfEaV1mluL0rDvTSYIXIxjfJjZVw7u+Wg9erLFnmonJ+ac9F7n2H6VvM7I/WE015UPlr+k3ewPpsQp45RsV8VxHihuu4QxEFyHrJWhX3iYYEPBLl0/pDCXlbk/c0/Xj5P4FSEz4CXhLOh161/8XlvNpgZQAugeXgjrUpXI1fybjQpgmuNMLCslNRxgmvgrWls7jnVsTjyTciNzs/HUMSG1+JJ9fo x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0MfXWRV+HCqmQzXseordGwR?= =?iso-8859-1?q?Cu6wCdsiWlbD+7YTzQkSjA0GaHIvETXsDFkc4VnRCQDhW3eVjtyFlLfd/S85?= =?iso-8859-1?q?Dzc4K0UYHksXUXeAaw/zkv+Dz2y4z/x/bF5bMx5XR6xWpBq0f3VkqX9Eb7dg?= =?iso-8859-1?q?eBeFuNhb3KUAEpxspbNbNxqS967zG/Wsj+W7kOZQNibwg6TmfSus1nLfnDoA?= =?iso-8859-1?q?HyyLWwRBDBiDWflMXA4qyWvknq/midiEsXPrggGkj4Oyl3dsVtifiJiFtGGC?= =?iso-8859-1?q?ZX69q/plKo2/oq6KoxIcDo1LlWD9Z00OWeKAfY4t6udkgGXQL3RJQorYW12F?= =?iso-8859-1?q?gZhAUeqBHxNSNeOy3ls65vc2BNFzTEYthH8mL3pIG6bkYhs/7OLWVMZBF3uI?= =?iso-8859-1?q?Le/Xc9r8uz8upgAKdLo8D9QfKw4NdkJyoONyCWBIjtNrEG6MuPs/h7MU1eDO?= =?iso-8859-1?q?IPEc73zZN7stn7WkQFTGFS1kyTR0tMrtbtvx1Exl1ANSJjIlbQeqApkKwX3i?= =?iso-8859-1?q?jL+fx6WG6C5TKtiygSRCDAXSuE4SGkQnrJm8EwQPDPhPdFaWrqjkyablshZc?= =?iso-8859-1?q?zN+W9v7pTqgkuCJhZ6bupt6NYM397I0+Yu1WTt3c3tziuSnG4eugzZcGNz8R?= =?iso-8859-1?q?B266k+p7zFDjhB59nYDRGmiiscBxx4ao2dUPxgpOyLSyn398hYoEwx8JqjwB?= =?iso-8859-1?q?AUPQMr1/OdzwiYCh0QOpB11AtcbuBlDN0Y5GIxBjOyM01TJfNZYgiwa4oUST?= =?iso-8859-1?q?z0r63LokxkD1+EwFCMZxjVaTVTOiB7xIek3543oE8v93QfrfV8AnmUxDsxQC?= =?iso-8859-1?q?jblgTQ+JRNRXwdQCQoWmbmWIoxEADoRDICvzYvqFSAJxmysO9EoSrjIBjrSM?= =?iso-8859-1?q?wGs3ZAAlbFy+wYip6rKcZW6qTTDNRojwHJvWUsuySDvtUlgdKlOg8MxFJs7o?= =?iso-8859-1?q?59hOval5sprZJPzGrW6YKsmggGUUrexOMaeTqwxSm2ATbUe2NK7reJPYS+uc?= =?iso-8859-1?q?vOg0v5S3nZJm8rE/wsgiOdRPFLAS2J7G71TPeGYnHyYRbr94+piLRcltzwdL?= =?iso-8859-1?q?0G0ixPGRMDqmlh8n62lXEDEwDDCTEFsEZZWrTBWStIOki+NcpbOE93ZLQZzE?= =?iso-8859-1?q?qvpdttOByj4KGNQHSvhhgsjLZBA6YdBk+BAdvO2HU5qBCzKLFlqu2Vs3azFL?= =?iso-8859-1?q?llXcUZ5HYQztYcKMNYJWZBrSCFSRLLQoBEH2+qQekUuKtJzrWqYP1WCNtTje?= =?iso-8859-1?q?aKSQB9HrJ7k0ByBgX3ihF/Qn0TwcAy0XVM/h5YT6Ldr4o+1ZthpeypLnCbrC?= =?iso-8859-1?q?+AYZy185kEbXNEfJUsfG75QnIXMOgwBxSFMX3X5Mv6OgCKRzW2ZW1R8da+hf?= =?iso-8859-1?q?F?= 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: 38867387-a24d-456d-11be-08dcbeb25f4e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:47:29.1628 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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: Aditya Garg This patch adds support for the switching between the Media and Function keys on the touchbar by pressing the Fn key on Apple Internal Keyboard. Signed-off-by: Aditya Garg --- drivers/hid/hid-appletb-kbd.c | 128 ++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/drivers/hid/hid-appletb-kbd.c b/drivers/hid/hid-appletb-kbd.c index ecac68fc7..442c4d884 100644 --- a/drivers/hid/hid-appletb-kbd.c +++ b/drivers/hid/hid-appletb-kbd.c @@ -26,6 +26,8 @@ #define APPLETB_KBD_MODE_OFF 3 #define APPLETB_KBD_MODE_MAX APPLETB_KBD_MODE_OFF +#define APPLETB_DEVID_KEYBOARD 1 + #define HID_USAGE_MODE 0x00ff0004 static int appletb_tb_def_mode = APPLETB_KBD_MODE_SPCL; @@ -35,11 +37,18 @@ MODULE_PARM_DESC(mode, "Default touchbar mode:\n" " 1 - function-keys\n" " [2] - special keys"); +static bool appletb_tb_fn_toggle = true; +module_param_named(fntoggle, appletb_tb_fn_toggle, bool, 0644); +MODULE_PARM_DESC(fntoggle, "Switch between Fn and media controls on pressing Fn key"); + struct appletb_kbd { struct hid_field *mode_field; u8 saved_mode; u8 current_mode; + struct input_handler inp_handler; + struct input_handle kbd_handle; + }; static const struct key_entry appletb_kbd_keymap[] = { @@ -172,6 +181,75 @@ static int appletb_kbd_hid_event(struct hid_device *hdev, struct hid_field *fiel return kbd->current_mode == APPLETB_KBD_MODE_OFF; } +static void appletb_kbd_inp_event(struct input_handle *handle, unsigned int type, + unsigned int code, int value) +{ + struct appletb_kbd *kbd = handle->private; + + if (type == EV_KEY && code == KEY_FN && appletb_tb_fn_toggle) { + if (value == 1) { + kbd->saved_mode = kbd->current_mode; + if (kbd->current_mode == APPLETB_KBD_MODE_SPCL) + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_FN); + else if (kbd->current_mode == APPLETB_KBD_MODE_FN) + appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_SPCL); + } else if (value == 0) { + if (kbd->saved_mode != kbd->current_mode) + appletb_kbd_set_mode(kbd, kbd->saved_mode); + } + } +} + +static int appletb_kbd_inp_connect(struct input_handler *handler, + struct input_dev *dev, + const struct input_device_id *id) +{ + struct appletb_kbd *kbd = handler->private; + struct input_handle *handle; + int rc; + + if (id->driver_info == APPLETB_DEVID_KEYBOARD) { + handle = &kbd->kbd_handle; + handle->name = "tbkbd"; + } else { + return -ENOENT; + } + + if (handle->dev) + return -EEXIST; + + handle->open = 0; + handle->dev = input_get_device(dev); + handle->handler = handler; + handle->private = kbd; + + rc = input_register_handle(handle); + if (rc) + goto err_free_dev; + + rc = input_open_device(handle); + if (rc) + goto err_unregister_handle; + + return 0; + + err_unregister_handle: + input_unregister_handle(handle); + err_free_dev: + input_put_device(handle->dev); + handle->dev = NULL; + return rc; +} + +static void appletb_kbd_inp_disconnect(struct input_handle *handle) +{ + input_close_device(handle); + input_unregister_handle(handle); + + input_put_device(handle->dev); + handle->dev = NULL; +} + static int appletb_kbd_input_configured(struct hid_device *hdev, struct hid_input *hidinput) { int idx; @@ -196,6 +274,40 @@ static int appletb_kbd_input_configured(struct hid_device *hdev, struct hid_inpu return 0; } +static const struct input_device_id appletb_kbd_input_devices[] = { + { + .flags = INPUT_DEVICE_ID_MATCH_BUS | + INPUT_DEVICE_ID_MATCH_VENDOR | + INPUT_DEVICE_ID_MATCH_KEYBIT, + .bustype = BUS_USB, + .vendor = USB_VENDOR_ID_APPLE, + .keybit = { [BIT_WORD(KEY_FN)] = BIT_MASK(KEY_FN) }, + .driver_info = APPLETB_DEVID_KEYBOARD, + }, + { } +}; + +static bool appletb_kbd_match_internal_device(struct input_handler *handler, + struct input_dev *inp_dev) +{ + struct device *dev = &inp_dev->dev; + + /* in kernel: dev && !is_usb_device(dev) */ + while (dev && !(dev->type && dev->type->name && + !strcmp(dev->type->name, "usb_device"))) + dev = dev->parent; + + /* + * Apple labels all their internal keyboards and trackpads as such, + * instead of maintaining an ever expanding list of product-id's we + * just look at the device's product name. + */ + if (dev) + return !!strstr(to_usb_device(dev)->product, "Internal Keyboard"); + + return false; +} + static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct appletb_kbd *kbd; @@ -228,6 +340,20 @@ static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id goto stop_hw; } + kbd->inp_handler.event = appletb_kbd_inp_event; + kbd->inp_handler.connect = appletb_kbd_inp_connect; + kbd->inp_handler.disconnect = appletb_kbd_inp_disconnect; + kbd->inp_handler.name = "appletb"; + kbd->inp_handler.id_table = appletb_kbd_input_devices; + kbd->inp_handler.match = appletb_kbd_match_internal_device; + kbd->inp_handler.private = kbd; + + ret = input_register_handler(&kbd->inp_handler); + if (ret) { + dev_err_probe(dev, ret, "Unable to register keyboard handler\n"); + goto close_hw; + } + ret = appletb_kbd_set_mode(kbd, appletb_tb_def_mode); if (ret) { dev_err_probe(dev, ret, "Failed to set touchbar mode\n"); @@ -251,6 +377,8 @@ static void appletb_kbd_remove(struct hid_device *hdev) appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_OFF); + input_unregister_handler(&kbd->inp_handler); + hid_hw_close(hdev); hid_hw_stop(hdev); } From patchwork Sat Aug 17 11:48:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767170 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 95B10C52D7D for ; Sat, 17 Aug 2024 11:48:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2362010E090; Sat, 17 Aug 2024 11:48:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="XjkbhSN8"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2048.outbound.protection.outlook.com [40.92.102.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7BC1310E090 for ; Sat, 17 Aug 2024 11:48:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q9zKwqQ69HvNRmKqXfxekdU2O8GKUHL3FJ+K8zHZ2h7Mpk0/lq0HgnuyUK8GnfJZQZ3s0ROlKIU3bduG2WkGZU8mbP7KuX/vfh+SKRCtxVPb/u1XTfwrw/Gxi8/Urt9LDUGCGJ370Ntv+Dq3NXcC7P0ZuZiVRAPifxoT6AU/2YCjLyU4OehPbB5bKJim80Hq4ybYUriXdwR+u904bEhoogrfYGGM5BiN8KmX1eLrn2duK6Nb4HevQB6nYVzkOAtf++lcppfGyIsAgB0sl1JAk9iIlGxPxv2FtUP4zmHTo39mempN0orWbz3QPI/S9TOtJoElawNM7p4Q2zjqtJLHCQ== 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=ezBa5SuXo62e7ASomopRq1CcIGTMHUo5DpzvmMIRuGc34jswjuj3xvqiivTn9PYB6wVBoePXDisbI3VqMdee94TkAXkAQFo9j1LwoFB8hOGeiBOBMH5GMQbDBdaAf3j2GRmYUAso7fHnG/4DSdODAYetyOSChimAeK/xccUsX/SHh8qtJ6n9EqFMUIe4UWIojhviK2ZBfUSPbSXQRc4ZWWBHAY6ruxnKbuFp8dwNr1i7guPBoarL5fVw1Xj36uhwrI54s2jzy2Ls9yr+lslSue3idpGtsRKBMUSGuLUs2+ujiYekJ0ojae+WsrsFoh0HiDrWWBVZXJbSOR/d4bZgeA== 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=XjkbhSN8k8Jt/ioJ2XsNbKN/d748SJNbvUxZ6JrRdzxZNUF+NHCYh1BdUDeStopefXwSzCljKBTCNGk5Rf9tf+DfhapiwoY3w1MHiSORSW0jKlNs/4K4aZ8eMW9h7aFAdZZM6JKilHdh9PBV/gUiuO8v23GKvMD2+yrw6AfB3nVehEEKNpnTib1gUMledVAvvB4FWgD7IPEinEg/uzXFgf+2HJEiW0aRxCI+w1l4FbYkBtrO+Z3PgsFy4SBdsJIAKrrU7fCsHi/YWDXG0YXKIN0F/TP82GpWESV4Ych2lHQxevZfq63Ze716tgRCRTTWQbKsNHcrItm91oKmtWhlWw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:48:08 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:48:08 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 4/10] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Topic: [PATCH v5 4/10] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Thread-Index: AQHa8JtUUasJfYprSU+JVVYDuJLkBA== Date: Sat, 17 Aug 2024 11:48:08 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [S0VX+XTgBOMGSEKDCck97VXZiPl2R8k3CzAVo/zUOKApfuJWmfZaTHUwVFGXRmQMJcCJnz6NfYE=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: b00e6bd8-42f2-409a-75b2-08dcbeb276ae x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: 4dT2Xq1nb8DHcy9EMaVy32OuJi+t6fkpKoUxq3DJ44GsOriLapC+Nc4k7ITdBd12/PIvywluFs/bo3vK8P32RO3sJQ/7qp9QRrCdZ0Hs/HeWnNFNMOLeEu0hEm1YWNSz68PHSLVJq/f2sHnpQmqVcLWEG3wpeQQeCwiNs/of4I4/poxmQOIgWYUwFxF9ySpXuDw6Z63DS8NGlEeE5sQrhpP72AcOuqVIGCw2gSQUErptQELrYFB137fwl3ZKiIcKmxnj630Zq9G/05wuNM9nqK7z3uqB7c7GSTFYtX61aNLpavct3GtAFDZmH8l4oBwbMK7g23KPq6mi/lGMdH1Z2wTtDexHII8xu0avC7OOeMYUwpdYl/stwh3UJCH/7uMG8eiPQaF4PNPXR34xUqAXxygLrbt9g2OJ8M2zLsqBWVAEu86/PRs3BGOSFNfSksgRttWzsjcwSAEscsHksTMDAoHDF9RkkvjU21LN+vnGBQauM0bhNwC7yLcnmeWsbHmYUeNbKDaXs3V4H4WatL2s72aEHXnVQ8udcnClinn0aaTEidY+NSNoGidqo1b5fGZqSdeoJ9jZVVFc9K+d1x3r0JFKQe1EKIpXUx9ey6wXPdI43jCi+/Mel9ffmlBeg4wE8kMNyhOL4l1GEmpjRs317yWuyPoFGSLTJz4HNfDNGSEN+cBMg2g66RxpHOOtGLeZ x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?uZdfrnmvXEb58+TYL10OPUy?= =?iso-8859-1?q?tiqOA8oNru0kPS/GJr73DTF/YlzasbM5TAShdosCOpiMlaKKF1qiRq84boN2?= =?iso-8859-1?q?xp6Vwa+w/JGxAkjrVJEizGuGkwzjJcmURhVbdVDWGZhbMbDnBpiIEfrH1KXc?= =?iso-8859-1?q?tel2febq4xU7fHA9eeMJNuoD29hHvjV3pv6t0KC8zOLIwkSbM2KJCBV09V4R?= =?iso-8859-1?q?jFcghiI83RZIFe0hiZuwZxbE83Bh+MiYudIrWtgZbQ+MIA+VBngEWc9BNK/l?= =?iso-8859-1?q?bK7dK873Oc7bp6lCXOM8ePYeDGZydrw1PoUgq6QUrJYQZMg+LMhJPaU8zC9P?= =?iso-8859-1?q?Gl893nFEvW6c8smbpjUJleef1+hwDeAg9+DSVWPCe8dOltzjtO9TdpvAlX3n?= =?iso-8859-1?q?N6I7j2rL6qI55Scb51HCTWkSTD4HLev8XGfZswcpIqCPwR5WwT7kMbKgzUEx?= =?iso-8859-1?q?ecvZisSNVhRMZ8MOq2Cn4EObV2rNfac7mlgXSHPCF39gO+UD0GJnJzIBVIfx?= =?iso-8859-1?q?3tv1EY2PBt1hlZadiFzlPX/5vwgkGxmRE0rFcyCbYb+20AYBR71a0LeniyEX?= =?iso-8859-1?q?G4R+AkeVSPM81cZQ8qDUENQin+fT82i+Ov5wSue3uH5RTmVh4foPFIoMTfFm?= =?iso-8859-1?q?TPr2WahfK57zX5EtY8KKebPUo8w/HRbPpF0Z7UFT4WSv4VMqnj/MackuqCMf?= =?iso-8859-1?q?mwqpVBaepqasg2qCoyBuVWiOalAeIvAKRTOA+K029Ii+xL8l7oFfOpjw4oQL?= =?iso-8859-1?q?Pz3cc5YOcaSMawKTabQBWqw3dsNmotgmy3k20jW7hwe//wH6zWvpnFJfhv7k?= =?iso-8859-1?q?5+3GUWakL8HMSJE2v1/KDfABwi6oGEv6j4yOHKL18UdVo6AZ7EN7oVukcegI?= =?iso-8859-1?q?JXUVFk5rgjU9l+4p+bF3TjkMyhcel4IlCvIJoohNqdhqGQtZCb7L7IzGWZ6d?= =?iso-8859-1?q?zOqraGMD+qe6PQMAUmrRMMmzBAwzQxpdT1D03IOB/NXWde9x8Tm8wUPQHUKv?= =?iso-8859-1?q?7vROFDaF0MYKEs6tVCCReQC/Rur6Ximc/q3LtGN2OHHoxbOVEiEWYtyZt705?= =?iso-8859-1?q?hen46PzTGef9d6en5BXXK/Jam3TT2mG9IwIKSw3Tpg1sOSRBSGNtt2L7OQi2?= =?iso-8859-1?q?F6fUeoU1ESR02sK1OX5Nv/y6qC0oPGg9veVZ+Q2alHYqPJVTcCOSuMq78L//?= =?iso-8859-1?q?l6bTB66n92dilyPD9vHO89cqdkis0/4XBDQ8j8JzIq1EgHQz32jGJXtBRk3j?= =?iso-8859-1?q?slKLKTuqoRlxkwGk7mpCE6+Hzr4IIluJq35NhseV76gGPfep7HYLdF46VAV4?= =?iso-8859-1?q?g+XZvMC37vojxumQxnkrst4J3tq/vieUhincor0WJWdaOZl5T8ZdeN/0bR/1?= =?iso-8859-1?q?I?= Content-ID: <359F22DEC835AB498FF3F448CAAC57CE@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: b00e6bd8-42f2-409a-75b2-08dcbeb276ae X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:48:08.3902 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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 Sat Aug 17 11:48:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767171 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 07D85C52D7D for ; Sat, 17 Aug 2024 11:49:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 712CD10E093; Sat, 17 Aug 2024 11:49:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="EExkK1Fy"; 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 9FF2610E093 for ; Sat, 17 Aug 2024 11:49:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kO2nycgBDJCBuhoQdkWLedNQTR+rXiG3AC+yDZ0P+Kke6EtvpOOfHa58aZch2+0/ASFa9Bho08XEy+0zJUz8XkfkCEYqP1Ykvi96o55F88c/Jyy0spYLO7SaRcDeCrZh8E9iGe35raGQbp4yycBo9TgYd2TGFcS+/98OtX559mTdThh+d+tw3DoHgbaScoErOKedvSTSzGzmT5N5X9/KijyGpV5JamUif6/ISMrmYv2GiVHty74brBIbgBkpGQfj/PFVi5LBJ+6btEFeb/Dc4evXbIR9T4Ro9oHRE0YtMCr9Nf7kuLdFOMVEJdL/9v5V3AXWtlSVi8Ikrafa89GWkQ== 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=NH7yyEtafIRiPSaZYTY7sarJKQywDFxABxzbiPr5h1+plcGrDaOwQPagMZ3QiDrvanwjA4W8ZGrb38s80jqcDo+V68ED02H9J5yZZ9kex2r/BMAFL39r4XWkyVIKMO4rNsmGaP+XZnA0N4lZJajgEfqw69uQZS+lQPjWp7bh8Vx8HAsT135XxvQ7Kr0Hn6zXPQVSqZnI5RR38DzEJUpgLlwzg/Nf/dA2xlSRIrePZYCZovTKKaJsVCTMQT4ZOh8YJ3COsu1FCWtydPtzT5iJ4itn+YfoHbGC4BzVoHSVQKVMbOko6HAx40SytdIM0NjrdKQF5P0w1LZts1/aQpNGwA== 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=EExkK1FyfhVb2xJB9MvSwNlaDH1+oji/o0lZoQsN8LDsOQicLJTw0dIOAh679yR4c4wh/OVRnKZPFz6hUsv6jfmD2LqUT8u3Mw20S4RhIE10yRSIA+f0EvHlU+JZ6xIuUv1OUwYBe0VL0UpYY4euMi5g3nVB137DzHIySvLnEDk8EAhRhnTgto1HgAXJVWYyJkwY4X/mk8rHORCcNP2WqYKgpqNnbShU1LN97qDrDP9RWRnXN3VqsCe88AvKP8PK1iOT0echsm0Kj79EwGLNrXUfFeKtjy9NJM0hpSOvwc7OjNFHJYoUlYJaGomsxxnkvwBT3QMcZ8Ww9ny0HUVZHw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:48:52 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:48:52 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 5/10] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Topic: [PATCH v5 5/10] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Thread-Index: AQHa8JtuGQaG8LLg5kyxpfXXHJcxPA== Date: Sat, 17 Aug 2024 11:48:52 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [98PHWyToOBdokOQ7FGATaYV6lIRHWoQNx8hF+dQQd/Bw8hTsHLB+MCOrVuEogJ7pk+WY61OqaAc=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: 81ade7e1-b17e-41a8-7b0e-08dcbeb290c9 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: 4fFrrFmT/xtrEpP+REqiJy2owTrzD9EK9a5123giw7XbG0aSTD3YxGvZHyRQ54K/Usm4A0YdD8jLL/7i1hdKUVSyVc08pD2xHVViufflm3DY+wNrJGWMo3y80lneLiC5ufYV0DVNr866JN5/zm3Cgprm59v0AGD1p0gDiuGukAyJJGA4GeK2VG4CCOHuwQq0f0HkJPeO3v8ZXtywiCym+tXO5Q6alqcwNB8tytEuqsAmZ2iIGFS1WTS0XFUS+8JPZGG3xBOtY8pjpPxq2G+Yj1N6qh2dNbbsQOEOSc5tNOuMMPdJbndJYpbivh0Vz3FRbcV2P9EU+QXyHM1dqLXMHE4MtWse6hkTE9eL4vN0YU70sitep0dTdEADRNCR4+NAVaRjR3gd+Im64TTzSyJSqvLDQym9dgZZHqwiAVNJ6Xrc8YXLzAZuJyc5kBmg/ZtNVGDX3176+zIOxsbrwzZxp7A7Y4FcDlYQQMkURRmd5OedjMJhqizpE9e6mdz/XwuriP2ZUZdy/X71wMai7Uw52vMD8xDeNecrtDe3qKNHByK+4ppvWAIjNPw2sOXyd6lFsVWM1oQMIQWPapBNhY8J60gLa6dL6S5jg8TfyjnJbYAR27UQCKi6J/TqH2ChJ+96MHIvpfKrTwVLy/LvnKCOv+ppSsi8dmDVpGXgoqNbEfcHgXoL0hQZlVydJN6pKKJw x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?oSeMMmt9Vn/RF9fJP6iDCCY?= =?iso-8859-1?q?+nljCrw2mU8driiFetfd7zFkt7MJvHoAhy9TwY9dc/okZ4xyNgmfzN7C2VWS?= =?iso-8859-1?q?2wVRAnn0lwPpVVPlAzciZpi6qlZk5mKds5sXM4DuPrlsKpJPaLWe+SSPbMRr?= =?iso-8859-1?q?76szGCeIpLYlIDdpNk5TXQZtiOlhIUIqsIKUY9RzfwZ9kIQxtiROV5dtLf00?= =?iso-8859-1?q?W/ZHbJehMaAerF0Xp3m0mFvXCvNEBte2uyf74cmRAk/3rOHgNvZqvHOqAe1Y?= =?iso-8859-1?q?nbOhZ5BiJjNRm2xxYoZIi7Ywww3W5UGNdNerAlUX5uWc64mzlE6ZrNl+iNC5?= =?iso-8859-1?q?Hu0563dGXu1/9SaP1PFlduo5Nf0ntxyFmp4GbOrpUht9WyS/daN1AtiE51iT?= =?iso-8859-1?q?1/vxeAHR/m7E3UQVqC32y9voPklRJYT4cFFzLdroP9oVre6lBBtdnfJfU9zW?= =?iso-8859-1?q?gmdheD6xhkkX8VTYgm4DkreNpNZ2R8nZ94RxZ90orNGEh9DP/qxCMfI6K7WV?= =?iso-8859-1?q?ju6dSdMk5u2cwLYmd9xcZQVJem3yYkqTniTQyFMUSyoQQtaQa4fLwV8/8kv6?= =?iso-8859-1?q?USh1sGxEdsmfqsVweXf/EKKEca/pwn2YRkEw71c9C9UPq+YYuTR1JU4Cg67M?= =?iso-8859-1?q?bQpQab9v8KSfjFnqDLwxh/85l9QpfgpC0eVEISo0URVTTgbgbfmN6Mo7Djye?= =?iso-8859-1?q?C1lq0I4bhQZ8prLW7PJwmYeRs9Xc/tqkGWjxwYh8x7BAfwESi1kpUfKInUAx?= =?iso-8859-1?q?izVYRPkOeHa6tq3JCqa3DXeScTqKJi1VRst/LvNWpRnVJr79V5GIuroFxcqF?= =?iso-8859-1?q?Q8oR4nMP0Awm3FRSVW8mZpNPIlaKx1jPbVBs5v9T+VkbMUOZIWDitETRAUqX?= =?iso-8859-1?q?8vKaf80D1bitLdotWSbUAmmFLFGiegBSbVb0lP9HrTTOaXDbkGhTNYIBJ0FQ?= =?iso-8859-1?q?UgSSpeDUyLP86hx2j1n87/CZnyCdy2bugzqXCWO8VXaTfXEEQZo7ETlEuP/y?= =?iso-8859-1?q?eOc7YoWxI0M9zAnz8JjpUmuIkMulLHYKESnvoEmwb7WUFeXa4c/L6Cb/Sq7I?= =?iso-8859-1?q?R2op7aBR5i5UNCF/nruWfvprsE5dFrYLoS4AjiBTTvz696sJP31xc10PBlX4?= =?iso-8859-1?q?p2jgRHfvLo4IQrX/Za4eMIPQ+1wQeTu0b8hjWeY+YGuqauqySOQHpTEwJ8u3?= =?iso-8859-1?q?G0wu9zGEMZSpLGc1RwXRtPDB+8JnKxMjH4EPUCSXQhaqd9EdsymDKoVxMpKh?= =?iso-8859-1?q?SHfvrOFJwMsHXkvxDoPK76oJN5kX/jYlScfWMaKFsKtCfml6uciVGK2sF/W8?= =?iso-8859-1?q?GkaP+8e0DxpMnq0L/CvgHPDZ00yGSvyhCcWUovpXiJcOYGgSA70+dz1KEUn/?= =?iso-8859-1?q?2?= Content-ID: <260721B35BDE004A9EA9EB76646947B6@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: 81ade7e1-b17e-41a8-7b0e-08dcbeb290c9 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:48:52.2154 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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 Sat Aug 17 11:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767172 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 1A440C52D7F for ; Sat, 17 Aug 2024 11:49:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 96AB010E094; Sat, 17 Aug 2024 11:49:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="j65dwuoe"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2102.outbound.protection.outlook.com [40.92.102.102]) by gabe.freedesktop.org (Postfix) with ESMTPS id A660C10E094 for ; Sat, 17 Aug 2024 11:49:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kXgBGR+wRWKg7IuMTx8UeR19mZuBUoEWg0bsQ0+kmZCHzJr6bsLYaR8ixaoXCSN05/69JvBiz8tsb2GaIvgyoHeZM44XS6jP7dmR0ly31JWQvTOaQwbbB42mivnCRuyt+Xuh6/ZOto3kW9ci5CqJMAfP6OpGNsancDhu2lJwb8TXIFsRdMMwM5tkH2NjlqcJItxwKCeGSUaGYBlZTtiQK4W1iFG2j2dh8rxRbAyd5emYyunThusIUIdbIRp5YehAGckLS+Rhwu2QyIkc9Zqo4Nu/r1mRLGhvbnvvJVeRA4b7QvVDnYitnGeUwPutRTpABNgdQqPTL3vgqn32LYdDMg== 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=v0dPbEa7QOb3u9HiM4asnjLJEjL54b+ri/LLJMkA8Jr4oWDjBu5RFd9jfia4f1JHMM4no8BsRc9LPhQ5y899SW1sCnttZyFiyrDWsk45fs9tCy5uSMiTlscDzJB+nOB+rpUWY0wnjXVaHCg9oOyQftSAiNslR/ya1KwBrzDj5AGDYExzyM91pYAnCKkIu9u67ixIygBCOQQEslsc+9YLQgFdXcVutPNKJ1MPrDNQg6iH5GupdM96RNcNzP2D/L/uh15Eq9bSB5O2h6X92825pfoa4kWZMwf6UgtRouQ2HlSf7yBI5a8N/Khi5qa0u6pe8JtPNKcjx7OWG3LfvjLpBg== 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=j65dwuoeyNYNldHEcdWAgXrsi3YTWairklsCmLLfE/eGTBNfDZ3ipKltjbRWI8F9UtIfkqKj6RQ1tG1X6QwY8HjpcYZQhWnJvd7Y2GjInSNvTmYF7yPAjNMw9Osmd1zZKIcUpM6LL7VGhQBnI3Rl0UUglOhPNu5ZxrNcGSAYVGGQdpuLKtYt/CKLzOA1/WcJPMkjMVeHkVyxzH/jgBTKyHSg/4fJ8ZfYB1Yj9Up9+t8GNu+60jQZG9tlYw8jTbQoX0tInrTNdre/pt5p3nW9+rBueNQ0pLuEkl3vYqrpHMB4f7SXzBhoMs78wVwSOyfOl53LKhiogvyqa/w7LPSvZw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN3P287MB0241.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Sat, 17 Aug 2024 11:49:29 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:49:29 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 6/10] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Topic: [PATCH v5 6/10] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Thread-Index: AQHa8JuE5QMYD2v6V0Cg7E5Ci2VY0Q== Date: Sat, 17 Aug 2024 11:49:29 +0000 Message-ID: <1AE4AB8C-7C1A-40CA-BC7D-146A67460490@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [bJ8yja5UFWK6IQG1st9Q/RvUu1sckXdME8WPfZfSR4YM2RczpzOAXa5ang5SSE4oiVGAjI/4Dfw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN3P287MB0241:EE_ x-ms-office365-filtering-correlation-id: 3f91b49f-2889-4050-6739-08dcbeb2a709 x-microsoft-antispam: BCL:0; ARA:14566002|461199028|15080799003|8060799006|19110799003|440099028|3412199025|102099032; x-microsoft-antispam-message-info: ICFq5JPTmzJSJsV3v6QDpvYDBs1CG/WQn/4qfhk42qQBgQeNurLfoEVarO03C4pYKp6OiE4+A3ufCfJNsm+60PdaRaOer+yPnYgDROWZcR1WIe84YPR50HY63mo/z5hQzi+YnU0w2vPUm8un5drgRtQZiIbWHuuhLVzsjITcm0a/gu+uHPRvaeoe2QZVwF6CjeXVeU6VhWNYOo31kXiMApftpg6igHQxMTLqDkhugq4oGidFCsD5Y0mw9+HtpMWWrE6Y0hwBvr+3WGLp1fBCojH9WuoGJO25Bvi4ZzUo4aLcHAeYMIZjM3VNcK0J6+g1G5sombHeIcROPd9iYsLxEyLxwb4TBkicJMpAbANNVihuujSkoIh3m3XDdcObT1/35c4SwZOohmeYSKSJH3KLGsPdJqyoR+fCqkxBPwvN+z4Uczu9A1Evfm27RHmcY64WTZkjJX1GbzcXZ1nb98gfet1Arpd/97zX1hCkHqkNg1KsatrJ1abfNss14tFIuNKtSHLJQIQVLXTnLTmZY24U2KTUJcu3/Zac0gacXQzgGfVLlC+VCNjcaRXdeznVC8p9zN5QzGAs6UbDmrwCN8t151HzYwN2UEH8iHEgIUIksDU+yNF7OI3t8DdcEYBRLR+XsQ5vQN1X5FonsTFWtOXXvvl/xmL4sbIJ1wAZbTEYafQmpfZjrufPNKnqUWNQsWom x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?IIM1aG1SzGp9dthEwJHLyyw?= =?iso-8859-1?q?4srXRanH9jUjJx34H4WETBJ/4OYWCx3fbk8ZqVr8SU3jWlrVol/jYpyYg7pj?= =?iso-8859-1?q?Fdu72vSc4Ek38kyvsHI4mk/lMqatinKL7i9cj9JaeTGqWrcA5zDzO3LCQ8c2?= =?iso-8859-1?q?Zen35i7OtNki5EpxFjzY101BxxD2eSMMlSvirDCoOJ78z4Hsu+J54cxYPGWY?= =?iso-8859-1?q?L/pxXJF92i0I/snG5iJoD/NHw30xwIsrz/+iheaAOfxVjlFs0wf0l1slG8sr?= =?iso-8859-1?q?wypPO7rxNWZZIOG+wo/sdRBml4duktjTm0mlQwOfGRLpGkJ4B1xgRqQPxwZU?= =?iso-8859-1?q?6ls/U8r4a+xN6xpZ7pR7Ikx5Ts4/HV+/4LU9dG4kpWHVdk0hnxI67OHOtgUJ?= =?iso-8859-1?q?74XiszaJ+OI237Gx+9h47QsYgZ5w+pSdwhaeahFP4noSAfHUygZfZqruJZXr?= =?iso-8859-1?q?D16v672M2kAI6v/Yw7Hd6N3rIB8cvzXWyZzRB+cZSR6NHbuBnemT43J/1tLJ?= =?iso-8859-1?q?SycnxKKRCCRdzGAU1su8jWL5Htuh0Q+4mv3qO7U0sdzamMM4jvNjCKD8BOPx?= =?iso-8859-1?q?U5PkFvlFW5W+pMWX1jdUhzLuSsS7RNkh/AXGKbbRpfQ8OPAxVZNP1+Goeyxg?= =?iso-8859-1?q?DI+UuaHoKaOBeSz0kO1oz8NvVhdV0Xk3wsE9cuVf8Vd7YwJRgqcPaf6qbnET?= =?iso-8859-1?q?jc1kZppE4BzNJOhc3Mey6WML29B8w+n5gTgZ0rnnsJGuEtXWwKTeqhF1/zEi?= =?iso-8859-1?q?VDu0AnLwtKZSAKfNBSwZZqj0T3J+KJi5M072sV3CBp+25pgSLjBgtCjie4rG?= =?iso-8859-1?q?uuLbw7MbOLtUmNgdjG2cI3r3lMLebQeYbqCzER9dlPtMe9r/6qzdhwSvbpJ7?= =?iso-8859-1?q?rJmHBtyobjfgrGtZx6EUK+pHqgQBAlXt/cxn0AawVQkvi43zNUXlwbzV8CRn?= =?iso-8859-1?q?CseGyO34mnN9avVAT1qukyDY9gXCos+kp1637N0BvrpkR4ifxFZ+dE054ysA?= =?iso-8859-1?q?5f9q+U7gb5MpUas8BgIqNFHSwi56PjqiCSPhOjRpTg+Xv87T5gKkGvHWgPtU?= =?iso-8859-1?q?mdXgYEpkiwK6a/81Oidd4tamcAfu17zvQq6zFihtELL/vCuNkOTZ5yV8MAWl?= =?iso-8859-1?q?bGR+ANDK8oUQPq/CNsXPKIRav3/cNQ+wHzCT5xNRDqPOlqTvQ8dOcqdRDwMr?= =?iso-8859-1?q?96C+XNTKhRzln0CXXOUPu0L7zRkicRhO45cTqFOZC6+3LTtEZmED85+Lwjh8?= =?iso-8859-1?q?NjaQJfXvG7Yq43C11spm5nSyiendeeXsf4Bx0QU/3g/Fmqv+LmAQmZSjNXsm?= =?iso-8859-1?q?QgJ/5N9I63zrvif0OFo6YKE1O8Kj2huE577cGvo3WqmGwQPbbI2BXFTH25sA?= =?iso-8859-1?q?n?= Content-ID: <1A07FC1BD94C0F41BB5D13E524035A72@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: 3f91b49f-2889-4050-6739-08dcbeb2a709 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:49:29.5418 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN3P287MB0241 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 Sat Aug 17 11:50:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767173 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 AB0E6C52D7D for ; Sat, 17 Aug 2024 11:50:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 110A5882B5; Sat, 17 Aug 2024 11:50:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="UrowVdlJ"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2104.outbound.protection.outlook.com [40.92.102.104]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3548110E099 for ; Sat, 17 Aug 2024 11:50:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WVPL1r8qjkYlhyxw9BkqioOc9ctpaMtSXvx0a5PyS1fU3Npr395sq0Y8Ve83hwFhMzvg3jZOf/mdFKg0ANz291u/eAbUqWIjGUfjv6/f71dnL6QErJ1YSShCq0ktWZIPlBtaelmkzGLnVZSaliuSxHBZB4GixH5kpnpikE6WyvRYIafB0+GkoZwAL11n1W/e4fl0KlfBvpAUyb/r7bf5QMJEjKDLk+2qbjBGSx4IGNXt1Z4Je8THbHwKjzY0ToriuC7f6/tdOD3J8tSyBIK3WOGhbf1A+Ua8pZa1X7ckj1VjS1rYQdHcE5GY1mOEOPIqNLuAYYcD11B17JhIK1e3fw== 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=kfmhoYlfS8LgFvPZsbYNykR696Tz8Hb/E4s8zuYTlffpkAzwNak4NZj3+BUbZGbHHlf0a6KCooWhSHAQRpYJuL8wZiya8fE9K23ZPdqlrELQQ2SV5JTepkaNAs35zyLH97zvdDExPGEyRpjJJR7Ksn/8ojN/QopxYzFw8+9JPK/u1i0jt2A2Y67GMFyi1qQ+GXXOJ+Akvb++MYYowW2ajMix6c8YynzX9iCd5Pubq0r1eTxb3BW6ibPS/v4pQ3jC8T6Wie+Xcp0sGUjwFvd4BSgXY6LO8MWsIYtvZ+VlwWimxI5w5c30BnOT6exMIT1zg+376/T/uxvycYkwj3emNw== 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=UrowVdlJSK8ZnIiOGXOxaGJMvYv23JDC8EzBTOJ+xx4SbBD69LUqWW3A6kVM7USAnpgqye7QmqLi/D5DCFPdi9r70/gIp+fXNG5RYxXyzM2tEQf4Q7XnHeak3anyb0D6/nOyLzh8SXJ0e4C8qauijWt3UIF+4ZiCJr6ZtZzHYHVjcXnQ6C+h2QQgQ+VnLFgcbVpNmRjcyN4gyyO7q7WaNci2MnpKLPW2HYLb+DTAF3hQ5n1BtwCyrnLaxF1J1h1fxJoyZ4SUDAJgx8D2JFY/hmF+tH6OORohNUu18NOrEHp0wN8bDKfsy+qhQR5ZUEHmCV8LQZB8/DwpP2v/T2q+Jw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB0120.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Sat, 17 Aug 2024 11:50:18 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:50:18 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 7/10] HID: multitouch: allow specifying if a device is direct in a class Thread-Topic: [PATCH v5 7/10] HID: multitouch: allow specifying if a device is direct in a class Thread-Index: AQHa8Juh8n5ElnZBdkWDzdlWlxIp2Q== Date: Sat, 17 Aug 2024 11:50:18 +0000 Message-ID: <013F1B8B-F187-4A9B-9882-0FD174B73860@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [LwWg1CGZoXqr7mZ1EK/g4gmjsAtg6IBd/sobjkd/95Ng31Y+NfcX+XxAozzC7JRnKqOqZ3xWZFk=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB0120:EE_ x-ms-office365-filtering-correlation-id: a880d336-efe4-4d4d-b606-08dcbeb2c44c x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|8060799006|15080799003|461199028|102099032|3412199025|440099028; x-microsoft-antispam-message-info: H1Q85fij9oeXoipeR/uEnt6FV3CT2RrdcLPI5yvBYPoEM0jJ1dJ6K5QgXQzUGokU5OuEylFSBR5cUfjGQ71yANDntyOPaTHBHhZGIq1MFk2HFDZ4V9wcI6JvC6UVFl4oEpFNpPh8KLcvXCaUQu9szIEifrQYfkcy/aAutfFdm6RO4DP79IczNUjI1W843BQJqffanvw5eMDrrq2nYNX84yC4ZWNhWTthP2+1vPLbD4Yvy6dV4NgilN6uZUXnQ2n2lccQAzxVP/IODloCSRNdcEOpbkVOaoTqVpcTNFDCQVRksMS6w+dYQ1owJLwvrAmVSbJA8MhgglcE/KkNhkXtVL//Q0n/Xe2EbWP8Bk0ZeJ1J0kCixZOkszgbEjJUY90Ri5SP9cu0m51ENeSXU8xP+jyPoOSTTbhCVJ8ggYa8nDzxcf2D97IBvh7gyl99tZ5prvLQeqyYVrhWI1yJP54su7WrGXEqPrkuH8fEutIk2i0F464kTYdO3ED9KMsKc3Tg7Gq2+zO+Bb601VYdPxfQL+I6UAHKroRELh2LaO00pVd8M+bJ1uhLxH+Kl5lJnWLMLaOPz+wjOwM9pBEIwswL3NdxdbMGTIw+wh5us45luK7UM+Qqd26CnkUckhq+p2UIXA0RaxDBpe1OdC+A+LiN0VDMcddomxZTTtWN2NWOJiJl4A7MdICoKfRYezhbV9Ye x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?yO9GVNNO7Q2IGPiI+cLhcdg?= =?iso-8859-1?q?HXnj97yWQgDvB88DLaiXsg6cbW6XVg4T1p2GOhezbxWREFMMax99Ox0iGWNf?= =?iso-8859-1?q?ksGufm/5G/hGY+5wVVJKcdR9gUtsJYsmeRupmz7eGwVMqDaqusHiE0LEdJiL?= =?iso-8859-1?q?7kQknPYi5zNvGNneXDkuJCMKaTyuXziqgX6sjZRhyZbEt/RjZBhisr/1Duin?= =?iso-8859-1?q?jurcJqypexhOcoVzW8AIkcKeW63W6XKnoL7ehh8DlGJ1XGvX2A4h0gL2B+XR?= =?iso-8859-1?q?Vsql/WrJt4UODe3GapG6duvTs2cNphJ79mbARkWSvJMa70hbLzy/9EsFAE15?= =?iso-8859-1?q?uI4+xeiogCTTdXaPB4LgccXSJrw6JIJRycXAL8CaNFggS28Pi5jOQj5zZSGi?= =?iso-8859-1?q?Y7uipRxNTnAPXNyyzZQN1QYDXmVIPP+7QwoTIQtgpMkphrlCCa+sPTV5aIn/?= =?iso-8859-1?q?ZSOfcVcLiPA7N/A2EM5tdcSDL+4Pcl8ebE6TS31lWjGqNh2rvR4jbdUaSTaz?= =?iso-8859-1?q?ToMpwPAByOIipCd6s0SyK0SElTpfJ2gDKfrVnYeRFJCSw7sCNkWB8J/V+9/X?= =?iso-8859-1?q?rztHf/uHtS9snz3S5Pyh4G0lr2myrp/0oJ+2C8uZr3yQkJ61o2ApThzQhq8o?= =?iso-8859-1?q?fXN9M7LI7DKT1XBS/74TQ3UCc+4Alo0PwdAuj9tHcR7MQmrgOiWDiXjlGd6J?= =?iso-8859-1?q?rfQXWB18JD/hN1gwTUlZ9gBSS3b25/90B4BgqQxYwmaxN8Rul+cMTj6U72W0?= =?iso-8859-1?q?R6WhwSpLvI4gTtOGmIve0Hu2E+spBkJYuv9F7bEtCcTCpWBxjNvg6ISYkEAV?= =?iso-8859-1?q?OqjTOg6QfWA12sxQLS8/TRxFkSsr47uPnPC8+QqBVGKyc5n75M+lSK3qpsGo?= =?iso-8859-1?q?N7ovtXkoUWhcO1KFFpHItlHqSIM5G6I2POYnt75BXw2R3LMmLnD6NB8hFs5P?= =?iso-8859-1?q?OOaZ5HYA95p+JTNKVd7E2nmW/5/1vHLSvmF+9ubXixYeb8zY3uBgrDbMi7BB?= =?iso-8859-1?q?O8bMyH967CkwvWDwlDIFX7nV2i7m9NcRCwYPnagRtiBGsFPqPc/uEMpjoPVv?= =?iso-8859-1?q?b1/JanrlUyfaDldk+/KImabu7aqFhLfVQ7dvFZTOXVMlr791MIVms5EhbnGk?= =?iso-8859-1?q?GntM9M5SNhDFsald1WoLKNCbdZ+8Ne5oeo+VxJdOUpuUHP/wvchh9KKxjlaB?= =?iso-8859-1?q?pz5Yz76/Mphp1mPI0oT1LWoSWNPlds+HcryuRLQEcNLNR8TnBKbu/b4Swuy9?= =?iso-8859-1?q?qiD2knkE9nV79u4JJmZiHU0Q7VEVUCiS1P9t0yzTP/5Y+LkkdUkKotcUFqRg?= =?iso-8859-1?q?8I1sksY2Z2MU5l36Xt392hYvUGDu70mtKoyyYWc2RxCXQmkg2mWlxIA7hggl?= =?iso-8859-1?q?9?= Content-ID: <174014C2A698AF44AE672D11956C26EA@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: a880d336-efe4-4d4d-b606-08dcbeb2c44c X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:50:18.6311 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB0120 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 Sat Aug 17 11:50: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: 13767174 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 D09C6C52D7F for ; Sat, 17 Aug 2024 11:51:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 51E1C10E099; Sat, 17 Aug 2024 11:51:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="XDrJiYFP"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2047.outbound.protection.outlook.com [40.92.102.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id B79E910E099 for ; Sat, 17 Aug 2024 11:51:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j3EG4y+e+FGhckBiUbEfozDQLNRDGonZJdCEsHn8hYs3Q7vkCymnH3vu75t7l8I3On5IwbSA6uOM+b3/yyv76hWdcgfFvAn98wXv1C6wzAtF7gwxDPOd/uBeuiuWofENGACKuEC8AX/xFntXz46f383tEwsxSyK8T4dQBey/1DP387WM2V4+K4TvpfI+e2j/Mlktnq+tetHjKlX28Z2KvBO2TJ0I/OK90v4TPEY6fJhRBl8LkQalndNm36ZkVyoVCT7M8XmxbwJL4KutlLEI46kirkPD95nVUZLOyOLfKQUvKoxHqZR29h+Fc1u4ZyJTFMP2c6dsF/RCfx3uvKGPfw== 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=KpnxmkDFZReHk/EYKcUyhClrfpY6nwYmOTM+KiZdYARyUDvMqsdKBe7e9DGir2CccvXKsoJa6CEIKctgriRrbtwFHqkpXn+U+qSiC0UaiWAUJQQrPFbg6r4PZd1/mj9jUGn92sd6iphE7ieLpFw1WXyfqP2no8GiS6h+48aLqDu8n6hVkqg5HZ151mp7wwhgJdQvIvR98j/iO3X/lIBWXUT6Um9rMWxcHiWrtpFzieNmnT1l/GTv+ZLSKDxtYtj4PrhLYCTorHARKHPX90MQrF6O9KxFMMIWgHeXWNAfI+UxpsbvQ+M9e9KI/5iw9F/vZ0ZeVJqRV0Jqf1hCmvGqcQ== 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=XDrJiYFPMcVWMpmo/xfhDEBVCcRZKakKGkzkk647RVoTVH5UbVYun7qNV5mKRnEkIhARJXGCXAudWT/9lffFPm24u+jYiJ7uFz+wRV1YhS0GW42Eeah7jH44VoI87YaCJGbAzEqQsCe4TBgfgyiVDOwKhK3Xrz7mxKLMuE0NrIM4ILMkPDsalZ6om383uKw4/sbHDF6DU+zuMD5NcZm0cBxdVOBZpFtflxht6RypYI3U1aD/wp25PdnGpY/fMoNoXbdzfXtkKwNlFDJT50n7kLpwYc+NR5Y5XJQQhyCH24wp4q0hum+LKLhzfe3ZEI+qGorSuJFFgC1mJS4YrrHlzg== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB0120.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Sat, 17 Aug 2024 11:50:56 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:50: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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 8/10] HID: multitouch: add device ID for Apple Touch Bars Thread-Topic: [PATCH v5 8/10] HID: multitouch: add device ID for Apple Touch Bars Thread-Index: AQHa8Ju4vlKyi/mj+Eq7W+97O1SRyA== Date: Sat, 17 Aug 2024 11:50:55 +0000 Message-ID: <924E0120-8BCF-4BB9-AB51-77729F02D11B@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Dk0/R9Q5zbH+VETMD4hIwIIKB8Jb4xmsAzLvI0N+QQQzqLhGYBjk7MrDH5VBm1BD3kZeHi88l94=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB0120:EE_ x-ms-office365-filtering-correlation-id: 06b81f95-9dfc-4042-7d07-08dcbeb2da85 x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|8060799006|15080799003|461199028|102099032|3412199025|440099028; x-microsoft-antispam-message-info: nUVSd72i0frY02FMUjffA7Bmp6lNxQaajPEGSqCjVdVPZlqrJ7kFzCU7se758boiDVojvinylnAyi7NEcmCBaF4w1aaYwxPP9vpZNgW2FKRxXD7JXEZvr5HNd9Nntay+e1Ul5wQq2+/oPOaqIt5RDSrQbMC6QGdNVNayctWECgl4LsTMYed+7qAK4SKwCq3fxaUKDliGDZWlIRN9FwfzIfYTfAyzjus7mG8GDynmIlk9mQ3xeCBP6p8kJc+sZ1Y1jhvatjqlvZI9yZzlv0HdGsDbH3D7qZyWARUZAR1ZNy+9UUR/1Rse3v3PwyxTOl9du2jN6vCINj2mKY434VF89Q5EiUKB18gxPuOSfg2PVOkVH8jMBsuRPZoJ/afm1b0qtySCxSeDRMfixUv1Wx9GBiDrSlEyGsVp4/kSIGNTfAekQa6MqB5E2LC1fUEUzJbvy+4CisowAbB4V6HN1vvE0K+LRz5FJnwkTO570i0mo2ad4az6AJprWPu6InpgtNi2qPameakzOFGWanRXsEXFhIbmFE6yfIqiCkYRFVZM+4TpNvaP27n9d09aL5gvWYteNXyEWlwSEwkhg2OyagcF67D/W1BKH5X7SVDI8xO+NtRwh35h/YWQh8QK/PlnuwCvpyK9nVgt7+1MRQ0YRsPuZfmr6vx/nQ6wQsPBWxuqMr7CrHjhPFegUa5JMBXDTsq1 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Rv84q0dNfoj0fQiR00dclqE?= =?iso-8859-1?q?Vung8qjXjx4Ao8asPhMUxjLQeUrnswcjybb9i/tDuNrtx8vDqFSkqY9u8gxt?= =?iso-8859-1?q?gGpXdeMdOeyGz7swiH+uLJg8ft+oVuYaIJy949mRjEJ9j3pPftVxxveg35Fu?= =?iso-8859-1?q?BMDFUkIPNOocS9XINx5nnsoe7ZLM9mcAzGAiDKqYs7GtLxs2wpsWfodqGeCY?= =?iso-8859-1?q?W20sLz8Oh23MYAveKGhUDN7gMf7JClsrunbhUFrPTKDQev+o3zmzv93kMEdG?= =?iso-8859-1?q?/DGhif60t4VOJGLXPcxmYrEvlKuU69jy8qJtzEU2gcJaieh3OPX7R+0F0hn+?= =?iso-8859-1?q?0wF9gjK6au/Y7BBf0uNW9i+vJ3NjRVhVzBU4crrRzO6YdgA6reLiMMKLWTur?= =?iso-8859-1?q?iKA/dcnNEzZGfnObzHZv0TNZU/Ppsc+HZx07thtERG88JYLMOJ94CL+DFdVT?= =?iso-8859-1?q?YbnyCeSs+owlBwpiJyITY1fpSmEEiuNTc8SekplnCxDyLptPbLXTn7Z2pB+J?= =?iso-8859-1?q?IHtZJnu8nhEixmJex9O2CR8P8XDjO0PCMqUgJsruPQPyJaFwglqA1+/BHdcl?= =?iso-8859-1?q?59tCVUK/qPTluj7TvfVRbBTsM/FeEeNVUOnFd0M3Mo2qbNT3pos/Rk+J3Cwx?= =?iso-8859-1?q?LPY/rXLRn87U1IJu7QtK0eysM/AH2Z/rV4tjOXHDPb22tx4JZJNSeva2rYTF?= =?iso-8859-1?q?GQ5p2JVUR6E6wSJR6w9LqF6wgNfhOuqDAO0NX3sWaMv5fqmCHekjsr0Z3JA8?= =?iso-8859-1?q?fyTG4QV5xFO7RyYGNpDf2fUqTU1T3tIk0ra5Uw90O8NIKBkOvc7fx/PhnsRo?= =?iso-8859-1?q?n24d0PxM4r1cQugzF6xkUj2OcHaWYe+dB7uZb/kFsKFRTx7JrB3roH4AikWw?= =?iso-8859-1?q?MmzPDyoLdfhUpuG9jhQ/zxB4utd3o5tRoDlGWadfOKLk0TSmLPNP2yJs5Tuw?= =?iso-8859-1?q?wBm6ZFH0wzn0nhPbKhozUCUcyrIbsIh03r6+rVxt2eLa4Bv+XIYmABtS65N6?= =?iso-8859-1?q?OuFEvwIXYVhOkb1Ox1HkADxdN4FZPAKvhIsuU7qLmE3KLomJOnesxnh6qtnw?= =?iso-8859-1?q?mNf9E5hoPcyypFjB8/QVpH54WxH8dGHgCgOq/V/7sX0hpjlDYS7g5cK+PyRd?= =?iso-8859-1?q?ZTnvDDWWSl00G2IWO9Pvtf8uRaIiDN2yJEMiOxoa/g7ti+3xlW69juFPcGSW?= =?iso-8859-1?q?NEsO84mFKYd2R23Z+Zc+9Zz1OC9s/xdjOyhe6D/smC7lZbCv0+m0TZL+5NHQ?= =?iso-8859-1?q?j9j6UuHCflYEQQ2z104kWTsUxh7ZwD0HdcPClAKDPLyxkzoLtESUgQlK91OD?= =?iso-8859-1?q?DAhwddUWkHwfhaTs9ZM8WyVw4q6RnGmS/8aLMdyhuuCkHBDVa+xVmMVWOUQj?= =?iso-8859-1?q?5?= 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: 06b81f95-9dfc-4042-7d07-08dcbeb2da85 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:50:55.8850 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB0120 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 Sat Aug 17 11:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767177 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 66C48C52D7F for ; Sat, 17 Aug 2024 11:51:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E0C6010E09A; Sat, 17 Aug 2024 11:51:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="Y6G+O4ud"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2025.outbound.protection.outlook.com [40.92.102.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 26F8F10E09A for ; Sat, 17 Aug 2024 11:51:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RkB5/w+j1YpS+CZIhvcMCbs8fHK8abedN9CoduV5EzbiLwvn455PhezZkLrpaZzbvCGD3A+V8m/wpOBvEqKcT0s0EwWyE9PqNL0eZNpJMGI9T4hb79BFMNKxZZJhdBkvGr+BrUChPj+LAiQzscJZ/ZhwcP/CGFwjsnSY3Z72Ty7Z/1LP2JIpAerF4x3C+/WhZjgaXTylwa7DcqYtagiWGMh5dDEOxdcZyodkBkWDAj6NpIkuu6jxqM2Bcoskug7JIgFTbGpGQoosOpsILCaw459Gjwe649+mrltfBeWo5dxi2zvWgYCJU+SZYt61YS+yAvldNO3jtapuMHUh6zjLRw== 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=flm5b6oqCjcYqw7sa4zU7H5c79bkt+q1dJA0xieZpmGAWfyL28Fm3jeZhFeHIgyFC8ZjKHEEDHNs9EoxV3TteCXopC/9txwvaI0zWz8Yl46fEPvnITuLSvuuA0ZaUmfcZN0/0CR8qusMI7XMfmUPB4NQsYeEwBmXFYOuIKkIepo6e/gExMipe5ukrLkK5/NkaDEzTweYra/zVPSZD8yDsYVxVgYVQucDsalPRYmIEMFRTSJYEH+l0U1SpqNzl5+GO514cLTB5CVwDk9TIihw70G++xLfhvF/Oy6QgVr1pQL9lUH1OcTLobZbqxNYtAjyotxSsTgtBbPNh3Qvmwmdig== 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=Y6G+O4udgKrwK26S5JaLRC0YkHR/lxC8lz5oBuxipSC6PxgEkQGi24IVrYk8RWlY7luUXEWUn8EHrudqLJXGms+A+yxS5mocG7ZM1+9bWrUz+xW3detB86XC+O+9KcgAhtQIg0xRIGZFAb8r+o+1moxUByOruoY8kI3bgWxeuxc7lablzVU8bvaUAQLLtWZCSe4XipwJyj4mZABs3QddOSaQIwfNIFLMcRPTmN8uZbmcFAKPdBVyBwSCi8yljVGnALRy0ouP3dGdvr/6k9s+UFMd+c2147BguTzWJp7BimoK2AqaMWr9s9RnQwifVrQRltnpABsQNZLrdijKdk7Amw== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB0120.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Sat, 17 Aug 2024 11:51:41 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:51:41 +0000 From: Aditya Garg To: "tzimmermann@suse.de" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "airlied@gmail.com" , "daniel@ffwll.ch" , Jiri Kosina , "bentiss@kernel.org" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 9/10] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Topic: [PATCH v5 9/10] drm/format-helper: Add conversion from XRGB8888 to BGR888 Thread-Index: AQHa8JvSrP6YA8vkbEOmU2NaACH4gQ== Date: Sat, 17 Aug 2024 11:51:41 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [0if0doK1Dj4+Grt19w3GWQ7jELUTPmZ6XIg4nqFdA3YlA50L/N7cOgUl3nS2ugzPRnkeGiU8hJU=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB0120:EE_ x-ms-office365-filtering-correlation-id: 47cd1aab-22cd-45d6-16de-08dcbeb2f577 x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|8060799006|15080799003|461199028|102099032|3412199025|440099028; x-microsoft-antispam-message-info: kFjtvnv5IORFfqcwqT2ULS1Dvb2VWDfEAR6mBJAU2fsmXnr8k4LoqFcagkuagYjr6ISkROp6scTgxKUHF1BJSeI0gArCIMRNvY4+WeHFAvFO5MlL1jt+NAGout4nZHqHMezTsYjlKbwF7ZEROK8Lrc5sDvP8fI6jKXq/dIvNnHTeioXOW0aIPbtNDXHPcR0Ob4cL5SJDUTSvj1JEh6g6Jn60KuZbrW9taGhPD4nw40IVobhswNk6prxWj4M5DfFoer5OZ5/Or7mRc0f/AmPsME7ECbiaLgwhXPGVxrLhkW7tNoyrhwA+wXb+HvRHqAxa5/BtF7EJ0es41WLe9LW1bSCq5jzhoIM9rmaq9D4loGmILSAqChHhjSWS7dAQl5LoxgVhXaWiT/Iiw0hXWnfcEo4iobcb8UIJJLE36ahdjMGl+00PyIFrbfaKLYFt+mr9NeObETb4/p9p1ma37Cvt8BCK2U1Fa/hPYROVLIKTdPimkz10EpPvGFzf+ToFzqeeJBQb8Nr1lKGckH78R7oCfYHpZqA/PjqZnHjeeURtNwfYEAAN1+gQTpoB+MjXzLD+6BuC6WUCgHrEEQdjS9qb/EuCQk3m1tHyeJTem0uvz7TPohj7vAosC44kz3/Eh82uLKjqhE9ljtoNenCndoT89qqRngecn8pTDOZ7YACcVwc= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?82EqXpJql5/QjyNEDtJd/yJ?= =?iso-8859-1?q?ETeq82+m7h6ImVQzYM1sWq1lpR0xUFtjx1Qz8O52z199sf/GeFh1aCUg+MwG?= =?iso-8859-1?q?eag/XLpOsJQEgZjcQfX3Kg8C5LFQsJH9u/lH+ZYf/pJObE2ADtcCJuaZwbn9?= =?iso-8859-1?q?ZKfSaBaoltrHiUrmMRiZOhtR4hLx/yvV7mknmEBc33KDKVQc13aPb17nEZx7?= =?iso-8859-1?q?sQphpWqaCVCOa8BURkEfjqB49JiCpUyCY2LeW1LdvKFfLfpjEUKkWxUwWIiR?= =?iso-8859-1?q?vklEuNNZGReLK2kKhwoMkkXwdHLTJnTg8/0ZUa2StXOC9Omp30Q/KL5F/NJY?= =?iso-8859-1?q?5dUds2vMbuKE6P4jfelGQ5hQAiSh/6vzWQjpjOO/ZpDd6Wmzxj8zNUf9VVWH?= =?iso-8859-1?q?Bbb/M4uHFAuJx8HTDn2IuAzt9Ep8OI6SUHxvRJx4lDDLXsQiSwosxhRUok/E?= =?iso-8859-1?q?I4rTrOMq6kUKSa0R2OkXCPNcFq5BcumkUDpL9MA4w6SeueLNdms7toNCbzwq?= =?iso-8859-1?q?xTCldO4gAmKnzERNpkFO1CCoN32yzjy0ByvoMwZ8qvBD+y/v/ioUMCESGxeU?= =?iso-8859-1?q?lroKKbq15nWqHEUUdFGXvGBnyzVS/YMTSh1nOh5YGXmkzri3IA4YGI7w75S9?= =?iso-8859-1?q?P6FZQSkmL/MN04jGHttnN1niFH6f+u3ARp0VI6tL1tYyR/CKYAVvYpKFiuKN?= =?iso-8859-1?q?kQC9wlAvLG1agBVS/oFUCM/jA3EiKLVjn+iR92J+2Mh2YAI5ht/SG8T8I7Ml?= =?iso-8859-1?q?SSiC9jk38F+da6c/S+uzXc/rMCk/DQg+GbTjPeTQKmQW6iGIZEnsCOpvG+Mz?= =?iso-8859-1?q?mGw5ADA0O4v80VJooD9+EEYgEeeeG+K2Z/6cNw1zc3rxAhSDrTICNreySNPo?= =?iso-8859-1?q?0G+oQ8m9OrxBcQU5B4c7WOi1opF1CdSDUHAJpcsIC47TMhki6pn4Dt3nkH7S?= =?iso-8859-1?q?ODAeplGgZpgZAm4XrfAn86NbG/ERMYEqp0YynE2b3rATELpnOKhxOfrBI69h?= =?iso-8859-1?q?GgsZcBW9PW5aCrRK+psw551Cy/W4/itP2mrL93aTbC23naWLasf7pvwi7ESE?= =?iso-8859-1?q?X2T7gij4smaBDWjsYU/aHprWlq7yIebzN40QSMMDDylMdQu7U8ReuqXFhPBb?= =?iso-8859-1?q?2SBPZQht9jbMxqcOcZigQEYOI/BgEd7ZPcutr6ZkKM49aLD+VamIhP8kG+ss?= =?iso-8859-1?q?wVvUqOdgyKcA3lKL6+qlDk0TGvy72J5P/2J7oIo1Y0WDIzVn5OkQigteJIgk?= =?iso-8859-1?q?Aq1beFkrMmBSrH1hGzTlHnNguh1xfMxxDjCmTiHssAYKn7x1QrDp52p5LXIe?= =?iso-8859-1?q?U4v33NsueU4HkoRWJSGRMnFTYFEiBEltS4OTgPmEgpe7KEfeCK8qwELaa1ye?= =?iso-8859-1?q?v?= Content-ID: <4583DFF36093704998B9690370DE8348@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: 47cd1aab-22cd-45d6-16de-08dcbeb2f577 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:51:41.1304 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB0120 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 Reviewed-by: Thomas Zimmermann --- 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 Sat Aug 17 11:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13767178 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 4B539C52D7D for ; Sat, 17 Aug 2024 11:52:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BDE5610E09C; Sat, 17 Aug 2024 11:52:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="Wh8ozI+f"; dkim-atps=neutral Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2063.outbound.protection.outlook.com [40.92.102.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C25E10E09C for ; Sat, 17 Aug 2024 11:52:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VspMEWQFV0ZfRtAitO4oILXS3CxKZXZAbelO/34lOdxZN8cXqUhwRDkCYU7HLsPpbRz/j657ac5nWhAsTNXubTqT8rli6SOuzJ6V+L2reg5EfHT4v5jD5f/FCETRHSE1HNHglh+XTBEUSH6TwPkVxDHmViUjNR/oqXs0w9WwAAf/lvdT8+DZ+QdP6wiv4bGb+PVOtuUTUns0gaMQGBHtUjgPUbG+biUMsMITkMHCFSSPwoEM/8mDAQVCWDTAx+jXaPEO9st45XyQFLB/s4JBkMLkhBCa/1MLhMWsMnCkYh3fx1lB/oRXmqo4PGyb2IKPT3v4+ggjhqAx17VCQqbpvA== 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=4RUYCikraQFlzfLUIl+MeSYsG9C4rmRBPfP+8woqoPk=; b=j5kbBCn7c4dG1QBQ7SVwuTge1Y7y61Oo+/HFGWnozats7bCYIvc0pJqJN136DvcOFizU1bjOxIOpdXcrYlUIgK7FpdRRoj0rae5bQinwlZ/kkVpgKZTa6PDH32YUejyZodIfuhy/bGwq3vCT8sgZCt1+WxtuU4ZIxmWseuoXyiCrJ+Sat5qN+MValDSwCeAWcuqS91Sa1DeiDqjtBYbx597sXKRUrU5P+bB+/9cN/JJzvTsOmTxqmg9VOOwScHuRgYew5c3V3cR11a8YY4iO6sK0yd3xtCx9vJ4jMjKfYHKKjvukaQ5hEq7iM+IaUDjHV0O6qsPOM6+dKVwIwYTw3w== 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=4RUYCikraQFlzfLUIl+MeSYsG9C4rmRBPfP+8woqoPk=; b=Wh8ozI+fhaUHDxQQB9c4fdNAswC62Gcv7HdKtJr3y6d50DGVwlfdDlLmHCYIR7yiVmtRKhg16rJVMnYkqf3o2UC8A9ni0uw6yiVbMkMl7/ur57AI6zU97V27pKhgGd7O0FplaXvJGWNbMBxjvO2gYyLC4M2cCcr+B/xVKc8m8jMFTNd4GDE/iWhg5zd3DPpl2MCDSCB+un92Fku2x3tmlp/uG8BQjyd1JWMCBvcH6dY1LqmlzNRgQhVJHcJdujsAYDYCvHTQ4wIQMI7hWDxBUUz5x6aXgd9BBm//MmiPhZI1MQKpoG+RAJInQG1eW6l8U7kxRCfbs/qeWHD1Ibu01w== Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:b3::9) by PN0P287MB0120.INDP287.PROD.OUTLOOK.COM (2603:1096:c01:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Sat, 17 Aug 2024 11:52:22 +0000 Received: from MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a]) by MA0P287MB0217.INDP287.PROD.OUTLOOK.COM ([fe80::98d2:3610:b33c:435a%6]) with mapi id 15.20.7875.016; Sat, 17 Aug 2024 11:52:22 +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" , =?iso-8859-1?q?Thomas_Wei=DFschuh?= CC: Orlando Chamberlain , Kerem Karabay , Linux Kernel Mailing List , "linux-input@vger.kernel.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH v5 10/10] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Topic: [PATCH v5 10/10] drm/tiny: add driver for Apple Touch Bars in x86 Macs Thread-Index: AQHa8JvrJkw/kjXWmEuT3rJn6wIjMw== Date: Sat, 17 Aug 2024 11:52:22 +0000 Message-ID: <3C9E8938-32EC-44AC-A783-3BFDE2F01290@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [1KFCbA5awKrFU4tR3ZJPHWa9xSG/S0xMcOTrkYSYRz1O7WCmTQdluWSrh94vGuOqcT4OY+Vm238=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MA0P287MB0217:EE_|PN0P287MB0120:EE_ x-ms-office365-filtering-correlation-id: a4ad0fd6-d483-43ff-4cf8-08dcbeb30de7 x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|8060799006|15080799003|461199028|102099032|3412199025|4302099013|440099028|1602099012; x-microsoft-antispam-message-info: PU8iHMlRKONc2L9wAUGlq8N06Wx6nH2ZCtqG6tK4Ngme8GqtrDAQqId3xf8ZpOuKu5IXCSciqn3it1RTPC5q/c7OGMSsCOAugsARtiQvF6tiKPI09bWQJY2z10XukfqdJ19FKKXIQHzQ3NZokRZcxm3cic/WEhBEwWkYMCMN1HLaKD5q6bdWpibJe952wArpsi/NPbIJNpiepwGGmqcQUaL1uSul6uyr3DdPNFKtdzhiJLoxemup0BehuyJoGliQ9x4G03dry9M23/KFgPuOoelOm+M8Km/OvYU675S3ISfDuQqanIAsK08xKV2ZbicYVZQsclaaG96fd2zEORt7XuoH40q9rdZE+g/ffum0sK5O7qTAKKtpjk+0zvPHh6AMWPQi6O3lOd8F2MTs1/SlsQHCVgneWXZZWimrHQdonAVM4mZSELf9kFfdVgnGsw3atxgAxpjgbfHQ9c//hM9cfG0VyBONeaWIZFcaRxOqUCvWpPmcRob/thhE9wh5GPd5/xi7RiATKtPNb6iStc8EmmQ8E0B+47zJfrXlwjZmDVRc5W42deTVhnIDHQUq00V6usuuFYdk1nq7XZeYMzrzPwtPdWWGo2psb6EWrVthoLOW4HHOgOMnxc1Y/HD9oazQe2F3kBuJumXtd4ww055SPgLF/nvp9KdxsZeTFu8tvZjFgU4vYkzGXHnT+g4C0wXYvKhVrryCuiIoRmjODpWYcF62ZOK0ZPrsSXk+TF/jFk7zo9i3RbrPx1gTof3qK/zSOO6u8P4BThvdwez3/t4sY/DKuzyz5VptkstF1DoJ7r8= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?64LyikjrL2NRascgfnTzP8v?= =?iso-8859-1?q?EvD8O/Ix6Nh7vcC9nfCXeChJlXJTabYqCkMtRp2FEZ0TJuQjPsxp7gq2Qmvw?= =?iso-8859-1?q?JkKqqEUf0qLl742eukdz2eQPTkauk/VyMDUj/XTrg6bU39+VzBz5BrKoxaNR?= =?iso-8859-1?q?tnSV8fGjLuBPbmKvfhtrkEO/Z8/X1uN2BwIq5kKHfKNilgKkkLh8KgbFJXsZ?= =?iso-8859-1?q?Z01S3jBhyVQb/lFTMlvxCJYbY+1rV9x58ZrSgYRYofX5rDNpPpkOMw/pswQV?= =?iso-8859-1?q?NpMJQTNqHLQKqGBOL/mKP8+jM/uaUJPMEkKHMQYaSbiCZ9D+XUl/Uk27ao20?= =?iso-8859-1?q?FOOHVme9gXvaem6H9e4IlRSpnG9dUeggczftlqI1V+oNrS3gTeEJc7F21eLp?= =?iso-8859-1?q?LZ3Wg++2GYszxtpHha2ECCu6q0ePx6ERYf1ZK3ogWBFWJdAbwbe2XktsaiF4?= =?iso-8859-1?q?drEm2d9cgx/6d6sv6S8hHWzfz3ZDpL8Ayn4a6pIxJejyaiCvruvJMLWiMcGE?= =?iso-8859-1?q?WvSv6ZvIy4YqOU0zHcR/nAniY6o+kOUOxFJbe4ZRdcmsrP/04GNWu3Qut4Ur?= =?iso-8859-1?q?y/Y811qtS6fy3rXvDFRiydUNi7RKPmZfQgNm7EhufEPl2NVw1Mju4CMU28rm?= =?iso-8859-1?q?EFhTWzs9nOhh1NkNAGiMhfojh59pn4nqWwOI5+iFbK+3XUTdF/46jIFNIlaf?= =?iso-8859-1?q?m92E/Eie2cwxp+GFNkLj6y6uf/gmzrs61O//hwLAnaety/PS7yo/qEIubJ/2?= =?iso-8859-1?q?gmfpTdV52ITpoppUDg4sdS4yI2rsDmbJr9DbHwQ9Ovyp9OF6lOQjFSy2jdQD?= =?iso-8859-1?q?X3atr5Kwr/W6xF8hw/rOTp4t6X7Bee9S1a5LLYWM9tnW05c3OD/kPoRRcRyy?= =?iso-8859-1?q?O4Rz8744vH9lJ7nnnKMwcXPnUcVTAEEU//jRBckoJDacyxStl8co0NvN9kvW?= =?iso-8859-1?q?n0xAjjV6BZfobGrVdvl8BCjZuhHoTJMwEYIKR4de38giuPrGlWvXbLdi42dy?= =?iso-8859-1?q?vk6Vr8u5WTKAY5XxWexBSeDhox2o33dvFxYl5hZMurtlM/uKBm4nqoUApGfC?= =?iso-8859-1?q?i4rgGuHikNTl+r0UPnv1o1RqaFJmArABXkbIDWv7bzDRebuMTsy1hlelqPHN?= =?iso-8859-1?q?vBrGQpFQPkDJ/cF7J3icBUBI5VTpYzYjh7HsBXhIoQLBngawAPkaKEi8SdGv?= =?iso-8859-1?q?+AhYjsj33Ss1XAT2JCZAKBq/7kw9RGI0m+PCnE2dSnxdkh7hlGRbuvFDhlFW?= =?iso-8859-1?q?Z8ktvkIzIkAe2ao4d2d5ursIEukbs0R1KaCLGbGH5jR4Eh5W+PuS82gFBPJ6?= =?iso-8859-1?q?A+7/9DZKk213939GU+JY1ko3hOwQbhndFdcepaLowHjkMJsBMm4wjD+xV4N4?= =?iso-8859-1?q?A?= Content-ID: <5458A91227687840B844127069B3ED23@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: a4ad0fd6-d483-43ff-4cf8-08dcbeb30de7 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2024 11:52:22.1344 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PN0P287MB0120 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 8766f3e5e..2665e6c57 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");