1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Universal power supply monitor class 4 * 5 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru> 6 * Copyright © 2004 Szabolcs Gyurko 7 * Copyright © 2003 Ian Molton <spyro@f2s.com> 8 * 9 * Modified: 2004, Oct Szabolcs Gyurko 10 */ 11 12 #ifndef __LINUX_POWER_SUPPLY_H__ 13 #define __LINUX_POWER_SUPPLY_H__ 14 15 #include <linux/device.h> 16 #include <linux/workqueue.h> 17 #include <linux/leds.h> 18 #include <linux/rwsem.h> 19 #include <linux/list.h> 20 #include <linux/spinlock.h> 21 #include <linux/notifier.h> 22 23 /* 24 * All voltages, currents, charges, energies, time and temperatures in uV, 25 * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise 26 * stated. It's driver's job to convert its raw values to units in which 27 * this class operates. 28 */ 29 30 /* 31 * For systems where the charger determines the maximum battery capacity 32 * the min and max fields should be used to present these values to user 33 * space. Unused/unknown fields will not appear in sysfs. 34 */ 35 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 /* What algorithm is the charger using? */ 45 enum power_supply_charge_type { 46 POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0, 47 POWER_SUPPLY_CHARGE_TYPE_NONE, 48 POWER_SUPPLY_CHARGE_TYPE_TRICKLE, /* slow speed */ 49 POWER_SUPPLY_CHARGE_TYPE_FAST, /* fast speed */ 50 POWER_SUPPLY_CHARGE_TYPE_STANDARD, /* normal speed */ 51 POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE, /* dynamically adjusted speed */ 52 POWER_SUPPLY_CHARGE_TYPE_CUSTOM, /* use CHARGE_CONTROL_* props */ 53 POWER_SUPPLY_CHARGE_TYPE_LONGLIFE, /* slow speed, longer life */ 54 POWER_SUPPLY_CHARGE_TYPE_BYPASS, /* bypassing the charger */ 55 }; 56 57 enum { 58 POWER_SUPPLY_HEALTH_UNKNOWN = 0, 59 POWER_SUPPLY_HEALTH_GOOD, 60 POWER_SUPPLY_HEALTH_OVERHEAT, 61 POWER_SUPPLY_HEALTH_DEAD, 62 POWER_SUPPLY_HEALTH_OVERVOLTAGE, 63 POWER_SUPPLY_HEALTH_UNDERVOLTAGE, 64 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE, 65 POWER_SUPPLY_HEALTH_COLD, 66 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, 67 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE, 68 POWER_SUPPLY_HEALTH_OVERCURRENT, 69 POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED, 70 POWER_SUPPLY_HEALTH_WARM, 71 POWER_SUPPLY_HEALTH_COOL, 72 POWER_SUPPLY_HEALTH_HOT, 73 POWER_SUPPLY_HEALTH_NO_BATTERY, 74 POWER_SUPPLY_HEALTH_BLOWN_FUSE, 75 POWER_SUPPLY_HEALTH_CELL_IMBALANCE, 76 }; 77 78 enum { 79 POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0, 80 POWER_SUPPLY_TECHNOLOGY_NiMH, 81 POWER_SUPPLY_TECHNOLOGY_LION, 82 POWER_SUPPLY_TECHNOLOGY_LIPO, 83 POWER_SUPPLY_TECHNOLOGY_LiFe, 84 POWER_SUPPLY_TECHNOLOGY_NiCd, 85 POWER_SUPPLY_TECHNOLOGY_LiMn, 86 POWER_SUPPLY_TECHNOLOGY_PbAc, 87 POWER_SUPPLY_TECHNOLOGY_NiZn, 88 POWER_SUPPLY_TECHNOLOGY_RAM, 89 POWER_SUPPLY_TECHNOLOGY_ZnAr, 90 }; 91 92 enum { 93 POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0, 94 POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, 95 POWER_SUPPLY_CAPACITY_LEVEL_LOW, 96 POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, 97 POWER_SUPPLY_CAPACITY_LEVEL_HIGH, 98 POWER_SUPPLY_CAPACITY_LEVEL_FULL, 99 }; 100 101 enum { 102 POWER_SUPPLY_SCOPE_UNKNOWN = 0, 103 POWER_SUPPLY_SCOPE_SYSTEM, 104 POWER_SUPPLY_SCOPE_DEVICE, 105 }; 106 107 enum { 108 POWER_SUPPLY_LOAD_SWITCH_UNKNOWN = 0, 109 POWER_SUPPLY_LOAD_SWITCH_ON, 110 POWER_SUPPLY_LOAD_SWITCH_OFF, 111 POWER_SUPPLY_LOAD_SWITCH_STANDBY, 112 POWER_SUPPLY_LOAD_SWITCH_SHIP, 113 }; 114 115 enum power_supply_property { 116 /* Properties of type `int' */ 117 POWER_SUPPLY_PROP_STATUS = 0, 118 POWER_SUPPLY_PROP_CHARGE_TYPE, 119 POWER_SUPPLY_PROP_CHARGE_TYPES, 120 POWER_SUPPLY_PROP_HEALTH, 121 POWER_SUPPLY_PROP_PRESENT, 122 POWER_SUPPLY_PROP_ONLINE, 123 POWER_SUPPLY_PROP_AUTHENTIC, 124 POWER_SUPPLY_PROP_TECHNOLOGY, 125 POWER_SUPPLY_PROP_CYCLE_COUNT, 126 POWER_SUPPLY_PROP_VOLTAGE_MAX, 127 POWER_SUPPLY_PROP_VOLTAGE_MIN, 128 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 129 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 130 POWER_SUPPLY_PROP_VOLTAGE_NOW, 131 POWER_SUPPLY_PROP_VOLTAGE_AVG, 132 POWER_SUPPLY_PROP_VOLTAGE_OCV, 133 POWER_SUPPLY_PROP_VOLTAGE_BOOT, 134 POWER_SUPPLY_PROP_CURRENT_MAX, 135 POWER_SUPPLY_PROP_CURRENT_NOW, 136 POWER_SUPPLY_PROP_CURRENT_AVG, 137 POWER_SUPPLY_PROP_CURRENT_BOOT, 138 POWER_SUPPLY_PROP_POWER_NOW, 139 POWER_SUPPLY_PROP_POWER_AVG, 140 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 141 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, 142 POWER_SUPPLY_PROP_CHARGE_FULL, 143 POWER_SUPPLY_PROP_CHARGE_EMPTY, 144 POWER_SUPPLY_PROP_CHARGE_NOW, 145 POWER_SUPPLY_PROP_CHARGE_AVG, 146 POWER_SUPPLY_PROP_CHARGE_COUNTER, 147 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, 148 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, 149 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 150 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, 151 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, 152 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, 153 POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */ 154 POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */ 155 POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR, 156 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, 157 POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, 158 POWER_SUPPLY_PROP_INPUT_POWER_LIMIT, 159 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 160 POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, 161 POWER_SUPPLY_PROP_ENERGY_FULL, 162 POWER_SUPPLY_PROP_ENERGY_EMPTY, 163 POWER_SUPPLY_PROP_ENERGY_NOW, 164 POWER_SUPPLY_PROP_ENERGY_AVG, 165 POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ 166 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ 167 POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ 168 POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */ 169 POWER_SUPPLY_PROP_CAPACITY_LEVEL, 170 POWER_SUPPLY_PROP_TEMP, 171 POWER_SUPPLY_PROP_TEMP_MAX, 172 POWER_SUPPLY_PROP_TEMP_MIN, 173 POWER_SUPPLY_PROP_TEMP_ALERT_MIN, 174 POWER_SUPPLY_PROP_TEMP_ALERT_MAX, 175 POWER_SUPPLY_PROP_TEMP_AMBIENT, 176 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, 177 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, 178 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 179 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 180 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, 181 POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 182 POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ 183 POWER_SUPPLY_PROP_USB_TYPE, 184 POWER_SUPPLY_PROP_SCOPE, 185 POWER_SUPPLY_PROP_PRECHARGE_CURRENT, 186 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, 187 POWER_SUPPLY_PROP_CALIBRATE, 188 POWER_SUPPLY_PROP_MANUFACTURE_YEAR, 189 POWER_SUPPLY_PROP_MANUFACTURE_MONTH, 190 POWER_SUPPLY_PROP_MANUFACTURE_DAY, 191 POWER_SUPPLY_PROP_INTERNAL_RESISTANCE, 192 POWER_SUPPLY_PROP_STATE_OF_HEALTH, 193 POWER_SUPPLY_PROP_LOAD_SWITCH, 194 /* Properties of type `const char *' */ 195 POWER_SUPPLY_PROP_MODEL_NAME, 196 POWER_SUPPLY_PROP_MANUFACTURER, 197 POWER_SUPPLY_PROP_SERIAL_NUMBER, 198 }; 199 200 enum power_supply_type { 201 POWER_SUPPLY_TYPE_UNKNOWN = 0, 202 POWER_SUPPLY_TYPE_BATTERY, 203 POWER_SUPPLY_TYPE_UPS, 204 POWER_SUPPLY_TYPE_MAINS, 205 POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */ 206 POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */ 207 POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */ 208 POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ 209 POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */ 210 POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */ 211 POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */ 212 POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ 213 POWER_SUPPLY_TYPE_WIRELESS, /* Wireless */ 214 }; 215 216 enum power_supply_usb_type { 217 POWER_SUPPLY_USB_TYPE_UNKNOWN = 0, 218 POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */ 219 POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */ 220 POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */ 221 POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */ 222 POWER_SUPPLY_USB_TYPE_C, /* Type C Port */ 223 POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */ 224 POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */ 225 POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */ 226 /* PD Standard Power Range Adjustable Voltage Supply */ 227 POWER_SUPPLY_USB_TYPE_PD_SPR_AVS, 228 POWER_SUPPLY_USB_TYPE_PD_PPS_SPR_AVS, /* Supports both PD PPS + SPR AVS */ 229 POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ 230 }; 231 232 enum power_supply_charge_behaviour { 233 POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO = 0, 234 POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE, 235 POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE_AWAKE, 236 POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE, 237 }; 238 239 enum power_supply_notifier_events { 240 PSY_EVENT_PROP_CHANGED, 241 }; 242 243 union power_supply_propval { 244 int intval; 245 const char *strval; 246 }; 247 248 struct device_node; 249 struct power_supply; 250 251 /* Run-time specific power supply configuration */ 252 struct power_supply_config { 253 struct fwnode_handle *fwnode; 254 255 /* Driver private data */ 256 void *drv_data; 257 258 /* Device specific sysfs attributes */ 259 const struct attribute_group **attr_grp; 260 261 char **supplied_to; 262 size_t num_supplicants; 263 264 bool no_wakeup_source; 265 }; 266 267 /* Description of power supply */ 268 struct power_supply_desc { 269 const char *name; 270 enum power_supply_type type; 271 u32 charge_types; 272 u32 usb_types; 273 u32 load_switches; 274 const enum power_supply_property *properties; 275 size_t num_properties; 276 277 /* 278 * Functions for drivers implementing power supply class. 279 * These shouldn't be called directly by other drivers for accessing 280 * this power supply. Instead use power_supply_*() functions (for 281 * example power_supply_get_property()). 282 */ 283 int (*get_property)(struct power_supply *psy, 284 enum power_supply_property psp, 285 union power_supply_propval *val); 286 int (*set_property)(struct power_supply *psy, 287 enum power_supply_property psp, 288 const union power_supply_propval *val); 289 /* 290 * property_is_writeable() will be called during registration 291 * of power supply. If this happens during device probe then it must 292 * not access internal data of device (because probe did not end). 293 */ 294 int (*property_is_writeable)(struct power_supply *psy, 295 enum power_supply_property psp); 296 void (*external_power_changed)(struct power_supply *psy); 297 /* 298 * Optional registration-time initialization. This runs in sleepable 299 * process context after driver data and any battery info are available, 300 * but before the device is added. The callback must not publish changes or 301 * start asynchronous activity that can access the power supply before 302 * registration completes. Return 0 on success or a negative errno on 303 * failure. 304 */ 305 int (*init)(struct power_supply *psy); 306 307 /* For APM emulation, think legacy userspace. */ 308 int use_for_apm; 309 310 /* 311 * Set if thermal zone should not be created for this power supply. 312 * For example for virtual supplies forwarding calls to actual 313 * sensors or other supplies. 314 */ 315 bool no_thermal; 316 317 u8 charge_behaviours; 318 }; 319 320 struct power_supply_ext { 321 const char *const name; 322 u8 charge_behaviours; 323 u32 charge_types; 324 const enum power_supply_property *properties; 325 size_t num_properties; 326 327 int (*get_property)(struct power_supply *psy, 328 const struct power_supply_ext *ext, 329 void *data, 330 enum power_supply_property psp, 331 union power_supply_propval *val); 332 int (*set_property)(struct power_supply *psy, 333 const struct power_supply_ext *ext, 334 void *data, 335 enum power_supply_property psp, 336 const union power_supply_propval *val); 337 int (*property_is_writeable)(struct power_supply *psy, 338 const struct power_supply_ext *ext, 339 void *data, 340 enum power_supply_property psp); 341 }; 342 343 struct power_supply { 344 const struct power_supply_desc *desc; 345 346 char **supplied_to; 347 size_t num_supplicants; 348 349 char **supplied_from; 350 size_t num_supplies; 351 352 /* Driver private data */ 353 void *drv_data; 354 355 /* private */ 356 struct device dev; 357 struct work_struct changed_work; 358 struct delayed_work deferred_register_work; 359 spinlock_t changed_lock; 360 bool changed; 361 bool update_groups; 362 bool initialized; 363 bool removing; 364 atomic_t use_cnt; 365 struct power_supply_battery_info *battery_info; 366 /* 367 * Held for read while ->external_power_changed() runs, and for write by 368 * power_supply_unregister() when it publishes @removing, so that it 369 * waits for an in-flight callback to finish. Without this a driver's 370 * data, typically devm-allocated on its own device, can be freed while 371 * the callback is still using it. 372 * Must not be shared with extensions_sem: callbacks may read their own 373 * properties, which takes that one for read. 374 */ 375 struct rw_semaphore epc_sem; 376 struct rw_semaphore extensions_sem; /* protects "extensions" */ 377 struct list_head extensions; 378 #ifdef CONFIG_THERMAL 379 struct thermal_zone_device *tzd; 380 struct thermal_cooling_device *tcd; 381 #endif 382 383 #ifdef CONFIG_LEDS_TRIGGERS 384 struct led_trigger *charging_or_full_trig; 385 struct led_trigger *online_trig; 386 struct led_trigger *charging_trig; 387 struct led_trigger *full_trig; 388 struct led_trigger *charging_blink_full_solid_trig; 389 struct led_trigger *charging_orange_full_green_trig; 390 #endif 391 }; 392 393 #define dev_to_psy(__dev) container_of_const(__dev, struct power_supply, dev) 394 395 /* 396 * This is recommended structure to specify static power supply parameters. 397 * Generic one, parametrizable for different power supplies. Power supply 398 * class itself does not use it, but that's what implementing most platform 399 * drivers, should try reuse for consistency. 400 */ 401 402 struct power_supply_info { 403 const char *name; 404 int technology; 405 int voltage_max_design; 406 int voltage_min_design; 407 int charge_full_design; 408 int charge_empty_design; 409 int energy_full_design; 410 int energy_empty_design; 411 int use_for_apm; 412 }; 413 414 struct power_supply_battery_ocv_table { 415 int ocv; /* microVolts */ 416 int capacity; /* percent */ 417 }; 418 419 struct power_supply_resistance_temp_table { 420 int temp; /* celsius */ 421 int resistance; /* internal resistance percent */ 422 }; 423 424 struct power_supply_vbat_ri_table { 425 int vbat_uv; /* Battery voltage in microvolt */ 426 int ri_uohm; /* Internal resistance in microohm */ 427 }; 428 429 /** 430 * struct power_supply_maintenance_charge_table - setting for maintenace charging 431 * @charge_current_max_ua: maintenance charging current that is used to keep 432 * the charge of the battery full as current is consumed after full charging. 433 * The corresponding charge_voltage_max_uv is used as a safeguard: when we 434 * reach this voltage the maintenance charging current is turned off. It is 435 * turned back on if we fall below this voltage. 436 * @charge_voltage_max_uv: maintenance charging voltage that is usually a bit 437 * lower than the constant_charge_voltage_max_uv. We can apply this settings 438 * charge_current_max_ua until we get back up to this voltage. 439 * @charge_safety_timer_minutes: maintenance charging safety timer, with an 440 * expiry time in minutes. We will only use maintenance charging in this 441 * setting for a certain amount of time, then we will first move to the next 442 * maintenance charge current and voltage pair in respective array and wait 443 * for the next safety timer timeout, or, if we reached the last maintencance 444 * charging setting, disable charging until we reach 445 * charge_restart_voltage_uv and restart ordinary CC/CV charging from there. 446 * These timers should be chosen to align with the typical discharge curve 447 * for the battery. 448 * 449 * Ordinary CC/CV charging will stop charging when the charge current goes 450 * below charge_term_current_ua, and then restart it (if the device is still 451 * plugged into the charger) at charge_restart_voltage_uv. This happens in most 452 * consumer products because the power usage while connected to a charger is 453 * not zero, and devices are not manufactured to draw power directly from the 454 * charger: instead they will at all times dissipate the battery a little, like 455 * the power used in standby mode. This will over time give a charge graph 456 * such as this: 457 * 458 * Energy 459 * ^ ... ... ... ... ... ... ... 460 * | . . . . . . . . . . . . . 461 * | .. . .. . .. . .. . .. . .. . .. 462 * |. .. .. .. .. .. .. 463 * +-------------------------------------------------------------------> t 464 * 465 * Practically this means that the Li-ions are wandering back and forth in the 466 * battery and this causes degeneration of the battery anode and cathode. 467 * To prolong the life of the battery, maintenance charging is applied after 468 * reaching charge_term_current_ua to hold up the charge in the battery while 469 * consuming power, thus lowering the wear on the battery: 470 * 471 * Energy 472 * ^ ....................................... 473 * | . ...................... 474 * | .. 475 * |. 476 * +-------------------------------------------------------------------> t 477 * 478 * Maintenance charging uses the voltages from this table: a table of settings 479 * is traversed using a slightly lower current and voltage than what is used for 480 * CC/CV charging. The maintenance charging will for safety reasons not go on 481 * indefinately: we lower the current and voltage with successive maintenance 482 * settings, then disable charging completely after we reach the last one, 483 * and after that we do not restart charging until we reach 484 * charge_restart_voltage_uv (see struct power_supply_battery_info) and restart 485 * ordinary CC/CV charging from there. 486 * 487 * As an example, a Samsung EB425161LA Lithium-Ion battery is CC/CV charged 488 * at 900mA to 4340mV, then maintenance charged at 600mA and 4150mV for up to 489 * 60 hours, then maintenance charged at 600mA and 4100mV for up to 200 hours. 490 * After this the charge cycle is restarted waiting for 491 * charge_restart_voltage_uv. 492 * 493 * For most mobile electronics this type of maintenance charging is enough for 494 * the user to disconnect the device and make use of it before both maintenance 495 * charging cycles are complete, if the current and voltage has been chosen 496 * appropriately. These need to be determined from battery discharge curves 497 * and expected standby current. 498 * 499 * If the voltage anyway drops to charge_restart_voltage_uv during maintenance 500 * charging, ordinary CC/CV charging is restarted. This can happen if the 501 * device is e.g. actively used during charging, so more current is drawn than 502 * the expected stand-by current. Also overvoltage protection will be applied 503 * as usual. 504 */ 505 struct power_supply_maintenance_charge_table { 506 int charge_current_max_ua; 507 int charge_voltage_max_uv; 508 int charge_safety_timer_minutes; 509 }; 510 511 #define POWER_SUPPLY_OCV_TEMP_MAX 20 512 513 /** 514 * struct power_supply_battery_info - information about batteries 515 * @technology: from the POWER_SUPPLY_TECHNOLOGY_* enum 516 * @energy_full_design_uwh: energy content when fully charged in microwatt 517 * hours 518 * @charge_full_design_uah: charge content when fully charged in microampere 519 * hours 520 * @voltage_min_design_uv: minimum voltage across the poles when the battery 521 * is at minimum voltage level in microvolts. If the voltage drops below this 522 * level the battery will need precharging when using CC/CV charging. 523 * @voltage_max_design_uv: voltage across the poles when the battery is fully 524 * charged in microvolts. This is the "nominal voltage" i.e. the voltage 525 * printed on the label of the battery. 526 * @tricklecharge_current_ua: the tricklecharge current used when trickle 527 * charging the battery in microamperes. This is the charging phase when the 528 * battery is completely empty and we need to carefully trickle in some 529 * charge until we reach the precharging voltage. 530 * @precharge_current_ua: current to use in the precharge phase in microamperes, 531 * the precharge rate is limited by limiting the current to this value. 532 * @precharge_voltage_max_uv: the maximum voltage allowed when precharging in 533 * microvolts. When we pass this voltage we will nominally switch over to the 534 * CC (constant current) charging phase defined by constant_charge_current_ua 535 * and constant_charge_voltage_max_uv. 536 * @charge_term_current_ua: when the current in the CV (constant voltage) 537 * charging phase drops below this value in microamperes the charging will 538 * terminate completely and not restart until the voltage over the battery 539 * poles reach charge_restart_voltage_uv unless we use maintenance charging. 540 * @charge_restart_voltage_uv: when the battery has been fully charged by 541 * CC/CV charging and charging has been disabled, and the voltage subsequently 542 * drops below this value in microvolts, the charging will be restarted 543 * (typically using CV charging). 544 * @overvoltage_limit_uv: If the voltage exceeds the nominal voltage 545 * voltage_max_design_uv and we reach this voltage level, all charging must 546 * stop and emergency procedures take place, such as shutting down the system 547 * in some cases. 548 * @constant_charge_current_max_ua: current in microamperes to use in the CC 549 * (constant current) charging phase. The charging rate is limited 550 * by this current. This is the main charging phase and as the current is 551 * constant into the battery the voltage slowly ascends to 552 * constant_charge_voltage_max_uv. 553 * @constant_charge_voltage_max_uv: voltage in microvolts signifying the end of 554 * the CC (constant current) charging phase and the beginning of the CV 555 * (constant voltage) charging phase. 556 * @maintenance_charge: an array of maintenance charging settings to be used 557 * after the main CC/CV charging phase is complete. 558 * @maintenance_charge_size: the number of maintenance charging settings in 559 * maintenance_charge. 560 * @alert_low_temp_charge_current_ua: The charging current to use if the battery 561 * enters low alert temperature, i.e. if the internal temperature is between 562 * temp_alert_min and temp_min. No matter the charging phase, this 563 * and alert_high_temp_charge_voltage_uv will be applied. 564 * @alert_low_temp_charge_voltage_uv: Same as alert_low_temp_charge_current_ua, 565 * but for the charging voltage. 566 * @alert_high_temp_charge_current_ua: The charging current to use if the 567 * battery enters high alert temperature, i.e. if the internal temperature is 568 * between temp_alert_max and temp_max. No matter the charging phase, this 569 * and alert_high_temp_charge_voltage_uv will be applied, usually lowering 570 * the charging current as an evasive manouver. 571 * @alert_high_temp_charge_voltage_uv: Same as 572 * alert_high_temp_charge_current_ua, but for the charging voltage. 573 * @factory_internal_resistance_uohm: the internal resistance of the battery 574 * at fabrication time, expressed in microohms. This resistance will vary 575 * depending on the lifetime and charge of the battery, so this is just a 576 * nominal ballpark figure. This internal resistance is given for the state 577 * when the battery is discharging. 578 * @factory_internal_resistance_charging_uohm: the internal resistance of the 579 * battery at fabrication time while charging, expressed in microohms. 580 * The charging process will affect the internal resistance of the battery 581 * so this value provides a better resistance under these circumstances. 582 * This resistance will vary depending on the lifetime and charge of the 583 * battery, so this is just a nominal ballpark figure. 584 * @ocv_temp: array indicating the open circuit voltage (OCV) capacity 585 * temperature indices. This is an array of temperatures in degrees Celsius 586 * indicating which capacity table to use for a certain temperature, since 587 * the capacity for reasons of chemistry will be different at different 588 * temperatures. Determining capacity is a multivariate problem and the 589 * temperature is the first variable we determine. 590 * @temp_ambient_alert_min: the battery will go outside of operating conditions 591 * when the ambient temperature goes below this temperature in degrees 592 * Celsius. 593 * @temp_ambient_alert_max: the battery will go outside of operating conditions 594 * when the ambient temperature goes above this temperature in degrees 595 * Celsius. 596 * @temp_alert_min: the battery should issue an alert if the internal 597 * temperature goes below this temperature in degrees Celsius. 598 * @temp_alert_max: the battery should issue an alert if the internal 599 * temperature goes above this temperature in degrees Celsius. 600 * @temp_min: the battery will go outside of operating conditions when 601 * the internal temperature goes below this temperature in degrees Celsius. 602 * Normally this means the system should shut down. 603 * @temp_max: the battery will go outside of operating conditions when 604 * the internal temperature goes above this temperature in degrees Celsius. 605 * Normally this means the system should shut down. 606 * @ocv_table: for each entry in ocv_temp there is a corresponding entry in 607 * ocv_table and a size for each entry in ocv_table_size. These arrays 608 * determine the capacity in percent in relation to the voltage in microvolts 609 * at the indexed temperature. 610 * @ocv_table_size: for each entry in ocv_temp this array is giving the size of 611 * each entry in the array of capacity arrays in ocv_table. 612 * @resist_table: this is a table that correlates a battery temperature to the 613 * expected internal resistance at this temperature. The resistance is given 614 * as a percentage of factory_internal_resistance_uohm. Knowing the 615 * resistance of the battery is usually necessary for calculating the open 616 * circuit voltage (OCV) that is then used with the ocv_table to calculate 617 * the capacity of the battery. The resist_table must be ordered descending 618 * by temperature: highest temperature with lowest resistance first, lowest 619 * temperature with highest resistance last. 620 * @resist_table_size: the number of items in the resist_table. 621 * @vbat2ri_discharging: this is a table that correlates Battery voltage (VBAT) 622 * to internal resistance (Ri). The resistance is given in microohm for the 623 * corresponding voltage in microvolts. The internal resistance is used to 624 * determine the open circuit voltage so that we can determine the capacity 625 * of the battery. These voltages to resistance tables apply when the battery 626 * is discharging. The table must be ordered descending by voltage: highest 627 * voltage first. 628 * @vbat2ri_discharging_size: the number of items in the vbat2ri_discharging 629 * table. 630 * @vbat2ri_charging: same function as vbat2ri_discharging but for the state 631 * when the battery is charging. Being under charge changes the battery's 632 * internal resistance characteristics so a separate table is needed.* 633 * The table must be ordered descending by voltage: highest voltage first. 634 * @vbat2ri_charging_size: the number of items in the vbat2ri_charging 635 * table. 636 * @bti_resistance_ohm: The Battery Type Indicator (BIT) nominal resistance 637 * in ohms for this battery, if an identification resistor is mounted 638 * between a third battery terminal and ground. This scheme is used by a lot 639 * of mobile device batteries. 640 * @bti_resistance_tolerance: The tolerance in percent of the BTI resistance, 641 * for example 10 for +/- 10%, if the bti_resistance is set to 7000 and the 642 * tolerance is 10% we will detect a proper battery if the BTI resistance 643 * is between 6300 and 7700 Ohm. 644 * 645 * This is the recommended struct to manage static battery parameters, 646 * populated by power_supply_get_battery_info(). Most platform drivers should 647 * use these for consistency. 648 * 649 * Its field names must correspond to elements in enum power_supply_property. 650 * The default field value is -EINVAL or NULL for pointers. 651 * 652 * CC/CV CHARGING: 653 * 654 * The charging parameters here assume a CC/CV charging scheme. This method 655 * is most common with Lithium Ion batteries (other methods are possible) and 656 * looks as follows: 657 * 658 * ^ Battery voltage 659 * | --- overvoltage_limit_uv 660 * | 661 * | ................................................... 662 * | .. constant_charge_voltage_max_uv 663 * | .. 664 * | . 665 * | . 666 * | . 667 * | . 668 * | . 669 * | .. precharge_voltage_max_uv 670 * | .. 671 * |. (trickle charging) 672 * +------------------------------------------------------------------> time 673 * 674 * ^ Current into the battery 675 * | 676 * | ............. constant_charge_current_max_ua 677 * | . . 678 * | . . 679 * | . . 680 * | . . 681 * | . .. 682 * | . .... 683 * | . ..... 684 * | ... precharge_current_ua ....... charge_term_current_ua 685 * | . . 686 * | . . 687 * |.... tricklecharge_current_ua . 688 * | . 689 * +-----------------------------------------------------------------> time 690 * 691 * These diagrams are synchronized on time and the voltage and current 692 * follow each other. 693 * 694 * With CC/CV charging commence over time like this for an empty battery: 695 * 696 * 1. When the battery is completely empty it may need to be charged with 697 * an especially small current so that electrons just "trickle in", 698 * this is the tricklecharge_current_ua. 699 * 700 * 2. Next a small initial pre-charge current (precharge_current_ua) 701 * is applied if the voltage is below precharge_voltage_max_uv until we 702 * reach precharge_voltage_max_uv. CAUTION: in some texts this is referred 703 * to as "trickle charging" but the use in the Linux kernel is different 704 * see below! 705 * 706 * 3. Then the main charging current is applied, which is called the constant 707 * current (CC) phase. A current regulator is set up to allow 708 * constant_charge_current_max_ua of current to flow into the battery. 709 * The chemical reaction in the battery will make the voltage go up as 710 * charge goes into the battery. This current is applied until we reach 711 * the constant_charge_voltage_max_uv voltage. 712 * 713 * 4. At this voltage we switch over to the constant voltage (CV) phase. This 714 * means we allow current to go into the battery, but we keep the voltage 715 * fixed. This current will continue to charge the battery while keeping 716 * the voltage the same. A chemical reaction in the battery goes on 717 * storing energy without affecting the voltage. Over time the current 718 * will slowly drop and when we reach charge_term_current_ua we will 719 * end the constant voltage phase. 720 * 721 * After this the battery is fully charged, and if we do not support maintenance 722 * charging, the charging will not restart until power dissipation makes the 723 * voltage fall so that we reach charge_restart_voltage_uv and at this point 724 * we restart charging at the appropriate phase, usually this will be inside 725 * the CV phase. 726 * 727 * If we support maintenance charging the voltage is however kept high after 728 * the CV phase with a very low current. This is meant to let the same charge 729 * go in for usage while the charger is still connected, mainly for 730 * dissipation for the power consuming entity while connected to the 731 * charger. 732 * 733 * All charging MUST terminate if the overvoltage_limit_uv is ever reached. 734 * Overcharging Lithium Ion cells can be DANGEROUS and lead to fire or 735 * explosions. 736 * 737 * DETERMINING BATTERY CAPACITY: 738 * 739 * Several members of the struct deal with trying to determine the remaining 740 * capacity in the battery, usually as a percentage of charge. In practice 741 * many chargers uses a so-called fuel gauge or coloumb counter that measure 742 * how much charge goes into the battery and how much goes out (+/- leak 743 * consumption). This does not help if we do not know how much capacity the 744 * battery has to begin with, such as when it is first used or was taken out 745 * and charged in a separate charger. Therefore many capacity algorithms use 746 * the open circuit voltage with a look-up table to determine the rough 747 * capacity of the battery. The open circuit voltage can be conceptualized 748 * with an ideal voltage source (V) in series with an internal resistance (Ri) 749 * like this: 750 * 751 * +-------> IBAT >----------------+ 752 * | ^ | 753 * [ ] Ri | | 754 * | | VBAT | 755 * o <---------- | | 756 * +| ^ | [ ] Rload 757 * .---. | | | 758 * | V | | OCV | | 759 * '---' | | | 760 * | | | | 761 * GND +-------------------------------+ 762 * 763 * If we disconnect the load (here simplified as a fixed resistance Rload) 764 * and measure VBAT with a infinite impedance voltage meter we will get 765 * VBAT = OCV and this assumption is sometimes made even under load, assuming 766 * Rload is insignificant. However this will be of dubious quality because the 767 * load is rarely that small and Ri is strongly nonlinear depending on 768 * temperature and how much capacity is left in the battery due to the 769 * chemistry involved. 770 * 771 * In many practical applications we cannot just disconnect the battery from 772 * the load, so instead we often try to measure the instantaneous IBAT (the 773 * current out from the battery), estimate the Ri and thus calculate the 774 * voltage drop over Ri and compensate like this: 775 * 776 * OCV = VBAT - (IBAT * Ri) 777 * 778 * The tables vbat2ri_discharging and vbat2ri_charging are used to determine 779 * (by interpolation) the Ri from the VBAT under load. These curves are highly 780 * nonlinear and may need many datapoints but can be found in datasheets for 781 * some batteries. This gives the compensated open circuit voltage (OCV) for 782 * the battery even under load. Using this method will also compensate for 783 * temperature changes in the environment: this will also make the internal 784 * resistance change, and it will affect the VBAT under load, so correlating 785 * VBAT to Ri takes both remaining capacity and temperature into consideration. 786 * 787 * Alternatively a manufacturer can specify how the capacity of the battery 788 * is dependent on the battery temperature which is the main factor affecting 789 * Ri. As we know all checmical reactions are faster when it is warm and slower 790 * when it is cold. You can put in 1500mAh and only get 800mAh out before the 791 * voltage drops too low for example. This effect is also highly nonlinear and 792 * the purpose of the table resist_table: this will take a temperature and 793 * tell us how big percentage of Ri the specified temperature correlates to. 794 * Usually we have 100% of the factory_internal_resistance_uohm at 25 degrees 795 * Celsius. 796 * 797 * The power supply class itself doesn't use this struct as of now. 798 */ 799 800 struct power_supply_battery_info { 801 unsigned int technology; 802 int energy_full_design_uwh; 803 int charge_full_design_uah; 804 int voltage_min_design_uv; 805 int voltage_max_design_uv; 806 int tricklecharge_current_ua; 807 int precharge_current_ua; 808 int precharge_voltage_max_uv; 809 int charge_term_current_ua; 810 int charge_restart_voltage_uv; 811 int overvoltage_limit_uv; 812 int constant_charge_current_max_ua; 813 int constant_charge_voltage_max_uv; 814 const struct power_supply_maintenance_charge_table *maintenance_charge; 815 int maintenance_charge_size; 816 int alert_low_temp_charge_current_ua; 817 int alert_low_temp_charge_voltage_uv; 818 int alert_high_temp_charge_current_ua; 819 int alert_high_temp_charge_voltage_uv; 820 int factory_internal_resistance_uohm; 821 int factory_internal_resistance_charging_uohm; 822 int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX]; 823 int temp_ambient_alert_min; 824 int temp_ambient_alert_max; 825 int temp_alert_min; 826 int temp_alert_max; 827 int temp_min; 828 int temp_max; 829 const struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; 830 int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; 831 const struct power_supply_resistance_temp_table *resist_table; 832 int resist_table_size; 833 const struct power_supply_vbat_ri_table *vbat2ri_discharging; 834 int vbat2ri_discharging_size; 835 const struct power_supply_vbat_ri_table *vbat2ri_charging; 836 int vbat2ri_charging_size; 837 int bti_resistance_ohm; 838 int bti_resistance_tolerance; 839 }; 840 841 #if IS_ENABLED(CONFIG_POWER_SUPPLY) 842 extern int power_supply_reg_notifier(struct notifier_block *nb); 843 extern void power_supply_unreg_notifier(struct notifier_block *nb); 844 extern struct power_supply *power_supply_get_by_name(const char *name); 845 extern int __must_check power_supply_get_system_batteries(struct device *dev, 846 struct power_supply ***psys); 847 extern void power_supply_put_system_batteries(struct power_supply **psys, int count); 848 extern void power_supply_put(struct power_supply *psy); 849 #else 850 static inline int power_supply_reg_notifier(struct notifier_block *nb) 851 { return -EOPNOTSUPP; } 852 static inline void power_supply_unreg_notifier(struct notifier_block *nb) {} 853 static inline void power_supply_put(struct power_supply *psy) {} 854 static inline struct power_supply *power_supply_get_by_name(const char *name) 855 { return NULL; } 856 static inline int __must_check power_supply_get_system_batteries(struct device *dev, 857 struct power_supply ***psys) 858 { 859 if (psys) 860 *psys = NULL; 861 return 0; 862 } 863 864 static inline void power_supply_put_system_batteries(struct power_supply **psys, 865 int count) 866 { 867 } 868 #endif 869 extern struct power_supply *power_supply_get_by_reference(struct fwnode_handle *fwnode, 870 const char *property); 871 extern struct power_supply *devm_power_supply_get_by_reference( 872 struct device *dev, const char *property); 873 874 extern const enum power_supply_property power_supply_battery_info_properties[]; 875 extern const size_t power_supply_battery_info_properties_size; 876 extern int power_supply_get_battery_info(struct power_supply *psy, 877 struct power_supply_battery_info **info_out); 878 extern void power_supply_put_battery_info(struct power_supply *psy, 879 struct power_supply_battery_info *info); 880 extern bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info, 881 enum power_supply_property psp); 882 extern int power_supply_battery_info_get_prop(struct power_supply_battery_info *info, 883 enum power_supply_property psp, 884 union power_supply_propval *val); 885 extern int power_supply_ocv2cap_simple(const struct power_supply_battery_ocv_table *table, 886 int table_len, int ocv); 887 extern const struct power_supply_battery_ocv_table * 888 power_supply_find_ocv2cap_table(struct power_supply_battery_info *info, 889 int temp, int *table_len); 890 extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, 891 int ocv, int temp); 892 extern int 893 power_supply_temp2resist_simple(const struct power_supply_resistance_temp_table *table, 894 int table_len, int temp); 895 extern int power_supply_vbat2ri(struct power_supply_battery_info *info, 896 int vbat_uv, bool charging); 897 extern const struct power_supply_maintenance_charge_table * 898 power_supply_get_maintenance_charging_setting(struct power_supply_battery_info *info, int index); 899 extern bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info, 900 int resistance); 901 extern void power_supply_changed(struct power_supply *psy); 902 extern int power_supply_am_i_supplied(struct power_supply *psy); 903 int power_supply_get_property_from_supplier(struct power_supply *psy, 904 enum power_supply_property psp, 905 union power_supply_propval *val); 906 907 static inline bool 908 power_supply_supports_maintenance_charging(struct power_supply_battery_info *info) 909 { 910 const struct power_supply_maintenance_charge_table *mt; 911 912 mt = power_supply_get_maintenance_charging_setting(info, 0); 913 914 return (mt != NULL); 915 } 916 917 static inline bool 918 power_supply_supports_vbat2ri(struct power_supply_battery_info *info) 919 { 920 return ((info->vbat2ri_discharging != NULL) && 921 info->vbat2ri_discharging_size > 0); 922 } 923 924 static inline bool 925 power_supply_supports_temp2ri(struct power_supply_battery_info *info) 926 { 927 return ((info->resist_table != NULL) && 928 info->resist_table_size > 0); 929 } 930 931 #ifdef CONFIG_POWER_SUPPLY 932 extern int power_supply_is_system_supplied(void); 933 #else 934 static inline int power_supply_is_system_supplied(void) { return -ENOSYS; } 935 #endif 936 937 extern int power_supply_get_property(struct power_supply *psy, 938 enum power_supply_property psp, 939 union power_supply_propval *val); 940 int power_supply_get_property_direct(struct power_supply *psy, enum power_supply_property psp, 941 union power_supply_propval *val); 942 #if IS_ENABLED(CONFIG_POWER_SUPPLY) 943 extern int power_supply_set_property(struct power_supply *psy, 944 enum power_supply_property psp, 945 const union power_supply_propval *val); 946 int power_supply_set_property_direct(struct power_supply *psy, enum power_supply_property psp, 947 const union power_supply_propval *val); 948 #else 949 static inline int power_supply_set_property(struct power_supply *psy, 950 enum power_supply_property psp, 951 const union power_supply_propval *val) 952 { return 0; } 953 static inline int power_supply_set_property_direct(struct power_supply *psy, 954 enum power_supply_property psp, 955 const union power_supply_propval *val) 956 { return 0; } 957 #endif 958 extern void power_supply_external_power_changed(struct power_supply *psy); 959 960 extern struct power_supply *__must_check 961 power_supply_register(struct device *parent, 962 const struct power_supply_desc *desc, 963 const struct power_supply_config *cfg); 964 extern struct power_supply *__must_check 965 devm_power_supply_register(struct device *parent, 966 const struct power_supply_desc *desc, 967 const struct power_supply_config *cfg); 968 extern void power_supply_unregister(struct power_supply *psy); 969 extern int power_supply_powers(struct power_supply *psy, struct device *dev); 970 971 extern int __must_check 972 power_supply_register_extension(struct power_supply *psy, 973 const struct power_supply_ext *ext, 974 struct device *dev, 975 void *data); 976 extern void power_supply_unregister_extension(struct power_supply *psy, 977 const struct power_supply_ext *ext); 978 979 #define to_power_supply(device) container_of(device, struct power_supply, dev) 980 981 extern void *power_supply_get_drvdata(struct power_supply *psy); 982 extern int power_supply_for_each_psy(void *data, int (*fn)(struct power_supply *psy, void *data)); 983 984 static inline bool power_supply_is_amp_property(enum power_supply_property psp) 985 { 986 switch (psp) { 987 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 988 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: 989 case POWER_SUPPLY_PROP_CHARGE_FULL: 990 case POWER_SUPPLY_PROP_CHARGE_EMPTY: 991 case POWER_SUPPLY_PROP_CHARGE_NOW: 992 case POWER_SUPPLY_PROP_CHARGE_AVG: 993 case POWER_SUPPLY_PROP_CHARGE_COUNTER: 994 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: 995 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: 996 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: 997 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: 998 case POWER_SUPPLY_PROP_CURRENT_MAX: 999 case POWER_SUPPLY_PROP_CURRENT_NOW: 1000 case POWER_SUPPLY_PROP_CURRENT_AVG: 1001 case POWER_SUPPLY_PROP_CURRENT_BOOT: 1002 return true; 1003 default: 1004 break; 1005 } 1006 1007 return false; 1008 } 1009 1010 static inline bool power_supply_is_watt_property(enum power_supply_property psp) 1011 { 1012 switch (psp) { 1013 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 1014 case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN: 1015 case POWER_SUPPLY_PROP_ENERGY_FULL: 1016 case POWER_SUPPLY_PROP_ENERGY_EMPTY: 1017 case POWER_SUPPLY_PROP_ENERGY_NOW: 1018 case POWER_SUPPLY_PROP_ENERGY_AVG: 1019 case POWER_SUPPLY_PROP_VOLTAGE_MAX: 1020 case POWER_SUPPLY_PROP_VOLTAGE_MIN: 1021 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 1022 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 1023 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 1024 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 1025 case POWER_SUPPLY_PROP_VOLTAGE_OCV: 1026 case POWER_SUPPLY_PROP_VOLTAGE_BOOT: 1027 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 1028 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: 1029 case POWER_SUPPLY_PROP_POWER_NOW: 1030 return true; 1031 default: 1032 break; 1033 } 1034 1035 return false; 1036 } 1037 1038 #ifdef CONFIG_SYSFS 1039 ssize_t power_supply_charge_behaviour_show(struct device *dev, 1040 unsigned int available_behaviours, 1041 enum power_supply_charge_behaviour behaviour, 1042 char *buf); 1043 1044 int power_supply_charge_behaviour_parse(unsigned int available_behaviours, const char *buf); 1045 ssize_t power_supply_charge_types_show(struct device *dev, 1046 unsigned int available_types, 1047 enum power_supply_charge_type current_type, 1048 char *buf); 1049 int power_supply_charge_types_parse(unsigned int available_types, const char *buf); 1050 #else 1051 static inline 1052 ssize_t power_supply_charge_behaviour_show(struct device *dev, 1053 unsigned int available_behaviours, 1054 enum power_supply_charge_behaviour behaviour, 1055 char *buf) 1056 { 1057 return -EOPNOTSUPP; 1058 } 1059 1060 static inline int power_supply_charge_behaviour_parse(unsigned int available_behaviours, 1061 const char *buf) 1062 { 1063 return -EOPNOTSUPP; 1064 } 1065 1066 static inline 1067 ssize_t power_supply_charge_types_show(struct device *dev, 1068 unsigned int available_types, 1069 enum power_supply_charge_type current_type, 1070 char *buf) 1071 { 1072 return -EOPNOTSUPP; 1073 } 1074 1075 static inline int power_supply_charge_types_parse(unsigned int available_types, const char *buf) 1076 { 1077 return -EOPNOTSUPP; 1078 } 1079 #endif 1080 1081 #endif /* __LINUX_POWER_SUPPLY_H__ */ 1082