VAR-SOM-MX6 USB OTG

From Variscite Wiki
VAR-SOM-MX6 - USB OTG

Configuring the USB OTG port under Linux

The USB OTG port configuration as either host, peripheral or OTG is set in the device tree of the board. It is determined by the value of the dr_mode property under the usbotg node.
dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"

Note: for the VAR-MX6CustomBoard "otg" is not supported - only "host" and "peripheral".
For implementing full native OTG functionality please see VAR-SOM-MX6 datasheet section 4.7 and VAR-SOLOCustomBoard schematics implementation.

For example:
Follow either the "Build the Linux kernel from source code" or "Customizing the Linux kernel" Wiki pages and edit the the appropriate device tree for your board
(imx6dl-var-som-solo-vsc.dts / imx6q-var-dart.dts / imx6qdl-var-som.dtsi / imx6q-var-som-vsc.dts):

&usbotg {
        vbus-supply = <&reg_usb_otg_vbus>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_usbotg_2>;
        disable-over-current;
        /* dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg" */
-       dr_mode = "host";
+       dr_mode = "otg";
        status = "okay";
};

If you build the kernel manually from source code, you should build only the device trees and copy them to your SD card.

Note: You can read the current dr_mode value on a running target, by executing the following command:

# cat /sys/firmware/devicetree/base/soc/aips-bus@02100000/usb@02184000/dr_mode; echo

Using the USB OTG port under Linux

As host

See USB host section.

As peripheral

In order to use the board as a peripheral, an appropriate module needs to be loaded.
For example, there is an Ethernet gadget module called g_ether, a mass storage gadget called g_mass_storage, a serial gadget called g_serial, etc.

Example using the g_mass_storage module to expose the BOOT partition on our recovery SD card to a PC:
Connect a micro-B plug to Standard-A plug cable between the board and a PC, and run the following on the board:

# umount /dev/mmcblk0p1
# modprobe g_mass_storage file=/dev/mmcblk0p1

Note: On the some board configurations the SD card device will be /dev/mmcblk1 instead of /dev/mmcblk0 in the example above.

The partition should be loaded on the PC as a mass storage device.

As OTG

With OTG, the board can be either a host, or a peripheral.
In order to use it as a host and connect a peripheral (e.g. a USB mouse) to it, an OTG cable is needed (a cable with a micro-A plug on one end and a Standard-A receptacle on the other).
In order to use it as a peripheral and connect it to a PC, for example, a cable with a micro-B plug on one end and a Standard-A plug on the other is needed.