blob: cdd3136829f15182464b865be099c141a8dd4f67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_ac.c - ACPI AC Adapter Driver ($Revision: 27 $)
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * 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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/init.h>
26#include <linux/types.h>
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000027#include <linux/dmi.h>
28#include <linux/delay.h>
Lan Tianyue63f6e22014-07-07 01:13:46 +020029#ifdef CONFIG_ACPI_PROCFS_POWER
30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
32#endif
Zhang Ruicc8ef522013-09-25 20:39:45 +080033#include <linux/platform_device.h>
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +040034#include <linux/power_supply.h>
Lv Zheng8b484632013-12-03 08:49:16 +080035#include <linux/acpi.h>
Ognjen Galicfa938542018-02-07 15:58:13 +010036#include <acpi/battery.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Len Browna192a952009-07-28 16:45:54 -040038#define PREFIX "ACPI: "
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define ACPI_AC_CLASS "ac_adapter"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define ACPI_AC_DEVICE_NAME "AC Adapter"
42#define ACPI_AC_FILE_STATE "state"
43#define ACPI_AC_NOTIFY_STATUS 0x80
44#define ACPI_AC_STATUS_OFFLINE 0x00
45#define ACPI_AC_STATUS_ONLINE 0x01
46#define ACPI_AC_STATUS_UNKNOWN 0xFF
47
48#define _COMPONENT ACPI_AC_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050049ACPI_MODULE_NAME("ac");
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Len Brownf52fd662007-02-12 22:42:12 -050051MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050052MODULE_DESCRIPTION("ACPI AC Adapter Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070053MODULE_LICENSE("GPL");
54
Lan Tianyue63f6e22014-07-07 01:13:46 +020055
Guenter Roeck98012842014-05-06 19:18:28 -070056static int acpi_ac_add(struct acpi_device *device);
57static int acpi_ac_remove(struct acpi_device *device);
58static void acpi_ac_notify(struct acpi_device *device, u32 event);
59
Hans de Goedeaf3ec832017-04-19 14:02:11 +020060struct acpi_ac_bl {
61 const char *hid;
62 int hrv;
63};
64
Guenter Roeck98012842014-05-06 19:18:28 -070065static const struct acpi_device_id ac_device_ids[] = {
66 {"ACPI0003", 0},
67 {"", 0},
68};
69MODULE_DEVICE_TABLE(acpi, ac_device_ids);
70
Hans de Goedeaf3ec832017-04-19 14:02:11 +020071/* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
72static const struct acpi_ac_bl acpi_ac_blacklist[] = {
73 { "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
74 { "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
75};
76
Guenter Roeck98012842014-05-06 19:18:28 -070077#ifdef CONFIG_PM_SLEEP
78static int acpi_ac_resume(struct device *dev);
79#endif
80static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
81
Lan Tianyue63f6e22014-07-07 01:13:46 +020082#ifdef CONFIG_ACPI_PROCFS_POWER
83extern struct proc_dir_entry *acpi_lock_ac_dir(void);
84extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
Lan Tianyue63f6e22014-07-07 01:13:46 +020085#endif
86
87
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000088static int ac_sleep_before_get_state_ms;
Carlo Caione91ea5b12018-04-18 14:04:40 +020089static int ac_check_pmic = 1;
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000090
Guenter Roeck98012842014-05-06 19:18:28 -070091static struct acpi_driver acpi_ac_driver = {
92 .name = "ac",
93 .class = ACPI_AC_CLASS,
94 .ids = ac_device_ids,
95 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
96 .ops = {
97 .add = acpi_ac_add,
98 .remove = acpi_ac_remove,
99 .notify = acpi_ac_notify,
100 },
101 .drv.pm = &acpi_ac_pm,
102};
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104struct acpi_ac {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100105 struct power_supply *charger;
106 struct power_supply_desc charger_desc;
Guenter Roeck98012842014-05-06 19:18:28 -0700107 struct acpi_device * device;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400108 unsigned long long state;
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700109 struct notifier_block battery_nb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100112#define to_acpi_ac(x) power_supply_get_drvdata(x)
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +0400113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* --------------------------------------------------------------------------
115 AC Adapter Management
116 -------------------------------------------------------------------------- */
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118static int acpi_ac_get_state(struct acpi_ac *ac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Guenter Roeck98012842014-05-06 19:18:28 -0700120 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Guenter Roeck98012842014-05-06 19:18:28 -0700122 if (!ac)
123 return -EINVAL;
124
125 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL,
Zhang Ruicc8ef522013-09-25 20:39:45 +0800126 &ac->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (ACPI_FAILURE(status)) {
Zhang Ruicc8ef522013-09-25 20:39:45 +0800128 ACPI_EXCEPTION((AE_INFO, status,
129 "Error reading AC Adapter state"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 ac->state = ACPI_AC_STATUS_UNKNOWN;
Patrick Mocheld550d982006-06-27 00:41:40 -0400131 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
Len Brown4be44fc2005-08-05 00:44:28 -0400133
Patrick Mocheld550d982006-06-27 00:41:40 -0400134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
Zhang Rui3151dbb2010-12-08 10:40:45 +0800137/* --------------------------------------------------------------------------
138 sysfs I/F
139 -------------------------------------------------------------------------- */
140static int get_ac_property(struct power_supply *psy,
141 enum power_supply_property psp,
142 union power_supply_propval *val)
143{
144 struct acpi_ac *ac = to_acpi_ac(psy);
145
146 if (!ac)
147 return -ENODEV;
148
149 if (acpi_ac_get_state(ac))
150 return -ENODEV;
151
152 switch (psp) {
153 case POWER_SUPPLY_PROP_ONLINE:
154 val->intval = ac->state;
155 break;
156 default:
157 return -EINVAL;
158 }
159 return 0;
160}
161
162static enum power_supply_property ac_props[] = {
163 POWER_SUPPLY_PROP_ONLINE,
164};
165
Lan Tianyue63f6e22014-07-07 01:13:46 +0200166#ifdef CONFIG_ACPI_PROCFS_POWER
167/* --------------------------------------------------------------------------
168 FS Interface (/proc)
169 -------------------------------------------------------------------------- */
170
171static struct proc_dir_entry *acpi_ac_dir;
172
173static 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
Lan Tianyue63f6e22014-07-07 01:13:46 +0200202static 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] */
Christoph Hellwig3f3942a2018-05-15 15:57:23 +0200216 entry = proc_create_single_data(ACPI_AC_FILE_STATE, S_IRUGO,
217 acpi_device_dir(ac->device), acpi_ac_seq_show, ac);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200218 if (!entry)
219 return -ENODEV;
220 return 0;
221}
222
223static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/* --------------------------------------------------------------------------
238 Driver Model
239 -------------------------------------------------------------------------- */
240
Guenter Roeck98012842014-05-06 19:18:28 -0700241static void acpi_ac_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Guenter Roeck98012842014-05-06 19:18:28 -0700243 struct acpi_ac *ac = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400246 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 switch (event) {
Len Brownf163ff52008-06-14 01:26:37 -0400249 default:
250 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
251 "Unsupported event [0x%x]\n", event));
Gustavo A. R. Silva1be9c3a2017-10-12 13:49:18 -0500252 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 case ACPI_AC_NOTIFY_STATUS:
Christian Lupien03d78252004-08-19 01:26:00 -0400254 case ACPI_NOTIFY_BUS_CHECK:
255 case ACPI_NOTIFY_DEVICE_CHECK:
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000256 /*
257 * A buggy BIOS may notify AC first and then sleep for
258 * a specific time before doing actual operations in the
259 * EC event handler (_Qxx). This will cause the AC state
260 * reported by the ACPI event to be incorrect, so wait for a
261 * specific time for the EC event handler to make progress.
262 */
263 if (ac_sleep_before_get_state_ms > 0)
264 msleep(ac_sleep_before_get_state_ms);
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 acpi_ac_get_state(ac);
Guenter Roeck98012842014-05-06 19:18:28 -0700267 acpi_bus_generate_netlink_event(device->pnp.device_class,
268 dev_name(&device->dev), event,
269 (u32) ac->state);
270 acpi_notifier_call_chain(device, event, (u32) ac->state);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100271 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 }
273
Patrick Mocheld550d982006-06-27 00:41:40 -0400274 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700277static int acpi_ac_battery_notify(struct notifier_block *nb,
278 unsigned long action, void *data)
279{
280 struct acpi_ac *ac = container_of(nb, struct acpi_ac, battery_nb);
281 struct acpi_bus_event *event = (struct acpi_bus_event *)data;
282
283 /*
284 * On HP Pavilion dv6-6179er AC status notifications aren't triggered
285 * when adapter is plugged/unplugged. However, battery status
286 * notifcations are triggered when battery starts charging or
287 * discharging. Re-reading AC status triggers lost AC notifications,
288 * if AC status has changed.
289 */
290 if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0 &&
291 event->type == ACPI_BATTERY_NOTIFY_STATUS)
292 acpi_ac_get_state(ac);
293
294 return NOTIFY_OK;
295}
296
Carlo Caione91ea5b12018-04-18 14:04:40 +0200297static int __init thinkpad_e530_quirk(const struct dmi_system_id *d)
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000298{
299 ac_sleep_before_get_state_ms = 1000;
300 return 0;
301}
302
Carlo Caione91ea5b12018-04-18 14:04:40 +0200303static int __init ac_do_not_check_pmic_quirk(const struct dmi_system_id *d)
304{
305 ac_check_pmic = 0;
306 return 0;
307}
308
309static const struct dmi_system_id ac_dmi_table[] __initconst = {
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000310 {
Hans de Goede6605e342018-04-12 12:01:57 +0200311 /* Thinkpad e530 */
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000312 .callback = thinkpad_e530_quirk,
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000313 .matches = {
314 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
315 DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
316 },
317 },
Carlo Caione91ea5b12018-04-18 14:04:40 +0200318 {
319 /* ECS EF20EA */
320 .callback = ac_do_not_check_pmic_quirk,
321 .matches = {
322 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
323 },
324 },
325 {
326 /* Lenovo Ideapad Miix 320 */
327 .callback = ac_do_not_check_pmic_quirk,
328 .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"),
332 },
333 },
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000334 {},
335};
336
Guenter Roeck98012842014-05-06 19:18:28 -0700337static int acpi_ac_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100339 struct power_supply_config psy_cfg = {};
Len Brown4be44fc2005-08-05 00:44:28 -0400340 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400341 struct acpi_ac *ac = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Guenter Roeck98012842014-05-06 19:18:28 -0700343
344 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400345 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Burman Yan36bcbec2006-12-19 12:56:11 -0800347 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400349 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Guenter Roeck98012842014-05-06 19:18:28 -0700351 ac->device = device;
352 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
353 strcpy(acpi_device_class(device), ACPI_AC_CLASS);
354 device->driver_data = ac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 result = acpi_ac_get_state(ac);
357 if (result)
358 goto end;
359
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100360 psy_cfg.drv_data = ac;
361
362 ac->charger_desc.name = acpi_device_bid(device);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200363#ifdef CONFIG_ACPI_PROCFS_POWER
364 result = acpi_ac_add_fs(ac);
365 if (result)
366 goto end;
367#endif
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100368 ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
369 ac->charger_desc.properties = ac_props;
370 ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
371 ac->charger_desc.get_property = get_ac_property;
372 ac->charger = power_supply_register(&ac->device->dev,
373 &ac->charger_desc, &psy_cfg);
374 if (IS_ERR(ac->charger)) {
375 result = PTR_ERR(ac->charger);
Lan Tianyuf197ac12012-07-20 13:29:16 +0800376 goto end;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
Guenter Roeck98012842014-05-06 19:18:28 -0700380 acpi_device_name(device), acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400381 ac->state ? "on-line" : "off-line");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700383 ac->battery_nb.notifier_call = acpi_ac_battery_notify;
384 register_acpi_notifier(&ac->battery_nb);
Lan Tianyuab0fd672013-10-12 21:04:48 +0800385end:
Lan Tianyue63f6e22014-07-07 01:13:46 +0200386 if (result) {
387#ifdef CONFIG_ACPI_PROCFS_POWER
388 acpi_ac_remove_fs(ac);
389#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 kfree(ac);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Patrick Mocheld550d982006-06-27 00:41:40 -0400393 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200396#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200397static int acpi_ac_resume(struct device *dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800398{
399 struct acpi_ac *ac;
400 unsigned old_state;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200401
402 if (!dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800403 return -EINVAL;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200404
Guenter Roeck98012842014-05-06 19:18:28 -0700405 ac = acpi_driver_data(to_acpi_device(dev));
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200406 if (!ac)
407 return -EINVAL;
408
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800409 old_state = ac->state;
410 if (acpi_ac_get_state(ac))
411 return 0;
412 if (old_state != ac->state)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100413 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800414 return 0;
415}
Shuah Khan06521c22014-02-12 20:19:05 -0700416#else
417#define acpi_ac_resume NULL
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200418#endif
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800419
Guenter Roeck98012842014-05-06 19:18:28 -0700420static int acpi_ac_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Guenter Roeck98012842014-05-06 19:18:28 -0700422 struct acpi_ac *ac = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Guenter Roeck98012842014-05-06 19:18:28 -0700424
425 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Guenter Roeck98012842014-05-06 19:18:28 -0700428 ac = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100430 power_supply_unregister(ac->charger);
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700431 unregister_acpi_notifier(&ac->battery_nb);
Zhang Ruicc8ef522013-09-25 20:39:45 +0800432
Lan Tianyue63f6e22014-07-07 01:13:46 +0200433#ifdef CONFIG_ACPI_PROCFS_POWER
434 acpi_ac_remove_fs(ac);
435#endif
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 kfree(ac);
438
Patrick Mocheld550d982006-06-27 00:41:40 -0400439 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Len Brown4be44fc2005-08-05 00:44:28 -0400442static int __init acpi_ac_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Hans de Goedeaf3ec832017-04-19 14:02:11 +0200444 unsigned int i;
Rich Townsend3f86b832006-07-01 11:36:54 -0400445 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Pavel Machek4d8316d2006-08-14 22:37:22 -0700447 if (acpi_disabled)
448 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Carlo Caione91ea5b12018-04-18 14:04:40 +0200450 dmi_check_system(ac_dmi_table);
451
452 if (ac_check_pmic) {
453 for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++)
454 if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1",
455 acpi_ac_blacklist[i].hrv)) {
456 pr_info(PREFIX "AC: found native %s PMIC, not loading\n",
457 acpi_ac_blacklist[i].hid);
458 return -ENODEV;
459 }
460 }
Hans de Goedeaf3ec832017-04-19 14:02:11 +0200461
Lan Tianyue63f6e22014-07-07 01:13:46 +0200462#ifdef CONFIG_ACPI_PROCFS_POWER
463 acpi_ac_dir = acpi_lock_ac_dir();
464 if (!acpi_ac_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400465 return -ENODEV;
Lan Tianyue63f6e22014-07-07 01:13:46 +0200466#endif
467
468
469 result = acpi_bus_register_driver(&acpi_ac_driver);
470 if (result < 0) {
471#ifdef CONFIG_ACPI_PROCFS_POWER
472 acpi_unlock_ac_dir(acpi_ac_dir);
473#endif
474 return -ENODEV;
475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Patrick Mocheld550d982006-06-27 00:41:40 -0400477 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Len Brown4be44fc2005-08-05 00:44:28 -0400480static void __exit acpi_ac_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Guenter Roeck98012842014-05-06 19:18:28 -0700482 acpi_bus_unregister_driver(&acpi_ac_driver);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200483#ifdef CONFIG_ACPI_PROCFS_POWER
484 acpi_unlock_ac_dir(acpi_ac_dir);
485#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487module_init(acpi_ac_init);
488module_exit(acpi_ac_exit);