How to set usb3.0 as device mode in orin nx

I want to use the type-c interface in custom carrier boart as the device mode, In this way, i can through pc get orin nx’s data. now i can use micro usb into device mode, and i want to know, whether i can set type-c who support usb3.0 mode into deivce mode.
in custom carrier boart have 3 type-c interface, usb3-0 ~ usb3-2.

xusb_padctl: xusb_padctl@3520000 {
		status = "okay";
		pads {
			usb2 {
				lanes {
					usb2-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-2 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
			usb3 {
				lanes {
					usb3-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-2 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
		};

		ports {
			usb2-0 {
				mode = "peripheral";
				status = "okay";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-b-connector", "gpio-usb-b-connector";
 					label = "micro-USB";
 					type = "micro";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-1 {
				mode = "host";
                                vbus-supply = <&p3509_vdd_av10_hub>;
				status = "okay";
			};
			usb2-2 {/* Goes to M2.E */
				mode = "host";
                                vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb3-0 {
				status = "okay";
				nvidia,usb2-companion = <1>;
			};
			usb3-1 {
				nvidia,usb2-companion = <1>;
				status = "okay";
			};
			usb3-2 {
				nvidia,usb2-companion = <1>;
				status = "okay";
			};
		};
	};

	tegra_xudc: xudc@3550000 {
		status = "okay";
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-0}>;
		phy-names = "usb2-0";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

	tegra_xhci: xhci@3610000 {
		status = "okay";
		nvidia,use-typec-switch;
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-1}>,
			<&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-2}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-0}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-1}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-2}>;
		phy-names = "usb2-1", "usb2-2", "usb3-0","usb3-1", "usb3-2";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

I have gained some information on other topics, and I have done similar things, but unfortunately, it still doesn’t work.

xusb_padctl: xusb_padctl@3520000 {
		status = "okay";
		pads {
			usb2 {
				lanes {
					usb2-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-2 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
			usb3 {
				lanes {
					usb3-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-2 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
		};

		ports {
			usb2-0 {
				mode = "peripheral";
				status = "okay";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-b-connector", "gpio-usb-b-connector";
 					label = "micro-USB";
 					type = "micro";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-1 {
				mode = "host";
                                vbus-supply = <&p3509_vdd_av10_hub>;
				status = "okay";
			};
			usb2-2 {/* Goes to M2.E */
				mode = "host";
                                vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb3-0 {
				status = "okay";
				dr_mode = "peripheral";
				nvidia,usb2-companion = <1>;
			};
			usb3-1 {
				nvidia,usb2-companion = <1>;
				status = "okay";
			};
			usb3-2 {
				nvidia,usb2-companion = <1>;
				status = "okay";
			};
		};
	};

	tegra_xudc: xudc@3550000 {
		status = "okay";
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-0}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-0}>;
		phy-names = "usb2-0", "usb3-0";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

	tegra_xhci: xhci@3610000 {
		status = "okay";
		nvidia,use-typec-switch;
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-1}>,
			<&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-2}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-1}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-2}>;
		phy-names = "usb2-1", "usb2-2", "usb3-1", "usb3-2";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

What kind of type C controller is your custom board using for the type C interface?

Any schematic to share?

Have you checked the adaptation guide document?

the controller is ti s3200, and the designer of the customized board told me that the design of the board was based on the official documentation.


Why all the nvidia,usb2-companion is same on your device tree?

This should match the hardware usb2 port. Did you read the document or you don’t know what I am talking about?

I’m sorry, as a beginner in this field, I did not configure the device tree correctly.Can you give me some advice!
I want to make usb3-1 enter device mode, as a mass storage container accessed by a PC. Any document can help me solve this problem?

Please refer to this section.

https://docs.nvidia.com/jetson/archives/r35.3.1/DeveloperGuide/text/HR/JetsonModuleAdaptationAndBringUp/JetsonAgxOrinSeries.html?highlight=xudc#porting-the-universal-serial-bus

i had read the section you remind, and follow the schematic,i had changed the dts part like this

xusb_padctl: xusb_padctl@3520000 {
		status = "okay";
		pads {
			usb2 {
				lanes {
					usb2-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-3 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb2-4 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
			usb3 {
				lanes {
					usb3-0 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-1 {
						nvidia,function = "xusb";
						status = "okay";
					};
					usb3-2 {
						nvidia,function = "xusb";
						status = "okay";
					};
				};
			};
		};

		ports {
			usb2-0 {
				mode = "peripheral";
				status = "okay";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-b-connector", "gpio-usb-b-connector";
 					label = "micro-USB";
 					type = "micro";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-1 {
				mode = "host";
                                vbus-supply = <&p3509_vdd_av10_hub>;
				status = "okay";
			};
			usb2-3 {
				mode = "host";
				vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb2-4 {
				mode = "host";
				vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb3-0 {
				status = "okay";
				nvidia,usb2-companion = <1>;
			};
			usb3-1 {
				nvidia,usb2-companion = <4>;
				status = "okay";
			};
			usb3-2 {
				nvidia,usb2-companion = <3>;
				status = "okay";
			};
		};
	};

	tegra_xudc: xudc@3550000 {
		status = "okay";
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-0}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-2}>;
		phy-names = "usb2-0", "usb3-2";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

	tegra_xhci: xhci@3610000 {
		status = "okay";
		nvidia,use-typec-switch;
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-1}>,
			<&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-3}>,
			<&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-4}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-0}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-1}>;
		phy-names = "usb2-1", "usb2-3", "usb2-4", "usb3-0", "usb3-1";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

What is the exact usb port that you want to set it as device mode?

Your device tree seems having conflict with it.

xudc driver says usb2-0, usb3-2. But your previous setting indicates usb3-2 is not a pair with usb2-0 at all.

i want to usb3-2 port as device mode, so i should let usb3-2 pair with usb2-0?
like this?

usb3-2 {
	nvidia,usb2-companion = <0>;
	status = "okay";
};

so i should let usb3-2 pair with usb2-0?

You should check your hardware schematic but not ask me.

my mistake, so according to schematic, i should let usb2-3 enter peripheral mode right?
like this:

ports {
			usb2-0 {
				mode = "peripheral";
				status = "disable";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-b-connector", "gpio-usb-b-connector";
 					label = "micro-USB";
 					type = "micro";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-1 {
				mode = "host";
                                vbus-supply = <&p3509_vdd_av10_hub>;
				status = "okay";
			};
			usb2-3 {
				mode = "peripheral";
				status = "okay";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-c-connector";
 					label = "USB-C";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-4 {
				mode = "host";
				vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb3-0 {
				status = "okay";
				nvidia,usb2-companion = <1>;
			};
			usb3-1 {
				nvidia,usb2-companion = <4>;
				status = "okay";
			};
			usb3-2 {
				nvidia,usb2-companion = <3>;
				status = "okay";
			};
		};
	};

	tegra_xudc: xudc@3550000 {
		status = "okay";
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-3}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-2}>;
		phy-names = "usb2-3", "usb3-2";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

	tegra_xhci: xhci@3610000 {
		status = "okay";
		nvidia,use-typec-switch;
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-1}>,
			<&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-4}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-0}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-1}>;
		phy-names = "usb2-1",  "usb2-4", "usb3-0", "usb3-1";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

and please disable usb ports which are not present in the schematic.

Please also refer to the kernel/kernel-5.10/Documentation/devicetree/bindings/connector/usb-connector.yaml as the document indicates.

This file is in the kernel public source code.

the specified port usb3-2 is still host mode, what i change file is kernel-dts/cvb/tegra234-p3509-a02.dtsi.

ports {
			usb2-0 {
				mode = "peripheral";
				status = "disabled";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-b-connector", "gpio-usb-b-connector";
 					label = "micro-USB";
 					type = "micro";
 					vbus-gpio = <USB_ROLE_DEVICE>;
					cable-connected-on-boot = <USB_ROLE_DEVICE>;
 				};
#endif
			};
			usb2-1 {
				mode = "host";
                                vbus-supply = <&p3509_vdd_av10_hub>;
				status = "disabled";
			};
			usb2-3 {
				mode = "peripheral";
				status = "okay";
                                vbus-supply = <&p3509_vdd_5v_sys>;
#if TEGRA_XUSB_DT_VERSION >= DT_VERSION_3
				usb-role-switch;
				connector {
					compatible = "usb-c-connector";
 					label = "USB-C";
 					data-role = "device";
 				};
#endif
			};
			usb2-4 {
				mode = "host";
				vbus-supply = <&p3509_vdd_5v_sys>;
				status = "okay";
			};
			usb3-0 {
				status = "disabled";
				nvidia,usb2-companion = <1>;
			};
			usb3-1 {
				nvidia,usb2-companion = <4>;
				status = "okay";
			};
			usb3-2 {
				nvidia,usb2-companion = <3>;
				status = "okay";
			};
		};
	};

	tegra_xudc: xudc@3550000 {
		status = "okay";
		phys = <&{/xusb_padctl@3520000/pads/usb2/lanes/usb2-3}>,
			<&{/xusb_padctl@3520000/pads/usb3/lanes/usb3-2}>;
		phy-names = "usb2-3", "usb3-2";
		nvidia,xusb-padctl = <&xusb_padctl>;
	};

Are you able to tell if your dtb change is taking effect? or you don’t know how to check?

I use a type-c cable to connect to the pc, and I can’t see the relevant nodes through the lsusb command, and I connect the keyboard to the interface, and it still works.

No, I mean are you able to tell if your dtb is really updated to you devcie.

請問這句有看不懂的地方嗎

I checked it with dtc decompilation, the nodes in the device are indeed updated

Could you share your dmesg?