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"
@@ -506,28 +507,64 @@ static void check_chassis_open(int init)
506507 }
507508}
508509
509- void charge_psys_onoff (uint8_t enable )
510+
511+ void charge_gate_onoff (uint8_t enable )
510512{
511513 int control0 = 0x0000 ;
512514 int control1 = 0x0000 ;
515+
516+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
517+ ISL9241_REG_CONTROL0 , & control0 )) {
518+ CPRINTS ("read gate control1 fail" );
519+ }
520+
521+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
522+ ISL9241_REG_CONTROL1 , & control1 )) {
523+ CPRINTS ("read gate control1 fail" );
524+ }
525+
526+ if (enable ) {
527+ control0 &= ~ISL9241_CONTROL0_NGATE ;
528+ control1 &= ~ISL9241_CONTROL1_BGATE ;
529+ CPRINTS ("B&N Gate off" );
530+ } else {
531+ control0 |= ISL9241_CONTROL0_NGATE ;
532+ control1 |= ISL9241_CONTROL1_BGATE ;
533+ CPRINTS ("B&N Gate on" );
534+ }
535+
536+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
537+ ISL9241_REG_CONTROL0 , control0 )) {
538+ CPRINTS ("Update gate control0 fail" );
539+ }
540+
541+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
542+ ISL9241_REG_CONTROL1 , control1 )) {
543+ CPRINTS ("Update gate control1 fail" );
544+ }
545+
546+ }
547+
548+
549+ void charge_psys_onoff (uint8_t enable )
550+ {
551+ int control1 = 0x0000 ;
513552 int control4 = 0x0000 ;
514553 int data = 0x0000 ;
515554
516555 if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
517556 ISL9241_REG_CONTROL1 , & control1 )) {
518- CPRINTS ("read charger control1 fail" );
557+ CPRINTS ("read psys control1 fail" );
519558 }
520559
521560 if (enable ) {
522- control0 &= ~ISL9241_CONTROL0_NGATE ;
523- control1 &= ~(ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
561+ control1 &= ~ISL9241_CONTROL1_IMON ;
524562 control1 |= ISL9241_CONTROL1_PSYS ;
525563 control4 &= ~ISL9241_CONTROL4_GP_COMPARATOR ;
526564 data = 0x0B00 ; /* Set ACOK reference to 4.544V */
527565 CPRINTS ("Power saving disable" );
528566 } else {
529- control0 |= ISL9241_CONTROL0_NGATE ;
530- control1 |= (ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
567+ control1 |= ISL9241_CONTROL1_IMON ;
531568 control1 &= ~ISL9241_CONTROL1_PSYS ;
532569 control4 |= ISL9241_CONTROL4_GP_COMPARATOR ;
533570 data = 0x0000 ; /* Set ACOK reference to 0V */
@@ -540,22 +577,55 @@ void charge_psys_onoff(uint8_t enable)
540577 CPRINTS ("Update ACOK reference fail" );
541578 }
542579
543- if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
544- ISL9241_REG_CONTROL0 , control0 )) {
545- CPRINTS ("Update charger control0 fail" );
546- }
547-
548580 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
549581 ISL9241_REG_CONTROL1 , control1 )) {
550- CPRINTS ("Update charger control1 fail" );
582+ CPRINTS ("Update psys control1 fail" );
551583 }
552584
553585 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
554586 ISL9241_REG_CONTROL4 , control4 )) {
555- CPRINTS ("Update charger control4 fail" );
587+ CPRINTS ("Update psys control4 fail" );
556588 }
557589}
558590
591+
592+ /*
593+ * Charger Low Power Mode Process
594+ * modern standby should not turn off Bfet and Nfet
595+ * DC only at S5 need enable
596+ * AC+DC at S5 & Fully charge need enable
597+ * AC+DC at Modern standby & Fully charge need enable
598+ * AC only need disable
599+ */
600+ void charger_low_power_update (void )
601+ {
602+ static int ac_state ;
603+ static int dc_state ;
604+ int batt_status ;
605+
606+ ac_state = extpower_is_present ();
607+ dc_state = battery_is_present ();
608+ battery_status (& batt_status );
609+
610+ if (dc_state && !ac_state &&
611+ chipset_in_state (CHIPSET_STATE_ANY_OFF )) {
612+ charge_gate_onoff (0 );
613+ charge_psys_onoff (0 );
614+ } else if (ac_state && dc_state &&
615+ batt_status & STATUS_FULLY_CHARGED ) {
616+ if (chipset_in_state (CHIPSET_STATE_ANY_OFF )) {
617+ charge_gate_onoff (0 );
618+ charge_psys_onoff (0 );
619+ } else if (chipset_in_state (CHIPSET_STATE_STANDBY ))
620+ charge_psys_onoff (0 );
621+ } else if (ac_state && !dc_state ) {
622+ charge_gate_onoff (1 );
623+ charge_psys_onoff (1 );
624+ }
625+ }
626+ DECLARE_HOOK (HOOK_AC_CHANGE , charger_low_power_update , HOOK_PRIO_DEFAULT );
627+ DECLARE_HOOK (HOOK_BATTERY_SOC_CHANGE , charger_low_power_update , HOOK_PRIO_DEFAULT );
628+
559629/* Initialize board. */
560630static void board_init (void )
561631{
@@ -586,6 +656,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT + 1);
586656static void board_chipset_startup (void )
587657{
588658 CPRINTS ("HOOK_CHIPSET_STARTUP - called board_chipset_startup" );
659+ charge_gate_onoff (1 );
589660 charge_psys_onoff (1 );
590661}
591662DECLARE_HOOK (HOOK_CHIPSET_STARTUP ,
@@ -595,12 +666,21 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
595666/* Called on AP S3 -> S5 transition */
596667static void board_chipset_shutdown (void )
597668{
669+ int batt_status ;
670+
671+ battery_status (& batt_status );
672+
598673 CPRINTS (" HOOK_CHIPSET_SHUTDOWN board_chipset_shutdown" );
599674
600675#ifdef CONFIG_EMI_REGION1
601676 lpc_set_host_event_mask (LPC_HOST_EVENT_SCI , 0 );
602677#endif
603- charge_psys_onoff (0 );
678+
679+ /* avoid AC mode enable charger LPM when charging*/
680+ if (!extpower_is_present () || (batt_status & STATUS_FULLY_CHARGED )) {
681+ charge_gate_onoff (0 );
682+ charge_psys_onoff (0 );
683+ }
604684}
605685DECLARE_HOOK (HOOK_CHIPSET_SHUTDOWN ,
606686 board_chipset_shutdown ,
@@ -613,6 +693,7 @@ static void board_chipset_resume(void)
613693 /*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
614694 gpio_set_level (GPIO_EC_MUTE_L , 1 );
615695 gpio_set_level (GPIO_CAM_EN , 1 );
696+ charge_psys_onoff (1 );
616697}
617698DECLARE_HOOK (HOOK_CHIPSET_RESUME , board_chipset_resume ,
618699 MOTION_SENSE_HOOK_PRIO - 1 );
@@ -626,6 +707,7 @@ static void board_chipset_suspend(void)
626707 gpio_set_level (GPIO_EC_MUTE_L , 0 );
627708 gpio_set_level (GPIO_CAM_EN , 0 );
628709 }
710+ charge_psys_onoff (0 );
629711}
630712DECLARE_HOOK (HOOK_CHIPSET_SUSPEND ,
631713 board_chipset_suspend ,
0 commit comments