Skip to content

Commit

Permalink
drivers: i2c: stm32: Disable suspend to idle during transaction
Browse files Browse the repository at this point in the history
Suspend-to-idle stops I2C module clocks, which must remain active during
transaction

Signed-off-by: Petr Hlineny <[email protected]>
  • Loading branch information
coran21 authored and carlescufi committed Feb 2, 2024
1 parent bc1a988 commit a97c825
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/i2c/i2c_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/drivers/clock_control.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/pm/policy.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <soc.h>
Expand Down Expand Up @@ -173,10 +174,11 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg,
/* Prevent driver from being suspended by PM until I2C transaction is complete */
#ifdef CONFIG_PM_DEVICE_RUNTIME
(void)pm_device_runtime_get(dev);
#else
pm_device_busy_set(dev);
#endif

/* Prevent the clocks to be stopped during the i2c transaction */
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);

current = msg;

while (num_msgs > 0) {
Expand All @@ -194,10 +196,10 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg,
num_msgs--;
}

pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);

#ifdef CONFIG_PM_DEVICE_RUNTIME
(void)pm_device_runtime_put(dev);
#else
pm_device_busy_clear(dev);
#endif

k_sem_give(&data->bus_mutex);
Expand Down

0 comments on commit a97c825

Please sign in to comment.