blob: bbcc2b5a70d4aa53a9b014c871241e93aaab66e3 [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 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/init.h>
30#include <linux/types.h>
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000031#include <linux/dmi.h>
32#include <linux/delay.h>
Lan Tianyue63f6e22014-07-07 01:13:46 +020033#ifdef CONFIG_ACPI_PROCFS_POWER
34#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
36#endif
Zhang Ruicc8ef522013-09-25 20:39:45 +080037#include <linux/platform_device.h>
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +040038#include <linux/power_supply.h>
Lv Zheng8b484632013-12-03 08:49:16 +080039#include <linux/acpi.h>
Alexander Mezin4eee4f02014-03-12 00:58:48 +070040#include "battery.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Len Browna192a952009-07-28 16:45:54 -040042#define PREFIX "ACPI: "
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define ACPI_AC_CLASS "ac_adapter"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_AC_DEVICE_NAME "AC Adapter"
46#define ACPI_AC_FILE_STATE "state"
47#define ACPI_AC_NOTIFY_STATUS 0x80
48#define ACPI_AC_STATUS_OFFLINE 0x00
49#define ACPI_AC_STATUS_ONLINE 0x01
50#define ACPI_AC_STATUS_UNKNOWN 0xFF
51
52#define _COMPONENT ACPI_AC_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050053ACPI_MODULE_NAME("ac");
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Len Brownf52fd662007-02-12 22:42:12 -050055MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050056MODULE_DESCRIPTION("ACPI AC Adapter Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_LICENSE("GPL");
58
Lan Tianyue63f6e22014-07-07 01:13:46 +020059
Guenter Roeck98012842014-05-06 19:18:28 -070060static int acpi_ac_add(struct acpi_device *device);
61static int acpi_ac_remove(struct acpi_device *device);
62static void acpi_ac_notify(struct acpi_device *device, u32 event);
63
64static const struct acpi_device_id ac_device_ids[] = {
65 {"ACPI0003", 0},
66 {"", 0},
67};
68MODULE_DEVICE_TABLE(acpi, ac_device_ids);
69
70#ifdef CONFIG_PM_SLEEP
71static int acpi_ac_resume(struct device *dev);
72#endif
73static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
74
Lan Tianyue63f6e22014-07-07 01:13:46 +020075#ifdef CONFIG_ACPI_PROCFS_POWER
76extern struct proc_dir_entry *acpi_lock_ac_dir(void);
77extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
78static int acpi_ac_open_fs(struct inode *inode, struct file *file);
79#endif
80
81
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000082static int ac_sleep_before_get_state_ms;
83
Guenter Roeck98012842014-05-06 19:18:28 -070084static struct acpi_driver acpi_ac_driver = {
85 .name = "ac",
86 .class = ACPI_AC_CLASS,
87 .ids = ac_device_ids,
88 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
89 .ops = {
90 .add = acpi_ac_add,
91 .remove = acpi_ac_remove,
92 .notify = acpi_ac_notify,
93 },
94 .drv.pm = &acpi_ac_pm,
95};
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097struct acpi_ac {
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +010098 struct power_supply *charger;
99 struct power_supply_desc charger_desc;
Guenter Roeck98012842014-05-06 19:18:28 -0700100 struct acpi_device * device;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400101 unsigned long long state;
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700102 struct notifier_block battery_nb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100105#define to_acpi_ac(x) power_supply_get_drvdata(x)
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +0400106
Lan Tianyue63f6e22014-07-07 01:13:46 +0200107#ifdef CONFIG_ACPI_PROCFS_POWER
108static const struct file_operations acpi_ac_fops = {
109 .owner = THIS_MODULE,
110 .open = acpi_ac_open_fs,
111 .read = seq_read,
112 .llseek = seq_lseek,
113 .release = single_release,
114};
115#endif
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* --------------------------------------------------------------------------
118 AC Adapter Management
119 -------------------------------------------------------------------------- */
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121static int acpi_ac_get_state(struct acpi_ac *ac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Guenter Roeck98012842014-05-06 19:18:28 -0700123 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Guenter Roeck98012842014-05-06 19:18:28 -0700125 if (!ac)
126 return -EINVAL;
127
128 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL,
Zhang Ruicc8ef522013-09-25 20:39:45 +0800129 &ac->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (ACPI_FAILURE(status)) {
Zhang Ruicc8ef522013-09-25 20:39:45 +0800131 ACPI_EXCEPTION((AE_INFO, status,
132 "Error reading AC Adapter state"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 ac->state = ACPI_AC_STATUS_UNKNOWN;
Patrick Mocheld550d982006-06-27 00:41:40 -0400134 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
Len Brown4be44fc2005-08-05 00:44:28 -0400136
Patrick Mocheld550d982006-06-27 00:41:40 -0400137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
Zhang Rui3151dbb2010-12-08 10:40:45 +0800140/* --------------------------------------------------------------------------
141 sysfs I/F
142 -------------------------------------------------------------------------- */
143static int get_ac_property(struct power_supply *psy,
144 enum power_supply_property psp,
145 union power_supply_propval *val)
146{
147 struct acpi_ac *ac = to_acpi_ac(psy);
148
149 if (!ac)
150 return -ENODEV;
151
152 if (acpi_ac_get_state(ac))
153 return -ENODEV;
154
155 switch (psp) {
156 case POWER_SUPPLY_PROP_ONLINE:
157 val->intval = ac->state;
158 break;
159 default:
160 return -EINVAL;
161 }
162 return 0;
163}
164
165static enum power_supply_property ac_props[] = {
166 POWER_SUPPLY_PROP_ONLINE,
167};
168
Lan Tianyue63f6e22014-07-07 01:13:46 +0200169#ifdef CONFIG_ACPI_PROCFS_POWER
170/* --------------------------------------------------------------------------
171 FS Interface (/proc)
172 -------------------------------------------------------------------------- */
173
174static struct proc_dir_entry *acpi_ac_dir;
175
176static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
177{
178 struct acpi_ac *ac = seq->private;
179
180
181 if (!ac)
182 return 0;
183
184 if (acpi_ac_get_state(ac)) {
185 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
186 return 0;
187 }
188
189 seq_puts(seq, "state: ");
190 switch (ac->state) {
191 case ACPI_AC_STATUS_OFFLINE:
192 seq_puts(seq, "off-line\n");
193 break;
194 case ACPI_AC_STATUS_ONLINE:
195 seq_puts(seq, "on-line\n");
196 break;
197 default:
198 seq_puts(seq, "unknown\n");
199 break;
200 }
201
202 return 0;
203}
204
205static int acpi_ac_open_fs(struct inode *inode, struct file *file)
206{
207 return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
208}
209
210static int acpi_ac_add_fs(struct acpi_ac *ac)
211{
212 struct proc_dir_entry *entry = NULL;
213
214 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
215 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
216 if (!acpi_device_dir(ac->device)) {
217 acpi_device_dir(ac->device) =
218 proc_mkdir(acpi_device_bid(ac->device), acpi_ac_dir);
219 if (!acpi_device_dir(ac->device))
220 return -ENODEV;
221 }
222
223 /* 'state' [R] */
224 entry = proc_create_data(ACPI_AC_FILE_STATE,
225 S_IRUGO, acpi_device_dir(ac->device),
226 &acpi_ac_fops, ac);
227 if (!entry)
228 return -ENODEV;
229 return 0;
230}
231
232static int acpi_ac_remove_fs(struct acpi_ac *ac)
233{
234
235 if (acpi_device_dir(ac->device)) {
236 remove_proc_entry(ACPI_AC_FILE_STATE,
237 acpi_device_dir(ac->device));
238 remove_proc_entry(acpi_device_bid(ac->device), acpi_ac_dir);
239 acpi_device_dir(ac->device) = NULL;
240 }
241
242 return 0;
243}
244#endif
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/* --------------------------------------------------------------------------
247 Driver Model
248 -------------------------------------------------------------------------- */
249
Guenter Roeck98012842014-05-06 19:18:28 -0700250static void acpi_ac_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Guenter Roeck98012842014-05-06 19:18:28 -0700252 struct acpi_ac *ac = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400255 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 switch (event) {
Len Brownf163ff52008-06-14 01:26:37 -0400258 default:
259 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
260 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 case ACPI_AC_NOTIFY_STATUS:
Christian Lupien03d782522004-08-19 01:26:00 -0400262 case ACPI_NOTIFY_BUS_CHECK:
263 case ACPI_NOTIFY_DEVICE_CHECK:
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000264 /*
265 * A buggy BIOS may notify AC first and then sleep for
266 * a specific time before doing actual operations in the
267 * EC event handler (_Qxx). This will cause the AC state
268 * reported by the ACPI event to be incorrect, so wait for a
269 * specific time for the EC event handler to make progress.
270 */
271 if (ac_sleep_before_get_state_ms > 0)
272 msleep(ac_sleep_before_get_state_ms);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 acpi_ac_get_state(ac);
Guenter Roeck98012842014-05-06 19:18:28 -0700275 acpi_bus_generate_netlink_event(device->pnp.device_class,
276 dev_name(&device->dev), event,
277 (u32) ac->state);
278 acpi_notifier_call_chain(device, event, (u32) ac->state);
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100279 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
Patrick Mocheld550d982006-06-27 00:41:40 -0400282 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700285static int acpi_ac_battery_notify(struct notifier_block *nb,
286 unsigned long action, void *data)
287{
288 struct acpi_ac *ac = container_of(nb, struct acpi_ac, battery_nb);
289 struct acpi_bus_event *event = (struct acpi_bus_event *)data;
290
291 /*
292 * On HP Pavilion dv6-6179er AC status notifications aren't triggered
293 * when adapter is plugged/unplugged. However, battery status
294 * notifcations are triggered when battery starts charging or
295 * discharging. Re-reading AC status triggers lost AC notifications,
296 * if AC status has changed.
297 */
298 if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0 &&
299 event->type == ACPI_BATTERY_NOTIFY_STATUS)
300 acpi_ac_get_state(ac);
301
302 return NOTIFY_OK;
303}
304
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000305static int thinkpad_e530_quirk(const struct dmi_system_id *d)
306{
307 ac_sleep_before_get_state_ms = 1000;
308 return 0;
309}
310
311static struct dmi_system_id ac_dmi_table[] = {
312 {
313 .callback = thinkpad_e530_quirk,
314 .ident = "thinkpad e530",
315 .matches = {
316 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
317 DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
318 },
319 },
320 {},
321};
322
Guenter Roeck98012842014-05-06 19:18:28 -0700323static int acpi_ac_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100325 struct power_supply_config psy_cfg = {};
Len Brown4be44fc2005-08-05 00:44:28 -0400326 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400327 struct acpi_ac *ac = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Guenter Roeck98012842014-05-06 19:18:28 -0700329
330 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400331 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Burman Yan36bcbec2006-12-19 12:56:11 -0800333 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400335 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Guenter Roeck98012842014-05-06 19:18:28 -0700337 ac->device = device;
338 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
339 strcpy(acpi_device_class(device), ACPI_AC_CLASS);
340 device->driver_data = ac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 result = acpi_ac_get_state(ac);
343 if (result)
344 goto end;
345
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100346 psy_cfg.drv_data = ac;
347
348 ac->charger_desc.name = acpi_device_bid(device);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200349#ifdef CONFIG_ACPI_PROCFS_POWER
350 result = acpi_ac_add_fs(ac);
351 if (result)
352 goto end;
353#endif
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100354 ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
355 ac->charger_desc.properties = ac_props;
356 ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
357 ac->charger_desc.get_property = get_ac_property;
358 ac->charger = power_supply_register(&ac->device->dev,
359 &ac->charger_desc, &psy_cfg);
360 if (IS_ERR(ac->charger)) {
361 result = PTR_ERR(ac->charger);
Lan Tianyuf197ac12012-07-20 13:29:16 +0800362 goto end;
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Len Brown4be44fc2005-08-05 00:44:28 -0400365 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
Guenter Roeck98012842014-05-06 19:18:28 -0700366 acpi_device_name(device), acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400367 ac->state ? "on-line" : "off-line");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700369 ac->battery_nb.notifier_call = acpi_ac_battery_notify;
370 register_acpi_notifier(&ac->battery_nb);
Lan Tianyuab0fd672013-10-12 21:04:48 +0800371end:
Lan Tianyue63f6e22014-07-07 01:13:46 +0200372 if (result) {
373#ifdef CONFIG_ACPI_PROCFS_POWER
374 acpi_ac_remove_fs(ac);
375#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 kfree(ac);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000379 dmi_check_system(ac_dmi_table);
Patrick Mocheld550d982006-06-27 00:41:40 -0400380 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200383#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200384static int acpi_ac_resume(struct device *dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800385{
386 struct acpi_ac *ac;
387 unsigned old_state;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200388
389 if (!dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800390 return -EINVAL;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200391
Guenter Roeck98012842014-05-06 19:18:28 -0700392 ac = acpi_driver_data(to_acpi_device(dev));
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200393 if (!ac)
394 return -EINVAL;
395
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800396 old_state = ac->state;
397 if (acpi_ac_get_state(ac))
398 return 0;
399 if (old_state != ac->state)
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100400 kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800401 return 0;
402}
Shuah Khan06521c22014-02-12 20:19:05 -0700403#else
404#define acpi_ac_resume NULL
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200405#endif
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800406
Guenter Roeck98012842014-05-06 19:18:28 -0700407static int acpi_ac_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Guenter Roeck98012842014-05-06 19:18:28 -0700409 struct acpi_ac *ac = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Guenter Roeck98012842014-05-06 19:18:28 -0700411
412 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400413 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Guenter Roeck98012842014-05-06 19:18:28 -0700415 ac = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Krzysztof Kozlowski297d7162015-03-12 08:44:11 +0100417 power_supply_unregister(ac->charger);
Alexander Mezin4eee4f02014-03-12 00:58:48 +0700418 unregister_acpi_notifier(&ac->battery_nb);
Zhang Ruicc8ef522013-09-25 20:39:45 +0800419
Lan Tianyue63f6e22014-07-07 01:13:46 +0200420#ifdef CONFIG_ACPI_PROCFS_POWER
421 acpi_ac_remove_fs(ac);
422#endif
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 kfree(ac);
425
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Len Brown4be44fc2005-08-05 00:44:28 -0400429static int __init acpi_ac_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Rich Townsend3f86b832006-07-01 11:36:54 -0400431 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Pavel Machek4d8316d2006-08-14 22:37:22 -0700433 if (acpi_disabled)
434 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Lan Tianyue63f6e22014-07-07 01:13:46 +0200436#ifdef CONFIG_ACPI_PROCFS_POWER
437 acpi_ac_dir = acpi_lock_ac_dir();
438 if (!acpi_ac_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400439 return -ENODEV;
Lan Tianyue63f6e22014-07-07 01:13:46 +0200440#endif
441
442
443 result = acpi_bus_register_driver(&acpi_ac_driver);
444 if (result < 0) {
445#ifdef CONFIG_ACPI_PROCFS_POWER
446 acpi_unlock_ac_dir(acpi_ac_dir);
447#endif
448 return -ENODEV;
449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Patrick Mocheld550d982006-06-27 00:41:40 -0400451 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
Len Brown4be44fc2005-08-05 00:44:28 -0400454static void __exit acpi_ac_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Guenter Roeck98012842014-05-06 19:18:28 -0700456 acpi_bus_unregister_driver(&acpi_ac_driver);
Lan Tianyue63f6e22014-07-07 01:13:46 +0200457#ifdef CONFIG_ACPI_PROCFS_POWER
458 acpi_unlock_ac_dir(acpi_ac_dir);
459#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461module_init(acpi_ac_init);
462module_exit(acpi_ac_exit);