From patchwork Sun Dec 29 09:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13922633 X-Patchwork-Delegate: jikos@jikos.cz Received: from PNYPR01CU001.outbound.protection.outlook.com (mail-centralindiaazolkn19010012.outbound.protection.outlook.com [52.103.68.12]) (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 80E0D282F1; Sun, 29 Dec 2024 09:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.68.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735465381; cv=fail; b=ayAgCWPWLWcCH/BH+HSfbaMBoWqnk9zCm4uOzXTZQKe4A2gYSOErgOpEezSTK3NMgG60GbmexqS2KIMsV1xvm1h/Zw6D0mCv8Jrq57RA7tfp0OshAtxc2adgucZfp3ImgQEIzJjkYRBg2nN9N5vBoSgobbp7d8h7SUd0l8CeZDY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735465381; c=relaxed/simple; bh=JBg4oY8JLDISqSDF1ROly9ZHI/+V2b7TZtxrF8NJZtA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=gAn11tjC8DGgqux9dYo1SEYKang9O77b+2TMmBNJMfPKZ6QUpNgpKVP045iJ0+XLCQ1kBudJKYDxwASbH+GyS2b+Iyj1Tkk7OT8ojiWCVrj6rooTGy/oVw5Run4wYNOAIeJyucf7Bb0KXkw4GrzXoGioXepCnL1qc9fClHtESHI= 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=ZAkUYuxi; arc=fail smtp.client-ip=52.103.68.12 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="ZAkUYuxi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xBAMR4VPTO/nFFkTHNDrFxpT0HrOiHFU3/oFQ+GUaH6Izzbo1H81HcNu3oarL7ZyIUSC66BxgXKu2OEhGA6UCCu8o6M9WHhTyjzPtsmGOyPlYtznyZZd5nnNtDwBrQ1xwIdHG41o1e62pc417EMXSOuMZokXAx3v4iEI8HqtU/FWrhbpjPN8t/Dpkd2R1/WAYeWOQwD9HZQQXrXQkjfjXkqs/48jIVqWAaajMk44CJBL0PxRyGRRxaqGH0T2BqhATiBakf0g3NWs+bqiCKOPzZwvh1UFWgnOx29N2hD0Xz1miMQrhsjxdmxueZzmYe7b33t6nlDZvsD8vOkfSRyxhg== 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=JBg4oY8JLDISqSDF1ROly9ZHI/+V2b7TZtxrF8NJZtA=; b=pGLfxlFK63KImzwGQ/7pG3FyKMkjqtVRZnIBafEuIQuLwc6R4Jg1SctYfYMfssFtI+EeOdeb1pTpbVi2eln3es7uOh9GhugdRdhKZsNGpBRFkJstEiiyTi28lD8G0D+00VgM3TlukfJe5DldS/YOwh9Ws2nGtmgG7DnhzrwrrFcXUAoAkmiduLoWwPBtJmL2sJM9OcaHsfs+gaIuOCnLfxdJO0h/YWe2/I7LMWSJHdQXObCNzSeCdZOYMW0KuWlKY5fdObSeRjcOMrVeWNlnWO2SbaA3D6/f+9oiamVRcQxQFTelrwHP5UIqzBshfQYeO2W49qyC/ZBWrTcfgliUMA== 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=JBg4oY8JLDISqSDF1ROly9ZHI/+V2b7TZtxrF8NJZtA=; b=ZAkUYuxig4M3Nbw1vsUeElMVGbEl102rZxFh7gnxDiYLdH+FFGYjU32mEQP7jADmYORvvvRfYqS8a/u89P12f/+XGDMBHaRFegCCcR8zq0ozwKKJg2EhHllqyRo0+TZA1qdCgBv2zBvrEVTsKDJJI3T0jjNsAPf1S6yHB8tojpYBhW3w7PeMeGAagLyTNjMlUSAeIGnGfFglZGUsMSAXNMBnx8OLRcO1/wz8xE4V7C9tkPfTDED2WDvn02+2BzfE2+vG1iDP6wxQVDoEjGakIN/6HsIRx8l9c2OxXMRViDhclysCE+363KUZ4SD3OU90WQw5VEsS0VtPp8uG41Q0VA== Received: from PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:cd::12) by MA0PR01MB7898.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:1c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.18; Sun, 29 Dec 2024 09:42:54 +0000 Received: from PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM ([fe80::d3b7:2498:cd95:5d06]) by PN3PR01MB7728.INDPRD01.PROD.OUTLOOK.COM ([fe80::d3b7:2498:cd95:5d06%3]) with mapi id 15.20.8293.000; Sun, 29 Dec 2024 09:42:54 +0000 From: Aditya Garg To: "jikos@kernel.org" , Benjamin Tissoires , "bentiss@kernel.org" CC: Kerem Karabay , Orlando Chamberlain , "linux-input@vger.kernel.org" , Linux Kernel Mailing List Subject: [PATCH 1/4] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Topic: [PATCH 1/4] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Thread-Index: AQHbWdYIZZSB+6FUGESIDO5+AECisA== Date: Sun, 29 Dec 2024 09:42:54 +0000 Message-ID: References: <793F0F3B-D51C-49C8-9236-124CF130E833@live.com> In-Reply-To: <793F0F3B-D51C-49C8-9236-124CF130E833@live.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PN3PR01MB7728:EE_|MA0PR01MB7898:EE_ x-ms-office365-filtering-correlation-id: 91a79b6b-15e6-4428-0988-08dd27ed2b5d x-microsoft-antispam: BCL:0;ARA:14566002|8060799006|7092599003|461199028|19110799003|8062599003|15080799006|102099032|440099028|3412199025; x-microsoft-antispam-message-info: =?utf-8?q?f8OOINrAtNMdnw5464OcUgf/80/Hcpm?= =?utf-8?q?pbMc3ub3M+BOuTo7WIWl7drCaeUyFhd/UR31uJVS8xHl4sVVY3Otezo000sBZuQk0?= =?utf-8?q?1MZ+fr4StZuSNTyYoTeAuI8neVyvkIekOMUndaTeJLvYx/BboZOE019Y4DU+bR4Cw?= =?utf-8?q?pOSSVpJs6EJ6q9ZxVa6cx9aqwL2HnumK2gyKn/1wJSHQUEjvR8ucnsiU8+LtQS3QP?= =?utf-8?q?wQ1WmROF6/lY0tqJGZT9wRpFF1lQK8GLjvv+nx5wH3H8AYNv/P5Zvdw8A+C4wnjuw?= =?utf-8?q?UzOJ0pNNU9tU6PtzIZP1gmL8rgsq0stCeffkqn/f1b3V1wv/FQBHZru35ImL5YqlJ?= =?utf-8?q?cmZbdpIv4n4SGS2+asYoiaayROnMWLQsdwFtQR4BnUcHpQGcWKwtmaYDh8uX5j5zu?= =?utf-8?q?bJii3y18WsFOduCeHJZF0ij5qKE2Fwz7cYFSeZL+Xyt87YcsYqvu0o+fFU05ytaVv?= =?utf-8?q?U8cMue6CGGVjTYLnVLcSVxIaPG0nX0y82GLhhe+GBnMNuXbHz4I1Iu+ZYwuvZ/fql?= =?utf-8?q?3DJqV0K+mfmetB/vp29tLEiwC7yYBrSo4V566M7eRNq2KbSiAKjE2Xyazg1qmVatg?= =?utf-8?q?e+C0uTgqfniv2kaRYNzgno3p5/fp36W/zPecpv+EwhaN6ZPuudyxwaJViRdlz5v3h?= =?utf-8?q?F4unmElk4PLQYBI3W6lWrT+Q8ubAFl3Uu944F2WfVEjokH0cesKGbDUGqijoDYlqq?= =?utf-8?q?tpi76cIvaVqIiBjtrRB3oZAfvSZorCEQJLIHMeQTowsqvozeneUMMcUt+2xEll2V9?= =?utf-8?q?00X1RcquQDDgDoQCVYLVV+T2NSc5w91CKj3hbdF9yJ3bKwsXF+6wIx03a2F4QkB1p?= =?utf-8?q?HbzsC/pnwKmuk3TU/80utaAnqXaNh7YwgOTs3g+GTDsD4PQnyoG7JEfClAWu6oW9t?= =?utf-8?q?QmFDiAJQMupY5IAPum49L8sl4+5OsqbitybDlStuEcPjOtQ+D0p2biUzDdEII18tP?= =?utf-8?q?Di1xSQvckUd3lTRMyN0IYA4TXtaKhbdKqsw/b1yS4I1zFo4o0DrVPV6V8BB0jGPxX?= =?utf-8?q?U6ToqaigWGePWg4yhoyee80DDgEkLYuiUBccm0Q=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?rk05wrJGkCoWsvEhWVrJ18csXglx?= =?utf-8?q?rrrWGJSTgvyOH3U2IFW5YYFLGqqCvxe7vBW/eES7SJEOjT61v5th0MaBh9yNx610M?= =?utf-8?q?9QP09ZmvanRg7JYY5+j4rQyC94hw3Mi83ZyhLbAMV3FiJmwTKZC4OLdYEyUyxZoKJ?= =?utf-8?q?ZGK77OeTK5MpJJHPX2F7r8bOWFXOqSIn1zf9Ui5EsZGjLiMGt15VNcy78J9bQpv9S?= =?utf-8?q?DJpurSsexanKw4au0+l7AtTQGc4xGMo9xlICRGFfEocaR8PHVMzG5AvkIvA7juBw/?= =?utf-8?q?asmKdONxm7TdrAlsvGVUn5oDYplqokKWOlyZycwMoWVH1xVykAM0FWMITVr9DoqaC?= =?utf-8?q?vnfX6mRaA+DV+4r/xeW+fpcfR2OV7uEW9fW1qQ57d4qv5MGTMdZ4ejVjTPrKlWZ+L?= =?utf-8?q?4CD0dgvHTEeNsp0qb4yVtW0HMm7erpYV1vXwCgS11gg/GkrT7vTDDUyY0A3QXFJaW?= =?utf-8?q?wTXCZvHbH5azr6KhyvXiILxd+ADTSFEJkHUus/hS6o7/sKDqaL3hx539uh31VGHlx?= =?utf-8?q?K3Z3113eXBpkY2DdBbWJEeR3+cqfuLGd/GzUwjyVlkVHQB/UuBAtrETDPCuRc2m0k?= =?utf-8?q?2C0XlKkyZf3TiXBG1z2yyUqSfZEgrrFXBFGtYuMiK4fwIIZTO6AcoFYGCl1b95yk+?= =?utf-8?q?qwYCsD6X2HLXiyc2LKOhlxUx+H0COHydARTzdmFkPLeuqTo2Rl/giTB3vxJ4tnGJ7?= =?utf-8?q?Auj6QhfuyYoNifeTNrKJ4DHhC3rxuTV6EdguS7CCriygnqHRWpZ3om/XBjVwQOCJO?= =?utf-8?q?5JAYVVUgHSJG85gD2zuLS61lSJvy03ocJH7jYpDevLV4HeKbORy+hjyjI7NfNqqh7?= =?utf-8?q?KrH5fgWZl9AHmr665b4YBzORmXiHhdfBaFEkGZ76Or/UnATcNMly/zPFbJrQpZOV0?= =?utf-8?q?dKSn0RZbraED2J07Fk1TiPZzHj2GArZOhrEymAmAR8KN6UCnQrZ2z2RI0ltFAUHJp?= =?utf-8?q?47YAeh1oCaapdKOR8rUdblASQ5lZTNBvlGZvSE6EovGA9eaU7/rXzrLOHm7//TXDv?= =?utf-8?q?73P8WqVacJnrrL/1ymlGY6f/X4a4kfffmpB+RFfRwd/PF4exT2DaBjEt9cRNO77fG?= =?utf-8?q?PZ5EzKlh7ZzbKTHvn/SAx7NH8cPJljVkIthOBE1YYDc5yjzGUO5Pw5S1bg3+WeEF7?= =?utf-8?q?hlrgaXAQxqIUZy4pZLBcyv5hrM2cwmWZWgnSit2Ldi4ppWbf5Msa5I3fByRaOgrtc?= =?utf-8?q?Dt6XDIGqDOemB1xuEZVmEWZpIjN0ObNlLEaiTxXnxaw9dDZW+eox1IF6xmRqtAdIx?= =?utf-8?q?agivVzenEQzHksjC?= Content-ID: <6AAE23BAEBD87D4FA893982B925FEAD8@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: 91a79b6b-15e6-4428-0988-08dd27ed2b5d X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Dec 2024 09:42:54.4192 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0PR01MB7898 From: Kerem Karabay This patch 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) },