USB Device Mode
#1
I've a kernel build with DWC2/3 drivers and dual-role support enabled. I'm unable to see any devices in /sys/class/udc. Is there anyone who has worked on this? As I understand I need:

CONFIG_USB_DWC3=y
CONFIG_USB_DWC3_DUAL_ROLE=y
CONFIG_USB_GADGET=y
CONFIG_USB_CONFIGFS=y
CONFIG_USB_ETH=y


I see two controllers:
# ls /sys/bus/platform/drivers/dwc3
bind  fe800000.usb  fe900000.usb  module  uevent  unbind

I'm not able to get any more information by inspecting that filesystem. For my config, I have:
# cat .config | grep USB_DWC3
CONFIG_USB_DWC3=m
# CONFIG_USB_DWC3_ULPI is not set
# CONFIG_USB_DWC3_HOST is not set
# CONFIG_USB_DWC3_GADGET is not set
CONFIG_USB_DWC3_DUAL_ROLE=y
CONFIG_USB_DWC3_HAPS=m
CONFIG_USB_DWC3_MESON_G12A=m
CONFIG_USB_DWC3_OF_SIMPLE=m


# cat .config | grep USB_GADGET
CONFIG_USB_GADGET=m
# CONFIG_USB_GADGET_DEBUG is not set
# CONFIG_USB_GADGET_DEBUG_FILES is not set
# CONFIG_USB_GADGET_DEBUG_FS is not set
CONFIG_USB_GADGET_VBUS_DRAW=2
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2
# CONFIG_USB_GADGET_XILINX is not set
CONFIG_USB_GADGETFS=m


# cat .config | grep USB_CONFIGFS
CONFIG_USB_CONFIGFS=m
CONFIG_USB_CONFIGFS_SERIAL=y
CONFIG_USB_CONFIGFS_ACM=y
CONFIG_USB_CONFIGFS_OBEX=y
CONFIG_USB_CONFIGFS_NCM=y
CONFIG_USB_CONFIGFS_ECM=y
CONFIG_USB_CONFIGFS_ECM_SUBSET=y
CONFIG_USB_CONFIGFS_RNDIS=y
CONFIG_USB_CONFIGFS_EEM=y
# CONFIG_USB_CONFIGFS_PHONET is not set
CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_CONFIGFS_F_LB_SS=y
CONFIG_USB_CONFIGFS_F_FS=y
CONFIG_USB_CONFIGFS_F_UAC1=y
# CONFIG_USB_CONFIGFS_F_UAC1_LEGACY is not set
CONFIG_USB_CONFIGFS_F_UAC2=y
CONFIG_USB_CONFIGFS_F_MIDI=y
CONFIG_USB_CONFIGFS_F_HID=y
CONFIG_USB_CONFIGFS_F_UVC=y
CONFIG_USB_CONFIGFS_F_PRINTER=y
#2
I made progress. The default device tree sets the first dwc3 controller as "otg." Unfortunately this seems to not have much effect. I've tried looking for a software switch and also tried plugging the board in as a device. How do you set this without needing a reboot?

Changing the two DWC3 nodes in the file "arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi:"

Code:
&usbdrd3_0 {
        status = "okay";
};

&usbdrd_dwc3_0 {
        status = "okay";
        dr_mode = "peripheral";
};

&usbdrd3_1 {
        status = "okay";
};

&usbdrd_dwc3_1 {
Code:
        status = "okay";
Code:
        dr_mode = "peripheral";
Code:
};

They are both listed in /sys/class/udc:
Code:
# ls /sys/class/udc
fe800000.usb  fe900000.usb

But, again, I'd like to change mode without needing to reboot. I'm also unsure how compatible the Type-C port is.
#3
Really hoping someone can help, I can't get USB3 device mode working still.

I have devices in /sys/class/udc and they function properly via configfs when
plugged into a USB2 only port. If I plug them into a superspeed port I get
nothing in dmesg on the host side. At first, I did get a response on the host, in
the form of:

Code:
[591550.770819] usb 1-1.2: new full-speed USB device number 76 using xhci_hcd
[591550.870962] usb 1-1.2: device descriptor read/64, error -32
[591551.078865] usb 1-1.2: device descriptor read/64, error -32
[591551.286875] usb 1-1.2: new full-speed USB device number 77 using xhci_hcd
[591551.386873] usb 1-1.2: device descriptor read/64, error -32
[591551.594859] usb 1-1.2: device descriptor read/64, error -32
[591551.703160] usb 1-1-port2: attempt power cycle

[img=15x15]data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==[/img]
However now I get no driver activity when binding the UDC in configfs or
loading or unloading the respective modules. Kernel is 5.7.15 w/ patches.

It doesn't seem like bad USB-C wiring fried port or tripped a polyfuse, the
port still works after attempting USB3 device mode.
#4
Your investigation helped me a lot, thanks Smile

I think that I have solved the problem. To change USB mode without reboot you should type:

Code:
echo device > /sys/kernel/debug/fe800000.usb/mode

but if the current mode is "otg" it will give those fails that you described on the host side. To avoid that set it to "host" before, and then "device".

Code:
echo host > /sys/kernel/debug/fe800000.usb/mode
echo device > /sys/kernel/debug/fe800000.usb/mode

I configured the device for CDC EEM and the host side works fine with it (and the appropriate driver, of course).

Update: I had to insert a little "sleep 0.03" between "echo host" and "echo device" for making it to work in a script.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best device image for docker usage? Dreamwalker 1 1,520 05-01-2022, 04:08 PM
Last Post: tllim
  Device unable to boot Lunix33 9 7,117 09-23-2021, 01:38 AM
Last Post: LMM
  Device bricked? TheHunter 1 2,324 03-10-2021, 05:27 PM
Last Post: TheHunter
  PCIe x4 mode - Lane 3 failure acdkyn 1 2,728 04-24-2020, 01:32 PM
Last Post: kuleszdl
  Non burst mode in MIPI DSI skumar 0 1,946 06-06-2019, 12:54 AM
Last Post: skumar
  Clarification of type-c superspeed device mode cpwrunner 4 6,201 07-03-2018, 11:44 AM
Last Post: cpwrunner

Forum Jump:


Users browsing this thread: 1 Guest(s)