This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 3e8a3c9cc2ee6d6a1a10379991165fa6ff8ea66a
Author: zhuyanlin <[email protected]>
AuthorDate: Fri Dec 3 17:41:58 2021 +0800

    driver:regulator: add delay feature
    
    N/A
---
 drivers/power/regulator.c       | 60 ++++++++++++++++++++++++++++++++++++++---
 include/nuttx/power/consumer.h  |  2 ++
 include/nuttx/power/regulator.h |  2 ++
 3 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/drivers/power/regulator.c b/drivers/power/regulator.c
index 1ee1b73..e097d73 100644
--- a/drivers/power/regulator.c
+++ b/drivers/power/regulator.c
@@ -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));
 }
 
 /****************************************************************************
diff --git a/include/nuttx/power/consumer.h b/include/nuttx/power/consumer.h
index 534a0a7..5c3c0d2 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 32ae249..9809cd2 100644
--- a/include/nuttx/power/regulator.h
+++ b/include/nuttx/power/regulator.h
@@ -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;

Reply via email to