Linux USB DRD Dual-Role Solution
RTL8730E USB is a Dual-Role Device (DRD) controller that can operate as either a USB host or a USB device. The operating role is selected through the dr_mode device tree property together with the role-switching method described below.
OTG
When dr_mode = "otg", both the host and device roles are initialized at driver startup. In a standard USB OTG design, the role is determined automatically by the OTG ID pin of the Micro-AB / Type-C connector: grounding the ID pin selects host mode, while a floating ID pin selects device mode.
DRD
On QFN100, the role is selected by software through the Realtek USB PHY force_mode mechanism instead of the OTG ID pin. It is controlled via the sysfs parameter
/sys/module/phy_rtk_usb/parameters/usb_force_mode:
1: Force USB host mode2: Force USB device mode
This feature is enabled by the device tree property rtk,usb-force-role-en.
Note
When QFN100 operates in OTG mode, specify the role manually via force_mode.
When to use:
Device mode: After completing insmod and ConfigFS configuration, set the following before enabling the UDC (see How to Enable and Disable Gadget):
echo 2 > /sys/module/phy_rtk_usb/parameters/usb_force_modeHost mode: After completing insmod, set:
echo 1 > /sys/module/phy_rtk_usb/parameters/usb_force_mode