diff options
author | Tomasz Michalec <tm@semihalf.com> | 2022-03-10 17:28:30 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-03-18 14:21:30 +0000 |
commit | 271ce65664e6db2d39bb6946ebc9cd9ad94762f3 (patch) | |
tree | fb9233dd755baf666f7550308fc416e620776e88 | |
parent | 5402491430b781153ce4d0903f3bb4c40bea53d9 (diff) | |
download | chrome-ec-271ce65664e6db2d39bb6946ebc9cd9ad94762f3.tar.gz |
zephyr: emul: Add support for reset message from partner
Add support in TCPCI emulator to send HardReset and CableReset from
partner emulator. These two messages are handled differently and
require additional actions in TCPCI upon receiving.
BUG=b:223766685
BRANCH=none
TEST=zmake configure --test test-drivers
Signed-off-by: Tomasz Michalec <tm@semihalf.com>
Change-Id: I1adfdb7dc363fedd62937e76f66862aa32f9eceb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3528404
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Tomasz Michalec <tmichalec@google.com>
Tested-by: Tomasz Michalec <tmichalec@google.com>
-rw-r--r-- | zephyr/emul/tcpc/emul_tcpci.c | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c index 3681109267..eb94aaae98 100644 --- a/zephyr/emul/tcpc/emul_tcpci.c +++ b/zephyr/emul/tcpc/emul_tcpci.c @@ -290,6 +290,23 @@ static int tcpci_emul_get_next_rx_msg(const struct emul *emul) } /** + * @brief Reset mask registers that are reset upon receiving or transmitting + * Hard Reset message. + * + * @param emul Pointer to TCPCI emulator + */ +static void tcpci_emul_reset_mask_regs(const struct emul *emul) +{ + struct tcpci_emul_data *data = emul->data; + + data->reg[TCPC_REG_ALERT_MASK] = 0xff; + data->reg[TCPC_REG_ALERT_MASK + 1] = 0x7f; + data->reg[TCPC_REG_POWER_STATUS_MASK] = 0xff; + data->reg[TCPC_REG_EXT_STATUS_MASK] = 0x01; + data->reg[TCPC_REG_ALERT_EXTENDED_MASK] = 0x07; +} + +/** * @brief Perform actions that are expected by TCPC on disabling PD message * delivery (clear RECEIVE_DETECT register and clear already received * messages in buffer) @@ -312,6 +329,7 @@ int tcpci_emul_add_rx_msg(const struct emul *emul, uint16_t rx_detect_mask; uint16_t rx_detect; uint16_t dev_cap_2; + uint16_t alert_reg; int rc; /* Acquire lock to prevent race conditions with TCPM accessing I2C */ @@ -358,6 +376,27 @@ int tcpci_emul_add_rx_msg(const struct emul *emul, return TCPCI_EMUL_TX_FAILED; } + tcpci_emul_get_reg(emul, TCPC_REG_ALERT, &alert_reg); + + /* Handle HardReset */ + if (rx_msg->type == TCPCI_MSG_TX_HARD_RESET) { + tcpci_emul_disable_pd_msg_delivery(emul); + tcpci_emul_reset_mask_regs(emul); + + alert_reg |= TCPC_REG_ALERT_RX_HARD_RST; + tcpci_emul_set_reg(emul, TCPC_REG_ALERT, alert_reg); + rc = tcpci_emul_alert_changed(emul); + + i2c_common_emul_unlock_data(&data->common.emul); + return rc; + } + + /* Handle CableReset */ + if (rx_msg->type == TCPCI_MSG_CABLE_RESET) { + tcpci_emul_disable_pd_msg_delivery(emul); + /* Rest of CableReset handling is the same as SOP* message */ + } + if (data->rx_msg == NULL) { tcpci_emul_get_reg(emul, TCPC_REG_DEV_CAP_2, &dev_cap_2); if ((!(dev_cap_2 & TCPC_REG_DEV_CAP_2_LONG_MSG) && @@ -377,8 +416,7 @@ int tcpci_emul_add_rx_msg(const struct emul *emul, data->rx_msg->next = rx_msg; if (alert) { - data->reg[TCPC_REG_ALERT + 1] |= - TCPC_REG_ALERT_RX_BUF_OVF >> 8; + alert_reg |= TCPC_REG_ALERT_RX_BUF_OVF; } } else { LOG_ERR("Cannot setup third message"); @@ -388,11 +426,11 @@ int tcpci_emul_add_rx_msg(const struct emul *emul, if (alert) { if (rx_msg->cnt > 133) { - data->reg[TCPC_REG_ALERT + 1] |= - TCPC_REG_ALERT_RX_BEGINNING >> 8; + alert_reg |= TCPC_REG_ALERT_RX_BEGINNING; } - data->reg[TCPC_REG_ALERT] |= TCPC_REG_ALERT_RX_STATUS; + alert_reg |= TCPC_REG_ALERT_RX_STATUS; + tcpci_emul_set_reg(emul, TCPC_REG_ALERT, alert_reg); rc = tcpci_emul_alert_changed(emul); if (rc != 0) { @@ -750,23 +788,6 @@ static void tcpci_emul_reset_role_ctrl(const struct emul *emul) } /** - * @brief Reset mask registers that are reset upon receiving or transmitting - * Hard Reset message. - * - * @param emul Pointer to TCPCI emulator - */ -static void tcpci_emul_reset_mask_regs(const struct emul *emul) -{ - struct tcpci_emul_data *data = emul->data; - - data->reg[TCPC_REG_ALERT_MASK] = 0xff; - data->reg[TCPC_REG_ALERT_MASK + 1] = 0x7f; - data->reg[TCPC_REG_POWER_STATUS_MASK] = 0xff; - data->reg[TCPC_REG_EXT_STATUS_MASK] = 0x01; - data->reg[TCPC_REG_ALERT_EXTENDED_MASK] = 0x07; -} - -/** * @brief Reset registers to default values. Vendor and reserved registers * are not changed. * |