From patchwork Tue Dec 31 17:34:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 854457 Received: from PNYPR01CU001.outbound.protection.outlook.com (mail-centralindiaazolkn19010009.outbound.protection.outlook.com [52.103.68.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B845442A8C; Tue, 31 Dec 2024 17:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.68.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735666459; cv=fail; b=LKZ3N0daHWXSzq8RRXh4/u8xkM98V9VfpiHcJXf3MgjywiQ7Fr41p7uebN4qD4RknnpohR+TwHRztE0Dwn9N5qLlHXnG38O7bD1SRZNoH8p4LU7LbnzystSAnvA84IqXUjH8fL2gUQ4cRqkFlN6pcLLMICuw4ppxJOHaAVhi9Ac= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735666459; c=relaxed/simple; bh=qHd3VxxlhFBnSZTfhCruMFqhdAwZy9WgJgF+lh7YNkQ=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=dLVeL2LO7JDSrQcFiBAyINxjIbD0vIVo98WytP9FeDYii3imlon1ssg3qrb54nG1NKThNPqCLUMkjqK/3+AmhVIvWxkt1O0sELLFBmInGfy18Lw5ZkNmuZWiuY0V8IV+kcjnjtfaVzihx7g+WS6G1tGq2D7IaFBb/3+Uj5ZGPOw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com; spf=pass smtp.mailfrom=live.com; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b=DUmJyk72; arc=fail smtp.client-ip=52.103.68.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=live.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=live.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=live.com header.i=@live.com header.b="DUmJyk72" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nyOd+xkvGDe8GBo/ohBFAqbj34i/JCxV5QpB5N15Ti68ePKtqhIsjOjD+1cCh3nv7/iYIrJs5ReNEWTHuUJS0Yx3JxdtXoyvAwmhfYpg2g8RwMw9BCgIOMhFZoFJVtJmQHsPv2CfgXb88e15nFI42mOpDD+TLQI3EsFNdY1XYFdz8W/PorKBrkDWD1vZwtYETlGl+mjtoVJeG8T4gAFN1gr/bE+HFBNgKybKrT5vR6H3QAK9r+LmR7a6dVtR/qLQ/radYJxyjV16stuApIfr/Cb+0zJZVG9x9G+iUmvsQfrPX8MdYtNzat3lNr3o0/8h+MgQbBal8VDeOFI9HAJXhQ== 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=qHd3VxxlhFBnSZTfhCruMFqhdAwZy9WgJgF+lh7YNkQ=; b=nadHTxMuaKPryQD5nNb0yiLAOgDPDmpDhB1Ta15Q4CuIMSrRYA++OR4Mpu3x+WyaNEHKocSFrDreaAqPE1o2yGGUc8hdOyDE3rmZxcnQNZaGpL4Y3F7g0S/X0YgI6S5o87ZOToZO07JVxwGBAWmEraXfkuYTJZ3WW7N+a+MdyekG6vrwiksAMnCQO87sgXHusK9sNHJm/sfcCjhTJxVOs6W/cein9z65lV05bE4DMsYxD7/eZ0dkamo9UaQWQ9gWpqKaekMT/W8ZyEx1lXrlq/t8V3z/5HZ810Q+oxmxHKrvTxF41/qyfN7P9ppbQw7q7PBQAC+uAy5kgcnz2ndDdg== 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=qHd3VxxlhFBnSZTfhCruMFqhdAwZy9WgJgF+lh7YNkQ=; b=DUmJyk721zAhiHSXMeP5OGuYKe5DKD1KGslfiv5o+2t31Ci4vXHnx9mkzpjtsWuTMfaiO2tM8csZVlcVQZVeNDYrhcbri//AJBvO+q0VGi7DdsQk6Z3m48FH1lKrXXeEIklCOQXUNMDRSqPqSC7q66bpbdqWkcuRtmvedY73FQNpyOQWlEQvvCoLBWOE83N8G7rFm5rySro738EMet0jlRxRcPIFUZEWR6M23JmgokSBih3MkE5shexOmBQB+5kdUy7iGX3aZOdOhHCgAp+B80QUPS+hOKxQLrwycA/O/63Ow/4+K6q229wQpeBzRq6ViSbmyFrHoca3LgSt13ua4g== Received: from PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:cd::12) by MAXPR01MB4261.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.20; Tue, 31 Dec 2024 17:34:12 +0000 Received: from PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM ([fe80::d3b7:2498:cd95:5d06]) by PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM ([fe80::d3b7:2498:cd95:5d06%4]) with mapi id 15.20.8314.012; Tue, 31 Dec 2024 17:34:11 +0000 From: Aditya Garg To: "jkosina@suse.cz" , Jiri Kosina , Benjamin Tissoires , "bentiss@kernel.org" CC: Kerem Karabay , Orlando Chamberlain , "linux-input@vger.kernel.org" , Linux Kernel Mailing List Subject: [PATCH v2 1/4] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH v2 1/4] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHbW6o0Q1WSXeSqf0qV0fay1F0rNA== Date: Tue, 31 Dec 2024 17:34:11 +0000 Message-ID: <42D62BAB-8F95-4A9E-B545-A1FC7E8B6F74@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-ms-publictraffictype: Email x-ms-traffictypediagnostic: PN3PR01MB7728:EE_|MAXPR01MB4261:EE_ x-ms-office365-filtering-correlation-id: a100ee8a-0f0d-4c59-1607-08dd29c156df x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|15080799006|8062599003|7092599003|8060799006|461199028|440099028|3412199025|102099032; x-microsoft-antispam-message-info: =?utf-8?q?Tdt0ZCDpUzqiajjzl6GNxFhq56FUkFB?= =?utf-8?q?EUegK0Saah1LkAwrD39JvKSzny4oj+hgK0vLPcYhik0hTMu0Mrcz6WtUryTCINInM?= =?utf-8?q?zb4C7T4ChJrmSfJXuEAyfLildlZ7D/iQCBDqrAeDQbI6obru4JnuJk85n6qNceE37?= =?utf-8?q?V7Ybi7/zCReAdvmoCciAd/nqEY1boSsLz2p1PuvEmBpzyPceAO0236uJhPFUKfC+Q?= =?utf-8?q?oUH4F/EI9r2uF1vuJ2jhy4pVK1FV3rzZy9zuNJRsBzVQ21SHnB9QnF3lUA2Wh/XOQ?= =?utf-8?q?sz8GINFnpVnvdZHK3WF/4ZaLRNXJTK0WnV0yI+Px5L5B0rop0ofjAK5w6HO7qSh2r?= =?utf-8?q?WKGjoDr1YgslhQDmUNEyLAUpYNXxFRliCPRgexHpQJA0xjy7gA5ma4Xxp9kAAXudj?= =?utf-8?q?b+kdHEcI6dt6Kp51EWgWjZdIHwO94aJeiGxIZnfTHYyIOICdXCB3O+JHeKoxrcc5r?= =?utf-8?q?jyMSgh6z4QgRnfX2HjutSLCGxGBro80ZElaOjiai+wSGznRz/sU0fzctNVKQA/Uzw?= =?utf-8?q?M8azsnOS3fNz5wjm2Tf7SENXUMTM/H2RCWRNUt7I2jLCy4HAVJGEs0+GxOrydG6Lb?= =?utf-8?q?626PxGyRV/AbB7G674Vx4IofS0Xmp1HWppipx+RS8ep4QynR3+CwWJ6hwB5nkdNZW?= =?utf-8?q?Lyj0/V0mCN7bI+0YHHfERbn32Hdflu7IsN1oCEAAoaFLekl0ptCPvAhK3XllEgEeH?= =?utf-8?q?d/uTn/Kz+0KuHxv5jsdJz2vN4hs3tDuztjbxi0nlqefABn6vXCF8WtgoaEsc5bEns?= =?utf-8?q?aL733EYiNYz+44GpL5c8NyAEk6HhnjEz/LH6HEp8s4qyPpkN+4AjIGfYVbtFtLeAP?= =?utf-8?q?+mz40HwsZzuLNgfbyDVtCMCSypjo9E8ieKSQNfChWx+7zG97ZmlwcWADsPJYFJDNh?= =?utf-8?q?lCBYPtw0YYQb7r+G7rm4hdRFLLqq5uoPH3x2pgs37g2N5xSQwJsAqBkBsLvV7J5ii?= =?utf-8?q?GSw47+RNdwbtsQVSz8vNOXwqbouaBFraRnX7fg4fn7eEif/efQpNXR7F8k2fNGHV4?= =?utf-8?q?KziFLqDYpc3y6yE9qnGu39RPraljc8mVl9Y7sMw=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?apD4ewXFw7BNdu5qByDgTPBA0gx6?= =?utf-8?q?/mkx8daiXk8xgABDytsHiW+EkRXbjd/YbGhCMLDyYdT+dS3V4moQuxSzcx89sPcoI?= =?utf-8?q?p7dgATzg1r6Y6A2/L47iPHfST0y89xAVt8UhKebwkLyLC4rIZVamEpbVoreDIhxcj?= =?utf-8?q?H9wDPaG5DLBl66Ngt+Wh1Xnsl3JYmJ1LKweMuxxFzD79lfpG2GWWv1QhK0BL8PKap?= =?utf-8?q?4wcw87xJuGIYR4X2+kB6mBAyJ0JguxANYUkNg+WNvoqgVJNCvqDgsr5HJh4d4miq0?= =?utf-8?q?HGcsBByxsIFs6SGAcA+bRjP6r5vEKpqWKgwqmzREmwPgFfEOtuZTfqVVg6gopGlH2?= =?utf-8?q?Z5RU36CmQM2YQkRoQ31U3rOF2gONQaUc1etcfoA13mC9rhudPjPQPX8SxKGCH+zO+?= =?utf-8?q?bP/QxwoJjr2SYRSNa0+wvyMJgKusBJhpAMqe5ISVIEkaxke3p8wJkCmv87qUHNX1O?= =?utf-8?q?Hx50sKVc+wQiyQD/TVf3JXEQIWhqh+ZMZs6XvntL5gNFQ4ONesO2lC7xw+QOWXr5J?= =?utf-8?q?wHB2N/YkRRPb5FhR8nWLfUabNbaTSJa4u6O1w2L3OKN6GUfC32ohDhABvR5CUCsS9?= =?utf-8?q?fnCmcRIgfFy/wxK+3hR8FDqydKHLxsJUBRAjVa+CG2MODBSdGN5dWGU2WtoBD8FAw?= =?utf-8?q?14A5rDe8bHb6OFNwww33fkU/YZZJgE42v3TCvH4yLrSiKxcg15lHDbIbaBDogJuS8?= =?utf-8?q?NL1tSnqEiz37zU7+5ZvXB76c1Jxk9KWTZwdV5n5dFzYGrMl4/5j9f378HCWvDB+ve?= =?utf-8?q?AIZY9UMOximYDXAXSvhwler4p37uvaOqo4lecXaxOG6xdpZGwm5kW5sshYhNPWYCT?= =?utf-8?q?fNKh3n9hzuWlTODMzEj2OT6nqQ/KO0nZ9auNQyzNuDmEE0Kby7MH4j/NmARFxnDER?= =?utf-8?q?KEVYBkUld7DqOWaEqpw8jpMRxE/ivhZBmaBzqofWaX5JmgGEty9Qff8/5Hc5MxNhC?= =?utf-8?q?htpzKYFAQ8ir2JQ8XMqkloQbr9ttxVbsYvOEmgOy6CWKtG9hG/r2KY4IRMwbfoLeb?= =?utf-8?q?3gYOMd23ps5mAzgUpjNQ0oZom7x+7F/6WclrmSQI3cNepd0fqgAw/lvTSvDMk4rPy?= =?utf-8?q?dENM2AaLYkQ3gaRIAd0/p3vyVp4lvCjT+C6mTLVpGumrv1hxaXOIfz6WgG3OlVZcZ?= =?utf-8?q?8XSoyf39o00wK13gondgneld8QWdjBjgI9kfujz0zoJaKoRU4AiAtQkV8+bavtZfn?= =?utf-8?q?0323U4nAt9oBl/l2kKq0sNElKsHNbViE7r+dYmeWsgME4o9VRhozxQo6jziZEImLB?= =?utf-8?q?0TY3hZ8wZEw0rmSo?= Content-ID: <9AF130527A9154428BFE5F75510C22FA@INDPRD01.PROD.OUTLOOK.COM> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-ae5c4.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: a100ee8a-0f0d-4c59-1607-08dd29c156df X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Dec 2024 17:34:11.9103 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MAXPR01MB4261 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 4d2a89d65..f6678db27 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 24de45f36..444d24cec 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) },