Skip to content

Commit 7cf9a58

Browse files
GTLin08fabiobaltieri
authored andcommitted
drivers/i2c: it81xx2: Avoid entering power policy during PIO transfers
Avoid entering low-power state during I2C host transfers in PIO mode. Entering a low-power state during an active PIO transfer may prevent the peripheral from generating the clock signal correctly, resulting in transmission errors. Signed-off-by: Tim Lin <[email protected]>
1 parent 744a563 commit 7cf9a58

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/i2c/i2c_ite_it8xxx2.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
944944

945945
/* Lock mutex of i2c controller */
946946
k_mutex_lock(&data->mutex, K_FOREVER);
947+
/* Block to enter power policy. */
948+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
947949
/*
948950
* If the transaction of write to read is divided into two
949951
* transfers, the repeat start transfer uses this flag to
@@ -961,9 +963,8 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
961963
* (No external pull-up), drop the transaction.
962964
*/
963965
if (i2c_bus_not_available(dev)) {
964-
/* Unlock mutex of i2c controller */
965-
k_mutex_unlock(&data->mutex);
966-
return -EIO;
966+
ret = -EIO;
967+
goto done;
967968
}
968969
}
969970

@@ -975,11 +976,6 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
975976
/* Store msgs to data struct. */
976977
data->msgs_list = msgs;
977978
bool fifo_mode_enable = fifo_mode_allowed(dev, msgs);
978-
979-
if (fifo_mode_enable) {
980-
/* Block to enter power policy. */
981-
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
982-
}
983979
#endif
984980
for (int i = 0; i < num_msgs; i++) {
985981

@@ -1056,8 +1052,6 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
10561052
if (data->num_msgs == 2) {
10571053
i2c_fifo_en_w2r(dev, 0);
10581054
}
1059-
/* Permit to enter power policy. */
1060-
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
10611055
}
10621056
#endif
10631057
/* reset i2c channel status */
@@ -1066,6 +1060,10 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
10661060
}
10671061
/* Save return value. */
10681062
ret = i2c_parsing_return_value(dev);
1063+
1064+
done:
1065+
/* Permit to enter power policy. */
1066+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
10691067
/* Unlock mutex of i2c controller */
10701068
k_mutex_unlock(&data->mutex);
10711069

0 commit comments

Comments
 (0)