From 10ec4afd238d82a4840491a46484d2311db39500 Mon Sep 17 00:00:00 2001 From: Even Xu Date: Wed, 30 Mar 2022 22:27:45 +0800 Subject: HID: intel-ish-hid: ipc: add ADL and RPL device id Add device IDs of Alder Lake N and Raptor Lake S into ishtp support list. Signed-off-by: Even Xu Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina --- drivers/hid/intel-ish-hid/ipc/hw-ish.h | 2 ++ drivers/hid/intel-ish-hid/ipc/pci-ish.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/hid/intel-ish-hid/ipc/hw-ish.h b/drivers/hid/intel-ish-hid/ipc/hw-ish.h index 07e3cbc86bef..e600dbf04dfc 100644 --- a/drivers/hid/intel-ish-hid/ipc/hw-ish.h +++ b/drivers/hid/intel-ish-hid/ipc/hw-ish.h @@ -30,6 +30,8 @@ #define TGL_H_DEVICE_ID 0x43FC #define ADL_S_DEVICE_ID 0x7AF8 #define ADL_P_DEVICE_ID 0x51FC +#define ADL_N_DEVICE_ID 0x54FC +#define RPL_S_DEVICE_ID 0x7A78 #define REVISION_ID_CHT_A0 0x6 #define REVISION_ID_CHT_Ax_SI 0x0 diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c index 8e9d9450cb83..2c67ec17bec6 100644 --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c @@ -41,6 +41,8 @@ static const struct pci_device_id ish_pci_tbl[] = { {PCI_DEVICE(PCI_VENDOR_ID_INTEL, TGL_H_DEVICE_ID)}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, ADL_S_DEVICE_ID)}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, ADL_P_DEVICE_ID)}, + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, ADL_N_DEVICE_ID)}, + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, RPL_S_DEVICE_ID)}, {0, } }; MODULE_DEVICE_TABLE(pci, ish_pci_tbl); -- cgit v1.2.3-59-g8ed1b From 95cd2cdc88c755dcd0a58b951faeb77742c733a4 Mon Sep 17 00:00:00 2001 From: Tao Jin Date: Sun, 3 Apr 2022 12:57:44 -0400 Subject: HID: multitouch: add quirks to enable Lenovo X12 trackpoint This applies the similar quirks used by previous generation devices such as X1 tablet for X12 tablet, so that the trackpoint and buttons can work. This patch was applied and tested working on 5.17.1 . Cc: stable@vger.kernel.org # 5.8+ given that it relies on 40d5bb87377a Signed-off-by: Tao Jin Signed-off-by: Benjamin Tissoires Link: https://lore.kernel.org/r/CO6PR03MB6241CB276FCDC7F4CEDC34F6E1E29@CO6PR03MB6241.namprd03.prod.outlook.com --- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-multitouch.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 053853a891c5..c297c63f3ec5 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -768,6 +768,7 @@ #define USB_DEVICE_ID_LENOVO_X1_COVER 0x6085 #define USB_DEVICE_ID_LENOVO_X1_TAB 0x60a3 #define USB_DEVICE_ID_LENOVO_X1_TAB3 0x60b5 +#define USB_DEVICE_ID_LENOVO_X12_TAB 0x60fe #define USB_DEVICE_ID_LENOVO_OPTICAL_USB_MOUSE_600E 0x600e #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D 0x608d #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019 0x6019 diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 99eabfb4145b..0dece608c023 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -2034,6 +2034,12 @@ static const struct hid_device_id mt_devices[] = { USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_TAB3) }, + /* Lenovo X12 TAB Gen 1 */ + { .driver_data = MT_CLS_WIN_8_FORCE_MULTI_INPUT, + HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, + USB_VENDOR_ID_LENOVO, + USB_DEVICE_ID_LENOVO_X12_TAB) }, + /* MosArt panels */ { .driver_data = MT_CLS_CONFIDENCE_MINUS_ONE, MT_USB_DEVICE(USB_VENDOR_ID_ASUS, -- cgit v1.2.3-59-g8ed1b From d170e8e02729ad3bc4924005cec1ad38409d82af Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 3 Mar 2022 08:47:31 +0100 Subject: HID: uclogic: Add support for touch ring reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for touch ring to UC-Logic driver. The touch ring reports can be flipped around a specific point to match the orientation and direction reported by the Wacom drivers. The proximity will also be reported similar to the Wacom drivers. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 39 ++++++++++++++++++++++++++++++++++++++- drivers/hid/hid-uclogic-params.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 05147f2d7564..b448616dacb9 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -90,6 +90,8 @@ static int uclogic_input_configured(struct hid_device *hdev, const char *suffix = NULL; struct hid_field *field; size_t len; + size_t i; + const struct uclogic_params_frame *frame; /* no report associated (HID_QUIRK_MULTI_INPUT not set) */ if (!hi->report) @@ -104,6 +106,19 @@ static int uclogic_input_configured(struct hid_device *hdev, drvdata->pen_input = hi->input; } + /* If it's one of the frame devices */ + for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) { + frame = ¶ms->frame_list[i]; + if (hi->report->id == frame->id) { + /* + * Disable EV_MSC reports for touch ring interfaces to + * make the Wacom driver pickup touch ring extents + */ + if (frame->touch_ring_byte > 0) + __clear_bit(EV_MSC, hi->input->evbit); + } + } + field = hi->report->field[0]; switch (field->application) { @@ -313,8 +328,16 @@ static int uclogic_raw_event_frame( /* If need to, and can, set pad device ID for Wacom drivers */ if (frame->dev_id_byte > 0 && frame->dev_id_byte < size) { - data[frame->dev_id_byte] = 0xf; + /* If we also have a touch ring and the finger left it */ + if (frame->touch_ring_byte > 0 && + frame->touch_ring_byte < size && + data[frame->touch_ring_byte] == 0) { + data[frame->dev_id_byte] = 0; + } else { + data[frame->dev_id_byte] = 0xf; + } } + /* If need to, and can, read rotary encoder state change */ if (frame->re_lsb > 0 && frame->re_lsb / 8 < size) { unsigned int byte = frame->re_lsb / 8; @@ -341,6 +364,20 @@ static int uclogic_raw_event_frame( drvdata->re_state = state; } + /* If need to, and can, transform the touch ring reports */ + if (frame->touch_ring_byte > 0 && frame->touch_ring_byte < size && + frame->touch_ring_flip_at != 0) { + __s8 value = data[frame->touch_ring_byte]; + + if (value != 0) { + value = frame->touch_ring_flip_at - value; + if (value < 0) + value = frame->touch_ring_max + value; + + data[frame->touch_ring_byte] = value; + } + } + return 0; } diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index 86f616dfbb53..fe13bc36983b 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -123,10 +123,32 @@ struct uclogic_params_frame { /* * Offset of the Wacom-style device ID byte in the report, to be set * to pad device ID (0xf), for compatibility with Wacom drivers. Zero - * if no changes to the report should be made. Only valid if "id" is - * not zero. + * if no changes to the report should be made. The ID byte will be set + * to zero whenever the byte pointed by "touch_ring_byte" is zero, if + * the latter is valid. Only valid if "id" is not zero. */ unsigned int dev_id_byte; + /* + * Offset of the touch ring state byte, in the report. + * Zero if not present. If dev_id_byte is also valid and non-zero, + * then the device ID byte will be cleared when the byte pointed to by + * this offset is zero. Only valid if "id" is not zero. + */ + unsigned int touch_ring_byte; + + /* + * Maximum value of the touch ring report. + * The minimum valid value is considered to be one, + * with zero being out-of-proximity (finger lift) value. + */ + __s8 touch_ring_max; + + /* + * The value to anchor the reversed reports at. + * I.e. one, if the reports should be flipped without offset. + * Zero if no reversal should be done. + */ + __s8 touch_ring_flip_at; }; /* @@ -191,7 +213,10 @@ extern int uclogic_params_init(struct uclogic_params *params, ".frame_list[0].desc_size = %u\n" \ ".frame_list[0].id = %u\n" \ ".frame_list[0].re_lsb = %u\n" \ - ".frame_list[0].dev_id_byte = %u\n" + ".frame_list[0].dev_id_byte = %u\n" \ + ".frame_list[0].touch_ring_byte = %u\n" \ + ".frame_list[0].touch_ring_max = %hhd\n" \ + ".frame_list[0].touch_ring_flip_at = %hhd\n" /* Tablet interface parameters *printf format arguments */ #define UCLOGIC_PARAMS_FMT_ARGS(_params) \ @@ -210,7 +235,10 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[0].desc_size, \ (_params)->frame_list[0].id, \ (_params)->frame_list[0].re_lsb, \ - (_params)->frame_list[0].dev_id_byte + (_params)->frame_list[0].dev_id_byte, \ + (_params)->frame_list[0].touch_ring_byte, \ + (_params)->frame_list[0].touch_ring_max, \ + (_params)->frame_list[0].touch_ring_flip_at /* Get a replacement report descriptor for a tablet's interface. */ extern int uclogic_params_get_desc(const struct uclogic_params *params, -- cgit v1.2.3-59-g8ed1b From ee0070367e1da844e385562fb4f33453b7f7c587 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 3 Mar 2022 08:47:32 +0100 Subject: HID: uclogic: Support custom device suffix for frames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support assigning custom device name suffixes to frame input devices instead of just "Pad". This allows distinguishing multiple frame input devices, e.g. for Huion HS610. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 46 ++++++++++++++++++++++------------------ drivers/hid/hid-uclogic-params.h | 6 ++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index b448616dacb9..96f3fb8c492c 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -110,6 +110,8 @@ static int uclogic_input_configured(struct hid_device *hdev, for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) { frame = ¶ms->frame_list[i]; if (hi->report->id == frame->id) { + /* Assign custom suffix, if any */ + suffix = frame->suffix; /* * Disable EV_MSC reports for touch ring interfaces to * make the Wacom driver pickup touch ring extents @@ -119,27 +121,29 @@ static int uclogic_input_configured(struct hid_device *hdev, } } - field = hi->report->field[0]; - - switch (field->application) { - case HID_GD_KEYBOARD: - suffix = "Keyboard"; - break; - case HID_GD_MOUSE: - suffix = "Mouse"; - break; - case HID_GD_KEYPAD: - suffix = "Pad"; - break; - case HID_DG_PEN: - suffix = "Pen"; - break; - case HID_CP_CONSUMER_CONTROL: - suffix = "Consumer Control"; - break; - case HID_GD_SYSTEM_CONTROL: - suffix = "System Control"; - break; + if (!suffix) { + field = hi->report->field[0]; + + switch (field->application) { + case HID_GD_KEYBOARD: + suffix = "Keyboard"; + break; + case HID_GD_MOUSE: + suffix = "Mouse"; + break; + case HID_GD_KEYPAD: + suffix = "Pad"; + break; + case HID_DG_PEN: + suffix = "Pen"; + break; + case HID_CP_CONSUMER_CONTROL: + suffix = "Consumer Control"; + break; + case HID_GD_SYSTEM_CONTROL: + suffix = "System Control"; + break; + } } if (suffix) { diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index fe13bc36983b..8042820e78b1 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -114,6 +114,10 @@ struct uclogic_params_frame { * Report ID, if reports should be tweaked, zero if not. */ unsigned int id; + /* + * The suffix to add to the input device name, if not NULL. + */ + const char *suffix; /* * Number of the least-significant bit of the 2-bit state of a rotary * encoder, in the report. Cannot point to a 2-bit field crossing a @@ -212,6 +216,7 @@ extern int uclogic_params_init(struct uclogic_params *params, ".frame_list[0].desc_ptr = %p\n" \ ".frame_list[0].desc_size = %u\n" \ ".frame_list[0].id = %u\n" \ + ".frame_list[0].suffix = %s\n" \ ".frame_list[0].re_lsb = %u\n" \ ".frame_list[0].dev_id_byte = %u\n" \ ".frame_list[0].touch_ring_byte = %u\n" \ @@ -234,6 +239,7 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[0].desc_ptr, \ (_params)->frame_list[0].desc_size, \ (_params)->frame_list[0].id, \ + (_params)->frame_list[0].suffix, \ (_params)->frame_list[0].re_lsb, \ (_params)->frame_list[0].dev_id_byte, \ (_params)->frame_list[0].touch_ring_byte, \ -- cgit v1.2.3-59-g8ed1b From 3e200d6cdb7d5c892fb4819be66c65385673a980 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 3 Mar 2022 08:47:33 +0100 Subject: HID: uclogic: Allow three frame parameter sets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow three frame parameter sets per each UC-Logic tablet interface. Bump the number of supported subreports to three as well to accommodate ID routing. This allows supporting the dial on Huion Q620M. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.h | 52 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index 8042820e78b1..f2649e8f959d 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -73,8 +73,8 @@ struct uclogic_params_pen { unsigned int desc_size; /* Report ID, if reports should be tweaked, zero if not */ unsigned int id; - /* The list of subreports */ - struct uclogic_params_pen_subreport subreport_list[1]; + /* The list of subreports, only valid if "id" is not zero */ + struct uclogic_params_pen_subreport subreport_list[3]; /* Type of in-range reporting, only valid if "id" is not zero */ enum uclogic_params_pen_inrange inrange; /* @@ -194,7 +194,7 @@ struct uclogic_params { * The list of frame control parameters and optional report descriptor * parts. Only valid, if "invalid" is false. */ - struct uclogic_params_frame frame_list[1]; + struct uclogic_params_frame frame_list[3]; }; /* Initialize a tablet interface and discover its parameters */ @@ -210,6 +210,8 @@ extern int uclogic_params_init(struct uclogic_params *params, ".pen.desc_size = %u\n" \ ".pen.id = %u\n" \ ".pen.subreport_list[0] = {0x%02hhx, %hhu}\n" \ + ".pen.subreport_list[1] = {0x%02hhx, %hhu}\n" \ + ".pen.subreport_list[2] = {0x%02hhx, %hhu}\n" \ ".pen.inrange = %s\n" \ ".pen.fragmented_hires = %s\n" \ ".pen.tilt_y_flipped = %s\n" \ @@ -221,7 +223,25 @@ extern int uclogic_params_init(struct uclogic_params *params, ".frame_list[0].dev_id_byte = %u\n" \ ".frame_list[0].touch_ring_byte = %u\n" \ ".frame_list[0].touch_ring_max = %hhd\n" \ - ".frame_list[0].touch_ring_flip_at = %hhd\n" + ".frame_list[0].touch_ring_flip_at = %hhd\n" \ + ".frame_list[1].desc_ptr = %p\n" \ + ".frame_list[1].desc_size = %u\n" \ + ".frame_list[1].id = %u\n" \ + ".frame_list[1].suffix = %s\n" \ + ".frame_list[1].re_lsb = %u\n" \ + ".frame_list[1].dev_id_byte = %u\n" \ + ".frame_list[1].touch_ring_byte = %u\n" \ + ".frame_list[1].touch_ring_max = %hhd\n" \ + ".frame_list[1].touch_ring_flip_at = %hhd\n" \ + ".frame_list[2].desc_ptr = %p\n" \ + ".frame_list[2].desc_size = %u\n" \ + ".frame_list[2].id = %u\n" \ + ".frame_list[2].suffix = %s\n" \ + ".frame_list[2].re_lsb = %u\n" \ + ".frame_list[2].dev_id_byte = %u\n" \ + ".frame_list[2].touch_ring_byte = %u\n" \ + ".frame_list[2].touch_ring_max = %hhd\n" \ + ".frame_list[2].touch_ring_flip_at = %hhd\n" /* Tablet interface parameters *printf format arguments */ #define UCLOGIC_PARAMS_FMT_ARGS(_params) \ @@ -233,6 +253,10 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->pen.id, \ (_params)->pen.subreport_list[0].value, \ (_params)->pen.subreport_list[0].id, \ + (_params)->pen.subreport_list[1].value, \ + (_params)->pen.subreport_list[1].id, \ + (_params)->pen.subreport_list[2].value, \ + (_params)->pen.subreport_list[2].id, \ uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \ ((_params)->pen.fragmented_hires ? "true" : "false"), \ ((_params)->pen.tilt_y_flipped ? "true" : "false"), \ @@ -244,7 +268,25 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[0].dev_id_byte, \ (_params)->frame_list[0].touch_ring_byte, \ (_params)->frame_list[0].touch_ring_max, \ - (_params)->frame_list[0].touch_ring_flip_at + (_params)->frame_list[0].touch_ring_flip_at, \ + (_params)->frame_list[1].desc_ptr, \ + (_params)->frame_list[1].desc_size, \ + (_params)->frame_list[1].id, \ + (_params)->frame_list[1].suffix, \ + (_params)->frame_list[1].re_lsb, \ + (_params)->frame_list[1].dev_id_byte, \ + (_params)->frame_list[1].touch_ring_byte, \ + (_params)->frame_list[1].touch_ring_max, \ + (_params)->frame_list[1].touch_ring_flip_at, \ + (_params)->frame_list[2].desc_ptr, \ + (_params)->frame_list[2].desc_size, \ + (_params)->frame_list[2].id, \ + (_params)->frame_list[2].suffix, \ + (_params)->frame_list[2].re_lsb, \ + (_params)->frame_list[2].dev_id_byte, \ + (_params)->frame_list[2].touch_ring_byte, \ + (_params)->frame_list[2].touch_ring_max, \ + (_params)->frame_list[2].touch_ring_flip_at /* Get a replacement report descriptor for a tablet's interface. */ extern int uclogic_params_get_desc(const struct uclogic_params *params, -- cgit v1.2.3-59-g8ed1b From c3e6e59af2a0c7937815808804eb4d9ddc9df9be Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 3 Mar 2022 08:47:34 +0100 Subject: HID: uclogic: Add support for Huion touch ring reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support touch ring reports found in Huion HS610 to the UC-Logic driver. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 40 ++++++++++++++++++++----- drivers/hid/hid-uclogic-rdesc.c | 65 +++++++++++++++++++++++++++++++++++----- drivers/hid/hid-uclogic-rdesc.h | 20 +++++++++---- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 5f50ceb875d6..3ac45e7572a0 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -745,22 +745,48 @@ static int uclogic_params_huion_init(struct uclogic_params *params, goto cleanup; } else if (found) { hid_dbg(hdev, "pen v2 parameters found\n"); - /* Create v2 frame parameters */ + /* Create v2 frame button parameters */ rc = uclogic_params_frame_init_with_desc( &p.frame_list[0], - uclogic_rdesc_v2_frame_arr, - uclogic_rdesc_v2_frame_size, - UCLOGIC_RDESC_V2_FRAME_ID); + uclogic_rdesc_v2_frame_buttons_arr, + uclogic_rdesc_v2_frame_buttons_size, + UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID); if (rc != 0) { hid_err(hdev, - "failed creating v2 frame parameters: %d\n", + "failed creating v2 frame button parameters: %d\n", rc); goto cleanup; } - /* Link frame button subreports from pen reports */ + + /* Create v2 frame touch ring parameters */ + rc = uclogic_params_frame_init_with_desc( + &p.frame_list[1], + uclogic_rdesc_v2_frame_touch_ring_arr, + uclogic_rdesc_v2_frame_touch_ring_size, + UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID); + if (rc != 0) { + hid_err(hdev, + "failed creating v2 frame touch ring parameters: %d\n", + rc); + goto cleanup; + } + p.frame_list[1].suffix = "Touch Ring"; + p.frame_list[1].dev_id_byte = + UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_DEV_ID_BYTE; + p.frame_list[1].touch_ring_byte = 5; + p.frame_list[1].touch_ring_max = 12; + p.frame_list[1].touch_ring_flip_at = 6; + + /* + * Link button and touch ring subreports from pen + * reports + */ p.pen.subreport_list[0].value = 0xe0; p.pen.subreport_list[0].id = - UCLOGIC_RDESC_V2_FRAME_ID; + UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID; + p.pen.subreport_list[1].value = 0xf0; + p.pen.subreport_list[1].id = + UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID; goto output; } hid_dbg(hdev, "pen v2 parameters not found\n"); diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 04644d93bd11..d64b607dce5d 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -652,12 +652,12 @@ const size_t uclogic_rdesc_v2_pen_template_size = sizeof(uclogic_rdesc_v2_pen_template_arr); /* - * Expand to the contents of a generic frame report descriptor. + * Expand to the contents of a generic frame buttons report descriptor. * * @_id: The report ID to use. * @_size: Size of the report to pad to, including report ID, bytes. */ -#define UCLOGIC_RDESC_FRAME_BYTES(_id, _size) \ +#define UCLOGIC_RDESC_FRAME_BUTTONS_BYTES(_id, _size) \ 0x05, 0x01, /* Usage Page (Desktop), */ \ 0x09, 0x07, /* Usage (Keypad), */ \ 0xA1, 0x01, /* Collection (Application), */ \ @@ -700,17 +700,66 @@ const size_t uclogic_rdesc_v2_pen_template_size = /* Fixed report descriptor for (tweaked) v1 frame reports */ const __u8 uclogic_rdesc_v1_frame_arr[] = { - UCLOGIC_RDESC_FRAME_BYTES(UCLOGIC_RDESC_V1_FRAME_ID, 8) + UCLOGIC_RDESC_FRAME_BUTTONS_BYTES(UCLOGIC_RDESC_V1_FRAME_ID, 8) }; const size_t uclogic_rdesc_v1_frame_size = sizeof(uclogic_rdesc_v1_frame_arr); -/* Fixed report descriptor for (tweaked) v2 frame reports */ -const __u8 uclogic_rdesc_v2_frame_arr[] = { - UCLOGIC_RDESC_FRAME_BYTES(UCLOGIC_RDESC_V2_FRAME_ID, 12) +/* Fixed report descriptor for (tweaked) v2 frame button reports */ +const __u8 uclogic_rdesc_v2_frame_buttons_arr[] = { + UCLOGIC_RDESC_FRAME_BUTTONS_BYTES(UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID, + 12) }; -const size_t uclogic_rdesc_v2_frame_size = - sizeof(uclogic_rdesc_v2_frame_arr); +const size_t uclogic_rdesc_v2_frame_buttons_size = + sizeof(uclogic_rdesc_v2_frame_buttons_arr); + +/* Fixed report descriptor for (tweaked) v2 frame touch ring reports */ +const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x07, /* Usage (Keypad), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID, + /* Report ID (DIAL_ID), */ + 0x14, /* Logical Minimum (0), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x09, 0x39, /* Usage (Tablet Function Keys), */ + 0xA0, /* Collection (Physical), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x09, 0x01, /* Usage (01h), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x07, /* Report Count (7), */ + 0x81, 0x01, /* Input (Constant), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x0A, 0xFF, 0xFF, /* Usage (FFFFh), */ + 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x38, /* Usage (Wheel), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x0B, /* Logical Maximum (11), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x30, /* Usage (X), */ + 0x09, 0x31, /* Usage (Y), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x2E, /* Report Count (46), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_v2_frame_touch_ring_size = + sizeof(uclogic_rdesc_v2_frame_touch_ring_arr); /* Fixed report descriptor for Ugee EX07 frame */ const __u8 uclogic_rdesc_ugee_ex07_frame_arr[] = { diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index 3d904c27b86a..f15a9d8a946b 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -124,12 +124,22 @@ extern const size_t uclogic_rdesc_v2_pen_template_size; extern const __u8 uclogic_rdesc_v1_frame_arr[]; extern const size_t uclogic_rdesc_v1_frame_size; -/* Report ID for tweaked v2 frame reports */ -#define UCLOGIC_RDESC_V2_FRAME_ID 0xf7 +/* Report ID for tweaked v2 frame button reports */ +#define UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID 0xf7 -/* Fixed report descriptor for (tweaked) v2 frame reports */ -extern const __u8 uclogic_rdesc_v2_frame_arr[]; -extern const size_t uclogic_rdesc_v2_frame_size; +/* Fixed report descriptor for (tweaked) v2 frame button reports */ +extern const __u8 uclogic_rdesc_v2_frame_buttons_arr[]; +extern const size_t uclogic_rdesc_v2_frame_buttons_size; + +/* Report ID for tweaked v2 frame touch ring reports */ +#define UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID 0xf8 + +/* Fixed report descriptor for (tweaked) v2 frame touch ring reports */ +extern const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[]; +extern const size_t uclogic_rdesc_v2_frame_touch_ring_size; + +/* Device ID byte offset in v2 frame touch ring reports */ +#define UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_DEV_ID_BYTE 0x4 /* Fixed report descriptor for Ugee EX07 frame */ extern const __u8 uclogic_rdesc_ugee_ex07_frame_arr[]; -- cgit v1.2.3-59-g8ed1b From 88115ea6308d6faf94b67e260209180a582bb2f1 Mon Sep 17 00:00:00 2001 From: Nehal Bakulchandra Shah Date: Fri, 8 Apr 2022 15:17:17 +0530 Subject: HID: amd_sfh: Remove name from maintainers list Remove my name from maintainer-ship of AMD SENSOR FUSION HUB DRIVER Signed-off-by: Nehal Bakulchandra Shah Acked-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- MAINTAINERS | 1 - 1 file changed, 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 9e15e069a256..6ab7120f63c8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1035,7 +1035,6 @@ F: arch/arm64/boot/dts/amd/amd-seattle-xgbe*.dtsi F: drivers/net/ethernet/amd/xgbe/ AMD SENSOR FUSION HUB DRIVER -M: Nehal Shah M: Basavaraj Natikar L: linux-input@vger.kernel.org S: Maintained -- cgit v1.2.3-59-g8ed1b From 6d09085b38e5ace0001cf4f3cdbd4bf247533b61 Mon Sep 17 00:00:00 2001 From: Joshua-Dickens Date: Tue, 22 Mar 2022 14:33:16 -0700 Subject: HID: wacom: Adding Support for new usages Added supprt for the following usages: * HID_DG_SCANTIME to report the timestamp for pen and touch events. * WACOM_HID_WD_BARRELSWITCH3 to support pens with 3 buttons. * WACOM_HID_WD_SEQUENCENUMBER to detect and report dropped packets. Signed-off-by: Joshua Dickens Reviewed-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 43 +++++++++++++++++++++++++++++++++++-------- drivers/hid/wacom_wac.h | 5 +++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index a7176fc0635d..64fe573deb9b 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1811,7 +1811,9 @@ int wacom_equivalent_usage(int usage) usage == WACOM_HID_WD_TOUCHSTRIP2 || usage == WACOM_HID_WD_TOUCHRING || usage == WACOM_HID_WD_TOUCHRINGSTATUS || - usage == WACOM_HID_WD_REPORT_VALID) { + usage == WACOM_HID_WD_REPORT_VALID || + usage == WACOM_HID_WD_BARRELSWITCH3 || + usage == WACOM_HID_WD_SEQUENCENUMBER) { return usage; } @@ -2196,8 +2198,11 @@ static void wacom_set_barrel_switch3_usage(struct wacom_wac *wacom_wac) if (!(features->quirks & WACOM_QUIRK_AESPEN) && wacom_wac->hid_data.barrelswitch && wacom_wac->hid_data.barrelswitch2 && - wacom_wac->hid_data.serialhi) + wacom_wac->hid_data.serialhi && + !wacom_wac->hid_data.barrelswitch3) { input_set_capability(input, EV_KEY, BTN_STYLUS3); + features->quirks |= WACOM_QUIRK_PEN_BUTTON3; + } } static void wacom_wac_pen_usage_mapping(struct hid_device *hdev, @@ -2261,6 +2266,9 @@ static void wacom_wac_pen_usage_mapping(struct hid_device *hdev, features->quirks |= WACOM_QUIRK_TOOLSERIAL; wacom_map_usage(input, usage, field, EV_MSC, MSC_SERIAL, 0); break; + case HID_DG_SCANTIME: + wacom_map_usage(input, usage, field, EV_MSC, MSC_TIMESTAMP, 0); + break; case WACOM_HID_WD_SENSE: features->quirks |= WACOM_QUIRK_SENSE; wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0); @@ -2274,6 +2282,11 @@ static void wacom_wac_pen_usage_mapping(struct hid_device *hdev, input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH); wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0); break; + case WACOM_HID_WD_BARRELSWITCH3: + wacom_wac->hid_data.barrelswitch3 = true; + wacom_map_usage(input, usage, field, EV_KEY, BTN_STYLUS3, 0); + features->quirks &= ~WACOM_QUIRK_PEN_BUTTON3; + break; } } @@ -2390,6 +2403,14 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field case WACOM_HID_WD_REPORT_VALID: wacom_wac->is_invalid_bt_frame = !value; return; + case WACOM_HID_WD_BARRELSWITCH3: + wacom_wac->hid_data.barrelswitch3 = value; + return; + case WACOM_HID_WD_SEQUENCENUMBER: + if (wacom_wac->hid_data.sequence_number != value) + hid_warn(hdev, "Dropped %hu packets", value - wacom_wac->hid_data.sequence_number); + wacom_wac->hid_data.sequence_number = value + 1; + return; } /* send pen events only when touch is up or forced out @@ -2442,12 +2463,15 @@ static void wacom_wac_pen_report(struct hid_device *hdev, if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) { int id = wacom_wac->id[0]; - int sw_state = wacom_wac->hid_data.barrelswitch | - (wacom_wac->hid_data.barrelswitch2 << 1); - - input_report_key(input, BTN_STYLUS, sw_state == 1); - input_report_key(input, BTN_STYLUS2, sw_state == 2); - input_report_key(input, BTN_STYLUS3, sw_state == 3); + if (wacom_wac->features.quirks & WACOM_QUIRK_PEN_BUTTON3 && + wacom_wac->hid_data.barrelswitch & wacom_wac->hid_data.barrelswitch2) { + wacom_wac->hid_data.barrelswitch = 0; + wacom_wac->hid_data.barrelswitch2 = 0; + wacom_wac->hid_data.barrelswitch3 = 1; + } + input_report_key(input, BTN_STYLUS, wacom_wac->hid_data.barrelswitch); + input_report_key(input, BTN_STYLUS2, wacom_wac->hid_data.barrelswitch2); + input_report_key(input, BTN_STYLUS3, wacom_wac->hid_data.barrelswitch3); /* * Non-USI EMR tools should have their IDs mangled to @@ -2529,6 +2553,9 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, field->logical_maximum = 255; } break; + case HID_DG_SCANTIME: + wacom_map_usage(input, usage, field, EV_MSC, MSC_TIMESTAMP, 0); + break; } } diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 466b62cc16dc..fef1538005b5 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -86,6 +86,7 @@ #define WACOM_QUIRK_AESPEN 0x0004 #define WACOM_QUIRK_BATTERY 0x0008 #define WACOM_QUIRK_TOOLSERIAL 0x0010 +#define WACOM_QUIRK_PEN_BUTTON3 0x0020 /* device types */ #define WACOM_DEVICETYPE_NONE 0x0000 @@ -108,6 +109,7 @@ #define WACOM_HID_WD_DIGITIZERFNKEYS (WACOM_HID_UP_WACOMDIGITIZER | 0x39) #define WACOM_HID_WD_SERIALNUMBER (WACOM_HID_UP_WACOMDIGITIZER | 0x5b) #define WACOM_HID_WD_SERIALHI (WACOM_HID_UP_WACOMDIGITIZER | 0x5c) +#define WACOM_HID_WD_BARRELSWITCH3 (WACOM_HID_UP_WACOMDIGITIZER | 0x5d) #define WACOM_HID_WD_TOOLTYPE (WACOM_HID_UP_WACOMDIGITIZER | 0x77) #define WACOM_HID_WD_DISTANCE (WACOM_HID_UP_WACOMDIGITIZER | 0x0132) #define WACOM_HID_WD_TOUCHSTRIP (WACOM_HID_UP_WACOMDIGITIZER | 0x0136) @@ -115,6 +117,7 @@ #define WACOM_HID_WD_TOUCHRING (WACOM_HID_UP_WACOMDIGITIZER | 0x0138) #define WACOM_HID_WD_TOUCHRINGSTATUS (WACOM_HID_UP_WACOMDIGITIZER | 0x0139) #define WACOM_HID_WD_REPORT_VALID (WACOM_HID_UP_WACOMDIGITIZER | 0x01d0) +#define WACOM_HID_WD_SEQUENCENUMBER (WACOM_HID_UP_WACOMDIGITIZER | 0x0220) #define WACOM_HID_WD_ACCELEROMETER_X (WACOM_HID_UP_WACOMDIGITIZER | 0x0401) #define WACOM_HID_WD_ACCELEROMETER_Y (WACOM_HID_UP_WACOMDIGITIZER | 0x0402) #define WACOM_HID_WD_ACCELEROMETER_Z (WACOM_HID_UP_WACOMDIGITIZER | 0x0403) @@ -300,6 +303,7 @@ struct hid_data { bool tipswitch; bool barrelswitch; bool barrelswitch2; + bool barrelswitch3; bool serialhi; bool confidence; int x; @@ -320,6 +324,7 @@ struct hid_data { int bat_connected; int ps_connected; bool pad_input_event_flag; + unsigned short sequence_number; }; struct wacom_remote_data { -- cgit v1.2.3-59-g8ed1b From 6ff1cae2e30a79265bcce85f617663c480936ab0 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 7 Apr 2022 13:54:06 +0200 Subject: HID: wacom: Correct power_supply type POWER_SUPPLY_TYPE_USB seems to only ever be used by USB ports that are used to charge the machine itself (so a "system" scope), like the single USB port on a phone, rather than devices. The wacom_sys driver is the only driver that sets its device battery as being a USB type, which doesn't seem correct based on its usage, so switch it to be a battery type like all the other USB-connected devices. Signed-off-by: Bastien Nocera Acked-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 066c567dbaa2..620fe74f5676 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1777,7 +1777,7 @@ static int __wacom_initialize_battery(struct wacom *wacom, bat_desc->get_property = wacom_battery_get_property; sprintf(battery->bat_name, "wacom_battery_%ld", n); bat_desc->name = battery->bat_name; - bat_desc->type = POWER_SUPPLY_TYPE_USB; + bat_desc->type = POWER_SUPPLY_TYPE_BATTERY; bat_desc->use_for_apm = 0; ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg); -- cgit v1.2.3-59-g8ed1b From eea4269f135e7bc11eef125c4ab6c7f50fb5c809 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 14 Apr 2022 13:09:33 +0200 Subject: HID: uclogic: Compress params format string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shorten the format string for printing out UC-Logic interface parameters so that it fits into a single log message. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.h | 90 +++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index f2649e8f959d..ebf84b56746b 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -203,45 +203,57 @@ extern int uclogic_params_init(struct uclogic_params *params, /* Tablet interface parameters *printf format string */ #define UCLOGIC_PARAMS_FMT_STR \ - ".invalid = %s\n" \ - ".desc_ptr = %p\n" \ - ".desc_size = %u\n" \ - ".pen.desc_ptr = %p\n" \ - ".pen.desc_size = %u\n" \ - ".pen.id = %u\n" \ - ".pen.subreport_list[0] = {0x%02hhx, %hhu}\n" \ - ".pen.subreport_list[1] = {0x%02hhx, %hhu}\n" \ - ".pen.subreport_list[2] = {0x%02hhx, %hhu}\n" \ - ".pen.inrange = %s\n" \ - ".pen.fragmented_hires = %s\n" \ - ".pen.tilt_y_flipped = %s\n" \ - ".frame_list[0].desc_ptr = %p\n" \ - ".frame_list[0].desc_size = %u\n" \ - ".frame_list[0].id = %u\n" \ - ".frame_list[0].suffix = %s\n" \ - ".frame_list[0].re_lsb = %u\n" \ - ".frame_list[0].dev_id_byte = %u\n" \ - ".frame_list[0].touch_ring_byte = %u\n" \ - ".frame_list[0].touch_ring_max = %hhd\n" \ - ".frame_list[0].touch_ring_flip_at = %hhd\n" \ - ".frame_list[1].desc_ptr = %p\n" \ - ".frame_list[1].desc_size = %u\n" \ - ".frame_list[1].id = %u\n" \ - ".frame_list[1].suffix = %s\n" \ - ".frame_list[1].re_lsb = %u\n" \ - ".frame_list[1].dev_id_byte = %u\n" \ - ".frame_list[1].touch_ring_byte = %u\n" \ - ".frame_list[1].touch_ring_max = %hhd\n" \ - ".frame_list[1].touch_ring_flip_at = %hhd\n" \ - ".frame_list[2].desc_ptr = %p\n" \ - ".frame_list[2].desc_size = %u\n" \ - ".frame_list[2].id = %u\n" \ - ".frame_list[2].suffix = %s\n" \ - ".frame_list[2].re_lsb = %u\n" \ - ".frame_list[2].dev_id_byte = %u\n" \ - ".frame_list[2].touch_ring_byte = %u\n" \ - ".frame_list[2].touch_ring_max = %hhd\n" \ - ".frame_list[2].touch_ring_flip_at = %hhd\n" + ".invalid = %s\n" \ + ".desc_ptr = %p\n" \ + ".desc_size = %u\n" \ + ".pen = {\n" \ + "\t.desc_ptr = %p\n" \ + "\t.desc_size = %u\n" \ + "\t.id = %u\n" \ + "\t.subreport_list = {\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t}\n" \ + "\t.inrange = %s\n" \ + "\t.fragmented_hires = %s\n" \ + "\t.tilt_y_flipped = %s\n" \ + "}\n" \ + ".frame_list = {\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "}\n" /* Tablet interface parameters *printf format arguments */ #define UCLOGIC_PARAMS_FMT_ARGS(_params) \ -- cgit v1.2.3-59-g8ed1b From f25df3532832c93b7857a61266e48fa0ab87bca7 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 14 Apr 2022 13:09:34 +0200 Subject: HID: uclogic: Reduce indent for params format str/args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve legibility of UCLOGIC_PARAMS_FMT_STR/ARGS. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.h | 186 +++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index ebf84b56746b..78965e683d20 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -203,102 +203,102 @@ extern int uclogic_params_init(struct uclogic_params *params, /* Tablet interface parameters *printf format string */ #define UCLOGIC_PARAMS_FMT_STR \ - ".invalid = %s\n" \ - ".desc_ptr = %p\n" \ - ".desc_size = %u\n" \ - ".pen = {\n" \ - "\t.desc_ptr = %p\n" \ - "\t.desc_size = %u\n" \ - "\t.id = %u\n" \ - "\t.subreport_list = {\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t}\n" \ - "\t.inrange = %s\n" \ - "\t.fragmented_hires = %s\n" \ - "\t.tilt_y_flipped = %s\n" \ - "}\n" \ - ".frame_list = {\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t},\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t},\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t},\n" \ - "}\n" + ".invalid = %s\n" \ + ".desc_ptr = %p\n" \ + ".desc_size = %u\n" \ + ".pen = {\n" \ + "\t.desc_ptr = %p\n" \ + "\t.desc_size = %u\n" \ + "\t.id = %u\n" \ + "\t.subreport_list = {\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t\t{0x%02hhx, %hhu},\n" \ + "\t}\n" \ + "\t.inrange = %s\n" \ + "\t.fragmented_hires = %s\n" \ + "\t.tilt_y_flipped = %s\n" \ + "}\n" \ + ".frame_list = {\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "\t{\n" \ + "\t\t.desc_ptr = %p\n" \ + "\t\t.desc_size = %u\n" \ + "\t\t.id = %u\n" \ + "\t\t.suffix = %s\n" \ + "\t\t.re_lsb = %u\n" \ + "\t\t.dev_id_byte = %u\n" \ + "\t\t.touch_ring_byte = %u\n" \ + "\t\t.touch_ring_max = %hhd\n" \ + "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t},\n" \ + "}\n" /* Tablet interface parameters *printf format arguments */ #define UCLOGIC_PARAMS_FMT_ARGS(_params) \ - ((_params)->invalid ? "true" : "false"), \ - (_params)->desc_ptr, \ - (_params)->desc_size, \ - (_params)->pen.desc_ptr, \ - (_params)->pen.desc_size, \ - (_params)->pen.id, \ - (_params)->pen.subreport_list[0].value, \ - (_params)->pen.subreport_list[0].id, \ - (_params)->pen.subreport_list[1].value, \ - (_params)->pen.subreport_list[1].id, \ - (_params)->pen.subreport_list[2].value, \ - (_params)->pen.subreport_list[2].id, \ - uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \ - ((_params)->pen.fragmented_hires ? "true" : "false"), \ - ((_params)->pen.tilt_y_flipped ? "true" : "false"), \ - (_params)->frame_list[0].desc_ptr, \ - (_params)->frame_list[0].desc_size, \ - (_params)->frame_list[0].id, \ - (_params)->frame_list[0].suffix, \ - (_params)->frame_list[0].re_lsb, \ - (_params)->frame_list[0].dev_id_byte, \ - (_params)->frame_list[0].touch_ring_byte, \ - (_params)->frame_list[0].touch_ring_max, \ - (_params)->frame_list[0].touch_ring_flip_at, \ - (_params)->frame_list[1].desc_ptr, \ - (_params)->frame_list[1].desc_size, \ - (_params)->frame_list[1].id, \ - (_params)->frame_list[1].suffix, \ - (_params)->frame_list[1].re_lsb, \ - (_params)->frame_list[1].dev_id_byte, \ - (_params)->frame_list[1].touch_ring_byte, \ - (_params)->frame_list[1].touch_ring_max, \ - (_params)->frame_list[1].touch_ring_flip_at, \ - (_params)->frame_list[2].desc_ptr, \ - (_params)->frame_list[2].desc_size, \ - (_params)->frame_list[2].id, \ - (_params)->frame_list[2].suffix, \ - (_params)->frame_list[2].re_lsb, \ - (_params)->frame_list[2].dev_id_byte, \ - (_params)->frame_list[2].touch_ring_byte, \ - (_params)->frame_list[2].touch_ring_max, \ - (_params)->frame_list[2].touch_ring_flip_at + ((_params)->invalid ? "true" : "false"), \ + (_params)->desc_ptr, \ + (_params)->desc_size, \ + (_params)->pen.desc_ptr, \ + (_params)->pen.desc_size, \ + (_params)->pen.id, \ + (_params)->pen.subreport_list[0].value, \ + (_params)->pen.subreport_list[0].id, \ + (_params)->pen.subreport_list[1].value, \ + (_params)->pen.subreport_list[1].id, \ + (_params)->pen.subreport_list[2].value, \ + (_params)->pen.subreport_list[2].id, \ + uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \ + ((_params)->pen.fragmented_hires ? "true" : "false"), \ + ((_params)->pen.tilt_y_flipped ? "true" : "false"), \ + (_params)->frame_list[0].desc_ptr, \ + (_params)->frame_list[0].desc_size, \ + (_params)->frame_list[0].id, \ + (_params)->frame_list[0].suffix, \ + (_params)->frame_list[0].re_lsb, \ + (_params)->frame_list[0].dev_id_byte, \ + (_params)->frame_list[0].touch_ring_byte, \ + (_params)->frame_list[0].touch_ring_max, \ + (_params)->frame_list[0].touch_ring_flip_at, \ + (_params)->frame_list[1].desc_ptr, \ + (_params)->frame_list[1].desc_size, \ + (_params)->frame_list[1].id, \ + (_params)->frame_list[1].suffix, \ + (_params)->frame_list[1].re_lsb, \ + (_params)->frame_list[1].dev_id_byte, \ + (_params)->frame_list[1].touch_ring_byte, \ + (_params)->frame_list[1].touch_ring_max, \ + (_params)->frame_list[1].touch_ring_flip_at, \ + (_params)->frame_list[2].desc_ptr, \ + (_params)->frame_list[2].desc_size, \ + (_params)->frame_list[2].id, \ + (_params)->frame_list[2].suffix, \ + (_params)->frame_list[2].re_lsb, \ + (_params)->frame_list[2].dev_id_byte, \ + (_params)->frame_list[2].touch_ring_byte, \ + (_params)->frame_list[2].touch_ring_max, \ + (_params)->frame_list[2].touch_ring_flip_at /* Get a replacement report descriptor for a tablet's interface. */ extern int uclogic_params_get_desc(const struct uclogic_params *params, -- cgit v1.2.3-59-g8ed1b From 2112b49eaa5c5cffc22ddd8b3b09f7d20bf13819 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 14 Apr 2022 13:09:35 +0200 Subject: HID: uclogic: Add support for bitmap dials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bitmap dial sends reports with a dedicated bit per direction: 1 means clockwise rotation, 2 means counterclockwise, as opposed to the normal 1 and -1 values. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 6 ++++++ drivers/hid/hid-uclogic-params.h | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 96f3fb8c492c..627f1d0c52f2 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -382,6 +382,12 @@ static int uclogic_raw_event_frame( } } + /* If need to, and can, transform the bitmap dial reports */ + if (frame->bitmap_dial_byte > 0 && frame->bitmap_dial_byte < size) { + if (data[frame->bitmap_dial_byte] == 2) + data[frame->bitmap_dial_byte] = -1; + } + return 0; } diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index 78965e683d20..e5ccc558abc3 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -153,6 +153,13 @@ struct uclogic_params_frame { * Zero if no reversal should be done. */ __s8 touch_ring_flip_at; + /* + * Offset of the bitmap dial byte, in the report. Zero if not present. + * Only valid if "id" is not zero. A bitmap dial sends reports with a + * dedicated bit per direction: 1 means clockwise rotation, 2 means + * counterclockwise, as opposed to the normal 1 and -1. + */ + unsigned int bitmap_dial_byte; }; /* @@ -230,6 +237,7 @@ extern int uclogic_params_init(struct uclogic_params *params, "\t\t.touch_ring_byte = %u\n" \ "\t\t.touch_ring_max = %hhd\n" \ "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t\t.bitmap_dial_byte = %u\n" \ "\t},\n" \ "\t{\n" \ "\t\t.desc_ptr = %p\n" \ @@ -241,6 +249,7 @@ extern int uclogic_params_init(struct uclogic_params *params, "\t\t.touch_ring_byte = %u\n" \ "\t\t.touch_ring_max = %hhd\n" \ "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t\t.bitmap_dial_byte = %u\n" \ "\t},\n" \ "\t{\n" \ "\t\t.desc_ptr = %p\n" \ @@ -252,6 +261,7 @@ extern int uclogic_params_init(struct uclogic_params *params, "\t\t.touch_ring_byte = %u\n" \ "\t\t.touch_ring_max = %hhd\n" \ "\t\t.touch_ring_flip_at = %hhd\n" \ + "\t\t.bitmap_dial_byte = %u\n" \ "\t},\n" \ "}\n" @@ -281,6 +291,7 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[0].touch_ring_byte, \ (_params)->frame_list[0].touch_ring_max, \ (_params)->frame_list[0].touch_ring_flip_at, \ + (_params)->frame_list[0].bitmap_dial_byte, \ (_params)->frame_list[1].desc_ptr, \ (_params)->frame_list[1].desc_size, \ (_params)->frame_list[1].id, \ @@ -290,6 +301,7 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[1].touch_ring_byte, \ (_params)->frame_list[1].touch_ring_max, \ (_params)->frame_list[1].touch_ring_flip_at, \ + (_params)->frame_list[1].bitmap_dial_byte, \ (_params)->frame_list[2].desc_ptr, \ (_params)->frame_list[2].desc_size, \ (_params)->frame_list[2].id, \ @@ -298,7 +310,8 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame_list[2].dev_id_byte, \ (_params)->frame_list[2].touch_ring_byte, \ (_params)->frame_list[2].touch_ring_max, \ - (_params)->frame_list[2].touch_ring_flip_at + (_params)->frame_list[2].touch_ring_flip_at, \ + (_params)->frame_list[2].bitmap_dial_byte /* Get a replacement report descriptor for a tablet's interface. */ extern int uclogic_params_get_desc(const struct uclogic_params *params, -- cgit v1.2.3-59-g8ed1b From 6facd076f5a9827800894c77a53d100c5f0a7d2f Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 14 Apr 2022 13:09:36 +0200 Subject: HID: uclogic: Add support for Huion Q620M MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Huion Q620M tablet needs a v2 frame dial. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 20 ++++++++++++++++ drivers/hid/hid-uclogic-rdesc.c | 50 ++++++++++++++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 10 ++++++++ 3 files changed, 80 insertions(+) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 3ac45e7572a0..09c332c6a412 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -777,6 +777,23 @@ static int uclogic_params_huion_init(struct uclogic_params *params, p.frame_list[1].touch_ring_max = 12; p.frame_list[1].touch_ring_flip_at = 6; + /* Create v2 frame dial parameters */ + rc = uclogic_params_frame_init_with_desc( + &p.frame_list[2], + uclogic_rdesc_v2_frame_dial_arr, + uclogic_rdesc_v2_frame_dial_size, + UCLOGIC_RDESC_V2_FRAME_DIAL_ID); + if (rc != 0) { + hid_err(hdev, + "failed creating v2 frame dial parameters: %d\n", + rc); + goto cleanup; + } + p.frame_list[2].suffix = "Dial"; + p.frame_list[2].dev_id_byte = + UCLOGIC_RDESC_V2_FRAME_DIAL_DEV_ID_BYTE; + p.frame_list[2].bitmap_dial_byte = 5; + /* * Link button and touch ring subreports from pen * reports @@ -787,6 +804,9 @@ static int uclogic_params_huion_init(struct uclogic_params *params, p.pen.subreport_list[1].value = 0xf0; p.pen.subreport_list[1].id = UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID; + p.pen.subreport_list[2].value = 0xf1; + p.pen.subreport_list[2].id = + UCLOGIC_RDESC_V2_FRAME_DIAL_ID; goto output; } hid_dbg(hdev, "pen v2 parameters not found\n"); diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index d64b607dce5d..dd792160fe7e 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -761,6 +761,56 @@ const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[] = { const size_t uclogic_rdesc_v2_frame_touch_ring_size = sizeof(uclogic_rdesc_v2_frame_touch_ring_arr); +/* Fixed report descriptor for (tweaked) v2 frame dial reports */ +const __u8 uclogic_rdesc_v2_frame_dial_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x07, /* Usage (Keypad), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, UCLOGIC_RDESC_V2_FRAME_DIAL_ID, + /* Report ID (DIAL_ID), */ + 0x14, /* Logical Minimum (0), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x09, 0x39, /* Usage (Tablet Function Keys), */ + 0xA0, /* Collection (Physical), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x09, 0x01, /* Usage (01h), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x06, /* Report Count (6), */ + 0x81, 0x01, /* Input (Constant), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x0A, 0xFF, 0xFF, /* Usage (FFFFh), */ + 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x38, /* Usage (Wheel), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0xFF, /* Logical Minimum (-1), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x81, 0x06, /* Input (Variable, Relative), */ + 0x09, 0x30, /* Usage (X), */ + 0x09, 0x31, /* Usage (Y), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x2E, /* Report Count (46), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_v2_frame_dial_size = + sizeof(uclogic_rdesc_v2_frame_dial_arr); + /* Fixed report descriptor for Ugee EX07 frame */ const __u8 uclogic_rdesc_ugee_ex07_frame_arr[] = { 0x05, 0x01, /* Usage Page (Desktop), */ diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index f15a9d8a946b..2ab6b7d5f5af 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -141,6 +141,16 @@ extern const size_t uclogic_rdesc_v2_frame_touch_ring_size; /* Device ID byte offset in v2 frame touch ring reports */ #define UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_DEV_ID_BYTE 0x4 +/* Report ID for tweaked v2 frame dial reports */ +#define UCLOGIC_RDESC_V2_FRAME_DIAL_ID 0xf9 + +/* Fixed report descriptor for (tweaked) v2 frame dial reports */ +extern const __u8 uclogic_rdesc_v2_frame_dial_arr[]; +extern const size_t uclogic_rdesc_v2_frame_dial_size; + +/* Device ID byte offset in v2 frame dial reports */ +#define UCLOGIC_RDESC_V2_FRAME_DIAL_DEV_ID_BYTE 0x4 + /* Fixed report descriptor for Ugee EX07 frame */ extern const __u8 uclogic_rdesc_ugee_ex07_frame_arr[]; extern const size_t uclogic_rdesc_ugee_ex07_frame_size; -- cgit v1.2.3-59-g8ed1b From 62f8857b2d082069b11851d1ae8ce101752436ee Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Wed, 20 Apr 2022 10:22:44 -0400 Subject: HID: amd_sfh: change global variables to static Smatch reports this representative issue amd_sfh_hid_report_desc.h:182:10: warning: symbol 'gyro3_report_descriptor' was not declared. Should it be static? Similar issues for comp3_report_descriptor and als_report_descriptor. Global variables should not be defined in header files. This only works because amd_sfh_hid_report_desc.h in only included by amd_sfh_hid_desc.c so change the storage-class specifiers to static. Signed-off-by: Tom Rix Acked-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h index 8d97ca0f9b52..697f2791ea9c 100644 --- a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h +++ b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h @@ -179,7 +179,7 @@ static const u8 accel3_report_descriptor[] = { 0xC0 /* HID end collection */ }; -const u8 gyro3_report_descriptor[] = { +static const u8 gyro3_report_descriptor[] = { 0x05, 0x20, /* Usage page */ 0x09, 0x76, /* Motion type Gyro3D */ 0xA1, 0x00, /* HID Collection (Physical) */ @@ -340,7 +340,7 @@ const u8 gyro3_report_descriptor[] = { 0xC0, /* HID end collection */ }; -const u8 comp3_report_descriptor[] = { +static const u8 comp3_report_descriptor[] = { 0x05, 0x20, /* Usage page */ 0x09, 0x83, /* Motion type Orientation compass 3D */ 0xA1, 0x00, /* HID Collection (Physical) */ @@ -512,7 +512,7 @@ const u8 comp3_report_descriptor[] = { 0xC0 /* HID end collection */ }; -const u8 als_report_descriptor[] = { +static const u8 als_report_descriptor[] = { 0x05, 0x20, /* HID usage page sensor */ 0x09, 0x41, /* HID usage sensor type Ambientlight */ 0xA1, 0x00, /* HID Collection (Physical) */ -- cgit v1.2.3-59-g8ed1b From 1d07cef7fd7599450b3d03e1915efc2a96e1f03f Mon Sep 17 00:00:00 2001 From: Marek Maślanka Date: Tue, 5 Apr 2022 17:04:07 +0200 Subject: HID: multitouch: Add support for Google Whiskers Touchpad The Google Whiskers touchpad does not work properly with the default multitouch configuration. Instead, use the same configuration as Google Rose. Signed-off-by: Marek Maslanka Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-multitouch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 0dece608c023..6bb3890b0f2c 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -2184,6 +2184,9 @@ static const struct hid_device_id mt_devices[] = { { .driver_data = MT_CLS_GOOGLE, HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_TOUCH_ROSE) }, + { .driver_data = MT_CLS_GOOGLE, + HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH_WIN_8, USB_VENDOR_ID_GOOGLE, + USB_DEVICE_ID_GOOGLE_WHISKERS) }, /* Generic MT device */ { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) }, -- cgit v1.2.3-59-g8ed1b From 116c3f4a78ebe478d5ad5a038baf931e93e7d748 Mon Sep 17 00:00:00 2001 From: Jonathan Teh Date: Sun, 13 Mar 2022 19:48:18 +0000 Subject: HID: hid-led: fix maximum brightness for Dream Cheeky Increase maximum brightness for Dream Cheeky to 63. Emperically determined based on testing in kernel 4.4 on this device: Bus 003 Device 002: ID 1d34:0004 Dream Cheeky Webmail Notifier Fixes: 6c7ad07e9e05 ("HID: migrate USB LED driver from usb misc to hid") Signed-off-by: Jonathan Teh Signed-off-by: Jiri Kosina --- drivers/hid/hid-led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-led.c b/drivers/hid/hid-led.c index c2c66ceca132..7d82f8d426bb 100644 --- a/drivers/hid/hid-led.c +++ b/drivers/hid/hid-led.c @@ -366,7 +366,7 @@ static const struct hidled_config hidled_configs[] = { .type = DREAM_CHEEKY, .name = "Dream Cheeky Webmail Notifier", .short_name = "dream_cheeky", - .max_brightness = 31, + .max_brightness = 63, .num_leds = 1, .report_size = 9, .report_type = RAW_REQUEST, -- cgit v1.2.3-59-g8ed1b From 1af20714fedad238362571620be0bd690ded05b6 Mon Sep 17 00:00:00 2001 From: Miaoqian Lin Date: Sat, 16 Apr 2022 07:37:21 +0000 Subject: HID: elan: Fix potential double free in elan_input_configured 'input' is a managed resource allocated with devm_input_allocate_device(), so there is no need to call input_free_device() explicitly or there will be a double free. According to the doc of devm_input_allocate_device(): * Managed input devices do not need to be explicitly unregistered or * freed as it will be done automatically when owner device unbinds from * its driver (or binding fails). Fixes: b7429ea53d6c ("HID: elan: Fix memleak in elan_input_configured") Fixes: 9a6a4193d65b ("HID: Add driver for USB ELAN Touchpad") Signed-off-by: Miaoqian Lin Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-elan.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 3091355d48df..8e4a5528e25d 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c @@ -188,7 +188,6 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER); if (ret) { hid_err(hdev, "Failed to init elan MT slots: %d\n", ret); - input_free_device(input); return ret; } @@ -200,7 +199,6 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi) hid_err(hdev, "Failed to register elan input device: %d\n", ret); input_mt_destroy_slots(input); - input_free_device(input); return ret; } -- cgit v1.2.3-59-g8ed1b From 24401f291dcc4f2c18b9e2f65763cbaadc7a1528 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 13 Feb 2022 22:49:22 +0100 Subject: HID: lenovo: Add support for ThinkPad TrackPoint Keyboard II This keyboard has two modes: regular HID and a native mode, which is used in Windows driver. Native mode disables (poor) middle mouse button scrolling emulation and reports middle button and scrolling events with a custom report ID, which could be better handled in the driver. This commit adds functional button mapping and native scrolling support. HID collection in Bluetooth mode for custom report ID=5 is broken and is patched upon connection. The collection initially contains incorrect Usage Minimum/Usage Maximum numbers and, more importantly, marks Input as Variable, not Array, while reporting values as in Array. The keyboard is very similar to Compact USB/Bluetooth Keyboard with TrackPoint, that's why this patch reuses all of cptkbd functions, except for input mapping. Signed-off-by: Florian Klink Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-ids.h | 2 + drivers/hid/hid-lenovo.c | 160 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 156 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 053853a891c5..1c5bd9882dea 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -761,7 +761,9 @@ #define USB_VENDOR_ID_LENOVO 0x17ef #define USB_DEVICE_ID_LENOVO_TPKBD 0x6009 #define USB_DEVICE_ID_LENOVO_CUSBKBD 0x6047 +#define USB_DEVICE_ID_LENOVO_TPIIUSBKBD 0x60ee #define USB_DEVICE_ID_LENOVO_CBTKBD 0x6048 +#define USB_DEVICE_ID_LENOVO_TPIIBTKBD 0x60e1 #define USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL 0x6049 #define USB_DEVICE_ID_LENOVO_TP10UBKBD 0x6062 #define USB_DEVICE_ID_LENOVO_TPPRODOCK 0x6067 diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 93b1f935e526..a612ae7dfbfc 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -4,6 +4,7 @@ * - ThinkPad USB Keyboard with TrackPoint (tpkbd) * - ThinkPad Compact Bluetooth Keyboard with TrackPoint (cptkbd) * - ThinkPad Compact USB Keyboard with TrackPoint (cptkbd) + * - ThinkPad TrackPoint Keyboard II USB/Bluetooth (cptkbd/tpIIkbd) * * Copyright (c) 2012 Bernhard Seibold * Copyright (c) 2014 Jamie Lentin @@ -110,6 +111,23 @@ static const __u8 lenovo_pro_dock_need_fixup_collection[] = { 0x2a, 0xff, 0xff, /* Usage Maximum (65535) */ }; +/* Broken ThinkPad TrackPoint II collection (Bluetooth mode) */ +static const __u8 lenovo_tpIIbtkbd_need_fixup_collection[] = { + 0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined 0xFF00) */ + 0x09, 0x01, /* Usage (0x01) */ + 0xA1, 0x01, /* Collection (Application) */ + 0x85, 0x05, /* Report ID (5) */ + 0x1A, 0xF1, 0x00, /* Usage Minimum (0xF1) */ + 0x2A, 0xFC, 0x00, /* Usage Maximum (0xFC) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x75, 0x01, /* Report Size (1) */ + 0x95, 0x0D, /* Report Count (13) */ + 0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) */ + 0x95, 0x03, /* Report Count (3) */ + 0x81, 0x01, /* Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) */ +}; + static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) { @@ -126,6 +144,19 @@ static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc, rdesc[152] = 0x00; } break; + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: + if (*rsize >= 263 && + memcmp(&rdesc[234], lenovo_tpIIbtkbd_need_fixup_collection, + sizeof(lenovo_tpIIbtkbd_need_fixup_collection)) == 0) { + rdesc[244] = 0x00; /* usage minimum = 0x00 */ + rdesc[247] = 0xff; /* usage maximum = 0xff */ + rdesc[252] = 0xff; /* logical maximum = 0xff */ + rdesc[254] = 0x08; /* report size = 0x08 */ + rdesc[256] = 0x01; /* report count = 0x01 */ + rdesc[258] = 0x00; /* input = 0x00 */ + rdesc[260] = 0x01; /* report count (2) = 0x01 */ + } + break; } return rdesc; } @@ -217,6 +248,101 @@ static int lenovo_input_mapping_cptkbd(struct hid_device *hdev, return 0; } +static int lenovo_input_mapping_tpIIkbd(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, + struct hid_usage *usage, unsigned long **bit, int *max) +{ + /* + * 0xff0a0000 = USB, HID_UP_MSVENDOR = BT. + * + * In BT mode, there are two HID_UP_MSVENDOR pages. + * Use only the page that contains report ID == 5. + */ + if (((usage->hid & HID_USAGE_PAGE) == 0xff0a0000 || + (usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) && + field->report->id == 5) { + switch (usage->hid & HID_USAGE) { + case 0x00bb: /* Fn-F4: Mic mute */ + map_key_clear(LENOVO_KEY_MICMUTE); + return 1; + case 0x00c3: /* Fn-F5: Brightness down */ + map_key_clear(KEY_BRIGHTNESSDOWN); + return 1; + case 0x00c4: /* Fn-F6: Brightness up */ + map_key_clear(KEY_BRIGHTNESSUP); + return 1; + case 0x00c1: /* Fn-F8: Notification center */ + map_key_clear(KEY_NOTIFICATION_CENTER); + return 1; + case 0x00bc: /* Fn-F9: Control panel */ + map_key_clear(KEY_CONFIG); + return 1; + case 0x00b6: /* Fn-F10: Bluetooth */ + map_key_clear(KEY_BLUETOOTH); + return 1; + case 0x00b7: /* Fn-F11: Keyboard config */ + map_key_clear(KEY_KEYBOARD); + return 1; + case 0x00b8: /* Fn-F12: User function */ + map_key_clear(KEY_PROG1); + return 1; + case 0x00b9: /* Fn-PrtSc: Snipping tool */ + map_key_clear(KEY_SELECTIVE_SCREENSHOT); + return 1; + case 0x00b5: /* Fn-Esc: Fn-lock toggle */ + map_key_clear(KEY_FN_ESC); + return 1; + } + } + + if ((usage->hid & HID_USAGE_PAGE) == 0xffa00000) { + switch (usage->hid & HID_USAGE) { + case 0x00fb: /* Middle mouse (in native USB mode) */ + map_key_clear(BTN_MIDDLE); + return 1; + } + } + + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && + field->report->id == 21) { + switch (usage->hid & HID_USAGE) { + case 0x0004: /* Middle mouse (in native Bluetooth mode) */ + map_key_clear(BTN_MIDDLE); + return 1; + } + } + + /* Compatibility middle/wheel mappings should be ignored */ + if (usage->hid == HID_GD_WHEEL) + return -1; + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON && + (usage->hid & HID_USAGE) == 0x003) + return -1; + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER && + (usage->hid & HID_USAGE) == 0x238) + return -1; + + /* Map wheel emulation reports: 0xff10 */ + if ((usage->hid & HID_USAGE_PAGE) == 0xff100000) { + field->flags |= HID_MAIN_ITEM_RELATIVE | HID_MAIN_ITEM_VARIABLE; + field->logical_minimum = -127; + field->logical_maximum = 127; + + switch (usage->hid & HID_USAGE) { + case 0x0000: + hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); + return 1; + case 0x0001: + hid_map_usage(hi, usage, bit, max, EV_REL, REL_WHEEL); + return 1; + default: + return -1; + } + } + + return 0; +} + static int lenovo_input_mapping_scrollpoint(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) @@ -326,6 +452,10 @@ static int lenovo_input_mapping(struct hid_device *hdev, case USB_DEVICE_ID_LENOVO_CBTKBD: return lenovo_input_mapping_cptkbd(hdev, hi, field, usage, bit, max); + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: + return lenovo_input_mapping_tpIIkbd(hdev, hi, field, + usage, bit, max); case USB_DEVICE_ID_IBM_SCROLLPOINT_III: case USB_DEVICE_ID_IBM_SCROLLPOINT_PRO: case USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL: @@ -363,10 +493,12 @@ static int lenovo_send_cmd_cptkbd(struct hid_device *hdev, switch (hdev->product) { case USB_DEVICE_ID_LENOVO_CUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: ret = hid_hw_raw_request(hdev, 0x13, buf, 3, HID_FEATURE_REPORT, HID_REQ_SET_REPORT); break; case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: ret = hid_hw_output_report(hdev, buf, 3); break; default: @@ -422,6 +554,8 @@ static ssize_t attr_fn_lock_store(struct device *dev, switch (hdev->product) { case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: lenovo_features_set_cptkbd(hdev); break; case USB_DEVICE_ID_LENOVO_TP10UBKBD: @@ -568,6 +702,8 @@ static int lenovo_event(struct hid_device *hdev, struct hid_field *field, switch (hdev->product) { case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: return lenovo_event_cptkbd(hdev, field, usage, value); case USB_DEVICE_ID_LENOVO_TP10UBKBD: case USB_DEVICE_ID_LENOVO_X1_TAB: @@ -960,8 +1096,9 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev) struct lenovo_drvdata *cptkbd_data; /* All the custom action happens on the USBMOUSE device for USB */ - if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD - && hdev->type != HID_TYPE_USBMOUSE) { + if (((hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD) || + (hdev->product == USB_DEVICE_ID_LENOVO_TPIIUSBKBD)) && + hdev->type != HID_TYPE_USBMOUSE) { hid_dbg(hdev, "Ignoring keyboard half of device\n"); return 0; } @@ -977,11 +1114,14 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev) /* * Tell the keyboard a driver understands it, and turn F7, F9, F11 into - * regular keys + * regular keys (Compact only) */ - ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); - if (ret) - hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); + if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD || + hdev->product == USB_DEVICE_ID_LENOVO_CBTKBD) { + ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); + if (ret) + hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); + } /* Switch middle button to native mode */ ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); @@ -1088,6 +1228,8 @@ static int lenovo_probe(struct hid_device *hdev, break; case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: ret = lenovo_probe_cptkbd(hdev); break; case USB_DEVICE_ID_LENOVO_TP10UBKBD: @@ -1154,6 +1296,8 @@ static void lenovo_remove(struct hid_device *hdev) break; case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: lenovo_remove_cptkbd(hdev); break; case USB_DEVICE_ID_LENOVO_TP10UBKBD: @@ -1172,6 +1316,8 @@ static int lenovo_input_configured(struct hid_device *hdev, case USB_DEVICE_ID_LENOVO_TPKBD: case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: + case USB_DEVICE_ID_LENOVO_TPIIUSBKBD: + case USB_DEVICE_ID_LENOVO_TPIIBTKBD: if (test_bit(EV_REL, hi->input->evbit)) { /* set only for trackpoint device */ __set_bit(INPUT_PROP_POINTER, hi->input->propbit); @@ -1188,7 +1334,9 @@ static int lenovo_input_configured(struct hid_device *hdev, static const struct hid_device_id lenovo_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) }, { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPIIUSBKBD) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPIIBTKBD) }, { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) }, { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_III) }, { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_PRO) }, -- cgit v1.2.3-59-g8ed1b From a0a5c2a696990520eba366fae67573306641b93b Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 13 Feb 2022 22:49:23 +0100 Subject: HID: lenovo: Sync Fn-lock state on button press for Compact and TrackPoint II keyboards When Fn-Esc is pressed on the keyboard, it emits the scancode which could be used to sync the fn_lock sysfs state. Previously fn_lock only allowed to set new Fn-lock state and did not keep the value in sync upon Fn-Esc press, which is now fixed. Signed-off-by: Florian Klink Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-lenovo.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index a612ae7dfbfc..e9466ae8a9cb 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -690,6 +690,15 @@ static int lenovo_event_cptkbd(struct hid_device *hdev, return 1; } + if (usage->type == EV_KEY && usage->code == KEY_FN_ESC && value == 1) { + /* + * The user has toggled the Fn-lock state. Toggle our own + * cached value of it and sync our value to the keyboard to + * ensure things are in sync (the syncing should be a no-op). + */ + cptkbd_data->fn_lock = !cptkbd_data->fn_lock; + } + return 0; } -- cgit v1.2.3-59-g8ed1b From 5c9b8fae88bc2f629926b7949dbc3672d4fbdad2 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 13 Feb 2022 22:49:24 +0100 Subject: HID: lenovo: Add note about different report numbers Signed-off-by: Florian Klink Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-lenovo.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index e9466ae8a9cb..9dabd6323234 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -487,6 +487,11 @@ static int lenovo_send_cmd_cptkbd(struct hid_device *hdev, if (!buf) return -ENOMEM; + /* + * Feature report 0x13 is used for USB, + * output report 0x18 is used for Bluetooth. + * buf[0] is ignored by hid_hw_raw_request. + */ buf[0] = 0x18; buf[1] = byte2; buf[2] = byte3; -- cgit v1.2.3-59-g8ed1b From b3ddadbf353cb4ac5ca66c200cfb25d632cc9e6f Mon Sep 17 00:00:00 2001 From: Ping Cheng Date: Sat, 23 Apr 2022 22:36:58 -0700 Subject: MAINTAINERS: Add Wacom driver maintainers As suggested by Bastien and Jiri. Signed-off-by: Ping Cheng Reviewed-by: Bastien Nocera Signed-off-by: Jiri Kosina --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9e15e069a256..77064cea9524 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8640,6 +8640,14 @@ F: drivers/hid/hid-sensor-* F: drivers/iio/*/hid-* F: include/linux/hid-sensor-* +HID WACOM DRIVER +M: Ping Cheng +M: Jason Gerecke +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/hid/wacom.h +F: drivers/hid/wacom_* + HIGH-RESOLUTION TIMERS, CLOCKEVENTS M: Thomas Gleixner L: linux-kernel@vger.kernel.org -- cgit v1.2.3-59-g8ed1b From 06be0d6442a07f73107964d7b56c21759c6dfb00 Mon Sep 17 00:00:00 2001 From: frank zago Date: Wed, 20 Apr 2022 21:40:41 -0500 Subject: HID: Add support for Mega World controller force feedback This patch adds support for one of the several Mega World USB game controller with integrated force feedback. It is a HID based memory-less game controller, with a weak motor on the left, and a strong one on the right. Signed-off-by: frank zago Signed-off-by: Jiri Kosina --- drivers/hid/Kconfig | 8 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 3 ++ drivers/hid/hid-megaworld.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 drivers/hid/hid-megaworld.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 7a674873d794..96750b390344 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -686,6 +686,14 @@ config HID_MAYFLASH Say Y here if you have HJZ Mayflash PS3 game controller adapters and want to enable force feedback support. +config HID_MEGAWORLD_FF + tristate "Mega World based game controller force feedback support" + depends on USB_HID + select INPUT_FF_MEMLESS + help + Say Y here if you have a Mega World based game controller and want + to have force feedback support for it. + config HID_REDRAGON tristate "Redragon keyboards" depends on HID diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index d5ce8d747b14..c2a2db163094 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -76,6 +76,7 @@ obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o obj-$(CONFIG_HID_MALTRON) += hid-maltron.o obj-$(CONFIG_HID_MCP2221) += hid-mcp2221.o obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o +obj-$(CONFIG_HID_MEGAWORLD_FF) += hid-megaworld.o obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o obj-$(CONFIG_HID_MULTITOUCH) += hid-multitouch.o diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 053853a891c5..b9e0f3deb080 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -868,6 +868,9 @@ #define USB_VENDOR_ID_MCS 0x16d0 #define USB_DEVICE_ID_MCS_GAMEPADBLOCK 0x0bcc +#define USB_VENDOR_MEGAWORLD 0x07b5 +#define USB_DEVICE_ID_MEGAWORLD_GAMEPAD 0x0312 + #define USB_VENDOR_ID_MGE 0x0463 #define USB_DEVICE_ID_MGE_UPS 0xffff #define USB_DEVICE_ID_MGE_UPS1 0x0001 diff --git a/drivers/hid/hid-megaworld.c b/drivers/hid/hid-megaworld.c new file mode 100644 index 000000000000..599657863cb9 --- /dev/null +++ b/drivers/hid/hid-megaworld.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Vibration support for Mega World controllers + * + * Copyright 2022 Frank Zago + * + * Derived from hid-zpff.c: + * Copyright (c) 2005, 2006 Anssi Hannula + */ + +#include +#include +#include +#include + +#include "hid-ids.h" + +struct mwctrl_device { + struct hid_report *report; + s32 *weak; + s32 *strong; +}; + +static int mwctrl_play(struct input_dev *dev, void *data, + struct ff_effect *effect) +{ + struct hid_device *hid = input_get_drvdata(dev); + struct mwctrl_device *mwctrl = data; + + *mwctrl->strong = effect->u.rumble.strong_magnitude >> 8; + *mwctrl->weak = effect->u.rumble.weak_magnitude >> 8; + + hid_hw_request(hid, mwctrl->report, HID_REQ_SET_REPORT); + + return 0; +} + +static int mwctrl_init(struct hid_device *hid) +{ + struct mwctrl_device *mwctrl; + struct hid_report *report; + struct hid_input *hidinput; + struct input_dev *dev; + int error; + int i; + + if (list_empty(&hid->inputs)) { + hid_err(hid, "no inputs found\n"); + return -ENODEV; + } + hidinput = list_entry(hid->inputs.next, struct hid_input, list); + dev = hidinput->input; + + for (i = 0; i < 4; i++) { + report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1); + if (!report) + return -ENODEV; + } + + mwctrl = kzalloc(sizeof(struct mwctrl_device), GFP_KERNEL); + if (!mwctrl) + return -ENOMEM; + + set_bit(FF_RUMBLE, dev->ffbit); + + error = input_ff_create_memless(dev, mwctrl, mwctrl_play); + if (error) { + kfree(mwctrl); + return error; + } + + mwctrl->report = report; + + /* Field 0 is always 2, and field 1 is always 0. The original + * windows driver has a 5 bytes command, where the 5th byte is + * a repeat of the 3rd byte, however the device has only 4 + * fields. It could be a bug in the driver, or there is a + * different device that needs it. + */ + report->field[0]->value[0] = 0x02; + + mwctrl->strong = &report->field[2]->value[0]; + mwctrl->weak = &report->field[3]->value[0]; + + return 0; +} + +static int mwctrl_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + int ret; + + ret = hid_parse(hdev); + if (ret) { + hid_err(hdev, "parse failed\n"); + return ret; + } + + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + if (ret) { + hid_err(hdev, "hw start failed\n"); + return ret; + } + + ret = mwctrl_init(hdev); + if (ret) + hid_hw_stop(hdev); + + return ret; +} + +static const struct hid_device_id mwctrl_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_MEGAWORLD, + USB_DEVICE_ID_MEGAWORLD_GAMEPAD) }, + { } +}; +MODULE_DEVICE_TABLE(hid, mwctrl_devices); + +static struct hid_driver mwctrl_driver = { + .name = "megaworld", + .id_table = mwctrl_devices, + .probe = mwctrl_probe, +}; +module_hid_driver(mwctrl_driver); + +MODULE_LICENSE("GPL"); -- cgit v1.2.3-59-g8ed1b From 87dc28eb11ac2f52b8f73af061f9acd32fb895c3 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 21 Apr 2022 19:50:48 +0200 Subject: HID: uclogic: Clarify params desc_size description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documentation improvements. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index e5ccc558abc3..a489c92cee43 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -189,7 +189,7 @@ struct uclogic_params { __u8 *desc_ptr; /* * Size of the common part of the replacement report descriptor. - * Only valid, if "desc_ptr" is not NULL. + * Only valid, if "desc_ptr" is valid and not NULL. */ unsigned int desc_size; /* -- cgit v1.2.3-59-g8ed1b From 4933a722a05c99be124bc31fbcc750d7c0a04bc9 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 21 Apr 2022 19:50:49 +0200 Subject: HID: uclogic: Clarify pen/frame desc_ptr description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documentation improvements. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index a489c92cee43..fa75efba3130 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -62,8 +62,8 @@ struct uclogic_params_pen_subreport { */ struct uclogic_params_pen { /* - * Pointer to report descriptor describing the inputs. - * Allocated with kmalloc. + * Pointer to report descriptor part describing the pen inputs. + * Allocated with kmalloc. NULL if the part is not specified. */ __u8 *desc_ptr; /* @@ -101,8 +101,8 @@ struct uclogic_params_pen { */ struct uclogic_params_frame { /* - * Pointer to report descriptor describing the inputs. - * Allocated with kmalloc. + * Pointer to report descriptor part describing the frame inputs. + * Allocated with kmalloc. NULL if the part is not specified. */ __u8 *desc_ptr; /* -- cgit v1.2.3-59-g8ed1b From d64a6e4460d6415df37590ecb76fad6bd5f2c8a6 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 21 Apr 2022 19:50:50 +0200 Subject: HID: uclogic: Pass keyboard reports as is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow keyboard reports from interface #1 of Huion tablets to pass unmodified, and stop the Wacom X.org driver from handling them. The method for the latter is rather crude and also take the Dial reports from the Wacom driver, but it's expected that libinput will be able to handle them (still to be tested). This enables Huion HS611 media and desktop keys. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 09c332c6a412..b85585ac3372 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -711,8 +711,12 @@ static int uclogic_params_huion_init(struct uclogic_params *params, iface = to_usb_interface(hdev->dev.parent); bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; - /* If it's not a pen interface */ - if (bInterfaceNumber != 0) { + /* If it's a custom keyboard interface */ + if (bInterfaceNumber == 1) { + /* Keep everything intact */ + goto output; + /* Else, if it's not a pen interface */ + } else if (bInterfaceNumber != 0) { uclogic_params_init_invalid(&p); goto output; } -- cgit v1.2.3-59-g8ed1b From f5927973f8d667eb93b81f796039c0ef94449866 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 21 Apr 2022 19:50:51 +0200 Subject: HID: uclogic: Support disabling pen usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restore the ability to disable pen usage in hid-uclogic to support e.g. keyboard interfaces which also have pen usages for some reason, but which we don't want to rewrite report descriptors for. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 19 +++++++++++++++++++ drivers/hid/hid-uclogic-params.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 627f1d0c52f2..8ef3d1830052 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -81,6 +81,24 @@ static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, return rdesc; } +static int uclogic_input_mapping(struct hid_device *hdev, + struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, + unsigned long **bit, + int *max) +{ + struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev); + struct uclogic_params *params = &drvdata->params; + + /* Discard invalid pen usages */ + if (params->pen.usage_invalid && (field->application == HID_DG_PEN)) + return -1; + + /* Let hid-core decide what to do */ + return 0; +} + static int uclogic_input_configured(struct hid_device *hdev, struct hid_input *hi) { @@ -515,6 +533,7 @@ static struct hid_driver uclogic_driver = { .remove = uclogic_remove, .report_fixup = uclogic_report_fixup, .raw_event = uclogic_raw_event, + .input_mapping = uclogic_input_mapping, .input_configured = uclogic_input_configured, #ifdef CONFIG_PM .resume = uclogic_resume, diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index fa75efba3130..fb2001018c46 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -61,6 +61,11 @@ struct uclogic_params_pen_subreport { * Noop (preserving functionality) when filled with zeroes. */ struct uclogic_params_pen { + /* + * True if pen usage is invalid for this interface and should be + * ignored, false otherwise. + */ + bool usage_invalid; /* * Pointer to report descriptor part describing the pen inputs. * Allocated with kmalloc. NULL if the part is not specified. @@ -214,6 +219,7 @@ extern int uclogic_params_init(struct uclogic_params *params, ".desc_ptr = %p\n" \ ".desc_size = %u\n" \ ".pen = {\n" \ + "\t.usage_invalid = %s\n" \ "\t.desc_ptr = %p\n" \ "\t.desc_size = %u\n" \ "\t.id = %u\n" \ @@ -270,6 +276,7 @@ extern int uclogic_params_init(struct uclogic_params *params, ((_params)->invalid ? "true" : "false"), \ (_params)->desc_ptr, \ (_params)->desc_size, \ + ((_params)->pen.usage_invalid ? "true" : "false"), \ (_params)->pen.desc_ptr, \ (_params)->pen.desc_size, \ (_params)->pen.id, \ -- cgit v1.2.3-59-g8ed1b From 4c60bc7d1f2a908f53260bc4a0831b3ea204f327 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 21 Apr 2022 19:50:52 +0200 Subject: HID: uclogic: Disable pen usage for Huion keyboard interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disable pen usage inputs for Huion interfaces reporting on-the-frame buttons. We don't want to change those, as they mostly work, but we want to avoid creation of a mute pen interface, confusing to users. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index b85585ac3372..22f9c4f9da8a 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -713,7 +713,8 @@ static int uclogic_params_huion_init(struct uclogic_params *params, /* If it's a custom keyboard interface */ if (bInterfaceNumber == 1) { - /* Keep everything intact */ + /* Keep everything intact, but mark pen usage invalid */ + p.pen.usage_invalid = true; goto output; /* Else, if it's not a pen interface */ } else if (bInterfaceNumber != 0) { -- cgit v1.2.3-59-g8ed1b From d88591a555325f6f0ec1f28c5fe2c7f2383a4366 Mon Sep 17 00:00:00 2001 From: Joshua-Dickens Date: Fri, 29 Apr 2022 17:01:34 -0700 Subject: Hid: wacom: Fix kernel test robot warning Kernel test robot throws the following warning - >> drivers/hid/wacom_wac.c:2411:42: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] hid_warn(hdev, "Dropped %hu packets", value - wacom_wac->hid_data.sequence_number); ~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %d Explicitly casting the argument to unsigned short to silence the warning and retain the intended behavior. Reported-by: kernel test robot Signed-off-by: Joshua Dickens Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 64fe573deb9b..9470c2b0b529 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2408,7 +2408,7 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field return; case WACOM_HID_WD_SEQUENCENUMBER: if (wacom_wac->hid_data.sequence_number != value) - hid_warn(hdev, "Dropped %hu packets", value - wacom_wac->hid_data.sequence_number); + hid_warn(hdev, "Dropped %hu packets", (unsigned short)(value - wacom_wac->hid_data.sequence_number)); wacom_wac->hid_data.sequence_number = value + 1; return; } -- cgit v1.2.3-59-g8ed1b From fc4ef9d5724973193bfa5ebed181dba6de3a56db Mon Sep 17 00:00:00 2001 From: Dongliang Mu Date: Fri, 6 May 2022 15:24:25 +0800 Subject: HID: bigben: fix slab-out-of-bounds Write in bigben_probe There is a slab-out-of-bounds Write bug in hid-bigbenff driver. The problem is the driver assumes the device must have an input but some malicious devices violate this assumption. Fix this by checking hid_device's input is non-empty before its usage. Reported-by: syzkaller Signed-off-by: Dongliang Mu Signed-off-by: Jiri Kosina --- drivers/hid/hid-bigbenff.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/hid/hid-bigbenff.c b/drivers/hid/hid-bigbenff.c index 74ad8bf98bfd..e8c5e3ac9fff 100644 --- a/drivers/hid/hid-bigbenff.c +++ b/drivers/hid/hid-bigbenff.c @@ -347,6 +347,12 @@ static int bigben_probe(struct hid_device *hid, bigben->report = list_entry(report_list->next, struct hid_report, list); + if (list_empty(&hid->inputs)) { + hid_err(hid, "no inputs found\n"); + error = -ENODEV; + goto error_hw_stop; + } + hidinput = list_first_entry(&hid->inputs, struct hid_input, list); set_bit(FF_RUMBLE, hidinput->input->ffbit); -- cgit v1.2.3-59-g8ed1b From b5d7f43e97dabfa04a4be5ff027ce7da119332be Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:20 +0530 Subject: HID: amd_sfh: Add support for sensor discovery Sensor discovery status fails in case of broken sensors or platform not supported. Hence disable driver on failure of sensor discovery. Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_client.c | 11 +++++++++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 7 +++++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.h | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c index c5de0ec4f9d0..444acd9e2cd6 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c @@ -227,6 +227,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) dev_dbg(dev, "sid 0x%x status 0x%x\n", cl_data->sensor_idx[i], cl_data->sensor_sts[i]); } + if (privdata->mp2_ops->discovery_status && + privdata->mp2_ops->discovery_status(privdata) == 0) { + amd_sfh_hid_client_deinit(privdata); + for (i = 0; i < cl_data->num_hid_devices; i++) { + devm_kfree(dev, cl_data->feature_report[i]); + devm_kfree(dev, in_data->input_report[i]); + devm_kfree(dev, cl_data->report_descr[i]); + } + dev_warn(dev, "Failed to discover, sensors not enabled\n"); + return -EOPNOTSUPP; + } schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP)); return 0; diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index 6b5fd90b0bd1..e18a4efd8839 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -130,6 +130,12 @@ static int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata) return 0; } +static int amd_sfh_dis_sts_v2(struct amd_mp2_dev *privdata) +{ + return (readl(privdata->mmio + AMD_P2C_MSG(1)) & + SENSOR_DISCOVERY_STATUS_MASK) >> SENSOR_DISCOVERY_STATUS_SHIFT; +} + void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info) { union sfh_cmd_param cmd_param; @@ -245,6 +251,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = { .response = amd_sfh_wait_response_v2, .clear_intr = amd_sfh_clear_intr_v2, .init_intr = amd_sfh_irq_init_v2, + .discovery_status = amd_sfh_dis_sts_v2, }; static const struct amd_mp2_ops amd_sfh_ops = { diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h index 97b99861fae2..9aa88a91ac8d 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h @@ -39,6 +39,9 @@ #define AMD_SFH_IDLE_LOOP 200 +#define SENSOR_DISCOVERY_STATUS_MASK GENMASK(5, 3) +#define SENSOR_DISCOVERY_STATUS_SHIFT 3 + /* SFH Command register */ union sfh_cmd_base { u32 ul; @@ -143,5 +146,6 @@ struct amd_mp2_ops { int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts); void (*clear_intr)(struct amd_mp2_dev *privdata); int (*init_intr)(struct amd_mp2_dev *privdata); + int (*discovery_status)(struct amd_mp2_dev *privdata); }; #endif -- cgit v1.2.3-59-g8ed1b From 696455e9d099fb024017e4d8a42b517dfd45b79e Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:21 +0530 Subject: HID: amd_sfh: Add sensor name by index for debug info Adding get sensor name for debug info. This will make debug messages clearer. Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_client.c | 34 ++++++++++++++++++++++++++------ drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 10 ++++++---- drivers/hid/amd-sfh-hid/amd_sfh_pcie.h | 1 + 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c index 444acd9e2cd6..0f770a2b47ff 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c @@ -141,6 +141,24 @@ u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts) return sensor_sts; } +const char *get_sensor_name(int idx) +{ + switch (idx) { + case accel_idx: + return "accelerometer"; + case gyro_idx: + return "gyroscope"; + case mag_idx: + return "magnetometer"; + case als_idx: + return "ALS"; + case HPD_IDX: + return "HPD"; + default: + return "unknown sensor type"; + } +} + int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) { struct amd_input_data *in_data = &privdata->in_data; @@ -219,13 +237,16 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) (privdata, cl_data->sensor_idx[i], SENSOR_DISABLED); if (status != SENSOR_ENABLED) cl_data->sensor_sts[i] = SENSOR_DISABLED; - dev_dbg(dev, "sid 0x%x status 0x%x\n", - cl_data->sensor_idx[i], cl_data->sensor_sts[i]); + dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", + cl_data->sensor_idx[i], + get_sensor_name(cl_data->sensor_idx[i]), + cl_data->sensor_sts[i]); goto cleanup; } } - dev_dbg(dev, "sid 0x%x status 0x%x\n", - cl_data->sensor_idx[i], cl_data->sensor_sts[i]); + dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n", + cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), + cl_data->sensor_sts[i]); } if (privdata->mp2_ops->discovery_status && privdata->mp2_ops->discovery_status(privdata) == 0) { @@ -268,8 +289,9 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata) (privdata, cl_data->sensor_idx[i], SENSOR_DISABLED); if (status != SENSOR_ENABLED) cl_data->sensor_sts[i] = SENSOR_DISABLED; - dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x status 0x%x\n", - cl_data->sensor_idx[i], cl_data->sensor_sts[i]); + dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x (%s) status 0x%x\n", + cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), + cl_data->sensor_sts[i]); } } diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index e18a4efd8839..dadc491bbf6b 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -353,8 +353,9 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev) (mp2, cl_data->sensor_idx[i], SENSOR_ENABLED); if (status == SENSOR_ENABLED) cl_data->sensor_sts[i] = SENSOR_ENABLED; - dev_dbg(dev, "resume sid 0x%x status 0x%x\n", - cl_data->sensor_idx[i], cl_data->sensor_sts[i]); + dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n", + cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), + cl_data->sensor_sts[i]); } } @@ -378,8 +379,9 @@ static int __maybe_unused amd_mp2_pci_suspend(struct device *dev) (mp2, cl_data->sensor_idx[i], SENSOR_DISABLED); if (status != SENSOR_ENABLED) cl_data->sensor_sts[i] = SENSOR_DISABLED; - dev_dbg(dev, "suspend sid 0x%x status 0x%x\n", - cl_data->sensor_idx[i], cl_data->sensor_sts[i]); + dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n", + cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), + cl_data->sensor_sts[i]); } } diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h index 9aa88a91ac8d..8c760526132a 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h @@ -138,6 +138,7 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata); u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts); void amd_mp2_suspend(struct amd_mp2_dev *mp2); void amd_mp2_resume(struct amd_mp2_dev *mp2); +const char *get_sensor_name(int idx); struct amd_mp2_ops { void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info); -- cgit v1.2.3-59-g8ed1b From 206c3c2d85de8847fb732a5fb71443bacd287216 Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:22 +0530 Subject: HID: amd_sfh: Modify the bus name Modifying the amd-sfh bus name to meaningful name. Fixes: 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)") Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_hid.c | 2 +- drivers/hid/amd-sfh-hid/amd_sfh_hid.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c index 2bf97b6ac973..6e487e41f4dd 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c @@ -141,7 +141,7 @@ int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data) hid->driver_data = hid_data; cli_data->hid_sensor_hubs[cur_hid_dev] = hid; - hid->bus = BUS_AMD_AMDTP; + hid->bus = BUS_AMD_SFH; hid->vendor = AMD_SFH_HID_VENDOR; hid->product = AMD_SFH_HID_PRODUCT; snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-amdtp", diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h index c60abd38054c..cb04f47c8648 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h @@ -12,7 +12,7 @@ #define AMDSFH_HID_H #define MAX_HID_DEVICES 5 -#define BUS_AMD_AMDTP 0x20 +#define BUS_AMD_SFH 0x20 #define AMD_SFH_HID_VENDOR 0x1022 #define AMD_SFH_HID_PRODUCT 0x0001 -- cgit v1.2.3-59-g8ed1b From 10f865cdcf37d26ae5e9595a7b4f9e06538e84e5 Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:23 +0530 Subject: HID: amd_sfh: Modify the hid name Modifying the amd-sfh hid name to meaningful name. Fixes: 4b2c53d93a4b ("SFH:Transport Driver to add support of AMD Sensor Fusion Hub (SFH)") Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_hid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c index 6e487e41f4dd..e2a9679e32be 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c @@ -144,7 +144,7 @@ int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data) hid->bus = BUS_AMD_SFH; hid->vendor = AMD_SFH_HID_VENDOR; hid->product = AMD_SFH_HID_PRODUCT; - snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-amdtp", + snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-amdsfh", hid->vendor, hid->product); rc = hid_add_device(hid); -- cgit v1.2.3-59-g8ed1b From 863fcfec6203363d92190ff0b8c93e6030e41fa9 Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:24 +0530 Subject: HID: amd_sfh: Add physical location to HID device when HID device is loaded a wrong string is shown as physical location is not declared. ``` hid-generic 0020:1022:0001.0009: hidraw4: HID v0.00 Device [hid-amdtp 1022:0001] on ``` Hence use amd sfh driver name or device name which is connected to the HID device. Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_hid.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c index e2a9679e32be..1089134030b0 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c @@ -12,6 +12,7 @@ #include #include "amd_sfh_hid.h" +#include "amd_sfh_pcie.h" #define AMD_SFH_RESPONSE_TIMEOUT 1500 @@ -120,6 +121,8 @@ static struct hid_ll_driver amdtp_hid_ll_driver = { int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data) { + struct amd_mp2_dev *mp2 = container_of(cli_data->in_data, struct amd_mp2_dev, in_data); + struct device *dev = &mp2->pdev->dev; struct hid_device *hid; struct amdtp_hid_data *hid_data; int rc; @@ -141,6 +144,8 @@ int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data) hid->driver_data = hid_data; cli_data->hid_sensor_hubs[cur_hid_dev] = hid; + strscpy(hid->phys, dev->driver ? dev->driver->name : dev_name(dev), + sizeof(hid->phys)); hid->bus = BUS_AMD_SFH; hid->vendor = AMD_SFH_HID_VENDOR; hid->product = AMD_SFH_HID_PRODUCT; -- cgit v1.2.3-59-g8ed1b From a8641d7d8500d41d312350470464e03f3df3672a Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:25 +0530 Subject: HID: amd_sfh: Move bus declaration outside of amd-sfh This should allow external drivers to reference this bus ID reservation and detect data coming from amd-sfh. Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/amd-sfh-hid/amd_sfh_hid.h | 1 - include/uapi/linux/input.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h index cb04f47c8648..ad264db63180 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h @@ -12,7 +12,6 @@ #define AMDSFH_HID_H #define MAX_HID_DEVICES 5 -#define BUS_AMD_SFH 0x20 #define AMD_SFH_HID_VENDOR 0x1022 #define AMD_SFH_HID_PRODUCT 0x0001 diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h index ee3127461ee0..ef4257ab3026 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h @@ -271,6 +271,7 @@ struct input_mask { #define BUS_RMI 0x1D #define BUS_CEC 0x1E #define BUS_INTEL_ISHTP 0x1F +#define BUS_AMD_SFH 0x20 /* * MT_TOOL types -- cgit v1.2.3-59-g8ed1b From 806fc359a39458c54dedc28b904ca27b3fc79b19 Mon Sep 17 00:00:00 2001 From: Basavaraj Natikar Date: Mon, 9 May 2022 18:50:26 +0530 Subject: HID: core: Display "SENSOR HUB" for sensor hub bus string in hid_info Currently sensor hub shows "", but this is a pretty common type available in many notebooks. Hence using the string "SENSOR HUB". Signed-off-by: Mario Limonciello Signed-off-by: Basavaraj Natikar Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index db925794fbe6..00154a1cd2d8 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2222,6 +2222,10 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) case BUS_VIRTUAL: bus = "VIRTUAL"; break; + case BUS_INTEL_ISHTP: + case BUS_AMD_SFH: + bus = "SENSOR HUB"; + break; default: bus = ""; } -- cgit v1.2.3-59-g8ed1b From a228809fa6f39c3fa46ac6b929024686750f7a09 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:40 +0200 Subject: HID: uclogic: Move param printing to a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move parameter printing from a format string/argument list to a function to allow printing the full parameters, which now wouldn't fit into a single print call. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 4 +- drivers/hid/hid-uclogic-params.c | 89 +++++++++++++++++++++++++++++- drivers/hid/hid-uclogic-params.h | 116 ++------------------------------------- 3 files changed, 93 insertions(+), 116 deletions(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 8ef3d1830052..8cac5944e63f 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -209,8 +209,8 @@ static int uclogic_probe(struct hid_device *hdev, goto failure; } params_initialized = true; - hid_dbg(hdev, "parameters:\n" UCLOGIC_PARAMS_FMT_STR, - UCLOGIC_PARAMS_FMT_ARGS(&drvdata->params)); + hid_dbg(hdev, "parameters:\n"); + uclogic_params_hid_dbg(hdev, &drvdata->params); if (drvdata->params.invalid) { hid_info(hdev, "interface is invalid, ignoring\n"); rc = -ENODEV; diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 22f9c4f9da8a..1d9168cc7dc0 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -29,8 +29,8 @@ * Returns: * The string representing the type, or NULL if the type is unknown. */ -const char *uclogic_params_pen_inrange_to_str( - enum uclogic_params_pen_inrange inrange) +static const char *uclogic_params_pen_inrange_to_str( + enum uclogic_params_pen_inrange inrange) { switch (inrange) { case UCLOGIC_PARAMS_PEN_INRANGE_NORMAL: @@ -44,6 +44,91 @@ const char *uclogic_params_pen_inrange_to_str( } } +/** + * Dump tablet interface pen parameters with hid_dbg(), indented with one tab. + * + * @hdev: The HID device the pen parameters describe. + * @pen: The pen parameters to dump. + */ +static void uclogic_params_pen_hid_dbg(const struct hid_device *hdev, + const struct uclogic_params_pen *pen) +{ + size_t i; + + hid_dbg(hdev, "\t.usage_invalid = %s\n", + (pen->usage_invalid ? "true" : "false")); + hid_dbg(hdev, "\t.desc_ptr = %p\n", pen->desc_ptr); + hid_dbg(hdev, "\t.desc_size = %u\n", pen->desc_size); + hid_dbg(hdev, "\t.id = %u\n", pen->id); + hid_dbg(hdev, "\t.subreport_list = {\n"); + for (i = 0; i < ARRAY_SIZE(pen->subreport_list); i++) { + hid_dbg(hdev, "\t\t{0x%02hhx, %hhu}%s\n", + pen->subreport_list[i].value, + pen->subreport_list[i].id, + i < (ARRAY_SIZE(pen->subreport_list) - 1) ? "," : ""); + } + hid_dbg(hdev, "\t}\n"); + hid_dbg(hdev, "\t.inrange = %s\n", + uclogic_params_pen_inrange_to_str(pen->inrange)); + hid_dbg(hdev, "\t.fragmented_hires = %s\n", + (pen->fragmented_hires ? "true" : "false")); + hid_dbg(hdev, "\t.tilt_y_flipped = %s\n", + (pen->tilt_y_flipped ? "true" : "false")); +} + +/** + * Dump tablet interface frame parameters with hid_dbg(), indented with two + * tabs. + * + * @hdev: The HID device the pen parameters describe. + * @frame: The frame parameters to dump. + */ +static void uclogic_params_frame_hid_dbg( + const struct hid_device *hdev, + const struct uclogic_params_frame *frame) +{ + hid_dbg(hdev, "\t\t.desc_ptr = %p\n", frame->desc_ptr); + hid_dbg(hdev, "\t\t.desc_size = %u\n", frame->desc_size); + hid_dbg(hdev, "\t\t.id = %u\n", frame->id); + hid_dbg(hdev, "\t\t.suffix = %s\n", frame->suffix); + hid_dbg(hdev, "\t\t.re_lsb = %u\n", frame->re_lsb); + hid_dbg(hdev, "\t\t.dev_id_byte = %u\n", frame->dev_id_byte); + hid_dbg(hdev, "\t\t.touch_ring_byte = %u\n", frame->touch_ring_byte); + hid_dbg(hdev, "\t\t.touch_ring_max = %hhd\n", frame->touch_ring_max); + hid_dbg(hdev, "\t\t.touch_ring_flip_at = %hhd\n", + frame->touch_ring_flip_at); + hid_dbg(hdev, "\t\t.bitmap_dial_byte = %u\n", + frame->bitmap_dial_byte); +} + +/** + * Dump tablet interface parameters with hid_dbg(). + * + * @hdev: The HID device the parameters describe. + * @params: The parameters to dump. + */ +void uclogic_params_hid_dbg(const struct hid_device *hdev, + const struct uclogic_params *params) +{ + size_t i; + + hid_dbg(hdev, ".invalid = %s\n", + params->invalid ? "true" : "false"); + hid_dbg(hdev, ".desc_ptr = %p\n", params->desc_ptr); + hid_dbg(hdev, ".desc_size = %u\n", params->desc_size); + hid_dbg(hdev, ".pen = {\n"); + uclogic_params_pen_hid_dbg(hdev, ¶ms->pen); + hid_dbg(hdev, "\t}\n"); + hid_dbg(hdev, ".frame_list = {\n"); + for (i = 0; i < ARRAY_SIZE(params->frame_list); i++) { + hid_dbg(hdev, "\t{\n"); + uclogic_params_frame_hid_dbg(hdev, ¶ms->frame_list[i]); + hid_dbg(hdev, "\t}%s\n", + i < (ARRAY_SIZE(params->frame_list) - 1) ? "," : ""); + } + hid_dbg(hdev, "}\n"); +} + /** * uclogic_params_get_str_desc - retrieve a string descriptor from a HID * device interface, putting it into a kmalloc-allocated buffer as is, without diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index fb2001018c46..c7573f70d35c 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -29,11 +29,6 @@ enum uclogic_params_pen_inrange { UCLOGIC_PARAMS_PEN_INRANGE_NONE, }; -/* Convert a pen in-range reporting type to a string */ -extern const char *uclogic_params_pen_inrange_to_str( - enum uclogic_params_pen_inrange inrange); - - /* * Pen report's subreport data. */ @@ -213,113 +208,6 @@ struct uclogic_params { extern int uclogic_params_init(struct uclogic_params *params, struct hid_device *hdev); -/* Tablet interface parameters *printf format string */ -#define UCLOGIC_PARAMS_FMT_STR \ - ".invalid = %s\n" \ - ".desc_ptr = %p\n" \ - ".desc_size = %u\n" \ - ".pen = {\n" \ - "\t.usage_invalid = %s\n" \ - "\t.desc_ptr = %p\n" \ - "\t.desc_size = %u\n" \ - "\t.id = %u\n" \ - "\t.subreport_list = {\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t\t{0x%02hhx, %hhu},\n" \ - "\t}\n" \ - "\t.inrange = %s\n" \ - "\t.fragmented_hires = %s\n" \ - "\t.tilt_y_flipped = %s\n" \ - "}\n" \ - ".frame_list = {\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t\t.bitmap_dial_byte = %u\n" \ - "\t},\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t\t.bitmap_dial_byte = %u\n" \ - "\t},\n" \ - "\t{\n" \ - "\t\t.desc_ptr = %p\n" \ - "\t\t.desc_size = %u\n" \ - "\t\t.id = %u\n" \ - "\t\t.suffix = %s\n" \ - "\t\t.re_lsb = %u\n" \ - "\t\t.dev_id_byte = %u\n" \ - "\t\t.touch_ring_byte = %u\n" \ - "\t\t.touch_ring_max = %hhd\n" \ - "\t\t.touch_ring_flip_at = %hhd\n" \ - "\t\t.bitmap_dial_byte = %u\n" \ - "\t},\n" \ - "}\n" - -/* Tablet interface parameters *printf format arguments */ -#define UCLOGIC_PARAMS_FMT_ARGS(_params) \ - ((_params)->invalid ? "true" : "false"), \ - (_params)->desc_ptr, \ - (_params)->desc_size, \ - ((_params)->pen.usage_invalid ? "true" : "false"), \ - (_params)->pen.desc_ptr, \ - (_params)->pen.desc_size, \ - (_params)->pen.id, \ - (_params)->pen.subreport_list[0].value, \ - (_params)->pen.subreport_list[0].id, \ - (_params)->pen.subreport_list[1].value, \ - (_params)->pen.subreport_list[1].id, \ - (_params)->pen.subreport_list[2].value, \ - (_params)->pen.subreport_list[2].id, \ - uclogic_params_pen_inrange_to_str((_params)->pen.inrange), \ - ((_params)->pen.fragmented_hires ? "true" : "false"), \ - ((_params)->pen.tilt_y_flipped ? "true" : "false"), \ - (_params)->frame_list[0].desc_ptr, \ - (_params)->frame_list[0].desc_size, \ - (_params)->frame_list[0].id, \ - (_params)->frame_list[0].suffix, \ - (_params)->frame_list[0].re_lsb, \ - (_params)->frame_list[0].dev_id_byte, \ - (_params)->frame_list[0].touch_ring_byte, \ - (_params)->frame_list[0].touch_ring_max, \ - (_params)->frame_list[0].touch_ring_flip_at, \ - (_params)->frame_list[0].bitmap_dial_byte, \ - (_params)->frame_list[1].desc_ptr, \ - (_params)->frame_list[1].desc_size, \ - (_params)->frame_list[1].id, \ - (_params)->frame_list[1].suffix, \ - (_params)->frame_list[1].re_lsb, \ - (_params)->frame_list[1].dev_id_byte, \ - (_params)->frame_list[1].touch_ring_byte, \ - (_params)->frame_list[1].touch_ring_max, \ - (_params)->frame_list[1].touch_ring_flip_at, \ - (_params)->frame_list[1].bitmap_dial_byte, \ - (_params)->frame_list[2].desc_ptr, \ - (_params)->frame_list[2].desc_size, \ - (_params)->frame_list[2].id, \ - (_params)->frame_list[2].suffix, \ - (_params)->frame_list[2].re_lsb, \ - (_params)->frame_list[2].dev_id_byte, \ - (_params)->frame_list[2].touch_ring_byte, \ - (_params)->frame_list[2].touch_ring_max, \ - (_params)->frame_list[2].touch_ring_flip_at, \ - (_params)->frame_list[2].bitmap_dial_byte - /* Get a replacement report descriptor for a tablet's interface. */ extern int uclogic_params_get_desc(const struct uclogic_params *params, __u8 **pdesc, @@ -328,4 +216,8 @@ extern int uclogic_params_get_desc(const struct uclogic_params *params, /* Free resources used by tablet interface's parameters */ extern void uclogic_params_cleanup(struct uclogic_params *params); +/* Dump tablet interface parameters with hid_dbg() */ +extern void uclogic_params_hid_dbg(const struct hid_device *hdev, + const struct uclogic_params *params); + #endif /* _HID_UCLOGIC_PARAMS_H */ -- cgit v1.2.3-59-g8ed1b From 945d5dd5a5f88b99c090d80948f589416e2ceb37 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:41 +0200 Subject: HID: uclogic: Return raw parameters from v2 pen init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return the raw parameters buffer from uclogic_params_pen_init_v2(), if requested, as a way to identify the tablet. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 92 +++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 1d9168cc7dc0..91379d7cd33e 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -338,28 +338,45 @@ static s32 uclogic_params_get_le24(const void *p) * uclogic_params_pen_init_v2() - initialize tablet interface pen * input and retrieve its parameters from the device, using v2 protocol. * - * @pen: Pointer to the pen parameters to initialize (to be - * cleaned up with uclogic_params_pen_cleanup()). Not modified in - * case of error, or if parameters are not found. Cannot be NULL. - * @pfound: Location for a flag which is set to true if the parameters - * were found, and to false if not (e.g. device was - * incompatible). Not modified in case of error. Cannot be NULL. - * @hdev: The HID device of the tablet interface to initialize and get - * parameters from. Cannot be NULL. + * @pen: Pointer to the pen parameters to initialize (to be + * cleaned up with uclogic_params_pen_cleanup()). Not + * modified in case of error, or if parameters are not + * found. Cannot be NULL. + * @pfound: Location for a flag which is set to true if the + * parameters were found, and to false if not (e.g. + * device was incompatible). Not modified in case of + * error. Cannot be NULL. + * @pparams_ptr: Location for a kmalloc'ed pointer to the retrieved raw + * parameters, which could be used to identify the tablet + * to some extent. Should be freed with kfree after use. + * NULL, if not needed. Not modified in case of error. + * Only set if *pfound is set to true. + * @pparams_len: Location for the length of the retrieved raw + * parameters. NULL, if not needed. Not modified in case + * of error. Only set if *pfound is set to true. + * @hdev: The HID device of the tablet interface to initialize + * and get parameters from. Cannot be NULL. * * Returns: * Zero, if successful. A negative errno code on error. */ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, bool *pfound, + __u8 **pparams_ptr, + size_t *pparams_len, struct hid_device *hdev) { int rc; bool found = false; - /* Buffer for (part of) the string descriptor */ + /* Buffer for (part of) the parameter string descriptor */ __u8 *buf = NULL; - /* Descriptor length required */ - const int len = 18; + /* Parameter string descriptor required length */ + const int params_len_min = 18; + /* Parameter string descriptor accepted length */ + const int params_len_max = 32; + /* Parameter string descriptor received length */ + int params_len; + size_t i; s32 resolution; /* Pen report descriptor template parameters */ s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM]; @@ -377,7 +394,7 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, * the Windows driver traffic. * NOTE: This enables fully-functional tablet mode. */ - rc = uclogic_params_get_str_desc(&buf, hdev, 200, len); + rc = uclogic_params_get_str_desc(&buf, hdev, 200, params_len_max); if (rc == -EPIPE) { hid_dbg(hdev, "string descriptor with pen parameters not found, assuming not compatible\n"); @@ -385,27 +402,28 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, } else if (rc < 0) { hid_err(hdev, "failed retrieving pen parameters: %d\n", rc); goto cleanup; - } else if (rc != len) { + } else if (rc < params_len_min) { hid_dbg(hdev, - "string descriptor with pen parameters has invalid length (got %d, expected %d), assuming not compatible\n", - rc, len); + "string descriptor with pen parameters is too short (got %d, expected at least %d), assuming not compatible\n", + rc, params_len_min); + goto finish; + } + + params_len = rc; + + /* + * Check it's not just a catch-all UTF-16LE-encoded ASCII + * string (such as the model name) some tablets put into all + * unknown string descriptors. + */ + for (i = 2; + i < params_len && + (buf[i] >= 0x20 && buf[i] < 0x7f && buf[i + 1] == 0); + i += 2); + if (i >= params_len) { + hid_dbg(hdev, + "string descriptor with pen parameters seems to contain only text, assuming not compatible\n"); goto finish; - } else { - size_t i; - /* - * Check it's not just a catch-all UTF-16LE-encoded ASCII - * string (such as the model name) some tablets put into all - * unknown string descriptors. - */ - for (i = 2; - i < len && - (buf[i] >= 0x20 && buf[i] < 0x7f && buf[i + 1] == 0); - i += 2); - if (i >= len) { - hid_dbg(hdev, - "string descriptor with pen parameters seems to contain only text, assuming not compatible\n"); - goto finish; - } } /* @@ -429,8 +447,6 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 / resolution; } - kfree(buf); - buf = NULL; /* * Generate pen report descriptor @@ -456,6 +472,13 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen, pen->fragmented_hires = true; pen->tilt_y_flipped = true; found = true; + if (pparams_ptr != NULL) { + *pparams_ptr = buf; + buf = NULL; + } + if (pparams_len != NULL) + *pparams_len = params_len; + finish: *pfound = found; rc = 0; @@ -828,7 +851,8 @@ static int uclogic_params_huion_init(struct uclogic_params *params, "transition firmware detected, not probing pen v2 parameters\n"); } else { /* Try to probe v2 pen parameters */ - rc = uclogic_params_pen_init_v2(&p.pen, &found, hdev); + rc = uclogic_params_pen_init_v2(&p.pen, &found, + NULL, NULL, hdev); if (rc != 0) { hid_err(hdev, "failed probing pen v2 parameters: %d\n", rc); -- cgit v1.2.3-59-g8ed1b From caf7e93479c73374a9fcad29f90477280444584e Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:42 +0200 Subject: HID: uclogic: Do not focus on touch ring only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Accommodate both touch ring and touch strip in naming throughout hid-uclogic by talking about abstract "touch" instead of "touch ring", wherever possible. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 20 +++++++++----------- drivers/hid/hid-uclogic-params.c | 20 ++++++++++---------- drivers/hid/hid-uclogic-params.h | 27 ++++++++++++++------------- drivers/hid/hid-uclogic-rdesc.c | 4 ++-- drivers/hid/hid-uclogic-rdesc.h | 8 ++++---- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 8cac5944e63f..cc53625ed1f7 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -134,7 +134,7 @@ static int uclogic_input_configured(struct hid_device *hdev, * Disable EV_MSC reports for touch ring interfaces to * make the Wacom driver pickup touch ring extents */ - if (frame->touch_ring_byte > 0) + if (frame->touch_byte > 0) __clear_bit(EV_MSC, hi->input->evbit); } } @@ -351,9 +351,8 @@ static int uclogic_raw_event_frame( /* If need to, and can, set pad device ID for Wacom drivers */ if (frame->dev_id_byte > 0 && frame->dev_id_byte < size) { /* If we also have a touch ring and the finger left it */ - if (frame->touch_ring_byte > 0 && - frame->touch_ring_byte < size && - data[frame->touch_ring_byte] == 0) { + if (frame->touch_byte > 0 && frame->touch_byte < size && + data[frame->touch_byte] == 0) { data[frame->dev_id_byte] = 0; } else { data[frame->dev_id_byte] = 0xf; @@ -387,16 +386,15 @@ static int uclogic_raw_event_frame( } /* If need to, and can, transform the touch ring reports */ - if (frame->touch_ring_byte > 0 && frame->touch_ring_byte < size && - frame->touch_ring_flip_at != 0) { - __s8 value = data[frame->touch_ring_byte]; - + if (frame->touch_byte > 0 && frame->touch_byte < size && + frame->touch_flip_at != 0) { + __s8 value = data[frame->touch_byte]; if (value != 0) { - value = frame->touch_ring_flip_at - value; + value = frame->touch_flip_at - value; if (value < 0) - value = frame->touch_ring_max + value; + value = frame->touch_max + value; - data[frame->touch_ring_byte] = value; + data[frame->touch_byte] = value; } } diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 91379d7cd33e..459f15288ccc 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -93,10 +93,10 @@ static void uclogic_params_frame_hid_dbg( hid_dbg(hdev, "\t\t.suffix = %s\n", frame->suffix); hid_dbg(hdev, "\t\t.re_lsb = %u\n", frame->re_lsb); hid_dbg(hdev, "\t\t.dev_id_byte = %u\n", frame->dev_id_byte); - hid_dbg(hdev, "\t\t.touch_ring_byte = %u\n", frame->touch_ring_byte); - hid_dbg(hdev, "\t\t.touch_ring_max = %hhd\n", frame->touch_ring_max); - hid_dbg(hdev, "\t\t.touch_ring_flip_at = %hhd\n", - frame->touch_ring_flip_at); + hid_dbg(hdev, "\t\t.touch_byte = %u\n", frame->touch_byte); + hid_dbg(hdev, "\t\t.touch_max = %hhd\n", frame->touch_max); + hid_dbg(hdev, "\t\t.touch_flip_at = %hhd\n", + frame->touch_flip_at); hid_dbg(hdev, "\t\t.bitmap_dial_byte = %u\n", frame->bitmap_dial_byte); } @@ -877,7 +877,7 @@ static int uclogic_params_huion_init(struct uclogic_params *params, &p.frame_list[1], uclogic_rdesc_v2_frame_touch_ring_arr, uclogic_rdesc_v2_frame_touch_ring_size, - UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID); + UCLOGIC_RDESC_V2_FRAME_TOUCH_ID); if (rc != 0) { hid_err(hdev, "failed creating v2 frame touch ring parameters: %d\n", @@ -886,10 +886,10 @@ static int uclogic_params_huion_init(struct uclogic_params *params, } p.frame_list[1].suffix = "Touch Ring"; p.frame_list[1].dev_id_byte = - UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_DEV_ID_BYTE; - p.frame_list[1].touch_ring_byte = 5; - p.frame_list[1].touch_ring_max = 12; - p.frame_list[1].touch_ring_flip_at = 6; + UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE; + p.frame_list[1].touch_byte = 5; + p.frame_list[1].touch_max = 12; + p.frame_list[1].touch_flip_at = 6; /* Create v2 frame dial parameters */ rc = uclogic_params_frame_init_with_desc( @@ -917,7 +917,7 @@ static int uclogic_params_huion_init(struct uclogic_params *params, UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID; p.pen.subreport_list[1].value = 0xf0; p.pen.subreport_list[1].id = - UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID; + UCLOGIC_RDESC_V2_FRAME_TOUCH_ID; p.pen.subreport_list[2].value = 0xf1; p.pen.subreport_list[2].id = UCLOGIC_RDESC_V2_FRAME_DIAL_ID; diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index c7573f70d35c..5bef8daaa607 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -128,31 +128,32 @@ struct uclogic_params_frame { * Offset of the Wacom-style device ID byte in the report, to be set * to pad device ID (0xf), for compatibility with Wacom drivers. Zero * if no changes to the report should be made. The ID byte will be set - * to zero whenever the byte pointed by "touch_ring_byte" is zero, if + * to zero whenever the byte pointed by "touch_byte" is zero, if * the latter is valid. Only valid if "id" is not zero. */ unsigned int dev_id_byte; /* - * Offset of the touch ring state byte, in the report. + * Offset of the touch ring/strip state byte, in the report. * Zero if not present. If dev_id_byte is also valid and non-zero, * then the device ID byte will be cleared when the byte pointed to by * this offset is zero. Only valid if "id" is not zero. */ - unsigned int touch_ring_byte; - - /* - * Maximum value of the touch ring report. - * The minimum valid value is considered to be one, - * with zero being out-of-proximity (finger lift) value. - */ - __s8 touch_ring_max; - + unsigned int touch_byte; /* - * The value to anchor the reversed reports at. + * The value to anchor the reversed touch ring/strip reports at. * I.e. one, if the reports should be flipped without offset. * Zero if no reversal should be done. + * Only valid if "touch_byte" is valid and not zero. + */ + __s8 touch_flip_at; + /* + * Maximum value of the touch ring/strip report around which the value + * should be wrapped when flipping according to "touch_flip_at". + * The minimum valid value is considered to be one, with zero being + * out-of-proximity (finger lift) value. + * Only valid if "touch_flip_at" is valid and not zero. */ - __s8 touch_ring_flip_at; + __s8 touch_max; /* * Offset of the bitmap dial byte, in the report. Zero if not present. * Only valid if "id" is not zero. A bitmap dial sends reports with a diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index dd792160fe7e..e2bd3a91e6fd 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -718,8 +718,8 @@ const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[] = { 0x05, 0x01, /* Usage Page (Desktop), */ 0x09, 0x07, /* Usage (Keypad), */ 0xA1, 0x01, /* Collection (Application), */ - 0x85, UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID, - /* Report ID (DIAL_ID), */ + 0x85, UCLOGIC_RDESC_V2_FRAME_TOUCH_ID, + /* Report ID (TOUCH_ID), */ 0x14, /* Logical Minimum (0), */ 0x05, 0x0D, /* Usage Page (Digitizer), */ 0x09, 0x39, /* Usage (Tablet Function Keys), */ diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index 2ab6b7d5f5af..b7bbaa70261e 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -131,15 +131,15 @@ extern const size_t uclogic_rdesc_v1_frame_size; extern const __u8 uclogic_rdesc_v2_frame_buttons_arr[]; extern const size_t uclogic_rdesc_v2_frame_buttons_size; -/* Report ID for tweaked v2 frame touch ring reports */ -#define UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_ID 0xf8 +/* Report ID for tweaked v2 frame touch ring/strip reports */ +#define UCLOGIC_RDESC_V2_FRAME_TOUCH_ID 0xf8 /* Fixed report descriptor for (tweaked) v2 frame touch ring reports */ extern const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[]; extern const size_t uclogic_rdesc_v2_frame_touch_ring_size; -/* Device ID byte offset in v2 frame touch ring reports */ -#define UCLOGIC_RDESC_V2_FRAME_TOUCH_RING_DEV_ID_BYTE 0x4 +/* Device ID byte offset in v2 frame touch ring/strip reports */ +#define UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE 0x4 /* Report ID for tweaked v2 frame dial reports */ #define UCLOGIC_RDESC_V2_FRAME_DIAL_ID 0xf9 -- cgit v1.2.3-59-g8ed1b From fbc08b4e8ea5582029dc3c05c954d4d157e4d3f8 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:43 +0200 Subject: HID: uclogic: Always shift touch reports to zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always decrement touch report values to have the range start with zero, regardless if flipped or not. This fixes the future non-flipped touch strip reports. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 15 ++++++++------- drivers/hid/hid-uclogic-params.c | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index cc53625ed1f7..c4ab94d58a0f 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -386,15 +386,16 @@ static int uclogic_raw_event_frame( } /* If need to, and can, transform the touch ring reports */ - if (frame->touch_byte > 0 && frame->touch_byte < size && - frame->touch_flip_at != 0) { + if (frame->touch_byte > 0 && frame->touch_byte < size) { __s8 value = data[frame->touch_byte]; - if (value != 0) { - value = frame->touch_flip_at - value; - if (value < 0) - value = frame->touch_max + value; - data[frame->touch_byte] = value; + if (value != 0) { + if (frame->touch_flip_at != 0) { + value = frame->touch_flip_at - value; + if (value <= 0) + value = frame->touch_max + value; + } + data[frame->touch_byte] = value - 1; } } diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 459f15288ccc..163efd026881 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -889,7 +889,7 @@ static int uclogic_params_huion_init(struct uclogic_params *params, UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE; p.frame_list[1].touch_byte = 5; p.frame_list[1].touch_max = 12; - p.frame_list[1].touch_flip_at = 6; + p.frame_list[1].touch_flip_at = 7; /* Create v2 frame dial parameters */ rc = uclogic_params_frame_init_with_desc( -- cgit v1.2.3-59-g8ed1b From 118dfdeaa3c64c781d0219fd58a65dc31b97c3f5 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:44 +0200 Subject: HID: uclogic: Differentiate touch ring and touch strip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve support for touch strips. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-params.c | 84 ++++++++++++++++++++++++++++------------ drivers/hid/hid-uclogic-rdesc.c | 48 +++++++++++++++++++++++ drivers/hid/hid-uclogic-rdesc.h | 4 ++ 3 files changed, 112 insertions(+), 24 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 163efd026881..7db63bb77158 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -808,6 +808,14 @@ static int uclogic_params_huion_init(struct uclogic_params *params, static const char transition_ver[] = "HUION_T153_160607"; char *ver_ptr = NULL; const size_t ver_len = sizeof(transition_ver) + 1; + __u8 *params_ptr = NULL; + size_t params_len = 0; + /* Parameters string descriptor of a model with touch ring (HS610) */ + const __u8 touch_ring_model_params_buf[] = { + 0x13, 0x03, 0x70, 0xC6, 0x00, 0x06, 0x7C, 0x00, + 0xFF, 0x1F, 0xD8, 0x13, 0x03, 0x0D, 0x10, 0x01, + 0x04, 0x3C, 0x3E + }; /* Check arguments */ if (params == NULL || hdev == NULL) { @@ -852,7 +860,8 @@ static int uclogic_params_huion_init(struct uclogic_params *params, } else { /* Try to probe v2 pen parameters */ rc = uclogic_params_pen_init_v2(&p.pen, &found, - NULL, NULL, hdev); + ¶ms_ptr, ¶ms_len, + hdev); if (rc != 0) { hid_err(hdev, "failed probing pen v2 parameters: %d\n", rc); @@ -872,24 +881,58 @@ static int uclogic_params_huion_init(struct uclogic_params *params, goto cleanup; } - /* Create v2 frame touch ring parameters */ - rc = uclogic_params_frame_init_with_desc( + /* Link from pen sub-report */ + p.pen.subreport_list[0].value = 0xe0; + p.pen.subreport_list[0].id = + UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID; + + /* If this is the model with touch ring */ + if (params_ptr != NULL && + params_len == sizeof(touch_ring_model_params_buf) && + memcmp(params_ptr, touch_ring_model_params_buf, + params_len) == 0) { + /* Create touch ring parameters */ + rc = uclogic_params_frame_init_with_desc( &p.frame_list[1], uclogic_rdesc_v2_frame_touch_ring_arr, uclogic_rdesc_v2_frame_touch_ring_size, UCLOGIC_RDESC_V2_FRAME_TOUCH_ID); - if (rc != 0) { - hid_err(hdev, - "failed creating v2 frame touch ring parameters: %d\n", - rc); - goto cleanup; + if (rc != 0) { + hid_err(hdev, + "failed creating v2 frame touch ring parameters: %d\n", + rc); + goto cleanup; + } + p.frame_list[1].suffix = "Touch Ring"; + p.frame_list[1].dev_id_byte = + UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE; + p.frame_list[1].touch_byte = 5; + p.frame_list[1].touch_max = 12; + p.frame_list[1].touch_flip_at = 7; + } else { + /* Create touch strip parameters */ + rc = uclogic_params_frame_init_with_desc( + &p.frame_list[1], + uclogic_rdesc_v2_frame_touch_strip_arr, + uclogic_rdesc_v2_frame_touch_strip_size, + UCLOGIC_RDESC_V2_FRAME_TOUCH_ID); + if (rc != 0) { + hid_err(hdev, + "failed creating v2 frame touch strip parameters: %d\n", + rc); + goto cleanup; + } + p.frame_list[1].suffix = "Touch Strip"; + p.frame_list[1].dev_id_byte = + UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE; + p.frame_list[1].touch_byte = 5; + p.frame_list[1].touch_max = 8; } - p.frame_list[1].suffix = "Touch Ring"; - p.frame_list[1].dev_id_byte = - UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE; - p.frame_list[1].touch_byte = 5; - p.frame_list[1].touch_max = 12; - p.frame_list[1].touch_flip_at = 7; + + /* Link from pen sub-report */ + p.pen.subreport_list[1].value = 0xf0; + p.pen.subreport_list[1].id = + UCLOGIC_RDESC_V2_FRAME_TOUCH_ID; /* Create v2 frame dial parameters */ rc = uclogic_params_frame_init_with_desc( @@ -908,19 +951,11 @@ static int uclogic_params_huion_init(struct uclogic_params *params, UCLOGIC_RDESC_V2_FRAME_DIAL_DEV_ID_BYTE; p.frame_list[2].bitmap_dial_byte = 5; - /* - * Link button and touch ring subreports from pen - * reports - */ - p.pen.subreport_list[0].value = 0xe0; - p.pen.subreport_list[0].id = - UCLOGIC_RDESC_V2_FRAME_BUTTONS_ID; - p.pen.subreport_list[1].value = 0xf0; - p.pen.subreport_list[1].id = - UCLOGIC_RDESC_V2_FRAME_TOUCH_ID; + /* Link from pen sub-report */ p.pen.subreport_list[2].value = 0xf1; p.pen.subreport_list[2].id = UCLOGIC_RDESC_V2_FRAME_DIAL_ID; + goto output; } hid_dbg(hdev, "pen v2 parameters not found\n"); @@ -961,6 +996,7 @@ output: memset(&p, 0, sizeof(p)); rc = 0; cleanup: + kfree(params_ptr); kfree(ver_ptr); uclogic_params_cleanup(&p); return rc; diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index e2bd3a91e6fd..3c3d4e8780dc 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -761,6 +761,54 @@ const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[] = { const size_t uclogic_rdesc_v2_frame_touch_ring_size = sizeof(uclogic_rdesc_v2_frame_touch_ring_arr); +/* Fixed report descriptor for (tweaked) v2 frame touch strip reports */ +const __u8 uclogic_rdesc_v2_frame_touch_strip_arr[] = { + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x07, /* Usage (Keypad), */ + 0xA1, 0x01, /* Collection (Application), */ + 0x85, UCLOGIC_RDESC_V2_FRAME_TOUCH_ID, + /* Report ID (TOUCH_ID), */ + 0x14, /* Logical Minimum (0), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x09, 0x39, /* Usage (Tablet Function Keys), */ + 0xA0, /* Collection (Physical), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x05, 0x09, /* Usage Page (Button), */ + 0x09, 0x01, /* Usage (01h), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x07, /* Report Count (7), */ + 0x81, 0x01, /* Input (Constant), */ + 0x75, 0x08, /* Report Size (8), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x01, /* Input (Constant), */ + 0x05, 0x0D, /* Usage Page (Digitizer), */ + 0x0A, 0xFF, 0xFF, /* Usage (FFFFh), */ + 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ + 0x95, 0x01, /* Report Count (1), */ + 0x81, 0x02, /* Input (Variable), */ + 0x05, 0x01, /* Usage Page (Desktop), */ + 0x09, 0x38, /* Usage (Wheel), */ + 0x95, 0x01, /* Report Count (1), */ + 0x15, 0x00, /* Logical Minimum (0), */ + 0x25, 0x07, /* Logical Maximum (7), */ + 0x81, 0x02, /* Input (Variable), */ + 0x09, 0x30, /* Usage (X), */ + 0x09, 0x31, /* Usage (Y), */ + 0x14, /* Logical Minimum (0), */ + 0x25, 0x01, /* Logical Maximum (1), */ + 0x75, 0x01, /* Report Size (1), */ + 0x95, 0x02, /* Report Count (2), */ + 0x81, 0x02, /* Input (Variable), */ + 0x95, 0x2E, /* Report Count (46), */ + 0x81, 0x01, /* Input (Constant), */ + 0xC0, /* End Collection, */ + 0xC0 /* End Collection */ +}; +const size_t uclogic_rdesc_v2_frame_touch_strip_size = + sizeof(uclogic_rdesc_v2_frame_touch_strip_arr); + /* Fixed report descriptor for (tweaked) v2 frame dial reports */ const __u8 uclogic_rdesc_v2_frame_dial_arr[] = { 0x05, 0x01, /* Usage Page (Desktop), */ diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h index b7bbaa70261e..0c6e95e8bde7 100644 --- a/drivers/hid/hid-uclogic-rdesc.h +++ b/drivers/hid/hid-uclogic-rdesc.h @@ -138,6 +138,10 @@ extern const size_t uclogic_rdesc_v2_frame_buttons_size; extern const __u8 uclogic_rdesc_v2_frame_touch_ring_arr[]; extern const size_t uclogic_rdesc_v2_frame_touch_ring_size; +/* Fixed report descriptor for (tweaked) v2 frame touch strip reports */ +extern const __u8 uclogic_rdesc_v2_frame_touch_strip_arr[]; +extern const size_t uclogic_rdesc_v2_frame_touch_strip_size; + /* Device ID byte offset in v2 frame touch ring/strip reports */ #define UCLOGIC_RDESC_V2_FRAME_TOUCH_DEV_ID_BYTE 0x4 -- cgit v1.2.3-59-g8ed1b From 61b1db5a14b7651e808176c17d629114763c3641 Mon Sep 17 00:00:00 2001 From: Roman Romanenko Date: Sun, 8 May 2022 18:01:45 +0200 Subject: HID: uclogic: Add pen support for XP-PEN Star 06 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to other UGEE pens, but the IDs were missing. Signed-off-by: Roman Romanenko Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-uclogic-core.c | 2 ++ drivers/hid/hid-uclogic-params.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 053853a891c5..f8b3774a3a10 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -1272,6 +1272,7 @@ #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540 0x0075 #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640 0x0094 #define USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01 0x0042 +#define USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06 0x0078 #define USB_DEVICE_ID_UGEE_TABLET_G5 0x0074 #define USB_DEVICE_ID_UGEE_TABLET_EX07S 0x0071 #define USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720 0x0055 diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index c4ab94d58a0f..c0fe66e50c58 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -521,6 +521,8 @@ static const struct hid_device_id uclogic_devices[] = { USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640) }, { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO01) }, + { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, + USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06) }, { } }; MODULE_DEVICE_TABLE(hid, uclogic_devices); diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 7db63bb77158..db838f16282d 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -1195,6 +1195,8 @@ int uclogic_params_init(struct uclogic_params *params, USB_DEVICE_ID_UGEE_XPPEN_TABLET_G540): case VID_PID(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_G640): + case VID_PID(USB_VENDOR_ID_UGEE, + USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06): case VID_PID(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_TABLET_RAINBOW_CV720): /* If this is the pen interface */ -- cgit v1.2.3-59-g8ed1b From f7d8e387d9aeff963e6691c0166269b8042b4ff9 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sun, 8 May 2022 18:01:46 +0200 Subject: HID: uclogic: Switch to Digitizer usage for styluses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The (incorrect) "Pen" (0x02) application usage used in replacement report descriptors throughout the drivers leads to all tablets recognized as a "direct" input device (i.e. a tablet monitor) by recent kernels, which messes up desktop environments [1]. Replace the application usage with "Digitizer" (0x01) for each non-display graphics tablet. [1] https://lore.kernel.org/linux-input/f39ce5d5-bd5b-bd3f-3ea2-9b2a89ba1eb1@gmail.com/ Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-kye.c | 12 ++++++------ drivers/hid/hid-uclogic-rdesc.c | 18 +++++++++--------- drivers/hid/hid-viewsonic.c | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c index f46616390a98..da903138eee4 100644 --- a/drivers/hid/hid-kye.c +++ b/drivers/hid/hid-kye.c @@ -33,7 +33,7 @@ static __u8 easypen_i405x_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -91,7 +91,7 @@ static __u8 mousepen_i608x_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -190,7 +190,7 @@ static __u8 mousepen_i608x_v2_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -289,7 +289,7 @@ static __u8 easypen_m610x_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -368,7 +368,7 @@ static __u8 pensketch_m912_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -497,7 +497,7 @@ static __u8 easypen_m406xe_rdesc_fixed[] = { 0xB1, 0x02, /* Feature (Variable), */ 0xC0, /* End Collection, */ 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x10, /* Report ID (16), */ 0x09, 0x20, /* Usage (Stylus), */ diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c index 3c3d4e8780dc..13f9ce73f1b1 100644 --- a/drivers/hid/hid-uclogic-rdesc.c +++ b/drivers/hid/hid-uclogic-rdesc.c @@ -21,7 +21,7 @@ /* Fixed WP4030U report descriptor */ __u8 uclogic_rdesc_wp4030u_fixed_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -66,7 +66,7 @@ const size_t uclogic_rdesc_wp4030u_fixed_size = /* Fixed WP5540U report descriptor */ __u8 uclogic_rdesc_wp5540u_fixed_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -143,7 +143,7 @@ const size_t uclogic_rdesc_wp5540u_fixed_size = /* Fixed WP8060U report descriptor */ __u8 uclogic_rdesc_wp8060u_fixed_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -220,7 +220,7 @@ const size_t uclogic_rdesc_wp8060u_fixed_size = /* Fixed WP1062 report descriptor */ __u8 uclogic_rdesc_wp1062_fixed_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -268,7 +268,7 @@ const size_t uclogic_rdesc_wp1062_fixed_size = /* Fixed PF1209 report descriptor */ __u8 uclogic_rdesc_pf1209_fixed_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -345,7 +345,7 @@ const size_t uclogic_rdesc_pf1209_fixed_size = /* Fixed PID 0522 tablet report descriptor, interface 0 (stylus) */ __u8 uclogic_rdesc_twhl850_fixed0_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -457,7 +457,7 @@ const size_t uclogic_rdesc_twhl850_fixed2_size = /* Fixed TWHA60 report descriptor, interface 0 (stylus) */ __u8 uclogic_rdesc_twha60_fixed0_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x09, /* Report ID (9), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -534,7 +534,7 @@ const size_t uclogic_rdesc_twha60_fixed1_size = /* Fixed report descriptor template for (tweaked) v1 pen reports */ const __u8 uclogic_rdesc_v1_pen_template_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x07, /* Report ID (7), */ 0x09, 0x20, /* Usage (Stylus), */ @@ -588,7 +588,7 @@ const size_t uclogic_rdesc_v1_pen_template_size = /* Fixed report descriptor template for (tweaked) v2 pen reports */ const __u8 uclogic_rdesc_v2_pen_template_arr[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x08, /* Report ID (8), */ 0x09, 0x20, /* Usage (Stylus), */ diff --git a/drivers/hid/hid-viewsonic.c b/drivers/hid/hid-viewsonic.c index df60c8fc2efd..8024b1d370e2 100644 --- a/drivers/hid/hid-viewsonic.c +++ b/drivers/hid/hid-viewsonic.c @@ -24,7 +24,7 @@ /* Fixed report descriptor of PD1011 signature pad */ static __u8 pd1011_rdesc_fixed[] = { 0x05, 0x0D, /* Usage Page (Digitizer), */ - 0x09, 0x02, /* Usage (Pen), */ + 0x09, 0x01, /* Usage (Digitizer), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x02, /* Report ID (2), */ 0x09, 0x20, /* Usage (Stylus), */ -- cgit v1.2.3-59-g8ed1b From fa33382c7f74a1444f90f324007da1431d7180b2 Mon Sep 17 00:00:00 2001 From: Bryan Cain Date: Thu, 5 May 2022 13:12:21 -0600 Subject: HID: apple: Properly handle function keys on Keychron keyboards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keychron's C-series and K-series of keyboards copy the vendor and product IDs of an Apple keyboard, but only behave like that device when set to "Mac" mode. In "Windows" mode, the Fn key doesn't generate a scancode, so it's impossible to use the F1-F12 keys when fnmode is set to its default value of 1. To fix this, make fnmode default to the new value of 3, which behaves like fnmode=2 for Keychron keyboards and like fnmode=1 for actual Apple keyboards. This way, Keychron devices are fully usable in both "Windows" and "Mac" modes, while behavior is unchanged for everything else. Signed-off-by: Bryan Cain Reviewed-by: Hans de Goede Tested-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-apple.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 0cf35caee9fa..42a568902f49 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "hid-ids.h" @@ -35,16 +36,17 @@ #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_FLAG_FKEY 0x01 #define HID_COUNTRY_INTERNATIONAL_ISO 13 #define APPLE_BATTERY_TIMEOUT_MS 60000 -static unsigned int fnmode = 1; +static unsigned int fnmode = 3; module_param(fnmode, uint, 0644); MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " - "[1] = fkeyslast, 2 = fkeysfirst)"); + "1 = fkeyslast, 2 = fkeysfirst, [3] = auto)"); static int iso_layout = -1; module_param(iso_layout, int, 0644); @@ -349,6 +351,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, const struct apple_key_translation *trans, *table; bool do_translate; u16 code = 0; + unsigned int real_fnmode; u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN); @@ -359,7 +362,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, return 1; } - if (fnmode) { + if (fnmode == 3) { + real_fnmode = (asc->quirks & APPLE_IS_KEYCHRON) ? 2 : 1; + } else { + real_fnmode = fnmode; + } + + if (real_fnmode) { if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI || hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO || hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS || @@ -406,7 +415,7 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, if (!code) { if (trans->flags & APPLE_FLAG_FKEY) { - switch (fnmode) { + switch (real_fnmode) { case 1: do_translate = !asc->fn_on; break; @@ -660,6 +669,11 @@ 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; + } + return 0; } -- cgit v1.2.3-59-g8ed1b