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