hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/drivers/acpi/battery.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * battery.c - ACPI Battery Driver (Revision: 2.0)
34 *
....@@ -5,20 +6,6 @@
56 * Copyright (C) 2004-2007 Vladimir Lebedev <vladimir.p.lebedev@intel.com>
67 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
78 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
8
- *
9
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License as published by
13
- * the Free Software Foundation; either version 2 of the License, or (at
14
- * your option) any later version.
15
- *
16
- * This program is distributed in the hope that it will be useful, but
17
- * WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
- * General Public License for more details.
20
- *
21
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229 */
2310
2411 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -36,12 +23,6 @@
3623 #include <linux/types.h>
3724
3825 #include <asm/unaligned.h>
39
-
40
-#ifdef CONFIG_ACPI_PROCFS_POWER
41
-#include <linux/proc_fs.h>
42
-#include <linux/seq_file.h>
43
-#include <linux/uaccess.h>
44
-#endif
4526
4627 #include <linux/acpi.h>
4728 #include <linux/power_supply.h>
....@@ -83,13 +64,12 @@
8364 module_param(cache_time, uint, 0644);
8465 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
8566
86
-#ifdef CONFIG_ACPI_PROCFS_POWER
87
-extern struct proc_dir_entry *acpi_lock_battery_dir(void);
88
-extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
89
-#endif
90
-
9167 static const struct acpi_device_id battery_device_ids[] = {
9268 {"PNP0C0A", 0},
69
+
70
+ /* Microsoft Surface Go 3 */
71
+ {"MSHW0146", 0},
72
+
9373 {"", 0},
9474 };
9575
....@@ -474,7 +454,7 @@
474454 u8 *ptr = (u8 *)battery + offsets[i].offset;
475455 if (element->type == ACPI_TYPE_STRING ||
476456 element->type == ACPI_TYPE_BUFFER)
477
- strncpy(ptr, element->string.pointer, 32);
457
+ strscpy(ptr, element->string.pointer, 32);
478458 else if (element->type == ACPI_TYPE_INTEGER) {
479459 strncpy(ptr, (u8 *)&element->integer.value,
480460 sizeof(u64));
....@@ -1014,7 +994,7 @@
1014994 */
1015995 if ((battery->state & ACPI_BATTERY_STATE_CRITICAL) ||
1016996 (test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
1017
- (battery->capacity_now <= battery->alarm)))
997
+ (battery->capacity_now <= battery->alarm)))
1018998 acpi_pm_wakeup_event(&battery->device->dev);
1019999
10201000 return result;
....@@ -1038,227 +1018,6 @@
10381018 sysfs_remove_battery(battery);
10391019 sysfs_add_battery(battery);
10401020 }
1041
-
1042
-/* --------------------------------------------------------------------------
1043
- FS Interface (/proc)
1044
- -------------------------------------------------------------------------- */
1045
-
1046
-#ifdef CONFIG_ACPI_PROCFS_POWER
1047
-static struct proc_dir_entry *acpi_battery_dir;
1048
-
1049
-static const char *acpi_battery_units(const struct acpi_battery *battery)
1050
-{
1051
- return (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) ?
1052
- "mA" : "mW";
1053
-}
1054
-
1055
-static int acpi_battery_info_proc_show(struct seq_file *seq, void *offset)
1056
-{
1057
- struct acpi_battery *battery = seq->private;
1058
- int result = acpi_battery_update(battery, false);
1059
-
1060
- if (result)
1061
- goto end;
1062
-
1063
- seq_printf(seq, "present: %s\n",
1064
- acpi_battery_present(battery) ? "yes" : "no");
1065
- if (!acpi_battery_present(battery))
1066
- goto end;
1067
- if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
1068
- seq_printf(seq, "design capacity: unknown\n");
1069
- else
1070
- seq_printf(seq, "design capacity: %d %sh\n",
1071
- battery->design_capacity,
1072
- acpi_battery_units(battery));
1073
-
1074
- if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
1075
- seq_printf(seq, "last full capacity: unknown\n");
1076
- else
1077
- seq_printf(seq, "last full capacity: %d %sh\n",
1078
- battery->full_charge_capacity,
1079
- acpi_battery_units(battery));
1080
-
1081
- seq_printf(seq, "battery technology: %srechargeable\n",
1082
- battery->technology ? "" : "non-");
1083
-
1084
- if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
1085
- seq_printf(seq, "design voltage: unknown\n");
1086
- else
1087
- seq_printf(seq, "design voltage: %d mV\n",
1088
- battery->design_voltage);
1089
- seq_printf(seq, "design capacity warning: %d %sh\n",
1090
- battery->design_capacity_warning,
1091
- acpi_battery_units(battery));
1092
- seq_printf(seq, "design capacity low: %d %sh\n",
1093
- battery->design_capacity_low,
1094
- acpi_battery_units(battery));
1095
- seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
1096
- seq_printf(seq, "capacity granularity 1: %d %sh\n",
1097
- battery->capacity_granularity_1,
1098
- acpi_battery_units(battery));
1099
- seq_printf(seq, "capacity granularity 2: %d %sh\n",
1100
- battery->capacity_granularity_2,
1101
- acpi_battery_units(battery));
1102
- seq_printf(seq, "model number: %s\n", battery->model_number);
1103
- seq_printf(seq, "serial number: %s\n", battery->serial_number);
1104
- seq_printf(seq, "battery type: %s\n", battery->type);
1105
- seq_printf(seq, "OEM info: %s\n", battery->oem_info);
1106
- end:
1107
- if (result)
1108
- seq_printf(seq, "ERROR: Unable to read battery info\n");
1109
- return result;
1110
-}
1111
-
1112
-static int acpi_battery_state_proc_show(struct seq_file *seq, void *offset)
1113
-{
1114
- struct acpi_battery *battery = seq->private;
1115
- int result = acpi_battery_update(battery, false);
1116
-
1117
- if (result)
1118
- goto end;
1119
-
1120
- seq_printf(seq, "present: %s\n",
1121
- acpi_battery_present(battery) ? "yes" : "no");
1122
- if (!acpi_battery_present(battery))
1123
- goto end;
1124
-
1125
- seq_printf(seq, "capacity state: %s\n",
1126
- (battery->state & 0x04) ? "critical" : "ok");
1127
- if ((battery->state & 0x01) && (battery->state & 0x02))
1128
- seq_printf(seq,
1129
- "charging state: charging/discharging\n");
1130
- else if (battery->state & 0x01)
1131
- seq_printf(seq, "charging state: discharging\n");
1132
- else if (battery->state & 0x02)
1133
- seq_printf(seq, "charging state: charging\n");
1134
- else
1135
- seq_printf(seq, "charging state: charged\n");
1136
-
1137
- if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
1138
- seq_printf(seq, "present rate: unknown\n");
1139
- else
1140
- seq_printf(seq, "present rate: %d %s\n",
1141
- battery->rate_now, acpi_battery_units(battery));
1142
-
1143
- if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
1144
- seq_printf(seq, "remaining capacity: unknown\n");
1145
- else
1146
- seq_printf(seq, "remaining capacity: %d %sh\n",
1147
- battery->capacity_now, acpi_battery_units(battery));
1148
- if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
1149
- seq_printf(seq, "present voltage: unknown\n");
1150
- else
1151
- seq_printf(seq, "present voltage: %d mV\n",
1152
- battery->voltage_now);
1153
- end:
1154
- if (result)
1155
- seq_printf(seq, "ERROR: Unable to read battery state\n");
1156
-
1157
- return result;
1158
-}
1159
-
1160
-static int acpi_battery_alarm_proc_show(struct seq_file *seq, void *offset)
1161
-{
1162
- struct acpi_battery *battery = seq->private;
1163
- int result = acpi_battery_update(battery, false);
1164
-
1165
- if (result)
1166
- goto end;
1167
-
1168
- if (!acpi_battery_present(battery)) {
1169
- seq_printf(seq, "present: no\n");
1170
- goto end;
1171
- }
1172
- seq_printf(seq, "alarm: ");
1173
- if (battery->alarm) {
1174
- seq_printf(seq, "%u %sh\n", battery->alarm,
1175
- acpi_battery_units(battery));
1176
- } else {
1177
- seq_printf(seq, "unsupported\n");
1178
- }
1179
- end:
1180
- if (result)
1181
- seq_printf(seq, "ERROR: Unable to read battery alarm\n");
1182
- return result;
1183
-}
1184
-
1185
-static ssize_t acpi_battery_write_alarm(struct file *file,
1186
- const char __user * buffer,
1187
- size_t count, loff_t * ppos)
1188
-{
1189
- int result = 0;
1190
- char alarm_string[12] = { '\0' };
1191
- struct seq_file *m = file->private_data;
1192
- struct acpi_battery *battery = m->private;
1193
-
1194
- if (!battery || (count > sizeof(alarm_string) - 1))
1195
- return -EINVAL;
1196
- if (!acpi_battery_present(battery)) {
1197
- result = -ENODEV;
1198
- goto end;
1199
- }
1200
- if (copy_from_user(alarm_string, buffer, count)) {
1201
- result = -EFAULT;
1202
- goto end;
1203
- }
1204
- alarm_string[count] = '\0';
1205
- if (kstrtoint(alarm_string, 0, &battery->alarm)) {
1206
- result = -EINVAL;
1207
- goto end;
1208
- }
1209
- result = acpi_battery_set_alarm(battery);
1210
- end:
1211
- if (result)
1212
- return result;
1213
- return count;
1214
-}
1215
-
1216
-static int acpi_battery_alarm_proc_open(struct inode *inode, struct file *file)
1217
-{
1218
- return single_open(file, acpi_battery_alarm_proc_show, PDE_DATA(inode));
1219
-}
1220
-
1221
-static const struct file_operations acpi_battery_alarm_fops = {
1222
- .owner = THIS_MODULE,
1223
- .open = acpi_battery_alarm_proc_open,
1224
- .read = seq_read,
1225
- .write = acpi_battery_write_alarm,
1226
- .llseek = seq_lseek,
1227
- .release = single_release,
1228
-};
1229
-
1230
-static int acpi_battery_add_fs(struct acpi_device *device)
1231
-{
1232
- pr_warning(PREFIX "Deprecated procfs I/F for battery is loaded, please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
1233
- if (!acpi_device_dir(device)) {
1234
- acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1235
- acpi_battery_dir);
1236
- if (!acpi_device_dir(device))
1237
- return -ENODEV;
1238
- }
1239
-
1240
- if (!proc_create_single_data("info", S_IRUGO, acpi_device_dir(device),
1241
- acpi_battery_info_proc_show, acpi_driver_data(device)))
1242
- return -ENODEV;
1243
- if (!proc_create_single_data("state", S_IRUGO, acpi_device_dir(device),
1244
- acpi_battery_state_proc_show, acpi_driver_data(device)))
1245
- return -ENODEV;
1246
- if (!proc_create_data("alarm", S_IFREG | S_IRUGO | S_IWUSR,
1247
- acpi_device_dir(device), &acpi_battery_alarm_fops,
1248
- acpi_driver_data(device)))
1249
- return -ENODEV;
1250
- return 0;
1251
-}
1252
-
1253
-static void acpi_battery_remove_fs(struct acpi_device *device)
1254
-{
1255
- if (!acpi_device_dir(device))
1256
- return;
1257
- remove_proc_subtree(acpi_device_bid(device), acpi_battery_dir);
1258
- acpi_device_dir(device) = NULL;
1259
-}
1260
-
1261
-#endif
12621021
12631022 /* --------------------------------------------------------------------------
12641023 Driver Interface
....@@ -1388,19 +1147,19 @@
13881147 },
13891148 },
13901149 {
1391
- /* ECS EF20EA */
1150
+ /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
13921151 .callback = battery_do_not_check_pmic_quirk,
13931152 .matches = {
13941153 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
13951154 },
13961155 },
13971156 {
1398
- /* Lenovo Ideapad Miix 320 */
1157
+ /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
13991158 .callback = battery_do_not_check_pmic_quirk,
14001159 .matches = {
1401
- DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1402
- DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80XF"),
1403
- DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
1160
+ DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1161
+ DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
1162
+ DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
14041163 },
14051164 },
14061165 {
....@@ -1414,6 +1173,14 @@
14141173 .matches = {
14151174 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
14161175 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
1176
+ },
1177
+ },
1178
+ {
1179
+ /* Microsoft Surface Go 3 */
1180
+ .callback = battery_notification_delay_quirk,
1181
+ .matches = {
1182
+ DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
1183
+ DMI_MATCH(DMI_PRODUCT_NAME, "Surface Go 3"),
14171184 },
14181185 },
14191186 {},
....@@ -1468,14 +1235,6 @@
14681235 if (result)
14691236 goto fail;
14701237
1471
-#ifdef CONFIG_ACPI_PROCFS_POWER
1472
- result = acpi_battery_add_fs(device);
1473
- if (result) {
1474
- acpi_battery_remove_fs(device);
1475
- goto fail;
1476
- }
1477
-#endif
1478
-
14791238 pr_info(PREFIX "%s Slot [%s] (battery %s)\n",
14801239 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
14811240 device->status.battery_present ? "present" : "absent");
....@@ -1504,9 +1263,6 @@
15041263 device_init_wakeup(&device->dev, 0);
15051264 battery = acpi_driver_data(device);
15061265 unregister_pm_notifier(&battery->pm_nb);
1507
-#ifdef CONFIG_ACPI_PROCFS_POWER
1508
- acpi_battery_remove_fs(device);
1509
-#endif
15101266 sysfs_remove_battery(battery);
15111267 mutex_destroy(&battery->lock);
15121268 mutex_destroy(&battery->sysfs_lock);
....@@ -1567,16 +1323,7 @@
15671323 }
15681324 }
15691325
1570
-#ifdef CONFIG_ACPI_PROCFS_POWER
1571
- acpi_battery_dir = acpi_lock_battery_dir();
1572
- if (!acpi_battery_dir)
1573
- return;
1574
-#endif
15751326 result = acpi_bus_register_driver(&acpi_battery_driver);
1576
-#ifdef CONFIG_ACPI_PROCFS_POWER
1577
- if (result < 0)
1578
- acpi_unlock_battery_dir(acpi_battery_dir);
1579
-#endif
15801327 battery_driver_registered = (result == 0);
15811328 }
15821329
....@@ -1596,10 +1343,6 @@
15961343 acpi_bus_unregister_driver(&acpi_battery_driver);
15971344 battery_hook_exit();
15981345 }
1599
-#ifdef CONFIG_ACPI_PROCFS_POWER
1600
- if (acpi_battery_dir)
1601
- acpi_unlock_battery_dir(acpi_battery_dir);
1602
-#endif
16031346 }
16041347
16051348 module_init(acpi_battery_init);