Skip to content

Commit bcb8d8d

Browse files
[nrf fromlist] drivers: i2c: i2c_nrfx_twim: add conditional PM ISR safety
Requesting/releasing TWIM device may be ISR safe, but it cannot be reliably known whether managing its power domain is. Is is then assumed that if power domains are used, device is no longer ISR safe. This macro let's us check if we will be requesting/releasing power domains and determines PM device ISR safety value. Upstream PR #: 96402 Signed-off-by: Michał Stasiak <[email protected]>
1 parent 2cffa44 commit bcb8d8d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

drivers/i2c/i2c_nrfx_twim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static DEVICE_API(i2c, i2c_nrfx_twim_driver_api) = {
285285
DT_PROP(I2C(idx), easydma_maxcnt_bits)), \
286286
}; \
287287
PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, \
288-
PM_DEVICE_ISR_SAFE); \
288+
I2C_PM_ISR_SAFE(idx)); \
289289
I2C_DEVICE_DT_DEINIT_DEFINE(I2C(idx), \
290290
i2c_nrfx_twim_init, \
291291
i2c_nrfx_twim_deinit, \

drivers/i2c/i2c_nrfx_twim_common.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ extern "C" {
3131
#define I2C_FREQUENCY(idx) I2C_NRFX_TWIM_FREQUENCY(DT_PROP_OR(I2C(idx), clock_frequency, \
3232
I2C_BITRATE_STANDARD))
3333

34+
/* Macro determines PM actions interrupt safety level.
35+
*
36+
* Requesting/releasing TWIM device may be ISR safe, but it cannot be reliably known whether
37+
* managing its power domain is. It is then assumed that if power domains are used, device is
38+
* no longer ISR safe. This macro let's us check if we will be requesting/releasing
39+
* power domains and determines PM device ISR safety value.
40+
*/
41+
#define I2c_PM_ISR_SAFE(idx) \
42+
COND_CODE_1( \
43+
UTIL_AND( \
44+
IS_ENABLED(CONFIG_PM_DEVICE_POWER_DOMAIN), \
45+
UTIL_AND( \
46+
DT_NODE_HAS_PROP(I2C(idx), power_domains), \
47+
DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE(I2C(idx), power_domains)) \
48+
) \
49+
), \
50+
(0), \
51+
(PM_DEVICE_ISR_SAFE) \
52+
)
53+
3454
struct i2c_nrfx_twim_common_config {
3555
nrfx_twim_t twim;
3656
nrfx_twim_config_t twim_config;

drivers/i2c/i2c_nrfx_twim_rtio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static int i2c_nrfx_twim_rtio_deinit(const struct device *dev)
287287
}, \
288288
.ctx = &_i2c##idx##_twim_rtio, \
289289
}; \
290-
PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, PM_DEVICE_ISR_SAFE); \
290+
PM_DEVICE_DT_DEFINE(I2C(idx), twim_nrfx_pm_action, I2C_PM_ISR_SAFE(idx)); \
291291
I2C_DEVICE_DT_DEINIT_DEFINE(I2C(idx), i2c_nrfx_twim_rtio_init, i2c_nrfx_twim_rtio_deinit, \
292292
PM_DEVICE_DT_GET(I2C(idx)), &twim_##idx##z_data, \
293293
&twim_##idx##z_config, POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \

0 commit comments

Comments
 (0)