JTX1_USB_as device

Hi
IN JTX1
How to configure USB port 0 as DEVICE ?
can I use one USB port Port 0 as 3.0 DEVICE and USB port 2 also as device, Port 2 does not have ID pin how to configure it as device by default?

Only the micro-USB connector can be used as device.

There were some changes from manual host/device mode selection for the JTX1 versus JTK1 which takes away the “enable_otg” file in “/sys/devices/platform/tegra-otg”. If you connect a micro-A connector and monitor “dmesg | tail” you’ll see an automatic change from suspend mode to host mode…if instead you unplug a micro-A, it goes from host mode to suspend mode. A type micro-B will give you a message about “extcon-gpio-states 1.extcon: Cable state 0” (connecting a micro-B would load the proper device mode driver if one were configured).

For device mode to do something you have to configure a driver, there is no device mode driver except in recovery mode when powering up with the recovery mode button held down. There is no need to configure as device “by default”, this is what the OTG connector does. If you are interested in writing something for device mode the gadget interface is probably the place to start. See:
[url]https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt[/url]
[url]http://www.linux-usb.org/gadget/[/url]

Capture from TRM:
“There are a total of 4 USB2 ports and 4 USB3 ports, and 1 HSIC port. Of the eight ports, one can be USB3.0 OTG or USB2.0 OTG while the rest are host mode only ports.”

Only one USB Super speed port can used as device mode. But One USB Super speed port combine one USB High speed port as device mode is supported.

The USB port 2 you mentioned is USB3 or USB2 port? Two USB3 port as device mode is not supported.

The ID is not need if you want to force the USB port under device mode.

To config JTX1 USB 3.0 port as device mode:
1> Modify the kernel following attached patch.
2> Enable Android Gadget:
echo 0 > /sys/class/android_usb/android0/enable
echo 0955 > /sys/class/android_usb/android0/idVendor
echo 7E00 > /sys/class/android_usb/android0/idProduct
echo mass_storage > /sys/class/android_usb/android0/functions
echo 0 > /sys/class/android_usb/android0/bDeviceClass
dd if=/dev/zero of=/home/ubuntu/msc.ext4.img bs=1M count=1k
mkfs.ext4 /home/ubuntu/msc.ext4.img
echo /home/ubuntu/msc.ext4.img > /sys/class/android_usb/android0/f_mass_storage/lun/file
echo 1 > /sys/class/android_usb/android0/enable
3> Plug in USB3.0 cable(Swap the TX/RX signal for normal USB3.0 A to A extension cable)
4> Plug in USB2.0 cable(The system need VBUS detect to identify a USB3.0 host connected)

The host will detect a storage device which emulated from JTX1

0001-jetson-tx1-xudc-with-usb2p0-ss1.patch.txt (2.3 KB)

Hi edli1983,
I also want to try USB 3.0 device on R24.2.1 version.
I follow the patch to configure kernel and device tree.

After I execute step 1~3, I cannot see any new device detected on my USB 3.0 host.

Below is TX1 kernel logs:
[ 347.333147] tegra-xudc tegra-xudc: Exit device controller ELPG done
[ 347.333262] tegra_xudc_runtime_suspend called
[ 347.333340] tegra-xudc tegra-xudc: Enter device controller ELPG
[ 347.333644] tegra-xudc tegra-xudc: Enter device controller ELPG done
[ 377.822468] tegra_xudc_runtime_resume called
[ 377.822586] tegra-xudc tegra-xudc: Exit device controller ELPG
[ 377.823680] tegra-xudc tegra-xudc: nvudc_resume_state():2585: Directing link to U0
[ 377.823786] tegra-xudc tegra-xudc: Exit device controller ELPG done
[ 377.823885] tegra_xudc_runtime_suspend called
[ 377.823956] tegra-xudc tegra-xudc: Enter device controller ELPG
[ 377.824248] tegra-xudc tegra-xudc: Enter device controller ELPG done
[ 418.436241] tegra_xudc_runtime_resume called

But if I add VBUS_DET, my host PC can detect a high spped USB mass storage.
Below is TX1 kernel logs:

[ 4672.181468] extcon-gpio-states 1.extcon: Cable state 1
[ 4672.181596] tegra-xotg xotg.26: extcon_id_notifications():222: USB_ID pin floating
[ 4672.181684] tegra-xhci tegra-xhci: received otg event 6
[ 4672.182461] tegra_xudc_runtime_resume called
[ 4672.182551] tegra-xudc tegra-xudc: Exit device controller ELPG
[ 4672.183702] tegra-xudc tegra-xudc: nvudc_resume_state():2585: Directing link to U0
[ 4672.183807] tegra-xudc tegra-xudc: Exit device controller ELPG done
[ 4672.183907] tegra-xudc tegra-xudc: vbus_detected():534: vbus_detected: vbus on detected
[ 4672.184124] tegra-xudc tegra-xudc: IRQ event for host controller as well
[ 4672.184241] tegra-xhci tegra-xhci: received otg event 0
[ 4672.184371] tegra-xotg xotg.26: xotg_work():876: state b_idle → b_peripheral
[ 4672.391034] extcon-gpio-states 1.extcon: Cable state 1
[ 4672.400306] android_work: did not send uevent (0 0 (null))
[ 4672.421289] android_work: sent uevent USB_STATE=CONNECTED

