From 3bc531e9c6874eb04fea5c886dc725d75774e58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wouter=20Horr=C3=A9?= Date: Wed, 23 Aug 2023 15:13:40 +0200 Subject: [PATCH] drivers: i2c: stm32: Support wakeup from STOP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for wakeup from STOP mode when the i2c device is configured as a target. Signed-off-by: Wouter Horré --- drivers/i2c/i2c_ll_stm32_v2.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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;