21
21
#include <linux/module.h>
22
22
#include <linux/slab.h>
23
23
#include <linux/timer.h>
24
+ #include <linux/string.h>
24
25
25
26
#include "hid-ids.h"
26
27
35
36
#define APPLE_NUMLOCK_EMULATION BIT(8)
36
37
#define APPLE_RDESC_BATTERY BIT(9)
37
38
#define APPLE_BACKLIGHT_CTL BIT(10)
39
+ #define APPLE_IS_KEYCHRON BIT(11)
38
40
39
41
#define APPLE_FLAG_FKEY 0x01
40
42
41
43
#define HID_COUNTRY_INTERNATIONAL_ISO 13
42
44
#define APPLE_BATTERY_TIMEOUT_MS 60000
43
45
44
- static unsigned int fnmode = 1 ;
46
+ static unsigned int fnmode = 3 ;
45
47
module_param (fnmode , uint , 0644 );
46
48
MODULE_PARM_DESC (fnmode , "Mode of fn key on Apple keyboards (0 = disabled, "
47
- "[1] = fkeyslast, 2 = fkeysfirst)" );
49
+ "1 = fkeyslast, 2 = fkeysfirst, [3] = auto )" );
48
50
49
51
static int iso_layout = -1 ;
50
52
module_param (iso_layout , int , 0644 );
@@ -349,6 +351,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
349
351
const struct apple_key_translation * trans , * table ;
350
352
bool do_translate ;
351
353
u16 code = 0 ;
354
+ unsigned int real_fnmode ;
352
355
353
356
u16 fn_keycode = (swap_fn_leftctrl ) ? (KEY_LEFTCTRL ) : (KEY_FN );
354
357
@@ -359,7 +362,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
359
362
return 1 ;
360
363
}
361
364
362
- if (fnmode ) {
365
+ if (fnmode == 3 ) {
366
+ real_fnmode = (asc -> quirks & APPLE_IS_KEYCHRON ) ? 2 : 1 ;
367
+ } else {
368
+ real_fnmode = fnmode ;
369
+ }
370
+
371
+ if (real_fnmode ) {
363
372
if (hid -> product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
364
373
hid -> product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
365
374
hid -> product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
@@ -406,7 +415,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
406
415
407
416
if (!code ) {
408
417
if (trans -> flags & APPLE_FLAG_FKEY ) {
409
- switch (fnmode ) {
418
+ switch (real_fnmode ) {
410
419
case 1 :
411
420
do_translate = !asc -> fn_on ;
412
421
break ;
@@ -660,6 +669,11 @@ static int apple_input_configured(struct hid_device *hdev,
660
669
asc -> quirks &= ~APPLE_HAS_FN ;
661
670
}
662
671
672
+ if (strncmp (hdev -> name , "Keychron" , 8 ) == 0 ) {
673
+ hid_info (hdev , "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n" );
674
+ asc -> quirks |= APPLE_IS_KEYCHRON ;
675
+ }
676
+
663
677
return 0 ;
664
678
}
665
679
0 commit comments