[lkml]   [2009]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subject[POWER] battery calibration parameters from sysfs

we're working on battery charging support for ST-Ericsson MFD ASICs
like AB3100 and later series. I have this issue about battery
parameters that I need advice on, and more specifically on how to use
sysfs to get that data in.

Most devices of this kind does not need the stuff we're doing so we're
the odd bird here. Other batteries are "smart" (contain factory
calibration inside of them) or get calibration from some BIOS or such.

In our code we have a number of (x,y) pair tables like this:

/* Vbat mV to Battery capacity % */
struct voltage_vs_capacity {
int voltage;
int capacity;

* Default calibration table for voltage vs battery capacity.
* Voltage in millivolts, capacity given in permil.
struct voltage_vs_capacity voltage_to_battery_capacity_init[] = {
{ 4177, 1000 },
{ 4070, 900 },
{ 3988, 800 },
{ 3834, 570 },
{ 3797, 470 },
{ 3768, 320 },
{ 3721, 190 },
{ 3633, 60 },
{ 3523, 30 },
{ 3200, 0 },

We then interpolate between two subsequent (xn,yn),(xn+1,yn+1)
pairs to get a calibrated capacity value from the voltage
level measured.

This is all good as long as you compile the calibration into the kernel
like this.

However we want to override the default table with one fed in
though e.g. sysfs, so calibration data for the battery can reside
in the file system. NOTE: this table is NOT of fixed length, i.e.
we don't know how many (x,y) pairs will be passed in.

Whereas the rule for sysfs is one value per file, creating an arbitrary
large hirarchy like this:


Is probably not very elegant. (Or is it?) Would it be permissible to
pass in a table like:

cat >/sys/.../v_vs_cap <<EOF

And have the kernel parse x,y pairs up to EOF?

Or would it be preferable to do this thing by creating some
misc device node like /dev/battery0 and a custom ioctl()?

Or is there some other way I haven't thought of?

Linus Walleij

 \ /
  Last update: 2009-12-04 11:45    [W:0.161 / U:0.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site