Skip to contentSkip to conversation

HID: lenovo: Add support for ThinkPad X13 Folio keyboard

PATCH In review Vishnu Sankar [email protected] 4 participants 6 messages May 22 – Jun 10

Subsystems (2)
lore
Share & tools
lore

Vishnu Sankar [email protected]

author
#0 lore raw

PATCH 1/2 HID: lenovo: Add support for ThinkPad X13 Folio keyboard

From: Vishnu Sankar <[email protected]>

Add USB ID support for the ThinkPad X13 detachable keyboard. The Keyboard uses the same HID raw event protocol as the ThinkPad X12 Gen 2. The functionality stays the same with X12 Gen 2 Keyboards.

Also declare KEY_PERFORMANCE capability in lenovo_input_configured() for X13 detachable, allowing userspace to discover the key via evdev capability bits.

---
 drivers/hid/hid-ids.h    |  1 +
 drivers/hid/hid-lenovo.c | 21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
drivers/hid/hid-ids.h +1 -0
index 4657d96fb083..064be2333a00 100644
@@ -874,6 +874,7 @@
 #define USB_DEVICE_ID_LENOVO_X1_TAB3	0x60b5
 #define USB_DEVICE_ID_LENOVO_X12_TAB	0x60fe
 #define USB_DEVICE_ID_LENOVO_X12_TAB2	0x61ae
+#define USB_DEVICE_ID_LENOVO_X13_TAB	0x62af
 #define USB_DEVICE_ID_LENOVO_YOGABOOK9I	0x6161
 #define USB_DEVICE_ID_LENOVO_OPTICAL_USB_MOUSE_600E	0x600e
 #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D	0x608d
drivers/hid/hid-lenovo.c +17 -4
index a6b73e03c16b..35b00619f045 100644
@@ -504,6 +504,7 @@ static int lenovo_input_mapping(struct hid_device *hdev,
 							       usage, bit, max);
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
 	case USB_DEVICE_ID_LENOVO_X1_TAB3:
@@ -620,6 +621,7 @@ static ssize_t attr_fn_lock_store(struct device *dev,
 		break;
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_TP10UBKBD:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -791,9 +793,10 @@ static int lenovo_raw_event(struct hid_device *hdev,
 	 * Lenovo TP X12 Tab KBD's Fn+XX is HID raw data defined. Report ID is 0x03
 	 * e.g.: Raw data received for MIC mute is 0x00020003.
 	 */
-	if (unlikely((hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB
-			|| hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2)
-			&& size >= 3 && report->id == 0x03))
+	if (unlikely((hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB ||
+		      hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2 ||
+		      hdev->product == USB_DEVICE_ID_LENOVO_X13_TAB) &&
+		      size >= 3 && report->id == 0x03))
 		return lenovo_raw_event_TP_X12_tab(hdev, le32_to_cpu(*(__le32 *)data));
 
 	return 0;
@@ -877,6 +880,7 @@ static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
 		return lenovo_event_cptkbd(hdev, field, usage, value);
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_TP10UBKBD:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1161,6 +1165,7 @@ static int lenovo_led_brightness_set(struct led_classdev *led_cdev,
 		break;
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_TP10UBKBD:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1355,7 +1360,8 @@ static int lenovo_probe_tp10ubkbd(struct hid_device *hdev)
 	 */
 
 	data->fn_lock = !(hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB ||
-			hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2);
+			hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2 ||
+			hdev->product == USB_DEVICE_ID_LENOVO_X13_TAB);
 
 	lenovo_led_set_tp10ubkbd(hdev, TP10UBKBD_FN_LOCK_LED, data->fn_lock);
 
@@ -1402,6 +1408,7 @@ static int lenovo_probe(struct hid_device *hdev,
 		break;
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_TP10UBKBD:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1490,6 +1497,7 @@ static void lenovo_remove(struct hid_device *hdev)
 		break;
 	case USB_DEVICE_ID_LENOVO_X12_TAB:
 	case USB_DEVICE_ID_LENOVO_X12_TAB2:
+	case USB_DEVICE_ID_LENOVO_X13_TAB:
 	case USB_DEVICE_ID_LENOVO_TP10UBKBD:
 	case USB_DEVICE_ID_LENOVO_X1_TAB:
 	case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1517,6 +1525,9 @@ static int lenovo_input_configured(struct hid_device *hdev,
 						hi->input->propbit);
 			}
 			break;
+		case USB_DEVICE_ID_LENOVO_X13_TAB:
+			input_set_capability(hi->input, EV_KEY, KEY_PERFORMANCE);
+			break;
 	}
 
 	return 0;
@@ -1551,6 +1562,8 @@ static const struct hid_device_id lenovo_devices[] = {
 		     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X12_TAB) },
 	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
 		     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X12_TAB2) },
+	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
+		     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X13_TAB) },
 	{ HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
 		     USB_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X_KEYBOARD) },
 	{ }
Signature · 1 line
2.54.0
author
#1 lore raw

