diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index a05edd5c8cb..5d22380118b 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "i2c_ll_stm32.h" #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL @@ -227,6 +229,16 @@ int i2c_stm32_target_register(const struct device *dev, return ret; } +#if defined(CONFIG_PM_DEVICE_RUNTIME) + if (pm_device_wakeup_is_capable(dev)) { + /* Mark device as active */ + (void)pm_device_runtime_get(dev); + /* Enable wake-up from stop */ + LOG_DBG("i2c: enabling wakeup from stop"); + LL_I2C_EnableWakeUpFromStop(cfg->i2c); + } +#endif /* defined(CONFIG_PM_DEVICE_RUNTIME) */ + LL_I2C_Enable(i2c); if (!data->slave_cfg) { @@ -306,6 +318,16 @@ int i2c_stm32_target_unregister(const struct device *dev, LL_I2C_Disable(i2c); +#if defined(CONFIG_PM_DEVICE_RUNTIME) + if (pm_device_wakeup_is_capable(dev)) { + /* Disable wake-up from STOP */ + LOG_DBG("i2c: disabling wakeup from stop"); + LL_I2C_DisableWakeUpFromStop(i2c); + /* Release the device */ + (void)pm_device_runtime_put(dev); + } +#endif /* defined(CONFIG_PM_DEVICE_RUNTIME) */ + data->slave_attached = false; return 0;