From: Greg Kroah-Hartman Date: Sat, 3 Feb 2024 03:35:36 +0000 (-0800) Subject: 5.4-stable patches X-Git-Tag: v6.1.77~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfe57d7d2631c611ca470efe2779a4eb6d8db1f8;p=thirdparty%2Fkernel%2Fstable-queue.git 5.4-stable patches added patches: hid-apple-add-2021-magic-keyboard-fn-key-mapping.patch hid-apple-add-support-for-the-2021-magic-keyboard.patch hid-apple-swap-the-fn-and-left-control-keys-on-apple-keyboards.patch --- diff --git a/queue-5.4/hid-apple-add-2021-magic-keyboard-fn-key-mapping.patch b/queue-5.4/hid-apple-add-2021-magic-keyboard-fn-key-mapping.patch new file mode 100644 index 00000000000..962db6be5e7 --- /dev/null +++ b/queue-5.4/hid-apple-add-2021-magic-keyboard-fn-key-mapping.patch @@ -0,0 +1,72 @@ +From 531cb56972f2773c941499fcfb639cd5128dfb27 Mon Sep 17 00:00:00 2001 +From: Benjamin Berg +Date: Mon, 8 Nov 2021 13:50:38 +0100 +Subject: HID: apple: Add 2021 magic keyboard FN key mapping + +From: Benjamin Berg + +commit 531cb56972f2773c941499fcfb639cd5128dfb27 upstream. + +The new 2021 apple models have a different FN key assignment. Add a new +translation table and use that for the 2021 magic keyboard. + +Signed-off-by: Benjamin Berg +Signed-off-by: Jiri Kosina +Cc: Aseda Aboagye +Signed-off-by: Greg Kroah-Hartman +--- + drivers/hid/hid-apple.c | 29 ++++++++++++++++++++++++++++- + 1 file changed, 28 insertions(+), 1 deletion(-) + +--- a/drivers/hid/hid-apple.c ++++ b/drivers/hid/hid-apple.c +@@ -70,6 +70,28 @@ struct apple_key_translation { + u8 flags; + }; + ++static const struct apple_key_translation apple2021_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_SEARCH, APPLE_FLAG_FKEY }, ++ { KEY_F5, KEY_MICMUTE, APPLE_FLAG_FKEY }, ++ { KEY_F6, KEY_SLEEP, 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 macbookair_fn_keys[] = { + { KEY_BACKSPACE, KEY_DELETE }, + { KEY_ENTER, KEY_INSERT }, +@@ -204,7 +226,9 @@ static int hidinput_apple_event(struct h + } + + if (fnmode) { +- if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && ++ if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) ++ table = apple2021_fn_keys; ++ else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && + hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) + table = macbookair_fn_keys; + else if (hid->product < 0x21d || hid->product >= 0x300) +@@ -363,6 +387,9 @@ static void apple_setup_input(struct inp + 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); diff --git a/queue-5.4/hid-apple-add-support-for-the-2021-magic-keyboard.patch b/queue-5.4/hid-apple-add-support-for-the-2021-magic-keyboard.patch new file mode 100644 index 00000000000..08907661d5f --- /dev/null +++ b/queue-5.4/hid-apple-add-support-for-the-2021-magic-keyboard.patch @@ -0,0 +1,52 @@ +From 0cd3be51733febb4f8acb92bcf55b75fe824dd05 Mon Sep 17 00:00:00 2001 +From: Alex Henrie +Date: Fri, 8 Oct 2021 01:37:01 -0600 +Subject: HID: apple: Add support for the 2021 Magic Keyboard + +From: Alex Henrie + +commit 0cd3be51733febb4f8acb92bcf55b75fe824dd05 upstream. + +Signed-off-by: Alex Henrie +Signed-off-by: Jiri Kosina +Cc: Aseda Aboagye +Signed-off-by: Greg Kroah-Hartman +--- + drivers/hid/hid-apple.c | 4 ++++ + drivers/hid/hid-ids.h | 1 + + drivers/hid/hid-quirks.c | 1 + + 3 files changed, 6 insertions(+) + +--- a/drivers/hid/hid-apple.c ++++ b/drivers/hid/hid-apple.c +@@ -596,6 +596,10 @@ static const struct hid_device_id apple_ + .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY), + .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021), ++ .driver_data = APPLE_HAS_FN }, ++ { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021), ++ .driver_data = APPLE_HAS_FN }, + + { } + }; +--- a/drivers/hid/hid-ids.h ++++ b/drivers/hid/hid-ids.h +@@ -175,6 +175,7 @@ + #define USB_DEVICE_ID_APPLE_IRCONTROL3 0x8241 + #define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 + #define USB_DEVICE_ID_APPLE_IRCONTROL5 0x8243 ++#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 0x029c + + #define USB_VENDOR_ID_ASUS 0x0486 + #define USB_DEVICE_ID_ASUS_T91MT 0x0185 +--- a/drivers/hid/hid-quirks.c ++++ b/drivers/hid/hid-quirks.c +@@ -308,6 +308,7 @@ static const struct hid_device_id hid_ha + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, + { 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) }, + #endif + #if IS_ENABLED(CONFIG_HID_APPLEIR) + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, diff --git a/queue-5.4/hid-apple-swap-the-fn-and-left-control-keys-on-apple-keyboards.patch b/queue-5.4/hid-apple-swap-the-fn-and-left-control-keys-on-apple-keyboards.patch new file mode 100644 index 00000000000..ebb99ccd60c --- /dev/null +++ b/queue-5.4/hid-apple-swap-the-fn-and-left-control-keys-on-apple-keyboards.patch @@ -0,0 +1,89 @@ +From 346338ef00d35bf8338ded171f9abeb9b10b43df Mon Sep 17 00:00:00 2001 +From: free5lot +Date: Fri, 15 May 2020 13:14:00 +0700 +Subject: HID: apple: Swap the Fn and Left Control keys on Apple keyboards + +From: free5lot + +commit 346338ef00d35bf8338ded171f9abeb9b10b43df upstream. + +This patch allows users to swap the Fn and left Control keys on all Apple +keyboards: internal (e.g. Macbooks) and external (both wired and wireless). +The patch adds a new hid-apple module param: swap_fn_leftctrl (off by default). + +Signed-off-by: Zakhar Semenov +Signed-off-by: Jiri Kosina +Cc: Aseda Aboagye +Signed-off-by: Greg Kroah-Hartman +--- + drivers/hid/hid-apple.c | 30 ++++++++++++++++++++++++++++-- + 1 file changed, 28 insertions(+), 2 deletions(-) + +--- a/drivers/hid/hid-apple.c ++++ b/drivers/hid/hid-apple.c +@@ -51,6 +51,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the + "(For people who want to keep Windows PC keyboard muscle memory. " + "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)"); + ++static unsigned int swap_fn_leftctrl; ++module_param(swap_fn_leftctrl, uint, 0644); ++MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. " ++ "(For people who want to keep PC keyboard muscle memory. " ++ "[0] = as-is, Mac layout, 1 = swapped, PC layout)"); ++ + struct apple_sc { + unsigned long quirks; + unsigned int fn_on; +@@ -163,6 +169,11 @@ static const struct apple_key_translatio + { } + }; + ++static const struct apple_key_translation swapped_fn_leftctrl_keys[] = { ++ { KEY_FN, KEY_LEFTCTRL }, ++ { } ++}; ++ + static const struct apple_key_translation *apple_find_translation( + const struct apple_key_translation *table, u16 from) + { +@@ -184,9 +195,11 @@ static int hidinput_apple_event(struct h + bool do_translate; + u16 code = 0; + +- if (usage->code == KEY_FN) { ++ u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN); ++ ++ if (usage->code == fn_keycode) { + asc->fn_on = !!value; +- input_event(input, usage->type, usage->code, value); ++ input_event(input, usage->type, KEY_FN, value); + return 1; + } + +@@ -271,6 +284,14 @@ static int hidinput_apple_event(struct h + } + } + ++ if (swap_fn_leftctrl) { ++ trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code); ++ if (trans) { ++ input_event(input, usage->type, trans->to, value); ++ return 1; ++ } ++ } ++ + return 0; + } + +@@ -341,6 +362,11 @@ static void apple_setup_input(struct inp + + for (trans = apple_iso_keyboard; 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); ++ } + } + + static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, diff --git a/queue-5.4/series b/queue-5.4/series index 46a6728f6c5..680f681d58a 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -170,3 +170,6 @@ netfilter-nft_ct-sanitize-layer-3-and-4-protocol-num.patch net-ipv4-fix-a-memleak-in-ip_setup_cork.patch af_unix-fix-lockdep-positive-in-sk_diag_dump_icons.patch net-sysfs-fix-sys-class-net-iface-path.patch +hid-apple-add-support-for-the-2021-magic-keyboard.patch +hid-apple-swap-the-fn-and-left-control-keys-on-apple-keyboards.patch +hid-apple-add-2021-magic-keyboard-fn-key-mapping.patch