Skip to content

Commit 144c71f

Browse files
author
Jiri Kosina
committed
Merge branch 'for-5.20/apple' into for-linus
2 parents c556717 + 20afcc4 commit 144c71f

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

drivers/hid/hid-apple.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define APPLE_NUMLOCK_EMULATION BIT(8)
3737
#define APPLE_RDESC_BATTERY BIT(9)
3838
#define APPLE_BACKLIGHT_CTL BIT(10)
39-
#define APPLE_IS_KEYCHRON BIT(11)
39+
#define APPLE_IS_NON_APPLE BIT(11)
4040

4141
#define APPLE_FLAG_FKEY 0x01
4242

@@ -65,6 +65,10 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
6565
"(For people who want to keep PC keyboard muscle memory. "
6666
"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
6767

68+
struct apple_non_apple_keyboard {
69+
char *name;
70+
};
71+
6872
struct apple_sc_backlight {
6973
struct led_classdev cdev;
7074
struct hid_device *hdev;
@@ -313,6 +317,27 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
313317
{ }
314318
};
315319

320+
static const struct apple_non_apple_keyboard non_apple_keyboards[] = {
321+
{ "SONiX USB DEVICE" },
322+
{ "Keychron" },
323+
{ "AONE" },
324+
{ "GANSS" }
325+
};
326+
327+
static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
328+
{
329+
int i;
330+
331+
for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
332+
char *non_apple = non_apple_keyboards[i].name;
333+
334+
if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
335+
return true;
336+
}
337+
338+
return false;
339+
}
340+
316341
static inline void apple_setup_key_translation(struct input_dev *input,
317342
const struct apple_key_translation *table)
318343
{
@@ -363,7 +388,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
363388
}
364389

365390
if (fnmode == 3) {
366-
real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
391+
real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
367392
} else {
368393
real_fnmode = fnmode;
369394
}
@@ -669,9 +694,9 @@ static int apple_input_configured(struct hid_device *hdev,
669694
asc->quirks &= ~APPLE_HAS_FN;
670695
}
671696

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;
697+
if (apple_is_non_apple_keyboard(hdev)) {
698+
hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
699+
asc->quirks |= APPLE_IS_NON_APPLE;
675700
}
676701

677702
return 0;

0 commit comments

Comments
 (0)