All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Henrik Rydberg" <rydberg@euromail.se>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Jiri Kosina <jkosina@suse.cz>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Henrik Rydberg <rydberg@euromail.se>,
	Benjamin Tissoires <benjamin.tissoires@enac.fr>
Subject: [PATCH v3 19/20] HID: hid-multitouch: Remove the redundant touch state
Date: Sat,  1 Sep 2012 21:47:14 +0200	[thread overview]
Message-ID: <1346528835-363-20-git-send-email-rydberg@euromail.se> (raw)
In-Reply-To: <1346528835-363-1-git-send-email-rydberg@euromail.se>

With the input_mt_sync_frame() function in place, there is no longer
any need to keep the full touch state in the driver. This patch
removes the slot state and replaces the lookup code with the input-mt
equivalent.

Cc: Benjamin Tissoires <benjamin.tissoires@enac.fr>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
 drivers/hid/hid-multitouch.c | 88 ++++++++++++--------------------------------
 1 file changed, 23 insertions(+), 65 deletions(-)

diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 1df86a7..eee19c9 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -56,7 +56,6 @@ struct mt_slot {
 	__s32 x, y, p, w, h;
 	__s32 contactid;	/* the device ContactID assigned to this slot */
 	bool touch_state;	/* is the touch valid? */
-	bool seen_in_this_frame;/* has this slot been updated */
 };
 
 struct mt_class {
@@ -94,7 +93,6 @@ struct mt_device {
 				* > 1 means hybrid (multitouch) protocol */
 	bool serial_maybe;	/* need to check for serial protocol */
 	bool curvalid;		/* is the current contact valid? */
-	struct mt_slot *slots;
 	unsigned mt_flags;	/* flags to pass to input-mt */
 };
 
@@ -136,25 +134,6 @@ static int cypress_compute_slot(struct mt_device *td)
 		return -1;
 }
 
-static int find_slot_from_contactid(struct mt_device *td)
-{
-	int i;
-	for (i = 0; i < td->maxcontacts; ++i) {
-		if (td->slots[i].contactid == td->curdata.contactid &&
-			td->slots[i].touch_state)
-			return i;
-	}
-	for (i = 0; i < td->maxcontacts; ++i) {
-		if (!td->slots[i].seen_in_this_frame &&
-			!td->slots[i].touch_state)
-			return i;
-	}
-	/* should not occurs. If this happens that means
-	 * that the device sent more touches that it says
-	 * in the report descriptor. It is ignored then. */
-	return -1;
-}
-
 static struct mt_class mt_classes[] = {
 	{ .name = MT_CLS_DEFAULT,
 		.quirks = MT_QUIRK_NOT_SEEN_MEANS_UP },
@@ -448,7 +427,7 @@ static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
 	return -1;
 }
 
-static int mt_compute_slot(struct mt_device *td)
+static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
 {
 	__s32 quirks = td->mtclass.quirks;
 
@@ -464,42 +443,23 @@ static int mt_compute_slot(struct mt_device *td)
 	if (quirks & MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE)
 		return td->curdata.contactid - 1;
 
-	return find_slot_from_contactid(td);
+	return input_mt_get_slot_by_key(input, td->curdata.contactid);
 }
 
 /*
  * this function is called when a whole contact has been processed,
  * so that it can assign it to a slot and store the data there
  */
-static void mt_complete_slot(struct mt_device *td)
+static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
 {
-	td->curdata.seen_in_this_frame = true;
 	if (td->curvalid) {
-		int slotnum = mt_compute_slot(td);
-
-		if (slotnum >= 0 && slotnum < td->maxcontacts)
-			td->slots[slotnum] = td->curdata;
-	}
-	td->num_received++;
-}
-
-
-/*
- * this function is called when a whole packet has been received and processed,
- * so that it can decide what to send to the input layer.
- */
-static void mt_emit_event(struct mt_device *td, struct input_dev *input)
-{
-	int i;
+		int slotnum = mt_compute_slot(td, input);
+		struct mt_slot *s = &td->curdata;
 
-	for (i = 0; i < td->maxcontacts; ++i) {
-		struct mt_slot *s = &(td->slots[i]);
-		if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
-			!s->seen_in_this_frame) {
-			s->touch_state = false;
-		}
+		if (slotnum < 0 || slotnum >= td->maxcontacts)
+			return;
 
-		input_mt_slot(input, i);
+		input_mt_slot(input, slotnum);
 		input_mt_report_slot_state(input, MT_TOOL_FINGER,
 			s->touch_state);
 		if (s->touch_state) {
@@ -516,24 +476,29 @@ static void mt_emit_event(struct mt_device *td, struct input_dev *input)
 			input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
 			input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor);
 		}
-		s->seen_in_this_frame = false;
-
 	}
 
+	td->num_received++;
+}
+
+/*
+ * this function is called when a whole packet has been received and processed,
+ * so that it can decide what to send to the input layer.
+ */
+static void mt_sync_frame(struct mt_device *td, struct input_dev *input)
+{
 	input_mt_sync_frame(input);
 	input_sync(input);
 	td->num_received = 0;
 }
 
-
-
 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);
 	__s32 quirks = td->mtclass.quirks;
 
