summaryrefslogtreecommitdiff
path: root/zephyr/include/emul/tcpc/emul_tcpci_partner_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/include/emul/tcpc/emul_tcpci_partner_common.h')
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_common.h172
1 files changed, 126 insertions, 46 deletions
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_common.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_common.h
index 4988c48576..fb715a47dc 100644
--- a/zephyr/include/emul/tcpc/emul_tcpci_partner_common.h
+++ b/zephyr/include/emul/tcpc/emul_tcpci_partner_common.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -14,6 +14,7 @@
#include <zephyr/drivers/emul.h>
#include <zephyr/kernel.h>
+#include <zephyr/sys/atomic.h>
#include <stdbool.h>
#include <stdint.h>
@@ -31,21 +32,20 @@
*/
/** Timeout for other side to respond to PD message */
-#define TCPCI_PARTNER_RESPONSE_TIMEOUT_MS 30
-#define TCPCI_PARTNER_RESPONSE_TIMEOUT \
- K_MSEC(TCPCI_PARTNER_RESPONSE_TIMEOUT_MS)
+#define TCPCI_PARTNER_RESPONSE_TIMEOUT_MS 30
+#define TCPCI_PARTNER_RESPONSE_TIMEOUT K_MSEC(TCPCI_PARTNER_RESPONSE_TIMEOUT_MS)
/** Timeout for source to transition to requested state after accept */
-#define TCPCI_PARTNER_TRANSITION_TIMEOUT_MS 550
-#define TCPCI_PARTNER_TRANSITION_TIMEOUT \
- K_MSEC(TCPCI_PARTNER_TRANSITION_TIMEOUT_MS)
+#define TCPCI_PARTNER_TRANSITION_TIMEOUT_MS 550
+#define TCPCI_PARTNER_TRANSITION_TIMEOUT \
+ K_MSEC(TCPCI_PARTNER_TRANSITION_TIMEOUT_MS)
/** Timeout for source to send capability again after failure */
-#define TCPCI_SOURCE_CAPABILITY_TIMEOUT_MS 150
-#define TCPCI_SOURCE_CAPABILITY_TIMEOUT \
- K_MSEC(TCPCI_SOURCE_CAPABILITY_TIMEOUT_MS)
+#define TCPCI_SOURCE_CAPABILITY_TIMEOUT_MS 150
+#define TCPCI_SOURCE_CAPABILITY_TIMEOUT \
+ K_MSEC(TCPCI_SOURCE_CAPABILITY_TIMEOUT_MS)
/** Timeout for source to send capability message after power swap */
-#define TCPCI_SWAP_SOURCE_START_TIMEOUT_MS 20
-#define TCPCI_SWAP_SOURCE_START_TIMEOUT \
- K_MSEC(TCPCI_SWAP_SOURCE_START_TIMEOUT_MS)
+#define TCPCI_SWAP_SOURCE_START_TIMEOUT_MS 20
+#define TCPCI_SWAP_SOURCE_START_TIMEOUT \
+ K_MSEC(TCPCI_SWAP_SOURCE_START_TIMEOUT_MS)
/** Common data for TCPCI partner device emulators */
struct tcpci_partner_data {
@@ -64,9 +64,13 @@ struct tcpci_partner_data {
/** Mutex for to_send queue */
struct k_mutex to_send_mutex;
/** Next SOP message id */
- int msg_id;
+ int sop_msg_id;
+ /** Next SOP' message id */
+ int sop_prime_msg_id;
/** Last received message id */
- int recv_msg_id;
+ int sop_recv_msg_id;
+ /** Last received SOP' message id */
+ int sop_prime_recv_msg_id;
/** Power role (used in message header) */
enum pd_power_role power_role;
/** Data role (used in message header) */
@@ -100,7 +104,7 @@ struct tcpci_partner_data {
*/
bool in_soft_reset;
/** Current AMS Control request being handled */
- enum pd_ctrl_msg_type cur_ams_ctrl_req;
+ enum pd_ctrl_msg_type cur_ams_ctrl_req;
/**
* If common code should send GoodCRC for each message. If false,
* then one of extensions should call tcpci_emul_partner_msg_status().
@@ -129,6 +133,15 @@ struct tcpci_partner_data {
* any status to received message.
*/
enum tcpci_emul_tx_status *received_msg_status;
+ /** Whether port partner is configured in DisplayPort mode */
+ bool displayport_configured;
+ /** The number of Enter Mode REQs received since connection
+ * or the last Hard Reset, whichever was more recent.
+ */
+ atomic_t mode_enter_attempts;
+ /* SVID of entered mode (0 if no mode is entered) */
+ uint16_t entered_svid;
+
/* VDMs with which the partner responds to discovery REQs. The VDM
* buffers include the VDM header, and the VDO counts include 1 for the
* VDM header. This structure has space for the mode response for a
@@ -140,6 +153,49 @@ struct tcpci_partner_data {
int svids_vdos;
uint32_t modes_vdm[VDO_MAX_SIZE];
int modes_vdos;
+ /* VDMs sent when responding to a mode entry command */
+ uint32_t enter_mode_vdm[VDO_MAX_SIZE];
+ int enter_mode_vdos;
+ /* VDMs sent when responding to DisplayPort status update command */
+ uint32_t dp_status_vdm[VDO_MAX_SIZE];
+ int dp_status_vdos;
+ /* VDMs sent when responding to DisplayPort config command */
+ uint32_t dp_config_vdm[VDO_MAX_SIZE];
+ int dp_config_vdos;
+ struct {
+ /* Index of the last battery we requested capabilities for. The
+ * BCDB response does not include the index so we need to track
+ * it manually. -1 indicates no outstanding request.
+ */
+ int index;
+ /* Stores Battery Capability Data Blocks (BCDBs) requested and
+ * received from the TCPM for later analysis. See USB-PD spec
+ * Rev 3.1, Ver 1.3 section 6.5.5
+ */
+ struct pd_bcdb bcdb[PD_BATT_MAX];
+ /* Stores a boolean status for each battery index indicating
+ * whether we have received a BCDB response for that battery.
+ */
+ bool have_response[PD_BATT_MAX];
+ } battery_capabilities;
+
+ /*
+ * Cable which is "plugged in" to this port partner
+ * Note: Much as in real life, cable should be attached before the port
+ * partner can be plugged in to properly discover its information.
+ * For tests, this means this poitner should be set before connecting
+ * the source or sink partner.
+ */
+ struct tcpci_cable_data *cable;
+};
+
+struct tcpci_cable_data {
+ /*
+ * Identity VDM ACKs which the cable is expected to send
+ * These include the VDM header
+ */
+ uint32_t identity_vdm[VDO_MAX_SIZE];
+ int identity_vdos;
};
/** Structure of message used by TCPCI partner emulator */
@@ -150,10 +206,17 @@ struct tcpci_partner_msg {
struct tcpci_emul_msg msg;
/** Time when message should be sent if message is delayed */
uint64_t time;
- /** Type of the message */
+ /** Message type that is placed in the Message Header. Its meaning
+ * depends on the class of message:
+ * - for Control Messages, see `enum pd_ctrl_msg_type`
+ * - for Data Messages, see `enum pd_data_msg_type`
+ * - for Extended Messages, see `enum pd_ext_msg_type`
+ */
int type;
/** Number of data objects */
int data_objects;
+ /** True if this is an extended message */
+ bool extended;
};
/** Identify sender of logged PD message */
@@ -184,7 +247,8 @@ struct tcpci_partner_log_msg {
enum tcpci_partner_handler_res {
TCPCI_PARTNER_COMMON_MSG_HANDLED,
TCPCI_PARTNER_COMMON_MSG_NOT_HANDLED,
- TCPCI_PARTNER_COMMON_MSG_HARD_RESET
+ TCPCI_PARTNER_COMMON_MSG_HARD_RESET,
+ TCPCI_PARTNER_COMMON_MSG_NO_GOODCRC,
};
/** Structure of TCPCI partner extension */
@@ -230,9 +294,8 @@ struct tcpci_partner_extension_ops {
* @param ext Pointer to partner extension
* @param common_data Pointer to TCPCI partner emulator
*/
- void (*hard_reset)(
- struct tcpci_partner_extension *ext,
- struct tcpci_partner_data *common_data);
+ void (*hard_reset)(struct tcpci_partner_extension *ext,
+ struct tcpci_partner_data *common_data);
/**
* @brief Function called when SoftReset message is received
@@ -240,9 +303,8 @@ struct tcpci_partner_extension_ops {
* @param ext Pointer to partner extension
* @param common_data Pointer to TCPCI partner emulator
*/
- void (*soft_reset)(
- struct tcpci_partner_extension *ext,
- struct tcpci_partner_data *common_data);
+ void (*soft_reset)(struct tcpci_partner_extension *ext,
+ struct tcpci_partner_data *common_data);
/**
* @brief Function called when partner emulator is disconnected from
@@ -251,9 +313,8 @@ struct tcpci_partner_extension_ops {
* @param ext Pointer to partner extension
* @param common_data Pointer to TCPCI partner emulator
*/
- void (*disconnect)(
- struct tcpci_partner_extension *ext,
- struct tcpci_partner_data *common_data);
+ void (*disconnect)(struct tcpci_partner_extension *ext,
+ struct tcpci_partner_data *common_data);
/**
* @brief Function called when partner emulator is connected to TCPM.
@@ -265,9 +326,8 @@ struct tcpci_partner_extension_ops {
* @return Negative value on error
* @return 0 on success
*/
- int (*connect)(
- struct tcpci_partner_extension *ext,
- struct tcpci_partner_data *common_data);
+ int (*connect)(struct tcpci_partner_extension *ext,
+ struct tcpci_partner_data *common_data);
};
/**
@@ -280,17 +340,6 @@ struct tcpci_partner_extension_ops {
void tcpci_partner_init(struct tcpci_partner_data *data, enum pd_rev_type rev);
/**
- * @brief Allocate message with space for header and given number of data
- * objects. Type of message is set to TCPCI_MSG_SOP by default.
- *
- * @param data_objects Number of data objects in message
- *
- * @return Pointer to new message on success
- * @return NULL on error
- */
-struct tcpci_partner_msg *tcpci_partner_alloc_msg(int data_objects);
-
-/**
* @brief Free message's memory
*
* @param msg Pointer to message
@@ -336,8 +385,7 @@ int tcpci_partner_send_msg(struct tcpci_partner_data *data,
* @return negative on failure
*/
int tcpci_partner_send_control_msg(struct tcpci_partner_data *data,
- enum pd_ctrl_msg_type type,
- uint64_t delay);
+ enum pd_ctrl_msg_type type, uint64_t delay);
/**
* @brief Send data message with optional delay. Data objects are copied to
@@ -356,9 +404,22 @@ int tcpci_partner_send_control_msg(struct tcpci_partner_data *data,
* @return negative on failure
*/
int tcpci_partner_send_data_msg(struct tcpci_partner_data *data,
- enum pd_data_msg_type type,
- uint32_t *data_obj, int data_obj_num,
- uint64_t delay);
+ enum pd_data_msg_type type, uint32_t *data_obj,
+ int data_obj_num, uint64_t delay);
+
+/**
+ * @brief Send an extended PD message to the port partner
+ *
+ * @param data Pointer to TCPCI partner emulator
+ * @param type Extended message type
+ * @param delay Message send delay in milliseconds, or zero for no delay.
+ * @param payload Pointer to data payload. Does not include any headers.
+ * @param payload_size Number of bytes in above payload
+ * @return negative on failure, 0 on success
+ */
+int tcpci_partner_send_extended_msg(struct tcpci_partner_data *data,
+ enum pd_ext_msg_type type, uint64_t delay,
+ uint8_t *payload, size_t payload_size);
/**
* @brief Remove all messages that are in delayed message queue
@@ -387,6 +448,25 @@ void tcpci_partner_common_send_hard_reset(struct tcpci_partner_data *data);
void tcpci_partner_common_send_soft_reset(struct tcpci_partner_data *data);
/**
+ * @brief Send a Get Battery Capabilities request to the TCPM
+ *
+ * @param data Pointer to TCPCI partner emulator
+ * @param battery_index Request capability info on this battery. Must
+ * be (0 <= battery_index < PD_BATT_MAX)
+ */
+void tcpci_partner_common_send_get_battery_capabilities(
+ struct tcpci_partner_data *data, int battery_index);
+
+/**
+ * @brief Resets the data structure used for tracking battery capability
+ * requests and responses.
+ *
+ * @param data Emulator state
+ */
+void tcpci_partner_reset_battery_capability_state(
+ struct tcpci_partner_data *data);
+
+/**
* @brief Start sender response timer for TCPCI_PARTNER_RESPONSE_TIMEOUT_MS.
* If @ref tcpci_partner_stop_sender_response_timer wasn't called before
* timeout, @ref tcpci_partner_sender_response_timeout is called.