Skip to content

Commit e282b63

Browse files
mstasiaknordicnordicjm
authored andcommitted
[nrf fromlist] drivers: sensor: qdec_nrfx: add conditional PM ISR safety
Requesting/releasing QDEC 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 a2b6884 commit e282b63

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/sensor/nordic/qdec_nrfx/qdec_nrfx.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,26 @@ static int qdec_nrfx_init(const struct device *dev)
272272
#define QDEC(idx) DT_NODELABEL(qdec##idx)
273273
#define QDEC_PROP(idx, prop) DT_PROP(QDEC(idx), prop)
274274

275+
/* Macro determines PM actions interrupt safety level.
276+
*
277+
* Requesting/releasing QDEC device may be ISR safe, but it cannot be reliably known whether
278+
* managing its power domain is. It is then assumed that if power domains are used, device is
279+
* no longer ISR safe. This macro let's us check if we will be requesting/releasing
280+
* power domains and determines PM device ISR safety value.
281+
*/
282+
#define QDEC_PM_ISR_SAFE(idx) \
283+
COND_CODE_1( \
284+
UTIL_AND( \
285+
IS_ENABLED(CONFIG_PM_DEVICE_POWER_DOMAIN), \
286+
UTIL_AND( \
287+
DT_NODE_HAS_PROP(QDEC(idx), power_domains), \
288+
DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE(QDEC(idx), power_domains)) \
289+
) \
290+
), \
291+
(0), \
292+
(PM_DEVICE_ISR_SAFE) \
293+
)
294+
275295
#define SENSOR_NRFX_QDEC_DEVICE(idx) \
276296
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(QDEC(idx)); \
277297
BUILD_ASSERT(QDEC_PROP(idx, steps) > 0, \
@@ -301,7 +321,7 @@ static int qdec_nrfx_init(const struct device *dev)
301321
.enable_pin = DT_PROP_OR(QDEC(idx), enable_pin, NRF_QDEC_PIN_NOT_CONNECTED), \
302322
.steps = QDEC_PROP(idx, steps), \
303323
}; \
304-
PM_DEVICE_DT_DEFINE(QDEC(idx), qdec_nrfx_pm_action, PM_DEVICE_ISR_SAFE); \
324+
PM_DEVICE_DT_DEFINE(QDEC(idx), qdec_nrfx_pm_action, QDEC_PM_ISR_SAFE(idx)); \
305325
SENSOR_DEVICE_DT_DEFINE(QDEC(idx), \
306326
qdec_nrfx_init, \
307327
PM_DEVICE_DT_GET(QDEC(idx)), \

0 commit comments

Comments
 (0)