blob: 300d37896e51f0b384ba5451e1ded3888bba9f3b [file] [log] [blame]
Anton Vorontsov4a11b592007-05-04 00:27:45 +04001Linux 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
Sebastian Reichel8c0984e2016-06-17 13:54:32 +020042See drivers/power/supply/ds2760_battery.c and drivers/power/supply/pda_power.c
43for the example how to declare and handle attributes.
Anton Vorontsov4a11b592007-05-04 00:27:45 +040044
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
Andres Salomonee8076e2009-07-02 09:45:18 -040079CHARGE_TYPE - batteries can typically charge at different rates.
80This defines trickle and fast charges. For batteries that
81are already charged or discharging, 'n/a' can be displayed (or
82'unknown', if the status is not known).
83
Ramakrishna Pallalab1b56872012-08-23 06:50:21 +053084AUTHENTIC - indicates the power supply (battery or charger) connected
85to the platform is authentic(1) or non authentic(0).
86
Anton Vorontsov4a11b592007-05-04 00:27:45 +040087HEALTH - represents health of the battery, values corresponds to
88POWER_SUPPLY_HEALTH_*, defined in battery.h.
89
Ramakrishna Pallalaa2ebfe22012-04-10 16:21:20 +053090VOLTAGE_OCV - open circuit voltage of the battery.
91
Anton Vorontsov4a11b592007-05-04 00:27:45 +040092VOLTAGE_MAX_DESIGN, VOLTAGE_MIN_DESIGN - design values for maximal and
93minimal power supply voltages. Maximal/minimal means values of voltages
94when battery considered "full"/"empty" at normal conditions. Yes, there is
95no direct relation between voltage and battery capacity, but some dumb
96batteries use voltage for very approximated calculation of capacity.
97Battery driver also can use this attribute just to inform userspace
98about maximal and minimal voltage thresholds of a given battery.
99
Dmitry Baryshkovc7cc9302008-01-07 04:12:41 +0300100VOLTAGE_MAX, VOLTAGE_MIN - same as _DESIGN voltage values except that
101these ones should be used if hardware could only guess (measure and
102retain) the thresholds of a given power supply.
103
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530104VOLTAGE_BOOT - Reports the voltage measured during boot
105
106CURRENT_BOOT - Reports the current measured during boot
107
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400108CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when
109battery considered full/empty.
110
111ENERGY_FULL_DESIGN, ENERGY_EMPTY_DESIGN - same as above but for energy.
112
113CHARGE_FULL, CHARGE_EMPTY - These attributes means "last remembered value
114of charge when battery became full/empty". It also could mean "value of
115charge when battery considered full/empty at given conditions (temperature,
116age)". I.e. these attributes represents real thresholds, not design values.
117
Liam Breck413de342017-06-07 11:37:52 -0700118ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
119
Andres Salomon8e552c32008-05-12 21:46:29 -0400120CHARGE_COUNTER - the current charge counter (in µAh). This could easily
121be negative; there is no empty or full value. It is only useful for
122relative, time-based measurements.
123
Liam Breck413de342017-06-07 11:37:52 -0700124PRECHARGE_CURRENT - the maximum charge current during precharge phase
125of charge cycle (typically 20% of battery capacity).
126CHARGE_TERM_CURRENT - Charge termination current. The charge cycle
127terminates when battery voltage is above recharge threshold, and charge
128current is below this setting (typically 10% of battery capacity).
129
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530130CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530131CONSTANT_CHARGE_CURRENT_MAX - maximum charge current supported by the
132power supply object.
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530133
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530134CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530135CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
136power supply object.
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530137
Liam Breck413de342017-06-07 11:37:52 -0700138INPUT_CURRENT_LIMIT - input current limit programmed by charger. Indicates
139the current drawn from a charging source.
140
Ramakrishna Pallalaea2ce922012-10-09 22:25:29 +0530141CHARGE_CONTROL_LIMIT - current charge control limit setting
142CHARGE_CONTROL_LIMIT_MAX - maximum charge control limit setting
143
Liam Breck413de342017-06-07 11:37:52 -0700144CALIBRATE - battery or coulomb counter calibration status
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400145
146CAPACITY - capacity in percents.
Ramakrishna Pallalae908c412012-07-05 16:59:12 +0530147CAPACITY_ALERT_MIN - minimum capacity alert value in percents.
148CAPACITY_ALERT_MAX - maximum capacity alert value in percents.
Andres Salomonb294a292009-06-30 02:13:01 -0400149CAPACITY_LEVEL - capacity level. This corresponds to
150POWER_SUPPLY_CAPACITY_LEVEL_*.
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400151
152TEMP - temperature of the power supply.
Anton Vorontsov588bd592013-10-27 22:20:59 -0700153TEMP_ALERT_MIN - minimum battery temperature alert.
154TEMP_ALERT_MAX - maximum battery temperature alert.
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400155TEMP_AMBIENT - ambient temperature.
Anton Vorontsov588bd592013-10-27 22:20:59 -0700156TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
157TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
Jenny TC6bb1d272014-07-08 11:34:18 +0530158TEMP_MIN - minimum operatable temperature
159TEMP_MAX - maximum operatable temperature
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400160
161TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
162while battery powers a load)
163TIME_TO_FULL - seconds left for battery to be considered full (i.e.
164while battery is charging)
165
166
167Battery <-> external power supply interaction
168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169Often power supplies are acting as supplies and supplicants at the same
170time. Batteries are good example. So, batteries usually care if they're
171externally powered or not.
172
173For that case, power supply class implements notification mechanism for
174batteries.
175
176External power supply (AC) lists supplicants (batteries) names in
177"supplied_to" struct member, and each power_supply_changed() call
178issued by external power supply will notify supplicants via
179external_power_changed callback.
180
181
Liam Breckc08b1f42017-06-07 11:37:51 -0700182Devicetree battery characteristics
183~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184Drivers should call power_supply_get_battery_info() to obtain battery
185characteristics from a devicetree battery node, defined in
186Documentation/devicetree/bindings/power/supply/battery.txt. This is
187implemented in drivers/power/supply/bq27xxx_battery.c.
188
189Properties in struct power_supply_battery_info and their counterparts in the
190battery node have names corresponding to elements in enum power_supply_property,
191for naming consistency between sysfs attributes and battery node properties.
192
193
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400194QA
195~~
196Q: Where is POWER_SUPPLY_PROP_XYZ attribute?
197A: If you cannot find attribute suitable for your driver needs, feel free
198 to add it and send patch along with your driver.
199
200 The attributes available currently are the ones currently provided by the
201 drivers written.
202
203 Good candidates to add in future: model/part#, cycle_time, manufacturer,
204 etc.
205
206
207Q: I have some very specific attribute (e.g. battery color), should I add
208 this attribute to standard ones?
209A: Most likely, no. Such attribute can be placed in the driver itself, if
210 it is useful. Of course, if the attribute in question applicable to
211 large set of batteries, provided by many drivers, and/or comes from
212 some general battery specification/standard, it may be a candidate to
213 be added to the core attribute set.
214
215
216Q: Suppose, my battery monitoring chip/firmware does not provides capacity
217 in percents, but provides charge_{now,full,empty}. Should I calculate
218 percentage capacity manually, inside the driver, and register CAPACITY
219 attribute? The same question about time_to_empty/time_to_full.
220A: Most likely, no. This class is designed to export properties which are
221 directly measurable by the specific hardware available.
222
223 Inferring not available properties using some heuristics or mathematical
224 model is not subject of work for a battery driver. Such functionality
225 should be factored out, and in fact, apm_power, the driver to serve
226 legacy APM API on top of power supply class, uses a simple heuristic of
227 approximating remaining battery capacity based on its charge, current,
228 voltage and so on. But full-fledged battery model is likely not subject
229 for kernel at all, as it would require floating point calculation to deal
230 with things like differential equations and Kalman filters. This is
231 better be handled by batteryd/libbattery, yet to be written.