[KERNEL][ICS-CM9 or JVU] USB Host mode (OTG) driver for SGS i9000 [BUILD 5]


: 8

  • USB Host: The ability to connect other USB external devices to your device.
  • USB OTG: The ability of a device to work either as a client or as a host in an USB network.
  • OTG cable: An USB-micro male - USB-A female cable. It also has pins 4 and 5 connected inside the USB-micro male part.
  • USB Y-cable: A special USB cable that has three ends: two USB male-A ends (one data, one power port) and one USB-mini-B male end.
  • LS: USB 1.0 Low-speed (1.5 Mb/s)
  • FS: USB 1.1 Full-speed (12 Mb/s)
  • HS: USB 2.0 High-speed (460 Mb/s)
  • USB Hub: A device that lets you split the USB signal
  • Powered USB Hub: A hub that has an external power supply support
  • Upstream: The direction from the client device to the host device.
  • Control Transfer: One of the five transfer types used by the USB specification. It is responsible for maintainin the state of the USB devices.
  • Bulk Transfer: One of the five transfer types used by the USB specification. This is the most used one, used by drives, cameras and most proprietary usb devices.
  • Interrupt Transfer: One of the five transfer type used by the USB specification. This is mainly used in HID devices, like mice, keyboards and game controllers.
  • Isochronous Transfer: One of the five transfer types used by the USB specification. This is used in streaming devices, like usb audio and usb video devices, dvb receivers, etc.
  • Split Transfer: One of the five transfer types used by the USB specification. It is responsible for converting USB 1.x signals into USB 2.0 signals.

How to connect the things:

You will need:

  • The phone
  • An OTG-cable (make sure it's not NOKIA branded, as they have square connectors. You can use some sandpaper to smooth those edges though, so they'll fit inside a normal micro-USB base)
  • Either a powered USB hub (preferably that powers the upstream connection as well)
  • Or a simple USB hub, with a mini-USB connector and a Y-cable, and some USB power source (in this case the upstream powering works out of the box). You will need a decent usb power source though (5V/750mA at least)
  • Make sure the HUB support USB 2.0 and IS indeed an USB 2.0 high-speed hub. USB 1.x Full-speed hubs are very instable Even if it's an USB 2.0 hub it might not work. Either try to find another one, or connect the device directly to the phone (check the connection graphical guide below)
  • And, but not least, some things to connect to the phone.

Here is a short video of me demonstrating how bad my spoken English is (among other things): http://youtu.be/Yqfk7BOd8J4
And here is a graphical connection guide:

Here is another one (from developersdevelopers), showing how to solder a cable for yourselves:

How to install the kernel:

For CM9/ICS versions: Boot to recovery and use CWM to flash the update. DO NOT TRY to flash this to anything else than teamhacksung's ICS ROM.
For stock GB versions: Use Odin to flash the new kernel. Make sure you already have a recent GB ROM on your phone.

How to use:

By default host mode is turned off, and won't be activated even if you put in an OTG cable. This is for stability reasons. There is an application on Market called "Usb Host Controller" that allows you to enable host functionality. (It can also be downloaded separately) For best results connect the devices in this order:

  • Add power to the USB Hub / connect the power part of the Y cable to a source of power
  • Set Operation Mode in "Usb Host Controller" to OTG
  • Connect the OTG cable to the USB hub or device
  • Connect the OTG cable to the phone

If everything is fine, you should see the USB hub inside the USB tab in UHC. Next you might try to connect your peripherals one by one to the hub. You should always check whether they are enumerated or not. (by pressing refresh)

What is working:

USB 2.0 devices seem to work fine. This includes flash drives, and other accessories like Canon DSLRs. This concludes all USB 2.0 devices I have at home.

What does not work:

USB 1.x devices are very quirky (more about this later). USB 1.x devices include almost all HID devices (like keyboard and mice). Some external hubs are failing too. If you cannot connect your hub to the device try with another one, or try connecting the device without an external hub in the middle.

Also you will need to power the devices externally, as the phone doesn't give out power on the OTG connector.

