mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-15 17:41:25 +00:00
atlas: improve discharged battery handling
we normally try to find out a few things about a battery (like charge level) before actaully applying charging power to it. when the battery is completely discharged, the controller on the battery can't respond as it is not self-powered. so, we have to avoid all operations that depend on the battery responding in the battery discovery/initialization path. as long as we report that a battery is present and it is not responsive, the charger task will enter ST_PRECHARGE which means it'll provide a "precharge" current to the battery to try to talk to it. this allows the battery's controller to report battery parameters allowing our charger task can do the right thing. BUG=b:79354967 BRANCH=none TEST=atlas now discovers the discharged battery reliably Change-Id: I5e5a3abda07508eb791b712fb2f9b9f5fe383e07 Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1065492 Commit-Ready: Caveh Jalali <caveh@google.com> Tested-by: Caveh Jalali <caveh@google.com> Reviewed-by: Caveh Jalali <caveh@google.com>
This commit is contained in:
@@ -41,7 +41,6 @@ struct board_batt_params {
|
||||
* discharged state.
|
||||
*/
|
||||
#define DEFAULT_BATTERY_TYPE BATTERY_LISHEN
|
||||
static enum battery_present batt_pres_prev = BP_NOT_SURE;
|
||||
static enum battery_type board_battery_type = BATTERY_TYPE_COUNT;
|
||||
|
||||
/* Battery may delay reporting battery present */
|
||||
@@ -199,14 +198,6 @@ enum battery_present battery_hw_present(void)
|
||||
return gpio_get_level(GPIO_BATTERY_PRESENT_L) ? BP_NO : BP_YES;
|
||||
}
|
||||
|
||||
static int battery_init(void)
|
||||
{
|
||||
int batt_status;
|
||||
|
||||
return battery_status(&batt_status) ? 0 :
|
||||
!!(batt_status & STATUS_INITIALIZED);
|
||||
}
|
||||
|
||||
/* Allow booting now that the battery has woke up */
|
||||
static void battery_now_present(void)
|
||||
{
|
||||
@@ -215,83 +206,13 @@ static void battery_now_present(void)
|
||||
}
|
||||
DECLARE_DEFERRED(battery_now_present);
|
||||
|
||||
/*
|
||||
* Check for case where XDSG bit is set indicating that even
|
||||
* though the FG can be read from the battery, the battery is not able to be
|
||||
* charged or discharged. This situation will happen if a battery disconnect was
|
||||
* intiaited via H1 setting the DISCONN signal to the battery. This will put the
|
||||
* battery pack into a sleep state and when power is reconnected, the FG can be
|
||||
* read, but the battery is still not able to provide power to the system. The
|
||||
* calling function returns batt_pres = BP_NO, which instructs the charging
|
||||
* state machine to prevent powering up the AP on battery alone which could lead
|
||||
* to a brownout event when the battery isn't able yet to provide power to the
|
||||
* system. .
|
||||
*/
|
||||
static int battery_check_disconnect(void)
|
||||
{
|
||||
int rv;
|
||||
uint8_t data[6];
|
||||
|
||||
/* Check if battery discharging is disabled. */
|
||||
rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
|
||||
SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
|
||||
if (rv)
|
||||
return BATTERY_DISCONNECT_ERROR;
|
||||
|
||||
if (data[3] & BATTERY_DISCHARGING_DISABLED)
|
||||
return BATTERY_DISCONNECTED;
|
||||
|
||||
return BATTERY_NOT_DISCONNECTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Physical detection of battery.
|
||||
*/
|
||||
enum battery_present battery_is_present(void)
|
||||
{
|
||||
enum battery_present batt_pres;
|
||||
static int battery_report_present_timer_started;
|
||||
if (battery_hw_present() == BP_NO || battery_is_cut_off())
|
||||
return BP_NO;
|
||||
|
||||
/* Get the physical hardware status */
|
||||
batt_pres = battery_hw_present();
|
||||
|
||||
/*
|
||||
* Make sure battery status is implemented, I2C transactions are
|
||||
* success & the battery status is Initialized to find out if it
|
||||
* is a working battery and it is not in the cut-off mode.
|
||||
*
|
||||
* If battery I2C fails but VBATT is high, battery is booting from
|
||||
* cut-off mode.
|
||||
*
|
||||
* FETs are turned off after Power Shutdown time.
|
||||
* The device will wake up when a voltage is applied to PACK.
|
||||
* Battery status will be inactive until it is initialized.
|
||||
*/
|
||||
if (batt_pres == BP_YES && batt_pres_prev != batt_pres &&
|
||||
(battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL ||
|
||||
battery_check_disconnect() != BATTERY_NOT_DISCONNECTED ||
|
||||
battery_init() == 0)) {
|
||||
battery_report_present = 0;
|
||||
} else if (batt_pres == BP_YES && batt_pres_prev == BP_NO &&
|
||||
!battery_report_present_timer_started) {
|
||||
/*
|
||||
* Wait 1 second before reporting present if it was
|
||||
* previously reported as not present
|
||||
*/
|
||||
battery_report_present_timer_started = 1;
|
||||
battery_report_present = 0;
|
||||
hook_call_deferred(&battery_now_present_data, SECOND);
|
||||
}
|
||||
|
||||
if (!battery_report_present)
|
||||
batt_pres = BP_NO;
|
||||
|
||||
batt_pres_prev = batt_pres;
|
||||
|
||||
return batt_pres;
|
||||
}
|
||||
|
||||
int board_battery_initialized(void)
|
||||
{
|
||||
return battery_hw_present() == batt_pres_prev;
|
||||
return BP_YES;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user