1515#include "als.h"
1616#include "bd99992gw.h"
1717#include "button.h"
18+ #include "battery.h"
1819#include "charge_state.h"
1920#include "charger.h"
2021#include "chipset.h"
@@ -496,56 +497,123 @@ static void check_chassis_open(int init)
496497 }
497498}
498499
499- void charge_psys_onoff (uint8_t enable )
500+ void charge_gate_onoff (uint8_t enable )
500501{
501502 int control0 = 0x0000 ;
502503 int control1 = 0x0000 ;
504+
505+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
506+ ISL9241_REG_CONTROL0 , & control0 )) {
507+ CPRINTS ("read gate control1 fail" );
508+ }
509+
510+ if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
511+ ISL9241_REG_CONTROL1 , & control1 )) {
512+ CPRINTS ("read gate control1 fail" );
513+ }
514+
515+ if (enable ) {
516+ control0 &= ~ISL9241_CONTROL0_NGATE ;
517+ control1 &= ~ISL9241_CONTROL1_BGATE ;
518+ CPRINTS ("B&N Gate off" );
519+ } else {
520+ control0 |= ISL9241_CONTROL0_NGATE ;
521+ control1 |= ISL9241_CONTROL1_BGATE ;
522+ CPRINTS ("B&N Gate on" );
523+ }
524+
525+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
526+ ISL9241_REG_CONTROL0 , control0 )) {
527+ CPRINTS ("Update gate control0 fail" );
528+ }
529+
530+ if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
531+ ISL9241_REG_CONTROL1 , control1 )) {
532+ CPRINTS ("Update gate control1 fail" );
533+ }
534+
535+ }
536+
537+
538+ void charge_psys_onoff (uint8_t enable )
539+ {
540+ int control1 = 0x0000 ;
503541 int control4 = 0x0000 ;
504542 int data = 0x0000 ;
505543
506544 if (i2c_read16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
507545 ISL9241_REG_CONTROL1 , & control1 )) {
508- CPRINTS ("read charger control1 fail" );
546+ CPRINTS ("read psys control1 fail" );
509547 }
510548
511549 if (enable ) {
512- control0 &= ~ISL9241_CONTROL0_NGATE ;
513- control1 &= ~(ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
550+ control1 &= ~ISL9241_CONTROL1_IMON ;
514551 control1 |= ISL9241_CONTROL1_PSYS ;
515552 control4 &= ~ISL9241_CONTROL4_GP_COMPARATOR ;
516- data = 0x0B00 ;
553+ data = 0x0B00 ; /* Set ACOK reference to 4.544V */
517554 CPRINTS ("Power saving disable" );
518555 } else {
519- control0 |= ISL9241_CONTROL0_NGATE ;
520- control1 |= (ISL9241_CONTROL1_IMON | ISL9241_CONTROL1_BGATE );
556+ control1 |= ISL9241_CONTROL1_IMON ;
521557 control1 &= ~ISL9241_CONTROL1_PSYS ;
522558 control4 |= ISL9241_CONTROL4_GP_COMPARATOR ;
523- data = 0x0000 ;
559+ data = 0x0000 ; /* Set ACOK reference to 0V */
524560 CPRINTS ("Power saving enable" );
525561 }
526562
527-
528563 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
529564 ISL9241_REG_ACOK_REFERENCE , data )) {
530- CPRINTS ("Update charger ACOK reference fail" );
531- }
532-
533- if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
534- ISL9241_REG_CONTROL0 , control0 )) {
535- CPRINTS ("Update charger control0 fail" );
565+ CPRINTS ("Update ACOK reference fail" );
536566 }
537567
538568 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
539569 ISL9241_REG_CONTROL1 , control1 )) {
540- CPRINTS ("Update charger control1 fail" );
570+ CPRINTS ("Update psys control1 fail" );
541571 }
542572
543573 if (i2c_write16 (I2C_PORT_CHARGER , ISL9241_ADDR_FLAGS ,
544574 ISL9241_REG_CONTROL4 , control4 )) {
545- CPRINTS ("Update charger control4 fail" );
575+ CPRINTS ("Update psys control4 fail" );
546576 }
547577}
548578
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+
549617/* Initialize board. */
550618static void board_init (void )
551619{
@@ -579,6 +647,7 @@ static void board_chipset_startup(void)
579647 if (version > 6 )
580648 gpio_set_level (GPIO_EN_INVPWR , 1 );
581649
650+ charge_gate_onoff (1 );
582651 charge_psys_onoff (1 );
583652}
584653DECLARE_HOOK (HOOK_CHIPSET_STARTUP ,
@@ -588,17 +657,21 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP,
588657/* Called on AP S3 -> S5 transition */
589658static void board_chipset_shutdown (void )
590659{
591- int version = board_get_version ();
660+ int batt_status ;
661+
662+ battery_status (& batt_status );
592663
593664 CPRINTS (" HOOK_CHIPSET_SHUTDOWN board_chipset_shutdown" );
594665
595666#ifdef CONFIG_EMI_REGION1
596667 lpc_set_host_event_mask (LPC_HOST_EVENT_SCI , 0 );
597668#endif
598- if (version > 6 )
599- gpio_set_level (GPIO_EN_INVPWR , 0 );
600669
601- charge_psys_onoff (0 );
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+ }
602675}
603676DECLARE_HOOK (HOOK_CHIPSET_SHUTDOWN ,
604677 board_chipset_shutdown ,
@@ -611,6 +684,7 @@ static void board_chipset_resume(void)
611684 /*gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);*/
612685 gpio_set_level (GPIO_EC_MUTE_L , 1 );
613686 gpio_set_level (GPIO_CAM_EN , 1 );
687+ charge_psys_onoff (1 );
614688}
615689DECLARE_HOOK (HOOK_CHIPSET_RESUME , board_chipset_resume ,
616690 MOTION_SENSE_HOOK_PRIO - 1 );
@@ -624,6 +698,7 @@ static void board_chipset_suspend(void)
624698 gpio_set_level (GPIO_EC_MUTE_L , 0 );
625699 gpio_set_level (GPIO_CAM_EN , 0 );
626700 }
701+ charge_psys_onoff (0 );
627702}
628703DECLARE_HOOK (HOOK_CHIPSET_SUSPEND ,
629704 board_chipset_suspend ,
0 commit comments