diff --git a/drivers/power/regulator.c b/drivers/power/regulator.c index 1ee1b7362c..e097d73805 100644 --- a/drivers/power/regulator.c +++ b/drivers/power/regulator.c @@ -33,6 +33,7 @@ #include #include #include +#include /**************************************************************************** * Private Function Prototypes @@ -526,14 +527,44 @@ int regulator_enable(FAR struct regulator_s *regulator) ret = _regulator_do_enable(rdev); if (ret < 0) { - return ret; + goto err; } } rdev->use_count++; + +err: nxsem_post(&rdev->regulator_sem); - return 0; + return ret; +} + +/**************************************************************************** + * Name: regulator_enable_delay + * + * Description: + * Enable the regulator output. + * + * Input parameters: + * regulator - The regulator consumer representative + * ms - The delay ms after regulator enable + * + * Returned value: + * Zero on success or a negated errno value on failure. + * + ****************************************************************************/ + +int regulator_enable_delay(FAR struct regulator_s *regulator, int ms) +{ + int ret; + + ret = regulator_enable(regulator); + if (!ret) + { + nxsig_usleep(1000 * ms); + } + + return ret; } /**************************************************************************** @@ -586,7 +617,30 @@ err: return ret; } - return 0; +/**************************************************************************** + * Name: regulator_disable_deferred + * + * Description: + * Disable the regulator after ms. + * + * Input parameters: + * regulator - The regulator consumer representative + * ms - The delay ms before disable regulator + * + * Returned value: + * Zero on success or a negated errno value on failure. + * + ****************************************************************************/ + +int regulator_disable_deferred(FAR struct regulator_s *regulator, int ms) +{ + if (!regulator) + { + return -EINVAL; + } + + return work_queue(LPWORK, (FAR struct work_s *)®ulator, + (worker_t)regulator_disable, regulator, MSEC2TICK(ms)); } /**************************************************************************** diff --git a/include/nuttx/power/consumer.h b/include/nuttx/power/consumer.h index 534a0a70ab..5c3c0d24a1 100644 --- a/include/nuttx/power/consumer.h +++ b/include/nuttx/power/consumer.h @@ -61,7 +61,9 @@ FAR struct regulator_s *regulator_get(const char *id); void regulator_put(FAR struct regulator_s *regulator); int regulator_is_enabled(FAR struct regulator_s *regulator); int regulator_enable(FAR struct regulator_s *regulator); +int regulator_enable_delay(FAR struct regulator_s *regulator, int ms); int regulator_disable(FAR struct regulator_s *regulator); +int regulator_disable_deferred(FAR struct regulator_s *regulator, int ms); int regulator_set_voltage(FAR struct regulator_s *regulator, int min_uv, int max_uv); int regulator_get_voltage(FAR struct regulator_s *regulator); diff --git a/include/nuttx/power/regulator.h b/include/nuttx/power/regulator.h index 32ae249143..9809cd2104 100644 --- a/include/nuttx/power/regulator.h +++ b/include/nuttx/power/regulator.h @@ -31,6 +31,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -44,6 +45,7 @@ struct regulator_dev_s; struct regulator_s { + struct work_s disable_work; int min_uv; int max_uv; struct list_node list;