xref: /OK3568_Linux_fs/kernel/include/linux/power_supply.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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/spinlock.h>
19 #include <linux/notifier.h>
20 #include <linux/android_kabi.h>
21 
22 /*
23  * All voltages, currents, charges, energies, time and temperatures in uV,
24  * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
25  * stated. It's driver's job to convert its raw values to units in which
26  * this class operates.
27  */
28 
29 /*
30  * For systems where the charger determines the maximum battery capacity
31  * the min and max fields should be used to present these values to user
32  * space. Unused/unknown fields will not appear in sysfs.
33  */
34 
35 enum {
36 	POWER_SUPPLY_STATUS_UNKNOWN = 0,
37 	POWER_SUPPLY_STATUS_CHARGING,
38 	POWER_SUPPLY_STATUS_DISCHARGING,
39 	POWER_SUPPLY_STATUS_NOT_CHARGING,
40 	POWER_SUPPLY_STATUS_FULL,
41 };
42 
43 /* What algorithm is the charger using? */
44 enum {
45 	POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
46 	POWER_SUPPLY_CHARGE_TYPE_NONE,
47 	POWER_SUPPLY_CHARGE_TYPE_TRICKLE,	/* slow speed */
48 	POWER_SUPPLY_CHARGE_TYPE_FAST,		/* fast speed */
49 	POWER_SUPPLY_CHARGE_TYPE_STANDARD,	/* normal speed */
50 	POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE,	/* dynamically adjusted speed */
51 	POWER_SUPPLY_CHARGE_TYPE_CUSTOM,	/* use CHARGE_CONTROL_* props */
52 	POWER_SUPPLY_CHARGE_TYPE_LONGLIFE,	/* slow speed, longer life */
53 
54 	/*
55 	 * force to 50 to minimize the chances of userspace binary
56 	 * incompatibility on newer upstream kernels
57 	 */
58 	POWER_SUPPLY_CHARGE_TYPE_TAPER = 50,	/* charging in CV phase */
59 };
60 
61 enum {
62 	POWER_SUPPLY_HEALTH_UNKNOWN = 0,
63 	POWER_SUPPLY_HEALTH_GOOD,
64 	POWER_SUPPLY_HEALTH_OVERHEAT,
65 	POWER_SUPPLY_HEALTH_DEAD,
66 	POWER_SUPPLY_HEALTH_OVERVOLTAGE,
67 	POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
68 	POWER_SUPPLY_HEALTH_COLD,
69 	POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
70 	POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
71 	POWER_SUPPLY_HEALTH_OVERCURRENT,
72 	POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED,
73 	POWER_SUPPLY_HEALTH_WARM,
74 	POWER_SUPPLY_HEALTH_COOL,
75 	POWER_SUPPLY_HEALTH_HOT,
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 };
87 
88 enum {
89 	POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
90 	POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
91 	POWER_SUPPLY_CAPACITY_LEVEL_LOW,
92 	POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
93 	POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
94 	POWER_SUPPLY_CAPACITY_LEVEL_FULL,
95 };
96 
97 enum {
98 	POWER_SUPPLY_SCOPE_UNKNOWN = 0,
99 	POWER_SUPPLY_SCOPE_SYSTEM,
100 	POWER_SUPPLY_SCOPE_DEVICE,
101 };
102 
103 enum power_supply_property {
104 	/* Properties of type `int' */
105 	POWER_SUPPLY_PROP_STATUS = 0,
106 	POWER_SUPPLY_PROP_CHARGE_TYPE,
107 	POWER_SUPPLY_PROP_HEALTH,
108 	POWER_SUPPLY_PROP_PRESENT,
109 	POWER_SUPPLY_PROP_ONLINE,
110 	POWER_SUPPLY_PROP_AUTHENTIC,
111 	POWER_SUPPLY_PROP_TECHNOLOGY,
112 	POWER_SUPPLY_PROP_CYCLE_COUNT,
113 	POWER_SUPPLY_PROP_VOLTAGE_MAX,
114 	POWER_SUPPLY_PROP_VOLTAGE_MIN,
115 	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
116 	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
117 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
118 	POWER_SUPPLY_PROP_VOLTAGE_AVG,
119 	POWER_SUPPLY_PROP_VOLTAGE_OCV,
120 	POWER_SUPPLY_PROP_VOLTAGE_BOOT,
121 	POWER_SUPPLY_PROP_CURRENT_MAX,
122 	POWER_SUPPLY_PROP_CURRENT_NOW,
123 	POWER_SUPPLY_PROP_CURRENT_AVG,
124 	POWER_SUPPLY_PROP_CURRENT_BOOT,
125 	POWER_SUPPLY_PROP_POWER_NOW,
126 	POWER_SUPPLY_PROP_POWER_AVG,
127 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
128 	POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
129 	POWER_SUPPLY_PROP_CHARGE_FULL,
130 	POWER_SUPPLY_PROP_CHARGE_EMPTY,
131 	POWER_SUPPLY_PROP_CHARGE_NOW,
132 	POWER_SUPPLY_PROP_CHARGE_AVG,
133 	POWER_SUPPLY_PROP_CHARGE_COUNTER,
134 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
135 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
136 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
137 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
138 	POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
139 	POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
140 	POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */
141 	POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */
142 	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
143 	POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
144 	POWER_SUPPLY_PROP_INPUT_POWER_LIMIT,
145 	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
146 	POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
147 	POWER_SUPPLY_PROP_ENERGY_FULL,
148 	POWER_SUPPLY_PROP_ENERGY_EMPTY,
149 	POWER_SUPPLY_PROP_ENERGY_NOW,
150 	POWER_SUPPLY_PROP_ENERGY_AVG,
151 	POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
152 	POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */
153 	POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
154 	POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */
155 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
156 	POWER_SUPPLY_PROP_TEMP,
157 	POWER_SUPPLY_PROP_TEMP_MAX,
158 	POWER_SUPPLY_PROP_TEMP_MIN,
159 	POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
160 	POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
161 	POWER_SUPPLY_PROP_TEMP_AMBIENT,
162 	POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
163 	POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
164 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
165 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
166 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
167 	POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
168 	POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
169 	POWER_SUPPLY_PROP_USB_TYPE,
170 	POWER_SUPPLY_PROP_SCOPE,
171 	POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
172 	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
173 	POWER_SUPPLY_PROP_CALIBRATE,
174 	POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
175 	POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
176 	POWER_SUPPLY_PROP_MANUFACTURE_DAY,
177 #if defined(CONFIG_NO_GKI)
178 	/* Charge pump properties */
179 	POWER_SUPPLY_PROP_CP_ALARM_STATUS,
180 	POWER_SUPPLY_PROP_CP_BAT_OVP_ALARM,
181 	POWER_SUPPLY_PROP_CP_BAT_OCP_ALARM,
182 	POWER_SUPPLY_PROP_CP_BAT_UCP_ALARM,
183 	POWER_SUPPLY_PROP_CP_BUS_OVP_ALARM,
184 	POWER_SUPPLY_PROP_CP_BUS_OCP_ALARM,
185 	POWER_SUPPLY_PROP_CP_BAT_THERM_ALARM,
186 	POWER_SUPPLY_PROP_CP_BUS_THERM_ALARM,
187 	POWER_SUPPLY_PROP_CP_DIE_THERM_ALARM,
188 	POWER_SUPPLY_PROP_CP_FAULT_STATUS,
189 	POWER_SUPPLY_PROP_CP_BAT_OVP_FAULT,
190 	POWER_SUPPLY_PROP_CP_BAT_OCP_FAULT,
191 	POWER_SUPPLY_PROP_CP_BUS_OVP_FAULT,
192 	POWER_SUPPLY_PROP_CP_BUS_OCP_FAULT,
193 	POWER_SUPPLY_PROP_CP_BAT_THERM_FAULT,
194 	POWER_SUPPLY_PROP_CP_BUS_THERM_FAULT,
195 	POWER_SUPPLY_PROP_CP_DIE_THERM_FAULT,
196 	POWER_SUPPLY_PROP_CP_VBUS_ERROR_STATUS,
197 	POWER_SUPPLY_PROP_CP_VBUS_HERROR_STATUS,
198 	POWER_SUPPLY_PROP_CP_VBUS_LERROR_STATUS,
199 	POWER_SUPPLY_PROP_CP_CHARGING_ENABLED,
200 	POWER_SUPPLY_PROP_CP_WDT_EN,
201 	POWER_SUPPLY_PROP_CP_VBUS,
202 	POWER_SUPPLY_PROP_CP_IBUS,
203 	POWER_SUPPLY_PROP_CP_SWITCHER_EN,
204 	POWER_SUPPLY_PROP_CP_BAT_TEMPERATURE,
205 	POWER_SUPPLY_PROP_CP_BUS_TEMPERATURE,
206 	POWER_SUPPLY_PROP_CP_DIE_TEMPERATURE,
207 	POWER_SUPPLY_PROP_CP_ISNS,
208 	POWER_SUPPLY_PROP_CP_TOGGLE_SWITCHER,
209 	POWER_SUPPLY_PROP_CP_IRQ_STATUS,
210 	POWER_SUPPLY_PROP_CP_ILIM,
211 #endif
212 	/* Properties of type `const char *' */
213 	POWER_SUPPLY_PROP_MODEL_NAME,
214 	POWER_SUPPLY_PROP_MANUFACTURER,
215 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
216 };
217 
218 enum power_supply_type {
219 	POWER_SUPPLY_TYPE_UNKNOWN = 0,
220 	POWER_SUPPLY_TYPE_BATTERY,
221 	POWER_SUPPLY_TYPE_UPS,
222 	POWER_SUPPLY_TYPE_MAINS,
223 	POWER_SUPPLY_TYPE_USB,			/* Standard Downstream Port */
224 	POWER_SUPPLY_TYPE_USB_DCP,		/* Dedicated Charging Port */
225 	POWER_SUPPLY_TYPE_USB_CDP,		/* Charging Downstream Port */
226 	POWER_SUPPLY_TYPE_USB_ACA,		/* Accessory Charger Adapters */
227 	POWER_SUPPLY_TYPE_USB_TYPE_C,		/* Type C Port */
228 	POWER_SUPPLY_TYPE_USB_PD,		/* Power Delivery Port */
229 	POWER_SUPPLY_TYPE_USB_PD_DRP,		/* PD Dual Role Port */
230 	POWER_SUPPLY_TYPE_APPLE_BRICK_ID,	/* Apple Charging Method */
231 	POWER_SUPPLY_TYPE_WIRELESS,		/* Wireless */
232 #if defined(CONFIG_NO_GKI)
233 	POWER_SUPPLY_TYPE_CHARGE_PUMP,		/* Charge Pump */
234 #endif
235 };
236 
237 enum power_supply_usb_type {
238 	POWER_SUPPLY_USB_TYPE_UNKNOWN = 0,
239 	POWER_SUPPLY_USB_TYPE_SDP,		/* Standard Downstream Port */
240 	POWER_SUPPLY_USB_TYPE_DCP,		/* Dedicated Charging Port */
241 	POWER_SUPPLY_USB_TYPE_CDP,		/* Charging Downstream Port */
242 	POWER_SUPPLY_USB_TYPE_ACA,		/* Accessory Charger Adapters */
243 	POWER_SUPPLY_USB_TYPE_C,		/* Type C Port */
244 	POWER_SUPPLY_USB_TYPE_PD,		/* Power Delivery Port */
245 	POWER_SUPPLY_USB_TYPE_PD_DRP,		/* PD Dual Role Port */
246 	POWER_SUPPLY_USB_TYPE_PD_PPS,		/* PD Programmable Power Supply */
247 	POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID,	/* Apple Charging Method */
248 };
249 
250 enum power_supply_notifier_events {
251 	PSY_EVENT_PROP_CHANGED,
252 };
253 
254 union power_supply_propval {
255 	int intval;
256 	const char *strval;
257 };
258 
259 struct device_node;
260 struct power_supply;
261 
262 /* Run-time specific power supply configuration */
263 struct power_supply_config {
264 	struct device_node *of_node;
265 	struct fwnode_handle *fwnode;
266 
267 	/* Driver private data */
268 	void *drv_data;
269 
270 	/* Device specific sysfs attributes */
271 	const struct attribute_group **attr_grp;
272 
273 	char **supplied_to;
274 	size_t num_supplicants;
275 
276 	ANDROID_KABI_RESERVE(1);
277 };
278 
279 /* Description of power supply */
280 struct power_supply_desc {
281 	const char *name;
282 	enum power_supply_type type;
283 	const enum power_supply_usb_type *usb_types;
284 	size_t num_usb_types;
285 	const enum power_supply_property *properties;
286 	size_t num_properties;
287 
288 	/*
289 	 * Functions for drivers implementing power supply class.
290 	 * These shouldn't be called directly by other drivers for accessing
291 	 * this power supply. Instead use power_supply_*() functions (for
292 	 * example power_supply_get_property()).
293 	 */
294 	int (*get_property)(struct power_supply *psy,
295 			    enum power_supply_property psp,
296 			    union power_supply_propval *val);
297 	int (*set_property)(struct power_supply *psy,
298 			    enum power_supply_property psp,
299 			    const union power_supply_propval *val);
300 	/*
301 	 * property_is_writeable() will be called during registration
302 	 * of power supply. If this happens during device probe then it must
303 	 * not access internal data of device (because probe did not end).
304 	 */
305 	int (*property_is_writeable)(struct power_supply *psy,
306 				     enum power_supply_property psp);
307 	void (*external_power_changed)(struct power_supply *psy);
308 	void (*set_charged)(struct power_supply *psy);
309 
310 	/*
311 	 * Set if thermal zone should not be created for this power supply.
312 	 * For example for virtual supplies forwarding calls to actual
313 	 * sensors or other supplies.
314 	 */
315 	bool no_thermal;
316 	/* For APM emulation, think legacy userspace. */
317 	int use_for_apm;
318 
319 	ANDROID_KABI_RESERVE(1);
320 };
321 
322 struct power_supply {
323 	const struct power_supply_desc *desc;
324 
325 	char **supplied_to;
326 	size_t num_supplicants;
327 
328 	char **supplied_from;
329 	size_t num_supplies;
330 	struct device_node *of_node;
331 
332 	/* Driver private data */
333 	void *drv_data;
334 
335 	/* private */
336 	struct device dev;
337 	struct work_struct changed_work;
338 	struct delayed_work deferred_register_work;
339 	spinlock_t changed_lock;
340 	bool changed;
341 	bool initialized;
342 	bool removing;
343 	atomic_t use_cnt;
344 #ifdef CONFIG_THERMAL
345 	struct thermal_zone_device *tzd;
346 	struct thermal_cooling_device *tcd;
347 #endif
348 
349 #ifdef CONFIG_LEDS_TRIGGERS
350 	struct led_trigger *charging_full_trig;
351 	char *charging_full_trig_name;
352 	struct led_trigger *charging_trig;
353 	char *charging_trig_name;
354 	struct led_trigger *full_trig;
355 	char *full_trig_name;
356 	struct led_trigger *online_trig;
357 	char *online_trig_name;
358 	struct led_trigger *charging_blink_full_solid_trig;
359 	char *charging_blink_full_solid_trig_name;
360 #endif
361 
362 	ANDROID_KABI_RESERVE(1);
363 };
364 
365 /*
366  * This is recommended structure to specify static power supply parameters.
367  * Generic one, parametrizable for different power supplies. Power supply
368  * class itself does not use it, but that's what implementing most platform
369  * drivers, should try reuse for consistency.
370  */
371 
372 struct power_supply_info {
373 	const char *name;
374 	int technology;
375 	int voltage_max_design;
376 	int voltage_min_design;
377 	int charge_full_design;
378 	int charge_empty_design;
379 	int energy_full_design;
380 	int energy_empty_design;
381 	int use_for_apm;
382 };
383 
384 struct power_supply_battery_ocv_table {
385 	int ocv;	/* microVolts */
386 	int capacity;	/* percent */
387 };
388 
389 struct power_supply_resistance_temp_table {
390 	int temp;	/* celsius */
391 	int resistance;	/* internal resistance percent */
392 };
393 
394 #define POWER_SUPPLY_OCV_TEMP_MAX 20
395 
396 /*
397  * This is the recommended struct to manage static battery parameters,
398  * populated by power_supply_get_battery_info(). Most platform drivers should
399  * use these for consistency.
400  * Its field names must correspond to elements in enum power_supply_property.
401  * The default field value is -EINVAL.
402  * Power supply class itself doesn't use this.
403  */
404 
405 struct power_supply_battery_info {
406 	int energy_full_design_uwh;	    /* microWatt-hours */
407 	int charge_full_design_uah;	    /* microAmp-hours */
408 	int voltage_min_design_uv;	    /* microVolts */
409 	int voltage_max_design_uv;	    /* microVolts */
410 	int tricklecharge_current_ua;	    /* microAmps */
411 	int precharge_current_ua;	    /* microAmps */
412 	int precharge_voltage_max_uv;	    /* microVolts */
413 	int charge_term_current_ua;	    /* microAmps */
414 	int charge_restart_voltage_uv;	    /* microVolts */
415 	int overvoltage_limit_uv;	    /* microVolts */
416 	int constant_charge_current_max_ua; /* microAmps */
417 	int constant_charge_voltage_max_uv; /* microVolts */
418 	int factory_internal_resistance_uohm;   /* microOhms */
419 	int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */
420 	int temp_ambient_alert_min;             /* celsius */
421 	int temp_ambient_alert_max;             /* celsius */
422 	int temp_alert_min;                     /* celsius */
423 	int temp_alert_max;                     /* celsius */
424 	int temp_min;                           /* celsius */
425 	int temp_max;                           /* celsius */
426 	struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX];
427 	int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
428 	struct power_supply_resistance_temp_table *resist_table;
429 	int resist_table_size;
430 
431 	ANDROID_KABI_RESERVE(1);
432 };
433 
434 extern struct atomic_notifier_head power_supply_notifier;
435 extern int power_supply_reg_notifier(struct notifier_block *nb);
436 extern void power_supply_unreg_notifier(struct notifier_block *nb);
437 extern struct power_supply *power_supply_get_by_name(const char *name);
438 extern void power_supply_put(struct power_supply *psy);
439 #ifdef CONFIG_OF
440 extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
441 							const char *property);
442 extern int power_supply_get_by_phandle_array(struct device_node *np,
443 					     const char *property,
444 					     struct power_supply **psy,
445 					     ssize_t size);
446 extern struct power_supply *devm_power_supply_get_by_phandle(
447 				    struct device *dev, const char *property);
448 #else /* !CONFIG_OF */
449 static inline struct power_supply *
power_supply_get_by_phandle(struct device_node * np,const char * property)450 power_supply_get_by_phandle(struct device_node *np, const char *property)
451 { return NULL; }
452 static inline int
power_supply_get_by_phandle_array(struct device_node * np,const char * property,struct power_supply ** psy,int size)453 power_supply_get_by_phandle_array(struct device_node *np,
454 				  const char *property,
455 				  struct power_supply **psy,
456 				  int size)
457 { return 0; }
458 static inline struct power_supply *
devm_power_supply_get_by_phandle(struct device * dev,const char * property)459 devm_power_supply_get_by_phandle(struct device *dev, const char *property)
460 { return NULL; }
461 #endif /* CONFIG_OF */
462 
463 extern int power_supply_get_battery_info(struct power_supply *psy,
464 					 struct power_supply_battery_info *info);
465 extern void power_supply_put_battery_info(struct power_supply *psy,
466 					  struct power_supply_battery_info *info);
467 extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
468 				       int table_len, int ocv);
469 extern struct power_supply_battery_ocv_table *
470 power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
471 				int temp, int *table_len);
472 extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
473 					int ocv, int temp);
474 extern int
475 power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
476 				int table_len, int temp);
477 extern void power_supply_changed(struct power_supply *psy);
478 extern int power_supply_am_i_supplied(struct power_supply *psy);
479 extern int power_supply_set_input_current_limit_from_supplier(
480 					 struct power_supply *psy);
481 extern int power_supply_set_battery_charged(struct power_supply *psy);
482 
483 #ifdef CONFIG_POWER_SUPPLY
484 extern int power_supply_is_system_supplied(void);
485 #else
power_supply_is_system_supplied(void)486 static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
487 #endif
488 
489 extern int power_supply_get_property(struct power_supply *psy,
490 			    enum power_supply_property psp,
491 			    union power_supply_propval *val);
492 #if IS_ENABLED(CONFIG_POWER_SUPPLY)
493 extern int power_supply_set_property(struct power_supply *psy,
494 			    enum power_supply_property psp,
495 			    const union power_supply_propval *val);
496 #else
power_supply_set_property(struct power_supply * psy,enum power_supply_property psp,const union power_supply_propval * val)497 static inline int power_supply_set_property(struct power_supply *psy,
498 			    enum power_supply_property psp,
499 			    const union power_supply_propval *val)
500 { return 0; }
501 #endif
502 extern int power_supply_property_is_writeable(struct power_supply *psy,
503 					enum power_supply_property psp);
504 extern void power_supply_external_power_changed(struct power_supply *psy);
505 
506 extern struct power_supply *__must_check
507 power_supply_register(struct device *parent,
508 				 const struct power_supply_desc *desc,
509 				 const struct power_supply_config *cfg);
510 extern struct power_supply *__must_check
511 power_supply_register_no_ws(struct device *parent,
512 				 const struct power_supply_desc *desc,
513 				 const struct power_supply_config *cfg);
514 extern struct power_supply *__must_check
515 devm_power_supply_register(struct device *parent,
516 				 const struct power_supply_desc *desc,
517 				 const struct power_supply_config *cfg);
518 extern struct power_supply *__must_check
519 devm_power_supply_register_no_ws(struct device *parent,
520 				 const struct power_supply_desc *desc,
521 				 const struct power_supply_config *cfg);
522 extern void power_supply_unregister(struct power_supply *psy);
523 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
524 
525 #define to_power_supply(device) container_of(device, struct power_supply, dev)
526 
527 extern void *power_supply_get_drvdata(struct power_supply *psy);
528 /* For APM emulation, think legacy userspace. */
529 extern struct class *power_supply_class;
530 
power_supply_is_amp_property(enum power_supply_property psp)531 static inline bool power_supply_is_amp_property(enum power_supply_property psp)
532 {
533 	switch (psp) {
534 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
535 	case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
536 	case POWER_SUPPLY_PROP_CHARGE_FULL:
537 	case POWER_SUPPLY_PROP_CHARGE_EMPTY:
538 	case POWER_SUPPLY_PROP_CHARGE_NOW:
539 	case POWER_SUPPLY_PROP_CHARGE_AVG:
540 	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
541 	case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
542 	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
543 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
544 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
545 	case POWER_SUPPLY_PROP_CURRENT_MAX:
546 	case POWER_SUPPLY_PROP_CURRENT_NOW:
547 	case POWER_SUPPLY_PROP_CURRENT_AVG:
548 	case POWER_SUPPLY_PROP_CURRENT_BOOT:
549 		return 1;
550 	default:
551 		break;
552 	}
553 
554 	return 0;
555 }
556 
power_supply_is_watt_property(enum power_supply_property psp)557 static inline bool power_supply_is_watt_property(enum power_supply_property psp)
558 {
559 	switch (psp) {
560 	case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
561 	case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
562 	case POWER_SUPPLY_PROP_ENERGY_FULL:
563 	case POWER_SUPPLY_PROP_ENERGY_EMPTY:
564 	case POWER_SUPPLY_PROP_ENERGY_NOW:
565 	case POWER_SUPPLY_PROP_ENERGY_AVG:
566 	case POWER_SUPPLY_PROP_VOLTAGE_MAX:
567 	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
568 	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
569 	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
570 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
571 	case POWER_SUPPLY_PROP_VOLTAGE_AVG:
572 	case POWER_SUPPLY_PROP_VOLTAGE_OCV:
573 	case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
574 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
575 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
576 	case POWER_SUPPLY_PROP_POWER_NOW:
577 		return 1;
578 	default:
579 		break;
580 	}
581 
582 	return 0;
583 }
584 
585 #ifdef CONFIG_POWER_SUPPLY_HWMON
586 int power_supply_add_hwmon_sysfs(struct power_supply *psy);
587 void power_supply_remove_hwmon_sysfs(struct power_supply *psy);
588 #else
power_supply_add_hwmon_sysfs(struct power_supply * psy)589 static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy)
590 {
591 	return 0;
592 }
593 
594 static inline
power_supply_remove_hwmon_sysfs(struct power_supply * psy)595 void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {}
596 #endif
597 
598 #endif /* __LINUX_POWER_SUPPLY_H__ */
599