From: Nick Dyer <nick.dyer@itdev.co.uk>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Daniel Kurtz <djkurtz@chromium.org>,
Henrik Rydberg <rydberg@euromail.se>,
Joonyoung Shim <jy0922.shim@samsung.com>,
Alan Bowens <Alan.Bowens@atmel.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Peter Meerwald <pmeerw@pmeerw.net>,
Benson Leung <bleung@chromium.org>,
Olof Johansson <olofj@chromium.org>,
Nick Dyer <nick.dyer@itdev.co.uk>
Subject: [PATCH 31/51] Input: atmel_mxt_ts - Add support for dynamic message size
Date: Thu, 27 Jun 2013 13:49:06 +0100 [thread overview]
Message-ID: <1372337366-9286-32-git-send-email-nick.dyer@itdev.co.uk> (raw)
In-Reply-To: <1372337366-9286-1-git-send-email-nick.dyer@itdev.co.uk>
The T5 object may have various sizes depending on the objects used on the
particular maXTouch chip and firmware version, therefore it can't be hardcoded
in the driver. Allocate a buffer on probe instead.
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 114 +++++++++++++++++-------------
1 file changed, 65 insertions(+), 49 deletions(-)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index b8e2b04..688eab3 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -79,6 +79,9 @@
#define MXT_SPT_MESSAGECOUNT_T44 44
#define MXT_SPT_CTECONFIG_T46 46
+/* MXT_GEN_MESSAGE_T5 object */
+#define MXT_RPTID_NOMSG 0xff
+
/* MXT_GEN_COMMAND_T6 field */
#define MXT_COMMAND_RESET 0
#define MXT_COMMAND_BACKUPNV 1
@@ -225,11 +228,6 @@ struct mxt_object {
u8 num_report_ids;
} __packed;
-struct mxt_message {
- u8 reportid;
- u8 message[7];
-};
-
/* Each client has this additional data */
struct mxt_data {
struct i2c_client *client;
@@ -247,8 +245,10 @@ struct mxt_data {
u32 info_crc;
u8 bootloader_addr;
struct t7_config t7_cfg;
+ u8 *msg_buf;
/* Cached parameters from object table */
+ u8 T5_msg_size;
u8 T6_reportid;
u16 T6_address;
u16 T7_address;
@@ -312,11 +312,10 @@ static bool mxt_object_readable(unsigned int type)
}
}
-static void mxt_dump_message(struct device *dev,
- struct mxt_message *message)
+static void mxt_dump_message(struct mxt_data *data, u8 *message)
{
- dev_dbg(dev, "reportid: %u\tmessage: %*ph\n",
- message->reportid, 7, message->message);
+ dev_dbg(&data->client->dev, "message: %*ph\n",
+ data->T5_msg_size, message);
}
static int mxt_wait_for_completion(struct mxt_data *data,
@@ -630,8 +629,7 @@ mxt_get_object(struct mxt_data *data, u8 type)
return NULL;
}
-static int mxt_read_message(struct mxt_data *data,
- struct mxt_message *message)
+static int mxt_read_message(struct mxt_data *data, u8 *message)
{
struct mxt_object *object;
u16 reg;
@@ -642,10 +640,10 @@ static int mxt_read_message(struct mxt_data *data,
reg = object->start_address;
return __mxt_read_reg(data->client, reg,
- sizeof(struct mxt_message), message);
+ data->T5_msg_size, message);
}
-static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
+static void mxt_input_button(struct mxt_data *data, u8 *message)
{
struct input_dev *input = data->input_dev;
const struct mxt_platform_data *pdata = data->pdata;
@@ -660,7 +658,7 @@ static void mxt_input_button(struct mxt_data *data, struct mxt_message *message)
for (i = 0; i < pdata->t19_num_keys; i++) {
if (pdata->t19_keymap[i] == KEY_RESERVED)
continue;
- button = !(message->message[0] & (1 << i));
+ button = !(message[1] & (1 << i));
input_report_key(input, pdata->t19_keymap[i], button);
}
}
@@ -671,12 +669,12 @@ static void mxt_input_sync(struct input_dev *input_dev)
input_sync(input_dev);
}
-static void mxt_input_touchevent(struct mxt_data *data,
- struct mxt_message *message, int id)
+static void mxt_input_touchevent(struct mxt_data *data, u8 *message)
{
struct device *dev = &data->client->dev;
- u8 status = message->message[0];
struct input_dev *input_dev = data->input_dev;
+ int id;
+ u8 status;
int x;
int y;
int area;
@@ -686,8 +684,10 @@ static void mxt_input_touchevent(struct mxt_data *data,
if (!data->enable_reporting)
return;
- x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
- y = (message->message[2] << 4) | ((message->message[3] & 0xf));
+ id = message[0] - data->T9_reportid_min;
+ status = message[1];
+ x = (message[2] << 4) | ((message[4] >> 4) & 0xf);
+ y = (message[3] << 4) | ((message[4] & 0xf));
/* Handle 10/12 bit switching */
if (data->max_x < 1024)
@@ -695,8 +695,8 @@ static void mxt_input_touchevent(struct mxt_data *data,
if (data->max_y < 1024)
y >>= 2;
- area = message->message[4];
- amplitude = message->message[5];
+ area = message[5];
+ amplitude = message[6];
dev_dbg(dev,
"[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
@@ -740,28 +740,28 @@ static u16 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)
+static bool mxt_is_T9_message(struct mxt_data *data, u8 *msg)
{
- u8 id = msg->reportid;
+ u8 id = msg[0];
return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
}
static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
{
- struct mxt_message message;
- const u8 *payload = &message.message[0];
+ u8 *message = &data->msg_buf[0];
+ const u8 *payload = &data->msg_buf[1];
struct device *dev = &data->client->dev;
u8 reportid;
bool update_input = false;
u32 crc;
do {
- if (mxt_read_message(data, &message)) {
+ if (mxt_read_message(data, message)) {
dev_err(dev, "Failed to read message\n");
return IRQ_NONE;
}
- reportid = message.reportid;
+ reportid = message[0];
if (reportid == data->T6_reportid) {
u8 status = payload[0];
@@ -777,17 +777,16 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data)
if (status & MXT_T6_STATUS_RESET)
complete(&data->reset_completion);
- } else if (mxt_is_T9_message(data, &message)) {
- int id = reportid - data->T9_reportid_min;
- mxt_input_touchevent(data, &message, id);
+ } else if (mxt_is_T9_message(data, message)) {
+ mxt_input_touchevent(data, message);
update_input = true;
- } else if (message.reportid == data->T19_reportid) {
- mxt_input_button(data, &message);
+ } else if (reportid == data->T19_reportid) {
+ mxt_input_button(data, message);
update_input = true;
} else {
- mxt_dump_message(dev, &message);
+ mxt_dump_message(data, message);
}
- } while (reportid != 0xff);
+ } while (reportid != MXT_RPTID_NOMSG);
if (data->enable_reporting && update_input)
mxt_input_sync(data->input_dev);
@@ -1236,16 +1235,15 @@ recheck:
static int mxt_make_highchg(struct mxt_data *data)
{
struct device *dev = &data->client->dev;
- struct mxt_message message;
int count = 10;
int error;
/* Read dummy message to make high CHG pin */
do {
- error = mxt_read_message(data, &message);
+ error = mxt_read_message(data, data->msg_buf);
if (error)
return error;
- } while (message.reportid != 0xff && --count);
+ } while (data->msg_buf[0] != MXT_RPTID_NOMSG && --count);
if (!count) {
dev_err(dev, "CHG pin isn't cleared\n");
@@ -1282,6 +1280,21 @@ static int mxt_get_info(struct mxt_data *data)
return 0;
}
+static void mxt_free_object_table(struct mxt_data *data)
+{
+ kfree(data->object_table);
+ data->object_table = NULL;
+ kfree(data->msg_buf);
+ data->msg_buf = NULL;
+ data->enable_reporting = false;
+ data->T5_msg_size = 0;
+ data->T6_reportid = 0;
+ data->T7_address = 0;
+ data->T9_reportid_min = 0;
+ data->T9_reportid_max = 0;
+ data->T19_reportid = 0;
+}
+
static int mxt_get_object_table(struct mxt_data *data)
{
struct i2c_client *client = data->client;
@@ -1323,6 +1336,9 @@ static int mxt_get_object_table(struct mxt_data *data)
min_id, max_id);
switch (object->type) {
+ case MXT_GEN_MESSAGE_T5:
+ /* CRC not enabled, therefore don't read last byte */
+ data->T5_msg_size = mxt_obj_size(object) - 1;
case MXT_GEN_COMMAND_T6:
data->T6_reportid = min_id;
data->T6_address = object->start_address;
@@ -1346,18 +1362,18 @@ static int mxt_get_object_table(struct mxt_data *data)
data->mem_size = end_address + 1;
}
+ data->msg_buf = kzalloc(data->T5_msg_size, GFP_KERNEL);
+ if (!data->msg_buf) {
+ dev_err(&client->dev, "Failed to allocate message buffer\n");
+ error = -ENOMEM;
+ goto free_object_table;
+ }
+
return 0;
-}
-static void mxt_free_object_table(struct mxt_data *data)
-{
- kfree(data->object_table);
- data->object_table = NULL;
- data->enable_reporting = false;
- data->T6_reportid = 0;
- data->T9_reportid_min = 0;
- data->T9_reportid_max = 0;
- data->T19_reportid = 0;
+free_object_table:
+ mxt_free_object_table(data);
+ return error;
}
static int mxt_read_t9_resolution(struct mxt_data *data)
@@ -1959,7 +1975,7 @@ err_unregister_device:
input_unregister_device(data->input_dev);
data->input_dev = NULL;
err_free_object:
- kfree(data->object_table);
+ mxt_free_object_table(data);
err_free_irq:
free_irq(data->irq, data);
err_free_pdata:
@@ -1977,7 +1993,7 @@ static int mxt_remove(struct i2c_client *client)
sysfs_remove_group(&client->dev.kobj, &mxt_attr_group);
free_irq(data->irq, data);
input_unregister_device(data->input_dev);
- kfree(data->object_table);
+ mxt_free_object_table(data);
if (!dev_get_platdata(&data->client->dev))
kfree(data->pdata);
kfree(data);
--
1.7.10.4
next prev parent reply other threads:[~2013-06-27 12:50 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-27 12:48 Atmel updates to atmel_mxt_ts touch controller driver - v6 Nick Dyer
2013-06-27 12:48 ` [PATCH 01/51] Input: atmel_mxt_ts - Remove unnecessary platform data Nick Dyer
2013-06-27 12:48 ` [PATCH 02/51] Input: atmel_mxt_ts - Improve T19 GPIO keys handling Nick Dyer
2013-07-18 17:11 ` rydberg
2013-06-27 12:48 ` [PATCH 03/51] Input: atmel_mxt_ts - Return IRQ_NONE when interrupt handler fails Nick Dyer
2013-06-27 12:48 ` [PATCH 04/51] Input: atmel_mxt_ts - define helper functions for size and instances Nick Dyer
2013-06-27 12:48 ` [PATCH 05/51] Input: atmel_mxt_ts - Select FW_LOADER for firmware code Nick Dyer
2013-06-27 12:48 ` [PATCH 06/51] Input: atmel_mxt_ts - wait for CHG assert in mxt_check_bootloader Nick Dyer
2013-06-27 12:48 ` [PATCH 07/51] Input: atmel_mxt_ts - wait for CHG after bootloader resets Nick Dyer
2013-06-27 12:48 ` [PATCH 08/51] Input: atmel_mxt_ts - Initialise IRQ before probing Nick Dyer
2013-07-18 17:13 ` rydberg
2013-06-27 12:48 ` [PATCH 09/51] Input: atmel_mxt_ts - Make wait-after-reset period compatible with all chips Nick Dyer
2013-06-27 12:48 ` [PATCH 10/51] Input: atmel_mxt_ts - Improve error reporting and debug Nick Dyer
2013-06-27 12:48 ` [PATCH 11/51] Input: atmel_mxt_ts - Implement CRC check for configuration data Nick Dyer
2013-09-18 16:59 ` [11/51] " Martin Fuzzey
2013-06-27 12:48 ` [PATCH 12/51] Input: atmel_mxt_ts - Download device config using firmware loader Nick Dyer
2013-09-18 17:08 ` [12/51] " Martin Fuzzey
2013-06-27 12:48 ` [PATCH 13/51] Input: atmel_mxt_ts - Calculate and check CRC in config file Nick Dyer
2013-06-27 12:48 ` [PATCH 14/51] Input: atmel_mxt_ts - Add additional bootloader addresses Nick Dyer
2013-06-27 12:48 ` [PATCH 15/51] Input: atmel_mxt_ts - Read and report bootloader version Nick Dyer
2013-06-27 12:48 ` [PATCH 16/51] Input: atmel_mxt_ts - Implement bootloader frame retries Nick Dyer
2013-06-27 12:48 ` [PATCH 17/51] Input: atmel_mxt_ts - Improve bootloader progress output Nick Dyer
2013-06-27 12:48 ` [PATCH 18/51] Input: atmel_mxt_ts - Add check for incorrect firmware file format Nick Dyer
2013-06-27 12:48 ` [PATCH 19/51] Input: atmel_mxt_ts - Read screen config from chip Nick Dyer
2013-06-27 12:48 ` [PATCH 20/51] Input: atmel_mxt_ts - Set default irqflags when there is no pdata Nick Dyer
2013-07-18 17:17 ` rydberg
2013-09-16 2:25 ` Dmitry Torokhov
2014-05-22 14:29 ` Nick Dyer
2014-05-23 16:37 ` Yufeng Shen
2014-05-24 12:41 ` Nick Dyer
2014-05-26 18:17 ` Yufeng Shen
2014-05-26 5:23 ` Dmitry Torokhov
2014-05-26 18:13 ` Yufeng Shen
2013-06-27 12:48 ` [PATCH 21/51] Input: atmel_mxt_ts - Use deep sleep mode when stopped Nick Dyer
2013-06-27 12:48 ` [PATCH 22/51] Input: atmel_mxt_ts - Add shutdown function Nick Dyer
2013-07-07 5:29 ` Dmitry Torokhov
2013-07-08 9:56 ` Nick Dyer
2013-07-10 16:55 ` Dmitry Torokhov
2013-07-10 18:32 ` Nick Dyer
2013-06-27 12:48 ` [PATCH 23/51] Input: atmel_mxt_ts - Rename pressure to amplitude to match spec Nick Dyer
2013-06-27 12:48 ` [PATCH 24/51] Input: atmel_mxt_ts - Rename touchscreen defines to include T9 Nick Dyer
2013-06-27 12:49 ` [PATCH 25/51] Input: atmel_mxt_ts - Handle multiple input reports in one message Nick Dyer
2013-07-18 17:18 ` rydberg
2013-06-27 12:49 ` [PATCH 26/51] Input: atmel_mxt_ts - Move input device init into separate function Nick Dyer
2013-07-07 5:34 ` Dmitry Torokhov
2013-07-08 9:41 ` Nick Dyer
2013-07-10 16:53 ` Dmitry Torokhov
2013-07-18 17:20 ` rydberg
2013-06-27 12:49 ` [PATCH 27/51] Input: atmel_mxt_ts - Handle APP_CRC_FAIL on startup Nick Dyer
2013-06-27 12:49 ` [PATCH 28/51] Input: atmel_mxt_ts - Handle bootloader previously unlocked Nick Dyer
2013-06-27 12:49 ` [PATCH 29/51] Input: atmel_mxt_ts - Add bootloader addresses for new chips Nick Dyer
2013-06-27 12:49 ` [PATCH 30/51] Input: atmel_mxt_ts - Recover from bootloader on probe Nick Dyer
2013-06-27 12:49 ` Nick Dyer [this message]
2013-06-27 12:49 ` [PATCH 32/51] Input: atmel_mxt_ts - Decode T6 status messages Nick Dyer
2013-06-27 12:49 ` [PATCH 33/51] Input: atmel_mxt_ts - Split message handler into separate functions Nick Dyer
2013-06-27 12:49 ` [PATCH 34/51] Input: atmel_mxt_ts - Implement T44 message handling Nick Dyer
2013-06-27 12:49 ` [PATCH 35/51] Input: atmel_mxt_ts - Output status from T48 Noise Supression Nick Dyer
2013-06-27 12:49 ` [PATCH 36/51] Input: atmel_mxt_ts - Output status from T42 Touch Suppression Nick Dyer
2013-06-27 12:49 ` [PATCH 37/51] Input: atmel_mxt_ts - Implement vector/orientation support Nick Dyer
2013-07-18 17:20 ` rydberg
2013-08-15 16:18 ` Nick Dyer
2013-06-27 12:49 ` [PATCH 38/51] Input: atmel_mxt_ts - implement I2C retries Nick Dyer
2013-06-27 12:49 ` [PATCH 39/51] Input: atmel_mxt_ts - Implement T63 Active Stylus support Nick Dyer
2013-07-18 17:21 ` rydberg
2013-06-27 12:49 ` [PATCH 40/51] Input: atmel_mxt_ts - Implement support for T15 Key Array Nick Dyer
2013-06-27 12:49 ` [PATCH 41/51] Input: atmel_mxt_ts - Remove unused defines Nick Dyer
2013-06-27 12:49 ` [PATCH 42/51] Input: atmel_mxt_ts - Verify Information Block checksum on probe Nick Dyer
2013-06-27 12:49 ` [PATCH 43/51] Input: atmel_mxt_ts - Use T18 RETRIGEN to handle IRQF_TRIGGER_LOW Nick Dyer
2013-06-27 12:49 ` [PATCH 44/51] Input: atmel_mxt_ts - Handle reports from T47 Stylus object Nick Dyer
2013-07-18 17:23 ` rydberg
2013-06-27 12:49 ` [PATCH 45/51] Input: atmel_mxt_ts - Release touch state during suspend Nick Dyer
2013-07-18 17:29 ` rydberg
2013-08-15 15:52 ` Nick Dyer
2013-06-27 12:49 ` [PATCH 46/51] Input: atmel_mxt_ts - Initialize power config before and after downloading cfg Nick Dyer
2013-06-27 12:49 ` [PATCH 47/51] Input: atmel_mxt_ts - Add regulator control support Nick Dyer
2013-06-27 12:49 ` [PATCH 48/51] Input: atmel_mxt_ts - Implement support for T100 touch object Nick Dyer
2013-06-27 12:49 ` [PATCH 49/51] Input: atmel_mxt_ts - Allow specification of firmware file name Nick Dyer
2013-06-27 12:49 ` [PATCH 50/51] Input: atmel_mxt_ts - Handle cfg filename via pdata/sysfs Nick Dyer
2013-06-27 12:49 ` [PATCH 51/51] Input: atmel_mxt_ts - Only use first T9 instance Nick Dyer
2013-06-27 15:17 ` Atmel updates to atmel_mxt_ts touch controller driver - v6 Nick Dyer
2013-07-18 19:47 ` rydberg
2013-08-15 15:55 ` Nick Dyer
2013-08-15 16:07 ` Dmitry Torokhov
2013-08-19 14:24 ` Nick Dyer
2013-09-10 13:58 ` Nick Dyer
[not found] ` <CAPDwgkOo7FYLujk16kJM=BqmXRKvZ2S_LOYURW0cXT5t=cmi6w@mail.gmail.com>
2014-01-15 10:44 ` Nick Dyer
[not found] ` <CAPDwgkOsP4K7r0-Mo-U52X9knRbGgbuD4dGptmj3x-LMTN75BA@mail.gmail.com>
2014-01-17 20:01 ` Nick Dyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372337366-9286-32-git-send-email-nick.dyer@itdev.co.uk \
--to=nick.dyer@itdev.co.uk \
--cc=Alan.Bowens@atmel.com \
--cc=bleung@chromium.org \
--cc=djkurtz@chromium.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jy0922.shim@samsung.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olofj@chromium.org \
--cc=pmeerw@pmeerw.net \
--cc=rydberg@euromail.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).