diff options
author | Daniel Kurtz <djkurtz@chromium.org> | 2014-05-19 02:01:12 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-05-19 02:27:23 -0400 |
commit | 1e0c0c5b9c9d79acea00cab402b511a268a8bc8e (patch) | |
tree | 254e333777f29c6ddca7c1d4d9e3a3a7ccaf51dd /drivers | |
parent | 8d4e1639066ff27e8c2c51b69b5ce2308da5c41c (diff) |
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: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Acked-by: Benson Leung <bleung@chromium.org>
Acked-by: Yufeng Shen <miletus@chromium.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 0cff8bb2ad75..40af02c26113 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
@@ -2,6 +2,8 @@ | |||
2 | * Atmel maXTouch Touchscreen driver | 2 | * Atmel maXTouch Touchscreen driver |
3 | * | 3 | * |
4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd |
5 | * Copyright (C) 2012 Google, Inc. | ||
6 | * | ||
5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | 7 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
6 | * | 8 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 9 | * This program is free software; you can redistribute it and/or modify it |
@@ -226,8 +228,8 @@ struct mxt_info { | |||
226 | struct mxt_object { | 228 | struct mxt_object { |
227 | u8 type; | 229 | u8 type; |
228 | u16 start_address; | 230 | u16 start_address; |
229 | u8 size; /* Size of each instance - 1 */ | 231 | u8 size_minus_one; |
230 | u8 instances; /* Number of instances - 1 */ | 232 | u8 instances_minus_one; |
231 | u8 num_report_ids; | 233 | u8 num_report_ids; |
232 | } __packed; | 234 | } __packed; |
233 | 235 | ||
@@ -256,6 +258,16 @@ struct mxt_data { | |||
256 | u8 T19_reportid; | 258 | u8 T19_reportid; |
257 | }; | 259 | }; |
258 | 260 | ||
261 | static size_t mxt_obj_size(const struct mxt_object *obj) | ||
262 | { | ||
263 | return obj->size_minus_one + 1; | ||
264 | } | ||
265 | |||
266 | static size_t mxt_obj_instances(const struct mxt_object *obj) | ||
267 | { | ||
268 | return obj->instances_minus_one + 1; | ||
269 | } | ||
270 | |||
259 | static bool mxt_object_readable(unsigned int type) | 271 | static bool mxt_object_readable(unsigned int type) |
260 | { | 272 | { |
261 | switch (type) { | 273 | switch (type) { |
@@ -498,7 +510,7 @@ static int mxt_write_object(struct mxt_data *data, | |||
498 | u16 reg; | 510 | u16 reg; |
499 | 511 | ||
500 | object = mxt_get_object(data, type); | 512 | object = mxt_get_object(data, type); |
501 | if (!object || offset >= object->size + 1) | 513 | if (!object || offset >= mxt_obj_size(object)) |
502 | return -EINVAL; | 514 | return -EINVAL; |
503 | 515 | ||
504 | reg = object->start_address; | 516 | reg = object->start_address; |
@@ -640,7 +652,7 @@ static int mxt_check_reg_init(struct mxt_data *data) | |||
640 | if (!mxt_object_writable(object->type)) | 652 | if (!mxt_object_writable(object->type)) |
641 | continue; | 653 | continue; |
642 | 654 | ||
643 | size = (object->size + 1) * (object->instances + 1); | 655 | size = mxt_obj_size(object) * mxt_obj_instances(object); |
644 | if (index + size > pdata->config_length) { | 656 | if (index + size > pdata->config_length) { |
645 | dev_err(dev, "Not enough config data!\n"); | 657 | dev_err(dev, "Not enough config data!\n"); |
646 | return -EINVAL; | 658 | return -EINVAL; |
@@ -717,7 +729,7 @@ static int mxt_get_object_table(struct mxt_data *data) | |||
717 | if (object->num_report_ids) { | 729 | if (object->num_report_ids) { |
718 | min_id = reportid; | 730 | min_id = reportid; |
719 | reportid += object->num_report_ids * | 731 | reportid += object->num_report_ids * |
720 | (object->instances + 1); | 732 | mxt_obj_instances(object); |
721 | max_id = reportid - 1; | 733 | max_id = reportid - 1; |
722 | } else { | 734 | } else { |
723 | min_id = 0; | 735 | min_id = 0; |
@@ -725,9 +737,10 @@ static int mxt_get_object_table(struct mxt_data *data) | |||
725 | } | 737 | } |
726 | 738 | ||
727 | dev_dbg(&data->client->dev, | 739 | dev_dbg(&data->client->dev, |
728 | "Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n", | 740 | "Type %2d Start %3d Size %3zd Instances %2zd ReportIDs %3u : %3u\n", |
729 | object->type, object->start_address, object->size + 1, | 741 | object->type, object->start_address, |
730 | object->instances + 1, min_id, max_id); | 742 | mxt_obj_size(object), mxt_obj_instances(object), |
743 | min_id, max_id); | ||
731 | 744 | ||
732 | switch (object->type) { | 745 | switch (object->type) { |
733 | case MXT_GEN_COMMAND_T6: | 746 | case MXT_GEN_COMMAND_T6: |
@@ -864,11 +877,11 @@ static ssize_t mxt_show_instance(char *buf, int count, | |||
864 | { | 877 | { |
865 | int i; | 878 | int i; |
866 | 879 | ||
867 | if (object->instances > 0) | 880 | if (mxt_obj_instances(object) > 1) |
868 | count += scnprintf(buf + count, PAGE_SIZE - count, | 881 | count += scnprintf(buf + count, PAGE_SIZE - count, |
869 | "Instance %u\n", instance); | 882 | "Instance %u\n", instance); |
870 | 883 | ||
871 | for (i = 0; i < object->size + 1; i++) | 884 | for (i = 0; i < mxt_obj_size(object); i++) |
872 | count += scnprintf(buf + count, PAGE_SIZE - count, | 885 | count += scnprintf(buf + count, PAGE_SIZE - count, |
873 | "\t[%2u]: %02x (%d)\n", i, val[i], val[i]); | 886 | "\t[%2u]: %02x (%d)\n", i, val[i], val[i]); |
874 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); | 887 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); |
@@ -901,8 +914,8 @@ static ssize_t mxt_object_show(struct device *dev, | |||
901 | count += scnprintf(buf + count, PAGE_SIZE - count, | 914 | count += scnprintf(buf + count, PAGE_SIZE - count, |
902 | "T%u:\n", object->type); | 915 | "T%u:\n", object->type); |
903 | 916 | ||
904 | for (j = 0; j < object->instances + 1; j++) { | 917 | for (j = 0; j < mxt_obj_instances(object); j++) { |
905 | u16 size = object->size + 1; | 918 | u16 size = mxt_obj_size(object); |
906 | u16 addr = object->start_address + j * size; | 919 | u16 addr = object->start_address + j * size; |
907 | 920 | ||
908 | error = __mxt_read_reg(data->client, addr, size, obuf); | 921 | error = __mxt_read_reg(data->client, addr, size, obuf); |