USB OTG cannot achieve direct switching from device to host

SDK:R36.4.4

We use the TYPE-A port as OTG, and the following phenomena occur:
Step 1:Execute the command:sudo bash -c ‘echo host > /sys/class/usb_role/usb2-0-role-switch/role’; HOST works.
Step 2:Execute the command:sudo bash -c ‘echo device > /sys/class/usb_role/usb2-0-role-switch/role’; DEVICE works.
Step 3:Execute the command:sudo bash -c ‘echo host > /sys/class/usb_role/usb2-0-role-switch/role’; HOST does not work.
Step 4:Execute the command:sudo bash -c ‘echo none > /sys/class/usb_role/usb2-0-role-switch/role’
Step 5:Execute the command:sudo bash -c ‘echo host > /sys/class/usb_role/usb2-0-role-switch/role’; HOST works.
To summarize, when switching from DEVICE to HOST, there must be a NONE state in between.
We need to switch directly from DEVICE to HOST.

DT:

*** Please note that this reply is generated by LLM automatically ***

Based on the provided context, I will attempt to address the issue you are facing with the Jetson Orin NX SDKR3644.

The problem you are experiencing is that when switching from DEVICE to HOST mode, you need to go through a NONE state in between, and you want to switch directly from DEVICE to HOST.

From the context, it is clear that the OTG port switching between the host driver (xHCI) and device driver (xUDC) roles are controlled by the Cypress Type-C controller and the ucsi_ccg driver in the Jetson AGX Orin Developer Kit.

The extcon-cables property is used to detect the USB VBUS pin, and when the extcon cable state is 1, the OTG port transitions to device mode. However, there is no direct mention of how to switch directly from DEVICE to HOST mode without going through the NONE state.

Comparing the provided steps, it seems that the issue is related to the sysclass/usb/role/usb2.0/roleswitch interface. When you execute the command echo host > sys/class/usb/role/usb2.0/roleswitch after being in DEVICE mode, it doesn’t work. However, if you switch to NONE mode first and then to HOST mode, it works.

One possible solution could be to modify the ucsi_ccg driver to allow direct switching from DEVICE to HOST mode without going through the NONE state. However, this would require modifying the driver code and may not be a straightforward solution.

Another possible solution could be to use a script or a program to automate the switching process, which would involve switching to NONE mode and then to HOST mode. This would not be a direct switch, but it would achieve the desired result.

Unfortunately, without more information about the ucsi_ccg driver and the sysclass/usb/role/usb2.0/roleswitch interface, it is difficult to provide a more detailed solution.

In summary, the issue you are facing is related to the OTG port switching mechanism, and the current implementation requires going through a NONE state when switching from DEVICE to HOST mode. Modifying the ucsi_ccg driver or using a script to automate the switching process may be possible solutions, but more information is needed to provide a more detailed answer.

*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***

Type A port by default could not work as OTG port from hardware aspect.

There is no proper device tree for such design.

The device tree is correct.

We need to switch directly from DEVICE to HOST via user space

There is no support from such case. The role switch follows the 3 roles case.