File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ static const struct battery_info info = {
4040 .discharging_max_c = 62 ,
4141};
4242
43+ static enum battery_present batt_pres_prev = BP_NOT_SURE ;
4344static uint8_t charging_maximum_level = NEED_RESTORE ;
4445static int old_btp ;
4546
@@ -100,20 +101,31 @@ static int battery_check_disconnect(void)
100101
101102enum battery_present battery_is_present (void )
102103{
103- enum battery_present bp ;
104+ enum battery_present batt_pres ;
104105 int mv ;
105106
106107 mv = adc_read_channel (ADC_VCIN1_BATT_TEMP );
107- bp = (mv < 3000 ? BP_YES : BP_NO );
108+ batt_pres = (mv < 3000 ? BP_YES : BP_NO );
108109
109110 if (mv == ADC_READ_ERROR )
110111 return BP_NO ;
111- else if (!bp )
112+
113+ /*
114+ * If the battery is present now and was present last time we checked,
115+ * return early.
116+ */
117+ if (batt_pres == BP_YES && batt_pres_prev == batt_pres )
118+ return batt_pres ;
119+
120+
121+ if (!batt_pres )
112122 return BP_NO ;
113123 else if (battery_check_disconnect () != BATTERY_NOT_DISCONNECTED )
114124 return BP_NOT_SURE ;
115- else
116- return bp ;
125+
126+ batt_pres_prev = batt_pres ;
127+
128+ return batt_pres ;
117129}
118130
119131#ifdef CONFIG_EMI_REGION1
You can’t perform that action at this time.
0 commit comments