Skip to content

Commit f0af5be

Browse files
GTLin08fabiobaltieri
authored andcommitted
drivers/i2c: it8xxx2: 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 7cf9a58 commit f0af5be

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/i2c/i2c_ite_enhance.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,11 @@ static int enhanced_i2c_cmd_queue_trans(const struct device *dev)
836836
IT8XXX2_I2C_MODE_SEL(base) = 0;
837837
IT8XXX2_I2C_CTR2(base) = 1;
838838
/*
839-
* The EC processor(CPU) cannot be in the k_cpu_idle() and power
840-
* policy during the transactions with the CQ mode(DMA mode).
839+
* The EC processor(CPU) cannot be in the k_cpu_idle() during the
840+
* transactions with the CQ mode(DMA mode).
841841
* Otherwise, the EC processor would be clock gated.
842842
*/
843843
chip_block_idle();
844-
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
845844
/* Start */
846845
IT8XXX2_I2C_CTR(base) = E_START_CQ;
847846

@@ -876,8 +875,7 @@ static int i2c_enhance_cq_transfer(const struct device *dev,
876875
config->port, data->addr_16bit, I2C_RC_TIMEOUT);
877876
}
878877

879-
/* Permit to enter power policy and idle mode. */
880-
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
878+
/* Permit to enter idle mode. */
881879
chip_permit_idle();
882880

883881
return data->err;
@@ -966,6 +964,8 @@ static int i2c_enhance_transfer(const struct device *dev,
966964
#endif
967965
/* Lock mutex of i2c controller */
968966
k_mutex_lock(&data->mutex, K_FOREVER);
967+
/* Block to enter power policy. */
968+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
969969

970970
data->num_msgs = num_msgs;
971971
data->addr_16bit = addr;
@@ -984,9 +984,8 @@ static int i2c_enhance_transfer(const struct device *dev,
984984
* (No external pull-up), drop the transaction.
985985
*/
986986
if (i2c_bus_not_available(dev)) {
987-
/* Unlock mutex of i2c controller */
988-
k_mutex_unlock(&data->mutex);
989-
return -EIO;
987+
ret = -EIO;
988+
goto done;
990989
}
991990
}
992991
}
@@ -1001,6 +1000,10 @@ static int i2c_enhance_transfer(const struct device *dev,
10011000
}
10021001
/* Save return value. */
10031002
ret = i2c_parsing_return_value(dev);
1003+
1004+
done:
1005+
/* Permit to enter power policy */
1006+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
10041007
/* Unlock mutex of i2c controller */
10051008
k_mutex_unlock(&data->mutex);
10061009

0 commit comments

Comments
 (0)