Signed-off-by: Aditya Garg <gargaditya08@xxxxxxxx> --- drivers/hid/hid-apple.c | 63 ++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 49812a76b..18b779403 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -30,7 +30,7 @@ #include "hid-ids.h" #define APPLE_RDESC_JIS BIT(0) -#define APPLE_IGNORE_MOUSE BIT(1) +/* BIT(1) reserved, was: APPLE_IGNORE_MOUSE */ #define APPLE_HAS_FN BIT(2) /* BIT(3) reserved, was: APPLE_HIDDEV */ #define APPLE_ISO_TILDE_QUIRK BIT(4) @@ -84,11 +84,29 @@ struct apple_non_apple_keyboard { char *name; }; +struct apple_non_apple_keyboard_disable_fn { + char *name; + u32 product_id; +}; + struct apple_sc_backlight { struct led_classdev cdev; struct hid_device *hdev; }; +struct apple_backlight_config_report { + u8 report_id; + u8 version; + u16 backlight_off, backlight_on_min, backlight_on_max; +}; + +struct apple_backlight_set_report { + u8 report_id; + u8 version; + u16 backlight; + u16 rate; +}; + struct apple_magic_backlight { struct led_classdev cdev; struct hid_report *brightness; @@ -152,20 +170,6 @@ static const struct apple_key_translation magic_keyboard_2015_fn_keys[] = { { } }; -struct apple_backlight_config_report { - u8 report_id; - u8 version; - u16 backlight_off, backlight_on_min, backlight_on_max; -}; - -struct apple_backlight_set_report { - u8 report_id; - u8 version; - u16 backlight; - u16 rate; -}; - - static const struct apple_key_translation apple2021_fn_keys[] = { { KEY_BACKSPACE, KEY_DELETE }, { KEY_ENTER, KEY_INSERT }, @@ -352,6 +356,7 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = { { } }; +/* We want the default fnmode be 2 in these keyboards */ static const struct apple_non_apple_keyboard non_apple_keyboards[] = { { "SONiX USB DEVICE" }, { "Keychron" }, @@ -364,6 +369,11 @@ static const struct apple_non_apple_keyboard non_apple_keyboards[] = { { "WKB603" }, }; +/* Some non Apple keyboards report they have fn, but do internal translation of their keys */ +static const struct apple_non_apple_keyboard_disable_fn non_apple_keyboards_disable_fn[] = { + { "Bluetooth Keyboard", USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI}, +}; + static bool apple_is_non_apple_keyboard(struct hid_device *hdev) { int i; @@ -378,6 +388,22 @@ static bool apple_is_non_apple_keyboard(struct hid_device *hdev) return false; } +static bool apple_disable_fn(struct hid_device *hdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(non_apple_keyboards_disable_fn); i++) { + char *non_apple = non_apple_keyboards_disable_fn[i].name; + u32 pid = non_apple_keyboards_disable_fn[i].product_id; + + if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0 && + hdev->product == pid) + return true; + } + + return false; +} + static inline void apple_setup_key_translation(struct input_dev *input, const struct apple_key_translation *table) { @@ -546,9 +572,6 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, } } - if (usage->hid == 0xc0301) /* Omoton KB066 quirk */ - code = KEY_F6; - if (usage->code != code) { input_event_with_scancode(input, usage->type, code, usage->hid, value); @@ -728,8 +751,8 @@ static int apple_input_configured(struct hid_device *hdev, { struct apple_sc *asc = hid_get_drvdata(hdev); - if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) { - hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n"); + if (((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) || apple_disable_fn(hdev)) { + hid_info(hdev, "Fn key not found or has internal handling (Apple Wireless Keyboard clone?), disabling Fn key handling\n"); asc->quirks &= ~APPLE_HAS_FN; } -- 2.43.0 â??>8â?? Feel free to submit it from my behalf if you want. Ive signed it.