2022-05-30 07:06:57

by José Expósito

[permalink] [raw]
Subject: Re: [PATCH] HID: apple: Reset quirks when Fn key is not found

Hi Hilton,

> Commit a5fe7864d8ad ("HID: apple: Do not reset quirks when the Fn key
> is not found") re-involves the fnmode issue fixed in commit
> a5d81646fa29 ("HID: apple: Disable Fn-key key-re-mapping on clone
> keyboards"), as linked below.

Reverting that commit will break battery reporting on the Magic
Keyboards 2015 and 2021.

When a keyboard has the APPLE_HAS_FN and another valid quirk, in this
case APPLE_RDESC_BATTERY, setting asc->quirks = 0 (i.e., removing all
quirks) also removes the valid ones.

> To make things work again, this commit reverts a5fe7864d8ad ("HID: apple:
> Do not reset quirks when the Fn key is not found")  and the recent
> workaround fa33382c7f74 ("HID: apple: Properly handle function keys on
> Keychron keyboards")

My understanding of Bryan's patch (in cc) was that the new config option
worked out of the box for Keychron and Apple keyboards and allowed for
manual configuration where required.

Could you explain a bit which bug is fixed by reverting these 2
commits, please? I don't own a Keychron keyboard for testing, so it is
not obvious to me why this change is required.

Thanks,Jose

> Link: https://lore.kernel.org/linux-input/[email protected]/
> Fixes: a5fe7864d8ad ("HID: apple: Do not reset quirks when the Fn key is not found")
> Signed-off-by: Hilton Chain <[email protected]>



2022-05-30 13:38:26

by Hilton Chain

[permalink] [raw]
Subject: Re: [PATCH] HID: apple: Reset quirks when Fn key is not found

Hi Jose,

> Reverting that commit will break battery reporting on the Magic
> Keyboards 2015 and 2021.
>
> When a keyboard has the APPLE_HAS_FN and another valid quirk, in this
> case APPLE_RDESC_BATTERY, setting asc->quirks = 0 (i.e., removing all
> quirks) also removes the valid ones.

Thanks for the explanation!

> My understanding of Bryan's patch (in cc) was that the new config option
> worked out of the box for Keychron and Apple keyboards and allowed for
> manual configuration where required.
>
> Could you explain a bit which bug is fixed by reverting these 2
> commits, please? I don't own a Keychron keyboard for testing, so it is
> not obvious to me why this change is required.

I own a GANSS keyboard which encounters this issue as well, related device
information given by `lsusb -v` below:

idVendor 0x05ac Apple, Inc.
idProduct 0x024f Aluminium Keyboard (ANSI)
iManufacturer 1 SONiX
iProduct 2 USB DEVICE

As I searching through, I found similar reports regarding another GANSS
model[1], and other brands like Varmilo[2] (a lot!) and Keychron. As a
common pattern, they mostly use 05ac:024f.

Currently I have two idea:

1. Modify Bryan's patch, so that fnmode default to 2 if device name not
starting with "Apple" (But I can't validate my assumption since I don't
own any Apple keyboards), I'll attach this patch in the next email.

2. Find out which quirk pattern solves this issue brute-forcely, I may
attach this patch later when I finally find a solution.

What's your opinion?

Stay boiled,
Hilton Chain

---
[1]: https://www.amazon.com/gp/customer-reviews/R1EV0B1FG21GGD
[2]: https://unix.stackexchange.com/questions/604791/keyboard-function-keys-always-trigger-media-shortcuts-regardless-of-whether-fn

2022-05-30 13:42:45

by Hilton Chain

[permalink] [raw]
Subject: [PATCH] HID: apple: Properly handle function keys on misset non-apple keyboards

This commit extends fa33382c7f74 ("HID: apple: Properly handle function
keys on Keychron keyboards") to support all misset non-apple keyboards.

Signed-off-by: Hilton Chain <[email protected]>
---

drivers/hid/hid-apple.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 42a568902f49..3b15753be467 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -36,7 +36,7 @@
#define APPLE_NUMLOCK_EMULATION BIT(8)
#define APPLE_RDESC_BATTERY BIT(9)
#define APPLE_BACKLIGHT_CTL BIT(10)
-#define APPLE_IS_KEYCHRON BIT(11)
+#define APPLE_IS_BAD_APPLE BIT(11)

#define APPLE_FLAG_FKEY 0x01

@@ -363,7 +363,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
}

if (fnmode == 3) {
- real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1;
+ real_fnmode = (asc->quirks & APPLE_IS_BAD_APPLE) ? 2 : 1;
} else {
real_fnmode = fnmode;
}
@@ -669,9 +669,9 @@ static int apple_input_configured(struct hid_device *hdev,
asc->quirks &= ~APPLE_HAS_FN;
}

- if (strncmp(hdev->name, "Keychron", 8) == 0) {
- hid_info(hdev, "Keychron keyboard detected; function keys will default to fnmode=2 behavior\n");
- asc->quirks |= APPLE_IS_KEYCHRON;
+ if (strncmp(hdev->name, "Apple", 5)) {
+ hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
+ asc->quirks |= APPLE_IS_BAD_APPLE;
}

return 0;

base-commit: b00ed48bb0a7c295facf9036135a573a5cdbe7de
--
2.36.1