Skip to content

Commit 4d10f93

Browse files
committed
fix cannot charge in G3
Simplify battery gate and psys logic Signed-off-by: Kieran Levin <ktl@frame.work>
1 parent cf31091 commit 4d10f93

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

board/hx30/board.c

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ DECLARE_HOOK(HOOK_INIT, vci_init, HOOK_PRIO_FIRST);
481481
static void board_power_off_deferred(void)
482482
{
483483
int i;
484+
/* Turn off BGATE and NGATE for power saving */
485+
charger_psys_enable(0);
486+
charge_gate_onoff(0);
487+
484488

485489
/* Disable interrupts */
486490
interrupt_disable();
@@ -618,7 +622,7 @@ void charge_gate_onoff(uint8_t enable)
618622
}
619623

620624

621-
void charge_psys_onoff(uint8_t enable)
625+
void charger_psys_enable(uint8_t enable)
622626
{
623627
int control1 = 0x0000;
624628
int control4 = 0x0000;
@@ -661,43 +665,6 @@ void charge_psys_onoff(uint8_t enable)
661665
}
662666

663667

664-
/*
665-
* Charger Low Power Mode Process
666-
* modern standby should not turn off Bfet and Nfet
667-
* DC only at S5 need enable
668-
* AC+DC at S5 & Fully charge need enable
669-
* AC+DC at Modern standby & Fully charge need enable
670-
* AC only need disable
671-
*/
672-
void charger_low_power_update(void)
673-
{
674-
static int ac_state;
675-
static int dc_state;
676-
int batt_status;
677-
678-
ac_state = extpower_is_present();
679-
dc_state = battery_is_present();
680-
battery_status(&batt_status);
681-
682-
if (dc_state && !ac_state &&
683-
chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
684-
charge_gate_onoff(0);
685-
charge_psys_onoff(0);
686-
} else if (ac_state && dc_state &&
687-
batt_status & STATUS_FULLY_CHARGED) {
688-
if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
689-
charge_gate_onoff(0);
690-
charge_psys_onoff(0);
691-
} else if (chipset_in_state(CHIPSET_STATE_STANDBY))
692-
charge_psys_onoff(0);
693-
} else if (ac_state && !dc_state) {
694-
charge_gate_onoff(1);
695-
charge_psys_onoff(1);
696-
}
697-
}
698-
DECLARE_HOOK(HOOK_AC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
699-
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, charger_low_power_update, HOOK_PRIO_DEFAULT);
700-
701668
/* Initialize board. */
702669
static void board_init(void)
703670
{
@@ -732,8 +699,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT + 1);
732699
static void board_chipset_startup(void)
733700
{
734701
CPRINTS("HOOK_CHIPSET_STARTUP - called board_chipset_startup");
735-
charge_gate_onoff(1);
736-
charge_psys_onoff(1);
702+
charger_psys_enable(1);
737703
}
738704
DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
739705
board_chipset_startup,
@@ -752,11 +718,8 @@ static void board_chipset_shutdown(void)
752718
lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, 0);
753719
#endif
754720

755-
/* avoid AC mode enable charger LPM when charging*/
756-
if (!extpower_is_present() || (batt_status & STATUS_FULLY_CHARGED)) {
757-
charge_gate_onoff(0);
758-
charge_psys_onoff(0);
759-
}
721+
charger_psys_enable(0);
722+
760723
}
761724
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
762725
board_chipset_shutdown,
@@ -780,7 +743,7 @@ static void board_chipset_resume(void)
780743
/*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
781744
gpio_set_level(GPIO_EC_MUTE_L, 1);
782745
gpio_set_level(GPIO_CAM_EN, 1);
783-
charge_psys_onoff(1);
746+
charger_psys_enable(1);
784747

785748
/* Enable BB retimer power, for MP boards. */
786749
if (board_get_version() > BOARD_VERSION_10 || force_gpio6_rework) {
@@ -803,7 +766,7 @@ static void board_chipset_suspend(void)
803766
gpio_set_level(GPIO_EC_MUTE_L, 0);
804767
gpio_set_level(GPIO_CAM_EN, 0);
805768
}
806-
charge_psys_onoff(0);
769+
charger_psys_enable(0);
807770

808771
/* Disable BB retimer power, for MP boards. */
809772
hook_call_deferred(&disable_bb_retimer_power_deferred_data, 3 * SECOND);
@@ -1006,6 +969,9 @@ static void charger_chips_init(void)
1006969

1007970
val = ISL9241_CONTROL1_PROCHOT_REF_6800 | ISL9241_CONTROL1_SWITCH_FREQ;
1008971

972+
/* make sure battery FET is enabled on EC on */
973+
val &= ~ISL9241_CONTROL1_BGATE;
974+
1009975
if (i2c_write16(I2C_PORT_CHARGER, ISL9241_ADDR_FLAGS,
1010976
ISL9241_REG_CONTROL1, val))
1011977
goto init_fail;

board/hx30/board.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ void board_prepare_for_deep_sleep(void);
787787
void board_resume_from_deep_sleep(void);
788788
#endif
789789

790+
void charge_gate_onoff(uint8_t enable);
791+
void charger_psys_enable(uint8_t enable);
790792
#endif /* !__ASSEMBLER__ */
791793

792794
#endif /* __CROS_EC_BOARD_H */

0 commit comments

Comments
 (0)