Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb-c: Add sink VIF policies to device tree, update the GenVIF script #52759

Merged
merged 1 commit into from
May 26, 2023

Conversation

madhurimaparuchuri
Copy link
Contributor

A VIF node is added to device tree to hold VIF specifications and USB sink VIF policies are added to usb-c-connector node as properties.

The GenVIF script is updated to start parsing from VIF node.

The exisiting USB-C Sink sample project is updated to include examples of new changes in device tree.

The XML output is validated against schema
https://compliance.usb.org/cv/VendorInfoFile/Schemas/Current/VendorInfoFile.xsd Changes to XML namespaces is done according to validation

Signed-off-by: Madhurima Paruchuri [email protected]

nordicjm
nordicjm previously approved these changes Dec 5, 2022
dts/bindings/usb-c/usb-c-connector.yaml Outdated Show resolved Hide resolved
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me this seems like a misuse of devicetree, but I will let @mbolivar-nordic and @galak decide on this.

Waiting for their review comments.

Comment on lines 5 to 27
A VIF node is a root element that describes the Qualifying Product in VIF
specification. It contains introductory material followed by an optional
product-level field element, zero or more Components, and zero or more
Optional Content elements.
This is based on VIF XML file schema in:
https://compliance.usb.org/cv/VendorInfoFile/Schemas/Current/VendorInfoFile.xsd

compatible: "vif"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand why vif should be a node.

Afaiu VIF is a Vendor Information file which describes the usb device, and creation of a vif file based on dts was introduced here: #51660

Starting to add a vif node in devicetree seems to be a misuse of the devicetree to me. but I would like @mbolivar-nordic or @galak to review and decide on this.

Copy link
Contributor Author

@madhurimaparuchuri madhurimaparuchuri Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some high level specifications required for VIF, specific to product but applicable to all ports. I see USB-C DT nodes are per port, hence added this node, which is referring to the ports as child(i.e, usb-c connector nodes). And the presence of VIF node in a project is optional with more than 95% of properties being optional within.

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madhurimaparuchuri :

Without commenting on if this is appropriate to include in devicetree (I am no longer maintaining the devicetree bindings so that I can focus on other tasks), I will say that choosing "vif" for the compatible is pretty clear namespace pollution. The namespace of compatible property values is shared across all hardware in the world, so a three-letter acronym had better be for something incredibly general purpose, which this definitely is not.

