Skip to content

Commit

Permalink
pm: device: Add power domain get function
Browse files Browse the repository at this point in the history
Add a function to get power domain device from a pm device.
Prompted by need to run runtime usage checks on pd from pm device.

Signed-off-by: Jacob McClellan <[email protected]>
  • Loading branch information
Jacob McClellan committed Nov 22, 2024
1 parent 829c03b commit f51d531
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/zephyr/pm/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ bool pm_device_wakeup_is_capable(const struct device *dev);
*/
bool pm_device_on_power_domain(const struct device *dev);

/**
* @brief Get the device's power domain.
*
* @param dev Device instance.
*
* @retval pd The device's power domain if on a power domain
* @retval NULL if not on a power domain
*/
const struct device *pm_device_get_power_domain(const struct device *dev);

/**
* @brief Add a device to a power domain.
*
Expand Down
13 changes: 13 additions & 0 deletions subsys/pm/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ bool pm_device_on_power_domain(const struct device *dev)
#endif
}

const struct device *pm_device_get_power_domain(const struct device *dev)
{
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
if (pm_device_on_power_domain(dev) == false) {
return NULL;
}
return dev->pm_base->domain;
#else
ARG_UNUSED(dev);
return NULL;
#endif
}

bool pm_device_is_powered(const struct device *dev)
{
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
Expand Down

0 comments on commit f51d531

Please sign in to comment.