USB device enumeration is also broken with mass storage devices: it will not re-enumerate the partitions and devices avialable after they have been connected. Since the 0.2 version of UHC it has a new function: reloading the partition table of a device. You have to do this manually. This might solve most of the "no partition found" problems, and will also lets you connect other Android devices.

Do I need a hub to get it working?

No, if you only want to connect one device you can connect it straight to the phone (if you provide it with +5V power). This means you can connect the one end of a Y cable to a power source, the other end to your device and the third end to the phone's OTG cable, and it will work. As it seems there are problems with some external hubs, if you can, then connect to the external device without using a hub in the middle.

What is "Usb Host Controller"?

Usb Host Controller is a small app, that let's you enumerate the USB devices that are connected to your phone. It also let's you easily mount and unmount FAT32 based partitions of the flash drives you connect. Besides these globally useful functions it also let's you control how the host mode should be working with.

Does DSLR Controller work?

According to chainfire the latest version (0.85) of DSLR Controller will work on CM9-ICS + Galaxy S and this kernel. On JVU even older versions (0.83) should work too.

Does it work on CM7, stock ROM, other Galaxy S variants, Nexus S, etc?

It currently works on the folloving devices and ROM versions:

  • Galaxy S i9000
    • CM9 / ICS
    • JVU / Gingerbread
  • Captivate
  • Nexus S

For other S5PV210/S5PC110/Hummingbird based devices this can be probably ported easily. I will do this if you ask me and the following things are present:
  • The kernel source is avialable on github. It is either a kernel for gingerbread (>=2.6.35) or for ICS (>=3.0)
  • It also contains (or has links to) the initramfs and all the other files needed to create an update.
  • If creating the update is not straightforward I also need a script to do this for me
  • After the update is made you will test it for me. If the feedback is positive I'll build versions for that device too, whenever something is changed.

Is there a chance that this will work without having an external power source?

Maybe. In theory the S3C controller has the appropriate functionality, but in practice it might not work (for example there might be missing connections inside the PCB, etc.)

What about USB 1.x devices

USB 1.x devices work since build 3 (the first JVU build), but only if you connect them to the device without a hub involved (you still need external power). They will still not work if you connect them to an USB 2.0 hub. You might connect more USB 1.x devices together if you happen to have an USB 1.x hub, but it needs patience (I managed to connect a mouse a keyboard and an external hard drive at one through an USB 1.x hub, but I had to try it at least 20 times to get them all properly enumerated. After that they worked though)

More info about USB 1.x devices: http://forum.xda-developers.com/show...&postcount=101

Since Build 5, you can also choose to disable the USB 2 functionality of the phone. This will increase stability for USB 1.x devices, but will decrease the transfer speed of USB 2 devices, like external drives. If you want to connect USB 1.x devices through an USB 2.0 HUB, you will need to disable USB 2 mode though.

How to debug

The easiest way to debug is the following:

Turn on "Wireless ADB" on your phone. You can use UHC, or any other app that supports this for that.

Next connect to your phone wirelessly from your PC, and use the following commands:


> adb connect     (enter the actual ip address you get for your phone)
> adb shell
$ su
# echo o > /sys/devices/platform/s3c-usbgadget/opmode
# cat /proc/kmsg
The above command includes setting the operation mode of the host controller to "OTG mode", so you don't have to do it on the UHC.

If everything is fine, you should see results similar to this: http://forum.xda-developers.com/show...&postcount=117

If devices don't get enumreated properly try switching back to client mode, then to OTG mode again, without disconnecting the devices. You might also try simply reconnecting the devices to the USB cable. Also make sure your power source can give out enough power. For debugging purposes I advice you to use the USB port of a computer / notebook as a power source because they can usually give out 1A of current out of one port. Most external chargers can only give out 500mA-600mA, which might not be enough for multiple devices.

It still doesn't work

There are unfortunately a lot of factors that might make the USB Host mode break. These include:

  • Non-conformant USB devices
  • Low quality cables
  • Low quality power soruces (chargers)
  • Solar flares
  • Underground nuclear tests
  • etc.

Try replacing the cables / devices / power sources and hope it will work next time.