All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/23 v6] cleanup atmel_mxt_ts
@ 2012-06-28 13:08 Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 01/23 v6] Input: atmel_mxt_ts - derive phys from i2c client adapter Daniel Kurtz
                   ` (23 more replies)
  0 siblings, 24 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

This patchset cleans up the atmel_mxt_ts touchscreen driver.

They were tested using an MXT224E, and apply cleanly to input/next.

Changes in v6:
 * Patches 1-8: No change
 * Patch 9: refactor per Henrik, and abort on error
 * Patch 10: rebased
 * Patch 11: kfree()
 * Patch 12-17: rebased
 * Patch 18: refactored per Henrik
 * Patch 19: Moved init spew from info -> debug & refactor kfree()
 * Patch 20, 23: refactored per Henrik
 * Patch 21-22: rebased
 * Patch 23: refactored per Henrik

Daniel Kurtz (23):
  Input: atmel_mxt_ts - derive phys from i2c client adapter
  Input: atmel_mxt_ts - use client name for irq
  Input: atmel_mxt_ts - detect OOM when creating mt slots
  Input: atmel_mxt_ts - warn if sysfs could not be created
  Input: atmel_mxt_ts - don't read T5 when dumping objects
  Input: atmel_mxt_ts - use scnprintf for object sysfs entry
  Input: atmel_mxt_ts - optimize reading objects in object sysfs entry
  Input: atmel_mxt_ts - print less overhead when dumping objects
  Input: atmel_mxt_ts - print all instances when dumping objects
  Input: atmel_mxt_ts - return errors from i2c layer
  Input: atmel_mxt_ts - add variable length __mxt_write_reg
  Input: atmel_mxt_ts - optimize writing of object table entries
  Input: atmel_mxt_ts - read ID information block in one i2c
    transaction
  Input: atmel_mxt_ts - update driver ID info logging
  Input: atmel_mxt_ts - add sysfs entries to read fw and hw version
  Input: atmel_mxt_ts - simplify event reporting
  Input: atmel_mxt_ts - add detail to touchevent debug message
  Input: atmel_mxt_ts - refactor when and how object table is freed
  Input: atmel_mxt_ts - cache T9 reportid range when reading object
    table
  Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt
  Input: atmel_mxt_ts - use T9 reportid range to init number of mt
    slots
  Input: atmel_mxt_ts - send all MT-B slots in one input report
  Input: atmel_mxt_ts - parse T6 reports

 drivers/input/touchscreen/atmel_mxt_ts.c |  468 +++++++++++++++--------------
 1 files changed, 242 insertions(+), 226 deletions(-)

-- 
1.7.7.3


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

* [PATCH 01/23 v6] Input: atmel_mxt_ts - derive phys from i2c client adapter
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 02/23 v6] Input: atmel_mxt_ts - use client name for irq Daniel Kurtz
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

This allows userspace to more easily distinguish which bus a particular
atmel_mxt_ts device is attached to.

The resulting phys will be something like:
 i2c-1-0067/input0

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 42e6450..b1108ca 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -250,6 +250,7 @@ struct mxt_finger {
 struct mxt_data {
 	struct i2c_client *client;
 	struct input_dev *input_dev;
+	char phys[64];		/* device physical location */
 	const struct mxt_platform_data *pdata;
 	struct mxt_object *object_table;
 	struct mxt_info info;
@@ -1106,6 +1107,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
 	}
 
 	input_dev->name = "Atmel maXTouch Touchscreen";
+	snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
+		 client->adapter->nr, client->addr);
+	input_dev->phys = data->phys;
+
 	input_dev->id.bustype = BUS_I2C;
 	input_dev->dev.parent = &client->dev;
 	input_dev->open = mxt_input_open;
-- 
1.7.7.3


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

* [PATCH 02/23 v6] Input: atmel_mxt_ts - use client name for irq
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 01/23 v6] Input: atmel_mxt_ts - derive phys from i2c client adapter Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 03/23 v6] Input: atmel_mxt_ts - detect OOM when creating mt slots Daniel Kurtz
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

The atmel_mxt_ts driver can support multiple devices simultaneously.
Use the i2c_client name instead of the driver name when requesting an
interrupt to make the different interrupts distinguishable in
/proc/interrupts and top.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index b1108ca..8b33f3a 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1154,7 +1154,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
 		goto err_free_object;
 
 	error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
-			pdata->irqflags, client->dev.driver->name, data);
+			pdata->irqflags, client->name, data);
 	if (error) {
 		dev_err(&client->dev, "Failed to register interrupt\n");
 		goto err_free_object;
-- 
1.7.7.3


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

* [PATCH 03/23 v6] Input: atmel_mxt_ts - detect OOM when creating mt slots
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 01/23 v6] Input: atmel_mxt_ts - derive phys from i2c client adapter Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 02/23 v6] Input: atmel_mxt_ts - use client name for irq Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created Daniel Kurtz
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Hopefully this new code path will never be used, but better safe than
sorry...

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 8b33f3a..926209c 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1136,7 +1136,9 @@ static int __devinit mxt_probe(struct i2c_client *client,
 			     0, 255, 0, 0);
 
 	/* For multi touch */
-	input_mt_init_slots(input_dev, MXT_MAX_FINGER);
+	error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
+	if (error)
+		goto err_free_mem;
 	input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
 			     0, MXT_MAX_AREA, 0, 0);
 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
-- 
1.7.7.3


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

* [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (2 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 03/23 v6] Input: atmel_mxt_ts - detect OOM when creating mt slots Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-07-05 17:22   ` Dmitry Torokhov
  2012-06-28 13:08 ` [PATCH 05/23 v6] Input: atmel_mxt_ts - don't read T5 when dumping objects Daniel Kurtz
                   ` (19 subsequent siblings)
  23 siblings, 1 reply; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

If sysfs entry creation fails, the driver is still usable, so don't
just abort probe.  Just warn and continue.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 926209c..c72f595 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1172,13 +1172,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
 
 	error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group);
 	if (error)
-		goto err_unregister_device;
+		dev_warn(&client->dev, "error creating sysfs entries.\n");
 
 	return 0;
 
-err_unregister_device:
-	input_unregister_device(input_dev);
-	input_dev = NULL;
 err_free_irq:
 	free_irq(client->irq, data);
 err_free_object:
-- 
1.7.7.3


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

* [PATCH 05/23 v6] Input: atmel_mxt_ts - don't read T5 when dumping objects
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (3 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 06/23 v6] Input: atmel_mxt_ts - use scnprintf for object sysfs entry Daniel Kurtz
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

