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

Search This thread

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
Build 3 released

Build 3 is the same code as Build 2, but it is built from the original GB/U2 kernel sources with JVU and CF-root 4.3 (link: http://xdaforums.com/showthread.php?t=788108 )

This kernel update works through Odin and does not contain "Usb Host Controller". You can download it from the market though.

One of the most visible changes are that USB 1.x devices do work on this kernel, but their working are a bit strange:

  • If connected straight to the phone they work fine. I've tried a mouse, a keyboard and a wireless mouse+keyboard combo. All three worked, although sometimes I had to unplug and replug them for the phone to recognize them. Mice and keyboards do work out of the box on the JVU version of android though, you will get a nice small mouse cursor, that you can use the same ways as you use it on a PC
  • They do not work if connected through an USB 2.0 hub, they throw the same errors, and won't enumerate
  • You can connect more than one USB 1.x device if you have an USB 1.x HUB though (I found one covered in dust in the attic :) ). I did need to unplug/replug it at least 20 times before all of the devices I connected to it were enumerated properly. After that they did work without problems though. You can also connect USB 2.0 devices to the USB 1.x hub, but they will work with inferior speed of course.

It also seems that some RFS code in the JVU ROM is sometimes trying to do something with the freshly connected flash drive. Doesn't really does anything useful though.

The sources can be found here: https://github.com/sztupy/samsung_kernel_galaxys_gb
They have been "hand ported", so they should apply to any GB kernel source without problems.

Now that I know that usb 1.x devices work I think I'll know why they fail on the CM9 build. Going to fix that.

Download link is at post 6, as usual.
 

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
Build 4

Build 4

Fixed the USB 1.x issue on the CM roms too.

The problem was that since kernel 3.x they started checking whether the root hub has a TT (transaction translator, which is responsible for converting USB 1 signals to USB 2 signals) and they hard coded that USB 2.0 root hubs doesn't have TT's. (quite stupid if you ask me) I haven't really found a way to circumvent this nicely so I simply hardcoded that our device's root hub does have a TT.

The other issues still remain though with USB 1.x devices, but at least external mice and keyboards are working (probably gamepads can be connected too now).

Download link at the usual location.
 

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
Is anybody working on porting this to the Nexus S? If so I can test.
Sorry for my impatience.

I don't know anything about an ongoing Nexus S port. I will help, but only if the following list is true:

  • 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 I need someone with the device to test it for me. If the feedback is positive I'll build versions for that device too, whenever something is changed.

(added this porting checklist to the FAQ too)
 
  • Like
Reactions: Bejda

Dinesen68

Member
Aug 18, 2011
30
1
@sztupy sir i didn't understand your post on build #3... you said that usb 1.x devices (mouse, keyborad,etc...) works when connected directly to the phone??? no need for a hub then... :) so i neeed only otg cable and mouse... YOU sir are LEGEND!!!!!
 

mf_417

Senior Member
Nov 25, 2010
72
11
tanx for great job, is there any future plan for using usb-flash without external power? you know, when connecting a flash to SGS2 it works fine and there is no need for external power.

ps: I know that using devices such as external hard drive will need power, but it seems (at least to me!) that using flash disks will not need any external power.
 

coooolboyz

Member
Jun 23, 2010
45
8
London
tanx for great job, is there any future plan for using usb-flash without external power? you know, when connecting a flash to SGS2 it works fine and there is no need for external power.

ps: I know that using devices such as external hard drive will need power, but it seems (at least to me!) that using flash disks will not need any external power.

I am still hopeful that this can be done. May be the current draw from the USB port is also modifiable. If it can be allowed for a max of 1A draw - even USB HDDs will work :)

Yeah - go ahead, call me a dreamer :D - but my dream of USB host on SGS came true, ain't it? :p
 

caravagio

Senior Member
Dec 2, 2009
83
42
Timisoara
Great work guys! But i have one question:
A friend of mine give me an micro USB to USB male adaptor. Can I use it in some configuration to receive data? Maybe with a USB Y cable!
Or a OTG cable it's a must!

Thank you!

Sent from my GT-I9000 using Tapatalk
 

eruur

Member
Jan 25, 2009
28
5
Paris
First of all fatastic work! I've been dreaming of an USB host driver for months :) So basically you made my dream come true <3

