10-bit address support
Subsystems (2)
Hi all,
After Sheng-Hui's fix to i2c-algo-bit, it would seem that we are almost there with 10-bit slave address support. There's one remaining thing that worries me though: the 7-bit and 10-bit address spaces overlap.
Quoted 1 line
From
Documentation/i2c/ten-bit-addresses:
"The sets of addresses do not intersect: the 7 bit address 0x10 is not the same as the 10 bit address 0x10 (though a single device could respond to both of them)."
So for example, if on a given system you have two devices on I2C bus segment 0, one responding to 7-bit address 0x2d and another responding to 10-bit address 0x2d, they will have the same device name 0-002d, meaning that instantiating the second one will fail.
Now I agree that this is extremely unlikely to happen, considering how rare 10-bit addresses are in the first place. Still I think we should fix this now, before the first 10-bit address I2C device gets supported by the Linux kernel.
I can think of 2 different ways of addressing the problem.
First way is to use a different device name format for 10-bit address devices, for example %d-10bit-%04x. This has the drawback that some user-space applications and libraries may not recognize these as valid i2c device names. libsensors and sensors-detect would be amongst these.
Second way is to add an offset to the 10-bit addresses, to avoid the overlap. The minimum offset is 0x80, but that would translate for example 0x2d to 0xad, which is not obviously "10-bit address 0x2d". So I'd rather go with a larger offset such as 0x1000. This translates 0x2d to 0x102d which is more obviously "10-bit address 0x2d". We have 16 bits to store the address so it shouldn't be an issue. Another possible offset would be 0xa000 (as 0xa is 10.)
Given how rare 10-bit addresses are, the second option has my favors. So my plan is to apply the following fix:
From: Jean Delvare <[email protected]>
Subject: i2c: Fix device name for 10-bit slave address
10-bit addresses overlap with traditional 7-bit addresses, leading in device name collisions. Add an arbitrary offset to 10-bit addresses to prevent this collision. The offset was chosen so that the address is still easily recognizable.
--- drivers/i2c/i2c-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core.c +3 -1
@@ -539,8 +539,10 @@ i2c_new_device(struct i2c_adapter *adap, client->dev.type = &i2c_client_type; client->dev.of_node = info->of_node; +/* For 10-bit clients, add an arbitrary offset to avoid collisions */ dev_set_name (&client->dev,"%d-%04x" ,i2c_adapter_id (adap), - client->addr); + client->addr | ((client->flags &I2C_CLIENT_TEN ) + ?0x1000 :0 )); status =device_register (&client->dev);if (status) goto out_err;
Anyone please let me know quickly if you have any objection.
Individual bus drivers may still need to be fixed to properly support 10-bit addresses, and user-space tools as well as they currently don't support them at all, but this can be added later on as needed.
Signature · 1 line
Jean Delvare
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 16 lines
-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Thursday, November 10, 2011 10:08 AM
To: Linux I2C
Cc: Jeffrey (Sheng-Hui) Chu
Subject: 10-bit address supportHi all,
After Sheng-Hui's fix to i2c-algo-bit, it would seem that we are almost there with 10-bit slave address support. There's one remaining thing that worries me though: the 7-bit and 10-bit address spaces overlap. From
Documentation/i2c/ten-bit-addresses:
Quoted 5 lines
"The sets of addresses do not intersect: the 7 bit address
0x10is not the same as the 10 bit address0x10(though a single device could respond to both of them)."From my understanding of the spec, there is no overlap.
The 10-bit client at 0x10 will be addressed by the following address sequence:0Xf0 0X10 <data-out> or 0xf0 0x10 <restart> 0xf1<data-in>
The 7-bit client at 0x10 will be addressed by the following address sequence:0x20 <data-out> or 0x21 <data-in>
0xf0 is equivalent to 7-bit address of 0x78 which is a reserved address in 7-bit space. A compliant 7-bit client should not use or respond to this address.
<snip>
Quoted 2 lines
--
Jean Delvare
Don't need to do any workaround. IMHO
Regards,
-Jeffrey
A message that is not in the archive (sent off-list or not yet received): B6A520E9CD57404AAFC0831E4FB39541AE68602AD7-4wnuKdaqIVJdD26/[email protected]
Quoted 20 lines · Jeffrey (Sheng-Hui) Chu
Quoted 11 lines
-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Thursday, November 10, 2011 10:08 AM
To: Linux I2C
Cc: Jeffrey (Sheng-Hui) Chu
Subject: 10-bit address supportHi all,
Quoted 8 lines
After Sheng-Hui's fix to i2c-algo-bit, it would seem that we are almost there with 10-bit slave address support. There's one remaining thing that worries me though: the 7-bit and 10-bit address spaces overlap. From
Documentation/i2c/ten-bit-addresses:"The sets of addresses do not intersect: the 7 bit address
0x10is not the same as the 10 bit address0x10(though a single device could respond to both of them)."
Quoted 8 lines
From my understanding of the spec, there is no overlap.
The 10-bit client at0x10will be addressed by the following address sequence:0Xf00X10<data-out> or0xf00x10<restart> 0xf1<data-in>The 7-bit client at
0x10will be addressed by the following address sequence:0x20<data-out> or0x21<data-in>
0xf0is equivalent to 7-bit address of0x78which is a reserved address in 7-bit space. A compliant 7-bit client should not use or respond to this address.
what you wrote above is completely exact, but is also completely unrelated to what I explained. The overlapping that currently exists is in the device names inside the kernel. It's a pure software issue.
Quoted 1 line
Don't need to do any workaround. IMHO
I'm certain we do.
Signature · 1 line
Jean Delvare
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 44 lines
-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Thursday, November 10, 2011 11:33 AM
To: Jeffrey (Sheng-Hui) Chu
Cc: Linux I2C
Subject: Re: 10-bit address supportQuoted 16 lines · Jeffrey (Sheng-Hui) Chu
Quoted 16 lines
-----Original Message-----
From: Jean Delvare [mailto:[email protected]]
Sent: Thursday, November 10, 2011 10:08 AM
To: Linux I2C
Cc: Jeffrey (Sheng-Hui) Chu
Subject: 10-bit address supportHi all,
After Sheng-Hui's fix to i2c-algo-bit, it would seem that we are almost there with 10-bit slave address support. There's one remaining thing that worries me though: the 7-bit and 10-bit address spaces overlap. From
Documentation/i2c/ten-bit-addresses:Quoted 6 lines
Quoted 3 lines
"The sets of addresses do not intersect: the 7 bit address
0x10is not the same as the 10 bit address0x10(though a single device could respond to both of them)."From my understanding of the spec, there is no overlap. The 10-bit client at
0x10will be addressed by the following addresssequence:
Quoted 3 lines
0Xf00X10<data-out> or0xf00x10<restart> 0xf1<data-in>The 7-bit client at
0x10will be addressed by the following addresssequence:
Quoted 3 lines
0x20<data-out> or0x21<data-in>
0xf0is equivalent to 7-bit address of0x78which is a reserved address in 7-bit space. A compliant 7-bit client should not use or respond to this address.
what you wrote above is completely exact, but is also completely unrelated to what I explained. The overlapping that currently exists is in the device names inside the kernel. It's a pure software issue.
Quoted 6 lines
Quoted 1 line
Don't need to do any workaround. IMHO
I'm certain we do.
--
Jean Delvare
You're right. It's my misunderstanding.
Regards,
-Jeffrey
Hi Jean,
Quoted 6 lines
I can think of 2 different ways of addressing the problem.
First way is to use a different device name format for 10-bit address devices, for example %d-10bit-%04x. This has the drawback that some user-space applications and libraries may not recognize these as valid i2c device names. libsensors and sensors-detect would be amongst these.
Wouldn't the cleanest solution be
"%d-%02x" for 7 bit
"%d-%04x" for 10 bit?
Yeah, I know that would really break userspace.
Quoted 4 lines
I'd rather go with a larger offset such as
0x1000. This translates0x2dto0x102dwhich is more obviously "10-bit address0x2d". We have 16 bits to store the address so it shouldn't be an issue. Another possible offset would be0xa000(as0xais 10.)
I like 0xa000 a tad better than 0x1000, but well... Then again, those devices are probably rare enough to take a non-intrusive approach.
Regards,
Wolfram
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Wolfram,
Quoted 11 lines · Wolfram Sang
Quoted 6 lines
I can think of 2 different ways of addressing the problem.
First way is to use a different device name format for 10-bit address devices, for example %d-10bit-%04x. This has the drawback that some user-space applications and libraries may not recognize these as valid i2c device names. libsensors and sensors-detect would be amongst these.
Wouldn't the cleanest solution be
"%d-%02x" for 7 bit
"%d-%04x" for 10 bit?
I'd rather use %03x for 10-bit then, for consistency.
Quoted 1 line
Yeah, I know that would really break userspace.
Yes indeed. While it wouldn't break libsensors (which uses sscanf "%hd-%x" to parse the fields), it would break at least sensors-detect, which really expects 4 hex digits in the sysfs name. This would definitely be a change in the user-space interface anyway, who knows which other tools would be affected.
Your solution was elegant (although it has its own drawbacks, such as leaving it to every library and application to come up with a creative way to handle and store 10-bit addresses separately from 7-bit addresses internally), but unfortunately it would have had to be implemented in the early days, not 8 years later.
Quoted 7 lines
Quoted 4 lines
I'd rather go with a larger offset such as
0x1000. This translates0x2dto0x102dwhich is more obviously "10-bit address0x2d". We have 16 bits to store the address so it shouldn't be an issue. Another possible offset would be0xa000(as0xais 10.)I like
0xa000a tad better than0x1000, but well... Then again, those devices are probably rare enough to take a non-intrusive approach.
Yes I agree, we really want to leave 7-bit addresses unaffected by the change.
0xa000 is not more intrusive than 0x1000, so if the majority - i.e. you ;) - is in favor of this, that's fine with me. I'll send a patch later today.
Thanks,
Signature · 1 line
Jean Delvare
A message that is not in the archive (sent off-list or not yet received): [email protected]
Wolfram Sang
Acked-byHi Jean,
Quoted 6 lines
Quoted 4 lines
Wouldn't the cleanest solution be
"%d-%02x" for 7 bit
"%d-%04x" for 10 bit?I'd rather use %03x for 10-bit then, for consistency.
Yup, I realized this a few hours later, too. This would leave the possibility to add true 16-bit addressing of the next to be i2c standard ;)
Quoted 2 lines
internally), but unfortunately it would have had to be implemented in the early days, not 8 years later.
Yes, and hopefully we can live with this drawback well enough.
Quoted 3 lines
0xa000is not more intrusive than0x1000, so if the majority - i.e. you ;) - is in favor of this, that's fine with me. I'll send a patch later today.
You can already add my:
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · Wolfram Sang
Hi Jean,
Quoted 2 lines
Quoted 2 lines
Wouldn't the cleanest solution be
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
"%d-%02x" for 7 bit
"%d-%04x" for 10 bit?I'd rather use %03x for 10-bit then, for consistency.
Yup, I realized this a few hours later, too. This would leave the possibility to add true 16-bit addressing of the next to be i2c standard ;)
Given the fiasco 10-bit address support was, I doubt we'll see any attempt to further extend the address space. The protocol penalty of 10-bit addressing is heavy and 7-bit addresses are often sufficient in practice. Where they are not, designers have resorted to using muxes and switches rather than 10-bit addresses.
Quoted 5 lines
Quoted 2 lines
internally), but unfortunately it would have had to be implemented in the early days, not 8 years later.
Yes, and hopefully we can live with this drawback well enough.
Quoted 7 lines
Quoted 3 lines
0xa000is not more intrusive than0x1000, so if the majority - i.e. you ;) - is in favor of this, that's fine with me. I'll send a patch later today.You can already add my:
Acked-by Wolfram Sang <[email protected]>
Thanks,
Signature · 1 line
Jean Delvare