T5 is the message processor object.  Reading it will only have two
outcomes, neither of which is particularly useful:
 1) the message count decrements, and a valid message will be lost
 2) an invalid message will be read (reportid == 0xff)

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index c72f595..9f8dd97 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -263,7 +263,6 @@ struct mxt_data {
 static bool mxt_object_readable(unsigned int type)
 {
 	switch (type) {
-	case MXT_GEN_MESSAGE_T5:
 	case MXT_GEN_COMMAND_T6:
 	case MXT_GEN_POWER_T7:
 	case MXT_GEN_ACQUIRE_T8:
-- 
1.7.7.3


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

* [PATCH 06/23 v6] Input: atmel_mxt_ts - use scnprintf for object sysfs entry
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (4 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 05/23 v6] Input: atmel_mxt_ts - don't read T5 when dumping objects Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 07/23 v6] Input: atmel_mxt_ts - optimize reading objects in " Daniel Kurtz
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Using scnprintf() is a cleaner way to ensure that we don't overwrite the
PAGE_SIZE sysfs output buffer.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 9f8dd97..55855b8 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -904,17 +904,13 @@ static ssize_t mxt_object_show(struct device *dev,
 	for (i = 0; i < data->info.object_num; i++) {
 		object = data->object_table + i;
 
-		count += snprintf(buf + count, PAGE_SIZE - count,
+		count += scnprintf(buf + count, PAGE_SIZE - count,
 				"Object[%d] (Type %d)\n",
 				i + 1, object->type);
-		if (count >= PAGE_SIZE)
-			return PAGE_SIZE - 1;
 
 		if (!mxt_object_readable(object->type)) {
-			count += snprintf(buf + count, PAGE_SIZE - count,
+			count += scnprintf(buf + count, PAGE_SIZE - count,
 					"\n");
-			if (count >= PAGE_SIZE)
-				return PAGE_SIZE - 1;
 			continue;
 		}
 
@@ -924,15 +920,11 @@ static ssize_t mxt_object_show(struct device *dev,
 			if (error)
 				return error;
 
-			count += snprintf(buf + count, PAGE_SIZE - count,
+			count += scnprintf(buf + count, PAGE_SIZE - count,
 					"\t[%2d]: %02x (%d)\n", j, val, val);
-			if (count >= PAGE_SIZE)
-				return PAGE_SIZE - 1;
 		}
 
-		count += snprintf(buf + count, PAGE_SIZE - count, "\n");
-		if (count >= PAGE_SIZE)
-			return PAGE_SIZE - 1;
+		count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
 	}
 
 	return count;
-- 
1.7.7.3


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

* [PATCH 07/23 v6] Input: atmel_mxt_ts - optimize reading objects in object sysfs entry
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (5 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 06/23 v6] Input: atmel_mxt_ts - use scnprintf for object sysfs entry Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 08/23 v6] Input: atmel_mxt_ts - print less overhead when dumping objects Daniel Kurtz
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Read each object in a single i2c transaction instead of byte-by-byte

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   35 ++++++++++++-----------------
 1 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 55855b8..94dd1d1 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -479,20 +479,6 @@ static int mxt_read_message(struct mxt_data *data,
 			sizeof(struct mxt_message), message);
 }
 
-static int mxt_read_object(struct mxt_data *data,
-				u8 type, u8 offset, u8 *val)
-{
-	struct mxt_object *object;
-	u16 reg;
-
-	object = mxt_get_object(data, type);
-	if (!object)
-		return -EINVAL;
-
-	reg = object->start_address;
-	return __mxt_read_reg(data->client, reg + offset, 1, val);
-}
-
 static int mxt_write_object(struct mxt_data *data,
 				 u8 type, u8 offset, u8 val)
 {
@@ -900,7 +886,14 @@ static ssize_t mxt_object_show(struct device *dev,
 	int i, j;
 	int error;
 	u8 val;
+	u8 *obuf;
+
+	/* Pre-allocate buffer large enough to hold max sized object. */
+	obuf = kmalloc(256, GFP_KERNEL);
+	if (!obuf)
+		return -ENOMEM;
 
+	error = 0;
 	for (i = 0; i < data->info.object_num; i++) {
 		object = data->object_table + i;
 
@@ -914,20 +907,22 @@ static ssize_t mxt_object_show(struct device *dev,
 			continue;
 		}
 
+		error = __mxt_read_reg(data->client, object->start_address,
+				object->size + 1, obuf);
+		if (error)
+			break;
+
 		for (j = 0; j < object->size + 1; j++) {
-			error = mxt_read_object(data,
-						object->type, j, &val);
-			if (error)
-				return error;
+			val = obuf[j];
 
 			count += scnprintf(buf + count, PAGE_SIZE - count,
 					"\t[%2d]: %02x (%d)\n", j, val, val);
 		}
-
 		count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
 	}
 
-	return count;
+	kfree(obuf);
+	return error ?: count;
 }
 
 static int mxt_load_fw(struct device *dev, const char *fn)
-- 
1.7.7.3


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

* [PATCH 08/23 v6] Input: atmel_mxt_ts - print less overhead when dumping objects
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (6 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 07/23 v6] Input: atmel_mxt_ts - optimize reading objects in " Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 09/23 v6] Input: atmel_mxt_ts - print all instances " Daniel Kurtz
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Conserve limited (PAGE_SIZE) sysfs output buffer space by only showing
readable objects and not printing the object's index, which is not useful
to userspace.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 94dd1d1..c8cfd7b 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -897,15 +897,11 @@ static ssize_t mxt_object_show(struct device *dev,
 	for (i = 0; i < data->info.object_num; i++) {
 		object = data->object_table + i;
 
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				"Object[%d] (Type %d)\n",
-				i + 1, object->type);
-
-		if (!mxt_object_readable(object->type)) {
-			count += scnprintf(buf + count, PAGE_SIZE - count,
-					"\n");
+		if (!mxt_object_readable(object->type))
 			continue;
-		}
+
+		count += scnprintf(buf + count, PAGE_SIZE - count,
+				"T%u:\n", object->type);
 
 		error = __mxt_read_reg(data->client, object->start_address,
 				object->size + 1, obuf);
-- 
1.7.7.3


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

* [PATCH 09/23 v6] Input: atmel_mxt_ts - print all instances when dumping objects
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (7 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 08/23 v6] Input: atmel_mxt_ts - print less overhead when dumping objects Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 10/23 v6] Input: atmel_mxt_ts - return errors from i2c layer Daniel Kurtz
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

For objects with multiple instances, dump them all, prepending each with
its "Instance #".

[rydberg@euromail.se: break out mxt_show_instance()]
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   36 +++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index c8cfd7b..ee37b0b 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -877,6 +877,24 @@ static void mxt_calc_resolution(struct mxt_data *data)
 	}
 }
 
+static ssize_t mxt_show_instance(char *buf, int count,
+				 struct mxt_object *object, int instance,
+				 const u8 *val)
+{
+	int i;
+
+	if (object->instances > 0)
+		count += scnprintf(buf + count, PAGE_SIZE - count,
+				   "Instance %u\n", instance);
+
+	for (i = 0; i < object->size + 1; i++)
+		count += scnprintf(buf + count, PAGE_SIZE - count,
+				"\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
+	count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
+
+	return count;
+}
+
 static ssize_t mxt_object_show(struct device *dev,
 				    struct device_attribute *attr, char *buf)
 {
@@ -885,7 +903,6 @@ static ssize_t mxt_object_show(struct device *dev,
 	int count = 0;
 	int i, j;
 	int error;
-	u8 val;
 	u8 *obuf;
 
 	/* Pre-allocate buffer large enough to hold max sized object. */
@@ -903,20 +920,19 @@ static ssize_t mxt_object_show(struct device *dev,
 		count += scnprintf(buf + count, PAGE_SIZE - count,
 				"T%u:\n", object->type);
 
-		error = __mxt_read_reg(data->client, object->start_address,
-				object->size + 1, obuf);
-		if (error)
-			break;
+		for (j = 0; j < object->instances + 1; j++) {
+			u16 size = object->size + 1;
+			u16 addr = object->start_address + j * size;
 
-		for (j = 0; j < object->size + 1; j++) {
-			val = obuf[j];
+			error = __mxt_read_reg(data->client, addr, size, obuf);
+			if (error)
+				goto done;
 
-			count += scnprintf(buf + count, PAGE_SIZE - count,
-					"\t[%2d]: %02x (%d)\n", j, val, val);
+			count = mxt_show_instance(buf, count, object, j, obuf);
 		}
-		count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
 	}
 
+done:
 	kfree(obuf);
 	return error ?: count;
 }
-- 
1.7.7.3


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

* [PATCH 10/23 v6] Input: atmel_mxt_ts - return errors from i2c layer
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (8 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 09/23 v6] Input: atmel_mxt_ts - print all instances " Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 11/23 v6] Input: atmel_mxt_ts - add variable length __mxt_write_reg Daniel Kurtz
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

The i2c layer can report a variety of errors, including -ENXIO for an i2c
NAK.  Instead of treating them all as -EIO, pass the actual i2c layer
error up to the caller.

However, still report as -EIO the unlikely case that a transaction was
partially completed, and no error message was returned from i2c_*().

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index ee37b0b..a68b227 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -396,6 +396,7 @@ static int __mxt_read_reg(struct i2c_client *client,
 {
 	struct i2c_msg xfer[2];
 	u8 buf[2];
+	int ret;
 
 	buf[0] = reg & 0xff;
 	buf[1] = (reg >> 8) & 0xff;
@@ -412,12 +413,17 @@ static int __mxt_read_reg(struct i2c_client *client,
 	xfer[1].len = len;
 	xfer[1].buf = val;
 
-	if (i2c_transfer(client->adapter, xfer, 2) != 2) {
-		dev_err(&client->dev, "%s: i2c transfer failed\n", __func__);
-		return -EIO;
+	ret = i2c_transfer(client->adapter, xfer, 2);
+	if (ret == 2) {
+		ret = 0;
+	} else {
+		if (ret >= 0)
+			ret = -EIO;
+		dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
+			__func__, ret);
 	}
 
-	return 0;
+	return ret;
 }
 
 static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
@@ -428,17 +434,23 @@ static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
 static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
 {
 	u8 buf[3];
+	int ret;
 
 	buf[0] = reg & 0xff;
 	buf[1] = (reg >> 8) & 0xff;
 	buf[2] = val;
 
-	if (i2c_master_send(client, buf, 3) != 3) {
-		dev_err(&client->dev, "%s: i2c send failed\n", __func__);
-		return -EIO;
+	ret = i2c_master_send(client, buf, 3);
+	if (ret == 3) {
+		ret = 0;
+	} else {
+		if (ret >= 0)
+			ret = -EIO;
+		dev_err(&client->dev, "%s: i2c send failed (%d)\n",
+			__func__, ret);
 	}
 
-	return 0;
+	return ret;
 }
 
 static int mxt_read_object_table(struct i2c_client *client,
-- 
1.7.7.3


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

* [PATCH 11/23 v6] Input: atmel_mxt_ts - add variable length __mxt_write_reg
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (9 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 10/23 v6] Input: atmel_mxt_ts - return errors from i2c layer Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 12/23 v6] Input: atmel_mxt_ts - optimize writing of object table entries Daniel Kurtz
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

The i2c bus requires 4 bytes to do a 1-byte write
(1 byte i2c address + 2 byte offset + 1 byte data).

By taking a length with writes, the driver can amortize transaction
overhead by performing larger transactions where appropriate.

This patch just sets up the new API.  Later patches refactor writes
to take advantage of the larger transactions.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index a68b227..dd2577b 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -431,17 +431,24 @@ static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
 	return __mxt_read_reg(client, reg, 1, val);
 }
 
-static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
+static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
+			   const void *val)
 {
-	u8 buf[3];
+	u8 *buf;
+	size_t count;
 	int ret;
 
+	count = len + 2;
+	buf = kmalloc(count, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
 	buf[0] = reg & 0xff;
 	buf[1] = (reg >> 8) & 0xff;
-	buf[2] = val;
+	memcpy(&buf[2], val, len);
 
-	ret = i2c_master_send(client, buf, 3);
-	if (ret == 3) {
+	ret = i2c_master_send(client, buf, count);
+	if (ret == count) {
 		ret = 0;
 	} else {
 		if (ret >= 0)
@@ -450,9 +457,15 @@ static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
 			__func__, ret);
 	}
 
+	kfree(buf);
 	return ret;
 }
 
+static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
+{
+	return __mxt_write_reg(client, reg, 1, &val);
+}
+
 static int mxt_read_object_table(struct i2c_client *client,
 				      u16 reg, u8 *object_buf)
 {
-- 
1.7.7.3


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

* [PATCH 12/23 v6] Input: atmel_mxt_ts - optimize writing of object table entries
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (10 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 11/23 v6] Input: atmel_mxt_ts - add variable length __mxt_write_reg Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 13/23 v6] Input: atmel_mxt_ts - read ID information block in one i2c transaction Daniel Kurtz
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Write each object using a single bulk i2c write transfer.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Joonyoung Shim <jy0922.shim@samsung.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index dd2577b..99d5210 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -655,7 +655,8 @@ static int mxt_check_reg_init(struct mxt_data *data)
 	struct mxt_object *object;
 	struct device *dev = &data->client->dev;
 	int index = 0;
-	int i, j, config_offset;
+	int i, size;
+	int ret;
 
 	if (!pdata->config) {
 		dev_dbg(dev, "No cfg data defined, skipping reg init\n");
@@ -668,18 +669,17 @@ static int mxt_check_reg_init(struct mxt_data *data)
 		if (!mxt_object_writable(object->type))
 			continue;
 
-		for (j = 0;
-		     j < (object->size + 1) * (object->instances + 1);
-		     j++) {
-			config_offset = index + j;
-			if (config_offset > pdata->config_length) {
-				dev_err(dev, "Not enough config data!\n");
-				return -EINVAL;
-			}
-			mxt_write_object(data, object->type, j,
-					 pdata->config[config_offset]);
+		size = (object->size + 1) * (object->instances + 1);
+		if (index + size > pdata->config_length) {
+			dev_err(dev, "Not enough config data!\n");
+			return -EINVAL;
 		}
-		index += (object->size + 1) * (object->instances + 1);
+
+		ret = __mxt_write_reg(data->client, object->start_address,
+				size, &pdata->config[index]);
+		if (ret)
+			return ret;
+		index += size;
 	}
 
 	return 0;
-- 
1.7.7.3


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

* [PATCH 13/23 v6] Input: atmel_mxt_ts - read ID information block in one i2c transaction
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (11 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 12/23 v6] Input: atmel_mxt_ts - optimize writing of object table entries Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 14/23 v6] Input: atmel_mxt_ts - update driver ID info logging Daniel Kurtz
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Reading the whole info block in one i2c transaction speeds up driver
probe significantly, especially on slower i2c busses.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   26 +++-----------------------
 1 files changed, 3 insertions(+), 23 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 99d5210..fac3791 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -36,6 +36,7 @@
 #define MXT_FW_NAME		"maxtouch.fw"
 
 /* Registers */
+#define MXT_INFO		0x00
 #define MXT_FAMILY_ID		0x00
 #define MXT_VARIANT_ID		0x01
 #define MXT_VERSION		0x02
@@ -760,32 +761,11 @@ static int mxt_get_info(struct mxt_data *data)
 	struct i2c_client *client = data->client;
 	struct mxt_info *info = &data->info;
 	int error;
-	u8 val;
-
-	error = mxt_read_reg(client, MXT_FAMILY_ID, &val);
-	if (error)
-		return error;
-	info->family_id = val;
-
-	error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
-	if (error)
-		return error;
-	info->variant_id = val;
-
-	error = mxt_read_reg(client, MXT_VERSION, &val);
-	if (error)
-		return error;
-	info->version = val;
-
-	error = mxt_read_reg(client, MXT_BUILD, &val);
-	if (error)
-		return error;
-	info->build = val;
 
-	error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
+	/* Read 7-byte info block starting at address 0 */
+	error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
 	if (error)
 		return error;
-	info->object_num = val;
 
 	return 0;
 }
-- 
1.7.7.3


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

* [PATCH 14/23 v6] Input: atmel_mxt_ts - update driver ID info logging
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (12 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 13/23 v6] Input: atmel_mxt_ts - read ID information block in one i2c transaction Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 15/23 v6] Input: atmel_mxt_ts - add sysfs entries to read fw and hw version Daniel Kurtz
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Print unsigned values as '%u'.
Also, parse and print the firmware version in its canonical format, as
suggested by Nick Dyer.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index fac3791..7a839d1 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -856,12 +856,12 @@ static int mxt_initialize(struct mxt_data *data)
 	info->matrix_ysize = val;
 
 	dev_info(&client->dev,
-			"Family ID: %d Variant ID: %d Version: %d Build: %d\n",
-			info->family_id, info->variant_id, info->version,
-			info->build);
+			"Family ID: %u Variant ID: %u Major.Minor.Build: %u.%u.%02X\n",
+			info->family_id, info->variant_id, info->version >> 4,
+			info->version & 0xf, info->build);
 
 	dev_info(&client->dev,
-			"Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n",
+			"Matrix X Size: %u Matrix Y Size: %u Object Num: %u\n",
 			info->matrix_xsize, info->matrix_ysize,
 			info->object_num);
 
-- 
1.7.7.3


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

* [PATCH 15/23 v6] Input: atmel_mxt_ts - add sysfs entries to read fw and hw version
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (13 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 14/23 v6] Input: atmel_mxt_ts - update driver ID info logging Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 16/23 v6] Input: atmel_mxt_ts - simplify event reporting Daniel Kurtz
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Make firmware and hardware version strings available to userspace.
This is useful, for example, to allow a userspace program to implement
a firwmare update policy.

Change-Id: I1eddb4bbf5f3f9ae6947a8528598973ddead18cf
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 7a839d1..f2c1fbe 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -882,6 +882,26 @@ static void mxt_calc_resolution(struct mxt_data *data)
 	}
 }
 
+/* Firmware Version is returned as Major.Minor.Build */
+static ssize_t mxt_fw_version_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct mxt_data *data = dev_get_drvdata(dev);
+	struct mxt_info *info = &data->info;
+	return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
+			 info->version >> 4, info->version & 0xf, info->build);
+}
+
+/* Hardware Version is returned as FamilyID.VariantID */
+static ssize_t mxt_hw_version_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct mxt_data *data = dev_get_drvdata(dev);
+	struct mxt_info *info = &data->info;
+	return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
+			 info->family_id, info->variant_id);
+}
+
 static ssize_t mxt_show_instance(char *buf, int count,
 				 struct mxt_object *object, int instance,
 				 const u8 *val)
