Commit 4eee8a67 authored by Diego Sueiro's avatar Diego Sueiro Committed by Maureen Helm
Browse files

drivers/i2c/i2c_imx: Check for I2C bus busy before starting transaction



In some cases the minimum time between Stop and Start was not being
considered when starting a new transfer.
This patches adds a checking on the I2C Bus Busy flag before starting
a new transaction.

Signed-off-by: default avatarDiego Sueiro <diego.sueiro@gmail.com>
parent a25c273f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -179,12 +179,21 @@ static int i2c_imx_transfer(struct device *dev, struct i2c_msg *msgs,
	struct i2c_imx_data *data = DEV_DATA(dev);
	struct i2c_master_transfer *transfer = &data->transfer;
	u8_t *buf, *buf_end;
	u16_t timeout = UINT16_MAX;
	int result = -EIO;

	if (!num_msgs) {
		return 0;
	}

	/* Wait until bus not busy */
	while ((I2C_I2SR_REG(base) & i2cStatusBusBusy) && (--timeout)) {
	}

	if (timeout == 0) {
		return result;
	}

	/* Make sure we're in a good state so slave recognises the Start */
	I2C_SetWorkMode(base, i2cModeSlave);
	transfer->currentMode = i2cModeSlave;