Skip to contentSkip to conversation

HID: initial USI support patches

PATCH In review Tero Kristo 2 participants 10 messages Dec 10, 2021 – Dec 14, 2021 HID

lore
Share & tools
lore
#0 lore raw

v4 cover HID: initial USI support patches

Hi,

As per request, this set contains initial USI support patches targeted for 5.17. Any patches still under discussion dropped from this set. Patch #3 is a split from previous revision, only containing the HID usage definitions.

Series is based on top of hid/for-next.

-Tero

#1 lore raw

PATCH v4 1/5 HID: Add map_msc() to avoid boilerplate code

From: Mika Westerberg <[email protected]>

Since we are going to have more MSC events too, add map_msc() that can be used to fill in necessary fields and avoid boilerplate code.

---
 drivers/hid/hid-input.c | 6 ++----
 include/linux/hid.h     | 4 ++++
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/hid/hid-input.c +2 -4
index 03f994541981..ad718ceb8af3 100644
@@ -52,6 +52,7 @@ static const struct {
 #define map_rel(c)	hid_map_usage(hidinput, usage, &bit, &max, EV_REL, (c))
 #define map_key(c)	hid_map_usage(hidinput, usage, &bit, &max, EV_KEY, (c))
 #define map_led(c)	hid_map_usage(hidinput, usage, &bit, &max, EV_LED, (c))
+#define map_msc(c)	hid_map_usage(hidinput, usage, &bit, &max, EV_MSC, (c))
 
 #define map_abs_clear(c)	hid_map_usage_clear(hidinput, usage, &bit, \
 		&max, EV_ABS, (c))
@@ -876,10 +877,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
 
 		case 0x5b: /* TransducerSerialNumber */
 		case 0x6e: /* TransducerSerialNumber2 */
-			usage->type = EV_MSC;
-			usage->code = MSC_SERIAL;
-			bit = input->mscbit;
-			max = MSC_MAX;
+			map_msc(MSC_SERIAL);
 			break;
 
 		default:  goto unknown;
include/linux/hid.h +4 -0
index 313fa4a2554f..cc797d608951 100644
@@ -1015,6 +1015,10 @@ static inline void hid_map_usage(struct hid_input *hidinput,
 		bmap = input->ledbit;
 		limit = LED_MAX;
 		break;
+	case EV_MSC:
+		bmap = input->mscbit;
+		limit = MSC_MAX;
+		break;
 	}
 
 	if (unlikely(c > limit || !bmap)) {
Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 2/5 HID: hid-input: Add suffix also for HID_DG_PEN

In reply to Tero Kristo

From: Mika Westerberg <[email protected]>

This and HID_DG_STYLUS are pretty much the same thing so add suffix for HID_DG_PEN too. This makes the input device name look better.

While doing this, remove the suffix override from hid-multitouch, as it is now handled by hid-input. Also, the suffix override done by hid-multitouch was wrong, as it mapped HID_DG_PEN => "Stylus" and HID_DG_STYLUS => "Pen".

---
 drivers/hid/hid-input.c      | 1 +
 drivers/hid/hid-multitouch.c | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-input.c +1 -0
index ad718ceb8af3..78205e445652 100644
@@ -1741,6 +1741,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid,
 		case HID_GD_MOUSE:
 			suffix = "Mouse";
 			break;
+		case HID_DG_PEN:
 		case HID_DG_STYLUS:
 			suffix = "Pen";
 			break;
drivers/hid/hid-multitouch.c +0 -3
index 082376a6cb3d..99eabfb4145b 100644
@@ -1606,9 +1606,6 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
 	case HID_DG_STYLUS:
 		/* force BTN_STYLUS to allow tablet matching in udev */
 		__set_bit(BTN_STYLUS, hi->input->keybit);
-		fallthrough;
-	case HID_DG_PEN:
-		suffix = "Stylus";
 		break;
 	default:
 		suffix = "UNKNOWN";
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCHv4 2/5] HID: hid-input: Add suffix also for HID_DG_PEN

Quoted 10 lines · Tero Kristo

From: Mika Westerberg <[email protected]>

This and HID_DG_STYLUS are pretty much the same thing so add suffix for HID_DG_PEN too. This makes the input device name look better.

