Re: [PATCH v2 2/2] i2c: busses: make use of i2c_8bit_addr_from_msg

2018-05-29 Thread Wolfram Sang
On Wed, May 16, 2018 at 09:16:47AM +0200, Peter Rosin wrote:
> 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  [diolan]
> Acked-by: Uwe Kleine-König  [emf32 and imx]
> Acked-by: Linus Walleij  [stu300]
> Signed-off-by: Peter Rosin 

Applied to for-next, thanks!



signature.asc
Description: PGP signature


Re: [PATCH v2 2/2] i2c: busses: make use of i2c_8bit_addr_from_msg

2018-05-16 Thread Uwe Kleine-König
Hello Peter,

On Wed, May 16, 2018 at 09:16:47AM +0200, Peter Rosin wrote:
> Acked-by: Uwe Kleine-König  [emf32 and imx]

s/emf/efm/

Best regards
Uwe

-- 
Pengutronix e.K.   | Uwe Kleine-König|
Industrial Linux Solutions | http://www.pengutronix.de/  |


[PATCH v2 2/2] i2c: busses: make use of i2c_8bit_addr_from_msg

2018-05-16 Thread Peter Rosin
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  [diolan]
Acked-by: Uwe Kleine-König  [emf32 and imx]
Acked-by: Linus Walleij  [stu300]
Signed-off-by: Peter Rosin 
---
 drivers/i2c/busses/i2c-aspeed.c |  3 +--
 drivers/i2c/busses/i2c-axxia.c  |  5 +++--
 drivers/i2c/busses/i2c-diolan-u2c.c | 11 ---
 drivers/i2c/busses/i2c-efm32.c  |  3 +--
 drivers/i2c/busses/i2c-eg20t.c  |  5 ++---
 drivers/i2c/busses/i2c-emev2.c  |  2 +-
 drivers/i2c/busses/i2c-hix5hd2.c|  9 ++---
 drivers/i2c/busses/i2c-imx-lpi2c.c  |  4 +---
 drivers/i2c/busses/i2c-imx.c| 10 +-
 drivers/i2c/busses/i2c-kempld.c |  7 +++
 drivers/i2c/busses/i2c-mxs.c|  9 +++--
 drivers/i2c/busses/i2c-ocores.c |  5 +
 drivers/i2c/busses/i2c-pasemi.c |  2 +-
 drivers/i2c/busses/i2c-qup.c|  2 +-
 drivers/i2c/busses/i2c-rcar.c   |  2 +-
 drivers/i2c/busses/i2c-riic.c   |  5 ++---
 drivers/i2c/busses/i2c-stu300.c | 22 +-
 drivers/i2c/busses/i2c-xiic.c   | 11 ++-
 18 files changed, 47 insertions(+), 70 deletions(-)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 7d4aeb4465b3..60e4d0e939a3 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -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 = >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))
diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 13f07482ec68..f70b097fd567 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -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;
diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c 
b/drivers/i2c/busses/i2c-diolan-u2c.c
index f718ee4e3332..3f28317cde39 100644
--- a/drivers/i2c/busses/i2c-diolan-u2c.c
+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
@@ -360,11 +360,11 @@ static int diolan_usb_xfer(struct i2c_adapter *adapter, 
struct i2c_msg *msgs,
if (ret < 0)
goto abort;
}
+   ret = diolan_i2c_put_byte_ack(dev,
+ i2c_8bit_addr_from_msg(pmsg));
+   if (ret < 0)
+   goto abort;
if (pmsg->flags & I2C_M_RD) {
-   ret =
-   diolan_i2c_put_byte_ack(dev, (pmsg->addr << 1) | 1);
-   if (ret < 0)
-   goto abort;
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,