2012-06-26 07:02:15

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 00/21 v5] cleanup atmel_mxt_ts

This patchset cleans up the atmel_mxt_ts touchscreen driver.

These patches mostly contain non-controversial changes that were previously
reviewed in previous versions of the patchset. However, based on feedback from
Henrik, the individual patches are now all much smaller and easier to review.

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

Whenever these patches (or their descendants) are accepted, there is a larger
patchset full of additional features and more significant changes that will
follow.

Changes in v5:
* Fixed phys per Dmitry's comments
* Removed "re-read matrix after applying pdata" per Nick
* T6 spew changd to dev_dbg per Nick


Daniel Kurtz (21):
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 - cache T9 reportid range when reading object
table
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 | 438 +++++++++++++++---------------
1 files changed, 217 insertions(+), 221 deletions(-)

--
1.7.7.3


2012-06-26 06:57:25

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 01/21 v5] Input: atmel_mxt_ts - derive phys from i2c client adapter

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 <[email protected]>
---
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

2012-06-26 06:57:39

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 18/21 v5] Input: atmel_mxt_ts - cache T9 reportid range when reading object table

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 <[email protected]>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 80 +++++++++++++++++-------------
1 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 7b042e5..4da12a9 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)
@@ -458,13 +459,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)
{
@@ -563,7 +557,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;
@@ -578,13 +571,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)
@@ -719,30 +707,49 @@ 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) {
+ kfree(data->object_table);
+ data->object_table = NULL;
+ 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_info(&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;
}
}

@@ -995,8 +1002,11 @@ static ssize_t mxt_update_fw_store(struct device *dev,
/* Wait for reset */
msleep(MXT_FWRESET_TIME);

+ /* Destroy old object table and any cached fields */
kfree(data->object_table);
data->object_table = NULL;
+ data->T9_reportid_min = 0;
+ data->T9_reportid_max = 0;

mxt_initialize(data);
}
--
1.7.7.3

2012-06-26 06:57:38

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 16/21 v5] Input: atmel_mxt_ts - simplify event reporting

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 <[email protected]>
---
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 0baff14..c4e6747 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;
@@ -518,75 +509,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)
@@ -600,15 +533,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

2012-06-26 06:57:22

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 04/21 v5] Input: atmel_mxt_ts - warn if sysfs could not be created

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 <[email protected]>
---
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

2012-06-26 06:58:21

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 19/21 v5] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots

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 <[email protected]>
---
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 4da12a9..b218b5f 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;
@@ -1074,6 +1072,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;
@@ -1103,6 +1102,10 @@ static int __devinit mxt_probe(struct i2c_client *client,

mxt_calc_resolution(data);

+ error = mxt_initialize(data);
+ if (error)
+ goto err_free_object;
+
__set_bit(EV_ABS, input_dev->evbit);
__set_bit(EV_KEY, input_dev->evbit);
__set_bit(BTN_TOUCH, input_dev->keybit);
@@ -1116,9 +1119,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,
@@ -1131,10 +1135,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_object;
-
error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
pdata->irqflags, client->name, data);
if (error) {
--
1.7.7.3

2012-06-26 06:58:19

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 17/21 v5] Input: atmel_mxt_ts - add detail to touchevent debug message

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
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 c4e6747..7b042e5 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)
@@ -530,9 +531,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

2012-06-26 06:58:18

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 20/21 v5] Input: atmel_mxt_ts - send all MT-B slots in one input report

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 <[email protected]>
---
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 b218b5f..f9a9be9 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -546,9 +546,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 irqreturn_t mxt_interrupt(int irq, void *dev_id)
@@ -560,6 +557,7 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
u8 reportid;
u8 max_reportid;
u8 min_reportid;
+ bool update_input = false;

