diff options
-rw-r--r-- | board/chell/board.c | 6 | ||||
-rw-r--r-- | board/elm/board.c | 6 | ||||
-rw-r--r-- | board/eve/board.c | 6 | ||||
-rw-r--r-- | board/glados/board.c | 6 | ||||
-rw-r--r-- | board/kevin/board.c | 5 | ||||
-rw-r--r-- | board/lucid/board.c | 5 | ||||
-rw-r--r-- | board/oak/board.c | 6 | ||||
-rw-r--r-- | board/pyro/board.c | 6 | ||||
-rw-r--r-- | board/reef/board.c | 6 | ||||
-rw-r--r-- | board/ryu/board.c | 6 | ||||
-rw-r--r-- | board/samus_pd/board.c | 6 | ||||
-rw-r--r-- | board/snappy/board.c | 6 | ||||
-rw-r--r-- | board/strago/board.c | 6 | ||||
-rw-r--r-- | board/wheatley/board.c | 6 | ||||
-rw-r--r-- | common/charge_manager.c | 10 | ||||
-rw-r--r-- | common/charge_ramp.c | 7 | ||||
-rw-r--r-- | common/charge_state_v2.c | 22 | ||||
-rw-r--r-- | common/host_command_pd.c | 2 | ||||
-rw-r--r-- | include/charge_manager.h | 4 | ||||
-rw-r--r-- | include/charge_ramp.h | 3 | ||||
-rw-r--r-- | include/charge_state_v2.h | 3 | ||||
-rw-r--r-- | test/charge_manager.c | 3 | ||||
-rw-r--r-- | test/charge_ramp.c | 7 |
23 files changed, 99 insertions, 44 deletions
diff --git a/board/chell/board.c b/board/chell/board.c index 2d59ab68fe..d08a81abba 100644 --- a/board/chell/board.c +++ b/board/chell/board.c @@ -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); } /** diff --git a/board/elm/board.c b/board/elm/board.c index 5631e1d7d2..4076979b4a 100644 --- a/board/elm/board.c +++ b/board/elm/board.c @@ -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); } diff --git a/board/eve/board.c b/board/eve/board.c index 7479b558e2..8a6015c1ee 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -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); } /** diff --git a/board/glados/board.c b/board/glados/board.c index 96e19fc6d6..b37f59feff 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -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); } /** diff --git a/board/kevin/board.c b/board/kevin/board.c index de8e381658..20ef89d8a3 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -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) diff --git a/board/lucid/board.c b/board/lucid/board.c index 298c072440..3923c7a183 100644 --- a/board/lucid/board.c +++ b/board/lucid/board.c @@ -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"); } diff --git a/board/oak/board.c b/board/oak/board.c index 73e0ca02eb..b56223adf3 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -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); } diff --git a/board/pyro/board.c b/board/pyro/board.c index 0b1860c521..d3176d7140 100644 --- a/board/pyro/board.c +++ b/board/pyro/board.c @@ -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); } /** diff --git a/board/reef/board.c b/board/reef/board.c index 322bdf67ad..c2a97d1689 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -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); } /** diff --git a/board/ryu/board.c b/board/ryu/board.c index d01bdfcfe4..0f7a5ba478 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -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"); } diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index 1431c50d32..288ff1cbb7 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -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(); } diff --git a/board/snappy/board.c b/board/snappy/board.c index 29b7b0f716..c7edd3547a 100644 --- a/board/snappy/board.c +++ b/board/snappy/board.c @@ -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); } /** diff --git a/board/strago/board.c b/board/strago/board.c index a013e0f73e..6459488567 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -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); } /** diff --git a/board/wheatley/board.c b/board/wheatley/board.c index deac227365..c467d4dd89 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -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 */ diff --git a/common/charge_manager.c b/common/charge_manager.c index cd59c93007..9d5df6184a 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -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 diff --git a/common/charge_ramp.c b/common/charge_ramp.c index e63b37b9bd..f7bd48662e 100644 --- a/common/charge_ramp.c +++ b/common/charge_ramp.c @@ -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) /* diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 41152ff961..06ee6a7861 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -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 */ diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 831b6159bc..ffd2d3b996 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -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"); } diff --git a/include/charge_manager.h b/include/charge_manager.h index 71cc8589aa..1082883445 100644 --- a/include/charge_manager.h +++ b/include/charge_manager.h @@ -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. diff --git a/include/charge_ramp.h b/include/charge_ramp.h index 6b7b3ad247..62145568c4 100644 --- a/include/charge_ramp.h +++ b/include/charge_ramp.h @@ -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( diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h index c5aedb7a94..e5855c2fe1 100644 --- a/include/charge_state_v2.h +++ b/include/charge_state_v2.h @@ -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); /** diff --git a/test/charge_manager.c b/test/charge_manager.c index 1c08245b92..a203a515c9 100644 --- a/test/charge_manager.c +++ b/test/charge_manager.c @@ -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; } diff --git a/test/charge_ramp.c b/test/charge_ramp.c index 4fc1c5ac63..33db036a59 100644 --- a/test/charge_ramp.c +++ b/test/charge_ramp.c @@ -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) |