USB OTG functionality in jetson-tk1

we want to use USB OTG functionality on jetson-tk1 board. we are using L4T 21.4 release.

we can test both host and gadget mode but mode switch(host to gadget or gadget to host) does not happen automatically based on type of cable connected. we need to enable/disable host/gadget mode by software means.
why OTG functionality does not work based on type of cable connected ?

we have noticed that to use gadget mode on OTG port, following commands manually needs to be fired

echo 0 > /sys/devices/platform/tegra-otg/enable_host
echo 1 > /sys/devices/platform/tegra-otg/enable_device
modprobe g_ether
echo connect > /sys/devices/platform/tegra-udc.0/udc/tegra-udc.0/soft_connect

and to use host mode, following commands need to be fired
echo 1 > /sys/devices/platform/tegra-otg/enable_host
echo 0 > /sys/devices/platform/tegra-otg/enable_device

thanks in advance

As far as I know there hasn’t been any attempt to write an OTG driver on Jetson (other than what is embedded when put in recovery mode). Change of mode via cable requires monitoring registers on the USB2 controller (see section 19.13.1.31 of the TRM) and then setting up for the specific device which would use the port via USB.

The popular smart phones and music devices out there tend to use OTG to become a mass storage device, and many people associate OTG as mass storage, but the reality is that OTG can become any type of device USB works with. The question is always what type of device do you want the port to become when in device mode? And do you have an existing, running driver for that device, even if not currently linked to USB?

we have our own custom gadget driver(similar to g_serial).

our use case if USB pen drive is connected to jetson otg port then jetson should switch to USB host mode and when jetson is connected to PC then it should switch to gadget mode.

right now we are using g_ether driver for gadget mode. we are able to use jetson board OTG port in both Host and gadget mode but it requires software intervention (i.e. change of mode via sysfs entry enable_host/enable_device).

our use case is based on cable connected on OTG port, kernel should automatically switch mode and this is how real OTG works.