yashsingh1/xdaforums huggingface dataset:
[Galaxy S I9000 Android Development] handarmbeinfuss:
usb modules are loading

Hi all!

Some progress:

I got the three modules, that seem to be important for USB client, to compile and load on the phone. s3c_udc_otg, g_android, and max8998_usbstuff. The last one is the wrapper that I created to split the usb dependent stuff from the independent things that may remain in the kernel.

This is great because it means that the regulator will start charging the battery again once a usb cable is plugged in. Before I was watching the battery indicator slowly dwindling...

USB debugging works after the three modules are loaded. USB storage does not. I don't know why, yet. Also g_android doesn't rmmod cleanly. I found this in the sources

/*
<------>Google gadget doesn't support module type building
static int __exit android_unbind(struct usb_composite_dev *cdev)
{
<------>gserial_cleanup();
<------>return 0;
}
*/

The hell with them. I might just use g_storage instead. I don't really need the USB debugging anyway. And that seems to be the only noteworthy difference between g_android and g_storage (if you ignore modem support, Samsung Kies, and the network endpoint).

Also, I got the S3C_OTG_HCD stuff to compile. It loads on the phone without errors. But it doesn't do anything. The debugging output stops right after it loads. Not even the probe call shows any output.

@coooolboyz:

I don't really consider it a problem that the i9000 doesn't support USB client and host at the same time. You can have one one cable plugged in anyway. And while you are switching them, you might just unload and load the other module as well. I guesss someone could even write a neat app for that. Or it might eventually be possible to use the present detection circuitry to determing what kind of USB device is connected and load the appropriate module automatically...

About compiling OHCI: I found a git repository that contains a different kernel source tree.

git.tarot.com.tw/android-ctc/kernel.git

There they have the OHCI enabled for S5CP1XX devices. The I9000 registers as S5CP11X. So I figured I might just add the neccessary platform and arch tags and, voila: OHCI_HCD compiles and loads on the phone. But once again, nothing happens.

On second thought, I don't even know, what's supposed to happen. On my Linux box, there are a bunch of entries in /sys/bus/usb/devices. They correspond to the root hubs of the USB controllers and they appear once UHCI_HCD and EHCI_HCD are loaded. On the i9000 no such files are present after either OHCI_HCD or S3C_OTG_HCD are loaded.

Well. That's it for now.

Anyone know what else (besides the files in /sys/bus/usb/devices appearing) is supposed to happen, when there's a USB root hub driver loaded?
[Galaxy S I9000 Android Development] coooolboyz:
That is very good. I too did load the S3C_OTG_HCD stuff on my phone, but nothing happened. I was pinning my hopes on getting the OHCI_HCD driver installed. But now that you are saying that even this does not work, I guess, I can forget my experiments in that direction.

Yes that cable detection is exactly what I had in my mind. I am guessing that cable detection works by seeing the output from dmesg. :D We should only have to connect the right cable to get the right functionality. :)

Before we move ahead in a different direction - let me ask you one thing - did you set the max power draw from USB port to 500mA? It would be good to know if OHCI/EHCI would (or would not) work with a higher power draw from USB port. I am saying this because even flash drives need 70/80 mA of power and by default our phones are set to allow a power draw of 2 mA only. The plugged in USB device may not get recognised due to this.
[Galaxy S I9000 Android Development] husq510:
it would be nice to have, yeah. You tried with pendrive w/o need of additional power ?
[Galaxy S I9000 Android Development] handarmbeinfuss:
Hm. If you are talking about USB_GADGET_VBUS_DRAW, I don't think this is for supplying power. It belongs to the gadged driver. So I would assume this is to specify how much power the phone is supposed to draw from a host. I'm not sure, if the device was made to supply power at all. You might need an external power supply (powered usb hub) for that. Also, as the guys working in the Nexus One showed, you even might need to supply the uplink port of a USB hub with external power. I haven't even looked into the hardware side of the issue, yet. I'll do that once I have working modules.

BTW. I remembered what you said about the Odroid. At least the Odroid-T (tablet) seems to have USB host built in. So I searched around for its kernel sources. They can be found here

dev.odroid.com/frs/download.php/50/odroid-c110-kernel-20100727.tar.gz

It seems like they don't use the S3C_OTG_HCD at all. But rather they have module parts

