]>
Commit | Line | Data |
---|---|---|
a63a5fa9 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
4a11b59d AV |
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 | |
4a11b59d AV |
10 | */ |
11 | ||
12 | #ifndef __LINUX_POWER_SUPPLY_H__ | |
13 | #define __LINUX_POWER_SUPPLY_H__ | |
14 | ||
297d716f | 15 | #include <linux/device.h> |
4a11b59d AV |
16 | #include <linux/workqueue.h> |
17 | #include <linux/leds.h> | |
948dcf96 | 18 | #include <linux/spinlock.h> |
d36240d2 | 19 | #include <linux/notifier.h> |
4a11b59d AV |
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 | ||
ba6cc850 | 42 | /* What algorithm is the charger using? */ |
ee8076ed AS |
43 | enum { |
44 | POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0, | |
45 | POWER_SUPPLY_CHARGE_TYPE_NONE, | |
ba6cc850 NC |
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 */ | |
46cbd0b0 | 51 | POWER_SUPPLY_CHARGE_TYPE_LONGLIFE, /* slow speed, longer life */ |
ee8076ed AS |
52 | }; |
53 | ||
4a11b59d AV |
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, | |
7e386e6e | 61 | POWER_SUPPLY_HEALTH_COLD, |
a05be991 RP |
62 | POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, |
63 | POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE, | |
e3e83cc6 | 64 | POWER_SUPPLY_HEALTH_OVERCURRENT, |
601c2a54 | 65 | POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED, |
98cc1b93 DM |
66 | POWER_SUPPLY_HEALTH_WARM, |
67 | POWER_SUPPLY_HEALTH_COOL, | |
68 | POWER_SUPPLY_HEALTH_HOT, | |
4a11b59d AV |
69 | }; |
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, | |
c7cc930f | 78 | POWER_SUPPLY_TECHNOLOGY_LiMn, |
4a11b59d AV |
79 | }; |
80 | ||
b294a290 AS |
81 | enum { |
82 | POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0, | |
83 | POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, | |
84 | POWER_SUPPLY_CAPACITY_LEVEL_LOW, | |
85 | POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, | |
86 | POWER_SUPPLY_CAPACITY_LEVEL_HIGH, | |
87 | POWER_SUPPLY_CAPACITY_LEVEL_FULL, | |
88 | }; | |
89 | ||
25a0bc2d JF |
90 | enum { |
91 | POWER_SUPPLY_SCOPE_UNKNOWN = 0, | |
92 | POWER_SUPPLY_SCOPE_SYSTEM, | |
93 | POWER_SUPPLY_SCOPE_DEVICE, | |
94 | }; | |
95 | ||
4a11b59d AV |
96 | enum power_supply_property { |
97 | /* Properties of type `int' */ | |
98 | POWER_SUPPLY_PROP_STATUS = 0, | |
ee8076ed | 99 | POWER_SUPPLY_PROP_CHARGE_TYPE, |
4a11b59d AV |
100 | POWER_SUPPLY_PROP_HEALTH, |
101 | POWER_SUPPLY_PROP_PRESENT, | |
102 | POWER_SUPPLY_PROP_ONLINE, | |
b1b56872 | 103 | POWER_SUPPLY_PROP_AUTHENTIC, |
4a11b59d | 104 | POWER_SUPPLY_PROP_TECHNOLOGY, |
c955fe8e | 105 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
c7cc930f DB |
106 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
107 | POWER_SUPPLY_PROP_VOLTAGE_MIN, | |
4a11b59d AV |
108 | POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, |
109 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | |
110 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | |
111 | POWER_SUPPLY_PROP_VOLTAGE_AVG, | |
a2ebfe2f | 112 | POWER_SUPPLY_PROP_VOLTAGE_OCV, |
a8adcc90 | 113 | POWER_SUPPLY_PROP_VOLTAGE_BOOT, |
fe3f6d09 | 114 | POWER_SUPPLY_PROP_CURRENT_MAX, |
4a11b59d AV |
115 | POWER_SUPPLY_PROP_CURRENT_NOW, |
116 | POWER_SUPPLY_PROP_CURRENT_AVG, | |
a8adcc90 | 117 | POWER_SUPPLY_PROP_CURRENT_BOOT, |
7faa144a AS |
118 | POWER_SUPPLY_PROP_POWER_NOW, |
119 | POWER_SUPPLY_PROP_POWER_AVG, | |
4a11b59d AV |
120 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
121 | POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, | |
122 | POWER_SUPPLY_PROP_CHARGE_FULL, | |
123 | POWER_SUPPLY_PROP_CHARGE_EMPTY, | |
124 | POWER_SUPPLY_PROP_CHARGE_NOW, | |
125 | POWER_SUPPLY_PROP_CHARGE_AVG, | |
8e552c36 | 126 | POWER_SUPPLY_PROP_CHARGE_COUNTER, |
3824c477 | 127 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, |
2815b786 | 128 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, |
3824c477 | 129 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, |
2815b786 | 130 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, |
ea2ce92e RP |
131 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, |
132 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, | |
813cab8f NC |
133 | POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */ |
134 | POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */ | |
6bb1d272 | 135 | POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, |
a4496d52 EBS |
136 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, |
137 | POWER_SUPPLY_PROP_INPUT_POWER_LIMIT, | |
4a11b59d AV |
138 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, |
139 | POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, | |
140 | POWER_SUPPLY_PROP_ENERGY_FULL, | |
141 | POWER_SUPPLY_PROP_ENERGY_EMPTY, | |
142 | POWER_SUPPLY_PROP_ENERGY_NOW, | |
143 | POWER_SUPPLY_PROP_ENERGY_AVG, | |
144 | POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ | |
e908c418 RP |
145 | POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ |
146 | POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ | |
bac705ab | 147 | POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */ |
b294a290 | 148 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
4a11b59d | 149 | POWER_SUPPLY_PROP_TEMP, |
6bb1d272 JT |
150 | POWER_SUPPLY_PROP_TEMP_MAX, |
151 | POWER_SUPPLY_PROP_TEMP_MIN, | |
e908c418 RP |
152 | POWER_SUPPLY_PROP_TEMP_ALERT_MIN, |
153 | POWER_SUPPLY_PROP_TEMP_ALERT_MAX, | |
4a11b59d | 154 | POWER_SUPPLY_PROP_TEMP_AMBIENT, |
e908c418 RP |
155 | POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, |
156 | POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, | |
4a11b59d AV |
157 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, |
158 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, | |
159 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, | |
160 | POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, | |
5f487cd3 | 161 | POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ |
cf450041 | 162 | POWER_SUPPLY_PROP_USB_TYPE, |
25a0bc2d | 163 | POWER_SUPPLY_PROP_SCOPE, |
413de34a | 164 | POWER_SUPPLY_PROP_PRECHARGE_CURRENT, |
6bb1d272 | 165 | POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, |
a8adcc90 | 166 | POWER_SUPPLY_PROP_CALIBRATE, |
feabe49e SR |
167 | POWER_SUPPLY_PROP_MANUFACTURE_YEAR, |
168 | POWER_SUPPLY_PROP_MANUFACTURE_MONTH, | |
169 | POWER_SUPPLY_PROP_MANUFACTURE_DAY, | |
4a11b59d AV |
170 | /* Properties of type `const char *' */ |
171 | POWER_SUPPLY_PROP_MODEL_NAME, | |
172 | POWER_SUPPLY_PROP_MANUFACTURER, | |
7c2670bb | 173 | POWER_SUPPLY_PROP_SERIAL_NUMBER, |
4a11b59d AV |
174 | }; |
175 | ||
176 | enum power_supply_type { | |
9b887227 KM |
177 | POWER_SUPPLY_TYPE_UNKNOWN = 0, |
178 | POWER_SUPPLY_TYPE_BATTERY, | |
4a11b59d AV |
179 | POWER_SUPPLY_TYPE_UPS, |
180 | POWER_SUPPLY_TYPE_MAINS, | |
71399aa5 BL |
181 | POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */ |
182 | POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */ | |
183 | POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */ | |
184 | POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ | |
185 | POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */ | |
186 | POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */ | |
187 | POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */ | |
188 | POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ | |
5ca937fb | 189 | POWER_SUPPLY_TYPE_WIRELESS, /* Wireless */ |
4a11b59d AV |
190 | }; |
191 | ||
cf450041 AT |
192 | enum power_supply_usb_type { |
193 | POWER_SUPPLY_USB_TYPE_UNKNOWN = 0, | |
194 | POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */ | |
195 | POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */ | |
196 | POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */ | |
197 | POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */ | |
198 | POWER_SUPPLY_USB_TYPE_C, /* Type C Port */ | |
199 | POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */ | |
200 | POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */ | |
201 | POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */ | |
202 | POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ | |
203 | }; | |
204 | ||
d36240d2 PR |
205 | enum power_supply_notifier_events { |
206 | PSY_EVENT_PROP_CHANGED, | |
207 | }; | |
208 | ||
4a11b59d AV |
209 | union power_supply_propval { |
210 | int intval; | |
211 | const char *strval; | |
212 | }; | |
213 | ||
b50df95c | 214 | struct device_node; |
297d716f | 215 | struct power_supply; |
b50df95c | 216 | |
297d716f | 217 | /* Run-time specific power supply configuration */ |
2dc9215d KK |
218 | struct power_supply_config { |
219 | struct device_node *of_node; | |
ece711b5 AT |
220 | struct fwnode_handle *fwnode; |
221 | ||
2dc9215d KK |
222 | /* Driver private data */ |
223 | void *drv_data; | |
224 | ||
cef8fe6a SR |
225 | /* Device specific sysfs attributes */ |
226 | const struct attribute_group **attr_grp; | |
227 | ||
2dc9215d KK |
228 | char **supplied_to; |
229 | size_t num_supplicants; | |
230 | }; | |
231 | ||
297d716f KK |
232 | /* Description of power supply */ |
233 | struct power_supply_desc { | |
4a11b59d AV |
234 | const char *name; |
235 | enum power_supply_type type; | |
9ba2353b | 236 | const enum power_supply_usb_type *usb_types; |
cf450041 | 237 | size_t num_usb_types; |
9ba2353b | 238 | const enum power_supply_property *properties; |
4a11b59d AV |
239 | size_t num_properties; |
240 | ||
bc154056 KK |
241 | /* |
242 | * Functions for drivers implementing power supply class. | |
243 | * These shouldn't be called directly by other drivers for accessing | |
244 | * this power supply. Instead use power_supply_*() functions (for | |
245 | * example power_supply_get_property()). | |
246 | */ | |
4a11b59d AV |
247 | int (*get_property)(struct power_supply *psy, |
248 | enum power_supply_property psp, | |
249 | union power_supply_propval *val); | |
0011d2d4 DM |
250 | int (*set_property)(struct power_supply *psy, |
251 | enum power_supply_property psp, | |
252 | const union power_supply_propval *val); | |
5c6e3a97 KK |
253 | /* |
254 | * property_is_writeable() will be called during registration | |
255 | * of power supply. If this happens during device probe then it must | |
256 | * not access internal data of device (because probe did not end). | |
257 | */ | |
0011d2d4 DM |
258 | int (*property_is_writeable)(struct power_supply *psy, |
259 | enum power_supply_property psp); | |
4a11b59d | 260 | void (*external_power_changed)(struct power_supply *psy); |
e5f5ccb6 | 261 | void (*set_charged)(struct power_supply *psy); |
4a11b59d | 262 | |
a69d82b9 KK |
263 | /* |
264 | * Set if thermal zone should not be created for this power supply. | |
265 | * For example for virtual supplies forwarding calls to actual | |
266 | * sensors or other supplies. | |
267 | */ | |
268 | bool no_thermal; | |
4a11b59d AV |
269 | /* For APM emulation, think legacy userspace. */ |
270 | int use_for_apm; | |
297d716f KK |
271 | }; |
272 | ||
273 | struct power_supply { | |
274 | const struct power_supply_desc *desc; | |
275 | ||
276 | char **supplied_to; | |
277 | size_t num_supplicants; | |
278 | ||
279 | char **supplied_from; | |
280 | size_t num_supplies; | |
281 | struct device_node *of_node; | |
4a11b59d | 282 | |
e44ea364 KK |
283 | /* Driver private data */ |
284 | void *drv_data; | |
285 | ||
4a11b59d | 286 | /* private */ |
297d716f | 287 | struct device dev; |
4a11b59d | 288 | struct work_struct changed_work; |
7f1a57fd | 289 | struct delayed_work deferred_register_work; |
948dcf96 ZM |
290 | spinlock_t changed_lock; |
291 | bool changed; | |
e3805385 | 292 | bool initialized; |
3ffa6583 | 293 | bool removing; |
bc154056 | 294 | atomic_t use_cnt; |
3be330bf JT |
295 | #ifdef CONFIG_THERMAL |
296 | struct thermal_zone_device *tzd; | |
952aeeb3 | 297 | struct thermal_cooling_device *tcd; |
3be330bf | 298 | #endif |
4a11b59d AV |
299 | |
300 | #ifdef CONFIG_LEDS_TRIGGERS | |
301 | struct led_trigger *charging_full_trig; | |
302 | char *charging_full_trig_name; | |
303 | struct led_trigger *charging_trig; | |
304 | char *charging_trig_name; | |
305 | struct led_trigger *full_trig; | |
306 | char *full_trig_name; | |
307 | struct led_trigger *online_trig; | |
308 | char *online_trig_name; | |
6501f728 VK |
309 | struct led_trigger *charging_blink_full_solid_trig; |
310 | char *charging_blink_full_solid_trig_name; | |
4a11b59d AV |
311 | #endif |
312 | }; | |
313 | ||
314 | /* | |
315 | * This is recommended structure to specify static power supply parameters. | |
316 | * Generic one, parametrizable for different power supplies. Power supply | |
317 | * class itself does not use it, but that's what implementing most platform | |
318 | * drivers, should try reuse for consistency. | |
319 | */ | |
320 | ||
321 | struct power_supply_info { | |
322 | const char *name; | |
323 | int technology; | |
324 | int voltage_max_design; | |
325 | int voltage_min_design; | |
326 | int charge_full_design; | |
327 | int charge_empty_design; | |
328 | int energy_full_design; | |
329 | int energy_empty_design; | |
330 | int use_for_apm; | |
331 | }; | |
332 | ||
3afb50d7 BW |
333 | struct power_supply_battery_ocv_table { |
334 | int ocv; /* microVolts */ | |
335 | int capacity; /* percent */ | |
336 | }; | |
337 | ||
65dbad71 BW |
338 | struct power_supply_resistance_temp_table { |
339 | int temp; /* celsius */ | |
340 | int resistance; /* internal resistance percent */ | |
341 | }; | |
342 | ||
3afb50d7 BW |
343 | #define POWER_SUPPLY_OCV_TEMP_MAX 20 |
344 | ||
c08b1f45 LB |
345 | /* |
346 | * This is the recommended struct to manage static battery parameters, | |
347 | * populated by power_supply_get_battery_info(). Most platform drivers should | |
348 | * use these for consistency. | |
349 | * Its field names must correspond to elements in enum power_supply_property. | |
350 | * The default field value is -EINVAL. | |
351 | * Power supply class itself doesn't use this. | |
352 | */ | |
353 | ||
354 | struct power_supply_battery_info { | |
355 | int energy_full_design_uwh; /* microWatt-hours */ | |
356 | int charge_full_design_uah; /* microAmp-hours */ | |
357 | int voltage_min_design_uv; /* microVolts */ | |
04fb5310 | 358 | int voltage_max_design_uv; /* microVolts */ |
5a63b7ba | 359 | int tricklecharge_current_ua; /* microAmps */ |
c08b1f45 | 360 | int precharge_current_ua; /* microAmps */ |
5a63b7ba | 361 | int precharge_voltage_max_uv; /* microVolts */ |
c08b1f45 | 362 | int charge_term_current_ua; /* microAmps */ |
5a63b7ba MV |
363 | int charge_restart_voltage_uv; /* microVolts */ |
364 | int overvoltage_limit_uv; /* microVolts */ | |
c08b1f45 LB |
365 | int constant_charge_current_max_ua; /* microAmps */ |
366 | int constant_charge_voltage_max_uv; /* microVolts */ | |
86131d93 | 367 | int factory_internal_resistance_uohm; /* microOhms */ |
3afb50d7 | 368 | int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ |
00cda13e DO |
369 | int temp_ambient_alert_min; /* celsius */ |
370 | int temp_ambient_alert_max; /* celsius */ | |
371 | int temp_alert_min; /* celsius */ | |
372 | int temp_alert_max; /* celsius */ | |
373 | int temp_min; /* celsius */ | |
374 | int temp_max; /* celsius */ | |
3afb50d7 BW |
375 | struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; |
376 | int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; | |
65dbad71 BW |
377 | struct power_supply_resistance_temp_table *resist_table; |
378 | int resist_table_size; | |
c08b1f45 LB |
379 | }; |
380 | ||
d36240d2 PR |
381 | extern struct atomic_notifier_head power_supply_notifier; |
382 | extern int power_supply_reg_notifier(struct notifier_block *nb); | |
383 | extern void power_supply_unreg_notifier(struct notifier_block *nb); | |
f38a1644 | 384 | #if IS_ENABLED(CONFIG_POWER_SUPPLY) |
9f3b795a | 385 | extern struct power_supply *power_supply_get_by_name(const char *name); |
1a352462 | 386 | extern void power_supply_put(struct power_supply *psy); |
f38a1644 RC |
387 | #else |
388 | static inline void power_supply_put(struct power_supply *psy) {} | |
389 | static inline struct power_supply *power_supply_get_by_name(const char *name) | |
390 | { return NULL; } | |
391 | #endif | |
abce9770 SR |
392 | #ifdef CONFIG_OF |
393 | extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, | |
394 | const char *property); | |
fe27e1df HG |
395 | extern struct power_supply *devm_power_supply_get_by_phandle( |
396 | struct device *dev, const char *property); | |
abce9770 SR |
397 | #else /* !CONFIG_OF */ |
398 | static inline struct power_supply * | |
399 | power_supply_get_by_phandle(struct device_node *np, const char *property) | |
400 | { return NULL; } | |
fe27e1df HG |
401 | static inline struct power_supply * |
402 | devm_power_supply_get_by_phandle(struct device *dev, const char *property) | |
403 | { return NULL; } | |
abce9770 | 404 | #endif /* CONFIG_OF */ |
c08b1f45 LB |
405 | |
406 | extern int power_supply_get_battery_info(struct power_supply *psy, | |
407 | struct power_supply_battery_info *info); | |
3afb50d7 BW |
408 | extern void power_supply_put_battery_info(struct power_supply *psy, |
409 | struct power_supply_battery_info *info); | |
410 | extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, | |
411 | int table_len, int ocv); | |
412 | extern struct power_supply_battery_ocv_table * | |
413 | power_supply_find_ocv2cap_table(struct power_supply_battery_info *info, | |
414 | int temp, int *table_len); | |
415 | extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, | |
416 | int ocv, int temp); | |
65dbad71 BW |
417 | extern int |
418 | power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table, | |
419 | int table_len, int temp); | |
4a11b59d AV |
420 | extern void power_supply_changed(struct power_supply *psy); |
421 | extern int power_supply_am_i_supplied(struct power_supply *psy); | |
c3142dd8 HG |
422 | extern int power_supply_set_input_current_limit_from_supplier( |
423 | struct power_supply *psy); | |
e5f5ccb6 | 424 | extern int power_supply_set_battery_charged(struct power_supply *psy); |
4a11b59d | 425 | |
0d4ed4e2 | 426 | #ifdef CONFIG_POWER_SUPPLY |
942ed161 MG |
427 | extern int power_supply_is_system_supplied(void); |
428 | #else | |
429 | static inline int power_supply_is_system_supplied(void) { return -ENOSYS; } | |
430 | #endif | |
431 | ||
bc154056 KK |
432 | extern int power_supply_get_property(struct power_supply *psy, |
433 | enum power_supply_property psp, | |
434 | union power_supply_propval *val); | |
c21161e4 | 435 | #if IS_ENABLED(CONFIG_POWER_SUPPLY) |
bc154056 KK |
436 | extern int power_supply_set_property(struct power_supply *psy, |
437 | enum power_supply_property psp, | |
438 | const union power_supply_propval *val); | |
c21161e4 RC |
439 | #else |
440 | static inline int power_supply_set_property(struct power_supply *psy, | |
441 | enum power_supply_property psp, | |
442 | const union power_supply_propval *val) | |
443 | { return 0; } | |
444 | #endif | |
bc154056 KK |
445 | extern int power_supply_property_is_writeable(struct power_supply *psy, |
446 | enum power_supply_property psp); | |
447 | extern void power_supply_external_power_changed(struct power_supply *psy); | |
297d716f KK |
448 | |
449 | extern struct power_supply *__must_check | |
450 | power_supply_register(struct device *parent, | |
451 | const struct power_supply_desc *desc, | |
2dc9215d | 452 | const struct power_supply_config *cfg); |
297d716f KK |
453 | extern struct power_supply *__must_check |
454 | power_supply_register_no_ws(struct device *parent, | |
455 | const struct power_supply_desc *desc, | |
2dc9215d | 456 | const struct power_supply_config *cfg); |
297d716f KK |
457 | extern struct power_supply *__must_check |
458 | devm_power_supply_register(struct device *parent, | |
459 | const struct power_supply_desc *desc, | |
2dc9215d | 460 | const struct power_supply_config *cfg); |
297d716f KK |
461 | extern struct power_supply *__must_check |
462 | devm_power_supply_register_no_ws(struct device *parent, | |
463 | const struct power_supply_desc *desc, | |
2dc9215d | 464 | const struct power_supply_config *cfg); |
4a11b59d | 465 | extern void power_supply_unregister(struct power_supply *psy); |
83516651 | 466 | extern int power_supply_powers(struct power_supply *psy, struct device *dev); |
4a11b59d | 467 | |
285995d1 OG |
468 | #define to_power_supply(device) container_of(device, struct power_supply, dev) |
469 | ||
e44ea364 | 470 | extern void *power_supply_get_drvdata(struct power_supply *psy); |
4a11b59d AV |
471 | /* For APM emulation, think legacy userspace. */ |
472 | extern struct class *power_supply_class; | |
473 | ||
51d07566 RK |
474 | static inline bool power_supply_is_amp_property(enum power_supply_property psp) |
475 | { | |
476 | switch (psp) { | |
477 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | |
478 | case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: | |
479 | case POWER_SUPPLY_PROP_CHARGE_FULL: | |
480 | case POWER_SUPPLY_PROP_CHARGE_EMPTY: | |
481 | case POWER_SUPPLY_PROP_CHARGE_NOW: | |
482 | case POWER_SUPPLY_PROP_CHARGE_AVG: | |
483 | case POWER_SUPPLY_PROP_CHARGE_COUNTER: | |
413de34a LB |
484 | case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: |
485 | case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: | |
3824c477 | 486 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: |
2815b786 | 487 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: |
51d07566 RK |
488 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
489 | case POWER_SUPPLY_PROP_CURRENT_NOW: | |
490 | case POWER_SUPPLY_PROP_CURRENT_AVG: | |
a8adcc90 | 491 | case POWER_SUPPLY_PROP_CURRENT_BOOT: |
25faa935 | 492 | return true; |
51d07566 RK |
493 | default: |
494 | break; | |
495 | } | |
496 | ||
25faa935 | 497 | return false; |
51d07566 RK |
498 | } |
499 | ||
500 | static inline bool power_supply_is_watt_property(enum power_supply_property psp) | |
501 | { | |
502 | switch (psp) { | |
503 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: | |
504 | case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN: | |
505 | case POWER_SUPPLY_PROP_ENERGY_FULL: | |
506 | case POWER_SUPPLY_PROP_ENERGY_EMPTY: | |
507 | case POWER_SUPPLY_PROP_ENERGY_NOW: | |
508 | case POWER_SUPPLY_PROP_ENERGY_AVG: | |
509 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: | |
510 | case POWER_SUPPLY_PROP_VOLTAGE_MIN: | |
511 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | |
512 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | |
513 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | |
514 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: | |
a2ebfe2f | 515 | case POWER_SUPPLY_PROP_VOLTAGE_OCV: |
a8adcc90 | 516 | case POWER_SUPPLY_PROP_VOLTAGE_BOOT: |
3824c477 | 517 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: |
2815b786 | 518 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: |
35c9d267 | 519 | case POWER_SUPPLY_PROP_POWER_NOW: |
25faa935 | 520 | return true; |
51d07566 RK |
521 | default: |
522 | break; | |
523 | } | |
524 | ||
25faa935 | 525 | return false; |
51d07566 RK |
526 | } |
527 | ||
e67d4dfc AS |
528 | #ifdef CONFIG_POWER_SUPPLY_HWMON |
529 | int power_supply_add_hwmon_sysfs(struct power_supply *psy); | |
530 | void power_supply_remove_hwmon_sysfs(struct power_supply *psy); | |
531 | #else | |
532 | static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy) | |
533 | { | |
534 | return 0; | |
535 | } | |
536 | ||
537 | static inline | |
538 | void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {} | |
539 | #endif | |
540 | ||
4a11b59d | 541 | #endif /* __LINUX_POWER_SUPPLY_H__ */ |