summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */