remove libdss from Makefile
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / include / linux / power_supply.h
... / ...
CommitLineData
1/*
2 * Universal power supply monitor class
3 *
4 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
5 * Copyright © 2004 Szabolcs Gyurko
6 * Copyright © 2003 Ian Molton <spyro@f2s.com>
7 *
8 * Modified: 2004, Oct Szabolcs Gyurko
9 *
10 * You may use this code as per GPL version 2
11 */
12
13#ifndef __LINUX_POWER_SUPPLY_H__
14#define __LINUX_POWER_SUPPLY_H__
15
16#include <linux/device.h>
17#include <linux/workqueue.h>
18#include <linux/leds.h>
19#include <linux/spinlock.h>
20#include <linux/notifier.h>
21#include <linux/types.h>
22
23/*
24 * All voltages, currents, charges, energies, time and temperatures in uV,
25 * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
26 * stated. It's driver's job to convert its raw values to units in which
27 * this class operates.
28 */
29
30/*
31 * For systems where the charger determines the maximum battery capacity
32 * the min and max fields should be used to present these values to user
33 * space. Unused/unknown fields will not appear in sysfs.
34 */
35
36enum {
37 POWER_SUPPLY_STATUS_UNKNOWN = 0,
38 POWER_SUPPLY_STATUS_CHARGING,
39 POWER_SUPPLY_STATUS_DISCHARGING,
40 POWER_SUPPLY_STATUS_NOT_CHARGING,
41 POWER_SUPPLY_STATUS_FULL,
42};
43
44enum {
45 POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
46 POWER_SUPPLY_CHARGE_TYPE_NONE,
47 POWER_SUPPLY_CHARGE_TYPE_TRICKLE,
48 POWER_SUPPLY_CHARGE_TYPE_FAST,
49};
50
51enum {
52 POWER_SUPPLY_HEALTH_UNKNOWN = 0,
53 POWER_SUPPLY_HEALTH_GOOD,
54 POWER_SUPPLY_HEALTH_OVERHEAT,
55 POWER_SUPPLY_HEALTH_DEAD,
56 POWER_SUPPLY_HEALTH_OVERVOLTAGE,
57 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
58 POWER_SUPPLY_HEALTH_COLD,
59 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
60 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
61 POWER_SUPPLY_HEALTH_UNDERVOLTAGE,
62 //moto from 10
63 POWER_SUPPLY_HEALTH_WARM,
64 POWER_SUPPLY_HEALTH_COOL,
65 POWER_SUPPLY_HEALTH_HOT,
66 POWER_SUPPLY_HEALTH_SLIGHTLY_COOL,
67};
68
69enum {
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
79enum {
80 POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
81 POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
82 POWER_SUPPLY_CAPACITY_LEVEL_LOW,
83 POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
84 POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
85 POWER_SUPPLY_CAPACITY_LEVEL_FULL,
86};
87
88enum {
89 POWER_SUPPLY_SCOPE_UNKNOWN = 0,
90 POWER_SUPPLY_SCOPE_SYSTEM,
91 POWER_SUPPLY_SCOPE_DEVICE,
92};
93
94enum {
95 POWER_SUPPLY_CHARGE_RATE_NONE = 0,
96 POWER_SUPPLY_CHARGE_RATE_NORMAL,
97 POWER_SUPPLY_CHARGE_RATE_WEAK,
98 POWER_SUPPLY_CHARGE_RATE_TURBO,
99};
100
101enum power_supply_property {
102 /* Properties of type `int' */
103 POWER_SUPPLY_PROP_STATUS = 0,
104 POWER_SUPPLY_PROP_CHARGE_TYPE,
105 POWER_SUPPLY_PROP_HEALTH,
106 POWER_SUPPLY_PROP_PRESENT,
107 POWER_SUPPLY_PROP_ONLINE,
108 POWER_SUPPLY_PROP_AUTHENTIC,
109 POWER_SUPPLY_PROP_CHARGING_ENABLED,
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_INPUT_VOLTAGE_REGULATION,
121 POWER_SUPPLY_PROP_CURRENT_MAX,
122 POWER_SUPPLY_PROP_CURRENT_NOW,
123 POWER_SUPPLY_PROP_CURRENT_AVG,
124 POWER_SUPPLY_PROP_CURRENT_FULL,
125 POWER_SUPPLY_PROP_CURRENT_BOOT,
126 POWER_SUPPLY_PROP_POWER_NOW,
127 POWER_SUPPLY_PROP_POWER_AVG,
128 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
129 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
130 POWER_SUPPLY_PROP_CHARGE_FULL,
131 POWER_SUPPLY_PROP_CHARGE_EMPTY,
132 POWER_SUPPLY_PROP_CHARGE_NOW,
133 POWER_SUPPLY_PROP_CHARGE_AVG,
134 POWER_SUPPLY_PROP_CHARGE_COUNTER,
135 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL,
136 POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL,
137 POWER_SUPPLY_PROP_CHARGE_TEMP,
138 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
139 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
140 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
141 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
142 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
143 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
144 POWER_SUPPLY_PROP_INPUT_CURRENT_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_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_SCOPE,
169 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
170 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
171 POWER_SUPPLY_PROP_CALIBRATE,
172 /* Local extensions */
173 POWER_SUPPLY_PROP_USB_HC,
174 POWER_SUPPLY_PROP_USB_OTG,
175 POWER_SUPPLY_PROP_CHARGE_ENABLED,
176 POWER_SUPPLY_PROP_FUELGAUGE_RESET,
177 POWER_SUPPLY_PROP_SOH,
178 /* Local extensions of type int64_t */
179 POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT,
180 /* Properties of type `const char *' */
181 POWER_SUPPLY_PROP_MODEL_NAME,
182 POWER_SUPPLY_PROP_MANUFACTURER,
183 POWER_SUPPLY_PROP_SERIAL_NUMBER,
184
185 POWER_SUPPLY_PROP_VCHGIN,
186 POWER_SUPPLY_PROP_VWCIN,
187 POWER_SUPPLY_PROP_VBYP,
188 POWER_SUPPLY_PROP_VSYS,
189 POWER_SUPPLY_PROP_VBAT,
190 POWER_SUPPLY_PROP_VGPADC,
191 POWER_SUPPLY_PROP_VCC1,
192 POWER_SUPPLY_PROP_VCC2,
193 POWER_SUPPLY_PROP_ICHGIN,
194 POWER_SUPPLY_PROP_IWCIN,
195 POWER_SUPPLY_PROP_IOTG,
196 POWER_SUPPLY_PROP_ITX,
197 POWER_SUPPLY_PROP_CO_ENABLE,
198 POWER_SUPPLY_PROP_RR_ENABLE,
199 POWER_SUPPLY_PROP_USBPD_RESET,
200 POWER_SUPPLY_PROP_USBPD_TEST_READ,
201 POWER_SUPPLY_PROP_CHARGE_RATE,
202};
203
204enum power_supply_type {
205 POWER_SUPPLY_TYPE_UNKNOWN = 0,
206 POWER_SUPPLY_TYPE_BATTERY,
207 POWER_SUPPLY_TYPE_UPS,
208 POWER_SUPPLY_TYPE_MAINS,
209 POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */
210 POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */
211 POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */
212 POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */
213 POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */
214 POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */
215 POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */
216 POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
217 POWER_SUPPLY_TYPE_OTG,
218 POWER_SUPPLY_TYPE_HV_MAINS,
219 POWER_SUPPLY_TYPE_PREPARE_TA,
220 POWER_SUPPLY_TYPE_SMART_NOTG,
221 POWER_SUPPLY_TYPE_END,
222};
223
224enum power_supply_notifier_events {
225 PSY_EVENT_PROP_CHANGED,
226 PSY_EVENT_PROP_ADDED,
227};
228
229union power_supply_propval {
230 int intval;
231 const char *strval;
232 int64_t int64val;
233};
234
235struct device_node;
236struct power_supply;
237
238/* Run-time specific power supply configuration */
239struct power_supply_config {
240 struct device_node *of_node;
241 /* Driver private data */
242 void *drv_data;
243
244 char **supplied_to;
245 size_t num_supplicants;
246};
247
248/* Description of power supply */
249struct power_supply_desc {
250 const char *name;
251 enum power_supply_type type;
252 enum power_supply_property *properties;
253 size_t num_properties;
254
255 /*
256 * Functions for drivers implementing power supply class.
257 * These shouldn't be called directly by other drivers for accessing
258 * this power supply. Instead use power_supply_*() functions (for
259 * example power_supply_get_property()).
260 */
261 int (*get_property)(struct power_supply *psy,
262 enum power_supply_property psp,
263 union power_supply_propval *val);
264 int (*set_property)(struct power_supply *psy,
265 enum power_supply_property psp,
266 const union power_supply_propval *val);
267 /*
268 * property_is_writeable() will be called during registration
269 * of power supply. If this happens during device probe then it must
270 * not access internal data of device (because probe did not end).
271 */
272 int (*property_is_writeable)(struct power_supply *psy,
273 enum power_supply_property psp);
274 void (*external_power_changed)(struct power_supply *psy);
275 void (*set_charged)(struct power_supply *psy);
276
277 /*
278 * Set if thermal zone should not be created for this power supply.
279 * For example for virtual supplies forwarding calls to actual
280 * sensors or other supplies.
281 */
282 bool no_thermal;
283 /* For APM emulation, think legacy userspace. */
284 int use_for_apm;
285};
286
287struct power_supply {
288 const struct power_supply_desc *desc;
289
290 char **supplied_to;
291 size_t num_supplicants;
292
293 char **supplied_from;
294 size_t num_supplies;
295 struct device_node *of_node;
296
297 /* Driver private data */
298 void *drv_data;
299
300 /* private */
301 struct device dev;
302 struct work_struct changed_work;
303 struct delayed_work deferred_register_work;
304 spinlock_t changed_lock;
305 bool changed;
306 bool initialized;
307 bool removing;
308 atomic_t use_cnt;
309#ifdef CONFIG_THERMAL
310 struct thermal_zone_device *tzd;
311 struct thermal_cooling_device *tcd;
312#endif
313
314#ifdef CONFIG_LEDS_TRIGGERS
315 struct led_trigger *charging_full_trig;
316 char *charging_full_trig_name;
317 struct led_trigger *charging_trig;
318 char *charging_trig_name;
319 struct led_trigger *full_trig;
320 char *full_trig_name;
321 struct led_trigger *online_trig;
322 char *online_trig_name;
323 struct led_trigger *charging_blink_full_solid_trig;
324 char *charging_blink_full_solid_trig_name;
325#endif
326};
327
328/*
329 * This is recommended structure to specify static power supply parameters.
330 * Generic one, parametrizable for different power supplies. Power supply
331 * class itself does not use it, but that's what implementing most platform
332 * drivers, should try reuse for consistency.
333 */
334
335struct power_supply_info {
336 const char *name;
337 int technology;
338 int voltage_max_design;
339 int voltage_min_design;
340 int charge_full_design;
341 int charge_empty_design;
342 int energy_full_design;
343 int energy_empty_design;
344 int use_for_apm;
345};
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
356struct 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 precharge_current_ua; /* microAmps */
361 int charge_term_current_ua; /* microAmps */
362 int constant_charge_current_max_ua; /* microAmps */
363 int constant_charge_voltage_max_uv; /* microVolts */
364};
365
366extern struct atomic_notifier_head power_supply_notifier;
367extern int power_supply_reg_notifier(struct notifier_block *nb);
368extern void power_supply_unreg_notifier(struct notifier_block *nb);
369extern struct power_supply *power_supply_get_by_name(const char *name);
370extern void power_supply_put(struct power_supply *psy);
371#ifdef CONFIG_OF
372extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
373 const char *property);
374extern struct power_supply *devm_power_supply_get_by_phandle(
375 struct device *dev, const char *property);
376#else /* !CONFIG_OF */
377static inline struct power_supply *
378power_supply_get_by_phandle(struct device_node *np, const char *property)
379{ return NULL; }
380static inline struct power_supply *
381devm_power_supply_get_by_phandle(struct device *dev, const char *property)
382{ return NULL; }
383#endif /* CONFIG_OF */
384
385extern int power_supply_get_battery_info(struct power_supply *psy,
386 struct power_supply_battery_info *info);
387extern void power_supply_changed(struct power_supply *psy);
388extern int power_supply_am_i_supplied(struct power_supply *psy);
389extern int power_supply_set_input_current_limit_from_supplier(
390 struct power_supply *psy);
391extern int power_supply_set_battery_charged(struct power_supply *psy);
392
393#ifdef CONFIG_POWER_SUPPLY
394extern int power_supply_is_system_supplied(void);
395#else
396static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
397#endif
398
399extern int power_supply_get_property(struct power_supply *psy,
400 enum power_supply_property psp,
401 union power_supply_propval *val);
402extern int power_supply_set_property(struct power_supply *psy,
403 enum power_supply_property psp,
404 const union power_supply_propval *val);
405extern int power_supply_property_is_writeable(struct power_supply *psy,
406 enum power_supply_property psp);
407extern void power_supply_external_power_changed(struct power_supply *psy);
408
409extern struct power_supply *__must_check
410power_supply_register(struct device *parent,
411 const struct power_supply_desc *desc,
412 const struct power_supply_config *cfg);
413extern struct power_supply *__must_check
414power_supply_register_no_ws(struct device *parent,
415 const struct power_supply_desc *desc,
416 const struct power_supply_config *cfg);
417extern struct power_supply *__must_check
418devm_power_supply_register(struct device *parent,
419 const struct power_supply_desc *desc,
420 const struct power_supply_config *cfg);
421extern struct power_supply *__must_check
422devm_power_supply_register_no_ws(struct device *parent,
423 const struct power_supply_desc *desc,
424 const struct power_supply_config *cfg);
425extern void power_supply_unregister(struct power_supply *psy);
426extern int power_supply_powers(struct power_supply *psy, struct device *dev);
427
428extern void *power_supply_get_drvdata(struct power_supply *psy);
429/* For APM emulation, think legacy userspace. */
430extern struct class *power_supply_class;
431
432static inline bool power_supply_is_amp_property(enum power_supply_property psp)
433{
434 switch (psp) {
435 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
436 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
437 case POWER_SUPPLY_PROP_CHARGE_FULL:
438 case POWER_SUPPLY_PROP_CHARGE_EMPTY:
439 case POWER_SUPPLY_PROP_CHARGE_NOW:
440 case POWER_SUPPLY_PROP_CHARGE_AVG:
441 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
442 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
443 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
444 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
445 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
446 case POWER_SUPPLY_PROP_CURRENT_MAX:
447 case POWER_SUPPLY_PROP_CURRENT_NOW:
448 case POWER_SUPPLY_PROP_CURRENT_AVG:
449 case POWER_SUPPLY_PROP_CURRENT_BOOT:
450 return 1;
451 default:
452 break;
453 }
454
455 return 0;
456}
457
458static inline bool power_supply_is_watt_property(enum power_supply_property psp)
459{
460 switch (psp) {
461 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
462 case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
463 case POWER_SUPPLY_PROP_ENERGY_FULL:
464 case POWER_SUPPLY_PROP_ENERGY_EMPTY:
465 case POWER_SUPPLY_PROP_ENERGY_NOW:
466 case POWER_SUPPLY_PROP_ENERGY_AVG:
467 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
468 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
469 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
470 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
471 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
472 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
473 case POWER_SUPPLY_PROP_VOLTAGE_OCV:
474 case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
475 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
476 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
477 case POWER_SUPPLY_PROP_POWER_NOW:
478 return 1;
479 default:
480 break;
481 }
482
483 return 0;
484}
485
486#endif /* __LINUX_POWER_SUPPLY_H__ */