linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L
@ 2022-05-16 18:13 José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 1/4] HID: uclogic: Make template placeholder IDs generic José Expósito
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: José Expósito @ 2022-05-16 18:13 UTC (permalink / raw)
  To: jikos
  Cc: benjamin.tissoires, spbnick, linux-input, linux-kernel,
	stefanberzl, José Expósito

Hello everyone,

This patchset adds support for the UGEE XP-PEN Deco L tablet.
This device belongs to a family of tablets that must receive a chunk of
magic data in order to be enabled (named UGEE v2 internally).

Once the device is enabled, its parameters can be discovered by parsing
a report descriptor. HUION v1 tablets have a similar report descriptor
but, in the case of UGEE v2 tablets, the number of buttons are also
discoverable [1].

The ability to discover the number of buttons is the reason for the
first 3 patches. They enable frame templates.
Because I lack the hardware to fully test this driver, I added some
KUnit tests to make sure no bugs are introduced.
I didn't see any other test in the subsystem (and I doubt I'm the first
person writing one) so please let me know if I need to move the test to
a different place.

The last patch enables the tablet and it should give Stefan a stable
code to work on his XP-PEN Deco Mini 7 tablet.

Stefan: I didn't include the code for the Mini 4 because once connected
no events are received until I unload and load the driver.
If anyone has a clue about why this could happen, I'd really appreciate
some help. [2]

Best wishes,
José Expósito

[1] I don't own a HUION v1 device, so I'm not sure if the information
    about the number of buttons is also present and it is not used in
    the driver for some reason.
[2] https://lore.kernel.org/linux-input/20220516112159.GA74406@elementary/T/#t

José Expósito (4):
  HID: uclogic: Make template placeholder IDs generic
  HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply()
  HID: uclogic: Allow to generate frame templates
  HID: uclogic: Add support for XP-PEN Deco L

 drivers/hid/Kconfig                  |   7 +
 drivers/hid/Makefile                 |   2 +
 drivers/hid/hid-ids.h                |   1 +
 drivers/hid/hid-uclogic-core.c       |   2 +
 drivers/hid/hid-uclogic-params.c     | 203 ++++++++++++++++++++++++-
 drivers/hid/hid-uclogic-rdesc-test.c | 215 +++++++++++++++++++++++++++
 drivers/hid/hid-uclogic-rdesc.c      | 124 ++++++++++++++-
 drivers/hid/hid-uclogic-rdesc.h      |  24 ++-
 8 files changed, 564 insertions(+), 14 deletions(-)
 create mode 100644 drivers/hid/hid-uclogic-rdesc-test.c


base-commit: f7d8e387d9aeff963e6691c0166269b8042b4ff9
-- 
2.25.1


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

