pm: device: Make power domain optional

Add a Kconfig symbol to enable/disable power domain on Zephyr.
Disabling power domain save some memory / space.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-11-29 15:50:12 -08:00 committed by Anas Nashif
parent ddfa048058
commit 2e732dff6d
3 changed files with 35 additions and 9 deletions

View file

@ -110,14 +110,16 @@ struct pm_device {
/** Event conditional var to listen to the sync request events */
struct k_condvar condvar;
#endif /* CONFIG_PM_DEVICE_RUNTIME */
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
/** Power Domain it belongs */
const struct device *domain;
#endif /* CONFIG_PM_DEVICE_POWER_DOMAIN */
/* Device PM status flags. */
atomic_t flags;
/** Device power state */
enum pm_device_state state;
/** Device PM action callback */
pm_device_action_cb_t action_cb;
/** Power Domain it belongs */
const struct device *domain;
};
#ifdef CONFIG_PM_DEVICE_RUNTIME
@ -128,6 +130,14 @@ struct pm_device {
#define Z_PM_DEVICE_RUNTIME_INIT(obj)
#endif /* CONFIG_PM_DEVICE_RUNTIME */
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
#define Z_PM_DEVICE_POWER_DOMAIN_INIT(_node_id) \
.domain = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(_node_id, \
power_domain)),
#else
#define Z_PM_DEVICE_POWER_DOMAIN_INIT(obj)
#endif /* CONFIG_PM_DEVICE_POWER_DOMAIN */
/**
* @brief Utility macro to initialize #pm_device.
*
@ -147,7 +157,7 @@ struct pm_device {
DT_NODE_EXISTS(node_id), \
(DT_PROP_OR(node_id, wakeup_source, 0)),\
(0)) << PM_DEVICE_FLAG_WS_CAPABLE), \
.domain = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, power_domain))\
Z_PM_DEVICE_POWER_DOMAIN_INIT(node_id) \
}
/**

View file

@ -54,6 +54,15 @@ module = PM_DEVICE
module-str = Device Power Management
source "subsys/logging/Kconfig.template.log_config"
config PM_DEVICE_POWER_DOMAIN
bool "Enable power domain"
depends on PM_DEVICE
default y
help
Enable support for Power Domain. With power domain enabled,
devices that depend on a domain will be notified when this
domain is suspended or resumed.
config PM_DEVICE_RUNTIME
bool "Runtime Device Power Management"
help

View file

@ -12,6 +12,13 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL);
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
#define PM_DOMAIN(_pm) \
(_pm)->domain
#else
#define PM_DOMAIN(_pm) NULL
#endif
/**
* @brief Suspend a device
*
@ -99,8 +106,8 @@ static void runtime_suspend_work(struct k_work *work)
* On async put, we have to suspend the domain when the device
* finishes its operation
*/
if (pm->domain != NULL) {
(void)pm_device_runtime_put(pm->domain);
if (PM_DOMAIN(pm) != NULL) {
(void)pm_device_runtime_put(PM_DOMAIN(pm));
}
__ASSERT(ret == 0, "Could not suspend device (%d)", ret);
@ -125,8 +132,8 @@ int pm_device_runtime_get(const struct device *dev)
* If the device is under a power domain, the domain has to be get
* first.
*/
if (pm->domain != NULL) {
ret = pm_device_runtime_get(pm->domain);
if (PM_DOMAIN(pm) != NULL) {
ret = pm_device_runtime_get(PM_DOMAIN(pm));
if (ret != 0) {
goto unlock;
}
@ -173,8 +180,8 @@ int pm_device_runtime_put(const struct device *dev)
/*
* Now put the domain
*/
if ((ret == 0) && dev->pm->domain != NULL) {
ret = pm_device_runtime_put(dev->pm->domain);
if ((ret == 0) && PM_DOMAIN(dev->pm) != NULL) {
ret = pm_device_runtime_put(PM_DOMAIN(dev->pm));
}
SYS_PORT_TRACING_FUNC_EXIT(pm, device_runtime_put, dev, ret);