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