blob: dc56925b2c66257157c30a116c0ae607718c9300 [file] [log] [blame]
Anton Vorontsov4a11b592007-05-04 00:27:45 +04001/*
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
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010016#include <linux/device.h>
Anton Vorontsov4a11b592007-05-04 00:27:45 +040017#include <linux/workqueue.h>
18#include <linux/leds.h>
Zoran Markovic948dcf92013-08-02 13:38:02 -070019#include <linux/spinlock.h>
Pali Rohárd36240d2013-11-19 11:18:03 +010020#include <linux/notifier.h>
Todd Poynor6a427732013-12-12 15:59:09 -080021#include <linux/types.h>
Anton Vorontsov4a11b592007-05-04 00:27:45 +040022
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 {
Andres Salomonee8076e2009-07-02 09:45:18 -040045 POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
46 POWER_SUPPLY_CHARGE_TYPE_NONE,
47 POWER_SUPPLY_CHARGE_TYPE_TRICKLE,
48 POWER_SUPPLY_CHARGE_TYPE_FAST,
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -070049 POWER_SUPPLY_CHARGE_TYPE_TAPER,
Andres Salomonee8076e2009-07-02 09:45:18 -040050};
51
52enum {
Anton Vorontsov4a11b592007-05-04 00:27:45 +040053 POWER_SUPPLY_HEALTH_UNKNOWN = 0,
54 POWER_SUPPLY_HEALTH_GOOD,
55 POWER_SUPPLY_HEALTH_OVERHEAT,
56 POWER_SUPPLY_HEALTH_DEAD,
57 POWER_SUPPLY_HEALTH_OVERVOLTAGE,
58 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
Mark Brown7e386e62008-11-30 22:43:21 +010059 POWER_SUPPLY_HEALTH_COLD,
Ramakrishna Pallalaa05be992012-11-30 13:57:46 +053060 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
61 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -070062 POWER_SUPPLY_HEALTH_WARM,
63 POWER_SUPPLY_HEALTH_COOL,
64 POWER_SUPPLY_HEALTH_HOT,
Anton Vorontsov4a11b592007-05-04 00:27:45 +040065};
66
67enum {
68 POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0,
69 POWER_SUPPLY_TECHNOLOGY_NiMH,
70 POWER_SUPPLY_TECHNOLOGY_LION,
71 POWER_SUPPLY_TECHNOLOGY_LIPO,
72 POWER_SUPPLY_TECHNOLOGY_LiFe,
73 POWER_SUPPLY_TECHNOLOGY_NiCd,
Dmitry Baryshkovc7cc9302008-01-07 04:12:41 +030074 POWER_SUPPLY_TECHNOLOGY_LiMn,
Anton Vorontsov4a11b592007-05-04 00:27:45 +040075};
76
Andres Salomonb294a292009-06-30 02:13:01 -040077enum {
78 POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
79 POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
80 POWER_SUPPLY_CAPACITY_LEVEL_LOW,
81 POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
82 POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
83 POWER_SUPPLY_CAPACITY_LEVEL_FULL,
84};
85
Jeremy Fitzhardinge25a0bc22011-12-07 11:24:20 -080086enum {
87 POWER_SUPPLY_SCOPE_UNKNOWN = 0,
88 POWER_SUPPLY_SCOPE_SYSTEM,
89 POWER_SUPPLY_SCOPE_DEVICE,
90};
91
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -070092enum {
93 POWER_SUPPLY_DP_DM_UNKNOWN = 0,
94 POWER_SUPPLY_DP_DM_PREPARE = 1,
95 POWER_SUPPLY_DP_DM_UNPREPARE = 2,
96 POWER_SUPPLY_DP_DM_CONFIRMED_HVDCP3 = 3,
97 POWER_SUPPLY_DP_DM_DP_PULSE = 4,
98 POWER_SUPPLY_DP_DM_DM_PULSE = 5,
99 POWER_SUPPLY_DP_DM_DP0P6_DMF = 6,
100 POWER_SUPPLY_DP_DM_DP0P6_DM3P3 = 7,
101 POWER_SUPPLY_DP_DM_DPF_DMF = 8,
102 POWER_SUPPLY_DP_DM_DPR_DMR = 9,
103 POWER_SUPPLY_DP_DM_HVDCP3_SUPPORTED = 10,
104 POWER_SUPPLY_DP_DM_ICL_DOWN = 11,
105 POWER_SUPPLY_DP_DM_ICL_UP = 12,
106 POWER_SUPPLY_DP_DM_FORCE_5V = 13,
107 POWER_SUPPLY_DP_DM_FORCE_9V = 14,
108 POWER_SUPPLY_DP_DM_FORCE_12V = 15,
109};
110
111enum {
112 POWER_SUPPLY_PL_NONE,
113 POWER_SUPPLY_PL_USBIN_USBIN,
114 POWER_SUPPLY_PL_USBIN_USBIN_EXT,
115 POWER_SUPPLY_PL_USBMID_USBMID,
116};
117
118enum {
119 POWER_SUPPLY_CHARGER_SEC_NONE = 0,
120 POWER_SUPPLY_CHARGER_SEC_CP,
121 POWER_SUPPLY_CHARGER_SEC_PL,
122 POWER_SUPPLY_CHARGER_SEC_CP_PL,
123};
124
125enum {
126 POWER_SUPPLY_CP_NONE = 0,
127 POWER_SUPPLY_CP_HVDCP3,
128 POWER_SUPPLY_CP_PPS,
129 POWER_SUPPLY_CP_WIRELESS,
130};
131
132enum {
133 POWER_SUPPLY_CONNECTOR_TYPEC,
134 POWER_SUPPLY_CONNECTOR_MICRO_USB,
135};
136
137enum {
138 POWER_SUPPLY_PL_STACKED_BATFET,
139 POWER_SUPPLY_PL_NON_STACKED_BATFET,
140};
141
142enum {
143 POWER_SUPPLY_PD_INACTIVE = 0,
144 POWER_SUPPLY_PD_ACTIVE,
145 POWER_SUPPLY_PD_PPS_ACTIVE,
146};
147
Ashay Jaiswal18f6e9d2018-06-13 18:20:33 +0530148enum {
149 POWER_SUPPLY_QC_CTM_DISABLE = BIT(0),
150 POWER_SUPPLY_QC_THERMAL_BALANCE_DISABLE = BIT(1),
151 POWER_SUPPLY_QC_INOV_THERMAL_DISABLE = BIT(2),
152};
153
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400154enum power_supply_property {
155 /* Properties of type `int' */
156 POWER_SUPPLY_PROP_STATUS = 0,
Andres Salomonee8076e2009-07-02 09:45:18 -0400157 POWER_SUPPLY_PROP_CHARGE_TYPE,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400158 POWER_SUPPLY_PROP_HEALTH,
159 POWER_SUPPLY_PROP_PRESENT,
160 POWER_SUPPLY_PROP_ONLINE,
Ramakrishna Pallalab1b56872012-08-23 06:50:21 +0530161 POWER_SUPPLY_PROP_AUTHENTIC,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400162 POWER_SUPPLY_PROP_TECHNOLOGY,
Alexey Starikovskiyc955fe82009-10-15 14:31:30 +0400163 POWER_SUPPLY_PROP_CYCLE_COUNT,
Dmitry Baryshkovc7cc9302008-01-07 04:12:41 +0300164 POWER_SUPPLY_PROP_VOLTAGE_MAX,
165 POWER_SUPPLY_PROP_VOLTAGE_MIN,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400166 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
167 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
168 POWER_SUPPLY_PROP_VOLTAGE_NOW,
169 POWER_SUPPLY_PROP_VOLTAGE_AVG,
Ramakrishna Pallalaa2ebfe22012-04-10 16:21:20 +0530170 POWER_SUPPLY_PROP_VOLTAGE_OCV,
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530171 POWER_SUPPLY_PROP_VOLTAGE_BOOT,
Heikki Krogerusfe3f6d02010-10-04 10:51:38 +0300172 POWER_SUPPLY_PROP_CURRENT_MAX,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400173 POWER_SUPPLY_PROP_CURRENT_NOW,
174 POWER_SUPPLY_PROP_CURRENT_AVG,
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530175 POWER_SUPPLY_PROP_CURRENT_BOOT,
Alexey Starikovskiy7faa1442009-03-27 22:23:52 -0400176 POWER_SUPPLY_PROP_POWER_NOW,
177 POWER_SUPPLY_PROP_POWER_AVG,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400178 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
179 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
180 POWER_SUPPLY_PROP_CHARGE_FULL,
181 POWER_SUPPLY_PROP_CHARGE_EMPTY,
182 POWER_SUPPLY_PROP_CHARGE_NOW,
183 POWER_SUPPLY_PROP_CHARGE_AVG,
Andres Salomon8e552c32008-05-12 21:46:29 -0400184 POWER_SUPPLY_PROP_CHARGE_COUNTER,
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530185 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530186 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530187 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530188 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
Ramakrishna Pallalaea2ce922012-10-09 22:25:29 +0530189 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
190 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
Jenny TC6bb1d272014-07-08 11:34:18 +0530191 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400192 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
193 POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
194 POWER_SUPPLY_PROP_ENERGY_FULL,
195 POWER_SUPPLY_PROP_ENERGY_EMPTY,
196 POWER_SUPPLY_PROP_ENERGY_NOW,
197 POWER_SUPPLY_PROP_ENERGY_AVG,
198 POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
Ramakrishna Pallalae908c412012-07-05 16:59:12 +0530199 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */
200 POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */
Andres Salomonb294a292009-06-30 02:13:01 -0400201 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400202 POWER_SUPPLY_PROP_TEMP,
Jenny TC6bb1d272014-07-08 11:34:18 +0530203 POWER_SUPPLY_PROP_TEMP_MAX,
204 POWER_SUPPLY_PROP_TEMP_MIN,
Ramakrishna Pallalae908c412012-07-05 16:59:12 +0530205 POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
206 POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400207 POWER_SUPPLY_PROP_TEMP_AMBIENT,
Ramakrishna Pallalae908c412012-07-05 16:59:12 +0530208 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
209 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400210 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
211 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
212 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
213 POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
Anton Vorontsov5f487cd2010-05-18 21:49:51 +0200214 POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
Adam Thomsoncf450042018-04-23 15:10:59 +0100215 POWER_SUPPLY_PROP_USB_TYPE,
Jeremy Fitzhardinge25a0bc22011-12-07 11:24:20 -0800216 POWER_SUPPLY_PROP_SCOPE,
Liam Breck413de342017-06-07 11:37:52 -0700217 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
Jenny TC6bb1d272014-07-08 11:34:18 +0530218 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530219 POWER_SUPPLY_PROP_CALIBRATE,
Todd Poynor314f5bb2012-07-03 15:41:20 -0700220 /* Local extensions */
221 POWER_SUPPLY_PROP_USB_HC,
Todd Poynorcd934f02012-07-13 13:30:04 -0700222 POWER_SUPPLY_PROP_USB_OTG,
Todd Poynor10152c22012-07-18 16:28:50 -0700223 POWER_SUPPLY_PROP_CHARGE_ENABLED,
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -0700224 POWER_SUPPLY_PROP_SET_SHIP_MODE,
225 POWER_SUPPLY_PROP_REAL_TYPE,
226 POWER_SUPPLY_PROP_CHARGE_NOW_RAW,
227 POWER_SUPPLY_PROP_CHARGE_NOW_ERROR,
228 POWER_SUPPLY_PROP_CAPACITY_RAW,
229 POWER_SUPPLY_PROP_BATTERY_CHARGING_ENABLED,
230 POWER_SUPPLY_PROP_CHARGING_ENABLED,
231 POWER_SUPPLY_PROP_STEP_CHARGING_ENABLED,
232 POWER_SUPPLY_PROP_STEP_CHARGING_STEP,
233 POWER_SUPPLY_PROP_PIN_ENABLED,
234 POWER_SUPPLY_PROP_INPUT_SUSPEND,
235 POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION,
236 POWER_SUPPLY_PROP_INPUT_CURRENT_MAX,
237 POWER_SUPPLY_PROP_INPUT_CURRENT_TRIM,
238 POWER_SUPPLY_PROP_INPUT_CURRENT_SETTLED,
239 POWER_SUPPLY_PROP_INPUT_VOLTAGE_SETTLED,
240 POWER_SUPPLY_PROP_VCHG_LOOP_DBC_BYPASS,
241 POWER_SUPPLY_PROP_CHARGE_COUNTER_SHADOW,
242 POWER_SUPPLY_PROP_HI_POWER,
243 POWER_SUPPLY_PROP_LOW_POWER,
244 POWER_SUPPLY_PROP_COOL_TEMP,
245 POWER_SUPPLY_PROP_WARM_TEMP,
246 POWER_SUPPLY_PROP_COLD_TEMP,
247 POWER_SUPPLY_PROP_HOT_TEMP,
248 POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL,
249 POWER_SUPPLY_PROP_RESISTANCE,
250 POWER_SUPPLY_PROP_RESISTANCE_CAPACITIVE,
251 POWER_SUPPLY_PROP_RESISTANCE_ID, /* in Ohms */
252 POWER_SUPPLY_PROP_RESISTANCE_NOW,
253 POWER_SUPPLY_PROP_FLASH_CURRENT_MAX,
254 POWER_SUPPLY_PROP_UPDATE_NOW,
255 POWER_SUPPLY_PROP_ESR_COUNT,
256 POWER_SUPPLY_PROP_BUCK_FREQ,
257 POWER_SUPPLY_PROP_BOOST_CURRENT,
258 POWER_SUPPLY_PROP_SAFETY_TIMER_ENABLE,
259 POWER_SUPPLY_PROP_CHARGE_DONE,
260 POWER_SUPPLY_PROP_FLASH_ACTIVE,
261 POWER_SUPPLY_PROP_FLASH_TRIGGER,
262 POWER_SUPPLY_PROP_FORCE_TLIM,
263 POWER_SUPPLY_PROP_DP_DM,
264 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMITED,
265 POWER_SUPPLY_PROP_INPUT_CURRENT_NOW,
266 POWER_SUPPLY_PROP_CHARGE_QNOVO_ENABLE,
267 POWER_SUPPLY_PROP_CURRENT_QNOVO,
268 POWER_SUPPLY_PROP_VOLTAGE_QNOVO,
269 POWER_SUPPLY_PROP_RERUN_AICL,
270 POWER_SUPPLY_PROP_CYCLE_COUNT_ID,
271 POWER_SUPPLY_PROP_SAFETY_TIMER_EXPIRED,
272 POWER_SUPPLY_PROP_RESTRICTED_CHARGING,
273 POWER_SUPPLY_PROP_CURRENT_CAPABILITY,
274 POWER_SUPPLY_PROP_TYPEC_MODE,
275 POWER_SUPPLY_PROP_TYPEC_CC_ORIENTATION, /* 0: N/C, 1: CC1, 2: CC2 */
276 POWER_SUPPLY_PROP_TYPEC_POWER_ROLE,
277 POWER_SUPPLY_PROP_TYPEC_SRC_RP,
278 POWER_SUPPLY_PROP_PD_ALLOWED,
279 POWER_SUPPLY_PROP_PD_ACTIVE,
280 POWER_SUPPLY_PROP_PD_IN_HARD_RESET,
281 POWER_SUPPLY_PROP_PD_CURRENT_MAX,
282 POWER_SUPPLY_PROP_PD_USB_SUSPEND_SUPPORTED,
283 POWER_SUPPLY_PROP_CHARGER_TEMP,
284 POWER_SUPPLY_PROP_CHARGER_TEMP_MAX,
285 POWER_SUPPLY_PROP_PARALLEL_DISABLE,
286 POWER_SUPPLY_PROP_PE_START,
287 POWER_SUPPLY_PROP_SOC_REPORTING_READY,
288 POWER_SUPPLY_PROP_DEBUG_BATTERY,
289 POWER_SUPPLY_PROP_FCC_DELTA,
290 POWER_SUPPLY_PROP_ICL_REDUCTION,
291 POWER_SUPPLY_PROP_PARALLEL_MODE,
292 POWER_SUPPLY_PROP_DIE_HEALTH,
293 POWER_SUPPLY_PROP_CONNECTOR_HEALTH,
294 POWER_SUPPLY_PROP_CTM_CURRENT_MAX,
295 POWER_SUPPLY_PROP_HW_CURRENT_MAX,
296 POWER_SUPPLY_PROP_PR_SWAP,
297 POWER_SUPPLY_PROP_CC_STEP,
298 POWER_SUPPLY_PROP_CC_STEP_SEL,
299 POWER_SUPPLY_PROP_SW_JEITA_ENABLED,
300 POWER_SUPPLY_PROP_PD_VOLTAGE_MAX,
301 POWER_SUPPLY_PROP_PD_VOLTAGE_MIN,
302 POWER_SUPPLY_PROP_SDP_CURRENT_MAX,
303 POWER_SUPPLY_PROP_CONNECTOR_TYPE,
304 POWER_SUPPLY_PROP_PARALLEL_BATFET_MODE,
305 POWER_SUPPLY_PROP_PARALLEL_FCC_MAX,
306 POWER_SUPPLY_PROP_MIN_ICL,
307 POWER_SUPPLY_PROP_MOISTURE_DETECTED,
308 POWER_SUPPLY_PROP_BATT_PROFILE_VERSION,
309 POWER_SUPPLY_PROP_BATT_FULL_CURRENT,
310 POWER_SUPPLY_PROP_RECHARGE_SOC,
311 POWER_SUPPLY_PROP_HVDCP_OPTI_ALLOWED,
312 POWER_SUPPLY_PROP_SMB_EN_MODE,
313 POWER_SUPPLY_PROP_SMB_EN_REASON,
314 POWER_SUPPLY_PROP_ESR_ACTUAL,
315 POWER_SUPPLY_PROP_ESR_NOMINAL,
316 POWER_SUPPLY_PROP_SOH,
317 POWER_SUPPLY_PROP_CLEAR_SOH,
318 POWER_SUPPLY_PROP_FORCE_RECHARGE,
319 POWER_SUPPLY_PROP_FCC_STEPPER_ENABLE,
320 POWER_SUPPLY_PROP_TOGGLE_STAT,
321 POWER_SUPPLY_PROP_MAIN_FCC_MAX,
Anirudh Ghayal37f8e3d2018-11-29 16:27:27 +0530322 POWER_SUPPLY_PROP_FG_RESET,
Ashay Jaiswal18f6e9d2018-06-13 18:20:33 +0530323 POWER_SUPPLY_PROP_QC_OPTI_DISABLE,
Umang Agrawal5e3a9572018-11-16 17:03:43 +0530324 POWER_SUPPLY_PROP_CC_SOC,
Subbaraman Narayanamurthy0fe2e0a2018-12-18 20:16:06 -0800325 POWER_SUPPLY_PROP_BATT_AGE_LEVEL,
Sahil Chandnae9ab4ef2019-01-17 16:43:13 +0530326 POWER_SUPPLY_PROP_SCALE_MODE_EN,
Umang Agrawalcf749f22018-10-09 11:30:45 +0530327 /* Charge pump properties */
328 POWER_SUPPLY_PROP_CP_STATUS1,
329 POWER_SUPPLY_PROP_CP_STATUS2,
330 POWER_SUPPLY_PROP_CP_ENABLE,
331 POWER_SUPPLY_PROP_CP_SWITCHER_EN,
332 POWER_SUPPLY_PROP_CP_DIE_TEMP,
333 POWER_SUPPLY_PROP_CP_ISNS,
334 POWER_SUPPLY_PROP_CP_TOGGLE_SWITCHER,
335 POWER_SUPPLY_PROP_CP_IRQ_STATUS,
336 POWER_SUPPLY_PROP_CP_ILIM,
Todd Poynor6a427732013-12-12 15:59:09 -0800337 /* Local extensions of type int64_t */
338 POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400339 /* Properties of type `const char *' */
340 POWER_SUPPLY_PROP_MODEL_NAME,
341 POWER_SUPPLY_PROP_MANUFACTURER,
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -0700342 POWER_SUPPLY_PROP_BATTERY_TYPE,
343 POWER_SUPPLY_PROP_CYCLE_COUNTS,
Subbaraman Narayanamurthyee0f7c412019-02-14 20:17:18 -0800344 /*
345 * Add local extensions for properties with string values between
346 * MODEL_NAME and SERIAL_NUMBER. Don't add below SERIAL_NUMBER.
347 */
348 POWER_SUPPLY_PROP_SERIAL_NUMBER,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400349};
350
351enum power_supply_type {
Kim, Milo9b887222011-11-30 23:08:33 -0800352 POWER_SUPPLY_TYPE_UNKNOWN = 0,
353 POWER_SUPPLY_TYPE_BATTERY,
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400354 POWER_SUPPLY_TYPE_UPS,
355 POWER_SUPPLY_TYPE_MAINS,
Benson Leung71399aa2017-05-08 15:02:48 -0700356 POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */
357 POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */
358 POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */
359 POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */
360 POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */
361 POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */
362 POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */
363 POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -0700364 POWER_SUPPLY_TYPE_USB_HVDCP, /* High Voltage DCP */
365 POWER_SUPPLY_TYPE_USB_HVDCP_3, /* Efficient High Voltage DCP */
366 POWER_SUPPLY_TYPE_WIRELESS, /* Accessory Charger Adapters */
367 POWER_SUPPLY_TYPE_USB_FLOAT, /* Floating charger */
368 POWER_SUPPLY_TYPE_BMS, /* Battery Monitor System */
369 POWER_SUPPLY_TYPE_PARALLEL, /* Parallel Path */
370 POWER_SUPPLY_TYPE_MAIN, /* Main Path */
371 POWER_SUPPLY_TYPE_WIPOWER, /* Wipower */
372 POWER_SUPPLY_TYPE_UFP, /* Type-C UFP */
373 POWER_SUPPLY_TYPE_DFP, /* Type-C DFP */
Umang Agrawalcf749f22018-10-09 11:30:45 +0530374 POWER_SUPPLY_TYPE_CHARGE_PUMP, /* Charge Pump */
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400375};
376
Adam Thomsoncf450042018-04-23 15:10:59 +0100377enum power_supply_usb_type {
378 POWER_SUPPLY_USB_TYPE_UNKNOWN = 0,
379 POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */
380 POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */
381 POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */
382 POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */
383 POWER_SUPPLY_USB_TYPE_C, /* Type C Port */
384 POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */
385 POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */
386 POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */
387 POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */
388};
389
Guru Das Srinagesh9bec9862018-10-10 17:15:06 -0700390/* Indicates USB Type-C CC connection status */
391enum power_supply_typec_mode {
392 POWER_SUPPLY_TYPEC_NONE,
393
394 /* Acting as source */
395 POWER_SUPPLY_TYPEC_SINK, /* Rd only */
396 POWER_SUPPLY_TYPEC_SINK_POWERED_CABLE, /* Rd/Ra */
397 POWER_SUPPLY_TYPEC_SINK_DEBUG_ACCESSORY,/* Rd/Rd */
398 POWER_SUPPLY_TYPEC_SINK_AUDIO_ADAPTER, /* Ra/Ra */
399 POWER_SUPPLY_TYPEC_POWERED_CABLE_ONLY, /* Ra only */
400
401 /* Acting as sink */
402 POWER_SUPPLY_TYPEC_SOURCE_DEFAULT, /* Rp default */
403 POWER_SUPPLY_TYPEC_SOURCE_MEDIUM, /* Rp 1.5A */
404 POWER_SUPPLY_TYPEC_SOURCE_HIGH, /* Rp 3A */
405 POWER_SUPPLY_TYPEC_NON_COMPLIANT,
406};
407
408enum power_supply_typec_src_rp {
409 POWER_SUPPLY_TYPEC_SRC_RP_STD,
410 POWER_SUPPLY_TYPEC_SRC_RP_1P5A,
411 POWER_SUPPLY_TYPEC_SRC_RP_3A
412};
413
414enum power_supply_typec_power_role {
415 POWER_SUPPLY_TYPEC_PR_NONE, /* CC lines in high-Z */
416 POWER_SUPPLY_TYPEC_PR_DUAL,
417 POWER_SUPPLY_TYPEC_PR_SINK,
418 POWER_SUPPLY_TYPEC_PR_SOURCE,
419};
420
Pali Rohárd36240d2013-11-19 11:18:03 +0100421enum power_supply_notifier_events {
422 PSY_EVENT_PROP_CHANGED,
423};
424
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400425union power_supply_propval {
426 int intval;
427 const char *strval;
Todd Poynor6a427732013-12-12 15:59:09 -0800428 int64_t int64val;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400429};
430
Anton Vorontsovb50df952013-06-28 18:17:22 -0700431struct device_node;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100432struct power_supply;
Anton Vorontsovb50df952013-06-28 18:17:22 -0700433
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100434/* Run-time specific power supply configuration */
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100435struct power_supply_config {
436 struct device_node *of_node;
Adam Thomsonece711b2018-05-22 16:16:23 +0100437 struct fwnode_handle *fwnode;
438
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100439 /* Driver private data */
440 void *drv_data;
441
442 char **supplied_to;
443 size_t num_supplicants;
444};
445
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100446/* Description of power supply */
447struct power_supply_desc {
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400448 const char *name;
449 enum power_supply_type type;
Adam Thomsoncf450042018-04-23 15:10:59 +0100450 enum power_supply_usb_type *usb_types;
451 size_t num_usb_types;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400452 enum power_supply_property *properties;
453 size_t num_properties;
454
Krzysztof Kozlowskibc154052015-03-12 08:44:03 +0100455 /*
456 * Functions for drivers implementing power supply class.
457 * These shouldn't be called directly by other drivers for accessing
458 * this power supply. Instead use power_supply_*() functions (for
459 * example power_supply_get_property()).
460 */
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400461 int (*get_property)(struct power_supply *psy,
462 enum power_supply_property psp,
463 union power_supply_propval *val);
Daniel Mack0011d2d2010-05-18 21:49:52 +0200464 int (*set_property)(struct power_supply *psy,
465 enum power_supply_property psp,
466 const union power_supply_propval *val);
Krzysztof Kozlowski5c6e3a92015-06-08 10:09:48 +0900467 /*
468 * property_is_writeable() will be called during registration
469 * of power supply. If this happens during device probe then it must
470 * not access internal data of device (because probe did not end).
471 */
Daniel Mack0011d2d2010-05-18 21:49:52 +0200472 int (*property_is_writeable)(struct power_supply *psy,
473 enum power_supply_property psp);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400474 void (*external_power_changed)(struct power_supply *psy);
Daniel Macke5f5ccb2009-07-23 20:35:53 +0200475 void (*set_charged)(struct power_supply *psy);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400476
Krzysztof Kozlowskia69d82b2014-10-07 17:47:36 +0200477 /*
478 * Set if thermal zone should not be created for this power supply.
479 * For example for virtual supplies forwarding calls to actual
480 * sensors or other supplies.
481 */
482 bool no_thermal;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400483 /* For APM emulation, think legacy userspace. */
484 int use_for_apm;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100485};
486
487struct power_supply {
488 const struct power_supply_desc *desc;
489
490 char **supplied_to;
491 size_t num_supplicants;
492
493 char **supplied_from;
494 size_t num_supplies;
495 struct device_node *of_node;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400496
Krzysztof Kozlowskie44ea362015-03-12 08:44:01 +0100497 /* Driver private data */
498 void *drv_data;
499
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400500 /* private */
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100501 struct device dev;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400502 struct work_struct changed_work;
Krzysztof Kozlowski7f1a57f2015-05-19 16:13:02 +0900503 struct delayed_work deferred_register_work;
Zoran Markovic948dcf92013-08-02 13:38:02 -0700504 spinlock_t changed_lock;
505 bool changed;
Rhyland Kleine3805382016-06-22 11:45:52 -0400506 bool initialized;
Benjamin Tissoires3ffa6582018-06-25 09:51:48 +0200507 bool removing;
Krzysztof Kozlowskibc154052015-03-12 08:44:03 +0100508 atomic_t use_cnt;
Jenny TC3be330b2012-05-09 20:36:47 +0530509#ifdef CONFIG_THERMAL
510 struct thermal_zone_device *tzd;
Ramakrishna Pallala952aeeb32012-10-09 22:25:59 +0530511 struct thermal_cooling_device *tcd;
Jenny TC3be330b2012-05-09 20:36:47 +0530512#endif
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400513
514#ifdef CONFIG_LEDS_TRIGGERS
515 struct led_trigger *charging_full_trig;
516 char *charging_full_trig_name;
517 struct led_trigger *charging_trig;
518 char *charging_trig_name;
519 struct led_trigger *full_trig;
520 char *full_trig_name;
521 struct led_trigger *online_trig;
522 char *online_trig_name;
Vasily Khoruzhick6501f722011-01-07 18:28:17 +0200523 struct led_trigger *charging_blink_full_solid_trig;
524 char *charging_blink_full_solid_trig_name;
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400525#endif
526};
527
528/*
529 * This is recommended structure to specify static power supply parameters.
530 * Generic one, parametrizable for different power supplies. Power supply
531 * class itself does not use it, but that's what implementing most platform
532 * drivers, should try reuse for consistency.
533 */
534
535struct power_supply_info {
536 const char *name;
537 int technology;
538 int voltage_max_design;
539 int voltage_min_design;
540 int charge_full_design;
541 int charge_empty_design;
542 int energy_full_design;
543 int energy_empty_design;
544 int use_for_apm;
545};
546
Liam Breckc08b1f42017-06-07 11:37:51 -0700547/*
548 * This is the recommended struct to manage static battery parameters,
549 * populated by power_supply_get_battery_info(). Most platform drivers should
550 * use these for consistency.
551 * Its field names must correspond to elements in enum power_supply_property.
552 * The default field value is -EINVAL.
553 * Power supply class itself doesn't use this.
554 */
555
556struct power_supply_battery_info {
557 int energy_full_design_uwh; /* microWatt-hours */
558 int charge_full_design_uah; /* microAmp-hours */
559 int voltage_min_design_uv; /* microVolts */
560 int precharge_current_ua; /* microAmps */
561 int charge_term_current_ua; /* microAmps */
562 int constant_charge_current_max_ua; /* microAmps */
563 int constant_charge_voltage_max_uv; /* microVolts */
564};
565
Pali Rohárd36240d2013-11-19 11:18:03 +0100566extern struct atomic_notifier_head power_supply_notifier;
567extern int power_supply_reg_notifier(struct notifier_block *nb);
568extern void power_supply_unreg_notifier(struct notifier_block *nb);
Michał Mirosław9f3b7952013-02-01 20:40:17 +0100569extern struct power_supply *power_supply_get_by_name(const char *name);
Krzysztof Kozlowski1a352462015-03-12 08:44:12 +0100570extern void power_supply_put(struct power_supply *psy);
Sebastian Reichelabce9772013-11-24 17:49:29 +0100571#ifdef CONFIG_OF
572extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
573 const char *property);
Hans de Goedefe27e1d2015-06-09 23:37:56 +0200574extern struct power_supply *devm_power_supply_get_by_phandle(
575 struct device *dev, const char *property);
Sebastian Reichelabce9772013-11-24 17:49:29 +0100576#else /* !CONFIG_OF */
577static inline struct power_supply *
578power_supply_get_by_phandle(struct device_node *np, const char *property)
579{ return NULL; }
Hans de Goedefe27e1d2015-06-09 23:37:56 +0200580static inline struct power_supply *
581devm_power_supply_get_by_phandle(struct device *dev, const char *property)
582{ return NULL; }
Sebastian Reichelabce9772013-11-24 17:49:29 +0100583#endif /* CONFIG_OF */
Liam Breckc08b1f42017-06-07 11:37:51 -0700584
585extern int power_supply_get_battery_info(struct power_supply *psy,
586 struct power_supply_battery_info *info);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400587extern void power_supply_changed(struct power_supply *psy);
588extern int power_supply_am_i_supplied(struct power_supply *psy);
Hans de Goedec3142dd2017-08-15 22:04:56 +0200589extern int power_supply_set_input_current_limit_from_supplier(
590 struct power_supply *psy);
Daniel Macke5f5ccb2009-07-23 20:35:53 +0200591extern int power_supply_set_battery_charged(struct power_supply *psy);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400592
Anton Vorontsov0d4ed4e2012-05-04 21:06:19 -0700593#ifdef CONFIG_POWER_SUPPLY
Matthew Garrett942ed162008-08-26 21:09:59 +0100594extern int power_supply_is_system_supplied(void);
595#else
596static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
597#endif
598
Krzysztof Kozlowskibc154052015-03-12 08:44:03 +0100599extern int power_supply_get_property(struct power_supply *psy,
600 enum power_supply_property psp,
601 union power_supply_propval *val);
602extern int power_supply_set_property(struct power_supply *psy,
603 enum power_supply_property psp,
604 const union power_supply_propval *val);
605extern int power_supply_property_is_writeable(struct power_supply *psy,
606 enum power_supply_property psp);
607extern void power_supply_external_power_changed(struct power_supply *psy);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100608
609extern struct power_supply *__must_check
610power_supply_register(struct device *parent,
611 const struct power_supply_desc *desc,
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100612 const struct power_supply_config *cfg);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100613extern struct power_supply *__must_check
614power_supply_register_no_ws(struct device *parent,
615 const struct power_supply_desc *desc,
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100616 const struct power_supply_config *cfg);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100617extern struct power_supply *__must_check
618devm_power_supply_register(struct device *parent,
619 const struct power_supply_desc *desc,
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100620 const struct power_supply_config *cfg);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100621extern struct power_supply *__must_check
622devm_power_supply_register_no_ws(struct device *parent,
623 const struct power_supply_desc *desc,
Krzysztof Kozlowski2dc92152015-03-12 08:44:02 +0100624 const struct power_supply_config *cfg);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400625extern void power_supply_unregister(struct power_supply *psy);
Jeremy Fitzhardinge83516652011-12-07 09:15:45 -0800626extern int power_supply_powers(struct power_supply *psy, struct device *dev);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400627
Ognjen Galic285995d2018-02-07 15:58:27 +0100628#define to_power_supply(device) container_of(device, struct power_supply, dev)
629
Krzysztof Kozlowskie44ea362015-03-12 08:44:01 +0100630extern void *power_supply_get_drvdata(struct power_supply *psy);
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400631/* For APM emulation, think legacy userspace. */
632extern struct class *power_supply_class;
633
Rhyland Klein51d07562011-01-25 11:10:06 -0800634static inline bool power_supply_is_amp_property(enum power_supply_property psp)
635{
636 switch (psp) {
637 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
638 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
639 case POWER_SUPPLY_PROP_CHARGE_FULL:
640 case POWER_SUPPLY_PROP_CHARGE_EMPTY:
641 case POWER_SUPPLY_PROP_CHARGE_NOW:
642 case POWER_SUPPLY_PROP_CHARGE_AVG:
643 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
Liam Breck413de342017-06-07 11:37:52 -0700644 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
645 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530646 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530647 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
Rhyland Klein51d07562011-01-25 11:10:06 -0800648 case POWER_SUPPLY_PROP_CURRENT_MAX:
649 case POWER_SUPPLY_PROP_CURRENT_NOW:
650 case POWER_SUPPLY_PROP_CURRENT_AVG:
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530651 case POWER_SUPPLY_PROP_CURRENT_BOOT:
Rhyland Klein51d07562011-01-25 11:10:06 -0800652 return 1;
653 default:
654 break;
655 }
656
657 return 0;
658}
659
660static inline bool power_supply_is_watt_property(enum power_supply_property psp)
661{
662 switch (psp) {
663 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
664 case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
665 case POWER_SUPPLY_PROP_ENERGY_FULL:
666 case POWER_SUPPLY_PROP_ENERGY_EMPTY:
667 case POWER_SUPPLY_PROP_ENERGY_NOW:
668 case POWER_SUPPLY_PROP_ENERGY_AVG:
669 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
670 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
671 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
672 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
673 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
674 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
Ramakrishna Pallalaa2ebfe22012-04-10 16:21:20 +0530675 case POWER_SUPPLY_PROP_VOLTAGE_OCV:
Ramakrishna Pallalaa8adcc902014-08-27 23:44:08 +0530676 case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
Ramakrishna Pallala3824c472012-05-06 18:16:44 +0530677 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
Ramakrishna Pallala2815b782012-07-30 12:49:21 +0530678 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
Rhyland Klein35c9d262011-02-28 16:55:31 -0800679 case POWER_SUPPLY_PROP_POWER_NOW:
Rhyland Klein51d07562011-01-25 11:10:06 -0800680 return 1;
681 default:
682 break;
683 }
684
685 return 0;
686}
687
Anton Vorontsov4a11b592007-05-04 00:27:45 +0400688#endif /* __LINUX_POWER_SUPPLY_H__ */