2021-04-29 13:32:28 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_PM_DEVICE_H_
|
|
|
|
#define ZEPHYR_INCLUDE_PM_DEVICE_H_
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device Power Management API
|
|
|
|
*
|
|
|
|
* @defgroup device_power_management_api Device Power Management API
|
|
|
|
* @ingroup power_management_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct device;
|
|
|
|
|
2021-05-03 17:36:10 +02:00
|
|
|
/** @def PM_DEVICE_ACTIVE_STATE
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* @brief device is in ACTIVE power state
|
|
|
|
*
|
|
|
|
* @details Normal operation of the device. All device context is retained.
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_ACTIVE_STATE 1
|
2021-04-29 13:32:28 +02:00
|
|
|
|
2021-05-03 17:36:10 +02:00
|
|
|
/** @def PM_DEVICE_LOW_POWER_STATE
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* @brief device is in LOW power state
|
|
|
|
*
|
|
|
|
* @details Device context is preserved by the HW and need not be
|
|
|
|
* restored by the driver.
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_LOW_POWER_STATE 2
|
2021-04-29 13:32:28 +02:00
|
|
|
|
2021-05-03 17:36:10 +02:00
|
|
|
/** @def PM_DEVICE_SUSPEND_STATE
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* @brief device is in SUSPEND power state
|
|
|
|
*
|
|
|
|
* @details Most device context is lost by the hardware.
|
|
|
|
* Device drivers must save and restore or reinitialize any context
|
|
|
|
* lost by the hardware
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_SUSPEND_STATE 3
|
2021-04-29 13:32:28 +02:00
|
|
|
|
2021-05-03 17:36:10 +02:00
|
|
|
/** @def PM_DEVICE_FORCE_SUSPEND_STATE
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* @brief device is in force SUSPEND power state
|
|
|
|
*
|
|
|
|
* @details Driver puts the device in suspended state after
|
|
|
|
* completing the ongoing transactions and will not process any
|
|
|
|
* queued work or will not take any new requests for processing.
|
|
|
|
* Most device context is lost by the hardware. Device drivers must
|
|
|
|
* save and restore or reinitialize any context lost by the hardware.
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_FORCE_SUSPEND_STATE 4
|
2021-04-29 13:32:28 +02:00
|
|
|
|
2021-05-03 17:36:10 +02:00
|
|
|
/** @def PM_DEVICE_OFF_STATE
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* @brief device is in OFF power state
|
|
|
|
*
|
|
|
|
* @details - Power has been fully removed from the device.
|
|
|
|
* The device context is lost when this state is entered, so the OS
|
|
|
|
* software will reinitialize the device when powering it back on
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_OFF_STATE 5
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/* Constants defining support device power commands */
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_SET_POWER_STATE 1
|
|
|
|
#define PM_DEVICE_GET_POWER_STATE 2
|
2021-04-29 13:32:28 +02:00
|
|
|
|
2021-05-03 18:01:40 +02:00
|
|
|
typedef void (*pm_device_cb)(const struct device *dev,
|
2021-04-29 13:32:28 +02:00
|
|
|
int status, void *context, void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Device PM info
|
|
|
|
*/
|
2021-05-03 17:42:31 +02:00
|
|
|
struct pm_device {
|
2021-04-29 13:32:28 +02:00
|
|
|
/** Pointer to the device */
|
|
|
|
const struct device *dev;
|
|
|
|
/** Lock to synchronize the get/put operations */
|
|
|
|
struct k_sem lock;
|
|
|
|
/* Following are packed fields protected by #lock. */
|
|
|
|
/** Device pm enable flag */
|
|
|
|
bool enable : 1;
|
|
|
|
/* Following are packed fields accessed with atomic bit operations. */
|
|
|
|
atomic_t atomic_flags;
|
|
|
|
/** Device usage count */
|
|
|
|
atomic_t usage;
|
|
|
|
/** Device idle internal power state */
|
|
|
|
atomic_t fsm_state;
|
|
|
|
/** Work object for asynchronous calls */
|
|
|
|
struct k_work work;
|
|
|
|
/** Event object to listen to the sync request events */
|
|
|
|
struct k_poll_event event;
|
|
|
|
/** Signal to notify the Async API callers */
|
|
|
|
struct k_poll_signal signal;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Bit position in device_pm::atomic_flags that records whether the
|
|
|
|
* device is busy.
|
|
|
|
*/
|
2021-05-03 17:36:10 +02:00
|
|
|
#define PM_DEVICE_ATOMIC_FLAGS_BUSY_BIT 0
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get name of device PM state
|
|
|
|
*
|
|
|
|
* @param state State id which name should be returned
|
|
|
|
*/
|
2021-05-03 17:45:25 +02:00
|
|
|
const char *pm_device_state_str(uint32_t state);
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/** Alias for legacy use of device_pm_control_nop */
|
|
|
|
#define device_pm_control_nop __DEPRECATED_MACRO NULL
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|