summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2018-06-30 07:47:51 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-07-19 20:12:52 -0700
commitee00a00061937817e3e4f5f95d117f92e4e1721f (patch)
tree3387fdf4f4a0267fa4cd543b6ceb258e53b62592
parent76d6f012d342e9a60f7e53c85fb15e82aac6518b (diff)
downloadchrome-ec-ee00a00061937817e3e4f5f95d117f92e4e1721f.tar.gz
bq25703: Fix charge ramp issue
Follow the below charge ramp sequence for BQ25703. 1. Set InputVoltage register (0x0A) value to slightly below the adaptor voltage with full load specification. 2. Disable external ILIM_HIZ by setting ChargerOption2 (0x32) bit 7 to 0. 3. Enable ICO test by setting ChargeOption3 (0x34h) bit 11 to 1. 4. Set IIN_HOST (0x0F) register value to the maximum amount of input current limit the user would like to sink on VBUS. 5. Wait for approximately 2sec, and check the ChargeStatus register (0x20) bit 14 for ICO completion. 6. Read ADC_IIN register (0x2B) after ICO is done and write this value back to IIN_HOST (0x0F) BUG=b:80279932 BRANCH=none TEST=Manually tested on BIP. Used USB Charging Voltage Current Panel Meter. Current showed on the display is same as input current read by charger command. CDP: charger rating with 5A,1.5A are ramped to 2.4A,1.5A respectively. DCP: charger rating with 5A,2A,1A are ramped to 2.4A,2.2A,1A respectively. SDP: USB3.0 -> ramped to 850mA USB2.0 (Manually modified max current to 900mA) -> ramped to 750mA Change-Id: I15e01ae033aa25890c81a4836dae809be31d313d Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/1123679 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Scott Collyer <scollyer@chromium.org>
-rw-r--r--driver/charger/bq25703.c69
-rw-r--r--driver/charger/bq25703.h52
2 files changed, 90 insertions, 31 deletions
diff --git a/driver/charger/bq25703.c b/driver/charger/bq25703.c
index 55e90ee7e3..4d9fd2edcd 100644
--- a/driver/charger/bq25703.c
+++ b/driver/charger/bq25703.c
@@ -7,9 +7,11 @@
#include "battery_smart.h"
#include "bq25703.h"
+#include "charge_ramp.h"
#include "charger.h"
#include "common.h"
#include "console.h"
+#include "hooks.h"
#include "i2c.h"
#include "timer.h"
@@ -64,6 +66,7 @@ static inline int raw_write16(int offset, int value)
return i2c_write16(I2C_PORT_CHARGER, BQ25703_I2C_ADDR1, offset, value);
}
+#ifdef CONFIG_CHARGE_RAMP_HW
static int bq25703_get_low_power_mode(int *mode)
{
int rv;
@@ -98,6 +101,7 @@ static int bq25703_set_low_power_mode(int enable)
return EC_SUCCESS;
}
+#endif
/* Charger interfaces */
@@ -263,20 +267,64 @@ int charger_set_option(int option)
}
#ifdef CONFIG_CHARGE_RAMP_HW
+
+static void bq25703_chg_ramp_handle(void)
+{
+ int ramp_curr;
+
+ /*
+ * Once the charge ramp is stable write back the stable ramp
+ * current to input current register.
+ */
+ if (chg_ramp_is_stable()) {
+ ramp_curr = chg_ramp_get_current_limit();
+ if (ramp_curr && !charger_set_input_current(ramp_curr))
+ CPRINTF("stable ramp current=%d\n", ramp_curr);
+ }
+}
+DECLARE_DEFERRED(bq25703_chg_ramp_handle);
+
int charger_set_hw_ramp(int enable)
{
- int reg, rv;
+ int option3_reg, option2_reg, rv;
- rv = raw_read16(BQ25703_REG_CHARGE_OPTION_3, &reg);
+ rv = raw_read16(BQ25703_REG_CHARGE_OPTION_3, &option3_reg);
+ if (rv)
+ return rv;
+ rv = raw_read16(BQ25703_REG_CHARGE_OPTION_2, &option2_reg);
if (rv)
return rv;
- if (enable)
- reg |= BQ25703_CHARGE_OPTION_3_EN_ICO_MODE;
- else
- reg &= ~BQ25703_CHARGE_OPTION_3_EN_ICO_MODE;
-
- return raw_write16(BQ25703_REG_CHARGE_OPTION_3, reg);
+ if (enable) {
+ /* Set InputVoltage register to BC1.2 minimum ramp voltage */
+ rv = raw_write16(BQ25703_REG_INPUT_VOLTAGE,
+ BQ25703_BC12_MIN_VOLTAGE_MV);
+ if (rv)
+ return rv;
+
+ /* Enable ICO algorithm */
+ option3_reg |= BQ25703_CHARGE_OPTION_3_EN_ICO_MODE;
+
+ /* 0b: Input current limit is set by BQ25703_REG_IIN_HOST */
+ option2_reg &= ~BQ25703_CHARGE_OPTION_2_EN_EXTILIM;
+
+ /* Charge ramp may take up to 2s to settle down */
+ hook_call_deferred(&bq25703_chg_ramp_handle_data, (4 * SECOND));
+ } else {
+ /* Disable ICO algorithm */
+ option3_reg &= ~BQ25703_CHARGE_OPTION_3_EN_ICO_MODE;
+
+ /*
+ * 1b: Input current limit is set by the lower value of
+ * ILIM_HIZ pin and BQ25703_REG_IIN_HOST
+ */
+ option2_reg |= BQ25703_CHARGE_OPTION_2_EN_EXTILIM;
+ }
+
+ rv = raw_write16(BQ25703_REG_CHARGE_OPTION_2, option2_reg);
+ if (rv)
+ return rv;
+ return raw_write16(BQ25703_REG_CHARGE_OPTION_3, option3_reg);
}
int chg_ramp_is_stable(void)
@@ -289,11 +337,6 @@ int chg_ramp_is_stable(void)
return reg & BQ25703_CHARGE_STATUS_ICO_DONE;
}
-int chg_ramp_is_detected(void)
-{
- return 1;
-}
-
int chg_ramp_get_current_limit(void)
{
int reg;
diff --git a/driver/charger/bq25703.h b/driver/charger/bq25703.h
index db7e50df52..db2c246658 100644
--- a/driver/charger/bq25703.h
+++ b/driver/charger/bq25703.h
@@ -11,24 +11,58 @@
/* I2C Interface */
#define BQ25703_I2C_ADDR1 0xD6
+/*
+ * BC1.2 minimum voltage threshold for BQ25703.
+ * BC1.2 charging port output voltage range is 4.75V to 5.25V,
+ * BQ25703 Input Voltage Accuracy is -2% to +2% (-95mV to +95mV)
+ * 4750mV - 95mV => 4655mV - 3200 (offset reg 0x0A) => 1455mv
+ * 1455mv & 0x1FC0 = 1408 (data for register 0x0A)
+ */
+#define BQ25703_BC12_MIN_VOLTAGE_MV 1408
+
/* Registers */
+
+/* ChargeOption0 Register */
#define BQ25703_REG_CHARGE_OPTION_0 0x00
+#define BQ25703_CHARGE_OPTION_0_LOW_POWER_MODE (1 << 15)
+#define BQ25703_CHARGE_OPTION_0_EN_LEARN (1 << 5)
+#define BQ25703_CHARGE_OPTION_0_CHRG_INHIBIT (1 << 0)
+
#define BQ25703_REG_CHARGE_CURRENT 0x02
#define BQ25703_REG_MAX_CHARGE_VOLTAGE 0x04
#define BQ25703_REG_CHARGE_OPTION_1 0x30
+
+/* ChargeOption2 Register */
#define BQ25703_REG_CHARGE_OPTION_2 0x32
+#define BQ25703_CHARGE_OPTION_2_EN_EXTILIM (1 << 7)
+
+/* ChargeOption3 Register */
#define BQ25703_REG_CHARGE_OPTION_3 0x34
+#define BQ25703_CHARGE_OPTION_3_EN_ICO_MODE (1 << 11)
+
#define BQ25703_REG_PROCHOT_OPTION_0 0x36
#define BQ25703_REG_PROCHOT_OPTION_1 0x38
+
+/* ADCOption Register */
#define BQ25703_REG_ADC_OPTION 0x3A
+#define BQ25703_ADC_OPTION_ADC_START (1 << 14)
+#define BQ25703_ADC_OPTION_EN_ADC_IIN (1 << 4)
+
+/* ChargeStatus Register */
#define BQ25703_REG_CHARGER_STATUS 0x20
+#define BQ25703_CHARGE_STATUS_ICO_DONE (1 << 14)
+
#define BQ25703_REG_PROCHOT_STATUS 0x22
#define BQ25703_REG_IIN_DPM 0x25
#define BQ25703_REG_ADC_PSYS 0x26
#define BQ25703_REG_ADC_VBUS 0x27
#define BQ25703_REG_ADC_IBAT 0x28
#define BQ25703_REG_ADC_CMPIN 0x2A
+
+/* ADCIIN Register */
#define BQ25703_REG_ADC_IIN 0x2B
+#define BQ25703_ADC_IIN_STEP_MA 50
+
#define BQ25703_REG_ADC_VSYS_VBAT 0x2C
#define BQ25703_REG_OTG_VOLTAGE 0x06
#define BQ25703_REG_OTG_CURRENT 0x08
@@ -38,22 +72,4 @@
#define BQ25703_REG_MANUFACTURER_ID 0x2E
#define BQ25703_REG_DEVICE_ADDRESS 0x2F
-/* ChargeOption0 Register */
-#define BQ25703_CHARGE_OPTION_0_LOW_POWER_MODE (1 << 15)
-#define BQ25703_CHARGE_OPTION_0_EN_LEARN (1 << 5)
-#define BQ25703_CHARGE_OPTION_0_CHRG_INHIBIT (1 << 0)
-
-/* ChargeOption3 Register */
-#define BQ25703_CHARGE_OPTION_3_EN_ICO_MODE (1 << 11)
-
-/* ChargeStatus Register */
-#define BQ25703_CHARGE_STATUS_ICO_DONE (1 << 14)
-
-/* ADCOption Register */
-#define BQ25703_ADC_OPTION_ADC_START (1 << 14)
-#define BQ25703_ADC_OPTION_EN_ADC_IIN (1 << 4)
-
-/* ADCIIN Register */
-#define BQ25703_ADC_IIN_STEP_MA 50
-
#endif /* __CROS_EC_BQ25703_H */