PATCH 2/2 HID: lenovo: Use KEY_PERFORMANCE capability for ThinkPad X12 Tab Gen 2

From: Vishnu Sankar <[email protected]>

The X12 Tab Gen 2 emits KEY_PERFORMANCE via Fn+F8 through the raw event handler but never declared the capability via input_set_capability(). This prevents userspace tools from discovering the key through evdev capability bits.

---
 drivers/hid/hid-lenovo.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-lenovo.c +1 -0
index 35b00619f045..3492ba8d0fb0 100644
@@ -1525,6 +1525,7 @@ static int lenovo_input_configured(struct hid_device *hdev,
 						hi->input->propbit);
 			}
 			break;
+		case USB_DEVICE_ID_LENOVO_X12_TAB2:
 		case USB_DEVICE_ID_LENOVO_X13_TAB:
 			input_set_capability(hi->input, EV_KEY, KEY_PERFORMANCE);
 			break;
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH 2/2] HID: lenovo: Use KEY_PERFORMANCE capability for ThinkPad X12 Tab Gen 2

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Low] The patch unconditionally adds the KEY_PERFORMANCE capability to all input nodes exposed by the device, causing capability pollution on unrelated interfaces.

Pre-existing issues:
- [High] The raw event handler emits keys like KEY_RFKILL, KEY_BOOKMARKS, and KEY_KBDILLUMTOGGLE, but their capabilities are never declared, causing the input subsystem to silently drop these events.
- [High] The raw event handler contains a loop that unconditionally fires key events on the first input node it encounters, ignoring capability routing and causing events to be dropped. --

commit 1b40b44e417a26a21650fec78e6a2ea55f535004
Author: Vishnu Sankar <[email protected]>

HID: lenovo: Use KEY_PERFORMANCE capability for ThinkPad X12 Tab Gen 2

This commit adds the KEY_PERFORMANCE capability for the ThinkPad X12 Tab Gen 2 and X13 Tab devices during input configuration. This allows userspace tools to discover the key emitted via the raw event handler.

drivers/hid/hid-lenovo.c static int lenovo_input_configured(struct hid_device *hdev, · line 1530

Quoted 11 lines
drivers/hid/hid-lenovo.c +1 -0
index 35b00619f0456..3492ba8d0fb02 100644
@@ -1525,6 +1525,7 @@ static int lenovo_input_configured(struct hid_device *hdev,
 						hi->input->propbit);
 			}
 			break;
+		case USB_DEVICE_ID_LENOVO_X12_TAB2:
 		case USB_DEVICE_ID_LENOVO_X13_TAB:
 			input_set_capability(hi->input, EV_KEY, KEY_PERFORMANCE);

[Severity: Low]
Does this unconditionally add the KEY_PERFORMANCE capability to all input nodes exposed by the device?

Since lenovo_input_configured() is invoked for every hid_input interface, this regression might advertise the capability on unrelated interfaces.

Could we filter this by checking the application usage or verifying it is the primary keyboard node?

[Severity: High]
This isn't a bug introduced by this patch, but I noticed the raw event handler also emits keys like KEY_RFKILL, KEY_PICKUP_PHONE, KEY_BOOKMARKS, and KEY_KBDILLUMTOGGLE.

Should we also declare the capabilities for these keys here?

Since they are generated from raw reports rather than standard HID descriptors, they appear to be missing from the capability bits, which would cause the input subsystem to silently drop these events.

[Severity: High]
This is a pre-existing issue, but looking at how the raw events are handled in lenovo_raw_event_TP_X12_tab(), is it possible the events are firing on the wrong input node?

The handler loops over hdev->inputs but returns immediately after reporting the key event on the first node it encounters. If the first device lacks the specific key capabilities, the input core might discard the event.

Should the loop instead locate the specific input node that possesses the corresponding key capability before dispatching?

Quoted 1 line
drivers/hid/hid-lenovo.c +0 -0
 			break;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw
In reply to Vishnu Sankar [email protected]

Hi Jiri / Benjamin,

Gently pinging on this series.
Is there anything blocking acceptance or any changes needed from my side? The series has been tested on physical hardware.

Thank you!

Vishnu

Quoted 127 lines · Vishnu Sankar

From: Vishnu Sankar <[email protected]>

Add USB ID support for the ThinkPad X13 detachable keyboard. The Keyboard uses the same HID raw event protocol as the ThinkPad X12 Gen 2. The functionality stays the same with X12 Gen 2 Keyboards.

Also declare KEY_PERFORMANCE capability in lenovo_input_configured() for X13 detachable, allowing userspace to discover the key via evdev capability bits.

---
 drivers/hid/hid-ids.h    |  1 +
 drivers/hid/hid-lenovo.c | 21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
drivers/hid/hid-ids.h +1 -0
index 4657d96fb083..064be2333a00 100644
@@ -874,6 +874,7 @@
 #define USB_DEVICE_ID_LENOVO_X1_TAB3   0x60b5
 #define USB_DEVICE_ID_LENOVO_X12_TAB   0x60fe
 #define USB_DEVICE_ID_LENOVO_X12_TAB2  0x61ae
