diff options
author | johnwc_yeh <johnwc_yeh@compal.corp-partner.google.com> | 2022-07-12 17:11:56 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-15 06:48:30 +0000 |
commit | 00217da2382ece25159e91e74b50b05a89eb83a5 (patch) | |
tree | a8c7e6594d77becc6ade27e759bc3efbe25a4a95 /driver | |
parent | 206b8c67919c3d00dcfc493388093989af1c6ff8 (diff) | |
download | chrome-ec-00217da2382ece25159e91e74b50b05a89eb83a5.tar.gz |
BB retimer: Add bb retimer usb3 state enable
The bb retimer usb3 state can be set to enable/disable.
Add mutexing access to the BB_RETIMER_REG_CONNECTION_STATE register.
BUG=b:233975818
BRANCH=None
TEST=build make -j BOARD=Banshee pass
Signed-off-by: johnwc_yeh <johnwc_yeh@compal.corp-partner.google.com>
Change-Id: Ie59223ac23d5380a52de0189b27fd12eeb81ec89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756998
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/retimer/bb_retimer.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/driver/retimer/bb_retimer.c b/driver/retimer/bb_retimer.c index d57c1318e5..add245cb08 100644 --- a/driver/retimer/bb_retimer.c +++ b/driver/retimer/bb_retimer.c @@ -37,6 +37,12 @@ #define BB_RETIMER_I2C_RETRY 5 +/* + * Mutex for BB_RETIMER_REG_CONNECTION_STATE register, which can be + * accessed from multiple tasks. + */ +K_MUTEX_DEFINE(bb_retimer_state_mutex); + /** * Utility functions */ @@ -376,10 +382,13 @@ static int retimer_set_state(const struct usb_mux *me, mux_state_t mux_state, uint32_t set_retimer_con = 0; uint8_t dp_pin_mode; int port = me->usb_port; + int rv = 0; /* This driver does not use host command ACKs */ *ack_required = false; + mutex_lock(&bb_retimer_state_mutex); + /* * Bit 0: DATA_CONNECTION_PRESENT * 0 - No connection present @@ -464,8 +473,10 @@ static int retimer_set_state(const struct usb_mux *me, mux_state_t mux_state, retimer_set_state_ufp(port, mux_state, &set_retimer_con); /* Writing the register4 */ - return bb_retimer_write(me, BB_RETIMER_REG_CONNECTION_STATE, - set_retimer_con); + rv = bb_retimer_write(me, BB_RETIMER_REG_CONNECTION_STATE, + set_retimer_con); + mutex_unlock(&bb_retimer_state_mutex); + return rv; } void bb_retimer_hpd_update(const struct usb_mux *me, mux_state_t mux_state, @@ -476,10 +487,13 @@ void bb_retimer_hpd_update(const struct usb_mux *me, mux_state_t mux_state, /* This driver does not use host command ACKs */ *ack_required = false; + mutex_lock(&bb_retimer_state_mutex); + if (bb_retimer_read(me, BB_RETIMER_REG_CONNECTION_STATE, - &retimer_con_reg) != EC_SUCCESS) + &retimer_con_reg) != EC_SUCCESS) { + mutex_unlock(&bb_retimer_state_mutex); return; - + } /* * Bit 14: IRQ_HPD (ignored if BIT8 = 0) * 0 - No IRQ_HPD @@ -514,6 +528,31 @@ void bb_retimer_hpd_update(const struct usb_mux *me, mux_state_t mux_state, /* Writing the register4 */ bb_retimer_write(me, BB_RETIMER_REG_CONNECTION_STATE, retimer_con_reg); + + mutex_unlock(&bb_retimer_state_mutex); +} + +void bb_retimer_set_usb3(const struct usb_mux *me, bool enable) +{ + int rv; + uint32_t reg_val = 0; + + mutex_lock(&bb_retimer_state_mutex); + + rv = bb_retimer_read(me, BB_RETIMER_REG_CONNECTION_STATE, ®_val); + if (rv != EC_SUCCESS) { + mutex_unlock(&bb_retimer_state_mutex); + return; + } + /* Bit 5: USB_3_CONNECTION */ + WRITE_BIT(reg_val, 5, enable); + rv = bb_retimer_write(me, BB_RETIMER_REG_CONNECTION_STATE, reg_val); + if (rv != EC_SUCCESS) { + mutex_unlock(&bb_retimer_state_mutex); + return; + } + + mutex_unlock(&bb_retimer_state_mutex); } static int retimer_low_power_mode(const struct usb_mux *me) |