HID: hid-multitouch: fix input mode feature command
PATCH 1/3 HID: hid-multitouch: fix input mode feature command
From: Benjamin Tissoires <[email protected]>
Zytronic panels shows a new way of setting the Input Mode feature. This feature is put in the second usage in the HID feature, instead of the first, as the majority of the multitouch devices.
This patch adds a detection step when the feature is presented to know where the feature is located in the report. We can then trigger the right command to the device. This removes the magic number "0" in the function mt_set_input_mode.
--- drivers/hid/hid-multitouch.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/hid/hid-multitouch.c +12 -1
@@ -83,6 +83,7 @@ struct mt_device {unsigned last_field_index;/* last field index of the report */ unsigned last_slot_field;/* the last field of a slot */ __s8 inputmode;/* InputMode HID feature, -1 if non-existent */ +__s8 inputmode_index;/* InputMode HID feature index in the report */ __s8 maxcontact_report_id;/* Maximum Contact Number HID feature, -1 if non-existent */ __u8 num_received;/* how many contacts we received */
@@ -260,10 +261,20 @@ static void mt_feature_mapping(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage) { struct mt_device *td = hid_get_drvdata(hdev); +int i;switch (usage->hid) {case HID_DG_INPUTMODE : td->inputmode = field->report->id; + td->inputmode_index =0 ;/* has to be updated below */ + +for (i=0 ; i < field->maxusage; i++) { +if (field->usage[i].hid == usage->hid) { + td->inputmode_index = i; +break ; + } + } +break ;case HID_DG_CONTACTMAX : td->maxcontact_report_id = field->report->id;
@@ -618,7 +629,7 @@ static void mt_set_input_mode(struct hid_device *hdev) re = &(hdev->report_enum[HID_FEATURE_REPORT ]); r = re->report_id_hash[td->inputmode];if (r) { - r->field[0 ]->value[0 ] =0x02 ; + r->field[0 ]->value[td->inputmode_index] =0x02 ;usbhid_submit_report (hdev, r,USB_DIR_OUT ); } }
Signature · 1 line
1.7.10.2
PATCH 2/3 HID: hid-multitouch: support arrays for the split of the touches in a report
From: Benjamin Tissoires <[email protected]>
Win8 certification introduced the ability to transmit two X and two Y per touch. The specification precises that it must be in an array, with a report count == 2.
This test guarantees that we split the touches on the last element in this array.
--- drivers/hid/hid-multitouch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hid/hid-multitouch.c +4 -1
@@ -601,7 +601,10 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,return 0 ; } -if (usage->hid == td->last_slot_field) +if (usage->hid == td->last_slot_field && + usage == &field->usage[field->maxusage -1 ]) +/* we only take into account the last report +* of a field if report_count > 1 */ mt_complete_slot (td); if (field->index == td->last_field_index
Signature · 1 line
1.7.10.2
Re: [PATCH 2/3] HID: hid-multitouch: support arrays for the split of the touches in a report
Hi Benjamin,
Quoted 17 lines
Win8 certification introduced the ability to transmit two X and two Y per touch. The specification precises that it must be in an array, with a report count == 2.
This test guarantees that we split the touches on the last element in this array.
Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/hid-multitouch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/hid/hid-multitouch.c +0
-0
drivers/hid/hid-multitouch.c static int mt_event(struct hid_device *hid, struct hid_field *field, · line 607
Quoted 8 lines
drivers/hid/hid-multitouch.c +4
-1@@ -601,7 +601,10 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,return 0 ; } -if (usage->hid == td->last_slot_field) +if (usage->hid == td->last_slot_field && + usage == &field->usage[field->maxusage -1 ]) +/* we only take into account the last report +* of a field if report_count > 1 */
This just looks so fragile... The report index should really be amount the arguments to mt_event(). Since we rely on the pointer to reveal the index, why not try something like (usage - &field->usage[0]) == (field->report_count - 1)? At least it shows clearly what we use the point for.
Quoted 6 lines
drivers/hid/hid-multitouch.c +0
-0mt_complete_slot (td); if (field->index == td->last_field_indexSignature · 1 line
1.7.10.2
Thanks,
Henrik
PATCH 3/3 HID: hid-multitouch: add support for Zytronic panels
In reply to benjamin.tissoiresFrom: Benjamin Tissoires <[email protected]>
--- drivers/hid/Kconfig | 1 + drivers/hid/hid-ids.h | 3 +++ drivers/hid/hid-multitouch.c | 5 +++++ 3 files changed, 9 insertions(+)
drivers/hid/Kconfig +1 -0
@@ -393,6 +393,7 @@ config HID_MULTITOUCH - Unitec Panels - XAT optical touch panels - Xiroku optical touch panels + - Zytronic touch panels If unsure, say N.
drivers/hid/hid-ids.h +3 -0
@@ -802,6 +802,9 @@#define USB_VENDOR_ID_ZYDACRON 0x13EC#define USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL 0x0006 +#define USB_VENDOR_ID_ZYTRONIC 0x14c8 +#define USB_DEVICE_ID_ZYTRONIC_ZXY100 0x0005 +#define USB_VENDOR_ID_PRIMAX 0x0461#define USB_DEVICE_ID_PRIMAX_KEYBOARD 0x4e05
drivers/hid/hid-multitouch.c +5 -0
@@ -1067,6 +1067,11 @@ static const struct hid_device_id mt_devices[] = {MT_USB_DEVICE (USB_VENDOR_ID_XIROKU , USB_DEVICE_ID_XIROKU_CSR2) }, + /* Zytronic panels */ + { .driver_data = MT_CLS_SERIAL, +MT_USB_DEVICE (USB_VENDOR_ID_ZYTRONIC , + USB_DEVICE_ID_ZYTRONIC_ZXY100) }, +/* Generic MT device */ { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) }, { }
Signature · 1 line
1.7.10.2
Hi Benjamin,
Quoted 27 lines
Zytronic panels shows a new way of setting the Input Mode feature. This feature is put in the second usage in the HID feature, instead of the first, as the majority of the multitouch devices.
This patch adds a detection step when the feature is presented to know where the feature is located in the report. We can then trigger the right command to the device. This removes the magic number "0" in the function
mt_set_input_mode.Signed-off-by Benjamin Tissoires <[email protected]>--- drivers/hid/hid-multitouch.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/hid/hid-multitouch.c +1
-0@@ -83,6 +83,7 @@ struct mt_device {unsigned last_field_index;/* last field index of the report */ unsigned last_slot_field;/* the last field of a slot */ __s8 inputmode;/* InputMode HID feature, -1 if non-existent */ +__s8 inputmode_index;/* InputMode HID feature index in the report */ __s8 maxcontact_report_id;/* Maximum Contact Number HID feature, -1 if non-existent */ __u8 num_received;/* how many contacts we received */
drivers/hid/hid-multitouch.c static void mt_feature_mapping(struct hid_device *hdev, · line 264
Quoted 4 lines
drivers/hid/hid-multitouch.c +1
-0@@ -260,10 +261,20 @@ static void mt_feature_mapping(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage) { struct mt_device *td = hid_get_drvdata(hdev); +int i;
Or a separate function to keep thing neat?
drivers/hid/hid-multitouch.c static void mt_feature_mapping(struct hid_device *hdev, · line 269
Quoted 5 lines
drivers/hid/hid-multitouch.c +1
-0switch (usage->hid) {case HID_DG_INPUTMODE : td->inputmode = field->report->id; + td->inputmode_index =0 ;/* has to be updated below */
Isn't this zero already?
drivers/hid/hid-multitouch.c static void mt_feature_mapping(struct hid_device *hdev, · line 274
Quoted 5 lines
drivers/hid/hid-multitouch.c +5
-0+ +for (i=0 ; i < field->maxusage; i++) { +if (field->usage[i].hid == usage->hid) { + td->inputmode_index = i; +break ;
The break here is an optimization of the dubious kind. ;-) Or do we expect more than one occurence?
Quoted 18 lines
drivers/hid/hid-multitouch.c +4
-1+ } + } +break ;case HID_DG_CONTACTMAX : td->maxcontact_report_id = field->report->id;@@ -618,7 +629,7 @@ static void mt_set_input_mode(struct hid_device *hdev) re = &(hdev->report_enum[HID_FEATURE_REPORT ]); r = re->report_id_hash[td->inputmode];if (r) { - r->field[0 ]->value[0 ] =0x02 ; + r->field[0 ]->value[td->inputmode_index] =0x02 ;usbhid_submit_report (hdev, r,USB_DIR_OUT ); } }Signature · 1 line
1.7.10.2
Thanks,
Henrik
Quoted 10 lines · benjamin.tissoires
From: Benjamin Tissoires <[email protected]>
Zytronic panels shows a new way of setting the Input Mode feature. This feature is put in the second usage in the HID feature, instead of the first, as the majority of the multitouch devices.
This patch adds a detection step when the feature is presented to know where the feature is located in the report. We can then trigger the right command to the device. This removes the magic number "0" in the function
mt_set_input_mode.
I have applied 1/3 and 3/3. For 2/3, Henrik raised concern which I'd like to have resolved first.
Thanks!
Signature · 2 lines
Jiri Kosina SUSE Labs
Hi Jiri,
Thanks a lot for that.
My apologies. I didn't thanked Henrik and commented his review. So thank you Henrik. (the "break" here is not an optimisation as field->maxusage may be greater than the real report count).
I'm currently quite overloaded with the hid over i2c bus, and I'm getting some very goods results. I'm stuck with the acpi part, but the rest of it is working pretty good for a draft. I'll keep you inform soon.
Cheers,
Benjamin
Quoted 21 lines · Jiri Kosina
Quoted 10 lines · benjamin.tissoires
From: Benjamin Tissoires <[email protected]>
Zytronic panels shows a new way of setting the Input Mode feature. This feature is put in the second usage in the HID feature, instead of the first, as the majority of the multitouch devices.
This patch adds a detection step when the feature is presented to know where the feature is located in the report. We can then trigger the right command to the device. This removes the magic number "0" in the function
mt_set_input_mode.I have applied 1/3 and 3/3. For 2/3, Henrik raised concern which I'd like to have resolved first.
Thanks!
--
Jiri Kosina
SUSE Labs
Quoted 4 lines · Benjamin Tissoires
Thanks a lot for that.
My apologies. I didn't thanked Henrik and commented his review. So thank you Henrik. (the "break" here is not an optimisation asfield->maxusagemay be greater than the real report count).
Yes, I thought so, and therefore applied that patch. 2/3 I am still keeping unapplied.
Quoted 4 lines
I'm currently quite overloaded with the hid over i2c bus, and I'm getting some very goods results. I'm stuck with the acpi part, but the rest of it is working pretty good for a draft. I'll keep you inform soon.
Sounds great, looking forward to seeing the implementation :)
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs