hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hid/hid-apple.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * USB HID quirks support for Linux
34 *
....@@ -9,10 +10,6 @@
910 */
1011
1112 /*
12
- * This program is free software; you can redistribute it and/or modify it
13
- * under the terms of the GNU General Public License as published by the Free
14
- * Software Foundation; either version 2 of the License, or (at your option)
15
- * any later version.
1613 */
1714
1815 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -53,6 +50,12 @@
5350 MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
5451 "(For people who want to keep Windows PC keyboard muscle memory. "
5552 "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
53
+
54
+static unsigned int swap_fn_leftctrl;
55
+module_param(swap_fn_leftctrl, uint, 0644);
56
+MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
57
+ "(For people who want to keep PC keyboard muscle memory. "
58
+ "[0] = as-is, Mac layout, 1 = swapped, PC layout)");
5659
5760 struct apple_sc {
5861 unsigned long quirks;
....@@ -166,6 +169,11 @@
166169 { }
167170 };
168171
172
+static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
173
+ { KEY_FN, KEY_LEFTCTRL },
174
+ { }
175
+};
176
+
169177 static const struct apple_key_translation *apple_find_translation(
170178 const struct apple_key_translation *table, u16 from)
171179 {
....@@ -187,9 +195,11 @@
187195 bool do_translate;
188196 u16 code = 0;
189197
190
- if (usage->code == KEY_FN) {
198
+ u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
199
+
200
+ if (usage->code == fn_keycode) {
191201 asc->fn_on = !!value;
192
- input_event(input, usage->type, usage->code, value);
202
+ input_event(input, usage->type, KEY_FN, value);
193203 return 1;
194204 }
195205
....@@ -274,6 +284,14 @@
274284 }
275285 }
276286
287
+ if (swap_fn_leftctrl) {
288
+ trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
289
+ if (trans) {
290
+ input_event(input, usage->type, trans->to, value);
291
+ return 1;
292
+ }
293
+ }
294
+
277295 return 0;
278296 }
279297
....@@ -344,6 +362,11 @@
344362
345363 for (trans = apple_iso_keyboard; trans->from; trans++)
346364 set_bit(trans->to, input->keybit);
365
+
366
+ if (swap_fn_leftctrl) {
367
+ for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
368
+ set_bit(trans->to, input->keybit);
369
+ }
347370 }
348371
349372 static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
....@@ -487,6 +510,8 @@
487510 .driver_data = APPLE_HAS_FN },
488511 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
489512 .driver_data = APPLE_HAS_FN },
513
+ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
514
+ .driver_data = APPLE_HAS_FN },
490515 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
491516 .driver_data = APPLE_HAS_FN },
492517 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),