* [PATCH i2c-tools v2 0/2] Add support for message modifier flags
@ 2025-12-23 13:22 Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Benoît Monin @ 2025-12-23 13:22 UTC (permalink / raw)
To: linux-i2c; +Cc: Jean Delvare, Thomas Petazzoni, Benoît Monin
I2C messages can be modified with a set of flags covered by the protocol
mangling and the skip repeated start functionalities. This series add
support for such flags to i2cdetect and i2ctransfer.
The first patch shows the support of protocol mangling and repeated
start skipping in the output of 'i2cdetect -F'.
The second 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 can be
useful for various test scenarios.
The patches use defines that have been present in the kernel since
v3.6 released in 2012. If compatibility with older kernel is required,
we will need to wrap some of them with #ifndef ... #endif.
Maybe a minimum kernel version can be documented in the README?
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
Changes in v2:
- Document the flags in i2ctransfer.8 man page.
- Link to v1: https://lore.kernel.org/r/20251128-msg-flags-v1-0-6353f26fa6bc@bootlin.com
---
Benoît Monin (2):
i2cdetect: Display mangling and nostart support
i2ctransfer: Add optional message modifier flags
tools/i2cdetect.c | 4 ++++
tools/i2ctransfer.8 | 26 +++++++++++++++++++++++++-
tools/i2ctransfer.c | 34 +++++++++++++++++++++++++---------
3 files changed, 54 insertions(+), 10 deletions(-)
---
base-commit: ea51da725b743da00b894dfdc4ab189f5a51e90e
change-id: 20251127-msg-flags-3d2b2da9ae28
Best regards,
--
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
@ 2025-12-23 13:22 ` Benoît Monin
2026-01-13 17:22 ` Wolfram Sang
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Benoît Monin @ 2025-12-23 13:22 UTC (permalink / raw)
To: linux-i2c; +Cc: Jean Delvare, Thomas Petazzoni, Benoît Monin
Show the support of protocol mangling and repeated start elision in the
list of fonctionnalities displayed with '-F'.
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
tools/i2cdetect.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/i2cdetect.c b/tools/i2cdetect.c
index bb2f146..70b585d 100644
--- a/tools/i2cdetect.c
+++ b/tools/i2cdetect.c
@@ -165,6 +165,10 @@ static const struct func all_func[] = {
{ .value = I2C_FUNC_SLAVE,
.name = "Target mode" },
#endif
+ { .value = I2C_FUNC_PROTOCOL_MANGLING,
+ .name = "Protocol mangling" },
+ { .value = I2C_FUNC_NOSTART,
+ .name = "Skip repeated start" },
{ .value = 0, .name = "" }
};
--
2.52.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
@ 2025-12-23 13:22 ` Benoît Monin
2026-01-13 17:33 ` Wolfram Sang
2026-01-20 14:45 ` Jean Delvare
2026-01-13 17:21 ` [PATCH i2c-tools v2 0/2] Add support for " Wolfram Sang
2026-01-20 14:15 ` Jean Delvare
3 siblings, 2 replies; 12+ messages in thread
From: Benoît Monin @ 2025-12-23 13:22 UTC (permalink / raw)
To: linux-i2c; +Cc: Jean Delvare, Thomas Petazzoni, 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
Since the new flags are optional, this patch preserves the compatibility
of the i2ctransfer syntax.
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
tools/i2ctransfer.8 | 26 +++++++++++++++++++++++++-
tools/i2ctransfer.c | 34 +++++++++++++++++++++++++---------
2 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/tools/i2ctransfer.8 b/tools/i2ctransfer.8
index 4bdf436..45c744d 100644
--- a/tools/i2ctransfer.8
+++ b/tools/i2ctransfer.8
@@ -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]
+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,27 @@ 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.
+Note that not all flags (or any) may be supported by your particular hardware.
+
+.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
diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
index 4db98e3..921ffaa 100644
--- a/tools/i2ctransfer.c
+++ b/tools/i2ctransfer.c
@@ -52,9 +52,16 @@ static void help(void)
" -V version info\n"
" -y yes to all confirmations\n"
" I2CBUS is an integer or an I2C bus name\n"
- " DESC describes the transfer in the form: {r|w}LENGTH[@address]\n"
- " 1) read/write-flag 2) LENGTH (range 0-65535, or '?')\n"
- " 3) I2C address (use last one if omitted)\n"
+ " DESC describes the transfer in the form: [inpst]{r|w}LENGTH[@address]\n"
+ " 1) optional message modifier flags\n"
+ " i: ignore NACK from client\n"
+ " n: no master ACK/NACK bit in a read message\n"
+ " p: emit a STOP after the message\n"
+ " s: skip repeated start\n"
+ " t: toggle read/write bit\n"
+ " 2) mandatory read/write flag\n"
+ " 3) LENGTH (range 0-65535, or '?')\n"
+ " 4) I2C address (use last one if omitted)\n"
" DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
" = (keep value constant until LENGTH)\n"
" + (increase value by 1 until LENGTH)\n"
@@ -202,12 +209,21 @@ int main(int argc, char *argv[])
case PARSE_GET_DESC:
flags = 0;
- switch (*arg_ptr++) {
- case 'r': flags |= I2C_M_RD; break;
- case 'w': break;
- default:
- fprintf(stderr, "Error: Invalid direction\n");
- goto err_out_with_arg;
+ for (int done = 0; !done; ) {
+ switch (*arg_ptr++) {
+ /* optional flags */
+ case 'i': flags |= I2C_M_IGNORE_NAK; break;
+ case 'n': flags |= I2C_M_NO_RD_ACK; break;
+ case 'p': flags |= I2C_M_STOP; break;
+ case 's': flags |= I2C_M_NOSTART; break;
+ case 't': flags |= I2C_M_REV_DIR_ADDR; break;
+ /* mandatory flags */
+ case 'r': flags |= I2C_M_RD; done = 1; break;
+ case 'w': done = 1; break;
+ default:
+ fprintf(stderr, "Error: Invalid flag\n");
+ goto err_out_with_arg;
+ }
}
if (*arg_ptr == '?') {
--
2.52.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 0/2] Add support for message modifier flags
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
@ 2026-01-13 17:21 ` Wolfram Sang
2026-01-20 14:15 ` Jean Delvare
3 siblings, 0 replies; 12+ messages in thread
From: Wolfram Sang @ 2026-01-13 17:21 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Jean Delvare, Thomas Petazzoni
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
Hi Benoît,
> The patches use defines that have been present in the kernel since
> v3.6 released in 2012. If compatibility with older kernel is required,
> we will need to wrap some of them with #ifndef ... #endif.
>
> Maybe a minimum kernel version can be documented in the README?
I'd rather have a little ifdeffery here. It should not be much, let's
have a look in the actual patches.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
@ 2026-01-13 17:22 ` Wolfram Sang
0 siblings, 0 replies; 12+ messages in thread
From: Wolfram Sang @ 2026-01-13 17:22 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Jean Delvare, Thomas Petazzoni
[-- Attachment #1: Type: text/plain, Size: 384 bytes --]
> @@ -165,6 +165,10 @@ static const struct func all_func[] = {
> { .value = I2C_FUNC_SLAVE,
> .name = "Target mode" },
> #endif
> + { .value = I2C_FUNC_PROTOCOL_MANGLING,
> + .name = "Protocol mangling" },
> + { .value = I2C_FUNC_NOSTART,
> + .name = "Skip repeated start" },
As we can see from entries above, the ifdeffery wouldn't be too bad for
those two, I'd think.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
@ 2026-01-13 17:33 ` Wolfram Sang
2026-01-16 13:01 ` Benoît Monin
2026-01-20 14:45 ` Jean Delvare
1 sibling, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2026-01-13 17:33 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Jean Delvare, Thomas Petazzoni
[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]
> --- a/tools/i2ctransfer.8
> +++ b/tools/i2ctransfer.8
> @@ -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]
> +specifies optional MESSAGE MODIFIER FLAGS. See the section below for details.
The documentation needs just a slight update like "if supported". It
depends not only on the Linux version but the controller driver anyhow.
> +++ b/tools/i2ctransfer.c
> @@ -52,9 +52,16 @@ static void help(void)
> " -V version info\n"
> " -y yes to all confirmations\n"
> " I2CBUS is an integer or an I2C bus name\n"
> - " DESC describes the transfer in the form: {r|w}LENGTH[@address]\n"
> - " 1) read/write-flag 2) LENGTH (range 0-65535, or '?')\n"
> - " 3) I2C address (use last one if omitted)\n"
> + " DESC describes the transfer in the form: [inpst]{r|w}LENGTH[@address]\n"
> + " 1) optional message modifier flags\n"
> + " i: ignore NACK from client\n"
> + " n: no master ACK/NACK bit in a read message\n"
> + " p: emit a STOP after the message\n"
> + " s: skip repeated start\n"
> + " t: toggle read/write bit\n"
> + " 2) mandatory read/write flag\n"
> + " 3) LENGTH (range 0-65535, or '?')\n"
> + " 4) I2C address (use last one if omitted)\n"
Same here. I think the help text can be static by saying "if supported"
> " DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
> " = (keep value constant until LENGTH)\n"
> " + (increase value by 1 until LENGTH)\n"
> @@ -202,12 +209,21 @@ int main(int argc, char *argv[])
> case PARSE_GET_DESC:
> flags = 0;
>
> - switch (*arg_ptr++) {
> - case 'r': flags |= I2C_M_RD; break;
> - case 'w': break;
> - default:
> - fprintf(stderr, "Error: Invalid direction\n");
> - goto err_out_with_arg;
> + for (int done = 0; !done; ) {
> + switch (*arg_ptr++) {
> + /* optional flags */
> + case 'i': flags |= I2C_M_IGNORE_NAK; break;
> + case 'n': flags |= I2C_M_NO_RD_ACK; break;
> + case 'p': flags |= I2C_M_STOP; break;
> + case 's': flags |= I2C_M_NOSTART; break;
> + case 't': flags |= I2C_M_REV_DIR_ADDR; break;
Brainstorming here: maybe a macro could help:
case 'i': add_flag_if_supported(flags, I2C_M_IGNORE_NAK);
?
Thanks and happy hacking,
Wolfram
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
2026-01-13 17:33 ` Wolfram Sang
@ 2026-01-16 13:01 ` Benoît Monin
2026-01-20 15:06 ` Jean Delvare
0 siblings, 1 reply; 12+ messages in thread
From: Benoît Monin @ 2026-01-16 13:01 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c, Jean Delvare, Thomas Petazzoni
On Tuesday, 13 January 2026 at 18:33:53 CET, Wolfram Sang wrote:
[...]
> > " DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
> > " = (keep value constant until LENGTH)\n"
> > " + (increase value by 1 until LENGTH)\n"
> > @@ -202,12 +209,21 @@ int main(int argc, char *argv[])
> > case PARSE_GET_DESC:
> > flags = 0;
> >
> > - switch (*arg_ptr++) {
> > - case 'r': flags |= I2C_M_RD; break;
> > - case 'w': break;
> > - default:
> > - fprintf(stderr, "Error: Invalid direction\n");
> > - goto err_out_with_arg;
> > + for (int done = 0; !done; ) {
> > + switch (*arg_ptr++) {
> > + /* optional flags */
> > + case 'i': flags |= I2C_M_IGNORE_NAK; break;
> > + case 'n': flags |= I2C_M_NO_RD_ACK; break;
> > + case 'p': flags |= I2C_M_STOP; break;
> > + case 's': flags |= I2C_M_NOSTART; break;
> > + case 't': flags |= I2C_M_REV_DIR_ADDR; break;
>
> Brainstorming here: maybe a macro could help:
>
> case 'i': add_flag_if_supported(flags, I2C_M_IGNORE_NAK);
>
> ?
>
I am having a hard time coming up with something here. There is the
__is_defined() macro in the kernel source[1], it only returns 0 or 1, not
the value of the define.
Maybe defining as zero the flags that are undefined would be acceptable?
E.g.
#ifndef I2C_M_IGNORE_NAK
#define I2C_M_IGNORE_NAK 0
#endif
Or you have another idea?
[1]: https://elixir.bootlin.com/linux/v6.19-rc5/source/tools/include/linux/kconfig.h#L35
Thanks for the review!
--
Benoît
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 0/2] Add support for message modifier flags
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
` (2 preceding siblings ...)
2026-01-13 17:21 ` [PATCH i2c-tools v2 0/2] Add support for " Wolfram Sang
@ 2026-01-20 14:15 ` Jean Delvare
2026-01-21 10:00 ` Benoît Monin
3 siblings, 1 reply; 12+ messages in thread
From: Jean Delvare @ 2026-01-20 14:15 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Thomas Petazzoni, Wolfram Sang
Hi Benoït, hi Wolfram,
On Tue, 23 Dec 2025 14:22:41 +0100, Benoît Monin wrote:
> I2C messages can be modified with a set of flags covered by the protocol
> mangling and the skip repeated start functionalities. This series add
> support for such flags to i2cdetect and i2ctransfer.
>
> The first patch shows the support of protocol mangling and repeated
> start skipping in the output of 'i2cdetect -F'.
>
> The second 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 can be
> useful for various test scenarios.
Out of curiosity, did you have an actual scenario where you needed to
do this? Protocol mangling is supposed to be rarely needed and avoided
as much as possible.
> The patches use defines that have been present in the kernel since
> v3.6 released in 2012. If compatibility with older kernel is required,
> we will need to wrap some of them with #ifndef ... #endif.
>
> Maybe a minimum kernel version can be documented in the README?
Be careful if you do. Kernel versions are a very broad indicator,
distribution kernel maintainers keep backporting features so an older
kernel can actually support something when its version suggests it
wouldn't. A kernel version should always be complemented with the actual
feature or flag so that users can look it up if needed.
>
> Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
> ---
> Changes in v2:
> - Document the flags in i2ctransfer.8 man page.
> - Link to v1: https://lore.kernel.org/r/20251128-msg-flags-v1-0-6353f26fa6bc@bootlin.com
>
> ---
> Benoît Monin (2):
> i2cdetect: Display mangling and nostart support
> i2ctransfer: Add optional message modifier flags
>
> tools/i2cdetect.c | 4 ++++
> tools/i2ctransfer.8 | 26 +++++++++++++++++++++++++-
> tools/i2ctransfer.c | 34 +++++++++++++++++++++++++---------
> 3 files changed, 54 insertions(+), 10 deletions(-)
> ---
> base-commit: ea51da725b743da00b894dfdc4ab189f5a51e90e
> change-id: 20251127-msg-flags-3d2b2da9ae28
I have read Wolfram's review of your patch set (thanks Wolfram!) and
must say I agree with everything he wrote.
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
2026-01-13 17:33 ` Wolfram Sang
@ 2026-01-20 14:45 ` Jean Delvare
1 sibling, 0 replies; 12+ messages in thread
From: Jean Delvare @ 2026-01-20 14:45 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Thomas Petazzoni, Wolfram Sang
On Tue, 23 Dec 2025 14:22:43 +0100, Benoît Monin wrote:
> @@ -202,12 +209,21 @@ int main(int argc, char *argv[])
> case PARSE_GET_DESC:
> flags = 0;
>
> - switch (*arg_ptr++) {
> - case 'r': flags |= I2C_M_RD; break;
> - case 'w': break;
> - default:
> - fprintf(stderr, "Error: Invalid direction\n");
> - goto err_out_with_arg;
> + for (int done = 0; !done; ) {
For compatibility with older C compilers, please declare "done" at the
beginning of the while loop.
> + switch (*arg_ptr++) {
> + /* optional flags */
> + case 'i': flags |= I2C_M_IGNORE_NAK; break;
> + case 'n': flags |= I2C_M_NO_RD_ACK; break;
> + case 'p': flags |= I2C_M_STOP; break;
> + case 's': flags |= I2C_M_NOSTART; break;
> + case 't': flags |= I2C_M_REV_DIR_ADDR; break;
> + /* mandatory flags */
I would write "mandatory direction flag" (singular because only one can
and must be present).
> + case 'r': flags |= I2C_M_RD; done = 1; break;
> + case 'w': done = 1; break;
> + default:
> + fprintf(stderr, "Error: Invalid flag\n");
> + goto err_out_with_arg;
> + }
> }
>
> if (*arg_ptr == '?') {
>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags
2026-01-16 13:01 ` Benoît Monin
@ 2026-01-20 15:06 ` Jean Delvare
0 siblings, 0 replies; 12+ messages in thread
From: Jean Delvare @ 2026-01-20 15:06 UTC (permalink / raw)
To: Benoît Monin; +Cc: Wolfram Sang, linux-i2c, Thomas Petazzoni
Hi Benoît,
On Fri, 16 Jan 2026 14:01:57 +0100, Benoît Monin wrote:
> On Tuesday, 13 January 2026 at 18:33:53 CET, Wolfram Sang wrote:
> [...]
> > > " DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
> > > " = (keep value constant until LENGTH)\n"
> > > " + (increase value by 1 until LENGTH)\n"
> > > @@ -202,12 +209,21 @@ int main(int argc, char *argv[])
> > > case PARSE_GET_DESC:
> > > flags = 0;
> > >
> > > - switch (*arg_ptr++) {
> > > - case 'r': flags |= I2C_M_RD; break;
> > > - case 'w': break;
> > > - default:
> > > - fprintf(stderr, "Error: Invalid direction\n");
> > > - goto err_out_with_arg;
> > > + for (int done = 0; !done; ) {
> > > + switch (*arg_ptr++) {
> > > + /* optional flags */
> > > + case 'i': flags |= I2C_M_IGNORE_NAK; break;
> > > + case 'n': flags |= I2C_M_NO_RD_ACK; break;
> > > + case 'p': flags |= I2C_M_STOP; break;
> > > + case 's': flags |= I2C_M_NOSTART; break;
> > > + case 't': flags |= I2C_M_REV_DIR_ADDR; break;
> >
> > Brainstorming here: maybe a macro could help:
> >
> > case 'i': add_flag_if_supported(flags, I2C_M_IGNORE_NAK);
> >
> > ?
> >
> I am having a hard time coming up with something here. There is the
> __is_defined() macro in the kernel source[1], it only returns 0 or 1, not
> the value of the define.
>
> Maybe defining as zero the flags that are undefined would be acceptable?
> E.g.
>
> #ifndef I2C_M_IGNORE_NAK
> #define I2C_M_IGNORE_NAK 0
> #endif
I don't think that's a good idea, because then you would simply ignore
the flag that was passed by the user if it's not supported? If so, this
is bad user experience. If the user asks for something unsupported, the
tool should report the lack of support, and fail.
> Or you have another idea?
I honestly think that a bunch of ifdefs in this part of the code would
work just fine and be acceptable. We don't plan to add more flags in
the future, and I think that's better than preprocessor magic which may
work or break depending on the compiler.
Something like:
/* optional flags */
case 'i':
#ifdef I2C_M_IGNORE_NAK
flags |= I2C_M_IGNORE_NAK;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'i');
#endif
break;
case 'n':
#ifdef I2C_M_NO_RD_ACK
flags |= I2C_M_NO_RD_ACK;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'n');
#endif
break;
case 'p':
#ifdef I2C_M_STOP
flags |= I2C_M_STOP;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 'p');
#endif
break;
case 's':
#ifdef I2C_M_NOSTART
flags |= I2C_M_NOSTART;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 's');
#endif
break;
case 't':
#ifdef I2C_M_REV_DIR_ADDR
flags |= I2C_M_REV_DIR_ADDR;
#else
fprintf(stderr, "Error: Unsupported flag '%c'\n", 't');
#endif
break;
That being said, I think you also need a second level of support check.
The above only checks if the flags are defined in the kernel headers,
which should generally correspond to the flags being supported by the
kernel. But just because the flags are known to the kernel, doesn't
mean that the i2c adapter you are operating on, supports protocol
mangling.
So I believe that you also need to extend check_funcs() to return the
supported functionality, and then check for I2C_FUNC_PROTOCOL_MANGLING
and I2C_FUNC_NOSTART after parsing the optional flags. If mangling
flags are passed by the user but the adapter's driver does not support
protocol mangling, the tool should report the incompatibility and stop.
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 0/2] Add support for message modifier flags
2026-01-20 14:15 ` Jean Delvare
@ 2026-01-21 10:00 ` Benoît Monin
2026-01-21 18:37 ` Jean Delvare
0 siblings, 1 reply; 12+ messages in thread
From: Benoît Monin @ 2026-01-21 10:00 UTC (permalink / raw)
To: Jean Delvare; +Cc: linux-i2c, Thomas Petazzoni, Wolfram Sang
Hi Jean,
On Tuesday, 20 January 2026 at 15:15:36 CET, Jean Delvare wrote:
> Hi Benoït, hi Wolfram,
>
> On Tue, 23 Dec 2025 14:22:41 +0100, Benoît Monin wrote:
> > I2C messages can be modified with a set of flags covered by the protocol
> > mangling and the skip repeated start functionalities. This series add
> > support for such flags to i2cdetect and i2ctransfer.
> >
> > The first patch shows the support of protocol mangling and repeated
> > start skipping in the output of 'i2cdetect -F'.
> >
> > The second 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 can be
> > useful for various test scenarios.
>
> Out of curiosity, did you have an actual scenario where you needed to
> do this? Protocol mangling is supposed to be rarely needed and avoided
> as much as possible.
>
My only need was to have a way to set the I2C_M_STOP flag, but since I
started modifying i2ctransfer, adding the other flags was not much
additional work.
If you think that some of the flags should not be exposed by i2ctransfer, I
can remove them.
> > The patches use defines that have been present in the kernel since
> > v3.6 released in 2012. If compatibility with older kernel is required,
> > we will need to wrap some of them with #ifndef ... #endif.
> >
> > Maybe a minimum kernel version can be documented in the README?
>
> Be careful if you do. Kernel versions are a very broad indicator,
> distribution kernel maintainers keep backporting features so an older
> kernel can actually support something when its version suggests it
> wouldn't. A kernel version should always be complemented with the actual
> feature or flag so that users can look it up if needed.
>
True. I will go with #ifdef instead, as you and Wolfram proposed. And I will
add a check against the adapter functionalities.
[...]
Thanks for the review!
--
Benoît Monin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH i2c-tools v2 0/2] Add support for message modifier flags
2026-01-21 10:00 ` Benoît Monin
@ 2026-01-21 18:37 ` Jean Delvare
0 siblings, 0 replies; 12+ messages in thread
From: Jean Delvare @ 2026-01-21 18:37 UTC (permalink / raw)
To: Benoît Monin; +Cc: linux-i2c, Thomas Petazzoni, Wolfram Sang
On Wed, 21 Jan 2026 11:00:56 +0100, Benoît Monin wrote:
> On Tuesday, 20 January 2026 at 15:15:36 CET, Jean Delvare wrote:
> > Out of curiosity, did you have an actual scenario where you needed to
> > do this? Protocol mangling is supposed to be rarely needed and avoided
> > as much as possible.
> >
> My only need was to have a way to set the I2C_M_STOP flag, but since I
> started modifying i2ctransfer, adding the other flags was not much
> additional work.
>
> If you think that some of the flags should not be exposed by i2ctransfer, I
> can remove them.
I was just curious, I have no objection to including them all in
i2ctransfer. Maybe someone else will need them in the future.
It might be a good idea to mention in the man page that these flags
should be used carefully though. They are a deviation from the standard
and devices may react badly if they do not expect that.
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-01-21 18:37 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 13:22 [PATCH i2c-tools v2 0/2] Add support for message modifier flags Benoît Monin
2025-12-23 13:22 ` [PATCH i2c-tools v2 1/2] i2cdetect: Display mangling and nostart support Benoît Monin
2026-01-13 17:22 ` Wolfram Sang
2025-12-23 13:22 ` [PATCH i2c-tools v2 2/2] i2ctransfer: Add optional message modifier flags Benoît Monin
2026-01-13 17:33 ` Wolfram Sang
2026-01-16 13:01 ` Benoît Monin
2026-01-20 15:06 ` Jean Delvare
2026-01-20 14:45 ` Jean Delvare
2026-01-13 17:21 ` [PATCH i2c-tools v2 0/2] Add support for " Wolfram Sang
2026-01-20 14:15 ` Jean Delvare
2026-01-21 10:00 ` Benoît Monin
2026-01-21 18:37 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox