Skip to content

Commit 319ffae

Browse files
Jordan Yatescarlescufi
authored andcommitted
pm: device: helper to query power state
Adds a helper function to query whether a device is currently powered. This can be used to determine if the chip can be initialised now, or if it needs to be deferred. Signed-off-by: Jordan Yates <[email protected]>
1 parent 3da90ad commit 319ffae

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/zephyr/pm/device.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,16 @@ int pm_device_power_domain_add(const struct device *dev,
555555
*/
556556
int pm_device_power_domain_remove(const struct device *dev,
557557
const struct device *domain);
558+
559+
/**
560+
* @brief Check if the device is currently powered.
561+
*
562+
* @param dev Device instance.
563+
*
564+
* @retval true If device is currently powered
565+
* @retval false If device is not currently powered
566+
*/
567+
bool pm_device_is_powered(const struct device *dev);
558568
#else
559569
static inline void pm_device_init_suspended(const struct device *dev)
560570
{
@@ -626,6 +636,11 @@ static inline int pm_device_power_domain_remove(const struct device *dev,
626636
return -ENOSYS;
627637
}
628638

639+
static inline bool pm_device_is_powered(const struct device *dev)
640+
{
641+
ARG_UNUSED(dev);
642+
return true;
643+
}
629644
#endif /* CONFIG_PM_DEVICE */
630645

631646
/** @} */

subsys/pm/device.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,19 @@ bool pm_device_on_power_domain(const struct device *dev)
372372
return false;
373373
#endif
374374
}
375+
376+
bool pm_device_is_powered(const struct device *dev)
377+
{
378+
#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
379+
struct pm_device *pm = dev->pm;
380+
381+
/* If a device doesn't support PM or is not under a PM domain,
382+
* assume it is always powered on.
383+
*/
384+
return (pm == NULL) ||
385+
(pm->domain == NULL) ||
386+
(pm->domain->pm->state == PM_DEVICE_STATE_ACTIVE);
387+
#else
388+
return true;
389+
#endif
390+
}

0 commit comments

Comments
 (0)