All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing
@ 2015-07-21 18:07 Jason Gerecke
  2015-07-21 18:07 ` [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count Jason Gerecke
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jason Gerecke @ 2015-07-21 18:07 UTC (permalink / raw)
  To: Jiri Kosina, Ping Cheng, Benjamin Tissoires
  Cc: Aaron Skomra, linux-input, Jason Gerecke, Jason Gerecke

In some cases, we need access to information before it becomes available
to the 'event' handler. In particular, for some devices we cannot properly
process the finger data without first knowing the "contact count" at the
very end of the report (e.g. the Cintiq 24HDT touch screen, when forced
through the GENERIC codepath).

Since the HID subsystem doesn't provide a way to take action before 'event'
is called, we take a cue from hid-multitouch.c and add a pre-process step
within the 'report' handler that performs the same function.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_sys.c |  1 -
 drivers/hid/wacom_wac.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 2a22163..d932349 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1690,7 +1690,6 @@ static struct hid_driver wacom_driver = {
 	.id_table =	wacom_ids,
 	.probe =	wacom_probe,
 	.remove =	wacom_remove,
-	.event =	wacom_wac_event,
 	.report =	wacom_wac_report,
 #ifdef CONFIG_PM
 	.resume =	wacom_resume,
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index f5a0d3c..1d9d5d1 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1437,6 +1437,12 @@ static int wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
 	return 0;
 }
 
+static void wacom_wac_pen_pre_report(struct hid_device *hdev,
+		struct hid_report *report)
+{
+	return;
+}
+
 static void wacom_wac_pen_report(struct hid_device *hdev,
 		struct hid_report *report)
 {
@@ -1564,6 +1570,12 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
 	return 0;
 }
 
+static void wacom_wac_finger_pre_report(struct hid_device *hdev,
+		struct hid_report *report)
+{
+	return;
+}
+
 static void wacom_wac_finger_report(struct hid_device *hdev,
 		struct hid_report *report)
 {
@@ -1615,6 +1627,25 @@ int wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
 	return 0;
 }
 
+static void wacom_report_events(struct hid_device *hdev, struct hid_report *report)
+{
+	int r;
+
+	for (r = 0; r < report->maxfield; r++) {
+		struct hid_field *field;
+		unsigned count, n;
+
+		field = report->field[r];
+		count = field->report_count;
+
+		if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
+			continue;
+
+		for (n = 0; n < count; n++)
+			wacom_wac_event(hdev, field, &field->usage[n], field->value[n]);
+	}
+}
+
 void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
 {
 	struct wacom *wacom = hid_get_drvdata(hdev);
@@ -1625,6 +1656,14 @@ void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
 		return;
 
 	if (WACOM_PEN_FIELD(field))
+		wacom_wac_pen_pre_report(hdev, report);
+
+	if (WACOM_FINGER_FIELD(field))
+		wacom_wac_finger_pre_report(hdev, report);
+
+	wacom_report_events(hdev, report);
+
+	if (WACOM_PEN_FIELD(field))
 		return wacom_wac_pen_report(hdev, report);
 
 	if (WACOM_FINGER_FIELD(field))
-- 
2.4.6


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

* [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count
  2015-07-21 18:07 [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jason Gerecke
@ 2015-07-21 18:07 ` Jason Gerecke
  2015-07-21 18:07 ` [PATCH 3/3] HID: wacom: Report touch width/height/orientation for GENERIC devices Jason Gerecke
  2015-07-23 12:04 ` [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Gerecke @ 2015-07-21 18:07 UTC (permalink / raw)
  To: Jiri Kosina, Ping Cheng, Benjamin Tissoires
  Cc: Aaron Skomra, linux-input, Jason Gerecke, Jason Gerecke

The reports sent from some touch devices (e.g. the Cintiq 24HDT) contain
junk data in the contact slots which follow the final "valid" contact.
To avoid forwarding it to usrspace, we store the reported contact count
during the pre-process phase and then only process that many contacts.
If a device sends its contacts across multiple reports (what Microsoft
refers to as "hybrid" mode) then the contact count will be zero for
reports other than the first.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 30 +++++++++++++++++++++++++++++-
 drivers/hid/wacom_wac.h |  4 ++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 1d9d5d1..09fe5d6 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1510,6 +1510,10 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
 		features->last_slot_field = usage->hid;
 		wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
 		break;
+	case HID_DG_CONTACTCOUNT:
+		wacom_wac->hid_data.cc_index = field->index;
+		wacom_wac->hid_data.cc_value_index = usage->usage_index;
+		break;
 	}
 }
 
@@ -1521,6 +1525,10 @@ static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
 	bool prox = hid_data->tipswitch &&
 		    !wacom_wac->shared->stylus_in_proximity;
 
