[Nexus S Android Development] anglergab:
Hi Sztupy!

Hi *!

First of all, Sztupy, thank you for this great mod and UHC app!

I'll share my experiences with USB Host/OTG mode.

Environment details: Nexus S, CM9.0 (update-cm-9.0.0-RC0-crespo-signed.no.v5.p0.zip), Matr1x kernel (Matr1x-cfs_v18.5.zip), OTG Build 5 in kernel.

OTG cable is recognized by UHC app. Switch between Host/Auto-Host/OTG/Client is working in UHC app. Root hub is found (note this is an internal HW in mobile).

First USB device: 2.0 Belkin hub, 7 ports, powered, supplies upstream no voltage/current.

Without Y-cable there is no voltage between the mobile and hub, so the hub is no way recognized. The sign of this (from /proc/kmsg):

<6>[ 4650.044056] => over current condition is changed

This happens without any USB peripheral connected. This is a sign of improper implementation of Host mode from the manufacturer. The PCB lacks some connections and/or voltage regulators/voltage pumps. The internal short circuit protection activates because the the power requirements of the newly connected root hub cannot be satisfied.

This means you'll need a Y-cable in the case of Nexus S, even if your USB peripheral is only bus-powered. The reason is simply: some hubs won't supply any voltage upstream to mobile, the USB Host Controller cannot supply voltage because of implementation specific reasons, so you'll need to feed in. But the resistance of the mobile is much smaller (i. e. it can draw 1 A!) than your bus-powered USB device. So the mobile'll eat all of the current/power, not leaving to the USB device. Thus you'll need to disable USB charging in UHC app. The phone'll further display charging, but this is a bug, it won't draw significant current anymore.

If you can see:

<7>[ 2211.028343] hub 1-0:1.0: no over-current condition exists

then it's fine.

So you must supply power through Y-cable even you have a bus-powered (low power) device (i. e. keyboard, mouse), and probably even you have a powered hub. (Because many powered hubs supply its power exclusively to their downstream ports).

After this, the OTG worked: though I've found USB 2.0 device operation very unstable. I'd to reconnect, reboot, many times before making it work. A few times my 2.0 pendrive was recognized while connected through a 2.0 hub. Obviously, it (the pendrive) was recognized more often when connected directly through Y-cable.

But I cannot open any file from pendrive: after listing directories, it stopped working, it seemed as disconnected every now and then. I suspect IRQ related bugs from kmsg. The LED on pendrive was flashing and nothing happened. Though it still flashed after disconnecting cable from mobile. Even after disconnecting the pendrive from Y-cable -- just kidding ;)

I've faced very often random reboots. First sign: the UI responds slowly, it freezes, then after seconds it restarts. I suppose here a watchdog timer. It's there to avoid the user disconnect the battery in case some type of load is high, and it's likely the phone would freeze. Battery disconnects should be avoided, because they may harm the SIM card reader and NAND chip. At times you can avoid restart by not pressing any UI element when the slowdown is experienced.

Surpisingly I've had much more luck with USB 1.0/1.1 devices. Some recognized devices: MS mouse (cursor was also displayed, though right button not working), MS wireless (proprietary RF) keyboard+mouse receiver. At the latter only the keyboard worked. The RD mouse sent successfully data to receiver, because LED was blinking, but the mobile wasn't able to interpret the data. I suppose MS applied some non-standard HID implementation at this point... This USB devices were connected directly through an Y-cable. I wanted to use a keyboard and a mouse at same time, but I found it impossible because for this you'll need a hub. For a hub to work, it should be 2.0, that we know very unstable. Even it'd be a 1.0 and a 2.0 device at the same time, which would be an unlucky combination.

Consequences:

many bugs with Nexus S, specially 2.0 support. Many random restarts.

I suppose some of the bugs exist because of the HW differences between SGS (Sztupy's mobile) and Nexus S.

Some of the problems can be explained by cheap and low-quality cables and home-made connections (at least short circuits were avoided ;) ) and low-power output of my old PC. I fed in power from a PC (MB manufactured in 2003). It can happen, that my MB won't supply easily more that 0.5 A to "devices" only with power lines connected. Many times it's required that the device must signal the host in order to request more current output. And the host decides whether the device should get it. This need of initialization is now (contrary to the practice in 2003) not widely implemented because of the many devices drawing current only on power lines.