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

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

input: touchscreen: Clean code for i2c_read and i2c_write



Use standard initializer code in gtp_i2c_read and
gtp_i2c_write functions for Goodix touchscreen driver.

CRs-fixed: 549289
Change-Id: Id954be61a0b4596339a659928fb630c5c5538a9a
Signed-off-by: default avatarShantanu Jain <shjain@codeaurora.org>
Signed-off-by: default avatarSudhakar Manapati <smanap@codeaurora.org>
parent a755bf0d
Loading
Loading
Loading
Loading
+33 −29
Original line number Original line Diff line number Diff line
@@ -139,27 +139,30 @@ Output:
int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len)
int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len)
{
{
	struct goodix_ts_data *ts = i2c_get_clientdata(client);
	struct goodix_ts_data *ts = i2c_get_clientdata(client);
	struct i2c_msg msgs[2];
	int ret = -EIO;
	int ret = -EIO;
	int retries = 0;
	u8 retries;

	struct i2c_msg msgs[2] = {
	msgs[0].flags = !I2C_M_RD;
		{
	msgs[0].addr = client->addr;
			.flags	= !I2C_M_RD,
	msgs[0].len = GTP_ADDR_LENGTH;
			.addr	= client->addr,
	msgs[0].buf = &buf[0];
			.len	= GTP_ADDR_LENGTH,

			.buf	= &buf[0],
	msgs[1].flags = I2C_M_RD;
		},
	msgs[1].addr = client->addr;
		{
	msgs[1].len = len - GTP_ADDR_LENGTH;
			.flags	= I2C_M_RD,
	msgs[1].buf = &buf[GTP_ADDR_LENGTH];
			.addr	= client->addr,
			.len	= len - GTP_ADDR_LENGTH,
			.buf	= &buf[GTP_ADDR_LENGTH],
		},
	};


	while (retries < 5) {
	for (retries = 0; retries < 5; retries++) {
		ret = i2c_transfer(client->adapter, msgs, 2);
		ret = i2c_transfer(client->adapter, msgs, 2);
		if (ret == 2)
		if (ret == 2)
			break;
			break;
		retries++;
		dev_err(&client->dev, "I2C retry: %d\n", retries + 1);
	}
	}
	if (retries >= 5) {
	if (retries == 5) {
#if GTP_SLIDE_WAKEUP
#if GTP_SLIDE_WAKEUP
		/* reset chip would quit doze mode */
		/* reset chip would quit doze mode */
		if (DOZE_ENABLED == doze_status)
		if (DOZE_ENABLED == doze_status)
@@ -169,7 +172,7 @@ int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len)
			gtp_reset_guitar(ts, 10);
			gtp_reset_guitar(ts, 10);
		else
		else
			dev_warn(&client->dev,
			dev_warn(&client->dev,
				"<GTP> gtp_reset_guitar exit init_done=%d:\n",
				"gtp_reset_guitar exit init_done=%d:\n",
				init_done);
				init_done);
	}
	}
	return ret;
	return ret;
@@ -190,22 +193,22 @@ Output:
int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len)
int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len)
{
{
	struct goodix_ts_data *ts = i2c_get_clientdata(client);
	struct goodix_ts_data *ts = i2c_get_clientdata(client);
	struct i2c_msg msg;
	int ret = -EIO;
	int ret = -EIO;
	int retries = 0;
	u8 retries;

	struct i2c_msg msg = {
	msg.flags = !I2C_M_RD;
		.flags = !I2C_M_RD,
	msg.addr = client->addr;
		.addr = client->addr,
	msg.len = len;
		.len = len,
	msg.buf = buf;
		.buf = buf,
	};


	while (retries < 5) {
	for (retries = 0; retries < 5; retries++) {
		ret = i2c_transfer(client->adapter, &msg, 1);
		ret = i2c_transfer(client->adapter, &msg, 1);
		if (ret == 1)
		if (ret == 1)
			break;
			break;
		retries++;
		dev_err(&client->dev, "I2C retry: %d\n", retries + 1);
	}
	}
	if ((retries >= 5)) {
	if ((retries == 5)) {
#if GTP_SLIDE_WAKEUP
#if GTP_SLIDE_WAKEUP
		if (DOZE_ENABLED == doze_status)
		if (DOZE_ENABLED == doze_status)
			return ret;
			return ret;
@@ -214,11 +217,12 @@ int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len)
			gtp_reset_guitar(ts, 10);
			gtp_reset_guitar(ts, 10);
		else
		else
			dev_warn(&client->dev,
			dev_warn(&client->dev,
				"<GTP> gtp_reset_guitar exit init_done=%d:\n",
				"gtp_reset_guitar exit init_done=%d:\n",
				init_done);
				init_done);
	}
	}
	return ret;
	return ret;
}
}

/*******************************************************
/*******************************************************
Function:
Function:
	i2c read twice, compare the results
	i2c read twice, compare the results