Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,730,051 Members 53,653 Now Online
XDA Developers Android and Mobile Development Forum

Manual USB OTG working

Tip us?
 
CaptainMuon
Old
(Last edited by CaptainMuon; 16th February 2013 at 05:50 PM.) Reason: adb over USB probably won't work. suggest adbWireless instead.
#1  
Junior Member - OP
Thanks Meter 174
Posts: 11
Join Date: Feb 2013
Storage Manual USB OTG working

Hi,

As you know, the Nexus 4 doesn't support USB OTG, meaning you can't use it with USB drives, gamepads, etc.. One reason is that the device doesn't seem to provide the neccessary 5V, the other reason is that it's not supported by the kernel.

So, I've been digging a bit, and now I can claim partial success! It's possible to supply the 5V yourself, and then activate USB host mode manually. It's a bit cumbersome, but for the beginning better than nothing. I tried a mouse and USB drives.

I should warn you that this is just a proof of concept and nothing that you'll want to use on a daily basis. Regular USB doesn't work properly while running this kernel, and I haven't checked battery consumption. Also this is based on Android 4.2.1, and if you have 4.2.2 you might not be able to make calls. That shouldn't be a problem as this is for testing only, though. Just let me say, I can't guarantee for anything, and I'm not responsible if you brick or blow up your phone.

You'll need:

- A USB OTG cable
- A USB Y cable to provide the 5V (It has two USB-A plugs and one USB-A socket.)
- My custom kernel
- Unlocked bootloader
- Android developer tools (adb, fastboot)

Load the boot image on your phone (this is not permantent):
Code:
$ fastboot boot myboot.img
Connect everything as follows (should be obvious):
- Y cable power plug (typically red) to the PC or adapter
- Other Y cable plug into the OTG cable
- OTG cable into the phone
- USB device into the Y cable socket

You need a remote shell on your device. Use adbWireless or similar to enable ADB over WiFi, then do:
Code:
$ adb connect 192.168.0.108:5555
(or whatever your phone's IP is)
$ adb shell
Now you should be on your phone. Do
Code:
shell@android:/ $ ls /sys/kernel/debug/msm_otg/
and you should see 'mode' if the new kernel works. Now become superuser and enable USB host mode:
Code:
shell@android:/ $ su
root@android:/ $ echo host > /sys/kernel/debug/msm_otg/mode
To disable USB host mode, use "none" or "peripheral". Note that at this point, I couldn't get it to go into regular USB mode. This means that MTP and adb over USB doesn't work yet.

Connect a device, and you should see more than two entries under "lsusb". Congratulations, your Nexus 4 has just recognized it's first USB device! If you install Stickmount (you have to sideload it since it's marked as not compatible), you can mount USB flash drives. Nexus Media Importer doesn't seem to work, though.

How does this work?
Basically, I just added the following line to the beginning of msm_otg_debugfs_init in msm_otg.c:
Code:
motg->pdata->otg_control = OTG_USER_CONTROL;
This enables the mode file in debugfs I use for mode switching. The next step would be to enable manual mode switching while keeping regular USB support, which shouldn't be too hard. Later down the line we can think about switching automatically on cable insertion, and maybe event getting 5V out of the device, but that would be a lot harder.

So, try it out, let me know if it works for you, and feel free to tinker around and improve what I've got!
The Following 148 Users Say Thank You to CaptainMuon For This Useful Post: [ Click to Expand ]
 
karendar
Old
#2  
Senior Member
Thanks Meter 620
Posts: 1,719
Join Date: Aug 2010
Location: Montreal

 
DONATE TO ME
Default Re: Manual USB OTG working

Nice to see some progress going. Only thing that irks me is the Y cable though, kinda defeats the purpose of OTG to me...

Thanks a bunch for your work though!

Sent from my Nexus 4 using xda premium
 
scorpio16v
Old
(Last edited by scorpio16v; 16th February 2013 at 08:37 PM.)
#3  
Senior Member
Thanks Meter 43
Posts: 321
Join Date: Oct 2006
You are a genius.
Just connected a powered USB-HUB and a mouse to my OTG cable, flashed the kernel and typed the commands directly with a terminal app on the device.
It simply works !!!

The Following 31 Users Say Thank You to scorpio16v For This Useful Post: [ Click to Expand ]
 
parker09
Old
#4  
parker09's Avatar
Senior Member
Thanks Meter 158
Posts: 883
Join Date: Apr 2010
Awesome development, one of my biggest gripes was the lack of USB OTG, I just assumed it was included as stock, that's why part of the reason I purchased this device.


Primary devices:

..... LG/Google Nexus 5: Android 4.4.2
..... Acer W510: Windows 8.1

Retired devices:

..... LG/Google Nexus 4: Android 4.4
..... HTC HD2: Windows Phone 7.8
..... HTC Legend: Android 4.0
..... UG802 USB: Android 4.0
..... Acer A500: Android 4.3
eparker.me
The Following 3 Users Say Thank You to parker09 For This Useful Post: [ Click to Expand ]
 
ziddey
Old
#5  
Senior Member
Thanks Meter 1442
Posts: 1,523
Join Date: Aug 2007

 
DONATE TO ME
This is awesome. Going to have to order some cables now. Since we have to supply power anyway, is it possible to support usb-otg + charging? Figure the phone is "too thin" anyway... I'll probably be making a 64gb microsdxc + battery case for the phone. Hello extended battery life.
The Following User Says Thank You to ziddey For This Useful Post: [ Click to Expand ]
 
eiriklf
Old
#6  
Member
Thanks Meter 13
Posts: 84
Join Date: Dec 2010
Great work, I was just looking for this yesterday. Would it work with a USB dac (Assuming I had a powered usb hub)? Just asking because I think usb audio is often overlooked, and I would really like to have it.
 
Addsome
Old
#7  
Member
Thanks Meter 15
Posts: 68
Join Date: Feb 2013
Nice!
 
Flynny75
Old
#8  
Senior Member
Thanks Meter 83
Posts: 308
Join Date: Jun 2010
Location: Aberystwyth
Default Re: Manual USB OTG working

It would also be interesting to see if the slimport adapter allows otg pass through (their website says it does)... Then that's HDMI +charging +mouse/keyboard. Even miracast + mouse/keyboard would be awesome

Sent from my Nexus 4 using Tapatalk 2
 
theabsurdman
Old
#9  
Senior Member
Thanks Meter 34
Posts: 239
Join Date: May 2010
Quote:
Originally Posted by Flynny75 View Post
Even miracast + mouse/keyboard would be awesome
we've already got that, haven't we?
 
luckylui
Old
#10  
luckylui's Avatar
Senior Member
Thanks Meter 364
Posts: 4,015
Join Date: Aug 2010
Location: Chi-Town
Default Re: Manual USB OTG working

Finally! Now I will get to use my 1TB Portable HDD!!

My 8 gig is FREE! Lol

Sent from my Nexus 4 using Tapatalk 2
Current: LG Nexus 5

Past: HTC One

Past: LG Nexus 4

Tablet: ASUS N7 8GB

Sent from my shuttle to mars!

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes