From: Nick Dyer <nick.dyer@itdev.co.uk>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Daniel Kurtz <djkurtz@chromium.org>,
Henrik Rydberg <rydberg@euromail.se>,
Joonyoung Shim <jy0922.shim@samsung.com>,
Alan.Bowens@atmel.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org, pmeerw@pmeerw.net,
bleung@chromium.org, olofj@chromium.org
Cc: Nick Dyer <nick.dyer@itdev.co.uk>
Subject: [PATCH 02/40] Input: atmel_mxt_ts - add macros for object instances and size
Date: Fri, 22 Feb 2013 17:57:49 +0000 [thread overview]
Message-ID: <1361555907-19840-3-git-send-email-nick.dyer@itdev.co.uk> (raw)
In-Reply-To: <1361555907-19840-1-git-send-email-nick.dyer@itdev.co.uk>
The raw Atmel Object Based Protocol stores the instances and size minus one as
an efficiency measure. This can easily lead to bugs. Rename the variables to
make it clear what they are and implement macros for the conversion.
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index b4bf946..1de1d24 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -216,6 +216,9 @@
/* Touchscreen absolute values */
#define MXT_MAX_AREA 0xff
+#define OBP_INSTANCES(o) ((u16)((o)->instances_minus_one) + 1)
+#define OBP_SIZE(o) ((u16)((o)->size_minus_one) + 1)
+
struct mxt_info {
u8 family_id;
u8 variant_id;
@@ -229,8 +232,8 @@ struct mxt_info {
struct mxt_object {
u8 type;
u16 start_address;
- u8 size; /* Size of each instance - 1 */
- u8 instances; /* Number of instances - 1 */
+ u8 size_minus_one;
+ u8 instances_minus_one;
u8 num_report_ids;
} __packed;
@@ -500,7 +503,7 @@ static int mxt_write_object(struct mxt_data *data,
u16 reg;
object = mxt_get_object(data, type);
- if (!object || offset >= object->size + 1)
+ if (!object || offset >= OBP_SIZE(object))
return -EINVAL;
reg = object->start_address;
@@ -684,7 +687,7 @@ static int mxt_check_reg_init(struct mxt_data *data)
if (!mxt_object_writable(object->type))
continue;
- size = (object->size + 1) * (object->instances + 1);
+ size = OBP_SIZE(object) * OBP_INSTANCES(object);
if (index + size > pdata->config_length) {
dev_err(dev, "Not enough config data!\n");
return -EINVAL;
@@ -809,7 +812,7 @@ static int mxt_get_object_table(struct mxt_data *data)
if (object->num_report_ids) {
min_id = reportid;
reportid += object->num_report_ids *
- (object->instances + 1);
+ OBP_INSTANCES(object);
max_id = reportid - 1;
} else {
min_id = 0;
@@ -818,8 +821,8 @@ static int mxt_get_object_table(struct mxt_data *data)
dev_dbg(&data->client->dev,
"Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n",
- object->type, object->start_address, object->size + 1,
- object->instances + 1, min_id, max_id);
+ object->type, object->start_address, OBP_SIZE(object),
+ OBP_INSTANCES(object), min_id, max_id);
switch (object->type) {
case MXT_GEN_COMMAND_T6:
@@ -949,11 +952,11 @@ static ssize_t mxt_show_instance(char *buf, int count,
{
int i;
- if (object->instances > 0)
+ if (OBP_INSTANCES(object) > 1)
count += scnprintf(buf + count, PAGE_SIZE - count,
"Instance %u\n", instance);
- for (i = 0; i < object->size + 1; i++)
+ for (i = 0; i < OBP_SIZE(object); i++)
count += scnprintf(buf + count, PAGE_SIZE - count,
"\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
@@ -986,8 +989,8 @@ static ssize_t mxt_object_show(struct device *dev,
count += scnprintf(buf + count, PAGE_SIZE - count,
"T%u:\n", object->type);
- for (j = 0; j < object->instances + 1; j++) {
- u16 size = object->size + 1;
+ for (j = 0; j < OBP_INSTANCES(object); j++) {
+ u16 size = OBP_SIZE(object);
u16 addr = object->start_address + j * size;
error = __mxt_read_reg(data->client, addr, size, obuf);
--
1.7.10.4
next prev parent reply other threads:[~2013-02-22 17:57 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 17:57 Atmel updates to atmel_mxt_ts touch controller driver Nick Dyer
2013-02-22 17:57 ` [PATCH 01/40] Input: atmel_mxt_ts - Make wait-after-reset period compatible with all chips Nick Dyer
2013-02-22 23:20 ` Benson Leung
2013-02-22 17:57 ` Nick Dyer [this message]
2013-02-22 17:57 ` [PATCH 03/40] Input: atmel_mxt_ts - Add memory access interface via sysfs Nick Dyer
2013-02-22 17:57 ` [PATCH 04/40] Input: atmel_mxt_ts - Implement debug output for messages Nick Dyer
2013-02-22 17:57 ` [PATCH 05/40] Input: atmel_mxt_ts - Improve error reporting and debug Nick Dyer
2013-02-22 17:57 ` [PATCH 06/40] Input: atmel_mxt_ts - Remove unnecessary platform data Nick Dyer
2013-02-22 17:57 ` [PATCH 07/40] Input: atmel_mxt_ts - Implement CRC check for configuration data Nick Dyer
2013-02-22 17:57 ` [PATCH 08/40] Input: atmel_mxt_ts - Download device config using firmware loader Nick Dyer
2013-02-22 17:57 ` [PATCH 09/40] Input: atmel_mxt_ts - Calculate and check CRC in config file Nick Dyer
2013-02-22 17:57 ` [PATCH 10/40] Input: atmel_mxt_ts - Improve bootloader support Nick Dyer
2013-02-22 17:57 ` [PATCH 11/40] Input: atmel_mxt_ts - Bootloader addresses for mXT1664/mXT1188S Nick Dyer
2013-02-22 19:06 ` Benson Leung
2013-02-22 19:51 ` Nick Dyer
2013-02-22 23:09 ` Benson Leung
2013-02-22 17:57 ` [PATCH 12/40] Input: atmel_mxt_ts - Read screen config from chip Nick Dyer
2013-02-22 17:58 ` [PATCH 13/40] Input: atmel_mxt_ts - Use deep sleep mode when stopped Nick Dyer
2013-02-22 17:58 ` [PATCH 14/40] Input: atmel_mxt_ts - add shutdown function Nick Dyer
2013-02-22 17:58 ` [PATCH 15/40] Input: atmel_mxt_ts - Improve touch reporting for T9 Nick Dyer
2013-02-22 17:58 ` [PATCH 16/40] Input: atmel_mxt_ts - Move input device configuration into separate function Nick Dyer
2013-02-22 17:58 ` [PATCH 17/40] Input: atmel_mxt_ts - Allow input device name to be configured from platform data Nick Dyer
2013-02-22 17:58 ` [PATCH 18/40] Input: atmel_mxt_ts - Add support for dynamic message size Nick Dyer
2013-02-22 17:58 ` [PATCH 19/40] Input: atmel_mxt_ts - Decode T6 status messages Nick Dyer
2013-02-22 17:58 ` [PATCH 20/40] Input: atmel_mxt_ts - Split interrupt handler into separate functions Nick Dyer
2013-02-22 17:58 ` [PATCH 21/40] Input: atmel_mxt_ts - Implement T44 message handling Nick Dyer
2013-02-22 17:58 ` [PATCH 22/40] Input: atmel_mxt_ts - Output status from T48 Noise Supression Nick Dyer
2013-02-22 17:58 ` [PATCH 23/40] Input: atmel_mxt_ts - Output status from T42 Touch Suppression Nick Dyer
2013-02-22 17:58 ` [PATCH 24/40] Input: atmel_mxt_ts - Implement vector/orientation support Nick Dyer
2013-02-22 17:58 ` [PATCH 25/40] Input: atmel_mxt_ts - implement I2C retries Nick Dyer
2013-02-22 17:58 ` [PATCH 26/40] Input: atmel_mxt_ts - Implement T63 Active Stylus support Nick Dyer
2013-02-22 17:58 ` [PATCH 27/40] Input: atmel_mxt_ts - Add check for incorrect firmware file format Nick Dyer
2013-02-22 17:58 ` [PATCH 28/40] Input: atmel_mxt_ts - Add CHG line handling in bootloader code Nick Dyer
2013-02-22 22:35 ` Benson Leung
2013-02-23 1:45 ` Benson Leung
2013-02-22 17:58 ` [PATCH 29/40] Input: atmel_mxt_ts - Use wait_for_chg in soft_reset Nick Dyer
2013-02-22 17:58 ` [PATCH 30/40] Input: atmel_mxt_ts - recover from bootloader on probe Nick Dyer
2013-02-22 17:58 ` [PATCH 31/40] Input: atmel_mxt_ts - Implement T15 Key Array support Nick Dyer
2013-02-22 17:58 ` [PATCH 32/40] Input: atmel_mxt_ts - remove unused defines Nick Dyer
2013-02-22 17:58 ` [PATCH 33/40] Input: atmel_mxt_ts - Verify Information Block checksum on probe Nick Dyer
2013-02-22 17:58 ` [PATCH 34/40] Input: atmel_mxt_ts - Remove mxt_make_highchg Nick Dyer
2013-02-22 17:58 ` [PATCH 35/40] Input: atmel_mxt_ts - Improve messages relating to info block read Nick Dyer
2013-02-22 17:58 ` [PATCH 36/40] Input: atmel_mxt_ts - Handle reports from T47 Stylus object Nick Dyer
2013-02-22 17:58 ` [PATCH 37/40] Input: atmel_mxt_ts - Release touch state during suspend Nick Dyer
2013-02-22 17:58 ` [PATCH 38/40] Input: atmel_mxt_ts - Initialize power config before and after downloading cfg Nick Dyer
2013-02-22 17:58 ` [PATCH 39/40] Input: atmel_mxt_ts - Add regulator control support Nick Dyer
2013-02-22 17:58 ` [PATCH 40/40] Input: atmel_mxt_ts - Implement support for T100 touch object Nick Dyer
2013-02-22 20:19 ` Atmel updates to atmel_mxt_ts touch controller driver Peter Meerwald
2013-02-22 20:53 ` Nick Dyer
2013-03-29 16:48 ` Henrik Rydberg
2013-04-08 14:36 ` 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=1361555907-19840-3-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).