ehci-s5pc110.c and ohci-s5pc110.c. With those (and some tweaking of the Makefiles), the ochi and ehci driver compile. However there are still a few symbols missing in the kernel. They are for powering on and off of the USB host part in the CPU. They are available in the mach-smdkc110 variety of the s5pc110 chip. The i9000, however, has a mach-jupiter board. And there, these symbols are missing. I could just patch over the two functions usb_host_phy_init and usb_host_phy_off, but I am a bit afraid to do so, until I know what side effects they might cause. Besides there might be a number of undefined register variables and the like. This is pretty low level, close to the hardware stuff...

so long
[Galaxy S I9000 Android Development] coooolboyz:
Aaah! It was a silly mistake from me. I should be more careful next time. :)

Thanks a lot for the Odroid source code. I tried looking for that, but couldn't find it. I have downloaded it but got no time to check that out.

Even though the boards are different, I am sure that we should be able to hack this code to work on SGS - who knows may be even cable sensing would work!

And on a side note - there does seem that there is a genuine interest in the community for USB Host/OTG support. I could see quite a few requests for this feature. :)

But this is a slow and painful process - as the risks of getting the phone damaged are quite high. :(
[Galaxy S I9000 Android Development] 19arek93:
What about Samsung help in this case? Maybe they will tell us something interesting, just need to talk with right person. You (really thank you!) are trying to add an extra functionality to the phone.

Good luck!
[Galaxy S I9000 Android Development] royleecn:
Actually I posted the same question few days ago and sorry did not notice your post.

I had a device called Smart Q5, using the S3C6410 as the CPU and its 2.0ROM developed by a Japanese Org. called Covia supports USB HOST, Client Mod, and ADB Mod. And of cause I had this ROM with me.

I am not a guy who can DIY ROM, but I hope I can do something for you.

Up! Up! Hope this USB HOST function would come to our Android ROM.
[Galaxy S I9000 Android Development] deezy7:
Bumpbumpbump!!

I would LOVE to have this feature!! If anyone is working on this out there, please accept my gratitude in advance!!!
[Galaxy S I9000 Android Development] 19arek93:
I see that we must wait. Maybe someone in the future will do this for us.
[Galaxy S I9000 Android Development] smazenka:
Im interested TOOOO '!!!!! exactly looking for possibility connect external card via usb.

Unfortunsatelly im only able to cross fingers for U;)
[Galaxy S I9000 Android Development] handarmbeinfuss:
ehci and ohci from odroid-t sources

Hi all!

Just to give you a heads up, and in case anyone else is working on this:

I got the module parts from the Odroid-T sources for ehci-hcd and ohci-hcd to compile. Quite a few dependencies that need resolving again. But it's doable. But that's where it ended for now.

Upon modprobing either of the two modules, my i9000 reboots. From what I could determine until now, it happens somewhere inside clk_get() in line 181 of ohci-s5pc110.c

usb_clk = clk_get(&pdev->dev, "usb-host");

I haven't dug further, yet. So I neither know why nor how it happens. Figuring this out is pretty slow since after each step I take, I need to wait for the device to boot, load dropbear, connect to the device, copy the modified modules, load them, and see if the device crashes again.

And now my wifi stopped working. Must be a side effect of the crashes. Maybe the filesystem got skewed during the last crash or something.

Anyone interested to try to fiddle around with this stuff? Should I make this a public git repository?

so long...
[Galaxy S I9000 Android Development] handarmbeinfuss:
Covia SmartQ5

Say, if you had this device, do you read Japanese?

I was unable to find an "English" button or something on the Covia website.

www.covia.net/main/product-smartq5.html

So if you could find a download link for kernel sources, I'd much appreciate a hint. (I am afraid, the ROMs won't be of much use.)

Cheers.
[Galaxy S I9000 Android Development] Bec07:
Would be really awesome to get this working!
[Galaxy S I9000 Android Development] handarmbeinfuss:
usb clocks

Hi all!

this is frustrating. can't get this to work. I don't know why the device crashes. And even the exact point in the code where it crashes is hard to determine.

Anyone have an idea how one might go about debugging this? I mean besides putting printk's into the code and see until which of them it runs?

so long...
[Galaxy S I9000 Android Development] Bec07:
Here's some help, kinda:

On N900 (linux) some devs were trying the exact same thing and they managed to randomly replicate the host thingy without external power by the time I left: https://garage.maemo.org/projects/h-e-n/

Maybe since this is being done at kernel level could be of some help.
[Galaxy S I9000 Android Development] ttabbal:
Please do, I started looking into it for the Vibrant and figured you guys might have a head start, looks like you do. I'd love to see where you are at compared to my little experiments, mostly around getting the host mode drivers to build.
[Galaxy S I9000 Android Development] handarmbeinfuss:
github repository

