driver:regulator: add delay feature

N/A
This commit is contained in:
zhuyanlin 2021-12-03 17:41:58 +08:00 committed by Xiang Xiao
parent b7db4304d6
commit 3e8a3c9cc2
3 changed files with 61 additions and 3 deletions

View File

@ -33,6 +33,7 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/power/regulator.h>
#include <nuttx/signal.h>
/****************************************************************************
* 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 *)&regulator,
(worker_t)regulator_disable, regulator, MSEC2TICK(ms));
}
/****************************************************************************

View File

@ -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);

View File

@ -31,6 +31,7 @@
#include <semaphore.h>
#include <nuttx/list.h>
#include <nuttx/wqueue.h>
/****************************************************************************
* 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;