hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/acpi/ac.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * acpi_ac.c - ACPI AC Adapter Driver ($Revision: 27 $)
34 *
45 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
56 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6
- *
7
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or (at
12
- * your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * General Public License for more details.
18
- *
19
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207 */
218
229 #include <linux/kernel.h>
....@@ -26,10 +13,6 @@
2613 #include <linux/types.h>
2714 #include <linux/dmi.h>
2815 #include <linux/delay.h>
29
-#ifdef CONFIG_ACPI_PROCFS_POWER
30
-#include <linux/proc_fs.h>
31
-#include <linux/seq_file.h>
32
-#endif
3316 #include <linux/platform_device.h>
3417 #include <linux/power_supply.h>
3518 #include <linux/acpi.h>
....@@ -79,14 +62,9 @@
7962 #endif
8063 static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
8164
82
-#ifdef CONFIG_ACPI_PROCFS_POWER
83
-extern struct proc_dir_entry *acpi_lock_ac_dir(void);
84
-extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
85
-#endif
86
-
87
-
8865 static int ac_sleep_before_get_state_ms;
8966 static int ac_check_pmic = 1;
67
+static int ac_only;
9068
9169 static struct acpi_driver acpi_ac_driver = {
9270 .name = "ac",
....@@ -121,6 +99,11 @@
12199
122100 if (!ac)
123101 return -EINVAL;
102
+
103
+ if (ac_only) {
104
+ ac->state = 1;
105
+ return 0;
106
+ }
124107
125108 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL,
126109 &ac->state);
....@@ -163,77 +146,6 @@
163146 POWER_SUPPLY_PROP_ONLINE,
164147 };
165148
166
-#ifdef CONFIG_ACPI_PROCFS_POWER
167
-/* --------------------------------------------------------------------------
168
- FS Interface (/proc)
169
- -------------------------------------------------------------------------- */
170
-
171
-static struct proc_dir_entry *acpi_ac_dir;
172
-
173
-static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
174
-{
175
- struct acpi_ac *ac = seq->private;
176
-
177
-
178
- if (!ac)
179
- return 0;
180
-
181
- if (acpi_ac_get_state(ac)) {
182
- seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
183
- return 0;
184
- }
185
-
186
- seq_puts(seq, "state: ");
187
- switch (ac->state) {
188
- case ACPI_AC_STATUS_OFFLINE:
189
- seq_puts(seq, "off-line\n");
190
- break;
191
- case ACPI_AC_STATUS_ONLINE:
192
- seq_puts(seq, "on-line\n");
193
- break;
194
- default:
195
- seq_puts(seq, "unknown\n");
196
- break;
197
- }
198
-
199
- return 0;
200
-}
201
-
202
-static int acpi_ac_add_fs(struct acpi_ac *ac)
203
-{
204
- struct proc_dir_entry *entry = NULL;
205
-
206
- printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
207
- " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
208
- if (!acpi_device_dir(ac->device)) {
209
- acpi_device_dir(ac->device) =
210
- proc_mkdir(acpi_device_bid(ac->device), acpi_ac_dir);
211
- if (!acpi_device_dir(ac->device))
212
- return -ENODEV;
213
- }
214
-
215
- /* 'state' [R] */
216
- entry = proc_create_single_data(ACPI_AC_FILE_STATE, S_IRUGO,
217
- acpi_device_dir(ac->device), acpi_ac_seq_show, ac);
218
- if (!entry)
219
- return -ENODEV;
220
- return 0;
221
-}
222
-
223
-static int acpi_ac_remove_fs(struct acpi_ac *ac)
224
-{
225
-
226
- if (acpi_device_dir(ac->device)) {
227
- remove_proc_entry(ACPI_AC_FILE_STATE,
228
- acpi_device_dir(ac->device));
229
- remove_proc_entry(acpi_device_bid(ac->device), acpi_ac_dir);
230
- acpi_device_dir(ac->device) = NULL;
231
- }
232
-
233
- return 0;
234
-}
235
-#endif
236
-
237149 /* --------------------------------------------------------------------------
238150 Driver Model
239151 -------------------------------------------------------------------------- */
....@@ -249,7 +161,7 @@
249161 default:
250162 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
251163 "Unsupported event [0x%x]\n", event));
252
- /* fall through */
164
+ fallthrough;
253165 case ACPI_AC_NOTIFY_STATUS:
254166 case ACPI_NOTIFY_BUS_CHECK:
255167 case ACPI_NOTIFY_DEVICE_CHECK:
....@@ -306,29 +218,43 @@
306218 return 0;
307219 }
308220
221
+static int __init ac_only_quirk(const struct dmi_system_id *d)
222
+{
223
+ ac_only = 1;
224
+ return 0;
225
+}
226
+
227
+/* Please keep this list alphabetically sorted */
309228 static const struct dmi_system_id ac_dmi_table[] __initconst = {
310229 {
311
- /* Thinkpad e530 */
312
- .callback = thinkpad_e530_quirk,
313
- .matches = {
314
- DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
315
- DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
316
- },
317
- },
318
- {
319
- /* ECS EF20EA */
230
+ /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
320231 .callback = ac_do_not_check_pmic_quirk,
321232 .matches = {
322233 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
323234 },
324235 },
325236 {
326
- /* Lenovo Ideapad Miix 320 */
237
+ /* Kodlix GK45 returning incorrect state */
238
+ .callback = ac_only_quirk,
239
+ .matches = {
240
+ DMI_MATCH(DMI_PRODUCT_NAME, "GK45"),
241
+ },
242
+ },
243
+ {
244
+ /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
327245 .callback = ac_do_not_check_pmic_quirk,
328246 .matches = {
329
- DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
330
- DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80XF"),
331
- DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
247
+ DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
248
+ DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
249
+ DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
250
+ },
251
+ },
252
+ {
253
+ /* Lenovo Thinkpad e530, see comment in acpi_ac_notify() */
254
+ .callback = thinkpad_e530_quirk,
255
+ .matches = {
256
+ DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
257
+ DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
332258 },
333259 },
334260 {},
....@@ -360,11 +286,6 @@
360286 psy_cfg.drv_data = ac;
361287
362288 ac->charger_desc.name = acpi_device_bid(device);
363
-#ifdef CONFIG_ACPI_PROCFS_POWER
364
- result = acpi_ac_add_fs(ac);
365
- if (result)
366
- goto end;
367
-#endif
368289 ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
369290 ac->charger_desc.properties = ac_props;
370291 ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
....@@ -384,9 +305,6 @@
384305 register_acpi_notifier(&ac->battery_nb);
385306 end:
386307 if (result) {
387
-#ifdef CONFIG_ACPI_PROCFS_POWER
388
- acpi_ac_remove_fs(ac);
389
-#endif
390308 kfree(ac);
391309 }
392310
....@@ -430,10 +348,6 @@
430348 power_supply_unregister(ac->charger);
431349 unregister_acpi_notifier(&ac->battery_nb);
432350
433
-#ifdef CONFIG_ACPI_PROCFS_POWER
434
- acpi_ac_remove_fs(ac);
435
-#endif
436
-
437351 kfree(ac);
438352
439353 return 0;
....@@ -459,18 +373,8 @@
459373 }
460374 }
461375
462
-#ifdef CONFIG_ACPI_PROCFS_POWER
463
- acpi_ac_dir = acpi_lock_ac_dir();
464
- if (!acpi_ac_dir)
465
- return -ENODEV;
466
-#endif
467
-
468
-
469376 result = acpi_bus_register_driver(&acpi_ac_driver);
470377 if (result < 0) {
471
-#ifdef CONFIG_ACPI_PROCFS_POWER
472
- acpi_unlock_ac_dir(acpi_ac_dir);
473
-#endif
474378 return -ENODEV;
475379 }
476380
....@@ -480,9 +384,6 @@
480384 static void __exit acpi_ac_exit(void)
481385 {
482386 acpi_bus_unregister_driver(&acpi_ac_driver);
483
-#ifdef CONFIG_ACPI_PROCFS_POWER
484
- acpi_unlock_ac_dir(acpi_ac_dir);
485
-#endif
486387 }
487388 module_init(acpi_ac_init);
488389 module_exit(acpi_ac_exit);