diff mbox series

[v2,07/10] i2c: mt7621: Use i2c_10bit_addr_*_from_msg() helpers

Message ID 20250213141045.2716943-8-andriy.shevchenko@linux.intel.com (mailing list archive)
State Under Review
Delegated to: Geert Uytterhoeven
Headers show
Series i2c: busses: Introduce and use i2c_10bit_addr_*_from_msg() | expand

Commit Message

Andy Shevchenko Feb. 13, 2025, 2:07 p.m. UTC
Use i2c_10bit_addr_*_from_msg() helpers instead of local copy.
No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-mt7621.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

AngeloGioacchino Del Regno Feb. 13, 2025, 4:01 p.m. UTC | #1
Il 13/02/25 15:07, Andy Shevchenko ha scritto:
> Use i2c_10bit_addr_*_from_msg() helpers instead of local copy.
> No functional change intended.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Can we please do the helper conversion as one commit and the (much needed)
cleanup of assigning len and de-duplicating the call to mtk_i2c_cmd() as
two commits?

One with just the conversion, one with the cleanup (or in inverse order,
as you wish).

Thanks,
Angelo

> ---
>   drivers/i2c/busses/i2c-mt7621.c | 20 ++++++++------------
>   1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
> index 2103f21f9ddd..0a288c998419 100644
> --- a/drivers/i2c/busses/i2c-mt7621.c
> +++ b/drivers/i2c/busses/i2c-mt7621.c
> @@ -164,22 +164,18 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
>   		/* write address */
>   		if (pmsg->flags & I2C_M_TEN) {
>   			/* 10 bits address */
> -			addr = 0xf0 | ((pmsg->addr >> 7) & 0x06);
> -			addr |= (pmsg->addr & 0xff) << 8;
> -			if (pmsg->flags & I2C_M_RD)
> -				addr |= 1;
> -			iowrite32(addr, i2c->base + REG_SM0D0_REG);
> -			ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, 2);
> -			if (ret)
> -				goto err_timeout;
> +			addr = i2c_10bit_addr_hi_from_msg(pmsg);
> +			addr |= i2c_10bit_addr_lo_from_msg(pmsg) << 8;
> +			len = 2;
>   		} else {
>   			/* 7 bits address */
>   			addr = i2c_8bit_addr_from_msg(pmsg);
> -			iowrite32(addr, i2c->base + REG_SM0D0_REG);
> -			ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, 1);
> -			if (ret)
> -				goto err_timeout;
> +			len = 1;
>   		}
> +		iowrite32(addr, i2c->base + REG_SM0D0_REG);
> +		ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, len);
> +		if (ret)
> +			goto err_timeout;
>   
>   		/* check address ACK */
>   		if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {
Andy Shevchenko Feb. 13, 2025, 4:37 p.m. UTC | #2
On Thu, Feb 13, 2025 at 05:01:20PM +0100, AngeloGioacchino Del Regno wrote:
> Il 13/02/25 15:07, Andy Shevchenko ha scritto:
> > Use i2c_10bit_addr_*_from_msg() helpers instead of local copy.
> > No functional change intended.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Can we please do the helper conversion as one commit and the (much needed)
> cleanup of assigning len and de-duplicating the call to mtk_i2c_cmd() as
> two commits?
> 
> One with just the conversion, one with the cleanup (or in inverse order,
> as you wish).

Yes we can.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 2103f21f9ddd..0a288c998419 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -164,22 +164,18 @@  static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 		/* write address */
 		if (pmsg->flags & I2C_M_TEN) {
 			/* 10 bits address */
-			addr = 0xf0 | ((pmsg->addr >> 7) & 0x06);
-			addr |= (pmsg->addr & 0xff) << 8;
-			if (pmsg->flags & I2C_M_RD)
-				addr |= 1;
-			iowrite32(addr, i2c->base + REG_SM0D0_REG);
-			ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, 2);
-			if (ret)
-				goto err_timeout;
+			addr = i2c_10bit_addr_hi_from_msg(pmsg);
+			addr |= i2c_10bit_addr_lo_from_msg(pmsg) << 8;
+			len = 2;
 		} else {
 			/* 7 bits address */
 			addr = i2c_8bit_addr_from_msg(pmsg);
-			iowrite32(addr, i2c->base + REG_SM0D0_REG);
-			ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, 1);
-			if (ret)
-				goto err_timeout;
+			len = 1;
 		}
+		iowrite32(addr, i2c->base + REG_SM0D0_REG);
+		ret = mtk_i2c_cmd(i2c, SM0CTL1_WRITE, len);
+		if (ret)
+			goto err_timeout;
 
 		/* check address ACK */
 		if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {