From bfce935caf214857b6cb7a84fc556b65b682c816 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 26 Apr 2021 12:47:13 +0200 Subject: [PATCH] power: remove device_pm_control_nop function Devices that do not require PM should just use NULL. `device_pm_control_nop` is still kept as an alias to NULL untill all in-tree usage is replaced with NULL. Code relying on device_pm_control function now returns -ENOTSUP (equivalent to calling device_pm_control_nop). Signed-off-by: Gerard Marull-Paretas --- include/device.h | 58 ++++++++++++++----------------------------- kernel/device.c | 9 ------- subsys/power/device.c | 3 +-- 3 files changed, 20 insertions(+), 50 deletions(-) diff --git a/include/device.h b/include/device.h index 5a3e9d8c99d..7fa898d06fb 100644 --- a/include/device.h +++ b/include/device.h @@ -141,7 +141,7 @@ typedef int16_t device_handle_t; * @param init_fn Address to the init function of the driver. * * @param pm_control_fn Pointer to device_pm_control function. - * Can be empty function (device_pm_control_nop) if not implemented. + * Can be NULL if not implemented. * * @param data_ptr Pointer to the device's private data. * @@ -199,7 +199,7 @@ typedef int16_t device_handle_t; * @param init_fn Address to the init function of the driver. * * @param pm_control_fn Pointer to device_pm_control function. - * Can be empty function (device_pm_control_nop) if not implemented. + * Can be NULL if not implemented. * * @param data_ptr Pointer to the device's private data. * @@ -744,25 +744,6 @@ void device_busy_clear(const struct device *dev); * Device PM functions */ -/** - * @brief No-op function to initialize unimplemented hook - * - * This function should be used to initialize device hook - * for which a device has no PM operations. - * - * @param unused_device Unused - * @param unused_ctrl_command Unused - * @param unused_context Unused - * @param cb Unused - * @param unused_arg Unused - * - * @retval -ENOTSUP for all operations. - */ -int device_pm_control_nop(const struct device *unused_device, - uint32_t unused_ctrl_command, - void *unused_context, - device_pm_cb cb, - void *unused_arg); /** * @brief Call the set power state function of a device * @@ -781,15 +762,12 @@ static inline int device_set_power_state(const struct device *dev, uint32_t device_power_state, device_pm_cb cb, void *arg) { - if (dev->device_pm_control) { - return dev->device_pm_control(dev, - DEVICE_PM_SET_POWER_STATE, - &device_power_state, cb, arg); - } else { - return device_pm_control_nop(dev, - DEVICE_PM_SET_POWER_STATE, - &device_power_state, cb, arg); + if (dev->device_pm_control == NULL) { + return -ENOSYS; } + + return dev->device_pm_control(dev, DEVICE_PM_SET_POWER_STATE, + &device_power_state, cb, arg); } /** @@ -808,15 +786,12 @@ static inline int device_set_power_state(const struct device *dev, static inline int device_get_power_state(const struct device *dev, uint32_t *device_power_state) { - if (dev->device_pm_control) { - return dev->device_pm_control(dev, - DEVICE_PM_GET_POWER_STATE, - device_power_state, NULL, NULL); - } else { - return device_pm_control_nop(dev, - DEVICE_PM_GET_POWER_STATE, - device_power_state, NULL, NULL); + if (dev->device_pm_control == NULL) { + return -ENOSYS; } + + return dev->device_pm_control(dev, DEVICE_PM_GET_POWER_STATE, + device_power_state, NULL, NULL); } /** @@ -945,10 +920,15 @@ static inline int device_pm_get_sync(const struct device *dev) { return -ENOTSUP static inline int device_pm_put(const struct device *dev) { return -ENOTSUP; } static inline int device_pm_put_sync(const struct device *dev) { return -ENOTSUP; } #endif -#else -#define device_pm_control_nop(...) NULL #endif +/** + * @brief Alias for legacy use of device_pm_control_nop. + * + * @note Usage of NULL is preferred, this alias will eventually be removed. + */ +#define device_pm_control_nop NULL + /** * @} */ diff --git a/kernel/device.c b/kernel/device.c index d8456d9b3ab..8d38cefea11 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -193,15 +193,6 @@ int device_required_foreach(const struct device *dev, } #ifdef CONFIG_PM_DEVICE -int device_pm_control_nop(const struct device *unused_device, - uint32_t unused_ctrl_command, - void *unused_context, - device_pm_cb cb, - void *unused_arg) -{ - return -ENOTSUP; -} - int device_any_busy_check(void) { const struct device *dev = __device_start; diff --git a/subsys/power/device.c b/subsys/power/device.c index 1fb1c35d04c..82efd31e029 100644 --- a/subsys/power/device.c +++ b/subsys/power/device.c @@ -142,8 +142,7 @@ void pm_create_device_list(void) const struct device *dev = &all_devices[pmi]; /* Ignore "device"s that don't support PM */ - if ((dev->device_pm_control == NULL) || - (dev->device_pm_control == device_pm_control_nop)) { + if (dev->device_pm_control == NULL) { continue; }