/* @twsi: The MVTWSI register structure to use. @chip: The chip address to read from. @addr: The address bytes to send. @alen: The length of the address bytes in bytes. @data: The buffer containing the data to be sent to the chip. @length: The length of data to be sent to the chip in bytes. @tick: The duration of a clock cycle at the current I2C speed.  */
static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip, u8 *addr, int alen, uchar *data, int length, uint tick)
/* @twsi: The MVTWSI register structure to use. @chip: The chip address to read from. @addr: The address bytes to send. @alen: The length of the address bytes in bytes. @data: The buffer containing the data to be sent to the chip. @length: The length of data to be sent to the chip in bytes. @tick: The duration of a clock cycle at the current I2C speed.  */
static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip, u8 *addr, int alen, uchar *data, int length, uint tick)
{
	int status, stop_status;
	status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1), tick);
	while ((status == 0) && (alen-- > 0))
		status = twsi_send(twsi, addr[alen], MVTWSI_STATUS_DATA_W_ACK,
				   tick);
	while ((status == 0) && (length-- > 0))
		status = twsi_send(twsi, *(data++), MVTWSI_STATUS_DATA_W_ACK,
				   tick);
	stop_status = twsi_stop(twsi, tick);
	return status != 0 ? status : stop_status;
}