Battery Gauge enhancements
Here is an enhanced version of the battery gauge driver. It will likely work with all kernels. A couple of bugs have been fixed and new sysfs properties have been added. These changes are in large part based on enhancements of the Ubuntu battery gauge driver for the original Nexus 7.
The following new properties are added to '/sys/class/power_supply/battery/':
- charge_now: remaining battery charge in uAh; compensated for load current/temperature (higher load current = lower usable capacity)
- charge_avg: remaining battery charge in uAh; uncompensated
- charge_full: charge in uAh, when battery is fully charged (as determined by battery gauge -> will go down as the battery ages)
- charge_full_design: design value of battery charge (the capacity a new battery is supposed to have)
- energy_now: remaining battery charge/energy in uWh; compensated for load current/temperature
- charge_counter (signed value): coulomb meter measuring amount of charge that has flowed into or out of the battery; periodically set to 0, when battery has minimal load (e.g. on USB power and fully charged or during deep sleep)
- power_now (signed value): amount of power flowing into or out of battery in uW (updated by the gauge every second); useful to see how fast/with how much power the battery is being charged
- cycle_count: battery charge cycle count; around 4000mAh worth of charging correspond to a full cycle (e.g. when the battery is charged 50% = 2000mAh two times, you get a full cycle)
Reading the sysfs properties results in the battery gauge driver requesting the current value via I2C from the battery gauge. AFAIK, the I2C transaction uses software I2C and will block the CPU for a few dozen micro seconds.
A public datasheet for the battery gauge exists:
Disclaimer: The changes are not extensively tested and missing locking has been added to the driver (previously, concurrent requests via sysfs could result in wrong values) - there may be deadlocks lurking. The driver plays a role in controlling the battery charger, use it at your own risk (if your N7 burns and takes your house with it, don't come running to me).
Feel free to submit these changes to Google, I won't. The Ubuntu enhancements for the original N7 were submitted in January and have been ignored.