Skip to content

Commit 81f1225

Browse files
Flavio Ceolinnashif
authored andcommitted
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 <[email protected]>
1 parent 29855b4 commit 81f1225

File tree

3 files changed

+57
-95
lines changed

3 files changed

+57
-95
lines changed

subsys/pm/device.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,6 @@
1010
#include <logging/log.h>
1111
LOG_MODULE_REGISTER(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL);
1212

13-
#if defined(CONFIG_PM_DEVICE)
14-
extern const struct device *__pm_device_slots_start[];
15-
16-
/* Number of devices successfully suspended. */
17-
static size_t num_susp;
18-
19-
static int _pm_devices(enum pm_device_state state)
20-
{
21-
const struct device *devs;
22-
size_t devc;
23-
24-
devc = z_device_get_all_static(&devs);
25-
26-
num_susp = 0;
27-
28-
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) {
29-
int ret;
30-
31-
/* ignore busy devices */
32-
if (pm_device_is_busy(dev) || pm_device_wakeup_is_enabled(dev)) {
33-
continue;
34-
}
35-
36-
ret = pm_device_state_set(dev, state);
37-
/* ignore devices not supporting or already at the given state */
38-
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) {
39-
continue;
40-
} else if (ret < 0) {
41-
LOG_ERR("Device %s did not enter %s state (%d)",
42-
dev->name, pm_device_state_str(state), ret);
43-
return ret;
44-
}
45-
46-
__pm_device_slots_start[num_susp] = dev;
47-
num_susp++;
48-
}
49-
50-
return 0;
51-
}
52-
53-
int pm_suspend_devices(void)
54-
{
55-
return _pm_devices(PM_DEVICE_STATE_SUSPENDED);
56-
}
57-
58-
void pm_resume_devices(void)
59-
{
60-
int32_t i;
61-
62-
for (i = (num_susp - 1); i >= 0; i--) {
63-
pm_device_state_set(__pm_device_slots_start[i],
64-
PM_DEVICE_STATE_ACTIVE);
65-
}
66-
67-
num_susp = 0;
68-
}
69-
#endif /* defined(CONFIG_PM_DEVICE) */
70-
7113
const char *pm_device_state_str(enum pm_device_state state)
7214
{
7315
switch (state) {

subsys/pm/pm_priv.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

subsys/pm/power.c

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <device.h>
78
#include <zephyr.h>
89
#include <kernel.h>
910
#include <timeout_q.h>
1011
#include <init.h>
1112
#include <string.h>
13+
#include <pm/device.h>
1214
#include <pm/pm.h>
1315
#include <pm/state.h>
1416
#include <pm/policy.h>
1517
#include <tracing/tracing.h>
1618

17-
#include "pm_priv.h"
18-
1919
#define PM_STATES_LEN (1 + PM_STATE_SOFT_OFF - PM_STATE_ACTIVE)
2020
#include <logging/log.h>
2121
LOG_MODULE_REGISTER(pm, CONFIG_PM_LOG_LEVEL);
@@ -99,6 +99,61 @@ static inline void pm_stop_timer(void) {}
9999
static void pm_stats_update(enum pm_state state) {}
100100
#endif
101101

102+
#ifdef CONFIG_PM_DEVICE
103+
extern const struct device *__pm_device_slots_start[];
104+
105+
/* Number of devices successfully suspended. */
106+
static size_t num_susp;
107+
108+
static int pm_suspend_devices(void)
109+
{
110+
const struct device *devs;
111+
size_t devc;
112+
113+
devc = z_device_get_all_static(&devs);
114+
115+
num_susp = 0;
116+
117+
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) {
118+
int ret;
119+
120+
/* ignore busy devices */
121+
if (pm_device_is_busy(dev) || pm_device_wakeup_is_enabled(dev)) {
122+
continue;
123+
}
124+
125+
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
126+
/* ignore devices not supporting or already at the given state */
127+
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) {
128+
continue;
129+
} else if (ret < 0) {
130+
LOG_ERR("Device %s did not enter %s state (%d)",
131+
dev->name,
132+
pm_device_state_str(PM_DEVICE_STATE_SUSPENDED),
133+
ret);
134+
return ret;
135+
}
136+
137+
__pm_device_slots_start[num_susp] = dev;
138+
num_susp++;
139+
}
140+
141+
return 0;
142+
}
143+
144+
static void pm_resume_devices(void)
145+
{
146+
size_t i;
147+
148+
for (i = 0; i < num_susp; i++) {
149+
pm_device_state_set(__pm_device_slots_start[i],
150+
PM_DEVICE_STATE_ACTIVE);
151+
}
152+
153+
num_susp = 0;
154+
}
155+
#endif /* CONFIG_PM_DEVICE */
156+
102157
static inline void exit_pos_ops(struct pm_state_info info)
103158
{
104159
extern __weak void

0 commit comments

Comments
 (0)