Generic battery interface
Hi!
(Vojtech and other thinkpad users: look at tp_smapi package; it includes stuff like "do not charge battery unless it is below 90%", which should make your battery last few more years).
(I'll still need to test it on x60, sorry).
Anyway, unlike acpi, tp_smapi uses some reasonably-nice one-value-per-file sysfs interface. I have few objections:
0) it needs to move to /sys/class/battery/tp_smapi or something like that
1) it probably should not include units in the files (hard to parse, and someone may have great idea to choose different units)
2) some optional method for battery applets to avoid polling would be nice (OTOH tp_smapi probably does not support notifications, so it is not its fault)
3) some fields look almost too specialized, but if hardware supports them, I guess we should export them, too...
...but otherwise it looks very good, certainly better than alternatives. Perhaps we should make something like this "generic" battery interface?
Good description is at
http://thinkwiki.org/wiki/Tp_smapi#Installation_from_source , and to give you a quick example:
# cat /sys/devices/platform/smapi/BAT0/installed # cat /sys/devices/platform/smapi/BAT0/state # idle/charging/discharging # cat /sys/devices/platform/smapi/BAT0/cycle_count # cat /sys/devices/platform/smapi/BAT0/current_now # instantaneous current # cat /sys/devices/platform/smapi/BAT0/current_avg # last minute average # cat /sys/devices/platform/smapi/BAT0/power_now # instantaneous power # cat /sys/devices/platform/smapi/BAT0/power_avg # last minute average # cat /sys/devices/platform/smapi/BAT0/last_full_capacity # cat /sys/devices/platform/smapi/BAT0/remaining_capacity # cat /sys/devices/platform/smapi/BAT0/design_capacity # cat /sys/devices/platform/smapi/BAT0/voltage # cat /sys/devices/platform/smapi/BAT0/design_voltage # cat /sys/devices/platform/smapi/BAT0/manufacturer # cat /sys/devices/platform/smapi/BAT0/model # cat /sys/devices/platform/smapi/BAT0/barcoding # cat /sys/devices/platform/smapi/BAT0/chemistry # cat /sys/devices/platform/smapi/BAT0/serial # cat /sys/devices/platform/smapi/BAT0/manufacture_date # cat /sys/devices/platform/smapi/BAT0/first_use_date # cat /sys/devices/platform/smapi/ac_connected
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
This would also be useful for the OLPC project - it's unlikely that it'll use ACPI, but a more feature-rich interface than /proc/apm would be massively helpful. This is just a matter of speccing out what information is needed and what format it should be presented in, and then adding a new device class, right?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Matthew Garrett
This would also be useful for the OLPC project - it's unlikely that it'll use ACPI, but a more feature-rich interface than
/proc/apmwould be massively helpful. This is just a matter of speccing out what information is needed and what format it should be presented in, and then adding a new device class, right?
Can we really assume there's one driver providing all battery-related attributes?
For example, on a ThinkPad you want the ACPI battery module loaded so that handles hande battery-related ACPI events, but on ACPI can't doesn't provide all available attributes. For example, ACPI reports the equvialent of
/sys/devices/platform/smapi/BAT0/power_avg (last minute average)
but not
/sys/devices/platform/smapi/BAT0/power_now (instantaneous average)
or
/sys/devices/platform/smapi/BAT0/cycle_count
or control functions like
/sys/devices/platform/smapi/BAT0/force_discharge
(see http://thinkwiki.org/wiki/tp_smapi for detials).
In this particular case we could split the ACPI module into two, one module for events and one module for the sysfs interface, and load only the first one on ThinkPads. But that's only because tp_smapi happens to reproduce all of ACPI's attributes; there are probably other cases whether neither method dominates the other.
So, if we insist on a standard battery device class name, how do we cope with multiple sources of information and control functions?
Shem
Quoted 2 lines · Shem Multinymous
Can we really assume there's one driver providing all battery-related attributes?
Hmm. That's a good point.
Quoted 2 lines
So, if we insist on a standard battery device class name, how do we cope with multiple sources of information and control functions?
Ignoring the multiple sources of information bit for the moment, we need to figure out the correct method of event notification anyway. There's a long-term plan to get rid of /proc/acpi, so acpi notifications need to be more more generic in any case.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Shem Multinymous
Can we really assume there's one driver providing all battery-related attributes?
Hmm. That's a good point.
Quoted 7 lines
Quoted 2 lines
So, if we insist on a standard battery device class name, how do we cope with multiple sources of information and control functions?
Ignoring the multiple sources of information bit for the moment, we need to figure out the correct method of event notification anyway. There's a long-term plan to get rid of
/proc/acpi, so acpi notifications need to be more more generic in any case.
You can poll sysfs files to be notified when states change...
thanks,
greg k-h
Hi!
Quoted 8 lines
Quoted 5 lines
This would also be useful for the OLPC project - it's unlikely that it'll use ACPI, but a more feature-rich interface than
/proc/apmwould be massively helpful. This is just a matter of speccing out what information is needed and what format it should be presented in, and then adding a new device class, right?Can we really assume there's one driver providing all battery-related attributes?
Anything else would be crazy, I'd say.
Quoted 4 lines
For example, on a ThinkPad you want the ACPI battery module loaded so that handles hande battery-related ACPI events, but on ACPI can't doesn't provide all available attributes. For example, ACPI reports the equvialent of
Quoted 8 lines
/sys/devices/platform/smapi/BAT0/power_avg(last minute average)
but not
/sys/devices/platform/smapi/BAT0/power_now(instantaneous average)
or
/sys/devices/platform/smapi/BAT0/cycle_count
or control functions like
/sys/devices/platform/smapi/BAT0/force_discharge
(see http://thinkwiki.org/wiki/tp_smapi for detials).
Well, in that case probably smapi driver should "hook into" acpi driver.
Quoted 5 lines
In this particular case we could split the ACPI module into two, one module for events and one module for the sysfs interface, and load only the first one on ThinkPads. But that's only because
tp_smapihappens to reproduce all of ACPI's attributes; there are probably other cases whether neither method dominates the other.
I hope such hardware will not be too common. Thinkpad is covered by accident, and I do not know about any other problematic machine.
Worst case, we would get equivalent of
/sys/class/battery/system_battery_acpi/... /sys/class/battery/system_battery_some_clever_vendor_hack/...
with some values common between both of them. I'd say it is still better than having vendor_hack in /sys in one format while having acpi battery in /proc/acpi in completely different format.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 2 lines · Pavel Machek
Well, in that case probably smapi driver should "hook into" acpi driver.
That would be odd, the SMAPI driver has nothing to do with the ACPI system. I don't think cross-system hooks are very popular...
Quoted 8 lines
Worst case, we would get equivalent of
/sys/class/battery/system_battery_acpi/.../sys/class/battery/system_battery_some_clever_vendor_hack/...with some values common between both of them. I'd say it is still better than having
vendor_hackin /sys in one format while having acpi battery in/proc/acpiin completely different format.
Aye, we need for a consistent interface to common functionality. How about /sys/class/battery/{acpi,apm,thinkpad}/BAT0?
So that for standard attributes, cat /sys/class/battery/*/BAT0/voltage gives something reasonable.
Shem
Quoted 9 lines · Shem Multinymous
Quoted 5 lines · Matthew Garrett
This would also be useful for the OLPC project - it's unlikely that it'll use ACPI, but a more feature-rich interface than
/proc/apmwould be massively helpful. This is just a matter of speccing out what information is needed and what format it should be presented in, and then adding a new device class, right?Can we really assume there's one driver providing all battery-related attributes?
No, we cannot. This is not true on ThinkPads, for example. We *can* make it true, but AFAIK that means overriding the entire generic ACPI battery driver, and greating a "glue" thinkpad_battery one that does:
1. generic ACPI battery access when ACPI is available
2. thinkpad specific ACPI battery access when ACPI is available
3. thinkpad specific EC firmware battery access (not ACPI).
That requires the new driver to use functions from ibm_acpi and tp_smapi, plus the stuff in the generic acpi battery access driver.
It might be the best way to go for ThinkPads, actually. Some rework on ibm_acpi ain't that bad, and tp_smapi is already undergoing major surgery.
Quoted 5 lines
In this particular case we could split the ACPI module into two, one module for events and one module for the sysfs interface, and load only the first one on ThinkPads. But that's only because
tp_smapihappens to reproduce all of ACPI's attributes; there are probably other cases whether neither method dominates the other.
Yes.
Quoted 2 lines
So, if we insist on a standard battery device class name, how do we cope with multiple sources of information and control functions?
Good question.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh