diff --git a/board/hammer/board.c b/board/hammer/board.c index cb6d7d836b..e17cacd141 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -270,11 +270,3 @@ int board_write_serial(const char *serialno) { return 0; } - -#ifdef BOARD_WAND -/* TODO(b:66575472): This assumes external power is always present. */ -int extpower_is_present(void) -{ - return 1; -} -#endif diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index d956fdcb5a..9b1573c59a 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1071,6 +1071,14 @@ wait_for_it: curr.requested_voltage = charger_closest_voltage( curr.batt.voltage + info->voltage_step); curr.requested_current = -1; +#endif +#ifdef CONFIG_EC_EC_COMM_BATTERY_SLAVE + /* + * On EC-EC slave, do not charge if curr.ac is 0: there + * might still be some external power available but we + * do not want to use it for charging. + */ + curr.requested_current = 0; #endif } charge_request(curr.requested_voltage, curr.requested_current); diff --git a/common/ec_ec_comm_slave.c b/common/ec_ec_comm_slave.c index 40bfef3492..608e1edc4f 100644 --- a/common/ec_ec_comm_slave.c +++ b/common/ec_ec_comm_slave.c @@ -12,6 +12,7 @@ #include "crc8.h" #include "ec_commands.h" #include "ec_ec_comm_slave.h" +#include "extpower.h" #include "hwtimer.h" #include "queue.h" #include "queue_policies.h" @@ -31,6 +32,9 @@ struct ec_response_battery_static_info base_battery_static; struct ec_response_battery_dynamic_info base_battery_dynamic; +/* Set if the master allows the slave to charge the battery. */ +static int charging_allowed; + /* * Our command parameter buffer must be big enough to fit any command * parameter, and crc byte. @@ -140,6 +144,7 @@ static void handle_cmd_charger_control( charger_enable_otg_power(0); charge_set_input_current_limit( MIN(MAX_CURRENT_MA, params->max_current), 0); + charging_allowed = params->allow_charging; } else { if (-params->max_current > MAX_OTG_CURRENT_MA || params->otg_voltage > MAX_OTG_VOLTAGE_MV) { @@ -153,11 +158,26 @@ static void handle_cmd_charger_control( charger_set_otg_current_voltage(-params->max_current, params->otg_voltage); charger_enable_otg_power(1); + charging_allowed = 0; } out: write_response(ret, seq, NULL, 0); } + +/* + * On dual-battery slave, we use the charging allowed signal from master to + * indicate whether external power is present. + * + * In most cases, this actually matches the external power status of the master + * (slave battery charging when AC is connected, or discharging when slave + * battery still has enough capacity), with one exception: when we do master to + * slave battery charging (in this case the "external" power is the master). + */ +int extpower_is_present(void) +{ + return charging_allowed; +} #endif void ec_ec_comm_slave_task(void *u)