summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJameson Thies <jthies@google.com>2022-04-22 21:47:14 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-02 22:56:32 +0000
commit96c7cd536662dea8ec2dd3509357c56c3174bfd7 (patch)
treefd2ea8e25555129fc6386ec73c7583f92766f477
parent695640c14d2dccbc718872430608c731fd162ba9 (diff)
downloadchrome-ec-96c7cd536662dea8ec2dd3509357c56c3174bfd7.tar.gz
TCMPV2: Add state to send Status extended messages
When a USB PD partner sends a Get_Status message, the EC should respond with a Status message. This CL adds the Status message response and creates a new function in usb_pd_dpm which will be used to build the Status Data Block (SDB). BUG=b:227236917 TEST=triggered Status message and saw that it correctly sent data from a modified dpm_get_status_msg function on a twinkie. BRANCH=None Signed-off-by: Jameson Thies <jthies@google.com> Change-Id: Ifafa6e9ee7d9a62ef75e5c9e96606ffba64c98b0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3602226 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Jameson Thies <jthies@google.com> Tested-by: Jameson Thies <jthies@google.com>
-rw-r--r--common/mock/usb_pd_dpm_mock.c5
-rw-r--r--common/usbc/usb_pd_dpm.c32
-rw-r--r--common/usbc/usb_pe_drp_sm.c56
-rw-r--r--include/usb_pd.h18
-rw-r--r--include/usb_pd_dpm.h9
-rw-r--r--test/fake_usbc.c5
6 files changed, 121 insertions, 4 deletions
diff --git a/common/mock/usb_pd_dpm_mock.c b/common/mock/usb_pd_dpm_mock.c
index 766cdcecf4..47b1290785 100644
--- a/common/mock/usb_pd_dpm_mock.c
+++ b/common/mock/usb_pd_dpm_mock.c
@@ -74,3 +74,8 @@ int dpm_get_source_pdo(const uint32_t **src_pdo, const int port)
*src_pdo = pd_src_pdo;
return pd_src_pdo_cnt;
}
+
+int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len)
+{
+ return EC_SUCCESS;
+}
diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c
index 3b682439f6..53c7127080 100644
--- a/common/usbc/usb_pd_dpm.c
+++ b/common/usbc/usb_pd_dpm.c
@@ -786,3 +786,35 @@ int dpm_get_source_current(const int port)
else
return 500;
}
+
+int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len)
+{
+ struct pd_sdb sdb;
+
+ /* TODO(b/227236917): Fill in fields of Status message */
+
+ /* Internal Temp */
+ sdb.internal_temp = 0x0;
+
+ /* Present Input */
+ sdb.present_input = 0x0;
+
+ /* Present Battery Input */
+ sdb.present_battery_input = 0x0;
+
+ /* Event Flags */
+ sdb.event_flags = 0x0;
+
+ /* Temperature Status */
+ sdb.temperature_status = PD_SDB_TEMPERATURE_STATUS_NOT_SUPPORTED;
+
+ /* Power Status */
+ sdb.power_status = 0x0;
+
+ /* USB PD Rev 3.0: 6.5.2 Status Message */
+ *len = 6;
+
+ memcpy(msg, &sdb, *len);
+
+ return EC_SUCCESS;
+}
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index c75e84158b..97a1d42f64 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -269,6 +269,7 @@ enum usb_pe_state {
PE_FRS_SNK_SRC_START_AMS,
PE_GIVE_BATTERY_CAP,
PE_GIVE_BATTERY_STATUS,
+ PE_GIVE_STATUS,
PE_SEND_ALERT,
PE_SRC_CHUNK_RECEIVED,
PE_SNK_CHUNK_RECEIVED,
@@ -391,6 +392,7 @@ __maybe_unused static __const_data const char * const pe_state_names[] = {
#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES
[PE_GIVE_BATTERY_CAP] = "PE_Give_Battery_Cap",
[PE_GIVE_BATTERY_STATUS] = "PE_Give_Battery_Status",
+ [PE_GIVE_STATUS] = "PE_Give_Status",
[PE_SEND_ALERT] = "PE_Send_Alert",
#else
[PE_SRC_CHUNK_RECEIVED] = "PE_SRC_Chunk_Received",
@@ -443,6 +445,8 @@ GEN_NOT_SUPPORTED(PE_GIVE_BATTERY_CAP);
#define PE_GIVE_BATTERY_CAP PE_GIVE_BATTERY_CAP_NOT_SUPPORTED
GEN_NOT_SUPPORTED(PE_GIVE_BATTERY_STATUS);
#define PE_GIVE_BATTERY_STATUS PE_GIVE_BATTERY_STATUS_NOT_SUPPORTED
+GEN_NOT_SUPPORTED(PE_GIVE_STATUS);
+#define PE_GIVE_STATUS PE_GIVE_STATUS_NOT_SUPPORTED
GEN_NOT_SUPPORTED(PE_SEND_ALERT);
#define PE_SEND_ALERT PE_SEND_ALERT_NOT_SUPPORTED
#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
@@ -2636,14 +2640,19 @@ static void pe_src_ready_run(int port)
/* Extended Message Requests */
if (ext > 0) {
switch (type) {
-#if defined(CONFIG_USB_PD_EXTENDED_MESSAGES) && defined(CONFIG_BATTERY)
+#if defined(CONFIG_USB_PD_EXTENDED_MESSAGES)
+#if defined(CONFIG_BATTERY)
case PD_EXT_GET_BATTERY_CAP:
set_state_pe(port, PE_GIVE_BATTERY_CAP);
break;
case PD_EXT_GET_BATTERY_STATUS:
set_state_pe(port, PE_GIVE_BATTERY_STATUS);
break;
-#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES && CONFIG_BATTERY */
+#endif /* CONFIG_BATTERY */
+ case PD_CTRL_GET_STATUS:
+ set_state_pe(port, PE_GIVE_STATUS);
+ return;
+#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
default:
extended_message_not_supported(port, payload);
}
@@ -3462,14 +3471,19 @@ static void pe_snk_ready_run(int port)
/* Extended Message Request */
if (ext > 0) {
switch (type) {
-#if defined(CONFIG_USB_PD_EXTENDED_MESSAGES) && defined(CONFIG_BATTERY)
+#if defined(CONFIG_USB_PD_EXTENDED_MESSAGES)
+#if defined(CONFIG_BATTERY)
case PD_EXT_GET_BATTERY_CAP:
set_state_pe(port, PE_GIVE_BATTERY_CAP);
break;
case PD_EXT_GET_BATTERY_STATUS:
set_state_pe(port, PE_GIVE_BATTERY_STATUS);
break;
-#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES && CONFIG_BATTERY */
+#endif /* CONFIG_BATTERY */
+ case PD_CTRL_GET_STATUS:
+ set_state_pe(port, PE_GIVE_STATUS);
+ return;
+#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */
default:
extended_message_not_supported(port, payload);
}
@@ -4211,6 +4225,36 @@ static void pe_give_battery_status_run(int port)
}
/**
+ * PE_SRC_Give_Source_Status and
+ * PE_SNK_Give_Sink_Status
+ */
+static void pe_give_status_entry(int port)
+{
+ uint8_t *msg = (uint8_t *)tx_emsg[port].buf;
+ uint32_t *len = &tx_emsg[port].len;
+
+ print_current_state(port);
+ if (dpm_get_status_msg(port, msg, len) != EC_SUCCESS)
+ pe_set_ready_state(port);
+
+ send_ext_data_msg(port, TCPCI_MSG_SOP, PD_EXT_STATUS);
+}
+
+static void pe_give_status_run(int port)
+{
+ if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) {
+ PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE);
+ pe_set_ready_state(port);
+ } else if (PE_CHK_FLAG(port, PE_FLAGS_PROTOCOL_ERROR) ||
+ PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) {
+ PE_CLR_FLAG(port, PE_FLAGS_PROTOCOL_ERROR);
+ PE_CLR_FLAG(port, PE_FLAGS_MSG_DISCARDED);
+ pe_send_soft_reset(port, TCPCI_MSG_SOP);
+ }
+}
+
+
+/**
* PE_SRC_Send_Source_Alert and
* PE_SNK_Send_Sink_Alert
*/
@@ -7697,6 +7741,10 @@ static __const_data const struct usb_state pe_states[] = {
.entry = pe_give_battery_status_entry,
.run = pe_give_battery_status_run,
},
+ [PE_GIVE_STATUS] = {
+ .entry = pe_give_status_entry,
+ .run = pe_give_status_run,
+ },
[PE_SEND_ALERT] = {
.entry = pe_send_alert_entry,
.run = pe_send_alert_run,
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 8468de814a..5b389e1bb4 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1190,6 +1190,24 @@ enum pd_ctrl_msg_type {
*/
#define BATT_CAP_REF(n) (((n) >> 16) & 0xff)
+/* SOP SDB fields for PD Rev 3.0 Section 6.5.2.1 */
+enum pd_sdb_temperature_status {
+ PD_SDB_TEMPERATURE_STATUS_NOT_SUPPORTED = 0,
+ PD_SDB_TEMPERATURE_STATUS_NORMAL = 2,
+ PD_SDB_TEMPERATURE_STATUS_WARNING = 4,
+ PD_SDB_TEMPERATURE_STATUS_OVER_TEMPERATURE = 6,
+} __packed;
+BUILD_ASSERT(sizeof(enum pd_sdb_temperature_status) == 1);
+
+struct pd_sdb {
+ uint8_t internal_temp;
+ uint8_t present_input;
+ uint8_t present_battery_input;
+ uint8_t event_flags;
+ enum pd_sdb_temperature_status temperature_status;
+ uint8_t power_status;
+};
+
/* Extended message type for REV 3.0 */
enum pd_ext_msg_type {
/* 0 Reserved */
diff --git a/include/usb_pd_dpm.h b/include/usb_pd_dpm.h
index c7ae53340d..663c711daa 100644
--- a/include/usb_pd_dpm.h
+++ b/include/usb_pd_dpm.h
@@ -122,6 +122,15 @@ int dpm_get_source_pdo(const uint32_t **src_pdo, const int port);
*/
int dpm_get_source_current(const int port);
+/*
+ * Build SOP Status Data Block (SDB)
+ *
+ * @param port USB-C port number
+ * @param *msg pointer to pd message
+ * @param *len pointer to uint32_t holding length of SDB
+ */
+int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len);
+
/* Enum for modules to describe to the DPM their setup status */
enum dpm_msg_setup_status {
MSG_SETUP_SUCCESS,
diff --git a/test/fake_usbc.c b/test/fake_usbc.c
index c1a48ad4d5..6e61a1ca81 100644
--- a/test/fake_usbc.c
+++ b/test/fake_usbc.c
@@ -314,6 +314,11 @@ int dpm_get_source_pdo(const uint32_t **src_pdo, const int port)
return pd_src_pdo_cnt;
}
+int dpm_get_status_msg(int port, uint8_t *msg, uint32_t *len)
+{
+ return EC_SUCCESS;
+}
+
static enum tcpc_rp_value lcl_rp;
__overridable void typec_select_src_current_limit_rp(int port,
enum tcpc_rp_value rp)