Skip to contentSkip to conversation

i2ctransfer: Add optional message modifier flags

PATCH Applied Benoît Monin 2 participants 3 messages Jun 10 – Jun 11 I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 i2ctransfer: Add optional message modifier flags

Allow setting protocol mangling and repeated start elision flags of an i2c message with a set of optional command-line flags. These optional flags are parsed at the beginning of the DESC field up to a read or write flag.

For example, to read one byte from address 0x50 followed by a stop, then write two bytes at 0x54 on bus 0, one would call i2ctransfer as follow:

    i2ctransfer 0 pr1@0x50 w2@0x54 0x10 0x20

Since the new flags are optional, this patch preserves the compatibility of the i2ctransfer syntax.

Handling of the message flags is done in add_flag_if_supported(). This function checks if the flag is defined at compile time and if the adapter supports the required functionality to handle the flag at runtime.

---
I2C messages can be modified with a set of flags covered by the protocol mangling and the skip repeated start functionalities.

The patch adds the parsing of optional flags to i2ctransfer message description. Those command-line flags then set the i2c message flags alongside the read/write flag.

I wrote these changes to test the insertion of I2C_M_STOP flag in multi-message transactions with i2ctransfer, but the other flags may be useful for various test scenarios.
---
Changes in v5:
- Drop the Unexpected flag error message to fallback on the missing r/w flag.
- Link to v4: https://patch.msgid.link/[email protected]

Changes in v4:
- Rebase on current upstream and drop first patch that has been merged.
- Return an enum from add_flag_if_supported(), to distinguish between the various possible cases.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Use ifdefs to check that the flags and functionalities are known
at compile-time.
- Check that the adapter supports the requested flags before using them
in i2ctransfer.
- Add a warning in i2ctransfer man page about the risk of using these flags.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Document the flags in i2ctransfer.8 man page.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 tools/i2ctransfer.8 |  28 +++++++++-
 tools/i2ctransfer.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 158 insertions(+), 14 deletions(-)
tools/i2ctransfer.8 +27 -1
index 4bdf436..ca41241 100644
@@ -96,8 +96,11 @@ The number of blocks is limited by the Linux Kernel and defined by I2C_RDWR_IOCT
 .I desc
 blocks are composed like this:
 
-.I {r|w}<length_of_message>[@address]
+.I [inpst]{r|w}<length_of_message>[@address]
 
+.TP
+.B [inpst]
+If supported, specifies optional MESSAGE MODIFIER FLAGS. See the section below for details.
 .TP
 .B {r|w}
 specifies if the message is read or write
@@ -141,6 +144,29 @@ decrease value by 1 until end of message (i.e. 0xff- means 0xff, 0xfe, 0xfd, ...
 p
 use value as seed for an 8 bit pseudo random sequence (i.e. 0p means 0x00, 0x50, 0xb0, ...)
 
+.SH "MESSAGE MODIFIER FLAGS"
+.PP
+These optional flags can be used to change the handling of a message when it is sent on the bus.
+They allow you to deviate from the I2C standard to work around device issues.
+They should be used with care, as they can confuse your I2C bus.
+Note that not all flags (or any) may be supported by your particular hardware and your kernel version.
+
+.TP
+.B i
+ignore NACK from client, treat them as ACK.
+.TP
+.B n
+in a read message, master ACK/NACK bit is skipped.
+.TP
+.B p
+emit a STOP after the message.
+.TP
+.B s
+skip repeated start.
+.TP
+.B t
+toggle read/write bit.
+
 .SH EXAMPLES
 .PP
 On bus 0, from an EEPROM at address 0x50, read 8 byte from offset 0x64
tools/i2ctransfer.c +131 -13

199 lines not on this page · raw message

---
base-commit: ec1267371e378fc6aaf1cd7686b5b9b31293255a
change-id: 20251127-msg-flags-3d2b2da9ae28

Best regards,

Signature · 3 lines
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Applied
#1 lore raw

Hi Benoît,

Quoted 9 lines · Benoît Monin

Allow setting protocol mangling and repeated start elision flags of an i2c message with a set of optional command-line flags. These optional flags are parsed at the beginning of the DESC field up to a read or write flag.

For example, to read one byte from address 0x50 followed by a stop, then write two bytes at 0x54 on bus 0, one would call i2ctransfer as follow:

    i2ctransfer 0 pr1@0x50 w2@0x54 0x10 0x20
Quoted 8 lines

Since the new flags are optional, this patch preserves the compatibility of the i2ctransfer syntax.

Handling of the message flags is done in add_flag_if_supported(). This function checks if the flag is defined at compile time and if the adapter supports the required functionality to handle the flag at runtime.

Applied, thank you!

It would be awesome if the PRINT_HEADER part could be extended to display to the user the flags used per message, if any. As an incremental patch. I don't know if you have time for that?

Happy hacking,

Wolfram

#2 lore raw

Hi Wolfram,

Quoted 2 lines · Wolfram Sang

Applied, thank you!

Thanks!

Quoted 4 lines

It would be awesome if the PRINT_HEADER part could be extended to display to the user the flags used per message, if any. As an incremental patch. I don't know if you have time for that?

I was thinking about that, I'll add it to my todo list. No ETA :)

Best regards,

Signature · 3 lines
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com