@@ -1047,10 +1067,14 @@ static ssize_t mxt_update_fw_store(struct device *dev,
 	return count;
 }
 
+static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
+static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
 static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
 static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
 
 static struct attribute *mxt_attrs[] = {
+	&dev_attr_fw_version.attr,
+	&dev_attr_hw_version.attr,
 	&dev_attr_object.attr,
 	&dev_attr_update_fw.attr,
 	NULL
-- 
1.7.7.3


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

* [PATCH 16/23 v6] Input: atmel_mxt_ts - simplify event reporting
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (14 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 15/23 v6] Input: atmel_mxt_ts - add sysfs entries to read fw and hw version Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 17/23 v6] Input: atmel_mxt_ts - add detail to touchevent debug message Daniel Kurtz
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Instead of carrying around per-finger state in the driver instance, just
report each finger as it arrives to the input layer, and let the input
layer (evdev) hold the event state (which it does anyway).

Note: this driver does not really do MT-B properly. Each input report
(a group of input events followed by a SYN_REPORT) only contains data for
a single contact.  When multiple fingers are present on a device, each is
properly reported in its own MT_SLOT.  However, there is only ever one
MT_SLOT per SYN_REPORT.  This is fixed in a subsequent patch.

This patch was tested with an mXT224E.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   89 ++++-------------------------
 1 files changed, 13 insertions(+), 76 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index f2c1fbe..c37584d 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -239,14 +239,6 @@ struct mxt_message {
 	u8 message[7];
 };
 
-struct mxt_finger {
-	int status;
-	int x;
-	int y;
-	int area;
-	int pressure;
-};
-
 /* Each client has this additional data */
 struct mxt_data {
 	struct i2c_client *client;
@@ -255,7 +247,6 @@ struct mxt_data {
 	const struct mxt_platform_data *pdata;
 	struct mxt_object *object_table;
 	struct mxt_info info;
-	struct mxt_finger finger[MXT_MAX_FINGER];
 	unsigned int irq;
 	unsigned int max_x;
 	unsigned int max_y;
@@ -519,75 +510,17 @@ static int mxt_write_object(struct mxt_data *data,
 	return mxt_write_reg(data->client, reg + offset, val);
 }
 
-static void mxt_input_report(struct mxt_data *data, int single_id)
-{
-	struct mxt_finger *finger = data->finger;
-	struct input_dev *input_dev = data->input_dev;
-	int status = finger[single_id].status;
-	int finger_num = 0;
-	int id;
-
-	for (id = 0; id < MXT_MAX_FINGER; id++) {
-		if (!finger[id].status)
-			continue;
-
-		input_mt_slot(input_dev, id);
-		input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
-				finger[id].status != MXT_RELEASE);
-
-		if (finger[id].status != MXT_RELEASE) {
-			finger_num++;
-			input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
-					finger[id].area);
-			input_report_abs(input_dev, ABS_MT_POSITION_X,
-					finger[id].x);
-			input_report_abs(input_dev, ABS_MT_POSITION_Y,
-					finger[id].y);
-			input_report_abs(input_dev, ABS_MT_PRESSURE,
-					finger[id].pressure);
-		} else {
-			finger[id].status = 0;
-		}
-	}
-
-	input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
-
-	if (status != MXT_RELEASE) {
-		input_report_abs(input_dev, ABS_X, finger[single_id].x);
-		input_report_abs(input_dev, ABS_Y, finger[single_id].y);
-		input_report_abs(input_dev,
-				 ABS_PRESSURE, finger[single_id].pressure);
-	}
-
-	input_sync(input_dev);
-}
-
 static void mxt_input_touchevent(struct mxt_data *data,
 				      struct mxt_message *message, int id)
 {
-	struct mxt_finger *finger = data->finger;
 	struct device *dev = &data->client->dev;
 	u8 status = message->message[0];
+	struct input_dev *input_dev = data->input_dev;
 	int x;
 	int y;
 	int area;
 	int pressure;
 
-	/* Check the touch is present on the screen */
-	if (!(status & MXT_DETECT)) {
-		if (status & MXT_RELEASE) {
-			dev_dbg(dev, "[%d] released\n", id);
-
-			finger[id].status = MXT_RELEASE;
-			mxt_input_report(data, id);
-		}
-		return;
-	}
-
-	/* Check only AMP detection */
-	if (!(status & (MXT_PRESS | MXT_MOVE)))
-		return;
-
 	x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
 	y = (message->message[2] << 4) | ((message->message[3] & 0xf));
 	if (data->max_x < 1024)
@@ -601,15 +534,19 @@ static void mxt_input_touchevent(struct mxt_data *data,
 	dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
 		status & MXT_MOVE ? "moved" : "pressed",
 		x, y, area);
+	input_mt_slot(input_dev, id);
+	input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
+				   status & MXT_DETECT);
+
+	if (status & MXT_DETECT) {
+		input_report_abs(input_dev, ABS_MT_POSITION_X, x);
+		input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
+		input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
+		input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
+	}
 
