Commit ff4dee17 authored by Keith Short's avatar Keith Short Committed by Anas Nashif
Browse files

pm: Guard all PM APIs



If a driver doesn't support PM, as indicated by setting the
pm_control_fn parameter to NULL, no need to manage busy or wakeup state.
This also prepares the PM support for issue #39286, which will allocate
PM structures only for the devices that request it.

Signed-off-by: default avatarKeith Short <keithshort@google.com>
parent 0bfde7bc
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -172,6 +172,9 @@ bool pm_device_is_any_busy(void)
	devc = z_device_get_all_static(&devs);

	for (const struct device *dev = devs; dev < (devs + devc); dev++) {
		if (dev->pm_control == NULL) {
			continue;
		}
		if (atomic_test_bit(&dev->pm->flags, PM_DEVICE_FLAG_BUSY)) {
			return true;
		}
@@ -182,16 +185,25 @@ bool pm_device_is_any_busy(void)

bool pm_device_is_busy(const struct device *dev)
{
	if (dev->pm_control == NULL) {
		return false;
	}
	return atomic_test_bit(&dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}

void pm_device_busy_set(const struct device *dev)
{
	if (dev->pm_control == NULL) {
		return;
	}
	atomic_set_bit(&dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}

void pm_device_busy_clear(const struct device *dev)
{
	if (dev->pm_control == NULL) {
		return;
	}
	atomic_clear_bit(&dev->pm->flags, PM_DEVICE_FLAG_BUSY);
}

@@ -199,6 +211,10 @@ bool pm_device_wakeup_enable(struct device *dev, bool enable)
{
	atomic_val_t flags, new_flags;

	if (dev->pm_control == NULL) {
		return false;
	}

	flags =	 atomic_get(&dev->pm->flags);

	if ((flags & BIT(PM_DEVICE_FLAGS_WS_CAPABLE)) == 0U) {
@@ -217,12 +233,18 @@ bool pm_device_wakeup_enable(struct device *dev, bool enable)

bool pm_device_wakeup_is_enabled(const struct device *dev)
{
	if (dev->pm_control == NULL) {
		return false;
	}
	return atomic_test_bit(&dev->pm->flags,
			       PM_DEVICE_FLAGS_WS_ENABLED);
}

bool pm_device_wakeup_is_capable(const struct device *dev)
{
	if (dev->pm_control == NULL) {
		return false;
	}
	return atomic_test_bit(&dev->pm->flags,
			       PM_DEVICE_FLAGS_WS_CAPABLE);
}