Commit 1e0c0c5b authored by Daniel Kurtz's avatar Daniel Kurtz Committed by Dmitry Torokhov

Input: atmel_mxt_ts - define helper functions for size and instances

These two object table entry fields are reported 1 less than their value.
When used, however, we always want the actual size and instances.

To keep the object size and instances 1-byte fields, and thus preserve
the object-table struct's 6-byte packed alignment, add some convenient
accessor functions that do the +1 every time these fields are accessed.
Signed-off-by: default avatarDaniel Kurtz <djkurtz@chromium.org>
Signed-off-by: default avatarNick Dyer <nick.dyer@itdev.co.uk>
Acked-by: default avatarBenson Leung <bleung@chromium.org>
Acked-by: default avatarYufeng Shen <miletus@chromium.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 8d4e1639
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
* Atmel maXTouch Touchscreen driver * Atmel maXTouch Touchscreen driver
* *
* Copyright (C) 2010 Samsung Electronics Co.Ltd * Copyright (C) 2010 Samsung Electronics Co.Ltd
* Copyright (C) 2012 Google, Inc.
*
* Author: Joonyoung Shim <jy0922.shim@samsung.com> * Author: Joonyoung Shim <jy0922.shim@samsung.com>
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
...@@ -226,8 +228,8 @@ struct mxt_info { ...@@ -226,8 +228,8 @@ struct mxt_info {
struct mxt_object { struct mxt_object {
u8 type; u8 type;
u16 start_address; u16 start_address;
u8 size; /* Size of each instance - 1 */ u8 size_minus_one;
u8 instances; /* Number of instances - 1 */ u8 instances_minus_one;
u8 num_report_ids; u8 num_report_ids;
} __packed; } __packed;
...@@ -256,6 +258,16 @@ struct mxt_data { ...@@ -256,6 +258,16 @@ struct mxt_data {
u8 T19_reportid; u8 T19_reportid;
}; };
static size_t mxt_obj_size(const struct mxt_object *obj)
{
return obj->size_minus_one + 1;
}
static size_t mxt_obj_instances(const struct mxt_object *obj)
{
return obj->instances_minus_one + 1;
}
static bool mxt_object_readable(unsigned int type) static bool mxt_object_readable(unsigned int type)
{ {
switch (type) { switch (type) {
...@@ -498,7 +510,7 @@ static int mxt_write_object(struct mxt_data *data, ...@@ -498,7 +510,7 @@ static int mxt_write_object(struct mxt_data *data,
u16 reg; u16 reg;
object = mxt_get_object(data, type); object = mxt_get_object(data, type);
if (!object || offset >= object->size + 1) if (!object || offset >= mxt_obj_size(object))
return -EINVAL; return -EINVAL;
reg = object->start_address; reg = object->start_address;
...@@ -640,7 +652,7 @@ static int mxt_check_reg_init(struct mxt_data *data) ...@@ -640,7 +652,7 @@ static int mxt_check_reg_init(struct mxt_data *data)
if (!mxt_object_writable(object->type)) if (!mxt_object_writable(object->type))
continue; continue;
size = (object->size + 1) * (object->instances + 1); size = mxt_obj_size(object) * mxt_obj_instances(object);
if (index + size > pdata->config_length) { if (index + size > pdata->config_length) {
dev_err(dev, "Not enough config data!\n"); dev_err(dev, "Not enough config data!\n");
return -EINVAL; return -EINVAL;
...@@ -717,7 +729,7 @@ static int mxt_get_object_table(struct mxt_data *data) ...@@ -717,7 +729,7 @@ static int mxt_get_object_table(struct mxt_data *data)
if (object->num_report_ids) { if (object->num_report_ids) {
min_id = reportid; min_id = reportid;
reportid += object->num_report_ids * reportid += object->num_report_ids *
(object->instances + 1); mxt_obj_instances(object);
max_id = reportid - 1; max_id = reportid - 1;
} else { } else {
min_id = 0; min_id = 0;
...@@ -725,9 +737,10 @@ static int mxt_get_object_table(struct mxt_data *data) ...@@ -725,9 +737,10 @@ static int mxt_get_object_table(struct mxt_data *data)
} }
dev_dbg(&data->client->dev, dev_dbg(&data->client->dev,
"Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n", "Type %2d Start %3d Size %3zd Instances %2zd ReportIDs %3u : %3u\n",
object->type, object->start_address, object->size + 1, object->type, object->start_address,
object->instances + 1, min_id, max_id); mxt_obj_size(object), mxt_obj_instances(object),
min_id, max_id);
switch (object->type) { switch (object->type) {
case MXT_GEN_COMMAND_T6: case MXT_GEN_COMMAND_T6:
...@@ -864,11 +877,11 @@ static ssize_t mxt_show_instance(char *buf, int count, ...@@ -864,11 +877,11 @@ static ssize_t mxt_show_instance(char *buf, int count,
{ {
int i; int i;
if (object->instances > 0) if (mxt_obj_instances(object) > 1)
count += scnprintf(buf + count, PAGE_SIZE - count, count += scnprintf(buf + count, PAGE_SIZE - count,
"Instance %u\n", instance); "Instance %u\n", instance);
for (i = 0; i < object->size + 1; i++) for (i = 0; i < mxt_obj_size(object); i++)
count += scnprintf(buf + count, PAGE_SIZE - count, count += scnprintf(buf + count, PAGE_SIZE - count,
"\t[%2u]: %02x (%d)\n", i, val[i], val[i]); "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
...@@ -901,8 +914,8 @@ static ssize_t mxt_object_show(struct device *dev, ...@@ -901,8 +914,8 @@ static ssize_t mxt_object_show(struct device *dev,
count += scnprintf(buf + count, PAGE_SIZE - count, count += scnprintf(buf + count, PAGE_SIZE - count,
"T%u:\n", object->type); "T%u:\n", object->type);
for (j = 0; j < object->instances + 1; j++) { for (j = 0; j < mxt_obj_instances(object); j++) {
u16 size = object->size + 1; u16 size = mxt_obj_size(object);
u16 addr = object->start_address + j * size; u16 addr = object->start_address + j * size;
error = __mxt_read_reg(data->client, addr, size, obuf); error = __mxt_read_reg(data->client, addr, size, obuf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment