diff options
author | Dino Li <Dino.Li@ite.com.tw> | 2021-07-07 15:55:04 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-22 19:54:04 +0000 |
commit | 154f661f50d08adc3a546360be020a7e0321fe2e (patch) | |
tree | 0a85a77f8aa5215595a91cf9c5d3c39972387c27 /common/i2c_controller.c | |
parent | 506a1ee872aad4ef21d7c90717f1917963dec6b1 (diff) | |
download | chrome-ec-154f661f50d08adc3a546360be020a7e0321fe2e.tar.gz |
zephyr: i2c: protect physical port
If i2c devices are connected to the same port, they should
use the same mutex_lock() index. So the new transaction won't
break the ongoing transaction.
BRANCH=none
BUG=b:189855648
TEST=Enable CONFIG_SMBUS_PEC and voltage regulator function on asurada.
No i2c transaction is broken.
Change-Id: Ib848e3c2e60b99ce66ad5fd2fc7095f90820a15d
Signed-off-by: Dino Li <Dino.Li@ite.com.tw>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3010920
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'common/i2c_controller.c')
-rw-r--r-- | common/i2c_controller.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/i2c_controller.c b/common/i2c_controller.c index 10ea4081cd..0596ddc422 100644 --- a/common/i2c_controller.c +++ b/common/i2c_controller.c @@ -83,6 +83,16 @@ static int i2c_port_is_locked(int port) if (port < 0) return 0; + if (IS_ENABLED(CONFIG_ZEPHYR)) { + /* + * For Zephyr: to convert an i2c port enum value to a port + * number in mutex_lock(), this number should be soc's i2c port + * where the i2 device is connected to. + */ + if (i2c_get_physical_port(port) >= 0) + port = i2c_get_physical_port(port); + } + return (i2c_port_active_list >> port) & 1; } @@ -287,6 +297,16 @@ void i2c_lock(int port, int lock) if (port < 0 || port >= ARRAY_SIZE(port_mutex)) return; + if (IS_ENABLED(CONFIG_ZEPHYR)) { + /* + * For Zephyr: to convert an i2c port enum value to a port + * number in mutex_lock(), this number should be soc's i2c port + * where the i2 device is connected to. + */ + if (i2c_get_physical_port(port) >= 0) + port = i2c_get_physical_port(port); + } + if (lock) { uint32_t irq_lock_key; |