-	finger[id].status = status & MXT_MOVE ?
-				MXT_MOVE : MXT_PRESS;
-	finger[id].x = x;
-	finger[id].y = y;
-	finger[id].area = area;
-	finger[id].pressure = pressure;
-
-	mxt_input_report(data, id);
+	input_mt_report_pointer_emulation(input_dev, false);
+	input_sync(input_dev);
 }
 
 static irqreturn_t mxt_interrupt(int irq, void *dev_id)
-- 
1.7.7.3


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

* [PATCH 17/23 v6] Input: atmel_mxt_ts - add detail to touchevent debug message
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (15 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 16/23 v6] Input: atmel_mxt_ts - simplify event reporting Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 18/23 v6] Input: atmel_mxt_ts - refactor when and how object table is freed Daniel Kurtz
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Update the debug message:
 * print inidividual status bits
 * print the pressure value
 * use '%u' for unsigned quantities

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index c37584d..d6b64a0f 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -195,6 +195,7 @@
 #define MXT_BOOT_STATUS_MASK	0x3f
 
 /* Touch status */
+#define MXT_UNGRIP		(1 << 0)
 #define MXT_SUPPRESS		(1 << 1)
 #define MXT_AMP			(1 << 2)
 #define MXT_VECTOR		(1 << 3)
@@ -531,9 +532,19 @@ static void mxt_input_touchevent(struct mxt_data *data,
 	area = message->message[4];
 	pressure = message->message[5];
 
-	dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id,
-		status & MXT_MOVE ? "moved" : "pressed",
-		x, y, area);
+	dev_dbg(dev,
+		"[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
+		id,
+		(status & MXT_DETECT) ? 'D' : '.',
+		(status & MXT_PRESS) ? 'P' : '.',
+		(status & MXT_RELEASE) ? 'R' : '.',
+		(status & MXT_MOVE) ? 'M' : '.',
+		(status & MXT_VECTOR) ? 'V' : '.',
+		(status & MXT_AMP) ? 'A' : '.',
+		(status & MXT_SUPPRESS) ? 'S' : '.',
+		(status & MXT_UNGRIP) ? 'U' : '.',
+		x, y, area, pressure);
+
 	input_mt_slot(input_dev, id);
 	input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
 				   status & MXT_DETECT);
-- 
1.7.7.3


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

* [PATCH 18/23 v6] Input: atmel_mxt_ts - refactor when and how object table is freed
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (16 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 17/23 v6] Input: atmel_mxt_ts - add detail to touchevent debug message Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 19/23 v6] Input: atmel_mxt_ts - cache T9 reportid range when reading object table Daniel Kurtz
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

The Object Table is freed in three cases:
  1) When the driver is being removed.
  2) In the error path of mxt_initialize().
  3) Just after a firmware update, when a new object table is
     about to be read.

For cases 2 & 3, the driver is not immediately unloaded, so this patch
refactors these cases to use a common cleanup function.  It also refactors
the mxt_initialize error paths to ensure that this cleanup happens.

Note: mxt_update_fw_store() does not handle errors during mxt_initialize().
A proposed fix for this is in a subsequent patchset.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index d6b64a0f..488e3e8 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -750,6 +750,12 @@ static int mxt_get_object_table(struct mxt_data *data)
 	return 0;
 }
 
+static void mxt_free_object_table(struct mxt_data *data)
+{
+	kfree(data->object_table);
+	data->object_table = NULL;
+}
+
 static int mxt_initialize(struct mxt_data *data)
 {
 	struct i2c_client *client = data->client;
@@ -772,12 +778,12 @@ static int mxt_initialize(struct mxt_data *data)
 	/* Get object table information */
 	error = mxt_get_object_table(data);
 	if (error)
-		return error;
+		goto err_free_object_table;
 
 	/* Check register init values */
 	error = mxt_check_reg_init(data);
 	if (error)
-		return error;
+		goto err_free_object_table;
 
 	mxt_handle_pdata(data);
 
@@ -795,12 +801,12 @@ static int mxt_initialize(struct mxt_data *data)
 	/* Update matrix size at info struct */
 	error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
 	if (error)
-		return error;
+		goto err_free_object_table;
 	info->matrix_xsize = val;
 
 	error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
 	if (error)
-		return error;
+		goto err_free_object_table;
 	info->matrix_ysize = val;
 
 	dev_info(&client->dev,
@@ -814,6 +820,10 @@ static int mxt_initialize(struct mxt_data *data)
 			info->object_num);
 
 	return 0;
+
+err_free_object_table:
+	mxt_free_object_table(data);
+	return error;
 }
 
 static void mxt_calc_resolution(struct mxt_data *data)
@@ -1000,8 +1010,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
 		/* Wait for reset */
 		msleep(MXT_FWRESET_TIME);
 
-		kfree(data->object_table);
-		data->object_table = NULL;
+		mxt_free_object_table(data);
 
 		mxt_initialize(data);
 	}
@@ -1128,7 +1137,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
 
 	error = mxt_initialize(data);
 	if (error)
-		goto err_free_object;
+		goto err_free_mem;
 
 	error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
 			pdata->irqflags, client->name, data);
-- 
1.7.7.3


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

* [PATCH 19/23 v6] Input: atmel_mxt_ts - cache T9 reportid range when reading object table
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (17 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 18/23 v6] Input: atmel_mxt_ts - refactor when and how object table is freed Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 20/23 v6] Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt Daniel Kurtz
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Streamline interrupt processing by caching the T9 reportid range when
first reading the object table.

In the process, refactor reading the object descriptor table.
First, since the object_table entries are now exactly the same layout
in device memory and in the driver, allocate an appropriately sized
array and fetch the entire table directly into it in a single i2c
transaction.  Since a 6 byte table object requires 10 bytes to read,
doing this dramatically reduces overhead.

Note: The cached T9 reportid's are initialized to 0, which is an invalid
reportid.  Thus, the checks in the interrupt handler will always fail for
devices that do not support the T9 object.  Therefore, after doing a
firmware update, the old object table is destroyed and all cached object
values are reset to 0, before reading the new object table, in case
the new firmware does not have the old objects.

This patch tested on an MXT224E.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   76 ++++++++++++++++--------------
 1 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 488e3e8..48f3637 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -227,13 +227,10 @@ struct mxt_info {
 struct mxt_object {
 	u8 type;
 	u16 start_address;
-	u8 size;
-	u8 instances;
+	u8 size;		/* Size of each instance - 1 */
+	u8 instances;		/* Number of instances - 1 */
 	u8 num_report_ids;
-
-	/* to map object and message */
-	u8 max_reportid;
-};
+} __packed;
 
 struct mxt_message {
 	u8 reportid;
@@ -251,6 +248,10 @@ struct mxt_data {
 	unsigned int irq;
 	unsigned int max_x;
 	unsigned int max_y;
+
+	/* Cached parameters from object table */
+	u8 T9_reportid_min;
+	u8 T9_reportid_max;
 };
 
 static bool mxt_object_readable(unsigned int type)
@@ -459,13 +460,6 @@ static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
 	return __mxt_write_reg(client, reg, 1, &val);
 }
 
