power_supply.h 40 KB

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