-	if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
+	if (hid->claimed & HID_CLAIMED_INPUT) {
 		switch (usage->hid) {
 		case HID_DG_INRANGE:
 			if (quirks & MT_QUIRK_ALWAYS_VALID)
@@ -586,11 +551,11 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,
 		}
 
 		if (usage->hid == td->last_slot_field)
-			mt_complete_slot(td);
+			mt_complete_slot(td, field->hidinput->input);
 
 		if (field->index == td->last_field_index
 			&& td->num_received >= td->num_expected)
-			mt_emit_event(td, field->hidinput->input);
+			mt_sync_frame(td, field->hidinput->input);
 
 	}
 
@@ -690,6 +655,9 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
 	if (cls->is_indirect)
 		td->mt_flags |= INPUT_MT_POINTER;
 
+	if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
+		td->mt_flags |= INPUT_MT_DROP_UNUSED;
+
 	input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
 
 	td->mt_flags = 0;
@@ -743,15 +711,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (ret)
 		goto fail;
 
-	td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
-				GFP_KERNEL);
-	if (!td->slots) {
-		dev_err(&hdev->dev, "cannot allocate multitouch slots\n");
-		hid_hw_stop(hdev);
-		ret = -ENOMEM;
-		goto fail;
-	}
-
 	ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
 
 	mt_set_maxcontacts(hdev);
@@ -782,7 +741,6 @@ static void mt_remove(struct hid_device *hdev)
 	struct mt_device *td = hid_get_drvdata(hdev);
 	sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
 	hid_hw_stop(hdev);
-	kfree(td->slots);
 	kfree(td);
 	hid_set_drvdata(hdev, NULL);
 }
-- 
1.7.12


  parent reply	other threads:[~2012-09-01 19:43 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-01 19:46 [PATCH v3 v3 00/20] Input and HID updates for 3.7 Henrik Rydberg
2012-09-01 19:46 ` [PATCH v3 01/20] Input: Break out MT data Henrik Rydberg
2012-09-13  5:15   ` Dmitry Torokhov
2012-09-13 17:58     ` Henrik Rydberg
2012-09-01 19:46 ` [PATCH v3 02/20] Input: Improve the events-per-packet estimate Henrik Rydberg
2012-09-13  5:16   ` Dmitry Torokhov
2012-09-01 19:46 ` [PATCH v3 03/20] Input: Make sure we follow all EV_KEY events Henrik Rydberg
2012-09-13  5:19   ` Dmitry Torokhov
2012-09-01 19:46 ` [PATCH v3 04/20] Input: Move autorepeat to the event-passing phase Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 05/20] Input: Send events one packet at a time Henrik Rydberg
2012-09-13  6:56   ` Dmitry Torokhov
2012-09-13 17:59     ` Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 06/20] Input: evdev - Add the events() callback Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 07/20] Input: MT - Add flags to input_mt_init_slots() Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 08/20] Input: MT - Handle frame synchronization in core Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 09/20] Input: MT - Add in-kernel tracking Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 10/20] Input: MT - Get slot by key Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 11/20] Input: bcm5974 - only setup button urb for TYPE1 devices Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 12/20] Input: bcm5974 - Preparatory renames Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 13/20] Input: bcm5974 - Drop pressure and width emulation Henrik Rydberg
2012-09-13  6:57   ` Dmitry Torokhov
2012-09-13 18:41     ` Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 14/20] Input: bcm5974 - Drop the logical dimensions Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 15/20] Input: bcm5974 - Convert to MT-B Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 16/20] HID: Only dump input if someone is listening Henrik Rydberg
2012-09-02  7:28   ` Jiri Kosina
2012-09-02  8:52     ` Henrik Rydberg
2012-09-03 13:17       ` Jiri Kosina
2012-09-06 20:57         ` Henrik Rydberg
2012-09-07  1:54           ` Ping Cheng
2012-09-07 12:52           ` Jiri Kosina
2012-09-10 19:02             ` Henrik Rydberg
2012-09-10 20:49               ` Jiri Kosina
2012-09-10 21:12                 ` Dmitry Torokhov
2012-09-14 19:25                   ` Henrik Rydberg
2012-09-15 15:33                     ` Input and HID updates for 3.7, version 4 Henrik Rydberg
2012-09-18 11:29                       ` Jiri Kosina
2012-09-18 16:19                         ` Henrik Rydberg
2012-09-19 16:57                           ` Dmitry Torokhov
2012-09-19 18:34                             ` Henrik Rydberg
2012-09-01 19:47 ` [PATCH v3 17/20] HID: Add an input configured notification callback Henrik Rydberg
2012-09-01 19:47 ` Henrik Rydberg
2012-09-01 19:47 ` Henrik Rydberg [this message]
2012-09-01 19:47 ` [PATCH 20/20] HID: hid-multitouch: Add missing contact count detection Henrik Rydberg
2012-09-03 12:59   ` Benjamin Tissoires
2012-09-03 17:07     ` Henrik Rydberg
2012-09-05 15:09     ` [PATCH v2 20/20] HID: hid-multitouch: Fix contact count on 3M panels Henrik Rydberg
2012-09-03 13:00 ` [PATCH v3 v3 00/20] Input and HID updates for 3.7 Benjamin Tissoires
2012-09-03 17:08   ` Henrik Rydberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346528835-363-20-git-send-email-rydberg@euromail.se \
    --to=rydberg@euromail.se \
    --cc=benjamin.tissoires@enac.fr \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.