Merge tag 'i2c-for-6.4-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / power_supply.h
CommitLineData
a63a5fa9 1/* SPDX-License-Identifier: GPL-2.0-only */
4a11b59d
AV
2/*
3 * Universal power supply monitor class
4 *
5 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
6 * Copyright © 2004 Szabolcs Gyurko
7 * Copyright © 2003 Ian Molton <spyro@f2s.com>
8 *
9 * Modified: 2004, Oct Szabolcs Gyurko
4a11b59d
AV
10 */
11
12#ifndef __LINUX_POWER_SUPPLY_H__
13#define __LINUX_POWER_SUPPLY_H__
14
297d716f 15#include <linux/device.h>
4a11b59d
AV
16#include <linux/workqueue.h>
17#include <linux/leds.h>
948dcf96 18#include <linux/spinlock.h>
d36240d2 19#include <linux/notifier.h>
4a11b59d
AV
20
21/*
22 * All voltages, currents, charges, energies, time and temperatures in uV,
23 * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
24 * stated. It's driver's job to convert its raw values to units in which
25 * this class operates.
26 */
27
28/*
29 * For systems where the charger determines the maximum battery capacity
30 * the min and max fields should be used to present these values to user
31 * space. Unused/unknown fields will not appear in sysfs.
32 */
33
34enum {
35 POWER_SUPPLY_STATUS_UNKNOWN = 0,
36 POWER_SUPPLY_STATUS_CHARGING,
37 POWER_SUPPLY_STATUS_DISCHARGING,
38 POWER_SUPPLY_STATUS_NOT_CHARGING,
39 POWER_SUPPLY_STATUS_FULL,
40};
41
ba6cc850 42/* What algorithm is the charger using? */
ee8076ed
AS
43enum {
44 POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
45 POWER_SUPPLY_CHARGE_TYPE_NONE,
ba6cc850
NC
46 POWER_SUPPLY_CHARGE_TYPE_TRICKLE, /* slow speed */
47 POWER_SUPPLY_CHARGE_TYPE_FAST, /* fast speed */
48 POWER_SUPPLY_CHARGE_TYPE_STANDARD, /* normal speed */
49 POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE, /* dynamically adjusted speed */
50 POWER_SUPPLY_CHARGE_TYPE_CUSTOM, /* use CHARGE_CONTROL_* props */
46cbd0b0 51 POWER_SUPPLY_CHARGE_TYPE_LONGLIFE, /* slow speed, longer life */
05f2281b 52 POWER_SUPPLY_CHARGE_TYPE_BYPASS, /* bypassing the charger */
ee8076ed
AS
53};
54
4a11b59d
AV
55enum {
56 POWER_SUPPLY_HEALTH_UNKNOWN = 0,
57 POWER_SUPPLY_HEALTH_GOOD,
58 POWER_SUPPLY_HEALTH_OVERHEAT,
59 POWER_SUPPLY_HEALTH_DEAD,
60 POWER_SUPPLY_HEALTH_OVERVOLTAGE,
61 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
7e386e6e 62 POWER_SUPPLY_HEALTH_COLD,
a05be991
RP
63 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
64 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
e3e83cc6 65 POWER_SUPPLY_HEALTH_OVERCURRENT,
601c2a54 66 POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED,
98cc1b93
DM
67 POWER_SUPPLY_HEALTH_WARM,
68 POWER_SUPPLY_HEALTH_COOL,
69 POWER_SUPPLY_HEALTH_HOT,
77d641ba 70 POWER_SUPPLY_HEALTH_NO_BATTERY,
4a11b59d
AV
71};
72
73enum {
74 POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0,
75 POWER_SUPPLY_TECHNOLOGY_NiMH,
76 POWER_SUPPLY_TECHNOLOGY_LION,
77 POWER_SUPPLY_TECHNOLOGY_LIPO,
78 POWER_SUPPLY_TECHNOLOGY_LiFe,
79 POWER_SUPPLY_TECHNOLOGY_NiCd,
c7cc930f 80 POWER_SUPPLY_TECHNOLOGY_LiMn,
4a11b59d
AV
81};
82
b294a290
AS
83enum {
84 POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
85 POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
86 POWER_SUPPLY_CAPACITY_LEVEL_LOW,
87 POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
88 POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
89 POWER_SUPPLY_CAPACITY_LEVEL_FULL,
90};
91
25a0bc2d
JF
92enum {
93 POWER_SUPPLY_SCOPE_UNKNOWN = 0,
94 POWER_SUPPLY_SCOPE_SYSTEM,
95 POWER_SUPPLY_SCOPE_DEVICE,
96};
97
4a11b59d
AV
98enum power_supply_property {
99 /* Properties of type `int' */
100 POWER_SUPPLY_PROP_STATUS = 0,
ee8076ed 101 POWER_SUPPLY_PROP_CHARGE_TYPE,
4a11b59d
AV
102 POWER_SUPPLY_PROP_HEALTH,
103 POWER_SUPPLY_PROP_PRESENT,
104 POWER_SUPPLY_PROP_ONLINE,
b1b56872 105 POWER_SUPPLY_PROP_AUTHENTIC,
4a11b59d 106 POWER_SUPPLY_PROP_TECHNOLOGY,
c955fe8e 107 POWER_SUPPLY_PROP_CYCLE_COUNT,
c7cc930f
DB
108 POWER_SUPPLY_PROP_VOLTAGE_MAX,
109 POWER_SUPPLY_PROP_VOLTAGE_MIN,
4a11b59d
AV
110 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
111 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
112 POWER_SUPPLY_PROP_VOLTAGE_NOW,
113 POWER_SUPPLY_PROP_VOLTAGE_AVG,
a2ebfe2f 114 POWER_SUPPLY_PROP_VOLTAGE_OCV,
a8adcc90 115 POWER_SUPPLY_PROP_VOLTAGE_BOOT,
fe3f6d09 116 POWER_SUPPLY_PROP_CURRENT_MAX,
4a11b59d
AV
117 POWER_SUPPLY_PROP_CURRENT_NOW,
118 POWER_SUPPLY_PROP_CURRENT_AVG,
a8adcc90 119 POWER_SUPPLY_PROP_CURRENT_BOOT,
7faa144a
AS
120 POWER_SUPPLY_PROP_POWER_NOW,
121 POWER_SUPPLY_PROP_POWER_AVG,
4a11b59d
AV
122 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
123 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
124 POWER_SUPPLY_PROP_CHARGE_FULL,
125 POWER_SUPPLY_PROP_CHARGE_EMPTY,
126 POWER_SUPPLY_PROP_CHARGE_NOW,
127 POWER_SUPPLY_PROP_CHARGE_AVG,
8e552c36 128 POWER_SUPPLY_PROP_CHARGE_COUNTER,
3824c477 129 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
2815b786 130 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
3824c477 131 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
2815b786 132 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
ea2ce92e
RP
133 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
134 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
813cab8f
NC
135 POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */
136 POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */
1b0b6cc8 137 POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
6bb1d272 138 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
a4496d52
EBS
139 POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
140 POWER_SUPPLY_PROP_INPUT_POWER_LIMIT,
4a11b59d
AV
141 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
142 POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
143 POWER_SUPPLY_PROP_ENERGY_FULL,
144 POWER_SUPPLY_PROP_ENERGY_EMPTY,
145 POWER_SUPPLY_PROP_ENERGY_NOW,
146 POWER_SUPPLY_PROP_ENERGY_AVG,
147 POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
e908c418
RP
148 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */
149 POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
bac705ab 150 POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */
b294a290 151 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
4a11b59d 152 POWER_SUPPLY_PROP_TEMP,
6bb1d272
JT
153 POWER_SUPPLY_PROP_TEMP_MAX,
154 POWER_SUPPLY_PROP_TEMP_MIN,
e908c418
RP
155 POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
156 POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
4a11b59d 157 POWER_SUPPLY_PROP_TEMP_AMBIENT,
e908c418
RP
158 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
159 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
4a11b59d
AV
160 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
161 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
162 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
163 POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
5f487cd3 164 POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
cf450041 165 POWER_SUPPLY_PROP_USB_TYPE,
25a0bc2d 166 POWER_SUPPLY_PROP_SCOPE,
413de34a 167 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
6bb1d272 168 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
a8adcc90 169 POWER_SUPPLY_PROP_CALIBRATE,
feabe49e
SR
170 POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
171 POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
172 POWER_SUPPLY_PROP_MANUFACTURE_DAY,
4a11b59d
AV
173 /* Properties of type `const char *' */
174 POWER_SUPPLY_PROP_MODEL_NAME,
175 POWER_SUPPLY_PROP_MANUFACTURER,
7c2670bb 176 POWER_SUPPLY_PROP_SERIAL_NUMBER,
4a11b59d
AV
177};
178
179enum power_supply_type {
9b887227
KM
180 POWER_SUPPLY_TYPE_UNKNOWN = 0,
181 POWER_SUPPLY_TYPE_BATTERY,
4a11b59d
AV
182 POWER_SUPPLY_TYPE_UPS,
183 POWER_SUPPLY_TYPE_MAINS,
71399aa5
BL
184 POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */
185 POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */
186 POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */
187 POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */
188 POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */
189 POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */
190 POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */
191 POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
5ca937fb 192 POWER_SUPPLY_TYPE_WIRELESS, /* Wireless */
4a11b59d
AV
193};
194
cf450041
AT
195enum power_supply_usb_type {
196 POWER_SUPPLY_USB_TYPE_UNKNOWN = 0,
197 POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */
198 POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */
199 POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */
200 POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */
201 POWER_SUPPLY_USB_TYPE_C, /* Type C Port */
202 POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */
203 POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */
204 POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */
205 POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
206};
207
1b0b6cc8
TW
208enum power_supply_charge_behaviour {
209 POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO = 0,
210 POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE,
211 POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE,
212};
213
d36240d2
PR
214enum power_supply_notifier_events {
215 PSY_EVENT_PROP_CHANGED,
216};
217
4a11b59d
AV
218union power_supply_propval {
219 int intval;
220 const char *strval;
221};
222
b50df95c 223struct device_node;
297d716f 224struct power_supply;
b50df95c 225
297d716f 226/* Run-time specific power supply configuration */
2dc9215d
KK
227struct power_supply_config {
228 struct device_node *of_node;
ece711b5
AT
229 struct fwnode_handle *fwnode;
230
2dc9215d
KK
231 /* Driver private data */
232 void *drv_data;
233
cef8fe6a
SR
234 /* Device specific sysfs attributes */
235 const struct attribute_group **attr_grp;
236
2dc9215d
KK
237 char **supplied_to;
238 size_t num_supplicants;
239};
240
297d716f
KK
241/* Description of power supply */
242struct power_supply_desc {
4a11b59d
AV
243 const char *name;
244 enum power_supply_type type;
9ba2353b 245 const enum power_supply_usb_type *usb_types;
cf450041 246 size_t num_usb_types;
9ba2353b 247 const enum power_supply_property *properties;
4a11b59d
AV
248 size_t num_properties;
249
bc154056
KK
250 /*
251 * Functions for drivers implementing power supply class.
252 * These shouldn't be called directly by other drivers for accessing
253 * this power supply. Instead use power_supply_*() functions (for
254 * example power_supply_get_property()).
255 */
4a11b59d
AV
256 int (*get_property)(struct power_supply *psy,
257 enum power_supply_property psp,
258 union power_supply_propval *val);
0011d2d4
DM
259 int (*set_property)(struct power_supply *psy,
260 enum power_supply_property psp,
261 const union power_supply_propval *val);
5c6e3a97
KK
262 /*
263 * property_is_writeable() will be called during registration
264 * of power supply. If this happens during device probe then it must
265 * not access internal data of device (because probe did not end).
266 */
0011d2d4
DM
267 int (*property_is_writeable)(struct power_supply *psy,
268 enum power_supply_property psp);
4a11b59d 269 void (*external_power_changed)(struct power_supply *psy);
e5f5ccb6 270 void (*set_charged)(struct power_supply *psy);
4a11b59d 271
a69d82b9
KK
272 /*
273 * Set if thermal zone should not be created for this power supply.
274 * For example for virtual supplies forwarding calls to actual
275 * sensors or other supplies.
276 */
277 bool no_thermal;
4a11b59d
AV
278 /* For APM emulation, think legacy userspace. */
279 int use_for_apm;
297d716f
KK
280};
281
282struct power_supply {
283 const struct power_supply_desc *desc;
284
285 char **supplied_to;
286 size_t num_supplicants;
287
288 char **supplied_from;
289 size_t num_supplies;
290 struct device_node *of_node;
4a11b59d 291
e44ea364
KK
292 /* Driver private data */
293 void *drv_data;
294
4a11b59d 295 /* private */
297d716f 296 struct device dev;
4a11b59d 297 struct work_struct changed_work;
7f1a57fd 298 struct delayed_work deferred_register_work;
948dcf96
ZM
299 spinlock_t changed_lock;
300 bool changed;
e3805385 301 bool initialized;
3ffa6583 302 bool removing;
bc154056 303 atomic_t use_cnt;
27a2195e 304 struct power_supply_battery_info *battery_info;
3be330bf
JT
305#ifdef CONFIG_THERMAL
306 struct thermal_zone_device *tzd;
952aeeb3 307 struct thermal_cooling_device *tcd;
3be330bf 308#endif
4a11b59d
AV
309
310#ifdef CONFIG_LEDS_TRIGGERS
311 struct led_trigger *charging_full_trig;
312 char *charging_full_trig_name;
313 struct led_trigger *charging_trig;
314 char *charging_trig_name;
315 struct led_trigger *full_trig;
316 char *full_trig_name;
317 struct led_trigger *online_trig;
318 char *online_trig_name;
6501f728
VK
319 struct led_trigger *charging_blink_full_solid_trig;
320 char *charging_blink_full_solid_trig_name;
4a11b59d
AV
321#endif
322};
323
324/*
325 * This is recommended structure to specify static power supply parameters.
326 * Generic one, parametrizable for different power supplies. Power supply
327 * class itself does not use it, but that's what implementing most platform
328 * drivers, should try reuse for consistency.
329 */
330
331struct power_supply_info {
332 const char *name;
333 int technology;
334 int voltage_max_design;
335 int voltage_min_design;
336 int charge_full_design;
337 int charge_empty_design;
338 int energy_full_design;
339 int energy_empty_design;
340 int use_for_apm;
341};
342
3afb50d7
BW
343struct power_supply_battery_ocv_table {
344 int ocv; /* microVolts */
345 int capacity; /* percent */
346};
347
65dbad71
BW
348struct power_supply_resistance_temp_table {
349 int temp; /* celsius */
350 int resistance; /* internal resistance percent */
351};
352
e9e7d165
LW
353struct power_supply_vbat_ri_table {
354 int vbat_uv; /* Battery voltage in microvolt */
355 int ri_uohm; /* Internal resistance in microohm */
356};
357
d72ce7d3
LW
358/**
359 * struct power_supply_maintenance_charge_table - setting for maintenace charging
360 * @charge_current_max_ua: maintenance charging current that is used to keep
361 * the charge of the battery full as current is consumed after full charging.
362 * The corresponding charge_voltage_max_uv is used as a safeguard: when we
363 * reach this voltage the maintenance charging current is turned off. It is
364 * turned back on if we fall below this voltage.
365 * @charge_voltage_max_uv: maintenance charging voltage that is usually a bit
366 * lower than the constant_charge_voltage_max_uv. We can apply this settings
367 * charge_current_max_ua until we get back up to this voltage.
368 * @safety_timer_minutes: maintenance charging safety timer, with an expiry
369 * time in minutes. We will only use maintenance charging in this setting
370 * for a certain amount of time, then we will first move to the next
371 * maintenance charge current and voltage pair in respective array and wait
372 * for the next safety timer timeout, or, if we reached the last maintencance
373 * charging setting, disable charging until we reach
374 * charge_restart_voltage_uv and restart ordinary CC/CV charging from there.
375 * These timers should be chosen to align with the typical discharge curve
376 * for the battery.
377 *
a1c7c1a4
LW
378 * Ordinary CC/CV charging will stop charging when the charge current goes
379 * below charge_term_current_ua, and then restart it (if the device is still
380 * plugged into the charger) at charge_restart_voltage_uv. This happens in most
381 * consumer products because the power usage while connected to a charger is
382 * not zero, and devices are not manufactured to draw power directly from the
383 * charger: instead they will at all times dissipate the battery a little, like
384 * the power used in standby mode. This will over time give a charge graph
385 * such as this:
386 *
387 * Energy
388 * ^ ... ... ... ... ... ... ...
389 * | . . . . . . . . . . . . .
390 * | .. . .. . .. . .. . .. . .. . ..
391 * |. .. .. .. .. .. ..
392 * +-------------------------------------------------------------------> t
393 *
394 * Practically this means that the Li-ions are wandering back and forth in the
395 * battery and this causes degeneration of the battery anode and cathode.
396 * To prolong the life of the battery, maintenance charging is applied after
397 * reaching charge_term_current_ua to hold up the charge in the battery while
398 * consuming power, thus lowering the wear on the battery:
399 *
400 * Energy
401 * ^ .......................................
402 * | . ......................
403 * | ..
404 * |.
405 * +-------------------------------------------------------------------> t
406 *
407 * Maintenance charging uses the voltages from this table: a table of settings
408 * is traversed using a slightly lower current and voltage than what is used for
d72ce7d3
LW
409 * CC/CV charging. The maintenance charging will for safety reasons not go on
410 * indefinately: we lower the current and voltage with successive maintenance
411 * settings, then disable charging completely after we reach the last one,
412 * and after that we do not restart charging until we reach
413 * charge_restart_voltage_uv (see struct power_supply_battery_info) and restart
414 * ordinary CC/CV charging from there.
415 *
416 * As an example, a Samsung EB425161LA Lithium-Ion battery is CC/CV charged
a1c7c1a4
LW
417 * at 900mA to 4340mV, then maintenance charged at 600mA and 4150mV for up to
418 * 60 hours, then maintenance charged at 600mA and 4100mV for up to 200 hours.
d72ce7d3
LW
419 * After this the charge cycle is restarted waiting for
420 * charge_restart_voltage_uv.
421 *
422 * For most mobile electronics this type of maintenance charging is enough for
423 * the user to disconnect the device and make use of it before both maintenance
a1c7c1a4
LW
424 * charging cycles are complete, if the current and voltage has been chosen
425 * appropriately. These need to be determined from battery discharge curves
426 * and expected standby current.
427 *
428 * If the voltage anyway drops to charge_restart_voltage_uv during maintenance
429 * charging, ordinary CC/CV charging is restarted. This can happen if the
430 * device is e.g. actively used during charging, so more current is drawn than
431 * the expected stand-by current. Also overvoltage protection will be applied
432 * as usual.
d72ce7d3
LW
433 */
434struct power_supply_maintenance_charge_table {
435 int charge_current_max_ua;
436 int charge_voltage_max_uv;
437 int charge_safety_timer_minutes;
438};
439
3afb50d7
BW
440#define POWER_SUPPLY_OCV_TEMP_MAX 20
441
e0dbd7b0
LW
442/**
443 * struct power_supply_battery_info - information about batteries
444 * @technology: from the POWER_SUPPLY_TECHNOLOGY_* enum
445 * @energy_full_design_uwh: energy content when fully charged in microwatt
446 * hours
447 * @charge_full_design_uah: charge content when fully charged in microampere
448 * hours
449 * @voltage_min_design_uv: minimum voltage across the poles when the battery
450 * is at minimum voltage level in microvolts. If the voltage drops below this
451 * level the battery will need precharging when using CC/CV charging.
452 * @voltage_max_design_uv: voltage across the poles when the battery is fully
453 * charged in microvolts. This is the "nominal voltage" i.e. the voltage
454 * printed on the label of the battery.
455 * @tricklecharge_current_ua: the tricklecharge current used when trickle
456 * charging the battery in microamperes. This is the charging phase when the
457 * battery is completely empty and we need to carefully trickle in some
458 * charge until we reach the precharging voltage.
459 * @precharge_current_ua: current to use in the precharge phase in microamperes,
460 * the precharge rate is limited by limiting the current to this value.
461 * @precharge_voltage_max_uv: the maximum voltage allowed when precharging in
462 * microvolts. When we pass this voltage we will nominally switch over to the
463 * CC (constant current) charging phase defined by constant_charge_current_ua
464 * and constant_charge_voltage_max_uv.
465 * @charge_term_current_ua: when the current in the CV (constant voltage)
466 * charging phase drops below this value in microamperes the charging will
467 * terminate completely and not restart until the voltage over the battery
468 * poles reach charge_restart_voltage_uv unless we use maintenance charging.
469 * @charge_restart_voltage_uv: when the battery has been fully charged by
470 * CC/CV charging and charging has been disabled, and the voltage subsequently
471 * drops below this value in microvolts, the charging will be restarted
472 * (typically using CV charging).
473 * @overvoltage_limit_uv: If the voltage exceeds the nominal voltage
474 * voltage_max_design_uv and we reach this voltage level, all charging must
475 * stop and emergency procedures take place, such as shutting down the system
476 * in some cases.
477 * @constant_charge_current_max_ua: current in microamperes to use in the CC
478 * (constant current) charging phase. The charging rate is limited
479 * by this current. This is the main charging phase and as the current is
480 * constant into the battery the voltage slowly ascends to
481 * constant_charge_voltage_max_uv.
482 * @constant_charge_voltage_max_uv: voltage in microvolts signifying the end of
483 * the CC (constant current) charging phase and the beginning of the CV
484 * (constant voltage) charging phase.
d72ce7d3
LW
485 * @maintenance_charge: an array of maintenance charging settings to be used
486 * after the main CC/CV charging phase is complete.
487 * @maintenance_charge_size: the number of maintenance charging settings in
488 * maintenance_charge.
0e8b903b
LW
489 * @alert_low_temp_charge_current_ua: The charging current to use if the battery
490 * enters low alert temperature, i.e. if the internal temperature is between
491 * temp_alert_min and temp_min. No matter the charging phase, this
492 * and alert_high_temp_charge_voltage_uv will be applied.
493 * @alert_low_temp_charge_voltage_uv: Same as alert_low_temp_charge_current_ua,
494 * but for the charging voltage.
495 * @alert_high_temp_charge_current_ua: The charging current to use if the
496 * battery enters high alert temperature, i.e. if the internal temperature is
497 * between temp_alert_max and temp_max. No matter the charging phase, this
498 * and alert_high_temp_charge_voltage_uv will be applied, usually lowering
499 * the charging current as an evasive manouver.
500 * @alert_high_temp_charge_voltage_uv: Same as
501 * alert_high_temp_charge_current_ua, but for the charging voltage.
e0dbd7b0
LW
502 * @factory_internal_resistance_uohm: the internal resistance of the battery
503 * at fabrication time, expressed in microohms. This resistance will vary
504 * depending on the lifetime and charge of the battery, so this is just a
e9e7d165
LW
505 * nominal ballpark figure. This internal resistance is given for the state
506 * when the battery is discharging.
507 * @factory_internal_resistance_charging_uohm: the internal resistance of the
508 * battery at fabrication time while charging, expressed in microohms.
509 * The charging process will affect the internal resistance of the battery
510 * so this value provides a better resistance under these circumstances.
511 * This resistance will vary depending on the lifetime and charge of the
512 * battery, so this is just a nominal ballpark figure.
e0dbd7b0
LW
513 * @ocv_temp: array indicating the open circuit voltage (OCV) capacity
514 * temperature indices. This is an array of temperatures in degrees Celsius
515 * indicating which capacity table to use for a certain temperature, since
516 * the capacity for reasons of chemistry will be different at different
517 * temperatures. Determining capacity is a multivariate problem and the
518 * temperature is the first variable we determine.
519 * @temp_ambient_alert_min: the battery will go outside of operating conditions
520 * when the ambient temperature goes below this temperature in degrees
521 * Celsius.
522 * @temp_ambient_alert_max: the battery will go outside of operating conditions
523 * when the ambient temperature goes above this temperature in degrees
524 * Celsius.
525 * @temp_alert_min: the battery should issue an alert if the internal
526 * temperature goes below this temperature in degrees Celsius.
527 * @temp_alert_max: the battery should issue an alert if the internal
528 * temperature goes above this temperature in degrees Celsius.
529 * @temp_min: the battery will go outside of operating conditions when
530 * the internal temperature goes below this temperature in degrees Celsius.
531 * Normally this means the system should shut down.
532 * @temp_max: the battery will go outside of operating conditions when
533 * the internal temperature goes above this temperature in degrees Celsius.
534 * Normally this means the system should shut down.
535 * @ocv_table: for each entry in ocv_temp there is a corresponding entry in
536 * ocv_table and a size for each entry in ocv_table_size. These arrays
537 * determine the capacity in percent in relation to the voltage in microvolts
538 * at the indexed temperature.
539 * @ocv_table_size: for each entry in ocv_temp this array is giving the size of
540 * each entry in the array of capacity arrays in ocv_table.
541 * @resist_table: this is a table that correlates a battery temperature to the
542 * expected internal resistance at this temperature. The resistance is given
543 * as a percentage of factory_internal_resistance_uohm. Knowing the
544 * resistance of the battery is usually necessary for calculating the open
545 * circuit voltage (OCV) that is then used with the ocv_table to calculate
546 * the capacity of the battery. The resist_table must be ordered descending
547 * by temperature: highest temperature with lowest resistance first, lowest
548 * temperature with highest resistance last.
549 * @resist_table_size: the number of items in the resist_table.
e9e7d165
LW
550 * @vbat2ri_discharging: this is a table that correlates Battery voltage (VBAT)
551 * to internal resistance (Ri). The resistance is given in microohm for the
552 * corresponding voltage in microvolts. The internal resistance is used to
553 * determine the open circuit voltage so that we can determine the capacity
554 * of the battery. These voltages to resistance tables apply when the battery
555 * is discharging. The table must be ordered descending by voltage: highest
556 * voltage first.
557 * @vbat2ri_discharging_size: the number of items in the vbat2ri_discharging
558 * table.
559 * @vbat2ri_charging: same function as vbat2ri_discharging but for the state
560 * when the battery is charging. Being under charge changes the battery's
561 * internal resistance characteristics so a separate table is needed.*
562 * The table must be ordered descending by voltage: highest voltage first.
563 * @vbat2ri_charging_size: the number of items in the vbat2ri_charging
564 * table.
1f918e0f
LW
565 * @bti_resistance_ohm: The Battery Type Indicator (BIT) nominal resistance
566 * in ohms for this battery, if an identification resistor is mounted
567 * between a third battery terminal and ground. This scheme is used by a lot
568 * of mobile device batteries.
569 * @bti_resistance_tolerance: The tolerance in percent of the BTI resistance,
570 * for example 10 for +/- 10%, if the bti_resistance is set to 7000 and the
571 * tolerance is 10% we will detect a proper battery if the BTI resistance
572 * is between 6300 and 7700 Ohm.
e0dbd7b0 573 *
c08b1f45
LB
574 * This is the recommended struct to manage static battery parameters,
575 * populated by power_supply_get_battery_info(). Most platform drivers should
576 * use these for consistency.
e0dbd7b0 577 *
c08b1f45 578 * Its field names must correspond to elements in enum power_supply_property.
e9e7d165
LW
579 * The default field value is -EINVAL or NULL for pointers.
580 *
581 * CC/CV CHARGING:
e0dbd7b0
LW
582 *
583 * The charging parameters here assume a CC/CV charging scheme. This method
584 * is most common with Lithium Ion batteries (other methods are possible) and
585 * looks as follows:
586 *
587 * ^ Battery voltage
588 * | --- overvoltage_limit_uv
589 * |
590 * | ...................................................
591 * | .. constant_charge_voltage_max_uv
592 * | ..
593 * | .
594 * | .
595 * | .
596 * | .
597 * | .
598 * | .. precharge_voltage_max_uv
599 * | ..
600 * |. (trickle charging)
601 * +------------------------------------------------------------------> time
602 *
603 * ^ Current into the battery
604 * |
605 * | ............. constant_charge_current_max_ua
606 * | . .
607 * | . .
608 * | . .
609 * | . .
610 * | . ..
611 * | . ....
612 * | . .....
613 * | ... precharge_current_ua ....... charge_term_current_ua
614 * | . .
615 * | . .
616 * |.... tricklecharge_current_ua .
617 * | .
618 * +-----------------------------------------------------------------> time
619 *
620 * These diagrams are synchronized on time and the voltage and current
621 * follow each other.
622 *
623 * With CC/CV charging commence over time like this for an empty battery:
624 *
625 * 1. When the battery is completely empty it may need to be charged with
626 * an especially small current so that electrons just "trickle in",
627 * this is the tricklecharge_current_ua.
628 *
629 * 2. Next a small initial pre-charge current (precharge_current_ua)
630 * is applied if the voltage is below precharge_voltage_max_uv until we
631 * reach precharge_voltage_max_uv. CAUTION: in some texts this is referred
632 * to as "trickle charging" but the use in the Linux kernel is different
633 * see below!
634 *
635 * 3. Then the main charging current is applied, which is called the constant
636 * current (CC) phase. A current regulator is set up to allow
637 * constant_charge_current_max_ua of current to flow into the battery.
638 * The chemical reaction in the battery will make the voltage go up as
639 * charge goes into the battery. This current is applied until we reach
640 * the constant_charge_voltage_max_uv voltage.
641 *
642 * 4. At this voltage we switch over to the constant voltage (CV) phase. This
643 * means we allow current to go into the battery, but we keep the voltage
644 * fixed. This current will continue to charge the battery while keeping
645 * the voltage the same. A chemical reaction in the battery goes on
646 * storing energy without affecting the voltage. Over time the current
647 * will slowly drop and when we reach charge_term_current_ua we will
648 * end the constant voltage phase.
649 *
650 * After this the battery is fully charged, and if we do not support maintenance
651 * charging, the charging will not restart until power dissipation makes the
652 * voltage fall so that we reach charge_restart_voltage_uv and at this point
653 * we restart charging at the appropriate phase, usually this will be inside
654 * the CV phase.
655 *
656 * If we support maintenance charging the voltage is however kept high after
657 * the CV phase with a very low current. This is meant to let the same charge
658 * go in for usage while the charger is still connected, mainly for
659 * dissipation for the power consuming entity while connected to the
660 * charger.
661 *
662 * All charging MUST terminate if the overvoltage_limit_uv is ever reached.
663 * Overcharging Lithium Ion cells can be DANGEROUS and lead to fire or
664 * explosions.
665 *
e9e7d165
LW
666 * DETERMINING BATTERY CAPACITY:
667 *
668 * Several members of the struct deal with trying to determine the remaining
669 * capacity in the battery, usually as a percentage of charge. In practice
670 * many chargers uses a so-called fuel gauge or coloumb counter that measure
671 * how much charge goes into the battery and how much goes out (+/- leak
672 * consumption). This does not help if we do not know how much capacity the
673 * battery has to begin with, such as when it is first used or was taken out
674 * and charged in a separate charger. Therefore many capacity algorithms use
675 * the open circuit voltage with a look-up table to determine the rough
676 * capacity of the battery. The open circuit voltage can be conceptualized
677 * with an ideal voltage source (V) in series with an internal resistance (Ri)
678 * like this:
679 *
680 * +-------> IBAT >----------------+
681 * | ^ |
682 * [ ] Ri | |
683 * | | VBAT |
684 * o <---------- | |
685 * +| ^ | [ ] Rload
686 * .---. | | |
687 * | V | | OCV | |
688 * '---' | | |
689 * | | | |
690 * GND +-------------------------------+
691 *
692 * If we disconnect the load (here simplified as a fixed resistance Rload)
693 * and measure VBAT with a infinite impedance voltage meter we will get
694 * VBAT = OCV and this assumption is sometimes made even under load, assuming
695 * Rload is insignificant. However this will be of dubious quality because the
696 * load is rarely that small and Ri is strongly nonlinear depending on
697 * temperature and how much capacity is left in the battery due to the
698 * chemistry involved.
699 *
700 * In many practical applications we cannot just disconnect the battery from
701 * the load, so instead we often try to measure the instantaneous IBAT (the
702 * current out from the battery), estimate the Ri and thus calculate the
703 * voltage drop over Ri and compensate like this:
704 *
705 * OCV = VBAT - (IBAT * Ri)
706 *
707 * The tables vbat2ri_discharging and vbat2ri_charging are used to determine
708 * (by interpolation) the Ri from the VBAT under load. These curves are highly
709 * nonlinear and may need many datapoints but can be found in datasheets for
710 * some batteries. This gives the compensated open circuit voltage (OCV) for
711 * the battery even under load. Using this method will also compensate for
712 * temperature changes in the environment: this will also make the internal
713 * resistance change, and it will affect the VBAT under load, so correlating
714 * VBAT to Ri takes both remaining capacity and temperature into consideration.
715 *
716 * Alternatively a manufacturer can specify how the capacity of the battery
717 * is dependent on the battery temperature which is the main factor affecting
718 * Ri. As we know all checmical reactions are faster when it is warm and slower
719 * when it is cold. You can put in 1500mAh and only get 800mAh out before the
720 * voltage drops too low for example. This effect is also highly nonlinear and
721 * the purpose of the table resist_table: this will take a temperature and
722 * tell us how big percentage of Ri the specified temperature correlates to.
723 * Usually we have 100% of the factory_internal_resistance_uohm at 25 degrees
724 * Celsius.
725 *
e0dbd7b0 726 * The power supply class itself doesn't use this struct as of now.
c08b1f45
LB
727 */
728
729struct power_supply_battery_info {
e0dbd7b0
LW
730 unsigned int technology;
731 int energy_full_design_uwh;
732 int charge_full_design_uah;
733 int voltage_min_design_uv;
734 int voltage_max_design_uv;
735 int tricklecharge_current_ua;
736 int precharge_current_ua;
737 int precharge_voltage_max_uv;
738 int charge_term_current_ua;
739 int charge_restart_voltage_uv;
740 int overvoltage_limit_uv;
741 int constant_charge_current_max_ua;
742 int constant_charge_voltage_max_uv;
d72ce7d3
LW
743 struct power_supply_maintenance_charge_table *maintenance_charge;
744 int maintenance_charge_size;
0e8b903b
LW
745 int alert_low_temp_charge_current_ua;
746 int alert_low_temp_charge_voltage_uv;
747 int alert_high_temp_charge_current_ua;
748 int alert_high_temp_charge_voltage_uv;
e0dbd7b0 749 int factory_internal_resistance_uohm;
e9e7d165 750 int factory_internal_resistance_charging_uohm;
e0dbd7b0
LW
751 int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];
752 int temp_ambient_alert_min;
753 int temp_ambient_alert_max;
754 int temp_alert_min;
755 int temp_alert_max;
756 int temp_min;
757 int temp_max;
3afb50d7
BW
758 struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX];
759 int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
65dbad71
BW
760 struct power_supply_resistance_temp_table *resist_table;
761 int resist_table_size;
e9e7d165
LW
762 struct power_supply_vbat_ri_table *vbat2ri_discharging;
763 int vbat2ri_discharging_size;
764 struct power_supply_vbat_ri_table *vbat2ri_charging;
765 int vbat2ri_charging_size;
1f918e0f
LW
766 int bti_resistance_ohm;
767 int bti_resistance_tolerance;
c08b1f45
LB
768};
769
d36240d2
PR
770extern struct atomic_notifier_head power_supply_notifier;
771extern int power_supply_reg_notifier(struct notifier_block *nb);
772extern void power_supply_unreg_notifier(struct notifier_block *nb);
f38a1644 773#if IS_ENABLED(CONFIG_POWER_SUPPLY)
9f3b795a 774extern struct power_supply *power_supply_get_by_name(const char *name);
1a352462 775extern void power_supply_put(struct power_supply *psy);
f38a1644
RC
776#else
777static inline void power_supply_put(struct power_supply *psy) {}
778static inline struct power_supply *power_supply_get_by_name(const char *name)
779{ return NULL; }
780#endif
abce9770
SR
781#ifdef CONFIG_OF
782extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
783 const char *property);
fe27e1df
HG
784extern struct power_supply *devm_power_supply_get_by_phandle(
785 struct device *dev, const char *property);
abce9770
SR
786#else /* !CONFIG_OF */
787static inline struct power_supply *
788power_supply_get_by_phandle(struct device_node *np, const char *property)
789{ return NULL; }
fe27e1df
HG
790static inline struct power_supply *
791devm_power_supply_get_by_phandle(struct device *dev, const char *property)
792{ return NULL; }
abce9770 793#endif /* CONFIG_OF */
c08b1f45 794
27a2195e
SR
795extern const enum power_supply_property power_supply_battery_info_properties[];
796extern const size_t power_supply_battery_info_properties_size;
c08b1f45 797extern int power_supply_get_battery_info(struct power_supply *psy,
25fd3303 798 struct power_supply_battery_info **info_out);
3afb50d7
BW
799extern void power_supply_put_battery_info(struct power_supply *psy,
800 struct power_supply_battery_info *info);
27a2195e
SR
801extern bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info,
802 enum power_supply_property psp);
803extern int power_supply_battery_info_get_prop(struct power_supply_battery_info *info,
804 enum power_supply_property psp,
805 union power_supply_propval *val);
3afb50d7
BW
806extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
807 int table_len, int ocv);
808extern struct power_supply_battery_ocv_table *
809power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
810 int temp, int *table_len);
811extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
812 int ocv, int temp);
65dbad71
BW
813extern int
814power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
815 int table_len, int temp);
e9e7d165
LW
816extern int power_supply_vbat2ri(struct power_supply_battery_info *info,
817 int vbat_uv, bool charging);
d72ce7d3
LW
818extern struct power_supply_maintenance_charge_table *
819power_supply_get_maintenance_charging_setting(struct power_supply_battery_info *info, int index);
1f918e0f
LW
820extern bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
821 int resistance);
4a11b59d
AV
822extern void power_supply_changed(struct power_supply *psy);
823extern int power_supply_am_i_supplied(struct power_supply *psy);
2220af8c
HG
824int power_supply_get_property_from_supplier(struct power_supply *psy,
825 enum power_supply_property psp,
826 union power_supply_propval *val);
e5f5ccb6 827extern int power_supply_set_battery_charged(struct power_supply *psy);
4a11b59d 828
d72ce7d3
LW
829static inline bool
830power_supply_supports_maintenance_charging(struct power_supply_battery_info *info)
831{
832 struct power_supply_maintenance_charge_table *mt;
833
834 mt = power_supply_get_maintenance_charging_setting(info, 0);
835
836 return (mt != NULL);
837}
838
e9e7d165
LW
839static inline bool
840power_supply_supports_vbat2ri(struct power_supply_battery_info *info)
841{
842 return ((info->vbat2ri_discharging != NULL) &&
843 info->vbat2ri_discharging_size > 0);
844}
845
846static inline bool
847power_supply_supports_temp2ri(struct power_supply_battery_info *info)
848{
849 return ((info->resist_table != NULL) &&
850 info->resist_table_size > 0);
851}
1f918e0f 852
0d4ed4e2 853#ifdef CONFIG_POWER_SUPPLY
942ed161
MG
854extern int power_supply_is_system_supplied(void);
855#else
856static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
857#endif
858
bc154056
KK
859extern int power_supply_get_property(struct power_supply *psy,
860 enum power_supply_property psp,
861 union power_supply_propval *val);
c21161e4 862#if IS_ENABLED(CONFIG_POWER_SUPPLY)
bc154056
KK
863extern int power_supply_set_property(struct power_supply *psy,
864 enum power_supply_property psp,
865 const union power_supply_propval *val);
c21161e4
RC
866#else
867static inline int power_supply_set_property(struct power_supply *psy,
868 enum power_supply_property psp,
869 const union power_supply_propval *val)
870{ return 0; }
871#endif
bc154056
KK
872extern int power_supply_property_is_writeable(struct power_supply *psy,
873 enum power_supply_property psp);
874extern void power_supply_external_power_changed(struct power_supply *psy);
297d716f
KK
875
876extern struct power_supply *__must_check
877power_supply_register(struct device *parent,
878 const struct power_supply_desc *desc,
2dc9215d 879 const struct power_supply_config *cfg);
297d716f
KK
880extern struct power_supply *__must_check
881power_supply_register_no_ws(struct device *parent,
882 const struct power_supply_desc *desc,
2dc9215d 883 const struct power_supply_config *cfg);
297d716f
KK
884extern struct power_supply *__must_check
885devm_power_supply_register(struct device *parent,
886 const struct power_supply_desc *desc,
2dc9215d 887 const struct power_supply_config *cfg);
297d716f
KK
888extern struct power_supply *__must_check
889devm_power_supply_register_no_ws(struct device *parent,
890 const struct power_supply_desc *desc,
2dc9215d 891 const struct power_supply_config *cfg);
4a11b59d 892extern void power_supply_unregister(struct power_supply *psy);
83516651 893extern int power_supply_powers(struct power_supply *psy, struct device *dev);
4a11b59d 894
285995d1
OG
895#define to_power_supply(device) container_of(device, struct power_supply, dev)
896
e44ea364 897extern void *power_supply_get_drvdata(struct power_supply *psy);
4a11b59d
AV
898/* For APM emulation, think legacy userspace. */
899extern struct class *power_supply_class;
900
51d07566
RK
901static inline bool power_supply_is_amp_property(enum power_supply_property psp)
902{
903 switch (psp) {
904 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
905 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
906 case POWER_SUPPLY_PROP_CHARGE_FULL:
907 case POWER_SUPPLY_PROP_CHARGE_EMPTY:
908 case POWER_SUPPLY_PROP_CHARGE_NOW:
909 case POWER_SUPPLY_PROP_CHARGE_AVG:
910 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
413de34a
LB
911 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
912 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
3824c477 913 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
2815b786 914 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
51d07566
RK
915 case POWER_SUPPLY_PROP_CURRENT_MAX:
916 case POWER_SUPPLY_PROP_CURRENT_NOW:
917 case POWER_SUPPLY_PROP_CURRENT_AVG:
a8adcc90 918 case POWER_SUPPLY_PROP_CURRENT_BOOT:
25faa935 919 return true;
51d07566
RK
920 default:
921 break;
922 }
923
25faa935 924 return false;
51d07566
RK
925}
926
927static inline bool power_supply_is_watt_property(enum power_supply_property psp)
928{
929 switch (psp) {
930 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
931 case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
932 case POWER_SUPPLY_PROP_ENERGY_FULL:
933 case POWER_SUPPLY_PROP_ENERGY_EMPTY:
934 case POWER_SUPPLY_PROP_ENERGY_NOW:
935 case POWER_SUPPLY_PROP_ENERGY_AVG:
936 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
937 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
938 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
939 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
940 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
941 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
a2ebfe2f 942 case POWER_SUPPLY_PROP_VOLTAGE_OCV:
a8adcc90 943 case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
3824c477 944 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
2815b786 945 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
35c9d267 946 case POWER_SUPPLY_PROP_POWER_NOW:
25faa935 947 return true;
51d07566
RK
948 default:
949 break;
950 }
951
25faa935 952 return false;
51d07566
RK
953}
954
e67d4dfc
AS
955#ifdef CONFIG_POWER_SUPPLY_HWMON
956int power_supply_add_hwmon_sysfs(struct power_supply *psy);
957void power_supply_remove_hwmon_sysfs(struct power_supply *psy);
958#else
959static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy)
960{
961 return 0;
962}
963
964static inline
965void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {}
966#endif
967
539b9c94
TW
968#ifdef CONFIG_SYSFS
969ssize_t power_supply_charge_behaviour_show(struct device *dev,
970 unsigned int available_behaviours,
971 enum power_supply_charge_behaviour behaviour,
972 char *buf);
973
974int power_supply_charge_behaviour_parse(unsigned int available_behaviours, const char *buf);
3367d1bd
TW
975#else
976static inline
977ssize_t power_supply_charge_behaviour_show(struct device *dev,
978 unsigned int available_behaviours,
979 enum power_supply_charge_behaviour behaviour,
980 char *buf)
981{
982 return -EOPNOTSUPP;
983}
984
985static inline int power_supply_charge_behaviour_parse(unsigned int available_behaviours,
986 const char *buf)
987{
988 return -EOPNOTSUPP;
989}
539b9c94
TW
990#endif
991
4a11b59d 992#endif /* __LINUX_POWER_SUPPLY_H__ */