-static int mxt_read_object_table(struct i2c_client *client,
-				      u16 reg, u8 *object_buf)
-{
-	return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE,
-				   object_buf);
-}
-
 static struct mxt_object *
 mxt_get_object(struct mxt_data *data, u8 type)
 {
@@ -564,7 +558,6 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 {
 	struct mxt_data *data = dev_id;
 	struct mxt_message message;
-	struct mxt_object *object;
 	struct device *dev = &data->client->dev;
 	int id;
 	u8 reportid;
@@ -579,13 +572,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 
 		reportid = message.reportid;
 
-		/* whether reportid is thing of MXT_TOUCH_MULTI_T9 */
-		object = mxt_get_object(data, MXT_TOUCH_MULTI_T9);
-		if (!object)
-			goto end;
-
-		max_reportid = object->max_reportid;
-		min_reportid = max_reportid - object->num_report_ids + 1;
+		max_reportid = data->T9_reportid_max;
+		min_reportid = data->T9_reportid_min;
 		id = reportid - min_reportid;
 
 		if (reportid >= min_reportid && reportid <= max_reportid)
@@ -720,30 +708,46 @@ static int mxt_get_info(struct mxt_data *data)
 
 static int mxt_get_object_table(struct mxt_data *data)
 {
+	struct i2c_client *client = data->client;
+	size_t table_size;
 	int error;
 	int i;
-	u16 reg;
-	u8 reportid = 0;
-	u8 buf[MXT_OBJECT_SIZE];
+	u8 reportid;
+
+	table_size = data->info.object_num * sizeof(struct mxt_object);
+	error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
+			data->object_table);
+	if (error)
+		return error;
 
+	/* Valid Report IDs start counting from 1 */
+	reportid = 1;
 	for (i = 0; i < data->info.object_num; i++) {
 		struct mxt_object *object = data->object_table + i;
+		u8 min_id, max_id;
 
-		reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
-		error = mxt_read_object_table(data->client, reg, buf);
-		if (error)
-			return error;
-
-		object->type = buf[0];
-		object->start_address = (buf[2] << 8) | buf[1];
-		object->size = buf[3];
-		object->instances = buf[4];
-		object->num_report_ids = buf[5];
+		le16_to_cpus(&object->start_address);
 
 		if (object->num_report_ids) {
+			min_id = reportid;
 			reportid += object->num_report_ids *
 					(object->instances + 1);
-			object->max_reportid = reportid;
+			max_id = reportid - 1;
+		} else {
+			min_id = 0;
+			max_id = 0;
+		}
+
+		dev_dbg(&data->client->dev,
+			"Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n",
+			object->type, object->start_address, object->size + 1,
+			object->instances + 1, min_id, max_id);
+
+		switch (object->type) {
+		case MXT_TOUCH_MULTI_T9:
+			data->T9_reportid_min = min_id;
+			data->T9_reportid_max = max_id;
+			break;
 		}
 	}
 
@@ -754,6 +758,8 @@ static void mxt_free_object_table(struct mxt_data *data)
 {
 	kfree(data->object_table);
 	data->object_table = NULL;
+	data->T9_reportid_min = 0;
+	data->T9_reportid_max = 0;
 }
 
 static int mxt_initialize(struct mxt_data *data)
-- 
1.7.7.3


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

* [PATCH 20/23 v6] Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (18 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 19/23 v6] Input: atmel_mxt_ts - cache T9 reportid range when reading object table Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 21/23 v6] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots Daniel Kurtz
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

This small refactor is in preparation for checking more report types
in the mxt_interrupt message processing loop.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 48f3637..a9e0b54 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -554,6 +554,12 @@ static void mxt_input_touchevent(struct mxt_data *data,
 	input_sync(input_dev);
 }
 
+static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
+{
+	u8 id = msg->reportid;
+	return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
+}
+
 static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 {
 	struct mxt_data *data = dev_id;
@@ -561,8 +567,6 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 	struct device *dev = &data->client->dev;
 	int id;
 	u8 reportid;
-	u8 max_reportid;
-	u8 min_reportid;
 
 	do {
 		if (mxt_read_message(data, &message)) {
@@ -572,11 +576,9 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 
 		reportid = message.reportid;
 
-		max_reportid = data->T9_reportid_max;
-		min_reportid = data->T9_reportid_min;
-		id = reportid - min_reportid;
+		id = reportid - data->T9_reportid_min;
 
-		if (reportid >= min_reportid && reportid <= max_reportid)
+		if (mxt_is_T9_message(data, &message))
 			mxt_input_touchevent(data, &message, id);
 		else
 			mxt_dump_message(dev, &message);
-- 
1.7.7.3


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

* [PATCH 21/23 v6] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (19 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 20/23 v6] Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 22/23 v6] Input: atmel_mxt_ts - send all MT-B slots in one input report Daniel Kurtz
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Atmel mxt devices can report one finger for each T9 reportid.
Therefore, this range can be used to report the max number of MT-B slots
to userspace instead of assuming a fixed 10.

Note that mxt_initialized() must complete early, since the input_dev
properties now depend on values in the object table.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index a9e0b54..2746b0d 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -212,8 +212,6 @@
 /* Touchscreen absolute values */
 #define MXT_MAX_AREA		0xff
 
-#define MXT_MAX_FINGER		10
-
 struct mxt_info {
 	u8 family_id;
 	u8 variant_id;
@@ -1086,6 +1084,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
 	struct mxt_data *data;
 	struct input_dev *input_dev;
 	int error;
+	unsigned int num_mt_slots;
 
 	if (!pdata)
 		return -EINVAL;
@@ -1115,6 +1114,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
 
 	mxt_calc_resolution(data);
 
+	error = mxt_initialize(data);
+	if (error)
+		goto err_free_mem;
+
 	__set_bit(EV_ABS, input_dev->evbit);
 	__set_bit(EV_KEY, input_dev->evbit);
 	__set_bit(BTN_TOUCH, input_dev->keybit);
@@ -1128,9 +1131,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
 			     0, 255, 0, 0);
 
 	/* For multi touch */
-	error = input_mt_init_slots(input_dev, MXT_MAX_FINGER);
+	num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
+	error = input_mt_init_slots(input_dev, num_mt_slots);
 	if (error)
-		goto err_free_mem;
+		goto err_free_object;
 	input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
 			     0, MXT_MAX_AREA, 0, 0);
 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
@@ -1143,10 +1147,6 @@ static int __devinit mxt_probe(struct i2c_client *client,
 	input_set_drvdata(input_dev, data);
 	i2c_set_clientdata(client, data);
 
-	error = mxt_initialize(data);
-	if (error)
-		goto err_free_mem;
-
 	error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
 			pdata->irqflags, client->name, data);
 	if (error) {
-- 
1.7.7.3


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

* [PATCH 22/23 v6] Input: atmel_mxt_ts - send all MT-B slots in one input report
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (20 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 21/23 v6] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-28 13:08 ` [PATCH 23/23 v6] Input: atmel_mxt_ts - parse T6 reports Daniel Kurtz
  2012-06-29 14:23 ` [PATCH 00/23 v6] cleanup atmel_mxt_ts Henrik Rydberg
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

Each interrupt contains information for all contacts with changing
properties.  Process all of this information at once, and send it all in a
a single input report (ie input events ending in EV_SYN/SYN_REPORT).

This patch was tested using an MXT224E.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 2746b0d..4c9a06c 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -547,9 +547,6 @@ static void mxt_input_touchevent(struct mxt_data *data,
 		input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
 		input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
 	}
-
-	input_mt_report_pointer_emulation(input_dev, false);
-	input_sync(input_dev);
 }
 
 static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
@@ -565,6 +562,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 	struct device *dev = &data->client->dev;
 	int id;
 	u8 reportid;
+	bool update_input = false;
 
 	do {
 		if (mxt_read_message(data, &message)) {
@@ -576,12 +574,19 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 
 		id = reportid - data->T9_reportid_min;
 
-		if (mxt_is_T9_message(data, &message))
+		if (mxt_is_T9_message(data, &message)) {
 			mxt_input_touchevent(data, &message, id);
-		else
+			update_input = true;
+		} else {
 			mxt_dump_message(dev, &message);
+		}
 	} while (reportid != 0xff);
 
+	if (update_input) {
+		input_mt_report_pointer_emulation(data->input_dev, false);
+		input_sync(data->input_dev);
+	}
+
 end:
 	return IRQ_HANDLED;
 }
-- 
1.7.7.3


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

* [PATCH 23/23 v6] Input: atmel_mxt_ts - parse T6 reports
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (21 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 22/23 v6] Input: atmel_mxt_ts - send all MT-B slots in one input report Daniel Kurtz
@ 2012-06-28 13:08 ` Daniel Kurtz
  2012-06-29 14:23 ` [PATCH 00/23 v6] cleanup atmel_mxt_ts Henrik Rydberg
  23 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-06-28 13:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen
  Cc: linux-input, linux-kernel, Olof Johansson, Benson Leung, Daniel Kurtz

The normal messages sent after boot or NVRAM update are T6 reports,
containing a status, and the config memory checksum.  Parse them and dump
a useful info message.

This patch tested on an MXT224E.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 4c9a06c..37190ab 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -248,6 +248,7 @@ struct mxt_data {
 	unsigned int max_y;
 
 	/* Cached parameters from object table */
+	u8 T6_reportid;
 	u8 T9_reportid_min;
 	u8 T9_reportid_max;
 };
@@ -549,6 +550,11 @@ static void mxt_input_touchevent(struct mxt_data *data,
 	}
 }
 
+static unsigned mxt_extract_T6_csum(const u8 *csum)
+{
+	return csum[0] | (csum[1] << 8) | (csum[2] << 16);
+}
+
 static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
 {
 	u8 id = msg->reportid;
@@ -559,8 +565,8 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 {
 	struct mxt_data *data = dev_id;
 	struct mxt_message message;
+	const u8 *payload = &message.message[0];
 	struct device *dev = &data->client->dev;
-	int id;
 	u8 reportid;
 	bool update_input = false;
 
@@ -572,9 +578,13 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
 
 		reportid = message.reportid;
 
-		id = reportid - data->T9_reportid_min;
-
-		if (mxt_is_T9_message(data, &message)) {
+		if (reportid == data->T6_reportid) {
+			u8 status = payload[0];
+			unsigned csum = mxt_extract_T6_csum(&payload[1]);
+			dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
+				status, csum);
+		} else if (mxt_is_T9_message(data, &message)) {
+			int id = reportid - data->T9_reportid_min;
 			mxt_input_touchevent(data, &message, id);
 			update_input = true;
 		} else {
@@ -749,6 +759,9 @@ static int mxt_get_object_table(struct mxt_data *data)
 			object->instances + 1, min_id, max_id);
 
 		switch (object->type) {
+		case MXT_GEN_COMMAND_T6:
+			data->T6_reportid = min_id;
+			break;
 		case MXT_TOUCH_MULTI_T9:
 			data->T9_reportid_min = min_id;
 			data->T9_reportid_max = max_id;
@@ -763,8 +776,10 @@ static void mxt_free_object_table(struct mxt_data *data)
 {
 	kfree(data->object_table);
 	data->object_table = NULL;
+	data->T6_reportid = 0;
 	data->T9_reportid_min = 0;
 	data->T9_reportid_max = 0;
+
 }
 
 static int mxt_initialize(struct mxt_data *data)
-- 
1.7.7.3


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

* Re: [PATCH 00/23 v6] cleanup atmel_mxt_ts
  2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
                   ` (22 preceding siblings ...)
  2012-06-28 13:08 ` [PATCH 23/23 v6] Input: atmel_mxt_ts - parse T6 reports Daniel Kurtz
@ 2012-06-29 14:23 ` Henrik Rydberg
  23 siblings, 0 replies; 28+ messages in thread
From: Henrik Rydberg @ 2012-06-29 14:23 UTC (permalink / raw)
  To: Daniel Kurtz
  Cc: Dmitry Torokhov, Joonyoung Shim, Nick Dyer, Yufeng Shen,
	linux-input, linux-kernel, Olof Johansson, Benson Leung

> This patchset cleans up the atmel_mxt_ts touchscreen driver.
> 
> They were tested using an MXT224E, and apply cleanly to input/next.
> 
> Changes in v6:
>  * Patches 1-8: No change
>  * Patch 9: refactor per Henrik, and abort on error
>  * Patch 10: rebased
>  * Patch 11: kfree()
>  * Patch 12-17: rebased
>  * Patch 18: refactored per Henrik
>  * Patch 19: Moved init spew from info -> debug & refactor kfree()
>  * Patch 20, 23: refactored per Henrik
>  * Patch 21-22: rebased
>  * Patch 23: refactored per Henrik
> 
> Daniel Kurtz (23):
>   Input: atmel_mxt_ts - derive phys from i2c client adapter
>   Input: atmel_mxt_ts - use client name for irq
>   Input: atmel_mxt_ts - detect OOM when creating mt slots
>   Input: atmel_mxt_ts - warn if sysfs could not be created
>   Input: atmel_mxt_ts - don't read T5 when dumping objects
>   Input: atmel_mxt_ts - use scnprintf for object sysfs entry
>   Input: atmel_mxt_ts - optimize reading objects in object sysfs entry
>   Input: atmel_mxt_ts - print less overhead when dumping objects
>   Input: atmel_mxt_ts - print all instances when dumping objects
>   Input: atmel_mxt_ts - return errors from i2c layer
>   Input: atmel_mxt_ts - add variable length __mxt_write_reg
>   Input: atmel_mxt_ts - optimize writing of object table entries
>   Input: atmel_mxt_ts - read ID information block in one i2c
>     transaction
>   Input: atmel_mxt_ts - update driver ID info logging
>   Input: atmel_mxt_ts - add sysfs entries to read fw and hw version
>   Input: atmel_mxt_ts - simplify event reporting
>   Input: atmel_mxt_ts - add detail to touchevent debug message
>   Input: atmel_mxt_ts - refactor when and how object table is freed
>   Input: atmel_mxt_ts - cache T9 reportid range when reading object
>     table
>   Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt
>   Input: atmel_mxt_ts - use T9 reportid range to init number of mt
>     slots
>   Input: atmel_mxt_ts - send all MT-B slots in one input report
>   Input: atmel_mxt_ts - parse T6 reports
> 
>  drivers/input/touchscreen/atmel_mxt_ts.c |  468 +++++++++++++++--------------
>  1 files changed, 242 insertions(+), 226 deletions(-)
> 
> -- 
> 1.7.7.3
> 

All 23 patches applied and pushed. Thank you!

Henrik

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

* Re: [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created
  2012-06-28 13:08 ` [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created Daniel Kurtz
@ 2012-07-05 17:22   ` Dmitry Torokhov
  2012-07-05 19:15     ` Henrik Rydberg
  0 siblings, 1 reply; 28+ messages in thread
From: Dmitry Torokhov @ 2012-07-05 17:22 UTC (permalink / raw)
  To: Daniel Kurtz
  Cc: Henrik Rydberg, Joonyoung Shim, Nick Dyer, Yufeng Shen,
	linux-input, linux-kernel, Olof Johansson, Benson Leung

Hi Daniel, Henrik,

On Thu, Jun 28, 2012 at 09:08:05PM +0800, Daniel Kurtz wrote:
> If sysfs entry creation fails, the driver is still usable, so don't
> just abort probe.  Just warn and continue.
> 

I understand that I am a bit late to the party :) but I do not agree
with this change. Failure to create attributes is not sometihng that
user could cause (at least not easily) and thus would not be a setup
issue but something more severe. I believe we should fail loading the
driver so sysfs attribute breakage will be noticed as soon as possible,
instead of discovering it much much later in the process.

So I think we should revert this one.

Thanks.

-- 
Dmitry

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

* Re: [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created
  2012-07-05 17:22   ` Dmitry Torokhov
@ 2012-07-05 19:15     ` Henrik Rydberg
  2012-07-16  2:34       ` Daniel Kurtz
  0 siblings, 1 reply; 28+ messages in thread
From: Henrik Rydberg @ 2012-07-05 19:15 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Daniel Kurtz, Joonyoung Shim, Nick Dyer, Yufeng Shen,
	linux-input, linux-kernel, Olof Johansson, Benson Leung

On Thu, Jul 05, 2012 at 10:22:30AM -0700, Dmitry Torokhov wrote:
> Hi Daniel, Henrik,
> 
> On Thu, Jun 28, 2012 at 09:08:05PM +0800, Daniel Kurtz wrote:
> > If sysfs entry creation fails, the driver is still usable, so don't
> > just abort probe.  Just warn and continue.
> > 
> 
> I understand that I am a bit late to the party :) but I do not agree
> with this change. Failure to create attributes is not sometihng that
> user could cause (at least not easily) and thus would not be a setup
> issue but something more severe. I believe we should fail loading the
> driver so sysfs attribute breakage will be noticed as soon as possible,
> instead of discovering it much much later in the process.
> 
> So I think we should revert this one.

Ok, I agree. Applied and pushed.

Daniel, I should probably have asked this before: what was the reason
for this patch in the first place?

Thanks,
Henrik

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

* Re: [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created
  2012-07-05 19:15     ` Henrik Rydberg
@ 2012-07-16  2:34       ` Daniel Kurtz
  0 siblings, 0 replies; 28+ messages in thread
From: Daniel Kurtz @ 2012-07-16  2:34 UTC (permalink / raw)
  To: Henrik Rydberg
  Cc: Dmitry Torokhov, Joonyoung Shim, Nick Dyer, Yufeng Shen,
	linux-input, linux-kernel, Olof Johansson, Benson Leung

On Fri, Jul 6, 2012 at 3:15 AM, Henrik Rydberg <rydberg@euromail.se> wrote:
> On Thu, Jul 05, 2012 at 10:22:30AM -0700, Dmitry Torokhov wrote:
>> Hi Daniel, Henrik,
>>
>> On Thu, Jun 28, 2012 at 09:08:05PM +0800, Daniel Kurtz wrote:
>> > If sysfs entry creation fails, the driver is still usable, so don't
>> > just abort probe.  Just warn and continue.
>> >
>>
>> I understand that I am a bit late to the party :) but I do not agree
>> with this change. Failure to create attributes is not sometihng that
>> user could cause (at least not easily) and thus would not be a setup
>> issue but something more severe. I believe we should fail loading the
>> driver so sysfs attribute breakage will be noticed as soon as possible,
>> instead of discovering it much much later in the process.
>>
>> So I think we should revert this one.
>
> Ok, I agree. Applied and pushed.
>
> Daniel, I should probably have asked this before: what was the reason
> for this patch in the first place?
>
> Thanks,
> Henrik

No additional reason beyond what is stated in the commit message -
that the driver is still usable without its sysfs entries, so no need
to abort probe.

I'm fine with reverting back to the fail fast approach, too.

Thanks,
Daniel

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

end of thread, other threads:[~2012-07-16  2:35 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-28 13:08 [PATCH 00/23 v6] cleanup atmel_mxt_ts Daniel Kurtz
2012-06-28 13:08 ` [PATCH 01/23 v6] Input: atmel_mxt_ts - derive phys from i2c client adapter Daniel Kurtz
2012-06-28 13:08 ` [PATCH 02/23 v6] Input: atmel_mxt_ts - use client name for irq Daniel Kurtz
2012-06-28 13:08 ` [PATCH 03/23 v6] Input: atmel_mxt_ts - detect OOM when creating mt slots Daniel Kurtz
2012-06-28 13:08 ` [PATCH 04/23 v6] Input: atmel_mxt_ts - warn if sysfs could not be created Daniel Kurtz
2012-07-05 17:22   ` Dmitry Torokhov
2012-07-05 19:15     ` Henrik Rydberg
2012-07-16  2:34       ` Daniel Kurtz
2012-06-28 13:08 ` [PATCH 05/23 v6] Input: atmel_mxt_ts - don't read T5 when dumping objects Daniel Kurtz
2012-06-28 13:08 ` [PATCH 06/23 v6] Input: atmel_mxt_ts - use scnprintf for object sysfs entry Daniel Kurtz
2012-06-28 13:08 ` [PATCH 07/23 v6] Input: atmel_mxt_ts - optimize reading objects in " Daniel Kurtz
2012-06-28 13:08 ` [PATCH 08/23 v6] Input: atmel_mxt_ts - print less overhead when dumping objects Daniel Kurtz
2012-06-28 13:08 ` [PATCH 09/23 v6] Input: atmel_mxt_ts - print all instances " Daniel Kurtz
2012-06-28 13:08 ` [PATCH 10/23 v6] Input: atmel_mxt_ts - return errors from i2c layer Daniel Kurtz
2012-06-28 13:08 ` [PATCH 11/23 v6] Input: atmel_mxt_ts - add variable length __mxt_write_reg Daniel Kurtz
2012-06-28 13:08 ` [PATCH 12/23 v6] Input: atmel_mxt_ts - optimize writing of object table entries Daniel Kurtz
2012-06-28 13:08 ` [PATCH 13/23 v6] Input: atmel_mxt_ts - read ID information block in one i2c transaction Daniel Kurtz
2012-06-28 13:08 ` [PATCH 14/23 v6] Input: atmel_mxt_ts - update driver ID info logging Daniel Kurtz
2012-06-28 13:08 ` [PATCH 15/23 v6] Input: atmel_mxt_ts - add sysfs entries to read fw and hw version Daniel Kurtz
2012-06-28 13:08 ` [PATCH 16/23 v6] Input: atmel_mxt_ts - simplify event reporting Daniel Kurtz
2012-06-28 13:08 ` [PATCH 17/23 v6] Input: atmel_mxt_ts - add detail to touchevent debug message Daniel Kurtz
2012-06-28 13:08 ` [PATCH 18/23 v6] Input: atmel_mxt_ts - refactor when and how object table is freed Daniel Kurtz
2012-06-28 13:08 ` [PATCH 19/23 v6] Input: atmel_mxt_ts - cache T9 reportid range when reading object table Daniel Kurtz
2012-06-28 13:08 ` [PATCH 20/23 v6] Input: atmel_mxt_ts - refactor reportid checking in mxt_interrupt Daniel Kurtz
2012-06-28 13:08 ` [PATCH 21/23 v6] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots Daniel Kurtz
2012-06-28 13:08 ` [PATCH 22/23 v6] Input: atmel_mxt_ts - send all MT-B slots in one input report Daniel Kurtz
2012-06-28 13:08 ` [PATCH 23/23 v6] Input: atmel_mxt_ts - parse T6 reports Daniel Kurtz
2012-06-29 14:23 ` [PATCH 00/23 v6] cleanup atmel_mxt_ts Henrik Rydberg

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.