From patchwork Fri Feb 17 10:23:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 58477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp816149wrn; Fri, 17 Feb 2023 02:46:13 -0800 (PST) X-Google-Smtp-Source: AK7set90JJBnwEDnsVmIOAg/8bdEhjL2bM9Sy4QFIyX3Y48lRAb41HgO64cBaaoa7SJjVLMRVNhj X-Received: by 2002:a62:6185:0:b0:593:e5fc:9dba with SMTP id v127-20020a626185000000b00593e5fc9dbamr425551pfb.26.1676630773275; Fri, 17 Feb 2023 02:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676630773; cv=none; d=google.com; s=arc-20160816; b=IpuJcPHLPYwjWRNKesajAbAj7xP1nOj3pJnP7SeG+I8VgwedcVGpacQiPq6713W5UK s2XOlBvs+/dWdPqs00eebDI1HVBK0S1u/JuPz9rHhY7BSF4s/3zEhikwMdWAeTKRKczK CGtstnrImWuJdtUbuvgrgnXgcF6CmCHu7Rs/7zk21JagNvLwNuzEr+iw93//o3TignHy ehZrhsRNBEznM1rSWqEH6dhlNnP35K+HMSEUkRFIBlvPjbmifRqy3mSj/NIwgnCvXWbR wDexe65iJq11E3nfbXEU5KgEsRHemALUCw5xpj5vDczIr2qgRCRCoPN0U7UqaHu+tUo+ 8u0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i4heeYp3ATHaNUse72w/QrOIobMCPoeJh7FfGXf+M0M=; b=ALe/iry10DmcyPdk/0NFkS5UY7xud9FYfBCcsODaxjNWxSfQ/OOZ05GMtqp+5rTo/Y jGwO3ntwDXDEkQUN1piNSD1kglfpJe6sQowH/rfx3l3tTIYOzmHQyXc8bt1thhrqGRX7 +kCeE5GlADYxpyqLqsTQ6s+oMscGLIZl3qpUkJa99377NoqnEx2hKZTWvHsnETsxdFAZ 5gda6QEmpfqiNPdP+0LCuHH/Tz1mMdzcdcP5680IUaHIpiWwONv9i8DVGW4BMPyYxuDl hkcY2uxW+9mqaCcide9mQUhpPckIUEgSAVLz6fivb7WkGMYRWXyN4n9/axlHiTsEOLTr aEpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ErSR7rta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a056a001ad100b005a8f32ae10fsi4677772pfv.308.2023.02.17.02.46.00; Fri, 17 Feb 2023 02:46:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ErSR7rta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjBQKYN (ORCPT + 99 others); Fri, 17 Feb 2023 05:24:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjBQKYK (ORCPT ); Fri, 17 Feb 2023 05:24:10 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E84263BDD; Fri, 17 Feb 2023 02:24:09 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id q5-20020a17090a1b0500b00229ca6a4636so929570pjq.0; Fri, 17 Feb 2023 02:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i4heeYp3ATHaNUse72w/QrOIobMCPoeJh7FfGXf+M0M=; b=ErSR7rtauE2hnfna5a9Jwh7d/y3lVdpK0zifdsIv8/54A9LyHV/rRWz7195cCgLSSU R2fmAjSbjvRM1AZfIpRm/BWZmcOjJ+z5wmldmpHDB1N5GmP0iPofU8F4/KbLpRuKCnVl Vg8VPMUl7PpBF7XeH9OSoP65knatR+Gxx/kuCLTwr4bfJtRC+z4k4/TE/PstYSTqOcbP 5vO9MzYJjb2MizmB1iQg5WEs78tH9fJh/kDyCeF8wfhP1gNAqxLOj/iFqpQPvSc9Ot6k ubToKy8108KRi9WbOb4XpKGCZUsPLUB5fufrh3XP+RuaG1WPE5vDromwV/TisFpEI2tC vKYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i4heeYp3ATHaNUse72w/QrOIobMCPoeJh7FfGXf+M0M=; b=Qbc6yDYMuHkrKsySidYiCD6lMd35/gdks8JC9UACip8RwNGS+gjabtH9i/Qjx9+kZ7 z8TIVMmxTWL41KO5fL2TrLV6IMB1D0d9XcaEpkM/wr2pn0m5CwnWa/tcnOBeBlphZCd6 8L7TYPV0CtthSJBjcD2SRKlIsac+wZgymtb7mfqY3cpKl+q8lk/+xykTFHYDZHAPOsyB hgUyzja516GmN/Z5LgkZeoBdudhnHswIQpSlf2xc27hj/8cB+IBTkH3cLZ7HeQh5ULHP fPfd7TaCSdA8NP5IfczuoDDfCOOElx2o7IG2eSqrO0p5BIjrYeO754usIT0CLS94JvVv TD8Q== X-Gm-Message-State: AO0yUKV4qFx9LSYZPPU6cCohgsRw+0FWsxJIwuh0BdPh1VaGe3IrmT4n iSO1HK4Ag8vystzH0QjuuxxlD7YDs6G+wg== X-Received: by 2002:a17:903:1106:b0:19a:906a:e052 with SMTP id n6-20020a170903110600b0019a906ae052mr144494plh.64.1676629448754; Fri, 17 Feb 2023 02:24:08 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id w4-20020a1709029a8400b0019aaba5c90bsm2832538plp.84.2023.02.17.02.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 02:24:08 -0800 (PST) From: Orlando Chamberlain To: linux-doc@vger.kernel.org, linux-input@vger.kernel.org Cc: Jonathan Corbet , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org, Pavel Machek , Aditya Garg , Aun-Ali Zaidi , Kerem Karabay , Andy Shevchenko , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Orlando Chamberlain Subject: [PATCH v3 1/2] Documentation: leds: standardise keyboard backlight led names Date: Fri, 17 Feb 2023 21:23:19 +1100 Message-Id: <20230217102319.3419-2-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217102319.3419-1-orlandoch.dev@gmail.com> References: <20230217102319.3419-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758074790149827559?= X-GMAIL-MSGID: =?utf-8?q?1758074790149827559?= Advice use of either "input*:*:kbd_backlight" or ":*:kbd_backlight". We don't want people using vendor or product name (e.g. "smc", "apple", "asus") as this information is available from sysfs anyway, and it made the folder names inconsistent. Signed-off-by: Orlando Chamberlain --- Documentation/leds/well-known-leds.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/leds/well-known-leds.txt b/Documentation/leds/well-known-leds.txt index 2160382c86be..4e5429fce4d8 100644 --- a/Documentation/leds/well-known-leds.txt +++ b/Documentation/leds/well-known-leds.txt @@ -44,6 +44,14 @@ Legacy: "lp5523:kb{1,2,3,4,5,6}" (Nokia N900) Frontlight/backlight of main keyboard. +Good: ":*:kbd_backlight" +Good: "input*:*:kbd_backlight" +Legacy: "*:*:kbd_backlight" + +Many drivers have the vendor or product name as the first field of the led name, +this makes names inconsistent and is redundant as that information is already in +sysfs. + Legacy: "button-backlight" (Motorola Droid 4) Some phones have touch buttons below screen; it is different from main From patchwork Fri Feb 17 10:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Orlando Chamberlain X-Patchwork-Id: 58478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp816397wrn; Fri, 17 Feb 2023 02:47:01 -0800 (PST) X-Google-Smtp-Source: AK7set8GBnX1bUOdbJ+wE2GTtpJzdOMOu2b3k6jULW9EiphVssLaJPeD6FbXoXtXcGnFGdqvWifn X-Received: by 2002:a05:6a20:244d:b0:c7:651c:beef with SMTP id t13-20020a056a20244d00b000c7651cbeefmr3457887pzc.7.1676630820900; Fri, 17 Feb 2023 02:47:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676630820; cv=none; d=google.com; s=arc-20160816; b=upKcsgT/AANer806nTqiTengRoDbn+r18jH6jBFt0dVL5nQ6KUJRKpGW4S3cAG9GIU vHe1V9ibBjHurknaJL6god0liqfrCPr4E/NegUb5v94DIOtT84Aska43RO21HRsQ1rte s2HOGzmBLiXe9K7qd0TDjkDctE/nb5GwIV6rfBoQcMs5St6Z7lRJBpKc4+Movf4IMf/v odwHDv7oHWNY2vLmawcZ+QChWRyVYg7xC3jOYbs1C5S+tc6kTjKnLxHPoepcGRkobY3f PgrQu/s9VdkswSudO/B7slxhFtyhHy2jFnsuQkpd9O/CePRjzMuuwykHE9Nt15WrCifM Pf1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ODCrxtZ3yufFSoHmMjpZuP3XvW6fxpmoLZ1oFttSEKA=; b=vNoaL/g9L5QAnBiVSklDrofH8TL8fiFZouub+Fex8LqvxxrvzWT7GS+mR7yKEYVzqD KoL4QAgP+xkt37Py5Vo6BeX1aa7gih2cGVb/5mirABE2sh4MtZRYEc+tJryVGovyaGQ/ qPJTgeVTttgnWSTdsV6GaOP0u5hhsZUUa2V4BQuKiWX7EqVlSFp4TfccYsk6FWIc9CBd TkBI3eNu7tIGKQdkEq50hqIMrRuATZUTc7affiKnD8XOJZJXvW4hrZwx5TU+VKTTOyzA OcDfo3ptDKNf7m7RWUv60auX0RCQZ6p+ckWPPljuX6uQLjAKaPBBkNPx44lnjZbtJ35B A99g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mdOsdayh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g65-20020a636b44000000b004fbfc2b436bsi4300456pgc.517.2023.02.17.02.46.47; Fri, 17 Feb 2023 02:47:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mdOsdayh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbjBQKYV (ORCPT + 99 others); Fri, 17 Feb 2023 05:24:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjBQKYQ (ORCPT ); Fri, 17 Feb 2023 05:24:16 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59A2163BF4; Fri, 17 Feb 2023 02:24:14 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id f4so948554plg.12; Fri, 17 Feb 2023 02:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ODCrxtZ3yufFSoHmMjpZuP3XvW6fxpmoLZ1oFttSEKA=; b=mdOsdayh21Du4BR++kSb7ZSDoA8hw8K+CmQqOGZ21lLuNGkfo7eB4BxSDPHOfhXgLZ q9DYBbaXIP8tZA3NU3mgU6CBYQKh8IY/+E/uWlVCpS6Z54HQnrA4Jm7F7BHLvZp3RF7T deq+TOuO5kdhN5xe1+DmDE7817ab/Ovc+itkyQTLdWgQxZ1OFxjJVsw+cQ/rPVSLwq2x xAQWWGiZFXL9DC6Dekv9+hnd/WAnosxzAL12boEWqJoNw4yJQitdV5Cax5Qb2sTAkTDP U+BRmlCP8ekodM2BPVF33kRcsVK81q5QXiPDgbuUHzObZOh+fc8TL7ap/LB2OM7ifS/H D2JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ODCrxtZ3yufFSoHmMjpZuP3XvW6fxpmoLZ1oFttSEKA=; b=Ze+5ThlOM+5DH6K3L+8tXK5oiaXKk/sNW/lK8hluzzBLIMZhaDO/piTKoX8ek0xvHr 4PQvFrKd5Y8z4Yp3Bcb9KywfwfnoZFym15VysWE7QnBUAfabfGWEaSXfbI7KWIG+MEEw WnF5PShbC9OY338yY6oI/dJorCRCLQhjVkZZ5zvBE7UdIs80R8xZaNE0NqsiLj4ds8bt FD8XKdurCfBEhR+V3gPMRukBLC6x1nBAHCXkquVqkZygGDW2cPBREqPBc/Iu60JoCiu1 /RKyNXMxEV6JZOqponfesXht9lzmKfjveXrFF3umvBJPGmxWSDw4DoGKsGZM929dFMyx xzlQ== X-Gm-Message-State: AO0yUKWMW6ckf4qYDRFVbjhXDB/+kLPRhG8jqqIz5TSgnjPsq2ia4DK8 UXXgOBzJo2G3HDFbLGBGWg2jW4w4fFsnrA== X-Received: by 2002:a17:902:cec1:b0:199:1e59:6857 with SMTP id d1-20020a170902cec100b001991e596857mr12091210plg.8.1676629453605; Fri, 17 Feb 2023 02:24:13 -0800 (PST) Received: from localhost.localdomain ([202.53.32.211]) by smtp.gmail.com with ESMTPSA id w4-20020a1709029a8400b0019aaba5c90bsm2832538plp.84.2023.02.17.02.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 02:24:13 -0800 (PST) From: Orlando Chamberlain To: linux-doc@vger.kernel.org, linux-input@vger.kernel.org Cc: Jonathan Corbet , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org, Pavel Machek , Aditya Garg , Aun-Ali Zaidi , Kerem Karabay , Andy Shevchenko , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Orlando Chamberlain Subject: [PATCH v3 2/2] HID: hid-apple-magic-backlight: Add driver for keyboard backlight on internal Magic Keyboards Date: Fri, 17 Feb 2023 21:23:20 +1100 Message-Id: <20230217102319.3419-3-orlandoch.dev@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217102319.3419-1-orlandoch.dev@gmail.com> References: <20230217102319.3419-1-orlandoch.dev@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758074839763327853?= X-GMAIL-MSGID: =?utf-8?q?1758074839763327853?= This driver adds support for the keyboard backlight on Intel T2 Macs with internal Magic Keyboards (MacBookPro16,x and MacBookAir9,1) Co-developed-by: Kerem Karabay Signed-off-by: Kerem Karabay Signed-off-by: Orlando Chamberlain Reviewed-by: Andy Shevchenko Reviewed-by: Thomas Weißschuh --- v2->v3: - remove unneeded inclusion - use s32 for report value type - remove unneeded null check - don't set drvdata as its never used - prepend "hid-" to module name v1->v2: - drop unneeded remove function - combine set functions - add missing header inclusions - avoid char as argument in favour of u8 - handful of style/formatting fixes - use standard led name ":white:kbd_backlight" - rename USAGE_MAGIC_BL to HID_USAGE_MAGIC_BL MAINTAINERS | 6 ++ drivers/hid/Kconfig | 13 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-apple-magic-backlight.c | 122 ++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 drivers/hid/hid-apple-magic-backlight.c diff --git a/MAINTAINERS b/MAINTAINERS index fb1471cb5ed3..3319f0c3ed1e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9201,6 +9201,12 @@ F: include/linux/pm.h F: include/linux/suspend.h F: kernel/power/ +HID APPLE MAGIC BACKLIGHT DRIVER +M: Orlando Chamberlain +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/hid/apple-magic-backlight.c + HID CORE LAYER M: Jiri Kosina M: Benjamin Tissoires diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index e2a5d30c8895..fe489632bfd9 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -130,6 +130,19 @@ config HID_APPLE Say Y here if you want support for keyboards of Apple iBooks, PowerBooks, MacBooks, MacBook Pros and Apple Aluminum. +config HID_APPLE_MAGIC_BACKLIGHT + tristate "Apple Magic Keyboard Backlight" + depends on USB_HID + depends on LEDS_CLASS + depends on NEW_LEDS + help + Say Y here if you want support for the keyboard backlight on Macs with + the magic keyboard (MacBookPro16,x and MacBookAir9,1). Note that this + driver is not for external magic keyboards. + + To compile this driver as a module, choose M here: the + module will be called hid-apple-magic-backlight. + config HID_APPLEIR tristate "Apple infrared receiver" depends on (USB_HID) diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index e8014c1a2f8b..dc8df002bc86 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_HID_ACCUTOUCH) += hid-accutouch.o obj-$(CONFIG_HID_ALPS) += hid-alps.o obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o +obj-$(CONFIG_HID_APPLE_MAGIC_BACKLIGHT) += hid-apple-magic-backlight.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o diff --git a/drivers/hid/hid-apple-magic-backlight.c b/drivers/hid/hid-apple-magic-backlight.c new file mode 100644 index 000000000000..210af2849e78 --- /dev/null +++ b/drivers/hid/hid-apple-magic-backlight.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Apple Magic Keyboard Backlight Driver + * + * For Intel Macs with internal Magic Keyboard (MacBookPro16,1-4 and MacBookAir9,1) + * + * Copyright (c) 2022 Kerem Karabay + * Copyright (c) 2023 Orlando Chamberlain + */ + +#include +#include +#include +#include +#include + +#include "hid-ids.h" + +#define HID_USAGE_MAGIC_BL 0xff00000f + +#define APPLE_MAGIC_REPORT_ID_POWER 3 +#define APPLE_MAGIC_REPORT_ID_BRIGHTNESS 1 + +struct apple_magic_backlight { + struct led_classdev cdev; + struct hid_device *hdev; + struct hid_report *brightness; + struct hid_report *power; +}; + +static void apple_magic_backlight_report_set(struct hid_report *rep, s32 value, u8 rate) +{ + rep->field[0]->value[0] = value; + rep->field[1]->value[0] = 0x5e; /* Mimic Windows */ + rep->field[1]->value[0] |= rate << 8; + + hid_hw_request(rep->device, rep, HID_REQ_SET_REPORT); +} + +static void apple_magic_backlight_set(struct apple_magic_backlight *backlight, + int brightness, char rate) +{ + apple_magic_backlight_report_set(backlight->power, brightness ? 1 : 0, rate); + if (brightness) + apple_magic_backlight_report_set(backlight->brightness, brightness, rate); +} + +static int apple_magic_backlight_led_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct apple_magic_backlight *backlight = container_of(led_cdev, + struct apple_magic_backlight, cdev); + + apple_magic_backlight_set(backlight, brightness, 1); + return 0; +} + +static int apple_magic_backlight_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + struct apple_magic_backlight *backlight; + int rc; + + rc = hid_parse(hdev); + if (rc) + return rc; + + /* + * Ensure this usb endpoint is for the keyboard backlight, not touchbar + * backlight. + */ + if (hdev->collection[0].usage != HID_USAGE_MAGIC_BL) + return -ENODEV; + + backlight = devm_kzalloc(&hdev->dev, sizeof(*backlight), GFP_KERNEL); + if (!backlight) + return -ENOMEM; + + rc = hid_hw_start(hdev, HID_CONNECT_DEFAULT); + if (rc) + return rc; + + backlight->brightness = hid_register_report(hdev, HID_FEATURE_REPORT, + APPLE_MAGIC_REPORT_ID_BRIGHTNESS, 0); + backlight->power = hid_register_report(hdev, HID_FEATURE_REPORT, + APPLE_MAGIC_REPORT_ID_POWER, 0); + + if (!backlight->brightness || !backlight->power) { + rc = -ENODEV; + goto hw_stop; + } + + backlight->hdev = hdev; + backlight->cdev.name = ":white:" LED_FUNCTION_KBD_BACKLIGHT; + backlight->cdev.max_brightness = backlight->brightness->field[0]->logical_maximum; + backlight->cdev.brightness_set_blocking = apple_magic_backlight_led_set; + + apple_magic_backlight_set(backlight, 0, 0); + + return devm_led_classdev_register(&hdev->dev, &backlight->cdev); + +hw_stop: + hid_hw_stop(hdev); + return rc; +} + +static const struct hid_device_id apple_magic_backlight_hid_ids[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) }, + { } +}; +MODULE_DEVICE_TABLE(hid, apple_magic_backlight_hid_ids); + +static struct hid_driver apple_magic_backlight_hid_driver = { + .name = "hid-apple-magic-backlight", + .id_table = apple_magic_backlight_hid_ids, + .probe = apple_magic_backlight_probe, +}; +module_hid_driver(apple_magic_backlight_hid_driver); + +MODULE_DESCRIPTION("MacBook Magic Keyboard Backlight"); +MODULE_AUTHOR("Orlando Chamberlain "); +MODULE_LICENSE("GPL");