Skip to contentSkip to conversation

Change in handling different input device in hid-multitouch

PATCH In review Benjamin Tissoires 3 participants 7 messages Dec 19, 2013 – Jan 6, 2014 HID

lore
Share & tools
lore
#0 lore raw

cover Change in handling different input device in hid-multitouch

Hi guys,

well, I have been reported a brand new device, which, as always presents a new way of dealing with multitouch and mouse and soever.
The new fancy stuff is capable to report mouse and touch, whereas by default, we consider mouse as garbage.

if you want to get an idea of the device:
http://www.pearl.de/a-PX2569-1002.shtml

So, we need to add a quirk for it, as usual, but I also cleaned up the way we treat the different input devices within the driver. I expect some bikesheding here, so I fire this right now until it's too late for 3.14 or 3.15 :)

Cheers,
Benjamin

Benjamin Tissoires (3):
HID: multitouch: switch to a callback system for handling events
HID: multitouch: introduce mt_protocol_generic
HID: multitouch: add support of other generic collections in hid-mt

 drivers/hid/hid-ids.h        |   3 +
 drivers/hid/hid-multitouch.c | 205 +++++++++++++++++++++++++++++++++----------
 include/linux/hid.h          |   3 +
 3 files changed, 166 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/3 HID: multitouch: switch to a callback system for handling events

In kernel v3.10, we added the support of pen in addition to touch because some devices presents both pen and touch on the same HID device. Now, we are seeing at least one device (ANTON Touch Pad) which presents a multitouch collection and a mouse collection which are both valid.

Instead of adding a lot of ifs and messing up with the code, we can switch to a callback system which allows to define in a better way each protocol used by each input report.

---
 drivers/hid/hid-multitouch.c | 136 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 101 insertions(+), 35 deletions(-)
drivers/hid/hid-multitouch.c +101 -35
index 1f0ba5c..1cdc21a 100644
@@ -91,6 +91,21 @@ struct mt_fields {
 	unsigned int length;
 };
 
