2022-02-03 22:10:07

by Aditya Garg

[permalink] [raw]
Subject: [PATCH v3 2/3] HID: apple: Add necessary IDs and configuration for T2 Macs.

From: Aun-Ali Zaidi <[email protected]>

This patch adds the necessary IDs and configuration for Macs with
the T2 Security chip.

Signed-off-by: Aun-Ali Zaidi <[email protected]>
Signed-off-by: Aditya Garg <[email protected]>
---
v2 :- Use better approach to map fn keys
v3 :- Use BIT(10) for APPLE_BACKLIGHT_CTL since 0x0200 (BIT (9)) has been used.
drivers/hid/hid-apple.c | 16 ++++++++++++++++
drivers/hid/hid-ids.h | 8 ++++++++
drivers/hid/hid-quirks.c | 16 ++++++++++++++++
3 files changed, 40 insertions(+)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index c22d445a9..823021c24 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -861,6 +861,22 @@ static const struct hid_device_id apple_devices[] = {
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K),
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132),
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680),
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213),
+ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K),
+ .driver_data = APPLE_HAS_FN },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223),
+ .driver_data = APPLE_HAS_FN },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K),
+ .driver_data = APPLE_HAS_FN },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F),
+ .driver_data = APPLE_HAS_FN },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 26cee452e..8ad26c20f 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -167,6 +167,14 @@
#define USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI 0x0272
#define USB_DEVICE_ID_APPLE_WELLSPRING9_ISO 0x0273
#define USB_DEVICE_ID_APPLE_WELLSPRING9_JIS 0x0274
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K 0x027a
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 0x027b
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 0x027c
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213 0x027d
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K 0x027e
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 0x027f
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K 0x0280
+#define USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F 0x0340
#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
#define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index 9af1dc8ae..963cf2a2e 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -294,6 +294,14 @@ static const struct hid_device_id hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
@@ -929,6 +937,14 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
{ }
--
2.25.1



2022-02-04 08:51:40

by Aditya Garg

