2021-04-29 13:32:28 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
2021-10-21 18:35:38 +02:00
|
|
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_
|
|
|
|
#define ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_
|
|
|
|
|
2021-04-29 13:45:57 +02:00
|
|
|
#include <device.h>
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-10-29 11:10:49 +02:00
|
|
|
* @brief Device Runtime Power Management API
|
|
|
|
* @defgroup subsys_pm_device_runtime Device Runtime
|
|
|
|
* @ingroup subsys_pm
|
2021-04-29 13:32:28 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-10-21 18:35:38 +02:00
|
|
|
#if defined(CONFIG_PM_DEVICE_RUNTIME) || defined(__DOXYGEN__)
|
2021-04-29 13:32:28 +02:00
|
|
|
/**
|
2021-05-03 17:11:11 +02:00
|
|
|
* @brief Enable device runtime PM
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-05-20 15:16:46 -07:00
|
|
|
* @funcprops \pre_kernel_ok
|
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @param dev Device instance.
|
2021-12-14 09:47:00 -08:00
|
|
|
*
|
|
|
|
* @retval 0 If the device runtime PM is enabled successfully.
|
|
|
|
* @retval -EPERM If device has power state locked.
|
|
|
|
* @retval -ENOSYS If the functionality is not available.
|
2021-04-29 13:32:28 +02:00
|
|
|
*/
|
2021-12-14 09:47:00 -08:00
|
|
|
int pm_device_runtime_enable(const struct device *dev);
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/**
|
2021-05-03 17:11:11 +02:00
|
|
|
* @brief Disable device runtime PM
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* If the device is currently suspended it will be resumed.
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-05-20 15:16:46 -07:00
|
|
|
* @funcprops \pre_kernel_ok
|
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @param dev Device instance.
|
|
|
|
*
|
|
|
|
* @retval 0 If the device runtime PM is disabled successfully.
|
|
|
|
* @retval -ENOSYS If the functionality is not available.
|
|
|
|
* @retval -errno Other negative errno, result of resuming the device.
|
2021-04-29 13:32:28 +02:00
|
|
|
*/
|
2021-11-02 11:27:16 +01:00
|
|
|
int pm_device_runtime_disable(const struct device *dev);
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-21 18:35:38 +02:00
|
|
|
* @brief Resume a device based on usage count.
|
|
|
|
*
|
|
|
|
* This function will resume the device if the device is suspended (usage count
|
|
|
|
* equal to 0). In case of a resume failure, usage count and device state will
|
|
|
|
* be left unchanged. In all other cases, usage count will be incremented.
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* If the device is still being suspended as a result of calling
|
2021-11-02 11:27:16 +01:00
|
|
|
* pm_device_runtime_put_async(), this function will wait for the operation to
|
|
|
|
* finish to then resume the device.
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @funcprops \pre_kernel_ok
|
|
|
|
*
|
|
|
|
* @param dev Device instance.
|
|
|
|
*
|
2021-11-25 11:36:49 +01:00
|
|
|
* @retval 0 If it succeeds. In case device runtime PM is not enabled or not
|
|
|
|
* available this function will be a no-op and will also return 0.
|
2021-10-21 18:35:38 +02:00
|
|
|
* @retval -errno Other negative errno, result of the PM action callback.
|
2021-04-29 13:32:28 +02:00
|
|
|
*/
|
2021-11-02 11:27:16 +01:00
|
|
|
int pm_device_runtime_get(const struct device *dev);
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-21 18:35:38 +02:00
|
|
|
* @brief Suspend a device based on usage count.
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* This function will suspend the device if the device is no longer required
|
|
|
|
* (usage count equal to 0). In case of suspend failure, usage count and device
|
|
|
|
* state will be left unchanged. In all other cases, usage count will be
|
|
|
|
* decremented (down to 0).
|
|
|
|
*
|
|
|
|
* @funcprops \pre_kernel_ok
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @param dev Device instance.
|
2021-05-20 15:16:46 -07:00
|
|
|
*
|
2021-11-25 11:36:49 +01:00
|
|
|
* @retval 0 If it succeeds. In case device runtime PM is not enabled or not
|
|
|
|
* available this function will be a no-op and will also return 0.
|
2021-10-21 18:35:38 +02:00
|
|
|
* @retval -EALREADY If device is already suspended (can only happen if get/put
|
|
|
|
* calls are unbalanced).
|
|
|
|
* @retval -errno Other negative errno, result of the action callback.
|
|
|
|
*
|
2021-11-02 11:27:16 +01:00
|
|
|
* @see pm_device_runtime_put_async()
|
2021-04-29 13:32:28 +02:00
|
|
|
*/
|
2021-11-02 11:27:16 +01:00
|
|
|
int pm_device_runtime_put(const struct device *dev);
|
2021-04-29 13:32:28 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-21 18:35:38 +02:00
|
|
|
* @brief Suspend a device based on usage count (asynchronously).
|
|
|
|
*
|
|
|
|
* This function will schedule the device suspension if the device is no longer
|
|
|
|
* required (usage count equal to 0). In all other cases, usage count will be
|
|
|
|
* decremented (down to 0).
|
|
|
|
*
|
|
|
|
* @note Asynchronous operations are not supported when in pre-kernel mode. In
|
2021-11-02 11:27:16 +01:00
|
|
|
* this case, the function will be blocking (equivalent to
|
|
|
|
* pm_device_runtime_put()).
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @funcprops \pre_kernel_ok, \async
|
2021-04-29 13:32:28 +02:00
|
|
|
*
|
2021-10-21 18:35:38 +02:00
|
|
|
* @param dev Device instance.
|
|
|
|
*
|
2021-11-25 11:36:49 +01:00
|
|
|
* @retval 0 If it succeeds. In case device runtime PM is not enabled or not
|
|
|
|
* available this function will be a no-op and will also return 0.
|
2021-10-21 18:35:38 +02:00
|
|
|
* @retval -EALREADY If device is already suspended (can only happen if get/put
|
|
|
|
* calls are unbalanced).
|
|
|
|
*
|
2021-11-02 11:27:16 +01:00
|
|
|
* @see pm_device_runtime_put()
|
2021-04-29 13:32:28 +02:00
|
|
|
*/
|
2021-11-02 11:27:16 +01:00
|
|
|
int pm_device_runtime_put_async(const struct device *dev);
|
2021-05-17 22:41:46 -07:00
|
|
|
|
2021-11-05 19:18:02 -07:00
|
|
|
/**
|
|
|
|
* @brief Check if device runtime is enabled for a given device.
|
|
|
|
*
|
|
|
|
* @funcprops \pre_kernel_ok
|
|
|
|
*
|
|
|
|
* @param dev Device instance.
|
|
|
|
*
|
|
|
|
* @retval true If device has device runtime PM enabled.
|
|
|
|
* @retval false If the device has device runtime PM disabled.
|
|
|
|
*
|
|
|
|
* @see pm_device_runtime_enable()
|
|
|
|
*/
|
|
|
|
bool pm_device_runtime_is_enabled(const struct device *dev);
|
|
|
|
|
2021-04-29 13:32:28 +02:00
|
|
|
#else
|
2021-12-14 09:47:00 -08:00
|
|
|
static inline int pm_device_runtime_enable(const struct device *dev) { return -ENOSYS; }
|
2021-11-02 11:27:16 +01:00
|
|
|
static inline int pm_device_runtime_disable(const struct device *dev) { return -ENOSYS; }
|
2021-11-25 11:36:49 +01:00
|
|
|
static inline int pm_device_runtime_get(const struct device *dev) { return 0; }
|
|
|
|
static inline int pm_device_runtime_put(const struct device *dev) { return 0; }
|
|
|
|
static inline int pm_device_runtime_put_async(const struct device *dev) { return 0; }
|
2021-11-05 19:18:02 -07:00
|
|
|
static inline bool pm_device_runtime_is_enabled(const struct device *dev) { return false; }
|
2021-04-29 13:32:28 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#endif /* ZEPHYR_INCLUDE_PM_DEVICE_RUNTIME_H_ */
|