USB Host mode on Defy

SlugZero

Member
Sep 11, 2012
38
647
0
USB Host Kernel for Defy

So for anyone who is keen enough to try this, here is my modified kernel with USB host support. I also compiled some of the USB storage modules into the kernel.

You have to copy the zImage to /system/bootmenu/2nd-boot/ and the android.hardware.usb.host.xml to /etc/permissions (It's not a flashable zip, sorry!) And don't forget to make a backup first:)

This is based on the AeroKernel from Quarx's latest nightlly, so it should work with the CM10.1/2 builds (tested it on CM10.2).

Please test and report any issues.

What you need:
- USB OTG cable
- Defy does not provide power via USB, you therefore need some sort of external power source for your USB device. The following should work:
- self-powered device (e.g. camera)
- hard disk with Y-cable, second end in external power source
- USB hub with external power source

What works:
- USB hub
- USB keyboard and mouse
- USB mass storage devices (with external app, I tested StickMount)
- disconnecting and reconnecting devices at the hub
- changing from client to host mode and vice versa on OTG cable connect/disconnect

Known issues/what does not work:
- first connect after boot works fine, but reconnecting the OTG cable needs a few (2-4) tries.
- sometimes after using host mode, charger or USB client connection is not detected any more
- when disconnecting a device, the driver sometimes gets stuck in a strange loop and phone must be rebooted


Amazing!! Did you need a self-powered cable or just plain OTG?
The USB device needs an external power source, but a simple externally powered USB hub with an OTG cable will do.
 

Attachments

level_666

Senior Member
Jun 26, 2009
86
67
0
Medellín
code3studio.com
- Defy does not provide power via USB, you therefore need some sort of external power source for your USB device. The following should work:
- self-powered device (e.g. camera)
- hard disk with Y-cable, second end in external power source
- USB hub with external power source

(...)

The USB device needs an external power source, but a simple externally powered USB hub with an OTG cable will do.
But according to an old picture on @Quarx site, and his explanation of that pic, defy does support output power via micro USB

Look here:
- http://quarx2k.ru/other/IMG_20120228_234016.jpg

- http://forum.xda-developers.com/showpost.php?p=33250160&postcount=11550
 
Last edited:
  • Like
Reactions: okij

SlugZero

Member
Sep 11, 2012
38
647
0
But according to an old picture on @Quarx site, and his explanation of that pic, defy does support output power via micro USB
thx, I did not know this pic. That means that Quarx probably has an easy way to fix this as soon as he's back. :)
I tried the MUSB_FORCE_HOST thing that MAPGPS posted earlier in this thread, but it did not work for me (and it's probably not the way it is supposed to be done anyway).
 

ela1103

Senior Member
Apr 24, 2011
682
289
83
HEART
So for anyone who is keen enough to try this, here is my modified kernel with USB host support. I also compiled some of the USB storage modules into the kernel.

You have to copy the zImage to /system/bootmenu/2nd-boot/ and the android.hardware.usb.host.xml to /etc/permissions (It's not a flashable zip, sorry!) And don't forget to make a backup first:)

This is based on the AeroKernel from Quarx's latest nightlly, so it should work with the CM10.1/2 builds (tested it on CM10.2).

Please test and report any issues.

What you need:
- USB OTG cable
- Defy does not provide power via USB, you therefore need some sort of external power source for your USB device. The following should work:
- self-powered device (e.g. camera)
- hard disk with Y-cable, second end in external power source
- USB hub with external power source

What works:
- USB hub
- USB keyboard and mouse
- USB mass storage devices (with external app, I tested StickMount)
- disconnecting and reconnecting devices at the hub
- changing from client to host mode and vice versa on OTG cable connect/disconnect

Known issues/what does not work:
- first connect after boot works fine, but reconnecting the OTG cable needs a few (2-4) tries.
- sometimes after using host mode, charger or USB client connection is not detected any more
- when disconnecting a device, the driver sometimes gets stuck in a strange loop and phone must be rebooted



The USB device needs an external power source, but a simple externally powered USB hub with an OTG cable will do.


iam waiting for the couple of years for our motorola defy usb otg .Thank You
 
  • Like
Reactions: srk_srinivas

SlugZero

Member
Sep 11, 2012
38
647
0
OTG without external power

I will not have time to work on this for the next month, so I want to share what I've got until now. I could power and mount an USB stick with the following change:
https://github.com/slugzero/jordan-kernel/commit/45e34e87e48edb47fc46a50ff761d13a51ececf1

This is very unstable, seems like power goes down again after a while. I could browse through the directories on the stick but I could not open any files any more. It also works immediately after boot only, disconnect and reconnect of devices does not work.
Since this may possibly damage your device, I recommend not testing this and also will not provide a compiled kernel until I got this working properly. Everyone who knows what he/she is doing, should be able to compile a kernel himself.

Input devices on the other hand work really nicely, see attached image:)


Btw. I am using the kernel I posted previously for more than one week now and had no issues so far, but I've got the feeling that power consumption is slightly higher. I think this is due to the changes in the musb part, I will have a look at this as soon as I am back.
 

Attachments

ljsh093

Senior Member
May 4, 2013
67
12
0
23
Guiping
I will not have time to work on this for the next month, so I want to share what I've got until now. I could power and mount an USB stick with the following change:
https://github.com/slugzero/jordan-kernel/commit/45e34e87e48edb47fc46a50ff761d13a51ececf1