* [PATCH for-5.19/uclogic 1/4] HID: uclogic: Make template placeholder IDs generic
  2022-05-16 18:13 [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L José Expósito
@ 2022-05-16 18:13 ` José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply() José Expósito
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: José Expósito @ 2022-05-16 18:13 UTC (permalink / raw)
  To: jikos
  Cc: benjamin.tissoires, spbnick, linux-input, linux-kernel,
	stefanberzl, José Expósito

Up until now, the report descriptor template parameter IDs were only
used with pen report descriptors and they were named accordingly.

Rename the enum and the total number of IDs to make them interface
agnostic.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-uclogic-params.c |  4 ++--
 drivers/hid/hid-uclogic-rdesc.c  | 14 +++++++-------
 drivers/hid/hid-uclogic-rdesc.h  | 10 +++++-----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c
index db838f16282d..b43142f98a8b 100644
--- a/drivers/hid/hid-uclogic-params.c
+++ b/drivers/hid/hid-uclogic-params.c
@@ -234,7 +234,7 @@ static int uclogic_params_pen_init_v1(struct uclogic_params_pen *pen,
 	const int len = 12;
 	s32 resolution;
 	/* Pen report descriptor template parameters */
-	s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
+	s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
 	__u8 *desc_ptr = NULL;
 
 	/* Check arguments */
@@ -379,7 +379,7 @@ static int uclogic_params_pen_init_v2(struct uclogic_params_pen *pen,
 	size_t i;
 	s32 resolution;
 	/* Pen report descriptor template parameters */
-	s32 desc_params[UCLOGIC_RDESC_PEN_PH_ID_NUM];
+	s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
 	__u8 *desc_ptr = NULL;
 
 	/* Check arguments */
diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c
index 13f9ce73f1b1..7126fba80968 100644
--- a/drivers/hid/hid-uclogic-rdesc.c
+++ b/drivers/hid/hid-uclogic-rdesc.c
@@ -979,7 +979,7 @@ const size_t uclogic_rdesc_xppen_deco01_frame_size =
  * uclogic_rdesc_template_apply() - apply report descriptor parameters to a
  * report descriptor template, creating a report descriptor. Copies the
  * template over to the new report descriptor and replaces every occurrence of
- * UCLOGIC_RDESC_PH_HEAD, followed by an index byte, with the value from the
+ * UCLOGIC_RDESC_PEN_PH_HEAD, followed by an index byte, with the value from the
  * parameter list at that index.
  *
  * @template_ptr:	Pointer to the template buffer.
@@ -996,7 +996,7 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
 				   const s32 *param_list,
 				   size_t param_num)
 {
-	static const __u8 head[] = {UCLOGIC_RDESC_PH_HEAD};
+	static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD};
 	__u8 *rdesc_ptr;
 	__u8 *p;
 	s32 v;
@@ -1005,12 +1005,12 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
 	if (rdesc_ptr == NULL)
 		return NULL;
 
-	for (p = rdesc_ptr; p + sizeof(head) < rdesc_ptr + template_size;) {
-		if (memcmp(p, head, sizeof(head)) == 0 &&
-		    p[sizeof(head)] < param_num) {
-			v = param_list[p[sizeof(head)]];
+	for (p = rdesc_ptr; p + sizeof(pen_head) < rdesc_ptr + template_size;) {
+		if (memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
+		    p[sizeof(pen_head)] < param_num) {
+			v = param_list[p[sizeof(pen_head)]];
 			put_unaligned(cpu_to_le32(v), (s32 *)p);
-			p += sizeof(head) + 1;
+			p += sizeof(pen_head) + 1;
 		} else {
 			p++;
 		}
diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h
index 0c6e95e8bde7..9d37090c39d1 100644
--- a/drivers/hid/hid-uclogic-rdesc.h
+++ b/drivers/hid/hid-uclogic-rdesc.h
@@ -81,7 +81,7 @@ extern __u8 uclogic_rdesc_twha60_fixed1_arr[];
 extern const size_t uclogic_rdesc_twha60_fixed1_size;
 
 /* Report descriptor template placeholder head */
-#define UCLOGIC_RDESC_PH_HEAD	0xFE, 0xED, 0x1D
+#define UCLOGIC_RDESC_PEN_PH_HEAD	0xFE, 0xED, 0x1D
 
 /* Apply report descriptor parameters to a report descriptor template */
 extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
@@ -89,19 +89,19 @@ extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
 					  const s32 *param_list,
 					  size_t param_num);
 
-/* Pen report descriptor template placeholder IDs */
-enum uclogic_rdesc_pen_ph_id {
+/* Report descriptor template placeholder IDs */
+enum uclogic_rdesc_ph_id {
 	UCLOGIC_RDESC_PEN_PH_ID_X_LM,
 	UCLOGIC_RDESC_PEN_PH_ID_X_PM,
 	UCLOGIC_RDESC_PEN_PH_ID_Y_LM,
 	UCLOGIC_RDESC_PEN_PH_ID_Y_PM,
 	UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM,
-	UCLOGIC_RDESC_PEN_PH_ID_NUM
+	UCLOGIC_RDESC_PH_ID_NUM
 };
 
 /* Report descriptor pen template placeholder */
 #define UCLOGIC_RDESC_PEN_PH(_ID) \
-	UCLOGIC_RDESC_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID
+	UCLOGIC_RDESC_PEN_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID
 
 /* Report ID for v1 pen reports */
 #define UCLOGIC_RDESC_V1_PEN_ID	0x07
-- 
2.25.1


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

* [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply()
  2022-05-16 18:13 [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 1/4] HID: uclogic: Make template placeholder IDs generic José Expósito
@ 2022-05-16 18:13 ` José Expósito
  2022-05-17  7:16   ` kernel test robot
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L José Expósito
  3 siblings, 1 reply; 9+ messages in thread
From: José Expósito @ 2022-05-16 18:13 UTC (permalink / raw)
  To: jikos
  Cc: benjamin.tissoires, spbnick, linux-input, linux-kernel,
	stefanberzl, José Expósito

The uclogic_rdesc_template_apply() function is used by the driver to
generate HID descriptors from templates.

In order to avoid regressions in future patches, add KUnit tests to
test the function.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/Kconfig                  |   7 ++
 drivers/hid/Makefile                 |   2 +
 drivers/hid/hid-uclogic-rdesc-test.c | 179 +++++++++++++++++++++++++++
 3 files changed, 188 insertions(+)
 create mode 100644 drivers/hid/hid-uclogic-rdesc-test.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 7a674873d794..11212963ee3d 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -458,6 +458,13 @@ config HID_UCLOGIC
 	help
 	Support for UC-Logic and Huion tablets.
 
+config HID_UCLOGIC_KUNIT_TEST
+	tristate "UC-Logic tests" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y
+	default KUNIT_ALL_TESTS
+	help
+	  KUnit tests for the UC-Logic driver.
+
 config HID_WALTOP
 	tristate "Waltop"
 	depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index d5ce8d747b14..b853906f2738 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -127,6 +127,8 @@ hid-uclogic-objs		:= hid-uclogic-core.o \
 				   hid-uclogic-rdesc.o \
 				   hid-uclogic-params.o
 obj-$(CONFIG_HID_UCLOGIC)	+= hid-uclogic.o
+obj-$(CONFIG_HID_UCLOGIC_KUNIT_TEST)	+= hid-uclogic-rdesc.o \
+					   hid-uclogic-rdesc-test.o
 obj-$(CONFIG_HID_UDRAW_PS3)	+= hid-udraw-ps3.o
 obj-$(CONFIG_HID_LED)		+= hid-led.o
 obj-$(CONFIG_HID_XIAOMI)	+= hid-xiaomi.o
diff --git a/drivers/hid/hid-uclogic-rdesc-test.c b/drivers/hid/hid-uclogic-rdesc-test.c
new file mode 100644
index 000000000000..71917de02b03
--- /dev/null
+++ b/drivers/hid/hid-uclogic-rdesc-test.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ *  HID driver for UC-Logic devices not fully compliant with HID standard
+ *
+ *  Copyright (c) 2022 José Expósito <jose.exposito89@gmail.com>
+ */
+
+#include <kunit/test.h>
+#include "./hid-uclogic-rdesc.h"
+
+struct uclogic_template_case {
+	const char *name;
+	const __u8 *template;
+	size_t template_size;
+	const s32 *param_list;
+	size_t param_num;
+	const __u8 *expected;
+};
+
+static const s32 params_pen_all[UCLOGIC_RDESC_PH_ID_NUM] = {
+	[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA,
+	[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
+	[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0xCC,
+	[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0xDD,
+	[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0xEE,
+};
+
+static const s32 params_pen_some[] = {
+	[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA,
+	[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
+};
+
+static const __u8 template_empty[] = { };
+static const __u8 template_small[] = { 0x00 };
+static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D };
+
+static const __u8 template_pen_ph_end[] = {
+	0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD
+};
+
+static const __u8 template_pen_all_params[] = {
+	UCLOGIC_RDESC_PEN_PH(X_LM),
+	0x47, UCLOGIC_RDESC_PEN_PH(X_PM),
+	0x27, UCLOGIC_RDESC_PEN_PH(Y_LM),
+	UCLOGIC_RDESC_PEN_PH(Y_PM),
+	0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM),
+};
+
+static const __u8 expected_pen_all_params[] = {
+	0xAA, 0x00, 0x00, 0x00,
+	0x47, 0xBB, 0x00, 0x00, 0x00,
+	0x27, 0xCC, 0x00, 0x00, 0x00,
+	0xDD, 0x00, 0x00, 0x00,
+	0x00, 0xEE, 0x00, 0x00, 0x00,
+};
+
+static const __u8 template_pen_some_params[] = {
+	0x01, 0x02,
+	UCLOGIC_RDESC_PEN_PH(X_LM),
+	0x03, UCLOGIC_RDESC_PEN_PH(X_PM),
+	0x04, 0x05,
+};
+
+static const __u8 expected_pen_some_params[] = {
+	0x01, 0x02,
+	0xAA, 0x00, 0x00, 0x00,
+	0x03, 0xBB, 0x00, 0x00, 0x00,
+	0x04, 0x05,
+};
+
+static const __u8 template_params_none[] = {
+	0x27, UCLOGIC_RDESC_PEN_PH(Y_LM),
+	UCLOGIC_RDESC_PEN_PH(Y_PM),
+	0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM),
+};
+
+static struct uclogic_template_case uclogic_template_cases[] = {
+	{
+		.name = "Empty template",
+		.template = template_empty,
+		.template_size = sizeof(template_empty),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = template_empty,
+	},
+	{
+		.name = "Template smaller than the placeholder",
+		.template = template_small,
+		.template_size = sizeof(template_small),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = template_small,
+	},
+	{
+		.name = "No placeholder",
+		.template = template_no_ph,
+		.template_size = sizeof(template_no_ph),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = template_no_ph,
+	},
+	{
+		.name = "Pen placeholder at the end, without ID",
+		.template = template_pen_ph_end,
+		.template_size = sizeof(template_pen_ph_end),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = template_pen_ph_end,
+	},
+	{
+		.name = "All params present in the pen template",
+		.template = template_pen_all_params,
+		.template_size = sizeof(template_pen_all_params),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = expected_pen_all_params,
+	},
+	{
+		.name = "Some params present in the pen template (complete param list)",
+		.template = template_pen_some_params,
+		.template_size = sizeof(template_pen_some_params),
+		.param_list = params_pen_all,
+		.param_num = ARRAY_SIZE(params_pen_all),
+		.expected = expected_pen_some_params,
+	},
+	{
+		.name = "Some params present in the pen template (incomplete param list)",
+		.template = template_pen_some_params,
+		.template_size = sizeof(template_pen_some_params),
+		.param_list = params_pen_some,
+		.param_num = ARRAY_SIZE(params_pen_some),
+		.expected = expected_pen_some_params,
+	},
+	{
+		.name = "No params present in the template",
+		.template = template_params_none,
+		.template_size = sizeof(template_params_none),
+		.param_list = params_pen_some,
+		.param_num = ARRAY_SIZE(params_pen_some),
+		.expected = template_params_none,
+	},
+};
+
+static void uclogic_template_case_desc(struct uclogic_template_case *t,
+				       char *desc)
+{
+	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(uclogic_template, uclogic_template_cases,
+		  uclogic_template_case_desc);
+
+static void uclogic_template_test(struct kunit *test)
+{
+	__u8 *res;
+	const struct uclogic_template_case *params = test->param_value;
+
+	res = uclogic_rdesc_template_apply(params->template,
+					   params->template_size,
+					   params->param_list,
+					   params->param_num);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
+	KUNIT_EXPECT_EQ(test, 0,
+			memcmp(res, params->expected, params->template_size));
+	kfree(res);
+}
+
+static struct kunit_case hid_uclogic_rdesc_test_cases[] = {
+	KUNIT_CASE_PARAM(uclogic_template_test, uclogic_template_gen_params),
+	{}
+};
+
+static struct kunit_suite hid_uclogic_rdesc_test_suite = {
+	.name = "hid-uclogic-rdesc-test",
+	.test_cases = hid_uclogic_rdesc_test_cases,
+};
+
+kunit_test_suite(hid_uclogic_rdesc_test_suite);
-- 
2.25.1


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

* [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates
  2022-05-16 18:13 [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 1/4] HID: uclogic: Make template placeholder IDs generic José Expósito
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply() José Expósito
@ 2022-05-16 18:13 ` José Expósito
  2022-05-17 23:30   ` kernel test robot
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L José Expósito
  3 siblings, 1 reply; 9+ messages in thread
From: José Expósito @ 2022-05-16 18:13 UTC (permalink / raw)
  To: jikos
  Cc: benjamin.tissoires, spbnick, linux-input, linux-kernel,
	stefanberzl, José Expósito

Add a new template placeholder to allow configuring the number of
buttons in the drawing tablet frame and update the KUnit tests to
cover the new case.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-uclogic-rdesc-test.c | 36 ++++++++++++++++++++++++++++
 drivers/hid/hid-uclogic-rdesc.c      | 14 ++++++++---
 drivers/hid/hid-uclogic-rdesc.h      |  6 +++++
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-uclogic-rdesc-test.c b/drivers/hid/hid-uclogic-rdesc-test.c
index 71917de02b03..1e22d1c86616 100644
--- a/drivers/hid/hid-uclogic-rdesc-test.c
+++ b/drivers/hid/hid-uclogic-rdesc-test.c
@@ -31,6 +31,10 @@ static const s32 params_pen_some[] = {
 	[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
 };
 
+static const s32 params_frame_all[UCLOGIC_RDESC_PH_ID_NUM] = {
+	[UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0xFF,
+};
+
 static const __u8 template_empty[] = { };
 static const __u8 template_small[] = { 0x00 };
 static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D };
@@ -39,6 +43,10 @@ static const __u8 template_pen_ph_end[] = {
 	0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD
 };
 
+static const __u8 template_btn_ph_end[] = {
+	0xAA, 0xBB, UCLOGIC_RDESC_FRAME_PH_BTN_HEAD
+};
+
 static const __u8 template_pen_all_params[] = {
 	UCLOGIC_RDESC_PEN_PH(X_LM),
 	0x47, UCLOGIC_RDESC_PEN_PH(X_PM),
@@ -55,6 +63,18 @@ static const __u8 expected_pen_all_params[] = {
 	0x00, 0xEE, 0x00, 0x00, 0x00,
 };
 
+static const __u8 template_frame_all_params[] = {
+	0x01, 0x02,
+	UCLOGIC_RDESC_FRAME_PH_BTN,
+	0x99,
+};
+
+static const __u8 expected_frame_all_params[] = {
+	0x01, 0x02,
+	0x2A, 0xFF, 0x00,
+	0x99,
+};
+
 static const __u8 template_pen_some_params[] = {
 	0x01, 0x02,
 	UCLOGIC_RDESC_PEN_PH(X_LM),
@@ -108,6 +128,14 @@ static struct uclogic_template_case uclogic_template_cases[] = {
 		.param_num = ARRAY_SIZE(params_pen_all),
 		.expected = template_pen_ph_end,
 	},
+	{
+		.name = "Frame button placeholder at the end, without ID",
+		.template = template_btn_ph_end,
+		.template_size = sizeof(template_btn_ph_end),
+		.param_list = params_frame_all,
+		.param_num = ARRAY_SIZE(params_frame_all),
+		.expected = template_btn_ph_end,
+	},
 	{
 		.name = "All params present in the pen template",
 		.template = template_pen_all_params,
@@ -116,6 +144,14 @@ static struct uclogic_template_case uclogic_template_cases[] = {
 		.param_num = ARRAY_SIZE(params_pen_all),
 		.expected = expected_pen_all_params,
 	},
+	{
+		.name = "All params present in the frame template",
+		.template = template_frame_all_params,
+		.template_size = sizeof(template_frame_all_params),
+		.param_list = params_frame_all,
+		.param_num = ARRAY_SIZE(params_frame_all),
+		.expected = expected_frame_all_params,
+	},
 	{
 		.name = "Some params present in the pen template (complete param list)",
 		.template = template_pen_some_params,
diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c
index 7126fba80968..cf04e71b7bb5 100644
--- a/drivers/hid/hid-uclogic-rdesc.c
+++ b/drivers/hid/hid-uclogic-rdesc.c
@@ -979,7 +979,7 @@ const size_t uclogic_rdesc_xppen_deco01_frame_size =
  * uclogic_rdesc_template_apply() - apply report descriptor parameters to a
  * report descriptor template, creating a report descriptor. Copies the
  * template over to the new report descriptor and replaces every occurrence of
- * UCLOGIC_RDESC_PEN_PH_HEAD, followed by an index byte, with the value from the
+ * the template placeholders, followed by an index byte, with the value from the
  * parameter list at that index.
  *
  * @template_ptr:	Pointer to the template buffer.
@@ -996,6 +996,7 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
 				   const s32 *param_list,
 				   size_t param_num)
 {
+	static const __u8 btn_head[] = {UCLOGIC_RDESC_FRAME_PH_BTN_HEAD};
 	static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD};
 	__u8 *rdesc_ptr;
 	__u8 *p;
@@ -1005,12 +1006,19 @@ __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
 	if (rdesc_ptr == NULL)
 		return NULL;
 
-	for (p = rdesc_ptr; p + sizeof(pen_head) < rdesc_ptr + template_size;) {
-		if (memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
+	for (p = rdesc_ptr; p + sizeof(btn_head) < rdesc_ptr + template_size;) {
+		if (p + sizeof(pen_head) < rdesc_ptr + template_size &&
+		    memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
 		    p[sizeof(pen_head)] < param_num) {
 			v = param_list[p[sizeof(pen_head)]];
 			put_unaligned(cpu_to_le32(v), (s32 *)p);
 			p += sizeof(pen_head) + 1;
+		} else if (memcmp(p, btn_head, sizeof(btn_head)) == 0 &&
+			   p[sizeof(btn_head)] < param_num) {
+			v = param_list[p[sizeof(btn_head)]];
+			put_unaligned((__u8)0x2A, p); /* Usage Maximum */
+			put_unaligned_le16(cpu_to_le16(v), p + 1);
+			p += sizeof(btn_head) + 1;
 		} else {
 			p++;
 		}
diff --git a/drivers/hid/hid-uclogic-rdesc.h b/drivers/hid/hid-uclogic-rdesc.h
index 9d37090c39d1..3d78299f082d 100644
--- a/drivers/hid/hid-uclogic-rdesc.h
+++ b/drivers/hid/hid-uclogic-rdesc.h
@@ -82,6 +82,7 @@ extern const size_t uclogic_rdesc_twha60_fixed1_size;
 
 /* Report descriptor template placeholder head */
 #define UCLOGIC_RDESC_PEN_PH_HEAD	0xFE, 0xED, 0x1D
+#define UCLOGIC_RDESC_FRAME_PH_BTN_HEAD	0xFE, 0xED
 
 /* Apply report descriptor parameters to a report descriptor template */
 extern __u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
@@ -96,6 +97,7 @@ enum uclogic_rdesc_ph_id {
 	UCLOGIC_RDESC_PEN_PH_ID_Y_LM,
 	UCLOGIC_RDESC_PEN_PH_ID_Y_PM,
 	UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM,
+	UCLOGIC_RDESC_FRAME_PH_ID_UM,
 	UCLOGIC_RDESC_PH_ID_NUM
 };
 
@@ -103,6 +105,10 @@ enum uclogic_rdesc_ph_id {
 #define UCLOGIC_RDESC_PEN_PH(_ID) \
 	UCLOGIC_RDESC_PEN_PH_HEAD, UCLOGIC_RDESC_PEN_PH_ID_##_ID
 
+/* Report descriptor frame buttons template placeholder */
+#define UCLOGIC_RDESC_FRAME_PH_BTN \
+	UCLOGIC_RDESC_FRAME_PH_BTN_HEAD, UCLOGIC_RDESC_FRAME_PH_ID_UM
+
 /* Report ID for v1 pen reports */
 #define UCLOGIC_RDESC_V1_PEN_ID	0x07
 
-- 
2.25.1


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

* [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L
  2022-05-16 18:13 [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L José Expósito
                   ` (2 preceding siblings ...)
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates José Expósito
@ 2022-05-16 18:13 ` José Expósito
  2022-05-17  4:12   ` kernel test robot
  2022-05-17 22:50   ` kernel test robot
  3 siblings, 2 replies; 9+ messages in thread
From: José Expósito @ 2022-05-16 18:13 UTC (permalink / raw)
  To: jikos
  Cc: benjamin.tissoires, spbnick, linux-input, linux-kernel,
	stefanberzl, José Expósito

The XP-PEN Deco L (UGEE) needs to be initialized by sending a buffer of
magic data, discovered by sniffing the Windows driver traffic.

In order to differentiate UGEE tablets that need this kind of
initialization from the previous ones, name them v2 internally and
create an entry point for them.

After initialization, the template report descriptors can be discovered
by parsing a string descriptor, similar to the one exposed by HUION v1
devices.

Add all the required elements to support the device.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-ids.h            |   1 +
 drivers/hid/hid-uclogic-core.c   |   2 +
 drivers/hid/hid-uclogic-params.c | 199 +++++++++++++++++++++++++++++++
 drivers/hid/hid-uclogic-rdesc.c  | 102 ++++++++++++++++
 drivers/hid/hid-uclogic-rdesc.h  |   8 ++
 5 files changed, 312 insertions(+)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index f8b3774a3a10..ea4e60de46db 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_DECO_L	0x0935
 #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
diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
index c0fe66e50c58..47a17375c7fc 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_DECO_L) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_UGEE,
 				USB_DEVICE_ID_UGEE_XPPEN_TABLET_STAR06) },
 	{ }
diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c
index b43142f98a8b..00090d11b413 100644
--- a/drivers/hid/hid-uclogic-params.c
+++ b/drivers/hid/hid-uclogic-params.c
@@ -1002,6 +1002,199 @@ static int uclogic_params_huion_init(struct uclogic_params *params,
 	return rc;
 }
 
+/**
+ * uclogic_probe_interface() - some tablets, like the Parblo A610 PLUS V2 or
+ * the XP-PEN Deco Mini 7, need to be initialized by sending them magic data.
+ *
+ * @hdev:	The HID device of the tablet interface to initialize and get
+ *		parameters from. Cannot be NULL.
+ * @magic_arr:	The magic data that should be sent to probe the interface.
+ *		Cannot be NULL.
+ * @magic_size:	Size of the magic data.
+ * @endpoint:	Endpoint where the magic data should be sent.
+ *
+ * Returns:
+ *	Zero, if successful. A negative errno code on error.
+ */
+static int uclogic_probe_interface(struct hid_device *hdev, u8 *magic_arr,
+				   int magic_size, int endpoint)
+{
+	struct usb_device *udev;
+	unsigned int pipe = 0;
+	int sent;
+	u8 *buf = NULL;
+	int rc = 0;
+
+	if (!hdev || !magic_arr) {
+		rc = -EINVAL;
+		goto cleanup;
+	}
+
+	buf = kmemdup(magic_arr, magic_size, GFP_KERNEL);
+	if (!buf) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	udev = hid_to_usb_dev(hdev);
+	pipe = usb_sndintpipe(udev, endpoint);
+
+	rc = usb_interrupt_msg(udev, pipe, buf, magic_size, &sent, 1000);
+	if (rc || sent != magic_size) {
+		hid_err(hdev, "Interface probing failed: %d\n", rc);
+		rc = -1;
+		goto cleanup;
+	}
+
+	rc = 0;
+cleanup:
+	kfree(buf);
+	return rc;
+}
+
+/**
+ * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by
+ * discovering their parameters.
+ *
+ * These tables, internally designed as v2 to differentiate them from older
+ * models, expect a payload of magic data in orther to be switched to the fully
+ * functional mode and expose their parameters in a similar way to the
+ * information present in uclogic_params_pen_init_v1() but with some
+ * differences.
+ *
+ * @params:	Parameters to fill in (to be cleaned with
+ *		uclogic_params_cleanup()). 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.
+ *
+ * Returns:
+ *	Zero, if successful. A negative errno code on error.
+ */
+static int uclogic_params_ugee_v2_init(struct uclogic_params *params,
+				       struct hid_device *hdev)
+{
+	int rc = 0;
+	struct usb_device *udev;
+	struct usb_interface *iface;
+	__u8 bInterfaceNumber;
+	const int str_desc_len = 12;
+	__u8 *str_desc = NULL;
+	__u8 *rdesc_pen = NULL;
+	__u8 *rdesc_frame = NULL;
+	s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
+	s32 resolution;
+	__u8 magic_arr[] = {
+		0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+	};
+	/* The resulting parameters (noop) */
+	struct uclogic_params p = {0, };
+
+	if (!params || !hdev) {
+		rc = -EINVAL;
+		goto cleanup;
+	}
+
+	udev = hid_to_usb_dev(hdev);
+	iface = to_usb_interface(hdev->dev.parent);
+	bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
+	if (bInterfaceNumber != 2) {
+		uclogic_params_init_invalid(&p);
+		goto output;
+	}
+
+	/*
+	 * Initialize the interface by sending magic data.
+	 * The specific data was discovered by sniffing the Windows driver
+	 * traffic.
+	 */
+	rc = uclogic_probe_interface(hdev, magic_arr, sizeof(magic_arr), 0x03);
+	if (rc) {
+		uclogic_params_init_invalid(&p);
+		goto output;
+	}
+
+	/*
+	 * Read the string descriptor containing pen and frame parameters.
+	 * The specific string descriptor and data were discovered by sniffing
+	 * the Windows driver traffic.
+	 */
+	rc = uclogic_params_get_str_desc(&str_desc, hdev, 100, str_desc_len);
+	if (rc != str_desc_len) {
+		hid_err(hdev, "failed retrieving pen and frame parameters: %d\n", rc);
+		uclogic_params_init_invalid(&p);
+		goto output;
+	}
+
+	desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
+		get_unaligned_le16(str_desc + 2);
+	desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
+		get_unaligned_le16(str_desc + 4);
+	desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM] = str_desc[6];
+	desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
+		get_unaligned_le16(str_desc + 8);
+	resolution = get_unaligned_le16(str_desc + 10);
+	if (resolution == 0) {
+		desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
+		desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
+	} else {
+		desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
+			desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
+			resolution;
+		desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
+			desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
+			resolution;
+	}
+	kfree(str_desc);
+	str_desc = NULL;
+
+	/* Initialize the pen interface */
+	rdesc_pen = uclogic_rdesc_template_apply(
+				uclogic_rdesc_ugee_v2_pen_template_arr,
+				uclogic_rdesc_ugee_v2_pen_template_size,
+				desc_params, ARRAY_SIZE(desc_params));
+	if (!rdesc_pen) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	p.pen.desc_ptr = rdesc_pen;
+	p.pen.desc_size = uclogic_rdesc_ugee_v2_pen_template_size;
+	p.pen.id = 0x02;
+	p.pen.subreport_list[0].value = 0xf0;
+	p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID;
+
+	/* Initialize the frame interface */
+	rdesc_frame = uclogic_rdesc_template_apply(
+				uclogic_rdesc_ugee_v2_frame_btn_template_arr,
+				uclogic_rdesc_ugee_v2_frame_btn_template_size,
+				desc_params, ARRAY_SIZE(desc_params));
+	if (!rdesc_frame) {
+		rc = -ENOMEM;
+		goto cleanup;
+	}
+
+	rc = uclogic_params_frame_init_with_desc(&p.frame_list[0],
+						 rdesc_frame,
+						 uclogic_rdesc_ugee_v2_frame_btn_template_size,
+						 UCLOGIC_RDESC_V1_FRAME_ID);
+	kfree(rdesc_frame);
+	if (rc) {
+		uclogic_params_init_invalid(&p);
+		goto output;
+	}
+
+output:
+	/* Output parameters */
+	memcpy(params, &p, sizeof(*params));
+	memset(&p, 0, sizeof(p));
+	rc = 0;
+cleanup:
+	kfree(str_desc);
+	uclogic_params_cleanup(&p);
+	return rc;
+}
+
 /**
  * uclogic_params_init() - initialize a tablet interface and discover its
  * parameters.
@@ -1237,6 +1430,12 @@ int uclogic_params_init(struct uclogic_params *params,
 			uclogic_params_init_invalid(&p);
 		}
 		break;
+	case VID_PID(USB_VENDOR_ID_UGEE,
+		     USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L):
+		rc = uclogic_params_ugee_v2_init(&p, hdev);
+		if (rc != 0)
+			goto cleanup;
+		break;
 	case VID_PID(USB_VENDOR_ID_TRUST,
 		     USB_DEVICE_ID_TRUST_PANORA_TABLET):
 	case VID_PID(USB_VENDOR_ID_UGEE,
diff --git a/drivers/hid/hid-uclogic-rdesc.c b/drivers/hid/hid-uclogic-rdesc.c
index cf04e71b7bb5..c552c989976a 100644
--- a/drivers/hid/hid-uclogic-rdesc.c
+++ b/drivers/hid/hid-uclogic-rdesc.c
@@ -859,6 +859,108 @@ const __u8 uclogic_rdesc_v2_frame_dial_arr[] = {
 const size_t uclogic_rdesc_v2_frame_dial_size =
 			sizeof(uclogic_rdesc_v2_frame_dial_arr);
 
+/* Fixed report descriptor template for UGEE v2 pen reports */
+const __u8 uclogic_rdesc_ugee_v2_pen_template_arr[] = {
+	0x05, 0x0d,         /*  Usage Page (Digitizers),                */
+	0x09, 0x01,         /*  Usage (Digitizer),                      */
+	0xa1, 0x01,         /*  Collection (Application),               */
+	0x85, 0x02,         /*      Report ID (2),                      */
+	0x09, 0x20,         /*      Usage (Stylus),                     */
+	0xa1, 0x00,         /*      Collection (Physical),              */
+	0x09, 0x42,         /*          Usage (Tip Switch),             */
+	0x09, 0x44,         /*          Usage (Barrel Switch),          */
+	0x09, 0x46,         /*          Usage (Tablet Pick),            */
+	0x75, 0x01,         /*          Report Size (1),                */
+	0x95, 0x03,         /*          Report Count (3),               */
+	0x14,               /*          Logical Minimum (0),            */
+	0x25, 0x01,         /*          Logical Maximum (1),            */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x95, 0x02,         /*          Report Count (2),               */
+	0x81, 0x03,         /*          Input (Constant, Variable),     */
+	0x09, 0x32,         /*          Usage (In Range),               */
+	0x95, 0x01,         /*          Report Count (1),               */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x95, 0x02,         /*          Report Count (2),               */
+	0x81, 0x03,         /*          Input (Constant, Variable),     */
+	0x75, 0x10,         /*          Report Size (16),               */
+	0x95, 0x01,         /*          Report Count (1),               */
+	0x35, 0x00,         /*          Physical Minimum (0),           */
+	0xa4,               /*          Push,                           */
+	0x05, 0x01,         /*          Usage Page (Desktop),           */
+	0x09, 0x30,         /*          Usage (X),                      */
+	0x65, 0x13,         /*          Unit (Inch),                    */
+	0x55, 0x0d,         /*          Unit Exponent (-3),             */
+	0x27, UCLOGIC_RDESC_PEN_PH(X_LM),
+			    /*          Logical Maximum (PLACEHOLDER),  */
+	0x47, UCLOGIC_RDESC_PEN_PH(X_PM),
+			    /*          Physical Maximum (PLACEHOLDER), */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x09, 0x31,         /*          Usage (Y),                      */
+	0x27, UCLOGIC_RDESC_PEN_PH(Y_LM),
+			    /*          Logical Maximum (PLACEHOLDER),  */
+	0x47, UCLOGIC_RDESC_PEN_PH(Y_PM),
+			    /*          Physical Maximum (PLACEHOLDER), */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0xb4,               /*          Pop,                            */
+	0x09, 0x30,         /*          Usage (Tip Pressure),           */
+	0x45, 0x00,         /*          Physical Maximum (0),           */
+	0x27, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM),
+			    /*          Logical Maximum (PLACEHOLDER),  */
+	0x75, 0x0D,         /*          Report Size (13),               */
+	0x95, 0x01,         /*          Report Count (1),               */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x75, 0x01,         /*          Report Size (1),                */
+	0x95, 0x03,         /*          Report Count (3),               */
+	0x81, 0x01,         /*          Input (Constant),               */
+	0x09, 0x3d,         /*          Usage (X Tilt),                 */
+	0x35, 0xC3,         /*          Physical Minimum (-61),         */
+	0x45, 0x3C,         /*          Physical Maximum (60),          */
+	0x15, 0xC3,         /*          Logical Minimum (-61),          */
+	0x25, 0x3C,         /*          Logical Maximum (60),           */
+	0x75, 0x08,         /*          Report Size (8),                */
+	0x95, 0x01,         /*          Report Count (1),               */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x09, 0x3e,         /*          Usage (Y Tilt),                 */
+	0x35, 0xC3,         /*          Physical Minimum (-61),         */
+	0x45, 0x3C,         /*          Physical Maximum (60),          */
+	0x15, 0xC3,         /*          Logical Minimum (-61),          */
+	0x25, 0x3C,         /*          Logical Maximum (60),           */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0xc0,               /*      End Collection,                     */
+	0xc0,               /*  End Collection                          */
+};
+const size_t uclogic_rdesc_ugee_v2_pen_template_size =
+			sizeof(uclogic_rdesc_ugee_v2_pen_template_arr);
+
+/* Fixed report descriptor template for UGEE v2 frame reports (buttons only) */
+const __u8 uclogic_rdesc_ugee_v2_frame_btn_template_arr[] = {
+	0x05, 0x01,         /*  Usage Page (Desktop),                   */
+	0x09, 0x07,         /*  Usage (Keypad),                         */
+	0xA1, 0x01,         /*  Collection (Application),               */
+	0x85, UCLOGIC_RDESC_V1_FRAME_ID,
+			    /*      Report ID,                          */
+	0x05, 0x0D,         /*      Usage Page (Digitizer),             */
+	0x09, 0x39,         /*      Usage (Tablet Function Keys),       */
+	0xA0,               /*      Collection (Physical),              */
+	0x75, 0x01,         /*          Report Size (1),                */
+	0x95, 0x08,         /*          Report Count (8),               */
+	0x81, 0x01,         /*          Input (Constant),               */
+	0x05, 0x09,         /*          Usage Page (Button),            */
+	0x19, 0x01,         /*          Usage Minimum (01h),            */
+	UCLOGIC_RDESC_FRAME_PH_BTN,
+			    /*          Usage Maximum (PLACEHOLDER),    */
+	0x95, 0x0A,         /*          Report Count (10),              */
+	0x14,               /*          Logical Minimum (0),            */
+	0x25, 0x01,         /*          Logical Maximum (1),            */
+	0x81, 0x02,         /*          Input (Variable),               */
+	0x95, 0x46,         /*          Report Count (70),              */
+	0x81, 0x01,         /*          Input (Constant),               */
+	0xC0,               /*      End Collection,                     */
+	0xC0                /*  End Collection                          */
+};
+const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size =
+			sizeof(uclogic_rdesc_ugee_v2_frame_btn_template_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 3d78299f082d..86e64a9ee6bd 100644
--- a/drivers/hid/hid-uclogic-rdesc.h
+++ b/drivers/hid/hid-uclogic-rdesc.h
@@ -161,6 +161,14 @@ 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 template for UGEE v2 pen reports */
+extern const __u8 uclogic_rdesc_ugee_v2_pen_template_arr[];
+extern const size_t uclogic_rdesc_ugee_v2_pen_template_size;
+
+/* Fixed report descriptor template for UGEE v2 frame reports (buttons only) */
+extern const __u8 uclogic_rdesc_ugee_v2_frame_btn_template_arr[];
+extern const size_t uclogic_rdesc_ugee_v2_frame_btn_template_size;
+
 /* 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;
-- 
2.25.1


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

* Re: [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L José Expósito
@ 2022-05-17  4:12   ` kernel test robot
  2022-05-17 22:50   ` kernel test robot
  1 sibling, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-05-17  4:12 UTC (permalink / raw)
  To: José Expósito, jikos
  Cc: kbuild-all, benjamin.tissoires, spbnick, linux-input,
	linux-kernel, stefanberzl, José Expósito

Hi "José,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on f7d8e387d9aeff963e6691c0166269b8042b4ff9]

url:    https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
base:   f7d8e387d9aeff963e6691c0166269b8042b4ff9
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220517/202205171208.uAUnAkVJ-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f117e735d50f52f57bdabb589453959d60ae3ce6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
        git checkout f117e735d50f52f57bdabb589453959d60ae3ce6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/hid/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/hid/hid-uclogic-params.c: In function 'uclogic_params_ugee_v2_init':
>> drivers/hid/hid-uclogic-params.c:1078:28: warning: variable 'udev' set but not used [-Wunused-but-set-variable]
    1078 |         struct usb_device *udev;
         |                            ^~~~


vim +/udev +1078 drivers/hid/hid-uclogic-params.c

  1054	
  1055	/**
  1056	 * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by
  1057	 * discovering their parameters.
  1058	 *
  1059	 * These tables, internally designed as v2 to differentiate them from older
  1060	 * models, expect a payload of magic data in orther to be switched to the fully
  1061	 * functional mode and expose their parameters in a similar way to the
  1062	 * information present in uclogic_params_pen_init_v1() but with some
  1063	 * differences.
  1064	 *
  1065	 * @params:	Parameters to fill in (to be cleaned with
  1066	 *		uclogic_params_cleanup()). Not modified in case of error.
  1067	 *		Cannot be NULL.
  1068	 * @hdev:	The HID device of the tablet interface to initialize and get
  1069	 *		parameters from. Cannot be NULL.
  1070	 *
  1071	 * Returns:
  1072	 *	Zero, if successful. A negative errno code on error.
  1073	 */
  1074	static int uclogic_params_ugee_v2_init(struct uclogic_params *params,
  1075					       struct hid_device *hdev)
  1076	{
  1077		int rc = 0;
> 1078		struct usb_device *udev;
  1079		struct usb_interface *iface;
  1080		__u8 bInterfaceNumber;
  1081		const int str_desc_len = 12;
  1082		__u8 *str_desc = NULL;
  1083		__u8 *rdesc_pen = NULL;
  1084		__u8 *rdesc_frame = NULL;
  1085		s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
  1086		s32 resolution;
  1087		__u8 magic_arr[] = {
  1088			0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  1089		};
  1090		/* The resulting parameters (noop) */
  1091		struct uclogic_params p = {0, };
  1092	
  1093		if (!params || !hdev) {
  1094			rc = -EINVAL;
  1095			goto cleanup;
  1096		}
  1097	
  1098		udev = hid_to_usb_dev(hdev);
  1099		iface = to_usb_interface(hdev->dev.parent);
  1100		bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
  1101		if (bInterfaceNumber != 2) {
  1102			uclogic_params_init_invalid(&p);
  1103			goto output;
  1104		}
  1105	
  1106		/*
  1107		 * Initialize the interface by sending magic data.
  1108		 * The specific data was discovered by sniffing the Windows driver
  1109		 * traffic.
  1110		 */
  1111		rc = uclogic_probe_interface(hdev, magic_arr, sizeof(magic_arr), 0x03);
  1112		if (rc) {
  1113			uclogic_params_init_invalid(&p);
  1114			goto output;
  1115		}
  1116	
  1117		/*
  1118		 * Read the string descriptor containing pen and frame parameters.
  1119		 * The specific string descriptor and data were discovered by sniffing
  1120		 * the Windows driver traffic.
  1121		 */
  1122		rc = uclogic_params_get_str_desc(&str_desc, hdev, 100, str_desc_len);
  1123		if (rc != str_desc_len) {
  1124			hid_err(hdev, "failed retrieving pen and frame parameters: %d\n", rc);
  1125			uclogic_params_init_invalid(&p);
  1126			goto output;
  1127		}
  1128	
  1129		desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
  1130			get_unaligned_le16(str_desc + 2);
  1131		desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
  1132			get_unaligned_le16(str_desc + 4);
  1133		desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM] = str_desc[6];
  1134		desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
  1135			get_unaligned_le16(str_desc + 8);
  1136		resolution = get_unaligned_le16(str_desc + 10);
  1137		if (resolution == 0) {
  1138			desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
  1139			desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
  1140		} else {
  1141			desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
  1142				desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
  1143				resolution;
  1144			desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
  1145				desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
  1146				resolution;
  1147		}
  1148		kfree(str_desc);
  1149		str_desc = NULL;
  1150	
  1151		/* Initialize the pen interface */
  1152		rdesc_pen = uclogic_rdesc_template_apply(
  1153					uclogic_rdesc_ugee_v2_pen_template_arr,
  1154					uclogic_rdesc_ugee_v2_pen_template_size,
  1155					desc_params, ARRAY_SIZE(desc_params));
  1156		if (!rdesc_pen) {
  1157			rc = -ENOMEM;
  1158			goto cleanup;
  1159		}
  1160	
  1161		p.pen.desc_ptr = rdesc_pen;
  1162		p.pen.desc_size = uclogic_rdesc_ugee_v2_pen_template_size;
  1163		p.pen.id = 0x02;
  1164		p.pen.subreport_list[0].value = 0xf0;
  1165		p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID;
  1166	
  1167		/* Initialize the frame interface */
  1168		rdesc_frame = uclogic_rdesc_template_apply(
  1169					uclogic_rdesc_ugee_v2_frame_btn_template_arr,
  1170					uclogic_rdesc_ugee_v2_frame_btn_template_size,
  1171					desc_params, ARRAY_SIZE(desc_params));
  1172		if (!rdesc_frame) {
  1173			rc = -ENOMEM;
  1174			goto cleanup;
  1175		}
  1176	
  1177		rc = uclogic_params_frame_init_with_desc(&p.frame_list[0],
  1178							 rdesc_frame,
  1179							 uclogic_rdesc_ugee_v2_frame_btn_template_size,
  1180							 UCLOGIC_RDESC_V1_FRAME_ID);
  1181		kfree(rdesc_frame);
  1182		if (rc) {
  1183			uclogic_params_init_invalid(&p);
  1184			goto output;
  1185		}
  1186	
  1187	output:
  1188		/* Output parameters */
  1189		memcpy(params, &p, sizeof(*params));
  1190		memset(&p, 0, sizeof(p));
  1191		rc = 0;
  1192	cleanup:
  1193		kfree(str_desc);
  1194		uclogic_params_cleanup(&p);
  1195		return rc;
  1196	}
  1197	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply()
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply() José Expósito
@ 2022-05-17  7:16   ` kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-05-17  7:16 UTC (permalink / raw)
  To: José Expósito, jikos
  Cc: llvm, kbuild-all, benjamin.tissoires, spbnick, linux-input,
	linux-kernel, stefanberzl, José Expósito

Hi "José,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on f7d8e387d9aeff963e6691c0166269b8042b4ff9]

url:    https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
base:   f7d8e387d9aeff963e6691c0166269b8042b4ff9
config: riscv-randconfig-r036-20220516 (https://download.01.org/0day-ci/archive/20220517/202205171527.RQ8sqqya-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 853fa8ee225edf2d0de94b0dcbd31bea916e825e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/59e13d6c9ab96d326e1575bd6cd2f0ca0c98f561
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
        git checkout 59e13d6c9ab96d326e1575bd6cd2f0ca0c98f561
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>, old ones prefixed by <<):

ERROR: modpost: missing MODULE_LICENSE() in drivers/hid/hid-uclogic-rdesc.o
ERROR: modpost: missing MODULE_LICENSE() in drivers/hid/hid-uclogic-rdesc-test.o
>> ERROR: modpost: "uclogic_rdesc_template_apply" [drivers/hid/hid-uclogic-rdesc-test.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L José Expósito
  2022-05-17  4:12   ` kernel test robot
@ 2022-05-17 22:50   ` kernel test robot
  1 sibling, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-05-17 22:50 UTC (permalink / raw)
  To: José Expósito, jikos
  Cc: llvm, kbuild-all, benjamin.tissoires, spbnick, linux-input,
	linux-kernel, stefanberzl, José Expósito

Hi "José,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on f7d8e387d9aeff963e6691c0166269b8042b4ff9]

url:    https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
base:   f7d8e387d9aeff963e6691c0166269b8042b4ff9
config: i386-randconfig-a006-20220516 (https://download.01.org/0day-ci/archive/20220518/202205180632.TtyLPtA5-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 853fa8ee225edf2d0de94b0dcbd31bea916e825e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f117e735d50f52f57bdabb589453959d60ae3ce6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
        git checkout f117e735d50f52f57bdabb589453959d60ae3ce6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/hid/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/hid/hid-uclogic-params.c:1078:21: warning: variable 'udev' set but not used [-Wunused-but-set-variable]
           struct usb_device *udev;
                              ^
   1 warning generated.


vim +/udev +1078 drivers/hid/hid-uclogic-params.c

  1054	
  1055	/**
  1056	 * uclogic_params_ugee_v2_init() - initialize a UGEE graphics tablets by
  1057	 * discovering their parameters.
  1058	 *
  1059	 * These tables, internally designed as v2 to differentiate them from older
  1060	 * models, expect a payload of magic data in orther to be switched to the fully
  1061	 * functional mode and expose their parameters in a similar way to the
  1062	 * information present in uclogic_params_pen_init_v1() but with some
  1063	 * differences.
  1064	 *
  1065	 * @params:	Parameters to fill in (to be cleaned with
  1066	 *		uclogic_params_cleanup()). Not modified in case of error.
  1067	 *		Cannot be NULL.
  1068	 * @hdev:	The HID device of the tablet interface to initialize and get
  1069	 *		parameters from. Cannot be NULL.
  1070	 *
  1071	 * Returns:
  1072	 *	Zero, if successful. A negative errno code on error.
  1073	 */
  1074	static int uclogic_params_ugee_v2_init(struct uclogic_params *params,
  1075					       struct hid_device *hdev)
  1076	{
  1077		int rc = 0;
> 1078		struct usb_device *udev;
  1079		struct usb_interface *iface;
  1080		__u8 bInterfaceNumber;
  1081		const int str_desc_len = 12;
  1082		__u8 *str_desc = NULL;
  1083		__u8 *rdesc_pen = NULL;
  1084		__u8 *rdesc_frame = NULL;
  1085		s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
  1086		s32 resolution;
  1087		__u8 magic_arr[] = {
  1088			0x02, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  1089		};
  1090		/* The resulting parameters (noop) */
  1091		struct uclogic_params p = {0, };
  1092	
  1093		if (!params || !hdev) {
  1094			rc = -EINVAL;
  1095			goto cleanup;
  1096		}
  1097	
  1098		udev = hid_to_usb_dev(hdev);
  1099		iface = to_usb_interface(hdev->dev.parent);
  1100		bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber;
  1101		if (bInterfaceNumber != 2) {
  1102			uclogic_params_init_invalid(&p);
  1103			goto output;
  1104		}
  1105	
  1106		/*
  1107		 * Initialize the interface by sending magic data.
  1108		 * The specific data was discovered by sniffing the Windows driver
  1109		 * traffic.
  1110		 */
  1111		rc = uclogic_probe_interface(hdev, magic_arr, sizeof(magic_arr), 0x03);
  1112		if (rc) {
  1113			uclogic_params_init_invalid(&p);
  1114			goto output;
  1115		}
  1116	
  1117		/*
  1118		 * Read the string descriptor containing pen and frame parameters.
  1119		 * The specific string descriptor and data were discovered by sniffing
  1120		 * the Windows driver traffic.
  1121		 */
  1122		rc = uclogic_params_get_str_desc(&str_desc, hdev, 100, str_desc_len);
  1123		if (rc != str_desc_len) {
  1124			hid_err(hdev, "failed retrieving pen and frame parameters: %d\n", rc);
  1125			uclogic_params_init_invalid(&p);
  1126			goto output;
  1127		}
  1128	
  1129		desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] =
  1130			get_unaligned_le16(str_desc + 2);
  1131		desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] =
  1132			get_unaligned_le16(str_desc + 4);
  1133		desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM] = str_desc[6];
  1134		desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] =
  1135			get_unaligned_le16(str_desc + 8);
  1136		resolution = get_unaligned_le16(str_desc + 10);
  1137		if (resolution == 0) {
  1138			desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0;
  1139			desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0;
  1140		} else {
  1141			desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM] =
  1142				desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM] * 1000 /
  1143				resolution;
  1144			desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] =
  1145				desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] * 1000 /
  1146				resolution;
  1147		}
  1148		kfree(str_desc);
  1149		str_desc = NULL;
  1150	
  1151		/* Initialize the pen interface */
  1152		rdesc_pen = uclogic_rdesc_template_apply(
  1153					uclogic_rdesc_ugee_v2_pen_template_arr,
  1154					uclogic_rdesc_ugee_v2_pen_template_size,
  1155					desc_params, ARRAY_SIZE(desc_params));
  1156		if (!rdesc_pen) {
  1157			rc = -ENOMEM;
  1158			goto cleanup;
  1159		}
  1160	
  1161		p.pen.desc_ptr = rdesc_pen;
  1162		p.pen.desc_size = uclogic_rdesc_ugee_v2_pen_template_size;
  1163		p.pen.id = 0x02;
  1164		p.pen.subreport_list[0].value = 0xf0;
  1165		p.pen.subreport_list[0].id = UCLOGIC_RDESC_V1_FRAME_ID;
  1166	
  1167		/* Initialize the frame interface */
  1168		rdesc_frame = uclogic_rdesc_template_apply(
  1169					uclogic_rdesc_ugee_v2_frame_btn_template_arr,
  1170					uclogic_rdesc_ugee_v2_frame_btn_template_size,
  1171					desc_params, ARRAY_SIZE(desc_params));
  1172		if (!rdesc_frame) {
  1173			rc = -ENOMEM;
  1174			goto cleanup;
  1175		}
  1176	
  1177		rc = uclogic_params_frame_init_with_desc(&p.frame_list[0],
  1178							 rdesc_frame,
  1179							 uclogic_rdesc_ugee_v2_frame_btn_template_size,
  1180							 UCLOGIC_RDESC_V1_FRAME_ID);
  1181		kfree(rdesc_frame);
  1182		if (rc) {
  1183			uclogic_params_init_invalid(&p);
  1184			goto output;
  1185		}
  1186	
  1187	output:
  1188		/* Output parameters */
  1189		memcpy(params, &p, sizeof(*params));
  1190		memset(&p, 0, sizeof(p));
  1191		rc = 0;
  1192	cleanup:
  1193		kfree(str_desc);
  1194		uclogic_params_cleanup(&p);
  1195		return rc;
  1196	}
  1197	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates
  2022-05-16 18:13 ` [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates José Expósito
@ 2022-05-17 23:30   ` kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2022-05-17 23:30 UTC (permalink / raw)
  To: José Expósito, jikos
  Cc: kbuild-all, benjamin.tissoires, spbnick, linux-input,
	linux-kernel, stefanberzl, José Expósito