ok. I finally found some time to upload all of this to github. so if anyone would like to try this out, be my guest.

HOWEVER:

Once you flash this kernel to the device, USB client will stop working. You won't even be able to charge the device without loading some modules by hand. You need to find a way to log in and do that (the terminal is a pain to work with. I use dropbear ssh server). IF THE BATTERY RUNS LOW BEFORE YOU FLASH BACK THE ORIGINAL KERNEL OR YOU MANAGED TO LOAD THE PROPER CLIENT MODULES, YOU MIGHT NOT BE ABLE TO RECOVER THE PHONE. There seems to be some protection against this in the kernel (low power shutdown and the like) but I'm not sure how this works and if you can still run the bootloader for re-flashing under these circumstances.

But for anyone willing to try. Here it goes:

mkdir kernelsource
cd kernelsource
wget "http://www.codesourcery.com/sgpp/lite/arm/portal/package6493/public/arm-none-eabi/arm-2010q1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2"
tar -xjvf arm-2010q1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

git clone git://github.com/handarmbeinfuss/i9000-initramfs.git
cd i9000-initramfs

now modify the file initramfs_list. replace all occurences of YOURNAME with your username

cd ..

git clone git://github.com/handarmbeinfuss/i9000-kernel.git
cd i9000-kernel
git checkout odroid-t-mod
make ARCH=arm aries_rev03_defconfig
make menuconfig

select the following options:

General Setup ->
Initial RAM filesystem and RAM disk (initramfs/initrd) support [*]
Initramfs source file(s)
(FULL PATH TO THE ABOVE EDITED initramfs_list)
System Type -> Mach S5PC110 Jupiter Board USB phy <M>
Device Drivers ->
USB Support ->
Support For Host Side USB <M>
EHCI HCD (USB 2.0) support <M>
OHCI HCD support <M>
USB Mass Storage support <M>
USB Gadget Support ->
S3C high speed(2.0, dual-speed) USB OTG device <M>
USB Gadget Drivers <M>
Android Gadget <M>
Voltage and Current Regulator Support ->
Maxim 8998 voltage regulator usb dependent stuff <M>

exit and save

make HOSTCFLAGS="-g -O2" ARCH=arm CROSS_COMPILE=../arm-2010q1/bin/arm-none-eabi- modules
make HOSTCFLAGS="-g -O2" ARCH=arm CROSS_COMPILE=../arm-2010q1/bin/arm-none-eabi- zImage

in arch/arm/boot there is a file zImage. This can be converted to a PDA file for Odin with

tar -cvf regulatorsplitkernel_PDA.tar zImage

this has to be flashed to the i9000

also the files

drivers/usb/host/ohci-hcd.ko
drivers/usb/host/ehci-hcd.ko
drivers/usb/gadget/s3c_udc_otg.ko
drivers/usb/gadget/g_android.ko
drivers/regulator/max8998_usbstuff.ko
arch/arm/mach-s5pc110/mach-jupiter-usb.ko

need to be copied to /system/lib/modules/2.6.29

then a run of

depmod

creates the module dependency file

now

modprobe max8998_usbstuff

will load the client side of things (this allows charging of the phone)

and

modprobe ohci-hcd

will load the host side. THIS WILL REBOOT THE DEVICE!!!

No success in getting USB host to work, yet. Any suggestions are welcome.

BTW: does anyone here know a good way to flash kernels from linux? or even better use the fastboot option of adb? I read somewhere this wasn't supported by the i9000...

so long
[Galaxy S I9000 Android Development] 19arek93:
Bump. Any devs with free time? ;)
[Galaxy S I9000 Android Development] deezy7:
Just bumping this up...I'd love for USB Host to become a reality on our phones, and you guys are making some incredible progress in here...
[Galaxy S I9000 Android Development] dt9394:
did u compile it using samsung official froyo source? I have successful compile the kernel using ur initramfs. I will try to flash it tonight.

(compiled busybox + su and added into initramfs)

Just pray it didnt brick my phone. :X

PS: the default kernel .config have usb driver compile inside kernel. Dont think i can load the usb module if anything went wrong...
[Galaxy S I9000 Android Development] 19arek93:
And.... ? :)
[Galaxy S I9000 Android Development] deezy7:
I'm wondering too :)
[Galaxy S I9000 Android Development] 19arek93:
And the thread is dead. :/
[Galaxy S I9000 Android Development] Arise:
Wake up baby, don't die!

With the proper custom cables/jacks expanding storage with usb sticks would be awesome.
[Galaxy S I9000 Android Development] Bec07:
N900 has gotten the support through various hacks,,, http://talk.maemo.org/showthread.php?t=65232

This is very doable with no need for an external power supply: https://garage.maemo.org/projects/h-e-n/

All we need is a very skilled team of devs, this is truly no easy thing!

The H-E-N project took around 8 months to reach beta state...
[Galaxy S I9000 Android Development] Arise:
Regarding the switching application, from client/host USB: I would be glad to give up at some USB menu option that runs when I plug the USB cable like Kies mode or wifi tethering and instead of those to switch to some usb hosting mode if adding new options is not possible.

Anyway... the work must be done in kernel.
[Galaxy S I9000 Android Development] 19arek93:
ehh.. bump.
[Galaxy S I9000 Android Development] Arise:
This one looks like a proper microUSB to Female A USB cable also OTG ready! Not very sure but looks like any other cable/adapter must have some pins soldered to work in OTG mode.

But I know for sure this aint cheap! Only shipping costs me a flat $60.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&itemSeq=93054478&uq=634253978375364040

Also, it seems there is a Nokia accessory, called Nokia CA-157. Don't know the wiring inside, but I guess this is just fine for our purpose.

A Nokia N8 with such a cable: http://twitpic.com/22x0q8
[Galaxy S I9000 Android Development] Bec07:
Cable is useless without the software.

I bought an adapter for 5$ +5 shipping off ebay and it's useless for now.

Also you can get an USB female to female adapter and use your default cable. 2-3$ at any hardware store.
[Galaxy S I9000 Android Development] handarmbeinfuss:
more kernel sources please

hi all!

ok. i didn't find much time to look into this during the past month or so. so no progress, yet. I i might be able to devote more time to it in the coming weeks. so bear with me.

@dt9394: i didn't know there were froyo sources out. I just used the ones from GT-I9000_OpenSource.zip from opensource.samsung.com

I'll have a look at the new ones and try to figure out what they changed.

did you use the original Samsung sources for compiling the kernel or did you use my git repository?

and did you get the phone to boot with your kernel? anything interesting happening?

@everyone: unfortunately no one seems to want to help with the kernel hacking. well. if anyone has some spare time, i'd appreciate hints to other mobile devices with the s5pc110 chipset that are known to have usb host and for which kernel sources are available for download. so far i only know of the odroid-t. but its sources are somewhat different from those of the i9000. and I don't know why loading the modules from the odroid-t causes my phone to reboot. if there were others out there, i might be able to compare those and find whatever i'm missing.

over and out
[Galaxy S I9000 Android Development] bergfex:
whats about the KIT-S5PC110 or the KIT S5PV210 Evaluation Board?

At least the KIT S5PV210 should have a USB OTG driver but it does use a S5PV210AH-A0 SoC.

..w.boardcon.com/KIT%20S5PV210.html
[Galaxy S I9000 Android Development] Arise:
Yeah, I also had in mind that KIT S5PV210 Evaluation Board. We need to get a hold on the drivers. Don't know if they are somewhere on the net floating, or they are just on their CD bundled with the board.

I don't believe the OTG cable is just a normal cable that has an USB A female on one end. Seems the wires inside are soldered a little bit different.

This is the reason why I think it could work out of the box with some proper cable or with minor interventions on the kernel.

I've attached a picture of my old cable custom made by some friend that I've used with great success in the past on my PDA: Fujitsu Siemens Loox 720. But that one used a custom connector with lots of pins and some of them were for USB client and some other for USB Host.
[Galaxy S I9000 Android Development] TheBeano:
Hi guys, regarding the cable, the USB switching chip (FSA9480) is set up to detect an OTG cable that has pin 4 and pin 5 on the micro-USB (ID and GND) shorted together. This triggers an interrupt from the USB switching chip and you will see in "USB OTG" in the kernel log. See fsa9480_i2c.c in the source code.

It looks like there is nothing actually coded to happen there (in Froyo) when it detects the cable, but at least it would be a way of detecting the cable and switching to OTG mode.
[Galaxy S I9000 Android Development] Arise:
So, am I right when I assume we need a real OTG cable with pins soldered different than from the standard cable?

We can't do much with connecting two straight adapters like in the attached image. Right?
[Galaxy S I9000 Android Development] TheBeano:
The other pins are the same as regular usb cables, it's just that pins 4 and 5 are shorted together on one end of the OTG cable. See figure 2 in this article. You can either modify a standard cable or buy a special one.

