pm: device: move flags construction to a macro

Move the construction of the initial value of `struct pm_device` `flags`
to a dedicated macro. This makes it cleaner to add additional default
values.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2022-03-12 21:05:02 +10:00 committed by Anas Nashif
parent ee48754af3
commit f1111dd679

View File

@ -163,6 +163,20 @@ struct pm_device {
#define Z_PM_DEVICE_POWER_DOMAIN_INIT(obj)
#endif /* CONFIG_PM_DEVICE_POWER_DOMAIN */
/**
* @brief Utility macro to initialize #pm_device flags
*
* @param node_id Devicetree node for the initialized device (can be invalid).
*/
#define Z_PM_DEVICE_FLAGS(node_id) \
(COND_CODE_1( \
DT_NODE_EXISTS(node_id), \
((DT_PROP_OR(node_id, wakeup_source, 0) \
<< PM_DEVICE_FLAG_WS_CAPABLE) | \
(DT_NODE_HAS_COMPAT(node_id, power_domain) << \
PM_DEVICE_FLAG_PD)), \
(0)))
/**
* @brief Utility macro to initialize #pm_device.
*
@ -173,18 +187,13 @@ struct pm_device {
* @param node_id Devicetree node for the initialized device (can be invalid).
* @param pm_action_cb Device PM control callback function.
*/
#define Z_PM_DEVICE_INIT(obj, node_id, pm_action_cb) \
{ \
Z_PM_DEVICE_RUNTIME_INIT(obj) \
.action_cb = pm_action_cb, \
.state = PM_DEVICE_STATE_ACTIVE, \
.flags = ATOMIC_INIT(COND_CODE_1( \
DT_NODE_EXISTS(node_id), \
((DT_PROP_OR(node_id, wakeup_source, 0) \
<< PM_DEVICE_FLAG_WS_CAPABLE) | \
(DT_NODE_HAS_COMPAT(node_id, power_domain) << \
PM_DEVICE_FLAG_PD)), (0))), \
Z_PM_DEVICE_POWER_DOMAIN_INIT(node_id) \
#define Z_PM_DEVICE_INIT(obj, node_id, pm_action_cb) \
{ \
Z_PM_DEVICE_RUNTIME_INIT(obj) \
.action_cb = pm_action_cb, \
.state = PM_DEVICE_STATE_ACTIVE, \
.flags = ATOMIC_INIT(Z_PM_DEVICE_FLAGS(node_id)), \
Z_PM_DEVICE_POWER_DOMAIN_INIT(node_id) \
}
/**