From: "Henrik Rydberg" <rydberg@euromail.se>
To: Daniel Kurtz <djkurtz@chromium.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Joonyoung Shim <jy0922.shim@samsung.com>,
Nick Dyer <nick.dyer@itdev.co.uk>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Benson Leung <bleung@chromium.org>,
Yufeng Shen <miletus@chromium.org>
Subject: Re: [PATCH 11/16 v2] Input: atmel_mxt_ts - refactor reading object table
Date: Fri, 13 Apr 2012 11:11:47 +0200 [thread overview]
Message-ID: <20120413091147.GA3923@polaris.bitmath.org> (raw)
In-Reply-To: <1333039766-8617-12-git-send-email-djkurtz@chromium.org>
Hi Daniel,
> Instead of reading each object separately, fetch the whole table in one
> large i2c transaction. A 6 byte table object requires 10 bytes to read,
> so doing this dramatically reduces overhead.
>
> Also, as a cleanup, move object_table allocation (and post-fw-update
> reallocation) into mxt_get_object_table().
>
> Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
> ---
> drivers/input/touchscreen/atmel_mxt_ts.c | 66 +++++++++++++++---------------
> 1 files changed, 33 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
> index 9d88faf..0d0dab6 100644
> --- a/drivers/input/touchscreen/atmel_mxt_ts.c
> +++ b/drivers/input/touchscreen/atmel_mxt_ts.c
> @@ -437,14 +437,7 @@ static int mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
> return 0;
> }
>
> -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)
> +static struct mxt_object *mxt_get_object(struct mxt_data *data, u8 type)
> {
> struct mxt_object *object;
> int i;
> @@ -733,25 +726,41 @@ static void mxt_handle_pdata(struct mxt_data *data)
>
> static int mxt_get_object_table(struct mxt_data *data)
> {
> + struct i2c_client *client = data->client;
> + struct device *dev = &client->dev;
> int error;
> int i;
> - u16 reg;
> u8 reportid = 0;
> - u8 buf[MXT_OBJECT_SIZE];
> + u8 *buf;
> + size_t buf_size;
>
> - for (i = 0; i < data->info.object_num; i++) {
> - struct mxt_object *object = data->object_table + i;
> + /* Free old object table, if there was one. */
> + kfree(data->object_table);
> + data->object_table = kcalloc(data->info.object_num,
> + sizeof(struct mxt_object), GFP_KERNEL);
> + if (!data->object_table) {
> + dev_err(dev, "Failed to allocate object table\n");
> + return -ENOMEM;
> + }
>
> - reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i;
> - error = mxt_read_object_table(data->client, reg, buf);
> - if (error)
> - return error;
> + buf_size = MXT_OBJECT_SIZE * data->info.object_num;
> + buf = kmalloc(buf_size, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
>
> - object->type = buf[0];
> - object->start_address = (buf[2] << 8) | buf[1];
> - object->size = buf[3] + 1;
> - object->instances = buf[4] + 1;
> - object->num_report_ids = buf[5];
> + error = mxt_read_reg(client, MXT_OBJECT_START, buf_size, buf);
> + if (error)
> + goto done;
> +
> + for (i = 0; i < data->info.object_num; i++) {
> + struct mxt_object *object = &data->object_table[i];
> + u8 *obj_buf = &buf[i * MXT_OBJECT_SIZE];
> +
> + object->type = obj_buf[0];
> + object->start_address = (obj_buf[2] << 8) | obj_buf[1];
> + object->size = obj_buf[3] + 1;
> + object->instances = obj_buf[4] + 1;
> + object->num_report_ids = obj_buf[5];
Putting this conversion in a function would be nice, it would also
make it clear that the inverse, used for writing, is currently
missing. Alternatively, how about making the object struct actually
match the read data? To top it off, one could introduce a collection,
prepending the buffer size, making the write operation trivial.
struct mxt_raw_object {
u8 type;
__le16 start_address_le;
u8 size_minus_one;
u8 instances_minus_one;
u8 num_report_ids;
};
struct mxt_raw_object_collection {
__le16 total_bytes_le;
struct mxt_raw_object instance[MAX_NUM_OBJECTS];
};
>
> if (object->num_report_ids) {
> reportid += object->num_report_ids * object->instances;
> @@ -759,7 +768,9 @@ static int mxt_get_object_table(struct mxt_data *data)
> }
> }
>
> - return 0;
> +done:
> + kfree(buf);
> + return error;
> }
>
> static int mxt_initialize(struct mxt_data *data)
> @@ -774,14 +785,6 @@ static int mxt_initialize(struct mxt_data *data)
> if (error)
> return error;
>
> - data->object_table = kcalloc(info->object_num,
> - sizeof(struct mxt_object),
> - GFP_KERNEL);
> - if (!data->object_table) {
> - dev_err(&client->dev, "Failed to allocate memory\n");
> - return -ENOMEM;
> - }
> -
> /* Get object table information */
> error = mxt_get_object_table(data);
> if (error)
> @@ -971,9 +974,6 @@ static ssize_t mxt_update_fw_store(struct device *dev,
> /* Wait for reset */
> msleep(MXT_FWRESET_TIME);
>
> - kfree(data->object_table);
> - data->object_table = NULL;
> -
> mxt_initialize(data);
> }
>
> --
> 1.7.7.3
>
Thanks,
Henrik
next prev parent reply other threads:[~2012-04-13 9:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-29 16:49 [PATCH 00/16 v2] cleanup atmel_mxt_ts Daniel Kurtz
2012-03-29 16:49 ` [PATCH 01/16 v2] Input: atmel_mxt_ts - use CONFIG_PM_SLEEP Daniel Kurtz
2012-03-29 16:49 ` [PATCH 02/16 v2] Input: atmel_mxt_ts - only allow root to update firmware Daniel Kurtz
2012-03-29 16:49 ` [PATCH 03/16 v2] Input: atmel_mxt_ts - refactor mxt_read/write_reg to take a length Daniel Kurtz
2012-04-11 9:05 ` Henrik Rydberg
2012-04-14 4:12 ` Daniel Kurtz
2012-03-29 16:49 ` [PATCH 04/16 v2] Input: atmel_mxt_ts - store actual size and instance Daniel Kurtz
2012-03-29 16:49 ` [PATCH 05/16 v2] Input: atmel_mxt_ts - verify object size in mxt_write_object Daniel Kurtz
2012-03-29 16:49 ` [PATCH 06/16 v2] Input: atmel_mxt_ts - do not read extra (checksum) byte Daniel Kurtz
2012-03-29 16:49 ` [PATCH 07/16 v2] Input: atmel_mxt_ts - dump each message on just 1 line Daniel Kurtz
2012-03-29 16:49 ` [PATCH 08/16 v2] Input: atmel_mxt_ts - refactor mxt_object_show Daniel Kurtz
2012-04-11 16:25 ` Henrik Rydberg
2012-03-29 16:49 ` [PATCH 09/16 v2] Input: atmel_mxt_ts - optimize writing of object table entries Daniel Kurtz
2012-04-13 9:13 ` Henrik Rydberg
2012-03-29 16:49 ` [PATCH 10/16 v2] Input: atmel_mxt_ts - refactor get info Daniel Kurtz
2012-03-29 16:49 ` [PATCH 11/16 v2] Input: atmel_mxt_ts - refactor reading object table Daniel Kurtz
2012-04-13 9:11 ` Henrik Rydberg [this message]
2012-04-13 9:21 ` Daniel Kurtz
2012-04-13 9:34 ` Henrik Rydberg
2012-04-13 10:10 ` Daniel Kurtz
2012-04-13 11:09 ` Henrik Rydberg
2012-03-29 16:49 ` [PATCH 12/16 v2] Input: atmel_mxt_ts - simplify event reporting Daniel Kurtz
2012-03-29 16:49 ` [PATCH 13/16 v2] Input: atmel_mxt_ts - cache T9 reportid range when reading object table Daniel Kurtz
2012-03-29 16:49 ` [PATCH 14/16 v2] Input: atmel_mxt_ts - parse vector field of data packets Daniel Kurtz
2012-03-29 16:49 ` [PATCH 15/16 v2] Input: atmel_mxt_ts - send all MT-B slots in one input report Daniel Kurtz
2012-04-13 9:20 ` Henrik Rydberg
2012-03-29 16:49 ` [PATCH 16/16 v2] Input: atmel_mxt_ts - parse T6 reports Daniel Kurtz
2012-04-09 13:14 ` [PATCH 00/16 v2] cleanup atmel_mxt_ts Daniel Kurtz
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=20120413091147.GA3923@polaris.bitmath.org \
--to=rydberg@euromail.se \
--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=miletus@chromium.org \
--cc=nick.dyer@itdev.co.uk \
/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