|
52 | 52 | #define APPLE_MAGIC_REPORT_ID_POWER 3 |
53 | 53 | #define APPLE_MAGIC_REPORT_ID_BRIGHTNESS 1 |
54 | 54 |
|
| 55 | +// DO NOT UPSTREAM: |
| 56 | +// temporary Fn key mode until xkeyboard-config has keyboard layouts with media |
| 57 | +// key mappings. At that point auto mode can drop function key mappings and this |
| 58 | +// mode can be dropped. |
| 59 | +#define FKEYS_IGNORE 4 |
| 60 | + |
55 | 61 | static unsigned int fnmode = 3; |
56 | 62 | module_param(fnmode, uint, 0644); |
57 | 63 | MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " |
58 | | - "1 = fkeyslast, 2 = fkeysfirst, [3] = auto)"); |
| 64 | + "1 = fkeyslast, 2 = fkeysfirst, [3] = auto, [4] = fkeysignore)"); |
59 | 65 |
|
60 | 66 | static int iso_layout = -1; |
61 | 67 | module_param(iso_layout, int, 0644); |
@@ -276,6 +282,16 @@ static const struct apple_key_translation apple_fn_keys[] = { |
276 | 282 | { } |
277 | 283 | }; |
278 | 284 |
|
| 285 | +static const struct apple_key_translation apple_fn_keys_minimal[] = { |
| 286 | + { KEY_BACKSPACE, KEY_DELETE }, |
| 287 | + { KEY_ENTER, KEY_INSERT }, |
| 288 | + { KEY_UP, KEY_PAGEUP }, |
| 289 | + { KEY_DOWN, KEY_PAGEDOWN }, |
| 290 | + { KEY_LEFT, KEY_HOME }, |
| 291 | + { KEY_RIGHT, KEY_END }, |
| 292 | + { } |
| 293 | +}; |
| 294 | + |
279 | 295 | static const struct apple_key_translation powerbook_fn_keys[] = { |
280 | 296 | { KEY_BACKSPACE, KEY_DELETE }, |
281 | 297 | { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY }, |
@@ -426,6 +442,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, |
426 | 442 |
|
427 | 443 | if (fnmode == 3) { |
428 | 444 | real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1; |
| 445 | + } else if (fnmode == FKEYS_IGNORE) { |
| 446 | + real_fnmode = 2; |
429 | 447 | } else { |
430 | 448 | real_fnmode = fnmode; |
431 | 449 | } |
@@ -505,7 +523,9 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, |
505 | 523 | table = macbookpro_dedicated_esc_fn_keys; |
506 | 524 | break; |
507 | 525 | default: |
508 | | - table = apple2021_fn_keys; |
| 526 | + table = (fnmode == FKEYS_IGNORE) ? |
| 527 | + apple_fn_keys_minimal : |
| 528 | + apple2021_fn_keys; |
509 | 529 | break; |
510 | 530 | } |
511 | 531 | else if (hid->product < 0x21d || hid->product >= 0x300) |
@@ -687,6 +707,7 @@ static void apple_setup_input(struct input_dev *input) |
687 | 707 |
|
688 | 708 | /* Enable all needed keys */ |
689 | 709 | apple_setup_key_translation(input, apple_fn_keys); |
| 710 | + apple_setup_key_translation(input, apple_fn_keys_minimal); |
690 | 711 | apple_setup_key_translation(input, powerbook_fn_keys); |
691 | 712 | apple_setup_key_translation(input, powerbook_numlock_keys); |
692 | 713 | apple_setup_key_translation(input, apple_iso_keyboard); |
@@ -924,6 +945,11 @@ static int apple_probe(struct hid_device *hdev, |
924 | 945 | hdev->type != HID_TYPE_SPI_KEYBOARD) |
925 | 946 | return -ENODEV; |
926 | 947 |
|
| 948 | + // key remapping will happen in xkeyboard-config so ignore |
| 949 | + // APPLE_ISO_TILDE_QUIRK |
| 950 | + if ((id->bus == BUS_SPI || id->bus == BUS_HOST) && fnmode == FKEYS_IGNORE) |
| 951 | + quirks &= ~APPLE_ISO_TILDE_QUIRK; |
| 952 | + |
927 | 953 | asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL); |
928 | 954 | if (asc == NULL) { |
929 | 955 | hid_err(hdev, "can't alloc apple descriptor\n"); |
@@ -1184,9 +1210,9 @@ static const struct hid_device_id apple_devices[] = { |
1184 | 1210 | { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021), |
1185 | 1211 | .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, |
1186 | 1212 | { HID_SPI_DEVICE(SPI_VENDOR_ID_APPLE, HID_ANY_ID), |
1187 | | - .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, |
| 1213 | + .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK |
1188 | 1214 | { HID_DEVICE(BUS_HOST, HID_GROUP_ANY, HOST_VENDOR_ID_APPLE, HID_ANY_ID), |
1189 | | - .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, |
| 1215 | + .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK }, // TODO: remove APPLE_ISO_TILDE_QUIRK |
1190 | 1216 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT), |
1191 | 1217 | .driver_data = APPLE_MAGIC_BACKLIGHT }, |
1192 | 1218 |
|
|
0 commit comments