Ejemplo n.º 1
0
static int cyttsp5_i2c_write_read_specific(struct device *dev, u8 write_len,
		u8 *write_buf, u8 *read_buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct i2c_msg msgs[2];
	u8 msg_count = 1;
	int rc;

	if (!write_buf || !write_len)
		return -EINVAL;

	msgs[0].addr = client->addr;
	msgs[0].flags = client->flags & I2C_M_TEN;
	msgs[0].len = write_len;
	msgs[0].buf = write_buf;
	rc = i2c_transfer(client->adapter, msgs, msg_count);

	if (rc < 0 || rc != msg_count)
		return (rc < 0) ? rc : -EIO;
	else
		rc = 0;

	if (read_buf)
		rc = cyttsp5_i2c_read_default_nosize(dev, read_buf,
				CY_I2C_DATA_SIZE);

	return rc;
}
/*****************************************************************
Parameters    :  dev      
                 write_len
                 write_buf
                 read_buf 
Return        :  
Description   :  
*****************************************************************/
static int cyttsp5_i2c_write_read_specific(struct device *dev, u8 write_len,
		u8 *write_buf, u8 *read_buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct i2c_msg msgs[2];
	u8 msg_count = 1;
	int rc;

	if (!write_buf || !write_len) {
		tp_log_err("%s %d:input parameter error.\n", __func__, __LINE__);
		return -EINVAL;
	}

	msgs[0].addr = client->addr;
	msgs[0].flags = client->flags & I2C_M_TEN;
	msgs[0].len = write_len;
	msgs[0].buf = write_buf;
	rc = i2c_transfer(client->adapter, msgs, msg_count);

	if (rc < 0 || rc != msg_count) {
#ifdef CONFIG_HUAWEI_DSM
		g_tp_dsm_info.constraints_I2C_status = rc;
		cyttsp5_tp_report_dsm_err(dev, DSM_TP_I2C_RW_ERROR_NO, g_tp_dsm_info.constraints_I2C_status);
#endif/*CONFIG_HUAWEI_DSM*/
		tp_log_err("%s %d:I2C transfer error, rc = %d\n", __func__, __LINE__, rc);
		return (rc < 0) ? rc : -EIO;
	}

	rc = 0;

	if (read_buf) {
		rc = cyttsp5_i2c_read_default_nosize(dev, read_buf,
				CY_I2C_DATA_SIZE);
		if (rc) {
			tp_log_err("%s %d:I2C read error, rc = %d\n", __func__, __LINE__, rc);
		}
	}

	return rc;
}