NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
Template:GLSDK USB DRD
Contents
Dual Role Device (DRD) support[edit]
Introduction[edit]
DRD is Dual Role Device, where usb controller (dwc3) can be configured to
"host-mode" or "device-mode". The role switch to host or device can be performed by one
of the following methods
- The role switching to "device" or "host" can done by writing to dwc3 debugfs nodes
- The dynamic role switching to "host" or "device" mode based on usb-id pin when the usb cable (type-A for host, type-B for device) is connected to usb1 or usb2 ports.
DRD Setup[edit]
In order to DRD to work both host stack and device stack along with gadget modules must be initialized. After kernel boot, by default the DRD port is configured to host mode or device mode based on ID pin. If gadget driver is not loaded then initialize the gadget stack by using following procedure.
Note: only the DRD capable port can be switched to either "host" or "device" modes. This operation is not required for host-only or peripheral-only ports.
1. After kernel is booted, mount debugfs and switch DRD port to device mode.
mount -t debugfs debugfs /mnt
The two nodes /mnt/48890000.usb and /mnt/488d0000.usb for usb1 & usb2 port are created respectively.
2.switch the DRD ports (usb1 or usb2) to "device" mode
echo "device" > /mnt/48890000.usb/mode. echo "device" > /mnt/488d0000.usb/mode.
3. Insert all the gadget module.
insmod <libcomposite.ko> insmod <gadget.ko> for DRD port1 or port2
Note: If both ports are configured for DRD mode, the two gadgets must be inserted for each port1 and port2 respectively.
4.Now ready to switch b/w host/device mode based on cable connect.
5.If host cable (mini/micro A-Receptacle, ID pin Ground) connected to DRD capable portX,the port should switch to host mode. Based on ID pin (in this case ID is Ground), port switches to host mode, as part of this if previous mode is device, the device stack is removed and host stack get initialized.
6.If device cable (mini/micro B-cable, ID pin Float) connected to DRD capable portX, the port should switch to device mode. Based on ID pin (In this case ID is Open), port switches to device mode, as part of this if previous mode is host, the host stack is removed and device stack get initialized.
DRD Testing on DRA7XX EVM (Standalone alone testing with onboard usb ports usb1 and usb2)[edit]
Build kernel and usb gadget modules[edit]
1. Build the kernel default omap2plus_defconfig
2. make sure the dr_mode is set to "otg" for usb1/2 in platform specific .dts specific files.
dr_mode = "otg";
For dra7xx, set dr_mode to "otg" in arch/arm/boot/dts/dra7-evm.dts files. For omap5, set dr_mode to "otg" in arch/arm/boot/dts/omap5.dtsi file.
3. Build the kernel and usb gadgets as modules (for example g_zero.ko , g_ncm.ko, g_mass_storage.ko etc).
5. create the sd card with file system and boot partition, refer to GLSDK software developers guide for more info.
6. copy arch/arm/boot/zImage and arch/arm/boot/dts/dra7*.dtb to /media/rootfs/boot partition of sd card.
7. install the modules to sdcard rootfs mount directory.
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules_install INSTALL_MOD_PATH=/media/rootfs
Setup/Testing DRD feature[edit]
1. The DRA7XX-EVM has usb1 (usb3.0 compatible) and usb2(usb2.0 only) ports, DRD can be tested by connecting usb1 and usb2 ports back to back with host-A type device-B type usb cables.
2. Remove any usb cable/adapter connected to usb1 or usb2 port. Boot the kernel. By default both usb1 and usb2 ports are set to host mode. In host mode you cannot insert the gadget modules. Hence configure usb1 and usb2 ports to device mode.
# mount -t debugfs debugfs /mnt To switch to device mode # echo "device" > /mnt/<controller-node>/mode To switch to host mode # echo "host" > /mnt/<controller-node>/mode
Note: The controller-node for usb1 is 48890000.usb and 488d0000.usb for usb2.
3.Load the usb gadget modules for usb1 port and usb2 port respectively (if not loaded).
# modprobe libcomposite.ko # modprobe g_zero.ko (for usb1 port) # modporbe g_mass_storage.ko file=/dev/ram0 stall=0 (for usb2 port)
The g_zero gadget is loaded to usb1, and g_mass_storage to usb2.
4.To view the current mode of usb1 or usb2
# cat /mnt/48890000.usb/mode OTG
6.Now connect the type-A cable (micro-A receptacle) to usb1 port, the dynamic usb-id pin is detected and usb1 port is configured to host mode automatically. connect usb2 port to usb1 port through type-B (mini-B type) cable. usb1 host will enumerate usb2-device(g_mass_storage.ko).
8.Reverse the cable, connect type-A receptacle to usb2 port (host-mode) and type-B cable to usb1 port (device mode). Now the usb2 becomes host dynamically and enumerate the usb1(device) g_zero gadget.
Note: The role switch can happen only if the current mode is different from previous mode. make sure build the kernel and device tree blob and load appropriate dtb file (dra7-evm.dtb or omap5-uevm.dtb)
DRD Testing for TI-OMAP5-UEVM[edit]
1. Follow the same procedure explained above for dra7xx EVM. The OMAP5 has only one DRD port, hence debug entry created for one drd port.
2. The debugfs node for usb1 port is "/<mount-point>/4a030000-dwc3/mode"
Driving VBUS using GPIO[edit]
In order to drive the drvvbus to be "always on" in between role switch between "host" mode or "device" mode. Please refer to reference patch implementation from link.
This patch is based on 3.14 kernel and u-boot-2014.07.
- u-boot-2014.07-drd-patches.tar - Includes u-boot changes which configure pinmux for drive vbus using gpio.