diff options
author | Peter Marheine <pmarheine@chromium.org> | 2023-02-16 00:14:21 +0000 |
---|---|---|
committer | Peter Marheine <pmarheine@chromium.org> | 2023-02-16 00:14:21 +0000 |
commit | f43d6df6f2860dbe8ec15aebdc28890771ad7897 (patch) | |
tree | 6877eff7016f9979e46017ea5221a16d36344304 /driver/ppc/rt1739.c | |
parent | dce247e97903a2464ff8884106bffa43587c1dcb (diff) | |
parent | 0849542c72359150a357945c010dca6b5a213633 (diff) | |
download | chrome-ec-f43d6df6f2860dbe8ec15aebdc28890771ad7897.tar.gz |
Merge remote-tracking branch cros/main into firmware-nissa-15217.B-mainfirmware-nissa-15217.126.B-main
Generated by: ./util/update_release_branch.py --zephyr --board nissa firmware-
nissa-15217.B-main
Relevant changes:
git log --oneline dce247e979..0849542c72 -- zephyr/program/nissa
util/getversion.sh
0849542c72 zephyr: add sleep property for keyboard factory test
5825d894b9 nissa: disable PLATFORM_EC_TCPC_INTERRUPT
25a400690f yavikso: Update fan table version 3
9263f14536 zephyr: remove shi node and add references to shi0
b40c6970d3 Craask: Charger limit for 65w adapter
6fd2d3ea6c zephyr: add comments for tcpc driver
00986ffb1c zephyr: move usbc interrupt handler to shim
2508094b14 yaviks: reduce RW image size (64KB)
55b6aaf52f yaviks: enable keyboard factory test
4786d1eac6 nissa: Add ocpc init function to Nissa boards
2ae1083638 zephyr: cros_kb: set KSI/KSO kbs mode by pinctrl driver
d415f4665a yaviks: Fix OCPC Vsys overshooting
93f9d42a7c zephyr: config: drop few more redundant options
BRANCH=None
BUG=b:254148652 b:260762509 b:265220075 b:268273712 b:265763662
BUG=b:253557900 b:254148652 b:269212593 b:267404783 b:262352202
TEST=`make -j buildall`
Force-Relevant-Builds: all
Change-Id: I195dd82af114180b611f9afd1465a69f7f43d417
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Diffstat (limited to 'driver/ppc/rt1739.c')
-rw-r--r-- | driver/ppc/rt1739.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/driver/ppc/rt1739.c b/driver/ppc/rt1739.c index 6a6e718c0c..e85f4f6202 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" @@ -89,19 +90,26 @@ static int rt1739_vbus_sink_enable(int port, int enable) #ifdef CONFIG_CMD_PPC_DUMP static int rt1739_dump(int port) { + ccprintf(" "); + for (int i = 0; i < 16; i++) { + ccprintf("%2X ", i); + } + ccprintf("\n"); + for (int i = 0; i <= 0x61; i++) { int val = 0; int rt = read_reg(port, i, &val); if (i % 16 == 0) - CPRINTF("%02X: ", i); + ccprintf("%02X: ", i); if (rt) - CPRINTF("-- "); + ccprintf("-- "); else - CPRINTF("%02X ", val); + ccprintf("%02X ", val); if (i % 16 == 15) - CPRINTF("\n"); + ccprintf("\n"); } + ccprintf("\n"); return EC_SUCCESS; } @@ -240,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)); @@ -278,6 +316,7 @@ static int rt1739_init(int port) return EC_SUCCESS; } +#ifdef CONFIG_USB_CHARGER static int rt1739_get_bc12_ilim(int charge_supplier) { switch (charge_supplier) { @@ -375,6 +414,7 @@ static void rt1739_usb_charger_task_event(const int port, uint32_t evt) rt1739_enable_bc12_detection(port, false); } } +#endif /* CONFIG_USB_CHARGER */ static atomic_t pending_events; @@ -396,8 +436,10 @@ void rt1739_deferred_interrupt(void) if (read_reg(port, RT1739_REG_INT_EVENT5, &event5)) continue; +#ifdef CONFIG_USB_CHARGER if (event5 & RT1739_BC12_SNK_DONE_INT) usb_charger_task_set_event(port, USB_CHG_EVENT_BC12); +#endif /* CONFIG_USB_CHARGER */ /* write to clear EVENT4 since FRS interrupt has been handled */ write_reg(port, RT1739_REG_INT_EVENT4, event4); @@ -438,6 +480,7 @@ const struct ppc_drv rt1739_ppc_drv = { .interrupt = &rt1739_interrupt, }; +#ifdef CONFIG_USB_CHARGER const struct bc12_drv rt1739_bc12_drv = { .usb_charger_task_init = rt1739_usb_charger_task_init, .usb_charger_task_event = rt1739_usb_charger_task_event, @@ -451,3 +494,4 @@ struct bc12_config bc12_ports[CHARGE_PORT_COUNT] = { }, }; #endif /* CONFIG_BC12_SINGLE_DRIVER */ +#endif /* CONFIG_USB_CHARGER */ |