Skip to content

Commit

Permalink
USB-C: genVIF: Cleanup and add support to pick static data from input
Browse files Browse the repository at this point in the history
Removed few VIF properties which are being hardcoded
Updated the script to parse source VIF XML and add information to
the output
Added optional Kconfig option to configure custom source VIF XML path
Cleaned up the code

Signed-off-by: Madhurima Paruchuri <[email protected]>
  • Loading branch information
madhurimaparuchuri authored and nashif committed May 26, 2023
1 parent 8ea9fce commit a19d905
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 276 deletions.
41 changes: 38 additions & 3 deletions cmake/vif.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,49 @@
# Generates USB-C VIF policies in XML format from device tree.
set(gen_vif_script ${ZEPHYR_BASE}/scripts/generate_usb_vif/generate_vif.py)
set(dts_compatible usb-c-connector)
set(vif_xml ${PROJECT_BINARY_DIR}/vif.xml)
set(vif_xml vif.xml)
set(board_vif_xml ${BOARD}_${vif_xml})
set(vif_out ${PROJECT_BINARY_DIR}/${vif_xml})

set(cmd_gen_vif ${PYTHON_EXECUTABLE} ${gen_vif_script}
--edt-pickle ${EDT_PICKLE}
--compatible ${dts_compatible}
--vif-out ${vif_xml}
--board ${BOARD}
--vif-out ${vif_out}
)

