diff options
author | Rong Chang <rongchang@chromium.org> | 2012-07-27 18:40:21 +0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-29 22:35:45 -0700 |
commit | 709f6d8b2e757884e847461a048bb2ad3527658e (patch) | |
tree | dd1d7cec9531b0577ca67d7aa6858f1d5cbbaba5 | |
parent | e533adccb782736d3e80697f068a24d78dc830b1 (diff) | |
download | chrome-ec-709f6d8b2e757884e847461a048bb2ad3527658e.tar.gz |
Set TPSCHROME temp range configuration
Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:11627
TEST=manual
Check pmu registers under uart console: "pmu"
TPSCHROME version < 3:
reg(7) == 0xbd
reg(8) == 0xfd
TPSCHROME version >= 3:
reg(7) == 0xbf
reg(8) == 0xff
Change-Id: Ifeda54aa142b362aa224575c55220913b0ee7436
Reviewed-on: https://gerrit.chromium.org/gerrit/28587
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r-- | board/snow/board.c | 52 | ||||
-rw-r--r-- | common/pmu_tps65090.c | 86 | ||||
-rw-r--r-- | include/pmu_tpschrome.h | 62 |
3 files changed, 178 insertions, 22 deletions
diff --git a/board/snow/board.c b/board/snow/board.c index ad951b4c37..d9a3d0cc20 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -261,30 +261,38 @@ void board_i2c_release(int port) */ void board_pmu_init(void) { - /** - * Explanation: - * - * 1. Timeout is by default 2hrs. This increases to 3hrs. At 1.8A - * charging, this should be long enough for the 4000mA-hr battery, - * assuming it spends about 30mins in the CC mode, but doesn't - * allow for much margin. - * 2. Change temp range T23 (0C-40C), to 1.8A max charge. This is - * currently set to 2.4A which is higher than the recommend charge - * current of 2A. - * 3. Change temp range T34 (40C-60C) to 1.8A max charge, and change - * charge voltage to 8.6V. This is currently set to 1.2A/8.49V. - * Because the NTC is on the board, this is quickly reached so - * slow charging may occur. The battery is rated for 2A charging - * up to 60C. - * 4. Set NOITERM bit. On a fully dead battery, the pack goes into a - * mode where it only lets in a very small current via there is a - * different charge path. This fools the charger into thinking - * the current vs voltage is bad. This bit corrects this. + int ver; + + /* + * Set fast charging timeout to 3hr. + * Enable gpio charge_en control. */ pmu_write(0x04, 0x06); - pmu_write(0x07, 0xbd); - pmu_write(0x08, 0xfd); - pmu_write(0x09, 0xe0); + + /* Set NOITERM bit */ + pmu_low_current_charging(1); + + /* + * High temperature charging + * termination voltage: 2.1V + * termination current: 100% + */ + pmu_set_term_voltage(RANGE_T34, TERM_V2100); + pmu_set_term_current(RANGE_T34, TERM_I1000); + /* + * Standard temperature charging + * termination voltage: 2.1V + * termination current: 100% + */ + pmu_set_term_voltage(RANGE_T23, TERM_V2100); + pmu_set_term_current(RANGE_T23, TERM_I1000); + + /* Workaround init values before ES3 */ + if (pmu_version(&ver) || ver < 3) { + /* Termination current: 75% */ + pmu_set_term_current(RANGE_T34, TERM_I0750); + pmu_set_term_current(RANGE_T23, TERM_I0750); + } } #endif /* CONFIG_BOARD_PMU_INIT */ diff --git a/common/pmu_tps65090.c b/common/pmu_tps65090.c index 3198e1eae4..ba75d82235 100644 --- a/common/pmu_tps65090.c +++ b/common/pmu_tps65090.c @@ -30,10 +30,18 @@ #define CG_CTRL5 0x09 #define CG_STATUS1 0x0a #define CG_STATUS2 0x0b +#define TPSCHROME_VER 0x19 /* Charger control */ #define CG_CTRL0_EN 1 +/* Charger termination voltage/current */ +#define CG_VSET_SHIFT 3 +#define CG_VSET_MASK (3 << CG_VSET_SHIFT) +#define CG_ISET_SHIFT 0 +#define CG_ISET_MASK (7 << CG_ISET_SHIFT) +#define CG_NOITERM (1 << 5) + /* IRQ events */ #define EVENT_VACG (1 << 1) #define EVENT_VBATG (1 << 3) @@ -84,6 +92,16 @@ int pmu_write(int reg, int value) return i2c_write8(I2C_PORT_CHARGER, TPS65090_I2C_ADDR, reg, value); } +/** + * Read tpschrome version + * + * @param version output value of tpschrome version + */ +int pmu_version(int *version) +{ + return pmu_read(TPSCHROME_VER, version); +} + int pmu_is_charger_alarm(void) { int status; @@ -129,6 +147,74 @@ int pmu_enable_charger(int enable) (reg & ~CG_CTRL0)); } +/** + * Set termination current for temperature ranges + * + * @param range T01 T12 T23 T34 T40 + * @param current enum termination current, I0250 == 25.0%: + * I0000 I0250 I0375 I0500 I0625 I0750 I0875 I1000 + */ +int pmu_set_term_current(enum TPS_TEMPERATURE_RANGE range, + enum TPS_TERMINATION_CURRENT current) +{ + int rv; + int reg_val; + + rv = pmu_read(CG_CTRL1 + range, ®_val); + if (rv) + return rv; + + reg_val &= ~CG_ISET_MASK; + reg_val |= current << CG_ISET_SHIFT; + + return pmu_write(CG_CTRL1 + range, reg_val); +} + +/** + * Set termination voltage for temperature ranges + * + * @param range T01 T12 T23 T34 T40 + * @param voltage enum termination voltage, V2050 == 2.05V: + * V2000 V2050 V2075 V2100 + */ +int pmu_set_term_voltage(enum TPS_TEMPERATURE_RANGE range, + enum TPS_TERMINATION_VOLTAGE voltage) +{ + int rv; + int reg_val; + + rv = pmu_read(CG_CTRL1 + range, ®_val); + if (rv) + return rv; + + reg_val &= ~CG_VSET_MASK; + reg_val |= voltage << CG_VSET_SHIFT; + + return pmu_write(CG_CTRL1 + range, reg_val); +} + +/** + * Enable low current charging + * + * @param enable enable/disable low current charging + */ +int pmu_low_current_charging(int enable) +{ + int rv; + int reg_val; + + rv = pmu_read(CG_CTRL5, ®_val); + if (rv) + return rv; + + if (enable) + reg_val |= CG_NOITERM; + else + reg_val &= ~CG_NOITERM; + + return pmu_write(CG_CTRL5, reg_val); +} + void pmu_init(void) { #ifdef CONFIG_PMU_BOARD_INIT diff --git a/include/pmu_tpschrome.h b/include/pmu_tpschrome.h index 9d8e90890b..eb4eb71b0c 100644 --- a/include/pmu_tpschrome.h +++ b/include/pmu_tpschrome.h @@ -8,6 +8,34 @@ #ifndef __CROS_EC_TPSCHROME_H #define __CROS_EC_TPSCHROME_H +enum TPS_TEMPERATURE_RANGE { + RANGE_T01, + RANGE_T12, /* low charging temperature range */ + RANGE_T23, /* standard charging temperature range */ + RANGE_T34, /* high charging temperature range */ + RANGE_T40, +}; + +/* Termination voltage */ +enum TPS_TERMINATION_VOLTAGE { + TERM_V2000, /* 2.000 V */ + TERM_V2050, /* 2.050 V */ + TERM_V2075, /* 2.075 V */ + TERM_V2100, /* 2.100 V */ +}; + +/* Termination current */ +enum TPS_TERMINATION_CURRENT { + TERM_I0000, /* 0 % */ + TERM_I0250, /* 25 % */ + TERM_I0375, /* 37.5 % */ + TERM_I0500, /* 50 % */ + TERM_I0625, /* 62.5 % */ + TERM_I0750, /* 75 % */ + TERM_I0875, /* 87.5 % */ + TERM_I1000, /* 100 % */ +}; + #define FET_BACKLIGHT 1 #define FET_LCD_PANEL 6 @@ -30,6 +58,13 @@ int pmu_read(int reg, int *value); int pmu_write(int reg, int value); /** + * Read tpschrome version + * + * @param version output tpschrome version info + */ +int pmu_version(int *version); + +/** * Check pmu charger alarm * * @return 0 if there's no charging alarm or pmu access failed @@ -65,6 +100,33 @@ int pmu_enable_fet(int fet_id, int enable, int *power_good); int pmu_enable_charger(int enable); /** + * Set termination current for temperature ranges + * + * @param range T01 T12 T23 T34 T40 + * @param current enum termination current, I0250 == 25.0%: + * I0000 I0250 I0375 I0500 I0625 I0750 I0875 I1000 + */ +int pmu_set_term_current(enum TPS_TEMPERATURE_RANGE range, + enum TPS_TERMINATION_CURRENT current); + +/** + * Set termination voltage for temperature ranges + * + * @param range T01 T12 T23 T34 T40 + * @param voltage enum termination voltage, V2050 == 2.05V: + * V2000 V2050 V2075 V2100 + */ +int pmu_set_term_voltage(enum TPS_TEMPERATURE_RANGE range, + enum TPS_TERMINATION_VOLTAGE voltage); + +/** + * Enable low current charging + * + * @param enable enable/disable low current charging + */ +int pmu_low_current_charging(int enable); + +/** * * Initialize pmu * */ void pmu_init(void); |