do {
if (mxt_read_message(data, &message)) {
@@ -573,12 +571,19 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
min_reportid = data->T9_reportid_min;
id = reportid - min_reportid;

- if (reportid >= min_reportid && reportid <= max_reportid)
+ if (reportid >= min_reportid && reportid <= max_reportid) {
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

2012-06-26 06:58:15

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 12/21 v5] Input: atmel_mxt_ts - optimize writing of object table entries

Write each object using a single bulk i2c write transfer.

Signed-off-by: Daniel Kurtz <[email protected]>
Reviewed-by: Joonyoung Shim <[email protected]>
---
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 d9e7e68..c16fd9c 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -654,7 +654,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");
@@ -667,18 +668,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

2012-06-26 06:58:13

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 21/21 v5] Input: atmel_mxt_ts - parse T6 reports

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 <[email protected]>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index f9a9be9..8350bcc 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;
};
@@ -555,8 +556,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;
bool update_input = false;

do {
@@ -567,11 +566,15 @@ 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;
-
- if (reportid >= min_reportid && reportid <= max_reportid) {
+ if (reportid == data->T6_reportid) {
+ unsigned csum = message.message[1] |
+ (message.message[2] << 8) |
+ (message.message[3] << 16);
+ dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
+ message.message[0], csum);
+ } else if (reportid >= data->T9_reportid_min &&
+ reportid <= data->T9_reportid_max) {
+ id = reportid - data->T9_reportid_min;
mxt_input_touchevent(data, &message, id);
update_input = true;
} else {
@@ -749,6 +752,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;
@@ -1008,6 +1014,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
/* Destroy old object table and any cached fields */
kfree(data->object_table);
data->object_table = NULL;
+ data->T6_reportid = 0;
data->T9_reportid_min = 0;
data->T9_reportid_max = 0;

--
1.7.7.3

2012-06-26 06:59:29

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 09/21 v5] Input: atmel_mxt_ts - print all instances when dumping objects

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 30 +++++++++++++++++++++---------
1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index c8cfd7b..25d3dd5 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -883,7 +883,7 @@ static ssize_t mxt_object_show(struct device *dev,
struct mxt_data *data = dev_get_drvdata(dev);
struct mxt_object *object;
int count = 0;
- int i, j;
+ int i, j, k;
int error;
u8 val;
u8 *obuf;
@@ -903,18 +903,30 @@ 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;
+
+ error = __mxt_read_reg(data->client, addr, size, obuf);
+ if (error)
+ break;

- for (j = 0; j < object->size + 1; j++) {
- val = obuf[j];
+ if (object->instances > 0)
+ count += scnprintf(buf + count,
+ PAGE_SIZE - count,
+ "Instance %u\n", j);

+ for (k = 0; k < object->size + 1; k++) {
+ val = obuf[k];
+
+ count += scnprintf(buf + count,
+ PAGE_SIZE - count,
+ "\t[%2u]: %02x (%d)\n",
+ k, val, val);
+ }
count += scnprintf(buf + count, PAGE_SIZE - count,
- "\t[%2d]: %02x (%d)\n", j, val, val);
+ "\n");
}
- count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
}

kfree(obuf);
--
1.7.7.3

2012-06-26 06:59:52

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 15/21 v5] Input: atmel_mxt_ts - add sysfs entries to read fw and hw version

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.

Signed-off-by: Daniel Kurtz <[email protected]>
---
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 be7da72..0baff14 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -881,6 +881,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_object_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1042,10 +1062,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

2012-06-26 06:59:50

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 13/21 v5] Input: atmel_mxt_ts - read ID information block in one i2c transaction

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
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 c16fd9c..07e0238 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
@@ -759,32 +760,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

2012-06-26 06:59:49

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 05/21 v5] Input: atmel_mxt_ts - don't read T5 when dumping objects

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 <[email protected]>
---
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

2012-06-26 06:59:47

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 14/21 v5] Input: atmel_mxt_ts - update driver ID info logging

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 <[email protected]>
---
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 07e0238..be7da72 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -855,12 +855,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

2012-06-26 07:01:16

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 07/21 v5] Input: atmel_mxt_ts - optimize reading objects in object sysfs entry

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
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

2012-06-26 07:01:14

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 06/21 v5] Input: atmel_mxt_ts - use scnprintf for object sysfs entry

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
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

2012-06-26 07:01:12

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 08/21 v5] Input: atmel_mxt_ts - print less overhead when dumping objects

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 <[email protected]>
---
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

2012-06-26 07:01:10

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 11/21 v5] Input: atmel_mxt_ts - add variable length __mxt_write_reg

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 <[email protected]>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 3672553..d9e7e68 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)
@@ -453,6 +460,11 @@ static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
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

2012-06-26 07:02:13

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 02/21 v5] Input: atmel_mxt_ts - use client name for irq

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 <[email protected]>
---
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

2012-06-26 07:02:57

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 03/21 v5] Input: atmel_mxt_ts - detect OOM when creating mt slots

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

Signed-off-by: Daniel Kurtz <[email protected]>
---
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

2012-06-26 07:04:57

by Daniel Kurtz

[permalink] [raw]
Subject: [PATCH 10/21 v5] Input: atmel_mxt_ts - return errors from i2c layer

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 <[email protected]>
---
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 25d3dd5..3672553 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

2012-06-27 06:01:21

by Henrik Rydberg

[permalink] [raw]
Subject: Re: [PATCH 09/21 v5] Input: atmel_mxt_ts - print all instances when dumping objects

Hi Daniel,

> For objects with multiple instances, dump them all, prepending each with
> its "Instance #".
>
> Signed-off-by: Daniel Kurtz <[email protected]>
> ---

The number of nested for loops is in the red here... How about this
(untested) version instead?

Thanks,
Henrik

>From 7e1ae92ac21abb6215df7b0714ca809fb86116c3 Mon Sep 17 00:00:00 2001
From: Daniel Kurtz <[email protected]>
Date: Tue, 26 Jun 2012 14:56:57 +0800
Subject: [PATCH] Input: atmel_mxt_ts - print all instances when dumping
objects

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

[[email protected]: break out mxt_print_instance()]
Signed-off-by: Daniel Kurtz <[email protected]>
Signed-off-by: Henrik Rydberg <[email protected]>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 36 +++++++++++++++++++++++---------
1 file 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..5609372 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -877,6 +877,25 @@ static void mxt_calc_resolution(struct mxt_data *data)
}
}

+static int mxt_print_instance(char *buf, int count,
+ struct mxt_object *object, int i,
+ const u8 *val)
+{
+ int j;
+
+ if (object->instances > 0)
+ count += scnprintf(buf + count, PAGE_SIZE - count,
+ "Instance %u\n", i);
+
+ for (j = 0; j < object->size + 1; j++)
+ count += scnprintf(buf + count, PAGE_SIZE - count,
+ "\t[%2u]: %02x (%d)\n", j, val[j], val[j]);
+
+ 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 +904,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,18 +921,16 @@ 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)
+ break;

- count += scnprintf(buf + count, PAGE_SIZE - count,
- "\t[%2d]: %02x (%d)\n", j, val, val);
+ count = mxt_print_instance(buf, count, object, j, obuf);
}
- count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
}

kfree(obuf);
--
1.7.11

2012-06-27 18:56:20

by Henrik Rydberg

[permalink] [raw]
Subject: Re: [PATCH 11/21 v5] Input: atmel_mxt_ts - add variable length __mxt_write_reg

Hi Daniel,

> 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 <[email protected]>
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 22 +++++++++++++++++-----
> 1 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index 3672553..d9e7e68 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)
> @@ -453,6 +460,11 @@ static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)

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
>

Thanks,
Henrik

2012-06-27 19:40:45

by Henrik Rydberg

[permalink] [raw]
Subject: Re: [PATCH 18/21 v5] Input: atmel_mxt_ts - cache T9 reportid range when reading object table

Hi Daniel,

> 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 <[email protected]>
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 80 +++++++++++++++++-------------
> 1 files changed, 45 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index 7b042e5..4da12a9 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)
> @@ -458,13 +459,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)
> {
> @@ -563,7 +557,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;
> @@ -578,13 +571,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)
> @@ -719,30 +707,49 @@ 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) {
> + kfree(data->object_table);
> + data->object_table = NULL;
> + return error;

Freeing the object table here does not look right. Either free it in
mxt_initialize() or move the allocation into this function as well.

> + }
> +
> + /* 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_info(&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);

On a normal boot, how many lines of output does this driver generate?

> +
> + switch (object->type) {
> + case MXT_TOUCH_MULTI_T9:
> + data->T9_reportid_min = min_id;
> + data->T9_reportid_max = max_id;
> + break;
> }
> }
>
> @@ -995,8 +1002,11 @@ static ssize_t mxt_update_fw_store(struct device *dev,
> /* Wait for reset */
> msleep(MXT_FWRESET_TIME);
>
> + /* Destroy old object table and any cached fields */
> kfree(data->object_table);
> data->object_table = NULL;
> + data->T9_reportid_min = 0;
> + data->T9_reportid_max = 0;
>
> mxt_initialize(data);
> }
> --
> 1.7.7.3
>

Thanks,
Henrik

2012-06-27 20:09:07

by Henrik Rydberg

[permalink] [raw]
Subject: Re: [PATCH 19/21 v5] Input: atmel_mxt_ts - use T9 reportid range to init number of mt slots

Hi Daniel,

> 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 <[email protected]>
> ---
> 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 4da12a9..b218b5f 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;
> @@ -1074,6 +1072,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;
> @@ -1103,6 +1102,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
>
> mxt_calc_resolution(data);
>
> + error = mxt_initialize(data);
> + if (error)
> + goto err_free_object;
> +

The comment on the previous patch actually stems from problems in
mxt_initialize(); if a function fails, there should be no need to tear
down stuff created inside the failing function. IOW, it should be goto
err_free_mem here, and mxt_initialize() should be fixed accordingly.

> __set_bit(EV_ABS, input_dev->evbit);
> __set_bit(EV_KEY, input_dev->evbit);
> __set_bit(BTN_TOUCH, input_dev->keybit);
> @@ -1116,9 +1119,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,
> @@ -1131,10 +1135,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_object;
> -
> error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
> pdata->irqflags, client->name, data);
> if (error) {
> --
> 1.7.7.3
>

Thanks,
Henrik

2012-06-27 20:29:03

by Henrik Rydberg

[permalink] [raw]
Subject: Re: [PATCH 21/21 v5] Input: atmel_mxt_ts - parse T6 reports

Hi Daniel

> 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 <[email protected]>
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 21 ++++++++++++++-------
> 1 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index f9a9be9..8350bcc 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;
> };
> @@ -555,8 +556,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;
> bool update_input = false;
>
> do {
> @@ -567,11 +566,15 @@ 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;
> -
> - if (reportid >= min_reportid && reportid <= max_reportid) {
> + if (reportid == data->T6_reportid) {
> + unsigned csum = message.message[1] |
> + (message.message[2] << 8) |
> + (message.message[3] << 16);
> + dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
> + message.message[0], csum);

The formatting here may pass checkpatch, but it is really ugly. When
the patches start to require a lot of line breaks, and this series
contains quite a few, then please break out new functions.

> + } else if (reportid >= data->T9_reportid_min &&
> + reportid <= data->T9_reportid_max) {
> + id = reportid - data->T9_reportid_min;
> mxt_input_touchevent(data, &message, id);
> update_input = true;
> } else {
> @@ -749,6 +752,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;
> @@ -1008,6 +1014,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
> /* Destroy old object table and any cached fields */
> kfree(data->object_table);
> data->object_table = NULL;
> + data->T6_reportid = 0;
> data->T9_reportid_min = 0;
> data->T9_reportid_max = 0;

This bunch of lines, for instance, would fit perfectly in a
mxt_destroy() function, which would also make the comment superfluous.

>
> --
> 1.7.7.3
>

Thanks.
Henrik