.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Sysfs interface for the universal power supply monitor class |
---|
3 | 4 | * |
---|
.. | .. |
---|
7 | 8 | * Copyright © 2003 Ian Molton <spyro@f2s.com> |
---|
8 | 9 | * |
---|
9 | 10 | * Modified: 2004, Oct Szabolcs Gyurko |
---|
10 | | - * |
---|
11 | | - * You may use this code as per GPL version 2 |
---|
12 | 11 | */ |
---|
13 | 12 | |
---|
14 | 13 | #include <linux/ctype.h> |
---|
.. | .. |
---|
19 | 18 | |
---|
20 | 19 | #include "power_supply.h" |
---|
21 | 20 | |
---|
22 | | -/* |
---|
23 | | - * This is because the name "current" breaks the device attr macro. |
---|
24 | | - * The "current" word resolves to "(get_current())" so instead of |
---|
25 | | - * "current" "(get_current())" appears in the sysfs. |
---|
26 | | - * |
---|
27 | | - * The source of this definition is the device.h which calls __ATTR |
---|
28 | | - * macro in sysfs.h which calls the __stringify macro. |
---|
29 | | - * |
---|
30 | | - * Only modification that the name is not tried to be resolved |
---|
31 | | - * (as a macro let's say). |
---|
32 | | - */ |
---|
| 21 | +#define MAX_PROP_NAME_LEN 30 |
---|
33 | 22 | |
---|
34 | | -#define POWER_SUPPLY_ATTR(_name) \ |
---|
35 | | -{ \ |
---|
36 | | - .attr = { .name = #_name }, \ |
---|
37 | | - .show = power_supply_show_property, \ |
---|
38 | | - .store = power_supply_store_property, \ |
---|
| 23 | +struct power_supply_attr { |
---|
| 24 | + const char *prop_name; |
---|
| 25 | + char attr_name[MAX_PROP_NAME_LEN + 1]; |
---|
| 26 | + struct device_attribute dev_attr; |
---|
| 27 | + const char * const *text_values; |
---|
| 28 | + int text_values_len; |
---|
| 29 | +}; |
---|
| 30 | + |
---|
| 31 | +#define _POWER_SUPPLY_ATTR(_name, _text, _len) \ |
---|
| 32 | +[POWER_SUPPLY_PROP_ ## _name] = \ |
---|
| 33 | +{ \ |
---|
| 34 | + .prop_name = #_name, \ |
---|
| 35 | + .attr_name = #_name "\0", \ |
---|
| 36 | + .text_values = _text, \ |
---|
| 37 | + .text_values_len = _len, \ |
---|
39 | 38 | } |
---|
40 | 39 | |
---|
41 | | -static struct device_attribute power_supply_attrs[]; |
---|
| 40 | +#define POWER_SUPPLY_ATTR(_name) _POWER_SUPPLY_ATTR(_name, NULL, 0) |
---|
| 41 | +#define _POWER_SUPPLY_ENUM_ATTR(_name, _text) \ |
---|
| 42 | + _POWER_SUPPLY_ATTR(_name, _text, ARRAY_SIZE(_text)) |
---|
| 43 | +#define POWER_SUPPLY_ENUM_ATTR(_name) \ |
---|
| 44 | + _POWER_SUPPLY_ENUM_ATTR(_name, POWER_SUPPLY_ ## _name ## _TEXT) |
---|
42 | 45 | |
---|
43 | | -static const char * const power_supply_type_text[] = { |
---|
44 | | - "Unknown", "Battery", "UPS", "Mains", "USB", |
---|
45 | | - "USB_DCP", "USB_CDP", "USB_ACA", "USB_C", |
---|
46 | | - "USB_PD", "USB_PD_DRP", "BrickID", |
---|
47 | | - "USB_HVDCP", "USB_HVDCP_3", "USB_HVDCP_3P5", "Wireless", "USB_FLOAT", |
---|
48 | | - "BMS", "Parallel", "Main", "USB_C_UFP", "USB_C_DFP", |
---|
49 | | - "Charge_Pump", |
---|
| 46 | +static const char * const POWER_SUPPLY_TYPE_TEXT[] = { |
---|
| 47 | + [POWER_SUPPLY_TYPE_UNKNOWN] = "Unknown", |
---|
| 48 | + [POWER_SUPPLY_TYPE_BATTERY] = "Battery", |
---|
| 49 | + [POWER_SUPPLY_TYPE_UPS] = "UPS", |
---|
| 50 | + [POWER_SUPPLY_TYPE_MAINS] = "Mains", |
---|
| 51 | + [POWER_SUPPLY_TYPE_USB] = "USB", |
---|
| 52 | + [POWER_SUPPLY_TYPE_USB_DCP] = "USB_DCP", |
---|
| 53 | + [POWER_SUPPLY_TYPE_USB_CDP] = "USB_CDP", |
---|
| 54 | + [POWER_SUPPLY_TYPE_USB_ACA] = "USB_ACA", |
---|
| 55 | + [POWER_SUPPLY_TYPE_USB_TYPE_C] = "USB_C", |
---|
| 56 | + [POWER_SUPPLY_TYPE_USB_PD] = "USB_PD", |
---|
| 57 | + [POWER_SUPPLY_TYPE_USB_PD_DRP] = "USB_PD_DRP", |
---|
| 58 | + [POWER_SUPPLY_TYPE_APPLE_BRICK_ID] = "BrickID", |
---|
| 59 | + [POWER_SUPPLY_TYPE_WIRELESS] = "Wireless", |
---|
| 60 | +#if defined(CONFIG_NO_GKI) |
---|
| 61 | + [POWER_SUPPLY_TYPE_CHARGE_PUMP] = "Charge_Pump", |
---|
| 62 | +#endif |
---|
50 | 63 | }; |
---|
51 | 64 | |
---|
52 | | -static const char * const power_supply_usb_type_text[] = { |
---|
53 | | - "Unknown", "SDP", "DCP", "CDP", "ACA", "C", |
---|
54 | | - "PD", "PD_DRP", "PD_PPS", "BrickID" |
---|
| 65 | +static const char * const POWER_SUPPLY_USB_TYPE_TEXT[] = { |
---|
| 66 | + [POWER_SUPPLY_USB_TYPE_UNKNOWN] = "Unknown", |
---|
| 67 | + [POWER_SUPPLY_USB_TYPE_SDP] = "SDP", |
---|
| 68 | + [POWER_SUPPLY_USB_TYPE_DCP] = "DCP", |
---|
| 69 | + [POWER_SUPPLY_USB_TYPE_CDP] = "CDP", |
---|
| 70 | + [POWER_SUPPLY_USB_TYPE_ACA] = "ACA", |
---|
| 71 | + [POWER_SUPPLY_USB_TYPE_C] = "C", |
---|
| 72 | + [POWER_SUPPLY_USB_TYPE_PD] = "PD", |
---|
| 73 | + [POWER_SUPPLY_USB_TYPE_PD_DRP] = "PD_DRP", |
---|
| 74 | + [POWER_SUPPLY_USB_TYPE_PD_PPS] = "PD_PPS", |
---|
| 75 | + [POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID] = "BrickID", |
---|
55 | 76 | }; |
---|
56 | 77 | |
---|
57 | | -static const char * const power_supply_status_text[] = { |
---|
58 | | - "Unknown", "Charging", "Discharging", "Not charging", "Full" |
---|
| 78 | +static const char * const POWER_SUPPLY_STATUS_TEXT[] = { |
---|
| 79 | + [POWER_SUPPLY_STATUS_UNKNOWN] = "Unknown", |
---|
| 80 | + [POWER_SUPPLY_STATUS_CHARGING] = "Charging", |
---|
| 81 | + [POWER_SUPPLY_STATUS_DISCHARGING] = "Discharging", |
---|
| 82 | + [POWER_SUPPLY_STATUS_NOT_CHARGING] = "Not charging", |
---|
| 83 | + [POWER_SUPPLY_STATUS_FULL] = "Full", |
---|
59 | 84 | }; |
---|
60 | 85 | |
---|
61 | | -static const char * const power_supply_charge_type_text[] = { |
---|
62 | | - "Unknown", "N/A", "Trickle", "Fast", "Taper" |
---|
| 86 | +static const char * const POWER_SUPPLY_CHARGE_TYPE_TEXT[] = { |
---|
| 87 | + [POWER_SUPPLY_CHARGE_TYPE_UNKNOWN] = "Unknown", |
---|
| 88 | + [POWER_SUPPLY_CHARGE_TYPE_NONE] = "N/A", |
---|
| 89 | + [POWER_SUPPLY_CHARGE_TYPE_TRICKLE] = "Trickle", |
---|
| 90 | + [POWER_SUPPLY_CHARGE_TYPE_FAST] = "Fast", |
---|
| 91 | + [POWER_SUPPLY_CHARGE_TYPE_STANDARD] = "Standard", |
---|
| 92 | + [POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE] = "Adaptive", |
---|
| 93 | + [POWER_SUPPLY_CHARGE_TYPE_CUSTOM] = "Custom", |
---|
| 94 | + [POWER_SUPPLY_CHARGE_TYPE_LONGLIFE] = "Long Life", |
---|
| 95 | + [POWER_SUPPLY_CHARGE_TYPE_TAPER] = "Taper", |
---|
63 | 96 | }; |
---|
64 | 97 | |
---|
65 | | -static const char * const power_supply_health_text[] = { |
---|
66 | | - "Unknown", "Good", "Overheat", "Dead", "Over voltage", |
---|
67 | | - "Unspecified failure", "Cold", "Watchdog timer expire", |
---|
68 | | - "Safety timer expire", "Over current", "Warm", "Cool", "Hot" |
---|
| 98 | +static const char * const POWER_SUPPLY_HEALTH_TEXT[] = { |
---|
| 99 | + [POWER_SUPPLY_HEALTH_UNKNOWN] = "Unknown", |
---|
| 100 | + [POWER_SUPPLY_HEALTH_GOOD] = "Good", |
---|
| 101 | + [POWER_SUPPLY_HEALTH_OVERHEAT] = "Overheat", |
---|
| 102 | + [POWER_SUPPLY_HEALTH_DEAD] = "Dead", |
---|
| 103 | + [POWER_SUPPLY_HEALTH_OVERVOLTAGE] = "Over voltage", |
---|
| 104 | + [POWER_SUPPLY_HEALTH_UNSPEC_FAILURE] = "Unspecified failure", |
---|
| 105 | + [POWER_SUPPLY_HEALTH_COLD] = "Cold", |
---|
| 106 | + [POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE] = "Watchdog timer expire", |
---|
| 107 | + [POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE] = "Safety timer expire", |
---|
| 108 | + [POWER_SUPPLY_HEALTH_OVERCURRENT] = "Over current", |
---|
| 109 | + [POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED] = "Calibration required", |
---|
| 110 | + [POWER_SUPPLY_HEALTH_WARM] = "Warm", |
---|
| 111 | + [POWER_SUPPLY_HEALTH_COOL] = "Cool", |
---|
| 112 | + [POWER_SUPPLY_HEALTH_HOT] = "Hot", |
---|
69 | 113 | }; |
---|
70 | 114 | |
---|
71 | | -static const char * const power_supply_technology_text[] = { |
---|
72 | | - "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", |
---|
73 | | - "LiMn" |
---|
| 115 | +static const char * const POWER_SUPPLY_TECHNOLOGY_TEXT[] = { |
---|
| 116 | + [POWER_SUPPLY_TECHNOLOGY_UNKNOWN] = "Unknown", |
---|
| 117 | + [POWER_SUPPLY_TECHNOLOGY_NiMH] = "NiMH", |
---|
| 118 | + [POWER_SUPPLY_TECHNOLOGY_LION] = "Li-ion", |
---|
| 119 | + [POWER_SUPPLY_TECHNOLOGY_LIPO] = "Li-poly", |
---|
| 120 | + [POWER_SUPPLY_TECHNOLOGY_LiFe] = "LiFe", |
---|
| 121 | + [POWER_SUPPLY_TECHNOLOGY_NiCd] = "NiCd", |
---|
| 122 | + [POWER_SUPPLY_TECHNOLOGY_LiMn] = "LiMn", |
---|
74 | 123 | }; |
---|
75 | 124 | |
---|
76 | | -static const char * const power_supply_capacity_level_text[] = { |
---|
77 | | - "Unknown", "Critical", "Low", "Normal", "High", "Full" |
---|
| 125 | +static const char * const POWER_SUPPLY_CAPACITY_LEVEL_TEXT[] = { |
---|
| 126 | + [POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN] = "Unknown", |
---|
| 127 | + [POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL] = "Critical", |
---|
| 128 | + [POWER_SUPPLY_CAPACITY_LEVEL_LOW] = "Low", |
---|
| 129 | + [POWER_SUPPLY_CAPACITY_LEVEL_NORMAL] = "Normal", |
---|
| 130 | + [POWER_SUPPLY_CAPACITY_LEVEL_HIGH] = "High", |
---|
| 131 | + [POWER_SUPPLY_CAPACITY_LEVEL_FULL] = "Full", |
---|
78 | 132 | }; |
---|
79 | 133 | |
---|
80 | | -static const char * const power_supply_scope_text[] = { |
---|
81 | | - "Unknown", "System", "Device" |
---|
| 134 | +static const char * const POWER_SUPPLY_SCOPE_TEXT[] = { |
---|
| 135 | + [POWER_SUPPLY_SCOPE_UNKNOWN] = "Unknown", |
---|
| 136 | + [POWER_SUPPLY_SCOPE_SYSTEM] = "System", |
---|
| 137 | + [POWER_SUPPLY_SCOPE_DEVICE] = "Device", |
---|
82 | 138 | }; |
---|
83 | 139 | |
---|
84 | | -static const char * const power_supply_usbc_text[] = { |
---|
85 | | - "Nothing attached", "Sink attached", "Powered cable w/ sink", |
---|
86 | | - "Debug Accessory", "Audio Adapter", "Powered cable w/o sink", |
---|
87 | | - "Source attached (default current)", |
---|
88 | | - "Source attached (medium current)", |
---|
89 | | - "Source attached (high current)", |
---|
90 | | - "Debug Accessory Mode (default current)", |
---|
91 | | - "Debug Accessory Mode (medium current)", |
---|
92 | | - "Debug Accessory Mode (high current)", |
---|
93 | | - "Non compliant", |
---|
94 | | - "Non compliant (Rp-Default/Rp-Default)", |
---|
95 | | - "Non compliant (Rp-1.5A/Rp-1.5A)", |
---|
96 | | - "Non compliant (Rp-3A/Rp-3A)" |
---|
| 140 | +static struct power_supply_attr power_supply_attrs[] = { |
---|
| 141 | + /* Properties of type `int' */ |
---|
| 142 | + POWER_SUPPLY_ENUM_ATTR(STATUS), |
---|
| 143 | + POWER_SUPPLY_ENUM_ATTR(CHARGE_TYPE), |
---|
| 144 | + POWER_SUPPLY_ENUM_ATTR(HEALTH), |
---|
| 145 | + POWER_SUPPLY_ATTR(PRESENT), |
---|
| 146 | + POWER_SUPPLY_ATTR(ONLINE), |
---|
| 147 | + POWER_SUPPLY_ATTR(AUTHENTIC), |
---|
| 148 | + POWER_SUPPLY_ENUM_ATTR(TECHNOLOGY), |
---|
| 149 | + POWER_SUPPLY_ATTR(CYCLE_COUNT), |
---|
| 150 | + POWER_SUPPLY_ATTR(VOLTAGE_MAX), |
---|
| 151 | + POWER_SUPPLY_ATTR(VOLTAGE_MIN), |
---|
| 152 | + POWER_SUPPLY_ATTR(VOLTAGE_MAX_DESIGN), |
---|
| 153 | + POWER_SUPPLY_ATTR(VOLTAGE_MIN_DESIGN), |
---|
| 154 | + POWER_SUPPLY_ATTR(VOLTAGE_NOW), |
---|
| 155 | + POWER_SUPPLY_ATTR(VOLTAGE_AVG), |
---|
| 156 | + POWER_SUPPLY_ATTR(VOLTAGE_OCV), |
---|
| 157 | + POWER_SUPPLY_ATTR(VOLTAGE_BOOT), |
---|
| 158 | + POWER_SUPPLY_ATTR(CURRENT_MAX), |
---|
| 159 | + POWER_SUPPLY_ATTR(CURRENT_NOW), |
---|
| 160 | + POWER_SUPPLY_ATTR(CURRENT_AVG), |
---|
| 161 | + POWER_SUPPLY_ATTR(CURRENT_BOOT), |
---|
| 162 | + POWER_SUPPLY_ATTR(POWER_NOW), |
---|
| 163 | + POWER_SUPPLY_ATTR(POWER_AVG), |
---|
| 164 | + POWER_SUPPLY_ATTR(CHARGE_FULL_DESIGN), |
---|
| 165 | + POWER_SUPPLY_ATTR(CHARGE_EMPTY_DESIGN), |
---|
| 166 | + POWER_SUPPLY_ATTR(CHARGE_FULL), |
---|
| 167 | + POWER_SUPPLY_ATTR(CHARGE_EMPTY), |
---|
| 168 | + POWER_SUPPLY_ATTR(CHARGE_NOW), |
---|
| 169 | + POWER_SUPPLY_ATTR(CHARGE_AVG), |
---|
| 170 | + POWER_SUPPLY_ATTR(CHARGE_COUNTER), |
---|
| 171 | + POWER_SUPPLY_ATTR(CONSTANT_CHARGE_CURRENT), |
---|
| 172 | + POWER_SUPPLY_ATTR(CONSTANT_CHARGE_CURRENT_MAX), |
---|
| 173 | + POWER_SUPPLY_ATTR(CONSTANT_CHARGE_VOLTAGE), |
---|
| 174 | + POWER_SUPPLY_ATTR(CONSTANT_CHARGE_VOLTAGE_MAX), |
---|
| 175 | + POWER_SUPPLY_ATTR(CHARGE_CONTROL_LIMIT), |
---|
| 176 | + POWER_SUPPLY_ATTR(CHARGE_CONTROL_LIMIT_MAX), |
---|
| 177 | + POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD), |
---|
| 178 | + POWER_SUPPLY_ATTR(CHARGE_CONTROL_END_THRESHOLD), |
---|
| 179 | + POWER_SUPPLY_ATTR(INPUT_CURRENT_LIMIT), |
---|
| 180 | + POWER_SUPPLY_ATTR(INPUT_VOLTAGE_LIMIT), |
---|
| 181 | + POWER_SUPPLY_ATTR(INPUT_POWER_LIMIT), |
---|
| 182 | + POWER_SUPPLY_ATTR(ENERGY_FULL_DESIGN), |
---|
| 183 | + POWER_SUPPLY_ATTR(ENERGY_EMPTY_DESIGN), |
---|
| 184 | + POWER_SUPPLY_ATTR(ENERGY_FULL), |
---|
| 185 | + POWER_SUPPLY_ATTR(ENERGY_EMPTY), |
---|
| 186 | + POWER_SUPPLY_ATTR(ENERGY_NOW), |
---|
| 187 | + POWER_SUPPLY_ATTR(ENERGY_AVG), |
---|
| 188 | + POWER_SUPPLY_ATTR(CAPACITY), |
---|
| 189 | + POWER_SUPPLY_ATTR(CAPACITY_ALERT_MIN), |
---|
| 190 | + POWER_SUPPLY_ATTR(CAPACITY_ALERT_MAX), |
---|
| 191 | + POWER_SUPPLY_ATTR(CAPACITY_ERROR_MARGIN), |
---|
| 192 | + POWER_SUPPLY_ENUM_ATTR(CAPACITY_LEVEL), |
---|
| 193 | + POWER_SUPPLY_ATTR(TEMP), |
---|
| 194 | + POWER_SUPPLY_ATTR(TEMP_MAX), |
---|
| 195 | + POWER_SUPPLY_ATTR(TEMP_MIN), |
---|
| 196 | + POWER_SUPPLY_ATTR(TEMP_ALERT_MIN), |
---|
| 197 | + POWER_SUPPLY_ATTR(TEMP_ALERT_MAX), |
---|
| 198 | + POWER_SUPPLY_ATTR(TEMP_AMBIENT), |
---|
| 199 | + POWER_SUPPLY_ATTR(TEMP_AMBIENT_ALERT_MIN), |
---|
| 200 | + POWER_SUPPLY_ATTR(TEMP_AMBIENT_ALERT_MAX), |
---|
| 201 | + POWER_SUPPLY_ATTR(TIME_TO_EMPTY_NOW), |
---|
| 202 | + POWER_SUPPLY_ATTR(TIME_TO_EMPTY_AVG), |
---|
| 203 | + POWER_SUPPLY_ATTR(TIME_TO_FULL_NOW), |
---|
| 204 | + POWER_SUPPLY_ATTR(TIME_TO_FULL_AVG), |
---|
| 205 | + POWER_SUPPLY_ENUM_ATTR(TYPE), |
---|
| 206 | + POWER_SUPPLY_ATTR(USB_TYPE), |
---|
| 207 | + POWER_SUPPLY_ENUM_ATTR(SCOPE), |
---|
| 208 | + POWER_SUPPLY_ATTR(PRECHARGE_CURRENT), |
---|
| 209 | + POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT), |
---|
| 210 | + POWER_SUPPLY_ATTR(CALIBRATE), |
---|
| 211 | + POWER_SUPPLY_ATTR(MANUFACTURE_YEAR), |
---|
| 212 | + POWER_SUPPLY_ATTR(MANUFACTURE_MONTH), |
---|
| 213 | + POWER_SUPPLY_ATTR(MANUFACTURE_DAY), |
---|
| 214 | +#if defined(CONFIG_NO_GKI) |
---|
| 215 | + /* Charge pump properties */ |
---|
| 216 | + POWER_SUPPLY_ATTR(CP_ALARM_STATUS), |
---|
| 217 | + POWER_SUPPLY_ATTR(CP_BAT_OVP_ALARM), |
---|
| 218 | + POWER_SUPPLY_ATTR(CP_BAT_OCP_ALARM), |
---|
| 219 | + POWER_SUPPLY_ATTR(CP_BAT_UCP_ALARM), |
---|
| 220 | + POWER_SUPPLY_ATTR(CP_BUS_OVP_ALARM), |
---|
| 221 | + POWER_SUPPLY_ATTR(CP_BUS_OCP_ALARM), |
---|
| 222 | + POWER_SUPPLY_ATTR(CP_BAT_THERM_ALARM), |
---|
| 223 | + POWER_SUPPLY_ATTR(CP_BUS_THERM_ALARM), |
---|
| 224 | + POWER_SUPPLY_ATTR(CP_DIE_THERM_ALARM), |
---|
| 225 | + POWER_SUPPLY_ATTR(CP_FAULT_STATUS), |
---|
| 226 | + POWER_SUPPLY_ATTR(CP_BAT_OVP_FAULT), |
---|
| 227 | + POWER_SUPPLY_ATTR(CP_BAT_OCP_FAULT), |
---|
| 228 | + POWER_SUPPLY_ATTR(CP_BUS_OVP_FAULT), |
---|
| 229 | + POWER_SUPPLY_ATTR(CP_BUS_OCP_FAULT), |
---|
| 230 | + POWER_SUPPLY_ATTR(CP_BAT_THERM_FAULT), |
---|
| 231 | + POWER_SUPPLY_ATTR(CP_BUS_THERM_FAULT), |
---|
| 232 | + POWER_SUPPLY_ATTR(CP_DIE_THERM_FAULT), |
---|
| 233 | + POWER_SUPPLY_ATTR(CP_VBUS_ERROR_STATUS), |
---|
| 234 | + POWER_SUPPLY_ATTR(CP_VBUS_HERROR_STATUS), |
---|
| 235 | + POWER_SUPPLY_ATTR(CP_VBUS_LERROR_STATUS), |
---|
| 236 | + POWER_SUPPLY_ATTR(CP_CHARGING_ENABLED), |
---|
| 237 | + POWER_SUPPLY_ATTR(CP_WDT_EN), |
---|
| 238 | + POWER_SUPPLY_ATTR(CP_VBUS), |
---|
| 239 | + POWER_SUPPLY_ATTR(CP_IBUS), |
---|
| 240 | + POWER_SUPPLY_ATTR(CP_SWITCHER_EN), |
---|
| 241 | + POWER_SUPPLY_ATTR(CP_BAT_TEMPERATURE), |
---|
| 242 | + POWER_SUPPLY_ATTR(CP_BUS_TEMPERATURE), |
---|
| 243 | + POWER_SUPPLY_ATTR(CP_DIE_TEMPERATURE), |
---|
| 244 | + POWER_SUPPLY_ATTR(CP_ISNS), |
---|
| 245 | + POWER_SUPPLY_ATTR(CP_TOGGLE_SWITCHER), |
---|
| 246 | + POWER_SUPPLY_ATTR(CP_IRQ_STATUS), |
---|
| 247 | + POWER_SUPPLY_ATTR(CP_ILIM), |
---|
| 248 | +#endif |
---|
| 249 | + /* Properties of type `const char *' */ |
---|
| 250 | + POWER_SUPPLY_ATTR(MODEL_NAME), |
---|
| 251 | + POWER_SUPPLY_ATTR(MANUFACTURER), |
---|
| 252 | + POWER_SUPPLY_ATTR(SERIAL_NUMBER), |
---|
97 | 253 | }; |
---|
98 | 254 | |
---|
99 | | -static const char * const power_supply_usbc_pr_text[] = { |
---|
100 | | - "none", "dual power role", "sink", "source" |
---|
101 | | -}; |
---|
| 255 | +static struct attribute * |
---|
| 256 | +__power_supply_attrs[ARRAY_SIZE(power_supply_attrs) + 1]; |
---|
102 | 257 | |
---|
103 | | -static const char * const power_supply_typec_src_rp_text[] = { |
---|
104 | | - "Rp-Default", "Rp-1.5A", "Rp-3A" |
---|
105 | | -}; |
---|
| 258 | +static struct power_supply_attr *to_ps_attr(struct device_attribute *attr) |
---|
| 259 | +{ |
---|
| 260 | + return container_of(attr, struct power_supply_attr, dev_attr); |
---|
| 261 | +} |
---|
| 262 | + |
---|
| 263 | +static enum power_supply_property dev_attr_psp(struct device_attribute *attr) |
---|
| 264 | +{ |
---|
| 265 | + return to_ps_attr(attr) - power_supply_attrs; |
---|
| 266 | +} |
---|
106 | 267 | |
---|
107 | 268 | static ssize_t power_supply_show_usb_type(struct device *dev, |
---|
108 | | - enum power_supply_usb_type *usb_types, |
---|
109 | | - ssize_t num_usb_types, |
---|
| 269 | + const struct power_supply_desc *desc, |
---|
110 | 270 | union power_supply_propval *value, |
---|
111 | 271 | char *buf) |
---|
112 | 272 | { |
---|
.. | .. |
---|
115 | 275 | bool match = false; |
---|
116 | 276 | int i; |
---|
117 | 277 | |
---|
118 | | - for (i = 0; i < num_usb_types; ++i) { |
---|
119 | | - usb_type = usb_types[i]; |
---|
| 278 | + for (i = 0; i < desc->num_usb_types; ++i) { |
---|
| 279 | + usb_type = desc->usb_types[i]; |
---|
120 | 280 | |
---|
121 | 281 | if (value->intval == usb_type) { |
---|
122 | 282 | count += sprintf(buf + count, "[%s] ", |
---|
123 | | - power_supply_usb_type_text[usb_type]); |
---|
| 283 | + POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); |
---|
124 | 284 | match = true; |
---|
125 | 285 | } else { |
---|
126 | 286 | count += sprintf(buf + count, "%s ", |
---|
127 | | - power_supply_usb_type_text[usb_type]); |
---|
| 287 | + POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); |
---|
128 | 288 | } |
---|
129 | 289 | } |
---|
130 | 290 | |
---|
.. | .. |
---|
144 | 304 | char *buf) { |
---|
145 | 305 | ssize_t ret; |
---|
146 | 306 | struct power_supply *psy = dev_get_drvdata(dev); |
---|
147 | | - enum power_supply_property psp = attr - power_supply_attrs; |
---|
| 307 | + struct power_supply_attr *ps_attr = to_ps_attr(attr); |
---|
| 308 | + enum power_supply_property psp = dev_attr_psp(attr); |
---|
148 | 309 | union power_supply_propval value; |
---|
149 | 310 | |
---|
150 | 311 | if (psp == POWER_SUPPLY_PROP_TYPE) { |
---|
.. | .. |
---|
164 | 325 | } |
---|
165 | 326 | } |
---|
166 | 327 | |
---|
| 328 | + if (ps_attr->text_values_len > 0 && |
---|
| 329 | + value.intval < ps_attr->text_values_len && value.intval >= 0) { |
---|
| 330 | + return sprintf(buf, "%s\n", ps_attr->text_values[value.intval]); |
---|
| 331 | + } |
---|
| 332 | + |
---|
167 | 333 | switch (psp) { |
---|
168 | | - case POWER_SUPPLY_PROP_STATUS: |
---|
169 | | - ret = sprintf(buf, "%s\n", |
---|
170 | | - power_supply_status_text[value.intval]); |
---|
171 | | - break; |
---|
172 | | - case POWER_SUPPLY_PROP_CHARGE_TYPE: |
---|
173 | | - ret = sprintf(buf, "%s\n", |
---|
174 | | - power_supply_charge_type_text[value.intval]); |
---|
175 | | - break; |
---|
176 | | - case POWER_SUPPLY_PROP_HEALTH: |
---|
177 | | - ret = sprintf(buf, "%s\n", |
---|
178 | | - power_supply_health_text[value.intval]); |
---|
179 | | - break; |
---|
180 | | - case POWER_SUPPLY_PROP_TECHNOLOGY: |
---|
181 | | - ret = sprintf(buf, "%s\n", |
---|
182 | | - power_supply_technology_text[value.intval]); |
---|
183 | | - break; |
---|
184 | | - case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
---|
185 | | - ret = sprintf(buf, "%s\n", |
---|
186 | | - power_supply_capacity_level_text[value.intval]); |
---|
187 | | - break; |
---|
188 | | - case POWER_SUPPLY_PROP_TYPE: |
---|
189 | | - case POWER_SUPPLY_PROP_REAL_TYPE: |
---|
190 | | - ret = sprintf(buf, "%s\n", |
---|
191 | | - power_supply_type_text[value.intval]); |
---|
192 | | - break; |
---|
193 | 334 | case POWER_SUPPLY_PROP_USB_TYPE: |
---|
194 | | - ret = power_supply_show_usb_type(dev, psy->desc->usb_types, |
---|
195 | | - psy->desc->num_usb_types, |
---|
196 | | - &value, buf); |
---|
197 | | - break; |
---|
198 | | - case POWER_SUPPLY_PROP_SCOPE: |
---|
199 | | - ret = sprintf(buf, "%s\n", |
---|
200 | | - power_supply_scope_text[value.intval]); |
---|
201 | | - break; |
---|
202 | | - case POWER_SUPPLY_PROP_TYPEC_MODE: |
---|
203 | | - ret = sprintf(buf, "%s\n", |
---|
204 | | - power_supply_usbc_text[value.intval]); |
---|
205 | | - break; |
---|
206 | | - case POWER_SUPPLY_PROP_TYPEC_POWER_ROLE: |
---|
207 | | - ret = sprintf(buf, "%s\n", |
---|
208 | | - power_supply_usbc_pr_text[value.intval]); |
---|
209 | | - break; |
---|
210 | | - case POWER_SUPPLY_PROP_TYPEC_SRC_RP: |
---|
211 | | - ret = sprintf(buf, "%s\n", |
---|
212 | | - power_supply_typec_src_rp_text[value.intval]); |
---|
213 | | - break; |
---|
214 | | - case POWER_SUPPLY_PROP_DIE_HEALTH: |
---|
215 | | - case POWER_SUPPLY_PROP_SKIN_HEALTH: |
---|
216 | | - case POWER_SUPPLY_PROP_CONNECTOR_HEALTH: |
---|
217 | | - ret = sprintf(buf, "%s\n", |
---|
218 | | - power_supply_health_text[value.intval]); |
---|
219 | | - break; |
---|
220 | | - case POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT: |
---|
221 | | - ret = sprintf(buf, "%lld\n", value.int64val); |
---|
| 335 | + ret = power_supply_show_usb_type(dev, psy->desc, |
---|
| 336 | + &value, buf); |
---|
222 | 337 | break; |
---|
223 | 338 | case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER: |
---|
224 | 339 | ret = sprintf(buf, "%s\n", value.strval); |
---|
.. | .. |
---|
235 | 350 | const char *buf, size_t count) { |
---|
236 | 351 | ssize_t ret; |
---|
237 | 352 | struct power_supply *psy = dev_get_drvdata(dev); |
---|
238 | | - enum power_supply_property psp = attr - power_supply_attrs; |
---|
| 353 | + struct power_supply_attr *ps_attr = to_ps_attr(attr); |
---|
| 354 | + enum power_supply_property psp = dev_attr_psp(attr); |
---|
239 | 355 | union power_supply_propval value; |
---|
240 | 356 | |
---|
241 | | - switch (psp) { |
---|
242 | | - case POWER_SUPPLY_PROP_STATUS: |
---|
243 | | - ret = sysfs_match_string(power_supply_status_text, buf); |
---|
244 | | - break; |
---|
245 | | - case POWER_SUPPLY_PROP_CHARGE_TYPE: |
---|
246 | | - ret = sysfs_match_string(power_supply_charge_type_text, buf); |
---|
247 | | - break; |
---|
248 | | - case POWER_SUPPLY_PROP_HEALTH: |
---|
249 | | - ret = sysfs_match_string(power_supply_health_text, buf); |
---|
250 | | - break; |
---|
251 | | - case POWER_SUPPLY_PROP_TECHNOLOGY: |
---|
252 | | - ret = sysfs_match_string(power_supply_technology_text, buf); |
---|
253 | | - break; |
---|
254 | | - case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
---|
255 | | - ret = sysfs_match_string(power_supply_capacity_level_text, buf); |
---|
256 | | - break; |
---|
257 | | - case POWER_SUPPLY_PROP_SCOPE: |
---|
258 | | - ret = sysfs_match_string(power_supply_scope_text, buf); |
---|
259 | | - break; |
---|
260 | | - default: |
---|
261 | | - ret = -EINVAL; |
---|
| 357 | + ret = -EINVAL; |
---|
| 358 | + if (ps_attr->text_values_len > 0) { |
---|
| 359 | + ret = __sysfs_match_string(ps_attr->text_values, |
---|
| 360 | + ps_attr->text_values_len, buf); |
---|
262 | 361 | } |
---|
263 | 362 | |
---|
264 | 363 | /* |
---|
.. | .. |
---|
284 | 383 | return count; |
---|
285 | 384 | } |
---|
286 | 385 | |
---|
287 | | -/* Must be in the same order as POWER_SUPPLY_PROP_* */ |
---|
288 | | -static struct device_attribute power_supply_attrs[] = { |
---|
289 | | - /* Properties of type `int' */ |
---|
290 | | - POWER_SUPPLY_ATTR(status), |
---|
291 | | - POWER_SUPPLY_ATTR(charge_type), |
---|
292 | | - POWER_SUPPLY_ATTR(health), |
---|
293 | | - POWER_SUPPLY_ATTR(present), |
---|
294 | | - POWER_SUPPLY_ATTR(online), |
---|
295 | | - POWER_SUPPLY_ATTR(authentic), |
---|
296 | | - POWER_SUPPLY_ATTR(technology), |
---|
297 | | - POWER_SUPPLY_ATTR(cycle_count), |
---|
298 | | - POWER_SUPPLY_ATTR(voltage_max), |
---|
299 | | - POWER_SUPPLY_ATTR(voltage_min), |
---|
300 | | - POWER_SUPPLY_ATTR(voltage_max_design), |
---|
301 | | - POWER_SUPPLY_ATTR(voltage_min_design), |
---|
302 | | - POWER_SUPPLY_ATTR(voltage_now), |
---|
303 | | - POWER_SUPPLY_ATTR(voltage_avg), |
---|
304 | | - POWER_SUPPLY_ATTR(voltage_ocv), |
---|
305 | | - POWER_SUPPLY_ATTR(voltage_boot), |
---|
306 | | - POWER_SUPPLY_ATTR(current_max), |
---|
307 | | - POWER_SUPPLY_ATTR(current_now), |
---|
308 | | - POWER_SUPPLY_ATTR(current_avg), |
---|
309 | | - POWER_SUPPLY_ATTR(current_boot), |
---|
310 | | - POWER_SUPPLY_ATTR(power_now), |
---|
311 | | - POWER_SUPPLY_ATTR(power_avg), |
---|
312 | | - POWER_SUPPLY_ATTR(charge_full_design), |
---|
313 | | - POWER_SUPPLY_ATTR(charge_empty_design), |
---|
314 | | - POWER_SUPPLY_ATTR(charge_full), |
---|
315 | | - POWER_SUPPLY_ATTR(charge_empty), |
---|
316 | | - POWER_SUPPLY_ATTR(charge_now), |
---|
317 | | - POWER_SUPPLY_ATTR(charge_avg), |
---|
318 | | - POWER_SUPPLY_ATTR(charge_counter), |
---|
319 | | - POWER_SUPPLY_ATTR(constant_charge_current), |
---|
320 | | - POWER_SUPPLY_ATTR(constant_charge_current_max), |
---|
321 | | - POWER_SUPPLY_ATTR(constant_charge_voltage), |
---|
322 | | - POWER_SUPPLY_ATTR(constant_charge_voltage_max), |
---|
323 | | - POWER_SUPPLY_ATTR(charge_control_limit), |
---|
324 | | - POWER_SUPPLY_ATTR(charge_control_limit_max), |
---|
325 | | - POWER_SUPPLY_ATTR(input_current_limit), |
---|
326 | | - POWER_SUPPLY_ATTR(energy_full_design), |
---|
327 | | - POWER_SUPPLY_ATTR(energy_empty_design), |
---|
328 | | - POWER_SUPPLY_ATTR(energy_full), |
---|
329 | | - POWER_SUPPLY_ATTR(energy_empty), |
---|
330 | | - POWER_SUPPLY_ATTR(energy_now), |
---|
331 | | - POWER_SUPPLY_ATTR(energy_avg), |
---|
332 | | - POWER_SUPPLY_ATTR(capacity), |
---|
333 | | - POWER_SUPPLY_ATTR(capacity_alert_min), |
---|
334 | | - POWER_SUPPLY_ATTR(capacity_alert_max), |
---|
335 | | - POWER_SUPPLY_ATTR(capacity_level), |
---|
336 | | - POWER_SUPPLY_ATTR(temp), |
---|
337 | | - POWER_SUPPLY_ATTR(temp_max), |
---|
338 | | - POWER_SUPPLY_ATTR(temp_min), |
---|
339 | | - POWER_SUPPLY_ATTR(temp_alert_min), |
---|
340 | | - POWER_SUPPLY_ATTR(temp_alert_max), |
---|
341 | | - POWER_SUPPLY_ATTR(temp_ambient), |
---|
342 | | - POWER_SUPPLY_ATTR(temp_ambient_alert_min), |
---|
343 | | - POWER_SUPPLY_ATTR(temp_ambient_alert_max), |
---|
344 | | - POWER_SUPPLY_ATTR(time_to_empty_now), |
---|
345 | | - POWER_SUPPLY_ATTR(time_to_empty_avg), |
---|
346 | | - POWER_SUPPLY_ATTR(time_to_full_now), |
---|
347 | | - POWER_SUPPLY_ATTR(time_to_full_avg), |
---|
348 | | - POWER_SUPPLY_ATTR(type), |
---|
349 | | - POWER_SUPPLY_ATTR(usb_type), |
---|
350 | | - POWER_SUPPLY_ATTR(scope), |
---|
351 | | - POWER_SUPPLY_ATTR(precharge_current), |
---|
352 | | - POWER_SUPPLY_ATTR(charge_term_current), |
---|
353 | | - POWER_SUPPLY_ATTR(calibrate), |
---|
354 | | - /* Local extensions */ |
---|
355 | | - POWER_SUPPLY_ATTR(usb_hc), |
---|
356 | | - POWER_SUPPLY_ATTR(usb_otg), |
---|
357 | | - POWER_SUPPLY_ATTR(charge_enabled), |
---|
358 | | - POWER_SUPPLY_ATTR(set_ship_mode), |
---|
359 | | - POWER_SUPPLY_ATTR(real_type), |
---|
360 | | - POWER_SUPPLY_ATTR(charge_now_raw), |
---|
361 | | - POWER_SUPPLY_ATTR(charge_now_error), |
---|
362 | | - POWER_SUPPLY_ATTR(capacity_raw), |
---|
363 | | - POWER_SUPPLY_ATTR(battery_charging_enabled), |
---|
364 | | - POWER_SUPPLY_ATTR(charging_enabled), |
---|
365 | | - POWER_SUPPLY_ATTR(step_charging_enabled), |
---|
366 | | - POWER_SUPPLY_ATTR(step_charging_step), |
---|
367 | | - POWER_SUPPLY_ATTR(pin_enabled), |
---|
368 | | - POWER_SUPPLY_ATTR(input_suspend), |
---|
369 | | - POWER_SUPPLY_ATTR(input_voltage_regulation), |
---|
370 | | - POWER_SUPPLY_ATTR(input_current_max), |
---|
371 | | - POWER_SUPPLY_ATTR(input_current_trim), |
---|
372 | | - POWER_SUPPLY_ATTR(input_current_settled), |
---|
373 | | - POWER_SUPPLY_ATTR(input_voltage_settled), |
---|
374 | | - POWER_SUPPLY_ATTR(bypass_vchg_loop_debouncer), |
---|
375 | | - POWER_SUPPLY_ATTR(charge_counter_shadow), |
---|
376 | | - POWER_SUPPLY_ATTR(hi_power), |
---|
377 | | - POWER_SUPPLY_ATTR(low_power), |
---|
378 | | - POWER_SUPPLY_ATTR(temp_cool), |
---|
379 | | - POWER_SUPPLY_ATTR(temp_warm), |
---|
380 | | - POWER_SUPPLY_ATTR(temp_cold), |
---|
381 | | - POWER_SUPPLY_ATTR(temp_hot), |
---|
382 | | - POWER_SUPPLY_ATTR(system_temp_level), |
---|
383 | | - POWER_SUPPLY_ATTR(resistance), |
---|
384 | | - POWER_SUPPLY_ATTR(resistance_capacitive), |
---|
385 | | - POWER_SUPPLY_ATTR(resistance_id), |
---|
386 | | - POWER_SUPPLY_ATTR(resistance_now), |
---|
387 | | - POWER_SUPPLY_ATTR(flash_current_max), |
---|
388 | | - POWER_SUPPLY_ATTR(update_now), |
---|
389 | | - POWER_SUPPLY_ATTR(esr_count), |
---|
390 | | - POWER_SUPPLY_ATTR(buck_freq), |
---|
391 | | - POWER_SUPPLY_ATTR(boost_current), |
---|
392 | | - POWER_SUPPLY_ATTR(safety_timer_enabled), |
---|
393 | | - POWER_SUPPLY_ATTR(charge_done), |
---|
394 | | - POWER_SUPPLY_ATTR(flash_active), |
---|
395 | | - POWER_SUPPLY_ATTR(flash_trigger), |
---|
396 | | - POWER_SUPPLY_ATTR(force_tlim), |
---|
397 | | - POWER_SUPPLY_ATTR(dp_dm), |
---|
398 | | - POWER_SUPPLY_ATTR(input_current_limited), |
---|
399 | | - POWER_SUPPLY_ATTR(input_current_now), |
---|
400 | | - POWER_SUPPLY_ATTR(charge_qnovo_enable), |
---|
401 | | - POWER_SUPPLY_ATTR(current_qnovo), |
---|
402 | | - POWER_SUPPLY_ATTR(voltage_qnovo), |
---|
403 | | - POWER_SUPPLY_ATTR(rerun_aicl), |
---|
404 | | - POWER_SUPPLY_ATTR(cycle_count_id), |
---|
405 | | - POWER_SUPPLY_ATTR(safety_timer_expired), |
---|
406 | | - POWER_SUPPLY_ATTR(restricted_charging), |
---|
407 | | - POWER_SUPPLY_ATTR(current_capability), |
---|
408 | | - POWER_SUPPLY_ATTR(typec_mode), |
---|
409 | | - POWER_SUPPLY_ATTR(typec_cc_orientation), |
---|
410 | | - POWER_SUPPLY_ATTR(typec_power_role), |
---|
411 | | - POWER_SUPPLY_ATTR(typec_src_rp), |
---|
412 | | - POWER_SUPPLY_ATTR(pd_allowed), |
---|
413 | | - POWER_SUPPLY_ATTR(pd_active), |
---|
414 | | - POWER_SUPPLY_ATTR(pd_in_hard_reset), |
---|
415 | | - POWER_SUPPLY_ATTR(pd_current_max), |
---|
416 | | - POWER_SUPPLY_ATTR(pd_usb_suspend_supported), |
---|
417 | | - POWER_SUPPLY_ATTR(charger_temp), |
---|
418 | | - POWER_SUPPLY_ATTR(charger_temp_max), |
---|
419 | | - POWER_SUPPLY_ATTR(parallel_disable), |
---|
420 | | - POWER_SUPPLY_ATTR(pe_start), |
---|
421 | | - POWER_SUPPLY_ATTR(soc_reporting_ready), |
---|
422 | | - POWER_SUPPLY_ATTR(debug_battery), |
---|
423 | | - POWER_SUPPLY_ATTR(fcc_delta), |
---|
424 | | - POWER_SUPPLY_ATTR(icl_reduction), |
---|
425 | | - POWER_SUPPLY_ATTR(parallel_mode), |
---|
426 | | - POWER_SUPPLY_ATTR(die_health), |
---|
427 | | - POWER_SUPPLY_ATTR(connector_health), |
---|
428 | | - POWER_SUPPLY_ATTR(ctm_current_max), |
---|
429 | | - POWER_SUPPLY_ATTR(hw_current_max), |
---|
430 | | - POWER_SUPPLY_ATTR(pr_swap), |
---|
431 | | - POWER_SUPPLY_ATTR(cc_step), |
---|
432 | | - POWER_SUPPLY_ATTR(cc_step_sel), |
---|
433 | | - POWER_SUPPLY_ATTR(sw_jeita_enabled), |
---|
434 | | - POWER_SUPPLY_ATTR(pd_voltage_max), |
---|
435 | | - POWER_SUPPLY_ATTR(pd_voltage_min), |
---|
436 | | - POWER_SUPPLY_ATTR(sdp_current_max), |
---|
437 | | - POWER_SUPPLY_ATTR(connector_type), |
---|
438 | | - POWER_SUPPLY_ATTR(parallel_batfet_mode), |
---|
439 | | - POWER_SUPPLY_ATTR(parallel_fcc_max), |
---|
440 | | - POWER_SUPPLY_ATTR(min_icl), |
---|
441 | | - POWER_SUPPLY_ATTR(moisture_detected), |
---|
442 | | - POWER_SUPPLY_ATTR(batt_profile_version), |
---|
443 | | - POWER_SUPPLY_ATTR(batt_full_current), |
---|
444 | | - POWER_SUPPLY_ATTR(recharge_soc), |
---|
445 | | - POWER_SUPPLY_ATTR(hvdcp_opti_allowed), |
---|
446 | | - POWER_SUPPLY_ATTR(smb_en_mode), |
---|
447 | | - POWER_SUPPLY_ATTR(smb_en_reason), |
---|
448 | | - POWER_SUPPLY_ATTR(esr_actual), |
---|
449 | | - POWER_SUPPLY_ATTR(esr_nominal), |
---|
450 | | - POWER_SUPPLY_ATTR(soh), |
---|
451 | | - POWER_SUPPLY_ATTR(clear_soh), |
---|
452 | | - POWER_SUPPLY_ATTR(force_recharge), |
---|
453 | | - POWER_SUPPLY_ATTR(fcc_stepper_enable), |
---|
454 | | - POWER_SUPPLY_ATTR(toggle_stat), |
---|
455 | | - POWER_SUPPLY_ATTR(main_fcc_max), |
---|
456 | | - POWER_SUPPLY_ATTR(fg_reset), |
---|
457 | | - POWER_SUPPLY_ATTR(qc_opti_disable), |
---|
458 | | - POWER_SUPPLY_ATTR(cc_soc), |
---|
459 | | - POWER_SUPPLY_ATTR(batt_age_level), |
---|
460 | | - POWER_SUPPLY_ATTR(scale_mode_en), |
---|
461 | | - POWER_SUPPLY_ATTR(voltage_vph), |
---|
462 | | - POWER_SUPPLY_ATTR(chip_version), |
---|
463 | | - POWER_SUPPLY_ATTR(therm_icl_limit), |
---|
464 | | - POWER_SUPPLY_ATTR(dc_reset), |
---|
465 | | - POWER_SUPPLY_ATTR(voltage_max_limit), |
---|
466 | | - POWER_SUPPLY_ATTR(real_capacity), |
---|
467 | | - POWER_SUPPLY_ATTR(force_main_icl), |
---|
468 | | - POWER_SUPPLY_ATTR(force_main_fcc), |
---|
469 | | - POWER_SUPPLY_ATTR(comp_clamp_level), |
---|
470 | | - POWER_SUPPLY_ATTR(adapter_cc_mode), |
---|
471 | | - POWER_SUPPLY_ATTR(skin_health), |
---|
472 | | - POWER_SUPPLY_ATTR(charge_disable), |
---|
473 | | - POWER_SUPPLY_ATTR(adapter_details), |
---|
474 | | - POWER_SUPPLY_ATTR(dead_battery), |
---|
475 | | - POWER_SUPPLY_ATTR(voltage_fifo), |
---|
476 | | - POWER_SUPPLY_ATTR(cc_uah), |
---|
477 | | - POWER_SUPPLY_ATTR(operating_freq), |
---|
478 | | - POWER_SUPPLY_ATTR(aicl_delay), |
---|
479 | | - POWER_SUPPLY_ATTR(aicl_icl), |
---|
480 | | - POWER_SUPPLY_ATTR(rtx), |
---|
481 | | - POWER_SUPPLY_ATTR(cutoff_soc), |
---|
482 | | - POWER_SUPPLY_ATTR(sys_soc), |
---|
483 | | - POWER_SUPPLY_ATTR(batt_soc), |
---|
484 | | - /* Capacity Estimation */ |
---|
485 | | - POWER_SUPPLY_ATTR(batt_ce_ctrl), |
---|
486 | | - POWER_SUPPLY_ATTR(batt_ce_full), |
---|
487 | | - /* Resistance Estimaton */ |
---|
488 | | - POWER_SUPPLY_ATTR(resistance_avg), |
---|
489 | | - POWER_SUPPLY_ATTR(batt_res_filt_cnts), |
---|
490 | | - POWER_SUPPLY_ATTR(aicl_done), |
---|
491 | | - POWER_SUPPLY_ATTR(voltage_step), |
---|
492 | | - POWER_SUPPLY_ATTR(otg_fastroleswap), |
---|
493 | | - POWER_SUPPLY_ATTR(apsd_rerun), |
---|
494 | | - POWER_SUPPLY_ATTR(apsd_timeout), |
---|
495 | | - /* Charge pump properties */ |
---|
496 | | - POWER_SUPPLY_ATTR(cp_status1), |
---|
497 | | - POWER_SUPPLY_ATTR(cp_status2), |
---|
498 | | - POWER_SUPPLY_ATTR(cp_enable), |
---|
499 | | - POWER_SUPPLY_ATTR(cp_switcher_en), |
---|
500 | | - POWER_SUPPLY_ATTR(cp_die_temp), |
---|
501 | | - POWER_SUPPLY_ATTR(cp_isns), |
---|
502 | | - POWER_SUPPLY_ATTR(cp_isns_slave), |
---|
503 | | - POWER_SUPPLY_ATTR(cp_toggle_switcher), |
---|
504 | | - POWER_SUPPLY_ATTR(cp_irq_status), |
---|
505 | | - POWER_SUPPLY_ATTR(cp_ilim), |
---|
506 | | - POWER_SUPPLY_ATTR(irq_status), |
---|
507 | | - POWER_SUPPLY_ATTR(parallel_output_mode), |
---|
508 | | - POWER_SUPPLY_ATTR(alignment), |
---|
509 | | - POWER_SUPPLY_ATTR(moisture_detection_enabled), |
---|
510 | | - POWER_SUPPLY_ATTR(cc_toggle_enable), |
---|
511 | | - POWER_SUPPLY_ATTR(fg_type), |
---|
512 | | - POWER_SUPPLY_ATTR(charger_status), |
---|
513 | | - /* Local extensions of type int64_t */ |
---|
514 | | - POWER_SUPPLY_ATTR(charge_counter_ext), |
---|
515 | | - POWER_SUPPLY_ATTR(charge_charger_state), |
---|
516 | | - /* Properties of type `const char *' */ |
---|
517 | | - POWER_SUPPLY_ATTR(model_name), |
---|
518 | | - POWER_SUPPLY_ATTR(ptmc_id), |
---|
519 | | - POWER_SUPPLY_ATTR(manufacturer), |
---|
520 | | - POWER_SUPPLY_ATTR(battery_type), |
---|
521 | | - POWER_SUPPLY_ATTR(cycle_counts), |
---|
522 | | - POWER_SUPPLY_ATTR(serial_number), |
---|
523 | | -}; |
---|
524 | | - |
---|
525 | | -static struct attribute * |
---|
526 | | -__power_supply_attrs[ARRAY_SIZE(power_supply_attrs) + 1]; |
---|
527 | | - |
---|
528 | 386 | static umode_t power_supply_attr_is_visible(struct kobject *kobj, |
---|
529 | 387 | struct attribute *attr, |
---|
530 | 388 | int attrno) |
---|
531 | 389 | { |
---|
532 | | - struct device *dev = container_of(kobj, struct device, kobj); |
---|
| 390 | + struct device *dev = kobj_to_dev(kobj); |
---|
533 | 391 | struct power_supply *psy = dev_get_drvdata(dev); |
---|
534 | 392 | umode_t mode = S_IRUSR | S_IRGRP | S_IROTH; |
---|
535 | 393 | int i; |
---|
| 394 | + |
---|
| 395 | + if (!power_supply_attrs[attrno].prop_name) |
---|
| 396 | + return 0; |
---|
536 | 397 | |
---|
537 | 398 | if (attrno == POWER_SUPPLY_PROP_TYPE) |
---|
538 | 399 | return mode; |
---|
.. | .. |
---|
562 | 423 | NULL, |
---|
563 | 424 | }; |
---|
564 | 425 | |
---|
| 426 | +static void str_to_lower(char *str) |
---|
| 427 | +{ |
---|
| 428 | + while (*str) { |
---|
| 429 | + *str = tolower(*str); |
---|
| 430 | + str++; |
---|
| 431 | + } |
---|
| 432 | +} |
---|
| 433 | + |
---|
565 | 434 | void power_supply_init_attrs(struct device_type *dev_type) |
---|
566 | 435 | { |
---|
567 | 436 | int i; |
---|
568 | 437 | |
---|
569 | 438 | dev_type->groups = power_supply_attr_groups; |
---|
570 | 439 | |
---|
571 | | - for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++) |
---|
572 | | - __power_supply_attrs[i] = &power_supply_attrs[i].attr; |
---|
| 440 | + for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++) { |
---|
| 441 | + struct device_attribute *attr; |
---|
| 442 | + |
---|
| 443 | + if (!power_supply_attrs[i].prop_name) { |
---|
| 444 | + pr_warn("%s: Property %d skipped because is is missing from power_supply_attrs\n", |
---|
| 445 | + __func__, i); |
---|
| 446 | + sprintf(power_supply_attrs[i].attr_name, "_err_%d", i); |
---|
| 447 | + } else { |
---|
| 448 | + str_to_lower(power_supply_attrs[i].attr_name); |
---|
| 449 | + } |
---|
| 450 | + |
---|
| 451 | + attr = &power_supply_attrs[i].dev_attr; |
---|
| 452 | + |
---|
| 453 | + attr->attr.name = power_supply_attrs[i].attr_name; |
---|
| 454 | + attr->show = power_supply_show_property; |
---|
| 455 | + attr->store = power_supply_store_property; |
---|
| 456 | + __power_supply_attrs[i] = &attr->attr; |
---|
| 457 | + } |
---|
573 | 458 | } |
---|
574 | 459 | |
---|
575 | | -static char *kstruprdup(const char *str, gfp_t gfp) |
---|
| 460 | +static int add_prop_uevent(struct device *dev, struct kobj_uevent_env *env, |
---|
| 461 | + enum power_supply_property prop, char *prop_buf) |
---|
576 | 462 | { |
---|
577 | | - char *ret, *ustr; |
---|
| 463 | + int ret = 0; |
---|
| 464 | + struct power_supply_attr *pwr_attr; |
---|
| 465 | + struct device_attribute *dev_attr; |
---|
| 466 | + char *line; |
---|
578 | 467 | |
---|
579 | | - ustr = ret = kmalloc(strlen(str) + 1, gfp); |
---|
| 468 | + pwr_attr = &power_supply_attrs[prop]; |
---|
| 469 | + dev_attr = &pwr_attr->dev_attr; |
---|
580 | 470 | |
---|
581 | | - if (!ret) |
---|
582 | | - return NULL; |
---|
| 471 | + ret = power_supply_show_property(dev, dev_attr, prop_buf); |
---|
| 472 | + if (ret == -ENODEV || ret == -ENODATA) { |
---|
| 473 | + /* |
---|
| 474 | + * When a battery is absent, we expect -ENODEV. Don't abort; |
---|
| 475 | + * send the uevent with at least the the PRESENT=0 property |
---|
| 476 | + */ |
---|
| 477 | + return 0; |
---|
| 478 | + } |
---|
583 | 479 | |
---|
584 | | - while (*str) |
---|
585 | | - *ustr++ = toupper(*str++); |
---|
| 480 | + if (ret < 0) |
---|
| 481 | + return ret; |
---|
586 | 482 | |
---|
587 | | - *ustr = 0; |
---|
| 483 | + line = strchr(prop_buf, '\n'); |
---|
| 484 | + if (line) |
---|
| 485 | + *line = 0; |
---|
588 | 486 | |
---|
589 | | - return ret; |
---|
| 487 | + return add_uevent_var(env, "POWER_SUPPLY_%s=%s", |
---|
| 488 | + pwr_attr->prop_name, prop_buf); |
---|
590 | 489 | } |
---|
591 | 490 | |
---|
592 | 491 | int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env) |
---|
.. | .. |
---|
594 | 493 | struct power_supply *psy = dev_get_drvdata(dev); |
---|
595 | 494 | int ret = 0, j; |
---|
596 | 495 | char *prop_buf; |
---|
597 | | - char *attrname; |
---|
598 | 496 | |
---|
599 | 497 | if (!psy || !psy->desc) { |
---|
600 | 498 | dev_dbg(dev, "No power supply yet\n"); |
---|
.. | .. |
---|
609 | 507 | if (!prop_buf) |
---|
610 | 508 | return -ENOMEM; |
---|
611 | 509 | |
---|
| 510 | + ret = add_prop_uevent(dev, env, POWER_SUPPLY_PROP_TYPE, prop_buf); |
---|
| 511 | + if (ret) |
---|
| 512 | + goto out; |
---|
| 513 | + |
---|
612 | 514 | for (j = 0; j < psy->desc->num_properties; j++) { |
---|
613 | | - struct device_attribute *attr; |
---|
614 | | - char *line; |
---|
615 | | - |
---|
616 | | - attr = &power_supply_attrs[psy->desc->properties[j]]; |
---|
617 | | - |
---|
618 | | - if (!attr->attr.name) { |
---|
619 | | - dev_info(dev, "%s:%d FAKE attr.name=NULL skip\n", |
---|
620 | | - __FILE__, __LINE__); |
---|
621 | | - continue; |
---|
622 | | - } |
---|
623 | | - |
---|
624 | | - ret = power_supply_show_property(dev, attr, prop_buf); |
---|
625 | | - if (ret == -ENODEV || ret == -ENODATA) { |
---|
626 | | - /* When a battery is absent, we expect -ENODEV. Don't abort; |
---|
627 | | - send the uevent with at least the the PRESENT=0 property */ |
---|
628 | | - ret = 0; |
---|
629 | | - continue; |
---|
630 | | - } |
---|
631 | | - |
---|
632 | | - if (ret < 0) |
---|
633 | | - goto out; |
---|
634 | | - |
---|
635 | | - line = strchr(prop_buf, '\n'); |
---|
636 | | - if (line) |
---|
637 | | - *line = 0; |
---|
638 | | - |
---|
639 | | - attrname = kstruprdup(attr->attr.name, GFP_KERNEL); |
---|
640 | | - if (!attrname) { |
---|
641 | | - ret = -ENOMEM; |
---|
642 | | - goto out; |
---|
643 | | - } |
---|
644 | | - |
---|
645 | | - ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s", attrname, prop_buf); |
---|
646 | | - kfree(attrname); |
---|
| 515 | + ret = add_prop_uevent(dev, env, psy->desc->properties[j], |
---|
| 516 | + prop_buf); |
---|
647 | 517 | if (ret) |
---|
648 | 518 | goto out; |
---|
649 | 519 | } |
---|