From patchwork Tue Feb 8 18:37:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12739189 X-Patchwork-Delegate: jikos@jikos.cz 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 874F7C433EF for ; Tue, 8 Feb 2022 18:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355389AbiBHShO (ORCPT ); Tue, 8 Feb 2022 13:37:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235940AbiBHShO (ORCPT ); Tue, 8 Feb 2022 13:37:14 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A58DC061579; Tue, 8 Feb 2022 10:37:13 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id l123-20020a1c2581000000b0037b9d960079so1842061wml.0; Tue, 08 Feb 2022 10:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L6agt1vf+amWniZh1gXtipOgD6wm2asGKzDyPpayMiA=; b=NBylJD5zJum1mLlZYAzx6SJmi4SSpVGKCqjwxTAFk7WDeDCBcL1Hgx64HM1ZOML97/ RKc3SzD4PeY+ECJio5x8kBm2Wc8q8OD1IWZJpf6BtQ+LUhTMWwQZ09BTQ7fvlqMIlO6I uAa6hlJZs0U97IsK3qS1Ij8oHl/GVeR3GaDHmaJ/1BHucBXRSNDuUdPjnrtWOap/lLze 7hxdVUg6+tciWvce/qRAGDFlD9Vfc4V3Ii3tM0lBQieHeKsFHSTQxa1igurvr6JVq/pQ ikecBzORPLtdHMzOs8gITy7RGrevY1iAXVPvuFWsOByvjgK5h5Dcy6Vr3lzsmw5S+msO VZFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L6agt1vf+amWniZh1gXtipOgD6wm2asGKzDyPpayMiA=; b=gei1CEthWMXipQyX4sRHe2hkUfGGLfEjFvhiKrRAhKiNosH+muWeac+uc55lTNiU3j fRE56HbQgdkJZf6vJZXvQa2+Z0R2SOyWfr7BeHYpJOaYcyFxbzhLVr3BFunLZ1/kVrH0 jLQdsAmnypW41Lb9mxDOtvNwlJd1VknS98MQsExZAXlNExCJ+SZoYpDFc9Ul3gb3e0Uu Bkj+C3Khc/H7UdKIaR5bJFi0HOeXLrm4bfeKKG3YNbwAhG0nWwcWTL3sGi3uZcx5QfWk yMdh6cE0pHNyH/3ABYg0SiG3Y/X6WK+EVxyaKaSB1Z6eBf30uGymfAsNEjfvNcTqLfGT 534Q== X-Gm-Message-State: AOAM530pmxvbhsAOQoilXLzFSnihawYr6K40vTV3ILk+zKwqr651trCk w6N9ma0CR/R/hMetJkAUzpQ= X-Google-Smtp-Source: ABdhPJybn0/Ym2G1A7pSnJMFr8KahuGFhK4pAGF44v8GL+B14EQGR3OiaFKZ7JtAcfu7de0QobdrAg== X-Received: by 2002:a05:600c:1f0a:: with SMTP id bd10mr2135080wmb.6.1644345431854; Tue, 08 Feb 2022 10:37:11 -0800 (PST) Received: from localhost.localdomain ([94.73.33.246]) by smtp.gmail.com with ESMTPSA id l20sm2945308wmq.22.2022.02.08.10.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:37:11 -0800 (PST) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v2 1/3] HID: apple: Refactor key translation setup Date: Tue, 8 Feb 2022 19:37:02 +0100 Message-Id: <20220208183704.40101-2-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208183704.40101-1-jose.exposito89@gmail.com> References: <20220208183704.40101-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The code used to map the apple_key_translation structs is duplicated. Extract it to a common function. Refactor, no functional changes. Signed-off-by: José Expósito --- drivers/hid/hid-apple.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 24802a4a636e..6ca393c0a390 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -202,6 +202,15 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = { { } }; +static inline void apple_setup_key_translation(struct input_dev *input, + const struct apple_key_translation *table) +{ + const struct apple_key_translation *trans; + + for (trans = table; trans->from; trans++) + set_bit(trans->to, input->keybit); +} + static const struct apple_key_translation *apple_find_translation( const struct apple_key_translation *table, u16 from) { @@ -452,30 +461,17 @@ static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc, static void apple_setup_input(struct input_dev *input) { - const struct apple_key_translation *trans; - set_bit(KEY_NUMLOCK, input->keybit); /* Enable all needed keys */ - for (trans = apple_fn_keys; trans->from; trans++) - set_bit(trans->to, input->keybit); - - for (trans = powerbook_fn_keys; trans->from; trans++) - set_bit(trans->to, input->keybit); - - for (trans = powerbook_numlock_keys; trans->from; trans++) - set_bit(trans->to, input->keybit); - - for (trans = apple_iso_keyboard; trans->from; trans++) - set_bit(trans->to, input->keybit); - - for (trans = apple2021_fn_keys; trans->from; trans++) - set_bit(trans->to, input->keybit); - - if (swap_fn_leftctrl) { - for (trans = swapped_fn_leftctrl_keys; trans->from; trans++) - set_bit(trans->to, input->keybit); - } + apple_setup_key_translation(input, apple_fn_keys); + apple_setup_key_translation(input, powerbook_fn_keys); + apple_setup_key_translation(input, powerbook_numlock_keys); + apple_setup_key_translation(input, apple_iso_keyboard); + apple_setup_key_translation(input, apple2021_fn_keys); + + if (swap_fn_leftctrl) + apple_setup_key_translation(input, swapped_fn_leftctrl_keys); } static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, From patchwork Tue Feb 8 18:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12739190 X-Patchwork-Delegate: jikos@jikos.cz 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6E30C4332F for ; Tue, 8 Feb 2022 18:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384992AbiBHShP (ORCPT ); Tue, 8 Feb 2022 13:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384954AbiBHShO (ORCPT ); Tue, 8 Feb 2022 13:37:14 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB3CFC061576; Tue, 8 Feb 2022 10:37:13 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id q7so4224432wrc.13; Tue, 08 Feb 2022 10:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BxL5OIWqqpAy6UyfrEJShM9WIDuebK75MbARP5wirg8=; b=kxqrBwpPMYD3IylFIVxVsovDv6QgZDopnXwBzbdSFUPuTWFnmN/fPSdQ/wOhzZzL0e Fn1Q2zyjvSALllyzii9Dexno66VgYTELeoTVkd7vSTP/+k0RBpT4vhd181OJPn3LYrcl u0PmePCgfRijHHyhi14ahUokEiVLTawI8dwi2wZgFgiOz5POcSK67pIZbsXHT0JeS+9b yNBMyYRxigcoao7rlDvGb8YUW/X7nUAtecmzn4n0Uy08zCVwOFpfIIVH7R7Xlsn+tkMa psoEtk2As1hQOWskDU1bhZe1aYv8JVDMZQUcoObphSx1CN/FKayP2hR9rVs3cATq/F+A MJNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BxL5OIWqqpAy6UyfrEJShM9WIDuebK75MbARP5wirg8=; b=jRfFkVbdiRfA13OzvU2JJVfQZTYjACicNarBLE/9v18P/uJujRv+5AHDo7raX/fvgg w2TReYRW2t9dGVFa5RYk0qZEqHwZ0DdmuY6wwESdH7jzS4kU73N8MbTzAQEX0ZbTv6K8 jd94wwN4ekXH5kHdiyubOLg/HQBPJxPzgCA8mmq+SYrPcw9QsLapy9/WeKnxLApR8CD/ Xaf5qmv8P48Y8AE1/a58tXlHdyCOXnCb1LsxBlKmHsTqSUsY1H/XxRt0Dvjdon6bOQBl hykmV/ykpNqUjIbwZtBgCeEEyDDz/lDBMRDGZ5d3GODHCXaVlYXW9akOAEoMDD3tLjmw thrA== X-Gm-Message-State: AOAM5322n/KnIuP10S/+6SXaPEQSi2SrqVC9jmjKune204rWYOP8bRVF vQ2YiHAVrHLyO6KVofIiBEM= X-Google-Smtp-Source: ABdhPJz6rHCygktNsudASkjo9NK5WWFglF+Ay6wa4YTCDDsK+BrYTode4eijsA8rMH9F59ppAb5u0Q== X-Received: by 2002:a05:6000:cf:: with SMTP id q15mr3560484wrx.536.1644345432557; Tue, 08 Feb 2022 10:37:12 -0800 (PST) Received: from localhost.localdomain ([94.73.33.246]) by smtp.gmail.com with ESMTPSA id l20sm2945308wmq.22.2022.02.08.10.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:37:12 -0800 (PST) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v2 2/3] HID: apple: Magic Keyboard first generation FN key mapping Date: Tue, 8 Feb 2022 19:37:03 +0100 Message-Id: <20220208183704.40101-3-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208183704.40101-1-jose.exposito89@gmail.com> References: <20220208183704.40101-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The function key mapping for the Magic Keyboard first generation (2007, 2009 and 2011 aluminum wireless models) was not present and the default one was used instead. This caused two main issues: - The F5 and F6 keys were sending KEY_KBDILLUMDOWN and KEY_KBDILLUMUP; however, the keyboard is not backlited. - The keyboard has the APPLE_NUMLOCK_EMULATION quirk with F6 set as the KEY_NUMLOCK key by "powerbook_numlock_keys". However, because F6 was mapped to KEY_KBDILLUMUP by the default mapping it was not possible to switch the numlock status. This means that, if numlock was enabled on session startup, it was not possible to disable it without connecting another keyboard. Add a custom translation table for the device leaving F5 unassigned and using F6 as the KEY_NUMLOCK key. Signed-off-by: José Expósito --- drivers/hid/hid-apple.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 6ca393c0a390..c140146e2370 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -76,6 +76,27 @@ struct apple_key_translation { u8 flags; }; +static const struct apple_key_translation magic_keyboard_alu_fn_keys[] = { + { KEY_BACKSPACE, KEY_DELETE }, + { KEY_ENTER, KEY_INSERT }, + { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, + { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, + { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY }, + { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY }, + { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY }, + { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, + { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, + { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY }, + { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY }, + { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, + { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, + { KEY_UP, KEY_PAGEUP }, + { KEY_DOWN, KEY_PAGEDOWN }, + { KEY_LEFT, KEY_HOME }, + { KEY_RIGHT, KEY_END }, + { } +}; + static const struct apple_key_translation apple2021_fn_keys[] = { { KEY_BACKSPACE, KEY_DELETE }, { KEY_ENTER, KEY_INSERT }, @@ -251,9 +272,19 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, } if (fnmode) { - if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 || - hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 || - hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021) + if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO || + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) + table = magic_keyboard_alu_fn_keys; + else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 || + hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 || + hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021) table = apple2021_fn_keys; else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) @@ -468,6 +499,7 @@ static void apple_setup_input(struct input_dev *input) apple_setup_key_translation(input, powerbook_fn_keys); apple_setup_key_translation(input, powerbook_numlock_keys); apple_setup_key_translation(input, apple_iso_keyboard); + apple_setup_key_translation(input, magic_keyboard_alu_fn_keys); apple_setup_key_translation(input, apple2021_fn_keys); if (swap_fn_leftctrl) From patchwork Tue Feb 8 18:37:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Patchwork-Id: 12739191 X-Patchwork-Delegate: jikos@jikos.cz 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF201C433EF for ; Tue, 8 Feb 2022 18:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385001AbiBHShQ (ORCPT ); Tue, 8 Feb 2022 13:37:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbiBHShP (ORCPT ); Tue, 8 Feb 2022 13:37:15 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7F7C061579; Tue, 8 Feb 2022 10:37:14 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id q198-20020a1ca7cf000000b0037bb52545c6so1803333wme.1; Tue, 08 Feb 2022 10:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qFTo/bi+FjWLNEXhekC/MI3dMk+TubwGuk6yd0dpJGU=; b=kiwXSfLsrQfkGXvJ7u+3BTLh8Fcruy6Dz1BVftSQVcfGbjRNmavlyTm7omSEKy50Wj bpUIaKp1lb529BdXhTnrYZSqOUzmMBYwN+uxUp+QxGeBYUBcl0CH9n3+UK9RwJGd80Xy 9ehirjizBu2j5EHIsxF8yiuRgCswq//ZKLHAnakvXH/KMcXPSYOIsraO96a/T7Qavpc+ gOvH8qG9OisNBZA/gV3N2sD2Ny89eYPiAO3V0w8gO9HJJyuyYT6dDZm2h0F3TQWB2h8a Q8xamO+Wp1IpncPU8ilyYvIZ7aMlv0SSRkJmSJawl6RIGakpALSjQVZcq1svY4Z3KBPl rVPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qFTo/bi+FjWLNEXhekC/MI3dMk+TubwGuk6yd0dpJGU=; b=DDWh79JGqKAeEjM0pApTZDYvfJEoexLXs/SyKSzFmShrUG0sw97PryVfWfcrIv/bTa YIHeg6UX54RYRtWv64i0ZCDZvQHvRixJt50/rF6yzYsIXuPcsUg7lBSl8IhjstSPo/L9 QvvecwlTp0cpiDi3bC2OR7MaDe11P9Umnv2DGRPvUOa+kKd8fzKy0e70KVlZaaYwHPWo ZhiTQL42nrw5a6DlwZGjZSmOBFNORB+VGZiRaUstESqf1RrBdHsfwWMM3TG9lYSrc1EZ 3K7tPm3WlVR/VCbjvYx9Gga7h7fOiowHq7xpZ9DSufTfbd82nVD5dZ/nTwSaR/6WSC60 VG1Q== X-Gm-Message-State: AOAM530R6YHyVz4jAVFTT/xXUfBVvKOx73P9quLTo6lzIBKPck3i0cA+ bvKFKcsb7djAyjUh8IsfJ/s= X-Google-Smtp-Source: ABdhPJxwpFPd8NjSVfFji4x1ADJbmOdeyIXwd1HIXa+5Zx6tcA/BS2T1SRS9Z62RzwrT00NVD62afA== X-Received: by 2002:a05:600c:3ac5:: with SMTP id d5mr2137484wms.107.1644345433388; Tue, 08 Feb 2022 10:37:13 -0800 (PST) Received: from localhost.localdomain ([94.73.33.246]) by smtp.gmail.com with ESMTPSA id l20sm2945308wmq.22.2022.02.08.10.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:37:13 -0800 (PST) From: =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= Subject: [PATCH v2 3/3] HID: apple: Magic Keyboard 2015 FN key mapping Date: Tue, 8 Feb 2022 19:37:04 +0100 Message-Id: <20220208183704.40101-4-jose.exposito89@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208183704.40101-1-jose.exposito89@gmail.com> References: <20220208183704.40101-1-jose.exposito89@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The Magic Keyboard 2015 function key mapping was not present and the default mapping was used. While this worked for most keys, the F5 and F6 keys were sending KEY_KBDILLUMDOWN and KEY_KBDILLUMUP; however, the keyboard is not backlited. Add a custom translation table for the keyboard leaving F5 and F6 unassigned to mimic the default behavior on macOS. Signed-off-by: José Expósito --- drivers/hid/hid-apple.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index c140146e2370..4a458e7fab42 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -97,6 +97,26 @@ static const struct apple_key_translation magic_keyboard_alu_fn_keys[] = { { } }; +static const struct apple_key_translation magic_keyboard_2015_fn_keys[] = { + { KEY_BACKSPACE, KEY_DELETE }, + { KEY_ENTER, KEY_INSERT }, + { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, + { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY }, + { KEY_F3, KEY_SCALE, APPLE_FLAG_FKEY }, + { KEY_F4, KEY_DASHBOARD, APPLE_FLAG_FKEY }, + { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY }, + { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY }, + { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY }, + { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY }, + { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY }, + { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY }, + { KEY_UP, KEY_PAGEUP }, + { KEY_DOWN, KEY_PAGEDOWN }, + { KEY_LEFT, KEY_HOME }, + { KEY_RIGHT, KEY_END }, + { } +}; + static const struct apple_key_translation apple2021_fn_keys[] = { { KEY_BACKSPACE, KEY_DELETE }, { KEY_ENTER, KEY_INSERT }, @@ -282,6 +302,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO || hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) table = magic_keyboard_alu_fn_keys; + else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 || + hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015) + table = magic_keyboard_2015_fn_keys; else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 || hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 || hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021) @@ -500,6 +523,7 @@ static void apple_setup_input(struct input_dev *input) apple_setup_key_translation(input, powerbook_numlock_keys); apple_setup_key_translation(input, apple_iso_keyboard); apple_setup_key_translation(input, magic_keyboard_alu_fn_keys); + apple_setup_key_translation(input, magic_keyboard_2015_fn_keys); apple_setup_key_translation(input, apple2021_fn_keys); if (swap_fn_leftctrl)