[permalink] [raw]
Subject: [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar

From: Aditya Garg <[email protected]>

This patch adds the Fn mapping for keyboards on certain T2 Macs.

Signed-off-by: Aditya Garg <[email protected]>
---
v2 :- Use better approach to map fn keys
v3 :- Use BIT(10) for APPLE_BACKLIGHT_CTL since 0x0200 (BIT (9)) has been used.
drivers/hid/hid-apple.c | 62 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 658d79375..5448e5a66 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -142,6 +142,51 @@ static const struct apple_key_translation macbookair_fn_keys[] = {
{ }
};

+static const struct apple_key_translation macbookpro_no_esc_fn_keys[] = {
+ { KEY_BACKSPACE, KEY_DELETE },
+ { KEY_ENTER, KEY_INSERT },
+ { KEY_GRAVE, KEY_ESC },
+ { KEY_1, KEY_F1 },
+ { KEY_2, KEY_F2 },
+ { KEY_3, KEY_F3 },
+ { KEY_4, KEY_F4 },
+ { KEY_5, KEY_F5 },
+ { KEY_6, KEY_F6 },
+ { KEY_7, KEY_F7 },
+ { KEY_8, KEY_F8 },
+ { KEY_9, KEY_F9 },
+ { KEY_0, KEY_F10 },
+ { KEY_MINUS, KEY_F11 },
+ { KEY_EQUAL, KEY_F12 },
+ { KEY_UP, KEY_PAGEUP },
+ { KEY_DOWN, KEY_PAGEDOWN },
+ { KEY_LEFT, KEY_HOME },
+ { KEY_RIGHT, KEY_END },
+ { }
+};
+
+static const struct apple_key_translation macbookpro_dedicated_esc_fn_keys[] = {
+ { KEY_BACKSPACE, KEY_DELETE },
+ { KEY_ENTER, KEY_INSERT },
+ { KEY_1, KEY_F1 },
+ { KEY_2, KEY_F2 },
+ { KEY_3, KEY_F3 },
+ { KEY_4, KEY_F4 },
+ { KEY_5, KEY_F5 },
+ { KEY_6, KEY_F6 },
+ { KEY_7, KEY_F7 },
+ { KEY_8, KEY_F8 },
+ { KEY_9, KEY_F9 },
+ { KEY_0, KEY_F10 },
+ { KEY_MINUS, KEY_F11 },
+ { KEY_EQUAL, KEY_F12 },
+ { KEY_UP, KEY_PAGEUP },
+ { KEY_DOWN, KEY_PAGEDOWN },
+ { KEY_LEFT, KEY_HOME },
+ { KEY_RIGHT, KEY_END },
+ { }
+};
+
static const struct apple_key_translation apple_fn_keys[] = {
{ KEY_BACKSPACE, KEY_DELETE },
{ KEY_ENTER, KEY_INSERT },
@@ -269,6 +314,17 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
table = apple2021_fn_keys;
+ else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
+ hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
+ hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
+ table = macbookpro_no_esc_fn_keys;
+ else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
+ hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
+ hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
+ table = macbookpro_dedicated_esc_fn_keys;
+ else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
+ hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
+ table = apple_fn_keys;
else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
table = macbookair_fn_keys;
@@ -480,6 +536,12 @@ static void apple_setup_input(struct input_dev *input)
set_bit(KEY_NUMLOCK, input->keybit);

/* Enable all needed keys */
+ for (trans = macbookpro_no_esc_fn_keys; trans->from; trans++)
+ set_bit(trans->to, input->keybit);
+
+ for (trans = macbookpro_dedicated_esc_fn_keys; trans->from; trans++)
+ set_bit(trans->to, input->keybit);
+
for (trans = apple_fn_keys; trans->from; trans++)
set_bit(trans->to, input->keybit);

--
2.25.1


2022-02-16 16:43:12

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar

On Thu, 3 Feb 2022, Aditya Garg wrote:

> From: Aditya Garg <[email protected]>
>
> This patch adds the Fn mapping for keyboards on certain T2 Macs.
>
> Signed-off-by: Aditya Garg <[email protected]>
> ---
> v2 :- Use better approach to map fn keys
> v3 :- Use BIT(10) for APPLE_BACKLIGHT_CTL since 0x0200 (BIT (9)) has been used.
> drivers/hid/hid-apple.c | 62 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
>
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 658d79375..5448e5a66 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -142,6 +142,51 @@ static const struct apple_key_translation macbookair_fn_keys[] = {
> { }
> };
>
> +static const struct apple_key_translation macbookpro_no_esc_fn_keys[] = {
> + { KEY_BACKSPACE, KEY_DELETE },
> + { KEY_ENTER, KEY_INSERT },
> + { KEY_GRAVE, KEY_ESC },
> + { KEY_1, KEY_F1 },
> + { KEY_2, KEY_F2 },
> + { KEY_3, KEY_F3 },
> + { KEY_4, KEY_F4 },
> + { KEY_5, KEY_F5 },
> + { KEY_6, KEY_F6 },
> + { KEY_7, KEY_F7 },
> + { KEY_8, KEY_F8 },
> + { KEY_9, KEY_F9 },
> + { KEY_0, KEY_F10 },
> + { KEY_MINUS, KEY_F11 },
> + { KEY_EQUAL, KEY_F12 },
> + { KEY_UP, KEY_PAGEUP },
> + { KEY_DOWN, KEY_PAGEDOWN },
> + { KEY_LEFT, KEY_HOME },
> + { KEY_RIGHT, KEY_END },
> + { }
> +};
> +
> +static const struct apple_key_translation macbookpro_dedicated_esc_fn_keys[] = {
> + { KEY_BACKSPACE, KEY_DELETE },
> + { KEY_ENTER, KEY_INSERT },
> + { KEY_1, KEY_F1 },
> + { KEY_2, KEY_F2 },
> + { KEY_3, KEY_F3 },
> + { KEY_4, KEY_F4 },
> + { KEY_5, KEY_F5 },
> + { KEY_6, KEY_F6 },
> + { KEY_7, KEY_F7 },
> + { KEY_8, KEY_F8 },
> + { KEY_9, KEY_F9 },
> + { KEY_0, KEY_F10 },
> + { KEY_MINUS, KEY_F11 },
> + { KEY_EQUAL, KEY_F12 },
> + { KEY_UP, KEY_PAGEUP },
> + { KEY_DOWN, KEY_PAGEDOWN },
> + { KEY_LEFT, KEY_HOME },
> + { KEY_RIGHT, KEY_END },
> + { }
> +};
> +
> static const struct apple_key_translation apple_fn_keys[] = {
> { KEY_BACKSPACE, KEY_DELETE },
> { KEY_ENTER, KEY_INSERT },
> @@ -269,6 +314,17 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
> hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
> hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
> table = apple2021_fn_keys;
> + else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
> + hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
> + hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
> + table = macbookpro_no_esc_fn_keys;
> + else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
> + hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
> + hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
> + table = macbookpro_dedicated_esc_fn_keys;
> + else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
> + hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
> + table = apple_fn_keys;
> else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
> hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
> table = macbookair_fn_keys;
> @@ -480,6 +536,12 @@ static void apple_setup_input(struct input_dev *input)
> set_bit(KEY_NUMLOCK, input->keybit);
>
> /* Enable all needed keys */
> + for (trans = macbookpro_no_esc_fn_keys; trans->from; trans++)
> + set_bit(trans->to, input->keybit);
> +
> + for (trans = macbookpro_dedicated_esc_fn_keys; trans->from; trans++)
> + set_bit(trans->to, input->keybit);
> +

This needed to be rebased on top of earlier Jos?'s refactoring of the
mapping setup patches; I've done that and pushed the whole series to
for-5.18/apple

Thanks,

--
Jiri Kosina
SUSE Labs