+#define USB_DEVICE_ID_LENOVO_X13_TAB   0x62af
 #define USB_DEVICE_ID_LENOVO_YOGABOOK9I        0x6161
 #define USB_DEVICE_ID_LENOVO_OPTICAL_USB_MOUSE_600E    0x600e
 #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D     0x608d
drivers/hid/hid-lenovo.c +17 -5
index a6b73e03c16b..35b00619f045 100644
@@ -504,6 +504,7 @@ static int lenovo_input_mapping(struct hid_device *hdev,
                                                               usage, bit, max);
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
        case USB_DEVICE_ID_LENOVO_X1_TAB3:
@@ -620,6 +621,7 @@ static ssize_t attr_fn_lock_store(struct device *dev,
                break;
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_TP10UBKBD:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -791,9 +793,10 @@ static int lenovo_raw_event(struct hid_device *hdev,
         * Lenovo TP X12 Tab KBD's Fn+XX is HID raw data defined. Report ID is 0x03
         * e.g.: Raw data received for MIC mute is 0x00020003.
         */
-       if (unlikely((hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB
-                       || hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2)
-                       && size >= 3 && report->id == 0x03))
+       if (unlikely((hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB ||
+                     hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2 ||
+                     hdev->product == USB_DEVICE_ID_LENOVO_X13_TAB) &&
+                     size >= 3 && report->id == 0x03))
                return lenovo_raw_event_TP_X12_tab(hdev, le32_to_cpu(*(__le32 *)data));
 
        return 0;
@@ -877,6 +880,7 @@ static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
                return lenovo_event_cptkbd(hdev, field, usage, value);
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_TP10UBKBD:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1161,6 +1165,7 @@ static int lenovo_led_brightness_set(struct led_classdev *led_cdev,
                break;
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_TP10UBKBD:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1355,7 +1360,8 @@ static int lenovo_probe_tp10ubkbd(struct hid_device *hdev)
         */
 
        data->fn_lock = !(hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB ||
-                       hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2);
+                       hdev->product == USB_DEVICE_ID_LENOVO_X12_TAB2 ||
+                       hdev->product == USB_DEVICE_ID_LENOVO_X13_TAB);
 
        lenovo_led_set_tp10ubkbd(hdev, TP10UBKBD_FN_LOCK_LED, data->fn_lock);
 
@@ -1402,6 +1408,7 @@ static int lenovo_probe(struct hid_device *hdev,
                break;
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_TP10UBKBD:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1490,6 +1497,7 @@ static void lenovo_remove(struct hid_device *hdev)
                break;
        case USB_DEVICE_ID_LENOVO_X12_TAB:
        case USB_DEVICE_ID_LENOVO_X12_TAB2:
+       case USB_DEVICE_ID_LENOVO_X13_TAB:
        case USB_DEVICE_ID_LENOVO_TP10UBKBD:
        case USB_DEVICE_ID_LENOVO_X1_TAB:
        case USB_DEVICE_ID_LENOVO_X1_TAB2:
@@ -1517,6 +1525,9 @@ static int lenovo_input_configured(struct hid_device *hdev,
                                                hi->input->propbit);
                        }
                        break;
+               case USB_DEVICE_ID_LENOVO_X13_TAB:
+                       input_set_capability(hi->input, EV_KEY, KEY_PERFORMANCE);
+                       break;
        }
 
        return 0;
@@ -1551,6 +1562,8 @@ static const struct hid_device_id lenovo_devices[] = {
                     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X12_TAB) },
        { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
                     USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X12_TAB2) },
+       { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
+                    USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X13_TAB) },
        { HID_DEVICE(BUS_I2C, HID_GROUP_GENERIC,
                     USB_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_LENOVO_YOGA_SLIM_7X_KEYBOARD) },
        { }
--

2.54.0

Signature · 3 lines
Regards,

      Vishnu Sankar
maintainer
#4 lore raw
Quoted 5 lines · Vishnu Sankar

Hi Jiri / Benjamin,

Gently pinging on this series.
Is there anything blocking acceptance or any changes needed from my side? The series has been tested on physical hardware.

Sorry for the delay. Now applied to hid.git#for-7.1/upstream-fixes.

Signature · 2 lines
Jiri Kosina
SUSE Labs
#5 lore raw

Hi Jiri,

Thank you so much.

Quoted 15 lines · Jiri Kosina
Quoted 5 lines · Vishnu Sankar

Hi Jiri / Benjamin,

Gently pinging on this series.
Is there anything blocking acceptance or any changes needed from my side? The series has been tested on physical hardware.

Sorry for the delay. Now applied to hid.git#for-7.1/upstream-fixes.

--
Jiri Kosina
SUSE Labs

Signature · 3 lines
Regards,

      Vishnu Sankar