summaryrefslogtreecommitdiff
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorShantanu Jain <shjain@codeaurora.org>2013-09-18 12:05:02 +0530
committerGerrit - the friendly Code Review server <code-review@localhost>2016-09-12 23:53:38 -0700
commit0ddb25d00e0800adc3457a0ed33403c25c2e0749 (patch)
tree71fd4d6d4657068e771233896ee10d83e6f78568 /drivers/input/touchscreen
parent90d5e14e3260c7230b0a3c2aad3f27c9d66b615f (diff)
input: touchscreen: Add dynamic detection support to Goodix driver
Add dynamic detection support to goodix driver, where the driver tries to read the chip id and make sure it is communicating with the right chip. gtp_read_version is modified to gtp_read_fw_version which reads the firmware version from the controller and will be used during fw update process. Change-Id: I2dc51b84f817413da6bf9b266e2fe7e0bb09c4bc Signed-off-by: Shantanu Jain <shjain@codeaurora.org> Signed-off-by: Sudhakar Manapati <smanap@codeaurora.org>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/gt9xx/gt9xx.c77
-rw-r--r--drivers/input/touchscreen/gt9xx/gt9xx.h40
2 files changed, 79 insertions, 38 deletions
diff --git a/drivers/input/touchscreen/gt9xx/gt9xx.c b/drivers/input/touchscreen/gt9xx/gt9xx.c
index e8f015b6367d..cd92389a1d5e 100644
--- a/drivers/input/touchscreen/gt9xx/gt9xx.c
+++ b/drivers/input/touchscreen/gt9xx/gt9xx.c
@@ -1050,39 +1050,73 @@ static int gtp_init_panel(struct goodix_ts_data *ts)
/*******************************************************
Function:
- Read chip version.
+ Read firmware version
Input:
client: i2c device
version: buffer to keep ic firmware version
Output:
read operation return.
- 2: succeed, otherwise: failed
+ 0: succeed, otherwise: failed
*******************************************************/
-int gtp_read_version(struct i2c_client *client, u16 *version)
+static int gtp_read_fw_version(struct i2c_client *client, u16 *version)
{
- int ret = -EIO;
- u8 buf[8] = { GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff };
-
- GTP_DEBUG_FUNC();
+ int ret = 0;
+ u8 buf[GTP_FW_VERSION_BUFFER_MAXSIZE] = {
+ GTP_REG_FW_VERSION >> 8, GTP_REG_FW_VERSION & 0xff };
ret = gtp_i2c_read(client, buf, sizeof(buf));
if (ret < 0) {
dev_err(&client->dev, "GTP read version failed.\n");
- return ret;
+ return -EIO;
}
if (version)
- *version = (buf[7] << 8) | buf[6];
+ *version = (buf[3] << 8) | buf[2];
+
+ return ret;
+}
+/*
+ * Function:
+ * Read and check chip id.
+ * Input:
+ * client: i2c device
+ * Output:
+ * read operation return.
+ * 0: succeed, otherwise: failed
+ */
+static int gtp_check_product_id(struct i2c_client *client)
+{
+ int ret = 0;
+ char product_id[GTP_PRODUCT_ID_MAXSIZE];
+ struct goodix_ts_data *ts = i2c_get_clientdata(client);
+ /* 04 bytes are used for the Product-id in the register space.*/
+ u8 buf[GTP_PRODUCT_ID_BUFFER_MAXSIZE] = {
+ GTP_REG_PRODUCT_ID >> 8, GTP_REG_PRODUCT_ID & 0xff };
+
+ ret = gtp_i2c_read(client, buf, sizeof(buf));
+ if (ret < 0) {
+ dev_err(&client->dev, "GTP read version failed.\n");
+ return -EIO;
+ }
if (buf[5] == 0x00) {
- dev_dbg(&client->dev, "IC Version: %c%c%c_%02x%02x\n", buf[2],
- buf[3], buf[4], buf[7], buf[6]);
+ /* copy (GTP_PRODUCT_ID_MAXSIZE - 1) from buffer. Ex: 915 */
+ strlcpy(product_id, &buf[2], GTP_PRODUCT_ID_MAXSIZE - 1);
} else {
if (buf[5] == 'S' || buf[5] == 's')
chip_gt9xxs = 1;
- dev_dbg(&client->dev, "IC Version: %c%c%c%c_%02x%02x\n", buf[2],
- buf[3], buf[4], buf[5], buf[7], buf[6]);
+ /* copy GTP_PRODUCT_ID_MAXSIZE from buffer. Ex: 915s */
+ strlcpy(product_id, &buf[2], GTP_PRODUCT_ID_MAXSIZE);
}
+
+ dev_info(&client->dev, "Goodix Product ID = %s\n", product_id);
+
+ if (!IS_ERR(ts->pdata->product_id))
+ ret = strcmp(product_id, ts->pdata->product_id);
+
+ if (ret != 0)
+ return -EINVAL;
+
return ret;
}
@@ -1575,10 +1609,9 @@ static int goodix_parse_dt(struct device *dev,
if (pdata->irq_gpio < 0)
return pdata->irq_gpio;
- rc = of_property_read_u32(np, "goodix,family-id", &temp_val);
- if (!rc)
- pdata->family_id = temp_val;
- else
+ rc = of_property_read_string(np, "goodix,product-id",
+ &pdata->product_id);
+ if (rc < 0 || strlen(pdata->product_id) > GTP_PRODUCT_ID_MAXSIZE)
return rc;
prop = of_find_property(np, "goodix,button-map", NULL);
@@ -1751,9 +1784,13 @@ static int goodix_ts_probe(struct i2c_client *client,
else
dev_info(&client->dev, "GTP works in interrupt mode.\n");
- ret = gtp_read_version(client, &version_info);
- if (ret != 2) {
- dev_err(&client->dev, "Read version failed.\n");
+ ret = gtp_read_fw_version(client, &version_info);
+ if (ret != 0)
+ dev_err(&client->dev, "GTP firmware version read failed.\n");
+
+ ret = gtp_check_product_id(client);
+ if (ret != 0) {
+ dev_err(&client->dev, "GTP Product id doesn't match.\n");
goto exit_free_irq;
}
if (ts->use_irq)
diff --git a/drivers/input/touchscreen/gt9xx/gt9xx.h b/drivers/input/touchscreen/gt9xx/gt9xx.h
index 19ed2c57a7de..662dcdf2951f 100644
--- a/drivers/input/touchscreen/gt9xx/gt9xx.h
+++ b/drivers/input/touchscreen/gt9xx/gt9xx.h
@@ -47,7 +47,7 @@ struct goodix_ts_platform_data {
u32 irq_gpio_flags;
int reset_gpio;
u32 reset_gpio_flags;
- u32 family_id;
+ const char *product_id;
u32 x_max;
u32 y_max;
u32 x_min;
@@ -205,30 +205,34 @@ extern u16 total_len;
#define GTP_INT_TRIGGER GTP_IRQ_TAB_FALLING
#endif
-#define GTP_MAX_TOUCH 5
-#define GTP_ESD_CHECK_CIRCLE 2000 /* jiffy: ms */
+#define GTP_PRODUCT_ID_MAXSIZE 5
+#define GTP_PRODUCT_ID_BUFFER_MAXSIZE 6
+#define GTP_FW_VERSION_BUFFER_MAXSIZE 4
+#define GTP_MAX_TOUCH 5
+#define GTP_ESD_CHECK_CIRCLE 2000 /* jiffy: ms */
/***************************PART3:OTHER define*********************************/
-#define GTP_DRIVER_VERSION "V1.8<2013/06/08>"
-#define GTP_I2C_NAME "Goodix-TS"
-#define GTP_POLL_TIME 10 /* jiffy: ms*/
-#define GTP_ADDR_LENGTH 2
+#define GTP_DRIVER_VERSION "V1.8.1<2013/09/01>"
+#define GTP_I2C_NAME "Goodix-TS"
+#define GTP_POLL_TIME 10 /* jiffy: ms*/
+#define GTP_ADDR_LENGTH 2
#define GTP_CONFIG_MIN_LENGTH 186
#define GTP_CONFIG_MAX_LENGTH 240
-#define FAIL 0
-#define SUCCESS 1
-#define SWITCH_OFF 0
-#define SWITCH_ON 1
+#define FAIL 0
+#define SUCCESS 1
+#define SWITCH_OFF 0
+#define SWITCH_ON 1
/* Registers define */
-#define GTP_READ_COOR_ADDR 0x814E
-#define GTP_REG_SLEEP 0x8040
-#define GTP_REG_SENSOR_ID 0x814A
-#define GTP_REG_CONFIG_DATA 0x8047
-#define GTP_REG_VERSION 0x8140
+#define GTP_READ_COOR_ADDR 0x814E
+#define GTP_REG_SLEEP 0x8040
+#define GTP_REG_SENSOR_ID 0x814A
+#define GTP_REG_CONFIG_DATA 0x8047
+#define GTP_REG_FW_VERSION 0x8144
+#define GTP_REG_PRODUCT_ID 0x8140
-#define RESOLUTION_LOC 3
-#define TRIGGER_LOC 8
+#define RESOLUTION_LOC 3
+#define TRIGGER_LOC 8
/* Log define */
#define GTP_DEBUG(fmt, arg...) do {\