diff --git a/board/ryu/board.c b/board/ryu/board.c index d7b3d2893d..11f7753ccd 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -415,6 +415,36 @@ void board_set_charge_limit(int charge_ma) CPRINTS("Failed to set input current limit for PD"); } +/** + * Return whether ramping is allowed for given supplier + */ +int board_is_ramp_allowed(int supplier) +{ + return supplier == CHARGE_SUPPLIER_BC12_DCP || + supplier == CHARGE_SUPPLIER_BC12_SDP || + supplier == CHARGE_SUPPLIER_BC12_CDP || + supplier == CHARGE_SUPPLIER_PROPRIETARY; +} + +/** + * Return the maximum allowed input current + */ +int board_get_ramp_current_limit(int supplier, int sup_curr) +{ + switch (supplier) { + case CHARGE_SUPPLIER_BC12_DCP: + return 2400; + case CHARGE_SUPPLIER_BC12_SDP: + return 1000; + case CHARGE_SUPPLIER_BC12_CDP: + return 2400; + case CHARGE_SUPPLIER_PROPRIETARY: + return sup_curr; + default: + return 500; + } +} + /* Send host event up to AP */ void pd_send_host_event(int mask) { diff --git a/board/ryu/board.h b/board/ryu/board.h index eb982ed44f..5ce4066fdf 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -21,6 +21,7 @@ /* Optional features */ #undef CONFIG_CMD_HASH #define CONFIG_CHARGE_MANAGER +#define CONFIG_CHARGE_RAMP_HW #define CONFIG_FORCE_CONSOLE_RESUME #define CONFIG_STM_HWTIMER32 #define CONFIG_USB_CHARGER diff --git a/common/charge_manager.c b/common/charge_manager.c index a231f0da9e..ed47c8812a 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -187,7 +187,7 @@ static void charge_manager_fill_power_info(int port, r->meas.current_max = 0; r->max_power = 0; } else { -#ifdef HAS_TASK_CHG_RAMP +#if defined(HAS_TASK_CHG_RAMP) || defined(CONFIG_CHARGE_RAMP_HW) /* Read ramped current if active charging port */ int use_ramp_current = (charge_port == port); #else @@ -456,6 +456,16 @@ static void charge_manager_refresh(void) } else { new_charge_current_uncapped = available_charge[new_supplier][new_port].current; +#ifdef CONFIG_CHARGE_RAMP_HW + /* + * Allow to set the maximum current value, so the hardware can + * know the range of acceptable current values for its ramping. + */ + if (board_is_ramp_allowed(new_supplier)) + new_charge_current_uncapped = + board_get_ramp_current_limit(new_supplier, + new_charge_current_uncapped); +#endif /* CONFIG_CHARGE_RAMP_HW */ /* Enforce port charge ceiling. */ if (charge_ceil[new_port] != CHARGE_CEIL_NONE) new_charge_current = MIN(charge_ceil[new_port], diff --git a/driver/charger/bq2589x.c b/driver/charger/bq2589x.c index e54f0d7a9e..2771924f1a 100644 --- a/driver/charger/bq2589x.c +++ b/driver/charger/bq2589x.c @@ -239,6 +239,35 @@ int charger_post_init(void) return EC_SUCCESS; } +/*****************************************************************************/ +/* Hardware current ramping (aka ICO: Input Current Optimizer) */ + +#ifdef CONFIG_CHARGE_RAMP_HW +int chg_ramp_is_stable(void) +{ + int val, rv; + + rv = bq2589x_read(BQ2589X_REG_ID, &val); + if (!rv && (val & BQ2589X_ID_ICO_OPTIMIZED)) + return 1; + else + return 0; +} + +int chg_ramp_is_detected(void) +{ + return 1; +} + +int chg_ramp_get_current_limit(void) +{ + int input_ma, rv; + + rv = bq2589x_read(BQ2589X_REG_ADC_INPUT_CURR, &input_ma); + + return rv ? -1 : 100 + (input_ma & 0x3f) * 50; +} +#endif /* CONFIG_CHARGE_RAMP_HW */ /*****************************************************************************/ /* Hooks */ diff --git a/driver/charger/bq2589x.h b/driver/charger/bq2589x.h index 771868a7cc..38d1f57b35 100644 --- a/driver/charger/bq2589x.h +++ b/driver/charger/bq2589x.h @@ -83,11 +83,15 @@ #define BQ2589X_BOOST_DEFAULT (BQ2589X_BOOST_LIM_DEFAULT |\ BQ2589X_BOOSTV_DEFAULT) +/* REG14: Device ID, reset and ICO status */ #define BQ2589X_DEVICE_ID_MASK 0x38 #define BQ25890_DEVICE_ID 0x18 #define BQ25892_DEVICE_ID 0x00 #define BQ25895_DEVICE_ID 0x38 +#define BQ2589X_ID_ICO_OPTIMIZED 0x40 + + /* Variant-specific configuration */ #if defined(CONFIG_CHARGER_BQ25890) #define BQ2589X_DEVICE_ID BQ25890_DEVICE_ID diff --git a/include/config.h b/include/config.h index 2699335996..05459bfb10 100644 --- a/include/config.h +++ b/include/config.h @@ -250,6 +250,9 @@ /* Compile input current ramping support */ #undef CONFIG_CHARGE_RAMP +/* The hardware has some input current ramping/back-off mechanism */ +#undef CONFIG_CHARGE_RAMP_HW + /*****************************************************************************/ /* Charger config */