18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Universal power supply monitor class 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright © 2007 Anton Vorontsov <cbou@mail.ru> 68c2ecf20Sopenharmony_ci * Copyright © 2004 Szabolcs Gyurko 78c2ecf20Sopenharmony_ci * Copyright © 2003 Ian Molton <spyro@f2s.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Modified: 2004, Oct Szabolcs Gyurko 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __LINUX_POWER_SUPPLY_H__ 138c2ecf20Sopenharmony_ci#define __LINUX_POWER_SUPPLY_H__ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/device.h> 168c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 178c2ecf20Sopenharmony_ci#include <linux/leds.h> 188c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 198c2ecf20Sopenharmony_ci#include <linux/notifier.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * All voltages, currents, charges, energies, time and temperatures in uV, 238c2ecf20Sopenharmony_ci * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise 248c2ecf20Sopenharmony_ci * stated. It's driver's job to convert its raw values to units in which 258c2ecf20Sopenharmony_ci * this class operates. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * For systems where the charger determines the maximum battery capacity 308c2ecf20Sopenharmony_ci * the min and max fields should be used to present these values to user 318c2ecf20Sopenharmony_ci * space. Unused/unknown fields will not appear in sysfs. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cienum { 358c2ecf20Sopenharmony_ci POWER_SUPPLY_STATUS_UNKNOWN = 0, 368c2ecf20Sopenharmony_ci POWER_SUPPLY_STATUS_CHARGING, 378c2ecf20Sopenharmony_ci POWER_SUPPLY_STATUS_DISCHARGING, 388c2ecf20Sopenharmony_ci POWER_SUPPLY_STATUS_NOT_CHARGING, 398c2ecf20Sopenharmony_ci POWER_SUPPLY_STATUS_FULL, 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* What algorithm is the charger using? */ 438c2ecf20Sopenharmony_cienum { 448c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0, 458c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_NONE, 468c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_TRICKLE, /* slow speed */ 478c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_FAST, /* fast speed */ 488c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_STANDARD, /* normal speed */ 498c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE, /* dynamically adjusted speed */ 508c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_CUSTOM, /* use CHARGE_CONTROL_* props */ 518c2ecf20Sopenharmony_ci POWER_SUPPLY_CHARGE_TYPE_LONGLIFE, /* slow speed, longer life */ 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cienum { 558c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_UNKNOWN = 0, 568c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_GOOD, 578c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_OVERHEAT, 588c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_DEAD, 598c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_OVERVOLTAGE, 608c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_UNSPEC_FAILURE, 618c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_COLD, 628c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, 638c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE, 648c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_OVERCURRENT, 658c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED, 668c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_WARM, 678c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_COOL, 688c2ecf20Sopenharmony_ci POWER_SUPPLY_HEALTH_HOT, 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cienum { 728c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0, 738c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_NiMH, 748c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_LION, 758c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_LIPO, 768c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_LiFe, 778c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_NiCd, 788c2ecf20Sopenharmony_ci POWER_SUPPLY_TECHNOLOGY_LiMn, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cienum { 828c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0, 838c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, 848c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_LOW, 858c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, 868c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_HIGH, 878c2ecf20Sopenharmony_ci POWER_SUPPLY_CAPACITY_LEVEL_FULL, 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cienum { 918c2ecf20Sopenharmony_ci POWER_SUPPLY_SCOPE_UNKNOWN = 0, 928c2ecf20Sopenharmony_ci POWER_SUPPLY_SCOPE_SYSTEM, 938c2ecf20Sopenharmony_ci POWER_SUPPLY_SCOPE_DEVICE, 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cienum power_supply_property { 978c2ecf20Sopenharmony_ci /* Properties of type `int' */ 988c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_STATUS = 0, 998c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_TYPE, 1008c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_HEALTH, 1018c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_PRESENT, 1028c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ONLINE, 1038c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_AUTHENTIC, 1048c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TECHNOLOGY, 1058c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CYCLE_COUNT, 1068c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_MAX, 1078c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_MIN, 1088c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 1098c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 1108c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_NOW, 1118c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_AVG, 1128c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_OCV, 1138c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_VOLTAGE_BOOT, 1148c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CURRENT_MAX, 1158c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CURRENT_NOW, 1168c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CURRENT_AVG, 1178c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CURRENT_BOOT, 1188c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_POWER_NOW, 1198c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_POWER_AVG, 1208c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 1218c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, 1228c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_FULL, 1238c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_EMPTY, 1248c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_NOW, 1258c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_AVG, 1268c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_COUNTER, 1278c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, 1288c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, 1298c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 1308c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, 1318c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, 1328c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, 1338c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */ 1348c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */ 1358c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, 1368c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT, 1378c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_INPUT_POWER_LIMIT, 1388c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 1398c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, 1408c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_FULL, 1418c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_EMPTY, 1428c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_NOW, 1438c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_ENERGY_AVG, 1448c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ 1458c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ 1468c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ 1478c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */ 1488c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CAPACITY_LEVEL, 1498c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP, 1508c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_MAX, 1518c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_MIN, 1528c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_ALERT_MIN, 1538c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_ALERT_MAX, 1548c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_AMBIENT, 1558c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, 1568c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, 1578c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 1588c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 1598c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, 1608c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 1618c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ 1628c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_USB_TYPE, 1638c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_SCOPE, 1648c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_PRECHARGE_CURRENT, 1658c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, 1668c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_CALIBRATE, 1678c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_MANUFACTURE_YEAR, 1688c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_MANUFACTURE_MONTH, 1698c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_MANUFACTURE_DAY, 1708c2ecf20Sopenharmony_ci /* Properties of type `const char *' */ 1718c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_MODEL_NAME, 1728c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_MANUFACTURER, 1738c2ecf20Sopenharmony_ci POWER_SUPPLY_PROP_SERIAL_NUMBER, 1748c2ecf20Sopenharmony_ci}; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cienum power_supply_type { 1778c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_UNKNOWN = 0, 1788c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_BATTERY, 1798c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_UPS, 1808c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_MAINS, 1818c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */ 1828c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */ 1838c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */ 1848c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */ 1858c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_TYPE_C, /* Type C Port */ 1868c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_PD, /* Power Delivery Port */ 1878c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_USB_PD_DRP, /* PD Dual Role Port */ 1888c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ 1898c2ecf20Sopenharmony_ci POWER_SUPPLY_TYPE_WIRELESS, /* Wireless */ 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_cienum power_supply_usb_type { 1938c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_UNKNOWN = 0, 1948c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_SDP, /* Standard Downstream Port */ 1958c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_DCP, /* Dedicated Charging Port */ 1968c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_CDP, /* Charging Downstream Port */ 1978c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_ACA, /* Accessory Charger Adapters */ 1988c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_C, /* Type C Port */ 1998c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_PD, /* Power Delivery Port */ 2008c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_PD_DRP, /* PD Dual Role Port */ 2018c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_PD_PPS, /* PD Programmable Power Supply */ 2028c2ecf20Sopenharmony_ci POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cienum power_supply_notifier_events { 2068c2ecf20Sopenharmony_ci PSY_EVENT_PROP_CHANGED, 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ciunion power_supply_propval { 2108c2ecf20Sopenharmony_ci int intval; 2118c2ecf20Sopenharmony_ci const char *strval; 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistruct device_node; 2158c2ecf20Sopenharmony_cistruct power_supply; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/* Run-time specific power supply configuration */ 2188c2ecf20Sopenharmony_cistruct power_supply_config { 2198c2ecf20Sopenharmony_ci struct device_node *of_node; 2208c2ecf20Sopenharmony_ci struct fwnode_handle *fwnode; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci /* Driver private data */ 2238c2ecf20Sopenharmony_ci void *drv_data; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci /* Device specific sysfs attributes */ 2268c2ecf20Sopenharmony_ci const struct attribute_group **attr_grp; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci char **supplied_to; 2298c2ecf20Sopenharmony_ci size_t num_supplicants; 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci/* Description of power supply */ 2338c2ecf20Sopenharmony_cistruct power_supply_desc { 2348c2ecf20Sopenharmony_ci const char *name; 2358c2ecf20Sopenharmony_ci enum power_supply_type type; 2368c2ecf20Sopenharmony_ci const enum power_supply_usb_type *usb_types; 2378c2ecf20Sopenharmony_ci size_t num_usb_types; 2388c2ecf20Sopenharmony_ci const enum power_supply_property *properties; 2398c2ecf20Sopenharmony_ci size_t num_properties; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci /* 2428c2ecf20Sopenharmony_ci * Functions for drivers implementing power supply class. 2438c2ecf20Sopenharmony_ci * These shouldn't be called directly by other drivers for accessing 2448c2ecf20Sopenharmony_ci * this power supply. Instead use power_supply_*() functions (for 2458c2ecf20Sopenharmony_ci * example power_supply_get_property()). 2468c2ecf20Sopenharmony_ci */ 2478c2ecf20Sopenharmony_ci int (*get_property)(struct power_supply *psy, 2488c2ecf20Sopenharmony_ci enum power_supply_property psp, 2498c2ecf20Sopenharmony_ci union power_supply_propval *val); 2508c2ecf20Sopenharmony_ci int (*set_property)(struct power_supply *psy, 2518c2ecf20Sopenharmony_ci enum power_supply_property psp, 2528c2ecf20Sopenharmony_ci const union power_supply_propval *val); 2538c2ecf20Sopenharmony_ci /* 2548c2ecf20Sopenharmony_ci * property_is_writeable() will be called during registration 2558c2ecf20Sopenharmony_ci * of power supply. If this happens during device probe then it must 2568c2ecf20Sopenharmony_ci * not access internal data of device (because probe did not end). 2578c2ecf20Sopenharmony_ci */ 2588c2ecf20Sopenharmony_ci int (*property_is_writeable)(struct power_supply *psy, 2598c2ecf20Sopenharmony_ci enum power_supply_property psp); 2608c2ecf20Sopenharmony_ci void (*external_power_changed)(struct power_supply *psy); 2618c2ecf20Sopenharmony_ci void (*set_charged)(struct power_supply *psy); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* 2648c2ecf20Sopenharmony_ci * Set if thermal zone should not be created for this power supply. 2658c2ecf20Sopenharmony_ci * For example for virtual supplies forwarding calls to actual 2668c2ecf20Sopenharmony_ci * sensors or other supplies. 2678c2ecf20Sopenharmony_ci */ 2688c2ecf20Sopenharmony_ci bool no_thermal; 2698c2ecf20Sopenharmony_ci /* For APM emulation, think legacy userspace. */ 2708c2ecf20Sopenharmony_ci int use_for_apm; 2718c2ecf20Sopenharmony_ci}; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cistruct power_supply { 2748c2ecf20Sopenharmony_ci const struct power_supply_desc *desc; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci char **supplied_to; 2778c2ecf20Sopenharmony_ci size_t num_supplicants; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci char **supplied_from; 2808c2ecf20Sopenharmony_ci size_t num_supplies; 2818c2ecf20Sopenharmony_ci struct device_node *of_node; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci /* Driver private data */ 2848c2ecf20Sopenharmony_ci void *drv_data; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci /* private */ 2878c2ecf20Sopenharmony_ci struct device dev; 2888c2ecf20Sopenharmony_ci struct work_struct changed_work; 2898c2ecf20Sopenharmony_ci struct delayed_work deferred_register_work; 2908c2ecf20Sopenharmony_ci spinlock_t changed_lock; 2918c2ecf20Sopenharmony_ci bool changed; 2928c2ecf20Sopenharmony_ci bool initialized; 2938c2ecf20Sopenharmony_ci bool removing; 2948c2ecf20Sopenharmony_ci atomic_t use_cnt; 2958c2ecf20Sopenharmony_ci#ifdef CONFIG_THERMAL 2968c2ecf20Sopenharmony_ci struct thermal_zone_device *tzd; 2978c2ecf20Sopenharmony_ci struct thermal_cooling_device *tcd; 2988c2ecf20Sopenharmony_ci#endif 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci#ifdef CONFIG_LEDS_TRIGGERS 3018c2ecf20Sopenharmony_ci struct led_trigger *charging_full_trig; 3028c2ecf20Sopenharmony_ci char *charging_full_trig_name; 3038c2ecf20Sopenharmony_ci struct led_trigger *charging_trig; 3048c2ecf20Sopenharmony_ci char *charging_trig_name; 3058c2ecf20Sopenharmony_ci struct led_trigger *full_trig; 3068c2ecf20Sopenharmony_ci char *full_trig_name; 3078c2ecf20Sopenharmony_ci struct led_trigger *online_trig; 3088c2ecf20Sopenharmony_ci char *online_trig_name; 3098c2ecf20Sopenharmony_ci struct led_trigger *charging_blink_full_solid_trig; 3108c2ecf20Sopenharmony_ci char *charging_blink_full_solid_trig_name; 3118c2ecf20Sopenharmony_ci#endif 3128c2ecf20Sopenharmony_ci}; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci/* 3158c2ecf20Sopenharmony_ci * This is recommended structure to specify static power supply parameters. 3168c2ecf20Sopenharmony_ci * Generic one, parametrizable for different power supplies. Power supply 3178c2ecf20Sopenharmony_ci * class itself does not use it, but that's what implementing most platform 3188c2ecf20Sopenharmony_ci * drivers, should try reuse for consistency. 3198c2ecf20Sopenharmony_ci */ 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistruct power_supply_info { 3228c2ecf20Sopenharmony_ci const char *name; 3238c2ecf20Sopenharmony_ci int technology; 3248c2ecf20Sopenharmony_ci int voltage_max_design; 3258c2ecf20Sopenharmony_ci int voltage_min_design; 3268c2ecf20Sopenharmony_ci int charge_full_design; 3278c2ecf20Sopenharmony_ci int charge_empty_design; 3288c2ecf20Sopenharmony_ci int energy_full_design; 3298c2ecf20Sopenharmony_ci int energy_empty_design; 3308c2ecf20Sopenharmony_ci int use_for_apm; 3318c2ecf20Sopenharmony_ci}; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_cistruct power_supply_battery_ocv_table { 3348c2ecf20Sopenharmony_ci int ocv; /* microVolts */ 3358c2ecf20Sopenharmony_ci int capacity; /* percent */ 3368c2ecf20Sopenharmony_ci}; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_cistruct power_supply_resistance_temp_table { 3398c2ecf20Sopenharmony_ci int temp; /* celsius */ 3408c2ecf20Sopenharmony_ci int resistance; /* internal resistance percent */ 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci#define POWER_SUPPLY_OCV_TEMP_MAX 20 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci/* 3468c2ecf20Sopenharmony_ci * This is the recommended struct to manage static battery parameters, 3478c2ecf20Sopenharmony_ci * populated by power_supply_get_battery_info(). Most platform drivers should 3488c2ecf20Sopenharmony_ci * use these for consistency. 3498c2ecf20Sopenharmony_ci * Its field names must correspond to elements in enum power_supply_property. 3508c2ecf20Sopenharmony_ci * The default field value is -EINVAL. 3518c2ecf20Sopenharmony_ci * Power supply class itself doesn't use this. 3528c2ecf20Sopenharmony_ci */ 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistruct power_supply_battery_info { 3558c2ecf20Sopenharmony_ci int energy_full_design_uwh; /* microWatt-hours */ 3568c2ecf20Sopenharmony_ci int charge_full_design_uah; /* microAmp-hours */ 3578c2ecf20Sopenharmony_ci int voltage_min_design_uv; /* microVolts */ 3588c2ecf20Sopenharmony_ci int voltage_max_design_uv; /* microVolts */ 3598c2ecf20Sopenharmony_ci int tricklecharge_current_ua; /* microAmps */ 3608c2ecf20Sopenharmony_ci int precharge_current_ua; /* microAmps */ 3618c2ecf20Sopenharmony_ci int precharge_voltage_max_uv; /* microVolts */ 3628c2ecf20Sopenharmony_ci int charge_term_current_ua; /* microAmps */ 3638c2ecf20Sopenharmony_ci int charge_restart_voltage_uv; /* microVolts */ 3648c2ecf20Sopenharmony_ci int overvoltage_limit_uv; /* microVolts */ 3658c2ecf20Sopenharmony_ci int constant_charge_current_max_ua; /* microAmps */ 3668c2ecf20Sopenharmony_ci int constant_charge_voltage_max_uv; /* microVolts */ 3678c2ecf20Sopenharmony_ci int factory_internal_resistance_uohm; /* microOhms */ 3688c2ecf20Sopenharmony_ci int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ 3698c2ecf20Sopenharmony_ci int temp_ambient_alert_min; /* celsius */ 3708c2ecf20Sopenharmony_ci int temp_ambient_alert_max; /* celsius */ 3718c2ecf20Sopenharmony_ci int temp_alert_min; /* celsius */ 3728c2ecf20Sopenharmony_ci int temp_alert_max; /* celsius */ 3738c2ecf20Sopenharmony_ci int temp_min; /* celsius */ 3748c2ecf20Sopenharmony_ci int temp_max; /* celsius */ 3758c2ecf20Sopenharmony_ci struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; 3768c2ecf20Sopenharmony_ci int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; 3778c2ecf20Sopenharmony_ci struct power_supply_resistance_temp_table *resist_table; 3788c2ecf20Sopenharmony_ci int resist_table_size; 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ciextern struct atomic_notifier_head power_supply_notifier; 3828c2ecf20Sopenharmony_ciextern int power_supply_reg_notifier(struct notifier_block *nb); 3838c2ecf20Sopenharmony_ciextern void power_supply_unreg_notifier(struct notifier_block *nb); 3848c2ecf20Sopenharmony_ciextern struct power_supply *power_supply_get_by_name(const char *name); 3858c2ecf20Sopenharmony_ciextern void power_supply_put(struct power_supply *psy); 3868c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 3878c2ecf20Sopenharmony_ciextern struct power_supply *power_supply_get_by_phandle(struct device_node *np, 3888c2ecf20Sopenharmony_ci const char *property); 3898c2ecf20Sopenharmony_ciextern struct power_supply *devm_power_supply_get_by_phandle( 3908c2ecf20Sopenharmony_ci struct device *dev, const char *property); 3918c2ecf20Sopenharmony_ci#else /* !CONFIG_OF */ 3928c2ecf20Sopenharmony_cistatic inline struct power_supply * 3938c2ecf20Sopenharmony_cipower_supply_get_by_phandle(struct device_node *np, const char *property) 3948c2ecf20Sopenharmony_ci{ return NULL; } 3958c2ecf20Sopenharmony_cistatic inline struct power_supply * 3968c2ecf20Sopenharmony_cidevm_power_supply_get_by_phandle(struct device *dev, const char *property) 3978c2ecf20Sopenharmony_ci{ return NULL; } 3988c2ecf20Sopenharmony_ci#endif /* CONFIG_OF */ 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ciextern int power_supply_get_battery_info(struct power_supply *psy, 4018c2ecf20Sopenharmony_ci struct power_supply_battery_info *info); 4028c2ecf20Sopenharmony_ciextern void power_supply_put_battery_info(struct power_supply *psy, 4038c2ecf20Sopenharmony_ci struct power_supply_battery_info *info); 4048c2ecf20Sopenharmony_ciextern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, 4058c2ecf20Sopenharmony_ci int table_len, int ocv); 4068c2ecf20Sopenharmony_ciextern struct power_supply_battery_ocv_table * 4078c2ecf20Sopenharmony_cipower_supply_find_ocv2cap_table(struct power_supply_battery_info *info, 4088c2ecf20Sopenharmony_ci int temp, int *table_len); 4098c2ecf20Sopenharmony_ciextern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, 4108c2ecf20Sopenharmony_ci int ocv, int temp); 4118c2ecf20Sopenharmony_ciextern int 4128c2ecf20Sopenharmony_cipower_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table, 4138c2ecf20Sopenharmony_ci int table_len, int temp); 4148c2ecf20Sopenharmony_ciextern void power_supply_changed(struct power_supply *psy); 4158c2ecf20Sopenharmony_ciextern int power_supply_am_i_supplied(struct power_supply *psy); 4168c2ecf20Sopenharmony_ciint power_supply_get_property_from_supplier(struct power_supply *psy, 4178c2ecf20Sopenharmony_ci enum power_supply_property psp, 4188c2ecf20Sopenharmony_ci union power_supply_propval *val); 4198c2ecf20Sopenharmony_ciextern int power_supply_set_battery_charged(struct power_supply *psy); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci#ifdef CONFIG_POWER_SUPPLY 4228c2ecf20Sopenharmony_ciextern int power_supply_is_system_supplied(void); 4238c2ecf20Sopenharmony_ci#else 4248c2ecf20Sopenharmony_cistatic inline int power_supply_is_system_supplied(void) { return -ENOSYS; } 4258c2ecf20Sopenharmony_ci#endif 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ciextern int power_supply_get_property(struct power_supply *psy, 4288c2ecf20Sopenharmony_ci enum power_supply_property psp, 4298c2ecf20Sopenharmony_ci union power_supply_propval *val); 4308c2ecf20Sopenharmony_ciextern int power_supply_set_property(struct power_supply *psy, 4318c2ecf20Sopenharmony_ci enum power_supply_property psp, 4328c2ecf20Sopenharmony_ci const union power_supply_propval *val); 4338c2ecf20Sopenharmony_ciextern int power_supply_property_is_writeable(struct power_supply *psy, 4348c2ecf20Sopenharmony_ci enum power_supply_property psp); 4358c2ecf20Sopenharmony_ciextern void power_supply_external_power_changed(struct power_supply *psy); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ciextern struct power_supply *__must_check 4388c2ecf20Sopenharmony_cipower_supply_register(struct device *parent, 4398c2ecf20Sopenharmony_ci const struct power_supply_desc *desc, 4408c2ecf20Sopenharmony_ci const struct power_supply_config *cfg); 4418c2ecf20Sopenharmony_ciextern struct power_supply *__must_check 4428c2ecf20Sopenharmony_cipower_supply_register_no_ws(struct device *parent, 4438c2ecf20Sopenharmony_ci const struct power_supply_desc *desc, 4448c2ecf20Sopenharmony_ci const struct power_supply_config *cfg); 4458c2ecf20Sopenharmony_ciextern struct power_supply *__must_check 4468c2ecf20Sopenharmony_cidevm_power_supply_register(struct device *parent, 4478c2ecf20Sopenharmony_ci const struct power_supply_desc *desc, 4488c2ecf20Sopenharmony_ci const struct power_supply_config *cfg); 4498c2ecf20Sopenharmony_ciextern struct power_supply *__must_check 4508c2ecf20Sopenharmony_cidevm_power_supply_register_no_ws(struct device *parent, 4518c2ecf20Sopenharmony_ci const struct power_supply_desc *desc, 4528c2ecf20Sopenharmony_ci const struct power_supply_config *cfg); 4538c2ecf20Sopenharmony_ciextern void power_supply_unregister(struct power_supply *psy); 4548c2ecf20Sopenharmony_ciextern int power_supply_powers(struct power_supply *psy, struct device *dev); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci#define to_power_supply(device) container_of(device, struct power_supply, dev) 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ciextern void *power_supply_get_drvdata(struct power_supply *psy); 4598c2ecf20Sopenharmony_ci/* For APM emulation, think legacy userspace. */ 4608c2ecf20Sopenharmony_ciextern struct class *power_supply_class; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic inline bool power_supply_is_amp_property(enum power_supply_property psp) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci switch (psp) { 4658c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 4668c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: 4678c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_FULL: 4688c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_EMPTY: 4698c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_NOW: 4708c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_AVG: 4718c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_COUNTER: 4728c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: 4738c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: 4748c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: 4758c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: 4768c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CURRENT_MAX: 4778c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CURRENT_NOW: 4788c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CURRENT_AVG: 4798c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CURRENT_BOOT: 4808c2ecf20Sopenharmony_ci return 1; 4818c2ecf20Sopenharmony_ci default: 4828c2ecf20Sopenharmony_ci break; 4838c2ecf20Sopenharmony_ci } 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci return 0; 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_cistatic inline bool power_supply_is_watt_property(enum power_supply_property psp) 4898c2ecf20Sopenharmony_ci{ 4908c2ecf20Sopenharmony_ci switch (psp) { 4918c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 4928c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN: 4938c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_FULL: 4948c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_EMPTY: 4958c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_NOW: 4968c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_ENERGY_AVG: 4978c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_MAX: 4988c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_MIN: 4998c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 5008c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 5018c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_NOW: 5028c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_AVG: 5038c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_OCV: 5048c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_VOLTAGE_BOOT: 5058c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 5068c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: 5078c2ecf20Sopenharmony_ci case POWER_SUPPLY_PROP_POWER_NOW: 5088c2ecf20Sopenharmony_ci return 1; 5098c2ecf20Sopenharmony_ci default: 5108c2ecf20Sopenharmony_ci break; 5118c2ecf20Sopenharmony_ci } 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci return 0; 5148c2ecf20Sopenharmony_ci} 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci#ifdef CONFIG_POWER_SUPPLY_HWMON 5178c2ecf20Sopenharmony_ciint power_supply_add_hwmon_sysfs(struct power_supply *psy); 5188c2ecf20Sopenharmony_civoid power_supply_remove_hwmon_sysfs(struct power_supply *psy); 5198c2ecf20Sopenharmony_ci#else 5208c2ecf20Sopenharmony_cistatic inline int power_supply_add_hwmon_sysfs(struct power_supply *psy) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci return 0; 5238c2ecf20Sopenharmony_ci} 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_cistatic inline 5268c2ecf20Sopenharmony_civoid power_supply_remove_hwmon_sysfs(struct power_supply *psy) {} 5278c2ecf20Sopenharmony_ci#endif 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci#endif /* __LINUX_POWER_SUPPLY_H__ */ 530