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:
parent
305ce33b77
commit
9b5152153b
2 changed files with 29 additions and 0 deletions
|
@ -50,6 +50,25 @@ int regulator_enable(const struct device *dev)
|
|||
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)
|
||||
{
|
||||
const struct regulator_driver_api *api =
|
||||
|
|
|
@ -210,6 +210,16 @@ static inline int regulator_parent_dvs_state_set(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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue