Skip to content

Commit 03897d4

Browse files
authored
Merge pull request #504 from FrameworkComputer/hx20.charger_lpm
fix cannot charge in G3
2 parents 9450caa + 81e3d0e commit 03897d4

File tree

2 files changed

+13
-48
lines changed

2 files changed

+13
-48
lines changed

board/hx20/board.c

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ DECLARE_HOOK(HOOK_INIT, vci_init, HOOK_PRIO_FIRST);
399399
static void board_power_off_deferred(void)
400400
{
401401
int i;
402+
/* Turn off BGATE and NGATE for power saving */
403+
charger_psys_enable(0);
404+
charge_gate_onoff(0);
402405

403406
/* Disable interrupts */
404407
interrupt_disable();
@@ -535,7 +538,7 @@ void charge_gate_onoff(uint8_t enable)
535538
}
536539

537540

538-
void charge_psys_onoff(uint8_t enable)
541+
void charger_psys_enable(uint8_t enable)
539542
{
540543
int control1 = 0x0000;
541544
int control4 = 0x0000;
@@ -576,44 +579,6 @@ void charge_psys_onoff(uint8_t enable)
576579
}
577580
}
578581

579-
580-
/*
581-
* Charger Low Power Mode Process
582-
* modern standby should not turn off Bfet and Nfet
583-
* DC only at S5 need enable
584-
* AC+DC at S5 & Fully charge need enable
585-
* AC+DC at Modern standby & Fully charge need enable
586-
* AC only need disable
587-
*/
588-
void charger_low_power_update(void)
589-
{
590-
static int ac_state;
591-
static int dc_state;
592-
int batt_status;
593-
594-
ac_state = extpower_is_present();
595-
dc_state = battery_is_present();
596-
battery_status(&batt_status);
597-
598-
if (dc_state && !ac_state &&
599-
chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
600-
charge_gate_onoff(0);
601-
charge_psys_onoff(0);
602-
} else if (ac_state && dc_state &&
603-
batt_status & STATUS_FULLY_CHARGED) {
604-
if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
605-
charge_gate_onoff(0);
606-
charge_psys_onoff(0);
607-
} else if (chipset_in_state(CHIPSET_STATE_STANDBY))
608-
charge_psys_onoff(0);
609-
} else if (ac_state && !dc_state) {
610-
charge_gate_onoff(1);
611-
charge_psys_onoff(1);
612-
}
613-
}
614-
DECLARE_HOOK(HOOK_AC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
615-
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
616-
617582
/* Initialize board. */
618583
static void board_init(void)
619584
{
@@ -647,8 +612,7 @@ static void board_chipset_startup(void)
647612
if (version > 6)
648613
gpio_set_level(GPIO_EN_INVPWR, 1);
649614

650-
charge_gate_onoff(1);
651-
charge_psys_onoff(1);
615+
charger_psys_enable(1);
652616
}
653617
DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
654618
board_chipset_startup,
@@ -667,11 +631,7 @@ static void board_chipset_shutdown(void)
667631
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, 0);
668632
#endif
669633

670-
/* avoid AC mode enable charger LPM when charging*/
671-
if (!extpower_is_present() || (batt_status & STATUS_FULLY_CHARGED)) {
672-
charge_gate_onoff(0);
673-
charge_psys_onoff(0);
674-
}
634+
charger_psys_enable(0);
675635
}
676636
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
677637
board_chipset_shutdown,
@@ -684,7 +644,7 @@ static void board_chipset_resume(void)
684644
/*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
685645
gpio_set_level(GPIO_EC_MUTE_L, 1);
686646
gpio_set_level(GPIO_CAM_EN, 1);
687-
charge_psys_onoff(1);
647+
charger_psys_enable(1);
688648
}
689649
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume,
690650
MOTION_SENSE_HOOK_PRIO-1);
@@ -698,7 +658,7 @@ static void board_chipset_suspend(void)
698658
gpio_set_level(GPIO_EC_MUTE_L, 0);
699659
gpio_set_level(GPIO_CAM_EN, 0);
700660
}
701-
charge_psys_onoff(0);
661+
charger_psys_enable(0);
702662
}
703663
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND,
704664
board_chipset_suspend,
@@ -885,6 +845,9 @@ static void charger_chips_init(void)
885845

886846
val = ISL9241_CONTROL1_PROCHOT_REF_6800 | ISL9241_CONTROL1_SWITCH_FREQ;
887847

848+
/* make sure battery FET is enabled on EC on */
849+
val &= ~ISL9241_CONTROL1_BGATE;
850+
888851
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
889852
ISL9241_REG_CONTROL1, val))
890853
goto init_fail;

board/hx20/board.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ void board_prepare_for_deep_sleep(void);
775775
void board_resume_from_deep_sleep(void);
776776
#endif
777777

778+
void charge_gate_onoff(uint8_t enable);
779+
void charger_psys_enable(uint8_t enable);
778780
#endif /* !__ASSEMBLER__ */
779781

780782
#endif /* __CROS_EC_BOARD_H */

0 commit comments

Comments
 (0)