Skip to content

Commit

Permalink
boards: spresense: Support using GPIO for power control
Browse files Browse the repository at this point in the history
Introduce CHIP_TYPE_GPIO to allow GPIO to be used for power control.
  • Loading branch information
SPRESENSE committed Dec 20, 2022
1 parent aaad5ad commit 30de35c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions boards/arm/cxd56xx/spresense/include/board.h
Expand Up @@ -29,6 +29,7 @@
#include <nuttx/irq.h>
#include <sys/boardctl.h>
#include <stdbool.h>
#include <arch/chip/pin.h>

#include "board_lcdpins.h"

Expand Down Expand Up @@ -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
{
Expand Down
12 changes: 12 additions & 0 deletions boards/arm/cxd56xx/spresense/src/cxd56_power.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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))
{
Expand All @@ -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;
}
Expand Down

0 comments on commit 30de35c

Please sign in to comment.