drivers: regulator: add regulator_is_enabled

Add a new API to check if a regulator is enabled or not.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-12-12 12:21:44 +01:00 committed by Carles Cufí
commit 9b5152153b
2 changed files with 29 additions and 0 deletions

View file

@ -50,6 +50,25 @@ int regulator_enable(const struct device *dev)
return ret; return ret;
} }
bool regulator_is_enabled(const struct device *dev)
{
const struct regulator_common_config *config =
(struct regulator_common_config *)dev->config;
struct regulator_common_data *data =
(struct regulator_common_data *)dev->data;
bool enabled;
if ((config->flags & REGULATOR_ALWAYS_ON) != 0U) {
enabled = true;
} else {
(void)k_mutex_lock(&data->lock, K_FOREVER);
enabled = data->refcnt != 0;
k_mutex_unlock(&data->lock);
}
return enabled;
}
int regulator_disable(const struct device *dev) int regulator_disable(const struct device *dev)
{ {
const struct regulator_driver_api *api = const struct regulator_driver_api *api =

View file

@ -210,6 +210,16 @@ static inline int regulator_parent_dvs_state_set(const struct device *dev,
*/ */
int regulator_enable(const struct device *dev); int regulator_enable(const struct device *dev);
/**
* @brief Check if a regulator is enabled.
*
* @param dev Regulator device instance.
*
* @retval true If regulator is enabled.
* @retval false If regulator is disabled.
*/
bool regulator_is_enabled(const struct device *dev);
/** /**
* @brief Disable a regulator. * @brief Disable a regulator.
* *