Hi "José,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on f7d8e387d9aeff963e6691c0166269b8042b4ff9]

url:    https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
base:   f7d8e387d9aeff963e6691c0166269b8042b4ff9
config: mips-randconfig-s032-20220516 (https://download.01.org/0day-ci/archive/20220518/202205180755.I9jze1Z4-lkp@intel.com/config)
compiler: mipsel-linux-gcc (GCC) 11.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/intel-lab-lkp/linux/commit/d296b420a45eab3527916c73203ed045b65af58e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jos-Exp-sito/Add-support-for-XP-PEN-Deco-L/20220517-021641
        git checkout d296b420a45eab3527916c73203ed045b65af58e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=mips SHELL=/bin/bash drivers/hid/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
   command-line: note: in included file:
   builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_ACQUIRE redefined
   builtin:0:0: sparse: this was the original definition
   builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_SEQ_CST redefined
   builtin:0:0: sparse: this was the original definition
   builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_ACQ_REL redefined
   builtin:0:0: sparse: this was the original definition
   builtin:1:9: sparse: sparse: preprocessor token __ATOMIC_RELEASE redefined
   builtin:0:0: sparse: this was the original definition
   drivers/hid/hid-uclogic-rdesc.c:1014:25: sparse: sparse: incorrect type in assignment (different base types) @@     expected signed int x @@     got restricted __le32 [usertype] @@
   drivers/hid/hid-uclogic-rdesc.c:1014:25: sparse:     expected signed int x
   drivers/hid/hid-uclogic-rdesc.c:1014:25: sparse:     got restricted __le32 [usertype]
>> drivers/hid/hid-uclogic-rdesc.c:1020:44: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned short [usertype] val @@     got restricted __le16 [usertype] @@
   drivers/hid/hid-uclogic-rdesc.c:1020:44: sparse:     expected unsigned short [usertype] val
   drivers/hid/hid-uclogic-rdesc.c:1020:44: sparse:     got restricted __le16 [usertype]

vim +1020 drivers/hid/hid-uclogic-rdesc.c

   974	
   975	const size_t uclogic_rdesc_xppen_deco01_frame_size =
   976				sizeof(uclogic_rdesc_xppen_deco01_frame_arr);
   977	
   978	/**
   979	 * uclogic_rdesc_template_apply() - apply report descriptor parameters to a
   980	 * report descriptor template, creating a report descriptor. Copies the
   981	 * template over to the new report descriptor and replaces every occurrence of
   982	 * the template placeholders, followed by an index byte, with the value from the
   983	 * parameter list at that index.
   984	 *
   985	 * @template_ptr:	Pointer to the template buffer.
   986	 * @template_size:	Size of the template buffer.
   987	 * @param_list:		List of template parameters.
   988	 * @param_num:		Number of parameters in the list.
   989	 *
   990	 * Returns:
   991	 *	Kmalloc-allocated pointer to the created report descriptor,
   992	 *	or NULL if allocation failed.
   993	 */
   994	__u8 *uclogic_rdesc_template_apply(const __u8 *template_ptr,
   995					   size_t template_size,
   996					   const s32 *param_list,
   997					   size_t param_num)
   998	{
   999		static const __u8 btn_head[] = {UCLOGIC_RDESC_FRAME_PH_BTN_HEAD};
  1000		static const __u8 pen_head[] = {UCLOGIC_RDESC_PEN_PH_HEAD};
  1001		__u8 *rdesc_ptr;
  1002		__u8 *p;
  1003		s32 v;
  1004	
  1005		rdesc_ptr = kmemdup(template_ptr, template_size, GFP_KERNEL);
  1006		if (rdesc_ptr == NULL)
  1007			return NULL;
  1008	
  1009		for (p = rdesc_ptr; p + sizeof(btn_head) < rdesc_ptr + template_size;) {
  1010			if (p + sizeof(pen_head) < rdesc_ptr + template_size &&
  1011			    memcmp(p, pen_head, sizeof(pen_head)) == 0 &&
  1012			    p[sizeof(pen_head)] < param_num) {
  1013				v = param_list[p[sizeof(pen_head)]];
  1014				put_unaligned(cpu_to_le32(v), (s32 *)p);
  1015				p += sizeof(pen_head) + 1;
  1016			} else if (memcmp(p, btn_head, sizeof(btn_head)) == 0 &&
  1017				   p[sizeof(btn_head)] < param_num) {
  1018				v = param_list[p[sizeof(btn_head)]];
  1019				put_unaligned((__u8)0x2A, p); /* Usage Maximum */
> 1020				put_unaligned_le16(cpu_to_le16(v), p + 1);

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-05-17 23:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 18:13 [PATCH for-5.19/uclogic 0/4] Add support for XP-PEN Deco L José Expósito
2022-05-16 18:13 ` [PATCH for-5.19/uclogic 1/4] HID: uclogic: Make template placeholder IDs generic José Expósito
2022-05-16 18:13 ` [PATCH for-5.19/uclogic 2/4] HID: uclogic: Add KUnit tests for uclogic_rdesc_template_apply() José Expósito
2022-05-17  7:16   ` kernel test robot
2022-05-16 18:13 ` [PATCH for-5.19/uclogic 3/4] HID: uclogic: Allow to generate frame templates José Expósito
2022-05-17 23:30   ` kernel test robot
2022-05-16 18:13 ` [PATCH for-5.19/uclogic 4/4] HID: uclogic: Add support for XP-PEN Deco L José Expósito
2022-05-17  4:12   ` kernel test robot
2022-05-17 22:50   ` kernel test robot

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