Find Your Device:
Or Continue to Thread: [KERNEL][ICS-CM9 or JVU] USB H…
17th January 2012, 08:42 AM |#4  
sztupy's Avatar
OP Recognized Developer
Flag London
Thanks Meter: 859
Donate to Me
For developers
For developers

Getting USB host mode was not really a priority for developers, and it wasn't also very easy. The kernel that Samsung provided had traces of EHCI and OHCI support, but they all seemed to be dead-ends. There was a working Host driver though on some releases, most notably the EA24 release of the Galaxy Tab. (From it we know that it is actually the same driver that is used on odroid2 and probably SGS2 too). This driver was actually not usable, but a fellow developer "Kevin Hester" fixed it, and posted it on his github account. Unfortunately his solution was based on a very old kernel, which used a lot of junk Samsung kernel stuff and deprecated features. Also he based the whole client-host switching code on the proprietary 30 pin connector, which is only used in Galaxy Tab variants. The above things meant that his code was not as easily portable as he probably thought.

My involvment was mainly to incorporate his fixed S3C Host driver to the latest 3.x kernel branch, fix some of it's internal workings, and put the client-host changer routines somewhere else (it actually landed in the client mode driver called s3c_udc_otg).

The driver works as following (if you find it inelegant note that the SGS2 does work the same way!):

The client mode gadget driver is always loaded. It is signalled by the FSA, if it sees that a cable is connected or disconnected. The FSA knows whether the cable is an OTG or a simple client one, and sends this information to the client driver.

Next the client driver decides whether it needs to change to host mode or not. If it changes, it deregisters his interrupt requests, and loads up the host driver. The client driver stays in memory, but without the interrupt handler routines it will not interfere with the host drivers working.

The host driver grabs the interrupt handler, and does the enumeration of the devices. It seems the root hub of the driver only does it once, so if anything changes between the phone and the first device (power loss, cable disconnection etc.) the driver won't notice it! (Thiks is why the first device should be a proper external usb hub, as it will re-enumerate devices if they are connected and disconnected. Losing the power supply will hang the host mode still though). EDIT: this is already solved.

The client driver still listens on cable changes by the FSA. For example if a cable is disconnected and the client driver is not in "host" mode, then it will shut down the host driver (it will unload it from the memory).

The client driver can be in 4 modes:
  • client: only client mode whatever happens
  • host: always host mode. The client will load the host mode driver the instant the client driver mode changes to host, and will stay so until the mode is changed again to something else
  • otg: client mode when no cable or a client cable is connected. Will switch to host mode if an otg cable is connected.
  • auto-host: client mode when no cable is connected. Will switch to host mode if an otg or a simple client cable is connected.

The actual mode can be queried from the file:

The actual mode can be set by echoing 'c','h','o' or 'a' to the previous file. (Or by using Usb Host Controller, which actually does the same internally)

After connecting external mass storage devices be aware that udev won't create the appropriate nodes inside /dev for them. Usb Host Controller will do this autoamtically, but from the console one needs to do an mknod, befure it can be mounted as a file system.

Build 5 notices

From Build 5 there are more host drivers built in: S3C in HS mode (original), S3C in LS/FS (eg. USB 1) mode, and an initial DWC driver. The latter is included as it uses the same specification, and it seems it might get into the upstream kernel branch too sometimes, meaning if it can be loaded it might actually get decent support later on. It also supports isochronous and split transactions, which the original S3C drivers lack.

The DWC driver does not work currently however, choosing it will usually crash the phone, and force a restart!

To change the driver you have to write 'l','f' or 'd' into the file:

Apart form that there is also a version file there, containing a few informations about the module.

There is also support to turn off charging, while the phone is connected to a charger. You can turn charging on/off inside the file disable_charger, which can be found somewhere in the sysfs (it's location might change between devices)
Last edited by sztupy; 16th April 2012 at 10:18 AM.
The Following 28 Users Say Thank You to sztupy For This Useful Post: [ View ]