diff options
-rw-r--r-- | common/charge_manager.c | 24 | ||||
-rw-r--r-- | common/charge_ramp.c | 4 | ||||
-rw-r--r-- | include/charge_manager.h | 9 | ||||
-rw-r--r-- | test/charge_ramp.c | 6 |
4 files changed, 41 insertions, 2 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c index 1c9bac377e..c0c5eded5e 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -16,6 +16,7 @@ #include "system.h" #include "tcpm.h" #include "timer.h" +#include "usb_charge.h" #include "usb_pd.h" #include "usb_pd_tcpm.h" #include "util.h" @@ -906,6 +907,29 @@ int charge_manager_get_power_limit_uw(void) return current_ma * voltage_mv; } +#ifdef HAS_TASK_CHG_RAMP +int charge_manager_get_ramp_start_current(int port, int supplier) +{ + /* + * A valid charge port is always detected as VBUS supplier type, + * 'USB charger' can detect the same port as BC1.2 DCP supplier type + * & also 'TCPC' can detect the same port as TYPEC supplier type. Thus + * a valid port is detected as 2 or 3 supplier types. Depending on the + * supplier's priority and the power that the supplier can provide, + * charge manager choses the charge supplier type of the port. + * + * If the USB charger detected supplier is BC1.2 DCP and the TCPC + * detected supplier is TYPEC then the supplier can provide stable + * current from TYPEC supplier's advertised current hence start + * ramping from TYPEC supplier's advertised current. + */ + return (supplier == CHARGE_SUPPLIER_BC12_DCP && + available_charge[CHARGE_SUPPLIER_TYPEC][port].current) ? + available_charge[CHARGE_SUPPLIER_TYPEC][port].current : + USB_CHARGER_MIN_CURR_MA; +} +#endif + #ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT void charge_manager_source_port(int port, int enable) { diff --git a/common/charge_ramp.c b/common/charge_ramp.c index f6942d7516..c84e126140 100644 --- a/common/charge_ramp.c +++ b/common/charge_ramp.c @@ -29,7 +29,6 @@ /* Current ramp increment */ #define RAMP_CURR_INCR_MA 64 #define RAMP_CURR_DELAY (500*MSEC) -#define RAMP_CURR_START_MA 500 /* How much to backoff the input current limit when limit has been found */ #define RAMP_ICL_BACKOFF (2*RAMP_CURR_INCR_MA) @@ -102,7 +101,8 @@ void chg_ramp_charge_supplier_change(int port, int supplier, int current, /* Set min and max input current limit based on if ramp is allowed */ if (board_is_ramp_allowed(active_sup)) { - min_icl = RAMP_CURR_START_MA; + min_icl = charge_manager_get_ramp_start_current(active_port, + active_sup); max_icl = board_get_ramp_current_limit(active_sup, current); } else { min_icl = max_icl = current; diff --git a/include/charge_manager.h b/include/charge_manager.h index 64c8272886..df69bc196a 100644 --- a/include/charge_manager.h +++ b/include/charge_manager.h @@ -194,4 +194,13 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, */ int board_vbus_source_enabled(int port); +/** + * Get ramp start current. + * + * @param port PD port. + * @param supplier Identified CHARGE_SUPPLIER_*. + * @return ramp start current. + */ +int charge_manager_get_ramp_start_current(int port, int supplier); + #endif /* __CROS_EC_CHARGE_MANAGER_H */ diff --git a/test/charge_ramp.c b/test/charge_ramp.c index 33db036a59..a300c5e04f 100644 --- a/test/charge_ramp.c +++ b/test/charge_ramp.c @@ -14,6 +14,7 @@ #include "task.h" #include "test_util.h" #include "timer.h" +#include "usb_charge.h" #include "util.h" #define TASK_EVENT_OVERCURRENT (1 << 0) @@ -36,6 +37,11 @@ static int charge_limit_ma; /* Mock functions */ +int charge_manager_get_ramp_start_current(int port, int supplier) +{ + return USB_CHARGER_MIN_CURR_MA; +} + int board_is_ramp_allowed(int supplier) { /* Ramp for TEST4-TEST8 */ |