pm: runtime: rename API with pm_device prefix

Use `pm_device_*` prefix for the device runtime PM API. This adds the
API to the `pm` namespace, making it clear part of the PM subsystem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-05-03 17:11:11 +02:00 committed by Anas Nashif
commit c524075780
7 changed files with 52 additions and 50 deletions

View file

@ -26,27 +26,27 @@ extern "C" {
#ifdef CONFIG_PM_DEVICE_RUNTIME
/**
* @brief Enable device idle PM
* @brief Enable device runtime PM
*
* Called by a device driver to enable device idle power management.
* The device might be asynchronously suspended if Idle PM is enabled
* Called by a device driver to enable device runtime power management.
* The device might be asynchronously suspended if runtime PM is enabled
* when the device is not use.
*
* @param dev Pointer to device structure of the specific device driver
* the caller is interested in.
*/
void device_pm_enable(const struct device *dev);
void pm_device_enable(const struct device *dev);
/**
* @brief Disable device idle PM
* @brief Disable device runtime PM
*
* Called by a device driver to disable device idle power management.
* The device might be asynchronously resumed if Idle PM is disabled
* Called by a device driver to disable device runtime power management.
* The device might be asynchronously resumed if runtime PM is disabled
*
* @param dev Pointer to device structure of the specific device driver
* the caller is interested in.
*/
void device_pm_disable(const struct device *dev);
void pm_device_disable(const struct device *dev);
/**
* @brief Call device resume asynchronously based on usage count
@ -62,7 +62,7 @@ void device_pm_disable(const struct device *dev);
* pm signal mechanism to know the completion of resume operation.
* @retval Errno Negative errno code if failure.
*/
int device_pm_get(const struct device *dev);
int pm_device_get(const struct device *dev);
/**
* @brief Call device resume synchronously based on usage count
@ -77,7 +77,7 @@ int device_pm_get(const struct device *dev);
* @retval 0 If successful.
* @retval Errno Negative errno code if failure.
*/
int device_pm_get_sync(const struct device *dev);
int pm_device_get_sync(const struct device *dev);
/**
* @brief Call device suspend asynchronously based on usage count
@ -93,7 +93,7 @@ int device_pm_get_sync(const struct device *dev);
* signal mechanism to know the completion of suspend operation.
* @retval Errno Negative errno code if failure.
*/
int device_pm_put(const struct device *dev);
int pm_device_put(const struct device *dev);
/**
* @brief Call device suspend synchronously based on usage count
@ -108,14 +108,14 @@ int device_pm_put(const struct device *dev);
* @retval 0 If successful.
* @retval Errno Negative errno code if failure.
*/
int device_pm_put_sync(const struct device *dev);
int pm_device_put_sync(const struct device *dev);
#else
static inline void device_pm_enable(const struct device *dev) { }
static inline void device_pm_disable(const struct device *dev) { }
static inline int device_pm_get(const struct device *dev) { return -ENOSYS; }
static inline int device_pm_get_sync(const struct device *dev) { return -ENOSYS; }
static inline int device_pm_put(const struct device *dev) { return -ENOSYS; }
static inline int device_pm_put_sync(const struct device *dev) { return -ENOSYS; }
static inline void pm_device_enable(const struct device *dev) { }
static inline void pm_device_disable(const struct device *dev) { }
static inline int pm_device_get(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_get_sync(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_put(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_put_sync(const struct device *dev) { return -ENOSYS; }
#endif
/** @} */

View file

@ -20,12 +20,12 @@ static int dummy_open(const struct device *dev)
printk("open()\n");
/* Make sure parent is resumed */
ret = device_pm_get_sync(parent);
ret = pm_device_get_sync(parent);
if (ret < 0) {
return ret;
}
ret = device_pm_get(dev);
ret = pm_device_get(dev);
if (ret < 0) {
return ret;
}
@ -80,14 +80,14 @@ static int dummy_close(const struct device *dev)
int ret;
printk("close()\n");
ret = device_pm_put_sync(dev);
ret = pm_device_put_sync(dev);
if (ret == 1) {
printk("Async suspend request ququed\n");
}
/* Parent can be suspended */
if (parent) {
device_pm_put(parent);
pm_device_put(parent);
}
return ret;
@ -155,7 +155,7 @@ int dummy_init(const struct device *dev)
printk("parent not found\n");
}
device_pm_enable(dev);
pm_device_enable(dev);
device_power_state = DEVICE_PM_ACTIVE_STATE;
k_poll_event_init(&async_evt, K_POLL_TYPE_SIGNAL,

View file

@ -77,7 +77,7 @@ static const struct dummy_parent_api funcs = {
int dummy_parent_init(const struct device *dev)
{
device_pm_enable(dev);
pm_device_enable(dev);
parent_power_state = DEVICE_PM_ACTIVE_STATE;
return 0;
}

View file

@ -94,7 +94,7 @@ fsm_out:
k_poll_signal_raise(&dev->pm->signal, pm_state);
}
static int device_pm_request(const struct device *dev,
static int pm_device_request(const struct device *dev,
uint32_t target_state, uint32_t pm_flags)
{
int result, signaled = 0;
@ -134,29 +134,29 @@ static int device_pm_request(const struct device *dev,
return result == target_state ? 0 : -EIO;
}
int device_pm_get(const struct device *dev)
int pm_device_get(const struct device *dev)
{
return device_pm_request(dev,
return pm_device_request(dev,
DEVICE_PM_ACTIVE_STATE, DEVICE_PM_ASYNC);
}
int device_pm_get_sync(const struct device *dev)
int pm_device_get_sync(const struct device *dev)
{
return device_pm_request(dev, DEVICE_PM_ACTIVE_STATE, 0);
return pm_device_request(dev, DEVICE_PM_ACTIVE_STATE, 0);
}
int device_pm_put(const struct device *dev)
int pm_device_put(const struct device *dev)
{
return device_pm_request(dev,
return pm_device_request(dev,
DEVICE_PM_SUSPEND_STATE, DEVICE_PM_ASYNC);
}
int device_pm_put_sync(const struct device *dev)
int pm_device_put_sync(const struct device *dev)
{
return device_pm_request(dev, DEVICE_PM_SUSPEND_STATE, 0);
return pm_device_request(dev, DEVICE_PM_SUSPEND_STATE, 0);
}
void device_pm_enable(const struct device *dev)
void pm_device_enable(const struct device *dev)
{
k_sem_take(&dev->pm->lock, K_FOREVER);
dev->pm->enable = true;
@ -176,7 +176,7 @@ void device_pm_enable(const struct device *dev)
k_sem_give(&dev->pm->lock);
}
void device_pm_disable(const struct device *dev)
void pm_device_disable(const struct device *dev)
{
k_sem_take(&dev->pm->lock, K_FOREVER);
dev->pm->enable = false;

View file

@ -9,6 +9,7 @@
#include <init.h>
#include <ztest.h>
#include <sys/printk.h>
#include <pm/device_runtime.h>
#include "abstract_driver.h"
@ -235,7 +236,7 @@ static void test_build_suspend_device_list(void)
}
/**
* @brief Test APIs to enable and disable automatic idle power management
* @brief Test APIs to enable and disable automatic runtime power management
*
* @details Test the API enable and disable, cause we do not implement our PM
* API here, it will use the default function to handle power status. So when
@ -244,7 +245,7 @@ static void test_build_suspend_device_list(void)
*
* @ingroup kernel_device_tests
*/
static void test_enable_and_disable_automatic_idle_pm(void)
static void test_enable_and_disable_automatic_runtime_pm(void)
{
const struct device *dev;
int ret;
@ -254,7 +255,7 @@ static void test_enable_and_disable_automatic_idle_pm(void)
zassert_false((dev == NULL), NULL);
/* check its status at first */
/* for cases that cannot run IDLE power, we skip it now */
/* for cases that cannot run runtime PM, we skip it now */
ret = device_get_power_state(dev, &device_power_state);
if (ret == -ENOSYS) {
TC_PRINT("Power management not supported on device");
@ -265,13 +266,13 @@ static void test_enable_and_disable_automatic_idle_pm(void)
zassert_true((ret == 0),
"Unable to get active state to device");
/* enable automatic idle PM and check its status */
device_pm_enable(dev);
/* enable automatic runtime PM and check its status */
pm_device_enable(dev);
zassert_not_null((dev->pm), "No device pm");
zassert_true((dev->pm->enable), "Pm is not enable");
/* disable automatic idle PM and check its status */
device_pm_disable(dev);
/* disable automatic runtime PM and check its status */
pm_device_disable(dev);
zassert_false((dev->pm->enable), "Pm shall not be enable");
}
@ -345,7 +346,7 @@ void test_dummy_device_pm(void)
"Error power status");
}
#else
static void test_enable_and_disable_automatic_idle_pm(void)
static void test_enable_and_disable_automatic_runtime_pm(void)
{
ztest_test_skip();
}
@ -475,7 +476,7 @@ void test_main(void)
ztest_unit_test(test_dummy_device_pm),
ztest_unit_test(test_build_suspend_device_list),
ztest_unit_test(test_dummy_device),
ztest_unit_test(test_enable_and_disable_automatic_idle_pm),
ztest_unit_test(test_enable_and_disable_automatic_runtime_pm),
ztest_unit_test(test_pre_kernel_detection),
ztest_user_unit_test(test_bogus_dynamic_name),
ztest_user_unit_test(test_null_dynamic_name),

View file

@ -6,18 +6,19 @@
#include <sys/printk.h>
#include <zephyr/types.h>
#include <pm/device_runtime.h>
#include "dummy_driver.h"
static uint32_t device_power_state;
static int dummy_open(const struct device *dev)
{
return device_pm_get_sync(dev);
return pm_device_get_sync(dev);
}
static int dummy_close(const struct device *dev)
{
return device_pm_put_sync(dev);
return pm_device_put_sync(dev);
}
static uint32_t dummy_get_power_state(const struct device *dev)
@ -73,7 +74,7 @@ static const struct dummy_driver_api funcs = {
int dummy_init(const struct device *dev)
{
device_pm_enable(dev);
pm_device_enable(dev);
return 0;
}

View file

@ -165,12 +165,12 @@ void test_power_state_trans(void)
* @brief notification between system and device
*
* @details
* - device driver notify its power state change by device_pm_get and
* device_pm_put
* - device driver notify its power state change by pm_device_get and
* pm_device_put
* - system inform device system power state change through device interface
* device_pm_control
*
* @see device_pm_get(), device_pm_put(), device_set_power_state(),
* @see pm_device_get(), pm_device_put(), device_set_power_state(),
* device_get_power_state()
*
* @ingroup power_tests