* [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg()
@ 2025-02-12 16:32 Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
` (7 more replies)
0 siblings, 8 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
For 8-bit addresses we have a helper function, define similar one
for 10-bit addresses and use it in the drivers. It allows to remove
some boilerplate code.
Andy Shevchenko (8):
i2c: Introduce i2c_10bit_addr_from_msg()
i2c: axxia: Use i2c_10bit_addr_from_msg() helper
i2c: bcm-kona: Use i2c_10bit_addr_from_msg() helper
i2c: eg20t: Use i2c_10bit_addr_from_msg() helper
i2c: kempld: Use i2c_10bit_addr_from_msg() helper
i2c: mt7621: Use i2c_10bit_addr_from_msg() helper
i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers
i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
drivers/i2c/busses/i2c-axxia.c | 19 ++-----------------
drivers/i2c/busses/i2c-bcm-kona.c | 9 ++++-----
drivers/i2c/busses/i2c-eg20t.c | 28 +++++-----------------------
drivers/i2c/busses/i2c-kempld.c | 4 +---
drivers/i2c/busses/i2c-mt7621.c | 4 +---
drivers/i2c/busses/i2c-mv64xxx.c | 10 ++--------
drivers/i2c/busses/i2c-rzv2m.c | 10 +++-------
include/linux/i2c.h | 10 ++++++++++
8 files changed, 28 insertions(+), 66 deletions(-)
--
2.45.1.3035.g276e886db78b
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 17:06 ` Fabrizio Castro
` (2 more replies)
2025-02-12 16:32 ` [PATCH v1 2/8] i2c: axxia: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
` (6 subsequent siblings)
7 siblings, 3 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
There are already a lot of drivers that have been using
i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
to have the similar for 10-bit addresses.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/i2c.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 997e80649889..4d281ff5582b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -952,6 +952,16 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
return (msg->addr << 1) | (msg->flags & I2C_M_RD);
}
+static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
+{
+ /*
+ * 10-bit address
+ * addr_1: 5'b11110 | addr[9:8] | (R/nW)
+ * addr_2: addr[7:0]
+ */
+ return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
+}
+
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 2/8] i2c: axxia: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 3/8] i2c: bcm-kona: " Andy Shevchenko
` (5 subsequent siblings)
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-axxia.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 741ee4636759..bee56e33531b 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -255,11 +255,6 @@ static int i2c_m_rd(const struct i2c_msg *msg)
return (msg->flags & I2C_M_RD) != 0;
}
-static int i2c_m_ten(const struct i2c_msg *msg)
-{
- return (msg->flags & I2C_M_TEN) != 0;
-}
-
static int i2c_m_recv_len(const struct i2c_msg *msg)
{
return (msg->flags & I2C_M_RECV_LEN) != 0;
@@ -439,20 +434,10 @@ static void axxia_i2c_set_addr(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
{
u32 addr_1, addr_2;
- if (i2c_m_ten(msg)) {
- /* 10-bit address
- * addr_1: 5'b11110 | addr[9:8] | (R/nW)
- * 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 */
+ if (msg->flags & I2C_M_TEN) {
+ addr_1 = i2c_10bit_addr_from_msg(msg);
addr_2 = msg->addr & 0xFF;
} else {
- /* 7-bit address
- * addr_1: addr[6:0] | (R/nW)
- * addr_2: dont care
- */
addr_1 = i2c_8bit_addr_from_msg(msg);
addr_2 = 0;
}
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 3/8] i2c: bcm-kona: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 2/8] i2c: axxia: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 4/8] i2c: eg20t: " Andy Shevchenko
` (4 subsequent siblings)
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-bcm-kona.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
index 340fe1305dd9..f8826e2d3ec2 100644
--- a/drivers/i2c/busses/i2c-bcm-kona.c
+++ b/drivers/i2c/busses/i2c-bcm-kona.c
@@ -470,14 +470,14 @@ static int bcm_kona_i2c_do_addr(struct bcm_kona_i2c_dev *dev,
unsigned char addr;
if (msg->flags & I2C_M_TEN) {
+ addr = i2c_10bit_addr_from_msg(msg);
+
/* First byte is 11110XX0 where XX is upper 2 bits */
- addr = 0xF0 | ((msg->addr & 0x300) >> 7);
- if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+ if (bcm_kona_i2c_write_byte(dev, addr & ~I2C_M_RD, 0) < 0)
return -EREMOTEIO;
/* Second byte is the remaining 8 bits */
- addr = msg->addr & 0xFF;
- if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+ if (bcm_kona_i2c_write_byte(dev, msg->addr & 0xFF, 0) < 0)
return -EREMOTEIO;
if (msg->flags & I2C_M_RD) {
@@ -486,7 +486,6 @@ static int bcm_kona_i2c_do_addr(struct bcm_kona_i2c_dev *dev,
return -EREMOTEIO;
/* Then re-send the first byte with the read bit set */
- addr = 0xF0 | ((msg->addr & 0x300) >> 7) | 0x01;
if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
return -EREMOTEIO;
}
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 4/8] i2c: eg20t: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
` (2 preceding siblings ...)
2025-02-12 16:32 ` [PATCH v1 3/8] i2c: bcm-kona: " Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 5/8] i2c: kempld: " Andy Shevchenko
` (3 subsequent siblings)
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-eg20t.c | 28 +++++-----------------------
1 file changed, 5 insertions(+), 23 deletions(-)
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 4914bfbee2a9..20151408bf9c 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -48,8 +48,6 @@
#define BUS_IDLE_TIMEOUT 20
#define PCH_I2CCTL_I2CMEN 0x0080
-#define TEN_BIT_ADDR_DEFAULT 0xF000
-#define TEN_BIT_ADDR_MASK 0xF0
#define PCH_START 0x0020
#define PCH_RESTART 0x0004
#define PCH_ESR_START 0x0001
@@ -58,7 +56,6 @@
#define PCH_ACK 0x0008
#define PCH_GETACK 0x0001
#define CLR_REG 0x0
-#define I2C_RD 0x1
#define I2CMCF_BIT 0x0080
#define I2CMIF_BIT 0x0002
#define I2CMAL_BIT 0x0010
@@ -76,8 +73,6 @@
#define I2CMBB_BIT 0x0020
#define BUFFER_MODE_MASK (I2CBMFI_BIT | I2CBMAL_BIT | I2CBMNA_BIT | \
I2CBMTO_BIT | I2CBMIS_BIT)
-#define I2C_ADDR_MSK 0xFF
-#define I2C_MSB_2B_MSK 0x300
#define FAST_MODE_CLK 400
#define FAST_MODE_EN 0x0001
#define SUB_ADDR_LEN_MAX 4
@@ -371,16 +366,12 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
struct i2c_algo_pch_data *adap = i2c_adap->algo_data;
u8 *buf;
u32 length;
- u32 addr;
- u32 addr_2_msb;
- u32 addr_8_lsb;
s32 wrcount;
s32 rtn;
void __iomem *p = adap->pch_base_address;
length = msgs->len;
buf = msgs->buf;
- addr = msgs->addr;
/* enable master tx */
pch_setbit(adap->pch_base_address, PCH_I2CCTL, I2C_TX_MODE);
@@ -394,8 +385,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
}
if (msgs->flags & I2C_M_TEN) {
- addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7) & 0x06;
- iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
+ iowrite32(i2c_10bit_addr_from_msg(msgs), p + PCH_I2CDR);
if (first)
pch_i2c_start(adap);
@@ -403,8 +393,7 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
if (rtn)
return rtn;
- addr_8_lsb = (addr & I2C_ADDR_MSK);
- iowrite32(addr_8_lsb, p + PCH_I2CDR);
+ iowrite32(msgs->addr & 0xff, p + PCH_I2CDR);
} else {
/* set 7 bit slave address and R/W bit as 0 */
iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
@@ -490,15 +479,11 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
u8 *buf;
u32 count;
u32 length;
- u32 addr;
- u32 addr_2_msb;
- u32 addr_8_lsb;
void __iomem *p = adap->pch_base_address;
s32 rtn;
length = msgs->len;
buf = msgs->buf;
- addr = msgs->addr;
/* enable master reception */
pch_clrbit(adap->pch_base_address, PCH_I2CCTL, I2C_TX_MODE);
@@ -509,8 +494,7 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
}
if (msgs->flags & I2C_M_TEN) {
- addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7);
- iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
+ iowrite32(i2c_10bit_addr_from_msg(msgs) & ~I2C_M_RD, p + PCH_I2CDR);
if (first)
pch_i2c_start(adap);
@@ -518,8 +502,7 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
if (rtn)
return rtn;
- addr_8_lsb = (addr & I2C_ADDR_MSK);
- iowrite32(addr_8_lsb, p + PCH_I2CDR);
+ iowrite32(msgs->addr & 0xff, p + PCH_I2CDR);
pch_i2c_restart(adap);
@@ -527,8 +510,7 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
if (rtn)
return rtn;
- addr_2_msb |= I2C_RD;
- iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
+ iowrite32(i2c_10bit_addr_from_msg(msgs), p + PCH_I2CDR);
} else {
/* 7 address bits + R/W bit */
iowrite32(i2c_8bit_addr_from_msg(msgs), p + PCH_I2CDR);
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 5/8] i2c: kempld: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
` (3 preceding siblings ...)
2025-02-12 16:32 ` [PATCH v1 4/8] i2c: eg20t: " Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 6/8] i2c: mt7621: " Andy Shevchenko
` (2 subsequent siblings)
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-kempld.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-kempld.c b/drivers/i2c/busses/i2c-kempld.c
index 212196af68ba..7508cc7a33a6 100644
--- a/drivers/i2c/busses/i2c-kempld.c
+++ b/drivers/i2c/busses/i2c-kempld.c
@@ -115,9 +115,7 @@ static int kempld_i2c_process(struct kempld_i2c_data *i2c)
if (i2c->state == STATE_ADDR) {
/* 10 bit address? */
if (i2c->msg->flags & I2C_M_TEN) {
- addr = 0xf0 | ((i2c->msg->addr >> 7) & 0x6);
- /* Set read bit if necessary */
- addr |= (i2c->msg->flags & I2C_M_RD) ? 1 : 0;
+ addr = i2c_10bit_addr_from_msg(msg);
i2c->state = STATE_ADDR10;
} else {
addr = i2c_8bit_addr_from_msg(i2c->msg);
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 6/8] i2c: mt7621: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
` (4 preceding siblings ...)
2025-02-12 16:32 ` [PATCH v1 5/8] i2c: kempld: " Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 7/8] i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-mt7621.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 2103f21f9ddd..125dc91fb329 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -164,10 +164,8 @@ 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 = i2c_10bit_addr_from_msg(pmsg);
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)
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 7/8] i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
` (5 preceding siblings ...)
2025-02-12 16:32 ` [PATCH v1 6/8] i2c: mt7621: " Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
7 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_*bit_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-mv64xxx.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 874309580c33..3f83c68947cc 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -27,7 +27,6 @@
#include <linux/err.h>
#include <linux/delay.h>
-#define MV64XXX_I2C_ADDR_ADDR(val) ((val & 0x7f) << 1)
#define MV64XXX_I2C_BAUD_DIV_N(val) (val & 0x7)
#define MV64XXX_I2C_BAUD_DIV_M(val) ((val & 0xf) << 3)
@@ -176,22 +175,17 @@ static void
mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data,
struct i2c_msg *msg)
{
- u32 dir = 0;
-
drv_data->cntl_bits = MV64XXX_I2C_REG_CONTROL_ACK |
MV64XXX_I2C_REG_CONTROL_TWSIEN;
if (!drv_data->atomic)
drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_INTEN;
- if (msg->flags & I2C_M_RD)
- dir = 1;
-
if (msg->flags & I2C_M_TEN) {
- drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir;
+ drv_data->addr1 = i2c_10bit_addr_from_msg(msg);
drv_data->addr2 = (u32)msg->addr & 0xff;
} else {
- drv_data->addr1 = MV64XXX_I2C_ADDR_ADDR((u32)msg->addr) | dir;
+ drv_data->addr1 = i2c_8bit_addr_from_msg(msg);
drv_data->addr2 = 0;
}
}
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
` (6 preceding siblings ...)
2025-02-12 16:32 ` [PATCH v1 7/8] i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers Andy Shevchenko
@ 2025-02-12 16:32 ` Andy Shevchenko
2025-02-12 17:08 ` Fabrizio Castro
7 siblings, 1 reply; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 16:32 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Use i2c_10bit_addr_from_msg() helper instead of local copy.
No functional change intended.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/i2c/busses/i2c-rzv2m.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-rzv2m.c b/drivers/i2c/busses/i2c-rzv2m.c
index 02b76e24a476..55c5ce3b0f97 100644
--- a/drivers/i2c/busses/i2c-rzv2m.c
+++ b/drivers/i2c/busses/i2c-rzv2m.c
@@ -287,13 +287,9 @@ static int rzv2m_i2c_send_address(struct rzv2m_i2c_priv *priv,
int ret;
if (msg->flags & I2C_M_TEN) {
- /*
- * 10-bit address
- * addr_1: 5'b11110 | addr[9:8] | (R/nW)
- * addr_2: addr[7:0]
- */
- addr = 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7);
- addr |= !!(msg->flags & I2C_M_RD);
+ /* 10-bit address */
+ addr = i2c_10bit_addr_from_msg(msg);
+
/* Send 1st address(extend code) */
ret = rzv2m_i2c_write_with_ack(priv, addr);
if (ret)
--
2.45.1.3035.g276e886db78b
^ permalink raw reply related [flat|nested] 21+ messages in thread
* RE: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
@ 2025-02-12 17:06 ` Fabrizio Castro
2025-02-12 18:36 ` Geert Uytterhoeven
2025-02-13 22:40 ` Andi Shyti
2 siblings, 0 replies; 21+ messages in thread
From: Fabrizio Castro @ 2025-02-12 17:06 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Sent: 12 February 2025 16:32
> Subject: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
>
> There are already a lot of drivers that have been using
> i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
> to have the similar for 10-bit addresses.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
> ---
> include/linux/i2c.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 997e80649889..4d281ff5582b 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -952,6 +952,16 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
> return (msg->addr << 1) | (msg->flags & I2C_M_RD);
> }
>
> +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
> +{
> + /*
> + * 10-bit address
> + * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> + * addr_2: addr[7:0]
> + */
> + return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
> +}
> +
> u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
> void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
>
> --
> 2.45.1.3035.g276e886db78b
^ permalink raw reply [flat|nested] 21+ messages in thread
* RE: [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
2025-02-12 16:32 ` [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
@ 2025-02-12 17:08 ` Fabrizio Castro
0 siblings, 0 replies; 21+ messages in thread
From: Fabrizio Castro @ 2025-02-12 17:08 UTC (permalink / raw)
To: Andy Shevchenko, Andi Shyti, Wolfram Sang,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-renesas-soc@vger.kernel.org
Cc: Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Sent: 12 February 2025 16:33
> Subject: [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
>
> Use i2c_10bit_addr_from_msg() helper instead of local copy.
> No functional change intended.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Fabrizio Castro <fabrizio.castro.jz@renesas.com>
> ---
> drivers/i2c/busses/i2c-rzv2m.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-rzv2m.c b/drivers/i2c/busses/i2c-rzv2m.c
> index 02b76e24a476..55c5ce3b0f97 100644
> --- a/drivers/i2c/busses/i2c-rzv2m.c
> +++ b/drivers/i2c/busses/i2c-rzv2m.c
> @@ -287,13 +287,9 @@ static int rzv2m_i2c_send_address(struct rzv2m_i2c_priv *priv,
> int ret;
>
> if (msg->flags & I2C_M_TEN) {
> - /*
> - * 10-bit address
> - * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> - * addr_2: addr[7:0]
> - */
> - addr = 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7);
> - addr |= !!(msg->flags & I2C_M_RD);
> + /* 10-bit address */
> + addr = i2c_10bit_addr_from_msg(msg);
> +
> /* Send 1st address(extend code) */
> ret = rzv2m_i2c_write_with_ack(priv, addr);
> if (ret)
> --
> 2.45.1.3035.g276e886db78b
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 17:06 ` Fabrizio Castro
@ 2025-02-12 18:36 ` Geert Uytterhoeven
2025-02-12 19:04 ` Andy Shevchenko
2025-02-13 22:41 ` Andi Shyti
2025-02-13 22:40 ` Andi Shyti
2 siblings, 2 replies; 21+ messages in thread
From: Geert Uytterhoeven @ 2025-02-12 18:36 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andi Shyti, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Hi Andy,
On Wed, 12 Feb 2025 at 17:35, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> There are already a lot of drivers that have been using
> i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
> to have the similar for 10-bit addresses.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Thanks for your patch!
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -952,6 +952,16 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
> return (msg->addr << 1) | (msg->flags & I2C_M_RD);
> }
>
> +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
Having never used 10-bit addressing myself, or even looked into it,
it took me a while to understand what this helper really does...
So this returns the high byte of the artificial 16-bit address that
must be used to address a target that uses 10-bit addressing?
Hence I think this should be renamed, to better match its purpose.
> +{
> + /*
> + * 10-bit address
> + * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> + * addr_2: addr[7:0]
I think the second comment line does not belong here, as this function
doesn't care about that part.
> + */
> + return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
> +}
Probably you also want to add a similar but much simpler helper to
return the low byte?
> +
> u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold);
> void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);
>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 18:36 ` Geert Uytterhoeven
@ 2025-02-12 19:04 ` Andy Shevchenko
2025-02-13 10:02 ` Wolfram Sang
2025-02-13 11:10 ` Geert Uytterhoeven
2025-02-13 22:41 ` Andi Shyti
1 sibling, 2 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-12 19:04 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Andi Shyti, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
On Wed, Feb 12, 2025 at 07:36:46PM +0100, Geert Uytterhoeven wrote:
> On Wed, 12 Feb 2025 at 17:35, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > There are already a lot of drivers that have been using
> > i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
> > to have the similar for 10-bit addresses.
...
> > +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
>
> Having never used 10-bit addressing myself, or even looked into it,
> it took me a while to understand what this helper really does...
> So this returns the high byte of the artificial 16-bit address that
> must be used to address a target that uses 10-bit addressing?
> Hence I think this should be renamed, to better match its purpose.
Since you are giving a constructive feedback, please, propose the name.
> > +{
> > + /*
> > + * 10-bit address
> > + * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> > + * addr_2: addr[7:0]
>
> I think the second comment line does not belong here, as this function
> doesn't care about that part.
I think the comment is okay to stay. It explains the full picture which is
helpful. It may be extended to say that the function returns only addr_1.
> > + */
> > + return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
> > +}
>
> Probably you also want to add a similar but much simpler helper to
> return the low byte?
Wouldn't it be too much?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 19:04 ` Andy Shevchenko
@ 2025-02-13 10:02 ` Wolfram Sang
2025-02-13 10:54 ` Andy Shevchenko
2025-02-13 13:04 ` Andy Shevchenko
2025-02-13 11:10 ` Geert Uytterhoeven
1 sibling, 2 replies; 21+ messages in thread
From: Wolfram Sang @ 2025-02-13 10:02 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Geert Uytterhoeven, Andi Shyti, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
[-- Attachment #1: Type: text/plain, Size: 161 bytes --]
Just a generic comment: please don't spend too much energy on 10-bit
support. I have never seen it used in the wild. It seems more like an
academic excercise.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-13 10:02 ` Wolfram Sang
@ 2025-02-13 10:54 ` Andy Shevchenko
2025-02-13 13:04 ` Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-13 10:54 UTC (permalink / raw)
To: Wolfram Sang, Geert Uytterhoeven, Andi Shyti, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
On Thu, Feb 13, 2025 at 11:02:55AM +0100, Wolfram Sang wrote:
>
> Just a generic comment: please don't spend too much energy on 10-bit
> support. I have never seen it used in the wild. It seems more like an
> academic excercise.
True, but still it makes sense to reduce the respective code base.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 19:04 ` Andy Shevchenko
2025-02-13 10:02 ` Wolfram Sang
@ 2025-02-13 11:10 ` Geert Uytterhoeven
1 sibling, 0 replies; 21+ messages in thread
From: Geert Uytterhoeven @ 2025-02-13 11:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andi Shyti, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Hi Andy,
On Wed, 12 Feb 2025 at 20:04, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Wed, Feb 12, 2025 at 07:36:46PM +0100, Geert Uytterhoeven wrote:
> > On Wed, 12 Feb 2025 at 17:35, Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > There are already a lot of drivers that have been using
> > > i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
> > > to have the similar for 10-bit addresses.
>
> ...
>
> > > +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
> >
> > Having never used 10-bit addressing myself, or even looked into it,
> > it took me a while to understand what this helper really does...
> > So this returns the high byte of the artificial 16-bit address that
> > must be used to address a target that uses 10-bit addressing?
> > Hence I think this should be renamed, to better match its purpose.
>
> Since you are giving a constructive feedback, please, propose the name.
i2c_10bit_addr_hi_from_msg()?
> > > +{
> > > + /*
> > > + * 10-bit address
> > > + * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> > > + * addr_2: addr[7:0]
> >
> > I think the second comment line does not belong here, as this function
> > doesn't care about that part.
>
> I think the comment is okay to stay. It explains the full picture which is
> helpful. It may be extended to say that the function returns only addr_1.
Or it could be moved outside this function, i.e. at the start of the
section listing all 10-bit address helpers?
>
> > > + */
> > > + return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
> > > +}
> >
> > Probably you also want to add a similar but much simpler helper to
> > return the low byte?
>
> Wouldn't it be too much?
I (my OCD ;-) love symmetry...
i2c_10bit_addr_lo_from_msg()?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-13 10:02 ` Wolfram Sang
2025-02-13 10:54 ` Andy Shevchenko
@ 2025-02-13 13:04 ` Andy Shevchenko
1 sibling, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-13 13:04 UTC (permalink / raw)
To: Wolfram Sang, Geert Uytterhoeven, Andi Shyti, linux-i2c,
linux-kernel, linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
On Thu, Feb 13, 2025 at 11:02:55AM +0100, Wolfram Sang wrote:
>
> Just a generic comment: please don't spend too much energy on 10-bit
> support. I have never seen it used in the wild. It seems more like an
> academic excercise.
Just for the record, AFAICS nomadik, octeon-core, qup, and maybe others
(that are not covered in the series) have bugs for 10-bit address mode.
FWIW, I2C_M_TEN is mentioned in a dozen of drivers outside of
i2c subsystem folder.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 17:06 ` Fabrizio Castro
2025-02-12 18:36 ` Geert Uytterhoeven
@ 2025-02-13 22:40 ` Andi Shyti
2 siblings, 0 replies; 21+ messages in thread
From: Andi Shyti @ 2025-02-13 22:40 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Wolfram Sang, linux-i2c, linux-kernel, linux-arm-kernel,
linux-mediatek, linux-renesas-soc, Krzysztof Adamski,
Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Hi Andy,
On Wed, Feb 12, 2025 at 06:32:26PM +0200, Andy Shevchenko wrote:
> There are already a lot of drivers that have been using
> i2c_8bit_addr_from_msg() for 7-bit addresses, now it's time
> to have the similar for 10-bit addresses.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
...
> +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
> +{
> + /*
> + * 10-bit address
> + * addr_1: 5'b11110 | addr[9:8] | (R/nW)
> + * addr_2: addr[7:0]
> + */
> + return 0xf0 | ((msg->addr & GENMASK(9, 8)) >> 7) | (msg->flags & I2C_M_RD);
> +}
> +
I personally like this patch and it was an item of my todo list.
I'm OK with having it merged.
Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
Andi
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-12 18:36 ` Geert Uytterhoeven
2025-02-12 19:04 ` Andy Shevchenko
@ 2025-02-13 22:41 ` Andi Shyti
2025-02-14 8:04 ` Geert Uytterhoeven
1 sibling, 1 reply; 21+ messages in thread
From: Andi Shyti @ 2025-02-13 22:41 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Andy Shevchenko, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Hi Geert,
> > @@ -952,6 +952,16 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
> > return (msg->addr << 1) | (msg->flags & I2C_M_RD);
> > }
> >
> > +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
>
> Having never used 10-bit addressing myself, or even looked into it,
> it took me a while to understand what this helper really does...
> So this returns the high byte of the artificial 16-bit address that
> must be used to address a target that uses 10-bit addressing?
> Hence I think this should be renamed, to better match its purpose.
It's coherent with i2c_8bit_addr_from_msg(), right?
Andi
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-13 22:41 ` Andi Shyti
@ 2025-02-14 8:04 ` Geert Uytterhoeven
2025-02-14 13:55 ` Andy Shevchenko
0 siblings, 1 reply; 21+ messages in thread
From: Geert Uytterhoeven @ 2025-02-14 8:04 UTC (permalink / raw)
To: Andi Shyti
Cc: Andy Shevchenko, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
Hi Andi,
On Thu, 13 Feb 2025 at 23:41, Andi Shyti <andi.shyti@kernel.org> wrote:
> > > @@ -952,6 +952,16 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg)
> > > return (msg->addr << 1) | (msg->flags & I2C_M_RD);
> > > }
> > >
> > > +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
> >
> > Having never used 10-bit addressing myself, or even looked into it,
> > it took me a while to understand what this helper really does...
> > So this returns the high byte of the artificial 16-bit address that
> > must be used to address a target that uses 10-bit addressing?
> > Hence I think this should be renamed, to better match its purpose.
>
> It's coherent with i2c_8bit_addr_from_msg(), right?
Is it? Unlike i2c_8bit_addr_from_msg(), it does not return the full
address,
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
2025-02-14 8:04 ` Geert Uytterhoeven
@ 2025-02-14 13:55 ` Andy Shevchenko
0 siblings, 0 replies; 21+ messages in thread
From: Andy Shevchenko @ 2025-02-14 13:55 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Andi Shyti, Wolfram Sang, linux-i2c, linux-kernel,
linux-arm-kernel, linux-mediatek, linux-renesas-soc,
Krzysztof Adamski, Florian Fainelli, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Stefan Roese,
Matthias Brugger, AngeloGioacchino Del Regno, Gregory CLEMENT,
Fabrizio Castro
On Fri, Feb 14, 2025 at 09:04:34AM +0100, Geert Uytterhoeven wrote:
...
> > > > +static inline u8 i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
> > >
> > > Having never used 10-bit addressing myself, or even looked into it,
> > > it took me a while to understand what this helper really does...
> > > So this returns the high byte of the artificial 16-bit address that
> > > must be used to address a target that uses 10-bit addressing?
> > > Hence I think this should be renamed, to better match its purpose.
> >
> > It's coherent with i2c_8bit_addr_from_msg(), right?
>
> Is it? Unlike i2c_8bit_addr_from_msg(), it does not return the full
> address,
Yeah, hi/lo together will be coherent, hence I sent a v2 with Geert's
suggestion being incorporated.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2025-02-14 13:55 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 16:32 [PATCH v1 0/8] i2c: busses: Introduce and use i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg() Andy Shevchenko
2025-02-12 17:06 ` Fabrizio Castro
2025-02-12 18:36 ` Geert Uytterhoeven
2025-02-12 19:04 ` Andy Shevchenko
2025-02-13 10:02 ` Wolfram Sang
2025-02-13 10:54 ` Andy Shevchenko
2025-02-13 13:04 ` Andy Shevchenko
2025-02-13 11:10 ` Geert Uytterhoeven
2025-02-13 22:41 ` Andi Shyti
2025-02-14 8:04 ` Geert Uytterhoeven
2025-02-14 13:55 ` Andy Shevchenko
2025-02-13 22:40 ` Andi Shyti
2025-02-12 16:32 ` [PATCH v1 2/8] i2c: axxia: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 3/8] i2c: bcm-kona: " Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 4/8] i2c: eg20t: " Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 5/8] i2c: kempld: " Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 6/8] i2c: mt7621: " Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 7/8] i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers Andy Shevchenko
2025-02-12 16:32 ` [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper Andy Shevchenko
2025-02-12 17:08 ` Fabrizio Castro
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.