summaryrefslogtreecommitdiff
path: root/driver/ppc/rt1739.c
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2023-02-07 16:39:20 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-08 05:50:32 +0000
commitefaba4f3b6d014fd77782e35b6a184d39c6c50b4 (patch)
tree4f87e0697ba118a75d137e9ce6c9e7c70e046cdf /driver/ppc/rt1739.c
parentf0a70403e25db4affec4e81405907876f38f39ee (diff)
downloadchrome-ec-efaba4f3b6d014fd77782e35b6a184d39c6c50b4.tar.gz
ppc/rt1739: implement dead battery boot
If rt1739 seems to be the only power source of the system, don't turn off its HV sink path. BUG=b:267412033 TEST=Verify that PPC is able to supply power in follow scenarios: 1) power on without battery 2) sysjump without battery 3) ec reset without battery BRANCH=none LOW_COVERAGE_REASON=early bringup Change-Id: I13d291edfc78f6e1491b3c4a0d8e2e661925004d Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4225988 Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@google.com> Tested-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'driver/ppc/rt1739.c')
-rw-r--r--driver/ppc/rt1739.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/driver/ppc/rt1739.c b/driver/ppc/rt1739.c
index 8412a3937f..c660320b9b 100644
--- a/driver/ppc/rt1739.c
+++ b/driver/ppc/rt1739.c
@@ -5,6 +5,7 @@
/* Richtek RT1739 USB-C Power Path Controller */
#include "atomic.h"
+#include "battery.h"
#include "common.h"
#include "config.h"
#include "console.h"
@@ -247,12 +248,42 @@ static int rt1739_set_frs_enable(int port, int enable)
static int rt1739_init(int port)
{
- int device_id, oc_setting;
+ int device_id, oc_setting, sys_ctrl, vbus_switch_ctrl;
+ bool batt_connected = false;
atomic_clear(&flags[port]);
- RETURN_ERROR(write_reg(port, RT1739_REG_SW_RESET, RT1739_SW_RESET));
- usleep(1 * MSEC);
+ RETURN_ERROR(read_reg(port, RT1739_REG_SYS_CTRL, &sys_ctrl));
+ RETURN_ERROR(
+ read_reg(port, RT1739_REG_VBUS_SWITCH_CTRL, &vbus_switch_ctrl));
+
+ if (IS_ENABLED(CONFIG_BATTERY_FUEL_GAUGE)) {
+ batt_connected = (battery_get_disconnect_state() ==
+ BATTERY_NOT_DISCONNECTED);
+ }
+
+ if (sys_ctrl & RT1739_DEAD_BATTERY) {
+ /*
+ * Dead battery boot, see b/267412033#comment6 for the init
+ * sequence.
+ */
+ RETURN_ERROR(
+ write_reg(port, RT1739_REG_SYS_CTRL,
+ RT1739_DEAD_BATTERY | RT1739_SHUTDOWN_OFF));
+ rt1739_vbus_sink_enable(port, true);
+ RETURN_ERROR(write_reg(port, RT1739_REG_SYS_CTRL,
+ RT1739_OT_EN | RT1739_SHUTDOWN_OFF));
+ } else if (batt_connected || !(vbus_switch_ctrl & RT1739_HV_SNK_EN)) {
+ /*
+ * If rt1739 is not sinking, or there's a working battery,
+ * we can reset its registers safely.
+ *
+ * Otherwise, don't touch the VBUS_SWITCH_CTRL reg.
+ */
+ RETURN_ERROR(
+ write_reg(port, RT1739_REG_SW_RESET, RT1739_SW_RESET));
+ usleep(1 * MSEC);
+ }
RETURN_ERROR(write_reg(port, RT1739_REG_SYS_CTRL,
RT1739_OT_EN | RT1739_SHUTDOWN_OFF));