289 lines · plain
1========================2Linux power supply class3========================4 5Synopsis6~~~~~~~~7Power supply class used to represent battery, UPS, AC or DC power supply8properties to user-space.9 10It defines core set of attributes, which should be applicable to (almost)11every power supply out there. Attributes are available via sysfs and uevent12interfaces.13 14Each attribute has well defined meaning, up to unit of measure used. While15the attributes provided are believed to be universally applicable to any16power supply, specific monitoring hardware may not be able to provide them17all, so any of them may be skipped.18 19Power supply class is extensible, and allows to define drivers own attributes.20The core attribute set is subject to the standard Linux evolution (i.e.21if it will be found that some attribute is applicable to many power supply22types or their drivers, it can be added to the core set).23 24It also integrates with LED framework, for the purpose of providing25typically expected feedback of battery charging/fully charged status and26AC/USB power supply online status. (Note that specific details of the27indication (including whether to use it at all) are fully controllable by28user and/or specific machine defaults, per design principles of LED29framework).30 31 32Attributes/properties33~~~~~~~~~~~~~~~~~~~~~34Power supply class has predefined set of attributes, this eliminates code35duplication across drivers. Power supply class insist on reusing its36predefined attributes *and* their units.37 38So, userspace gets predictable set of attributes and their units for any39kind of power supply, and can process/present them to a user in consistent40manner. Results for different power supplies and machines are also directly41comparable.42 43See drivers/power/supply/ds2760_battery.c for the example how to declare44and handle attributes.45 46 47Units48~~~~~49Quoting include/linux/power_supply.h:50 51 All voltages, currents, charges, energies, time and temperatures in µV,52 µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise53 stated. It's driver's job to convert its raw values to units in which54 this class operates.55 56 57Attributes/properties detailed58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~59 60+--------------------------------------------------------------------------+61| **Charge/Energy/Capacity - how to not confuse** |62+--------------------------------------------------------------------------+63| **Because both "charge" (µAh) and "energy" (µWh) represents "capacity" |64| of battery, this class distinguish these terms. Don't mix them!** |65| |66| - `CHARGE_*` |67| attributes represents capacity in µAh only. |68| - `ENERGY_*` |69| attributes represents capacity in µWh only. |70| - `CAPACITY` |71| attribute represents capacity in *percents*, from 0 to 100. |72+--------------------------------------------------------------------------+73 74Postfixes:75 76_AVG77 *hardware* averaged value, use it if your hardware is really able to78 report averaged values.79_NOW80 momentary/instantaneous values.81 82STATUS83 this attribute represents operating status (charging, full,84 discharging (i.e. powering a load), etc.). This corresponds to85 `BATTERY_STATUS_*` values, as defined in battery.h.86 87CHARGE_TYPE88 batteries can typically charge at different rates.89 This defines trickle and fast charges. For batteries that90 are already charged or discharging, 'n/a' can be displayed (or91 'unknown', if the status is not known).92 93AUTHENTIC94 indicates the power supply (battery or charger) connected95 to the platform is authentic(1) or non authentic(0).96 97HEALTH98 represents health of the battery, values corresponds to99 POWER_SUPPLY_HEALTH_*, defined in battery.h.100 101VOLTAGE_OCV102 open circuit voltage of the battery.103 104VOLTAGE_MAX_DESIGN, VOLTAGE_MIN_DESIGN105 design values for maximal and minimal power supply voltages.106 Maximal/minimal means values of voltages when battery considered107 "full"/"empty" at normal conditions. Yes, there is no direct relation108 between voltage and battery capacity, but some dumb109 batteries use voltage for very approximated calculation of capacity.110 Battery driver also can use this attribute just to inform userspace111 about maximal and minimal voltage thresholds of a given battery.112 113VOLTAGE_MAX, VOLTAGE_MIN114 same as _DESIGN voltage values except that these ones should be used115 if hardware could only guess (measure and retain) the thresholds of a116 given power supply.117 118VOLTAGE_BOOT119 Reports the voltage measured during boot120 121CURRENT_BOOT122 Reports the current measured during boot123 124CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN125 design charge values, when battery considered full/empty.126 127ENERGY_FULL_DESIGN, ENERGY_EMPTY_DESIGN128 same as above but for energy.129 130CHARGE_FULL, CHARGE_EMPTY131 These attributes means "last remembered value of charge when battery132 became full/empty". It also could mean "value of charge when battery133 considered full/empty at given conditions (temperature, age)".134 I.e. these attributes represents real thresholds, not design values.135 136ENERGY_FULL, ENERGY_EMPTY137 same as above but for energy.138 139CHARGE_COUNTER140 the current charge counter (in µAh). This could easily141 be negative; there is no empty or full value. It is only useful for142 relative, time-based measurements.143 144PRECHARGE_CURRENT145 the maximum charge current during precharge phase of charge cycle146 (typically 20% of battery capacity).147 148CHARGE_TERM_CURRENT149 Charge termination current. The charge cycle terminates when battery150 voltage is above recharge threshold, and charge current is below151 this setting (typically 10% of battery capacity).152 153CONSTANT_CHARGE_CURRENT154 constant charge current programmed by charger.155 156 157CONSTANT_CHARGE_CURRENT_MAX158 maximum charge current supported by the power supply object.159 160CONSTANT_CHARGE_VOLTAGE161 constant charge voltage programmed by charger.162CONSTANT_CHARGE_VOLTAGE_MAX163 maximum charge voltage supported by the power supply object.164 165INPUT_CURRENT_LIMIT166 input current limit programmed by charger. Indicates167 the current drawn from a charging source.168INPUT_VOLTAGE_LIMIT169 input voltage limit programmed by charger. Indicates170 the voltage limit from a charging source.171INPUT_POWER_LIMIT172 input power limit programmed by charger. Indicates173 the power limit from a charging source.174 175CHARGE_CONTROL_LIMIT176 current charge control limit setting177CHARGE_CONTROL_LIMIT_MAX178 maximum charge control limit setting179 180CALIBRATE181 battery or coulomb counter calibration status182 183CAPACITY184 capacity in percents.185CAPACITY_ALERT_MIN186 minimum capacity alert value in percents.187CAPACITY_ALERT_MAX188 maximum capacity alert value in percents.189CAPACITY_LEVEL190 capacity level. This corresponds to POWER_SUPPLY_CAPACITY_LEVEL_*.191 192TEMP193 temperature of the power supply.194TEMP_ALERT_MIN195 minimum battery temperature alert.196TEMP_ALERT_MAX197 maximum battery temperature alert.198TEMP_AMBIENT199 ambient temperature.200TEMP_AMBIENT_ALERT_MIN201 minimum ambient temperature alert.202TEMP_AMBIENT_ALERT_MAX203 maximum ambient temperature alert.204TEMP_MIN205 minimum operatable temperature206TEMP_MAX207 maximum operatable temperature208 209TIME_TO_EMPTY210 seconds left for battery to be considered empty211 (i.e. while battery powers a load)212TIME_TO_FULL213 seconds left for battery to be considered full214 (i.e. while battery is charging)215 216 217Battery <-> external power supply interaction218~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~219Often power supplies are acting as supplies and supplicants at the same220time. Batteries are good example. So, batteries usually care if they're221externally powered or not.222 223For that case, power supply class implements notification mechanism for224batteries.225 226External power supply (AC) lists supplicants (batteries) names in227"supplied_to" struct member, and each power_supply_changed() call228issued by external power supply will notify supplicants via229external_power_changed callback.230 231 232Devicetree battery characteristics233~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~234Drivers should call power_supply_get_battery_info() to obtain battery235characteristics from a devicetree battery node, defined in236Documentation/devicetree/bindings/power/supply/battery.yaml. This is237implemented in drivers/power/supply/bq27xxx_battery.c.238 239Properties in struct power_supply_battery_info and their counterparts in the240battery node have names corresponding to elements in enum power_supply_property,241for naming consistency between sysfs attributes and battery node properties.242 243 244QA245~~246 247Q:248 Where is POWER_SUPPLY_PROP_XYZ attribute?249A:250 If you cannot find attribute suitable for your driver needs, feel free251 to add it and send patch along with your driver.252 253 The attributes available currently are the ones currently provided by the254 drivers written.255 256 Good candidates to add in future: model/part#, cycle_time, manufacturer,257 etc.258 259 260Q:261 I have some very specific attribute (e.g. battery color), should I add262 this attribute to standard ones?263A:264 Most likely, no. Such attribute can be placed in the driver itself, if265 it is useful. Of course, if the attribute in question applicable to266 large set of batteries, provided by many drivers, and/or comes from267 some general battery specification/standard, it may be a candidate to268 be added to the core attribute set.269 270 271Q:272 Suppose, my battery monitoring chip/firmware does not provides capacity273 in percents, but provides charge_{now,full,empty}. Should I calculate274 percentage capacity manually, inside the driver, and register CAPACITY275 attribute? The same question about time_to_empty/time_to_full.276A:277 Most likely, no. This class is designed to export properties which are278 directly measurable by the specific hardware available.279 280 Inferring not available properties using some heuristics or mathematical281 model is not subject of work for a battery driver. Such functionality282 should be factored out, and in fact, apm_power, the driver to serve283 legacy APM API on top of power supply class, uses a simple heuristic of284 approximating remaining battery capacity based on its charge, current,285 voltage and so on. But full-fledged battery model is likely not subject286 for kernel at all, as it would require floating point calculation to deal287 with things like differential equations and Kalman filters. This is288 better be handled by batteryd/libbattery, yet to be written.289