Re: [PATCH resend] HID: apple: fix up the F6 key on the Omoton KB066 keyboard
From: Aditya Garg <hidden>
Date: 2025-02-24 05:47:02
Subsystem:
hid core layer, the rest · Maintainers:
Jiri Kosina, Benjamin Tissoires, Linus Torvalds
On 24 Feb 2025, at 11:10 AM, Alex Henrie [off-list ref] wrote: On Sun, Feb 23, 2025 at 10:30 PM Aditya Garg [off-list ref] wrote:quoted
quoted
On 24 Feb 2025, at 10:49 AM, Alex Henrie [off-list ref] wrote: On Sun, Feb 23, 2025 at 10:05 PM Aditya Garg [off-list ref] wrote:quoted
quoted
quoted
Removing APPLE_HAS_FN quirk seems to be a better idea tbhI agree. I'll send a patch shortly that will do exactly that.I just made a patch. I'll sent it soon.I was going to spend a little more time looking over the patch I wrote before I sent it, but I just sent it to avoid wasting your time on duplicated effort. The most difficult part of the patch was writing a clear explanation in the commit message.
Commit messages are definitely a PITA LOL Could you see this patch btw. It also addresses some minor code style issues in the driver. —>8— From 09472be6428dd74064b2165a2a78e61e049c2667 Mon Sep 17 00:00:00 2001 From: Aditya Garg <redacted> Date: Mon, 24 Feb 2025 11:10:42 +0530 Subject: [PATCH] fix Signed-off-by: Aditya Garg <redacted> --- 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.