linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
@ 2022-01-24 15:08 Aditya Garg
  2022-01-24 15:09 ` [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Aditya Garg @ 2022-01-24 15:08 UTC (permalink / raw)
  To: jkosina, jikos, alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Paul Pawlowski <paul@mrarm.io>

This patch introduces the requisite plumbing for supporting keyboard
backlight on T2-attached, USB exposed models. The quirk mechanism was
used to reuse the existing hid-apple driver.

Signed-off-by: Paul Pawlowski <paul@mrarm.io>
Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 drivers/hid/hid-apple.c | 125 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 24802a4a6..c22d445a9 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -7,6 +7,7 @@
  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  *  Copyright (c) 2006-2007 Jiri Kosina
  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
+ *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
  */
 
 /*
@@ -33,6 +34,7 @@
 /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
 #define APPLE_NUMLOCK_EMULATION	BIT(8)
 #define APPLE_RDESC_BATTERY	BIT(9)
+#define APPLE_BACKLIGHT_CTL	0x0200
 
 #define APPLE_FLAG_FKEY		0x01
 
@@ -61,6 +63,12 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
 		"(For people who want to keep PC keyboard muscle memory. "
 		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
 
+struct apple_sc_backlight {
+	struct led_classdev cdev;
+	struct hid_device *hdev;
+	unsigned short backlight_off, backlight_on_min, backlight_on_max;
+};
+
 struct apple_sc {
 	struct hid_device *hdev;
 	unsigned long quirks;
@@ -68,6 +76,7 @@ struct apple_sc {
 	unsigned int fn_found;
 	DECLARE_BITMAP(pressed_numlock, KEY_CNT);
 	struct timer_list battery_timer;
+	struct apple_sc_backlight *backlight;
 };
 
 struct apple_key_translation {
@@ -76,6 +85,20 @@ struct apple_key_translation {
 	u8 flags;
 };
 
+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 },
@@ -530,6 +553,105 @@ static int apple_input_configured(struct hid_device *hdev,
 	return 0;
 }
 
+static bool apple_backlight_check_support(struct hid_device *hdev)
+{
+	int i;
+	unsigned int hid;
+	struct hid_report *report;
+
+	list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
+		for (i = 0; i < report->maxfield; i++) {
+			hid = report->field[i]->usage->hid;
+			if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
+				return true;
+		}
+	}
+
+	return false;
+}
+
+static int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
+{
+	int ret = 0;
+	struct apple_backlight_set_report *rep;
+
+	rep = kmalloc(sizeof(*rep), GFP_KERNEL);
+	if (rep == NULL)
+		return -ENOMEM;
+
+	rep->report_id = 0xB0;
+	rep->version = 1;
+	rep->backlight = value;
+	rep->rate = rate;
+
+	ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
+				 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
+
+	kfree(rep);
+	return ret;
+}
+
+static int apple_backlight_led_set(struct led_classdev *led_cdev,
+	enum led_brightness brightness)
+{
+	struct apple_sc_backlight *backlight = container_of(led_cdev,
+							    struct apple_sc_backlight, cdev);
+
+	return apple_backlight_set(backlight->hdev, brightness, 0);
+}
+
+static int apple_backlight_init(struct hid_device *hdev)
+{
+	int ret;
+	struct apple_sc *asc = hid_get_drvdata(hdev);
+	struct apple_backlight_config_report *rep;
+
+	if (!apple_backlight_check_support(hdev))
+		return -EINVAL;
+
+	rep = kmalloc(0x200, GFP_KERNEL);
+	if (rep == NULL)
+		return -ENOMEM;
+
+	ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
+				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+	if (ret < 0) {
+		hid_err(hdev, "backlight request failed: %d\n", ret);
+		goto cleanup_and_exit;
+	}
+	if (ret < 8 || rep->version != 1) {
+		hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
+		ret = -EINVAL;
+		goto cleanup_and_exit;
+	}
+
+	hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
+		rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
+
+	asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
+	if (!asc->backlight) {
+		ret = -ENOMEM;
+		goto cleanup_and_exit;
+	}
+
+	asc->backlight->hdev = hdev;
+	asc->backlight->cdev.name = "apple::kbd_backlight";
+	asc->backlight->cdev.max_brightness = rep->backlight_on_max;
+	asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
+
+	ret = apple_backlight_set(hdev, 0, 0);
+	if (ret < 0) {
+		hid_err(hdev, "backlight set request failed: %d\n", ret);
+		goto cleanup_and_exit;
+	}
+
+	ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
+
+cleanup_and_exit:
+	kfree(rep);
+	return ret;
+}
+
 static int apple_probe(struct hid_device *hdev,
 		const struct hid_device_id *id)
 {
@@ -565,6 +687,9 @@ static int apple_probe(struct hid_device *hdev,
 		  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
 	apple_fetch_battery(hdev);
 
+	if (quirks & APPLE_BACKLIGHT_CTL)
+		apple_backlight_init(hdev);
+
 	return 0;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for T2 Macs.
  2022-01-24 15:08 [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
@ 2022-01-24 15:09 ` Aditya Garg
  2022-01-24 15:10   ` [PATCH v2 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar Aditya Garg
  2022-01-31 12:05 ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
  2022-02-03 12:15 ` Aditya Garg
  2 siblings, 1 reply; 12+ messages in thread