However there is one point I haven't understood. Out of curiosity, how come we need a Y USB cable for DSLR even though the camera has it's own powersource? Wouldn't OTG+µUSB/USB cables work?

Thank you again!
 

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
@sztupy sir i didn't understand your post on build #3... you said that usb 1.x devices (mouse, keyborad,etc...) works when connected directly to the phone??? no need for a hub then... :) so i neeed only otg cable and mouse... YOU sir are LEGEND!!!!!

Sorry, I might have not been clear: you still need external power, just not a hub.
 

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
First of all fatastic work! I've been dreaming of an USB host driver for months :) So basically you made my dream come true <3

However there is one point I haven't understood. Out of curiosity, how come we need a Y USB cable for DSLR even though the camera has it's own powersource? Wouldn't OTG+µUSB/USB cables work?

Thank you again!

Without power on the USB cable the external device won't recognize the phone as connected. You only need a small power (100mA/5V), but that's still more than 0...
 
  • Like
Reactions: eruur

GrNick

Member
Aug 16, 2011
29
7
Athens

Thanx for the GB kernel, had downloaded from your website and gave it a try on JW1. Booted normally, no freezes/reboots as was the case with Semaphore2.6.0beta

Still not working though, had tried the first and second setup (as shown in your photo-diagram). Apparently the hub is recognized but then a series of errors appear, see attached log.
 

Attachments

  • GB-Kernel.txt
    2.4 KB · Views: 46

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
Thanx for the GB kernel, had downloaded from your website and gave it a try on JW1. Booted normally, no freezes/reboots as was the case with Semaphore2.6.0beta

Still not working though, had tried the first and second setup (as shown in your photo-diagram). Apparently the hub is recognized but then a series of errors appear, see attached log.

usb usb1 and hub 1-0:1.0 are the root hubs, so it didn't recognize any external devices connected. And the errors you get are not fatal.

This is what you should see after connecting the OTG cable with power on it:

Code:
<4>[  121.879477] Setting OTG host mode
<6>[  121.880625] otg_dbg: in s5pc110_otg_drv_probe()::00075
<6>[  121.881723] => s3c_otg_drv_probe
<6>[  121.889999] android_work: did not send uevent (0 0   (null))
<4>[  121.911548] otg_host_phy_int : USBPHYCTL=0x1,PHYPWR=0x1c0,PHYCLK=0x7,USBCF
G=0x570f
<6>[  122.012718] s3c_otghcd s3c_otghcd: S3C OTGHCD
<6>[  122.013517] s3c_otghcd s3c_otghcd: new USB bus registered, assigned bus nu
mber 1
<6>[  122.014997] s3c_otghcd s3c_otghcd: irq 88, io mem 0xec000000
<7>[  122.274091] usb usb1: default language 0x0409
<7>[  122.274967] usb usb1: udev 1, busnum 1, minor = 0
<6>[  122.275647] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
<6>[  122.276949] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumb
er=1
<6>[  122.278124] usb usb1: Product: S3C OTGHCD
<6>[  122.278767] usb usb1: Manufacturer: Linux 3.0.8-I9000XXJVU-CL851880-gdf30d
e5-dirty EMSP_OTGHCD
<6>[  122.279944] usb usb1: SerialNumber: s3cotg
<7>[  122.301682] usb usb1: usb_probe_device
<7>[  122.302412] usb usb1: configuration #1 chosen from 1 choice
<7>[  122.304081] usb usb1: adding 1-0:1.0 (config #1, interface 0)
<7>[  122.305607] hub 1-0:1.0: usb_probe_interface
<7>[  122.306720] hub 1-0:1.0: usb_probe_interface - got id
<6>[  122.307386] hub 1-0:1.0: USB hub found
<6>[  122.308699] hub 1-0:1.0: 1 port detected
<7>[  122.309356] hub 1-0:1.0: standalone hub
<7>[  122.309982] hub 1-0:1.0: ganged power switching
<7>[  122.311085] hub 1-0:1.0: global over-current protection
<7>[  122.311870] hub 1-0:1.0: Single TT
<7>[  122.312518] hub 1-0:1.0: TT requires at most 32 FS bit times (2664 ns)
<7>[  122.313676] hub 1-0:1.0: power on to power good time: 0ms
<7>[  122.314417] hub 1-0:1.0: local power source is good
<7>[  122.315634] hub 1-0:1.0: no over-current condition exists
<7>[  122.316312] hub 1-0:1.0: enabling power on all ports
<6>[  122.317440] otg_dbg: in root_hub_feature()::00477
<6>[  122.318086] => case SetPortFeature -USB_PORT_FEAT_POWER
<6>[  122.321182] otg_dbg: in s5pc110_otg_drv_probe()::00175
<6>[  122.321904] => OTG HCD Initialized HCD, bus=C110 OTG Controller, usbbus=1
<4>[  122.324111] platform_driver_register...
<6>[  122.419719] otg_dbg: in otg_handle_interrupt()::00087
<6>[  122.419848] => Port Interrupt
<6>[  122.420080] otg_dbg: in process_port_intr()::00276
<6>[  122.420193] => over current condition is changed
<3>[  122.420457] otg_err: in otg_power_work()::00064
<3>[  122.420569] => invalid otghost data
<7>[  122.421154] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0000

If you see the above then the driver has initialized. Now if you connect a device you should see something like this:

Code:
<7>[  267.710401] hub 1-0:1.0: port 1, status 0101, change 0000, 12 Mb/s
<6>[  267.710537] otg_dbg: in root_hub_feature()::00483
<6>[  267.710697] => case SetPortFeature -USB_PORT_FEAT_RESET
<6>[  267.770828] otg_dbg: in otg_handle_interrupt()::00087
<6>[  267.770979] => Port Interrupt
<6>[  267.771126] otg_dbg: in process_port_intr()::00271
<6>[  267.771224] => port enable/disable changed
<6>[  267.898307] usb 1-1: new high speed USB device number 2 using s3c_otghcd
<6>[  267.903381] otg_dbg: in root_hub_feature()::00483
<6>[  267.903581] => case SetPortFeature -USB_PORT_FEAT_RESET
<7>[  268.032346] usb 1-1: default language 0x0409
<7>[  268.040267] usb 1-1: udev 2, busnum 1, minor = 1
<6>[  268.040655] usb 1-1: New USB device found, idVendor=0bda, idProduct=0158
<6>[  268.041295] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumbe
r=3
<6>[  268.041700] usb 1-1: Product: USB2.0-CRW
<6>[  268.044172] usb 1-1: Manufacturer: Generic
<6>[  268.044534] usb 1-1: SerialNumber: 20060413092100000
<7>[  268.051383] usb 1-1: usb_probe_device
<7>[  268.053385] usb 1-1: configuration #1 chosen from 1 choice
<7>[  268.056127] usb 1-1: adding 1-1:1.0 (config #1, interface 0)
<7>[  268.064331] usb-storage 1-1:1.0: usb_probe_interface
<7>[  268.064781] usb-storage 1-1:1.0: usb_probe_interface - got id
<6>[  268.067598] scsi0 : usb-storage 1-1:1.0
<7>[  268.076137] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0002
<7>[  268.084306] hub 1-0:1.0: port 1 enable change, status 00000503
<7>[  268.084728] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0000
<5>[  269.095521] scsi 0:0:0:0: Direct-Access     Generic- Multi-Card       1.00
 PQ: 0 ANSI: 0 CCS
<5>[  269.096291] sd 0:0:0:0: Attached scsi generic sg0 type 0
<5>[  269.898271] sd 0:0:0:0: [sda] 32372736 512-byte logical blocks: (16.5 GB/1
5.4 GiB)
<5>[  269.901262] sd 0:0:0:0: [sda] Write Protect is off
<7>[  269.904633] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
<3>[  269.907291] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.908459] sd 0:0:0:0: [sda] Assuming drive cache: write through
<3>[  269.935427] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.939397] sd 0:0:0:0: [sda] Assuming drive cache: write through
<6>[  269.947403]  sda: sda1
<3>[  269.991071] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.992633] sd 0:0:0:0: [sda] Assuming drive cache: write through
<5>[  269.992804] sd 0:0:0:0: [sda] Attached SCSI removable disk

If this doesn't happen, then try to setting the mode to "client" in UHC, then back to "OTG" (while all devices are connected).
 

Epic_VS

Senior Member
Dec 6, 2011
173
42
The kernel source is avialable on github. It is either a kernel for gingerbread (>=2.6.35) or for ICS (>=3.0)
The stock kernel source is available, but not at github: git://android.git.kernel.org/kernel/samsung.git

