diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2023-01-12 16:16:52 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-13 10:41:56 +0000 |
commit | 59464159ceb76c39dbcbb057acdafd19cc794e17 (patch) | |
tree | f14c352b70d3dafae034b131f76f0e60ae1e33e2 | |
parent | 49abac39678928a242f94115f523ba462146412a (diff) | |
download | chrome-ec-59464159ceb76c39dbcbb057acdafd19cc794e17.tar.gz |
syv682x: cached force discharge config
syv682x vbus discharge function is getting called from
ppc_dev_is_connected to reset the discharge config many times.
We cached the force discharge config to reduce the i2c traffics
on IT81202 i2c ports.
BUG=none
TEST=i2c traffic reduces. FRS is working.
BRANCH=none
Change-Id: Iebae413d8f6621b8c99dc28c744220f54d420062
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4160813
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Auto-Submit: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Commit-Queue: Eric Yilun Lin <yllin@google.com>
-rw-r--r-- | driver/ppc/syv682x.c | 16 | ||||
-rw-r--r-- | zephyr/test/drivers/default/src/ppc_syv682x.c | 12 |
2 files changed, 25 insertions, 3 deletions
diff --git a/driver/ppc/syv682x.c b/driver/ppc/syv682x.c index 42488a4a26..85c781a488 100644 --- a/driver/ppc/syv682x.c +++ b/driver/ppc/syv682x.c @@ -150,6 +150,15 @@ static int syv682x_discharge_vbus(int port, int enable) #ifndef CONFIG_USBC_PPC_SYV682X_SMART_DISCHARGE int regval; int rv; + /* cached force discharge flag to reduce the call to the discharge + * function. + */ + static uint8_t sd_flags[CONFIG_USB_PD_PORT_MAX_COUNT] = { + [0 ... CONFIG_USB_PD_PORT_MAX_COUNT - 1] = 0xFF + }; + + if ((!!enable) == sd_flags[port]) + return EC_SUCCESS; rv = read_reg(port, SYV682X_CONTROL_2_REG, ®val); if (rv) @@ -160,7 +169,12 @@ static int syv682x_discharge_vbus(int port, int enable) else regval &= ~SYV682X_CONTROL_2_FDSG; - return write_reg(port, SYV682X_CONTROL_2_REG, regval); + rv = write_reg(port, SYV682X_CONTROL_2_REG, regval); + + if (!rv) + sd_flags[port] = !!enable; + + return rv; #else /* * Smart discharge mode is enabled, nothing to do diff --git a/zephyr/test/drivers/default/src/ppc_syv682x.c b/zephyr/test/drivers/default/src/ppc_syv682x.c index cc5ca49588..6755fa6f56 100644 --- a/zephyr/test/drivers/default/src/ppc_syv682x.c +++ b/zephyr/test/drivers/default/src/ppc_syv682x.c @@ -55,6 +55,14 @@ static void *syv682x_test_setup(void) return &fixture; } +static void syv682x_test_before(void *data) +{ + /* Reset ppc_discharge_vbus to disable to clear the cached force + * discharge bit in the CONTROL_2 register + */ + ppc_discharge_vbus(syv682x_port, false); +} + static void syv682x_test_after(void *data) { struct ppc_syv682x_fixture *fixture = data; @@ -79,8 +87,8 @@ static void syv682x_test_after(void *data) I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST_SUITE(ppc_syv682x, drivers_predicate_post_main, syv682x_test_setup, NULL, - syv682x_test_after, NULL); +ZTEST_SUITE(ppc_syv682x, drivers_predicate_post_main, syv682x_test_setup, + syv682x_test_before, syv682x_test_after, NULL); ZTEST_F(ppc_syv682x, test_syv682x_board_is_syv682c) { |