diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2015-04-16 11:12:01 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-04-21 00:18:50 +0000 |
commit | 94baa433bcaeff9dcc0c25d3c19f01ecef485b1a (patch) | |
tree | bd57921026a9319d5aff8ab5ea661be802b852cd | |
parent | e4f8b16a62fcecfd1bcb3007143f4c6071db84aa (diff) | |
download | chrome-ec-stabilize-6996.B.tar.gz |
bq2589x: update driverstabilize-6996.B
Update the BQ2589x charger driver to configure properly the boost
used as a VBUS 5V source.
Define the bits used for I2C registers configuration.
Return success in unused charger callbacks to avoid blocking the
charge state machine.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=chrome-os-partner:38603
TEST=On Ryu P4 reworked with BQ25892, plug a C-A receptacle adapter and
see the 5V VBUS coming up, un-plug it and see VBUS going away,
try several PD/type-C charger and check the selected current limit.
Change-Id: I24b832b6d130ff6dfda1ce47f5e445d65279fa7d
Reviewed-on: https://chromium-review.googlesource.com/266063
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-- | driver/charger/bq2589x.c | 33 | ||||
-rw-r--r-- | driver/charger/bq2589x.h | 27 | ||||
-rw-r--r-- | include/config.h | 7 |
3 files changed, 58 insertions, 9 deletions
diff --git a/driver/charger/bq2589x.c b/driver/charger/bq2589x.c index 3e9e4bfd36..9614d4ce26 100644 --- a/driver/charger/bq2589x.c +++ b/driver/charger/bq2589x.c @@ -19,6 +19,11 @@ #define CPUTS(outstr) cputs(CC_CHARGER, outstr) #define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) +/* 5V Boost settings */ +#ifndef CONFIG_CHARGER_BQ2589X_BOOST +#define CONFIG_CHARGER_BQ2589X_BOOST BQ2589X_BOOST_DEFAULT +#endif + /* Charger information */ static const struct charger_info bq2589x_charger_info = { .name = "bq2589x", @@ -50,7 +55,7 @@ static int bq2589x_watchdog_reset(void) rv = bq2589x_read(BQ2589X_REG_CFG2, &val); if (rv) return rv; - val |= (1 << 6); + val |= BQ2589X_CFG2_WD_RST; return bq2589x_write(BQ2589X_REG_CFG2, val); } @@ -73,7 +78,8 @@ int charger_enable_otg_power(int enabled) rv = bq2589x_read(BQ2589X_REG_CFG2, &val); if (rv) return rv; - val = (val & ~0x30) | (enabled ? 0x20 : 0x10); + val = (val & ~(BQ2589X_CFG2_CHG_CONFIG | BQ2589X_CFG2_OTG_CONFIG)) + | (enabled ? BQ2589X_CFG2_OTG_CONFIG : BQ2589X_CFG2_CHG_CONFIG); return bq2589x_write(BQ2589X_REG_CFG2, val); } @@ -126,12 +132,15 @@ int charger_device_id(int *id) int charger_get_option(int *option) { - return EC_ERROR_UNIMPLEMENTED; + /* Ignored: does not exist */ + *option = 0; + return EC_SUCCESS; } int charger_set_option(int option) { - return EC_ERROR_UNIMPLEMENTED; + /* Ignored: does not exist */ + return EC_SUCCESS; } const struct charger_info *charger_get_info(void) @@ -141,12 +150,14 @@ const struct charger_info *charger_get_info(void) int charger_get_status(int *status) { - return EC_ERROR_UNIMPLEMENTED; + /* TODO(crosbug.com/p/38603) implement using REG0C value */ + *status = 0; + return EC_SUCCESS; } int charger_set_mode(int mode) { - return EC_ERROR_UNIMPLEMENTED; + return EC_SUCCESS; } int charger_get_current(int *current) @@ -209,10 +220,11 @@ int charger_post_init(void) { #ifdef CONFIG_CHARGER_ILIM_PIN_DISABLED int val, rv; + /* Ignore ILIM pin value */ rv = bq2589x_read(BQ2589X_REG_INPUT_CURR, &val); if (rv) return rv; - val &= ~0x40; + val &= ~BQ2589X_INPUT_CURR_EN_ILIM; rv = bq2589x_write(BQ2589X_REG_INPUT_CURR, val); if (rv) return rv; @@ -253,6 +265,9 @@ static void bq2589x_init(void) if (bq2589x_watchdog_reset()) return; + if (bq2589x_write(BQ2589X_REG_BOOST_MODE, CONFIG_CHARGER_BQ2589X_BOOST)) + return; + CPRINTF("BQ2589%c initialized\n", BQ2589X_DEVICE_ID == BQ25890_DEVICE_ID ? '0' : (BQ2589X_DEVICE_ID == BQ25895_DEVICE_ID ? '5' : '2')); @@ -271,10 +286,10 @@ static int command_bq2589x(int argc, char **argv) /* Trigger one ADC conversion */ bq2589x_read(BQ2589X_REG_CFG1, &value); - bq2589x_write(BQ2589X_REG_CFG1, value | 0x80); + bq2589x_write(BQ2589X_REG_CFG1, value | BQ2589X_CFG1_CONV_START); do { bq2589x_read(BQ2589X_REG_CFG1, &value); - } while (value & 0x80); /* Wait for End of Conversion */ + } while (value & BQ2589X_CFG1_CONV_START); /* Wait for End of Conv. */ bq2589x_read(BQ2589X_REG_ADC_BATT_VOLT, &batt_mv); bq2589x_read(BQ2589X_REG_ADC_SYS_VOLT, &sys_mv); diff --git a/driver/charger/bq2589x.h b/driver/charger/bq2589x.h index cd74404b79..b7959238e0 100644 --- a/driver/charger/bq2589x.h +++ b/driver/charger/bq2589x.h @@ -31,6 +31,33 @@ #define BQ2589X_REG_ADC_INPUT_CURR 0x13 /* Read-only */ #define BQ2589X_REG_ID 0x14 +/* REG00 : input current register bit definitions */ +#define BQ2589X_INPUT_CURR_EN_ILIM (1<<6) + +/* REG02 : first configuration register bit definitions */ +#define BQ2589X_CFG1_CONV_START (1<<7) +#define BQ2589X_CFG1_AUTO_DPDM_EN (1<<0) + +/* REG03 : second configuration register bit definitions */ +#define BQ2589X_CFG2_CHG_CONFIG (1<<4) +#define BQ2589X_CFG2_OTG_CONFIG (1<<5) +#define BQ2589X_CFG2_WD_RST (1<<6) + +/* 5V VBUS Boost settings */ +#define BQ2589X_BOOSTV_MV(mv) (((((mv) - 4550)/64) & 0xF) << 4) +#define BQ2589X_BOOSTV_DEFAULT BQ2589X_BOOSTV_MV(4998) +#define BQ2589X_BOOST_LIM_500MA 0x00 +#define BQ2589X_BOOST_LIM_750MA 0x01 +#define BQ2589X_BOOST_LIM_1200MA 0x02 +#define BQ2589X_BOOST_LIM_1400MA 0x03 +#define BQ2589X_BOOST_LIM_1650MA 0x04 +#define BQ2589X_BOOST_LIM_1875MA 0x05 +#define BQ2589X_BOOST_LIM_2150MA 0x06 +#define BQ2589X_BOOST_LIM_2450MA 0x07 +#define BQ2589X_BOOST_LIM_DEFAULT BQ2589X_BOOST_LIM_1400MA +#define BQ2589X_BOOST_DEFAULT (BQ2589X_BOOST_LIM_DEFAULT |\ + BQ2589X_BOOSTV_DEFAULT) + #define BQ2589X_DEVICE_ID_MASK 0x38 #define BQ25890_DEVICE_ID 0x18 #define BQ25892_DEVICE_ID 0x00 diff --git a/include/config.h b/include/config.h index 6cc5687ea8..cb6be599a9 100644 --- a/include/config.h +++ b/include/config.h @@ -249,6 +249,13 @@ #undef CONFIG_CHARGER_TPS65090 /* Note: does not use CONFIG_CHARGER */ /* + * BQ2589x 5V boost current limit and voltage. + * Should be the combination of BQ2589X_BOOSTV_MV(voltage) and + * BQ2589X_BOOST_LIM_xxxMA. + */ +#undef CONFIG_CHARGER_BQ2589X_BOOST + +/* * Board specific charging current limit, in mA. If defined, the charge state * machine will not allow the battery to request more current than this. */ |