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,
 
  127#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__) 
  139#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN 
  141        const struct device *domain;
 
  153#ifdef CONFIG_PM_DEVICE_RUNTIME 
  154#define Z_PM_DEVICE_RUNTIME_INIT(obj)                   \ 
  155        .lock = Z_SEM_INITIALIZER(obj.lock, 1, 1),      \ 
  156        .event = Z_EVENT_INITIALIZER(obj.event), 
  158#define Z_PM_DEVICE_RUNTIME_INIT(obj) 
  161#ifdef CONFIG_PM_DEVICE_POWER_DOMAIN 
  162#define Z_PM_DEVICE_POWER_DOMAIN_INIT(_node_id)                 \ 
  163        .domain = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(_node_id,    \ 
  166#define Z_PM_DEVICE_POWER_DOMAIN_INIT(obj) 
  174#define Z_PM_DEVICE_FLAGS(node_id)                                       \ 
  176                 DT_NODE_EXISTS(node_id),                                \ 
  177                 ((DT_PROP_OR(node_id, wakeup_source, 0)                 \ 
  178                         << PM_DEVICE_FLAG_WS_CAPABLE) |                 \ 
  179                  (DT_PROP_OR(node_id, zephyr_pm_device_runtime_auto, 0) \ 
  180                         << PM_DEVICE_FLAG_RUNTIME_AUTO) |               \ 
  181                  (DT_NODE_HAS_COMPAT(node_id, power_domain) <<          \ 
  182                         PM_DEVICE_FLAG_PD)),                            \ 
  195#define Z_PM_DEVICE_INIT(obj, node_id, pm_action_cb)              \ 
  197                Z_PM_DEVICE_RUNTIME_INIT(obj)                     \ 
  198                .action_cb = pm_action_cb,                        \ 
  199                .state = PM_DEVICE_STATE_ACTIVE,                  \ 
  200                .flags = ATOMIC_INIT(Z_PM_DEVICE_FLAGS(node_id)), \ 
  201                Z_PM_DEVICE_POWER_DOMAIN_INIT(node_id)            \ 
  209#define Z_PM_DEVICE_NAME(dev_id) _CONCAT(__pm_device_, dev_id) 
  222#define Z_PM_DEVICE_DEFINE_SLOT(dev_id)                                 \ 
  223        static const STRUCT_SECTION_ITERABLE_ALTERNATE(pm_device_slots, device, \ 
  224                        _CONCAT(__pm_slot_, dev_id)) 
  226#ifdef CONFIG_PM_DEVICE 
  234#define Z_PM_DEVICE_DEFINE(node_id, dev_id, pm_action_cb)               \ 
  235        Z_PM_DEVICE_DEFINE_SLOT(dev_id);                                \ 
  236        static struct pm_device Z_PM_DEVICE_NAME(dev_id) =              \ 
  237        Z_PM_DEVICE_INIT(Z_PM_DEVICE_NAME(dev_id), node_id,             \ 
  245#define Z_PM_DEVICE_GET(dev_id) (&Z_PM_DEVICE_NAME(dev_id)) 
  248#define Z_PM_DEVICE_DEFINE(node_id, dev_id, pm_action_cb) 
  249#define Z_PM_DEVICE_GET(dev_id) NULL 
  264#define PM_DEVICE_DEFINE(dev_id, pm_action_cb) \ 
  265        Z_PM_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, pm_action_cb) 
  277#define PM_DEVICE_DT_DEFINE(node_id, pm_action_cb)                      \ 
  278        Z_PM_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id),        \ 
  291#define PM_DEVICE_DT_INST_DEFINE(idx, pm_action_cb)                     \ 
  292        Z_PM_DEVICE_DEFINE(DT_DRV_INST(idx),                            \ 
  293                           Z_DEVICE_DT_DEV_ID(DT_DRV_INST(idx)),        \ 
  304#define PM_DEVICE_GET(dev_id) \ 
  305        Z_PM_DEVICE_GET(dev_id) 
  315#define PM_DEVICE_DT_GET(node_id) \ 
  316        PM_DEVICE_GET(Z_DEVICE_DT_DEV_ID(node_id)) 
  326#define PM_DEVICE_DT_INST_GET(idx) \ 
  327        PM_DEVICE_DT_GET(DT_DRV_INST(idx)) 
  370#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__) 
  557                               const struct device *domain);
 
  572                                  const struct device *domain);
 
  653                                             const struct device *domain)
 
  659                                                const struct device *domain)
 
long atomic_t
Definition: atomic.h:22
 
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:394
 
pm_device_state
Device power states.
Definition: device.h:58
 
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:109
 
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:120
 
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.
 
bool pm_device_is_any_busy(void)
Check if any device is busy.
 
pm_device_action
Device PM actions.
Definition: device.h:80
 
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:414
 
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:67
 
@ PM_DEVICE_STATE_OFF
Definition: device.h:76
 
@ PM_DEVICE_STATE_SUSPENDING
Definition: device.h:69
 
@ PM_DEVICE_STATE_ACTIVE
Definition: device.h:60
 
@ PM_DEVICE_ACTION_TURN_OFF
Definition: device.h:90
 
@ PM_DEVICE_ACTION_SUSPEND
Definition: device.h:82
 
@ PM_DEVICE_ACTION_RESUME
Definition: device.h:84
 
@ PM_DEVICE_ACTION_TURN_ON
Definition: device.h:96
 
#define ENOSYS
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:380
 
struct pm_device * pm
Definition: device.h:405
 
Definition: kernel.h:2169
 
A structure used to submit work after a delay.
Definition: kernel.h:3793
 
Device PM info.
Definition: device.h:126
 
uint32_t usage
Definition: device.h:135
 
enum pm_device_state state
Definition: device.h:146
 
pm_device_action_cb_t action_cb
Definition: device.h:148
 
struct k_work_delayable work
Definition: device.h:137
 
atomic_t flags
Definition: device.h:144
 
struct k_event event
Definition: device.h:133
 
struct k_sem lock
Definition: device.h:131
 
const struct device * dev
Definition: device.h:129