if (CONFIG_GENVIF_INPUT_VIF_XML_PATH)
if (IS_ABSOLUTE ${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
if (EXISTS ${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
set(vif_source_xml ${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
endif ()
elseif (EXISTS ${APPLICATION_CONFIG_DIR}/${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
set(vif_source_xml ${APPLICATION_CONFIG_DIR}/${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
endif ()
else ()
if (EXISTS ${APPLICATION_CONFIG_DIR}/boards/${board_vif_xml})
set(vif_source_xml ${APPLICATION_CONFIG_DIR}/boards/${board_vif_xml})
elseif (EXISTS ${APPLICATION_CONFIG_DIR}/${vif_xml})
set(vif_source_xml ${APPLICATION_CONFIG_DIR}/${vif_xml})
elseif (EXISTS ${BOARD_DIR}/${vif_xml})
set(vif_source_xml ${BOARD_DIR}/${vif_xml})
endif ()
endif ()

if (DEFINED vif_source_xml)
list(APPEND cmd_gen_vif --vif-source-xml ${vif_source_xml})
else ()
if (CONFIG_GENVIF_INPUT_VIF_XML_PATH)
message(FATAL_ERROR "Incorrect VIF source XML file path. To fix specify"
" correct XML file path at 'CONFIG_GENVIF_INPUT_VIF_XML_PATH'.")
else ()
message(FATAL_ERROR "No VIF source XML file found. To fix, create"
" '${board_vif_xml}' in 'boards' directory of application"
" directory, or create '${vif_xml}' file in application"
" directory or board directory, or supply a custom XML VIF path"
" using 'CONFIG_GENVIF_INPUT_VIF_XML_PATH'.")
endif ()
endif ()

add_custom_command(
OUTPUT ${vif_xml}
DEPENDS ${EDT_PICKLE}
Expand Down
57 changes: 28 additions & 29 deletions dts/bindings/usb-c/usb-c-connector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ description: |
This is based on Linux, documentation:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/connector/usb-connector.yaml?h=v5.19&id=3d7cb6b04c3f3115719235cc6866b10326de34cd
Example:
USB-C connector attached to a STM32 UCPD typec port controller, which has
power delivery support and enables SINK.
vbus1: vbus {
compatible = "zephyr,usb-c-vbus-adc";
io-channels = <&adc2 8>;
output-ohms = <49900>;
full-ohms = <(330000 + 49900)>;
};
ports {
#address-cells = <1>;
#size-cells = <0>;
port1: usb-c-port@1 {
compatible = "usb-c-connector";
reg = <1>;
tcpc = <&ucpd1>;
vbus = <&vbus1>;
power-role = "SINK";
sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)
PDO_VAR(5000, 12000, 2000)>;
op-sink-microwatt = <10000000>;
};
};
compatible: "usb-c-connector"

include: base.yaml
Expand Down Expand Up @@ -136,32 +164,3 @@ properties:
description: |
Minimum power, in microwatts, needed by the sink. A Capability
Mismatch is sent to the Source if the power can't be met.
# EXAMPLE:
#
# USB-C connector attached to a STM32 UCPD typec port controller, which has
# power delivery support and enables SINK.
#
# #include <dt-bindings/usb-c/pd.h>
#
# vbus1: vbus {
# compatible = "zephyr,usb-c-vbus-adc";
# io-channels = <&adc2 8>;
# output-ohms = <49900>;
# full-ohms = <(330000 + 49900)>;
# };
#
# ports {
# #address-cells = <1>;
# #size-cells = <0>;
# port1: usb-c-port@1 {
# compatible = "usb-c-connector";
# reg = <1>;
# tcpc = <&ucpd1>;
# vbus = <&vbus1>;
# power-role = "SINK";
# sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)
# PDO_VAR(5000, 12000, 2000)>;
# op-sink-microwatt = <10000000>;
# };
# };
9 changes: 9 additions & 0 deletions samples/subsys/usb_c/sink/vif.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<vif:VIF xmlns:vif="http://usb.org/VendorInfoFile.xsd">
<vif:Vendor_Name>Zephyr</vif:Vendor_Name>
<vif:Model_Part_Number>Sink</vif:Model_Part_Number>
<vif:Product_Revision>1</vif:Product_Revision>
<vif:TID>0</vif:TID>
<vif:VIF_Product_Type value="0">Port Product</vif:VIF_Product_Type>
<vif:Certification_Type value="0">End Product</vif:Certification_Type>
</vif:VIF>
97 changes: 0 additions & 97 deletions scripts/generate_usb_vif/constants.py

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/generate_usb_vif/constants/dt_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains device tree constants defined to be used by generate_vif.py"""

SINK_PDOS = "sink-pdos"
PD_DISABLE = "pd-disable"
POWER_ROLE = "power-role"

DT_VIF_ELEMENTS = {
SINK_PDOS: "SnkPdoList",
}
33 changes: 33 additions & 0 deletions scripts/generate_usb_vif/constants/other_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains generic constants defined to be used by generate_vif.py"""

NAME = "name"
VALUE = "value"
TEXT = "text"
ATTRIBUTES = "attributes"
CHILD = "child"
TRUE = "true"
FALSE = "false"

PD_PORT_TYPE_VALUES = {
"sink": ("0", "Consumer Only"),
"source": ("3", "Provider Only"),
"dual": ("4", "DRP"),
}

TYPE_C_STATE_MACHINE_VALUES = {
"sink": ("1", "SNK"),
"source": ("0", "SRC"),
"dual": ("2", "DRP"),
}

FR_SWAP_REQD_TYPE_C_CURRENT_AS_INITIAL_SOURCE_VALUES = {
0: "FR_Swap not supported",
1: "Default USB Power",
2: "1.5A @ 5V",
3: "3A @ 5V",
}
19 changes: 19 additions & 0 deletions scripts/generate_usb_vif/constants/pdo_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains PDO constants defined to be used by generate_vif.py"""

# PDO
PDO_TYPE_FIXED = 0
PDO_TYPE_BATTERY = 1
PDO_TYPE_VARIABLE = 2
PDO_TYPE_AUGUMENTED = 3

PDO_TYPES = {
PDO_TYPE_FIXED: "Fixed",
PDO_TYPE_BATTERY: "Battery",
PDO_TYPE_VARIABLE: "Variable",
PDO_TYPE_AUGUMENTED: "Augmented",
}
29 changes: 29 additions & 0 deletions scripts/generate_usb_vif/constants/vif_element_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains VIF element constants defined to be used by generate_vif.py"""

VENDOR_NAME = "Vendor_Name"
MODEL_PART_NUMBER = "Model_Part_Number"
PRODUCT_REVISION = "Product_Revision"
TID = "TID"
VIF_PRODUCT_TYPE = "VIF_Product_Type"
CERTIFICATION_TYPE = "Certification_Type"
COMPONENT = "Component"

USB_PD_SUPPORT = "USB_PD_Support"
PD_PORT_TYPE = "PD_Port_Type"
TYPE_C_STATE_MACHINE = "Type_C_State_Machine"
SINK_PDO = "SnkPDO"
SINK_PDO_SUPPLY_TYPE = "Snk_PDO_Supply_Type"
SINK_PDO_VOLTAGE = "Snk_PDO_Voltage"
SINK_PDO_OP_CURRENT = "Snk_PDO_Op_Current"
SINK_PDO_OP_POWER = "Snk_PDO_Op_Power"
SINK_PDO_MIN_VOLTAGE = "Snk_PDO_Min_Voltage"
SINK_PDO_MAX_VOLTAGE = "Snk_PDO_Max_Voltage"
PD_POWER_AS_SINK = "PD_Power_As_Sink"
HIGHER_CAPABILITY_SET = "Higher_Capability_Set"
FR_SWAP_REQD_TYPE_C_CURRENT_AS_INITIAL_SOURCE = "FR_Swap_Reqd_Type_C_Current_As_Initial_Source"
NUM_SNK_PDOS = "Num_Snk_PDOs"
37 changes: 37 additions & 0 deletions scripts/generate_usb_vif/constants/xml_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

# Copyright (c) 2022 The Chromium OS Authors
# SPDX-License-Identifier: Apache-2.0

"""This file contains XML constants defined to be used by generate_vif.py"""

from constants import other_constants
from constants import vif_element_constants

XML_ENCODING = "utf-8"
XML_ELEMENT_NAME_PREFIX = "vif"
XML_ROOT_ELEMENT_NAME = "VIF"
XML_VIF_NAMESPACE = "http://usb.org/VendorInfoFile.xsd"
XML_NAMESPACE_ATTRIBUTES = {
"xmlns:vif": XML_VIF_NAMESPACE,
}

VIF_SPEC_ELEMENTS = {
"VIF_Specification": {
other_constants.TEXT: "3.19",
},
"VIF_App": {
other_constants.CHILD: {
"Description": {
other_constants.TEXT: "This VIF XML file is generated by the Zephyr GenVIF script",
}
}
},
}

VIF_SPEC_ELEMENTS_FROM_SOURCE_XML = {vif_element_constants.VENDOR_NAME,
vif_element_constants.MODEL_PART_NUMBER,
vif_element_constants.PRODUCT_REVISION,
vif_element_constants.TID,
vif_element_constants.VIF_PRODUCT_TYPE,
vif_element_constants.CERTIFICATION_TYPE, }
Loading

0 comments on commit a19d905

Please sign in to comment.