bq2598x: ryu: take into account hardware input current optimizer

Take profit of the hardware input current ramping/back-off integrated
in the BQ2589x charger by setting the current limits higher for BC1.2
USB modes and letting the hardware adjust to the actual charger
limitation depending on the VBUS voltage droop.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=smaug
BUG=chrome-os-partner:42045
TEST=Connect a Nexus 9 DCP charger to Smaug and see the input current
adjusted to 1650mA without brown-out, read back the value properly from
the AP:
$ ectool usbpdpower
Port 0: SNK Charger DCP 4958mV / 1650mA, max 5000mV / 1650mA / 8250mW

Change-Id: I348e5ee4980a5652f72f279ab4e3a7126583b093
Reviewed-on: https://chromium-review.googlesource.com/282584
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vincent Palatin
2015-06-29 14:33:22 -07:00
committed by ChromeOS Commit Bot
parent a11ffa6c93
commit cdef497a4e
6 changed files with 78 additions and 1 deletions

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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],

View File

@@ -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 */

View File

@@ -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

View File

@@ -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 */