forked from nuttx/nuttx-update
cxd56_power: Add lowerhalf interface to keep power when cold sleep
Add board interface to keep power when entering/recover sleep. Some driver wants to keep power when entering sleep mode.
This commit is contained in:
parent
bbc8562f65
commit
97a6fd4d18
2 changed files with 91 additions and 13 deletions
|
@ -202,6 +202,26 @@ bool board_xtal_power_monitor(void);
|
|||
|
||||
int board_lna_power_control(bool en);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_set_reset_gpo
|
||||
*
|
||||
* Description:
|
||||
* Set gpo to off when power off the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_set_reset_gpo(int target);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_unset_reset_gpo
|
||||
*
|
||||
* Description:
|
||||
* Keep gpo status when power off the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_unset_reset_gpo(int target);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BOARD_GPO_MAX_PIN_NUM 7
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
@ -62,6 +64,7 @@ static struct pm_cpu_freqlock_s g_hv_lock =
|
|||
PM_CPUFREQLOCK_INIT(PM_CPUFREQLOCK_TAG('B', 'P', 0),
|
||||
PM_CPUFREQLOCK_FLAG_HV);
|
||||
#endif
|
||||
static uint8_t g_reset_gpo_targets = 0xFF;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
|
@ -127,21 +130,39 @@ int board_pmic_write(uint8_t addr, void *buf, uint32_t size)
|
|||
|
||||
int board_power_setup(int status)
|
||||
{
|
||||
int pin;
|
||||
#ifdef CONFIG_BOARD_USB_DISABLE_IN_DEEP_SLEEPING
|
||||
int ret;
|
||||
uint8_t val = 0;
|
||||
#endif
|
||||
uint32_t bootcause;
|
||||
|
||||
/* Enable USB after wakeup from deep sleeping */
|
||||
|
||||
bootcause = up_pm_get_bootcause();
|
||||
|
||||
switch (bootcause)
|
||||
{
|
||||
case PM_BOOT_POR_NORMAL:
|
||||
case PM_BOOT_POR_DEADBATT:
|
||||
case PM_BOOT_WDT_REBOOT:
|
||||
case PM_BOOT_WDT_RESET:
|
||||
/* Power off Hi-Z of GPO switches (except for GPO0)
|
||||
* in first boot-up stage */
|
||||
|
||||
for (pin = 1; pin <= BOARD_GPO_MAX_PIN_NUM; pin++)
|
||||
{
|
||||
if (cxd56_pmic_get_gpo_hiz(PMIC_GET_CH(PMIC_GPO(pin))) == -1)
|
||||
{
|
||||
board_power_control(PMIC_GPO(pin), false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_BOARD_USB_DISABLE_IN_DEEP_SLEEPING
|
||||
case PM_BOOT_DEEP_WKUPL:
|
||||
case PM_BOOT_DEEP_WKUPS:
|
||||
case PM_BOOT_DEEP_RTC:
|
||||
case PM_BOOT_DEEP_OTHERS:
|
||||
/* Enable USB after wakeup from deep sleeping */
|
||||
|
||||
ret = cxd56_pmic_read(PMIC_REG_CNT_USB2, &val, sizeof(val));
|
||||
if ((ret == 0) && (val & PMIC_SET_CHGOFF))
|
||||
{
|
||||
|
@ -149,10 +170,10 @@ int board_power_setup(int status)
|
|||
cxd56_pmic_write(PMIC_REG_CNT_USB2, &val, sizeof(val));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Disable unused DDC/LDO permanently */
|
||||
|
||||
|
@ -162,15 +183,14 @@ int board_power_setup(int status)
|
|||
|
||||
board_power_control(POWER_AUDIO_DVDD, false);
|
||||
|
||||
/* Power off all of GPO switches (except for GPO0) in boot-up stage */
|
||||
|
||||
board_power_control(PMIC_GPO(1) | PMIC_GPO(2) | PMIC_GPO(3) | PMIC_GPO(4) |
|
||||
PMIC_GPO(5) | PMIC_GPO(6) | PMIC_GPO(7), false);
|
||||
|
||||
/* Set GPO0 to Hi-Z */
|
||||
|
||||
cxd56_pmic_set_gpo_hiz(PMIC_GET_CH(PMIC_GPO(0)));
|
||||
|
||||
/* Initialize reset GPO targets (reset all) */
|
||||
|
||||
g_reset_gpo_targets = 0xFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -519,6 +539,8 @@ int board_lna_power_control(bool en)
|
|||
#ifdef CONFIG_BOARDCTL_RESET
|
||||
int board_reset(int status)
|
||||
{
|
||||
board_power_control(PMIC_TYPE_GPO | g_reset_gpo_targets, false);
|
||||
|
||||
/* Restore the original state for bootup after power cycle */
|
||||
|
||||
if (!up_interrupt_context())
|
||||
|
@ -563,11 +585,7 @@ int board_power_off(int status)
|
|||
enum pm_sleepmode_e mode;
|
||||
uint8_t val;
|
||||
|
||||
/* Power off explicitly because GPOs are kept during deep sleeping */
|
||||
|
||||
board_power_control(PMIC_GPO(0) | PMIC_GPO(1) | PMIC_GPO(2) | PMIC_GPO(3) |
|
||||
PMIC_GPO(4) | PMIC_GPO(5) | PMIC_GPO(6) | PMIC_GPO(7),
|
||||
false);
|
||||
board_power_control(PMIC_TYPE_GPO | g_reset_gpo_targets, false);
|
||||
|
||||
/* Set DDC_ANA output to HiZ before sleeping for power saving */
|
||||
|
||||
|
@ -605,3 +623,43 @@ int board_power_off(int status)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_set_reset_gpo
|
||||
*
|
||||
* Description:
|
||||
* Set gpo to off when power off the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_set_reset_gpo(int target)
|
||||
{
|
||||
if ((PMIC_GET_TYPE(target) & PMIC_TYPE_GPO) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_reset_gpo_targets |= PMIC_GET_CH(target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_unset_reset_gpo
|
||||
*
|
||||
* Description:
|
||||
* Keep gpo status when power off the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_unset_reset_gpo(int target)
|
||||
{
|
||||
if ((PMIC_GET_TYPE(target) & PMIC_TYPE_GPO) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_reset_gpo_targets &= ~PMIC_GET_CH(target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue