/* @client: i2c device. @reg: the register to write to. @buf: raw data buffer to write. @len: length of the buffer to write  */
static int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, unsigned len)
/* @client: i2c device. @reg: the register to write to. @buf: raw data buffer to write. @len: length of the buffer to write  */
static int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, unsigned len)
{
	u8 *addr_buf;
	struct i2c_msg msg;
	int ret;
	addr_buf = kmalloc(len + 2, GFP_KERNEL);
	if (!addr_buf)
		return -ENOMEM;
	addr_buf[0] = reg >> 8;
	addr_buf[1] = reg & 0xFF;
	memcpy(&addr_buf[2], buf, len);
	msg.flags = 0;
	msg.addr = client->addr;
	msg.buf = addr_buf;
	msg.len = len + 2;
	ret = i2c_transfer(client->adapter, &msg, 1);
	kfree(addr_buf);
	return ret < 0 ? ret : (ret != 1 ? -EIO : 0);
}