diff options
Diffstat (limited to 'driver/charger')
-rw-r--r-- | driver/charger/isl9241.c | 60 | ||||
-rw-r--r-- | driver/charger/isl9241.h | 25 |
2 files changed, 52 insertions, 33 deletions
diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index 5f3566095c..2bb3d75f28 100644 --- a/driver/charger/isl9241.c +++ b/driver/charger/isl9241.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. * - * Renesas (Intersil) ISL-9241 battery charger driver. + * Renesas (Intersil) ISL-9241 (and RAA489110) battery charger driver. */ /* TODO(b/175881324) */ @@ -28,19 +28,6 @@ #error "ISL9241 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC." #endif -/* Sense resistor default values in milli Ohm */ -#define ISL9241_DEFAULT_RS1 20 /* Input current sense resistor */ -#define ISL9241_DEFAULT_RS2 10 /* Battery charge current sense resistor */ - -#define BOARD_RS1 CONFIG_CHARGER_SENSE_RESISTOR_AC -#define BOARD_RS2 CONFIG_CHARGER_SENSE_RESISTOR - -#define BC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS2) / BOARD_RS2) -#define BC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS2) / ISL9241_DEFAULT_RS2) - -#define AC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS1) / BOARD_RS1) -#define AC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS1) / ISL9241_DEFAULT_RS1) - /* Console output macros */ #define CPRINTS(format, args...) cprints(CC_CHARGER, "ISL9241 " format, ##args) @@ -487,14 +474,14 @@ int isl9241_set_ac_prochot(int chgnum, int ma) uint16_t reg; /* - * The register reserves bits [6:0] and bits [15:13]. - * This routine should ensure these bits are not set - * before writing the register. + * The register reserves bits [6:0] ([4:0] for rsa489110) and bits + * [15:13]. This routine should ensure these bits are not set before + * writing the register. */ - if (ma > AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MAX)) - reg = ISL9241_AC_PROCHOT_CURRENT_MAX; - else if (ma < AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MIN)) - reg = ISL9241_AC_PROCHOT_CURRENT_MIN; + if (ma > ISL9241_AC_PROCHOT_CURRENT_MAX) + reg = AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MAX); + else if (ma < ISL9241_AC_PROCHOT_CURRENT_MIN) + reg = AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MIN); else reg = AC_CURRENT_TO_REG(ma); @@ -510,9 +497,9 @@ int isl9241_set_dc_prochot(int chgnum, int ma) int rv; /* - * The register reserves bits [7:0] and bits [15:14]. - * This routine should ensure these bits are not set - * before writing the register. + * The register reserves bits [7:0] ([5:0] for RAA489110) and bits + * [15:14]. This routine should ensure these bits are not set before + * writing the register. */ if (ma > ISL9241_DC_PROCHOT_CURRENT_MAX) ma = ISL9241_DC_PROCHOT_CURRENT_MAX; @@ -738,6 +725,19 @@ static bool isl9241_is_in_chrg(int chgnum) return trickle_charge_enabled || fast_charge_enabled; } +static enum ec_error_list +isl9241_update_force_buck_mode(int chgnum, enum mask_update_action action) +{ + if (IS_ENABLED(CONFIG_CHARGER_ISL9241)) + return isl9241_update(chgnum, ISL9241_REG_CONTROL4, + ISL9241_CONTROL4_FORCE_BUCK_MODE, action); + else + /* CONFIG_CHARGER_RAA489110 */ + return isl9241_update(chgnum, ISL9241_REG_CONTROL0, + RAA489110_CONTROL0_EN_FORCE_BUCK_MODE, + action); +} + /* * Transition from Bypass to BAT. */ @@ -749,8 +749,7 @@ static enum ec_error_list isl9241_bypass_to_bat(int chgnum) mutex_lock(&control3_mutex_isl9241); /* 1: Disable force forward buck/reverse boost. */ - isl9241_update(chgnum, ISL9241_REG_CONTROL4, - ISL9241_CONTROL4_FORCE_BUCK_MODE, MASK_CLR); + isl9241_update_force_buck_mode(chgnum, MASK_CLR); /* * 2: Turn off BYPSG, turn on NGATE, disable charge pump 100%, disable @@ -787,8 +786,7 @@ static enum ec_error_list isl9241_bypass_chrg_to_bat(int chgnum) mutex_lock(&control3_mutex_isl9241); /* 1: Disable force forward buck/reverse boost. */ - isl9241_update(chgnum, ISL9241_REG_CONTROL4, - ISL9241_CONTROL4_FORCE_BUCK_MODE, MASK_CLR); + isl9241_update_force_buck_mode(chgnum, MASK_CLR); /* 2: Disable fast charge. */ isl9241_write(chgnum, ISL9241_REG_CHG_CURRENT_LIMIT, 0); /* 3: Disable trickle charge. */ @@ -928,8 +926,7 @@ static enum ec_error_list isl9241_nvdc_to_bypass(int chgnum) /* 17: Read diode emulation active bit. */ /* 18: Disable 10mA discharge on CSOP. */ /* 19*: Force forward buck/reverse boost mode. */ - isl9241_update(chgnum, ISL9241_REG_CONTROL4, - ISL9241_CONTROL4_FORCE_BUCK_MODE, MASK_SET); + isl9241_update_force_buck_mode(chgnum, MASK_SET); if (!isl9241_is_ac_present(chgnum)) { /* @@ -985,8 +982,7 @@ static enum ec_error_list isl9241_bypass_to_nvdc(int chgnum) /* 1*: Reduce system load below ACLIM. */ /* 3*: Disable force forward buck/reverse boost. */ - rv = isl9241_update(chgnum, ISL9241_REG_CONTROL4, - ISL9241_CONTROL4_FORCE_BUCK_MODE, MASK_CLR); + rv = isl9241_update_force_buck_mode(chgnum, MASK_CLR); if (rv) return rv; diff --git a/driver/charger/isl9241.h b/driver/charger/isl9241.h index c3f843f380..4e766a9886 100644 --- a/driver/charger/isl9241.h +++ b/driver/charger/isl9241.h @@ -2,7 +2,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * Renesas (Intersil) ISL-9241 battery charger driver header. + * Renesas (Intersil) ISL-9241 (and RAA489110) battery charger driver header. */ #ifndef __CROS_EC_ISL9241_H @@ -45,6 +45,7 @@ #define ISL9241_CONTROL0_INPUT_VTG_REGULATION BIT(2) #define ISL9241_CONTROL0_EN_VIN_VOUT_COMP BIT(5) #define ISL9241_CONTROL0_EN_CHARGE_PUMPS BIT(6) +#define RAA489110_CONTROL0_EN_FORCE_BUCK_MODE BIT(10) #define ISL9241_CONTROL0_EN_BYPASS_GATE BIT(11) #define ISL9241_CONTROL0_NGATE_OFF BIT(12) @@ -105,7 +106,11 @@ #define ISL9241_REG_OTG_VOLTAGE 0x49 #define ISL9241_REG_OTG_CURRENT 0x4A +#ifdef CONFIG_CHARGER_RAA489110 +#define ISL9241_MV_TO_ACOK_REFERENCE(mv) (((mv) / 144) << 6) +#else /* CONFIG_CHARGER_ISL9241 */ #define ISL9241_MV_TO_ACOK_REFERENCE(mv) (((mv) / 96) << 6) +#endif /* VIN Voltage (ADP Min Voltage) (default 4.096V) */ #define ISL9241_REG_VIN_VOLTAGE 0x4B @@ -129,6 +134,7 @@ #define ISL9241_INFORMATION2_ACOK_PIN BIT(14) #define ISL9241_REG_CONTROL4 0x4E +/* ISL9241 only */ #define ISL9241_CONTROL4_FORCE_BUCK_MODE BIT(10) /* 11: Rsense (Rs1:Rs2) ratio for PSYS (0 - 2:1, 1 - 1:1) */ #define ISL9241_CONTROL4_PSYS_RSENSE_RATIO BIT(11) @@ -153,7 +159,11 @@ #define ISL9241_REG_DEVICE_ID 0xFF #define ISL9241_VIN_ADC_BIT_OFFSET 6 +#ifdef CONFIG_CHARGER_RAA489110 +#define ISL9241_VIN_ADC_STEP_MV 144 +#else /* CONFIG_CHARGER_ISL9241 */ #define ISL9241_VIN_ADC_STEP_MV 96 +#endif #define ISL9241_ADC_POLLING_TIME_US 400 @@ -169,4 +179,17 @@ */ #define ISL9241_BYPASS_VSYS_TIMEOUT_MS 500 +/* Sense resistor default values in milli Ohm */ +#define ISL9241_DEFAULT_RS1 20 /* Input current sense resistor */ +#define ISL9241_DEFAULT_RS2 10 /* Battery charge current sense resistor */ + +#define BOARD_RS1 CONFIG_CHARGER_SENSE_RESISTOR_AC +#define BOARD_RS2 CONFIG_CHARGER_SENSE_RESISTOR + +#define BC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS2) / BOARD_RS2) +#define BC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS2) / ISL9241_DEFAULT_RS2) + +#define AC_REG_TO_CURRENT(REG) (((REG)*ISL9241_DEFAULT_RS1) / BOARD_RS1) +#define AC_CURRENT_TO_REG(CUR) (((CUR)*BOARD_RS1) / ISL9241_DEFAULT_RS1) + #endif /* __CROS_EC_ISL9241_H */ |