Because you're going to need to modify the kernel to support this anyway you could just have a software switch for OTG mode and not rely on the cable detection, then you can just use the above adapters or dual-female adapters with standard cables.
[Galaxy S I9000 Android Development] Arise:
This guy created some patches but those are for qualcomm. I think won't help us too much.

Offtopic:

http://imgs.xkcd.com/comics/surgery.png
[Galaxy S I9000 Android Development] Arise:
Just took a look at the latest kernel source from odroid, and inside there are no longer the files:

ehci-s5pc110.c and ohci-s5pc110.c.

Now there seems to be some new files, like: ehci-s5pv210.c and ohci-s5pv210.c

Most changes seems to be related to just mass replacing of c110 with pv210, but also some extra code changes.

Don't know if I'm wrong, maybe I've downloaded the wrong kernel for the wrong board but double checked and the files with s5pv210 seems to be related to the same product.
[Galaxy S I9000 Android Development] handarmbeinfuss:
samsung froyo sources

hm. that would be consistent with the "new" samsung froyo sources. I hadn't seen those before. but they are a lot more promising than the old ones. the s5pv210 is sort of the sister chip of the i9000's s5pc110. although it is targeted more at netbooks, they seem very similar. and from what i can tell, samsung seems to want to keep both of their kernel code bases together.

anyway. there are now ehci modules in the samsung sources, although they are not compiled by default. if you activate them, they compile without any problems. they also load without problems on the device. they don't do anything, however. that is because for some reason the corresponding s5pv210-ehci device is not created by the kernel upon boot. i don't know why that is. i tried hijacking another device that is unused so far (s5p-cec). which caused the module to actually probe the usb hardware. but it ended up in tons of "coherent DMA mask is unset" error messages and insmod not returning to the shell. don't know what that means. but i think poking around in these modules is very promising...

that's that for today.

as for the hardware side of things: i checked back with the specs of the chip. I might have been wrong in my previous assessment. the hardware might indeed be able to load the client and host part at the same time. it just can't USE it at the same time. but then again, there's only one usb jack, so you can't have a pc and a device plugged in anyway. so that shouldn't be a problem. i don't know if you need any special cable or anything to make it switch to host mode, though. i don't really think so. but we'll see.

so long
[Galaxy S I9000 Android Development] 19arek93:
It looks like our Samsung Processor has a workinig USB Host on Android 2.1(?) & 2.2. I'm right?

http://mycyclopedia.tistory.com/228

http://www.androidal.pl/odroid-s-tania-i-mocna-konsolka-z-androidem/10537

And this!:

http://odroidfans.nfshost.com/

"Ordroid-7"
[Galaxy S I9000 Android Development] handarmbeinfuss:
usb ehci module loading

yes. apparantly. that's why I had a look at the kernel sources of the odroid-t (the -s and now -7 are very similar). this is what i tried to port to the i9000's sources before the froyo kernel was available.

looking at the new ones for the odroid boards and the i9000, there are few differences in the usb host code. there are, however, massive differences in the usb client (otg) code. i can't say how that might influence switching between the two modes.

i got the ehci-hcd module to load and register a usb bus. i don't know why the s5pv210-ehci kernel device wasn't registered at bootup. I hacked a second call for doing that into the ehci-hcd module. that did the trick. on loading the module, however, the kernel log states "hub 1-0:1.0: 0 ports detected". I don't know what that means.

i tried attaching a powered usb hub and plugging in a usb device. the i9000 just sat there and did nothing. well, maybe i got the wiring wrong on my connector. could someone out there with a factory made otg cable (or whatever they are called) please measure pin connectivity? what i'd like to know, is if there are any resistor networks inside the cable and which of the pins of the micro usb plug (the one that would connect to the phone) connect to which of the pins of the standard usb jack (the one to which you would connect a device or usb hub).

so long
[Galaxy S I9000 Android Development] handarmbeinfuss:
ehci ports

hi all!

ok. i figured out that the micro usb port needs a connection of the id pin to ground. so the data cable that was shipped with the phone can't be used to connect to a hub. i bought a separate micro usb plug and soldered pin 4 to 5. now the ehci-hcd module loads with "1 port detected". so far so good.

i tried connecting a usb hub, but it didn't show up in the logs. no reaction at all. i tried reversing the data lines, injecting 5V power into the cable, no reaction.

ideas?