This is very unstable, seems like power goes down again after a while. I could browse through the directories on the stick but I could not open any files any more. It also works immediately after boot only, disconnect and reconnect of devices does not work.
Since this may possibly damage your device, I recommend not testing this and also will not provide a compiled kernel until I got this working properly. Everyone who knows what he/she is doing, should be able to compile a kernel himself.

Input devices on the other hand work really nicely, see attached image:)


Btw. I am using the kernel I posted previously for more than one week now and had no issues so far, but I've got the feeling that power consumption is slightly higher. I think this is due to the changes in the musb part, I will have a look at this as soon as I am back.
Hello, mester. Thx for ur kernel. Is this mouse powered by dry cell? And can support wireless mouse?

Sorry for my bad English.:(
 
Last edited:

SlugZero

Member
Sep 11, 2012
38
647
0
@SlugZero, thanks for OTG:)
I looked into it and made some fixes., reconnecting works after boot, but not always... And usb works.
If you not mind, after fully fix i can include it in cm builds.

@Quarx, it's me who has to thank you for your awesome work:)

Of course I do not mind if you merge it. And thanks for fixing it!

Is this mouse powered by dry cell? And can support wireless mouse?
@ljsh093, mouse is powered by phone. USB wireless mouse works, but I would recommend using a Bluetooth wireless mouse.
 

SlugZero

Member
Sep 11, 2012
38
647
0
New OTG Kernel

Here is a new version of the OTG kernel based on the latest AeroKernel for Android 4.2/4.3.
I integrated Quarx's fixes and made some more stability fixes which focus on not breaking existing kernel functionality. So as long as you do not connect an OTG cable, you should not notice any difference to the latest AeroKernel.

OTG Features:
  • Switch from regular mode to OTG mode any time by plugging/unplugging cable.
  • Connect devices with power consumption up to 100mA without an external power supply.
  • Connect devices with power consumption up to 200mA without external power supply at your own risk. They might work or might not, or they may break your device. I tried a few USB devices and my Defy is still ok, however some of the devices disconnected after some time, possibly due to voltage drop.
  • Connect any USB device which is supported by Android/Linux Kernel via USB hub with external power supply (might need additional Kernel modules)


Working devices: (i.e. devices I plugged in that worked)
  • Mouse, Keyboard
  • Cordless Mouse
  • USB Flash Drives
  • Camera
  • Joystick :)

Issues in OTG mode:
  • Disconnecting USB devices does not work properly. After unplugging a USB device, the next thing you connect to the USB port will not be detected (no matter if it is a charger, USB cable or USB device). You have to unplug and replug the cable at least once more (sometimes more often). Afterwards, everything works as usual.
  • After unplugging the USB device without removing the OTG cable, other USB devices will not be detected. Always unplug the OTG cable when changing devices
.

Please keep in mind that this feature is not officially supported by Motorola or by anyone, so if it does not work as you'd expect, chances are high that it will never work. I will not work any further on this because I ran out of ideas how to fix the remaining issues (maybe hardware related) and because it works good enough for my purposes already.

If some people here give me positive feedback that this kernel works good for them, I will ask Quarx to merge it.

Edit:
For anyone who is interested in this, I recompiled the OTG kernel with the latest (final?) changes for the 2.6.32 kernel. As development on the 2.6.32 kernel has stopped, there is no point in merging it into Quarx's repository any more. Quarx's 3.0 kernel will support OTG by default:)

Some people reported that connecting works for them only after a fresh boot. Reconnect works as described on my device (MB525 green lens), but it could be different on other devices.
 

Attachments

Last edited:

hoderer

Senior Member
Apr 18, 2013
73
20
0
Just what I was waiting for. THANKS ALOT, SlugZero!!!

EDIT: My USB Competition Pro does work after restarting! Played THE GREAT GIANA SISTERS with an amiga-emulator. GREAT! Plug and unplug serveral times didn't help before, had to restart.

EDIT 2: Somehow I'm not able to mount an USB-stick... the stick is recognized by "usb host controller", but not under "connected mass storange", its under "connected usb-devices" only. See the attached screenshots. Anyone successfully mounted an usb-stick? Any help is appreciated. Thanks alot!
 

Attachments

Last edited:

SlugZero

Member
Sep 11, 2012
38
647
0
Just what I was waiting for. THANKS ALOT, SlugZero!!!

EDIT: My USB Competition Pro does work after restarting! Played THE GREAT GIANA SISTERS with an amiga-emulator. GREAT! Plug and unplug serveral times didn't help before, had to restart.

EDIT 2: Somehow I'm not able to mount an USB-stick... the stick is recognized by "usb host controller", but not under "connected mass storange", its under "connected usb-devices" only. See the attached screenshots. Anyone successfully mounted an usb-stick? Any help is appreciated. Thanks alot!
You're welcome:)

I guess your stick is drawing too much power. I did not find many devices that work with only 100mA (which is what the device appears to provide). Most report that they require at least 200mA, but some of them still worked for me.
As a general recommendation, I would try to connect a new device via externally powered USB hub first, to rule out any driver issues. When this works, try to connect it directly to the phone to see if that works, too.

If the device does not work when you connect it with a hub, enter the following in terminal before connecting, then connect your device and see if the output contains some information that is helpful for you. If not, post the last part of your kmsg.txt here:)
Code:
su
cat /proc/kmsg |tee /sdcard/kmsg.txt
 
  • Like
Reactions: hoderer

supernilz

New member
Oct 23, 2013
3
1
0
I'm having trouble getting OTG.
Is the zip provided by slugzero a flashable zip or do I have to copy it anywhere? A short and simple step-by-step would help very much :)
Thanks alot!