summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-11-03 18:26:26 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-09 12:49:30 -0800
commit75f740fa231703b7000fdfbee8f7225214c1a7ff (patch)
tree9a7053d0bab3b07c698e0fb93633ed17d4bc240d
parent92a65427d3881f3d2ec64b1ab540fb5a4aa0ce93 (diff)
downloadchrome-ec-75f740fa231703b7000fdfbee8f7225214c1a7ff.tar.gz
glados: isl9237: add HW charge ramping
Add HW charge ramping option and enable on glados. Modify charge_manager to enable/disable HW charge ramping when option is defined. Unfortunately, the isl9237 doesn't have a way to determine what the input current limit has settled on, so the EC will always report the max input current for that supplier. BUG=chrome-os-partner:47335 BRANCH=none TEST=plug in CDP, SDP, DCP, type-C, and PD charger. Make sure we ramp to a reasonable value for the correct suppliers. Make sure we don't ramp for type-C and PD chargers. Change-Id: Ib541fa0be48d8f4d261c71b853b0ee72b2adbf6b Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311301 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/glados/board.c34
-rw-r--r--board/glados/board.h1
-rw-r--r--common/charge_manager.c5
-rw-r--r--driver/charger/bq2589x.c17
-rw-r--r--driver/charger/bq2589x.h1
-rw-r--r--driver/charger/isl9237.c63
-rw-r--r--include/charger.h1
7 files changed, 120 insertions, 2 deletions
diff --git a/board/glados/board.c b/board/glados/board.c
index 299e04fbae..2681c49f94 100644
--- a/board/glados/board.c
+++ b/board/glados/board.c
@@ -321,6 +321,40 @@ void board_set_charge_limit(int charge_ma)
CONFIG_CHARGER_INPUT_CURRENT));
}
+/**
+ * Return whether ramping is allowed for given supplier
+ */
+int board_is_ramp_allowed(int supplier)
+{
+ /* Don't allow ramping in RO when write protected */
+ if (system_get_image_copy() != SYSTEM_IMAGE_RW
+ && system_is_locked())
+ return 0;
+ else
+ 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 2000;
+ case CHARGE_SUPPLIER_BC12_SDP:
+ return 1000;
+ case CHARGE_SUPPLIER_BC12_CDP:
+ case CHARGE_SUPPLIER_PROPRIETARY:
+ return sup_curr;
+ default:
+ return 500;
+ }
+}
+
/* Enable or disable input devices, based upon chipset state and tablet mode */
static void enable_input_devices(void)
{
diff --git a/board/glados/board.h b/board/glados/board.h
index 0d4063c2dd..ff9f817dca 100644
--- a/board/glados/board.h
+++ b/board/glados/board.h
@@ -20,6 +20,7 @@
#define CONFIG_BOARD_VERSION
#define CONFIG_BUTTON_COUNT 2
#define CONFIG_CHARGE_MANAGER
+#define CONFIG_CHARGE_RAMP_HW
#define CONFIG_CHARGER
#define CONFIG_CHARGER_V2
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 2dec5210b6..392cd74040 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -7,6 +7,7 @@
#include "battery.h"
#include "charge_manager.h"
#include "charge_ramp.h"
+#include "charger.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
@@ -511,6 +512,10 @@ static void charge_manager_refresh(void)
new_port, new_supplier, new_charge_current,
registration_time[new_port]);
#else
+#ifdef CONFIG_CHARGE_RAMP_HW
+ /* Enable or disable charge ramp */
+ charger_set_hw_ramp(board_is_ramp_allowed(new_supplier));
+#endif
board_set_charge_limit(new_charge_current);
#endif
CPRINTS("CL: p%d s%d i%d v%d", new_port, new_supplier,
diff --git a/driver/charger/bq2589x.c b/driver/charger/bq2589x.c
index dc4d768275..e36007f16a 100644
--- a/driver/charger/bq2589x.c
+++ b/driver/charger/bq2589x.c
@@ -259,6 +259,23 @@ int charger_post_init(void)
/* Hardware current ramping (aka ICO: Input Current Optimizer) */
#ifdef CONFIG_CHARGE_RAMP_HW
+int charger_set_hw_ramp(int enable)
+{
+ int val, rv;
+
+ rv = i2c_read8(I2C_PORT_CHARGER, BQ2589X_ADDR, BQ2589X_REG_CFG1, &val);
+ if (rv)
+ return rv;
+
+ if (enable)
+ val |= BQ2589X_CFG1_ICO_EN;
+ else
+ val &= ~BQ2589X_CFG1_ICO_EN;
+
+ return i2c_write8(I2C_PORT_CHARGER, BQ2589X_ADDR, BQ2589X_REG_CFG1,
+ val);
+}
+
int chg_ramp_is_stable(void)
{
int val, rv;
diff --git a/driver/charger/bq2589x.h b/driver/charger/bq2589x.h
index 970517f116..ed49aeb661 100644
--- a/driver/charger/bq2589x.h
+++ b/driver/charger/bq2589x.h
@@ -37,6 +37,7 @@
/* REG02 : first configuration register bit definitions */
#define BQ2589X_CFG1_CONV_START (1<<7)
+#define BQ2589X_CFG1_ICO_EN (1<<4)
#define BQ2589X_CFG1_AUTO_DPDM_EN (1<<0)
/* REG03 : second configuration register bit definitions */
diff --git a/driver/charger/isl9237.c b/driver/charger/isl9237.c
index 0afb598dda..2d8c78190b 100644
--- a/driver/charger/isl9237.c
+++ b/driver/charger/isl9237.c
@@ -216,15 +216,30 @@ int charger_set_voltage(int voltage)
int charger_post_init(void)
{
+ int rv, reg;
+
#ifdef CONFIG_TRICKLE_CHARGING
- int rv;
const struct battery_info *bi = battery_get_info();
rv = raw_write16(ISL9237_REG_SYS_VOLTAGE_MIN, bi->voltage_min);
if (rv)
return rv;
#endif
- return EC_SUCCESS;
+
+ rv = charger_get_option(&reg);
+ if (rv)
+ return rv;
+
+#ifdef CONFIG_CHARGE_RAMP_HW
+ /* Set input voltage regulation reference voltage for charge ramp */
+ reg &= ~ISL9237_C0_VREG_REF_MASK;
+ reg |= ISL9237_C0_VREG_REF_4200;
+#else
+ /* Disable voltage regulation loop to disable charge ramp */
+ reg |= ISL9237_C0_DISABLE_VREG;
+#endif
+
+ return charger_set_option(reg);
}
int charger_discharge_on_ac(int enable)
@@ -245,6 +260,50 @@ int charger_discharge_on_ac(int enable)
return raw_write16(ISL9237_REG_CONTROL1, control1);
}
+/*****************************************************************************/
+/* Hardware current ramping */
+
+#ifdef CONFIG_CHARGE_RAMP_HW
+int charger_set_hw_ramp(int enable)
+{
+ int rv, reg;
+
+ rv = charger_get_option(&reg);
+ if (rv)
+ return rv;
+
+ /* HW ramp is controlled by input voltage regulation reference bits */
+ if (enable)
+ reg &= ~ISL9237_C0_DISABLE_VREG;
+ else
+ reg |= ISL9237_C0_DISABLE_VREG;
+
+ return charger_set_option(reg);
+}
+
+int chg_ramp_is_stable(void)
+{
+ /*
+ * Since ISL cannot read the current limit that the ramp has settled
+ * on, then we can never consider the ramp stable, because we never
+ * know what the stable limit is.
+ */
+ return 0;
+}
+
+int chg_ramp_is_detected(void)
+{
+ return 1;
+}
+
+int chg_ramp_get_current_limit(void)
+{
+ /* ISL doesn't have a way to get this info */
+ return 0;
+}
+#endif /* CONFIG_CHARGE_RAMP_HW */
+
+
#ifdef CONFIG_CHARGER_PSYS
static void charger_enable_psys(void)
{
diff --git a/include/charger.h b/include/charger.h
index c73f0b6d33..70d0ff7543 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -111,6 +111,7 @@ int charger_manufacturer_id(int *id);
int charger_device_id(int *id);
int charger_get_option(int *option);
int charger_set_option(int option);
+int charger_set_hw_ramp(int enable);
/* Print all charger info for debugging purposes */
void print_charger_debug(void);