From d14883b6fd881ff821d88e670d1c4ead4479f983 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 7 Apr 2023 15:28:13 -0700 Subject: RAA489110: Add RAA489110 driver RAA489110 is an EPR capable version of ISL9241. BUG=b:277280318 BRANCH=None TEST=make BOARD=hades TEST=./twister --toolchain host -T zephyr/test/drivers -s drivers.isl9241 Signed-off-by: Daisuke Nojiri Change-Id: I15eb1f652027f157ccb6b3a2d509531bef0c7c6c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4409986 Reviewed-by: Paul Fagerburg Commit-Queue: Paul Fagerburg --- driver/build.mk | 1 + driver/charger/isl9241.c | 39 ++++++++++++++++++++++++--------------- driver/charger/isl9241.h | 12 +++++++++++- 3 files changed, 36 insertions(+), 16 deletions(-) (limited to 'driver') diff --git a/driver/build.mk b/driver/build.mk index da10cf3cbe..ba8078b11e 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -76,6 +76,7 @@ driver-$(CONFIG_CHARGER_ISL9238C)+=charger/isl923x.o driver-$(CONFIG_CHARGER_ISL9241)+=charger/isl9241.o driver-$(CONFIG_CHARGER_MT6370)+=charger/rt946x.o driver-$(CONFIG_CHARGER_RAA489000)+=charger/isl923x.o +driver-$(CONFIG_CHARGER_RAA489110)+=charger/isl9241.o driver-$(CONFIG_CHARGER_RT9466)+=charger/rt946x.o driver-$(CONFIG_CHARGER_RT9467)+=charger/rt946x.o driver-$(CONFIG_CHARGER_RT9490)+=charger/rt9490.o diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index 266150f2eb..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) */ @@ -474,9 +474,9 @@ 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 > ISL9241_AC_PROCHOT_CURRENT_MAX) reg = AC_CURRENT_TO_REG(ISL9241_AC_PROCHOT_CURRENT_MAX); @@ -497,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; @@ -725,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. */ @@ -736,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 @@ -774,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. */ @@ -915,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)) { /* @@ -972,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 b068d48faa..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 -- cgit v1.2.1