1414#include "adc_chip.h"
1515#include "als.h"
1616#include "bd99992gw.h"
17+ #include "battery.h"
1718#include "button.h"
1819#include "charge_state.h"
1920#include "charger.h"
@@ -523,28 +524,64 @@ static void check_chassis_open(int init)
523524 }
524525}
525526
526- void charge_psys_onoff (uint8_t enable )
527+
528+ void charge_gate_onoff (uint8_t enable )
527529{
528530 int control0 = 0x0000 ;
529531 int control1 = 0x0000 ;
532+
533+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
534+ ISL9241_REG_CONTROL0 , & control0 )) {
535+ CPRINTS ("read gate control1 fail" );
536+ }
537+
538+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
539+ ISL9241_REG_CONTROL1 , & control1 )) {
540+ CPRINTS ("read gate control1 fail" );
541+ }
542+
543+ if (enable ) {
544+ control0 &= ~ISL9241_CONTROL0_NGATE ;
545+ control1 &= ~ISL9241_CONTROL1_BGATE ;
546+ CPRINTS ("B&N Gate off" );
547+ } else {
548+ control0 |= ISL9241_CONTROL0_NGATE ;
549+ control1 |= ISL9241_CONTROL1_BGATE ;
550+ CPRINTS ("B&N Gate on" );
551+ }
552+
553+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
554+ ISL9241_REG_CONTROL0 , control0 )) {
555+ CPRINTS ("Update gate control0 fail" );
556+ }
557+
558+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
559+ ISL9241_REG_CONTROL1 , control1 )) {
560+ CPRINTS ("Update gate control1 fail" );
561+ }
562+
563+ }
564+
565+
566+ void charge_psys_onoff (uint8_t enable )
567+ {
568+ int control1 = 0x0000 ;
530569 int control4 = 0x0000 ;
531570 int data = 0x0000 ;
532571
533572 if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
534573 ISL9241_REG_CONTROL1 , & control1 )) {
535- CPRINTS ("read charger control1 fail" );
574+ CPRINTS ("read psys control1 fail" );
536575 }
537576
538577 if (enable ) {
539- control0 &= ~ISL9241_CONTROL0_NGATE ;
540- control1 &= ~(ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
578+ control1 &= ~ISL9241_CONTROL1_IMON ;
541579 control1 |= ISL9241_CONTROL1_PSYS ;
542580 control4 &= ~ISL9241_CONTROL4_GP_COMPARATOR ;
543581 data = 0x0B00 ; /* Set ACOK reference to 4.544V */
544582 CPRINTS ("Power saving disable" );
545583 } else {
546- control0 |= ISL9241_CONTROL0_NGATE ;
547- control1 |= (ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
584+ control1 |= ISL9241_CONTROL1_IMON ;
548585 control1 &= ~ISL9241_CONTROL1_PSYS ;
549586 control4 |= ISL9241_CONTROL4_GP_COMPARATOR ;
550587 data = 0x0000 ; /* Set ACOK reference to 0V */
@@ -557,22 +594,55 @@ void charge_psys_onoff(uint8_t enable)
557594 CPRINTS ("Update ACOK reference fail" );
558595 }
559596
560- if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
561- ISL9241_REG_CONTROL0 , control0 )) {
562- CPRINTS ("Update charger control0 fail" );
563- }
564-
565597 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
566598 ISL9241_REG_CONTROL1 , control1 )) {
567- CPRINTS ("Update charger control1 fail" );
599+ CPRINTS ("Update psys control1 fail" );
568600 }
569601
570602 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
571603 ISL9241_REG_CONTROL4 , control4 )) {
572- CPRINTS ("Update charger control4 fail" );
604+ CPRINTS ("Update psys control4 fail" );
573605 }
574606}
575607
608+
609+ /*
610+ * Charger Low Power Mode Process
611+ * modern standby should not turn off Bfet and Nfet
612+ * DC only at S5 need enable
613+ * AC+DC at S5 & Fully charge need enable
614+ * AC+DC at Modern standby & Fully charge need enable
615+ * AC only need disable
616+ */
617+ void charger_low_power_update (void )
618+ {
619+ static int ac_state ;
620+ static int dc_state ;
621+ int batt_status ;
622+
623+ ac_state = extpower_is_present ();
624+ dc_state = battery_is_present ();
625+ battery_status (& batt_status );
626+
627+ if (dc_state && !ac_state &&
628+ chipset_in_state (CHIPSET_STATE_ANY_OFF )) {
629+ charge_gate_onoff (0 );
630+ charge_psys_onoff (0 );
631+ } else if (ac_state && dc_state &&
632+ batt_status & STATUS_FULLY_CHARGED ) {
633+ if (chipset_in_state (CHIPSET_STATE_ANY_OFF )) {
634+ charge_gate_onoff (0 );
635+ charge_psys_onoff (0 );
636+ } else if (chipset_in_state (CHIPSET_STATE_STANDBY ))
637+ charge_psys_onoff (0 );
638+ } else if (ac_state && !dc_state ) {
639+ charge_gate_onoff (1 );
640+ charge_psys_onoff (1 );
641+ }
642+ }
643+ DECLARE_HOOK (HOOK_AC_CHANGE , charger_low_power_update , HOOK_PRIO_DEFAULT );
644+ DECLARE_HOOK (HOOK_BATTERY_SOC_CHANGE , charger_low_power_update , HOOK_PRIO_DEFAULT );
645+
576646/* Initialize board. */
577647static void board_init (void )
578648{
@@ -603,6 +673,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT + 1);
603673static void board_chipset_startup (void )
604674{
605675 CPRINTS ("HOOK_CHIPSET_STARTUP - called board_chipset_startup" );
676+ charge_gate_onoff (1 );
606677 charge_psys_onoff (1 );
607678}
608679DECLARE_HOOK (HOOK_CHIPSET_STARTUP ,
@@ -612,12 +683,21 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
612683/* Called on AP S3 -> S5 transition */
613684static void board_chipset_shutdown (void )
614685{
686+ int batt_status ;
687+
688+ battery_status (& batt_status );
689+
615690 CPRINTS (" HOOK_CHIPSET_SHUTDOWN board_chipset_shutdown" );
616691
617692#ifdef CONFIG_EMI_REGION1
618693 lpc_set_host_event_mask (LPC_HOST_EVENT_SCI , 0 );
619694#endif
620- charge_psys_onoff (0 );
695+
696+ /* avoid AC mode enable charger LPM when charging*/
697+ if (!extpower_is_present () || (batt_status & STATUS_FULLY_CHARGED )) {
698+ charge_gate_onoff (0 );
699+ charge_psys_onoff (0 );
700+ }
621701}
622702DECLARE_HOOK (HOOK_CHIPSET_SHUTDOWN ,
623703 board_chipset_shutdown ,
@@ -630,6 +710,7 @@ static void board_chipset_resume(void)
630710 /*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
631711 gpio_set_level (GPIO_EC_MUTE_L , 1 );
632712 gpio_set_level (GPIO_CAM_EN , 1 );
713+ charge_psys_onoff (1 );
633714}
634715DECLARE_HOOK (HOOK_CHIPSET_RESUME , board_chipset_resume ,
635716 MOTION_SENSE_HOOK_PRIO - 1 );
@@ -643,6 +724,7 @@ static void board_chipset_suspend(void)
643724 gpio_set_level (GPIO_EC_MUTE_L , 0 );
644725 gpio_set_level (GPIO_CAM_EN , 0 );
645726 }
727+ charge_psys_onoff (0 );
646728}
647729DECLARE_HOOK (HOOK_CHIPSET_SUSPEND ,
648730 board_chipset_suspend ,
0 commit comments