pm: device: Remove the need of a private header

Move functions around so it is not necessary to keep a header
that with functions declaration that is just used in one single
place.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin
2021-08-19 21:07:15 -07:00
committed by Anas Nashif
parent 29855b41b4
commit 81f1225040
3 changed files with 57 additions and 95 deletions
-58
View File
@@ -10,64 +10,6 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL);
#if defined(CONFIG_PM_DEVICE)
extern const struct device *__pm_device_slots_start[];
/* Number of devices successfully suspended. */
static size_t num_susp;
static int _pm_devices(enum pm_device_state state)
{
const struct device *devs;
size_t devc;
devc = z_device_get_all_static(&devs);
num_susp = 0;
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) {
int ret;
/* ignore busy devices */
if (pm_device_is_busy(dev) || pm_device_wakeup_is_enabled(dev)) {
continue;
}
ret = pm_device_state_set(dev, state);
/* ignore devices not supporting or already at the given state */
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) {
continue;
} else if (ret < 0) {
LOG_ERR("Device %s did not enter %s state (%d)",
dev->name, pm_device_state_str(state), ret);
return ret;
}
__pm_device_slots_start[num_susp] = dev;
num_susp++;
}
return 0;
}
int pm_suspend_devices(void)
{
return _pm_devices(PM_DEVICE_STATE_SUSPENDED);
}
void pm_resume_devices(void)
{
int32_t i;
for (i = (num_susp - 1); i >= 0; i--) {
pm_device_state_set(__pm_device_slots_start[i],
PM_DEVICE_STATE_ACTIVE);
}
num_susp = 0;
}
#endif /* defined(CONFIG_PM_DEVICE) */
const char *pm_device_state_str(enum pm_device_state state)
{
switch (state) {
-35
View File
@@ -1,35 +0,0 @@
/*
* Copyright (c) 2021 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_SUBSYS_PM_PRIV_H_
#define ZEPHYR_SUBSYS_PM_PRIV_H_
#include <pm/pm.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Function to suspend the devices in PM device list
*/
int pm_suspend_devices(void);
/**
* @brief Function to force suspend the devices in PM device list
*/
int pm_force_suspend_devices(void);
/**
* @brief Function to resume the devices in PM device list
*/
void pm_resume_devices(void);
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_SUBSYS_PM_PRIV_H_ */
+57 -2
View File
@@ -4,18 +4,18 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <device.h>
#include <zephyr.h>
#include <kernel.h>
#include <timeout_q.h>
#include <init.h>
#include <string.h>
#include <pm/device.h>
#include <pm/pm.h>
#include <pm/state.h>
#include <pm/policy.h>
#include <tracing/tracing.h>
#include "pm_priv.h"
#define PM_STATES_LEN (1 + PM_STATE_SOFT_OFF - PM_STATE_ACTIVE)
#include <logging/log.h>
LOG_MODULE_REGISTER(pm, CONFIG_PM_LOG_LEVEL);
@@ -99,6 +99,61 @@ static inline void pm_stop_timer(void) {}
static void pm_stats_update(enum pm_state state) {}
#endif
#ifdef CONFIG_PM_DEVICE
extern const struct device *__pm_device_slots_start[];
/* Number of devices successfully suspended. */
static size_t num_susp;
static int pm_suspend_devices(void)
{
const struct device *devs;
size_t devc;
devc = z_device_get_all_static(&devs);
num_susp = 0;
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) {
int ret;
/* ignore busy devices */
if (pm_device_is_busy(dev) || pm_device_wakeup_is_enabled(dev)) {
continue;
}
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
/* ignore devices not supporting or already at the given state */
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) {
continue;
} else if (ret < 0) {
LOG_ERR("Device %s did not enter %s state (%d)",
dev->name,
pm_device_state_str(PM_DEVICE_STATE_SUSPENDED),
ret);
return ret;
}
__pm_device_slots_start[num_susp] = dev;
num_susp++;
}
return 0;
}
static void pm_resume_devices(void)
{
size_t i;
for (i = 0; i < num_susp; i++) {
pm_device_state_set(__pm_device_slots_start[i],
PM_DEVICE_STATE_ACTIVE);
}
num_susp = 0;
}
#endif /* CONFIG_PM_DEVICE */
static inline void exit_pos_ops(struct pm_state_info info)
{
extern __weak void