Mathkid95's kernel source is available at git hub though:
ICS: https://github.com/mathkid95/linux_samsung_ics_real
GB: https://github.com/mathkid95/linux_samsung

It also contains (or has links to) the initramfs and all the other files needed to create an update.
I don't really know what you are talking about, but I found these links:
http://xdaforums.com/showthread.php?t=875184
http://forums.androidcentral.com/t-.../48675-how-compile-nexus-s-kernel-source.html


If creating the update is not straightforward I also need a script to do this for me
If my knowledge is correct, can't you just unzip a kernel update and replace the zImage.


After the update is made I need someone with the device to test it for me. If the feedback is positive I'll build versions for that device too, whenever something is changed.

You will have a lot of testers on the Nexus S SubForums
 

coooolboyz

Member
Jun 23, 2010
45
8
London
Hi sztupy

In the below log files - I see - "PHYPWR=0x1c0" - I remember seeing [in the S5PC110 manual] something like set the value to 0x1b1 or 0x1b0 for powering the connected devices.

Now I am not sure if this can be changed - or if I am way of the mark and making a very stupid dance in front of the whole world. My apologies if that's the case.

But do you think this is something which can be pursued to give peripherals their own power from the phone? I hope I'm not pestering you too much.

usb usb1 and hub 1-0:1.0 are the root hubs, so it didn't recognize any external devices connected. And the errors you get are not fatal.

This is what you should see after connecting the OTG cable with power on it:

Code:
<4>[  121.879477] Setting OTG host mode
<6>[  121.880625] otg_dbg: in s5pc110_otg_drv_probe()::00075
<6>[  121.881723] => s3c_otg_drv_probe
<6>[  121.889999] android_work: did not send uevent (0 0   (null))
<4>[  121.911548] otg_host_phy_int : USBPHYCTL=0x1,PHYPWR=0x1c0,PHYCLK=0x7,USBCF
G=0x570f
<6>[  122.012718] s3c_otghcd s3c_otghcd: S3C OTGHCD
<6>[  122.013517] s3c_otghcd s3c_otghcd: new USB bus registered, assigned bus nu
mber 1
<6>[  122.014997] s3c_otghcd s3c_otghcd: irq 88, io mem 0xec000000
<7>[  122.274091] usb usb1: default language 0x0409
<7>[  122.274967] usb usb1: udev 1, busnum 1, minor = 0
<6>[  122.275647] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
<6>[  122.276949] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumb
er=1
<6>[  122.278124] usb usb1: Product: S3C OTGHCD
<6>[  122.278767] usb usb1: Manufacturer: Linux 3.0.8-I9000XXJVU-CL851880-gdf30d
e5-dirty EMSP_OTGHCD
<6>[  122.279944] usb usb1: SerialNumber: s3cotg
<7>[  122.301682] usb usb1: usb_probe_device
<7>[  122.302412] usb usb1: configuration #1 chosen from 1 choice
<7>[  122.304081] usb usb1: adding 1-0:1.0 (config #1, interface 0)
<7>[  122.305607] hub 1-0:1.0: usb_probe_interface
<7>[  122.306720] hub 1-0:1.0: usb_probe_interface - got id
<6>[  122.307386] hub 1-0:1.0: USB hub found
<6>[  122.308699] hub 1-0:1.0: 1 port detected
<7>[  122.309356] hub 1-0:1.0: standalone hub
<7>[  122.309982] hub 1-0:1.0: ganged power switching
<7>[  122.311085] hub 1-0:1.0: global over-current protection
<7>[  122.311870] hub 1-0:1.0: Single TT
<7>[  122.312518] hub 1-0:1.0: TT requires at most 32 FS bit times (2664 ns)
<7>[  122.313676] hub 1-0:1.0: power on to power good time: 0ms
<7>[  122.314417] hub 1-0:1.0: local power source is good
<7>[  122.315634] hub 1-0:1.0: no over-current condition exists
<7>[  122.316312] hub 1-0:1.0: enabling power on all ports
<6>[  122.317440] otg_dbg: in root_hub_feature()::00477
<6>[  122.318086] => case SetPortFeature -USB_PORT_FEAT_POWER
<6>[  122.321182] otg_dbg: in s5pc110_otg_drv_probe()::00175
<6>[  122.321904] => OTG HCD Initialized HCD, bus=C110 OTG Controller, usbbus=1
<4>[  122.324111] platform_driver_register...
<6>[  122.419719] otg_dbg: in otg_handle_interrupt()::00087
<6>[  122.419848] => Port Interrupt
<6>[  122.420080] otg_dbg: in process_port_intr()::00276
<6>[  122.420193] => over current condition is changed
<3>[  122.420457] otg_err: in otg_power_work()::00064
<3>[  122.420569] => invalid otghost data
<7>[  122.421154] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0000

If you see the above then the driver has initialized. Now if you connect a device you should see something like this:

Code:
<7>[  267.710401] hub 1-0:1.0: port 1, status 0101, change 0000, 12 Mb/s
<6>[  267.710537] otg_dbg: in root_hub_feature()::00483
<6>[  267.710697] => case SetPortFeature -USB_PORT_FEAT_RESET
<6>[  267.770828] otg_dbg: in otg_handle_interrupt()::00087
<6>[  267.770979] => Port Interrupt
<6>[  267.771126] otg_dbg: in process_port_intr()::00271
<6>[  267.771224] => port enable/disable changed
<6>[  267.898307] usb 1-1: new high speed USB device number 2 using s3c_otghcd
<6>[  267.903381] otg_dbg: in root_hub_feature()::00483
<6>[  267.903581] => case SetPortFeature -USB_PORT_FEAT_RESET
<7>[  268.032346] usb 1-1: default language 0x0409
<7>[  268.040267] usb 1-1: udev 2, busnum 1, minor = 1
<6>[  268.040655] usb 1-1: New USB device found, idVendor=0bda, idProduct=0158
<6>[  268.041295] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumbe
r=3
<6>[  268.041700] usb 1-1: Product: USB2.0-CRW
<6>[  268.044172] usb 1-1: Manufacturer: Generic
<6>[  268.044534] usb 1-1: SerialNumber: 20060413092100000
<7>[  268.051383] usb 1-1: usb_probe_device
<7>[  268.053385] usb 1-1: configuration #1 chosen from 1 choice
<7>[  268.056127] usb 1-1: adding 1-1:1.0 (config #1, interface 0)
<7>[  268.064331] usb-storage 1-1:1.0: usb_probe_interface
<7>[  268.064781] usb-storage 1-1:1.0: usb_probe_interface - got id
<6>[  268.067598] scsi0 : usb-storage 1-1:1.0
<7>[  268.076137] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0002
<7>[  268.084306] hub 1-0:1.0: port 1 enable change, status 00000503
<7>[  268.084728] hub 1-0:1.0: state 7 ports 1 chg 0000 evt 0000
<5>[  269.095521] scsi 0:0:0:0: Direct-Access     Generic- Multi-Card       1.00
 PQ: 0 ANSI: 0 CCS
<5>[  269.096291] sd 0:0:0:0: Attached scsi generic sg0 type 0
<5>[  269.898271] sd 0:0:0:0: [sda] 32372736 512-byte logical blocks: (16.5 GB/1
5.4 GiB)
<5>[  269.901262] sd 0:0:0:0: [sda] Write Protect is off
<7>[  269.904633] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
<3>[  269.907291] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.908459] sd 0:0:0:0: [sda] Assuming drive cache: write through
<3>[  269.935427] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.939397] sd 0:0:0:0: [sda] Assuming drive cache: write through
<6>[  269.947403]  sda: sda1
<3>[  269.991071] sd 0:0:0:0: [sda] No Caching mode page present
<3>[  269.992633] sd 0:0:0:0: [sda] Assuming drive cache: write through
<5>[  269.992804] sd 0:0:0:0: [sda] Attached SCSI removable disk

If this doesn't happen, then try to setting the mode to "client" in UHC, then back to "OTG" (while all devices are connected).


---------- Post added at 03:12 PM ---------- Previous post was at 03:04 PM ----------

I just did a quick search and found the manual here - http://pdadb.net/download/samsung_s5pc110_manual_en.rar

In all possibility, you may already know this - but please have a look at Page Numbers 880 and then 387.

Hopefully that may help us all?

:)
 
  • Like
Reactions: sztupy

sztupy

Inactive Recognized Developer
Dec 21, 2008
1,061
877
Edinburgh
sztupy.hu
Hi sztupy
In the below log files - I see - "PHYPWR=0x1c0" - I remember seeing [in the S5PC110 manual] something like set the value to 0x1b1 or 0x1b0 for powering the connected devices.

Hi!

Thanks for the link, I haven't seen that it contains specification to the USBPHYPWR register. This was a part where there was a difference between the SGS2 and the SGS1 usb host implementation: the PIN 5. Well the manual was not really a big help though:

Code:
Reserved  [5]  Reserved, but should be 0x1

The SGS2 AP documentation says nothing about this register unfortunately: http://www.samsung.com/global/syste.../2/738994Pulbicmanual_Exynos4210_Ver00001.pdf

SGS2 actually set this bit as 0 and not 1. I don't know if I should revert the changes to the code and set it as 1 as it was used to be.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 144
    USB Host mode driver for Samsung Galaxy S (i9000)

    Also available on the Samsung Captivate and Nexus S
    Vibrant and i9000B builds are avialable in some onecosmic kernels

    Disclaimer: This kernel will enable some very early, and rough usb OTG support for your phone. Currently the phone DOES NOT give out power, so you NEED an external power source to be able to use this kernel. This is true for ALL USB devices, even with those that have their own power source, and doesn't requre external bus powering. Solving this limitation is a TODO, but we cannot guarantee anything. There are some other phones that have usb host support the same way this kernel has (eg. they need external power), like the Nexus One, and there is also a community using this, so if you're saying that usb host support has no sense if you need an external power source then you are definitely mistaken.

    This kernel is built upon teamhacksung's ICS Build 14 kernel, and will only work with that particular ROM (and later b15 and b16 versions of it). There is also a build for stock JVU (Gingerbread). It is possible to port this to older ROMs too (like CM7, or pre-GB ROMs). Ask your favourite kernel developer to do this for you. I only plan to support the CM9 and the stock Gingerbread version.

    The patches are quite device-independent, so they should also work for other similar handsets, like all SGS variants (Captivate, Vibrant, epic, etc.), and also some distant relatives like the Nexus S, or the Galaxy Tab. I do not own these handsets, so you have to ask your favourite kernel developer to port the changesets to the other variants. I have already a build script for Captivate (CM9) and Nexus S (ICS) ports.

    I might also try to create kernels for other devices if the following are true:
    • 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 I need someone with the device to test it for me. If the feedback is positive I'll build versions for that device too, whenever something is changed.

    Credits goes to:
    • The misterious guy at Samsung(?) called chul2 for the original s3c host drivers
    • Kevin Hester (kevinh, probably also nicknamed geeksville, punkgeek and humcycles) for fixing the s3c host driver for the Samsung Galaxy Tab
    • Ever kernel developer at teamhacksung for bringing ICS goodness to Galaxy S

    This is a very early, and very rough usb host support. Expect crashes, freezes and things that are not working! You will also need external power (probably through a Y-cable or a powered usb hub, see the device connection guide below). Also make sure you are only using USB 2.0 (high-speed) devices. The driver does has some quirks with USB 1.x low-speed and full-speed devices, like mice, keyboards, gamepads and similar things. Read the FAQ for more information about them. And of course it doesn't work with USB 3.0 (super-speed) devices.

    Device conection guide:

    attachment.php


    FAQ: see post 2
    ChangeLog: see post 3
    Developer notes: see post 4
    Download links: see post 6

    Usb Host Controller: see it's own topic
    48
    FAQ!

    Terminology
    • 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:
    attachment.php


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


    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
      • CM9 / ICS
    • Nexus S
      • (official) ICS 4.0.3

    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://xdaforums.com/showpost.php?p=21673976&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:

    Code:
    > adb connect 192.168.1.100     (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://xdaforums.com/showpost.php?p=21686936&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.
    29
    Downloads

    Downloads

    CWM Kernel Update:

    Odin kernel updates:

    Usb Host Controller:
    All releases can be found here: http://xdaforums.com/showthread.php?t=1468531

    Directory listing of all released files: http://android.sztupy.hu/dl/usbhost/

    Source code of kernel driver:
    If you build a kernel that use the above source, please also link to Usb Host Controller and this topic, because without them the modification is not really usable for an end-user! If you do link both, and also drop me a PM, I will add your kernel to this list.

    External resources:
    28
    ChangeLog

    ChangeLog

    28
    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:

    Code:
    /sys/devices/platform/s3c-usbgadget/opmode

    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:

    Code:
    /sys/devices/platform/s3c-usbgadget/hostdriver

    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)