blob: 324b5a096effffc8110460df01336fb77e1894d2 [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>
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030033#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -080036#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h>
41
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
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030059#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -040060extern struct proc_dir_entry *acpi_lock_ac_dir(void);
61extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -080062static int acpi_ac_open_fs(struct inode *inode, struct file *file);
63#endif
Rich Townsend3f86b832006-07-01 11:36:54 -040064
Lan Tianyu0ab5bb62013-05-08 07:28:46 +000065static int ac_sleep_before_get_state_ms;
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067struct acpi_ac {
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +040068 struct power_supply charger;
Zhang Ruicc8ef522013-09-25 20:39:45 +080069 struct acpi_device *adev;
70 struct platform_device *pdev;
Matthew Wilcox27663c52008-10-10 02:22:59 -040071 unsigned long long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
Phil Carmody497888c2011-07-14 15:07:13 +030074#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger)
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +040075
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +030076#ifdef CONFIG_ACPI_PROCFS_POWER
Arjan van de Vend7508032006-07-04 13:06:00 -040077static const struct file_operations acpi_ac_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -070078 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -040079 .open = acpi_ac_open_fs,
80 .read = seq_read,
81 .llseek = seq_lseek,
82 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -080084#endif
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +040085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* --------------------------------------------------------------------------
87 AC Adapter Management
88 -------------------------------------------------------------------------- */
89
Len Brown4be44fc2005-08-05 00:44:28 -040090static int acpi_ac_get_state(struct acpi_ac *ac)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Zhang Ruicc8ef522013-09-25 20:39:45 +080092 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Zhang Ruicc8ef522013-09-25 20:39:45 +080094 status = acpi_evaluate_integer(ac->adev->handle, "_PSR", NULL,
95 &ac->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (ACPI_FAILURE(status)) {
Zhang Ruicc8ef522013-09-25 20:39:45 +080097 ACPI_EXCEPTION((AE_INFO, status,
98 "Error reading AC Adapter state"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 ac->state = ACPI_AC_STATUS_UNKNOWN;
Patrick Mocheld550d982006-06-27 00:41:40 -0400100 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
Len Brown4be44fc2005-08-05 00:44:28 -0400102
Patrick Mocheld550d982006-06-27 00:41:40 -0400103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Zhang Rui3151dbb2010-12-08 10:40:45 +0800106/* --------------------------------------------------------------------------
107 sysfs I/F
108 -------------------------------------------------------------------------- */
109static int get_ac_property(struct power_supply *psy,
110 enum power_supply_property psp,
111 union power_supply_propval *val)
112{
113 struct acpi_ac *ac = to_acpi_ac(psy);
114
115 if (!ac)
116 return -ENODEV;
117
118 if (acpi_ac_get_state(ac))
119 return -ENODEV;
120
121 switch (psp) {
122 case POWER_SUPPLY_PROP_ONLINE:
123 val->intval = ac->state;
124 break;
125 default:
126 return -EINVAL;
127 }
128 return 0;
129}
130
131static enum power_supply_property ac_props[] = {
132 POWER_SUPPLY_PROP_ONLINE,
133};
134
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300135#ifdef CONFIG_ACPI_PROCFS_POWER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* --------------------------------------------------------------------------
137 FS Interface (/proc)
138 -------------------------------------------------------------------------- */
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140static struct proc_dir_entry *acpi_ac_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
143{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200144 struct acpi_ac *ac = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400148 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 if (acpi_ac_get_state(ac)) {
151 seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400152 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154
155 seq_puts(seq, "state: ");
156 switch (ac->state) {
157 case ACPI_AC_STATUS_OFFLINE:
158 seq_puts(seq, "off-line\n");
159 break;
160 case ACPI_AC_STATUS_ONLINE:
161 seq_puts(seq, "on-line\n");
162 break;
163 default:
164 seq_puts(seq, "unknown\n");
165 break;
166 }
167
Patrick Mocheld550d982006-06-27 00:41:40 -0400168 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
Len Brown4be44fc2005-08-05 00:44:28 -0400170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static int acpi_ac_open_fs(struct inode *inode, struct file *file)
172{
Al Virod9dda782013-03-31 18:16:14 -0400173 return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Zhang Ruicc8ef522013-09-25 20:39:45 +0800176static int acpi_ac_add_fs(struct acpi_ac *ac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Len Brown4be44fc2005-08-05 00:44:28 -0400178 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Zhang Rui6d855fc2011-01-10 11:16:30 +0800180 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
181 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
Zhang Ruicc8ef522013-09-25 20:39:45 +0800182 if (!acpi_device_dir(ac->adev)) {
183 acpi_device_dir(ac->adev) =
184 proc_mkdir(acpi_device_bid(ac->adev), acpi_ac_dir);
185 if (!acpi_device_dir(ac->adev))
Patrick Mocheld550d982006-06-27 00:41:40 -0400186 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 /* 'state' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700190 entry = proc_create_data(ACPI_AC_FILE_STATE,
Zhang Ruicc8ef522013-09-25 20:39:45 +0800191 S_IRUGO, acpi_device_dir(ac->adev),
192 &acpi_ac_fops, ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400194 return -ENODEV;
Patrick Mocheld550d982006-06-27 00:41:40 -0400195 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Zhang Ruicc8ef522013-09-25 20:39:45 +0800198static int acpi_ac_remove_fs(struct acpi_ac *ac)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Zhang Ruicc8ef522013-09-25 20:39:45 +0800201 if (acpi_device_dir(ac->adev)) {
202 remove_proc_entry(ACPI_AC_FILE_STATE,
203 acpi_device_dir(ac->adev));
204 remove_proc_entry(acpi_device_bid(ac->adev), acpi_ac_dir);
205 acpi_device_dir(ac->adev) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
Patrick Mocheld550d982006-06-27 00:41:40 -0400208 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800210#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/* --------------------------------------------------------------------------
213 Driver Model
214 -------------------------------------------------------------------------- */
215
Zhang Ruicc8ef522013-09-25 20:39:45 +0800216static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Zhang Ruicc8ef522013-09-25 20:39:45 +0800218 struct acpi_ac *ac = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400221 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 switch (event) {
Len Brownf163ff52008-06-14 01:26:37 -0400224 default:
225 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
226 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 case ACPI_AC_NOTIFY_STATUS:
Christian Lupien03d78252004-08-19 01:26:00 -0400228 case ACPI_NOTIFY_BUS_CHECK:
229 case ACPI_NOTIFY_DEVICE_CHECK:
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000230 /*
231 * A buggy BIOS may notify AC first and then sleep for
232 * a specific time before doing actual operations in the
233 * EC event handler (_Qxx). This will cause the AC state
234 * reported by the ACPI event to be incorrect, so wait for a
235 * specific time for the EC event handler to make progress.
236 */
237 if (ac_sleep_before_get_state_ms > 0)
238 msleep(ac_sleep_before_get_state_ms);
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 acpi_ac_get_state(ac);
Zhang Ruicc8ef522013-09-25 20:39:45 +0800241 acpi_bus_generate_netlink_event(ac->adev->pnp.device_class,
242 dev_name(&ac->pdev->dev),
243 event, (u32) ac->state);
244 acpi_notifier_call_chain(ac->adev, event, (u32) ac->state);
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +0400245 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
Patrick Mocheld550d982006-06-27 00:41:40 -0400248 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000251static int thinkpad_e530_quirk(const struct dmi_system_id *d)
252{
253 ac_sleep_before_get_state_ms = 1000;
254 return 0;
255}
256
257static struct dmi_system_id ac_dmi_table[] = {
258 {
259 .callback = thinkpad_e530_quirk,
260 .ident = "thinkpad e530",
261 .matches = {
262 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
263 DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
264 },
265 },
266 {},
267};
268
Zhang Ruicc8ef522013-09-25 20:39:45 +0800269static int acpi_ac_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Len Brown4be44fc2005-08-05 00:44:28 -0400271 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400272 struct acpi_ac *ac = NULL;
Zhang Ruicc8ef522013-09-25 20:39:45 +0800273 struct acpi_device *adev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Zhang Ruicc8ef522013-09-25 20:39:45 +0800275 if (!pdev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400276 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Zhang Ruicc8ef522013-09-25 20:39:45 +0800278 result = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
279 if (result)
280 return -ENODEV;
281
Burman Yan36bcbec2006-12-19 12:56:11 -0800282 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (!ac)
Patrick Mocheld550d982006-06-27 00:41:40 -0400284 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Zhang Ruicc8ef522013-09-25 20:39:45 +0800286 strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
287 strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
288 ac->adev = adev;
289 ac->pdev = pdev;
290 platform_set_drvdata(pdev, ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 result = acpi_ac_get_state(ac);
293 if (result)
294 goto end;
295
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300296#ifdef CONFIG_ACPI_PROCFS_POWER
Zhang Ruicc8ef522013-09-25 20:39:45 +0800297 result = acpi_ac_add_fs(ac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (result)
299 goto end;
Zhang Ruicc8ef522013-09-25 20:39:45 +0800300#endif
301 ac->charger.name = acpi_device_bid(adev);
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +0400302 ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
303 ac->charger.properties = ac_props;
304 ac->charger.num_properties = ARRAY_SIZE(ac_props);
305 ac->charger.get_property = get_ac_property;
Zhang Ruicc8ef522013-09-25 20:39:45 +0800306 result = power_supply_register(&pdev->dev, &ac->charger);
Lan Tianyuf197ac12012-07-20 13:29:16 +0800307 if (result)
308 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Zhang Ruicc8ef522013-09-25 20:39:45 +0800310 result = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev),
311 ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler, ac);
312 if (result) {
313 power_supply_unregister(&ac->charger);
314 goto end;
315 }
Len Brown4be44fc2005-08-05 00:44:28 -0400316 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
Zhang Ruicc8ef522013-09-25 20:39:45 +0800317 acpi_device_name(adev), acpi_device_bid(adev),
Len Brown4be44fc2005-08-05 00:44:28 -0400318 ac->state ? "on-line" : "off-line");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Len Brown4be44fc2005-08-05 00:44:28 -0400320 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (result) {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300322#ifdef CONFIG_ACPI_PROCFS_POWER
Zhang Ruicc8ef522013-09-25 20:39:45 +0800323 acpi_ac_remove_fs(ac);
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800324#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 kfree(ac);
326 }
327
Lan Tianyu0ab5bb62013-05-08 07:28:46 +0000328 dmi_check_system(ac_dmi_table);
Patrick Mocheld550d982006-06-27 00:41:40 -0400329 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200332#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200333static int acpi_ac_resume(struct device *dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800334{
335 struct acpi_ac *ac;
336 unsigned old_state;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200337
338 if (!dev)
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800339 return -EINVAL;
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200340
Zhang Ruicc8ef522013-09-25 20:39:45 +0800341 ac = platform_get_drvdata(to_platform_device(dev));
Rafael J. Wysockiccda7062012-06-27 23:26:35 +0200342 if (!ac)
343 return -EINVAL;
344
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800345 old_state = ac->state;
346 if (acpi_ac_get_state(ac))
347 return 0;
348 if (old_state != ac->state)
349 kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
350 return 0;
351}
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200352#endif
Zhang Ruicc8ef522013-09-25 20:39:45 +0800353static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume);
Alexey Starikovskiy5bfeca32007-11-14 17:00:39 -0800354
Zhang Ruicc8ef522013-09-25 20:39:45 +0800355static int acpi_ac_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Zhang Ruicc8ef522013-09-25 20:39:45 +0800357 struct acpi_ac *ac;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Zhang Ruicc8ef522013-09-25 20:39:45 +0800359 if (!pdev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400360 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Zhang Ruicc8ef522013-09-25 20:39:45 +0800362 acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev),
363 ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Zhang Ruicc8ef522013-09-25 20:39:45 +0800365 ac = platform_get_drvdata(pdev);
Alexey Starikovskiyd5b4a3d2007-09-26 19:44:06 +0400366 if (ac->charger.dev)
367 power_supply_unregister(&ac->charger);
Zhang Ruicc8ef522013-09-25 20:39:45 +0800368
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300369#ifdef CONFIG_ACPI_PROCFS_POWER
Zhang Ruicc8ef522013-09-25 20:39:45 +0800370 acpi_ac_remove_fs(ac);
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800371#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 kfree(ac);
374
Patrick Mocheld550d982006-06-27 00:41:40 -0400375 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Zhang Ruicc8ef522013-09-25 20:39:45 +0800378static const struct acpi_device_id acpi_ac_match[] = {
379 { "ACPI0003", 0 },
380 { }
381};
382MODULE_DEVICE_TABLE(acpi, acpi_ac_match);
383
384static struct platform_driver acpi_ac_driver = {
385 .probe = acpi_ac_probe,
386 .remove = acpi_ac_remove,
387 .driver = {
388 .name = "acpi-ac",
389 .owner = THIS_MODULE,
390 .pm = &acpi_ac_pm_ops,
391 .acpi_match_table = ACPI_PTR(acpi_ac_match),
392 },
393};
394
Len Brown4be44fc2005-08-05 00:44:28 -0400395static int __init acpi_ac_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Rich Townsend3f86b832006-07-01 11:36:54 -0400397 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Pavel Machek4d8316d2006-08-14 22:37:22 -0700399 if (acpi_disabled)
400 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300402#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -0400403 acpi_ac_dir = acpi_lock_ac_dir();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (!acpi_ac_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400405 return -ENODEV;
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Zhang Ruicc8ef522013-09-25 20:39:45 +0800408 result = platform_driver_register(&acpi_ac_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 if (result < 0) {
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300410#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -0400411 acpi_unlock_ac_dir(acpi_ac_dir);
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800412#endif
Patrick Mocheld550d982006-06-27 00:41:40 -0400413 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415
Patrick Mocheld550d982006-06-27 00:41:40 -0400416 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419static void __exit acpi_ac_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Zhang Ruicc8ef522013-09-25 20:39:45 +0800421 platform_driver_unregister(&acpi_ac_driver);
Alexey Starikovskiyfdcedbb2007-11-19 16:33:45 +0300422#ifdef CONFIG_ACPI_PROCFS_POWER
Rich Townsend3f86b832006-07-01 11:36:54 -0400423 acpi_unlock_ac_dir(acpi_ac_dir);
Andrey Borzenkov8a246ee2007-11-14 17:00:37 -0800424#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426module_init(acpi_ac_init);
427module_exit(acpi_ac_exit);