You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2023/03/01 08:21:27 UTC

[nuttx] 02/09: boards: spresense: Support using GPIO for power control

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

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

commit b60fbefabecdfd4eb0aefdd68a62fd7995730089
Author: SPRESENSE <41...@users.noreply.github.com>
AuthorDate: Wed Mar 1 14:28:13 2023 +0900

    boards: spresense: Support using GPIO for power control
    
    Introduce CHIP_TYPE_GPIO to allow GPIO to be used for power control.
---
 boards/arm/cxd56xx/spresense/include/board.h   |  3 +++
 boards/arm/cxd56xx/spresense/src/cxd56_power.c | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/boards/arm/cxd56xx/spresense/include/board.h b/boards/arm/cxd56xx/spresense/include/board.h
index 53d3ec20e7..aa385c46a0 100644
--- a/boards/arm/cxd56xx/spresense/include/board.h
+++ b/boards/arm/cxd56xx/spresense/include/board.h
@@ -29,6 +29,7 @@
 #include <nuttx/irq.h>
 #include <sys/boardctl.h>
 #include <stdbool.h>
+#include <arch/chip/pin.h>
 
 #include "board_lcdpins.h"
 
@@ -166,11 +167,13 @@
 #define PMIC_TYPE_LSW       (1u << 8)
 #define PMIC_TYPE_GPO       (1u << 9)
 #define PMIC_TYPE_DDCLDO    (1u << 10)
+#define CHIP_TYPE_GPIO      (1u << 11)
 #define PMIC_GET_TYPE(v)    ((v) & 0xff00)
 #define PMIC_GET_CH(v)      ((v) & 0x00ff)
 #define PMIC_LSW(n)         (PMIC_TYPE_LSW | (1u << (n)))
 #define PMIC_GPO(n)         (PMIC_TYPE_GPO | (1u << (n)))
 #define PMIC_DDCLDO(n)      (PMIC_TYPE_DDCLDO | (1u << (n)))
+#define CHIP_GPIO(n)        (CHIP_TYPE_GPIO | (n))
 
 enum board_power_device
 {
diff --git a/boards/arm/cxd56xx/spresense/src/cxd56_power.c b/boards/arm/cxd56xx/spresense/src/cxd56_power.c
index 32dafde225..3c596ceedd 100644
--- a/boards/arm/cxd56xx/spresense/src/cxd56_power.c
+++ b/boards/arm/cxd56xx/spresense/src/cxd56_power.c
@@ -200,6 +200,9 @@ int board_power_control(int target, bool en)
       pfunc = cxd56_pmic_set_ddc_ldo;
       break;
 #endif /* CONFIG_CXD56_PMIC */
+    case CHIP_TYPE_GPIO:
+      board_gpio_write(PMIC_GET_CH(target), en ? 1 : 0);
+      break;
     default:
       break;
     }
@@ -253,6 +256,10 @@ int board_power_control_tristate(int target, int value)
           usleep(1);
         }
     }
+  else if (PMIC_GET_TYPE(target) == CHIP_TYPE_GPIO)
+    {
+      board_gpio_write(PMIC_GET_CH(target), value);
+    }
   else
     {
       en = value ? true : false;
@@ -274,6 +281,7 @@ bool board_power_monitor(int target)
 {
   bool ret = false;
   bool (*pfunc)(uint8_t chset) = NULL;
+  int  status;
 
   switch (PMIC_GET_TYPE(target))
     {
@@ -288,6 +296,10 @@ bool board_power_monitor(int target)
       pfunc = cxd56_pmic_get_ddc_ldo;
       break;
 #endif /* CONFIG_CXD56_PMIC */
+    case CHIP_TYPE_GPIO:
+      status = board_gpio_read(PMIC_GET_CH(target));
+      ret = (status == 1);
+      break;
     default:
       break;
     }