USB host mode power management extension for Nexus 7
Timur's kernel for Nexus 7 enables you to connect multiple USB devices (DAC, ethernet adapter, flash drive, hard drive, DVB/T, mouse, keyboard) and operate all of these devices from internal battery or using an external power source. When using an external power supply, there will be no battery drain and your N7 will even charge. A special variant of the kernel is available for permanent installations, such as in-car dashboard setups.
Two kernel variants
- Both kernel variants provide "powered USB host mode + charging" functionality. This allows you to use your USB slave devices without interrupt and as long as you want. A USB OTG Y-adapter is needed to connect an external power supply. You should be able to find OTG Y-adapters on ebay.
- Both kernel variants fix a number of shortcomings in the default kernel, in order to provide robust host mode operations.
- Both kernel variants enable usb-audio.
Kernel for mobile use
- This kernel variant behaves like a standard Nexus 7, but with one added funtionality: when external power is detected, it will be used to operate the host and to charge it's internal battery.
- To activate charging, you must first connect your external power supply to your OTG Y-adapter - then plug the OTG adapter into your Nexus 7 - and then connect any slave devices.
- When external power drops ("mobile use"), this kernel variant will switch from "powered USB host mode + charging" to default OTG mode. In default OTG mode, the host will operate USB slave devices from it's internal battery.
- In OTG mode, the host will not be able to automatically detect the return of external power. In order for the host to detect and make use of external power again, the OTG adapter needs to be unplugged and reconnected.
Kernel for fixed installation
- The FI variant of the kernel is for permanent installations and setups where cables are hidden or can only be accessed with much effort (dashboard setup, etc.).
- This kernel provides reliable sleep mode behavior in exchange for OTG functionality. When external power is dropped, the host will be able to enter deep sleep (LP0) and keep it's charge over long periods of times.
- Return of external power will reliably wake the host from sleep. (This is not possible with the mobile-use kernel, as it tries to operate slave devices from it's internal battery, when external power drops.)
Using an USB DAC
Due to restrictions in the Android audio subsystem, a USB DAC must be connected at system boot time, in order for it to become accessible as a sound device. It may be possible, to solve this problem, by using 3rd party solutions, which enable audio hot-plugging.
FI kernel + Power Loss
Sudden loss of external power can result in a number of problematic situations. This is the case, for example, when slave devices build up state, while being in use. USB mouse and keyboard are often stateless devices and will not suffer any state related issues after a sudden power loss. But state is in play, whenever external filesystems are being used. And also, when a USB DAC is playing back an audio stream.
When a statefull USB session is interrupted by loss of external power, what happens in most cases, is that all slave devices will loose power, while the host will be able to continue operations on battery power. Even if the host will fall into deep sleep mode shortly, it will be able to keep it's state, while slave devices will loose theirs. In a power loss situation, USB slave devices will usually not unplug themselfs. From the point of view of the USB host, these devices keep being registered USB slave devices. They will just stop functioning the way they normally do.
When external power comes back, all slave devices will restart and also the host will start using external power again for it's operations. The problem takes place, when applications, running on the host, may or may not notice, that something has happened with the devices they were using just moments ago.
An application reading from an external SD-card may or may not notice, that when it is using it's file handles now, that the device is returning error codes, instead of data.
A music player application, trying to continue sending it's data stream to a USB DAC, may or may not notice, that the USB DAC is unable to play back the continued audio stream, because it has lost knowledge about data references, the host is sending.
In short, removing power from slave devices is likely to result in all sort of difficult situations. Often, these difficulties can be overcome. What is important to realize here, is that most of these problems are usually on the application level. And the only way to resolve these issues is also on the application level.
External filesystems may need to be remounted. And applications reading and writing to an external SD-card (or a SSD drive) may need to cope with a file system, suddenly being unmount and eventually getting remounted.
Music player applications may need to be triggered to pause and unpause playback. This will make them create and use new audio stream handles, which may be required for a newly started DAC to accept any music data.
Allowing a music app to continue sending an old (unpaused) audio stream to a newly restarted USB DAC, can temporary destabilize all communications on the newly established USB session. Pausing and unpausing now, may not be able to resolve the issue anymore. In some situations the problem will resolve itself over time. In other situations, killing the Music player process (or switching to a different music app) will be the only way back to normal operations. All such issues can be prevented by pausing audio going to the USB DAC, before it will restart. Installation of a dedicated Android service can solve this issue reliably.
Using an USB hub
Depending on the ability of your USB hub to use a dedicated power source, there are two options available:
Option 1: Use this when your USB hub does not provide an external power connector. Connect external power directly to arm 1 of your OTG Y-cable and connect your USB hub to the other arm. Power will flow to hub and N7 in parallel. You can disconnect your N7 and power will continue to flow to your hub and to all connected slave devices.
Option 2: Your USB hub provides it's own power connector. You can still use Option 1, but you can also feed power directly to the hub. In the latter case use an OTG Y-cable to make your N7 become the USB host (arm 1) towards the hub and have it draw power (arm 2) from one of the USB hub's slave connectors.
Kernel installers can be found on the Nexus 7 kernel download page.
There is a Rootzwiki discussion thread.
There is also an old discussion thread.