Input: edt-ft5x06 - show crc and header errors by sysfs
authorDario Binacchi <dario.binacchi@amarulasolutions.com>
Tue, 28 Jun 2022 17:58:59 +0000 (10:58 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 29 Jun 2022 05:00:18 +0000 (22:00 -0700)
M06 sends packets with header and crc for data verification. Now you can
check at runtime how many packets have been dropped.

Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Link: https://lore.kernel.org/r/20220621123937.1330389-7-dario.binacchi@amarulasolutions.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/edt-ft5x06.c

index 03e7e9522a0616696bb6094a8a3af4208ccd5e98..82beddb2876160f3f48a7b5a900abf0788865e7e 100644 (file)
@@ -134,6 +134,8 @@ struct edt_ft5x06_ts_data {
 
        struct edt_reg_addr reg_addr;
        enum edt_ver version;
+       unsigned int crc_errors;
+       unsigned int header_errors;
 };
 
 struct edt_i2c_chip_data {
@@ -182,6 +184,7 @@ static bool edt_ft5x06_ts_check_crc(struct edt_ft5x06_ts_data *tsdata,
                crc ^= buf[i];
 
        if (crc != buf[buflen-1]) {
+               tsdata->crc_errors++;
                dev_err_ratelimited(&tsdata->client->dev,
                                    "crc error: 0x%02x expected, got 0x%02x\n",
                                    crc, buf[buflen-1]);
@@ -239,6 +242,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
        if (tsdata->version == EDT_M06) {
                if (rdbuf[0] != 0xaa || rdbuf[1] != 0xaa ||
                        rdbuf[2] != datalen) {
+                       tsdata->header_errors++;
                        dev_err_ratelimited(dev,
                                        "Unexpected header: %02x%02x%02x!\n",
                                        rdbuf[0], rdbuf[1], rdbuf[2]);
@@ -553,6 +557,30 @@ static ssize_t fw_version_show(struct device *dev,
 
 static DEVICE_ATTR_RO(fw_version);
 
+/* m06 only */
+static ssize_t header_errors_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
+
+       return sysfs_emit(buf, "%d\n", tsdata->header_errors);
+}
+
+static DEVICE_ATTR_RO(header_errors);
+
+/* m06 only */
+static ssize_t crc_errors_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct edt_ft5x06_ts_data *tsdata = i2c_get_clientdata(client);
+
+       return sysfs_emit(buf, "%d\n", tsdata->crc_errors);
+}
+
+static DEVICE_ATTR_RO(crc_errors);
+
 static struct attribute *edt_ft5x06_attrs[] = {
        &edt_ft5x06_attr_gain.dattr.attr,
        &edt_ft5x06_attr_offset.dattr.attr,
@@ -562,6 +590,8 @@ static struct attribute *edt_ft5x06_attrs[] = {
        &edt_ft5x06_attr_report_rate.dattr.attr,
        &dev_attr_model.attr,
        &dev_attr_fw_version.attr,
+       &dev_attr_header_errors.attr,
+       &dev_attr_crc_errors.attr,
        NULL
 };