2424#define APPLE_RDESC_JIS 0x0001
2525#define APPLE_IGNORE_MOUSE 0x0002
2626#define APPLE_HAS_FN 0x0004
27- #define APPLE_HIDDEV 0x0008
28- /* 0x0010 reserved, was: APPLE_ISO_KEYBOARD */
27+ /* 0x0008 reserved, was: APPLE_HIDDEV */
28+ #define APPLE_ISO_TILDE_QUIRK 0x0010
2929#define APPLE_MIGHTYMOUSE 0x0020
3030#define APPLE_INVERT_HWHEEL 0x0040
31- #define APPLE_IGNORE_HIDINPUT 0x0080
31+ /* 0x0080 reserved, was: APPLE_IGNORE_HIDINPUT */
3232#define APPLE_NUMLOCK_EMULATION 0x0100
3333
3434#define APPLE_FLAG_FKEY 0x01
@@ -40,10 +40,10 @@ module_param(fnmode, uint, 0644);
4040MODULE_PARM_DESC (fnmode , "Mode of fn key on Apple keyboards (0 = disabled, "
4141 "[1] = fkeyslast, 2 = fkeysfirst)" );
4242
43- static unsigned int iso_layout = 1 ;
44- module_param (iso_layout , uint , 0644 );
45- MODULE_PARM_DESC (iso_layout , "Enable/Disable hardcoded ISO-layout of the keyboard . "
46- "(0 = disabled, [1] = enabled)" );
43+ static int iso_layout = - 1 ;
44+ module_param (iso_layout , int , 0644 );
45+ MODULE_PARM_DESC (iso_layout , "Swap the backtick/tilde and greater-than/less-than keys . "
46+ "([-1] = auto, 0 = disabled, 1 = enabled)" );
4747
4848static unsigned int swap_opt_cmd ;
4949module_param (swap_opt_cmd , uint , 0644 );
@@ -277,14 +277,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
277277 }
278278 }
279279
280- if (iso_layout ) {
281- if (hid -> country == HID_COUNTRY_INTERNATIONAL_ISO ) {
282- trans = apple_find_translation (apple_iso_keyboard , usage -> code );
283- if (trans ) {
284- input_event_with_scancode (input , usage -> type ,
285- trans -> to , usage -> hid , value );
286- return 1 ;
287- }
280+ if (iso_layout > 0 || (iso_layout < 0 && (asc -> quirks & APPLE_ISO_TILDE_QUIRK ) &&
281+ hid -> country == HID_COUNTRY_INTERNATIONAL_ISO )) {
282+ trans = apple_find_translation (apple_iso_keyboard , usage -> code );
283+ if (trans ) {
284+ input_event_with_scancode (input , usage -> type ,
285+ trans -> to , usage -> hid , value );
286+ return 1 ;
288287 }
289288 }
290289
@@ -440,7 +439,6 @@ static int apple_probe(struct hid_device *hdev,
440439{
441440 unsigned long quirks = id -> driver_data ;
442441 struct apple_sc * asc ;
443- unsigned int connect_mask = HID_CONNECT_DEFAULT ;
444442 int ret ;
445443
446444 asc = devm_kzalloc (& hdev -> dev , sizeof (* asc ), GFP_KERNEL );
@@ -459,12 +457,7 @@ static int apple_probe(struct hid_device *hdev,
459457 return ret ;
460458 }
461459
462- if (quirks & APPLE_HIDDEV )
463- connect_mask |= HID_CONNECT_HIDDEV_FORCE ;
464- if (quirks & APPLE_IGNORE_HIDINPUT )
465- connect_mask &= ~HID_CONNECT_HIDINPUT ;
466-
467- ret = hid_hw_start (hdev , connect_mask );
460+ ret = hid_hw_start (hdev , HID_CONNECT_DEFAULT );
468461 if (ret ) {
469462 hid_err (hdev , "hw start failed\n" );
470463 return ret ;
@@ -533,9 +526,11 @@ static const struct hid_device_id apple_devices[] = {
533526 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ),
534527 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
535528 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ),
536- .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
529+ .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
530+ APPLE_ISO_TILDE_QUIRK },
537531 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ),
538- .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
532+ .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
533+ APPLE_ISO_TILDE_QUIRK },
539534 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE ,
540535 USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ),
541536 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
@@ -544,14 +539,14 @@ static const struct hid_device_id apple_devices[] = {
544539 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
545540 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ),
546541 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
547- { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI ),
548- .driver_data = APPLE_HAS_FN },
549- { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI ),
550- .driver_data = APPLE_HAS_FN },
551- { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI ),
552- .driver_data = APPLE_HAS_FN },
553- { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI ),
554- .driver_data = APPLE_HAS_FN },
542+ { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ),
543+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
544+ { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ),
545+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
546+ { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015 ),
547+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
548+ { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015 ),
549+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
555550 { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRING_ANSI ),
556551 .driver_data = APPLE_HAS_FN },
557552 { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_WELLSPRING_ISO ),
@@ -633,13 +628,18 @@ static const struct hid_device_id apple_devices[] = {
633628 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ),
634629 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
635630 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ),
636- .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
631+ .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
632+ APPLE_ISO_TILDE_QUIRK },
637633 { HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ),
638634 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
639635 { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY ),
640636 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
641637 { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY ),
642638 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
639+ { HID_USB_DEVICE (USB_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ),
640+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
641+ { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE , USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ),
642+ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
643643
644644 { }
645645};
0 commit comments