i2c: busses: Introduce and use i2c_10bit_addr_from_msg()
Subsystems (7)
cover i2c: busses: Introduce and use i2c_10bit_addr_from_msg()
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(-)
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 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.
--- include/linux/i2c.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/i2c.h +10 -0
@@ -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);
Signature · 1 line
2.45.1.3035.g276e886db78b
RE: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
Quoted 9 lines
From: Andy Shevchenko <[email protected]>
Sent: 12 February 2025 16:32
Subject: [PATCH v1 1/8] i2c: Introducei2c_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 <[email protected]>
Quoted 27 lines
--- include/linux/i2c.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/linux/i2c.h +10
-1@@ -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
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
In reply to Andy ShevchenkoHi Andy,
Quoted 5 lines · Andy Shevchenko
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 <[email protected]>
Thanks for your patch!
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 955
Quoted 7 lines
include/linux/i2c.h +1
-0@@ -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.
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 960
Quoted 5 lines
include/linux/i2c.h +5
-0+{ +/* +* 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.
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 963
Quoted 3 lines
include/linux/i2c.h +3
-0+*/ +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?
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 967
Quoted 4 lines
include/linux/i2c.h +1
-0+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 -- [email protected]
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
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
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.
...
Quoted 7 lines
Quoted 1 line
+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.
Quoted 8 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 960
Quoted 5 lines
include/linux/i2c.h +5
-0+{ +/* +* 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.
Quoted 6 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 963
Quoted 3 lines
include/linux/i2c.h +3
-0+*/ +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?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
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.
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
Quoted 4 lines · Wolfram Sang
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
In reply to Wolfram SangQuoted 4 lines · Wolfram Sang
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
In reply to Andy ShevchenkoHi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 5 lines · Geert Uytterhoeven
Quoted 3 lines · Andy Shevchenko
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....
Quoted 2 lines
Quoted 1 line
+static inline u8
i2c_10bit_addr_from_msg(const struct i2c_msg *msg)
Quoted 7 lines
Quoted 5 lines
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()?
Quoted 11 lines
Quoted 8 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 960
Quoted 5 lines
include/linux/i2c.h +5
-0+{ +/* +* 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?
Quoted 9 lines
Quoted 7 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 963
Quoted 4 lines
include/linux/i2c.h +3
-0+*/ +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
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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
Andi Shyti
maintainerRe: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
In reply to Geert UytterhoevenHi Geert,
Quoted 11 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 955
Quoted 5 lines
include/linux/i2c.h +1
-0@@ -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
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
Hi Andi,
Quoted 12 lines · Andi Shyti
Quoted 11 lines
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 955
Quoted 5 lines
include/linux/i2c.h +1
-0@@ -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.
Quoted 1 line
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
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] 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
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
On Fri, Feb 14, 2025 at 09:04:34AM +0100, Geert Uytterhoeven wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
+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.
Quoted 4 lines
Quoted 1 line
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/8] i2c: Introduce i2c_10bit_addr_from_msg()
In reply to Andy ShevchenkoHi Andy,
Quoted 5 lines · Andy Shevchenko
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 <[email protected]>
...
include/linux/i2c.h static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) · line 964
Quoted 10 lines
include/linux/i2c.h +10
-0+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.
Andi
PATCH 2/8 i2c: axxia: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-axxia.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-)
drivers/i2c/busses/i2c-axxia.c +2 -17
@@ -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 ; }
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 3/8 i2c: bcm-kona: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-bcm-kona.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-bcm-kona.c +4 -5
@@ -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 ; }
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 4/8 i2c: eg20t: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-eg20t.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-)
drivers/i2c/busses/i2c-eg20t.c +5 -23
@@ -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 );
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 5/8 i2c: kempld: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-kempld.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-kempld.c +1 -3
@@ -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);
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 6/8 i2c: mt7621: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-mt7621.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-mt7621.c +1 -3
@@ -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)
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 7/8 i2c: mv64xxx: Use i2c_*bit_addr_from_msg() helpers
In reply to Andy ShevchenkoUse i2c_*bit_addr_from_msg() helpers instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-mv64xxx.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-mv64xxx.c +2 -8
@@ -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 ; } }
Signature · 1 line
2.45.1.3035.g276e886db78b
PATCH 8/8 i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
In reply to Andy ShevchenkoUse i2c_10bit_addr_from_msg() helper instead of local copy. No functional change intended.
--- drivers/i2c/busses/i2c-rzv2m.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-rzv2m.c +3 -7
@@ -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)
Signature · 1 line
2.45.1.3035.g276e886db78b
RE: [PATCH v1 8/8] i2c: rzv2m: Use i2c_10bit_addr_from_msg() helper
Quoted 8 lines
From: Andy Shevchenko <[email protected]>
Sent: 12 February 2025 16:33
Subject: [PATCH v1 8/8] i2c: rzv2m: Usei2c_10bit_addr_from_msg()helperUse
i2c_10bit_addr_from_msg()helper instead of local copy. No functional change intended.Signed-off-by Andy Shevchenko <[email protected]>
Quoted 27 lines
--- drivers/i2c/busses/i2c-rzv2m.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/i2c/busses/i2c-rzv2m.c +3
-8@@ -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