summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2016-12-20 13:53:44 +0100
committerchrome-bot <chrome-bot@chromium.org>2017-01-05 18:39:58 -0800
commitb1101b8ed66f751c1a66108357c897677e582ccb (patch)
tree383ac5521c6d770cf00bba177063c47fd82227d8
parent0c7b7f222c59726edca80b1a01f8f217cc5cfcf7 (diff)
downloadchrome-ec-b1101b8ed66f751c1a66108357c897677e582ccb.tar.gz
charger: isl923x: Add support for ISL9238
ISL9237 and ISL9238 are almost identical, with few register changes, let's make the driver generic, to support both chargers. BRANCH=none BUG=chrome-os-partner:61166 TEST=make buildall -j Change-Id: I029894dd62ab7e45897d877289707ee8c1ff1d09 Reviewed-on: https://chromium-review.googlesource.com/422197 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r--driver/build.mk3
-rw-r--r--driver/charger/isl9237.h248
-rw-r--r--driver/charger/isl923x.c (renamed from driver/charger/isl9237.c)114
-rw-r--r--driver/charger/isl923x.h264
-rw-r--r--include/config.h1
5 files changed, 330 insertions, 300 deletions
diff --git a/driver/build.mk b/driver/build.mk
index aab87ee035..32da5f9686 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -47,7 +47,8 @@ driver-$(CONFIG_CHARGER_BQ24773)+=charger/bq24773.o
driver-$(CONFIG_CHARGER_BQ25890)+=charger/bq2589x.o
driver-$(CONFIG_CHARGER_BQ25892)+=charger/bq2589x.o
driver-$(CONFIG_CHARGER_BQ25895)+=charger/bq2589x.o
-driver-$(CONFIG_CHARGER_ISL9237)+=charger/isl9237.o
+driver-$(CONFIG_CHARGER_ISL9237)+=charger/isl923x.o
+driver-$(CONFIG_CHARGER_ISL9238)+=charger/isl923x.o
# I/O expander
driver-$(CONFIG_IO_EXPANDER_PCA9534)+=ioexpander_pca9534.o
diff --git a/driver/charger/isl9237.h b/driver/charger/isl9237.h
deleted file mode 100644
index 27a3bab377..0000000000
--- a/driver/charger/isl9237.h
+++ /dev/null
@@ -1,248 +0,0 @@
-/* Copyright 2015 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Intersil ISL-9237 battery charger driver.
- */
-
-#ifndef __CROS_EC_ISL9237_H
-#define __CROS_EC_ISL9237_H
-
-#define ISL9237_ADDR 0x12 /* 7bit address 0001001 */
-
-/* Registers */
-#define ISL9237_REG_CHG_CURRENT 0x14
-#define ISL9237_REG_ADAPTER_CURRENT1 0x3f
-#define ISL9237_REG_ADAPTER_CURRENT2 0x3b
-#define ISL9237_REG_SYS_VOLTAGE_MAX 0x15
-#define ISL9237_REG_SYS_VOLTAGE_MIN 0x3e
-#define ISL9237_REG_PROCHOT_AC 0x47
-#define ISL9237_REG_PROCHOT_DC 0x48
-#define ISL9237_REG_T1_T2 0x38
-#define ISL9237_REG_CONTROL1 0x3c
-#define ISL9237_REG_CONTROL2 0x3d
-#define ISL9237_REG_INFO 0x3a
-#define ISL9237_REG_OTG_VOLTAGE 0x49
-#define ISL9237_REG_OTG_CURRENT 0x4a
-#define ISL9237_REG_MANUFACTURER_ID 0xfe
-#define ISL9237_REG_DEVICE_ID 0xff
-#define ISL9237_REG_CONTROL0 0x39
-
-/* Sense resistor default values in mOhm */
-#define ISL9237_DEFAULT_SENSE_RESISTOR_AC 20
-#define ISL9237_DEFAULT_SENSE_RESISTOR 10
-
-/* Maximum charging current register value */
-#define ISL9237_CURRENT_REG_MAX 0x17c0 /* bit<12:2> 10111110000 */
-
-/* 2-level adpater current limit duration T1 & T2 in micro seconds */
-#define ISL9237_T1_10000 0x00
-#define ISL9237_T1_20000 0x01
-#define ISL9237_T1_15000 0x02
-#define ISL9237_T1_5000 0x03
-#define ISL9237_T1_1000 0x04
-#define ISL9237_T1_500 0x05
-#define ISL9237_T1_100 0x06
-#define ISL9237_T1_0 0x07
-#define ISL9237_T2_10 (0x00 << 8)
-#define ISL9237_T2_100 (0x01 << 8)
-#define ISL9237_T2_500 (0x02 << 8)
-#define ISL9237_T2_1000 (0x03 << 8)
-#define ISL9237_T2_300 (0x04 << 8)
-#define ISL9237_T2_750 (0x05 << 8)
-#define ISL9237_T2_2000 (0x06 << 8)
-#define ISL9237_T2_10000 (0x07 << 8)
-
-#define ISL9237_SYS_VOLTAGE_REG_MAX 13824
-#define ISL9237_SYS_VOLTAGE_REG_MIN 2048
-
-/* PROCHOT# debounce time and duration time in micro seconds */
-#define ISL9237_PROCHOT_DURATION_10000 (0 << 6)
-#define ISL9237_PROCHOT_DURATION_20000 (1 << 6)
-#define ISL9237_PROCHOT_DURATION_15000 (2 << 6)
-#define ISL9237_PROCHOT_DURATION_5000 (3 << 6)
-#define ISL9237_PROCHOT_DURATION_1000 (4 << 6)
-#define ISL9237_PROCHOT_DURATION_500 (5 << 6)
-#define ISL9237_PROCHOT_DURATION_100000 (6 << 6)
-#define ISL9237_PROCHOT_DURATION_0 (7 << 6)
-#define ISL9237_PROCHOT_DURATION_MASK (7 << 6)
-
-#define ISL9237_PROCHOT_DEBOUNCE_10 (0 << 9)
-#define ISL9237_PROCHOT_DEBOUNCE_100 (1 << 9)
-#define ISL9237_PROCHOT_DEBOUNCE_500 (2 << 9)
-#define ISL9237_PROCHOT_DEBOUNCE_1000 (3 << 9)
-#define ISL9237_PROCHOT_DEBOUNCE_MASK (3 << 9)
-
-/* Maximum PROCHOT register value */
-#define ISL9237_PROCHOT_AC_REG_MAX 6400
-#define ISL9237_PROCHOT_DC_REG_MAX 12800
-
-/* Control0: adapter voltage regulation reference */
-#define ISL9237_C0_VREG_REF_3900 0
-#define ISL9237_C0_VREG_REF_4200 1
-#define ISL9237_C0_VREG_REF_4500 2
-#define ISL9237_C0_VREG_REF_4800 3
-#define ISL9237_C0_VREG_REF_MASK 0x03
-
-/* Control0: disable adapter voltaqe regulation */
-#define ISL9237_C0_DISABLE_VREG (1 << 2)
-
-/* Control0: battery DCHOT reference for RS2 == 20mOhm */
-#define ISL9237_C0_DCHOT_6A (0 << 3)
-#define ISL9237_C0_DCHOT_5A (1 << 3)
-#define ISL9237_C0_DCHOT_4A (2 << 3)
-#define ISL9237_C0_DCHOT_3A (3 << 3)
-#define ISL9237_C0_DCHOT_MASK (3 << 3)
-
-/* Control1: general purpose comparator debounce time in micro second */
-#define ISL9237_C1_GP_DEBOUNCE_2 (0 << 14)
-#define ISL9237_C1_GP_DEBOUNCE_12 (1 << 14)
-#define ISL9237_C1_GP_DEBOUNCE_2000 (2 << 14)
-#define ISL9237_C1_GP_DEBOUNCE_5000000 (3 << 14)
-#define ISL9237_C1_GP_DEBOUNCE_MASK (3 << 14)
-
-/* Control1: learn mode */
-#define ISL9237_C1_LEARN_MODE_AUTOEXIT (1 << 13)
-#define ISL9237_C1_LEARN_MODE_ENABLE (1 << 12)
-
-/* Control1: OTG enable */
-#define ISL9237_C1_OTG (1 << 11)
-
-/* Control1: audio filter */
-#define ISL9237_C1_AUDIO_FILTER (1 << 10)
-
-/* Control1: switch frequency */
-#define ISL9237_C1_SWITCH_FREQ_PROG (0 << 7) /* 1000kHz or PROG */
-#define ISL9237_C1_SWITCH_FREQ_913K (1 << 7)
-#define ISL9237_C1_SWITCH_FREQ_839K (2 << 7)
-#define ISL9237_C1_SWITCH_FREQ_777K (3 << 7)
-#define ISL9237_C1_SWITCH_FREQ_723K (4 << 7)
-#define ISL9237_C1_SWITCH_FREQ_676K (5 << 7)
-#define ISL9237_C1_SWITCH_FREQ_635K (6 << 7)
-#define ISL9237_C1_SWITCH_FREQ_599K (7 << 7)
-#define ISL9237_C1_SWITCH_FREQ_MASK (7 << 7)
-
-/* Control1: turbo mode */
-#define ISL9237_C1_TURBO_MODE (1 << 6)
-
-/* Control1: AMON & BMON */
-#define ISL9237_C1_DISABLE_MON (1 << 5)
-#define ISL9237_C1_SELECT_BMON (1 << 4)
-
-/* Control1: PSYS, VSYS, VSYSLO */
-#define ISL9237_C1_ENABLE_PSYS (1 << 3)
-#define ISL9237_C1_ENABLE_VSYS (1 << 2)
-#define ISL9237_C1_VSYSLO_REF_6000 0
-#define ISL9237_C1_VSYSLO_REF_6300 1
-#define ISL9237_C1_VSYSLO_REF_6600 2
-#define ISL9237_C1_VSYSLO_REF_6900 3
-#define ISL9237_C1_VSYSLO_REF_MASK 3
-
-/* Control2: trickle charging current in mA */
-#define ISL9237_C2_TRICKLE_256 (0 << 14)
-#define ISL9237_C2_TRICKLE_128 (1 << 14)
-#define ISL9237_C2_TRICKLE_64 (2 << 14)
-#define ISL9237_C2_TRICKLE_512 (3 << 14)
-#define ISL9237_C2_TRICKLE_MASK (3 << 14)
-
-/* Control2: OTGEN debounce time in ms */
-#define ISL9237_C2_OTG_DEBOUNCE_1300 (0 << 13)
-#define ISL9237_C2_OTG_DEBOUNCE_150 (1 << 13)
-#define ISL9237_C2_OTG_DEBOUNCE_MASK (1 << 13)
-
-/* Control2: 2-level adapter over current */
-#define ISL9237_C2_2LVL_OVERCURRENT (1 << 12)
-
-/* Control2: adapter insertion debounce time in ms */
-#define ISL9237_C2_ADAPTER_DEBOUNCE_1300 (0 << 11)
-#define ISL9237_C2_ADAPTER_DEBOUNCE_150 (1 << 11)
-#define ISL9237_C2_ADAPTER_DEBOUNCE_MASK (1 << 11)
-
-/* Control2: PROCHOT debounce time in uS */
-#define ISL9237_C2_PROCHOT_DEBOUNCE_10 (0 << 9)
-#define ISL9237_C2_PROCHOT_DEBOUNCE_100 (1 << 9)
-#define ISL9237_C2_PROCHOT_DEBOUNCE_500 (2 << 9)
-#define ISL9237_C2_PROCHOT_DEBOUNCE_1000 (3 << 9)
-#define ISL9237_C2_PROCHOT_DEBOUNCE_MASK (3 << 9)
-
-/* Control2: min PROCHOT duration in uS */
-#define ISL9237_C2_PROCHOT_DURATION_10000 (0 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_20000 (1 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_15000 (2 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_5000 (3 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_1000 (4 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_500 (5 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_100 (6 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_0 (7 << 6)
-#define ISL9237_C2_PROCHOT_DURATION_MASK (7 << 6)
-
-/* Control2: turn off ASGATE in OTG mode */
-#define ISL9237_C2_ASGATE_OFF (1 << 5)
-
-/* Control2: CMIN, general purpose comparator reference in mV */
-#define ISL9237_C2_CMIN_2000 (0 << 4)
-#define ISL9237_C2_CMIN_1200 (1 << 4)
-
-/* Control2: general purpose comparator enable */
-#define ISL9237_C2_COMPARATOR (1 << 3)
-
-/* Control2: invert CMOUT, general purpose comparator output, polarity */
-#define ISL9237_C2_INVERT_CMOUT (1 << 2)
-
-/* Control2: disable WOC, way over current */
-#define ISL9237_C2_WOC_OFF (1 << 1)
-
-/* Control2: PSYS gain in uA/W */
-#define ISL9237_C2_PSYS_GAIN (1 << 0)
-
-/* OTG voltage limit in mV, current limit in mA */
-#define ISL9237_OTG_VOLTAGE_MIN 4864
-#define ISL9237_OTG_VOLTAGE_MAX 5376
-#define ISL9237_OTG_CURRENT_MAX 4096
-
-/* Info register fields */
-#define ISL9237_INFO_PROG_RESISTOR_MASK 0xf
-#define ISL9237_INFO_TRICKLE_ACTIVE_MASK (1 << 4)
-#define ISL9237_INFO_PSTATE_SHIFT 5
-#define ISL9237_INFO_PSTATE_MASK 3
-
-enum isl9237_power_stage {
- BUCK_MODE,
- BOOST_MODE,
- BUCK_BOOST_MODE,
- REVERSE_BUCK_MODE
-};
-
-#define ISL9237_INFO_FSM_STATE_SHIFT 7
-#define ISL9237_INFO_FSM_STATE_MASK 7
-
-enum isl9237_fsm_state {
- FSM_OFF,
- FSM_BAT,
- FSM_ADPT,
- FSM_ACOK,
- FSM_VSYS,
- FSM_CHRG,
- FSM_ENTOG,
- FSM_OTG
-};
-
-#define ISL9237_INFO_VSYSLO (1 << 10)
-#define ISL9237_INFO_DCHOT (1 << 11)
-#define ISL9237_INFO_ACHOT (1 << 12)
-
-
-#define CHARGER_NAME "isl9237"
-#define CHARGE_V_MAX ISL9237_SYS_VOLTAGE_REG_MAX
-#define CHARGE_V_MIN ISL9237_SYS_VOLTAGE_REG_MIN
-#define CHARGE_V_STEP 8
-#define CHARGE_I_MAX ISL9237_CURRENT_REG_MAX
-#define CHARGE_I_MIN 4
-#define CHARGE_I_OFF 0
-#define CHARGE_I_STEP 4
-#define INPUT_I_MAX ISL9237_CURRENT_REG_MAX
-#define INPUT_I_MIN 4
-#define INPUT_I_STEP 4
-
-#define I2C_ADDR_CHARGER ISL9237_ADDR
-#endif /* __CROS_EC_ISL9237_H */
diff --git a/driver/charger/isl9237.c b/driver/charger/isl923x.c
index 3be623ff00..81a9dd3582 100644
--- a/driver/charger/isl9237.c
+++ b/driver/charger/isl923x.c
@@ -2,7 +2,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
- * Intersil ISL9237 battery charger driver.
+ * Intersil ISL-9237/8 battery charger driver.
*/
#include "adc.h"
@@ -13,7 +13,7 @@
#include "common.h"
#include "hooks.h"
#include "i2c.h"
-#include "isl9237.h"
+#include "isl923x.h"
#include "timer.h"
#include "util.h"
@@ -62,12 +62,12 @@ static inline int raw_write16(int offset, int value)
static int isl9237_set_current(uint16_t current)
{
- return raw_write16(ISL9237_REG_CHG_CURRENT, CURRENT_TO_REG(current));
+ return raw_write16(ISL923X_REG_CHG_CURRENT, CURRENT_TO_REG(current));
}
static int isl9237_set_voltage(uint16_t voltage)
{
- return raw_write16(ISL9237_REG_SYS_VOLTAGE_MAX, voltage);
+ return raw_write16(ISL923X_REG_SYS_VOLTAGE_MAX, voltage);
}
/* chip specific interfaces */
@@ -77,11 +77,11 @@ int charger_set_input_current(int input_current)
int rv;
uint16_t reg = AC_CURRENT_TO_REG(input_current);
- rv = raw_write16(ISL9237_REG_ADAPTER_CURRENT1, reg);
+ rv = raw_write16(ISL923X_REG_ADAPTER_CURRENT1, reg);
if (rv)
return rv;
- return raw_write16(ISL9237_REG_ADAPTER_CURRENT2, reg);
+ return raw_write16(ISL923X_REG_ADAPTER_CURRENT2, reg);
}
int charger_get_input_current(int *input_current)
@@ -89,7 +89,7 @@ int charger_get_input_current(int *input_current)
int rv;
int reg;
- rv = raw_read16(ISL9237_REG_ADAPTER_CURRENT1, &reg);
+ rv = raw_read16(ISL923X_REG_ADAPTER_CURRENT1, &reg);
if (rv)
return rv;
@@ -102,7 +102,7 @@ int charger_manufacturer_id(int *id)
int rv;
int reg;
- rv = raw_read16(ISL9237_REG_MANUFACTURER_ID, &reg);
+ rv = raw_read16(ISL923X_REG_MANUFACTURER_ID, &reg);
if (rv)
return rv;
@@ -115,7 +115,7 @@ int charger_device_id(int *id)
int rv;
int reg;
- rv = raw_read16(ISL9237_REG_DEVICE_ID, &reg);
+ rv = raw_read16(ISL923X_REG_DEVICE_ID, &reg);
if (rv)
return rv;
@@ -129,12 +129,12 @@ int charger_get_option(int *option)
uint32_t controls;
int reg;
- rv = raw_read8(ISL9237_REG_CONTROL0, &reg);
+ rv = raw_read8(ISL923X_REG_CONTROL0, &reg);
if (rv)
return rv;
controls = reg;
- rv = raw_read16(ISL9237_REG_CONTROL1, &reg);
+ rv = raw_read16(ISL923X_REG_CONTROL1, &reg);
if (rv)
return rv;
@@ -149,13 +149,13 @@ int charger_set_option(int option)
uint16_t reg;
reg = option & 0xffff;
- rv = raw_write16(ISL9237_REG_CONTROL0, reg);
+ rv = raw_write16(ISL923X_REG_CONTROL0, reg);
if (rv)
return rv;
reg = (option >> 16) & 0xffff;
- return raw_write16(ISL9237_REG_CONTROL1, reg);
+ return raw_write16(ISL923X_REG_CONTROL1, reg);
}
/* Charger interfaces */
@@ -183,7 +183,7 @@ int charger_set_mode(int mode)
if (!learn_mode)
rv = charger_discharge_on_ac(0);
- /* ISL9237 does not support inhibit mode setting. */
+ /* ISL923X does not support inhibit mode setting. */
return rv;
}
@@ -192,7 +192,7 @@ int charger_get_current(int *current)
int rv;
int reg;
- rv = raw_read16(ISL9237_REG_CHG_CURRENT, &reg);
+ rv = raw_read16(ISL923X_REG_CHG_CURRENT, &reg);
if (rv)
return rv;
@@ -207,14 +207,14 @@ int charger_set_current(int current)
int charger_get_voltage(int *voltage)
{
- return raw_read16(ISL9237_REG_SYS_VOLTAGE_MAX, voltage);
+ return raw_read16(ISL923X_REG_SYS_VOLTAGE_MAX, voltage);
}
int charger_set_voltage(int voltage)
{
- /* The ISL9237 will drop voltage to as low as requested. As the
+ /* The ISL923X will drop voltage to as low as requested. As the
* charger state machine will pass in 0 voltage, protect the system
- * voltage by capping to the minimum. The reason is that the ISL9237
+ * voltage by capping to the minimum. The reason is that the ISL923X
* only can regulate the system voltage which will kill the board's
* power if below 0. */
if (voltage == 0) {
@@ -232,7 +232,7 @@ int charger_post_init(void)
#ifdef CONFIG_TRICKLE_CHARGING
const struct battery_info *bi = battery_get_info();
- rv = raw_write16(ISL9237_REG_SYS_VOLTAGE_MIN, bi->voltage_min);
+ rv = raw_write16(ISL923X_REG_SYS_VOLTAGE_MIN, bi->voltage_min);
if (rv)
return rv;
#endif
@@ -241,31 +241,42 @@ int charger_post_init(void)
* [10:9]: Prochot# Debounce time
* 11b: 1ms
*/
- rv = raw_read16(ISL9237_REG_CONTROL2, &reg);
+ rv = raw_read16(ISL923X_REG_CONTROL2, &reg);
if (rv)
return rv;
- rv = raw_write16(ISL9237_REG_CONTROL2,
+ rv = raw_write16(ISL923X_REG_CONTROL2,
reg |
- ISL9237_C2_PROCHOT_DEBOUNCE_1000 |
- ISL9237_C2_ADAPTER_DEBOUNCE_150);
+ ISL923X_C2_PROCHOT_DEBOUNCE_1000 |
+ ISL923X_C2_ADAPTER_DEBOUNCE_150);
if (rv)
return rv;
+#ifdef CONFIG_CHARGE_RAMP_HW
+#ifdef CONFIG_ISL9237
rv = charger_get_option(&reg);
if (rv)
return rv;
-#ifdef CONFIG_CHARGE_RAMP_HW
/* Set input voltage regulation reference voltage for charge ramp */
- reg &= ~ISL9237_C0_VREG_REF_MASK;
- reg |= ISL9237_C0_VREG_REF_4200;
+ reg &= ~ISL923X_C0_VREG_REF_MASK;
+ reg |= ISL923X_C0_VREG_REF_4200;
+
+ return charger_set_option(reg);
#else
- /* Disable voltage regulation loop to disable charge ramp */
- reg |= ISL9237_C0_DISABLE_VREG;
+ /* ISL9238 default input voltage regulation is 4096 mV. */
+ return EC_SUCCESS;
#endif
+#else
+ rv = charger_get_option(&reg);
+ if (rv)
+ return rv;
+
+ /* Disable voltage regulation loop to disable charge ramp */
+ reg |= ISL923X_C0_DISABLE_VREG;
return charger_set_option(reg);
+#endif
}
int charger_discharge_on_ac(int enable)
@@ -273,17 +284,17 @@ int charger_discharge_on_ac(int enable)
int rv;
int control1;
- rv = raw_read16(ISL9237_REG_CONTROL1, &control1);
+ rv = raw_read16(ISL923X_REG_CONTROL1, &control1);
if (rv)
return rv;
- control1 &= ~ISL9237_C1_LEARN_MODE_AUTOEXIT;
+ control1 &= ~ISL923X_C1_LEARN_MODE_AUTOEXIT;
if (enable)
- control1 |= ISL9237_C1_LEARN_MODE_ENABLE;
+ control1 |= ISL923X_C1_LEARN_MODE_ENABLE;
else
- control1 &= ~ISL9237_C1_LEARN_MODE_ENABLE;
+ control1 &= ~ISL923X_C1_LEARN_MODE_ENABLE;
- rv = raw_write16(ISL9237_REG_CONTROL1, control1);
+ rv = raw_write16(ISL923X_REG_CONTROL1, control1);
learn_mode = !rv && enable;
return rv;
@@ -303,9 +314,9 @@ int charger_set_hw_ramp(int enable)
/* HW ramp is controlled by input voltage regulation reference bits */
if (enable)
- reg &= ~ISL9237_C0_DISABLE_VREG;
+ reg &= ~ISL923X_C0_DISABLE_VREG;
else
- reg |= ISL9237_C0_DISABLE_VREG;
+ reg |= ISL923X_C0_DISABLE_VREG;
return charger_set_option(reg);
}
@@ -348,9 +359,9 @@ static void charger_enable_psys(void)
/*
* enable system power monitor PSYS function
*/
- if (!raw_read16(ISL9237_REG_CONTROL1, &val)) {
- val |= ISL9237_C1_ENABLE_PSYS;
- raw_write16(ISL9237_REG_CONTROL1, val);
+ if (!raw_read16(ISL923X_REG_CONTROL1, &val)) {
+ val |= ISL923X_C1_ENABLE_PSYS;
+ raw_write16(ISL923X_REG_CONTROL1, val);
}
}
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, charger_enable_psys, HOOK_PRIO_DEFAULT);
@@ -362,14 +373,15 @@ static void charger_disable_psys(void)
/*
* disable system power monitor PSYS function
*/
- if (!raw_read16(ISL9237_REG_CONTROL1, &val)) {
- val &= ~ISL9237_C1_ENABLE_PSYS;
- raw_write16(ISL9237_REG_CONTROL1, val);
+ if (!raw_read16(ISL923X_REG_CONTROL1, &val)) {
+ val &= ~ISL923X_C1_ENABLE_PSYS;
+ raw_write16(ISL923X_REG_CONTROL1, val);
}
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, charger_disable_psys, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_CMD_CHARGER_PSYS
+/* TODO(crosbug.com/p/61166): This dead code is ISL9237-specific. */
#define PSYS_ADC_READ_COUNT 100
static int charger_get_system_power(void)
{
@@ -378,7 +390,7 @@ static int charger_get_system_power(void)
int ret;
int val;
- ret = raw_read16(ISL9237_REG_CONTROL2, &val);
+ ret = raw_read16(ISL923X_REG_CONTROL2, &val);
if (ret)
return ret;
@@ -397,11 +409,11 @@ static int charger_get_system_power(void)
*
* Do not divide the constants first to ensure precision is not lost.
*/
- if (val & ISL9237_C2_PSYS_GAIN)
- return ((adc * ISL9237_C2_PSYS_GAIN_0_36) /
+ if (val & ISL923X_C2_PSYS_GAIN)
+ return ((adc * ISL923X_C2_PSYS_GAIN_0_36) /
PSYS_ADC_READ_COUNT);
else
- return ((adc * ISL9237_C2_PSYS_GAIN_1_44) /
+ return ((adc * ISL923X_C2_PSYS_GAIN_1_44) /
PSYS_ADC_READ_COUNT);
}
@@ -425,17 +437,17 @@ static int console_command_amon_bmon(int argc, char **argv)
int adc, curr, val, ret;
ret = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL9237_REG_CONTROL1, &val);
+ ISL923X_REG_CONTROL1, &val);
if (ret)
return ret;
/* Enable monitor */
- val &= ~ISL9237_C1_DISABLE_MON;
+ val &= ~ISL923X_C1_DISABLE_MON;
if (argc == 1 || (argc >= 2 && argv[1][0] == 'a')) {
/* Switch to AMON */
- val &= ~ISL9237_C1_SELECT_BMON;
+ val &= ~ISL923X_C1_SELECT_BMON;
ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL9237_REG_CONTROL1, val);
+ ISL923X_REG_CONTROL1, val);
if (ret)
return ret;
@@ -446,9 +458,9 @@ static int console_command_amon_bmon(int argc, char **argv)
if (argc == 1 || (argc >= 2 && argv[1][0] == 'b')) {
/* Switch to BMON */
- val |= ISL9237_C1_SELECT_BMON;
+ val |= ISL923X_C1_SELECT_BMON;
ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL9237_REG_CONTROL1, val);
+ ISL923X_REG_CONTROL1, val);
if (ret)
return ret;
diff --git a/driver/charger/isl923x.h b/driver/charger/isl923x.h
new file mode 100644
index 0000000000..ba018e766c
--- /dev/null
+++ b/driver/charger/isl923x.h
@@ -0,0 +1,264 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Intersil ISL-9237/8 battery charger driver.
+ */
+
+#ifndef __CROS_EC_ISL923X_H
+#define __CROS_EC_ISL923X_H
+
+#define ISL923X_ADDR 0x12 /* 7bit address 0001001 */
+
+/* Registers */
+#define ISL923X_REG_CHG_CURRENT 0x14
+#define ISL923X_REG_ADAPTER_CURRENT1 0x3f
+#define ISL923X_REG_ADAPTER_CURRENT2 0x3b
+#define ISL923X_REG_SYS_VOLTAGE_MAX 0x15
+#define ISL923X_REG_SYS_VOLTAGE_MIN 0x3e
+#define ISL923X_REG_PROCHOT_AC 0x47
+#define ISL923X_REG_PROCHOT_DC 0x48
+#define ISL923X_REG_T1_T2 0x38
+#define ISL923X_REG_CONTROL0 0x39
+#define ISL923X_REG_CONTROL1 0x3c
+#define ISL923X_REG_CONTROL2 0x3d
+#define ISL9238_REG_CONTROL3 0x4c
+#define ISL9238_REG_CONTROL4 0x4e
+#define ISL923X_REG_INFO 0x3a
+#define ISL9238_REG_INFO2 0x4d
+#define ISL923X_REG_OTG_VOLTAGE 0x49
+#define ISL923X_REG_OTG_CURRENT 0x4a
+#define ISL9238_REG_INPUT_VOLTAGE 0x4b
+#define ISL923X_REG_MANUFACTURER_ID 0xfe
+#define ISL923X_REG_DEVICE_ID 0xff
+
+/* Sense resistor default values in mOhm */
+#define ISL923X_DEFAULT_SENSE_RESISTOR_AC 20
+#define ISL923X_DEFAULT_SENSE_RESISTOR 10
+
+/* Maximum charging current register value */
+#define ISL923X_CURRENT_REG_MAX 0x17c0 /* bit<12:2> 10111110000 */
+
+/* 2-level adpater current limit duration T1 & T2 in micro seconds */
+#define ISL923X_T1_10000 0x00
+#define ISL923X_T1_20000 0x01
+#define ISL923X_T1_15000 0x02
+#define ISL923X_T1_5000 0x03
+#define ISL923X_T1_1000 0x04
+#define ISL923X_T1_500 0x05
+#define ISL923X_T1_100 0x06
+#define ISL923X_T1_0 0x07
+#define ISL923X_T2_10 (0x00 << 8)
+#define ISL923X_T2_100 (0x01 << 8)
+#define ISL923X_T2_500 (0x02 << 8)
+#define ISL923X_T2_1000 (0x03 << 8)
+#define ISL923X_T2_300 (0x04 << 8)
+#define ISL923X_T2_750 (0x05 << 8)
+#define ISL923X_T2_2000 (0x06 << 8)
+#define ISL923X_T2_10000 (0x07 << 8)
+
+#define ISL9237_SYS_VOLTAGE_REG_MAX 13824
+#define ISL9238_SYS_VOLTAGE_REG_MAX 18304
+#define ISL923X_SYS_VOLTAGE_REG_MIN 2048
+
+/* PROCHOT# debounce time and duration time in micro seconds */
+#define ISL923X_PROCHOT_DURATION_10000 (0 << 6)
+#define ISL923X_PROCHOT_DURATION_20000 (1 << 6)
+#define ISL923X_PROCHOT_DURATION_15000 (2 << 6)
+#define ISL923X_PROCHOT_DURATION_5000 (3 << 6)
+#define ISL923X_PROCHOT_DURATION_1000 (4 << 6)
+#define ISL923X_PROCHOT_DURATION_500 (5 << 6)
+#define ISL923X_PROCHOT_DURATION_100000 (6 << 6)
+#define ISL923X_PROCHOT_DURATION_0 (7 << 6)
+#define ISL923X_PROCHOT_DURATION_MASK (7 << 6)
+
+#define ISL923X_PROCHOT_DEBOUNCE_10 (0 << 9)
+#define ISL923X_PROCHOT_DEBOUNCE_100 (1 << 9)
+#define ISL923X_PROCHOT_DEBOUNCE_500 (2 << 9)
+#define ISL923X_PROCHOT_DEBOUNCE_1000 (3 << 9)
+#define ISL923X_PROCHOT_DEBOUNCE_MASK (3 << 9)
+
+/* Maximum PROCHOT register value */
+#define ISL923X_PROCHOT_AC_REG_MAX 6400
+#define ISL923X_PROCHOT_DC_REG_MAX 12800
+
+/* Control0: adapter voltage regulation reference */
+#define ISL9237_C0_VREG_REF_3900 0
+#define ISL9237_C0_VREG_REF_4200 1
+#define ISL9237_C0_VREG_REF_4500 2
+#define ISL9237_C0_VREG_REF_4800 3
+#define ISL9237_C0_VREG_REF_MASK 0x03
+
+/* Control0: disable adapter voltaqe regulation */
+#define ISL923X_C0_DISABLE_VREG (1 << 2)
+
+/* Control0: battery DCHOT reference for RS2 == 20mOhm */
+#define ISL923X_C0_DCHOT_6A (0 << 3)
+#define ISL923X_C0_DCHOT_5A (1 << 3)
+#define ISL923X_C0_DCHOT_4A (2 << 3)
+#define ISL923X_C0_DCHOT_3A (3 << 3)
+#define ISL923X_C0_DCHOT_MASK (3 << 3)
+
+/* Control1: general purpose comparator debounce time in micro second */
+#define ISL923X_C1_GP_DEBOUNCE_2 (0 << 14)
+#define ISL923X_C1_GP_DEBOUNCE_12 (1 << 14)
+#define ISL923X_C1_GP_DEBOUNCE_2000 (2 << 14)
+#define ISL923X_C1_GP_DEBOUNCE_5000000 (3 << 14)
+#define ISL923X_C1_GP_DEBOUNCE_MASK (3 << 14)
+
+/* Control1: learn mode */
+#define ISL923X_C1_LEARN_MODE_AUTOEXIT (1 << 13)
+#define ISL923X_C1_LEARN_MODE_ENABLE (1 << 12)
+
+/* Control1: OTG enable */
+#define ISL923X_C1_OTG (1 << 11)
+
+/* Control1: audio filter */
+#define ISL923X_C1_AUDIO_FILTER (1 << 10)
+
+/* Control1: switch frequency, ISL9238 defines bit 7 as unused */
+#define ISL923X_C1_SWITCH_FREQ_PROG (0 << 7) /* 1000kHz or PROG */
+#define ISL9237_C1_SWITCH_FREQ_913K (1 << 7)
+#define ISL923X_C1_SWITCH_FREQ_839K (2 << 7)
+#define ISL9237_C1_SWITCH_FREQ_777K (3 << 7)
+#define ISL923X_C1_SWITCH_FREQ_723K (4 << 7)
+#define ISL9237_C1_SWITCH_FREQ_676K (5 << 7)
+#define ISL923X_C1_SWITCH_FREQ_635K (6 << 7)
+#define ISL9237_C1_SWITCH_FREQ_599K (7 << 7)
+#define ISL923X_C1_SWITCH_FREQ_MASK (7 << 7)
+
+/* Control1: turbo mode */
+#define ISL923X_C1_TURBO_MODE (1 << 6)
+
+/* Control1: AMON & BMON */
+#define ISL923X_C1_DISABLE_MON (1 << 5)
+#define ISL923X_C1_SELECT_BMON (1 << 4)
+
+/* Control1: PSYS, VSYS, VSYSLO */
+#define ISL923X_C1_ENABLE_PSYS (1 << 3)
+#define ISL923X_C1_ENABLE_VSYS (1 << 2)
+#define ISL923X_C1_VSYSLO_REF_6000 0
+#define ISL923X_C1_VSYSLO_REF_6300 1
+#define ISL923X_C1_VSYSLO_REF_6600 2
+#define ISL923X_C1_VSYSLO_REF_6900 3
+#define ISL923X_C1_VSYSLO_REF_MASK 3
+
+/* Control2: trickle charging current in mA */
+#define ISL923X_C2_TRICKLE_256 (0 << 14)
+#define ISL923X_C2_TRICKLE_128 (1 << 14)
+#define ISL923X_C2_TRICKLE_64 (2 << 14)
+#define ISL923X_C2_TRICKLE_512 (3 << 14)
+#define ISL923X_C2_TRICKLE_MASK (3 << 14)
+
+/* Control2: OTGEN debounce time in ms */
+#define ISL923X_C2_OTG_DEBOUNCE_1300 (0 << 13)
+#define ISL923X_C2_OTG_DEBOUNCE_150 (1 << 13)
+#define ISL923X_C2_OTG_DEBOUNCE_MASK (1 << 13)
+
+/* Control2: 2-level adapter over current */
+#define ISL923X_C2_2LVL_OVERCURRENT (1 << 12)
+
+/* Control2: adapter insertion debounce time in ms */
+#define ISL923X_C2_ADAPTER_DEBOUNCE_1300 (0 << 11)
+#define ISL923X_C2_ADAPTER_DEBOUNCE_150 (1 << 11)
+#define ISL923X_C2_ADAPTER_DEBOUNCE_MASK (1 << 11)
+
+/* Control2: PROCHOT debounce time in uS */
+#define ISL9238_C2_PROCHOT_DEBOUNCE_7 (0 << 9)
+#define ISL9237_C2_PROCHOT_DEBOUNCE_10 (0 << 9)
+#define ISL923X_C2_PROCHOT_DEBOUNCE_100 (1 << 9)
+#define ISL923X_C2_PROCHOT_DEBOUNCE_500 (2 << 9)
+#define ISL923X_C2_PROCHOT_DEBOUNCE_1000 (3 << 9)
+#define ISL923X_C2_PROCHOT_DEBOUNCE_MASK (3 << 9)
+
+/* Control2: min PROCHOT duration in uS */
+#define ISL923X_C2_PROCHOT_DURATION_10000 (0 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_20000 (1 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_15000 (2 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_5000 (3 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_1000 (4 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_500 (5 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_100 (6 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_0 (7 << 6)
+#define ISL923X_C2_PROCHOT_DURATION_MASK (7 << 6)
+
+/* Control2: turn off ASGATE in OTG mode */
+#define ISL923X_C2_ASGATE_OFF (1 << 5)
+
+/* Control2: CMIN, general purpose comparator reference in mV */
+#define ISL923X_C2_CMIN_2000 (0 << 4)
+#define ISL923X_C2_CMIN_1200 (1 << 4)
+
+/* Control2: general purpose comparator enable */
+#define ISL923X_C2_COMPARATOR (1 << 3)
+
+/* Control2: invert CMOUT, general purpose comparator output, polarity */
+#define ISL923X_C2_INVERT_CMOUT (1 << 2)
+
+/* Control2: disable WOC, way over current */
+#define ISL923X_C2_WOC_OFF (1 << 1)
+
+/* Control2: PSYS gain in uA/W (ISL9237 only) */
+#define ISL9237_C2_PSYS_GAIN (1 << 0)
+
+/* Control2: PSYS gain in uA/W (ISL9238 only) */
+#define ISL9238_C3_PSYS_GAIN (1 << 9)
+
+/* OTG voltage limit in mV, current limit in mA */
+#define ISL923X_OTG_VOLTAGE_MIN 4864
+#define ISL923X_OTG_VOLTAGE_MAX 5376
+#define ISL923X_OTG_CURRENT_MAX 4096
+
+/* Info register fields */
+#define ISL9237_INFO_PROG_RESISTOR_MASK 0xf
+#define ISL923X_INFO_TRICKLE_ACTIVE_MASK (1 << 4)
+#define ISL9237_INFO_PSTATE_SHIFT 5
+#define ISL9237_INFO_PSTATE_MASK 3
+
+enum isl9237_power_stage {
+ BUCK_MODE,
+ BOOST_MODE,
+ BUCK_BOOST_MODE,
+ REVERSE_BUCK_MODE
+};
+
+#define ISL9237_INFO_FSM_STATE_SHIFT 7
+#define ISL9237_INFO_FSM_STATE_MASK 7
+
+enum isl9237_fsm_state {
+ FSM_OFF,
+ FSM_BAT,
+ FSM_ADPT,
+ FSM_ACOK,
+ FSM_VSYS,
+ FSM_CHRG,
+ FSM_ENTOG,
+ FSM_OTG
+};
+
+#define ISL923X_INFO_VSYSLO (1 << 10)
+#define ISL923X_INFO_DCHOT (1 << 11)
+#define ISL9237_INFO_ACHOT (1 << 12)
+
+#if defined(CONFIG_CHARGER_ISL9237)
+#define CHARGER_NAME "isl9237"
+#define CHARGE_V_MAX ISL9237_SYS_VOLTAGE_REG_MAX
+#define CHARGE_V_MIN ISL923X_SYS_VOLTAGE_REG_MIN
+#define CHARGE_V_STEP 8
+#elif defined(CONFIG_CHARGER_ISL9238)
+#define CHARGER_NAME "isl9238"
+#define CHARGE_V_MAX ISL9238_SYS_VOLTAGE_REG_MAX
+#define CHARGE_V_MIN ISL923X_SYS_VOLTAGE_REG_MIN
+#define CHARGE_V_STEP 8
+#endif
+
+#define CHARGE_I_MAX ISL923X_CURRENT_REG_MAX
+#define CHARGE_I_MIN 4
+#define CHARGE_I_OFF 0
+#define CHARGE_I_STEP 4
+#define INPUT_I_MAX ISL923X_CURRENT_REG_MAX
+#define INPUT_I_MIN 4
+#define INPUT_I_STEP 4
+
+#define I2C_ADDR_CHARGER ISL923X_ADDR
+#endif /* __CROS_EC_ISL923X_H */
diff --git a/include/config.h b/include/config.h
index 15679582f8..ff23a7ec4e 100644
--- a/include/config.h
+++ b/include/config.h
@@ -390,6 +390,7 @@
#undef CONFIG_CHARGER_BQ25892
#undef CONFIG_CHARGER_BQ25895
#undef CONFIG_CHARGER_ISL9237
+#undef CONFIG_CHARGER_ISL9238
#undef CONFIG_CHARGER_TPS65090 /* Note: does not use CONFIG_CHARGER */
/*