summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-04-02 11:14:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-05 17:48:04 -0700
commita536bdb1cdec91963a813e5241b8c2bce16eb130 (patch)
treebe7627668e8c8a7063c86ebf3cfed041ddf53750 /driver
parent5aec786f4c698f264c868cef000d88b4d2e43100 (diff)
downloadchrome-ec-a536bdb1cdec91963a813e5241b8c2bce16eb130.tar.gz
charger: bd99955: Disable BC1.2 detection
bd99955 enables BC1.2 detection by default and auto-sets current limit based upon the detection results. This is undesirable because it races against our external current limit settings (eg. USB-C / PD detection). BUG=chrome-os-partner:51766 BRANCH=None TEST=Manual on kevin. Plug zinger 10 times, verify that battery charges at ~1500mA on each plug, except for cases where Zinger falls into reset / OC loop (a separate issue). Change-Id: I787b2434c30b89fe78bbe50666075c694bf64503 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/336970 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/bd99955.c64
-rw-r--r--driver/charger/bd99955.h5
2 files changed, 51 insertions, 18 deletions
diff --git a/driver/charger/bd99955.c b/driver/charger/bd99955.c
index 3563c4ff14..61dc4eaf31 100644
--- a/driver/charger/bd99955.c
+++ b/driver/charger/bd99955.c
@@ -10,6 +10,7 @@
#include "bd99955.h"
#include "charger.h"
#include "console.h"
+#include "hooks.h"
#include "i2c.h"
#include "task.h"
#include "util.h"
@@ -352,18 +353,46 @@ int charger_set_voltage(int voltage)
BD99955_BAT_CHG_COMMAND);
}
-int charger_post_init(void)
+static void bd99995_init(void)
{
- int rv;
+ int reg;
+ const struct battery_info *bi = battery_get_info();
- /*
- * TODO: Disable charger & re-enable to initialize it.
- */
- rv = charger_discharge_on_ac(1);
- if (rv)
- return rv;
+ /* Disable BC1.2 detection on VCC */
+ if (ch_raw_read16(BD99955_CMD_VCC_UCD_SET, &reg,
+ BD99955_EXTENDED_COMMAND))
+ return;
+ reg &= ~BD99955_CMD_UCD_SET_USBDETEN;
+ ch_raw_write16(BD99955_CMD_VCC_UCD_SET, reg,
+ BD99955_EXTENDED_COMMAND);
+
+ /* Disable BC1.2 detection on VBUS */
+ if (ch_raw_read16(BD99955_CMD_VBUS_UCD_SET, &reg,
+ BD99955_EXTENDED_COMMAND))
+ return;
+ reg &= ~BD99955_CMD_UCD_SET_USBDETEN;
+ ch_raw_write16(BD99955_CMD_VBUS_UCD_SET, reg,
+ BD99955_EXTENDED_COMMAND);
- return charger_discharge_on_ac(0);
+ /* Disable BC1.2 charge enable trigger */
+ if (ch_raw_read16(BD99955_CMD_CHGOP_SET1, &reg,
+ BD99955_EXTENDED_COMMAND))
+ return;
+ reg |= (BD99955_CMD_CHGOP_SET1_VCC_BC_DISEN |
+ BD99955_CMD_CHGOP_SET1_VBUS_BC_DISEN);
+ ch_raw_write16(BD99955_CMD_CHGOP_SET1, reg,
+ BD99955_EXTENDED_COMMAND);
+
+ /* Set battery OVP to 500 + maximum battery voltage */
+ ch_raw_write16(BD99955_CMD_VBATOVP_SET,
+ (bi->voltage_max + 500) & 0x7ff0,
+ BD99955_EXTENDED_COMMAND);
+}
+DECLARE_HOOK(HOOK_INIT, bd99995_init, HOOK_PRIO_DEFAULT);
+
+int charger_post_init(void)
+{
+ return EC_SUCCESS;
}
int charger_discharge_on_ac(int enable)
@@ -472,15 +501,14 @@ static int console_command_bd99955(int argc, char **argv)
char rw, *e;
enum bd99955_command cmd;
+ if (argc < 4)
+ return EC_ERROR_PARAM_COUNT;
+
rw = argv[1][0];
- if (rw == 'r') {
- if (argc < 4)
+ if (rw == 'w' && argc < 5)
return EC_ERROR_PARAM_COUNT;
- } else if (rw == 'w') {
- if (argc < 5)
- return EC_ERROR_PARAM_COUNT;
- } else
- return EC_ERROR_PARAM_COUNT;
+ else if (rw != 'w' && rw != 'r')
+ return EC_ERROR_PARAM1;
reg = strtoi(argv[2], &e, 16);
if (*e || reg < 0)
@@ -488,12 +516,12 @@ static int console_command_bd99955(int argc, char **argv)
cmd = strtoi(argv[3], &e, 0);
if (*e || cmd < 0)
- return EC_ERROR_INVAL;
+ return EC_ERROR_PARAM3;
if (argc == 5) {
val = strtoi(argv[4], &e, 16);
if (*e || val < 0)
- return EC_ERROR_INVAL;
+ return EC_ERROR_PARAM4;
}
if (rw == 'r')
diff --git a/driver/charger/bd99955.h b/driver/charger/bd99955.h
index 9b1da4baf2..aab249842c 100644
--- a/driver/charger/bd99955.h
+++ b/driver/charger/bd99955.h
@@ -80,6 +80,8 @@ enum bd99955_charge_port {
#define BD99955_CMD_VIN_CTRL_SET_VCC_EN (1 << 5)
#define BD99955_CMD_CHGOP_SET1 0x0B
+#define BD99955_CMD_CHGOP_SET1_VCC_BC_DISEN (1 << 11)
+#define BD99955_CMD_CHGOP_SET1_VBUS_BC_DISEN (1 << 10)
#define BD99955_CMD_CHGOP_SET2 0x0C
#define BD99955_CMD_CHGOP_SET2_BATT_LEARN (1 << 8)
#define BD99955_CMD_CHGOP_SET2_CHG_EN (1 << 7)
@@ -118,6 +120,9 @@ enum bd99955_charge_port {
#define BD99955_CMD_PMON_DACIN_VAL 0x26
#define BD99955_CMD_IOUT_DACIN_VAL 0x27
#define BD99955_CMD_VCC_UCD_SET 0x28
+/* Bits for both VCC_UDC_SET and VBUS_UCD_SET regs */
+#define BD99955_CMD_UCD_SET_BCSRETRY (1 << 12)
+#define BD99955_CMD_UCD_SET_USBDETEN (1 << 7)
#define BD99955_CMD_VCC_UCD_STATUS 0x29
#define BD99955_CMD_VCC_IDD_STATUS 0x2A
#define BD99955_CMD_VCC_UCD_FCTRL_SET 0x2B