Input: edt-ft5x06 – add support for Evervision FT5726 [Linux 5.1]

Input: edt-ft5x06 – add support for Evervision FT5726 [Linux 5.1]

This Linux kernel change "Input: edt-ft5x06 – add support for Evervision FT5726" is included in the Linux 5.1 release. This change is authored by Marco Felsch <m.felsch [at] pengutronix.de> on Sun Jan 13 23:08:32 2019 -0800. The commit for this change in Linux stable tree is a2f39da (patch).

Input: edt-ft5x06 - add support for Evervision FT5726

Evervision displays are using different Focaltech touchscreen
controllers. This commit adds the initial support for the ones using the
FT5726 controller. Receiving the touch data is the same as for the
GENERIC_FT but the x and y cooridnates are swapped. The main differences
are the register addresses where the GAIN and THRESHOLD parameters are
stored.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

There are 48 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 .../bindings/input/touchscreen/edt-ft5x06.txt      |  4 +-
 drivers/input/touchscreen/edt-ft5x06.c             | 44 ++++++++++++++++++++--
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.txt b/Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.txt
index da2dc5d..179e434 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.txt
@@ -1,11 +1,12 @@
 FocalTech EDT-FT5x06 Polytouch driver
 =====================================

-There are 3 variants of the chip for various touch panel sizes
+There are 5 variants of the chip for various touch panel sizes
 FT5206GE1  2.8" .. 3.8"
 FT5306DE4  4.3" .. 7"
 FT5406EE8  7"   .. 8.9"
 FT5506EEG  7"   .. 8.9"
+FT5726NEI  5.7” .. 11.6"

 The software interface is identical for all those chips, so that
 currently there is no need for the driver to distinguish between the
@@ -19,6 +20,7 @@ Required properties:
            or:  "edt,edt-ft5306"
            or:  "edt,edt-ft5406"
            or:  "edt,edt-ft5506"
+           or:  "evervision,ev-ft5726"
            or:  "focaltech,ft6236"

  - reg:         I2C slave address of the chip (0x38)
diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 1e18ca0..1cd5b80 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -31,6 +31,7 @@
 #include <linux/interrupt.h>
 #include <linux/input.h>
 #include <linux/i2c.h>
+#include <linux/kernel.h>
 #include <linux/uaccess.h>
 #include <linux/delay.h>
 #include <linux/debugfs.h>
@@ -53,6 +54,9 @@
 #define M09_REGISTER_NUM_X     0x94
 #define M09_REGISTER_NUM_Y     0x95

+#define EV_REGISTER_THRESHOLD      0x40
+#define EV_REGISTER_GAIN       0x41
+
 #define NO_REGISTER            0xff

 #define WORK_REGISTER_OPMODE       0x3c
@@ -73,6 +77,7 @@ enum edt_ver {
    EDT_M06,
    EDT_M09,
    EDT_M12,
+   EV_FT,
    GENERIC_FT,
 };

@@ -190,6 +195,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)

    case EDT_M09:
    case EDT_M12:
+   case EV_FT:
    case GENERIC_FT:
        cmd = 0x0;
        offset = 3;
@@ -242,6 +248,10 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)

        x = ((buf[0] << 8) | buf[1]) & 0x0fff;
        y = ((buf[2] << 8) | buf[3]) & 0x0fff;
+       /* The FT5x26 send the y coordinate first */
+       if (tsdata->version == EV_FT)
+           swap(x, y);
+
        id = (buf[2] >> 4) & 0x0f;
        down = type != TOUCH_EVENT_UP;

