mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
charge_state_v2: Limit i/p current to meet allowed MAX i/p system power
If battery is not present, input current is set to PD_MAX_CURRENT_MA.
If the input power set is greater than the maximum allowed system power,
system might get damaged. Hence, limit the input current to meet maximum
allowed input system power.
BUG=chrome-os-partner:58498
BRANCH=none
TEST=Manually tested on Reef. Removed the battery & using 'charger'
console command observed the following.
With Zinger charger at 20V - Input current is set to 2.25A
With Type-C & other chargers - Input current is set to 3A
Change-Id: Ife8686f322e095aa74b740a7c469bfe87107fb9a
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/397865
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
64414f92b3
commit
f66113247a
@@ -340,11 +340,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -326,13 +326,15 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Limit input current 95% ratio on elm board for safety */
|
||||
charge_ma = (charge_ma * 95) / 100;
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -439,8 +439,10 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Enable charging trigger by BC1.2 detection */
|
||||
int bc12_enable = (supplier == CHARGE_SUPPLIER_BC12_CDP ||
|
||||
@@ -452,7 +454,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
return;
|
||||
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -312,11 +312,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -245,7 +245,8 @@ int board_set_active_charge_port(int charge_port)
|
||||
return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
|
||||
}
|
||||
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/*
|
||||
* Ignore lower charge ceiling on PD transition if our battery is
|
||||
@@ -259,7 +260,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
}
|
||||
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
int extpower_is_present(void)
|
||||
|
||||
@@ -171,12 +171,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
int rv;
|
||||
|
||||
charge_ma = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
|
||||
rv = charge_set_input_current_limit(charge_ma);
|
||||
rv = charge_set_input_current_limit(charge_ma, charge_mv);
|
||||
if (rv < 0)
|
||||
CPRINTS("Failed to set input current limit for PD");
|
||||
}
|
||||
|
||||
@@ -310,11 +310,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -573,8 +573,10 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Enable charging trigger by BC1.2 detection */
|
||||
int bc12_enable = (supplier == CHARGE_SUPPLIER_BC12_CDP ||
|
||||
@@ -586,7 +588,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
return;
|
||||
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -586,8 +586,10 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Enable charging trigger by BC1.2 detection */
|
||||
int bc12_enable = (supplier == CHARGE_SUPPLIER_BC12_CDP ||
|
||||
@@ -599,7 +601,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
return;
|
||||
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -549,13 +549,15 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
int rv;
|
||||
|
||||
charge_current_limit = MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT);
|
||||
rv = charge_set_input_current_limit(charge_current_limit);
|
||||
rv = charge_set_input_current_limit(charge_current_limit, charge_mv);
|
||||
if (rv < 0)
|
||||
CPRINTS("Failed to set input current limit for PD");
|
||||
}
|
||||
|
||||
@@ -498,11 +498,13 @@ static int board_update_charge_limit(int charge_ma)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Update current limit and notify EC if it changed */
|
||||
if (board_update_charge_limit(charge_ma))
|
||||
if (board_update_charge_limit(charge_ma), charge_mv)
|
||||
pd_send_ec_int();
|
||||
}
|
||||
|
||||
|
||||
@@ -572,8 +572,10 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
/* Enable charging trigger by BC1.2 detection */
|
||||
int bc12_enable = (supplier == CHARGE_SUPPLIER_BC12_CDP ||
|
||||
@@ -585,7 +587,7 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
return;
|
||||
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -335,11 +335,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -300,11 +300,13 @@ int board_set_active_charge_port(int charge_port)
|
||||
* @param port Port number.
|
||||
* @param supplier Charge supplier type.
|
||||
* @param charge_ma Desired charge limit (mA).
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
|
||||
}
|
||||
|
||||
/* Enable or disable input devices, based upon chipset state and tablet mode */
|
||||
|
||||
@@ -560,7 +560,8 @@ static void charge_manager_refresh(void)
|
||||
#ifdef HAS_TASK_CHG_RAMP
|
||||
chg_ramp_charge_supplier_change(
|
||||
new_port, new_supplier, new_charge_current,
|
||||
registration_time[new_port]);
|
||||
registration_time[new_port],
|
||||
new_charge_voltage);
|
||||
#else
|
||||
#ifdef CONFIG_CHARGE_RAMP_HW
|
||||
/* Enable or disable charge ramp */
|
||||
@@ -568,7 +569,8 @@ static void charge_manager_refresh(void)
|
||||
#endif
|
||||
board_set_charge_limit(new_port, new_supplier,
|
||||
new_charge_current,
|
||||
new_charge_current_uncapped);
|
||||
new_charge_current_uncapped,
|
||||
new_charge_voltage);
|
||||
#endif /* HAS_TASK_CHG_RAMP */
|
||||
|
||||
power_changed = 1;
|
||||
@@ -826,8 +828,8 @@ void charge_manager_force_ceil(int port, int ceil)
|
||||
* waiting for our deferred task to run.
|
||||
*/
|
||||
if (port == charge_port && ceil < charge_current)
|
||||
board_set_charge_limit(port, CHARGE_SUPPLIER_PD,
|
||||
ceil, charge_current_uncapped);
|
||||
board_set_charge_limit(port, CHARGE_SUPPLIER_PD, ceil,
|
||||
charge_current_uncapped, charge_voltage);
|
||||
|
||||
/*
|
||||
* Now inform charge_manager so it stays in sync with the state of
|
||||
|
||||
@@ -66,6 +66,7 @@ static int oc_info_idx[CONFIG_USB_PD_PORT_COUNT];
|
||||
static int active_port = CHARGE_PORT_NONE;
|
||||
static int active_sup;
|
||||
static int active_icl;
|
||||
static int active_vtg;
|
||||
static timestamp_t reg_time;
|
||||
|
||||
static int stablize_port;
|
||||
@@ -77,7 +78,7 @@ static int min_icl;
|
||||
|
||||
|
||||
void chg_ramp_charge_supplier_change(int port, int supplier, int current,
|
||||
timestamp_t registration_time)
|
||||
timestamp_t registration_time, int voltage)
|
||||
{
|
||||
/*
|
||||
* If the last active port was a valid port and the port
|
||||
@@ -97,6 +98,7 @@ void chg_ramp_charge_supplier_change(int port, int supplier, int current,
|
||||
/* Set new active port, set ramp state, and wake ramp task */
|
||||
active_port = port;
|
||||
active_sup = supplier;
|
||||
active_vtg = voltage;
|
||||
|
||||
/* Set min and max input current limit based on if ramp is allowed */
|
||||
if (board_is_ramp_allowed(active_sup)) {
|
||||
@@ -320,7 +322,8 @@ void chg_ramp_task(void)
|
||||
|
||||
/* Set the input current limit */
|
||||
lim = chg_ramp_get_current_limit();
|
||||
board_set_charge_limit(active_port, active_sup, lim, lim);
|
||||
board_set_charge_limit(active_port, active_sup, lim,
|
||||
lim, active_vtg);
|
||||
|
||||
if (ramp_st == CHG_RAMP_STABILIZE)
|
||||
/*
|
||||
|
||||
@@ -1106,7 +1106,7 @@ int charge_get_battery_temp(int idx, int *temp_ptr)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int charge_set_input_current_limit(int ma)
|
||||
int charge_set_input_current_limit(int ma, int mv)
|
||||
{
|
||||
/*
|
||||
* If battery is not present and we are not locked, then allow system
|
||||
@@ -1114,8 +1114,26 @@ int charge_set_input_current_limit(int ma)
|
||||
* the charger but this is no worse then 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()) {
|
||||
#ifdef CONFIG_USB_POWER_DELIVERY
|
||||
#if ((PD_MAX_POWER_MW * 1000) / PD_MAX_VOLTAGE_MV != PD_MAX_CURRENT_MA)
|
||||
/*
|
||||
* If battery is not present, input current is set to
|
||||
* PD_MAX_CURRENT_MA. If the input power set is greater than
|
||||
* the maximum allowed system power, system might get damaged.
|
||||
* Hence, limit the input current to meet maximum allowed
|
||||
* input system power.
|
||||
*/
|
||||
if (mv > 0 && mv * curr.desired_input_current >
|
||||
PD_MAX_POWER_MW * 1000)
|
||||
ma = (PD_MAX_POWER_MW * 1000) / mv;
|
||||
else
|
||||
return EC_SUCCESS;
|
||||
#else
|
||||
return EC_SUCCESS;
|
||||
#endif
|
||||
#endif /* CONFIG_USB_POWER_DELIVERY */
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CHARGER_MAX_INPUT_CURRENT
|
||||
/* Limit input current limit to max limit for this board */
|
||||
|
||||
@@ -126,7 +126,7 @@ static void pd_check_chg_status(struct ec_response_pd_status *pd_status)
|
||||
|
||||
/* Set input current limit */
|
||||
rv = charge_set_input_current_limit(MAX(pd_status->curr_lim_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
CONFIG_CHARGER_INPUT_CURRENT), 0);
|
||||
if (rv < 0)
|
||||
CPRINTS("Failed to set input curr limit from PD MCU");
|
||||
}
|
||||
|
||||
@@ -127,8 +127,10 @@ int board_set_active_charge_port(int charge_port);
|
||||
* @param supplier Identified CHARGE_SUPPLIER_*.
|
||||
* @param charge_ma Desired charge current limit, <= max_ma.
|
||||
* @param max_ma Maximum charge current limit, >= charge_ma.
|
||||
* @param charge_mv Negotiated charge voltage (mV).
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma);
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv);
|
||||
|
||||
/*
|
||||
* Get whether the port is sourcing power on VBUS.
|
||||
|
||||
@@ -82,9 +82,10 @@ int chg_ramp_is_detected(void);
|
||||
* @supplier Active charging supplier
|
||||
* @current Minimum input current limit
|
||||
* @registration_time Timestamp of when the supplier is registered
|
||||
* @voltage Negotiated charge voltage.
|
||||
*/
|
||||
void chg_ramp_charge_supplier_change(int port, int supplier, int current,
|
||||
timestamp_t registration_time);
|
||||
timestamp_t registration_time, int voltage);
|
||||
|
||||
#else
|
||||
static inline void chg_ramp_charge_supplier_change(
|
||||
|
||||
@@ -68,9 +68,10 @@ enum ec_status charger_profile_override_set_param(uint32_t param,
|
||||
* time AC is applied.
|
||||
*
|
||||
* @param ma New input current limit in mA
|
||||
* @param mv Negotiated charge voltage in mV.
|
||||
* @return EC_SUCCESS or error
|
||||
*/
|
||||
int charge_set_input_current_limit(int ma);
|
||||
int charge_set_input_current_limit(int ma, int mv);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,8 @@ static int new_power_request[CONFIG_USB_PD_PORT_COUNT];
|
||||
static int power_role[CONFIG_USB_PD_PORT_COUNT];
|
||||
|
||||
/* Callback functions called by CM on state change */
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma,
|
||||
int max_ma, int charge_mv)
|
||||
{
|
||||
active_charge_limit = charge_ma;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
|
||||
vbus_low_current_ma;
|
||||
}
|
||||
|
||||
void board_set_charge_limit(int port, int supplier, int limit_ma, int max_ma)
|
||||
void board_set_charge_limit(int port, int supplier, int limit_ma,
|
||||
int max_ma, int max_mv)
|
||||
{
|
||||
charge_limit_ma = limit_ma;
|
||||
if (charge_limit_ma > overcurrent_current_ma)
|
||||
@@ -79,7 +80,7 @@ static void plug_charger_with_ts(int supplier_type, int port, int min_current,
|
||||
vbus_low_current_ma = vbus_low_current;
|
||||
overcurrent_current_ma = overcurrent_current;
|
||||
chg_ramp_charge_supplier_change(port, supplier_type, min_current,
|
||||
reg_time);
|
||||
reg_time, 0);
|
||||
}
|
||||
|
||||
static void plug_charger(int supplier_type, int port, int min_current,
|
||||
@@ -93,7 +94,7 @@ static void plug_charger(int supplier_type, int port, int min_current,
|
||||
static void unplug_charger(void)
|
||||
{
|
||||
chg_ramp_charge_supplier_change(CHARGE_PORT_NONE, CHARGE_SUPPLIER_NONE,
|
||||
0, get_time());
|
||||
0, get_time(), 0);
|
||||
}
|
||||
|
||||
static int unplug_charger_and_check(void)
|
||||
|
||||
Reference in New Issue
Block a user