Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ddb25d0 authored by Shantanu Jain's avatar Shantanu Jain Committed by Gerrit - the friendly Code Review server
Browse files

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: default avatarShantanu Jain <shjain@codeaurora.org>
Signed-off-by: default avatarSudhakar Manapati <smanap@codeaurora.org>
parent 90d5e14e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ Required properties:
 - interrupt-parent	: Parent of interrupt.
 - interrupts		: Configuration of touch panel controller interrupt
				GPIO.
 - goodix,family-id	: Family identification of the controller.
 - goodix,product-id	: Product identification of the controller.
 - interrupt-gpios	: Interrupt gpio which is to provide interrupts to
				host, same as "interrupts" node.
 - reset-gpios		: Reset gpio to control the reset of chip.
@@ -54,7 +54,7 @@ i2c@f9927000 {
			goodix,panel-coords = <0 0 720 1200>;
			goodix,display-coords = <0 0 720 1080>;
			goodix,button-map= <158 102 139>;
			goodix,family-id = <0x0>;
			goodix,product-id = "915";
			goodix,cfg-data = [
		41 D0 02 00 05 0A 05 01 01 08
		12 58 50 41 03 05 00 00 00 00
+57 −20
Original line number Diff line number Diff line
@@ -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)
+22 −18
Original line number Diff line number Diff line
@@ -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,11 +205,14 @@ extern u16 total_len;
#define GTP_INT_TRIGGER		GTP_IRQ_TAB_FALLING
#endif

#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_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
@@ -225,7 +228,8 @@ extern u16 total_len;
#define GTP_REG_SLEEP		0x8040
#define GTP_REG_SENSOR_ID	0x814A
#define GTP_REG_CONFIG_DATA	0x8047
#define GTP_REG_VERSION			0x8140
#define GTP_REG_FW_VERSION	0x8144
#define GTP_REG_PRODUCT_ID	0x8140

#define RESOLUTION_LOC		3
#define TRIGGER_LOC		8