+	wacom_wac->hid_data.num_received++;
+	if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected)
+		return;
+
 	if (mt) {
 		int slot;
 
@@ -1573,7 +1581,19 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
 static void wacom_wac_finger_pre_report(struct hid_device *hdev,
 		struct hid_report *report)
 {
-	return;
+	struct wacom *wacom = hid_get_drvdata(hdev);
+	struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+	struct hid_data* hid_data = &wacom_wac->hid_data;
+
+	if (hid_data->cc_index >= 0) {
+		struct hid_field *field = report->field[hid_data->cc_index];
+		int value = field->value[hid_data->cc_value_index];
+		if (value)
+			hid_data->num_expected = value;
+	}
+	else {
+		hid_data->num_expected = wacom_wac->features.touch_max;
+	}
 }
 
 static void wacom_wac_finger_report(struct hid_device *hdev,
@@ -1584,10 +1604,18 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
 	struct input_dev *input = wacom_wac->touch_input;
 	unsigned touch_max = wacom_wac->features.touch_max;
 
+	/* If more packets of data are expected, give us a chance to
+	 * process them rather than immediately syncing a partial
+	 * update.
+	 */
+	if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected)
+		return;
+
 	if (touch_max > 1)
 		input_mt_sync_frame(input);
 
 	input_sync(input);
+	wacom_wac->hid_data.num_received = 0;
 
 	/* keep touch state for pen event */
 	wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 2978c30..c245a66 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -193,6 +193,10 @@ struct hid_data {
 	int width;
 	int height;
 	int id;
+	int cc_index;
+	int cc_value_index;
+	int num_expected;
+	int num_received;
 };
 
 struct wacom_wac {
-- 
2.4.6


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

* [PATCH 3/3] HID: wacom: Report touch width/height/orientation for GENERIC devices
  2015-07-21 18:07 [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jason Gerecke
  2015-07-21 18:07 ` [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count Jason Gerecke
@ 2015-07-21 18:07 ` Jason Gerecke
  2015-07-23 12:04 ` [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Gerecke @ 2015-07-21 18:07 UTC (permalink / raw)
  To: Jiri Kosina, Ping Cheng, Benjamin Tissoires
  Cc: Aaron Skomra, linux-input, Jason Gerecke, Jason Gerecke

The HID_DG_WIDTH and HID_DG_HEIGHT usages report with width and height of
contacts. From this information, a crude determination of orientation is
also possible. This patch reports all three to userspace if a device
reports this usage.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 09fe5d6..280deb2 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1497,6 +1497,13 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
 			wacom_map_usage(input, usage, field, EV_ABS,
 					ABS_MT_POSITION_Y, 4);
 		break;
+	case HID_DG_WIDTH:
+	case HID_DG_HEIGHT:
+		features->last_slot_field = usage->hid;
+		wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MAJOR, 0);
+		wacom_map_usage(input, usage, field, EV_ABS, ABS_MT_TOUCH_MINOR, 0);
+		input_set_abs_params(input, ABS_MT_ORIENTATION, 0, 1, 0, 0);
+		break;
 	case HID_DG_CONTACTID:
 		features->last_slot_field = usage->hid;
 		break;
@@ -1545,6 +1552,13 @@ static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
 				 hid_data->x);
 		input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
 				 hid_data->y);
+
+		if (test_bit(ABS_MT_TOUCH_MAJOR, input->absbit)) {
+			input_report_abs(input, ABS_MT_TOUCH_MAJOR, max(hid_data->width, hid_data->height));
+			input_report_abs(input, ABS_MT_TOUCH_MINOR, min(hid_data->width, hid_data->height));
+			if (hid_data->width != hid_data->height)
+				input_report_abs(input, ABS_MT_ORIENTATION, hid_data->width <= hid_data->height ? 0 : 1);
+		}
 	}
 }
 
@@ -1561,6 +1575,12 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
 	case HID_GD_Y:
 		wacom_wac->hid_data.y = value;
 		break;
+	case HID_DG_WIDTH:
+		wacom_wac->hid_data.width = value;
+		break;
+	case HID_DG_HEIGHT:
+		wacom_wac->hid_data.height = value;
+		break;
 	case HID_DG_CONTACTID:
 		wacom_wac->hid_data.id = value;
 		break;
-- 
2.4.6


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

* Re: [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing
  2015-07-21 18:07 [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jason Gerecke
  2015-07-21 18:07 ` [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count Jason Gerecke
  2015-07-21 18:07 ` [PATCH 3/3] HID: wacom: Report touch width/height/orientation for GENERIC devices Jason Gerecke
@ 2015-07-23 12:04 ` Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2015-07-23 12:04 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: Ping Cheng, Benjamin Tissoires, Aaron Skomra, linux-input, Jason Gerecke

On Tue, 21 Jul 2015, Jason Gerecke wrote:

> In some cases, we need access to information before it becomes available
> to the 'event' handler. In particular, for some devices we cannot properly
> process the finger data without first knowing the "contact count" at the
> very end of the report (e.g. the Cintiq 24HDT touch screen, when forced
> through the GENERIC codepath).
> 
> Since the HID subsystem doesn't provide a way to take action before 'event'
> is called, we take a cue from hid-multitouch.c and add a pre-process step
> within the 'report' handler that performs the same function.

The whole series is now in for-4.3/wacom.

Thanks,

-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2015-07-23 12:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-21 18:07 [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jason Gerecke
2015-07-21 18:07 ` [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count Jason Gerecke
2015-07-21 18:07 ` [PATCH 3/3] HID: wacom: Report touch width/height/orientation for GENERIC devices Jason Gerecke
2015-07-23 12:04 ` [PATCH 1/3] HID: wacom: Perform all event processing as part of report processing Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.