power_supply.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. #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. /*
  48. * force to 50 to minimize the chances of userspace binary
  49. * incompatibility on newer upstream kernels
  50. */
  51. POWER_SUPPLY_CHARGE_TYPE_TAPER = 50, /* charging in CV phase */
  52. };
  53. enum {
  54. POWER_SUPPLY_HEALTH_UNKNOWN = 0,
  55. POWER_SUPPLY_HEALTH_GOOD,
  56. POWER_SUPPLY_HEALTH_OVERHEAT,
  57. POWER_SUPPLY_HEALTH_DEAD,
  58. POWER_SUPPLY_HEALTH_OVERVOLTAGE,
  59. POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
  60. POWER_SUPPLY_HEALTH_COLD,
  61. POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
  62. POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
  63. POWER_SUPPLY_HEALTH_OVERCURRENT,
  64. POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED,
  65. POWER_SUPPLY_HEALTH_WARM,
  66. POWER_SUPPLY_HEALTH_COOL,
  67. POWER_SUPPLY_HEALTH_HOT,
  68. };
  69. enum {
  70. POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0,
  71. POWER_SUPPLY_TECHNOLOGY_NiMH,
  72. POWER_SUPPLY_TECHNOLOGY_LION,
  73. POWER_SUPPLY_TECHNOLOGY_LIPO,
  74. POWER_SUPPLY_TECHNOLOGY_LiFe,
  75. POWER_SUPPLY_TECHNOLOGY_NiCd,
  76. POWER_SUPPLY_TECHNOLOGY_LiMn,
  77. };
  78. enum {
  79. POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
  80. POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
  81. POWER_SUPPLY_CAPACITY_LEVEL_LOW,
  82. POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
  83. POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
  84. POWER_SUPPLY_CAPACITY_LEVEL_FULL,
  85. };
  86. enum {
  87. POWER_SUPPLY_SCOPE_UNKNOWN = 0,
  88. POWER_SUPPLY_SCOPE_SYSTEM,
  89. POWER_SUPPLY_SCOPE_DEVICE,
  90. };
  91. enum power_supply_property {
  92. /* Properties of type `int' */
  93. POWER_SUPPLY_PROP_STATUS = 0,
  94. POWER_SUPPLY_PROP_CHARGE_TYPE,
  95. POWER_SUPPLY_PROP_HEALTH,
  96. POWER_SUPPLY_PROP_PRESENT,
  97. POWER_SUPPLY_PROP_ONLINE,
  98. POWER_SUPPLY_PROP_AUTHENTIC,
  99. POWER_SUPPLY_PROP_TECHNOLOGY,
  100. POWER_SUPPLY_PROP_CYCLE_COUNT,
  101. POWER_SUPPLY_PROP_VOLTAGE_MAX,
  102. POWER_SUPPLY_PROP_VOLTAGE_MIN,
  103. POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
  104. POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
  105. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  106. POWER_SUPPLY_PROP_VOLTAGE_AVG,
  107. POWER_SUPPLY_PROP_VOLTAGE_OCV,
  108. POWER_SUPPLY_PROP_VOLTAGE_BOOT,
  109. POWER_SUPPLY_PROP_CURRENT_MAX,
  110. POWER_SUPPLY_PROP_CURRENT_NOW,
  111. POWER_SUPPLY_PROP_CURRENT_AVG,
  112. POWER_SUPPLY_PROP_CURRENT_BOOT,
  113. POWER_SUPPLY_PROP_POWER_NOW,
  114. POWER_SUPPLY_PROP_POWER_AVG,
  115. POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  116. POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
  117. POWER_SUPPLY_PROP_CHARGE_FULL,
  118. POWER_SUPPLY_PROP_CHARGE_EMPTY,
  119. POWER_SUPPLY_PROP_CHARGE_NOW,
  120. POWER_SUPPLY_PROP_CHARGE_AVG,
  121. POWER_SUPPLY_PROP_CHARGE_COUNTER,
  122. POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
  123. POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
  124. POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
  125. POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
  126. POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
  127. POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
  128. POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */
  129. POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */
  130. POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
  131. POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
  132. POWER_SUPPLY_PROP_INPUT_POWER_LIMIT,
  133. POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
  134. POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
  135. POWER_SUPPLY_PROP_ENERGY_FULL,
  136. POWER_SUPPLY_PROP_ENERGY_EMPTY,
  137. POWER_SUPPLY_PROP_ENERGY_NOW,
  138. POWER_SUPPLY_PROP_ENERGY_AVG,
  139. POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
  140. POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */
  141. POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
  142. POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */
  143. POWER_SUPPLY_PROP_CAPACITY_LEVEL,
  144. POWER_SUPPLY_PROP_TEMP,
  145. POWER_SUPPLY_PROP_TEMP_MAX,
  146. POWER_SUPPLY_PROP_TEMP_MIN,
  147. POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
  148. POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
  149. POWER_SUPPLY_PROP_TEMP_AMBIENT,
  150. POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
  151. POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
  152. POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
  153. POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
  154. POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
  155. POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
  156. POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
  157. POWER_SUPPLY_PROP_USB_TYPE,
  158. POWER_SUPPLY_PROP_SCOPE,
  159. POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
  160. POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
  161. POWER_SUPPLY_PROP_CALIBRATE,
  162. POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
  163. POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
  164. POWER_SUPPLY_PROP_MANUFACTURE_DAY,
  165. /* Properties of type `const char *' */
  166. POWER_SUPPLY_PROP_MODEL_NAME,
  167. POWER_SUPPLY_PROP_MANUFACTURER,
  168. POWER_SUPPLY_PROP_SERIAL_NUMBER,
  169. };
  170. enum power_supply_type {
  171. POWER_SUPPLY_TYPE_UNKNOWN = 0,
  172. POWER_SUPPLY_TYPE_BATTERY,
  173. POWER_SUPPLY_TYPE_UPS,
  174. POWER_SUPPLY_TYPE_MAINS,
  175. POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */
  176. POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */
  177. POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */
  178. POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */
  179. POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */
  180. POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */
  181. POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */
  182. POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
  183. POWER_SUPPLY_TYPE_WIRELESS, /* Wireless */
  184. };
  185. enum power_supply_usb_type {
  186. POWER_SUPPLY_USB_TYPE_UNKNOWN = 0,
  187. POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */
  188. POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */
  189. POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */
  190. POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */
  191. POWER_SUPPLY_USB_TYPE_C, /* Type C Port */
  192. POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */
  193. POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */
  194. POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */
  195. POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
  196. };
  197. enum power_supply_notifier_events {
  198. PSY_EVENT_PROP_CHANGED,
  199. };
  200. union power_supply_propval {
  201. int intval;
  202. const char *strval;
  203. };
  204. struct device_node;
  205. struct power_supply;
  206. /* Run-time specific power supply configuration */
  207. struct power_supply_config {
  208. struct device_node *of_node;
  209. struct fwnode_handle *fwnode;
  210. /* Driver private data */
  211. void *drv_data;
  212. /* Device specific sysfs attributes */
  213. const struct attribute_group **attr_grp;
  214. char **supplied_to;
  215. size_t num_supplicants;
  216. ANDROID_KABI_RESERVE(1);
  217. };
  218. /* Description of power supply */
  219. struct power_supply_desc {
  220. const char *name;
  221. enum power_supply_type type;
  222. const enum power_supply_usb_type *usb_types;
  223. size_t num_usb_types;
  224. const enum power_supply_property *properties;
  225. size_t num_properties;
  226. /*
  227. * Functions for drivers implementing power supply class.
  228. * These shouldn't be called directly by other drivers for accessing
  229. * this power supply. Instead use power_supply_*() functions (for
  230. * example power_supply_get_property()).
  231. */
  232. int (*get_property)(struct power_supply *psy,
  233. enum power_supply_property psp,
  234. union power_supply_propval *val);
  235. int (*set_property)(struct power_supply *psy,
  236. enum power_supply_property psp,
  237. const union power_supply_propval *val);
  238. /*
  239. * property_is_writeable() will be called during registration
  240. * of power supply. If this happens during device probe then it must
  241. * not access internal data of device (because probe did not end).
  242. */
  243. int (*property_is_writeable)(struct power_supply *psy,
  244. enum power_supply_property psp);
  245. void (*external_power_changed)(struct power_supply *psy);
  246. void (*set_charged)(struct power_supply *psy);
  247. /*
  248. * Set if thermal zone should not be created for this power supply.
  249. * For example for virtual supplies forwarding calls to actual
  250. * sensors or other supplies.
  251. */
  252. bool no_thermal;
  253. /* For APM emulation, think legacy userspace. */
  254. int use_for_apm;
  255. ANDROID_KABI_RESERVE(1);
  256. };
  257. struct power_supply {
  258. const struct power_supply_desc *desc;
  259. char **supplied_to;
  260. size_t num_supplicants;
  261. char **supplied_from;
  262. size_t num_supplies;
  263. struct device_node *of_node;
  264. /* Driver private data */
  265. void *drv_data;
  266. /* private */
  267. struct device dev;
  268. struct work_struct changed_work;
  269. struct delayed_work deferred_register_work;
  270. spinlock_t changed_lock;
  271. bool changed;
  272. bool initialized;
  273. bool removing;
  274. atomic_t use_cnt;
  275. #ifdef CONFIG_THERMAL
  276. struct thermal_zone_device *tzd;
  277. struct thermal_cooling_device *tcd;
  278. #endif
  279. #ifdef CONFIG_LEDS_TRIGGERS
  280. struct led_trigger *charging_full_trig;
  281. char *charging_full_trig_name;
  282. struct led_trigger *charging_trig;
  283. char *charging_trig_name;
  284. struct led_trigger *full_trig;
  285. char *full_trig_name;
  286. struct led_trigger *online_trig;
  287. char *online_trig_name;
  288. struct led_trigger *charging_blink_full_solid_trig;
  289. char *charging_blink_full_solid_trig_name;
  290. #endif
  291. ANDROID_KABI_RESERVE(1);
  292. };
  293. /*
  294. * This is recommended structure to specify static power supply parameters.
  295. * Generic one, parametrizable for different power supplies. Power supply
  296. * class itself does not use it, but that's what implementing most platform
  297. * drivers, should try reuse for consistency.
  298. */
  299. struct power_supply_info {
  300. const char *name;
  301. int technology;
  302. int voltage_max_design;
  303. int voltage_min_design;
  304. int charge_full_design;
  305. int charge_empty_design;
  306. int energy_full_design;
  307. int energy_empty_design;
  308. int use_for_apm;
  309. };
  310. struct power_supply_battery_ocv_table {
  311. int ocv; /* microVolts */
  312. int capacity; /* percent */
  313. };
  314. struct power_supply_resistance_temp_table {
  315. int temp; /* celsius */
  316. int resistance; /* internal resistance percent */
  317. };
  318. #define POWER_SUPPLY_OCV_TEMP_MAX 20
  319. /*
  320. * This is the recommended struct to manage static battery parameters,
  321. * populated by power_supply_get_battery_info(). Most platform drivers should
  322. * use these for consistency.
  323. * Its field names must correspond to elements in enum power_supply_property.
  324. * The default field value is -EINVAL.
  325. * Power supply class itself doesn't use this.
  326. */
  327. struct power_supply_battery_info {
  328. int energy_full_design_uwh; /* microWatt-hours */
  329. int charge_full_design_uah; /* microAmp-hours */
  330. int voltage_min_design_uv; /* microVolts */
  331. int voltage_max_design_uv; /* microVolts */
  332. int tricklecharge_current_ua; /* microAmps */
  333. int precharge_current_ua; /* microAmps */
  334. int precharge_voltage_max_uv; /* microVolts */
  335. int charge_term_current_ua; /* microAmps */
  336. int charge_restart_voltage_uv; /* microVolts */
  337. int overvoltage_limit_uv; /* microVolts */
  338. int constant_charge_current_max_ua; /* microAmps */
  339. int constant_charge_voltage_max_uv; /* microVolts */
  340. int factory_internal_resistance_uohm; /* microOhms */
  341. int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */
  342. int temp_ambient_alert_min; /* celsius */
  343. int temp_ambient_alert_max; /* celsius */
  344. int temp_alert_min; /* celsius */
  345. int temp_alert_max; /* celsius */
  346. int temp_min; /* celsius */
  347. int temp_max; /* celsius */
  348. struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX];
  349. int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
  350. struct power_supply_resistance_temp_table *resist_table;
  351. int resist_table_size;
  352. ANDROID_KABI_RESERVE(1);
  353. };
  354. extern struct atomic_notifier_head power_supply_notifier;
  355. extern int power_supply_reg_notifier(struct notifier_block *nb);
  356. extern void power_supply_unreg_notifier(struct notifier_block *nb);
  357. extern struct power_supply *power_supply_get_by_name(const char *name);
  358. extern void power_supply_put(struct power_supply *psy);
  359. #ifdef CONFIG_OF
  360. extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
  361. const char *property);
  362. extern int power_supply_get_by_phandle_array(struct device_node *np,
  363. const char *property,
  364. struct power_supply **psy,
  365. ssize_t size);
  366. extern struct power_supply *devm_power_supply_get_by_phandle(
  367. struct device *dev, const char *property);
  368. #else /* !CONFIG_OF */
  369. static inline struct power_supply *
  370. power_supply_get_by_phandle(struct device_node *np, const char *property)
  371. { return NULL; }
  372. static inline int
  373. power_supply_get_by_phandle_array(struct device_node *np,
  374. const char *property,
  375. struct power_supply **psy,
  376. int size)
  377. { return 0; }
  378. static inline struct power_supply *
  379. devm_power_supply_get_by_phandle(struct device *dev, const char *property)
  380. { return NULL; }
  381. #endif /* CONFIG_OF */
  382. extern int power_supply_get_battery_info(struct power_supply *psy,
  383. struct power_supply_battery_info *info);
  384. extern void power_supply_put_battery_info(struct power_supply *psy,
  385. struct power_supply_battery_info *info);
  386. extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
  387. int table_len, int ocv);
  388. extern struct power_supply_battery_ocv_table *
  389. power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
  390. int temp, int *table_len);
  391. extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
  392. int ocv, int temp);
  393. extern int
  394. power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
  395. int table_len, int temp);
  396. extern void power_supply_changed(struct power_supply *psy);
  397. extern int power_supply_am_i_supplied(struct power_supply *psy);
  398. extern int power_supply_set_input_current_limit_from_supplier(
  399. struct power_supply *psy);
  400. extern int power_supply_set_battery_charged(struct power_supply *psy);
  401. #ifdef CONFIG_POWER_SUPPLY
  402. extern int power_supply_is_system_supplied(void);
  403. #else
  404. static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
  405. #endif
  406. extern int power_supply_get_property(struct power_supply *psy,
  407. enum power_supply_property psp,
  408. union power_supply_propval *val);
  409. #if IS_ENABLED(CONFIG_POWER_SUPPLY)
  410. extern int power_supply_set_property(struct power_supply *psy,
  411. enum power_supply_property psp,
  412. const union power_supply_propval *val);
  413. #else
  414. static inline int power_supply_set_property(struct power_supply *psy,
  415. enum power_supply_property psp,
  416. const union power_supply_propval *val)
  417. { return 0; }
  418. #endif
  419. extern int power_supply_property_is_writeable(struct power_supply *psy,
  420. enum power_supply_property psp);
  421. extern void power_supply_external_power_changed(struct power_supply *psy);
  422. extern struct power_supply *__must_check
  423. power_supply_register(struct device *parent,
  424. const struct power_supply_desc *desc,
  425. const struct power_supply_config *cfg);
  426. extern struct power_supply *__must_check
  427. power_supply_register_no_ws(struct device *parent,
  428. const struct power_supply_desc *desc,
  429. const struct power_supply_config *cfg);
  430. extern struct power_supply *__must_check
  431. devm_power_supply_register(struct device *parent,
  432. const struct power_supply_desc *desc,
  433. const struct power_supply_config *cfg);
  434. extern struct power_supply *__must_check
  435. devm_power_supply_register_no_ws(struct device *parent,
  436. const struct power_supply_desc *desc,
  437. const struct power_supply_config *cfg);
  438. extern void power_supply_unregister(struct power_supply *psy);
  439. extern int power_supply_powers(struct power_supply *psy, struct device *dev);
  440. #define to_power_supply(device) container_of(device, struct power_supply, dev)
  441. extern void *power_supply_get_drvdata(struct power_supply *psy);
  442. /* For APM emulation, think legacy userspace. */
  443. extern struct class *power_supply_class;
  444. static inline bool power_supply_is_amp_property(enum power_supply_property psp)
  445. {
  446. switch (psp) {
  447. case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  448. case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
  449. case POWER_SUPPLY_PROP_CHARGE_FULL:
  450. case POWER_SUPPLY_PROP_CHARGE_EMPTY:
  451. case POWER_SUPPLY_PROP_CHARGE_NOW:
  452. case POWER_SUPPLY_PROP_CHARGE_AVG:
  453. case POWER_SUPPLY_PROP_CHARGE_COUNTER:
  454. case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
  455. case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
  456. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
  457. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
  458. case POWER_SUPPLY_PROP_CURRENT_MAX:
  459. case POWER_SUPPLY_PROP_CURRENT_NOW:
  460. case POWER_SUPPLY_PROP_CURRENT_AVG:
  461. case POWER_SUPPLY_PROP_CURRENT_BOOT:
  462. return 1;
  463. default:
  464. break;
  465. }
  466. return 0;
  467. }
  468. static inline bool power_supply_is_watt_property(enum power_supply_property psp)
  469. {
  470. switch (psp) {
  471. case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
  472. case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
  473. case POWER_SUPPLY_PROP_ENERGY_FULL:
  474. case POWER_SUPPLY_PROP_ENERGY_EMPTY:
  475. case POWER_SUPPLY_PROP_ENERGY_NOW:
  476. case POWER_SUPPLY_PROP_ENERGY_AVG:
  477. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  478. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  479. case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
  480. case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
  481. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  482. case POWER_SUPPLY_PROP_VOLTAGE_AVG:
  483. case POWER_SUPPLY_PROP_VOLTAGE_OCV:
  484. case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
  485. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
  486. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
  487. case POWER_SUPPLY_PROP_POWER_NOW:
  488. return 1;
  489. default:
  490. break;
  491. }
  492. return 0;
  493. }
  494. #ifdef CONFIG_POWER_SUPPLY_HWMON
  495. int power_supply_add_hwmon_sysfs(struct power_supply *psy);
  496. void power_supply_remove_hwmon_sysfs(struct power_supply *psy);
  497. #else
  498. static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy)
  499. {
  500. return 0;
  501. }
  502. static inline
  503. void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {}
  504. #endif
  505. #endif /* __LINUX_POWER_SUPPLY_H__ */