Skip to content

Commit

Permalink
drivers: i2c: add an option to skip auto-sending stop on last message
Browse files Browse the repository at this point in the history
The I2C transfer API has been recently changed to always automatically
set a STOP on the last message, which was well documented but
implemented only by few drivers.

Unfortunately, while documented, this is a change in the current
behavior and it turns out that some applications depended on it for some
complex operations.

Add a flag to temporarily restore the old behavior, buying time to fix
the application code depending on this.

(cherry picked from commit 61f4ba2)

Original-Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
GitOrigin-RevId: 61f4ba2
Change-Id: Ic2532471a1ae4f43e929101f60e9f37e902f19a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5882735
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
  • Loading branch information
fabiobaltieri authored and Chromeos LUCI committed Sep 23, 2024
1 parent 58e30e4 commit 89c951e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions drivers/i2c/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ config I2C_CALLBACK
help
API and implementations of i2c_transfer_cb.

config I2C_ALLOW_NO_STOP_TRANSACTIONS
bool "Allows I2C transfers with no STOP on the last transaction [DEPRECATED]"
depends on !I2C_NRFX_TWI
depends on !I2C_NRFX_TWIM
depends on !I2C_STM32
depends on !I2C_GD32
depends on !I2C_ESP32
depends on !I2C_DW
select DEPRECATED
help
Allow I2C transactions with no STOP on the last message. This is
unsupported and can leave the bus in an unexpected state. The option
will be removed in Zephyr 4.1.

config I2C_RTIO
bool "I2C RTIO API"
select EXPERIMENTAL
Expand Down
8 changes: 6 additions & 2 deletions include/zephyr/drivers/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,9 @@ static inline int z_impl_i2c_transfer(const struct device *dev,
return 0;
}

msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
if (!IS_ENABLED(CONFIG_I2C_ALLOW_NO_STOP_TRANSACTIONS)) {
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
}

int res = api->transfer(dev, msgs, num_msgs, addr);

Expand Down Expand Up @@ -865,7 +867,9 @@ static inline int i2c_transfer_cb(const struct device *dev,
return 0;
}

msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
if (!IS_ENABLED(CONFIG_I2C_ALLOW_NO_STOP_TRANSACTIONS)) {
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
}

return api->transfer_cb(dev, msgs, num_msgs, addr, cb, userdata);
}
Expand Down

0 comments on commit 89c951e

Please sign in to comment.