Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 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 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 16 | #include <linux/device.h> |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 17 | #include <linux/workqueue.h> |
| 18 | #include <linux/leds.h> |
Zoran Markovic | 948dcf9 | 2013-08-02 13:38:02 -0700 | [diff] [blame] | 19 | #include <linux/spinlock.h> |
Pali Rohár | d36240d | 2013-11-19 11:18:03 +0100 | [diff] [blame] | 20 | #include <linux/notifier.h> |
Todd Poynor | 6a42773 | 2013-12-12 15:59:09 -0800 | [diff] [blame] | 21 | #include <linux/types.h> |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 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 | |
| 36 | enum { |
| 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 | |
| 44 | enum { |
Andres Salomon | ee8076e | 2009-07-02 09:45:18 -0400 | [diff] [blame] | 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, |
Guru Das Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 49 | POWER_SUPPLY_CHARGE_TYPE_TAPER, |
Andres Salomon | ee8076e | 2009-07-02 09:45:18 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | enum { |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 53 | 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 Brown | 7e386e6 | 2008-11-30 22:43:21 +0100 | [diff] [blame] | 59 | POWER_SUPPLY_HEALTH_COLD, |
Ramakrishna Pallala | a05be99 | 2012-11-30 13:57:46 +0530 | [diff] [blame] | 60 | POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, |
| 61 | POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE, |
Guru Das Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 62 | POWER_SUPPLY_HEALTH_WARM, |
| 63 | POWER_SUPPLY_HEALTH_COOL, |
| 64 | POWER_SUPPLY_HEALTH_HOT, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | enum { |
| 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 Baryshkov | c7cc930 | 2008-01-07 04:12:41 +0300 | [diff] [blame] | 74 | POWER_SUPPLY_TECHNOLOGY_LiMn, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 75 | }; |
| 76 | |
Andres Salomon | b294a29 | 2009-06-30 02:13:01 -0400 | [diff] [blame] | 77 | enum { |
| 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 Fitzhardinge | 25a0bc2 | 2011-12-07 11:24:20 -0800 | [diff] [blame] | 86 | enum { |
| 87 | POWER_SUPPLY_SCOPE_UNKNOWN = 0, |
| 88 | POWER_SUPPLY_SCOPE_SYSTEM, |
| 89 | POWER_SUPPLY_SCOPE_DEVICE, |
| 90 | }; |
| 91 | |
Guru Das Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 92 | enum { |
| 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 | |
| 111 | enum { |
| 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 | |
| 118 | enum { |
| 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 | |
| 125 | enum { |
| 126 | POWER_SUPPLY_CP_NONE = 0, |
| 127 | POWER_SUPPLY_CP_HVDCP3, |
| 128 | POWER_SUPPLY_CP_PPS, |
| 129 | POWER_SUPPLY_CP_WIRELESS, |
| 130 | }; |
| 131 | |
| 132 | enum { |
| 133 | POWER_SUPPLY_CONNECTOR_TYPEC, |
| 134 | POWER_SUPPLY_CONNECTOR_MICRO_USB, |
| 135 | }; |
| 136 | |
| 137 | enum { |
| 138 | POWER_SUPPLY_PL_STACKED_BATFET, |
| 139 | POWER_SUPPLY_PL_NON_STACKED_BATFET, |
| 140 | }; |
| 141 | |
| 142 | enum { |
| 143 | POWER_SUPPLY_PD_INACTIVE = 0, |
| 144 | POWER_SUPPLY_PD_ACTIVE, |
| 145 | POWER_SUPPLY_PD_PPS_ACTIVE, |
| 146 | }; |
| 147 | |
Ashay Jaiswal | 18f6e9d | 2018-06-13 18:20:33 +0530 | [diff] [blame] | 148 | enum { |
| 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 Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 154 | enum power_supply_property { |
| 155 | /* Properties of type `int' */ |
| 156 | POWER_SUPPLY_PROP_STATUS = 0, |
Andres Salomon | ee8076e | 2009-07-02 09:45:18 -0400 | [diff] [blame] | 157 | POWER_SUPPLY_PROP_CHARGE_TYPE, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 158 | POWER_SUPPLY_PROP_HEALTH, |
| 159 | POWER_SUPPLY_PROP_PRESENT, |
| 160 | POWER_SUPPLY_PROP_ONLINE, |
Ramakrishna Pallala | b1b5687 | 2012-08-23 06:50:21 +0530 | [diff] [blame] | 161 | POWER_SUPPLY_PROP_AUTHENTIC, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 162 | POWER_SUPPLY_PROP_TECHNOLOGY, |
Alexey Starikovskiy | c955fe8 | 2009-10-15 14:31:30 +0400 | [diff] [blame] | 163 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
Dmitry Baryshkov | c7cc930 | 2008-01-07 04:12:41 +0300 | [diff] [blame] | 164 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
| 165 | POWER_SUPPLY_PROP_VOLTAGE_MIN, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 166 | 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 Pallala | a2ebfe2 | 2012-04-10 16:21:20 +0530 | [diff] [blame] | 170 | POWER_SUPPLY_PROP_VOLTAGE_OCV, |
Ramakrishna Pallala | a8adcc90 | 2014-08-27 23:44:08 +0530 | [diff] [blame] | 171 | POWER_SUPPLY_PROP_VOLTAGE_BOOT, |
Heikki Krogerus | fe3f6d0 | 2010-10-04 10:51:38 +0300 | [diff] [blame] | 172 | POWER_SUPPLY_PROP_CURRENT_MAX, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 173 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 174 | POWER_SUPPLY_PROP_CURRENT_AVG, |
Ramakrishna Pallala | a8adcc90 | 2014-08-27 23:44:08 +0530 | [diff] [blame] | 175 | POWER_SUPPLY_PROP_CURRENT_BOOT, |
Alexey Starikovskiy | 7faa144 | 2009-03-27 22:23:52 -0400 | [diff] [blame] | 176 | POWER_SUPPLY_PROP_POWER_NOW, |
| 177 | POWER_SUPPLY_PROP_POWER_AVG, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 178 | 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 Salomon | 8e552c3 | 2008-05-12 21:46:29 -0400 | [diff] [blame] | 184 | POWER_SUPPLY_PROP_CHARGE_COUNTER, |
Ramakrishna Pallala | 3824c47 | 2012-05-06 18:16:44 +0530 | [diff] [blame] | 185 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, |
Ramakrishna Pallala | 2815b78 | 2012-07-30 12:49:21 +0530 | [diff] [blame] | 186 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, |
Ramakrishna Pallala | 3824c47 | 2012-05-06 18:16:44 +0530 | [diff] [blame] | 187 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, |
Ramakrishna Pallala | 2815b78 | 2012-07-30 12:49:21 +0530 | [diff] [blame] | 188 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, |
Ramakrishna Pallala | ea2ce92 | 2012-10-09 22:25:29 +0530 | [diff] [blame] | 189 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, |
| 190 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, |
Jenny TC | 6bb1d27 | 2014-07-08 11:34:18 +0530 | [diff] [blame] | 191 | POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 192 | 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 Pallala | e908c41 | 2012-07-05 16:59:12 +0530 | [diff] [blame] | 199 | POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ |
| 200 | POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ |
Andres Salomon | b294a29 | 2009-06-30 02:13:01 -0400 | [diff] [blame] | 201 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 202 | POWER_SUPPLY_PROP_TEMP, |
Jenny TC | 6bb1d27 | 2014-07-08 11:34:18 +0530 | [diff] [blame] | 203 | POWER_SUPPLY_PROP_TEMP_MAX, |
| 204 | POWER_SUPPLY_PROP_TEMP_MIN, |
Ramakrishna Pallala | e908c41 | 2012-07-05 16:59:12 +0530 | [diff] [blame] | 205 | POWER_SUPPLY_PROP_TEMP_ALERT_MIN, |
| 206 | POWER_SUPPLY_PROP_TEMP_ALERT_MAX, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 207 | POWER_SUPPLY_PROP_TEMP_AMBIENT, |
Ramakrishna Pallala | e908c41 | 2012-07-05 16:59:12 +0530 | [diff] [blame] | 208 | POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, |
| 209 | POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 210 | 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 Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 214 | POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ |
Adam Thomson | cf45004 | 2018-04-23 15:10:59 +0100 | [diff] [blame] | 215 | POWER_SUPPLY_PROP_USB_TYPE, |
Jeremy Fitzhardinge | 25a0bc2 | 2011-12-07 11:24:20 -0800 | [diff] [blame] | 216 | POWER_SUPPLY_PROP_SCOPE, |
Liam Breck | 413de34 | 2017-06-07 11:37:52 -0700 | [diff] [blame] | 217 | POWER_SUPPLY_PROP_PRECHARGE_CURRENT, |
Jenny TC | 6bb1d27 | 2014-07-08 11:34:18 +0530 | [diff] [blame] | 218 | POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, |
Ramakrishna Pallala | a8adcc90 | 2014-08-27 23:44:08 +0530 | [diff] [blame] | 219 | POWER_SUPPLY_PROP_CALIBRATE, |
Todd Poynor | 314f5bb | 2012-07-03 15:41:20 -0700 | [diff] [blame] | 220 | /* Local extensions */ |
| 221 | POWER_SUPPLY_PROP_USB_HC, |
Todd Poynor | cd934f0 | 2012-07-13 13:30:04 -0700 | [diff] [blame] | 222 | POWER_SUPPLY_PROP_USB_OTG, |
Todd Poynor | 10152c2 | 2012-07-18 16:28:50 -0700 | [diff] [blame] | 223 | POWER_SUPPLY_PROP_CHARGE_ENABLED, |
Guru Das Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 224 | 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 Ghayal | 37f8e3d | 2018-11-29 16:27:27 +0530 | [diff] [blame] | 322 | POWER_SUPPLY_PROP_FG_RESET, |
Ashay Jaiswal | 18f6e9d | 2018-06-13 18:20:33 +0530 | [diff] [blame] | 323 | POWER_SUPPLY_PROP_QC_OPTI_DISABLE, |
Umang Agrawal | 5e3a957 | 2018-11-16 17:03:43 +0530 | [diff] [blame] | 324 | POWER_SUPPLY_PROP_CC_SOC, |
Subbaraman Narayanamurthy | 0fe2e0a | 2018-12-18 20:16:06 -0800 | [diff] [blame] | 325 | POWER_SUPPLY_PROP_BATT_AGE_LEVEL, |
Sahil Chandna | e9ab4ef | 2019-01-17 16:43:13 +0530 | [diff] [blame] | 326 | POWER_SUPPLY_PROP_SCALE_MODE_EN, |
Umang Agrawal | cf749f2 | 2018-10-09 11:30:45 +0530 | [diff] [blame] | 327 | /* 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 Poynor | 6a42773 | 2013-12-12 15:59:09 -0800 | [diff] [blame] | 337 | /* Local extensions of type int64_t */ |
| 338 | POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 339 | /* Properties of type `const char *' */ |
| 340 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 341 | POWER_SUPPLY_PROP_MANUFACTURER, |
Guru Das Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 342 | POWER_SUPPLY_PROP_BATTERY_TYPE, |
| 343 | POWER_SUPPLY_PROP_CYCLE_COUNTS, |
Subbaraman Narayanamurthy | ee0f7c41 | 2019-02-14 20:17:18 -0800 | [diff] [blame] | 344 | /* |
| 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 Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | enum power_supply_type { |
Kim, Milo | 9b88722 | 2011-11-30 23:08:33 -0800 | [diff] [blame] | 352 | POWER_SUPPLY_TYPE_UNKNOWN = 0, |
| 353 | POWER_SUPPLY_TYPE_BATTERY, |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 354 | POWER_SUPPLY_TYPE_UPS, |
| 355 | POWER_SUPPLY_TYPE_MAINS, |
Benson Leung | 71399aa | 2017-05-08 15:02:48 -0700 | [diff] [blame] | 356 | 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 Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 364 | 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 Agrawal | cf749f2 | 2018-10-09 11:30:45 +0530 | [diff] [blame] | 374 | POWER_SUPPLY_TYPE_CHARGE_PUMP, /* Charge Pump */ |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 375 | }; |
| 376 | |
Adam Thomson | cf45004 | 2018-04-23 15:10:59 +0100 | [diff] [blame] | 377 | enum 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 Srinagesh | 9bec986 | 2018-10-10 17:15:06 -0700 | [diff] [blame] | 390 | /* Indicates USB Type-C CC connection status */ |
| 391 | enum 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 | |
| 408 | enum 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 | |
| 414 | enum 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ár | d36240d | 2013-11-19 11:18:03 +0100 | [diff] [blame] | 421 | enum power_supply_notifier_events { |
| 422 | PSY_EVENT_PROP_CHANGED, |
| 423 | }; |
| 424 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 425 | union power_supply_propval { |
| 426 | int intval; |
| 427 | const char *strval; |
Todd Poynor | 6a42773 | 2013-12-12 15:59:09 -0800 | [diff] [blame] | 428 | int64_t int64val; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 429 | }; |
| 430 | |
Anton Vorontsov | b50df95 | 2013-06-28 18:17:22 -0700 | [diff] [blame] | 431 | struct device_node; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 432 | struct power_supply; |
Anton Vorontsov | b50df95 | 2013-06-28 18:17:22 -0700 | [diff] [blame] | 433 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 434 | /* Run-time specific power supply configuration */ |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 435 | struct power_supply_config { |
| 436 | struct device_node *of_node; |
Adam Thomson | ece711b | 2018-05-22 16:16:23 +0100 | [diff] [blame] | 437 | struct fwnode_handle *fwnode; |
| 438 | |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 439 | /* Driver private data */ |
| 440 | void *drv_data; |
| 441 | |
| 442 | char **supplied_to; |
| 443 | size_t num_supplicants; |
| 444 | }; |
| 445 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 446 | /* Description of power supply */ |
| 447 | struct power_supply_desc { |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 448 | const char *name; |
| 449 | enum power_supply_type type; |
Adam Thomson | cf45004 | 2018-04-23 15:10:59 +0100 | [diff] [blame] | 450 | enum power_supply_usb_type *usb_types; |
| 451 | size_t num_usb_types; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 452 | enum power_supply_property *properties; |
| 453 | size_t num_properties; |
| 454 | |
Krzysztof Kozlowski | bc15405 | 2015-03-12 08:44:03 +0100 | [diff] [blame] | 455 | /* |
| 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 Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 461 | int (*get_property)(struct power_supply *psy, |
| 462 | enum power_supply_property psp, |
| 463 | union power_supply_propval *val); |
Daniel Mack | 0011d2d | 2010-05-18 21:49:52 +0200 | [diff] [blame] | 464 | int (*set_property)(struct power_supply *psy, |
| 465 | enum power_supply_property psp, |
| 466 | const union power_supply_propval *val); |
Krzysztof Kozlowski | 5c6e3a9 | 2015-06-08 10:09:48 +0900 | [diff] [blame] | 467 | /* |
| 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 Mack | 0011d2d | 2010-05-18 21:49:52 +0200 | [diff] [blame] | 472 | int (*property_is_writeable)(struct power_supply *psy, |
| 473 | enum power_supply_property psp); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 474 | void (*external_power_changed)(struct power_supply *psy); |
Daniel Mack | e5f5ccb | 2009-07-23 20:35:53 +0200 | [diff] [blame] | 475 | void (*set_charged)(struct power_supply *psy); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 476 | |
Krzysztof Kozlowski | a69d82b | 2014-10-07 17:47:36 +0200 | [diff] [blame] | 477 | /* |
| 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 Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 483 | /* For APM emulation, think legacy userspace. */ |
| 484 | int use_for_apm; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | struct 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 Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 496 | |
Krzysztof Kozlowski | e44ea36 | 2015-03-12 08:44:01 +0100 | [diff] [blame] | 497 | /* Driver private data */ |
| 498 | void *drv_data; |
| 499 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 500 | /* private */ |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 501 | struct device dev; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 502 | struct work_struct changed_work; |
Krzysztof Kozlowski | 7f1a57f | 2015-05-19 16:13:02 +0900 | [diff] [blame] | 503 | struct delayed_work deferred_register_work; |
Zoran Markovic | 948dcf9 | 2013-08-02 13:38:02 -0700 | [diff] [blame] | 504 | spinlock_t changed_lock; |
| 505 | bool changed; |
Rhyland Klein | e380538 | 2016-06-22 11:45:52 -0400 | [diff] [blame] | 506 | bool initialized; |
Benjamin Tissoires | 3ffa658 | 2018-06-25 09:51:48 +0200 | [diff] [blame] | 507 | bool removing; |
Krzysztof Kozlowski | bc15405 | 2015-03-12 08:44:03 +0100 | [diff] [blame] | 508 | atomic_t use_cnt; |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 509 | #ifdef CONFIG_THERMAL |
| 510 | struct thermal_zone_device *tzd; |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 511 | struct thermal_cooling_device *tcd; |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 512 | #endif |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 513 | |
| 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 Khoruzhick | 6501f72 | 2011-01-07 18:28:17 +0200 | [diff] [blame] | 523 | struct led_trigger *charging_blink_full_solid_trig; |
| 524 | char *charging_blink_full_solid_trig_name; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 525 | #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 | |
| 535 | struct 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 Breck | c08b1f4 | 2017-06-07 11:37:51 -0700 | [diff] [blame] | 547 | /* |
| 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 | |
| 556 | struct 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ár | d36240d | 2013-11-19 11:18:03 +0100 | [diff] [blame] | 566 | extern struct atomic_notifier_head power_supply_notifier; |
| 567 | extern int power_supply_reg_notifier(struct notifier_block *nb); |
| 568 | extern void power_supply_unreg_notifier(struct notifier_block *nb); |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 569 | extern struct power_supply *power_supply_get_by_name(const char *name); |
Krzysztof Kozlowski | 1a35246 | 2015-03-12 08:44:12 +0100 | [diff] [blame] | 570 | extern void power_supply_put(struct power_supply *psy); |
Sebastian Reichel | abce977 | 2013-11-24 17:49:29 +0100 | [diff] [blame] | 571 | #ifdef CONFIG_OF |
| 572 | extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, |
| 573 | const char *property); |
Hans de Goede | fe27e1d | 2015-06-09 23:37:56 +0200 | [diff] [blame] | 574 | extern struct power_supply *devm_power_supply_get_by_phandle( |
| 575 | struct device *dev, const char *property); |
Sebastian Reichel | abce977 | 2013-11-24 17:49:29 +0100 | [diff] [blame] | 576 | #else /* !CONFIG_OF */ |
| 577 | static inline struct power_supply * |
| 578 | power_supply_get_by_phandle(struct device_node *np, const char *property) |
| 579 | { return NULL; } |
Hans de Goede | fe27e1d | 2015-06-09 23:37:56 +0200 | [diff] [blame] | 580 | static inline struct power_supply * |
| 581 | devm_power_supply_get_by_phandle(struct device *dev, const char *property) |
| 582 | { return NULL; } |
Sebastian Reichel | abce977 | 2013-11-24 17:49:29 +0100 | [diff] [blame] | 583 | #endif /* CONFIG_OF */ |
Liam Breck | c08b1f4 | 2017-06-07 11:37:51 -0700 | [diff] [blame] | 584 | |
| 585 | extern int power_supply_get_battery_info(struct power_supply *psy, |
| 586 | struct power_supply_battery_info *info); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 587 | extern void power_supply_changed(struct power_supply *psy); |
| 588 | extern int power_supply_am_i_supplied(struct power_supply *psy); |
Hans de Goede | c3142dd | 2017-08-15 22:04:56 +0200 | [diff] [blame] | 589 | extern int power_supply_set_input_current_limit_from_supplier( |
| 590 | struct power_supply *psy); |
Daniel Mack | e5f5ccb | 2009-07-23 20:35:53 +0200 | [diff] [blame] | 591 | extern int power_supply_set_battery_charged(struct power_supply *psy); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 592 | |
Anton Vorontsov | 0d4ed4e | 2012-05-04 21:06:19 -0700 | [diff] [blame] | 593 | #ifdef CONFIG_POWER_SUPPLY |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 594 | extern int power_supply_is_system_supplied(void); |
| 595 | #else |
| 596 | static inline int power_supply_is_system_supplied(void) { return -ENOSYS; } |
| 597 | #endif |
| 598 | |
Krzysztof Kozlowski | bc15405 | 2015-03-12 08:44:03 +0100 | [diff] [blame] | 599 | extern int power_supply_get_property(struct power_supply *psy, |
| 600 | enum power_supply_property psp, |
| 601 | union power_supply_propval *val); |
| 602 | extern int power_supply_set_property(struct power_supply *psy, |
| 603 | enum power_supply_property psp, |
| 604 | const union power_supply_propval *val); |
| 605 | extern int power_supply_property_is_writeable(struct power_supply *psy, |
| 606 | enum power_supply_property psp); |
| 607 | extern void power_supply_external_power_changed(struct power_supply *psy); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 608 | |
| 609 | extern struct power_supply *__must_check |
| 610 | power_supply_register(struct device *parent, |
| 611 | const struct power_supply_desc *desc, |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 612 | const struct power_supply_config *cfg); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 613 | extern struct power_supply *__must_check |
| 614 | power_supply_register_no_ws(struct device *parent, |
| 615 | const struct power_supply_desc *desc, |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 616 | const struct power_supply_config *cfg); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 617 | extern struct power_supply *__must_check |
| 618 | devm_power_supply_register(struct device *parent, |
| 619 | const struct power_supply_desc *desc, |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 620 | const struct power_supply_config *cfg); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 621 | extern struct power_supply *__must_check |
| 622 | devm_power_supply_register_no_ws(struct device *parent, |
| 623 | const struct power_supply_desc *desc, |
Krzysztof Kozlowski | 2dc9215 | 2015-03-12 08:44:02 +0100 | [diff] [blame] | 624 | const struct power_supply_config *cfg); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 625 | extern void power_supply_unregister(struct power_supply *psy); |
Jeremy Fitzhardinge | 8351665 | 2011-12-07 09:15:45 -0800 | [diff] [blame] | 626 | extern int power_supply_powers(struct power_supply *psy, struct device *dev); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 627 | |
Ognjen Galic | 285995d | 2018-02-07 15:58:27 +0100 | [diff] [blame] | 628 | #define to_power_supply(device) container_of(device, struct power_supply, dev) |
| 629 | |
Krzysztof Kozlowski | e44ea36 | 2015-03-12 08:44:01 +0100 | [diff] [blame] | 630 | extern void *power_supply_get_drvdata(struct power_supply *psy); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 631 | /* For APM emulation, think legacy userspace. */ |
| 632 | extern struct class *power_supply_class; |
| 633 | |
Rhyland Klein | 51d0756 | 2011-01-25 11:10:06 -0800 | [diff] [blame] | 634 | static 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 Breck | 413de34 | 2017-06-07 11:37:52 -0700 | [diff] [blame] | 644 | case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: |
| 645 | case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: |
Ramakrishna Pallala | 3824c47 | 2012-05-06 18:16:44 +0530 | [diff] [blame] | 646 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: |
Ramakrishna Pallala | 2815b78 | 2012-07-30 12:49:21 +0530 | [diff] [blame] | 647 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: |
Rhyland Klein | 51d0756 | 2011-01-25 11:10:06 -0800 | [diff] [blame] | 648 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 649 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
| 650 | case POWER_SUPPLY_PROP_CURRENT_AVG: |
Ramakrishna Pallala | a8adcc90 | 2014-08-27 23:44:08 +0530 | [diff] [blame] | 651 | case POWER_SUPPLY_PROP_CURRENT_BOOT: |
Rhyland Klein | 51d0756 | 2011-01-25 11:10:06 -0800 | [diff] [blame] | 652 | return 1; |
| 653 | default: |
| 654 | break; |
| 655 | } |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static 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 Pallala | a2ebfe2 | 2012-04-10 16:21:20 +0530 | [diff] [blame] | 675 | case POWER_SUPPLY_PROP_VOLTAGE_OCV: |
Ramakrishna Pallala | a8adcc90 | 2014-08-27 23:44:08 +0530 | [diff] [blame] | 676 | case POWER_SUPPLY_PROP_VOLTAGE_BOOT: |
Ramakrishna Pallala | 3824c47 | 2012-05-06 18:16:44 +0530 | [diff] [blame] | 677 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: |
Ramakrishna Pallala | 2815b78 | 2012-07-30 12:49:21 +0530 | [diff] [blame] | 678 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: |
Rhyland Klein | 35c9d26 | 2011-02-28 16:55:31 -0800 | [diff] [blame] | 679 | case POWER_SUPPLY_PROP_POWER_NOW: |
Rhyland Klein | 51d0756 | 2011-01-25 11:10:06 -0800 | [diff] [blame] | 680 | return 1; |
| 681 | default: |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 688 | #endif /* __LINUX_POWER_SUPPLY_H__ */ |