yashsingh1/xdaforums huggingface dataset:
[Nexus One Android Development] theloginwithnoname:
read registers

possibly interesting code in this file:

http://github.com/CyanogenMod/cm-kernel/blob/android-msm-2.6.34/drivers/power/ds2782_battery.c

specifically the functions prefixed ds2782_read_reg. Combined with the other .c and .h files, this will allow us to read the current age of the battery and what it thinks its capacity is! This is effectively dumpreg I think

If only I had a working C compiler, I'd give this code a go...

p.s. signature at bottom:

MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com>");
MODULE_DESCRIPTION("Maxim/Dallas DS2782 Stand-Alone Fuel Gauage IC driver");

Now you've seen that Maxim/Dallas name before, right!? ;)
[Nexus One Android Development] theloginwithnoname:
sure am.

I'll definately be keeping an eye on it in future. I never saw the voltage fluctuate much before shutdown, staying at least 3.4 - the pre people have reported the shutdown occurs when volts gets to 3.2? my first voltage after boot on charge is 3.454

I briefly saw the red battery icon and went to grab my cable but it got tangled up and I couldn't get it into the phone in time! maroon!! shame
[Nexus One Android Development] houmles:
Here is nexus one kernel with this:

if ((di->status.status_reg & 0x80) && (di->status.current_uA <=20000)) {

modification of ds2784_battery.c.

http://www.multiupload.com/V21IFK72BJ
[Nexus One Android Development] theloginwithnoname:
Nice work fella! Rog, off you go
[Nexus One Android Development] theloginwithnoname:
write registers?!

and this file:

http://github.com/CyanogenMod/cm-kernel/blob/android-msm-2.6.34/drivers/power/ds2760_battery.c

has code to write! function ds2760_battery_write_rated_capacity

Just need a C developer now...
[Nexus One Android Development] RogerPodacter:
Nice find! so I looked through those files quickly, i assume those are the fuel gauges for the other phones in the cm kernel? because it doesnt quite make sense, they are also on the main AOSP git site under the nexus one kernel. unless google just left them in but not needed.

my point is are these used by the nexus one at all, which answer is most probably no. i wonder why they didnt write similar functions for the nexus ds2784 driver file...unless it is newer and functions differently. notice in our ds2784 driver, doesnt the code return certain values into the registers? i'll have to look again. but maybe in older fuel gauge IC they needed to manually write values back to the file. but the new ds2784 now takes care of that differently.

we just need to add this to our driver!
[Nexus One Android Development] RogerPodacter:
thanks a bunch! just flash from recovery? i'll give it a go...
[Nexus One Android Development] theloginwithnoname:
He built a zImage for you, which requires a slightly different techique - download it and I'll dig out instructions for you.

edit

connect your phone to PC (windows?), drop to command line. type the following:

<path-to-android-sdk>\fastboot boot <path-and-filename-of-that-download>

(last parameter is case sensitive I think)

boot your phone into recovery and choose fastboot.

it will boot off that image and remain running that image til you restart the phone, when it will revert to your previous boot image (CM6) - neat huh!
[Nexus One Android Development] RogerPodacter:
i grabbed the file, i hope i can do everything from the phone since i have no admin access here at work so cant install anything if needed.
[Nexus One Android Development] RogerPodacter:
that's pretty sweet, i had no idea fastboot could do that. i'll give it a try in a bit, my fastboot pc is at home:(
[Nexus One Android Development] theloginwithnoname:
OK, just make sure you follw the edited version of my post - fastboot boot <image-filename>, the other one actually flashes ;)

what charge you on at the moment?? best to get to 15% then fastboot that image.

nandroid backup first I'd say, and take a copy to your PC.
[Nexus One Android Development] RogerPodacter:
well actually i am up around 90%. i figure it would be safer to test near the upper limit just in case that somehow prevents my phone from stopping the charge or whatever. rather than having to watch the phone for 2 hours while it charges from 15%, it could start off ok then i get distracted and it blows up! just kidding, but the second test would be from empty to full once i see that it actually stops charging correctly at 100%.

Edit: this sucks, I've been having major issues with the integrity of MT nand backups lately. The last thing I need...
[Nexus One Android Development] RogerPodacter:
ok i'm testing it out right now. the first problem is that it breaks my wifi it seems. not really sure, but in settings under wifi, the checkbox has the word "error" below it. and when i try to select the checkbox, nothing happens and it remains unchecked. obviously no wifi networks show up in the list either.

however, so far so good with charging. it didnt break anything in terms of it actually charges the phone. mAh is increasing like normal, voltage is as well, and percentage so far has gone from 89%, to 90%, to 91% now. so that's good i guess.

i remember reading thru ds2784_battery.c and saw logs or changes that had to do with wlan, or merging code, or something like that. you guys see anything in there related to wifi and why it would break it? hope someone can take a look...

EDIT: its possible that something else broke the wifi related to what i just flashed, but not necessarily because of adding that line of code.
[Nexus One Android Development] RogerPodacter:
i have an idea for at least how we could get values we were looking for.

looking at line 184:

s->status_reg = raw[DS2784_REG_STS];

and ds2784_reg_sts reads 0x00 from the wl_ds2784.h file.

so then at line 105, couldnt someone just add whatever additional addresses we want to see and add it to that line that outputs all those parameters we already see in the battery log?

or couldnt we just do that, and take a wild guess and assume its the same address as over in the palm pre thread? lol
[Nexus One Android Development] theloginwithnoname:
Agree RP, I've built a Linux box today so will be looking to compile a ROM over the next day or two. Hopefully I can start playing about with the fragments of code I've posted to produce some more meaningful logs/results with the hope of getting to the learning stage.

Signing off from Android as it's been a long day with the little ol' green one today!
[Nexus One Android Development] dvgrhl:
What file are you looking at for this?

I agree. At least we know we don't need to look there anymore. I don't think it will be hard to add in additional logging output where we want it. I'll pull down the source code tonight and start going through it. If you can point out the files and lines that you want to add output at, I'll code it in and either compile it (if I can) or pass it on to houmles (as long as he's not annoyed with us yet :)) for him to compile.
[Nexus One Android Development] RogerPodacter:
dvgrhl,

I've quoted the post I believe contains the important stuff. particularly:

I can never open the first file onthe device. i had to copy to my computer, and use some crappy free hex editor program to see inside. i dont know much so that's how i did it. i think theloginwithnoname has been trying to kill his battery to the exact point that would trigger the battery's learning flag to be set and then quickly go grab that file to see if the register value changes or appears.

as for outputs we'd want to see, what would we want to see? guess w1_ds2784 lists everything in the beginning. i'm not really sure...

EDIT: turns out that file easily opens up with notepad on my work computer. this battery_log file is the output from ds2784_battery lines 105 - 119

static int battery_log_print(struct seq_file *sf, void *private)
{
unsigned n;
mutex_lock(&battery_log_lock);
seq_printf(sf, "timestamp mV mA avg mA uAh dC %% src mode reg full\n");
for (n = battery_log_tail; n != battery_log_head; n = (n + 1) & BATTERY_LOG_MASK) {
struct battery_status *s = battery_log + n;
seq_printf(sf, "%9d %5d %6d %6d %8d %4d %3d %s %s 0x%02x %d\n",
s->timestamp, s->voltage_uV / 1000,
s->current_uA / 1000, s->current_avg_uA / 1000,
s->charge_uAh, s->temp_C,
s->percentage,
battery_source[s->charge_source],
battery_mode[s->charge_mode],
s->status_reg, s->battery_full);
}
mutex_unlock(&battery_log_lock);
return 0;
}

somehow we have to use that. i'm gonna try to do what nologinname did and drain my battery and try to grab that file and check the reg value.

Edit: this post somewhat gives an idea of what we're trying to do.

http://forums.precentral.net/palm-pre/256967-find-out-how-good-bad-your-battery-6.html#post2584858
[Nexus One Android Development] houmles:
yep, i forgot to upload the wifi driver which have to be manualy pushed to /system/lib/

here it is http://www.multiupload.com/SV0D3PP9O3
[Nexus One Android Development] RogerPodacter:
Ok I'll try this again later. But since the 20 mA didn't stop charge anyway, would this wifi lib make a difference at this point?
[Nexus One Android Development] houmles:
This just fix your wifi problem, nothing all.
[Nexus One Android Development] pershoot:
i was looking over this thread and thought to use battery percentage, for signifying when to stop charging.

i was then perusing this thread:

http://xdaforums.com/showthread.php?t=741322&page=8

and came across xdabravo's thread and github, and came across:

http://github.com/xdabravoteam/cm-kernel/commit/ffb0ef63ab15c0a03df6ab25dd7325d06f199e79

i went ahead and merged in the current_uA check as well as swapping status register 0x80 with percentage < 99 to not turn off charge, and when percentage is = 100, turn charging off.

let me know how things go.

flash at your own risk!

http://droidbasement.com/nexus/kern...-cm_2635.3-oc-uv-xtra-btn-aud-ram-neon_fp.zip
[Nexus One Android Development] RogerPodacter:
From 100% - 90%, mine says 0x81 with value 1. then at 89% mine changes to 0x01 with value 0. this is all during discharge, no charging.

Roger

0x81 -> 1 (100-90%, ac full, usb full)

0x01 -> 0 (stays like this for <89%, usb slow charging, and ac fast charging. and lowest voltage was 3693 mV)

loginnoname

0x87 -> 1

0x07 -> 0

0x27 -> 0

0x77 ->

0x67 ->

i'll drain tonight and update this post.
[Nexus One Android Development] RogerPodacter:
That link does not work. I'll flash and test though.
[Nexus One Android Development] RogerPodacter:
Link doesn't work. I'll flash and test though.
[Nexus One Android Development] pershoot:
Refresh. Link works (I just edited it)
[Nexus One Android Development] pershoot:
Were u able to dload it?
[Nexus One Android Development] dvgrhl:
Am I reading this correctly that these values are what di->status.status_reg holds? IF that is the case, then:

di->status.status_reg & 0x80

would return 0 when di->status.status_reg < 0x79, and would return 128 when di->status.status_reg <= 0x80. That means that from 100%-90% the following if statement is being satisfied:

if (di->status.status_reg & 0x80) {
di->status.battery_full = 1;
charge_mode = CHARGE_BATT_DISABLE;
} else
di->status.battery_full = 0;

and only when it is <90% does it reach the else statement.
[Nexus One Android Development] RogerPodacter:
Downloading it now. But I don't think this will work because this is the older driver. It was since updated which removed those conditions. So I can't flash this file unless I was on eclair. Could you take a look at the new driver and compare and maybe see what they did, why that 80 mA condition was there in the first place?

Also even using the new driver without the 80 mA condition, the phone still shuts off at 80ma. How is that possible?
[Nexus One Android Development] chowlala:
Downloading it now. Will give it a shot in a few minutes. Thanks so much for checking the thread out pers. :)
[Nexus One Android Development] pershoot:
my source is current. this is the driver that is being shipped from AOSP.

ds2784 with ds2482 W1 master

http://android.git.kernel.org/?p=ke...54cfa3b22c61dd50eae;hb=android-msm-2.6.35-wip
[Nexus One Android Development] RogerPodacter:
If so then this explains a lot. However what is the altered driver we switched to later in this thread?

the one here:

http://github.com/CyanogenMod/cm-kernel/blob/android-msm-2.6.34/drivers/power/ds2784_battery.c
[Nexus One Android Development] RogerPodacter:
REMOVED for not reading first:)
[Nexus One Android Development] chowlala:
Definitely viably working at this point. I didn't turn off my phone, and I was able to achieve a charge rate of 4.172 - which is the "bump charge" I get if I turn off the phone to charge it once it hits max.

This is starting to turn out to be really interesting. Phone is stable thus far. Checked the battery status' via OSmonitor, everything seems to be alright. =)

Now to figure out the other end. How to make it turn off only at 1% instead of random values.
[Nexus One Android Development] RogerPodacter:
so did you check your mAh as well? edited for not reading first
[Nexus One Android Development] RogerPodacter:
if you want to make the phone not shut off at random lower values, if you read back thru this thread, there is a learning mode that we can enable in the ds2784 battery IC. reference the palm pre thread i linked to, they got this done and it opens up a whole bunch of info that we can use. but it seems in android its not quite as easy. so we would like to edit the battery driver to be able to read the register values and figure out which bit/byte or address enables all of this. someone could make a very useful utility if this works out. we just need some experts.

this whole time i guess i was using the wrong driver?? it was right at first, then moved on to what i thought was newer but wasnt, and now back to the original one. oops:o
[Nexus One Android Development] RogerPodacter:
sounds right. is there any chance of being able to interact with this stuff? or at least for now, doing a "dumpreg" like they did over at precentral so we can just see all our numbers. i think that would be a good first step.

what are the chances that since palm pre and nexus one both use the same ds2784 that we can build off what they already figured out?

http://forums.precentral.net/palm-pre/256967-find-out-how-good-bad-your-battery-6.html

cause we still need to figure out where the "learning" mode bit can be set.

also, we been using wrong file. this one is what we can use from now on:

http://github.com/xdabravoteam/cm-kernel/commit/ffb0ef63ab15c0a03df6ab25dd7325d06f199e79
[Nexus One Android Development] chowlala:
Yeah, I picked up on that following the thread. Not too sure where the "learning mode" is though, But I did plug in when my phone blinked red and hit the "shutting off". But again, not sure if I got it in the window frame. Guess we'll just have to keep exploring.

We're making good progress though. Pershoot is already adding these changes into his kernel, give us that extra hour/half hour on the top bit.

Now, as for mAh, i clocked in about 1371-5 mAh before I had to yank the cable out to go to work. However, I did notice in the logs that the battery had hit a point message saying the battery is fully charged though. So I'm not too sure how this works out in the end.

Further testing required fer shure.
[Nexus One Android Development] RogerPodacter:
i'll give it a test in a few minutes here.

i would think to check the register but not have your phone die at the very end, you can wait till that very last second when you think its ready. then quick plug in the charger only long enough to go to sys/kernel/debug/battery_log and copy that quickly. i dont think the driver writes to that log very often. i think its only once every 50 seconds. so if the bit was switched, you probably could see it if it showed up. wait what am i saying, that log is a cumulative log, so it would just add on existing data. so just plug in and there's no rush, if the reg switched, it will be there towards the end of the log.
[Nexus One Android Development] theloginwithnoname:
And I started a post in your kernel thread that would have asked you if you had any ideas. Lucky I never completed ;)

Flashed your latest .35 kernel with the above in it. It goes all the way from 90 to 100 in incremental steps (see earlier log post), but only gets to the ~1360mAh capacity.

There is a battery_state_changed event that fires - perhaps we could use that to output additional info or re-set the state depending on the mAh value? (something like: if battery.currentAh < 1400, battery.state = charging / battery.full = false)
[Nexus One Android Development] chowlala:
Don't forget, batteries actually enter a degradation once we begin using them, hence, the maximum charge capacities of batteries begin to fall with constant usage, never allowing us to maintain it at 1400 mAh.
[Nexus One Android Development] theloginwithnoname:
And that degradation "ratio" is what AGE is - a percentage of the set capacity. If the battery's capacity is set to 1500, at new AGE will be 100% - after 6 months it's likely ~90% - therefore your maximum capacity after 6 months = 90% of 1500, or 1350.

Calibrating will re-set the AGE ratio based on how much charge your battery can hold up to the set capacity.

So I want to: 1) set my capacity to 1500, 2) set my age to 100%, 3) see what charge I get. 4) recalibrate 5) see what my age is, 6) see what charge I get ;)
[Nexus One Android Development] pershoot:
i just charged up from 11% to full (as indicated by android). my device usually shuts down around 8-9%. lets see if i get 4-5%.

will report back.
[Nexus One Android Development] RogerPodacter:
i still have to wonder, after all this, why does a bump charge seem to work? by work i mean get our batteries up to 1400 mAh. whether that is usable extra charge, we dont know. (i think it is, afterall the mAh decreases as used until 1360 where it starts 99%, 98%, etc.). so what mechanism is stopping the charge in the driver? its probably happening when the battery_status == 1 somehow tells the battery "you are full now", even though if the battery were left on its own it would allow for mroe juice before it stopped.

the other probelm i just started having is that i take off the charger and hit 99% within 1 minutes. previously the phone would stay at 100% for an hour with no use before it dropped.

anyway, today i'll try a old fashioned full discharge see as low as i can get it. another day of funtimes..:D.
[Nexus One Android Development] theloginwithnoname:
It only works sometimes on mine. I can get 1358 or 1482 with an off-charge, be that a simple power-off and charge overnight, or a full bump - there's no rhyme nor reason to it!

But I understand what you are saying.

Stiff upper lip old boy - we'll get there.

I have spent a large chunk of time today trying to get a Linux box into a state where I can compile C code that uses include files like the battery code does. Unsuccessfully. I can compile a simple C program but cannot get my includes include/paths right! Need a HOW-TO or some time on gtalk with a developer badly. (Have the SDK and the NDK, and the Java runtime btw).

p.s. saw this on the Pre thread - we'll need to be aware of this when we get to dumping the registers:

http://forums.precentral.net/palm-pre/256967-find-out-how-good-bad-your-battery-18.html#post2625061
[Nexus One Android Development] RogerPodacter:
dvgrhl just got build environment working, so i wouldnt worry too much (though i know you'll want it working in general). hope he wouldnt mind me posting from his PM.

so at least we can get going...

EDIT: that pre post is interesting, someone says their pre shuts off exactly at 3.4 volts. my nexus does not, i've barely ever gotten to 3.48 and it shut down, with 8% battery left. but upon immediate reboot, voltage read 3.41 or so. now why would it be reading inaccurately prior to the shutdown? i'd guess since most li-ion batteries are same that if the nexus UVF undervolt is 3.4 as well?
[Nexus One Android Development] theloginwithnoname:
OK cool, he may me able to help me out then. I'll look for him online in the forums tomorrow. In the meanwhile I've posted this as I didn't find anything useful whilst googling...

Failing that, I will write up a brief spec that a developer could use in conjunction with the AOSP code and the Pre scripts.
[Nexus One Android Development] RogerPodacter:
i did have a somewhat promising result last night, it does seem pershoot's 20 mA addition works in principle. i was able to get an extra top off to about 1371 mAh with current draw of 55 mA. so in principle it works and may be possible. learn mode and dumpreg is still the real answer though.

08/25/2010 00:00:00 [INFORMATION] batt: 98%, 4143 mV, 163 mA (59 avg), 38.7 C, 1350 mAh
08/25/2010 00:00:50 [INFORMATION] batt: 99%, 4143 mV, 163 mA (162 avg), 39.0 C, 1353 mA
08/25/2010 00:01:40 [INFORMATION] batt: 99%, 4143 mV, 159 mA (150 avg), 39.0 C, 1355 mA
08/25/2010 00:02:30 [INFORMATION] batt: 99%, 4148 mV, 154 mA (154 avg), 39.0 C, 1358 mA
08/25/2010 00:03:20 [INFORMATION] batt: 99%, 4148 mV, 134 mA (144 avg), 39.1 C, 1360 mA
08/25/2010 00:04:10 [INFORMATION] batt: 99%, 4148 mV, 133 mA (136 avg), 39.2 C, 1361 mA
08/25/2010 00:05:01 [INFORMATION] batt: 100%, 4148 mV, 133 mA (140 avg), 39.2 C, 1363 mA
08/25/2010 00:05:51 [INFORMATION] batt: 100%, 4148 mV, 135 mA (99 avg), 39.0 C, 1364 mAh
08/25/2010 00:06:48 [INFORMATION] batt: 100%, 4148 mV, 140 mA (77 avg), 39.1 C, 1366 mAh

08/25/2010 00:06:48 [INFORMATION] batt: charging OFF [TIMEOUT] <- this ive never seen before
08/25/2010 00:07:38 [INFORMATION] batt: 100%, 4094 mV, -201 mA (-262 avg), 39.2 C, 1363 mA
08/25/2010 00:07:38 [INFORMATION] batt: charging FAST

08/25/2010 00:08:28 [INFORMATION] batt: 100%, 4148 mV, 149 mA (167 avg), 39.2 C, 1364 mAh
08/25/2010 00:09:18 [INFORMATION] batt: 100%, 4148 mV, 106 mA (146 avg), 39.0 C, 1366 mAh
08/25/2010 00:10:08 [INFORMATION] batt: 100%, 4153 mV, 138 mA (135 avg), 39.0 C, 1368 mAh
08/25/2010 00:10:58 [INFORMATION] batt: 100%, 4138 mV, 64 mA (121 avg), 39.0 C, 1369 mAh
08/25/2010 00:11:48 [INFORMATION] batt: 100%, 4143 mV, 77 mA (95 avg), 39.0 C, 1371 mAh <- a little better at least
08/25/2010 00:12:39 [INFORMATION] batt: 100%, 4148 mV, 55 mA (29 avg), 39.1 C, 1368 mA
08/25/2010 00:12:39 [INFORMATION] batt: charging BATTOFF [FULL]

08/25/2010 00:13:29 [INFORMATION] batt: 100%, 4133 mV, 0 mA (0 avg), 39.2 C, 1368 mAh
08/25/2010 00:14:19 [INFORMATION] batt: 100%, 4133 mV, 0 mA (0 avg), 39.2 C, 1368 mAh
08/25/2010 00:15:09 [INFORMATION] batt: 100%, 4133 mV, 0 mA (0 avg), 39.2 C, 1368 mAh
08/25/2010 00:15:52 [INFORMATION] batt: charging OFF [FULL] <- I unplugged here
08/25/2010 00:15:59 [INFORMATION] batt: 100%, 4094 mV, -436 mA (0 avg), 39.5 C, 1368 mA
08/25/2010 00:16:54 [INFORMATION] batt: 100%, 4089 mV, -150 mA (-313 avg), 39.2 C, 1363 mA
08/25/2010 00:17:44 [INFORMATION] batt: 99%, 4104 mV, -113 mA (-282 avg), 39.1 C, 1360 mAh

also weird is the TIMEOUT messages, then charging starts back up. i've never seen this before.
[Nexus One Android Development] RogerPodacter:
sounds good. earlier you mentioned pershoots edits. is that edited driver file available somewhere to view the source code changes? or were you just going off of his description in his post. i'd like to see the edits just to understand what's going on.
[Nexus One Android Development] pershoot:
im concerned about your TIMEOUT and wanting to make an adjustment to remedy it.

can you please drain to 10%, charge to 100% from wall, clear stats. let it discharge below 90% (85% works) then plug it in to USB and monitor it until 100% and report back?