Could you give me some ideas to make USB 3.0 device mode works?

Hi yenyu,
Have you got USB 3.0(super speed) otg works? Or it still runs at USB 2.0(high speed)

Hi,

For the answer given by edli1983, can anyone help me with the steps to modify Linux kernel with the patch as I’m a begineer to this. Is there some tutorial or any other thread which explains the steps in details for a practical perspective ?

A patch file encodes the differences between two folders in their subfolders and files.
It is produced by diff command.Type

man diff

to get information about how to use it.
In a few words, if you look at the patch file with a text editor, there is context and lines to check it applies on the expected file, the lines beginning by ‘-’ are the old ones to be removed, and lines beginning by ‘+’ are to be added (this format assumes the patch was produced by diff using -u option).

Then it allows to apply the same modification to another unpatched folder with patch command. See also:

man patch

I have a similar issue. I have added all the proper defconfig for android_g gadget device support over otg but my kernel/dtb does not create the /sys/class/android_usb/ directory. What could cause no /sys/class directory even being created?

CONFIG_USB_OTG=y
# CONFIG_USB_OTG_WHITELIST is not set
CONFIG_USB_XHCI_HCD=y
CONFIG_TEGRA_XUSB_PLATFORM=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_ACM=y
CONFIG_USB_STORAGE=y
CONFIG_USB_NV_SHIELD_LED=y
CONFIG_USB_NV_SHIELD_PDA=y
CONFIG_USB_OTG_WAKELOCK=y
CONFIG_USB_TEGRA_OTG=y
CONFIG_USB_TEGRA_XOTG=y
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_VBUS_DRAW=500
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=4
CONFIG_USB_TEGRA=y
CONFIG_USB_TEGRA_XUDC=y
CONFIG_PLAT_FPGA_T210=y
CONFIG_USB_G_ANDROID=y
CONFIG_USB_TEGRA_CD=y
15.714125] init: write_file: Unable to open '/sys/block/mmcblk1/queue/read_ahead_kb': No such file or directory
[   15.724732] init: write_file: Unable to open '/sys/class/android_usb/android0/iSerial': No such file or directory
[   15.735112] init: write_file: Unable to open '/sys/class/android_usb/android0/iManufacturer': No such file or directory
[   15.745984] init: write_file: Unable to open '/sys/class/android_usb/android0/iProduct': No such file or directory
[   15.756427] init: write_file: Unable to open '/sys/class/android_usb/android0/f_rndis/manufacturer': No such file or directory
[   15.767949] init: write_file: Unable to open '/sys/class/android_usb/android0/f_rndis/vendorID': No such file or directory
[   15.779049] init: write_file: Unable to open '/sys/class/android_usb/android0/f_rndis/wceis': No such file or directory

Do you have:

CONFIG_SYSFS=y

There are basically different drivers or options to enable different branches of “/sys”. CONFIG_SYSFS is the parent. You could look for others named after “SYSFS”, e.g., this is an example:

CONFIG_TEGRA_ISOMGR_SYSFS=y

If there is a driver which would be reflected in existence of a “/sys” subdirectory, but the driver fails to load, then that part of “/sys” would also disappear. I don’t know the particular option related to “/sys/class”.

Thanks for the reply linuxdev. Yes I do have sysfs enabled

CONFIG_SYSFS=y
CONFIG_TMPFS=y
CONFIG_TEGRA_ISOMGR=y
CONFIG_TEGRA_ISOMGR_POOL_KB_PER_SEC=0
CONFIG_TEGRA_ISOMGR_SYSFS=y
CONFIG_TEGRA_ISOMGR_MAX_ISO_BW_QUIRK=y

I can see all other class devices but no tegra-otg or android_usb.

I applied the patch above and see no difference.

Does this have anything to do with --odmdata 0x84000 setting USB port assignment to 2.0 and 3.0 as was TK1?

Here is my default otg settings in DTB: I am sure there is a lane assignment for OTG USB 2.0 on the only usb otg port that has the wrong dts setting:

extcon {
		extcon@0 {
			status = "disabled";
		};
	};

	udc@7d000000 {
		nvidia,port-otg;
		nvidia,charging-supported;
		#extcon-cells = <1>;
		status = "okay";
	};

        otg@7d000000 {
		#extcon-cells = <1>;
		status = "okay";
	};

	xusb_pad_ctl: xusb_padctl { /* Put common control config here */
		nvidia,ss_portmap = <0x21>;
		nvidia,lane_owner = <0xff56>; /* Use 0xF to disable lane assign */
		nvidia,lane-map = <0x14>;
		nvidia,enable-sata-port;
		status = "okay";
	};

	xusb@70090000 {
		/* nvidia,uses_external_pmic;
		/* nvidia,gpio_controls_muxed_ss_lanes; */
		nvidia,gpio_ss1_sata = <0>;
		nvidia,ulpicap = <0>; /* No ulpi support. can we remove */
		nvidia,portmap = <0x0e03>;
		nvidia,common_padctl = <&xusb_pad_ctl>;
		status = "okay";
	};

	xudc@700d0000 {
		nvidia,common_padctl = <&xusb_pad_ctl>;
		nvidia,portmap = <0x0108>;
		#extcon-cells = <1>;
		status = "disabled";
	};

	xotg {
		#extcon-cells = <1>;
		nvidia,common_padctl = <&xusb_pad_ctl>;
		status = "disabled";
	};

I dont even see a directory in /sys/devices/platform for tegra-otg

tegra-apbdma
tegra-camera-platform.45
tegra-carveouts.23
tegra-fuse
tegra-sata.0
tegra-supply-tests.35
tegra-xhci

in log:
extcon-gpio-states 1.extcon: Cable state 1

I also see this with otg wakelock enabled:

its the only dmesg log I get with default defconfig and default dts.

otg_wakelock_init: No USB transceiver found

Hi, edli1983

I’m trying to enable USB 3.0 and OTG for a webcam device. I made similar changes as you mentioned below except android_g_gadget. I enabled module of g_webcam. However after step 3 and 4 I cannot change tx1 to device mode automatically, when I plug in usb 2.0 cable, I see below from dmesg
[ +0.000106] tegra-xhci tegra-xhci: received otg event 6
[ +0.000131] tegra-xudc tegra-xudc: extcon_notifications():773: device is not ready, ignore this event
if I try to load g_webcam manually I got
[Apr28 14:51] udc tegra-xudc: registering UDC driver [g_webcam]
[ +0.000042] g_webcam gadget: adding config #1 ‘Video’/ffffffbffcfde5a0
[ +0.000020] g_webcam gadget: adding ‘uvc’/ffffffc0de5bb010 to config ‘Video’/ffffffbffcfde5a0
[ +0.001208] g_webcam gadget: uvc_function_bind
[ +0.000020] g_webcam gadget: Unable to allocate control EP
[ +0.000019] g_webcam gadget: adding ‘uvc’/ffffffc0de5bb010 → -22
[ +0.000018] g_webcam gadget: added config ‘Video’/1 → -22
[ +0.000032] g_webcam tegra-xudc: failed to start g_webcam: -22

Do you know if I need to manually switch USB 3 to device mode or some other steps I’m missing?

thanks

This is sort of guessing, but make sure you have “CONFIG_USB_G_ANDROID”.

Thanks for the suggestions. Yes, I intend to create a webcam device so left out the config_usb_g_android. If I put that in then host can detect a mass storage device. I’ll try to see how I can do the same for g_webcam.

turns out the g_webcam in kernel 3.10.96 doesn’t support super speed usb. Really need to make 4.4 for tx1 now

hi edli1983,
I follow https://devtalk.nvidia.com/default/topic/952472/jetson-tx1/jtx1_usb_as-device/post/4937794/#4937794
and when I
3> Plug in USB3.0 cable(Host PC USB3 port and TX1 USB3 port(name USB1))
4> Plug in USB2.0 cable(Host PC USB3 port and TX1 USB3 port(name USB1))
=> Host no detect anything.

but when I
4> Plug in USB2.0 cable(Host PC USB3/USB2 port and TX1 USB2 port(name USB0 - micro USB))
=> Host detect a “Linux File-CD Gadget USB Device” and I am getting the
“USB 3.0 This device can perform faster. This USB Mass Storage Device can transfer information faster if you connect it to a Super-Speed USB 3.0 port” message.

Did the result was normal for this test?

Best regards,

Hi FoxK,
The correct steps should be
3> Plug in USB3.0 cable(Host PC one USB3 port and TX1 USB3 port(name USB1))
4> Plug in USB2.0 cable(Host PC another USB3/USB2 port and TX1 USB2 port(name USB0 - micro USB))
Host PC and TX1 are connected with two cables.

And you should see the mass_storage present on Host PC.