CHROMIUM: Input: atmel_mxt_ts - add sysfs entry to read info checksum
authorDaniel Kurtz <djkurtz@chromium.org>
Fri, 27 Apr 2012 13:44:58 +0000 (21:44 +0800)
committerGrant Grundler <grundler@google.com>
Thu, 24 May 2012 22:12:10 +0000 (15:12 -0700)
The device stores the Information Block Checksum in the 3 bytes
immediately following the Information Block.

Read these three bytes, cache the value, and add a sysfs entry so
userspace can read it.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
BUG=chrome-os-partner:9103
TEST=cat /sys/bus/i2c/drivers/atmel_mxt_ts/2-004b/info_csum

Change-Id: I27512c624bad15674bc7c50c15717913595affe4
Reviewed-on: https://gerrit.chromium.org/gerrit/20599
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Ready: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
drivers/input/touchscreen/atmel_mxt_ts.c

index aae8ea4..9e5b33d 100644 (file)
@@ -269,6 +269,7 @@ struct mxt_data {
        unsigned int max_x;
        unsigned int max_y;
 
+       u32 info_csum;
        u32 config_csum;
 
        /* Cached parameters from object table */
@@ -777,6 +778,7 @@ static int mxt_get_object_table(struct mxt_data *data)
        int i;
        u8 reportid;
        u8 buf[data->info.object_num][MXT_OBJECT_SIZE];
+       u8 csum[3];
 
        data->object_table = kcalloc(data->info.object_num,
                                     sizeof(struct mxt_object), GFP_KERNEL);
@@ -789,7 +791,19 @@ static int mxt_get_object_table(struct mxt_data *data)
        if (error)
                return error;
 
-       /* Vaild Report IDs start counting from 1. */
+       /*
+        * Read Information Block checksum from 3 bytes immediately following
+        * info block
+        */
+       error = mxt_read_reg(client, MXT_OBJECT_START + sizeof(buf),
+                            sizeof(csum), csum);
+       if (error)
+               return error;
+
+       data->info_csum = csum[0] | (csum[1] << 8) | (csum[2] << 16);
+       dev_info(dev, "Information Block Checksum = %06x\n", data->info_csum);
+
+       /* Valid Report IDs start counting from 1 */
        reportid = 1;
        for (i = 0; i < data->info.object_num; i++) {
                struct mxt_object *object = &data->object_table[i];
@@ -993,6 +1007,13 @@ static ssize_t mxt_hw_version_show(struct device *dev,
                         info->family_id, info->variant_id);
 }
 
+static ssize_t mxt_info_csum_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct mxt_data *data = dev_get_drvdata(dev);
+       return scnprintf(buf, PAGE_SIZE, "%06x\n", data->info_csum);
+}
+
 static ssize_t mxt_object_show(struct device *dev,
                               struct device_attribute *attr, char *buf)
 {
@@ -1106,6 +1127,7 @@ static DEVICE_ATTR(calibrate, S_IWUSR, NULL, mxt_calibrate_store);
 static DEVICE_ATTR(config_csum, S_IRUGO, mxt_config_csum_show, NULL);
 static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
 static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
+static DEVICE_ATTR(info_csum, S_IRUGO, mxt_info_csum_show, NULL);
 static DEVICE_ATTR(object, S_IRUGO | S_IWUSR, mxt_object_show,
                   mxt_object_store);
 static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
@@ -1116,6 +1138,7 @@ static struct attribute *mxt_attrs[] = {
        &dev_attr_config_csum.attr,
        &dev_attr_fw_version.attr,
        &dev_attr_hw_version.attr,
+       &dev_attr_info_csum.attr,
        &dev_attr_object.attr,
        &dev_attr_update_fw.attr,
        NULL