Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Manual USB OTG working

OP CaptainMuon

16th February 2013, 06:45 PM   |  #1  
OP Junior Member
Thanks Meter: 174
 
11 posts
Join Date:Joined: Feb 2013
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!
Last edited by CaptainMuon; 16th February 2013 at 06:50 PM. Reason: adb over USB probably won't work. suggest adbWireless instead.
The Following 148 Users Say Thank You to CaptainMuon For This Useful Post: [ View ]
16th February 2013, 06:59 PM   |  #2  
Senior Member
Flag Montreal
Thanks Meter: 623
 
1,729 posts
Join Date:Joined: Aug 2010
Donate to Me
More
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
16th February 2013, 09:22 PM   |  #3  
Senior Member
Thanks Meter: 44
 
321 posts
Join Date:Joined: 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 !!!

Last edited by scorpio16v; 16th February 2013 at 09:37 PM.
The Following 31 Users Say Thank You to scorpio16v For This Useful Post: [ View ]
17th February 2013, 12:28 AM   |  #4  
parker09's Avatar
Senior Member
Thanks Meter: 169
 
890 posts
Join Date:Joined: Apr 2010
More
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.
The Following 3 Users Say Thank You to parker09 For This Useful Post: [ View ]
17th February 2013, 12:44 AM   |  #5  
Senior Member
Thanks Meter: 1,483
 
1,571 posts
Join Date:Joined: 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: [ View ]
17th February 2013, 12:55 AM   |  #6  
Member
Thanks Meter: 13
 
85 posts
Join Date:Joined: 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.
17th February 2013, 01:20 AM   |  #7  
Member
Thanks Meter: 16
 
68 posts
Join Date:Joined: Feb 2013
Nice!
17th February 2013, 01:22 AM   |  #8  
Senior Member
Flag Aberystwyth
Thanks Meter: 93
 
346 posts
Join Date:Joined: Jun 2010
More
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
17th February 2013, 01:28 AM   |  #9  
Senior Member
Thanks Meter: 34
 
239 posts
Join Date:Joined: May 2010
Quote:
Originally Posted by Flynny75

Even miracast + mouse/keyboard would be awesome

we've already got that, haven't we?
17th February 2013, 02:14 AM   |  #10  
luckylui's Avatar
Senior Member
Flag Chi-Town
Thanks Meter: 365
 
4,018 posts
Join Date:Joined: Aug 2010
More
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

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes