charge_state_v2: Fix current limit when lid has no battery

The logic of drawing as much current as possible when no battery
is connected (on the lid), and system unlocked, makes sense during
early bringup.

However, it will not work when the base is also connected, as we
did not implement the required no-battery logic in the base/lid
power allocation algorithm (nor do we plan to, as it is only
required during very early bringup, when we should not expect
power transfer between lid and base to work properly).

Also, we need to record input_voltage in
charge_set_input_current_limit, even when lid battery is not
present (yet), otherwise the algorithm gets confused and believes
no power is available.

BRANCH=none
BUG=b:71881017
TEST=Boot lux from dead battery and base connected, lux does not
     attempt to drive OTG to the base.

Change-Id: I0cdd0956a82a724dbbf9c010760dcb956a58c1bf
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/874982
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Nicolas Boichat
2018-01-19 09:04:36 +08:00
committed by chrome-bot
parent 4d0eb3be49
commit cbd086d13b

View File

@@ -67,6 +67,8 @@ static int prev_base_connected;
static int charge_base;
static int prev_charge_base;
static int prev_current_base;
#else
static const int base_connected;
#endif
/* Is battery connected but unresponsive after precharge? */
@@ -1168,7 +1170,7 @@ DECLARE_HOOK(HOOK_AC_CHANGE, charge_wakeup, HOOK_PRIO_DEFAULT);
static int get_desired_input_current(enum battery_present batt_present,
const struct charger_info * const info)
{
if (batt_present == BP_YES || system_is_locked()) {
if (batt_present == BP_YES || system_is_locked() || base_connected) {
#ifdef CONFIG_CHARGE_MANAGER
int ilim = charge_manager_get_charger_current();
return ilim == CHARGE_CURRENT_UNINITIALIZED ?
@@ -1801,13 +1803,17 @@ int charge_set_output_current_limit(int ma, int mv)
int charge_set_input_current_limit(int ma, int mv)
{
#ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER
curr.input_voltage = mv;
#endif
/*
* If battery is not present and we are not locked, then allow system
* to pull as much input current as needed. Yes, we might overcurrent
* the charger but this is no worse then browning out due to
* insufficient input current.
* If battery is not present, we are not locked, and base is not
* connected then allow system to pull as much input current as needed.
* Yes, we might overcurrent the charger but this is no worse than
* browning out due to insufficient input current.
*/
if (curr.batt.is_present != BP_YES && !system_is_locked()) {
if (curr.batt.is_present != BP_YES && !system_is_locked() &&
!base_connected) {
#ifdef CONFIG_USB_POWER_DELIVERY
#if ((PD_MAX_POWER_MW * 1000) / PD_MAX_VOLTAGE_MV != PD_MAX_CURRENT_MA)
/*
@@ -1834,7 +1840,6 @@ int charge_set_input_current_limit(int ma, int mv)
#endif
curr.desired_input_current = ma;
#ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER
curr.input_voltage = mv;
/* Wake up charger task to allocate current between lid and base. */
charge_wakeup();
return EC_SUCCESS;