summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2020-11-12 10:51:27 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-17 20:53:27 +0000
commit21f1d75e7bea96bf1c33986a0ab5406a80c7c1c2 (patch)
treef1694a63c2fe86483fab5d27b421ecb1fa131294 /util
parentc0a778cef35a9b06be6014121c18cb26d3691184 (diff)
downloadchrome-ec-21f1d75e7bea96bf1c33986a0ab5406a80c7c1c2.tar.gz
genvif: add override XML initialization
You can now feed in a VIF XML file with fields that you want to override and these will get set instead of using the CONFIG_ initialization for those fields. $ build/morphius/util/genvif -o build/morphius \ -b morphius_sku5_dvt2 \ --over board/morphius/sku5_dvt2.xml Where the override file is a valid VIF file (no matter how partial it is). Tags such as <? .... ?> and comments <!-- .... --> are ignored. In the above example the override file looked as followed: <?xml version="1.0" encoding="UTF-8"?> <VIF> <Model_Part_Number>Morphius SKU5</Model_Part_Number> <Product_Revision>DVT2</Product_Revision> </VIF> The Model_Part_Number and Product_Revision used this override value instead of "morphius" and "FIX-ME". The values can also be used to set other values. I added a couple of those but the uses of get_vif_field can be added to create more automated generation. Here are a couple of examples: static bool is_src(void) { int override_value; bool was_overridden; /* Determine if we are DRP, SRC or SNK */ was_overridden = get_vif_field_tag_number( &vif.Component[0] .vif_field[Type_C_State_Machine], &override_value); if (was_overridden) { switch (override_value) { case SRC: case DRP: return true; case SNK: return false; default: break; } } return src_pdo_cnt; } and /* Determine if we are DRP, SRC or SNK */ was_overridden = get_vif_field_tag_number( &vif->Component[0] .vif_field[Type_C_State_Machine], &override_value); if (was_overridden) { switch (override_value) { case SRC: case SNK: case DRP: type = (enum dtype)override_value; break; default: was_overridden = false; } } if (!was_overridden) { if (is_drp()) type = DRP; else if (is_src() && is_snk()) /* No DRP with SRC and SNK PDOs detected. So ignore. */ /* ie. Twinkie or Plankton */ return 0; else if (is_src()) type = SRC; else if (is_snk()) type = SNK; else return 1; } Bumped the version to 3.0.0.6. BUG=b:172489443 BRANCH=none TEST=use --over to override fields within the XML Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ic1ecd3e0d2f643c3315bcc8abecdf7490fb69b8a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2535672 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/genvif.c2344
-rw-r--r--util/genvif.h12
2 files changed, 1910 insertions, 446 deletions
diff --git a/util/genvif.c b/util/genvif.c
index e1bc3d3361..a049a452c3 100644
--- a/util/genvif.c
+++ b/util/genvif.c
@@ -15,6 +15,7 @@
#include <getopt.h>
#include <dirent.h>
#include <limits.h>
+#include <ctype.h>
#include "config.h"
#include "usb_pd.h"
@@ -26,7 +27,7 @@
#define VIF_APP_VENDOR_VALUE "Google"
#define VIF_APP_NAME_VALUE "EC GENVIF"
-#define VIF_APP_VERSION_VALUE "3.0.0.5"
+#define VIF_APP_VERSION_VALUE "3.0.0.6"
#define VENDOR_NAME_VALUE "Google"
#define DEFAULT_MISSING_TID 0xFFFF
@@ -35,6 +36,8 @@
const uint32_t *src_pdo;
uint32_t src_pdo_cnt;
+struct vif_t vif;
+
/*
* local type to make decisions on the output for Source, Sink and DRP
*/
@@ -44,6 +47,15 @@ enum dtype {
DRP
};
+enum ptype {
+ PORT_CONSUMER_ONLY = 0,
+ PORT_CONSUMER_PRODUCER = 1,
+ PORT_PRODUCER_CONSUMER = 2,
+ PORT_PROVIDER_ONLY = 3,
+ PORT_DRP = 4,
+ PORT_EMARKER = 5,
+};
+
/*
* Device_Speed options, defined in the VIF specification
*/
@@ -65,19 +77,519 @@ enum bc_1_2_support {
BC_1_2_SUPPORT_BOTH = 3
};
+
+/*
+ * TAG Name Strings
+ */
+#define NAME_INIT(str) [str] = #str
+
+const char *vif_name[] = {
+ NAME_INIT(VIF_Specification),
+ NAME_INIT(Vendor_Name),
+ NAME_INIT(Model_Part_Number),
+ NAME_INIT(Product_Revision),
+ NAME_INIT(TID),
+ NAME_INIT(VIF_Product_Type),
+ NAME_INIT(Certification_Type),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_name) == VIF_Indexes);
+
+const char *vif_app_name[] = {
+ NAME_INIT(Vendor),
+ NAME_INIT(Name),
+ NAME_INIT(Version),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_app_name) == VIF_App_Indexes);
+
+const char *vif_component_name[] = {
+ NAME_INIT(Port_Label),
+ NAME_INIT(Connector_Type),
+ NAME_INIT(USB4_Supported),
+ NAME_INIT(USB_PD_Support),
+ NAME_INIT(PD_Port_Type),
+ NAME_INIT(Type_C_State_Machine),
+ NAME_INIT(Port_Battery_Powered),
+ NAME_INIT(BC_1_2_Support),
+ NAME_INIT(PD_Spec_Revision_Major),
+ NAME_INIT(PD_Spec_Revision_Minor),
+ NAME_INIT(PD_Spec_Version_Major),
+ NAME_INIT(PD_Spec_Version_Minor),
+ NAME_INIT(PD_Specification_Revision),
+ NAME_INIT(SOP_Capable),
+ NAME_INIT(SOP_P_Capable),
+ NAME_INIT(SOP_PP_Capable),
+ NAME_INIT(SOP_P_Debug_Capable),
+ NAME_INIT(SOP_PP_Debug_Capable),
+ NAME_INIT(Manufacturer_Info_Supported_Port),
+ NAME_INIT(Manufacturer_Info_VID_Port),
+ NAME_INIT(Manufacturer_Info_PID_Port),
+ NAME_INIT(USB_Comms_Capable),
+ NAME_INIT(DR_Swap_To_DFP_Supported),
+ NAME_INIT(DR_Swap_To_UFP_Supported),
+ NAME_INIT(Unconstrained_Power),
+ NAME_INIT(VCONN_Swap_To_On_Supported),
+ NAME_INIT(VCONN_Swap_To_Off_Supported),
+ NAME_INIT(Responds_To_Discov_SOP_UFP),
+ NAME_INIT(Responds_To_Discov_SOP_DFP),
+ NAME_INIT(Attempts_Discov_SOP),
+ NAME_INIT(Chunking_Implemented_SOP),
+ NAME_INIT(Unchunked_Extended_Messages_Supported),
+ NAME_INIT(Security_Msgs_Supported_SOP),
+ NAME_INIT(Num_Fixed_Batteries),
+ NAME_INIT(Num_Swappable_Battery_Slots),
+ NAME_INIT(ID_Header_Connector_Type_SOP),
+ NAME_INIT(Type_C_Can_Act_As_Host),
+ NAME_INIT(Type_C_Can_Act_As_Device),
+ NAME_INIT(Type_C_Implements_Try_SRC),
+ NAME_INIT(Type_C_Implements_Try_SNK),
+ NAME_INIT(Type_C_Supports_Audio_Accessory),
+ NAME_INIT(Type_C_Supports_VCONN_Powered_Accessory),
+ NAME_INIT(Type_C_Is_VCONN_Powered_Accessory),
+ NAME_INIT(Type_C_Is_Debug_Target_SRC),
+ NAME_INIT(Type_C_Is_Debug_Target_SNK),
+ NAME_INIT(Captive_Cable),
+ NAME_INIT(RP_Value),
+ NAME_INIT(Type_C_Port_On_Hub),
+ NAME_INIT(Type_C_Power_Source),
+ NAME_INIT(Type_C_Sources_VCONN),
+ NAME_INIT(Type_C_Is_Alt_Mode_Controller),
+ NAME_INIT(Type_C_Is_Alt_Mode_Adapter),
+ NAME_INIT(USB4_Router_Index),
+ NAME_INIT(USB4_Lane_0_Adapter),
+ NAME_INIT(USB4_Max_Speed),
+ NAME_INIT(USB4_DFP_Supported),
+ NAME_INIT(USB4_UFP_Supported),
+ NAME_INIT(USB4_USB3_Tunneling_Supported),
+ NAME_INIT(USB4_DP_Tunneling_Supported),
+ NAME_INIT(USB4_PCIe_Tunneling_Supported),
+ NAME_INIT(USB4_TBT3_Compatibility_Supported),
+ NAME_INIT(USB4_CL1_State_Supported),
+ NAME_INIT(USB4_CL2_State_Supported),
+ NAME_INIT(USB4_Num_Retimers),
+ NAME_INIT(USB4_DP_Bit_Rate),
+ NAME_INIT(USB4_Num_DP_Lanes),
+ NAME_INIT(Host_Supports_USB_Data),
+ NAME_INIT(Host_Speed),
+ NAME_INIT(Host_Contains_Captive_Retimer),
+ NAME_INIT(Host_Truncates_DP_For_tDHPResponse),
+ NAME_INIT(Host_Gen1x1_tLinkTurnaround),
+ NAME_INIT(Host_Gen2x1_tLinkTurnaround),
+ NAME_INIT(Host_Is_Embedded),
+ NAME_INIT(Host_Suspend_Supported),
+ NAME_INIT(Is_DFP_On_Hub),
+ NAME_INIT(Hub_Port_Number),
+ NAME_INIT(Device_Supports_USB_Data),
+ NAME_INIT(Device_Speed),
+ NAME_INIT(Device_Contains_Captive_Retimer),
+ NAME_INIT(Device_Truncates_DP_For_tDHPResponse),
+ NAME_INIT(Device_Gen1x1_tLinkTurnaround),
+ NAME_INIT(Device_Gen2x1_tLinkTurnaround),
+ NAME_INIT(BC_1_2_Charging_Port_Type),
+ NAME_INIT(PD_Power_As_Source),
+ NAME_INIT(USB_Suspend_May_Be_Cleared),
+ NAME_INIT(Sends_Pings),
+ NAME_INIT(Accepts_PR_Swap_As_Src),
+ NAME_INIT(Accepts_PR_Swap_As_Snk),
+ NAME_INIT(Requests_PR_Swap_As_Src),
+ NAME_INIT(Requests_PR_Swap_As_Snk),
+ NAME_INIT(FR_Swap_Supported_As_Initial_Sink),
+ NAME_INIT(FR_Swap_Type_C_Current_Capability_As_Initial_Sink),
+ NAME_INIT(FR_Swap_Reqd_Type_C_Current_As_Initial_Source),
+ NAME_INIT(Master_Port),
+ NAME_INIT(Num_Src_PDOs),
+ NAME_INIT(PD_OC_Protection),
+ NAME_INIT(PD_OCP_Method),
+ NAME_INIT(PD_Power_As_Sink),
+ NAME_INIT(No_USB_Suspend_May_Be_Set),
+ NAME_INIT(GiveBack_May_Be_Set),
+ NAME_INIT(Higher_Capability_Set),
+ NAME_INIT(Num_Snk_PDOs),
+ NAME_INIT(XID_SOP),
+ NAME_INIT(Data_Capable_As_USB_Host_SOP),
+ NAME_INIT(Data_Capable_As_USB_Device_SOP),
+ NAME_INIT(Product_Type_UFP_SOP),
+ NAME_INIT(Product_Type_DFP_SOP),
+ NAME_INIT(DFP_VDO_Port_Number),
+ NAME_INIT(Modal_Operation_Supported_SOP),
+ NAME_INIT(USB_VID_SOP),
+ NAME_INIT(PID_SOP),
+ NAME_INIT(bcdDevice_SOP),
+ NAME_INIT(SVID_Fixed_SOP),
+ NAME_INIT(Num_SVIDs_Min_SOP),
+ NAME_INIT(Num_SVIDs_Max_SOP),
+ NAME_INIT(AMA_HW_Vers),
+ NAME_INIT(AMA_FW_Vers),
+ NAME_INIT(AMA_VCONN_Reqd),
+ NAME_INIT(AMA_VCONN_Power),
+ NAME_INIT(AMA_VBUS_Reqd),
+ NAME_INIT(AMA_Superspeed_Support),
+ NAME_INIT(Product_Total_Source_Power_mW),
+ NAME_INIT(Port_Source_Power_Type),
+ NAME_INIT(Port_Source_Power_Gang),
+ NAME_INIT(Port_Source_Power_Gang_Max_Power),
+ NAME_INIT(XID),
+ NAME_INIT(Data_Capable_As_USB_Host),
+ NAME_INIT(Data_Capable_As_USB_Device),
+ NAME_INIT(Product_Type),
+ NAME_INIT(Modal_Operation_Supported),
+ NAME_INIT(USB_VID),
+ NAME_INIT(PID),
+ NAME_INIT(bcdDevice),
+ NAME_INIT(Cable_HW_Vers),
+ NAME_INIT(Cable_FW_Vers),
+ NAME_INIT(Type_C_To_Type_A_B_C),
+ NAME_INIT(Type_C_To_Type_C_Capt_Vdm_V2),
+ NAME_INIT(Cable_Latency),
+ NAME_INIT(Cable_Termination_Type),
+ NAME_INIT(VBUS_Through_Cable),
+ NAME_INIT(Cable_VBUS_Current),
+ NAME_INIT(Cable_Superspeed_Support),
+ NAME_INIT(Cable_USB_Highest_Speed),
+ NAME_INIT(Max_VBUS_Voltage_Vdm_V2),
+ NAME_INIT(Manufacturer_Info_Supported),
+ NAME_INIT(Manufacturer_Info_VID),
+ NAME_INIT(Manufacturer_Info_PID),
+ NAME_INIT(Chunking_Implemented),
+ NAME_INIT(Security_Msgs_Supported),
+ NAME_INIT(ID_Header_Connector_Type),
+ NAME_INIT(SVID_Fixed),
+ NAME_INIT(Cable_Num_SVIDs_Min),
+ NAME_INIT(Cable_Num_SVIDs_Max),
+ NAME_INIT(VPD_HW_Vers),
+ NAME_INIT(VPD_FW_Vers),
+ NAME_INIT(VPD_Max_VBUS_Voltage),
+ NAME_INIT(VPD_Charge_Through_Support),
+ NAME_INIT(VPD_Charge_Through_Current),
+ NAME_INIT(VPD_VBUS_Impedance),
+ NAME_INIT(VPD_Ground_Impedance),
+ NAME_INIT(Cable_SOP_PP_Controller),
+ NAME_INIT(SBU_Supported),
+ NAME_INIT(SBU_Type),
+ NAME_INIT(Active_Cable_Operating_Temp_Support),
+ NAME_INIT(Active_Cable_Max_Operating_Temp),
+ NAME_INIT(Active_Cable_Shutdown_Temp_Support),
+ NAME_INIT(Active_Cable_Shutdown_Temp),
+ NAME_INIT(Active_Cable_U3_CLd_Power),
+ NAME_INIT(Active_Cable_U3_U0_Trans_Mode),
+ NAME_INIT(Active_Cable_Physical_Connection),
+ NAME_INIT(Active_Cable_Active_Element),
+ NAME_INIT(Active_Cable_USB4_Support),
+ NAME_INIT(Active_Cable_USB2_Hub_Hops_Consumed),
+ NAME_INIT(Active_Cable_USB2_Supported),
+ NAME_INIT(Active_Cable_USB32_Supported),
+ NAME_INIT(Active_Cable_USB_Lanes),
+ NAME_INIT(Active_Cable_Optically_Isolated),
+ NAME_INIT(Active_Cable_USB_Gen),
+ NAME_INIT(Repeater_One_Type),
+ NAME_INIT(Repeater_Two_Type),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_component_name) == Component_Indexes);
+
+const char *vif_component_snk_pdo_name[] = {
+ NAME_INIT(Snk_PDO_Supply_Type),
+ NAME_INIT(Snk_PDO_Voltage),
+ NAME_INIT(Snk_PDO_Op_Power),
+ NAME_INIT(Snk_PDO_Min_Voltage),
+ NAME_INIT(Snk_PDO_Max_Voltage),
+ NAME_INIT(Snk_PDO_Op_Current),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_component_snk_pdo_name) == Snk_PDO_Indexes);
+
+const char *vif_component_src_pdo_name[] = {
+ NAME_INIT(Src_PDO_Supply_Type),
+ NAME_INIT(Src_PDO_Peak_Current),
+ NAME_INIT(Src_PDO_Voltage),
+ NAME_INIT(Src_PDO_Max_Current),
+ NAME_INIT(Src_PDO_Min_Voltage),
+ NAME_INIT(Src_PDO_Max_Voltage),
+ NAME_INIT(Src_PDO_Max_Power),
+ NAME_INIT(Src_PD_OCP_OC_Debounce),
+ NAME_INIT(Src_PD_OCP_OC_Threshold),
+ NAME_INIT(Src_PD_OCP_UV_Debounce),
+ NAME_INIT(Src_PD_OCP_UV_Threshold_Type),
+ NAME_INIT(Src_PD_OCP_UV_Threshold),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_component_src_pdo_name) == Src_PDO_Indexes);
+
+const char *vif_component_sop_svid_mode_name[] = {
+ NAME_INIT(SVID_Mode_Enter_SOP),
+ NAME_INIT(SVID_Mode_Recog_Mask_SOP),
+ NAME_INIT(SVID_Mode_Recog_Value_SOP),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_component_sop_svid_mode_name) ==
+ SopSVID_Mode_Indexes);
+
+const char *vif_component_sop_svid_name[] = {
+ NAME_INIT(SVID_SOP),
+ NAME_INIT(SVID_Modes_Fixed_SOP),
+ NAME_INIT(SVID_Num_Modes_Min_SOP),
+ NAME_INIT(SVID_Num_Modes_Max_SOP),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_component_sop_svid_name) == SopSVID_Indexes);
+
+const char *vif_cable_mode_name[] = {
+ NAME_INIT(SVID_Mode_Enter),
+ NAME_INIT(SVID_Mode_Recog_Mask),
+ NAME_INIT(SVID_Mode_Recog_Value),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_cable_mode_name) == CableSVID_Mode_Indexes);
+
+const char *vif_cable_svid_name[] = {
+ NAME_INIT(SVID),
+ NAME_INIT(SVID_Modes_Fixed),
+ NAME_INIT(SVID_Num_Modes_Min),
+ NAME_INIT(SVID_Num_Modes_Max),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_cable_svid_name) == CableSVID_Indexes);
+
+const char *vif_product_name[] = {
+ NAME_INIT(Product_VID),
+ NAME_INIT(USB4_Dock),
+ NAME_INIT(USB4_Num_Internal_Host_Controllers),
+ NAME_INIT(USB4_Num_PCIe_DN_Bridges),
+ NAME_INIT(USB4_Audio_Supported),
+ NAME_INIT(USB4_HID_Supported),
+ NAME_INIT(USB4_Printer_Supported),
+ NAME_INIT(USB4_Mass_Storage_Supported),
+ NAME_INIT(USB4_Video_Supported),
+ NAME_INIT(USB4_Comms_Networking_Supported),
+ NAME_INIT(USB4_Media_Transfer_Protocol_Supported),
+ NAME_INIT(USB4_Smart_Card_Supported),
+ NAME_INIT(USB4_Still_Image_Capture_Supported),
+ NAME_INIT(USB4_Monitor_Device_Supported),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_product_name) == Product_Indexes);
+
+const char *vif_product_pcie_endpoint_name[] = {
+ NAME_INIT(USB4_PCIe_Endpoint_Vendor_ID),
+ NAME_INIT(USB4_PCIe_Endpoint_Device_ID),
+ NAME_INIT(USB4_PCIe_Endpoint_Class_Code),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_product_pcie_endpoint_name) ==
+ PCIe_Endpoint_Indexes);
+
+const char *vif_product_usb4_router_name[] = {
+ NAME_INIT(USB4_Router_ID),
+ NAME_INIT(USB4_Silicon_VID),
+ NAME_INIT(USB4_Num_Lane_Adapters),
+ NAME_INIT(USB4_Num_USB3_DN_Adapters),
+ NAME_INIT(USB4_Num_DP_IN_Adapters),
+ NAME_INIT(USB4_Num_DP_OUT_Adapters),
+ NAME_INIT(USB4_Num_PCIe_DN_Adapters),
+ NAME_INIT(USB4_TBT3_Not_Supported),
+ NAME_INIT(USB4_PCIe_Wake_Supported),
+ NAME_INIT(USB4_USB3_Wake_Supported),
+ NAME_INIT(USB4_Num_Unused_Adapters),
+ NAME_INIT(USB4_TBT3_VID),
+ NAME_INIT(USB4_PCIe_Switch_Vendor_ID),
+ NAME_INIT(USB4_PCIe_Switch_Device_ID),
+ NAME_INIT(USB4_Num_PCIe_Endpoints),
+};
+BUILD_ASSERT(ARRAY_SIZE(vif_product_usb4_router_name) == USB4_Router_Indexes);
+
+
+static bool streq(const char *str1, const char *str2)
+{
+ return strcmp(str1, str2) == 0;
+}
+
+/*****************************************************************************
+ * VIF Structure Override Value Retrieve Functions
+ */
+__maybe_unused
+static bool get_vif_field_tag_number(struct vif_field_t *vif_field, int *value)
+{
+ if (vif_field->tag_value == NULL)
+ return false;
+
+ *value = atoi(vif_field->tag_value);
+ return true;
+}
+__maybe_unused
+static bool get_vif_field_str_number(struct vif_field_t *vif_field, int *value)
+{
+ if (vif_field->str_value == NULL)
+ return false;
+
+ *value = atoi(vif_field->str_value);
+ return true;
+}
+
+static bool get_vif_field_tag_bool(struct vif_field_t *vif_field, bool *value)
+{
+ if (vif_field->tag_value == NULL)
+ return false;
+
+ *value = streq(vif_field->tag_value, "true");
+ return true;
+}
+static bool get_vif_field_str_bool(struct vif_field_t *vif_field, bool *value)
+{
+ if (vif_field->str_value == NULL)
+ return false;
+
+ *value = streq(vif_field->str_value, "YES");
+ return true;
+}
+__maybe_unused
+static bool get_vif_field_bool(struct vif_field_t *vif_field, bool *value)
+{
+ bool rv;
+
+ rv = get_vif_field_tag_bool(vif_field, value);
+ if (!rv)
+ rv = get_vif_field_str_bool(vif_field, value);
+
+ return rv;
+}
+
+__maybe_unused
+static bool get_vif_field_tag_str(struct vif_field_t *vif_field, char **value)
+{
+ if (vif_field->tag_value == NULL)
+ return false;
+
+ *value = vif_field->tag_value;
+ return true;
+}
+__maybe_unused
+static bool get_vif_field_str_str(struct vif_field_t *vif_field, char **value)
+{
+ if (vif_field->str_value == NULL)
+ return false;
+
+ *value = vif_field->str_value;
+ return true;
+}
+/*
+ * VIF Structure Override Value Retrieve Functions
+ *****************************************************************************/
+
+
/*****************************************************************************
* Generic Helper Functions
*/
static bool is_src(void)
{
+ int override_value;
+ bool was_overridden;
+
+ /* Determine if we are DRP, SRC or SNK */
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[Type_C_State_Machine],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case SRC:
+ case DRP:
+ return true;
+ case SNK:
+ return false;
+ default:
+ was_overridden = false;
+ break;
+ }
+ }
+ if (!was_overridden) {
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[PD_Port_Type],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case PORT_PROVIDER_ONLY: /* SRC */
+ case PORT_DRP: /* DRP */
+ return true;
+ case PORT_CONSUMER_ONLY: /* SNK */
+ return false;
+ default:
+ was_overridden = false;
+ }
+ }
+ }
return src_pdo_cnt;
}
static bool is_snk(void)
{
+ int override_value;
+ bool was_overridden;
+
+ /* Determine if we are DRP, SRC or SNK */
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[Type_C_State_Machine],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case SNK:
+ case DRP:
+ return true;
+ case SRC:
+ return false;
+ default:
+ was_overridden = false;
+ break;
+ }
+ }
+ if (!was_overridden) {
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[PD_Port_Type],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case PORT_CONSUMER_ONLY: /* SNK */
+ case PORT_DRP: /* DRP */
+ return true;
+ case PORT_PROVIDER_ONLY: /* SRC */
+ return false;
+ default:
+ was_overridden = false;
+ }
+ }
+ }
return (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) ? pd_snk_pdo_cnt : 0;
}
static bool is_drp(void)
{
+ int override_value;
+ bool was_overridden;
+
+ /* Determine if we are DRP, SRC or SNK */
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[Type_C_State_Machine],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case DRP:
+ return true;
+ case SNK:
+ return false;
+ case SRC:
+ default:
+ was_overridden = false;
+ break;
+ }
+ }
+ if (!was_overridden) {
+ was_overridden = get_vif_field_tag_number(
+ &vif.Component[0]
+ .vif_field[PD_Port_Type],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case PORT_DRP: /* DRP */
+ return true;
+ case PORT_CONSUMER_ONLY: /* SNK */
+ return false;
+ case PORT_PROVIDER_ONLY: /* SRC */
+ default:
+ was_overridden = false;
+ }
+ }
+ }
if (is_src())
return !!(src_pdo[0] & PDO_FIXED_DUAL_ROLE);
return false;
@@ -85,6 +597,15 @@ static bool is_drp(void)
static bool can_act_as_device(void)
{
+ bool override_value;
+ bool was_overridden;
+
+ was_overridden = get_vif_field_bool(
+ &vif.Component[0].vif_field[Type_C_Can_Act_As_Device],
+ &override_value);
+ if (was_overridden)
+ return override_value;
+
#if defined(USB_DEV_CLASS) && defined(USB_CLASS_BILLBOARD)
return (USB_DEV_CLASS == USB_CLASS_BILLBOARD);
#else
@@ -94,6 +615,15 @@ static bool can_act_as_device(void)
static bool can_act_as_host(void)
{
+ bool override_value;
+ bool was_overridden;
+
+ was_overridden = get_vif_field_bool(
+ &vif.Component[0].vif_field[Type_C_Can_Act_As_Host],
+ &override_value);
+ if (was_overridden)
+ return override_value;
+
return (!(IS_ENABLED(CONFIG_USB_CTVPD) ||
IS_ENABLED(CONFIG_USB_VPD)));
}
@@ -125,6 +655,9 @@ static bool vif_fields_present(struct vif_field_t *vif_fields, int count)
}
return false;
}
+/*
+ * Generic Helper Functions
+ *****************************************************************************/
/*****************************************************************************
@@ -439,9 +972,7 @@ static void vif_output_vif_xml(FILE *vif_file, struct vif_t *vif, int level)
vif_out_field(vif_file, level, &vif->vif_field[VIF_Specification]);
vif_out_str(vif_file, level++, "<VIF_App>");
- vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Vendor]);
- vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Name]);
- vif_out_field(vif_file, level, &vif->vif_field[VIF_App_Version]);
+ vif_out_fields(vif_file, level, vif->vif_app_field, VIF_App_Indexes);
vif_out_str(vif_file, --level, "</VIF_App>");
vif_out_fields_range(vif_file, level,
@@ -454,8 +985,11 @@ static int vif_output_xml(const char *name, struct vif_t *vif)
FILE *vif_file;
vif_file = fopen(name, "w+");
- if (vif_file == NULL)
+ if (vif_file == NULL) {
+ fprintf(stderr, "Output file '%s' could not be created\n",
+ name);
return 1;
+ }
vif_out_str(vif_file, level,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
@@ -477,30 +1011,905 @@ static int vif_output_xml(const char *name, struct vif_t *vif)
/*****************************************************************************
- * VIF Structure Initialization Helper Functions
+ * VIF Structure Override from XML file functions
*/
-static void set_vif_field(struct vif_field_t *vif_field,
+FILE *override_file;
+
+int pushback_cnt;
+char pushback_stack[20];
+
+static bool ov_open(const char *over_name)
+{
+ override_file = fopen(over_name, "r");
+
+ pushback_cnt = 0;
+ return override_file != NULL;
+}
+static int ov_getc(void)
+{
+ if (!override_file)
+ return EOF;
+
+ if (pushback_cnt)
+ return pushback_stack[--pushback_cnt];
+ return getc(override_file);
+}
+static void ovpre_getc(int cnt)
+{
+ if (pushback_cnt < cnt) {
+ int new_pushback_cnt = cnt;
+
+ while (cnt > 0)
+ pushback_stack[--cnt] = ov_getc();
+ pushback_cnt = new_pushback_cnt;
+ }
+}
+static void ovpre_drop(int cnt)
+{
+ pushback_cnt -= cnt;
+ if (pushback_cnt < 0)
+ pushback_cnt = 0;
+}
+static int ovpre_peek(int index)
+{
+ return pushback_stack[pushback_cnt - index - 1];
+}
+static void ov_pushback(int ch)
+{
+ pushback_stack[pushback_cnt++] = ch;
+}
+static void ov_close(void)
+{
+ if (override_file)
+ fclose(override_file);
+
+ pushback_cnt = 0;
+ override_file = NULL;
+}
+
+
+static void set_override_vif_field(struct vif_field_t *vif_field,
const char *name,
const char *tag_value,
const char *str_value)
{
char *ptr;
- if (name) {
- ptr = malloc(strlen(name)+1);
- strcpy(ptr, name);
- vif_field->name = ptr;
+ if (vif_field->str_value) {
+ free(vif_field->str_value);
+ vif_field->str_value = NULL;
}
- if (str_value) {
+ if (vif_field->tag_value) {
+ free(vif_field->tag_value);
+ vif_field->tag_value = NULL;
+ }
+
+ vif_field->name = name;
+ if (tag_value && tag_value[0]) {
+ ptr = malloc(strlen(tag_value)+1);
+ strcpy(ptr, tag_value);
+ vif_field->tag_value = ptr;
+
+ /*
+ * If the tag_value was provided and the str_value was
+ * not and this is a boolean value, then fill in the
+ * str_value
+ */
+ if (!str_value || str_value[0] == '\0') {
+ if (streq(tag_value, "true"))
+ str_value = "YES";
+ else if (streq(tag_value, "false"))
+ str_value = "NO";
+ }
+ }
+ if (str_value && str_value[0]) {
ptr = malloc(strlen(str_value)+1);
strcpy(ptr, str_value);
vif_field->str_value = ptr;
}
+}
+
+static void ignore_xml_version_tag(void)
+{
+ int ch;
+
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '?') {
+ ch = ov_getc();
+ if (ch == '>')
+ break;
+ ov_pushback(ch);
+ }
+ }
+}
+static void ignore_comment_tag(void)
+{
+ int ch;
+
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '-') {
+ ovpre_getc(2);
+ if (ovpre_peek(0) == '-' &&
+ ovpre_peek(1) == '>') {
+ /* --> */
+ ovpre_drop(2);
+ break;
+ }
+ }
+ }
+}
+static void ignore_white_space(void)
+{
+ int ch;
+
+ while ((ch = ov_getc()) != EOF) {
+ if (!isspace(ch)) {
+ ov_pushback(ch);
+ break;
+ }
+ }
+}
+static void ignore_to_end_tag(void)
+{
+ int ch;
+
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '>')
+ break;
+ }
+}
+static bool get_next_tag(char *name,
+ char *tag_value,
+ char *str_value)
+{
+ int ch;
+ int name_index = 0;
+ int tag_index = 0;
+ int str_index = 0;
+
+ name[0] = '\0';
+ tag_value[0] = '\0';
+ str_value[0] = '\0';
+
+ /*
+ * Ignore <? .... ?>
+ * Ignore <!-- ... -->
+ * Find tags <X/>, <X> and </X>
+ */
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '<') {
+ /*
+ * Ignore XML version <? ... ?>
+ */
+ ovpre_getc(1);
+ if (ovpre_peek(0) == '?') {
+ ovpre_drop(1);
+ ignore_xml_version_tag();
+ continue;
+ }
+
+ /*
+ * Ignore XML comment <!-- ... -->
+ */
+ ovpre_getc(3);
+ if (ovpre_peek(0) == '!' &&
+ ovpre_peek(1) == '-' &&
+ ovpre_peek(2) == '-') {
+ ovpre_drop(3);
+ ignore_comment_tag();
+ continue;
+ }
+
+ /* Looking for terminating tag */
+ ovpre_getc(1);
+ if (ovpre_peek(0) == '/') {
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '>')
+ break;
+ name[name_index++] = ch;
+ }
+ name[name_index] = '\0';
+ return true;
+ }
+
+ /* Looking for a tag name */
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '_' || isalpha(ch) || isdigit(ch)) {
+ name[name_index++] = ch;
+ } else {
+ ov_pushback(ch);
+ break;
+ }
+ }
+ name[name_index] = '\0';
+
+ /* Consume any whitespace */
+ ignore_white_space();
+
+ /* See if there is a tag_string value */
+ ovpre_getc(7);
+ if (ovpre_peek(0) == 'v' &&
+ ovpre_peek(1) == 'a' &&
+ ovpre_peek(2) == 'l' &&
+ ovpre_peek(3) == 'u' &&
+ ovpre_peek(4) == 'e' &&
+ ovpre_peek(5) == '=' &&
+ ovpre_peek(6) == '"') {
+ ovpre_drop(7);
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '"')
+ break;
+ tag_value[tag_index++] = ch;
+ }
+ tag_value[tag_index] = '\0';
+ }
+
+ /* Consume any whitespace */
+ ignore_white_space();
+
+ /* /> ending the tag will conclude this tag */
+ ovpre_getc(2);
+ if (ovpre_peek(0) == '/' &&
+ ovpre_peek(1) == '>') {
+ ovpre_drop(2);
+ return true;
+ }
+ if (ovpre_peek(0) == '>') {
+ ovpre_drop(1);
+ while ((ch = ov_getc()) != EOF) {
+ if (ch == '<') {
+ ov_pushback(ch);
+ break;
+ }
+ str_value[str_index++] = ch;
+ }
+ str_value[str_index] = '\0';
+
+ ovpre_getc(2);
+ if (ovpre_peek(0) == '<' &&
+ ovpre_peek(1) == '/') {
+ ovpre_drop(2);
+ ignore_to_end_tag();
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+static void override_vif_product_pcie_endpoint_field(
+ struct vif_PCIeEndpointListType_t *endpoint)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/PCIeEndpoint"))
+ break;
+
+ for (i = 0; i < PCIe_Endpoint_Indexes; i++)
+ if (streq(name, vif_product_pcie_endpoint_name[i]))
+ break;
+ if (i != PCIe_Endpoint_Indexes)
+ set_override_vif_field(
+ &endpoint->vif_field[i],
+ vif_product_pcie_endpoint_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/USB4Router/PCIeEndpoint:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+static void override_vif_product_pcie_endpoint_list_field(
+ struct vif_PCIeEndpointListType_t *endpoint_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int endpoint_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/PCIeEndpointList"))
+ break;
+
+ if (streq(name, "PCIeEndpoint"))
+ override_vif_product_pcie_endpoint_field(
+ &endpoint_list[endpoint_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Product/USB4Router/PCIeEndpointList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_product_usb4router_fields(
+ struct vif_Usb4RouterListType_t *router)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int endpoint_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/USB4Router"))
+ break;
+
+ if (streq(name, "PCIeEndpointList"))
+ override_vif_product_pcie_endpoint_list_field(
+ &router->PCIeEndpointList[endpoint_index++]);
+ else {
+ int i;
+
+ for (i = 0; i < USB4_Router_Indexes; i++)
+ if (streq(name,
+ vif_product_usb4_router_name[i]))
+ break;
+ if (i != USB4_Router_Indexes)
+ set_override_vif_field(
+ &router->vif_field[i],
+ vif_product_usb4_router_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/USB4Router:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+}
+static void override_vif_product_usb4routerlist_fields(
+ struct vif_Usb4RouterListType_t *router_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int router_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/USB4RouterList"))
+ break;
+
+ if (streq(name, "USB4Router"))
+ override_vif_product_usb4router_fields(
+ &router_list[router_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Product/USB4RouterList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_product_fields(struct vif_Product_t *vif_product)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/Product"))
+ break;
+
+ if (streq(name, "USB4RouterList"))
+ override_vif_product_usb4routerlist_fields(
+ vif_product->USB4RouterList);
+ else {
+ int i;
+
+ for (i = 0; i < Product_Indexes; i++)
+ if (streq(name, vif_product_name[i]))
+ break;
+ if (i != Product_Indexes)
+ set_override_vif_field(
+ &vif_product->vif_field[i],
+ vif_product_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIFF/Product:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+}
+
+static void override_vif_component_src_pdo_fields(
+ struct vif_srcPdoList_t *vif_src_pdo)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/SrcPdo"))
+ break;
+
+ for (i = 0; i < Src_PDO_Indexes; i++)
+ if (streq(name, vif_component_src_pdo_name[i]))
+ break;
+ if (i != Src_PDO_Indexes)
+ set_override_vif_field(
+ &vif_src_pdo->vif_field[i],
+ vif_component_src_pdo_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/SrcPdo:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+static void override_vif_component_src_pdo_list_fields(
+ struct vif_srcPdoList_t *vif_src_pdo_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int src_pdo_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/SrcPdoList"))
+ break;
+
+ if (streq(name, "SrcPdo"))
+ override_vif_component_src_pdo_fields(
+ &vif_src_pdo_list[src_pdo_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/SrcPdoList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_snk_pdo_fields(
+ struct vif_snkPdoList_t *vif_snk_pdo)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/SnkPdo"))
+ break;
+
+ for (i = 0; i < Snk_PDO_Indexes; i++)
+ if (streq(name, vif_component_snk_pdo_name[i]))
+ break;
+ if (i != Snk_PDO_Indexes)
+ set_override_vif_field(
+ &vif_snk_pdo->vif_field[i],
+ vif_component_snk_pdo_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/SnkPdo:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+static void override_vif_component_snk_pdo_list_fields(
+ struct vif_snkPdoList_t *vif_snk_pdo_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int snk_pdo_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/SnkPdoList"))
+ break;
+
+ if (streq(name, "SnkPdo"))
+ override_vif_component_snk_pdo_fields(
+ &vif_snk_pdo_list[snk_pdo_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/SnkPdoList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_sop_svid_mode_fields(
+ struct vif_sopSVIDModeList_t *svid_mode)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/SOPSVIDMode"))
+ break;
+
+ for (i = 0; i < SopSVID_Indexes; i++)
+ if (streq(name, vif_component_sop_svid_mode_name[i]))
+ break;
+ if (i != SopSVID_Indexes)
+ set_override_vif_field(
+ &svid_mode->vif_field[i],
+ vif_component_sop_svid_mode_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/SOPSVIDMode:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+static void override_vif_component_sop_svid_mode_list_fields(
+ struct vif_sopSVIDModeList_t *svid_mode_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int mode_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/SOPSVIDModeList"))
+ break;
+
+ if (streq(name, "SOPSVIDMode"))
+ override_vif_component_sop_svid_mode_fields(
+ &svid_mode_list[mode_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/SOPSVIDModeList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_sop_svid_fields(
+ struct vif_sopSVIDList_t *vif_sop_svid)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/SOPSVID"))
+ break;
+
+ if (streq(name, "SOPSVIDModeList"))
+ override_vif_component_sop_svid_mode_list_fields(
+ vif_sop_svid->SOPSVIDModeList);
+ else {
+ int i;
+
+ for (i = 0; i < SopSVID_Indexes; i++)
+ if (streq(name,
+ vif_component_sop_svid_name[i]))
+ break;
+ if (i != SopSVID_Indexes)
+ set_override_vif_field(
+ &vif_sop_svid->vif_field[i],
+ vif_component_sop_svid_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/SOPSVID:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+}
+static void override_vif_component_sop_svid_list_fields(
+ struct vif_sopSVIDList_t *vif_sop_svid_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int sop_svid_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/SOPSVIDList"))
+ break;
+
+ if (streq(name, "SOPSVID"))
+ override_vif_component_sop_svid_fields(
+ &vif_sop_svid_list[sop_svid_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/SOPSVIDList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_cable_svid_mode_fields(
+ struct vif_cableSVIDModeList_t *vif_cable_mode)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/CableSVIDMode"))
+ break;
+
+ for (i = 0; i < CableSVID_Mode_Indexes; i++)
+ if (streq(name, vif_cable_mode_name[i]))
+ break;
+ if (i != CableSVID_Mode_Indexes)
+ set_override_vif_field(
+ &vif_cable_mode->vif_field[i],
+ vif_cable_mode_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/CableSVIDMode:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+static void override_vif_component_cable_svid_mode_list_fields(
+ struct vif_cableSVIDModeList_t *vif_cable_mode_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int mode_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/CableSVIDModeList"))
+ break;
+
+ if (streq(name, "CableSVIDMode"))
+ override_vif_component_cable_svid_mode_fields(
+ &vif_cable_mode_list[mode_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/CableSVIDModeList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_cable_svid_fields(
+ struct vif_cableSVIDList_t *vif_cable_svid)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int mode_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/CableSVID"))
+ break;
+
+ if (streq(name, "CableSVIDModeList"))
+ override_vif_component_cable_svid_mode_list_fields(
+ &vif_cable_svid->CableSVIDModeList[
+ mode_index++]);
+ else {
+ int i;
+
+ for (i = 0; i < CableSVID_Indexes; i++)
+ if (streq(name, vif_cable_svid_name[i]))
+ break;
+ if (i != CableSVID_Indexes)
+ set_override_vif_field(
+ &vif_cable_svid->vif_field[i],
+ vif_cable_svid_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component/CableSVID:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+}
+static void override_vif_component_cable_svid_list_fields(
+ struct vif_cableSVIDList_t *vif_cable_svid_list)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int cable_svid_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/CableSVIDList"))
+ break;
+
+ if (streq(name, "CableSVID"))
+ override_vif_component_cable_svid_fields(
+ &vif_cable_svid_list[cable_svid_index++]);
+ else
+ fprintf(stderr,
+ "VIF/Component/CableSVIDList:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_component_fields(
+ struct vif_Component_t *vif_component)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/Component"))
+ break;
+
+ if (streq(name, "SrcPdoList"))
+ override_vif_component_src_pdo_list_fields(
+ vif_component->SrcPdoList);
+ else if (streq(name, "SnkPdoList"))
+ override_vif_component_snk_pdo_list_fields(
+ vif_component->SnkPdoList);
+ else if (streq(name, "SOPSVIDList"))
+ override_vif_component_sop_svid_list_fields(
+ vif_component->SOPSVIDList);
+ else if (streq(name, "CableSVIDList"))
+ override_vif_component_cable_svid_list_fields(
+ vif_component->CableSVIDList);
+ else {
+ int i;
+
+ for (i = 0; i < Component_Indexes; i++)
+ if (streq(name, vif_component_name[i]))
+ break;
+ if (i != Component_Indexes)
+ set_override_vif_field(
+ &vif_component->vif_field[i],
+ vif_component_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF/Component:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+}
+
+static void override_vif_app_fields(struct vif_t *vif)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ int i;
+
+ if (streq(name, "/VIF_App"))
+ break;
+
+ for (i = 0; i < VIF_App_Indexes; i++)
+ if (streq(name, vif_app_name[i]))
+ break;
+ if (i == VIF_App_Indexes)
+ fprintf(stderr,
+ "VIFF/VIF_App:"
+ " Unknown tag '%s'\n", name);
+ }
+}
+
+static void override_vif_fields(struct vif_t *vif)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+ int component_index = 0;
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "/VIF"))
+ break;
+
+ if (streq(name, "VIF_App"))
+ override_vif_app_fields(vif);
+ else if (streq(name, "Component"))
+ override_vif_component_fields(
+ &vif->Component[component_index++]);
+ else if (streq(name, "Product"))
+ override_vif_product_fields(&vif->Product);
+ else {
+ int i;
+
+ for (i = 0; i < VIF_Indexes; i++)
+ if (streq(name, vif_name[i]))
+ break;
+ if (i != VIF_Indexes)
+ set_override_vif_field(
+ &vif->vif_field[i],
+ vif_name[i],
+ tag_value,
+ str_value);
+ else
+ fprintf(stderr,
+ "VIF:"
+ " Unknown tag '%s'\n", name);
+ }
+ }
+
+ /*
+ * Don't care what they requested, I am making the file and that
+ * means VIF/VIF_App is to be set by me.
+ */
+ set_override_vif_field(&vif->vif_app_field[Vendor],
+ vif_app_name[Vendor],
+ NULL,
+ VIF_APP_VENDOR_VALUE);
+
+ set_override_vif_field(&vif->vif_app_field[Name],
+ vif_app_name[Name],
+ NULL,
+ VIF_APP_NAME_VALUE);
+
+ set_override_vif_field(&vif->vif_app_field[Version],
+ vif_app_name[Version],
+ NULL,
+ VIF_APP_VERSION_VALUE);
+}
+
+static int override_gen_vif(char *over_name, struct vif_t *vif)
+{
+ char name[80];
+ char tag_value[80];
+ char str_value[80];
+
+ if (!ov_open(over_name)) {
+ fprintf(stderr, "Override file '%s' could not be opened\n",
+ over_name);
+ return 1;
+ }
+
+ while (get_next_tag(name, tag_value, str_value)) {
+ if (streq(name, "VIF"))
+ override_vif_fields(vif);
+ else
+ fprintf(stderr,
+ "Unknown tag '%s'\n", name);
+ }
+
+ ov_close();
+ return 0;
+}
+/*
+ * VIF Structure Override from XML file functions
+ *****************************************************************************/
+
+
+/*****************************************************************************
+ * VIF Structure Initialization Helper Functions
+ */
+static void set_vif_field(struct vif_field_t *vif_field,
+ const char *name,
+ const char *tag_value,
+ const char *str_value)
+{
+ char *ptr;
+
+ /*
+ * Override already set or trying to set to nothing should do
+ * nothing. Just return
+ */
+ if ((vif_field->name || vif_field->str_value || vif_field->tag_value) ||
+ (str_value == NULL && tag_value == NULL))
+ return;
+
+ vif_field->name = name;
if (tag_value) {
ptr = malloc(strlen(tag_value)+1);
strcpy(ptr, tag_value);
vif_field->tag_value = ptr;
}
+ if (str_value) {
+ ptr = malloc(strlen(str_value)+1);
+ strcpy(ptr, str_value);
+ vif_field->str_value = ptr;
+ }
}
__maybe_unused static void set_vif_field_b(struct vif_field_t *vif_field,
const char *name,
@@ -516,7 +1925,7 @@ __maybe_unused static void set_vif_field_stis(struct vif_field_t *vif_field,
const char *tag_value,
const int str_value)
{
- char str_str[80];
+ char str_str[20];
sprintf(str_str, "%d", str_value);
set_vif_field(vif_field, name, tag_value, str_str);
@@ -526,7 +1935,7 @@ __maybe_unused static void set_vif_field_itss(struct vif_field_t *vif_field,
const int tag_value,
const char *str_value)
{
- char str_tag[80];
+ char str_tag[20];
sprintf(str_tag, "%d", tag_value);
set_vif_field(vif_field, name, str_tag, str_value);
@@ -536,8 +1945,8 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field,
const int tag_value,
const int str_value)
{
- char str_tag[80];
- char str_str[80];
+ char str_tag[20];
+ char str_str[20];
sprintf(str_tag, "%d", tag_value);
sprintf(str_str, "%d", str_value);
@@ -547,7 +1956,6 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field,
* VIF Structure Initialization Helper Functions
*****************************************************************************/
-
/*****************************************************************************
* VIF Structure Initialization from Config Functions
*/
@@ -723,16 +2131,16 @@ __maybe_unused static int32_t init_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo,
power_mw = (current_ma * voltage_mv) / 1000;
set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type],
- "Snk_PDO_Supply_Type",
- "0", "Fixed");
+ vif_component_snk_pdo_name[Snk_PDO_Supply_Type],
+ "0", "Fixed");
sprintf(str, "%dmV", voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Voltage],
- "Snk_PDO_Voltage",
- voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Voltage],
+ voltage, str);
sprintf(str, "%dmA", current_ma);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current],
- "Snk_PDO_Op_Current",
- current, str);
+ vif_component_snk_pdo_name[Snk_PDO_Op_Current],
+ current, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
uint32_t max_voltage = (pdo >> 20) & 0x3ff;
@@ -745,20 +2153,20 @@ __maybe_unused static int32_t init_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo,
power_mw = power * 250;
set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type],
- "Snk_PDO_Supply_Type",
- "1", "Battery");
+ vif_component_snk_pdo_name[Snk_PDO_Supply_Type],
+ "1", "Battery");
sprintf(str, "%dmV", min_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage],
- "Snk_PDO_Min_Voltage",
- min_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Min_Voltage],
+ min_voltage, str);
sprintf(str, "%dmV", max_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage],
- "Snk_PDO_Max_Voltage",
- max_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Max_Voltage],
+ max_voltage, str);
sprintf(str, "%dmW", power_mw);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Power],
- "Snk_PDO_Op_Power",
- power, str);
+ vif_component_snk_pdo_name[Snk_PDO_Op_Power],
+ power, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_VARIABLE) {
uint32_t max_voltage = (pdo >> 20) & 0x3ff;
@@ -771,20 +2179,20 @@ __maybe_unused static int32_t init_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo,
power_mw = (current_ma * max_voltage_mv) / 1000;
set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type],
- "Snk_PDO_Supply_Type",
- "2", "Variable (non-battery)");
+ vif_component_snk_pdo_name[Snk_PDO_Supply_Type],
+ "2", "Variable (non-battery)");
sprintf(str, "%dmV", min_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage],
- "Snk_PDO_Min_Voltage",
- min_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Min_Voltage],
+ min_voltage, str);
sprintf(str, "%dmV", max_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage],
- "Snk_PDO_Max_Voltage",
- max_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Max_Voltage],
+ max_voltage, str);
sprintf(str, "%dmA", current_ma);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current],
- "Snk_PDO_Op_Current",
- current, str);
+ vif_component_snk_pdo_name[Snk_PDO_Op_Current],
+ current, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) {
uint32_t pps = (pdo >> 28) & 3;
@@ -803,20 +2211,20 @@ __maybe_unused static int32_t init_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo,
power_mw = (pps_current_ma * pps_max_voltage_mv) / 1000;
set_vif_field(&snkPdo->vif_field[Snk_PDO_Supply_Type],
- "Snk_PDO_Supply_Type",
- "3", "PPS");
+ vif_component_snk_pdo_name[Snk_PDO_Supply_Type],
+ "3", "PPS");
sprintf(str, "%dmA", pps_current_ma);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Op_Current],
- "Snk_PDO_Op_Current",
- pps_current, str);
+ vif_component_snk_pdo_name[Snk_PDO_Op_Current],
+ pps_current, str);
sprintf(str, "%dmV", pps_min_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Min_Voltage],
- "Snk_PDO_Min_Voltage",
- pps_min_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Min_Voltage],
+ pps_min_voltage, str);
sprintf(str, "%dmV", pps_max_voltage_mv);
set_vif_field_itss(&snkPdo->vif_field[Snk_PDO_Max_Voltage],
- "Snk_PDO_Max_Voltage",
- pps_max_voltage, str);
+ vif_component_snk_pdo_name[Snk_PDO_Max_Voltage],
+ pps_max_voltage, str);
} else {
fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo);
return -1;
@@ -855,19 +2263,19 @@ __maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo,
power_mw = (current_ma * voltage_mv) / 1000;
set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type],
- "Src_PDO_Supply_Type",
- "0", "Fixed");
+ vif_component_src_pdo_name[Src_PDO_Supply_Type],
+ "0", "Fixed");
set_vif_field(&srcPdo->vif_field[Src_PDO_Peak_Current],
- "Src_PDO_Peak_Current",
- "0", "100% IOC");
+ vif_component_src_pdo_name[Src_PDO_Peak_Current],
+ "0", "100% IOC");
sprintf(str, "%dmV", voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Voltage],
- "Src_PDO_Voltage",
- voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Voltage],
+ voltage, str);
sprintf(str, "%dmA", current_ma);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current],
- "Src_PDO_Max_Current",
- current, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Current],
+ current, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
uint32_t max_voltage = (pdo >> 20) & 0x3ff;
@@ -880,20 +2288,20 @@ __maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo,
power_mw = power * 250;
set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type],
- "Src_PDO_Supply_Type",
- "1", "Battery");
+ vif_component_src_pdo_name[Src_PDO_Supply_Type],
+ "1", "Battery");
sprintf(str, "%dmV", min_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage],
- "Src_PDO_Min_Voltage",
- min_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Min_Voltage],
+ min_voltage, str);
sprintf(str, "%dmV", max_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Voltage],
- "Src_PDO_Max_Voltage",
- max_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Voltage],
+ max_voltage, str);
sprintf(str, "%dmW", power_mw);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Power],
- "Src_PDO_Max_Power",
- power, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Power],
+ power, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_VARIABLE) {
uint32_t max_voltage = (pdo >> 20) & 0x3ff;
@@ -906,23 +2314,23 @@ __maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo,
power_mw = (current_ma * max_voltage_mv) / 1000;
set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type],
- "Src_PDO_Supply_Type",
- "2", "Variable (non-battery)");
+ vif_component_src_pdo_name[Src_PDO_Supply_Type],
+ "2", "Variable (non-battery)");
set_vif_field(&srcPdo->vif_field[Src_PDO_Peak_Current],
- "Src_PDO_Peak_Current",
- "0", "100% IOC");
+ vif_component_src_pdo_name[Src_PDO_Peak_Current],
+ "0", "100% IOC");
sprintf(str, "%dmV", min_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage],
- "Src_PDO_Min_Voltage",
- min_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Min_Voltage],
+ min_voltage, str);
sprintf(str, "%dmV", max_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Voltage],
- "Src_PDO_Max_Voltage",
- max_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Voltage],
+ max_voltage, str);
sprintf(str, "%dmA", current_ma);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current],
- "Src_PDO_Max_Current",
- current, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Current],
+ current, str);
} else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) {
uint32_t pps = (pdo >> 28) & 3;
@@ -941,20 +2349,20 @@ __maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo,
power_mw = (pps_current_ma * pps_max_voltage_mv) / 1000;
set_vif_field(&srcPdo->vif_field[Src_PDO_Supply_Type],
- "Src_PDO_Supply_Type",
- "3", "PPS");
+ vif_component_src_pdo_name[Src_PDO_Supply_Type],
+ "3", "PPS");
sprintf(str, "%dmA", pps_current_ma);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Current],
- "Src_PDO_Max_Current",
- pps_current, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Current],
+ pps_current, str);
sprintf(str, "%dmV", pps_min_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Min_Voltage],
- "Src_PDO_Min_Voltage",
- pps_min_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Min_Voltage],
+ pps_min_voltage, str);
sprintf(str, "%dmV", pps_max_voltage_mv);
set_vif_field_itss(&srcPdo->vif_field[Src_PDO_Max_Voltage],
- "Src_PDO_Max_Voltage",
- pps_max_voltage, str);
+ vif_component_src_pdo_name[Src_PDO_Max_Voltage],
+ pps_max_voltage, str);
} else {
fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo);
@@ -968,84 +2376,85 @@ __maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo,
* Init VIF Fields
*/
static void init_vif_fields(struct vif_field_t *vif_fields,
+ struct vif_field_t *vif_app_fields,
const char *board)
{
set_vif_field(&vif_fields[VIF_Specification],
- "VIF_Specification",
- NULL,
- "3.12");
+ vif_name[VIF_Specification],
+ NULL,
+ "3.12");
- set_vif_field(&vif_fields[VIF_App_Vendor],
- "Vendor",
- NULL,
- VIF_APP_VENDOR_VALUE);
+ set_vif_field(&vif_app_fields[Vendor],
+ vif_app_name[Vendor],
+ NULL,
+ VIF_APP_VENDOR_VALUE);
- set_vif_field(&vif_fields[VIF_App_Name],
- "Name",
- NULL,
- VIF_APP_NAME_VALUE);
+ set_vif_field(&vif_app_fields[Name],
+ vif_app_name[Name],
+ NULL,
+ VIF_APP_NAME_VALUE);
- set_vif_field(&vif_fields[VIF_App_Version],
- "Version",
- NULL,
- VIF_APP_VERSION_VALUE);
+ set_vif_field(&vif_app_fields[Version],
+ vif_app_name[Version],
+ NULL,
+ VIF_APP_VERSION_VALUE);
set_vif_field(&vif_fields[Vendor_Name],
- "Vendor_Name",
- NULL,
- VENDOR_NAME_VALUE);
+ vif_name[Vendor_Name],
+ NULL,
+ VENDOR_NAME_VALUE);
#if defined(CONFIG_USB_PD_MODEL_PART_NUMBER)
set_vif_field(&vif_fields[Model_Part_Number],
- "Model_Part_Number",
- NULL,
- CONFIG_USB_PD_MODEL_PART_NUMBER);
+ vif_name[Model_Part_Number],
+ NULL,
+ CONFIG_USB_PD_MODEL_PART_NUMBER);
#else
if (board && strlen(board) > 0)
set_vif_field(&vif_fields[Model_Part_Number],
- "Model_Part_Number",
- NULL,
- board);
+ vif_name[Model_Part_Number],
+ NULL,
+ board);
else
set_vif_field(&vif_fields[Model_Part_Number],
- "Model_Part_Number",
- NULL,
- "FIX-ME");
+ vif_name[Model_Part_Number],
+ NULL,
+ "FIX-ME");
#endif
#if defined(CONFIG_USB_PD_PRODUCT_REVISION)
set_vif_field(&vif_fields[Product_Revision],
- "Product_Revision",
- NULL,
- CONFIG_USB_PD_PRODUCT_REVISION);
+ vif_name[Product_Revision],
+ NULL,
+ CONFIG_USB_PD_PRODUCT_REVISION);
#else
set_vif_field(&vif_fields[Product_Revision],
- "Product_Revision",
- NULL,
- "FIX-ME");
+ vif_name[Product_Revision],
+ NULL,
+ "FIX-ME");
#endif
#if defined(CONFIG_USB_PD_TID)
set_vif_field_stis(&vif_fields[TID],
- "TID",
- NULL,
- CONFIG_USB_PD_TID);
+ vif_name[TID],
+ NULL,
+ CONFIG_USB_PD_TID);
#else
set_vif_field_stis(&vif_fields[TID],
- "TID",
- NULL,
- DEFAULT_MISSING_TID);
+ vif_name[TID],
+ NULL,
+ DEFAULT_MISSING_TID);
#endif
set_vif_field(&vif_fields[VIF_Product_Type],
- "VIF_Product_Type",
- "0",
- "Port Product");
+ vif_name[VIF_Product_Type],
+ "0",
+ "Port Product");
set_vif_field(&vif_fields[Certification_Type],
- "Certification_Type",
- "0",
- "End Product");
+ vif_name[Certification_Type],
+ "0",
+ "End Product");
}
/*********************************************************************
@@ -1053,14 +2462,12 @@ static void init_vif_fields(struct vif_field_t *vif_fields,
*/
static void init_vif_product_fields(struct vif_field_t *vif_fields)
{
- {
- char hex_str[10];
+ char hex_str[10];
- sprintf(hex_str, "%04X", USB_VID_GOOGLE);
- set_vif_field_itss(&vif_fields[Product_VID],
- "Product_VID",
- USB_VID_GOOGLE, hex_str);
- }
+ sprintf(hex_str, "%04X", USB_VID_GOOGLE);
+ set_vif_field_itss(&vif_fields[Product_VID],
+ vif_product_name[Product_VID],
+ USB_VID_GOOGLE, hex_str);
}
/*********************************************************************
@@ -1080,70 +2487,70 @@ static void init_vif_component_fields(struct vif_field_t *vif_fields,
{
#if defined(CONFIG_USB_PD_PORT_LABEL)
set_vif_field_stis(&vif_fields[Port_Label],
- "Port_Label",
- NULL,
- CONFIG_USB_PD_PORT_LABEL);
+ vif_component_name[Port_Label],
+ NULL,
+ CONFIG_USB_PD_PORT_LABEL);
#else
set_vif_field(&vif_fields[Port_Label],
- "Port_Label",
- NULL,
- "0");
+ vif_component_name[Port_Label],
+ NULL,
+ "0");
#endif
set_vif_field(&vif_fields[Connector_Type],
- "Connector_Type",
- "2",
- "USB Type-C");
+ vif_component_name[Connector_Type],
+ "2",
+ "USB Type-C");
set_vif_field_b(&vif_fields[USB4_Supported],
- "USB4_Supported",
- IS_ENABLED(CONFIG_USB_PD_USB4));
+ vif_component_name[USB4_Supported],
+ IS_ENABLED(CONFIG_USB_PD_USB4));
set_vif_field_b(&vif_fields[USB_PD_Support],
- "USB_PD_Support",
- (IS_ENABLED(CONFIG_USB_PRL_SM) ||
- IS_ENABLED(CONFIG_USB_POWER_DELIVERY)));
+ vif_component_name[USB_PD_Support],
+ (IS_ENABLED(CONFIG_USB_PRL_SM) ||
+ IS_ENABLED(CONFIG_USB_POWER_DELIVERY)));
switch (type) {
case SNK:
set_vif_field(&vif_fields[PD_Port_Type],
- "PD_Port_Type",
- "0",
- "Consumer Only");
+ vif_component_name[PD_Port_Type],
+ "0",
+ "Consumer Only");
set_vif_field(&vif_fields[Type_C_State_Machine],
- "Type_C_State_Machine",
- "1",
- "SNK");
+ vif_component_name[Type_C_State_Machine],
+ "1",
+ "SNK");
break;
case SRC:
set_vif_field(&vif_fields[PD_Port_Type],
- "PD_Port_Type",
- "3",
- "Provider Only");
+ vif_component_name[PD_Port_Type],
+ "3",
+ "Provider Only");
set_vif_field(&vif_fields[Type_C_State_Machine],
- "Type_C_State_Machine",
- "0",
- "SRC");
+ vif_component_name[Type_C_State_Machine],
+ "0",
+ "SRC");
break;
case DRP:
set_vif_field(&vif_fields[PD_Port_Type],
- "PD_Port_Type",
- "4",
- "DRP");
+ vif_component_name[PD_Port_Type],
+ "4",
+ "DRP");
set_vif_field(&vif_fields[Type_C_State_Machine],
- "Type_C_State_Machine",
- "2",
- "DRP");
+ vif_component_name[Type_C_State_Machine],
+ "2",
+ "DRP");
break;
}
set_vif_field_b(&vif_fields[Captive_Cable],
- "Captive_Cable",
- false);
+ vif_component_name[Captive_Cable],
+ false);
set_vif_field_b(&vif_fields[Port_Battery_Powered],
- "Port_Battery_Powered",
- IS_ENABLED(CONFIG_BATTERY));
+ vif_component_name[Port_Battery_Powered],
+ IS_ENABLED(CONFIG_BATTERY));
*bc_support = BC_1_2_SUPPORT_NONE;
if (IS_ENABLED(CONFIG_BC12_DETECT_MAX14637))
@@ -1158,27 +2565,27 @@ static void init_vif_component_fields(struct vif_field_t *vif_fields,
switch (*bc_support) {
case BC_1_2_SUPPORT_NONE:
set_vif_field(&vif_fields[BC_1_2_Support],
- "BC_1_2_Support",
- "0",
- "None");
+ vif_component_name[BC_1_2_Support],
+ "0",
+ "None");
break;
case BC_1_2_SUPPORT_PORTABLE_DEVICE:
set_vif_field(&vif_fields[BC_1_2_Support],
- "BC_1_2_Support",
- "1",
- "Portable Device");
+ vif_component_name[BC_1_2_Support],
+ "1",
+ "Portable Device");
break;
case BC_1_2_SUPPORT_CHARGING_PORT:
set_vif_field(&vif_fields[BC_1_2_Support],
- "BC_1_2_Support",
- "2",
- "Charging Port");
+ vif_component_name[BC_1_2_Support],
+ "2",
+ "Charging Port");
break;
case BC_1_2_SUPPORT_BOTH:
set_vif_field(&vif_fields[BC_1_2_Support],
- "BC_1_2_Support",
- "3",
- "Both");
+ vif_component_name[BC_1_2_Support],
+ "3",
+ "Both");
break;
}
}
@@ -1192,52 +2599,52 @@ static void init_vif_component_general_pd_fields(
{
if (IS_ENABLED(CONFIG_USB_PD_REV30) || IS_ENABLED(CONFIG_USB_PRL_SM)) {
set_vif_field(&vif_fields[PD_Spec_Revision_Major],
- "PD_Spec_Revision_Major",
- "3",
- NULL);
+ vif_component_name[PD_Spec_Revision_Major],
+ "3",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Revision_Minor],
- "PD_Spec_Revision_Minor",
- "0",
- NULL);
+ vif_component_name[PD_Spec_Revision_Minor],
+ "0",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Version_Major],
- "PD_Spec_Version_Major",
- "2",
- NULL);
+ vif_component_name[PD_Spec_Version_Major],
+ "2",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Version_Minor],
- "PD_Spec_Version_Minor",
- "0",
- NULL);
+ vif_component_name[PD_Spec_Version_Minor],
+ "0",
+ NULL);
set_vif_field(&vif_fields[PD_Specification_Revision],
- "PD_Specification_Revision",
- "2",
- "Revision 3.0");
+ vif_component_name[PD_Specification_Revision],
+ "2",
+ "Revision 3.0");
} else {
set_vif_field(&vif_fields[PD_Spec_Revision_Major],
- "PD_Spec_Revision_Major",
- "2",
- NULL);
+ vif_component_name[PD_Spec_Revision_Major],
+ "2",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Revision_Minor],
- "PD_Spec_Revision_Minor",
- "0",
- NULL);
+ vif_component_name[PD_Spec_Revision_Minor],
+ "0",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Version_Major],
- "PD_Spec_Version_Major",
- "1",
- NULL);
+ vif_component_name[PD_Spec_Version_Major],
+ "1",
+ NULL);
set_vif_field(&vif_fields[PD_Spec_Version_Minor],
- "PD_Spec_Version_Minor",
- "3",
- NULL);
+ vif_component_name[PD_Spec_Version_Minor],
+ "3",
+ NULL);
set_vif_field(&vif_fields[PD_Specification_Revision],
- "PD_Specification_Revision",
- "1",
- "Revision 2.0");
+ vif_component_name[PD_Specification_Revision],
+ "1",
+ "Revision 2.0");
}
set_vif_field_b(&vif_fields[USB_Comms_Capable],
- "USB_Comms_Capable",
+ vif_component_name[USB_Comms_Capable],
(!(IS_ENABLED(CONFIG_USB_VPD) ||
IS_ENABLED(CONFIG_USB_CTVPD))));
@@ -1265,8 +2672,8 @@ static void init_vif_component_general_pd_fields(
supports_to_dfp &= can_act_as_device();
set_vif_field_b(&vif_fields[DR_Swap_To_DFP_Supported],
- "DR_Swap_To_DFP_Supported",
- supports_to_dfp);
+ vif_component_name[DR_Swap_To_DFP_Supported],
+ supports_to_dfp);
}
{
@@ -1293,8 +2700,8 @@ static void init_vif_component_general_pd_fields(
supports_to_ufp &= can_act_as_host();
set_vif_field_b(&vif_fields[DR_Swap_To_UFP_Supported],
- "DR_Swap_To_UFP_Supported",
- supports_to_ufp);
+ vif_component_name[DR_Swap_To_UFP_Supported],
+ supports_to_ufp);
}
if (is_src()) {
@@ -1302,7 +2709,7 @@ static void init_vif_component_general_pd_fields(
if (IS_ENABLED(CONFIG_CHARGER))
/* USB-C UP bit set */
set_vif_field_b(&vif_fields[Unconstrained_Power],
- "Unconstrained_Power",
+ vif_component_name[Unconstrained_Power],
(src_pdo[0] & PDO_FIXED_UNCONSTRAINED));
else {
/* Barrel charger being used */
@@ -1314,104 +2721,104 @@ static void init_vif_component_general_pd_fields(
#endif
set_vif_field_b(&vif_fields[Unconstrained_Power],
- "Unconstrained_Power",
+ vif_component_name[Unconstrained_Power],
(dedicated_charge_port_count > 0));
}
} else {
/* Not SRC capable */
set_vif_field_b(&vif_fields[Unconstrained_Power],
- "Unconstrained_Power",
- false);
+ vif_component_name[Unconstrained_Power],
+ false);
}
set_vif_field_b(&vif_fields[VCONN_Swap_To_On_Supported],
- "VCONN_Swap_To_On_Supported",
- IS_ENABLED(CONFIG_USBC_VCONN_SWAP));
+ vif_component_name[VCONN_Swap_To_On_Supported],
+ IS_ENABLED(CONFIG_USBC_VCONN_SWAP));
set_vif_field_b(&vif_fields[VCONN_Swap_To_Off_Supported],
- "VCONN_Swap_To_Off_Supported",
- IS_ENABLED(CONFIG_USBC_VCONN_SWAP));
+ vif_component_name[VCONN_Swap_To_Off_Supported],
+ IS_ENABLED(CONFIG_USBC_VCONN_SWAP));
set_vif_field_b(&vif_fields[Responds_To_Discov_SOP_UFP],
- "Responds_To_Discov_SOP_UFP",
- (IS_ENABLED(CONFIG_USB_PD_USB4) ||
- IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)));
+ vif_component_name[Responds_To_Discov_SOP_UFP],
+ (IS_ENABLED(CONFIG_USB_PD_USB4) ||
+ IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)));
set_vif_field_b(&vif_fields[Responds_To_Discov_SOP_DFP],
- "Responds_To_Discov_SOP_DFP",
- (IS_ENABLED(CONFIG_USB_PD_USB4) ||
- IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)));
+ vif_component_name[Responds_To_Discov_SOP_DFP],
+ (IS_ENABLED(CONFIG_USB_PD_USB4) ||
+ IS_ENABLED(CONFIG_USB_PD_TBT_COMPAT_MODE)));
set_vif_field_b(&vif_fields[Attempts_Discov_SOP],
- "Attempts_Discov_SOP",
- ((!IS_ENABLED(CONFIG_USB_PD_SIMPLE_DFP)) ||
- (type != SRC)));
+ vif_component_name[Attempts_Discov_SOP],
+ ((!IS_ENABLED(CONFIG_USB_PD_SIMPLE_DFP)) ||
+ (type != SRC)));
set_vif_field_b(&vif_fields[Chunking_Implemented_SOP],
- "Chunking_Implemented_SOP",
- (IS_ENABLED(CONFIG_USB_PD_REV30) &&
- IS_ENABLED(CONFIG_USB_PRL_SM)));
+ vif_component_name[Chunking_Implemented_SOP],
+ (IS_ENABLED(CONFIG_USB_PD_REV30) &&
+ IS_ENABLED(CONFIG_USB_PRL_SM)));
set_vif_field_b(&vif_fields[Unchunked_Extended_Messages_Supported],
- "Unchunked_Extended_Messages_Supported",
- false);
+ vif_component_name[Unchunked_Extended_Messages_Supported],
+ false);
if (IS_ENABLED(CONFIG_USB_PD_MANUFACTURER_INFO)) {
char hex_str[10];
set_vif_field_b(&vif_fields[Manufacturer_Info_Supported_Port],
- "Manufacturer_Info_Supported_Port",
- true);
+ vif_component_name[Manufacturer_Info_Supported_Port],
+ true);
sprintf(hex_str, "%04X", USB_VID_GOOGLE);
set_vif_field_itss(&vif_fields[Manufacturer_Info_VID_Port],
- "Manufacturer_Info_VID_Port",
- USB_VID_GOOGLE, hex_str);
+ vif_component_name[Manufacturer_Info_VID_Port],
+ USB_VID_GOOGLE, hex_str);
#if defined(CONFIG_USB_PID)
sprintf(hex_str, "%04X", CONFIG_USB_PID);
set_vif_field_itss(&vif_fields[
- Manufacturer_Info_PID_Port],
- "Manufacturer_Info_PID_Port",
- CONFIG_USB_PID, hex_str);
+ Manufacturer_Info_PID_Port],
+ vif_component_name[Manufacturer_Info_PID_Port],
+ CONFIG_USB_PID, hex_str);
#else
sprintf(hex_str, "%04X", DEFAULT_MISSING_PID);
set_vif_field_itss(&vif_fields[
- Manufacturer_Info_PID_Port],
- "Manufacturer_Info_PID_Port",
- DEFAULT_MISSING_PID, hex_str);
+ Manufacturer_Info_PID_Port],
+ vif_component_name[Manufacturer_Info_PID_Port],
+ DEFAULT_MISSING_PID, hex_str);
#endif
} else {
set_vif_field_b(&vif_fields[Manufacturer_Info_Supported_Port],
- "Manufacturer_Info_Supported_Port",
- false);
+ vif_component_name[Manufacturer_Info_Supported_Port],
+ false);
}
set_vif_field_b(&vif_fields[Security_Msgs_Supported_SOP],
- "Security_Msgs_Supported_SOP",
- IS_ENABLED(CONFIG_USB_PD_SECURITY_MSGS));
+ vif_component_name[Security_Msgs_Supported_SOP],
+ IS_ENABLED(CONFIG_USB_PD_SECURITY_MSGS));
#if defined(CONFIG_NUM_FIXED_BATTERIES)
set_vif_field_itss(&vif_fields[Num_Fixed_Batteries],
- "Num_Fixed_Batteries",
- CONFIG_NUM_FIXED_BATTERIES, NULL);
+ vif_component_name[Num_Fixed_Batteries],
+ CONFIG_NUM_FIXED_BATTERIES, NULL);
#elif defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD)
set_vif_field(&vif_fields[Num_Fixed_Batteries],
- "Num_Fixed_Batteries",
- "0", NULL);
+ vif_component_name[Num_Fixed_Batteries],
+ "0", NULL);
#else
set_vif_field(&vif_fields[Num_Fixed_Batteries],
- "Num_Fixed_Batteries",
- "1", NULL);
+ vif_component_name[Num_Fixed_Batteries],
+ "1", NULL);
#endif
set_vif_field(&vif_fields[Num_Swappable_Battery_Slots],
- "Num_Swappable_Battery_Slots",
- "0", NULL);
+ vif_component_name[Num_Swappable_Battery_Slots],
+ "0", NULL);
set_vif_field(&vif_fields[ID_Header_Connector_Type_SOP],
- "ID_Header_Connector_Type_SOP",
- "2", "USB Type-C Receptacle");
+ vif_component_name[ID_Header_Connector_Type_SOP],
+ "2", "USB Type-C Receptacle");
}
/*********************************************************************
@@ -1421,24 +2828,24 @@ static void init_vif_component_sop_capabilities_fields(
struct vif_field_t *vif_fields)
{
set_vif_field_b(&vif_fields[SOP_Capable],
- "SOP_Capable",
- can_act_as_host());
+ vif_component_name[SOP_Capable],
+ can_act_as_host());
set_vif_field_b(&vif_fields[SOP_P_Capable],
- "SOP_P_Capable",
- IS_ENABLED(CONFIG_USB_PD_DECODE_SOP));
+ vif_component_name[SOP_P_Capable],
+ IS_ENABLED(CONFIG_USB_PD_DECODE_SOP));
set_vif_field_b(&vif_fields[SOP_PP_Capable],
- "SOP_PP_Capable",
- IS_ENABLED(CONFIG_USB_PD_DECODE_SOP));
+ vif_component_name[SOP_PP_Capable],
+ IS_ENABLED(CONFIG_USB_PD_DECODE_SOP));
set_vif_field_b(&vif_fields[SOP_P_Debug_Capable],
- "SOP_P_Debug_Capable",
- false);
+ vif_component_name[SOP_P_Debug_Capable],
+ false);
set_vif_field_b(&vif_fields[SOP_PP_Debug_Capable],
- "SOP_PP_Debug_Capable",
- false);
+ vif_component_name[SOP_PP_Debug_Capable],
+ false);
}
/*********************************************************************
@@ -1449,12 +2856,12 @@ static void init_vif_component_usb_type_c_fields(
enum dtype type)
{
set_vif_field_b(&vif_fields[Type_C_Implements_Try_SRC],
- "Type_C_Implements_Try_SRC",
- IS_ENABLED(CONFIG_USB_PD_TRY_SRC));
+ vif_component_name[Type_C_Implements_Try_SRC],
+ IS_ENABLED(CONFIG_USB_PD_TRY_SRC));
set_vif_field_b(&vif_fields[Type_C_Implements_Try_SNK],
- "Type_C_Implements_Try_SNK",
- false);
+ vif_component_name[Type_C_Implements_Try_SNK],
+ false);
{
int rp = CONFIG_USB_PD_PULLUP;
@@ -1466,59 +2873,60 @@ static void init_vif_component_usb_type_c_fields(
switch (rp) {
case 0:
set_vif_field(&vif_fields[RP_Value],
- "RP_Value",
- "0", "Default");
+ vif_component_name[RP_Value],
+ "0", "Default");
break;
case 1:
set_vif_field(&vif_fields[RP_Value],
- "RP_Value",
- "1", "1.5A");
+ vif_component_name[RP_Value],
+ "1", "1.5A");
break;
case 2:
set_vif_field(&vif_fields[RP_Value],
- "RP_Value",
- "2", "3A");
+ vif_component_name[RP_Value],
+ "2", "3A");
break;
default:
set_vif_field_itss(&vif_fields[RP_Value],
- "RP_Value",
- rp, NULL);
+ vif_component_name[RP_Value],
+ rp, NULL);
}
}
if (type == SNK)
set_vif_field_b(
&vif_fields[Type_C_Supports_VCONN_Powered_Accessory],
- "Type_C_Supports_VCONN_Powered_Accessory",
- false);
+ vif_component_name
+ [Type_C_Supports_VCONN_Powered_Accessory],
+ false);
set_vif_field_b(&vif_fields[Type_C_Is_VCONN_Powered_Accessory],
- "Type_C_Is_VCONN_Powered_Accessory",
- false);
+ vif_component_name[Type_C_Is_VCONN_Powered_Accessory],
+ false);
set_vif_field_b(&vif_fields[Type_C_Is_Debug_Target_SRC],
- "Type_C_Is_Debug_Target_SRC",
- true);
+ vif_component_name[Type_C_Is_Debug_Target_SRC],
+ true);
set_vif_field_b(&vif_fields[Type_C_Is_Debug_Target_SNK],
- "Type_C_Is_Debug_Target_SNK",
- true);
+ vif_component_name[Type_C_Is_Debug_Target_SNK],
+ true);
set_vif_field_b(&vif_fields[Type_C_Can_Act_As_Host],
- "Type_C_Can_Act_As_Host",
- can_act_as_host());
+ vif_component_name[Type_C_Can_Act_As_Host],
+ can_act_as_host());
set_vif_field_b(&vif_fields[Type_C_Is_Alt_Mode_Controller],
- "Type_C_Is_Alt_Mode_Controller",
- IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP));
+ vif_component_name[Type_C_Is_Alt_Mode_Controller],
+ IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP));
set_vif_field_b(&vif_fields[Type_C_Can_Act_As_Device],
- "Type_C_Can_Act_As_Device",
- can_act_as_device());
+ vif_component_name[Type_C_Can_Act_As_Device],
+ can_act_as_device());
set_vif_field_b(&vif_fields[Type_C_Is_Alt_Mode_Adapter],
- "Type_C_Is_Alt_Mode_Adapter",
- IS_ENABLED(CONFIG_USB_ALT_MODE_ADAPTER));
+ vif_component_name[Type_C_Is_Alt_Mode_Adapter],
+ IS_ENABLED(CONFIG_USB_ALT_MODE_ADAPTER));
{
int ps = 1;
@@ -1531,37 +2939,37 @@ static void init_vif_component_usb_type_c_fields(
switch (ps) {
case 0:
set_vif_field(&vif_fields[Type_C_Power_Source],
- "Type_C_Power_Source",
- "0", "Externally Powered");
+ vif_component_name[Type_C_Power_Source],
+ "0", "Externally Powered");
break;
case 1:
set_vif_field(&vif_fields[Type_C_Power_Source],
- "Type_C_Power_Source",
- "1", "UFP-powered");
+ vif_component_name[Type_C_Power_Source],
+ "1", "UFP-powered");
break;
case 2:
set_vif_field(&vif_fields[Type_C_Power_Source],
- "Type_C_Power_Source",
- "2", "Both");
+ vif_component_name[Type_C_Power_Source],
+ "2", "Both");
break;
default:
set_vif_field_itss(&vif_fields[Type_C_Power_Source],
- "Type_C_Power_Source",
- ps, NULL);
+ vif_component_name[Type_C_Power_Source],
+ ps, NULL);
}
}
set_vif_field_b(&vif_fields[Type_C_Port_On_Hub],
- "Type_C_Port_On_Hub",
- false);
+ vif_component_name[Type_C_Port_On_Hub],
+ false);
set_vif_field_b(&vif_fields[Type_C_Supports_Audio_Accessory],
- "Type_C_Supports_Audio_Accessory",
- false);
+ vif_component_name[Type_C_Supports_Audio_Accessory],
+ false);
set_vif_field_b(&vif_fields[Type_C_Sources_VCONN],
- "Type_C_Sources_VCONN",
- IS_ENABLED(CONFIG_USBC_VCONN));
+ vif_component_name[Type_C_Sources_VCONN],
+ IS_ENABLED(CONFIG_USBC_VCONN));
}
/*********************************************************************
@@ -1587,33 +2995,33 @@ static void init_vif_component_usb_data_ufp_fields(
switch (ds) {
case USB_2:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- USB_2, "USB 2");
+ vif_component_name[Device_Speed],
+ USB_2, "USB 2");
break;
case USB_GEN11:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- USB_GEN11, "USB 3.2 GEN 1x1");
+ vif_component_name[Device_Speed],
+ USB_GEN11, "USB 3.2 GEN 1x1");
break;
case USB_GEN21:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- USB_GEN21, "USB 3.2 GEN 2x1");
+ vif_component_name[Device_Speed],
+ USB_GEN21, "USB 3.2 GEN 2x1");
break;
case USB_GEN12:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- USB_GEN12, "USB 3.2 GEN 1x2");
+ vif_component_name[Device_Speed],
+ USB_GEN12, "USB 3.2 GEN 1x2");
break;
case USB_GEN22:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- USB_GEN22, "USB 3.2 GEN 2x2");
+ vif_component_name[Device_Speed],
+ USB_GEN22, "USB 3.2 GEN 2x2");
break;
default:
set_vif_field_itss(&vif_fields[Device_Speed],
- "Device_Speed",
- ds, NULL);
+ vif_component_name[Device_Speed],
+ ds, NULL);
}
}
@@ -1642,42 +3050,42 @@ static void init_vif_component_usb_data_dfp_fields(
switch (ds) {
case USB_2:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- USB_2, "USB 2");
+ vif_component_name[Host_Speed],
+ USB_2, "USB 2");
break;
case USB_GEN11:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- USB_GEN11, "USB 3.2 GEN 1x1");
+ vif_component_name[Host_Speed],
+ USB_GEN11, "USB 3.2 GEN 1x1");
break;
case USB_GEN21:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- USB_GEN21, "USB 3.2 GEN 2x1");
+ vif_component_name[Host_Speed],
+ USB_GEN21, "USB 3.2 GEN 2x1");
break;
case USB_GEN12:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- USB_GEN12, "USB 3.2 GEN 1x2");
+ vif_component_name[Host_Speed],
+ USB_GEN12, "USB 3.2 GEN 1x2");
break;
case USB_GEN22:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- USB_GEN22, "USB 3.2 GEN 2x2");
+ vif_component_name[Host_Speed],
+ USB_GEN22, "USB 3.2 GEN 2x2");
break;
default:
set_vif_field_itss(&vif_fields[Host_Speed],
- "Host_Speed",
- ds, NULL);
+ vif_component_name[Host_Speed],
+ ds, NULL);
}
set_vif_field_b(&vif_fields[Host_Contains_Captive_Retimer],
- "Host_Contains_Captive_Retimer",
- false);
+ vif_component_name[Host_Contains_Captive_Retimer],
+ false);
set_vif_field_b(&vif_fields[Host_Is_Embedded],
- "Host_Is_Embedded",
- false);
+ vif_component_name[Host_Is_Embedded],
+ false);
}
/*********************************************************************
@@ -1708,76 +3116,78 @@ static int init_vif_component_pd_source_fields(
}
set_vif_field_itss(&vif_fields[PD_Power_As_Source],
- "PD_Power_As_Source",
- *src_max_power, NULL);
+ vif_component_name[PD_Power_As_Source],
+ *src_max_power, NULL);
}
if (type == DRP || type == SRC)
set_vif_field_b(&vif_fields[USB_Suspend_May_Be_Cleared],
- "USB_Suspend_May_Be_Cleared",
- false);
+ vif_component_name[USB_Suspend_May_Be_Cleared],
+ false);
if (type == DRP || type == SRC)
set_vif_field_b(&vif_fields[Sends_Pings],
- "Sends_Pings",
- false);
+ vif_component_name[Sends_Pings],
+ false);
if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) &&
type == DRP &&
IS_ENABLED(CONFIG_USB_PD_FRS))
set_vif_field(&vif_fields[
FR_Swap_Type_C_Current_Capability_As_Initial_Sink],
- "FR_Swap_Type_C_Current_Capability_As_Initial_Sink",
+ vif_component_name
+ [FR_Swap_Type_C_Current_Capability_As_Initial_Sink],
"3", "3A @ 5V");
else
set_vif_field(&vif_fields[
FR_Swap_Type_C_Current_Capability_As_Initial_Sink],
- "FR_Swap_Type_C_Current_Capability_As_Initial_Sink",
+ vif_component_name
+ [FR_Swap_Type_C_Current_Capability_As_Initial_Sink],
"0", "FR_Swap not supported");
if (IS_ENABLED(CONFIG_USB_PD_REV30) || IS_ENABLED(CONFIG_USB_PRL_SM))
set_vif_field_b(&vif_fields[Master_Port],
- "Master_Port",
+ vif_component_name[Master_Port],
false);
if (type == DRP || type == SRC)
set_vif_field_itss(&vif_fields[Num_Src_PDOs],
- "Num_Src_PDOs",
- src_pdo_cnt, NULL);
+ vif_component_name[Num_Src_PDOs],
+ src_pdo_cnt, NULL);
if (type == DRP || type == SRC) {
if (IS_ENABLED(CONFIG_USBC_PPC)) {
int resp = 0;
set_vif_field_b(&vif_fields[PD_OC_Protection],
- "PD_OC_Protection",
- true);
+ vif_component_name[PD_OC_Protection],
+ true);
switch (resp) {
case 0:
set_vif_field(&vif_fields[PD_OCP_Method],
- "PD_OCP_Method",
- "0", "Over-Current Response");
+ vif_component_name[PD_OCP_Method],
+ "0", "Over-Current Response");
break;
case 1:
set_vif_field(&vif_fields[PD_OCP_Method],
- "PD_OCP_Method",
- "1", "Under-Voltage Response");
+ vif_component_name[PD_OCP_Method],
+ "1", "Under-Voltage Response");
break;
case 2:
set_vif_field(&vif_fields[PD_OCP_Method],
- "PD_OCP_Method",
- "2", "Both");
+ vif_component_name[PD_OCP_Method],
+ "2", "Both");
break;
default:
set_vif_field_itss(&vif_fields[PD_OCP_Method],
- "PD_OCP_Method",
- resp, NULL);
+ vif_component_name[PD_OCP_Method],
+ resp, NULL);
}
} else {
set_vif_field_b(&vif_fields[PD_OC_Protection],
- "PD_OC_Protection",
- false);
+ vif_component_name[PD_OC_Protection],
+ false);
}
}
@@ -1814,29 +3224,30 @@ static int init_vif_component_pd_sink_fields(
}
set_vif_field_itss(&vif_fields[PD_Power_As_Sink],
- "PD_Power_As_Sink",
- snk_max_power, NULL);
+ vif_component_name[PD_Power_As_Sink],
+ snk_max_power, NULL);
set_vif_field_b(&vif_fields[No_USB_Suspend_May_Be_Set],
- "No_USB_Suspend_May_Be_Set",
- true);
+ vif_component_name[No_USB_Suspend_May_Be_Set],
+ true);
set_vif_field_b(&vif_fields[GiveBack_May_Be_Set],
- "GiveBack_May_Be_Set",
- IS_ENABLED(CONFIG_USB_PD_GIVE_BACK));
+ vif_component_name[GiveBack_May_Be_Set],
+ IS_ENABLED(CONFIG_USB_PD_GIVE_BACK));
set_vif_field_b(&vif_fields[Higher_Capability_Set],
- "Higher_Capability_Set",
- false);
+ vif_component_name[Higher_Capability_Set],
+ false);
set_vif_field(&vif_fields[
- FR_Swap_Reqd_Type_C_Current_As_Initial_Source],
- "FR_Swap_Reqd_Type_C_Current_As_Initial_Source",
- "0", "FR_Swap not supported");
+ FR_Swap_Reqd_Type_C_Current_As_Initial_Source],
+ vif_component_name
+ [FR_Swap_Reqd_Type_C_Current_As_Initial_Source],
+ "0", "FR_Swap not supported");
set_vif_field_itss(&vif_fields[Num_Snk_PDOs],
- "Num_Snk_PDOs",
- pd_snk_pdo_cnt, NULL);
+ vif_component_name[Num_Snk_PDOs],
+ pd_snk_pdo_cnt, NULL);
return 0;
}
@@ -1852,24 +3263,24 @@ static void init_vif_component_pd_dual_role_fields(
return;
set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Src],
- "Accepts_PR_Swap_As_Src",
- true);
+ vif_component_name[Accepts_PR_Swap_As_Src],
+ true);
set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Snk],
- "Accepts_PR_Swap_As_Snk",
- true);
+ vif_component_name[Accepts_PR_Swap_As_Snk],
+ true);
set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Src],
- "Requests_PR_Swap_As_Src",
- true);
+ vif_component_name[Requests_PR_Swap_As_Src],
+ true);
set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Snk],
- "Requests_PR_Swap_As_Snk",
- true);
+ vif_component_name[Requests_PR_Swap_As_Snk],
+ true);
set_vif_field_b(&vif_fields[FR_Swap_Supported_As_Initial_Sink],
- "FR_Swap_Supported_As_Initial_Sink",
- IS_ENABLED(CONFIG_USB_PD_FRS));
+ vif_component_name[FR_Swap_Supported_As_Initial_Sink],
+ IS_ENABLED(CONFIG_USB_PD_FRS));
}
/*********************************************************************
@@ -1881,7 +3292,6 @@ static void init_vif_component_pd_dual_role_fields(
* Fields that are not currently being initialized
*
* vif_Component
- * XID_SOP numericFieldType
* Data_Capable_As_USB_Host_SOP booleanFieldType
* Data_Capable_As_USB_Device_SOP booleanFieldType
* Product_Type_UFP_SOP numericFieldType
@@ -1900,20 +3310,20 @@ static void init_vif_component_sop_discovery_fields(
char hex_str[10];
set_vif_field(&vif_fields[XID_SOP],
- "XID_SOP",
- "0",
- "0");
+ vif_component_name[XID_SOP],
+ "0",
+ "0");
#if defined(CONFIG_USB_PID)
sprintf(hex_str, "%04X", CONFIG_USB_PID);
set_vif_field_itss(&vif_fields[PID_SOP],
- "PID_SOP",
- CONFIG_USB_PID, hex_str);
+ vif_component_name[PID_SOP],
+ CONFIG_USB_PID, hex_str);
#else
sprintf(hex_str, "%04X", DEFAULT_MISSING_PID);
set_vif_field_itss(&vif_fields[PID_SOP],
- "PID_SOP",
- DEFAULT_MISSING_PID, hex_str);
+ vif_component_name[PID_SOP],
+ DEFAULT_MISSING_PID, hex_str);
#endif
}
@@ -1927,9 +3337,9 @@ static void init_vif_component_bc_1_2_fields(
if (bc_support == BC_1_2_SUPPORT_CHARGING_PORT ||
bc_support == BC_1_2_SUPPORT_BOTH)
set_vif_field(&vif_fields[BC_1_2_Charging_Port_Type],
- "BC_1_2_Charging_Port_Type",
- "1",
- "CDP");
+ vif_component_name[BC_1_2_Charging_Port_Type],
+ "1",
+ "CDP");
}
/*********************************************************************
@@ -1954,106 +3364,145 @@ static void init_vif_component_product_power_fields(
sprintf(str, "%dmW", src_max_power);
set_vif_field_itss(&vif_fields[Product_Total_Source_Power_mW],
- "Product_Total_Source_Power_mW",
- src_max_power, str);
+ vif_component_name[Product_Total_Source_Power_mW],
+ src_max_power, str);
}
if (type == DRP || type == SRC)
set_vif_field(&vif_fields[Port_Source_Power_Type],
- "Port_Source_Power_Type",
- "0", "Assured");
+ vif_component_name[Port_Source_Power_Type],
+ "0", "Assured");
}
static int gen_vif(const char *name,
const char *board,
- const char *vif_producer)
+ const char *vif_producer,
+ struct vif_t *vif)
{
- struct vif_t vif;
+ int override_value;
+ bool was_overridden;
enum dtype type;
int32_t src_max_power = 0;
enum bc_1_2_support bc_support = BC_1_2_SUPPORT_NONE;
/* Determine if we are DRP, SRC or SNK */
- if (is_drp())
- type = DRP;
- else if (is_src() && is_snk())
- /* No DRP with SRC and SNK PDOs detected. So ignore. */
- /* ie. Twinkie or Plankton */
- return 0;
- else if (is_src())
- type = SRC;
- else if (is_snk())
- type = SNK;
- else
- return 1;
+ was_overridden = get_vif_field_tag_number(
+ &vif->Component[0]
+ .vif_field[Type_C_State_Machine],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case SRC:
+ case SNK:
+ case DRP:
+ type = (enum dtype)override_value;
+ break;
+ default:
+ was_overridden = false;
+ }
+ }
+ if (!was_overridden) {
+ was_overridden = get_vif_field_tag_number(
+ &vif->Component[0]
+ .vif_field[PD_Port_Type],
+ &override_value);
+ if (was_overridden) {
+ switch (override_value) {
+ case PORT_CONSUMER_ONLY: /* SNK */
+ type = SNK;
+ break;
+ case PORT_PROVIDER_ONLY: /* SRC */
+ type = SRC;
+ break;
+ case PORT_DRP: /* DRP */
+ type = DRP;
+ break;
+ default:
+ was_overridden = false;
+ }
+ }
+ }
+ if (!was_overridden) {
+ if (is_drp())
+ type = DRP;
+ else if (is_src() && is_snk())
+ /* No DRP with SRC and SNK PDOs detected. So ignore. */
+ /* ie. Twinkie or Plankton */
+ return 0;
+ else if (is_src())
+ type = SRC;
+ else if (is_snk())
+ type = SNK;
+ else
+ return 1;
+ }
/*********************************************************************
* Initialize the vif structure
*/
- memset(&vif, 0, sizeof(struct vif_t));
-
init_vif_fields(
- vif.vif_field,
+ vif->vif_field,
+ vif->vif_app_field,
board);
init_vif_product_fields(
- vif.Product.vif_field);
+ vif->Product.vif_field);
init_vif_component_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
&bc_support,
type);
init_vif_component_general_pd_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
type);
init_vif_component_sop_capabilities_fields(
- vif.Component[0].vif_field);
+ vif->Component[0].vif_field);
init_vif_component_usb_type_c_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
type);
init_vif_component_usb_data_ufp_fields(
- vif.Component[0].vif_field);
+ vif->Component[0].vif_field);
init_vif_component_usb_data_dfp_fields(
- vif.Component[0].vif_field);
+ vif->Component[0].vif_field);
if (init_vif_component_pd_source_fields(
- vif.Component[0].vif_field,
- vif.Component[0].SrcPdoList,
+ vif->Component[0].vif_field,
+ vif->Component[0].SrcPdoList,
&src_max_power,
type))
return 1;
if (init_vif_component_pd_sink_fields(
- vif.Component[0].vif_field,
- vif.Component[0].SnkPdoList,
+ vif->Component[0].vif_field,
+ vif->Component[0].SnkPdoList,
type))
return 1;
init_vif_component_pd_dual_role_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
type);
init_vif_component_sop_discovery_fields(
- vif.Component[0].vif_field);
+ vif->Component[0].vif_field);
init_vif_component_bc_1_2_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
bc_support);
init_vif_component_product_power_fields(
- vif.Component[0].vif_field,
+ vif->Component[0].vif_field,
src_max_power,
type);
/*********************************************************************
* Format the structure in XML and output it to file
*/
- return vif_output_xml(name, &vif);
+ return vif_output_xml(name, vif);
}
/*
* VIF Structure Initialization from Config Functions
@@ -2071,20 +3520,24 @@ int main(int argc, char **argv)
int name_size;
const char * const short_opt = "hb:o:";
const struct option long_opts[] = {
- { "help", 0, NULL, 'h' },
+ { "help", 0, NULL, 'h' },
{ "board", 1, NULL, 'b' },
- { "out", 1, NULL, 'o' },
+ { "out", 1, NULL, 'o' },
+ { "over", 1, NULL, 'v'},
{ NULL }
};
vif_producer = argv[0];
+ /* Clear the VIF structure */
+ memset(&vif, 0, sizeof(struct vif_t));
+
do {
nopt = getopt_long(argc, argv, short_opt, long_opts, NULL);
switch (nopt) {
case 'h': /* -h or --help */
- printf("USAGE: %s -b <board name> -o <out directory>\n",
- vif_producer);
+ printf("USAGE: %s -b <board name> -o <out directory>"
+ " --over <override XML file>\n", vif_producer);
return 1;
case 'b': /* -b or --board */
@@ -2094,6 +3547,13 @@ int main(int argc, char **argv)
case 'o': /* -o or --out */
out = optarg;
break;
+
+ case 'v': /* --over */
+ /* Handle overrides */
+ if (override_gen_vif(optarg, &vif))
+ return 1;
+ break;
+
case -1:
break;
@@ -2121,9 +3581,9 @@ int main(int argc, char **argv)
return 1;
}
- ret = gen_vif(name, board, vif_producer);
+ /* Finish CONFIG initialization and output the file */
+ ret = gen_vif(name, board, vif_producer, &vif);
free(name);
-
return ret;
}
diff --git a/util/genvif.h b/util/genvif.h
index ef4f3d5ec1..634dbfc861 100644
--- a/util/genvif.h
+++ b/util/genvif.h
@@ -17,7 +17,7 @@
struct vif_field_t {
- char *name;
+ const char *name;
char *tag_value;
char *str_value;
};
@@ -378,9 +378,6 @@ struct vif_Product_t {
enum vif_indexes {
VIF_Specification, /* version */
- VIF_App_Vendor, /* nonEmptyString */
- VIF_App_Name, /* nonEmptyString */
- VIF_App_Version, /* version */
Vendor_Name, /* nonEmptyString */
Model_Part_Number, /* nonEmptyString */
Product_Revision, /* nonEmptyString */
@@ -389,8 +386,15 @@ enum vif_indexes {
Certification_Type, /* numericFieldType */
VIF_Indexes
};
+enum vif_app_indexes {
+ Vendor, /* nonEmptyString */
+ Name, /* nonEmptyString */
+ Version, /* version */
+ VIF_App_Indexes
+};
struct vif_t {
struct vif_field_t vif_field[VIF_Indexes];
+ struct vif_field_t vif_app_field[VIF_App_Indexes];
struct vif_Product_t Product;
struct vif_Component_t Component[MAX_NUM_COMPONENTS];