summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2019-04-22 11:12:08 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-05 00:27:14 +0000
commit5ddfe10ed4d6073f252960149d0b9744e0ba2a93 (patch)
treeb2adf31cd21ff8125ff4e9b50dfe70867881d1c7
parentb8723d58a8f624a2dfee3a3d7f28030dcd926d68 (diff)
downloadchrome-ec-5ddfe10ed4d6073f252960149d0b9744e0ba2a93.tar.gz
vif: Update VIF generator to Revision 1.40, Version 1.0 of the spec
Update the Vendor Information File generator so that it complies with Revision 1.40, Version 1.0 of the spec. The VIF files are generated when the board is built. So, make -j BOARD=<board> will create build/<board>/<board>_vif.txt A VIF can be generated manually after the board is built with build/<board>/util/genvif -b <board name> -o <out directory> BUG=b:131087690 BRANCH=none TEST=manual Generate VIF for Atlas and checked fields. Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: Iaa1eaf1f01f9d36ad3afd2818ebe81359b8531f6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1577739 Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Sam Hurst <shurst@google.com>
-rw-r--r--board/coffeecake/board.h3
-rw-r--r--board/dingdong/board.h3
-rw-r--r--board/hoho/board.h3
-rw-r--r--include/config.h59
-rw-r--r--util/genvif.c1105
5 files changed, 824 insertions, 349 deletions
diff --git a/board/coffeecake/board.h b/board/coffeecake/board.h
index 8ab4e381f2..f69ebe2f29 100644
--- a/board/coffeecake/board.h
+++ b/board/coffeecake/board.h
@@ -71,6 +71,9 @@
#define CONFIG_WP_ALWAYS
#define CONFIG_FLASH_READOUT_PROTECTION
+/* Inform VIF generator that this board is an Alt Mode Adapter */
+#define CONFIG_USB_ALT_MODE_ADAPTER
+
#ifndef __ASSEMBLER__
/* Timer selection */
diff --git a/board/dingdong/board.h b/board/dingdong/board.h
index 27f4b0af50..64947960ba 100644
--- a/board/dingdong/board.h
+++ b/board/dingdong/board.h
@@ -56,6 +56,9 @@
#define CONFIG_WP_ALWAYS
#define CONFIG_FLASH_READOUT_PROTECTION
+/* Inform VIF generator that this board is an Alt Mode Adapter */
+#define CONFIG_USB_ALT_MODE_ADAPTER
+
#ifndef __ASSEMBLER__
/* Timer selection */
diff --git a/board/hoho/board.h b/board/hoho/board.h
index 8eead97ae5..21fb536a6f 100644
--- a/board/hoho/board.h
+++ b/board/hoho/board.h
@@ -66,6 +66,9 @@
#define CONFIG_WP_ALWAYS
#define CONFIG_FLASH_READOUT_PROTECTION
+/* Inform VIF generator that this board is an Alt Mode Adapter */
+#define CONFIG_USB_ALT_MODE_ADAPTER
+
#ifndef __ASSEMBLER__
/* Timer selection */
diff --git a/include/config.h b/include/config.h
index ff3c75aab3..91a58aa9e9 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3977,6 +3977,52 @@
#undef CONFIG_USB_PD_PCIE_TUNNELING
/*
+ * The following two macros are ASCII text strings that matches what appears
+ * in the USB-IF Product Registration form for this device. These macros are
+ * used during VIF generation and they form the product name in the
+ * USB Integrator’s List.
+ */
+#undef CONFIG_USB_PD_MODEL_PART_NUMBER
+#undef CONFIG_USB_PD_PRODUCT_REVISION
+
+/*
+ * Should be defined if the device is a TypeC Alt Mode Adapter. This macro
+ * is used during VIF generation.
+ */
+#undef CONFIG_USB_ALT_MODE_ADAPTER
+
+/*
+ * A text string, provided by the USB-IF. This macro is used during VIF
+ * generation.
+ */
+#undef CONFIG_USB_PD_TID
+
+/*
+ * An ASCII text string that must correspond with the port label given on the
+ * device picture submitted to USB-IF by the Vendor along with the VIF. This
+ * macro is used during VIF generation.
+ */
+#undef CONFIG_USB_PD_PORT_LABEL
+
+/*
+ * Define if Get_Manufacturer_Info request PD message is supported.
+ * Used during VIF generation.
+ */
+#undef CONFIG_USB_PD_MANUFACTURER_INFO
+
+/*
+ * Define if both Security_Request and Security_Response PD messages are
+ * supported. Used during VIF generation.
+ */
+#undef CONFIG_USB_PD_SECURITY_MSGS
+
+/*
+ * The number of non-removable batteries in the device. Used duing VIF
+ * generation.
+ */
+#undef CONFIG_NUM_FIXED_BATTERIES
+
+/*
* Track VBUS level in TCPC module. This will only be needed if we're acting
* as an external TCPC.
*/
@@ -4194,19 +4240,6 @@
/* USB Device version of product */
#undef CONFIG_USB_BCD_DEV
-/*
- * Used during generation of VIF for USB Type-C Compliance Testing.
- * Indicates whether the UUT can communicate with USB 2.0 or USB 3.1 as a host
- * or as the Downstream Facing Port of a hub.
- */
-#undef CONFIG_VIF_TYPE_C_CAN_ACT_AS_HOST
-
-/*
- * Used during generation of VIF for USB Type-C Compliance Testing.
- * Indicates whether the UUT has a captive cable.
- */
-#undef CONFIG_VIF_CAPTIVE_CABLE
-
/*****************************************************************************/
/* Compile chip support for the USB device controller */
diff --git a/util/genvif.c b/util/genvif.c
index 66640a8a03..404363a033 100644
--- a/util/genvif.c
+++ b/util/genvif.c
@@ -21,18 +21,81 @@
#include "charge_manager.h"
#include "system.h"
-#define PD_REV_2_0 1
-#define PD_REV_3_0 2
-
-#define GENVIF_TITLE "EC GENVIF, Version 1.1"
-#define VIF_SPEC "Revision 1.22, Version 1.0"
-#define VENDOR_NAME "Google"
-#define PD_SPEC_REV PD_REV_2_0
-
-enum tab {INTRO = 0, GENERAL, USB, SOURCE, SINK, ROLE, SOP1, SOP2};
-enum dtype {SNK = 0, SRC = 3, DRP = 4};
+/*
+ * Vendor Info File Generator
+ * Revision 1.40, Version 1.0
+ */
-const uint32_t vdo_idh __attribute__((weak)) = 0;
+#define GENVIF_TITLE "EC GENVIF, Version 1.40"
+#define VIF_SPEC "Revision 1.40, Version 1.0"
+#define VENDOR_NAME "Google"
+
+enum spec_rev {
+ PD_REV_2_0 = 1,
+ PD_REV_3_0
+};
+
+enum field {
+ INTRO = 0,
+ PRODUCT,
+ GENERAL,
+ USB,
+ DEVICE,
+ SOURCE,
+ SINK,
+ DUAL_ROLE,
+ SOP,
+ BC12,
+};
+
+enum dtype {
+ SRC = 0,
+ SNK,
+ DRP
+};
+
+enum vif_product_type {
+ PORT = 0,
+ CABLE,
+ RE_TIMER
+};
+
+enum conn_type {
+ TYPE_A = 0,
+ TYPE_B,
+ TYPE_C,
+ MICRO_AB
+};
+
+enum port_type {
+ PT_CONSUMER = 0,
+ PT_CONSUMER_PROVIDER,
+ PT_PROVIDER_CONSUMER,
+ PT_PROVIDER,
+ PT_DRP,
+ PT_EMARKER
+};
+
+enum bc_1_2_support {
+ BC_NONE = 0,
+ BC_PORTABLE_DEVICE,
+ BC_CHARGING_PORT,
+ BC_BOTH
+};
+
+enum power_source {
+ PS_EXT_POWERED = 0,
+ PS_UFP_POWERED,
+ PS_BOTH
+};
+
+enum usb_speed {
+ USB_2,
+ USB_GEN11,
+ USB_GEN21,
+ USB_GEN12,
+ USB_GEN22
+};
const uint32_t *src_pdo;
uint32_t src_pdo_cnt;
@@ -54,7 +117,7 @@ static void write_title(FILE *vif)
fprintf(vif, ";\r\n");
}
-static void write_tab(FILE *vif, enum tab t)
+static void write_field(FILE *vif, enum field t)
{
if (!vif)
return;
@@ -63,29 +126,36 @@ static void write_tab(FILE *vif, enum tab t)
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
switch (t) {
case INTRO:
- fprintf(vif, "; Intro tab\r\n");
+ fprintf(vif, "; Intro Fields\r\n");
+ break;
+ case PRODUCT:
+ fprintf(vif, "; VIF Product Fields\r\n");
break;
case GENERAL:
- fprintf(vif, "; General PD Settings tab\r\n");
+ fprintf(vif, "; General PD Fields\r\n");
break;
case USB:
- fprintf(vif, "; USB Type-C tab\r\n");
+ fprintf(vif, "; USB Type-C Fields\r\n");
+ break;
+ case DEVICE:
+ fprintf(vif, "; USB Device Fields\r\n");
break;
case SOURCE:
- fprintf(vif, "; Source tab\r\n");
+ fprintf(vif, "; PD Source Fields\r\n");
break;
case SINK:
- fprintf(vif, "; Sink tab\r\n");
+ fprintf(vif, "; PD Sink Fields\r\n");
break;
- case ROLE:
- fprintf(vif, "; Dual Role tab\r\n");
+ case DUAL_ROLE:
+ fprintf(vif, "; PD Dual Role Fields\r\n");
break;
- case SOP1:
- fprintf(vif, "; SOP Discovery - Part One tab\r\n");
+ case SOP:
+ fprintf(vif, "; SOP Discovery Fields\r\n");
break;
- case SOP2:
- fprintf(vif, "; SOP Discovery - Part Two tab\r\n");
+ case BC12:
+ fprintf(vif, ": Battery Charging 1.2 Fields\r\n");
break;
+
}
fprintf(vif, "%s\r\n",
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
@@ -115,14 +185,6 @@ static int is_snk(void)
#endif
}
-static int is_unconstrained(void)
-{
- if (is_src())
- return !!(src_pdo[0] & PDO_FIXED_UNCONSTRAINED);
- else
- return 0;
-}
-
static int is_drp(void)
{
if (is_src())
@@ -131,148 +193,6 @@ static int is_drp(void)
return 0;
}
-#ifdef CONFIG_USB_PD_DUAL_ROLE
-static char *giveback(void)
-{
-#ifdef CONFIG_USB_PD_GIVE_BACK
- return "YES";
-#else
- return "NO";
-#endif
-}
-#endif
-
-static char *is_comms_cap(void)
-{
- if (is_src())
- return yes_no(src_pdo[0] & PDO_FIXED_COMM_CAP);
- else
- return "NO";
-}
-
-static char *dr_swap_to_ufp_supported(void)
-{
- if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP))
- return yes_no(pd_check_data_swap(0, PD_ROLE_DFP));
-
- return "NO";
-}
-
-static char *dr_swap_to_dfp_supported(void)
-{
- if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP))
- return yes_no(pd_check_data_swap(0, PD_ROLE_UFP));
-
- return "NO";
-}
-
-static char *vconn_swap(void)
-{
-#ifdef CONFIG_USBC_VCONN_SWAP
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *try_src(void)
-{
-#ifdef CONFIG_USB_PD_TRY_SRC
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *can_act_as_host(void)
-{
-#ifdef CONFIG_VIF_TYPE_C_CAN_ACT_AS_HOST
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *can_act_as_device(void)
-{
-#ifdef CONFIG_USB
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *captive_cable(void)
-{
-#ifdef CONFIG_VIF_CAPTIVE_CABLE
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *sources_vconn(void)
-{
-#ifdef CONFIG_USBC_VCONN
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static char *battery_powered(void)
-{
-#ifdef CONFIG_BATTERY
- return "YES";
-#else
- return "NO";
-#endif
-}
-
-static uint32_t product_type(void)
-{
- return PD_IDH_PTYPE(vdo_idh);
-}
-
-static uint32_t pid_sop(void)
-{
-#ifdef CONFIG_USB_PID
- return CONFIG_USB_PID;
-#else
- return 0;
-#endif
-}
-
-static uint32_t rp_value(void)
-{
-#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
- return CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT;
-#else
- return 0;
-#endif
-}
-
-static char *attempts_discov_sop(enum dtype type)
-{
-#ifdef CONFIG_USB_PD_SIMPLE_DFP
- if (type == SRC)
- return "NO";
- else
- return "YES";
-#else
- return "YES";
-#endif
-}
-
-static uint32_t bcddevice_sop(void)
-{
-#ifdef CONFIG_USB_BCD_DEV
- return CONFIG_USB_BCD_DEV;
-#else
- return 0;
-#endif
-}
-
/* Application exits on failure */
__attribute__((__format__(__printf__, 2, 3)))
static void append(char **buf, const char *fmt, ...)
@@ -379,6 +299,32 @@ static int32_t write_pdo_to_buf(char **buf, uint32_t pdo,
else
append(buf, "\tSnk_PDO_Op_Current%d: %d\r\n", pnum,
current);
+ } else if ((pdo & PDO_TYPE_MASK) == PDO_TYPE_AUGMENTED) {
+ uint32_t pps = (pdo >> 28) & 3;
+ uint32_t pps_max_voltage = (pdo >> 17) & 0xff;
+ uint32_t pps_min_voltage = (pdo >> 8) & 0xff;
+ uint32_t pps_current = pdo & 0x7f;
+
+ if (pps) {
+ fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo);
+ return -1;
+ }
+
+ append(buf, "\t%s_PDO_Supply_Type%d: 3\r\n",
+ (type == SRC) ? "Src" : "Snk", pnum);
+
+ if (type == SRC)
+ append(buf, "\tSrc_PDO_Max_Current%d: %d\r\n", pnum,
+ pps_current);
+ else
+ append(buf, "\tSnk_PDO_Op_Current%d: %d\r\n", pnum,
+ pps_current);
+
+ append(buf, "\t%s_PDO_Min_Voltage%d: %d\r\n",
+ (type == SRC) ? "Src" : "Snk", pnum, pps_min_voltage);
+
+ append(buf, "\t%s_PDO_Max_Voltage%d: %d\r\n",
+ (type == SRC) ? "Src" : "Snk", pnum, pps_max_voltage);
} else {
fprintf(stderr, "ERROR: Invalid PDO_TYPE %d.\n", pdo);
return -1;
@@ -389,134 +335,485 @@ static int32_t write_pdo_to_buf(char **buf, uint32_t pdo,
return power;
}
-/**
- * Carriage and line feed, '\r\n', is needed because the file is processed
- * on a Windows machine.
+/*
+ * Intro Fields
*/
-static int gen_vif(const char *name, const char *board,
- const char *vif_producer)
+
+static void write_vif_specification(FILE *vif)
{
- FILE *vif;
- enum dtype type;
- char *type_name;
+ fprintf(vif, "$VIF_Specification: \"%s\"\r\n", VIF_SPEC);
+}
- if (is_drp()) {
- type = DRP;
- type_name = "DRP";
- } else if (is_src() && is_snk()) {
- /* No DRP with SRC and SNK PDOs detected. So ignore. */
- /* ie. Twinki or Plankton */
- return 0;
- } else if (is_src()) {
- type = SRC;
- type_name = "SRC";
- } else if (is_snk()) {
- type = SNK;
- type_name = "SNK";
- } else {
- return 1;
+static void write_vif_producer(FILE *vif, const char *vp)
+{
+ fprintf(vif, "$VIF_Producer: \"%s\"\r\n", vp);
+}
+
+static void write_vendor_name(FILE *vif)
+{
+ fprintf(vif, "$Vendor_Name: \"%s\"\r\n", VENDOR_NAME);
+}
+
+static void write_model_part_number(FILE *vif)
+{
+#ifdef CONFIG_USB_PD_MODEL_PART_NUMBER
+ fprintf(vif, "$Model_Part_Number: \"%s\"\r\n",
+ CONFIG_USB_PD_MODEL_PART_NUMBER);
+#endif
+}
+
+static void write_product_revision(FILE *vif)
+{
+#ifdef CONFIG_USB_PD_PRODUCT_REVISION
+ fprintf(vif, "$Model_Part_Number: \"%s\"\r\n",
+ CONFIG_USB_PD_PRODUCT_REVISION);
+#endif
+}
+
+static void write_tid(FILE *vif)
+{
+#ifdef CONFIG_USB_PD_TID
+ fprintf(vif, "$TID: \"%s\"\r\n", CONFIG_USB_PD_TID);
+#endif
+}
+
+/*
+ * VIF Product Fields
+ */
+
+static void write_vif_product_type(FILE *vif)
+{
+ fprintf(vif, "VIF_Product_Type: %d\r\n", PORT);
+}
+
+static void write_port_label(FILE *vif)
+{
+#ifdef CONFIG_USB_PD_PORT_LABEL
+ fprintf(vif, "$Port_Label: %s\r\n", CONFIG_USB_PD_PORT_LABEL);
+#endif
+}
+
+static void write_connector_type(FILE *vif)
+{
+ fprintf(vif, "Connector_Type: %d\r\n", TYPE_C);
+}
+
+static void write_usb_pd_support(FILE *vif)
+{
+ char *yn = "NO";
+
+#if defined(CONFIG_USB_PRL_SM) || defined(CONFIG_USB_POWER_DELIVERY)
+ yn = "YES";
+#endif
+
+ fprintf(vif, "USB_PD_Support: %s", yn);
+}
+
+static void write_pd_port_type(FILE *vif, enum dtype type)
+
+{
+ enum port_type pt;
+
+ switch (type) {
+ case SNK:
+ pt = PT_CONSUMER;
+ break;
+ case SRC:
+ pt = PT_PROVIDER;
+ break;
+ case DRP:
+ pt = PT_DRP;
+ break;
}
- /* Create VIF */
- vif = fopen(name, "w+");
- if (vif == NULL)
- return 1;
+ fprintf(vif, "PD_Port_Type: %d\r\n", pt);
+}
- /* Write VIF Title */
- write_title(vif);
+static void write_type_c_state_machine(FILE *vif, enum dtype type)
+{
+ fprintf(vif, "Type_C_State_Machine: %d\r\n", type);
+}
- /* Write Intro Tab comment */
- write_tab(vif, INTRO);
+static void write_captive_cable(FILE *vif)
+{
+ fprintf(vif, "Captive_Cable: NO\r\n");
+}
- /* Write VIF Header */
- fprintf(vif, "$VIF_Specification: \"%s\"\r\n", VIF_SPEC);
- fprintf(vif, "$VIF_Producer: \"%s\"\r\n", vif_producer);
- fprintf(vif, "UUT_Device_Type: %d ; %s\r\n", type, type_name);
- fprintf(vif, "$Vendor_Name: \"%s\"\r\n", VENDOR_NAME);
- fprintf(vif, "$Product_Name: \"%s\"\r\n", board);
+static void write_port_battery_powered(FILE *vif)
+{
+#ifdef CONFIG_BATTERY
+ fprintf(vif, "Port_Battery_Powered: YES\r\n");
+#else
+ fprintf(vif, "Port_Battery_Powered: NO\r\n");
+#endif
+}
+
+static void write_bc_1_2_support(FILE *vif, enum dtype type)
+{
+ enum bc_1_2_support bc = BC_NONE;
+
+ fprintf(vif, "BC_1_2_Support: %d\r\n", bc);
+}
+
+/*
+ * General PD Fields
+ */
- /* Write General PD Settings Tab comment */
- write_tab(vif, GENERAL);
+static void write_pd_spec_rev(FILE *vif)
+{
+ enum spec_rev rev;
- fprintf(vif, "PD_Specification_Revision: %d\r\n", PD_SPEC_REV);
- fprintf(vif, "SOP_Capable: YES\r\n");
- fprintf(vif, "SOP_P_Capable: NO\r\n");
+#if defined(CONFIG_USB_PD_REV30) || defined(CONFIG_USB_PRL_SM)
+ rev = PD_REV_3_0;
+#else
+ rev = PD_REV_2_0;
+#endif
+ fprintf(vif, "PD_Specification_Revision: %d\r\n", rev);
+}
+
+static void write_usb_comms_capable(FILE *vif)
+{
+ char *yn = "YES";
+
+#if defined(CONFIG_USB_VPD) || defined(CONFIG_USB_CTVPD)
+ yn = "NO";
+#endif
+ fprintf(vif, "USB_Comms_Capable: %s\r\n", yn);
+}
+
+static void write_dr_swap_to_dfp_supported(FILE *vif)
+{
+ char *yn = "NO";
+
+ if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP))
+ yn = yes_no(pd_check_data_swap(0, PD_ROLE_DFP));
+
+ fprintf(vif, "DR_Swap_To_DFP_Supported: %s\r\n", yn);
+}
+
+static void write_dr_swap_to_ufp_supported(FILE *vif)
+{
+ char *yn = "NO";
+
+ if (is_src() && (src_pdo[0] & PDO_FIXED_DATA_SWAP))
+ yn = yes_no(pd_check_data_swap(0, PD_ROLE_UFP));
+
+
+ fprintf(vif, "DR_Swap_To_UFP_Supported: %s\r\n", yn);
+}
+
+static void write_unconstrained_power(FILE *vif)
+{
+ int yn = 0;
+
+ if (is_src())
+ yn = !!(src_pdo[0] & PDO_FIXED_UNCONSTRAINED);
+
+ fprintf(vif, "Unconstrained_Power: %s\r\n", yes_no(yn));
+}
+
+static void write_vconn_swap_to_on_supported(FILE *vif)
+{
+ char *yn = "NO";
+
+#ifdef CONFIG_USBC_VCONN_SWAP
+ yn = "YES";
+#endif
+
+ fprintf(vif, "VCONN_Swap_To_On_Supported: %s\r\n", yn);
+}
+
+static void write_vconn_swap_to_off_supported(FILE *vif)
+{
+ char *yn = "NO";
+
+#ifdef CONFIG_USBC_VCONN_SWAP
+ yn = "YES";
+#endif
+
+ fprintf(vif, "VCONN_Swap_To_Off_Supported: %s\r\n", yn);
+}
+
+static void write_responds_to_discov_sop_ufp(FILE *vif)
+{
+ fprintf(vif, "Responds_To_Discov_SOP_UFP: NO\r\n");
+}
+
+static void write_responds_to_discov_sop_dfp(FILE *vif)
+{
+ fprintf(vif, "Responds_To_Discov_SOP_DFP: NO\r\n");
+}
+
+static void write_attempts_discov_sop(FILE *vif, enum dtype type)
+{
+ char *yn = "YES";
+
+#ifdef CONFIG_USB_PD_SIMPLE_DFP
+ if (type == SRC)
+ yn = "NO";
+ else
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Attempts_Discov_SOP: %s\r\n", yn);
+}
+
+static void write_chunking_implemented_sop(FILE *vif)
+{
+ char *yn = "NO";
+
+#if defined(CONFIG_USB_PD_REV30) && defined(CONFIG_USB_PRL_SM)
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Chunking_Implemented_SOP: %s\r\n", yn);
+}
+
+static void write_unchunked_extended_messages_supported(FILE *vif)
+{
+ fprintf(vif, "Unchunked_Extended_Messages_Supported: NO\r\n");
+}
+
+static void write_manufacturer_info_supported_port(FILE *vif)
+{
+ char *yn = "NO";
+
+#ifdef CONFIG_USB_PD_MANUFACTURER_INFO
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Manufacturer_Info_Supported_Port: %s\r\n", yn);
+}
+
+static void write_manufacturer_info_pid_port(FILE *vif)
+{
+#ifdef USB_PID_GOOGLE
+ fprintf(vif, "Manufacturer_Info_PID_Port: 0x%04x\r\n", USB_PID_GOOGLE);
+#endif
+}
+
+static void write_security_msgs_supported_sop(FILE *vif)
+{
+ char *yn = "NO";
+
+#ifdef CONFIG_USB_PD_SECURITY_MSGS
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Security_Msgs_Supported_SOP: %s\r\n", yn);
+}
+
+static void write_num_fixed_batteries(FILE *vif)
+{
+ int num = 1;
+
+#ifdef CONFIG_NUM_FIXED_BATTERIES
+ num = CONFIG_NUM_FIXED_BATTERIES;
+#else
+#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD)
+ num = 0;
+#endif
+#endif
+
+ fprintf(vif, "Num_Fixed_Batteries: %d\r\n", num);
+}
+
+static void write_num_swappable_battery_slots(FILE *vif)
+{
+ fprintf(vif, "Num_Swappable_Battery_Slots: 0\r\n");
+}
+
+static void write_sop_capable(FILE *vif)
+{
+ char *yn = "YES";
+
+#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD)
+ yn = "NO";
+#endif
+
+ fprintf(vif, "SOP_Capable: %s\r\n", yn);
+}
+
+static void write_sop_p_capable(FILE *vif)
+{
+ char *yn = "NO";
+
+#if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD)
+ yn = "YES";
+#endif
+
+ fprintf(vif, "SOP_P_Capable: %s\r\n", yn);
+}
+
+static void write_sop_pp_capable(FILE *vif)
+{
fprintf(vif, "SOP_PP_Capable: NO\r\n");
+}
+
+static void write_sop_p_debug_capable(FILE *vif)
+{
fprintf(vif, "SOP_P_Debug_Capable: NO\r\n");
+}
+
+static void write_sop_pp_debug_capable(FILE *vif)
+{
fprintf(vif, "SOP_PP_Debug_Capable: NO\r\n");
- fprintf(vif, "USB_Comms_Capable: %s\r\n", is_comms_cap());
- fprintf(vif, "DR_Swap_To_DFP_Supported: %s\r\n",
- dr_swap_to_dfp_supported());
- fprintf(vif, "DR_Swap_To_UFP_Supported: %s\r\n",
- dr_swap_to_ufp_supported());
- fprintf(vif, "Unconstrained_Powered: %s\r\n",
- yes_no(is_unconstrained()));
- fprintf(vif, "VCONN_Swap_To_On_Supported: %s\r\n", vconn_swap());
- fprintf(vif, "VCONN_Swap_To_Off_Supported: %s\r\n", vconn_swap());
- fprintf(vif, "Responds_To_Discov_SOP: YES\r\n");
- fprintf(vif, "Attempts_Discov_SOP: %s\r\n", attempts_discov_sop(type));
-
- /* Write USB Type-C Tab comment */
- write_tab(vif, USB);
-
- /* set Type_C_State_Machine */
- {
- int typec;
-
- switch (type) {
- case DRP:
- typec = 2;
- break;
+}
- case SNK:
- typec = 1;
- break;
+/*
+ * USB Type-C Fields
+ */
- default:
- typec = 0;
- }
+static void write_type_c_implements_try_src(FILE *vif)
+{
+ char *yn = "NO";
- fprintf(vif,
- "Type_C_State_Machine: %d ; %s\r\n", typec, type_name);
- }
+#ifdef CONFIG_USB_PD_TRY_SRC
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Type_C_Implements_Try_SRC: %s\r\n", yn);
+}
- fprintf(vif, "Type_C_Implements_Try_SRC: %s\r\n", try_src());
+static void write_type_c_implements_try_snk(FILE *vif)
+{
fprintf(vif, "Type_C_Implements_Try_SNK: NO\r\n");
- fprintf(vif, "Rp_Value: %d\r\n", rp_value());
- /* None of the current devices send SOP' / SOP", so NO.*/
- fprintf(vif, "Type_C_Is_VCONN_Powered_Accessory: NO\r\n");
+}
+
+static void write_rp_value(FILE *vif)
+{
+ /*
+ * 0 - Default
+ * 1 - 1.5A
+ * 2 - 3A
+ */
+ int rp = CONFIG_USB_PD_PULLUP;
+
+#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
+ rp = CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT;
+#endif
+
+ fprintf(vif, "Rp_Value: %d\r\n", rp);
+}
+
+static void write_type_c_supports_vconn_powered_accessory(FILE *vif)
+{
fprintf(vif, "Type_C_Supports_VCONN_Powered_Accessory: NO\r\n");
+}
+static void write_type_c_is_debug_target_src(FILE *vif)
+{
fprintf(vif, "Type_C_Is_Debug_Target_SRC: YES\r\n");
+}
+
+static void write_type_c_is_debug_target_snk(FILE *vif)
+{
fprintf(vif, "Type_C_Is_Debug_Target_SNK: YES\r\n");
+}
+
+static void write_type_c_can_act_as_host(FILE *vif)
+{
+ char *yn = "YES";
+
+ #if defined(CONFIG_USB_CTVPD) || defined(CONFIG_USB_VPD)
+ yn = "NO";
+ #endif
+
+ fprintf(vif, "Type_C_Can_Act_As_Host: %s\r\n", yn);
+}
+
+static void write_type_c_is_alt_mode_controller(FILE *vif)
+{
+ fprintf(vif, "Type_C_Is_Alt_Mode_Controller: NO\r\n");
+}
+
+static void write_type_c_can_act_as_device(FILE *vif)
+{
+ char *yn = "NO";
+
+#if defined(USB_DEV_CLASS) && defined(USB_CLASS_BILLBOARD)
+ if (USB_DEV_CLASS == USB_CLASS_BILLBOARD)
+ yn = "YES";
+#endif
- fprintf(vif, "Type_C_Can_Act_As_Host: %s\r\n", can_act_as_host());
- /* Supports USB 3.1 when communicating as a host */
- fprintf(vif, "Type_C_Host_Speed: 4\r\n");
- fprintf(vif, "Type_C_Can_Act_As_Device: %s\r\n", can_act_as_device());
- fprintf(vif, "Type_C_Device_Speed: 4\r\n");
+ fprintf(vif, "Type_C_Can_Act_As_Device: %s\r\n", yn);
+}
+
+static void write_type_c_is_alt_mode_adapter(FILE *vif)
+{
+ char *yn = "NO";
+
+ if (IS_ENABLED(CONFIG_USB_ALT_MODE_ADAPTER))
+ yn = "YES";
+
+ fprintf(vif, "Type_C_Is_Alt_Mode_Adapter: %s\r\n", yn);
+}
+
+static void write_type_c_power_source(FILE *vif)
+{
+ /*
+ * 0 - Externally Powered
+ * 1 - USB-powered
+ * 2 - Both
+ */
+ int ps = 1;
+
+ if (CONFIG_DEDICATED_CHARGE_PORT_COUNT == 1)
+ ps = 0;
- fprintf(vif, "Type_C_Is_Alt_Mode_Controller: YES\r\n");
- fprintf(vif, "Type_C_Is_Alt_Mode_Device: NO\r\n");
+ fprintf(vif, "Type_C_Power_Source: %d\r\n", ps);
+}
- fprintf(vif, "Type_C_Power_Source: 2\r\n");
- fprintf(vif, "Type_C_BC_1_2_Support: 1\r\n");
- fprintf(vif, "Type_C_Battery_Powered: %s\r\n", battery_powered());
+static void write_type_c_port_on_hub(FILE *vif)
+{
fprintf(vif, "Type_C_Port_On_Hub: NO\r\n");
+}
+
+static void write_type_c_supports_audio_accessory(FILE *vif)
+{
fprintf(vif, "Type_C_Supports_Audio_Accessory: NO\r\n");
- fprintf(vif, "Captive_Cable: %s\r\n", captive_cable());
- fprintf(vif, "Type_C_Source_Vconn: %s\r\n", sources_vconn());
+}
- /* Write Source Fields */
- if (type == DRP || type == SRC) {
- uint32_t max_power = 0;
- char *buf = NULL;
- int i;
- int32_t pwr;
+static void write_type_c_sources_vconn(FILE *vif)
+{
+ char *yn = "NO";
+
+#ifdef CONFIG_USBC_VCONN
+ yn = "YES";
+#endif
+
+ fprintf(vif, "Type_C_Source_Vconn: %s\r\n", yn);
+}
+
+/*
+ * USB Device Fields
+ */
+
+static void write_device_speed(FILE *vif)
+{
+ /*
+ * TODO(shurst): USB_2 might not be true for all boards and will need
+ * changing for future board that implement USB_GENx.
+ */
+ enum usb_speed speed = USB_2;
+
+ fprintf(vif, "Device_Speed: %d\r\n", speed);
+}
+
+/*
+ * PD Source Fields
+ */
+static int write_pd_source_fields(FILE *vif, enum dtype type)
+{
+ uint32_t max_power = 0;
+ char *pdo_buf = NULL;
+ int i;
+ int32_t pwr;
- /* Write Source PDOs */
+ if (type == DRP || type == SRC) {
+ /* Source PDOs */
for (i = 0; i < src_pdo_cnt; i++) {
- pwr = write_pdo_to_buf(&buf, src_pdo[i], SRC, i+1);
+ pwr = write_pdo_to_buf(&pdo_buf, src_pdo[i], SRC, i+1);
if (pwr < 0) {
fprintf(stderr, "ERROR: Out of memory.\n");
fclose(vif);
@@ -527,26 +824,54 @@ static int gen_vif(const char *name, const char *board,
max_power = pwr;
}
- /* Write Source Tab comment */
- write_tab(vif, SOURCE);
+ /* Source Fields */
fprintf(vif, "PD_Power_as_Source: %d\r\n", max_power);
fprintf(vif, "USB_Suspend_May_Be_Cleared: YES\r\n");
fprintf(vif, "Sends_Pings: NO\r\n");
fprintf(vif, "Num_Src_PDOs: %d\r\n", src_pdo_cnt);
- fprintf(vif, "\r\n%s\r\n", buf);
- free(buf);
+
+ if (IS_ENABLED(CONFIG_USBC_PPC)) {
+ /*
+ * 0 – Over-Current Response
+ * 1 – Under-Voltage Response
+ * 2 – Both
+ */
+ int resp = 0;
+
+ fprintf(vif, "PD_OC_Protection: YES\r\n");
+ fprintf(vif, "PD_OCP_Method: %d\r\n", resp);
+ } else {
+ fprintf(vif, "PD_OC_Protection: NO\r\n");
+ }
+
+ fprintf(vif, "\r\n%s\r\n", pdo_buf);
+ free(pdo_buf);
}
+ return 0;
+}
+
+/*
+ * PD Sink Fields
+ */
+static int write_pd_sink_fields(FILE *vif, enum dtype type)
+{
#ifdef CONFIG_USB_PD_DUAL_ROLE
- if (type == DRP || type == SNK) {
- uint32_t max_power = 0;
- char *buf = NULL;
- int32_t pwr;
- int i;
+ uint32_t max_power = 0;
+ char *pdo_buf = NULL;
+ int32_t pwr;
+ int i;
+ char *giveback = "NO";
- /* Write Sink PDOs */
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ giveback = "YES";
+#endif
+
+ if (type == DRP || type == SNK) {
+ /* Sink PDOs */
for (i = 0; i < pd_snk_pdo_cnt; i++) {
- pwr = write_pdo_to_buf(&buf, pd_snk_pdo[i], SNK, i+1);
+ pwr = write_pdo_to_buf(&pdo_buf,
+ pd_snk_pdo[i], SNK, i+1);
if (pwr < 0) {
fprintf(stderr, "ERROR: Out of memory.\n");
@@ -558,72 +883,181 @@ static int gen_vif(const char *name, const char *board,
max_power = pwr;
}
- /* Write Sink Tab comment */
- write_tab(vif, SINK);
+ /* Sink Fields */
fprintf(vif, "PD_Power_as_Sink: %d\r\n", max_power);
- fprintf(vif, "USB_Suspend_May_Be_Cleared: NO\r\n");
- fprintf(vif, "GiveBack_May_Be_Set: %s\r\n", giveback());
+ fprintf(vif, "No_USB_Suspend_May_Be_Set: YES\r\n");
+ fprintf(vif, "GiveBack_May_Be_Set: %s\r\n", giveback);
fprintf(vif, "Higher_Capability_Set: NO\r\n");
fprintf(vif, "Num_Snk_PDOs: %d\r\n", pd_snk_pdo_cnt);
- fprintf(vif, "\r\n%s\r\n", buf);
- free(buf);
+ fprintf(vif, "\r\n%s\r\n", pdo_buf);
+ free(pdo_buf);
}
+#endif
+ return 0;
+}
- /* Write DRP Fields */
+/*
+ * PD Dual Role Fields
+ */
+static void write_pd_drp_fields(FILE *vif, enum dtype type)
+{
+#ifdef CONFIG_USB_PD_DUAL_ROLE
if (type == DRP) {
- /* Write Dual Role Tab comment */
- write_tab(vif, ROLE);
+ /* Dual Role Fields */
fprintf(vif, "Accepts_PR_Swap_As_Src: YES\r\n");
fprintf(vif, "Accepts_PR_Swap_As_Snk: YES\r\n");
fprintf(vif, "Requests_PR_Swap_As_Src: YES\r\n");
- fprintf(vif, "Requests_PR_Swap_As_Snk: YES\r\n");
+ fprintf(vif, "FR_Swap_Supported_As_Initial_Sink: NO\r\n");
}
#endif
+}
- /* Write SOP Discovery -Part One Tab comment */
- write_tab(vif, SOP1);
- /* SOP Discovery Fields */
- fprintf(vif, "Structured_VDM_Version_SOP: 0\r\n");
- fprintf(vif, "XID_SOP: 0\r\n");
- fprintf(vif, "Data_Capable_as_USB_Host_SOP: %s\r\n",
- can_act_as_host());
- fprintf(vif, "Data_Capable_as_USB_Device_SOP: %s\r\n",
- can_act_as_device());
- fprintf(vif, "Product_Type_SOP: %d\r\n", product_type());
- fprintf(vif, "Modal_Operation_Supported_SOP: YES\r\n");
- fprintf(vif, "USB_VID_SOP: 0x%04x\r\n", USB_VID_GOOGLE);
- fprintf(vif, "PID_SOP: 0x%04x\r\n", pid_sop());
- fprintf(vif, "bcdDevice_SOP: 0x%04x\r\n", bcddevice_sop());
-
- {
- int svid_num;
-
- /* Write SOP Discovery -Part One Tab comment */
- write_tab(vif, SOP2);
-#ifdef USB_SID_DISPLAYPORT
- svid_num = 2;
-#else
- svid_num = 1;
-#endif
- fprintf(vif, "SVID_fixed_SOP: YES\r\n");
- fprintf(vif, "Num_SVIDs_min_SOP: %d\r\n", svid_num);
- fprintf(vif, "Num_SVIDs_max_SOP: %d\r\n\n", svid_num);
- }
+/**
+ * Carriage and line feed, '\r\n', is needed because the file is processed
+ * on a Windows machine.
+ */
+static int gen_vif(const char *name, const char *board,
+ const char *vif_producer)
+{
+ FILE *vif;
+ enum dtype type;
+
+ 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;
+
+ /*
+ * Create VIF
+ */
+ vif = fopen(name, "w+");
+ if (vif == NULL)
+ return 1;
+
+ /*
+ * Write VIF Title
+ */
+ write_title(vif);
+
+ /*
+ * Write Intro Fields comment
+ */
+ write_field(vif, INTRO);
+
+ write_vif_specification(vif);
+ write_vif_producer(vif, vif_producer);
+ write_vendor_name(vif);
+ write_model_part_number(vif);
+ write_product_revision(vif);
+ write_tid(vif);
+
+ /*
+ * Write VIF Product Fields
+ */
+ write_field(vif, PRODUCT);
+
+ write_vif_product_type(vif);
+ write_port_label(vif);
+ write_connector_type(vif);
+ write_usb_pd_support(vif);
+ write_pd_port_type(vif, type);
+ write_type_c_state_machine(vif, type);
+ write_captive_cable(vif);
+ write_port_battery_powered(vif);
+ write_bc_1_2_support(vif, type);
+
+
+ /*
+ * Write General PD Fields
+ */
+ write_field(vif, GENERAL);
+
+ write_pd_spec_rev(vif);
+ write_usb_comms_capable(vif);
+ write_dr_swap_to_dfp_supported(vif);
+ write_dr_swap_to_ufp_supported(vif);
+ write_unconstrained_power(vif);
+ write_vconn_swap_to_on_supported(vif);
+ write_vconn_swap_to_off_supported(vif);
+ write_responds_to_discov_sop_ufp(vif);
+ write_responds_to_discov_sop_dfp(vif);
+ write_attempts_discov_sop(vif, type);
+ write_chunking_implemented_sop(vif);
+ write_unchunked_extended_messages_supported(vif);
+ write_manufacturer_info_supported_port(vif);
+ write_manufacturer_info_pid_port(vif);
+ write_security_msgs_supported_sop(vif);
+ write_num_fixed_batteries(vif);
+ write_num_swappable_battery_slots(vif);
+ write_sop_capable(vif);
+ write_sop_p_capable(vif);
+ write_sop_pp_capable(vif);
+ write_sop_p_debug_capable(vif);
+ write_sop_pp_debug_capable(vif);
+
+ /*
+ * Write USB Type-C Fields
+ */
+ write_field(vif, USB);
+
+ write_type_c_implements_try_src(vif);
+ write_type_c_implements_try_snk(vif);
+ write_rp_value(vif);
+ write_type_c_supports_vconn_powered_accessory(vif);
+ write_type_c_is_debug_target_src(vif);
+ write_type_c_is_debug_target_snk(vif);
+ write_type_c_can_act_as_host(vif);
+ write_type_c_is_alt_mode_controller(vif);
+ write_type_c_can_act_as_device(vif);
+ write_type_c_is_alt_mode_adapter(vif);
+ write_type_c_power_source(vif);
+ write_type_c_port_on_hub(vif);
+ write_type_c_supports_audio_accessory(vif);
+ write_type_c_sources_vconn(vif);
+
+
+ /*
+ * Write USB Device Fields
+ */
+ write_field(vif, DEVICE);
+
+ write_device_speed(vif);
+
+ /*
+ * Write PD Source Fields
+ */
+ write_field(vif, SOURCE);
+
+ write_pd_source_fields(vif, type);
+
+ /*
+ * Write PD Sink Fields
+ */
+ write_field(vif, SINK);
+
+ write_pd_sink_fields(vif, type);
+
+
+ /*
+ * Write DRP Fields
+ */
+ write_field(vif, DUAL_ROLE);
+
+ write_pd_drp_fields(vif, type);
+
+ /*
+ * Battery Charging 1.2 Fields
+ */
+ write_field(vif, BC12);
- fprintf(vif, "\tSVID1_SOP: 0x%04x\r\n", USB_VID_GOOGLE);
- fprintf(vif, "\tSVID1_modes_fixed_SOP: YES\r\n");
- fprintf(vif, "\tSVID1_num_modes_min_SOP: 1\r\n");
- fprintf(vif, "\tSVID1_num_modes_max_SOP: 1\r\n");
- fprintf(vif, "\tSVID1_mode1_enter_SOP: YES\r\n\n");
-
-#ifdef USB_SID_DISPLAYPORT
- fprintf(vif, "\tSVID2_SOP: 0x%04x\r\n", USB_SID_DISPLAYPORT);
- fprintf(vif, "\tSVID2_modes_fixed_SOP: YES\r\n");
- fprintf(vif, "\tSVID2_num_modes_min_SOP: 2\r\n");
- fprintf(vif, "\tSVID2_num_modes_max_SOP: 2\r\n");
- fprintf(vif, "\tSVID2_mode1_enter_SOP: YES\r\n");
- fprintf(vif, "\tSVID2_mode2_enter_SOP: YES\r\n");
-#endif
fclose(vif);
return 0;
}
@@ -663,7 +1097,6 @@ int main(int argc, char **argv)
case 'o': /* -o or --out */
out = optarg;
break;
-
case -1:
break;