-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i2cget doesn't support implicit "next" address (BUS CHIP vs BUS CHIP ADDR) #414
Comments
any idea how larger addresses work in linux? the
|
okay, so it looks like 16-bit addresses aren't a thing, but 10-bit addresses are. they sound pretty unsupported on linux though, judging by https://docs.kernel.org/i2c/ten-bit-addresses.html --- which implies that it's not just the toybox versions of these tools that don't support 10-bit addresses? |
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/i2c-dev.h#L25 doesn't look good either:
|
In Debian distributions we can read and write with i2cset and i2cget to our EEPROM successfully. With the same command line in the toybox tools it doesn't work. https://kernel.googlesource.com/pub/scm/utils/i2c-tools/i2c-tools/+/v3.0.1/tools/i2cset.c |
okay, but even for the data address, the code you linked to seems to have the same limit as toybox. toybox says:
whereas the i2c-tools code has limits of 0x3f, 0x7f, and 0xff respectively? (so the only obvious difference is that -- if i can find a reference confirm that there is a lower limit on bus number -- we should reduce INT_MAX to 0x3f.) can you give a specific command that you claim works with i2c-tools but not with toybox? |
Examples: i2c-tools Prepare to read on bus 1 from device 0x57 at address 0x00 (addres, high byte) 0x40 (address, low byte) toybox Prepare to read on bus 1 from device 0x57 at address 0x00 (addres, high byte) 0x40 (address, low byte) For the first 255 bytes it would work, but what if I wan't to read from address 256 or higher i2c-tools
toybox
|
ah, okay, so the actual bug here is that toybox is
but should be
and you need the "implicit next address" functionality. seems easy enough (i think we just pass -1 to the kernel as the address in that case?), but i probably won't have time to prepare a patch before the weekend. (and i don't have an appropriate i2c device to test with, so you'll have to tell us whether or not it works!) |
I took a wild stab at it (commit e8f2f55) but don't have a test environment set up here? (Can't even tell if I broke it, if somebody could give it a try...) |
heh, that looks exactly like the patch i'd have written, so we're in "fools seldom differ" territory at the very least :-) |
I have a hardware on my table, I tested it. It doesn't work correct. I give an example what I measure on the I2C-bus with the oscilloscope. i2c-tools
toybox
|
We just changed i2cget so if you provide just the bus and chip, it would read the next (first?) available address, which is the ability to provide one LESS argument, not one more. According to https://manpages.debian.org/unstable/i2c-tools/i2cget.8.en.html the usage line there is i2cget [-f] [-y] [-a] i2cbus chip-address [data-address [mode [length]]] which is up to FIVE arguments. And you're providing chip address 1, data address 0x57, mode 0, length 64. Hmmm... I'll see what I can figure out? Still haven't got a test setup for this... |
I'm missing some domain expertise here. I read the "mode parameter" paragraph of the man page 3 times and don't understand the different cases. In linux/i2c.h there's I2C_FUNC_SMBUS_READ_BYTE and also I2C_FUNC_SMBUS_READ_BYTE_DATA and I have no idea the difference between them. See also I2C_FUNC_SMBUS_READ_BLOCK_DATA and I2C_FUNC_SMBUS_READ_I2C_BLOCK with the helpful comment on the second "I2C-like block xfer". I'm gonna try to go find some tutorials. I last used i2c seriously in 2010 and even that was just "bytes at addresses" using the existing command line tools. And if I do change anything: no test environment. (sudo i2cdetect -l on my laptop shows nothing). |
P.S. I still don't think you've given it a ten bit address, which the kernel supports: when the driver returns I2C_M_TEN you can set I2C_M_TEN in the i2c_msg flags. The userspace tool hasn't got an option to say to do so, and the bus definition is insane enough that the 8 bit and 10 bit addresses are completely separate rather than 8 bit naturally being the first quarter of the 10 bit range which is why it can't just autodetect this because always using 10 bit when available means you won't see anything wired to 8 bit, but always using 8 bit for addresses that fit means you won't see those addresses in 10 bit...) I could add a flag for that to toybox, but despite the initial title that doesn't seem to be the problem you're actually having... |
Please forget the 10bit topic. This concerns the device address and has nothing to do with the current topic of 16bit addressing of a cell in the device. For toybox it would be of advantage, if it would support this. i2c-tools can't do this either, i don't think there is a cry for it. By the way, why are there two different tools for linux (toybox and i2c-tools) which support the same functions? Does it make sense to invent the wheel twice? |
With And with |
https://manpages.debian.org/unstable/i2c-tools/i2cget.8.en.html The main problem is @ If the function would only writes an 0x57ra on the bus then it would work |
Do you have access to a raspberry pi4 hardware? |
"Does it make sense to invent the wheel twice." If it didn't Linux wouldn't exist because BSD already existed. You complained: "The message after i2cget -y 1 0x57 0x00 0x40" was "Max 3 arguments", and now you're saying that's an i2cset command line. (i2cset already takes 4 arguments.) I'm confused. |
I think user here wants to use i2cget without giving command byte. So the device will spit out whatever is in its shift register. This can be done by simply reading opened i2c file instead of sending "command" with ioctl. I send patch to mailing list http://lists.landley.net/pipermail/toybox-landley.net/2023-March/029502.html I tested this briefly by reading EDID info out my monitor. Seems to behave more like i2cget i have installed on my distro now. |
I recommend you to get a harware (e.g. EEPROM 24FC128 from Microchip) and test it yourself. By the way with reading EDID toybox will always work. They only have 128 bytes to read. |
Did commit ba5b7c2 help? |
Looks like a step forward. Measured on the bus with the oscilloscope now looks correct. as answer I get in each case The last byte of the return it is the value in the cell. I don't know what the other 3 bytes before are. My cells are: I testes also addresse over 256. Works as well. Good job. I could already live with this solution. However, it would be trustworthy to know what the three bytes before the cell content are and if they are really necessary. |
i suspect it's just uninitialized memory from:
|
Yes integer sized byte variable is most likely containing some extra garbage in some cases. There seems to be also some argument parsing issues if Artifact build with this
And this
behave differently |
Sigh. The reason I haven't given this one more thorough review/cleanup is I'm afraid to introduce regressions without a proper test environment. I'll try to fix this up after lunch. (The argument parsing is missing FORCE_FLAGS: confirm() lives in i2cdetect's flag context but when you only build i2cget standalone then i2cdetext=n which means all its FLAG_y macros are constant 0, which lets the dead code eliminator drop out code that's not used in the current build. FORCE_FLAGS diables that...) |
Give commit 1819be9 a try? |
Works as I expect. |
The functions i2cget and i2cset do not allow 16bit addresses.
But they should be available. There are devices that want to be addressed 16bit.
According the source-code I can't see an option for a workaround.
i2cget BUS CHIP ADDR
i2cset BUS CHIP ADDR VALUE... MODE
In both cases I speak about the parameter ADDR.
The text was updated successfully, but these errors were encountered: