linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [POWER] battery calibration parameters from sysfs
@ 2009-12-04 10:42 Linus Walleij
  2009-12-04 10:49 ` Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Linus Walleij @ 2009-12-04 10:42 UTC (permalink / raw)
  To: cbou, dwmw2; +Cc: LKML, linux-embedded

Hi,

we're working on battery charging support for ST-Ericsson MFD ASICs
like AB3100 and later series. I have this issue about battery
calibration
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:

/sys/.../v_vs_cap/x0
/sys/.../v_vs_cap/y0
/sys/.../v_vs_cap/x1
/sys/.../v_vs_cap/y2
...
/sys/.../v_vs_cap/xN
/sys/.../v_vs_cap/yN

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

cat >/sys/.../v_vs_cap <<EOF
x0,y0
x1,y1
x2,y2
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?

Yours,
Linus Walleij
ST-Ericsson

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2009-12-18  8:48 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-04 10:42 [POWER] battery calibration parameters from sysfs Linus Walleij
2009-12-04 10:49 ` Mark Brown
2009-12-04 14:17   ` Mark Brown
2009-12-05 13:08   ` Linus Walleij
2009-12-05 17:45     ` Mark Brown
2009-12-07 11:48     ` Mark Brown
2009-12-07 14:07       ` Linus Walleij
2009-12-07 16:56         ` Mark Brown
2009-12-08  5:27           ` Brian Swetland
2009-12-08 10:28             ` Mark Brown
2009-12-13 13:24           ` Pavel Machek
2009-12-14 12:12             ` Mark Brown
2009-12-14 21:22               ` Pavel Machek
2009-12-14 23:43                 ` Aras Vaichas
2009-12-15  3:02                   ` Bill Gatliff
2009-12-15 22:58                     ` Aras Vaichas
2009-12-15 23:32                       ` Stanislav Brabec
2009-12-16  9:40                         ` Andy Green
     [not found]                           ` <4B28AAFC.5010108-/Zus8d0mwwtBDgjK7y7TUQ@public.gmane.org>
2009-12-18  8:48                             ` Pavel Machek
     [not found]               ` <20091214121247.GB22388-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
2009-12-16 22:53                 ` Pavel Machek
2009-12-13 13:19         ` Pavel Machek
2009-12-14 11:50           ` Mark Brown
2009-12-14 11:58             ` Pavel Machek
2009-12-14 12:14               ` Mark Brown
2009-12-04 11:34 ` Alexander Clouter
2009-12-06 20:52 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).