From: Daniel Kurtz <hidden> Date: 2012-06-26 07:02:15
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
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:57:22
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:57:25
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:57:38
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 89 ++++-------------------------
1 files changed, 13 insertions(+), 76 deletions(-)
@@ -239,14 +239,6 @@ struct mxt_message {u8message[7];};-structmxt_finger{-intstatus;-intx;-inty;-intarea;-intpressure;-};-/* Each client has this additional data */structmxt_data{structi2c_client*client;
@@ -518,75 +509,17 @@ static int mxt_write_object(struct mxt_data *data,returnmxt_write_reg(data->client,reg+offset,val);}-staticvoidmxt_input_report(structmxt_data*data,intsingle_id)-{-structmxt_finger*finger=data->finger;-structinput_dev*input_dev=data->input_dev;-intstatus=finger[single_id].status;-intfinger_num=0;-intid;--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);-}-staticvoidmxt_input_touchevent(structmxt_data*data,structmxt_message*message,intid){-structmxt_finger*finger=data->finger;structdevice*dev=&data->client->dev;u8status=message->message[0];+structinput_dev*input_dev=data->input_dev;intx;inty;intarea;intpressure;-/* 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)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:57:39
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 80 +++++++++++++++++-------------
1 files changed, 45 insertions(+), 35 deletions(-)
@@ -227,13 +227,10 @@ struct mxt_info {structmxt_object{u8type;u16start_address;-u8size;-u8instances;+u8size;/* Size of each instance - 1 */+u8instances;/* Number of instances - 1 */u8num_report_ids;--/* to map object and message */-u8max_reportid;-};+}__packed;structmxt_message{u8reportid;
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:58:13
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:58:18
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:58:21
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
@@ -1074,6 +1072,7 @@ static int __devinit mxt_probe(struct i2c_client *client,structmxt_data*data;structinput_dev*input_dev;interror;+unsignedintnum_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)+gotoerr_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)-gotoerr_free_mem;+gotoerr_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)-gotoerr_free_object;-error=request_threaded_irq(client->irq,NULL,mxt_interrupt,pdata->irqflags,client->name,data);if(error){
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:59:29
For objects with multiple instances, dump them all, prepending each with
its "Instance #".
Signed-off-by: Daniel Kurtz <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 30 +++++++++++++++++++++---------
1 files changed, 21 insertions(+), 9 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:59:47
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:59:49
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:59:50
Reading the whole info block in one i2c transaction speeds up driver
probe significantly, especially on slower i2c busses.
Signed-off-by: Daniel Kurtz <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 26 +++-----------------------
1 files changed, 3 insertions(+), 23 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 06:59:52
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
@@ -881,6 +881,26 @@ static void mxt_calc_resolution(struct mxt_data *data)}}+/* Firmware Version is returned as Major.Minor.Build */+staticssize_tmxt_fw_version_show(structdevice*dev,+structdevice_attribute*attr,char*buf)+{+structmxt_data*data=dev_get_drvdata(dev);+structmxt_info*info=&data->info;+returnscnprintf(buf,PAGE_SIZE,"%u.%u.%02X\n",+info->version>>4,info->version&0xf,info->build);+}++/* Hardware Version is returned as FamilyID.VariantID */+staticssize_tmxt_hw_version_show(structdevice*dev,+structdevice_attribute*attr,char*buf)+{+structmxt_data*data=dev_get_drvdata(dev);+structmxt_info*info=&data->info;+returnscnprintf(buf,PAGE_SIZE,"%u.%u\n",+info->family_id,info->variant_id);+}+staticssize_tmxt_object_show(structdevice*dev,structdevice_attribute*attr,char*buf){
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:01:10
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:01:12
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 12 ++++--------
1 files changed, 4 insertions(+), 8 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:01:14
Using scnprintf() is a cleaner way to ensure that we don't overwrite the
PAGE_SIZE sysfs output buffer.
Signed-off-by: Daniel Kurtz <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 16 ++++------------
1 files changed, 4 insertions(+), 12 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:01:16
Read each object in a single i2c transaction instead of byte-by-byte
Signed-off-by: Daniel Kurtz <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 35 ++++++++++++-----------------
1 files changed, 15 insertions(+), 20 deletions(-)
@@ -479,20 +479,6 @@ static int mxt_read_message(struct mxt_data *data,sizeof(structmxt_message),message);}-staticintmxt_read_object(structmxt_data*data,-u8type,u8offset,u8*val)-{-structmxt_object*object;-u16reg;--object=mxt_get_object(data,type);-if(!object)-return-EINVAL;--reg=object->start_address;-return__mxt_read_reg(data->client,reg+offset,1,val);-}-staticintmxt_write_object(structmxt_data*data,u8type,u8offset,u8val){
@@ -900,7 +886,14 @@ static ssize_t mxt_object_show(struct device *dev,inti,j;interror;u8val;+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;
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:02:13
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:02:57
Hopefully this new code path will never be used, but better safe than
sorry...
Signed-off-by: Daniel Kurtz <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
@@ -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)+gotoerr_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,
From: Daniel Kurtz <hidden> Date: 2012-06-26 07:04:57
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
From: Henrik Rydberg <hidden> Date: 2012-06-27 06:01:21
Hi Daniel,
For objects with multiple instances, dump them all, prepending each with
its "Instance #".
Signed-off-by: Daniel Kurtz <redacted>
---
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 <redacted>
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 #".
[rydberg@euromail.se: break out mxt_print_instance()]
Signed-off-by: Daniel Kurtz <redacted>
Signed-off-by: Henrik Rydberg <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 36 +++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 10 deletions(-)
@@ -885,7 +904,6 @@ static ssize_t mxt_object_show(struct device *dev,intcount=0;inti,j;interror;-u8val;u8*obuf;/* Pre-allocate buffer large enough to hold max sized object. */
From: Henrik Rydberg <hidden> Date: 2012-06-27 18:56:20
Hi Daniel,
quoted hunk
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
From: Henrik Rydberg <hidden> Date: 2012-06-27 19:40:45
Hi Daniel,
quoted hunk
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 80 +++++++++++++++++-------------
1 files changed, 45 insertions(+), 35 deletions(-)
@@ -227,13 +227,10 @@ struct mxt_info {structmxt_object{u8type;u16start_address;-u8size;-u8instances;+u8size;/* Size of each instance - 1 */+u8instances;/* Number of instances - 1 */u8num_report_ids;--/* to map object and message */-u8max_reportid;-};+}__packed;structmxt_message{u8reportid;
From: Henrik Rydberg <hidden> Date: 2012-06-27 20:09:07
Hi Daniel,
quoted hunk
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
@@ -1074,6 +1072,7 @@ static int __devinit mxt_probe(struct i2c_client *client,structmxt_data*data;structinput_dev*input_dev;interror;+unsignedintnum_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)+gotoerr_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.
From: Henrik Rydberg <hidden> Date: 2012-06-27 20:29:03
Hi Daniel
quoted hunk
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 <redacted>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
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.