Please choose a better, more descriptive name, and make sure to expand the acronym (I guess it's "vendor info file") in the description field in the binding.

In general, please remember that you are the VIF domain expert here, but this binding lives in a larger world where there's lots of other hardware and people who will read your documentation without your domain knowledge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galak to review and decide on this

This is the decision maker on whether to put this in DT, since he is overall maintainer for the bindings.

I now only co-maintain the DT infrastructure and API.

Copy link
Collaborator

@tejlmand tejlmand Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now only co-maintain the DT infrastructure and API.

I know, but given your experience then your feedback serves as very valid input (at least better input than my feedback) on whether this approach looks appropriate for bindings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to agree that the devicetree should not directly represent the VIF fields for a few reasons:

  1. The USB Implementers' Forum revs the VIF format somewhat regularly to keep up with new USB features. Sometimes, existing fields change name or format without changing the underlying meaning. Keeping up with these changes in the devicetree would involve changing a public-facing (sort of) API in the devicetree bindings.
  2. Many of the fields will be unknowable to the Zephyr build system, and which ones are knowable depends on the hardware. To produce a valid VIF for, say, compliance testing, a developer would need to add in additional fields from some other source. If I were adding those fields, I'd probably want to use a format other than devicetree.
  3. The bindings need to describe the devicetree properties, so they need to be verbose like the spec or refer to the spec or summarize the spec at the risk of vagueness or inaccuracy. I'd rather avoid the issue.
  4. The VIF contains some parallel structure to the existing devicetree, e.g. different pieces for different ports. I'd prefer not to replicate that and risk them being inconsistent.

I'd prefer that the nodes for the port and individual port components contain properties for VIF-relevant information that is determined by the hardware, and the VIF generator would parse those properties (probably among other data sources) while constructing the VIF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I avoided adding elements to device tree. I am reading properties that are already there in device tree and generating the VIF, not adding any properties or nodes in this revision. The information that is there in VIF node in earlier revisions is being read form an XML file (manually added) in project folder if it's present (overriding the output VIF file).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejlmand
Could you review the new revision and let me know if any changes are required in this PR

gmarull
gmarull previously requested changes Dec 5, 2022
Comment on lines 259 to 289
# 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";
# num-snk-pdos= <2>;
# sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_USB_COMM)
# PDO_VAR(5000, 12000, 2000)>;
# op-sink-microwatt = <10000000>;
# fr-swap-reqd-type-c-current-as-initial-source= <0>;
# vconn-swap-to-off-supported;
# };
# };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plase move example to bindings docs at the top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmarull
Could you review the new revision and let me know if any changes are required in this PR


tid:
type: string
required: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all required false are redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision of this PR


vif-product-type:
type: int
enum: [0, 1, 2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to make DT files more readable, I'd suggest providing definitions for such enums. See include/zephyr/dt-bindings for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision of this PR

Comment on lines 95 to 112
# EXAMPLE:
#
#
# vif {
# address-cells = <1>;
# size-cells = <0>;
# usbcvif1: usbcvif@1 {
# compatible = "vif";
# reg = <1>;
# vendor-name = "Zephyr";
# model-part-number = "b_g474e_dpow1";
# product-revision= "1";
# tid= "0";
# vif-product-type= <0>;
# certification-type= <0>;
# component =<&port1>;
# };
# };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision of this PR

Comment on lines 30 to 32
num-snk-pdos= <1>;
sink-pdos = <PDO_FIXED(5000, 100, 0)>;
fr-swap-reqd-type-c-current-as-initial-source= <0>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space before =, please revisit formatting on all files.

Copy link
Contributor Author

@madhurimaparuchuri madhurimaparuchuri Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision of this PR

compatible = "vif";
reg = <1>;
vendor-name = "Zephyr";
model-part-number = "b_g474e_dpow1";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's standard model property. Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model-part-number seemed to be different from model and more specific to USB-C component. Following is it's definition : "To be provided by the Vendor. This field should match what appears in the USB-IF Product Registration form. If the Qualifying Product has a Model Name entry in USB4 DROM, then this field should be identical to that entry. The USB-IF uses this field and /VIF/Product_Revision to generate the product name in the USB Integrator’s List"

cmake/vif.cmake Outdated
)

if(CONFIG_GENVIF_INPUT_VIF_XML_PATH)
if (EXISTS ${APPLICATION_SOURCE_DIR}/${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still uses APPLICATION_SOURCE_DIR

cmake/vif.cmake Outdated
)

if(CONFIG_GENVIF_INPUT_VIF_XML_PATH)
if (EXISTS ${APPLICATION_SOURCE_DIR}/${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
set(vif_source_xml ${APPLICATION_SOURCE_DIR}/${CONFIG_GENVIF_INPUT_VIF_XML_PATH})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you missed this part:

The CMake code can then be simplified.

Code stilkl suffers from the fact that if user makes a typo, like oof.xml instead of the correct foo.xml (which is the file existing on disk), then vif_source_xml is unset and no file argument is passed to python script.

Hence no build failure and user may not notice a mistake was made.

alevkoy
alevkoy previously approved these changes Mar 27, 2023

xml_root = get_root()
source_xml_root = None
if args.vif_source_xml:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this arg is required, do you need to check this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's not required, removing in new revision

scripts/generate_usb_vif/generate_vif.py Show resolved Hide resolved
@madhurimaparuchuri
Copy link
Contributor Author

I was trying to push upstream rebase first and commit(my changes) next. As part of it I made soft reset of last commit, when I pushed it, this pull request is closed. I am trying to reopen it. Meanwhile this commit has latest changes which I was trying to push here to resolve comments : main...madhurimaparuchuri:zephyr:gvif

@madhurimaparuchuri
Copy link
Contributor Author

madhurimaparuchuri commented Apr 3, 2023

The related commit (Updated version) is added back to this PR, but the commit looks like a whole new change now. Sorry for messing the PR, it's unintentional.

Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix ensure old comments are addressed.

cmake/vif.cmake Outdated
Comment on lines 16 to 20
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})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this comment a month ago which is still not addressed: #52759 (comment)

The CMake code can then be simplified.

Code stilkl suffers from the fact that if user makes a typo, like oof.xml instead of the correct foo.xml (which is the file existing on disk), then vif_source_xml is unset and no file argument is passed to python script.

Hence no build failure and user may not notice a mistake was made.

Please fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build breaks if there is a typo in the file path configured at present

As discussed offline, I added the error messages in CMAKE to say the build failed due to file not found in new revision

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you added an extra check below, accepted.

Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks better, some minor nits.

Seems only a single APPLICATION_SOURCE_DIR was updated to APPLICATION_CONFIG_DIR wrt. vif xml file.
That should of course be all occurrences in order to be consistent with general conf file behavior.

cmake/vif.cmake Outdated
Comment on lines 25 to 28
if (EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}_${vif_xml})
set(vif_source_xml ${APPLICATION_SOURCE_DIR}/boards/${BOARD}_${vif_xml})
elseif (EXISTS ${APPLICATION_SOURCE_DIR}/${vif_xml})
set(vif_source_xml ${APPLICATION_SOURCE_DIR}/${vif_xml})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those should also be updated to use APPLICATION_CONFIG_DIR instead of APPLICATION_CONFIG_DIR to be consistent with other configuration files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision

cmake/vif.cmake Outdated
if(CONFIG_GENVIF_INPUT_VIF_XML_PATH)
message(FATAL_ERROR "Incorrect VIF source XML file path")
else()
message(FATAL_ERROR "No VIF source XML file found")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please some extra information on how to fix this situation.
Could be something along:

To fix, create 'vif.xml' in the application directory or specify a vif.xml using 'CONFIG_GENVIF_INPUT_VIF_XML_PATH'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the changes in new revision, Thank you

cmake/vif.cmake Outdated
Comment on lines 16 to 20
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})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you added an extra check below, accepted.

@madhurimaparuchuri madhurimaparuchuri force-pushed the gvif branch 3 times, most recently from bcefad9 to 5c7165d Compare May 23, 2023 12:52
cmake/vif.cmake Outdated
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'.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please line wrap.

CMake allows multiple strings with message() and will concatenate those when printing.

Suggested change
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'.")
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'."
)

cmake/vif.cmake Outdated
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'.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also line wrap here.

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]>
@fabiobaltieri
Copy link
Member

@gmarull could you revisit this?

@gmarull gmarull dismissed their stale review May 26, 2023 14:06

no time to review, will leave to others

@nashif nashif merged commit a19d905 into zephyrproject-rtos:main May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: Devicetree Binding PR modifies or adds a Device Tree binding area: USB Universal Serial Bus area: USB-C
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants