Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_PM_DEVICE_H_
8#define ZEPHYR_INCLUDE_PM_DEVICE_H_
9
10#include <kernel.h>
11#include <sys/atomic.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
25struct device;
26
52};
53
69};
70
83};
84
88struct pm_device {
90 const struct device *dev;
92 struct k_mutex lock;
93 /* Following are packed fields protected by #lock. */
95 bool enable : 1;
96 /* Device PM status flags. */
106};
107
117#define Z_PM_DEVICE_INIT(obj, node_id) \
118 { \
119 .usage = 0U, \
120 .lock = Z_MUTEX_INITIALIZER(obj.lock), \
121 .condvar = Z_CONDVAR_INITIALIZER(obj.condvar), \
122 .state = PM_DEVICE_STATE_ACTIVE, \
123 .flags = ATOMIC_INIT(COND_CODE_1( \
124 DT_NODE_EXISTS(node_id), \
125 (DT_PROP_OR(node_id, wakeup_source, 0)),\
126 (0)) << PM_DEVICE_FLAGS_WS_CAPABLE), \
127 }
128
139typedef int (*pm_device_control_callback_t)(const struct device *dev,
140 enum pm_device_action action);
141
148
167int pm_device_state_set(const struct device *dev,
169
179int pm_device_state_get(const struct device *dev,
180 enum pm_device_state *state);
181
182#ifdef CONFIG_PM_DEVICE
191void pm_device_busy_set(const struct device *dev);
192
200void pm_device_busy_clear(const struct device *dev);
201
211bool pm_device_is_any_busy(void);
212
224bool pm_device_is_busy(const struct device *dev);
225#else
226static inline void pm_device_busy_set(const struct device *dev) {}
227static inline void pm_device_busy_clear(const struct device *dev) {}
228static inline bool pm_device_is_any_busy(void) { return false; }
229static inline bool pm_device_is_busy(const struct device *dev) { return false; }
230#endif
231
232__deprecated static inline void device_busy_set(const struct device *dev)
233{
235}
236
237__deprecated static inline void device_busy_clear(const struct device *dev)
238{
240}
241
242__deprecated static inline int device_any_busy_check(void)
243{
244 return pm_device_is_any_busy() ? -EBUSY : 0;
245}
246
247__deprecated static inline int device_busy_check(const struct device *dev)
248{
249 return pm_device_is_busy(dev) ? -EBUSY : 0;
250}
251
253#define device_pm_control_nop __DEPRECATED_MACRO NULL
254
267bool pm_device_wakeup_enable(struct device *dev, bool enable);
268
279bool pm_device_wakeup_is_enabled(const struct device *dev);
280
289bool pm_device_wakeup_is_capable(const struct device *dev);
290
293#ifdef __cplusplus
294}
295#endif
296
297#endif
int atomic_t
Definition: atomic.h:21
bool pm_device_wakeup_is_enabled(const struct device *dev)
Check if a power management wakeup source is enabled.
static void pm_device_busy_clear(const struct device *dev)
Definition: device.h:227
static int device_busy_check(const struct device *dev)
Definition: device.h:247
int pm_device_state_set(const struct device *dev, enum pm_device_state state)
Set the power state of a device.
static void pm_device_busy_set(const struct device *dev)
Definition: device.h:226
pm_device_state
Device power states.
Definition: device.h:28
static bool pm_device_is_any_busy(void)
Definition: device.h:228
bool pm_device_wakeup_enable(struct device *dev, bool enable)
Enable a power management wakeup source.
static int device_any_busy_check(void)
Definition: device.h:242
int(* pm_device_control_callback_t)(const struct device *dev, enum pm_device_action action)
Device power management control function callback.
Definition: device.h:139
static void device_busy_set(const struct device *dev)
Definition: device.h:232
bool pm_device_wakeup_is_capable(const struct device *dev)
Check if a device is wake up capable.
const char * pm_device_state_str(enum pm_device_state state)
Get name of device PM state.
static void device_busy_clear(const struct device *dev)
Definition: device.h:237
pm_device_action
Device PM actions.
Definition: device.h:72
pm_device_flag
Device PM flags.
Definition: device.h:55
static bool pm_device_is_busy(const struct device *dev)
Definition: device.h:229
int pm_device_state_get(const struct device *dev, enum pm_device_state *state)
Obtain the power state of a device.
@ PM_DEVICE_STATE_SUSPENDED
Definition: device.h:44
@ PM_DEVICE_STATE_OFF
Definition: device.h:51
@ PM_DEVICE_STATE_ACTIVE
Definition: device.h:30
@ PM_DEVICE_STATE_LOW_POWER
Definition: device.h:37
@ PM_DEVICE_ACTION_TURN_OFF
Definition: device.h:78
@ PM_DEVICE_ACTION_SUSPEND
Definition: device.h:74
@ PM_DEVICE_ACTION_FORCE_SUSPEND
Definition: device.h:80
@ PM_DEVICE_ACTION_RESUME
Definition: device.h:76
@ PM_DEVICE_ACTION_LOW_POWER
Definition: device.h:82
@ PM_DEVICE_FLAGS_WS_ENABLED
Definition: device.h:64
@ PM_DEVICE_FLAG_TRANSITIONING
Definition: device.h:66
@ PM_DEVICE_FLAGS_WS_CAPABLE
Definition: device.h:62
@ PM_DEVICE_FLAG_COUNT
Definition: device.h:68
@ PM_DEVICE_FLAG_BUSY
Definition: device.h:57
#define EBUSY
Definition: errno.h:55
state
Definition: http_parser_state.h:30
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
Definition: kernel.h:2786
Definition: kernel.h:2680
A structure used to submit work after a delay.
Definition: kernel.h:3651
Device PM info.
Definition: device.h:88
uint32_t usage
Definition: device.h:99
enum pm_device_state state
Definition: device.h:101
struct k_mutex lock
Definition: device.h:92
struct k_work_delayable work
Definition: device.h:103
atomic_t flags
Definition: device.h:97
struct k_condvar condvar
Definition: device.h:105
const struct device * dev
Definition: device.h:90
bool enable
Definition: device.h:95