7#ifndef ZEPHYR_INCLUDE_PM_DEVICE_H_
8#define ZEPHYR_INCLUDE_PM_DEVICE_H_
35 PM_DEVICE_FLAG_TURN_ON_FAILED,
37 PM_DEVICE_FLAG_PD_CLAIMED,
42 PM_DEVICE_FLAG_WS_CAPABLE,
44 PM_DEVICE_FLAG_WS_ENABLED,
46 PM_DEVICE_FLAG_RUNTIME_ENABLED,
48 PM_DEVICE_FLAG_STATE_LOCKED,
52 PM_DEVICE_FLAG_RUNTIME_AUTO,
54 PM_DEVICE_FLAG_ISR_SAFE,
67#define PM_DEVICE_ISR_SAFE 1
148#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__)
152#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
154 const struct device *domain;
168#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__)
190#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__)
197BUILD_ASSERT(offsetof(
struct pm_device, base) == 0);
202#ifdef CONFIG_PM_DEVICE_RUNTIME
203#define Z_PM_DEVICE_RUNTIME_INIT(obj) \
204 .lock = Z_SEM_INITIALIZER(obj.lock, 1, 1), \
205 .event = Z_EVENT_INITIALIZER(obj.event),
207#define Z_PM_DEVICE_RUNTIME_INIT(obj)
210#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN
211#define Z_PM_DEVICE_POWER_DOMAIN_INIT(_node_id) \
212 .domain = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(_node_id, \
215#define Z_PM_DEVICE_POWER_DOMAIN_INIT(obj)
223#define Z_PM_DEVICE_FLAGS(node_id) \
225 DT_NODE_EXISTS(node_id), \
226 ((DT_PROP_OR(node_id, wakeup_source, 0) \
227 << PM_DEVICE_FLAG_WS_CAPABLE) | \
228 (DT_PROP_OR(node_id, zephyr_pm_device_runtime_auto, 0) \
229 << PM_DEVICE_FLAG_RUNTIME_AUTO) | \
230 (DT_NODE_HAS_COMPAT(node_id, power_domain) << \
231 PM_DEVICE_FLAG_PD)), \
245#define Z_PM_DEVICE_BASE_INIT(obj, node_id, pm_action_cb, _flags) \
247 .action_cb = pm_action_cb, \
248 .state = PM_DEVICE_STATE_ACTIVE, \
249 .flags = ATOMIC_INIT(Z_PM_DEVICE_FLAGS(node_id) | (_flags)), \
250 Z_PM_DEVICE_POWER_DOMAIN_INIT(node_id) \
263#define Z_PM_DEVICE_INIT(obj, node_id, pm_action_cb, isr_safe) \
265 .base = Z_PM_DEVICE_BASE_INIT(obj, node_id, pm_action_cb, \
266 isr_safe ? BIT(PM_DEVICE_FLAG_ISR_SAFE) : 0), \
267 COND_CODE_1(isr_safe, (), (Z_PM_DEVICE_RUNTIME_INIT(obj))) \
275#define Z_PM_DEVICE_NAME(dev_id) _CONCAT(__pm_device_, dev_id)
288#define Z_PM_DEVICE_DEFINE_SLOT(dev_id) \
289 static STRUCT_SECTION_ITERABLE_ALTERNATE(pm_device_slots, device, \
290 _CONCAT(__pm_slot_, dev_id))
292#ifdef CONFIG_PM_DEVICE
300#define Z_PM_DEVICE_DEFINE(node_id, dev_id, pm_action_cb, isr_safe) \
301 Z_PM_DEVICE_DEFINE_SLOT(dev_id); \
302 static struct COND_CODE_1(isr_safe, (pm_device_isr), (pm_device)) \
303 Z_PM_DEVICE_NAME(dev_id) = \
304 Z_PM_DEVICE_INIT(Z_PM_DEVICE_NAME(dev_id), node_id, \
305 pm_action_cb, isr_safe)
312#define Z_PM_DEVICE_GET(dev_id) ((struct pm_device_base *)&Z_PM_DEVICE_NAME(dev_id))
315#define Z_PM_DEVICE_DEFINE(node_id, dev_id, pm_action_cb, isr_safe)
316#define Z_PM_DEVICE_GET(dev_id) NULL
332#define PM_DEVICE_DEFINE(dev_id, pm_action_cb, ...) \
333 Z_PM_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, pm_action_cb, \
334 COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (__VA_ARGS__)))
347#define PM_DEVICE_DT_DEFINE(node_id, pm_action_cb, ...) \
348 Z_PM_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), pm_action_cb, \
349 COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (__VA_ARGS__)))
362#define PM_DEVICE_DT_INST_DEFINE(idx, pm_action_cb, ...) \
363 Z_PM_DEVICE_DEFINE(DT_DRV_INST(idx), \
364 Z_DEVICE_DT_DEV_ID(DT_DRV_INST(idx)), \
366 COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (__VA_ARGS__)))
376#define PM_DEVICE_GET(dev_id) \
377 Z_PM_DEVICE_GET(dev_id)
387#define PM_DEVICE_DT_GET(node_id) \
388 PM_DEVICE_GET(Z_DEVICE_DT_DEV_ID(node_id))
398#define PM_DEVICE_DT_INST_GET(idx) \
399 PM_DEVICE_DT_GET(DT_DRV_INST(idx))
442#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
629 const struct device *domain);
644 const struct device *domain);
742 const struct device *domain)
750 const struct device *domain)
long atomic_t
Definition: atomic_types.h:15
bool pm_device_wakeup_is_enabled(const struct device *dev)
Check if a device is enabled as a wake up source.
int pm_device_power_domain_remove(const struct device *dev, const struct device *domain)
Remove a device from a power domain.
bool pm_device_on_power_domain(const struct device *dev)
Check if the device is on a switchable power domain.
int pm_device_action_run(const struct device *dev, enum pm_device_action action)
Run a pm action on a device.
static void pm_device_init_suspended(const struct device *dev)
Initialize a device state to PM_DEVICE_STATE_SUSPENDED.
Definition: device.h:466
pm_device_state
Device power states.
Definition: device.h:70
bool pm_device_wakeup_enable(const struct device *dev, bool enable)
Enable or disable a device as a wake up source.
void pm_device_children_action_run(const struct device *dev, enum pm_device_action action, pm_device_action_failed_cb_t failure_cb)
Run a pm action on all children of a device.
void pm_device_busy_set(const struct device *dev)
Mark a device as busy.
int(* pm_device_action_cb_t)(const struct device *dev, enum pm_device_action action)
Device PM action callback.
Definition: device.h:121
void pm_device_busy_clear(const struct device *dev)
Clear a device busy status.
bool pm_device_is_busy(const struct device *dev)
Check if a device is busy.
bool(* pm_device_action_failed_cb_t)(const struct device *dev, int err)
Device PM action failed callback.
Definition: device.h:132
bool pm_device_is_powered(const struct device *dev)
Check if the device is currently powered.
int pm_device_power_domain_add(const struct device *dev, const struct device *domain)
Add a device to a power domain.
void pm_device_state_unlock(const struct device *dev)
Unlock the current device state.
void pm_device_state_lock(const struct device *dev)
Lock current device state.
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.
int pm_device_driver_init(const struct device *dev, pm_device_action_cb_t action_cb)
Setup a device driver into the lowest valid power mode.
bool pm_device_is_any_busy(void)
Check if any device is busy.
pm_device_action
Device PM actions.
Definition: device.h:92
bool pm_device_state_is_locked(const struct device *dev)
Check if the device pm is locked.
static void pm_device_init_off(const struct device *dev)
Initialize a device state to PM_DEVICE_STATE_OFF.
Definition: device.h:486
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
Device is suspended.
Definition: device.h:79
@ PM_DEVICE_STATE_OFF
Device is turned off (power removed).
Definition: device.h:88
@ PM_DEVICE_STATE_SUSPENDING
Device is being suspended.
Definition: device.h:81
@ PM_DEVICE_STATE_ACTIVE
Device is in active or regular state.
Definition: device.h:72
@ PM_DEVICE_ACTION_TURN_OFF
Turn off.
Definition: device.h:102
@ PM_DEVICE_ACTION_SUSPEND
Suspend.
Definition: device.h:94
@ PM_DEVICE_ACTION_RESUME
Resume.
Definition: device.h:96
@ PM_DEVICE_ACTION_TURN_ON
Turn on.
Definition: device.h:108
#define ENOSYS
Function not implemented.
Definition: errno.h:83
state
Definition: parser_state.h:29
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
struct pm_device_base * pm_base
Definition: device.h:415
Event Structure.
Definition: kernel.h:2207
Kernel Spin Lock.
Definition: spinlock.h:45
A structure used to submit work after a delay.
Definition: kernel.h:3889
Device PM info.
Definition: device.h:141
uint32_t usage
Device usage count.
Definition: device.h:150
pm_device_action_cb_t action_cb
Device PM action callback.
Definition: device.h:147
enum pm_device_state state
Device power state.
Definition: device.h:145
atomic_t flags
Device PM status flags.
Definition: device.h:143
Runtime PM info for device with synchronous PM.
Definition: device.h:187
struct k_spinlock lock
Lock to synchronize the synchronous get/put operations.
Definition: device.h:192
struct pm_device_base base
Base info.
Definition: device.h:189
Runtime PM info for device with generic PM.
Definition: device.h:165
struct k_work_delayable work
Work object for asynchronous calls.
Definition: device.h:176
struct k_event event
Event var to listen to the sync request events.
Definition: device.h:174
struct k_sem lock
Lock to synchronize the get/put operations.
Definition: device.h:172
const struct device * dev
Pointer to the device.
Definition: device.h:170
struct pm_device_base base
Base info.
Definition: device.h:167