From: Aditya Garg @ 2022-01-24 15:09 UTC (permalink / raw)
  To: jkosina, jikos, alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Aun-Ali Zaidi <admin@kodeit.net>

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

Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 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



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar
  2022-01-24 15:09 ` [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
@ 2022-01-24 15:10   ` Aditya Garg
  0 siblings, 0 replies; 12+ messages in thread
From: Aditya Garg @ 2022-01-24 15:10 UTC (permalink / raw)
  To: jkosina, jikos, alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Aditya Garg <gargaditya08@live.com>

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

Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 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



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-01-24 15:08 [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
  2022-01-24 15:09 ` [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
@ 2022-01-31 12:05 ` Aditya Garg
  2022-02-02 13:40   ` Jiri Kosina
  2022-02-03 12:15 ` Aditya Garg
  2 siblings, 1 reply; 12+ messages in thread
From: Aditya Garg @ 2022-01-31 12:05 UTC (permalink / raw)
  To: jkosina, jikos, alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain, Linus Torvalds, Greg KH

Hi

It has been a week since I have sent this series of patches, but I haven't got a reply yet. Before that, I had sent a v1 of the same, on which I wasn't contacted as well. May I have an update on this series. No reply for a long time is something which doesn't sound good.

Regards
Aditya

> On 24-Jan-2022, at 8:38 PM, Aditya Garg <gargaditya08@live.com> wrote:
> 
> From: Paul Pawlowski <paul@mrarm.io>
> 
> This patch introduces the requisite plumbing for supporting keyboard
> backlight on T2-attached, USB exposed models. The quirk mechanism was
> used to reuse the existing hid-apple driver.
> 
> Signed-off-by: Paul Pawlowski <paul@mrarm.io>
> Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
> drivers/hid/hid-apple.c | 125 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 125 insertions(+)
> 
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 24802a4a6..c22d445a9 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -7,6 +7,7 @@
>  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
>  *  Copyright (c) 2006-2007 Jiri Kosina
>  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
> + *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
>  */
> 
> /*
> @@ -33,6 +34,7 @@
> /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
> #define APPLE_NUMLOCK_EMULATION	BIT(8)
> #define APPLE_RDESC_BATTERY	BIT(9)
> +#define APPLE_BACKLIGHT_CTL	0x0200
> 
> #define APPLE_FLAG_FKEY		0x01
> 
> @@ -61,6 +63,12 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
> 		"(For people who want to keep PC keyboard muscle memory. "
> 		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
> 
> +struct apple_sc_backlight {
> +	struct led_classdev cdev;
> +	struct hid_device *hdev;
> +	unsigned short backlight_off, backlight_on_min, backlight_on_max;
> +};
> +
> struct apple_sc {
> 	struct hid_device *hdev;
> 	unsigned long quirks;
> @@ -68,6 +76,7 @@ struct apple_sc {
> 	unsigned int fn_found;
> 	DECLARE_BITMAP(pressed_numlock, KEY_CNT);
> 	struct timer_list battery_timer;
> +	struct apple_sc_backlight *backlight;
> };
> 
> struct apple_key_translation {
> @@ -76,6 +85,20 @@ struct apple_key_translation {
> 	u8 flags;
> };
> 
> +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 },
> @@ -530,6 +553,105 @@ static int apple_input_configured(struct hid_device *hdev,
> 	return 0;
> }
> 
> +static bool apple_backlight_check_support(struct hid_device *hdev)
> +{
> +	int i;
> +	unsigned int hid;
> +	struct hid_report *report;
> +
> +	list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
> +		for (i = 0; i < report->maxfield; i++) {
> +			hid = report->field[i]->usage->hid;
> +			if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
> +				return true;
> +		}
> +	}
> +
> +	return false;
> +}
> +
> +static int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
> +{
> +	int ret = 0;
> +	struct apple_backlight_set_report *rep;
> +
> +	rep = kmalloc(sizeof(*rep), GFP_KERNEL);
> +	if (rep == NULL)
> +		return -ENOMEM;
> +
> +	rep->report_id = 0xB0;
> +	rep->version = 1;
> +	rep->backlight = value;
> +	rep->rate = rate;
> +
> +	ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
> +				 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
> +
> +	kfree(rep);
> +	return ret;
> +}
> +
> +static int apple_backlight_led_set(struct led_classdev *led_cdev,
> +	enum led_brightness brightness)
> +{
> +	struct apple_sc_backlight *backlight = container_of(led_cdev,
> +							    struct apple_sc_backlight, cdev);
> +
> +	return apple_backlight_set(backlight->hdev, brightness, 0);
> +}
> +
> +static int apple_backlight_init(struct hid_device *hdev)
> +{
> +	int ret;
> +	struct apple_sc *asc = hid_get_drvdata(hdev);
> +	struct apple_backlight_config_report *rep;
> +
> +	if (!apple_backlight_check_support(hdev))
> +		return -EINVAL;
> +
> +	rep = kmalloc(0x200, GFP_KERNEL);
> +	if (rep == NULL)
> +		return -ENOMEM;
> +
> +	ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
> +				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
> +	if (ret < 0) {
> +		hid_err(hdev, "backlight request failed: %d\n", ret);
> +		goto cleanup_and_exit;
> +	}
> +	if (ret < 8 || rep->version != 1) {
> +		hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
> +		ret = -EINVAL;
> +		goto cleanup_and_exit;
> +	}
> +
> +	hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
> +		rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
> +
> +	asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
> +	if (!asc->backlight) {
> +		ret = -ENOMEM;
> +		goto cleanup_and_exit;
> +	}
> +
> +	asc->backlight->hdev = hdev;
> +	asc->backlight->cdev.name = "apple::kbd_backlight";
> +	asc->backlight->cdev.max_brightness = rep->backlight_on_max;
> +	asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
> +
> +	ret = apple_backlight_set(hdev, 0, 0);
> +	if (ret < 0) {
> +		hid_err(hdev, "backlight set request failed: %d\n", ret);
> +		goto cleanup_and_exit;
> +	}
> +
> +	ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
> +
> +cleanup_and_exit:
> +	kfree(rep);
> +	return ret;
> +}
> +
> static int apple_probe(struct hid_device *hdev,
> 		const struct hid_device_id *id)
> {
> @@ -565,6 +687,9 @@ static int apple_probe(struct hid_device *hdev,
> 		  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
> 	apple_fetch_battery(hdev);
> 
> +	if (quirks & APPLE_BACKLIGHT_CTL)
> +		apple_backlight_init(hdev);
> +
> 	return 0;
> }
> 
> -- 
> 2.25.1
> 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-01-31 12:05 ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
@ 2022-02-02 13:40   ` Jiri Kosina
  2022-02-02 14:18     ` Aditya Garg
  0 siblings, 1 reply; 12+ messages in thread
From: Jiri Kosina @ 2022-02-02 13:40 UTC (permalink / raw)
  To: Aditya Garg
  Cc: alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List, paul, Aun-Ali Zaidi,
	Orlando Chamberlain, Linus Torvalds, Greg KH

On Mon, 31 Jan 2022, Aditya Garg wrote:

> It has been a week since I have sent this series of patches, but I 
> haven't got a reply yet. Before that, I had sent a v1 of the same, on 
> which I wasn't contacted as well. May I have an update on this series. 
> No reply for a long time is something which doesn't sound good.

A week during merge window and -rc1 phase is not that horrible, please be 
a little bit more patient.

The patchset hasn't been lost, it's on my radar and I'll process it this 
week still.

Thanks,

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-02-02 13:40   ` Jiri Kosina
@ 2022-02-02 14:18     ` Aditya Garg
  0 siblings, 0 replies; 12+ messages in thread
From: Aditya Garg @ 2022-02-02 14:18 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List, paul, Aun-Ali Zaidi,
	Orlando Chamberlain, Linus Torvalds, Greg KH



> On 02-Feb-2022, at 7:10 PM, Jiri Kosina <jikos@kernel.org> wrote:
> 
> On Mon, 31 Jan 2022, Aditya Garg wrote:
> 
>> It has been a week since I have sent this series of patches, but I 
>> haven't got a reply yet. Before that, I had sent a v1 of the same, on 
>> which I wasn't contacted as well. May I have an update on this series. 
>> No reply for a long time is something which doesn't sound good.
> 
> A week during merge window and -rc1 phase is not that horrible, please be 
> a little bit more patient.
> 
Sorry for being impatient :)
> The patchset hasn't been lost, it's on my radar and I'll process it this 
> week still.
Thanks
> 
> Thanks,
> 
> -- 
> Jiri Kosina
> SUSE Labs
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-01-24 15:08 [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
  2022-01-24 15:09 ` [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
  2022-01-31 12:05 ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
@ 2022-02-03 12:15 ` Aditya Garg
  2022-02-03 12:21   ` [PATCH v3 " Aditya Garg
  2022-02-14  9:55   ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Jiri Kosina
  2 siblings, 2 replies; 12+ messages in thread
From: Aditya Garg @ 2022-02-03 12:15 UTC (permalink / raw)
  To: jkosina, Jiri Kosina, alexhenrie24, benjamin.tissoires,
	linux-input, Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain



> On 24-Jan-2022, at 8:38 PM, Aditya Garg <gargaditya08@live.com> wrote:
> 
> From: Paul Pawlowski <paul@mrarm.io>
> 
> This patch introduces the requisite plumbing for supporting keyboard
> backlight on T2-attached, USB exposed models. The quirk mechanism was
> used to reuse the existing hid-apple driver.
> 
> Signed-off-by: Paul Pawlowski <paul@mrarm.io>
> Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
> drivers/hid/hid-apple.c | 125 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 125 insertions(+)
> 
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 24802a4a6..c22d445a9 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -7,6 +7,7 @@
>  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
>  *  Copyright (c) 2006-2007 Jiri Kosina
>  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
> + *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
>  */
> 
> /*
> @@ -33,6 +34,7 @@
> /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
> #define APPLE_NUMLOCK_EMULATION	BIT(8)
> #define APPLE_RDESC_BATTERY	BIT(9)
> +#define APPLE_BACKLIGHT_CTL	0x0200
Jiri, should it be BIT(10)? 0x0200 is BIT(9) if I ain’t wrong.
> 
> #define APPLE_FLAG_FKEY		0x01
> 
> @@ -61,6 +63,12 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
> 		"(For people who want to keep PC keyboard muscle memory. "
> 		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
> 
> +struct apple_sc_backlight {
> +	struct led_classdev cdev;
> +	struct hid_device *hdev;
> +	unsigned short backlight_off, backlight_on_min, backlight_on_max;
> +};
> +
> struct apple_sc {
> 	struct hid_device *hdev;
> 	unsigned long quirks;
> @@ -68,6 +76,7 @@ struct apple_sc {
> 	unsigned int fn_found;
> 	DECLARE_BITMAP(pressed_numlock, KEY_CNT);
> 	struct timer_list battery_timer;
> +	struct apple_sc_backlight *backlight;
> };
> 
> struct apple_key_translation {
> @@ -76,6 +85,20 @@ struct apple_key_translation {
> 	u8 flags;
> };
> 
> +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 },
> @@ -530,6 +553,105 @@ static int apple_input_configured(struct hid_device *hdev,
> 	return 0;
> }
> 
> +static bool apple_backlight_check_support(struct hid_device *hdev)
> +{
> +	int i;
> +	unsigned int hid;
> +	struct hid_report *report;
> +
> +	list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
> +		for (i = 0; i < report->maxfield; i++) {
> +			hid = report->field[i]->usage->hid;
> +			if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
> +				return true;
> +		}
> +	}
> +
> +	return false;
> +}
> +
> +static int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
> +{
> +	int ret = 0;
> +	struct apple_backlight_set_report *rep;
> +
> +	rep = kmalloc(sizeof(*rep), GFP_KERNEL);
> +	if (rep == NULL)
> +		return -ENOMEM;
> +
> +	rep->report_id = 0xB0;
> +	rep->version = 1;
> +	rep->backlight = value;
> +	rep->rate = rate;
> +
> +	ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
> +				 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
> +
> +	kfree(rep);
> +	return ret;
> +}
> +
> +static int apple_backlight_led_set(struct led_classdev *led_cdev,
> +	enum led_brightness brightness)
> +{
> +	struct apple_sc_backlight *backlight = container_of(led_cdev,
> +							    struct apple_sc_backlight, cdev);
> +
> +	return apple_backlight_set(backlight->hdev, brightness, 0);
> +}
> +
> +static int apple_backlight_init(struct hid_device *hdev)
> +{
> +	int ret;
> +	struct apple_sc *asc = hid_get_drvdata(hdev);
> +	struct apple_backlight_config_report *rep;
> +
> +	if (!apple_backlight_check_support(hdev))
> +		return -EINVAL;
> +
> +	rep = kmalloc(0x200, GFP_KERNEL);
> +	if (rep == NULL)
> +		return -ENOMEM;
> +
> +	ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
> +				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
> +	if (ret < 0) {
> +		hid_err(hdev, "backlight request failed: %d\n", ret);
> +		goto cleanup_and_exit;
> +	}
> +	if (ret < 8 || rep->version != 1) {
> +		hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
> +		ret = -EINVAL;
> +		goto cleanup_and_exit;
> +	}
> +
> +	hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
> +		rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
> +
> +	asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
> +	if (!asc->backlight) {
> +		ret = -ENOMEM;
> +		goto cleanup_and_exit;
> +	}
> +
> +	asc->backlight->hdev = hdev;
> +	asc->backlight->cdev.name = "apple::kbd_backlight";
> +	asc->backlight->cdev.max_brightness = rep->backlight_on_max;
> +	asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
> +
> +	ret = apple_backlight_set(hdev, 0, 0);
> +	if (ret < 0) {
> +		hid_err(hdev, "backlight set request failed: %d\n", ret);
> +		goto cleanup_and_exit;
> +	}
> +
> +	ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
> +
> +cleanup_and_exit:
> +	kfree(rep);
> +	return ret;
> +}
> +
> static int apple_probe(struct hid_device *hdev,
> 		const struct hid_device_id *id)
> {
> @@ -565,6 +687,9 @@ static int apple_probe(struct hid_device *hdev,
> 		  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
> 	apple_fetch_battery(hdev);
> 
> +	if (quirks & APPLE_BACKLIGHT_CTL)
> +		apple_backlight_init(hdev);
> +
> 	return 0;
> }
> 
> -- 
> 2.25.1
> 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-02-03 12:15 ` Aditya Garg
@ 2022-02-03 12:21   ` Aditya Garg
  2022-02-03 12:22     ` [PATCH v3 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
  2022-02-14  9:55   ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Jiri Kosina
  1 sibling, 1 reply; 12+ messages in thread
From: Aditya Garg @ 2022-02-03 12:21 UTC (permalink / raw)
  To: jkosina, Jiri Kosina, alexhenrie24, benjamin.tissoires,
	linux-input, Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Paul Pawlowski <paul@mrarm.io>

This patch introduces the requisite plumbing for supporting keyboard
backlight on T2-attached, USB exposed models. The quirk mechanism was
used to reuse the existing hid-apple driver.

Signed-off-by: Paul Pawlowski <paul@mrarm.io>
Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
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 | 125 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 24802a4a6..c22d445a9 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -7,6 +7,7 @@
  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  *  Copyright (c) 2006-2007 Jiri Kosina
  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
+ *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
  */
 
 /*
@@ -33,6 +34,7 @@
 /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
 #define APPLE_NUMLOCK_EMULATION	BIT(8)
 #define APPLE_RDESC_BATTERY	BIT(9)
+#define APPLE_BACKLIGHT_CTL	BIT(10)
 
 #define APPLE_FLAG_FKEY		0x01
 
@@ -61,6 +63,12 @@ MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
 		"(For people who want to keep PC keyboard muscle memory. "
 		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
 
+struct apple_sc_backlight {
+	struct led_classdev cdev;
+	struct hid_device *hdev;
+	unsigned short backlight_off, backlight_on_min, backlight_on_max;
+};
+
 struct apple_sc {
 	struct hid_device *hdev;
 	unsigned long quirks;
@@ -68,6 +76,7 @@ struct apple_sc {
 	unsigned int fn_found;
 	DECLARE_BITMAP(pressed_numlock, KEY_CNT);
 	struct timer_list battery_timer;
+	struct apple_sc_backlight *backlight;
 };
 
 struct apple_key_translation {
@@ -76,6 +85,20 @@ struct apple_key_translation {
 	u8 flags;
 };
 
+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 },
@@ -530,6 +553,105 @@ static int apple_input_configured(struct hid_device *hdev,
 	return 0;
 }
 
+static bool apple_backlight_check_support(struct hid_device *hdev)
+{
+	int i;
+	unsigned int hid;
+	struct hid_report *report;
+
+	list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
+		for (i = 0; i < report->maxfield; i++) {
+			hid = report->field[i]->usage->hid;
+			if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
+				return true;
+		}
+	}
+
+	return false;
+}
+
+static int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
+{
+	int ret = 0;
+	struct apple_backlight_set_report *rep;
+
+	rep = kmalloc(sizeof(*rep), GFP_KERNEL);
+	if (rep == NULL)
+		return -ENOMEM;
+
+	rep->report_id = 0xB0;
+	rep->version = 1;
+	rep->backlight = value;
+	rep->rate = rate;
+
+	ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
+				 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
+
+	kfree(rep);
+	return ret;
+}
+
+static int apple_backlight_led_set(struct led_classdev *led_cdev,
+	enum led_brightness brightness)
+{
+	struct apple_sc_backlight *backlight = container_of(led_cdev,
+							    struct apple_sc_backlight, cdev);
+
+	return apple_backlight_set(backlight->hdev, brightness, 0);
+}
+
+static int apple_backlight_init(struct hid_device *hdev)
+{
+	int ret;
+	struct apple_sc *asc = hid_get_drvdata(hdev);
+	struct apple_backlight_config_report *rep;
+
+	if (!apple_backlight_check_support(hdev))
+		return -EINVAL;
+
+	rep = kmalloc(0x200, GFP_KERNEL);
+	if (rep == NULL)
+		return -ENOMEM;
+
+	ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
+				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+	if (ret < 0) {
+		hid_err(hdev, "backlight request failed: %d\n", ret);
+		goto cleanup_and_exit;
+	}
+	if (ret < 8 || rep->version != 1) {
+		hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
+		ret = -EINVAL;
+		goto cleanup_and_exit;
+	}
+
+	hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
+		rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
+
+	asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
+	if (!asc->backlight) {
+		ret = -ENOMEM;
+		goto cleanup_and_exit;
+	}
+
+	asc->backlight->hdev = hdev;
+	asc->backlight->cdev.name = "apple::kbd_backlight";
+	asc->backlight->cdev.max_brightness = rep->backlight_on_max;
+	asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
+
+	ret = apple_backlight_set(hdev, 0, 0);
+	if (ret < 0) {
+		hid_err(hdev, "backlight set request failed: %d\n", ret);
+		goto cleanup_and_exit;
+	}
+
+	ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
+
+cleanup_and_exit:
+	kfree(rep);
+	return ret;
+}
+
 static int apple_probe(struct hid_device *hdev,
 		const struct hid_device_id *id)
 {
@@ -565,6 +687,9 @@ static int apple_probe(struct hid_device *hdev,
 		  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
 	apple_fetch_battery(hdev);
 
+	if (quirks & APPLE_BACKLIGHT_CTL)
+		apple_backlight_init(hdev);
+
 	return 0;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/3] HID: apple: Add necessary IDs and configuration for T2 Macs.
  2022-02-03 12:21   ` [PATCH v3 " Aditya Garg
@ 2022-02-03 12:22     ` Aditya Garg
  2022-02-03 12:23       ` [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar Aditya Garg
  0 siblings, 1 reply; 12+ messages in thread
From: Aditya Garg @ 2022-02-03 12:22 UTC (permalink / raw)
  To: jkosina, Jiri Kosina, alexhenrie24, benjamin.tissoires,
	linux-input, Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Aun-Ali Zaidi <admin@kodeit.net>

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

Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
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



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar
  2022-02-03 12:22     ` [PATCH v3 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
@ 2022-02-03 12:23       ` Aditya Garg
  2022-02-16 15:57         ` Jiri Kosina
  0 siblings, 1 reply; 12+ messages in thread
From: Aditya Garg @ 2022-02-03 12:23 UTC (permalink / raw)
  To: jkosina, Jiri Kosina, alexhenrie24, benjamin.tissoires,
	linux-input, Linux Kernel Mailing List
  Cc: paul, Aun-Ali Zaidi, Orlando Chamberlain

From: Aditya Garg <gargaditya08@live.com>

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

Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
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



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs.
  2022-02-03 12:15 ` Aditya Garg
  2022-02-03 12:21   ` [PATCH v3 " Aditya Garg
@ 2022-02-14  9:55   ` Jiri Kosina
  1 sibling, 0 replies; 12+ messages in thread
From: Jiri Kosina @ 2022-02-14  9:55 UTC (permalink / raw)
  To: Aditya Garg
  Cc: alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List, paul, Aun-Ali Zaidi,
	Orlando Chamberlain

On Thu, 3 Feb 2022, Aditya Garg wrote:

> 
> 
> > On 24-Jan-2022, at 8:38 PM, Aditya Garg <gargaditya08@live.com> wrote:
> > 
> > From: Paul Pawlowski <paul@mrarm.io>
> > 
> > This patch introduces the requisite plumbing for supporting keyboard
> > backlight on T2-attached, USB exposed models. The quirk mechanism was
> > used to reuse the existing hid-apple driver.
> > 
> > Signed-off-by: Paul Pawlowski <paul@mrarm.io>
> > Signed-off-by: Aun-Ali Zaidi <admin@kodeit.net>
> > Signed-off-by: Aditya Garg <gargaditya08@live.com>
> > ---
> > drivers/hid/hid-apple.c | 125 ++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 125 insertions(+)
> > 
> > diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> > index 24802a4a6..c22d445a9 100644
> > --- a/drivers/hid/hid-apple.c
> > +++ b/drivers/hid/hid-apple.c
> > @@ -7,6 +7,7 @@
> >  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
> >  *  Copyright (c) 2006-2007 Jiri Kosina
> >  *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
> > + *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
> >  */
> > 
> > /*
> > @@ -33,6 +34,7 @@
> > /* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
> > #define APPLE_NUMLOCK_EMULATION	BIT(8)
> > #define APPLE_RDESC_BATTERY	BIT(9)
> > +#define APPLE_BACKLIGHT_CTL	0x0200
> Jiri, should it be BIT(10)? 0x0200 is BIT(9) if I ain’t wrong.

Yes, please use BIT(10). Thanks,

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar
  2022-02-03 12:23       ` [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar Aditya Garg
@ 2022-02-16 15:57         ` Jiri Kosina
  0 siblings, 0 replies; 12+ messages in thread
From: Jiri Kosina @ 2022-02-16 15:57 UTC (permalink / raw)
  To: Aditya Garg
  Cc: alexhenrie24, benjamin.tissoires, linux-input,
	Linux Kernel Mailing List, paul, Aun-Ali Zaidi,
	Orlando Chamberlain

On Thu, 3 Feb 2022, Aditya Garg wrote:

> From: Aditya Garg <gargaditya08@live.com>
> 
> This patch adds the Fn mapping for keyboards on certain T2 Macs.
> 
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
> 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-02-16 15:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 15:08 [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
2022-01-24 15:09 ` [PATCH v2 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
2022-01-24 15:10   ` [PATCH v2 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar Aditya Garg
2022-01-31 12:05 ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Aditya Garg
2022-02-02 13:40   ` Jiri Kosina
2022-02-02 14:18     ` Aditya Garg
2022-02-03 12:15 ` Aditya Garg
2022-02-03 12:21   ` [PATCH v3 " Aditya Garg
2022-02-03 12:22     ` [PATCH v3 2/3] HID: apple: Add necessary IDs and configuration for " Aditya Garg
2022-02-03 12:23       ` [PATCH v3 3/3] HID: apple: Add fn mapping for MacBook Pros with Touch Bar Aditya Garg
2022-02-16 15:57         ` Jiri Kosina
2022-02-14  9:55   ` [PATCH v2 1/3] HID: apple: Add support for keyboard backlight on certain T2 Macs Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).