While doing this, remove the suffix override from hid-multitouch, as it is now handled by hid-input. Also, the suffix override done by hid-multitouch was wrong, as it mapped HID_DG_PEN => "Stylus" and HID_DG_STYLUS => "Pen".

FWIW, I was thinking at the following:
---

drivers/hid/hid-input.c +9 -0
index 837585f4e673..fe0da7bf24a9 100644
@@ -1775,6 +1775,15 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid,
                        suffix = "Mouse";
                        break;
                case HID_DG_PEN:
+                       /*
+                        * yes, there is an issue here:
+                        *  DG_PEN -> "Stylus"
+                        *  DG_STYLUS -> "Pen"
+                        * But changing this now means users with config snippets
+                        * will have to change it and the test suite will not be happy.
+                        */
+                       suffix = "Stylus";
+                       break;
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;

---

Because the current patch breaks the test suite.

Cheers,
Benjamin

Quoted 37 lines
---
 drivers/hid/hid-input.c      | 1 +
 drivers/hid/hid-multitouch.c | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-input.c +1 -0
index ad718ceb8af3..78205e445652 100644
@@ -1741,6 +1741,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid,
                case HID_GD_MOUSE:
                        suffix = "Mouse";
                        break;
+               case HID_DG_PEN:
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;
drivers/hid/hid-multitouch.c +0 -4
index 082376a6cb3d..99eabfb4145b 100644
@@ -1606,9 +1606,6 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
        case HID_DG_STYLUS:
                /* force BTN_STYLUS to allow tablet matching in udev */
                __set_bit(BTN_STYLUS, hi->input->keybit);
-               fallthrough;
-       case HID_DG_PEN:
-               suffix = "Stylus";
                break;
        default:
                suffix = "UNKNOWN";
--

2.25.1

#4 lore raw

Re: [PATCHv4 2/5] HID: hid-input: Add suffix also for HID_DG_PEN

Quoted 41 lines · Benjamin Tissoires
Quoted 10 lines · Tero Kristo

From: Mika Westerberg <[email protected]>

This and HID_DG_STYLUS are pretty much the same thing so add suffix for HID_DG_PEN too. This makes the input device name look better.

While doing this, remove the suffix override from hid-multitouch, as it is now handled by hid-input. Also, the suffix override done by hid-multitouch was wrong, as it mapped HID_DG_PEN => "Stylus" and HID_DG_STYLUS => "Pen".

FWIW, I was thinking at the following:
---

