Skip to content

Commit cf6aad2

Browse files
committed
[modify] double check battery D-FET state
when D-FET not active we should return not_sure Signed-off-by: Leo_Tsai <[email protected]>
1 parent 1795d9d commit cf6aad2

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

board/hx20/battery.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,42 @@ __override void battery_charger_notify(uint8_t flag)
8080
}
8181
}
8282

83+
static int battery_check_disconnect(void)
84+
{
85+
int rv;
86+
uint8_t data[6];
87+
88+
/* Check if battery charging + discharging is disabled. */
89+
rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
90+
SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
91+
if (rv)
92+
return BATTERY_DISCONNECT_ERROR;
93+
94+
if (data[3] & BATTERY_DISCHARGING_DISABLED)
95+
return BATTERY_DISCONNECTED;
96+
97+
98+
return BATTERY_NOT_DISCONNECTED;
99+
}
100+
83101
enum battery_present battery_is_present(void)
84102
{
85103
enum battery_present bp;
86104
int mv;
87105

88106
mv = adc_read_channel(ADC_VCIN1_BATT_TEMP);
89-
90-
if (mv == ADC_READ_ERROR)
91-
return -1;
92-
93107
bp = (mv < 3000 ? BP_YES : BP_NO);
94108

95-
return bp;
109+
if (mv == ADC_READ_ERROR)
110+
return BP_NO;
111+
else if (!bp)
112+
return BP_NO;
113+
else if (!(charger_current_battery_params()->flags & BATT_FLAG_RESPONSIVE))
114+
return BP_NOT_SURE;
115+
else if (battery_check_disconnect() != BATTERY_NOT_DISCONNECTED)
116+
return BP_NOT_SURE;
117+
else
118+
return bp;
96119
}
97120

98121
#ifdef CONFIG_EMI_REGION1

board/hx20/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161

162162
#define CONFIG_BATTERY_CUT_OFF
163163
#define CONFIG_BATTERY_SMART
164+
#define CONFIG_BATTERY_PRESENT_CUSTOM
164165
#define CONFIG_BOARD_VERSION_CUSTOM
165166
#define CONFIG_CHARGE_MANAGER
166167
/* #define CONFIG_CHARGE_RAMP_SW */

board/hx20/cypress5525.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ void cypd_update_power(void)
358358

359359
if (extpower_is_present() ||
360360
(charger_current_battery_params()->flags & BATT_FLAG_RESPONSIVE &&
361-
charger_current_battery_params()->state_of_charge > 0))
361+
charger_current_battery_params()->state_of_charge > 0 &&
362+
battery_is_present() == BP_YES))
362363
system_power_present = 1;
363364
else
364365
system_power_present = 0;
@@ -370,7 +371,8 @@ int cypd_update_power_status(void)
370371
int rv = EC_SUCCESS;
371372
int power_stat = 0;
372373
if (charger_current_battery_params()->flags & BATT_FLAG_RESPONSIVE &&
373-
charger_current_battery_params()->state_of_charge > 0) {
374+
charger_current_battery_params()->state_of_charge > 0 &&
375+
battery_is_present() == BP_YES) {
374376
power_stat |= BIT(3);
375377
}
376378
if (extpower_is_present()) {

0 commit comments

Comments
 (0)