@@ -275,8 +285,10 @@ static int edt_ft5x06_register_write(struct edt_ft5x06_ts_data *tsdata,
        wrbuf[3] = wrbuf[0] ^ wrbuf[1] ^ wrbuf[2];
        return edt_ft5x06_ts_readwrite(tsdata->client, 4,
                    wrbuf, 0, NULL);
+   /* fallthrough */
    case EDT_M09:
    case EDT_M12:
+   case EV_FT:
    case GENERIC_FT:
        wrbuf[0] = addr;
        wrbuf[1] = value;
@@ -315,8 +327,10 @@ static int edt_ft5x06_register_read(struct edt_ft5x06_ts_data *tsdata,
        }
        break;

+   /* fallthrough */
    case EDT_M09:
    case EDT_M12:
+   case EV_FT:
    case GENERIC_FT:
        wrbuf[0] = addr;
        error = edt_ft5x06_ts_readwrite(tsdata->client, 1,
@@ -605,8 +619,9 @@ static int edt_ft5x06_work_mode(struct edt_ft5x06_ts_data *tsdata)
                  tsdata->threshold);
    edt_ft5x06_register_write(tsdata, reg_addr->reg_gain,
                  tsdata->gain);
-   edt_ft5x06_register_write(tsdata, reg_addr->reg_offset,
-                 tsdata->offset);
+   if (reg_addr->reg_offset != NO_REGISTER)
+       edt_ft5x06_register_write(tsdata, reg_addr->reg_offset,
+                     tsdata->offset);
    if (reg_addr->reg_report_rate != NO_REGISTER)
        edt_ft5x06_register_write(tsdata, reg_addr->reg_report_rate,
                  tsdata->report_rate);
@@ -867,6 +882,16 @@ static int edt_ft5x06_ts_identify(struct i2c_client *client,
        case 0x5a:   /* Solomon Goldentek Display */
            snprintf(model_name, EDT_NAME_LEN, "GKTW50SCED1R0");
            break;
+       case 0x59:  /* Evervision Display with FT5xx6 TS */
+           tsdata->version = EV_FT;
+           error = edt_ft5x06_ts_readwrite(client, 1, "\x53",
+                           1, rdbuf);
+           if (error)
+               return error;
+           strlcpy(fw_version, rdbuf, 1);
+           snprintf(model_name, EDT_NAME_LEN,
+                "EVERVISION-FT5726NEi");
+           break;
        default:
            snprintf(model_name, EDT_NAME_LEN,
                 "generic ft5x06 (%02x)",
@@ -912,7 +937,9 @@ static void edt_ft5x06_ts_get_defaults(struct device *dev,
    tsdata->threshold = edt_ft5x06_register_read(tsdata,
                             reg_addr->reg_threshold);
    tsdata->gain = edt_ft5x06_register_read(tsdata, reg_addr->reg_gain);
-   tsdata->offset = edt_ft5x06_register_read(tsdata, reg_addr->reg_offset);
+   if (reg_addr->reg_offset != NO_REGISTER)
+       tsdata->offset =
+           edt_ft5x06_register_read(tsdata, reg_addr->reg_offset);
    if (reg_addr->reg_report_rate != NO_REGISTER)
        tsdata->report_rate = edt_ft5x06_register_read(tsdata,
                        reg_addr->reg_report_rate);
@@ -954,6 +981,15 @@ static void edt_ft5x06_ts_get_defaults(struct device *dev,
        reg_addr->reg_num_y = M09_REGISTER_NUM_Y;
        break;

+   case EV_FT:
+       reg_addr->reg_threshold = EV_REGISTER_THRESHOLD;
+       reg_addr->reg_gain = EV_REGISTER_GAIN;
+       reg_addr->reg_offset = NO_REGISTER;
+       reg_addr->reg_num_x = NO_REGISTER;
+       reg_addr->reg_num_y = NO_REGISTER;
+       reg_addr->reg_report_rate = NO_REGISTER;
+       break;
+
    case GENERIC_FT:
        /* this is a guesswork */
        reg_addr->reg_threshold = M09_REGISTER_THRESHOLD;
@@ -1155,6 +1191,7 @@ static SIMPLE_DEV_PM_OPS(edt_ft5x06_ts_pm_ops,
 static const struct i2c_device_id edt_ft5x06_ts_id[] = {
    { .name = "edt-ft5x06", .driver_data = (long)&edt_ft5x06_data },
    { .name = "edt-ft5506", .driver_data = (long)&edt_ft5506_data },
+   { .name = "ev-ft5726", .driver_data = (long)&edt_ft5506_data },
    /* Note no edt- prefix for compatibility with the ft6236.c driver */
    { .name = "ft6236", .driver_data = (long)&edt_ft6236_data },
    { /* sentinel */ }
@@ -1167,6 +1204,7 @@ static SIMPLE_DEV_PM_OPS(edt_ft5x06_ts_pm_ops,
    { .compatible = "edt,edt-ft5306", .data = &edt_ft5x06_data },
    { .compatible = "edt,edt-ft5406", .data = &edt_ft5x06_data },
    { .compatible = "edt,edt-ft5506", .data = &edt_ft5506_data },
+   { .compatible = "evervision,ev-ft5726", .data = &edt_ft5506_data },
    /* Note focaltech vendor prefix for compatibility with ft6236.c */
    { .compatible = "focaltech,ft6236", .data = &edt_ft6236_data },
    { /* sentinel */ }

Leave a Reply

Your email address will not be published. Required fields are marked *