Skip to content

Commit 2d18c7e

Browse files
GTLin08fabiobaltieri
authored andcommitted
drivers/i2c: it51xxx: 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 f0af5be commit 2d18c7e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

drivers/i2c/i2c_ite_it51xxx.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,10 @@ static int i2c_it51xxx_transfer(const struct device *dev, struct i2c_msg *msgs,
14591459
#endif
14601460
/* Lock mutex of i2c controller */
14611461
k_mutex_lock(&data->mutex, K_FOREVER);
1462+
#ifdef CONFIG_PM
1463+
/* Block to enter power policy. */
1464+
i2c_ite_pm_policy_state_lock_get(data, I2CM_ITE_PM_POLICY_FLAG);
1465+
#endif
14621466
/*
14631467
* If the transaction of write to read is divided into two transfers, the repeat start
14641468
* transfer uses this flag to exclude checking bus busy.
@@ -1473,9 +1477,8 @@ static int i2c_it51xxx_transfer(const struct device *dev, struct i2c_msg *msgs,
14731477
* (No external pull-up), drop the transaction.
14741478
*/
14751479
if (i2c_bus_not_available(dev)) {
1476-
/* Unlock mutex of i2c controller */
1477-
k_mutex_unlock(&data->mutex);
1478-
return -EIO;
1480+
ret = -EIO;
1481+
goto done;
14791482
}
14801483
}
14811484

@@ -1490,13 +1493,6 @@ static int i2c_it51xxx_transfer(const struct device *dev, struct i2c_msg *msgs,
14901493
data->msg_index = 0;
14911494

14921495
bool fifo_mode_enable = fifo_mode_allowed(dev, msgs);
1493-
1494-
if (fifo_mode_enable) {
1495-
#ifdef CONFIG_PM
1496-
/* Block to enter power policy. */
1497-
i2c_ite_pm_policy_state_lock_get(data, I2CM_ITE_PM_POLICY_FLAG);
1498-
#endif
1499-
}
15001496
#endif
15011497
for (int i = 0; i < num_msgs; i++) {
15021498
data->widx = 0;
@@ -1572,10 +1568,6 @@ static int i2c_it51xxx_transfer(const struct device *dev, struct i2c_msg *msgs,
15721568
if (data->num_msgs == 2) {
15731569
i2c_fifo_en_w2r(dev, false);
15741570
}
1575-
#ifdef CONFIG_PM
1576-
/* Permit to enter power policy. */
1577-
i2c_ite_pm_policy_state_lock_put(data, I2CM_ITE_PM_POLICY_FLAG);
1578-
#endif
15791571
}
15801572
#endif
15811573
/* Reset i2c channel status */
@@ -1586,6 +1578,11 @@ static int i2c_it51xxx_transfer(const struct device *dev, struct i2c_msg *msgs,
15861578
/* Save return value. */
15871579
ret = i2c_parsing_return_value(dev);
15881580

1581+
done:
1582+
#ifdef CONFIG_PM
1583+
/* Permit to enter power policy. */
1584+
i2c_ite_pm_policy_state_lock_put(data, I2CM_ITE_PM_POLICY_FLAG);
1585+
#endif
15891586
/* Unlock mutex of i2c controller */
15901587
k_mutex_unlock(&data->mutex);
15911588

0 commit comments

Comments
 (0)