+struct mt_protocol {
+	char *suffix;
+	int (*event)(struct hid_device *hdev, struct hid_field *field,
+			struct hid_usage *usage, __s32 value);
+	void (*report)(struct hid_device *hdev, struct hid_report *report);
+	int (*input_mapping)(struct hid_device *hdev,
+			struct hid_input *hidinput, struct hid_field *field,
+			struct hid_usage *usage, unsigned long **bit, int *max);
+	int (*input_mapped)(struct hid_device *hdev,
+			struct hid_input *hidinput, struct hid_field *field,
+			struct hid_usage *usage, unsigned long **bit, int *max);
+	void (*input_configured)(struct hid_device *hdev,
+				 struct hid_input *hidinput);
+};
+
 struct mt_device {
 	struct mt_slot curdata;	/* placeholder of incoming data */
 	struct mt_class mtclass;	/* our mt device class */
@@ -99,8 +114,7 @@ struct mt_device {
 	int cc_index;	/* contact count field index in the report */
 	int cc_value_index;	/* contact count value index in the field */
 	unsigned last_slot_field;	/* the last field of a slot */
-	unsigned mt_report_id;	/* the report ID of the multitouch device */
-	unsigned pen_report_id;	/* the report ID of the pen device */
+	struct mt_protocol protocols[HID_MAX_IDS]; /* per-id callbacks */
 	__s16 inputmode;	/* InputMode HID feature, -1 if non-existent */
 	__s16 inputmode_index;	/* InputMode HID feature index in the report */
 	__s16 maxcontact_report_id;	/* Maximum Contact Number HID feature,
@@ -119,6 +133,54 @@ struct mt_device {
 static void mt_post_parse_default_settings(struct mt_device *td);
 static void mt_post_parse(struct mt_device *td);
 
+static int mt_touch_input_mapping(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max);
+static int mt_touch_input_mapped(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max);
+static int mt_touch_event(struct hid_device *hid,
+		struct hid_field *field, struct hid_usage *usage,
+		__s32 value);
+static void mt_touch_report(struct hid_device *hid,
+		struct hid_report *report);
+static void mt_touch_input_configured(struct hid_device *hdev,
+		struct hid_input *hi);
+
+static struct mt_protocol mt_protocol_touch = {
+	.suffix = NULL,
+	.event = mt_touch_event,
+	.report = mt_touch_report,
+	.input_mapping = mt_touch_input_mapping,
+	.input_mapped = mt_touch_input_mapped,
+	.input_configured = mt_touch_input_configured,
+};
+
+static int mt_pen_input_mapping(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max);
+static int mt_pen_input_mapped(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max);
+static int mt_pen_event(struct hid_device *hid,
+		struct hid_field *field, struct hid_usage *usage,
+		__s32 value);
+static void mt_pen_report(struct hid_device *hid,
+		struct hid_report *report);
+static void mt_pen_input_configured(struct hid_device *hdev,
+		struct hid_input *hi);
+
+static struct mt_protocol mt_protocol_pen = {
+	.suffix = "Pen",
+	.event = mt_pen_event,
+	.report = mt_pen_report,
+	.input_mapping = mt_pen_input_mapping,
+	.input_mapped = mt_pen_input_mapped,
+	.input_configured = mt_pen_input_configured,
+};
+
+static struct mt_protocol mt_protocol_ignore = { 0 };
+
 /* classes of device behavior */
 #define MT_CLS_DEFAULT				0x0001
 
@@ -364,10 +426,6 @@ static int mt_pen_input_mapping(struct hid_device *hdev, struct hid_input *hi,
 		struct hid_field *field, struct hid_usage *usage,
 		unsigned long **bit, int *max)
 {
-	struct mt_device *td = hid_get_drvdata(hdev);
-
-	td->pen_report_id = field->report->id;
-
 	return 0;
 }
 
@@ -480,7 +538,6 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
 		case HID_DG_CONTACTID:
 			mt_store_field(usage, td, hi);
 			td->touches_by_report++;
-			td->mt_report_id = field->report->id;
 			return 1;
 		case HID_DG_WIDTH:
 			hid_map_usage(hi, usage, bit, max,
@@ -776,57 +833,71 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
 		struct hid_field *field, struct hid_usage *usage,
 		unsigned long **bit, int *max)
 {
+	struct mt_device *td = hid_get_drvdata(hdev);
+	unsigned report_id = field->report->id;
+
 	/* Only map fields from TouchScreen or TouchPad collections.
 	* We need to ignore fields that belong to other collections
 	* such as Mouse that might have the same GenericDesktop usages. */
 	if (field->application != HID_DG_TOUCHSCREEN &&
 	    field->application != HID_DG_PEN &&
 	    field->application != HID_DG_TOUCHPAD)
-		return -1;
+		td->protocols[report_id] = mt_protocol_ignore;
 
 	if (field->physical == HID_DG_STYLUS)
-		return mt_pen_input_mapping(hdev, hi, field, usage, bit, max);
+		td->protocols[report_id] = mt_protocol_pen;
+
+	else if (field->application == HID_DG_TOUCHSCREEN ||
+	    field->application == HID_DG_PEN ||
+	    field->application == HID_DG_TOUCHPAD)
+		td->protocols[report_id] = mt_protocol_touch;
 
-	return mt_touch_input_mapping(hdev, hi, field, usage, bit, max);
+	if (td->protocols[report_id].input_mapping)
+		return td->protocols[report_id].input_mapping(hdev, hi,
+				field, usage, bit, max);
+
+	/* ignore if no protocol is given */
+	return -1;
 }
 
 static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
 		struct hid_field *field, struct hid_usage *usage,
 		unsigned long **bit, int *max)
 {
-	if (field->physical == HID_DG_STYLUS)
-		return mt_pen_input_mapped(hdev, hi, field, usage, bit, max);
+	struct mt_device *td = hid_get_drvdata(hdev);
+	unsigned report_id = field->report->id;
+
+	if (td->protocols[report_id].input_mapped)
+		return td->protocols[report_id].input_mapped(hdev, hi, field,
+				usage, bit, max);
 
-	return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
+	/* ignore if no protocol is given */
+	return -1;
 }
 
 static int mt_event(struct hid_device *hid, struct hid_field *field,
 				struct hid_usage *usage, __s32 value)
 {
 	struct mt_device *td = hid_get_drvdata(hid);
+	unsigned report_id = field->report->id;
 
-	if (field->report->id == td->mt_report_id)
-		return mt_touch_event(hid, field, usage, value);
-
-	if (field->report->id == td->pen_report_id)
-		return mt_pen_event(hid, field, usage, value);
+	if (td->protocols[report_id].event)
+		return td->protocols[report_id].event(hid, field, usage, value);
 
-	/* ignore other reports */
+	/* ignore if no protocol is given */
 	return 1;
 }
 
 static void mt_report(struct hid_device *hid, struct hid_report *report)
 {
 	struct mt_device *td = hid_get_drvdata(hid);
+	unsigned report_id = report->id;
 
 	if (!(hid->claimed & HID_CLAIMED_INPUT))
 		return;
 
-	if (report->id == td->mt_report_id)
-		mt_touch_report(hid, report);
-
-	if (report->id == td->pen_report_id)
-		mt_pen_report(hid, report);
+	if (td->protocols[report_id].report)
+		return td->protocols[report_id].report(hid, report);
 }
 
 static void mt_set_input_mode(struct hid_device *hdev)
@@ -906,17 +977,14 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
 {
 	struct mt_device *td = hid_get_drvdata(hdev);
 	char *name;
-	const char *suffix = NULL;
-
-	if (hi->report->id == td->mt_report_id)
-		mt_touch_input_configured(hdev, hi);
+	const char *suffix;
+	unsigned report_id = hi->report->id;
 
-	if (hi->report->field[0]->physical == HID_DG_STYLUS) {
-		suffix = "Pen";
-		mt_pen_input_configured(hdev, hi);
-	}
+	if (td->protocols[report_id].input_configured)
+		td->protocols[report_id].input_configured(hdev, hi);
 
-	if (suffix) {
+	if (td->protocols[report_id].suffix) {
+		suffix = td->protocols[report_id].suffix;
 		name = devm_kzalloc(&hi->input->dev,
 				    strlen(hdev->name) + strlen(suffix) + 2,
 				    GFP_KERNEL);
@@ -974,8 +1042,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	td->inputmode = -1;
 	td->maxcontact_report_id = -1;
 	td->cc_index = -1;
-	td->mt_report_id = -1;
-	td->pen_report_id = -1;
 	hid_set_drvdata(hdev, td);
 
 	td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/3 HID: multitouch: introduce mt_protocol_generic

In reply to Benjamin Tissoires

most of the protocol callbacks used by the pen protocol are generic, they just ask hid-input to treat the incoming data. Introduce a generic protocol to avoid having to copy/paste the pens callbacks for other kinds of input reports.

---
 drivers/hid/hid-multitouch.c | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)
drivers/hid/hid-multitouch.c +26 -16
index 1cdc21a..4dd6c6c 100644
@@ -156,26 +156,36 @@ static struct mt_protocol mt_protocol_touch = {
 	.input_configured = mt_touch_input_configured,
 };
 
-static int mt_pen_input_mapping(struct hid_device *hdev,
+static int mt_generic_input_mapping(struct hid_device *hdev,
 		struct hid_input *hi, struct hid_field *field,
 		struct hid_usage *usage, unsigned long **bit, int *max);
-static int mt_pen_input_mapped(struct hid_device *hdev,
+static int mt_generic_input_mapped(struct hid_device *hdev,
 		struct hid_input *hi, struct hid_field *field,
 		struct hid_usage *usage, unsigned long **bit, int *max);
-static int mt_pen_event(struct hid_device *hid,
+static int mt_generic_event(struct hid_device *hid,
 		struct hid_field *field, struct hid_usage *usage,
 		__s32 value);
-static void mt_pen_report(struct hid_device *hid,
+static void mt_generic_report(struct hid_device *hid,
 		struct hid_report *report);
+
+static struct mt_protocol mt_protocol_generic = {
+	.suffix = NULL,
+	.event = mt_generic_event,
+	.report = mt_generic_report,
+	.input_mapping = mt_generic_input_mapping,
+	.input_mapped = mt_generic_input_mapped,
+	.input_configured = NULL,
+};
+
 static void mt_pen_input_configured(struct hid_device *hdev,
 		struct hid_input *hi);
 
 static struct mt_protocol mt_protocol_pen = {
 	.suffix = "Pen",
-	.event = mt_pen_event,
-	.report = mt_pen_report,
-	.input_mapping = mt_pen_input_mapping,
-	.input_mapped = mt_pen_input_mapped,
+	.event = mt_generic_event,
+	.report = mt_generic_report,
+	.input_mapping = mt_generic_input_mapping,
+	.input_mapped = mt_generic_input_mapped,
 	.input_configured = mt_pen_input_configured,
 };
 
@@ -422,28 +432,28 @@ static void mt_store_field(struct hid_usage *usage, struct mt_device *td,
 	f->usages[f->length++] = usage->hid;
 }
 
-static int mt_pen_input_mapping(struct hid_device *hdev, struct hid_input *hi,
-		struct hid_field *field, struct hid_usage *usage,
-		unsigned long **bit, int *max)
+static int mt_generic_input_mapping(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max)
 {
 	return 0;
 }
 
-static int mt_pen_input_mapped(struct hid_device *hdev, struct hid_input *hi,
-		struct hid_field *field, struct hid_usage *usage,
-		unsigned long **bit, int *max)
+static int mt_generic_input_mapped(struct hid_device *hdev,
+		struct hid_input *hi, struct hid_field *field,
+		struct hid_usage *usage, unsigned long **bit, int *max)
 {
 	return 0;
 }
 
-static int mt_pen_event(struct hid_device *hid, struct hid_field *field,
+static int mt_generic_event(struct hid_device *hid, struct hid_field *field,
 				struct hid_usage *usage, __s32 value)
 {
 	/* let hid-input handle it */
 	return 0;
 }
 
-static void mt_pen_report(struct hid_device *hid, struct hid_report *report)
+static void mt_generic_report(struct hid_device *hid, struct hid_report *report)
 {
 	struct hid_field *field = report->field[0];
 
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/3 HID: multitouch: add support of other generic collections in hid-mt

In reply to Benjamin Tissoires

The ANTEC Touch Pad is a device which can switch from a multitouch touchpad to a mouse. It thus presents several generic collections which are currently ignored by hid-multitouch. Enable them by using the generic protocol. Adding also a suffix for them depending on their application.

---
 drivers/hid/hid-ids.h        |  3 +++
 drivers/hid/hid-multitouch.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 include/linux/hid.h          |  3 +++
 3 files changed, 46 insertions(+), 3 deletions(-)
drivers/hid/hid-ids.h +3 -0
index 2bf397f..4221494 100644
@@ -67,6 +67,9 @@
 #define USB_VENDOR_ID_ALPS		0x0433
 #define USB_DEVICE_ID_IBM_GAMEPAD	0x1101
 
+#define USB_VENDOR_ID_ANTON		0x1130
+#define USB_DEVICE_ID_ANTON_TOUCH_PAD	0x3101
+
 #define USB_VENDOR_ID_APPLE		0x05ac
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE	0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE	0x030d
drivers/hid/hid-multitouch.c +40 -3

89 lines not on this page · raw message

include/linux/hid.h +3 -0
index 31b9d29..2b2041a 100644
@@ -201,6 +201,7 @@ struct hid_item {
 #define HID_GD_VBRZ		0x00010045
 #define HID_GD_VNO		0x00010046
 #define HID_GD_FEATURE		0x00010047
+#define HID_GD_SYSTEM_CONTROL	0x00010080
 #define HID_GD_UP		0x00010090
 #define HID_GD_DOWN		0x00010091
 #define HID_GD_RIGHT		0x00010092
@@ -208,6 +209,8 @@ struct hid_item {
 
 #define HID_DC_BATTERYSTRENGTH	0x00060020
 
+#define HID_CP_CONSUMER_CONTROL	0x000c0001
+
 #define HID_DG_DIGITIZER	0x000d0001
 #define HID_DG_PEN		0x000d0002
 #define HID_DG_LIGHTPEN		0x000d0003
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [patch 3/3] HID: multitouch: add support of other generic collections in hid-mt

Hi Benjamin,

Quoted 4 lines

The ANTEC Touch Pad is a device which can switch from a multitouch touchpad to a mouse. It thus presents several generic collections which are currently ignored by hid-multitouch. Enable them by using the generic protocol. Adding also a suffix for them depending on their application.

In what way does this and the preceeding patches differ from "else if (is_pen || export_all_inputs)"? Adding a functional pattern which then is converted to a generic case, such that the usual branching is bound to occur anyways, seems unnecessary.

Thanks,
Henrik

#5 lore raw

Re: [patch 3/3] HID: multitouch: add support of other generic collections in hid-mt

Quoted 9 lines · Henrik Rydberg
Quoted 4 lines

The ANTEC Touch Pad is a device which can switch from a multitouch touchpad to a mouse. It thus presents several generic collections which are currently ignored by hid-multitouch. Enable them by using the generic protocol. Adding also a suffix for them depending on their application.

In what way does this and the preceeding patches differ from "else if (is_pen || export_all_inputs)"? Adding a functional pattern which then is converted to a generic case, such that the usual branching is bound to occur anyways, seems unnecessary.

Benjamin,

did you have chance to do any followup work on this?

If this is to go into 3.14, it's the time to have the thing finalized.

Thanks,

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

Re: [patch 3/3] HID: multitouch: add support of other generic collections in hid-mt

Quoted 12 lines · Jiri Kosina
Quoted 9 lines · Henrik Rydberg
Quoted 4 lines

The ANTEC Touch Pad is a device which can switch from a multitouch touchpad to a mouse. It thus presents several generic collections which are currently ignored by hid-multitouch. Enable them by using the generic protocol. Adding also a suffix for them depending on their application.

In what way does this and the preceeding patches differ from "else if (is_pen || export_all_inputs)"? Adding a functional pattern which then is converted to a generic case, such that the usual branching is bound to occur anyways, seems unnecessary.

Quoted 6 lines

Benjamin,

did you have chance to do any followup work on this?

If this is to go into 3.14, it's the time to have the thing finalized.

Hi Jiri,

well, I'm still not sure what to answer to address Henrik's comments. I will work on that later in the week I think, but currently I am focusing on hid-logitech-dj and others, which is rather time consuming.

I think Maks is fine with the current status (he still have to use a backport due to an arm platform), so let's skip this for 3.15.

Cheers,
Benjamin