From 70a1969f52d1d2b5d9bb71b68a42312378ed73ce Mon Sep 17 00:00:00 2001 From: Denis Brockus Date: Fri, 6 Nov 2020 11:17:28 -0700 Subject: genvif: split up initialization to spec field groupings BUG=b:172665003 BRANCH=none TEST=verify XML output Signed-off-by: Denis Brockus Change-Id: Ic356fc0df99e449f90bdb0390e5473c621f717d8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2523451 Tested-by: Denis Brockus Commit-Queue: Denis Brockus Reviewed-by: Keith Short --- util/genvif.c | 807 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 482 insertions(+), 325 deletions(-) (limited to 'util') diff --git a/util/genvif.c b/util/genvif.c index 9b19796596..0e42334f78 100644 --- a/util/genvif.c +++ b/util/genvif.c @@ -552,41 +552,39 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, * * Fields that are not currently being initialized * - * vif_cableSVIDModeList - * SVID_Mode_Enter booleanFieldType - * SVID_Mode_Recog_Mask numericFieldType - * SVID_Mode_Recog_Value numericFieldType - * - * vif_cableSVIDList - * SVID numericFieldType - * SVID_Modes_Fixed booleanFieldType - * SVID_Num_Modes_Min numericFieldType - * SVID_Num_Modes_Max numericFieldType - * - * vif_sopSVIDModeList - * SVID_Mode_Enter_SOP booleanFieldType - * SVID_Mode_Recog_Mask_SOP numericFieldType - * SVID_Mode_Recog_Value_SOP numericFieldType - * - * vif_sopSVIDList - * SVID_SOP numericFieldType - * SVID_Modes_Fixed_SOP booleanFieldType - * SVID_Num_Modes_Min_SOP numericFieldType - * SVID_Num_Modes_Max_SOP numericFieldType + * vif_Component USB4 Port Fields + * USB4_Lane_0_Adapter numericFieldType + * USB4_Max_Speed numericFieldType + * USB4_DFP_Supported booleanFieldType + * USB4_UFP_Supported booleanFieldType + * USB4_USB3_Tunneling_Supported booleanFieldType + * USB4_DP_Tunneling_Supported booleanFieldType + * USB4_PCIe_Tunneling_Supported booleanFieldType + * USB4_TBT3_Compatibility_Supported booleanFieldType + * USB4_CL1_State_Supported booleanFieldType + * USB4_CL2_State_Supported booleanFieldType + * USB4_Num_Retimers numericFieldType + * USB4_DP_Bit_Rate numericFieldType + * USB4_Num_DP_Lanes numericFieldType * - * vif_srcPdoList - * Src_PD_OCP_OC_Debounce numericFieldType - * Src_PD_OCP_OC_Threshold numericFieldType - * Src_PD_OCP_UV_Debounce numericFieldType - * Src_PD_OCP_UV_Threshold_Type numericFieldType - * Src_PD_OCP_UV_Threshold numericFieldType + * vif_Component USB4 Product Fields + * USB4_Dock booleanFieldType + * USB4_Num_Internal_Host_Controllers numericFieldType + * USB4_Num_PCIe_DN_Bridges numericFieldType * - * vif_PCIeEndpointListType - * USB4_PCIe_Endpoint_Vendor_ID numericFieldType - * USB4_PCIe_Endpoint_Device_ID numericFieldType - * USB4_PCIe_Endpoint_Class_Code numericFieldType + * vif_Component USB4 Device Class Fallback Support + * USB4_Audio_Supported booleanFieldType + * USB4_HID_Supported booleanFieldType + * USB4_Printer_Supported booleanFieldType + * USB4_Mass_Storage_Supported booleanFieldType + * USB4_Video_Supported booleanFieldType + * USB4_Comms_Networking_Supported booleanFieldType + * USB4_Media_Transfer_Protocol_Supported booleanFieldType + * USB4_Smart_Card_Supported booleanFieldType + * USB4_Still_Image_Capture_Supported booleanFieldType + * USB4_Monitor_Device_Supported booleanFieldType * - * vif_Usb4RouterListType + * vif_Usb4RouterListType USB4 Router Fields * USB4_Router_ID numericFieldType * USB4_Silicon_VID numericFieldType * USB4_Num_Lane_Adapters numericFieldType @@ -603,54 +601,31 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, * USB4_PCIe_Switch_Device_ID numericFieldType * USB4_Num_PCIe_Endpoints numericFieldType * - * vif_Component - * Manufacturer_Info_VID_Port numericFieldType - * USB4_Router_Index numericFieldType - * USB4_Lane_0_Adapter numericFieldType - * USB4_Max_Speed numericFieldType - * USB4_DFP_Supported booleanFieldType - * USB4_UFP_Supported booleanFieldType - * USB4_USB3_Tunneling_Supported booleanFieldType - * USB4_DP_Tunneling_Supported booleanFieldType - * USB4_PCIe_Tunneling_Supported booleanFieldType - * USB4_TBT3_Compatibility_Supported booleanFieldType - * USB4_CL1_State_Supported booleanFieldType - * USB4_CL2_State_Supported booleanFieldType - * USB4_Num_Retimers numericFieldType - * USB4_DP_Bit_Rate numericFieldType - * USB4_Num_DP_Lanes numericFieldType - * Host_Supports_USB_Data booleanFieldType - * Host_Truncates_DP_For_tDHPResponse booleanFieldType - * Host_Gen1x1_tLinkTurnaround numericFieldType - * Host_Gen2x1_tLinkTurnaround numericFieldType - * Host_Suspend_Supported booleanFieldType - * Is_DFP_On_Hub booleanFieldType - * Hub_Port_Number numericFieldType - * Device_Supports_USB_Data booleanFieldType - * Device_Contains_Captive_Retimer booleanFieldType - * Device_Truncates_DP_For_tDHPResponse booleanFieldType - * Device_Gen1x1_tLinkTurnaround numericFieldType - * Device_Gen2x1_tLinkTurnaround numericFieldType - * XID_SOP numericFieldType - * Data_Capable_As_USB_Host_SOP booleanFieldType - * Data_Capable_As_USB_Device_SOP booleanFieldType - * Product_Type_UFP_SOP numericFieldType - * Product_Type_DFP_SOP numericFieldType - * DFP_VDO_Port_Number numericFieldType - * Modal_Operation_Supported_SOP booleanFieldType - * USB_VID_SOP numericFieldType - * bcdDevice_SOP numericFieldType - * SVID_Fixed_SOP booleanFieldType - * Num_SVIDs_Min_SOP numericFieldType - * Num_SVIDs_Max_SOP numericFieldType + * vif_PCIeEndpointListType PCIe Endpoint Fields + * USB4_PCIe_Endpoint_Vendor_ID numericFieldType + * USB4_PCIe_Endpoint_Device_ID numericFieldType + * USB4_PCIe_Endpoint_Class_Code numericFieldType + * + * vif_sopSVIDList SOP SVIDs + * SVID_SOP numericFieldType + * SVID_Modes_Fixed_SOP booleanFieldType + * SVID_Num_Modes_Min_SOP numericFieldType + * SVID_Num_Modes_Max_SOP numericFieldType + * + * vif_sopSVIDModeList SOP SVID Modes + * SVID_Mode_Enter_SOP booleanFieldType + * SVID_Mode_Recog_Mask_SOP numericFieldType + * SVID_Mode_Recog_Value_SOP numericFieldType + * + * vif_Component Alternate Mode Adapter Fields * AMA_HW_Vers numericFieldType * AMA_FW_Vers numericFieldType - * AMA_VCONN_Reqd booleanFieldType * AMA_VCONN_Power booleanFieldType + * AMA_VCONN_Reqd booleanFieldType * AMA_VBUS_Reqd booleanFieldType * AMA_Superspeed_Support numericFieldType - * Port_Source_Power_Gang nonEmptyString - * Port_Source_Power_Gang_Max_Power numericFieldType + * + * vif_Component Cable/eMarker Fields * XID numericFieldType * Data_Capable_As_USB_Host booleanFieldType * Data_Capable_As_USB_Device booleanFieldType @@ -665,8 +640,8 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, * Type_C_To_Type_C_Capt_Vdm_V2 numericFieldType * Cable_Latency numericFieldType * Cable_Termination_Type numericFieldType - * VBUS_Through_Cable booleanFieldType * Cable_VBUS_Current numericFieldType + * VBUS_Through_Cable booleanFieldType * Cable_Superspeed_Support numericFieldType * Cable_USB_Highest_Speed numericFieldType * Max_VBUS_Voltage_Vdm_V2 numericFieldType @@ -676,16 +651,22 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, * Chunking_Implemented booleanFieldType * Security_Msgs_Supported booleanFieldType * ID_Header_Connector_Type numericFieldType - * SVID_Fixed booleanFieldType * Cable_Num_SVIDs_Min numericFieldType * Cable_Num_SVIDs_Max numericFieldType - * VPD_HW_Vers numericFieldType - * VPD_FW_Vers numericFieldType - * VPD_Max_VBUS_Voltage numericFieldType - * VPD_Charge_Through_Support booleanFieldType - * VPD_Charge_Through_Current numericFieldType - * VPD_VBUS_Impedance numericFieldType - * VPD_Ground_Impedance numericFieldType + * SVID_Fixed booleanFieldType + * + * vif_cableSVIDList Cable SVIDs + * SVID numericFieldType + * SVID_Modes_Fixed booleanFieldType + * SVID_Num_Modes_Min numericFieldType + * SVID_Num_Modes_Max numericFieldType + * + * vif_cableSVIDModeList Cable SVID Modes + * SVID_Mode_Enter booleanFieldType + * SVID_Mode_Recog_Mask numericFieldType + * SVID_Mode_Recog_Value numericFieldType + * + * vif_Component Active Cable Fields * Cable_SOP_PP_Controller booleanFieldType * SBU_Supported booleanFieldType * SBU_Type numericFieldType @@ -698,33 +679,29 @@ __maybe_unused static void set_vif_field_itis(struct vif_field_t *vif_field, * Active_Cable_Physical_Connection numericFieldType * Active_Cable_Active_Element numericFieldType * Active_Cable_USB4_Support booleanFieldType - * Active_Cable_USB2_Hub_Hops_Consumed numericFieldType * Active_Cable_USB2_Supported booleanFieldType + * Active_Cable_USB2_Hub_Hops_Consumed numericFieldType * Active_Cable_USB32_Supported booleanFieldType * Active_Cable_USB_Lanes numericFieldType * Active_Cable_Optically_Isolated booleanFieldType * Active_Cable_USB_Gen numericFieldType + * + * vif_Component VCONN Powered Device + * VPD_HW_Vers numericFieldType + * VPD_FW_Vers numericFieldType + * VPD_Max_VBUS_Voltage numericFieldType + * VPD_Charge_Through_Support booleanFieldType + * VPD_Charge_Through_Current numericFieldType + * VPD_VBUS_Impedance numericFieldType + * VPD_Ground_Impedance numericFieldType + * + * vif_Component Repeater Fields * Repeater_One_Type numericFieldType * Repeater_Two_Type numericFieldType - * - * vif_Product - * USB4_Dock booleanFieldType - * USB4_Num_Internal_Host_Controllers numericFieldType - * USB4_Num_PCIe_DN_Bridges numericFieldType - * USB4_Audio_Supported booleanFieldType - * USB4_HID_Supported booleanFieldType - * USB4_Printer_Supported booleanFieldType - * USB4_Mass_Storage_Supported booleanFieldType - * USB4_Video_Supported booleanFieldType - * USB4_Comms_Networking_Supported booleanFieldType - * USB4_Media_Transfer_Protocol_Supported booleanFieldType - * USB4_Smart_Card_Supported booleanFieldType - * USB4_Still_Image_Capture_Supported booleanFieldType - * USB4_Monitor_Device_Supported booleanFieldType */ -__maybe_unused static int32_t set_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo, - uint32_t pdo) +__maybe_unused static int32_t init_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo, + uint32_t pdo) { int32_t power_mw; char str[40]; @@ -843,14 +820,26 @@ __maybe_unused static int32_t set_vif_snk_pdo(struct vif_snkPdoList_t *snkPdo, return power_mw; } -__maybe_unused static int32_t set_vif_src_pdo(struct vif_srcPdoList_t *srcPdo, - uint32_t pdo) +__maybe_unused static int32_t init_vif_src_pdo(struct vif_srcPdoList_t *srcPdo, + uint32_t pdo) { int32_t power_mw; char str[40]; /********************************************************************* * Source PDOs + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * Fields that are not currently being initialized + * + * vif_srcPdoList + * Src_PD_OCP_OC_Debounce numericFieldType + * Src_PD_OCP_OC_Threshold numericFieldType + * Src_PD_OCP_UV_Debounce numericFieldType + * Src_PD_OCP_UV_Threshold_Type numericFieldType + * Src_PD_OCP_UV_Threshold numericFieldType */ if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_FIXED) { uint32_t current = pdo & 0x3ff; @@ -970,40 +959,12 @@ __maybe_unused static int32_t set_vif_src_pdo(struct vif_srcPdoList_t *srcPdo, return power_mw; } -static int gen_vif(const char *name, - const char *board, - const char *vif_producer) +/********************************************************************* + * Init VIF Fields + */ +static void init_vif_fields(struct vif_field_t *vif_fields, + const char *board) { - enum dtype type; - struct vif_t vif; - struct vif_field_t *vif_fields; - - int32_t src_max_power = 0; - enum bc_1_2_support bc_support; - - - /* 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; - - /* Start with an empty vif */ - memset(&vif, 0, sizeof(struct vif_t)); - - /********************************************************************* - * VIF Fields - */ - vif_fields = vif.vif_field; - set_vif_field(&vif_fields[VIF_Specification], "VIF_Specification", NULL, @@ -1080,12 +1041,13 @@ static int gen_vif(const char *name, "Certification_Type", "0", "End Product"); +} - /********************************************************************* - * VIF/Product Fields - */ - vif_fields = vif.Product.vif_field; - +/********************************************************************* + * Init VIF/Product Fields + */ +static void init_vif_product_fields(struct vif_field_t *vif_fields) +{ { char hex_str[10]; @@ -1094,12 +1056,23 @@ static int gen_vif(const char *name, "Product_VID", USB_VID_GOOGLE, hex_str); } +} - /********************************************************************* - * VIF/Component[] Fields - */ - vif_fields = vif.Component[0].vif_field; - +/********************************************************************* + * Init VIF/Component[] Fields + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * Fields that are not currently being initialized + * + * vif_Component + * USB4_Router_Index numericFieldType + */ +static void init_vif_component_fields(struct vif_field_t *vif_fields, + enum bc_1_2_support *bc_support, + enum dtype type) +{ #if defined(CONFIG_USB_PD_PORT_LABEL) set_vif_field_stis(&vif_fields[Port_Label], "Port_Label", @@ -1167,17 +1140,17 @@ static int gen_vif(const char *name, "Port_Battery_Powered", IS_ENABLED(CONFIG_BATTERY)); - bc_support = BC_1_2_SUPPORT_NONE; + *bc_support = BC_1_2_SUPPORT_NONE; if (IS_ENABLED(CONFIG_BC12_DETECT_MAX14637)) - bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; + *bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; if (IS_ENABLED(CONFIG_BC12_DETECT_MT6360)) - bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; + *bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; if (IS_ENABLED(CONFIG_BC12_DETECT_PI3USB9201)) - bc_support = BC_1_2_SUPPORT_BOTH; + *bc_support = BC_1_2_SUPPORT_BOTH; if (IS_ENABLED(CONFIG_BC12_DETECT_PI3USB9281)) - bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; + *bc_support = BC_1_2_SUPPORT_PORTABLE_DEVICE; - switch (bc_support) { + switch (*bc_support) { case BC_1_2_SUPPORT_NONE: set_vif_field(&vif_fields[BC_1_2_Support], "BC_1_2_Support", @@ -1203,10 +1176,15 @@ static int gen_vif(const char *name, "Both"); break; } +} - /********************************************************************* - * General PD Fields - */ +/********************************************************************* + * Init VIF/Component[] General PD Fields + */ +static void init_vif_component_general_pd_fields( + struct vif_field_t *vif_fields, + enum dtype type) +{ 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", @@ -1420,10 +1398,14 @@ static int gen_vif(const char *name, set_vif_field(&vif_fields[ID_Header_Connector_Type_SOP], "ID_Header_Connector_Type_SOP", "2", "USB Type-C Receptacle"); +} - /********************************************************************* - * SOP* Capabilities - */ +/********************************************************************* + * Init VIF/Component[] SOP* Capabilities Fields + */ +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()); @@ -1443,10 +1425,15 @@ static int gen_vif(const char *name, set_vif_field_b(&vif_fields[SOP_PP_Debug_Capable], "SOP_PP_Debug_Capable", false); +} - /********************************************************************* - * USB Type-C Fields - */ +/********************************************************************* + * Init VIF/Component[] USB Type-C Fields + */ +static void init_vif_component_usb_type_c_fields( + struct vif_field_t *vif_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)); @@ -1561,83 +1548,113 @@ static int gen_vif(const char *name, set_vif_field_b(&vif_fields[Type_C_Sources_VCONN], "Type_C_Sources_VCONN", IS_ENABLED(CONFIG_USBC_VCONN)); +} - /********************************************************************* - * USB Data - Upstream Facing Port Fields - */ - { - int ds = USB_2; +/********************************************************************* + * Init VIF/Component[] USB Data - Upstream Facing Port Fields + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * Fields that are not currently being initialized + * + * vif_Component + * Device_Supports_USB_Data booleanFieldType + * Device_Contains_Captive_Retimer booleanFieldType + * Device_Truncates_DP_For_tDHPResponse booleanFieldType + * Device_Gen1x1_tLinkTurnaround numericFieldType + * Device_Gen2x1_tLinkTurnaround numericFieldType + */ +static void init_vif_component_usb_data_ufp_fields( + struct vif_field_t *vif_fields) +{ + int ds = USB_2; - switch (ds) { - case USB_2: - set_vif_field_itss(&vif_fields[Device_Speed], - "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"); - break; - case USB_GEN21: - set_vif_field_itss(&vif_fields[Device_Speed], - "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"); - break; - case USB_GEN22: - set_vif_field_itss(&vif_fields[Device_Speed], - "Device_Speed", - USB_GEN22, "USB 3.2 GEN 2x2"); - break; - default: - set_vif_field_itss(&vif_fields[Device_Speed], - "Device_Speed", - ds, NULL); - } + switch (ds) { + case USB_2: + set_vif_field_itss(&vif_fields[Device_Speed], + "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"); + break; + case USB_GEN21: + set_vif_field_itss(&vif_fields[Device_Speed], + "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"); + break; + case USB_GEN22: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + USB_GEN22, "USB 3.2 GEN 2x2"); + break; + default: + set_vif_field_itss(&vif_fields[Device_Speed], + "Device_Speed", + ds, NULL); } +} - /********************************************************************* - * USB Data - Downstream Facing Port Fields - */ - { - int ds = USB_2; +/********************************************************************* + * Init VIF/Component[] USB Data - Downstream Facing Port Fields + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * Fields that are not currently being initialized + * + * vif_Component + * Host_Supports_USB_Data booleanFieldType + * Is_DFP_On_Hub booleanFieldType + * Hub_Port_Number numericFieldType + * Host_Truncates_DP_For_tDHPResponse booleanFieldType + * Host_Gen1x1_tLinkTurnaround numericFieldType + * Host_Gen2x1_tLinkTurnaround numericFieldType + * Host_Suspend_Supported booleanFieldType + */ +static void init_vif_component_usb_data_dfp_fields( + struct vif_field_t *vif_fields) +{ + int ds = USB_2; - switch (ds) { - case USB_2: - set_vif_field_itss(&vif_fields[Host_Speed], - "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"); - break; - case USB_GEN21: - set_vif_field_itss(&vif_fields[Host_Speed], - "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"); - break; - case USB_GEN22: - set_vif_field_itss(&vif_fields[Host_Speed], - "Host_Speed", - USB_GEN22, "USB 3.2 GEN 2x2"); - break; - default: - set_vif_field_itss(&vif_fields[Host_Speed], - "Host_Speed", - ds, NULL); - } + switch (ds) { + case USB_2: + set_vif_field_itss(&vif_fields[Host_Speed], + "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"); + break; + case USB_GEN21: + set_vif_field_itss(&vif_fields[Host_Speed], + "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"); + break; + case USB_GEN22: + set_vif_field_itss(&vif_fields[Host_Speed], + "Host_Speed", + USB_GEN22, "USB 3.2 GEN 2x2"); + break; + default: + set_vif_field_itss(&vif_fields[Host_Speed], + "Host_Speed", + ds, NULL); } set_vif_field_b(&vif_fields[Host_Contains_Captive_Retimer], @@ -1647,10 +1664,17 @@ static int gen_vif(const char *name, set_vif_field_b(&vif_fields[Host_Is_Embedded], "Host_Is_Embedded", false); +} - /********************************************************************* - * PD Source Fields - */ +/********************************************************************* + * Init VIF/Component[] PD Source Fields + */ +static int init_vif_component_pd_source_fields( + struct vif_field_t *vif_fields, + struct vif_srcPdoList_t *comp_src_pdo_list, + int32_t *src_max_power, + enum dtype type) +{ if (type == DRP || type == SRC) { int i; @@ -1658,20 +1682,20 @@ static int gen_vif(const char *name, for (i = 0; i < src_pdo_cnt; i++) { int32_t pwr; - pwr = set_vif_src_pdo(&vif.Component[0].SrcPdoList[i], - src_pdo[i]); + pwr = init_vif_src_pdo(&comp_src_pdo_list[i], + src_pdo[i]); if (pwr < 0) { fprintf(stderr, "ERROR: Setting SRC PDO.\n"); return 1; } - if (pwr > src_max_power) - src_max_power = pwr; + if (pwr > *src_max_power) + *src_max_power = pwr; } set_vif_field_itss(&vif_fields[PD_Power_As_Source], "PD_Power_As_Source", - src_max_power, NULL); + *src_max_power, NULL); } if (type == DRP || type == SRC) @@ -1743,96 +1767,122 @@ static int gen_vif(const char *name, } } - /********************************************************************* - * PD Sink Fields - */ - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) { - int i; - int32_t snk_max_power = 0; + return 0; +} - /* Sink PDOs */ - for (i = 0; i < pd_snk_pdo_cnt; i++) { - int32_t pwr; +/********************************************************************* + * Init VIF/Component[] PD Sink Fields + */ +static int init_vif_component_pd_sink_fields( + struct vif_field_t *vif_fields, + struct vif_snkPdoList_t *comp_snk_pdo_list, + enum dtype type) +{ + int i; + int32_t snk_max_power = 0; - pwr = set_vif_snk_pdo(&vif.Component[0].SnkPdoList[i], - pd_snk_pdo[i]); - if (pwr < 0) { - fprintf(stderr, "ERROR: Setting SNK PDO.\n"); - return 1; - } + if (!IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) || type == SRC) + return 0; + + /* Sink PDOs */ + for (i = 0; i < pd_snk_pdo_cnt; i++) { + int32_t pwr; - if (pwr > snk_max_power) - snk_max_power = pwr; + pwr = init_vif_snk_pdo(&comp_snk_pdo_list[i], + pd_snk_pdo[i]); + if (pwr < 0) { + fprintf(stderr, "ERROR: Setting SNK PDO.\n"); + return 1; } - set_vif_field_itss(&vif_fields[PD_Power_As_Sink], - "PD_Power_As_Sink", - snk_max_power, NULL); + if (pwr > snk_max_power) + snk_max_power = pwr; } - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) - set_vif_field_b(&vif_fields[No_USB_Suspend_May_Be_Set], - "No_USB_Suspend_May_Be_Set", - true); + set_vif_field_itss(&vif_fields[PD_Power_As_Sink], + "PD_Power_As_Sink", + snk_max_power, NULL); - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) - set_vif_field_b(&vif_fields[GiveBack_May_Be_Set], - "GiveBack_May_Be_Set", - IS_ENABLED(CONFIG_USB_PD_GIVE_BACK)); + set_vif_field_b(&vif_fields[No_USB_Suspend_May_Be_Set], + "No_USB_Suspend_May_Be_Set", + true); - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) - set_vif_field_b(&vif_fields[Higher_Capability_Set], - "Higher_Capability_Set", - false); + set_vif_field_b(&vif_fields[GiveBack_May_Be_Set], + "GiveBack_May_Be_Set", + IS_ENABLED(CONFIG_USB_PD_GIVE_BACK)); - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) - 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"); + set_vif_field_b(&vif_fields[Higher_Capability_Set], + "Higher_Capability_Set", + false); - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && - (type == DRP || type == SNK)) - set_vif_field_itss(&vif_fields[Num_Snk_PDOs], - "Num_Snk_PDOs", - pd_snk_pdo_cnt, NULL); + 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"); - /********************************************************************* - * PD Dual Role Fields - */ - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) - set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Src], - "Accepts_PR_Swap_As_Src", - true); - - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) - set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Snk], - "Accepts_PR_Swap_As_Snk", - true); - - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) - set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Src], - "Requests_PR_Swap_As_Src", - true); - - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) - set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Snk], - "Requests_PR_Swap_As_Snk", - true); - - if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) && type == DRP) - set_vif_field_b(&vif_fields[FR_Swap_Supported_As_Initial_Sink], - "FR_Swap_Supported_As_Initial_Sink", - IS_ENABLED(CONFIG_USB_PD_FRS)); + set_vif_field_itss(&vif_fields[Num_Snk_PDOs], + "Num_Snk_PDOs", + pd_snk_pdo_cnt, NULL); - /********************************************************************* - * SOP Discovery Fields - */ + return 0; +} + +/********************************************************************* + * Init VIF/Component[] PD Dual Role Fields + */ +static void init_vif_component_pd_dual_role_fields( + struct vif_field_t *vif_fields, + enum dtype type) +{ + if (!IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE) || type != DRP) + return; + + set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Src], + "Accepts_PR_Swap_As_Src", + true); + + set_vif_field_b(&vif_fields[Accepts_PR_Swap_As_Snk], + "Accepts_PR_Swap_As_Snk", + true); + + set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Src], + "Requests_PR_Swap_As_Src", + true); + + set_vif_field_b(&vif_fields[Requests_PR_Swap_As_Snk], + "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)); +} + +/********************************************************************* + * Init VIF/Component[] SOP Discovery Fields + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * 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 + * Product_Type_DFP_SOP numericFieldType + * DFP_VDO_Port_Number numericFieldType + * Modal_Operation_Supported_SOP booleanFieldType + * USB_VID_SOP numericFieldType + * bcdDevice_SOP numericFieldType + * Num_SVIDs_Min_SOP numericFieldType + * Num_SVIDs_Max_SOP numericFieldType + * SVID_Fixed_SOP booleanFieldType + */ +static void init_vif_component_sop_discovery_fields( + struct vif_field_t *vif_fields) +{ if (IS_ENABLED(CONFIG_USB_PD_TCPMV2)) { char hex_str[10]; @@ -1848,20 +1898,40 @@ static int gen_vif(const char *name, DEFAULT_MISSING_PID, hex_str); #endif } +} - /********************************************************************* - * Battery Charging 1.2 Fields - */ +/********************************************************************* + * Init VIF/Component[] Battery Charging 1.2 Fields + */ +static void init_vif_component_bc_1_2_fields( + struct vif_field_t *vif_fields, + enum bc_1_2_support bc_support) +{ 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"); +} - /********************************************************************* - * Product Power Fields - */ +/********************************************************************* + * Init VIF/Component[] Product Power Fields + * + * TODO: Generic todo to fill in additional fields as the need presents + * itself + * + * Fields that are not currently being initialized + * + * vif_Component + * Port_Source_Power_Gang nonEmptyString + * Port_Source_Power_Gang_Max_Power numericFieldType + */ +static void init_vif_component_product_power_fields( + struct vif_field_t *vif_fields, + int32_t src_max_power, + enum dtype type) +{ if (type == DRP || type == SRC) { char str[10]; @@ -1875,6 +1945,93 @@ static int gen_vif(const char *name, set_vif_field(&vif_fields[Port_Source_Power_Type], "Port_Source_Power_Type", "0", "Assured"); +} + +static int gen_vif(const char *name, + const char *board, + const char *vif_producer) +{ + struct vif_t vif; + 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; + + /********************************************************************* + * Initialize the vif structure + */ + memset(&vif, 0, sizeof(struct vif_t)); + + init_vif_fields( + vif.vif_field, + board); + + init_vif_product_fields( + vif.Product.vif_field); + + init_vif_component_fields( + vif.Component[0].vif_field, + &bc_support, + type); + + init_vif_component_general_pd_fields( + vif.Component[0].vif_field, + type); + + init_vif_component_sop_capabilities_fields( + vif.Component[0].vif_field); + + init_vif_component_usb_type_c_fields( + vif.Component[0].vif_field, + type); + + init_vif_component_usb_data_ufp_fields( + vif.Component[0].vif_field); + + init_vif_component_usb_data_dfp_fields( + vif.Component[0].vif_field); + + if (init_vif_component_pd_source_fields( + 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, + type)) + return 1; + + init_vif_component_pd_dual_role_fields( + vif.Component[0].vif_field, + type); + + init_vif_component_sop_discovery_fields( + vif.Component[0].vif_field); + + init_vif_component_bc_1_2_fields( + vif.Component[0].vif_field, + bc_support); + + init_vif_component_product_power_fields( + vif.Component[0].vif_field, + src_max_power, + type); /********************************************************************* * Format the structure in XML and output it to file -- cgit v1.2.1