summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2015-06-29 14:33:22 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-01 02:15:19 +0000
commitcdef497a4e50dc05818e7b327997ecb2de10c206 (patch)
treecbbb6b49dc29b02490c80925dc3e7bfe31b8c741
parenta11ffa6c93e28f536cf97eb29e613399d25baf63 (diff)
downloadchrome-ec-cdef497a4e50dc05818e7b327997ecb2de10c206.tar.gz
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>
-rw-r--r--board/ryu/board.c30
-rw-r--r--board/ryu/board.h1
-rw-r--r--common/charge_manager.c12
-rw-r--r--driver/charger/bq2589x.c29
-rw-r--r--driver/charger/bq2589x.h4
-rw-r--r--include/config.h3
6 files changed, 78 insertions, 1 deletions
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 */