Commit 30a64757 authored by Peter Rosin's avatar Peter Rosin Committed by Wolfram Sang
Browse files

i2c: busses: make use of i2c_8bit_addr_from_msg



Because it looks neater.

For diolan, this allows factoring out some code that is now common
between if and else.

For eg20t, pch_i2c_writebytes is always called with a write in
msgs->flags, and pch_i2c_readbytes with a read.

For imx, i2c_imx_dma_write and i2c_imx_write are always called with a
write in msgs->flags, and i2c_imx_read with a read.

For qup, qup_i2c_write_tx_fifo_v1 is always called with a write in
qup->msg->flags.

For stu300, also restructure debug output for resends, since that
code as a result is only handling debug output.

Reviewed-by: Guenter Roeck <linux@roeck-us.net> [diolan]
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> [efm32 and imx]
Acked-by: Linus Walleij <linus.walleij@linaro.org> [stu300]
Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent ac6d5298
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -335,13 +335,12 @@ static void aspeed_i2c_do_start(struct aspeed_i2c_bus *bus)
{
	u32 command = ASPEED_I2CD_M_START_CMD | ASPEED_I2CD_M_TX_CMD;
	struct i2c_msg *msg = &bus->msgs[bus->msgs_index];
	u8 slave_addr = msg->addr << 1;
	u8 slave_addr = i2c_8bit_addr_from_msg(msg);

	bus->master_state = ASPEED_I2C_MASTER_START;
	bus->buf_index = 0;

	if (msg->flags & I2C_M_RD) {
		slave_addr |= 1;
		command |= ASPEED_I2CD_M_RX_CMD;
		/* Need to let the hardware know to NACK after RX. */
		if (msg->len == 1 && !(msg->flags & I2C_M_RECV_LEN))
+3 −2
Original line number Diff line number Diff line
@@ -351,13 +351,15 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
		 *   addr_2: addr[7:0]
		 */
		addr_1 = 0xF0 | ((msg->addr >> 7) & 0x06);
		if (i2c_m_rd(msg))
			addr_1 |= 1;	/* Set the R/nW bit of the address */
		addr_2 = msg->addr & 0xFF;
	} else {
		/* 7-bit address
		 *   addr_1: addr[6:0] | (R/nW)
		 *   addr_2: dont care
		 */
		addr_1 = (msg->addr << 1) & 0xFF;
		addr_1 = i2c_8bit_addr_from_msg(msg);
		addr_2 = 0;
	}

@@ -365,7 +367,6 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
		/* I2C read transfer */
		rx_xfer = i2c_m_recv_len(msg) ? I2C_SMBUS_BLOCK_MAX : msg->len;
		tx_xfer = 0;
		addr_1 |= 1;	/* Set the R/nW bit of the address */
	} else {
		/* I2C write transfer */
		rx_xfer = 0;
+4 −7
Original line number Diff line number Diff line
@@ -360,11 +360,11 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
			if (ret < 0)
				goto abort;
		}
		if (pmsg->flags & I2C_M_RD) {
			ret =
			    diolan_i2c_put_byte_ack(dev, (pmsg->addr << 1) | 1);
		ret = diolan_i2c_put_byte_ack(dev,
					      i2c_8bit_addr_from_msg(pmsg));
		if (ret < 0)
			goto abort;
		if (pmsg->flags & I2C_M_RD) {
			for (j = 0; j < pmsg->len; j++) {
				u8 byte;
				bool ack = j < pmsg->len - 1;
@@ -393,9 +393,6 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
				pmsg->buf[j] = byte;
			}
		} else {
			ret = diolan_i2c_put_byte_ack(dev, pmsg->addr << 1);
			if (ret < 0)
				goto abort;
			for (j = 0; j < pmsg->len; j++) {
				ret = diolan_i2c_put_byte_ack(dev,
							      pmsg->buf[j]);
+1 −2
Original line number Diff line number Diff line
@@ -144,8 +144,7 @@ static void efm32_i2c_send_next_msg(struct efm32_i2c_ddata *ddata)
	struct i2c_msg *cur_msg = &ddata->msgs[ddata->current_msg];

	efm32_i2c_write32(ddata, REG_CMD, REG_CMD_START);
	efm32_i2c_write32(ddata, REG_TXDATA, cur_msg->addr << 1 |
			(cur_msg->flags & I2C_M_RD ? 1 : 0));
	efm32_i2c_write32(ddata, REG_TXDATA, i2c_8bit_addr_from_msg(cur_msg));
}

static void efm32_i2c_send_next_byte(struct efm32_i2c_ddata *ddata)
+2 −3
Original line number Diff line number Diff line
@@ -414,7 +414,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
		iowrite32(addr_8_lsb, p + PCH_I2CDR);
	} else {
		/* set 7 bit slave address and R/W bit as 0 */
		iowrite32(addr << 1, p + PCH_I2CDR);
		iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
		if (first)
			pch_i2c_start(adap);
	}
@@ -538,8 +538,7 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
		iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
	} else {
		/* 7 address bits + R/W bit */
		addr = (((addr) << 1) | (I2C_RD));
		iowrite32(addr, p + PCH_I2CDR);
		iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
	}

	/* check if it is the first message */
Loading