drivers/hid/hid-input.c +0 -0
index 837585f4e673..fe0da7bf24a9 100644
@@ -1775,6 +1775,15 @@ static struct hid_input 
 *hidinput_allocate(struct hid_device *hid,
                         suffix = "Mouse";
                         break;

                case HID_DG_PEN:
+                       /*
+                        * yes, there is an issue here:
+                        *  DG_PEN -> "Stylus"
+                        *  DG_STYLUS -> "Pen"
+                        * But changing this now means users with config snippets
+                        * will have to change it and the test suite will not be happy.
+                        */
+                       suffix = "Stylus";
+                       break;
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;
---

Quoted 1 line

Because the current patch breaks the test suite.

Ah I see, do you want me to re-post in this form?

-Tero

Quoted 44 lines

Cheers,
Benjamin

Quoted 39 lines

---
 drivers/hid/hid-input.c      | 1 +
 drivers/hid/hid-multitouch.c | 3 ---

 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-input.c +0 -0
index ad718ceb8af3..78205e445652 100644
@@ -1741,6 +1741,7 @@ static struct hid_input 
 *hidinput_allocate(struct hid_device *hid,

                case HID_GD_MOUSE:
                        suffix = "Mouse";
                        break;
+               case HID_DG_PEN:
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;

drivers/hid/hid-multitouch.c +0 -0
index 082376a6cb3d..99eabfb4145b 100644
@@ -1606,9 +1606,6 @@ static int mt_input_configured(struct 
 hid_device *hdev, struct hid_input *hi)

        case HID_DG_STYLUS:
                /* force BTN_STYLUS to allow tablet matching in udev */ __set_bit(BTN_STYLUS, hi->input->keybit);
-               fallthrough;
-       case HID_DG_PEN:
-               suffix = "Stylus";
                break;
        default:
                suffix = "UNKNOWN";

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCHv4 2/5] HID: hid-input: Add suffix also for HID_DG_PEN

Quoted 45 lines · Tero Kristo
Quoted 42 lines · Benjamin Tissoires
Quoted 10 lines · Tero Kristo

From: Mika Westerberg <[email protected]>

This and HID_DG_STYLUS are pretty much the same thing so add suffix for HID_DG_PEN too. This makes the input device name look better.

While doing this, remove the suffix override from hid-multitouch, as it is now handled by hid-input. Also, the suffix override done by hid-multitouch was wrong, as it mapped HID_DG_PEN => "Stylus" and HID_DG_STYLUS => "Pen".

FWIW, I was thinking at the following:
---

drivers/hid/hid-input.c +5 -0
index 837585f4e673..fe0da7bf24a9 100644
@@ -1775,6 +1775,15 @@ static struct hid_input
 *hidinput_allocate(struct hid_device *hid,
                        suffix = "Mouse";
                        break;
                case HID_DG_PEN:
+                       /*
+                        * yes, there is an issue here:
+                        *  DG_PEN -> "Stylus"
+                        *  DG_STYLUS -> "Pen"
+                        * But changing this now means users with

config snippets
+ * will have to change it and the test suite
will not be happy.

drivers/hid/hid-input.c +3 -1
+                        */
+                       suffix = "Stylus";
+                       break;
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;
---
Quoted 3 lines
Quoted 1 line

Because the current patch breaks the test suite.

Ah I see, do you want me to re-post in this form?

Nah, no need for a repost. I fixed the patch locally and pushed to for-5.17/core.

Cheers,
Benjamin

Quoted 48 lines

-Tero

Quoted 44 lines

Cheers,
Benjamin

Quoted 39 lines
---
 drivers/hid/hid-input.c      | 1 +
 drivers/hid/hid-multitouch.c | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-input.c +1 -0
index ad718ceb8af3..78205e445652 100644
@@ -1741,6 +1741,7 @@ static struct hid_input
 *hidinput_allocate(struct hid_device *hid,
                case HID_GD_MOUSE:
                        suffix = "Mouse";
                        break;
+               case HID_DG_PEN:
                case HID_DG_STYLUS:
                        suffix = "Pen";
                        break;
drivers/hid/hid-multitouch.c +0 -3
index 082376a6cb3d..99eabfb4145b 100644
@@ -1606,9 +1606,6 @@ static int mt_input_configured(struct
 hid_device *hdev, struct hid_input *hi)
        case HID_DG_STYLUS:
                /* force BTN_STYLUS to allow tablet matching in udev */
                __set_bit(BTN_STYLUS, hi->input->keybit);
-               fallthrough;
-       case HID_DG_PEN:
-               suffix = "Stylus";
                break;
        default:
                suffix = "UNKNOWN";

--
2.25.1

#6 lore raw

Re: [PATCHv4 2/5] HID: hid-input: Add suffix also for HID_DG_PEN

Quoted 42 lines · Benjamin Tissoires
Quoted 41 lines · Tero Kristo
Quoted 39 lines · Benjamin Tissoires
Quoted 9 lines · Tero Kristo

From: Mika Westerberg <[email protected]>

This and HID_DG_STYLUS are pretty much the same thing so add suffix for HID_DG_PEN too. This makes the input device name look better.

While doing this, remove the suffix override from hid-multitouch, as it is now handled by hid-input. Also, the suffix override done by hid-multitouch was wrong, as it mapped HID_DG_PEN => "Stylus" and HID_DG_STYLUS => "Pen".

FWIW, I was thinking at the following:
---

drivers/hid/hid-input.c +5 -0
index 837585f4e673..fe0da7bf24a9 100644
@@ -1775,6 +1775,15 @@ static struct hid_input
 *hidinput_allocate(struct hid_device *hid,
                         suffix = "Mouse";
                         break;
                 case HID_DG_PEN:
+                       /*
+                        * yes, there is an issue here:
+                        *  DG_PEN -> "Stylus"
+                        *  DG_STYLUS -> "Pen"
+                        * But changing this now means users with

config snippets
+ * will have to change it and the test suite
will not be happy.

drivers/hid/hid-input.c +3 -1
+                        */
+                       suffix = "Stylus";
+                       break;
                 case HID_DG_STYLUS:
                         suffix = "Pen";
                         break;
---
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Because the current patch breaks the test suite.

Ah I see, do you want me to re-post in this form?

Nah, no need for a repost. I fixed the patch locally and pushed to for-5.17/core.

Thanks a lot!

-Tero

Quoted 46 lines

Cheers,
Benjamin

Quoted 43 lines

-Tero

Quoted 41 lines

Cheers,
Benjamin

Quoted 38 lines
---
  drivers/hid/hid-input.c      | 1 +
  drivers/hid/hid-multitouch.c | 3 ---
  2 files changed, 1 insertion(+), 3 deletions(-)
drivers/hid/hid-input.c +1 -0
index ad718ceb8af3..78205e445652 100644
@@ -1741,6 +1741,7 @@ static struct hid_input
 *hidinput_allocate(struct hid_device *hid,
                 case HID_GD_MOUSE:
                         suffix = "Mouse";
                         break;
+               case HID_DG_PEN:
                 case HID_DG_STYLUS:
                         suffix = "Pen";
                         break;
drivers/hid/hid-multitouch.c +0 -3
index 082376a6cb3d..99eabfb4145b 100644
@@ -1606,9 +1606,6 @@ static int mt_input_configured(struct
 hid_device *hdev, struct hid_input *hi)
         case HID_DG_STYLUS:
                 /* force BTN_STYLUS to allow tablet matching in udev */
                 __set_bit(BTN_STYLUS, hi->input->keybit);
-               fallthrough;
-       case HID_DG_PEN:
-               suffix = "Stylus";
                 break;
         default:
                 suffix = "UNKNOWN";

--
2.25.1

#7 lore raw

PATCH v4 3/5 HID: Add hid usages for USI style pens

In reply to Tero Kristo

Add usage codes for USI style pens, based on the USB-HID usage table:
https://usb.org/document-library/hid-usage-tables-122

See chapter 16, Digitizers Page (0x0D)

---
 include/linux/hid.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/hid.h +10 -0
index cc797d608951..b8634d17d11e 100644
@@ -241,6 +241,7 @@ struct hid_item {
 #define HID_DG_TOUCH		0x000d0033
 #define HID_DG_UNTOUCH		0x000d0034
 #define HID_DG_TAP		0x000d0035
+#define HID_DG_TRANSDUCER_INDEX	0x000d0038
 #define HID_DG_TABLETFUNCTIONKEY	0x000d0039
 #define HID_DG_PROGRAMCHANGEKEY	0x000d003a
 #define HID_DG_BATTERYSTRENGTH	0x000d003b
@@ -253,6 +254,15 @@ struct hid_item {
 #define HID_DG_BARRELSWITCH	0x000d0044
 #define HID_DG_ERASER		0x000d0045
 #define HID_DG_TABLETPICK	0x000d0046
+#define HID_DG_PEN_COLOR			0x000d005c
+#define HID_DG_PEN_LINE_WIDTH			0x000d005e
+#define HID_DG_PEN_LINE_STYLE			0x000d0070
+#define HID_DG_PEN_LINE_STYLE_INK		0x000d0072
+#define HID_DG_PEN_LINE_STYLE_PENCIL		0x000d0073
+#define HID_DG_PEN_LINE_STYLE_HIGHLIGHTER	0x000d0074
+#define HID_DG_PEN_LINE_STYLE_CHISEL_MARKER	0x000d0075
+#define HID_DG_PEN_LINE_STYLE_BRUSH		0x000d0076
+#define HID_DG_PEN_LINE_STYLE_NO_PREFERENCE	0x000d0077
 
 #define HID_CP_CONSUMERCONTROL	0x000c0001
 #define HID_CP_NUMERICKEYPAD	0x000c0002
Signature · 1 line
2.25.1
#8 lore raw

PATCH v4 4/5 HID: input: Make hidinput_find_field() static

In reply to Tero Kristo

From: Mika Westerberg <[email protected]>

This function is not called outside of hid-input.c so we can make it static.

---
 drivers/hid/hid-input.c | 4 ++--
 include/linux/hid.h     | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid-input.c +2 -2
index 78205e445652..1179ef1d257a 100644
@@ -1463,7 +1463,8 @@ void hidinput_report_event(struct hid_device *hid, struct hid_report *report)
 }
 EXPORT_SYMBOL_GPL(hidinput_report_event);
 
-int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field)
+static int hidinput_find_field(struct hid_device *hid, unsigned int type,
+			       unsigned int code, struct hid_field **field)
 {
 	struct hid_report *report;
 	int i, j;
@@ -1478,7 +1479,6 @@ int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int
 	}
 	return -1;
 }
-EXPORT_SYMBOL_GPL(hidinput_find_field);
 
 struct hid_field *hidinput_get_led_field(struct hid_device *hid)
 {
include/linux/hid.h +0 -1
index b8634d17d11e..6b482c855605 100644
@@ -904,7 +904,6 @@ extern void hidinput_disconnect(struct hid_device *);
 
 int hid_set_field(struct hid_field *, unsigned, __s32);
 int hid_input_report(struct hid_device *, int type, u8 *, u32, int);
-int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
 struct hid_field *hidinput_get_led_field(struct hid_device *hid);
 unsigned int hidinput_count_leds(struct hid_device *hid);
 __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code);
Signature · 1 line
2.25.1
#9 lore raw

PATCH v4 5/5 HID: debug: Add USI usages

In reply to Tero Kristo

From: Mika Westerberg <[email protected]>

Add USI defined usages to the HID debug code.

---
 drivers/hid/hid-debug.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/hid/hid-debug.c +35 -0
index 7a92e2a04a09..26c31d759914 100644
@@ -141,8 +141,10 @@ static const struct hid_usage_entry hid_usage_table[] = {
     {0, 0x33, "Touch"},
     {0, 0x34, "UnTouch"},
     {0, 0x35, "Tap"},
+    {0, 0x38, "Transducer Index"},
     {0, 0x39, "TabletFunctionKey"},
     {0, 0x3a, "ProgramChangeKey"},
+    {0, 0x3B, "Battery Strength"},
     {0, 0x3c, "Invert"},
     {0, 0x42, "TipSwitch"},
     {0, 0x43, "SecondaryTipSwitch"},
@@ -160,7 +162,40 @@ static const struct hid_usage_entry hid_usage_table[] = {
     {0, 0x59, "ButtonType"},
     {0, 0x5A, "SecondaryBarrelSwitch"},
     {0, 0x5B, "TransducerSerialNumber"},
+    {0, 0x5C, "Preferred Color"},
+    {0, 0x5D, "Preferred Color is Locked"},
+    {0, 0x5E, "Preferred Line Width"},
+    {0, 0x5F, "Preferred Line Width is Locked"},
     {0, 0x6e, "TransducerSerialNumber2"},
+    {0, 0x70, "Preferred Line Style"},
+      {0, 0x71, "Preferred Line Style is Locked"},
+      {0, 0x72, "Ink"},
+      {0, 0x73, "Pencil"},
+      {0, 0x74, "Highlighter"},
+      {0, 0x75, "Chisel Marker"},
+      {0, 0x76, "Brush"},
+      {0, 0x77, "No Preference"},
+    {0, 0x80, "Digitizer Diagnostic"},
+    {0, 0x81, "Digitizer Error"},
+      {0, 0x82, "Err Normal Status"},
+      {0, 0x83, "Err Transducers Exceeded"},
+      {0, 0x84, "Err Full Trans Features Unavailable"},
+      {0, 0x85, "Err Charge Low"},
+    {0, 0x90, "Transducer Software Info"},
+      {0, 0x91, "Transducer Vendor Id"},
+      {0, 0x92, "Transducer Product Id"},
+    {0, 0x93, "Device Supported Protocols"},
+    {0, 0x94, "Transducer Supported Protocols"},
+      {0, 0x95, "No Protocol"},
+      {0, 0x96, "Wacom AES Protocol"},
+      {0, 0x97, "USI Protocol"},
+      {0, 0x98, "Microsoft Pen Protocol"},
+    {0, 0xA0, "Supported Report Rates"},
+      {0, 0xA1, "Report Rate"},
+      {0, 0xA2, "Transducer Connected"},
+      {0, 0xA3, "Switch Disabled"},
+      {0, 0xA4, "Switch Unimplemented"},
+      {0, 0xA5, "Transducer Switches"},
   { 15, 0, "PhysicalInterfaceDevice" },
     {0, 0x00, "Undefined"},
     {0, 0x01, "Physical_Interface_Device"},
Signature · 1 line
2.25.1