summaryrefslogtreecommitdiff
path: root/zephyr/include/emul/tcpc
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/include/emul/tcpc')
-rw-r--r--zephyr/include/emul/tcpc/emul_ps8xxx.h13
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci.h278
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_common.h172
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_drp.h14
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_ext.h101
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_snk.h104
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_snk.h19
-rw-r--r--zephyr/include/emul/tcpc/emul_tcpci_partner_src.h14
8 files changed, 424 insertions, 291 deletions
diff --git a/zephyr/include/emul/tcpc/emul_ps8xxx.h b/zephyr/include/emul/tcpc/emul_ps8xxx.h
index aff21e94c7..6e96af571b 100644
--- a/zephyr/include/emul/tcpc/emul_ps8xxx.h
+++ b/zephyr/include/emul/tcpc/emul_ps8xxx.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.
*/
@@ -47,19 +47,20 @@ enum ps8xxx_emul_port {
};
/* For now all devices supported by this emulator has the same FW rev reg */
-#define PS8XXX_REG_FW_REV 0x82
+#define PS8XXX_REG_FW_REV 0x82
/**
- * @brief Get pointer to specific "hidden" I2C device
+ * @brief Get pointer to i2c_common_data for specific "hidden" I2C device
*
* @param emul Pointer to PS8xxx emulator
* @param port Select which "hidden" I2C device should be obtained
*
* @return NULL if given "hidden" I2C device cannot be found
- * @return pointer to "hidden" I2C device
+ * @return pointer to "hidden" device i2c_common_emul_data
*/
-struct i2c_emul *ps8xxx_emul_get_i2c_emul(const struct emul *emul,
- enum ps8xxx_emul_port port);
+struct i2c_common_emul_data *
+ps8xxx_emul_get_i2c_common_data(const struct emul *emul,
+ enum ps8xxx_emul_port port);
/**
* @brief Get pointer to TCPCI emulator that is base for PS8xxx emulator
diff --git a/zephyr/include/emul/tcpc/emul_tcpci.h b/zephyr/include/emul/tcpc/emul_tcpci.h
index dd225c5f6e..8175b9ce96 100644
--- a/zephyr/include/emul/tcpc/emul_tcpci.h
+++ b/zephyr/include/emul/tcpc/emul_tcpci.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.
*/
@@ -17,27 +17,13 @@
#include <zephyr/drivers/i2c_emul.h>
#include <usb_pd_tcpm.h>
+#include "emul/emul_common_i2c.h"
+
/**
- * @brief TCPCI emulator backend API
- * @defgroup tcpci_emul TCPCI emulator
- * @{
- *
- * TCPCI emulator supports access to its registers using I2C messages.
- * It follows Type-C Port Controller Interface Specification. It is possible
- * to use this emulator as base for implementation of specific TCPC emulator
- * which follows TCPCI specification. Emulator allows to set callbacks
- * on change of CC status or transmitting message to implement partner emulator.
- * There is also callback used to inform about alert line state change.
- * Application may alter emulator state:
- *
- * - call @ref tcpci_emul_set_reg and @ref tcpci_emul_get_reg to set and get
- * value of TCPCI registers
- * - call functions from emul_common_i2c.h to setup custom handlers for I2C
- * messages
- * - call @ref tcpci_emul_add_rx_msg to setup received SOP messages
- * - call @ref tcpci_emul_get_tx_msg to examine sended message
- * - call @ref tcpci_emul_set_rev to set revision of emulated TCPCI
+ * Number of emulated register. This include vendor registers defined in TCPCI
+ * specification
*/
+#define TCPCI_EMUL_REG_COUNT 0x100
/** SOP message structure */
struct tcpci_emul_msg {
@@ -46,7 +32,7 @@ struct tcpci_emul_msg {
/** Number of bytes in buf */
int cnt;
/** Type of message (SOP, SOP', etc) */
- uint8_t type;
+ uint8_t sop_type;
/** Index used to mark accessed byte */
int idx;
/** Pointer to optional second message */
@@ -64,6 +50,80 @@ struct tcpci_emul_msg {
typedef void (*tcpci_emul_alert_state_func)(const struct emul *emul, bool alert,
void *data);
+/** Run-time data used by the emulator */
+struct tcpci_ctx {
+ /** Common I2C data for TCPC */
+ struct i2c_common_emul_data common;
+
+ /** Current state of all emulated TCPCI registers */
+ uint8_t reg[TCPCI_EMUL_REG_COUNT];
+
+ /** Structures representing TX and RX buffers */
+ struct tcpci_emul_msg *rx_msg;
+ struct tcpci_emul_msg *tx_msg;
+
+ /** Data that should be written to register (except TX_BUFFER) */
+ uint16_t write_data;
+
+ /** Return error when trying to write to RO register */
+ bool error_on_ro_write;
+ /** Return error when trying to write 1 to reserved bit */
+ bool error_on_rsvd_write;
+
+ /** User function called when alert line could change */
+ tcpci_emul_alert_state_func alert_callback;
+ /** Data passed to alert_callback */
+ void *alert_callback_data;
+
+ /** Callbacks for TCPCI partner */
+ const struct tcpci_emul_partner_ops *partner;
+
+ /** Reference to Alert# GPIO emulator. */
+ const struct device *alert_gpio_port;
+ gpio_pin_t alert_gpio_pin;
+};
+
+/** Run-time data used by the emulator */
+struct tcpc_emul_data {
+ /** Pointer to the common TCPCI emulator context */
+ struct tcpci_ctx *tcpci_ctx;
+
+ /** Pointer to chip specific data */
+ void *chip_data;
+
+ const struct i2c_common_emul_cfg i2c_cfg;
+};
+
+#define TCPCI_EMUL_DEFINE(n, init, cfg_ptr, chip_data_ptr, bus_api) \
+ static uint8_t tcpci_emul_tx_buf_##n[128]; \
+ static struct tcpci_emul_msg tcpci_emul_tx_msg_##n = { \
+ .buf = tcpci_emul_tx_buf_##n, \
+ }; \
+ static struct tcpci_ctx tcpci_ctx##n = { \
+ .tx_msg = &tcpci_emul_tx_msg_##n, \
+ .error_on_ro_write = true, \
+ .error_on_rsvd_write = true, \
+ .alert_gpio_port = COND_CODE_1( \
+ DT_INST_NODE_HAS_PROP(n, alert_gpio), \
+ (DEVICE_DT_GET(DT_GPIO_CTLR( \
+ DT_INST_PROP(n, alert_gpio), gpios))), \
+ (NULL)), \
+ .alert_gpio_pin = COND_CODE_1( \
+ DT_INST_NODE_HAS_PROP(n, alert_gpio), \
+ (DT_GPIO_PIN(DT_INST_PROP(n, alert_gpio), gpios)), \
+ (0)), \
+ }; \
+ static struct tcpc_emul_data tcpc_emul_data_##n = { \
+ .tcpci_ctx = &tcpci_ctx##n, \
+ .chip_data = chip_data_ptr, \
+ .i2c_cfg = { \
+ .dev_label = DT_NODE_FULL_NAME(DT_DRV_INST(n)), \
+ .data = &tcpci_ctx##n.common, \
+ .addr = DT_INST_REG_ADDR(n), \
+ }, \
+ }; \
+ EMUL_DT_INST_DEFINE(n, init, &tcpc_emul_data_##n, cfg_ptr, bus_api)
+
/** Response from TCPCI specific device operations */
enum tcpci_emul_ops_resp {
TCPCI_EMUL_CONTINUE = 0,
@@ -72,10 +132,7 @@ enum tcpci_emul_ops_resp {
};
/** Revisions supported by TCPCI emaluator */
-enum tcpci_emul_rev {
- TCPCI_EMUL_REV1_0_VER1_0 = 0,
- TCPCI_EMUL_REV2_0_VER1_1
-};
+enum tcpci_emul_rev { TCPCI_EMUL_REV1_0_VER1_0 = 0, TCPCI_EMUL_REV2_0_VER1_1 };
/** Status of TX message send to TCPCI emulator partner */
enum tcpci_emul_tx_status {
@@ -90,67 +147,6 @@ enum tcpci_emul_tx_status {
TCPCI_EMUL_TX_UNKNOWN
};
-/** TCPCI specific device operations. Not all of them need to be implemented. */
-struct tcpci_emul_dev_ops {
- /**
- * @brief Function called for each byte of read message
- *
- * @param emul Pointer to TCPCI emulator
- * @param ops Pointer to device operations structure
- * @param reg First byte of last write message
- * @param val Pointer where byte to read should be stored
- * @param bytes Number of bytes already readded
- *
- * @return TCPCI_EMUL_CONTINUE to continue with default handler
- * @return TCPCI_EMUL_DONE to immedietly return success
- * @return TCPCI_EMUL_ERROR to immedietly return error
- */
- enum tcpci_emul_ops_resp (*read_byte)(const struct emul *emul,
- const struct tcpci_emul_dev_ops *ops,
- int reg, uint8_t *val, int bytes);
-
- /**
- * @brief Function called for each byte of write message
- *
- * @param emul Pointer to TCPCI emulator
- * @param ops Pointer to device operations structure
- * @param reg First byte of write message
- * @param val Received byte of write message
- * @param bytes Number of bytes already received
- *
- * @return TCPCI_EMUL_CONTINUE to continue with default handler
- * @return TCPCI_EMUL_DONE to immedietly return success
- * @return TCPCI_EMUL_ERROR to immedietly return error
- */
- enum tcpci_emul_ops_resp (*write_byte)(const struct emul *emul,
- const struct tcpci_emul_dev_ops *ops,
- int reg, uint8_t val, int bytes);
-
- /**
- * @brief Function called on the end of write message
- *
- * @param emul Pointer to TCPCI emulator
- * @param ops Pointer to device operations structure
- * @param reg Register which is written
- * @param msg_len Length of handled I2C message
- *
- * @return TCPCI_EMUL_CONTINUE to continue with default handler
- * @return TCPCI_EMUL_DONE to immedietly return success
- * @return TCPCI_EMUL_ERROR to immedietly return error
- */
- enum tcpci_emul_ops_resp (*handle_write)(const struct emul *emul,
- const struct tcpci_emul_dev_ops *ops,
- int reg, int msg_len);
-
- /**
- * @brief Function called on reset
- *
- * @param emul Pointer to TCPCI emulator
- * @param ops Pointer to device operations structure
- */
- void (*reset)(const struct emul *emul, struct tcpci_emul_dev_ops *ops);
-};
-
/** TCPCI partner operations. Not all of them need to be implemented. */
struct tcpci_emul_partner_ops {
/**
@@ -166,8 +162,7 @@ struct tcpci_emul_partner_ops {
void (*transmit)(const struct emul *emul,
const struct tcpci_emul_partner_ops *ops,
const struct tcpci_emul_msg *tx_msg,
- enum tcpci_msg_type type,
- int retry);
+ enum tcpci_msg_type type, int retry);
/**
* @brief Function called when control settings change to allow partner
@@ -201,18 +196,9 @@ struct tcpci_emul_partner_ops {
};
/**
- * @brief Get i2c_emul for TCPCI emulator
- *
- * @param emul Pointer to TCPCI emulator
- *
- * @return Pointer to I2C TCPCI emulator
- */
-struct i2c_emul *tcpci_emul_get_i2c_emul(const struct emul *emul);
-
-/**
* @brief Set value of given register of TCPCI
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param reg Register address which value will be changed
* @param val New value of the register
*
@@ -222,6 +208,68 @@ struct i2c_emul *tcpci_emul_get_i2c_emul(const struct emul *emul);
int tcpci_emul_set_reg(const struct emul *emul, int reg, uint16_t val);
/**
+ * @brief Function called for each byte of read message from TCPCI
+ *
+ * @param emul Pointer to TCPC emulator
+ * @param reg First byte of last write message
+ * @param val Pointer where byte to read should be stored
+ * @param bytes Number of bytes already readded
+ *
+ * @return 0 on success
+ */
+int tcpci_emul_read_byte(const struct emul *emul, int reg, uint8_t *val,
+ int bytes);
+
+/**
+ * @brief Function called for each byte of write message from TCPCI.
+ * Data are stored in write_data field of tcpci_emul_data or in tx_msg
+ * in case of writing to TX buffer.
+ *
+ * @param emul Pointer to TCPC emulator
+ * @param reg First byte of write message
+ * @param val Received byte of write message
+ * @param bytes Number of bytes already received
+ *
+ * @return 0 on success
+ * @return -EIO on invalid write to TX buffer
+ */
+int tcpci_emul_write_byte(const struct emul *emul, int reg, uint8_t val,
+ int bytes);
+
+/**
+ * @brief Handle I2C write message. It is checked if accessed register isn't RO
+ * and reserved bits are set to 0.
+ *
+ * @param emul Pointer to TCPC emulator
+ * @param reg Register which is written
+ * @param msg_len Length of handled I2C message
+ *
+ * @return 0 on success
+ * @return -EIO on error
+ */
+int tcpci_emul_handle_write(const struct emul *emul, int reg, int msg_len);
+
+/**
+ * @brief Set up a new TCPCI emulator
+ *
+ * This should be called for each TCPC device that needs to be
+ * registered on the I2C bus.
+ *
+ * @param emul Pointer to TCPC emulator
+ * @param parent Pointer to emulated I2C bus
+ */
+void tcpci_emul_i2c_init(const struct emul *emul, const struct device *i2c_dev);
+
+/**
+ * @brief Reset registers to default values. Vendor and reserved registers
+ * are not changed.
+ *
+ * @param emul Pointer to TCPC emulator
+ * @return 0 if successful
+ */
+int tcpci_emul_reset(const struct emul *emul);
+
+/**
* @brief Get value of given register of TCPCI
*
* @param emul Pointer to TCPCI emulator
@@ -237,7 +285,7 @@ int tcpci_emul_get_reg(const struct emul *emul, int reg, uint16_t *val);
/**
* @brief Add up to two SOP RX messages
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param rx_msg Pointer to message that is added
* @param alert Select if alert register should be updated
*
@@ -255,7 +303,7 @@ int tcpci_emul_add_rx_msg(const struct emul *emul,
/**
* @brief Get SOP TX message to examine what was sended by TCPM
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
*
* @return Pointer to TX message
*/
@@ -264,24 +312,15 @@ struct tcpci_emul_msg *tcpci_emul_get_tx_msg(const struct emul *emul);
/**
* @brief Set TCPCI revision in PD_INT_REV register
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param rev Requested revision
*/
void tcpci_emul_set_rev(const struct emul *emul, enum tcpci_emul_rev rev);
/**
- * @brief Set callbacks for specific TCPC device emulator
- *
- * @param emul Pointer to TCPCI emulator
- * @param dev_ops Pointer to callbacks
- */
-void tcpci_emul_set_dev_ops(const struct emul *emul,
- struct tcpci_emul_dev_ops *dev_ops);
-
-/**
* @brief Set callback which is called when alert register is changed
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param alert_callback Pointer to callback
* @param alert_callback_data Pointer to data passed to callback as an argument
*/
@@ -292,7 +331,7 @@ void tcpci_emul_set_alert_callback(const struct emul *emul,
/**
* @brief Set callbacks for port partner device emulator
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param partner Pointer to callbacks
*/
void tcpci_emul_set_partner_ops(const struct emul *emul,
@@ -301,7 +340,7 @@ void tcpci_emul_set_partner_ops(const struct emul *emul,
/**
* @brief Emulate connection of specific device to emulated TCPCI
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param partner_power_role Power role of connected partner (sink or source)
* @param partner_cc1 Voltage on partner CC1 line (usually Rd or Rp)
* @param partner_cc2 Voltage on partner CC2 line (usually open or Ra if active
@@ -321,7 +360,7 @@ int tcpci_emul_connect_partner(const struct emul *emul,
/** @brief Emulate the disconnection of the partner device to emulated TCPCI
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
*
* @return 0 on success
*/
@@ -330,13 +369,22 @@ int tcpci_emul_disconnect_partner(const struct emul *emul);
/**
* @brief Allows port partner to select if message was received correctly
*
- * @param emul Pointer to TCPCI emulator
+ * @param emul Pointer to TCPC emulator
* @param status Status of sended message
*/
void tcpci_emul_partner_msg_status(const struct emul *emul,
enum tcpci_emul_tx_status status);
/**
+ * @brief Gets the common data associated with the tcpci chip overall
+ *
+ * @param emul Pointer to TCPC emulator
+ * @return Pointer to struct i2c_common_emul_data
+ */
+struct i2c_common_emul_data *
+emul_tcpci_generic_get_i2c_common_data(const struct emul *emul);
+
+/**
* @}
*/
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.
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_drp.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_drp.h
index fcc8d6a85a..e4f58fcd37 100644
--- a/zephyr/include/emul/tcpc/emul_tcpci_partner_drp.h
+++ b/zephyr/include/emul/tcpc/emul_tcpci_partner_drp.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -55,12 +55,12 @@ struct tcpci_drp_emul_data {
*
* @return Pointer to USB-C DRP extension
*/
-struct tcpci_partner_extension *tcpci_drp_emul_init(
- struct tcpci_drp_emul_data *data,
- struct tcpci_partner_data *common_data,
- enum pd_power_role power_role,
- struct tcpci_partner_extension *src_ext,
- struct tcpci_partner_extension *snk_ext);
+struct tcpci_partner_extension *
+tcpci_drp_emul_init(struct tcpci_drp_emul_data *data,
+ struct tcpci_partner_data *common_data,
+ enum pd_power_role power_role,
+ struct tcpci_partner_extension *src_ext,
+ struct tcpci_partner_extension *snk_ext);
/**
* @brief Set correct flags for first capabilities PDO to indicate that this
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_ext.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_ext.h
new file mode 100644
index 0000000000..f0627c95bd
--- /dev/null
+++ b/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_ext.h
@@ -0,0 +1,101 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * @file
+ *
+ * @brief Backend API for USB-C malfunctioning device emulator
+ */
+
+#ifndef __EMUL_TCPCI_PARTNER_FAULTY_EXT_H
+#define __EMUL_TCPCI_PARTNER_FAULTY_EXT_H
+
+#include <zephyr/drivers/emul.h>
+#include "emul/tcpc/emul_tcpci.h"
+#include "emul/tcpc/emul_tcpci_partner_common.h"
+#include "usb_pd.h"
+
+/**
+ * @brief USB-C malfunctioning device extension backend API
+ * @defgroup tcpci_faulty_ext USB-C malfunctioning device extension
+ * @{
+ *
+ * USB-C malfunctioning device extension can be used with TCPCI partner
+ * emulator. It can be configured to not respond to source capability message
+ * (by not sending GoodCRC or Request after GoodCRC).
+ */
+
+/** Structure describing malfunctioning emulator data */
+struct tcpci_faulty_ext_data {
+ struct tcpci_partner_extension ext;
+ /* List of action to perform */
+ struct k_fifo action_list;
+};
+
+/** Actions that can be performed by malfunctioning emulator */
+enum tcpci_faulty_ext_action_type {
+ /**
+ * Fail to receive SourceCapabilities message. From TCPM point of view,
+ * GoodCRC message is not received.
+ */
+ TCPCI_FAULTY_EXT_FAIL_SRC_CAP = BIT(0),
+ /**
+ * Ignore to respond to SourceCapabilities message with Request message.
+ * From TCPM point of view, GoodCRC message is received, but Request is
+ * missing.
+ */
+ TCPCI_FAULTY_EXT_IGNORE_SRC_CAP = BIT(1),
+ /** Discard SourceCapabilities message and send Accept message */
+ TCPCI_FAULTY_EXT_DISCARD_SRC_CAP = BIT(2),
+};
+
+/** Structure to put in malfunctioning emulator action list */
+struct tcpci_faulty_ext_action {
+ /* Reserved for FIFO */
+ void *fifo_reserved;
+ /* Actions that emulator should perform */
+ uint32_t action_mask;
+ /* Number of times to repeat action */
+ int count;
+};
+
+/* Count of actions which is treated by emulator as infinite */
+#define TCPCI_FAULTY_EXT_INFINITE_ACTION 0
+
+/**
+ * @brief Initialise USB-C malfunctioning device data structure
+ *
+ * @param data Pointer to USB-C malfunctioning device emulator data
+ * @param common_data Pointer to USB-C device emulator common data
+ * @param ext Pointer to next USB-C emulator extension
+ *
+ * @return Pointer to USB-C malfunctioning extension
+ */
+struct tcpci_partner_extension *
+tcpci_faulty_ext_init(struct tcpci_faulty_ext_data *data,
+ struct tcpci_partner_data *common_data,
+ struct tcpci_partner_extension *ext);
+
+/**
+ * @brief Add action to perform by USB-C malfunctioning extension
+ *
+ * @param data Pointer to USB-C malfunctioning device extension data
+ * @param action Non standard behavior to perform by emulator
+ */
+void tcpci_faulty_ext_append_action(struct tcpci_faulty_ext_data *data,
+ struct tcpci_faulty_ext_action *action);
+
+/**
+ * @brief Clear all actions of USB-C malfunctioning extension
+ *
+ * @param data Pointer to USB-C malfunctioning device extension data
+ */
+void tcpci_faulty_ext_clear_actions_list(struct tcpci_faulty_ext_data *data);
+
+/**
+ * @}
+ */
+
+#endif /* __EMUL_TCPCI_PARTNER_FAULTY_EXT_H */
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_snk.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_snk.h
deleted file mode 100644
index 8334f5f01d..0000000000
--- a/zephyr/include/emul/tcpc/emul_tcpci_partner_faulty_snk.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/**
- * @file
- *
- * @brief Backend API for USB-C malfunctioning sink device emulator
- */
-
-#ifndef __EMUL_TCPCI_PARTNER_FAULTY_SNK_H
-#define __EMUL_TCPCI_PARTNER_FAULTY_SNK_H
-
-#include <zephyr/drivers/emul.h>
-#include "emul/tcpc/emul_tcpci.h"
-#include "emul/tcpc/emul_tcpci_partner_common.h"
-#include "emul/tcpc/emul_tcpci_partner_snk.h"
-#include "usb_pd.h"
-
-/**
- * @brief USB-C malfunctioning sink device extension backend API
- * @defgroup tcpci_faulty_snk_emul USB-C malfunctioning sink device extension
- * @{
- *
- * USB-C malfunctioning sink device extension can be used with TCPCI partner
- * emulator. It can be configured to not respond to source capability message
- * (by not sending GoodCRC or Request after GoodCRC).
- */
-
-/** Structure describing malfunctioning sink emulator data */
-struct tcpci_faulty_snk_emul_data {
- struct tcpci_partner_extension ext;
- /* List of action to perform */
- struct k_fifo action_list;
-};
-
-/** Actions that can be performed by malfunctioning sink emulator */
-enum tcpci_faulty_snk_action_type {
- /**
- * Fail to receive SourceCapabilities message. From TCPM point of view,
- * GoodCRC message is not received.
- */
- TCPCI_FAULTY_SNK_FAIL_SRC_CAP = BIT(0),
- /**
- * Ignore to respond to SourceCapabilities message with Request message.
- * From TCPM point of view, GoodCRC message is received, but Request is
- * missing.
- */
- TCPCI_FAULTY_SNK_IGNORE_SRC_CAP = BIT(1),
- /** Discard SourceCapabilities message and send Accept message */
- TCPCI_FAULTY_SNK_DISCARD_SRC_CAP = BIT(2),
-};
-
-/** Structure to put in malfunctioning sink emulator action list */
-struct tcpci_faulty_snk_action {
- /* Reserved for FIFO */
- void *fifo_reserved;
- /* Actions that emulator should perform */
- uint32_t action_mask;
- /* Number of times to repeat action */
- int count;
-};
-
-/* Count of actions which is treated by emulator as infinite */
-#define TCPCI_FAULTY_SNK_INFINITE_ACTION 0
-
-/**
- * @brief Initialise USB-C malfunctioning sink device data structure
- *
- * @param data Pointer to USB-C malfunctioning sink device emulator data
- * @param common_data Pointer to USB-C device emulator common data
- * @param ext Pointer to next USB-C emulator extension
- *
- * @return Pointer to USB-C malfunctioning sink extension
- */
-struct tcpci_partner_extension *tcpci_faulty_snk_emul_init(
- struct tcpci_faulty_snk_emul_data *data,
- struct tcpci_partner_data *common_data,
- struct tcpci_partner_extension *ext);
-
-/**
- * @brief Add action to perform by USB-C malfunctioning sink extension
- *
- * @param data Pointer to USB-C malfunctioning sink device extension data
- * @param action Non standard behavior to perform by emulator
- */
-void tcpci_faulty_snk_emul_append_action(
- struct tcpci_faulty_snk_emul_data *data,
- struct tcpci_faulty_snk_action *action);
-
-/**
- * @brief Clear all actions of USB-C malfunctioning sink extension
- *
- * @param data Pointer to USB-C malfunctioning sink device extension data
- */
-void tcpci_faulty_snk_emul_clear_actions_list(
- struct tcpci_faulty_snk_emul_data *data);
-
-/**
- * @}
- */
-
-#endif /* __EMUL_TCPCI_PARTNER_FAULTY_SNK_H */
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_snk.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_snk.h
index 5e23a770da..584458942b 100644
--- a/zephyr/include/emul/tcpc/emul_tcpci_partner_snk.h
+++ b/zephyr/include/emul/tcpc/emul_tcpci_partner_snk.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.
*/
@@ -41,6 +41,8 @@ struct tcpci_snk_emul_data {
bool ping_received;
/** PD_DATA_ALERT message received */
bool alert_received;
+ /** Last received 5V fixed source cap */
+ uint32_t last_5v_source_cap;
};
/**
@@ -53,10 +55,10 @@ struct tcpci_snk_emul_data {
*
* @return Pointer to USB-C sink extension
*/
-struct tcpci_partner_extension *tcpci_snk_emul_init(
- struct tcpci_snk_emul_data *data,
- struct tcpci_partner_data *common_data,
- struct tcpci_partner_extension *ext);
+struct tcpci_partner_extension *
+tcpci_snk_emul_init(struct tcpci_snk_emul_data *data,
+ struct tcpci_partner_data *common_data,
+ struct tcpci_partner_extension *ext);
/**
* @brief Clear the ping received flag.
@@ -73,6 +75,13 @@ void tcpci_snk_emul_clear_ping_received(struct tcpci_snk_emul_data *sink_data);
void tcpci_snk_emul_clear_alert_received(struct tcpci_snk_emul_data *sink_data);
/**
+ * @brief Clear the last received 5V fixed source cap.
+ *
+ * @param sink_data
+ */
+void tcpci_snk_emul_clear_last_5v_cap(struct tcpci_snk_emul_data *sink_data);
+
+/**
* @}
*/
diff --git a/zephyr/include/emul/tcpc/emul_tcpci_partner_src.h b/zephyr/include/emul/tcpc/emul_tcpci_partner_src.h
index 00f592ae2f..e72d0e4135 100644
--- a/zephyr/include/emul/tcpc/emul_tcpci_partner_src.h
+++ b/zephyr/include/emul/tcpc/emul_tcpci_partner_src.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.
*/
@@ -95,10 +95,10 @@ enum check_pdos_res tcpci_src_emul_check_pdos(struct tcpci_src_emul_data *data);
*
* @return Pointer to USB-C source extension
*/
-struct tcpci_partner_extension *tcpci_src_emul_init(
- struct tcpci_src_emul_data *data,
- struct tcpci_partner_data *common_data,
- struct tcpci_partner_extension *ext);
+struct tcpci_partner_extension *
+tcpci_src_emul_init(struct tcpci_src_emul_data *data,
+ struct tcpci_partner_data *common_data,
+ struct tcpci_partner_extension *ext);
/**
* @brief Send capability message constructed from source device emulator PDOs
@@ -134,9 +134,7 @@ int tcpci_src_emul_send_capability_msg(struct tcpci_src_emul_data *data,
*/
int tcpci_src_emul_send_capability_msg_with_timer(
struct tcpci_src_emul_data *data,
- struct tcpci_partner_data *common_data,
- uint64_t delay);
-
+ struct tcpci_partner_data *common_data, uint64_t delay);
/**
* @brief Clear the alert received flag.