pda_power: only register available psu
[deliverable/linux.git] / Documentation / power_supply_class.txt
CommitLineData
4a11b59d
AV
1Linux power supply class
2========================
3
4Synopsis
5~~~~~~~~
6Power supply class used to represent battery, UPS, AC or DC power supply
7properties to user-space.
8
9It defines core set of attributes, which should be applicable to (almost)
10every power supply out there. Attributes are available via sysfs and uevent
11interfaces.
12
13Each attribute has well defined meaning, up to unit of measure used. While
14the attributes provided are believed to be universally applicable to any
15power supply, specific monitoring hardware may not be able to provide them
16all, so any of them may be skipped.
17
18Power supply class is extensible, and allows to define drivers own attributes.
19The core attribute set is subject to the standard Linux evolution (i.e.
20if it will be found that some attribute is applicable to many power supply
21types or their drivers, it can be added to the core set).
22
23It also integrates with LED framework, for the purpose of providing
24typically expected feedback of battery charging/fully charged status and
25AC/USB power supply online status. (Note that specific details of the
26indication (including whether to use it at all) are fully controllable by
27user and/or specific machine defaults, per design principles of LED
28framework).
29
30
31Attributes/properties
32~~~~~~~~~~~~~~~~~~~~~
33Power supply class has predefined set of attributes, this eliminates code
34duplication across drivers. Power supply class insist on reusing its
35predefined attributes *and* their units.
36
37So, userspace gets predictable set of attributes and their units for any
38kind of power supply, and can process/present them to a user in consistent
39manner. Results for different power supplies and machines are also directly
40comparable.
41
42See drivers/power/ds2760_battery.c and drivers/power/pda_power.c for the
43example how to declare and handle attributes.
44
45
46Units
47~~~~~
48Quoting include/linux/power_supply.h:
49
50 All voltages, currents, charges, energies, time and temperatures in µV,
51 µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
52 stated. It's driver's job to convert its raw values to units in which
53 this class operates.
54
55
56Attributes/properties detailed
57~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
59~ ~ ~ ~ ~ ~ ~ Charge/Energy/Capacity - how to not confuse ~ ~ ~ ~ ~ ~ ~
60~ ~
61~ Because both "charge" (µAh) and "energy" (µWh) represents "capacity" ~
62~ of battery, this class distinguish these terms. Don't mix them! ~
63~ ~
64~ CHARGE_* attributes represents capacity in µAh only. ~
65~ ENERGY_* attributes represents capacity in µWh only. ~
66~ CAPACITY attribute represents capacity in *percents*, from 0 to 100. ~
67~ ~
68~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
69
70Postfixes:
71_AVG - *hardware* averaged value, use it if your hardware is really able to
72report averaged values.
73_NOW - momentary/instantaneous values.
74
75STATUS - this attribute represents operating status (charging, full,
76discharging (i.e. powering a load), etc.). This corresponds to
77BATTERY_STATUS_* values, as defined in battery.h.
78
79HEALTH - represents health of the battery, values corresponds to
80POWER_SUPPLY_HEALTH_*, defined in battery.h.
81
82VOLTAGE_MAX_DESIGN, VOLTAGE_MIN_DESIGN - design values for maximal and
83minimal power supply voltages. Maximal/minimal means values of voltages
84when battery considered "full"/"empty" at normal conditions. Yes, there is
85no direct relation between voltage and battery capacity, but some dumb
86batteries use voltage for very approximated calculation of capacity.
87Battery driver also can use this attribute just to inform userspace
88about maximal and minimal voltage thresholds of a given battery.
89
90CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when
91battery considered full/empty.
92
93ENERGY_FULL_DESIGN, ENERGY_EMPTY_DESIGN - same as above but for energy.
94
95CHARGE_FULL, CHARGE_EMPTY - These attributes means "last remembered value
96of charge when battery became full/empty". It also could mean "value of
97charge when battery considered full/empty at given conditions (temperature,
98age)". I.e. these attributes represents real thresholds, not design values.
99
100ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
101
102CAPACITY - capacity in percents.
4a11b59d
AV
103
104TEMP - temperature of the power supply.
105TEMP_AMBIENT - ambient temperature.
106
107TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
108while battery powers a load)
109TIME_TO_FULL - seconds left for battery to be considered full (i.e.
110while battery is charging)
111
112
113Battery <-> external power supply interaction
114~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115Often power supplies are acting as supplies and supplicants at the same
116time. Batteries are good example. So, batteries usually care if they're
117externally powered or not.
118
119For that case, power supply class implements notification mechanism for
120batteries.
121
122External power supply (AC) lists supplicants (batteries) names in
123"supplied_to" struct member, and each power_supply_changed() call
124issued by external power supply will notify supplicants via
125external_power_changed callback.
126
127
128QA
129~~
130Q: Where is POWER_SUPPLY_PROP_XYZ attribute?
131A: If you cannot find attribute suitable for your driver needs, feel free
132 to add it and send patch along with your driver.
133
134 The attributes available currently are the ones currently provided by the
135 drivers written.
136
137 Good candidates to add in future: model/part#, cycle_time, manufacturer,
138 etc.
139
140
141Q: I have some very specific attribute (e.g. battery color), should I add
142 this attribute to standard ones?
143A: Most likely, no. Such attribute can be placed in the driver itself, if
144 it is useful. Of course, if the attribute in question applicable to
145 large set of batteries, provided by many drivers, and/or comes from
146 some general battery specification/standard, it may be a candidate to
147 be added to the core attribute set.
148
149
150Q: Suppose, my battery monitoring chip/firmware does not provides capacity
151 in percents, but provides charge_{now,full,empty}. Should I calculate
152 percentage capacity manually, inside the driver, and register CAPACITY
153 attribute? The same question about time_to_empty/time_to_full.
154A: Most likely, no. This class is designed to export properties which are
155 directly measurable by the specific hardware available.
156
157 Inferring not available properties using some heuristics or mathematical
158 model is not subject of work for a battery driver. Such functionality
159 should be factored out, and in fact, apm_power, the driver to serve
160 legacy APM API on top of power supply class, uses a simple heuristic of
161 approximating remaining battery capacity based on its charge, current,
162 voltage and so on. But full-fledged battery model is likely not subject
163 for kernel at all, as it would require floating point calculation to deal
164 with things like differential equations and Kalman filters. This is
165 better be handled by batteryd/libbattery, yet to be written.
This page took 0.094193 seconds and 5 git commands to generate.