summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2022-08-24 15:56:07 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-25 08:49:45 +0000
commit604b237e3d3aa361dad876f8c52141b390548376 (patch)
treeee25dc487d55f792b81d63eeb6a7b15ef64a19f1
parent2d9d2a058395ca76787bf41a66a7a5125929cb40 (diff)
downloadchrome-ec-604b237e3d3aa361dad876f8c52141b390548376.tar.gz
charger/rt9490: workaround code cleanup
Rearrange the workaround code and common init code: Workaround goes to zephyr/project/corsola, and limit its access to Krabby and Tentacruel only. BUG=none TEST=manually check charger works fine on tentacruel BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: Ieb7526f9e8aa36ac8457a6388f427a63ce4a105e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3853777 Reviewed-by: Eric Yilun Lin <yllin@google.com> Tested-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--driver/charger/rt9490.c9
-rw-r--r--zephyr/projects/corsola/src/krabby/charger_workaround.c41
2 files changed, 32 insertions, 18 deletions
diff --git a/driver/charger/rt9490.c b/driver/charger/rt9490.c
index a7f5fd28e3..204949abde 100644
--- a/driver/charger/rt9490.c
+++ b/driver/charger/rt9490.c
@@ -311,11 +311,6 @@ static int rt9490_init_setting(int chgnum)
/* Disable AUTO_AICR / AUTO_MIVR */
RETURN_ERROR(rt9490_clr_bit(chgnum, RT9490_REG_ADD_CTRL0,
RT9490_AUTO_AICR | RT9490_AUTO_MIVR));
- /* Disable charge timer */
- RETURN_ERROR(rt9490_clr_bit(chgnum, RT9490_REG_SAFETY_TMR_CTRL,
- RT9490_EN_TRICHG_TMR |
- RT9490_EN_PRECHG_TMR |
- RT9490_EN_FASTCHG_TMR));
RETURN_ERROR(rt9490_set_mivr(chgnum, default_init_setting.mivr));
RETURN_ERROR(rt9490_set_ieoc(chgnum, default_init_setting.eoc_current));
RETURN_ERROR(rt9490_set_iprec(chgnum, batt_info->precharge_current));
@@ -339,6 +334,10 @@ static int rt9490_init_setting(int chgnum)
RT9490_CHG_IRQ_MASK4_ALL));
RETURN_ERROR(rt9490_set_bit(chgnum, RT9490_REG_CHG_IRQ_MASK5,
RT9490_CHG_IRQ_MASK5_ALL));
+ /* Reduce SW freq from 1.5MHz to 1MHz
+ * for 10% higher current rating b/215294785
+ */
+ RETURN_ERROR(rt9490_enable_pwm_1mhz(CHARGER_SOLO, true));
return EC_SUCCESS;
}
diff --git a/zephyr/projects/corsola/src/krabby/charger_workaround.c b/zephyr/projects/corsola/src/krabby/charger_workaround.c
index 3001327ed8..07a4379737 100644
--- a/zephyr/projects/corsola/src/krabby/charger_workaround.c
+++ b/zephyr/projects/corsola/src/krabby/charger_workaround.c
@@ -3,12 +3,22 @@
* found in the LICENSE file.
*/
+#include <zephyr/sys/util.h>
+
#include "charger.h"
#include "driver/charger/rt9490.h"
#include "hooks.h"
#include "i2c.h"
#include "system.h"
+/*
+ * This workaround and the board id checks only apply to krabby and early
+ * tentacruel devices.
+ * Newer project should have all of these fixed.
+ */
+BUILD_ASSERT(IS_ENABLED(CONFIG_BOARD_KRABBY) ||
+ IS_ENABLED(CONFIG_BOARD_TENTACRUEL));
+
static void enter_hidden_mode(void)
{
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
@@ -42,10 +52,10 @@ static void ibus_adc_workaround(void)
/* b/214880220#comment44: lock i2c at 400khz */
static void i2c_speed_workaround(void)
{
- /*
- * This workaround can be applied to all version of RT9490 in our cases
- * no need to identify chip version.
- */
+ if (system_get_board_version() >= 3) {
+ return;
+ }
+
enter_hidden_mode();
/* Set to Auto mode, default run at 400kHz */
i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
@@ -55,14 +65,6 @@ static void i2c_speed_workaround(void)
chg_chips[CHARGER_SOLO].i2c_addr_flags, 0xF7, 0x14);
}
-static void pwm_freq_workaround(void)
-{
- /* Reduce SW freq from 1.5MHz to 1MHz
- * for 10% higher current rating b/215294785
- */
- rt9490_enable_pwm_1mhz(CHARGER_SOLO, true);
-}
-
static void eoc_deglitch_workaround(void)
{
if (system_get_board_version() != 1) {
@@ -75,11 +77,24 @@ static void eoc_deglitch_workaround(void)
RT9490_REG_ADD_CTRL0, RT9490_TD_EOC, MASK_CLR);
}
+static void disable_safety_timer(void)
+{
+ if (system_get_board_version() >= 2) {
+ return;
+ }
+ /* Disable charge timer */
+ i2c_write8(chg_chips[CHARGER_SOLO].i2c_port,
+ chg_chips[CHARGER_SOLO].i2c_addr_flags,
+ RT9490_REG_SAFETY_TMR_CTRL,
+ RT9490_EN_TRICHG_TMR | RT9490_EN_PRECHG_TMR |
+ RT9490_EN_FASTCHG_TMR);
+}
+
static void board_rt9490_workaround(void)
{
ibus_adc_workaround();
i2c_speed_workaround();
- pwm_freq_workaround();
eoc_deglitch_workaround();
+ disable_safety_timer();
}
DECLARE_HOOK(HOOK_INIT, board_rt9490_workaround, HOOK_PRIO_DEFAULT);