[USB OTG] [21NOV13] [PATCH] Externally Powered USB OTG

Standard

By: ziddey

Externally Powered USB OTG – Nexus 4

This is an all-in-one patch to enable externally powered OTG (technically usb host mode) support. It’s built off either the stock kernel or Franco’s kernel sources, and should work with any ROM (that these kernels otherwise support). Refer to the second post for details on modifications and additions.

Again, power MUST be supplied externally, as there is no way for the phone to provide it.

Requirements:

Power MUST be supplied to both the USB device and phone. The easiest way would be by using an OTG Y-cable:

If using a traditional OTG cable, a USB Y-cable can be used:
 

Some powered USB hubs also send power up to the host and can be used directly with a regular OTG cable.

I am not endorsing any specific product or seller. Links are provided solely as examples, and are by no means definitive. As long as the phone and device both get 5V (charger, computer, etc.), and the data pins are connected, host mode will work (provided enough current can be supplied).

Installation:

Simply install the zip in recovery. Script will automatically install/patch necessary files. Must reinstall any time ROM is updated.

To uninstall, simply reflash your ROM. Data wipe is not necessary. If for some reason that’s not an option, use the flashable unmod script to remove ROM-side modifications. Flash your kernel of choice afterwards (must flash “reset” kernel first if flashing an “anykernel”).

Recovery:
(Optional)

For support in recovery, I’ve created a sort of “any-any” script. It replaces the recovery’s kernel with the boot one. Therefore, by flashing thisafter the main patch, OTG will effectively be enabled in recovery (after a reboot). However, it is on the actual recovery itself to provide support for usb drives– TWRP does. Otherwise, you’ll have to manually mount any drives via linux console commands.

For your own safety/sanity, ensure the main patch works before flashing this. If recovery fails to boot after flashing, it can easily be replaced by using GooManager or similar. Worst case scenario, a new recovery can always be flashed via fastboot.

Downloads:
(Changelog at end of second post)

MAKE SURE TO DOWNLOAD THE RIGHT VERSION FOR YOUR ROM.
I don’t keep track of all the different ROMs so it’s on you guys to figure out which one is appropriate. The -CM builds have the two “CAF” commits that are now required for CM and its derivatives (unless they have specifically reverted the associated commits).

Current:
Note: Most likely INCOMPATIBLE with CM11

Old:

Bugs / Notes:

  • An OTG cable has the ID pin grounded out, which is used to trigger usb host mode. However, ID pin detection is broken in the Nexus 4 (although working for Slimport detection). Instead, we rely on detection of a “proprietary” charger (voltage on the data pins) in order to determine when to enable host mode.
  • Self-powered devices (e.g. digital cameras) don’t send power to the phone. This will cause the device to not be detectable. Therefore, external power is still required.
  • Slimport cannot work concurrently with usb data due to hardware limitations (Slimport takes over the usb data pins).
  • USB drive will automatically mount at /storage/usbdisk0 (also accessible at /usbdisk and /mnt/usbdisk). Media scanning should occur automatically. Make sure to unmount before removal to avoid data loss.
  • Stock Android only supports FAT for storage. NTFS/exFAT/ext4 partitions may require the use of a third party app like StickMount(CM now supports these partitions natively!).
  • There appears to be a minor bug in the AOSP code that prevents available space from being reported in Settings->Storage->USB Storage. The screenshot is of CM10.1, which has this fixed
  • Current builds do not allow for host mode without charging. Use this as a workaround:
    Quote:
    Originally Posted by RussianBear View Post
    For those that want to stop usb charging, create a script modifying this to either 1 (disabled) or 0 (enabled). Works for me Not responsible for your phone(s) exploding.echo 1 > /sys/module/pm8921_charger/parameters/disabled
    echo 0 > /sys/module/pm8921_charger/parameters/disabled

  • Standard Disclaimer– Flashing this patch is at your own risk, and carries no warranty or liability on my part. The assumption is that you will perform due diligence before flashing and make any necessary backups if required.

Screenshots:

  

Credits:

  • CaptainMuon, for proving that host mode is possible on the Nexus 4.
  • Franco, for his kernel, which this patch is based off.
  • garyd9, for his command to patch platform.xml.
  • Chainfire, for his usb host wisdom, and article on secondary storage write permissions.
  • arpruss, for his compiled zip-for-android
  • All you guys for testing!

Leave a comment