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;
}
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 =