Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/proc_fs.h> |
| 31 | #include <linux/seq_file.h> |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 32 | #include <linux/power_supply.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <acpi/acpi_bus.h> |
| 34 | #include <acpi/acpi_drivers.h> |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define ACPI_AC_COMPONENT 0x00020000 |
| 37 | #define ACPI_AC_CLASS "ac_adapter" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #define ACPI_AC_DEVICE_NAME "AC Adapter" |
| 39 | #define ACPI_AC_FILE_STATE "state" |
| 40 | #define ACPI_AC_NOTIFY_STATUS 0x80 |
| 41 | #define ACPI_AC_STATUS_OFFLINE 0x00 |
| 42 | #define ACPI_AC_STATUS_ONLINE 0x01 |
| 43 | #define ACPI_AC_STATUS_UNKNOWN 0xFF |
| 44 | |
| 45 | #define _COMPONENT ACPI_AC_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 46 | ACPI_MODULE_NAME("ac"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 48 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 49 | MODULE_DESCRIPTION("ACPI AC Adapter Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | MODULE_LICENSE("GPL"); |
| 51 | |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 52 | extern struct proc_dir_entry *acpi_lock_ac_dir(void); |
| 53 | extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); |
| 54 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | static int acpi_ac_add(struct acpi_device *device); |
| 56 | static int acpi_ac_remove(struct acpi_device *device, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static int acpi_ac_open_fs(struct inode *inode, struct file *file); |
| 58 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 59 | const static struct acpi_device_id ac_device_ids[] = { |
| 60 | {"ACPI0003", 0}, |
| 61 | {"", 0}, |
| 62 | }; |
| 63 | MODULE_DEVICE_TABLE(acpi, ac_device_ids); |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static struct acpi_driver acpi_ac_driver = { |
Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 66 | .name = "ac", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | .class = ACPI_AC_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 68 | .ids = ac_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | .ops = { |
| 70 | .add = acpi_ac_add, |
| 71 | .remove = acpi_ac_remove, |
| 72 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct acpi_ac { |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 76 | struct power_supply charger; |
Patrick Mochel | af96179 | 2006-05-19 16:54:32 -0400 | [diff] [blame] | 77 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | unsigned long state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 81 | #define to_acpi_ac(x) container_of(x, struct acpi_ac, charger); |
| 82 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 83 | static const struct file_operations acpi_ac_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | .open = acpi_ac_open_fs, |
| 85 | .read = seq_read, |
| 86 | .llseek = seq_lseek, |
| 87 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 89 | static int get_ac_property(struct power_supply *psy, |
| 90 | enum power_supply_property psp, |
| 91 | union power_supply_propval *val) |
| 92 | { |
| 93 | struct acpi_ac *ac = to_acpi_ac(psy); |
| 94 | switch (psp) { |
| 95 | case POWER_SUPPLY_PROP_ONLINE: |
| 96 | val->intval = ac->state; |
| 97 | break; |
| 98 | default: |
| 99 | return -EINVAL; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static enum power_supply_property ac_props[] = { |
| 105 | POWER_SUPPLY_PROP_ONLINE, |
| 106 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* -------------------------------------------------------------------------- |
| 109 | AC Adapter Management |
| 110 | -------------------------------------------------------------------------- */ |
| 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | static int acpi_ac_get_state(struct acpi_ac *ac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | if (!ac) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 118 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Patrick Mochel | a6ba5eb | 2006-05-19 16:54:41 -0400 | [diff] [blame] | 120 | status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 122 | ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | ac->state = ACPI_AC_STATUS_UNKNOWN; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 124 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 127 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* -------------------------------------------------------------------------- |
| 131 | FS Interface (/proc) |
| 132 | -------------------------------------------------------------------------- */ |
| 133 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | static struct proc_dir_entry *acpi_ac_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | static int acpi_ac_seq_show(struct seq_file *seq, void *offset) |
| 137 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 138 | struct acpi_ac *ac = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | if (!ac) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 142 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | if (acpi_ac_get_state(ac)) { |
| 145 | seq_puts(seq, "ERROR: Unable to read AC Adapter state\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 146 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | seq_puts(seq, "state: "); |
| 150 | switch (ac->state) { |
| 151 | case ACPI_AC_STATUS_OFFLINE: |
| 152 | seq_puts(seq, "off-line\n"); |
| 153 | break; |
| 154 | case ACPI_AC_STATUS_ONLINE: |
| 155 | seq_puts(seq, "on-line\n"); |
| 156 | break; |
| 157 | default: |
| 158 | seq_puts(seq, "unknown\n"); |
| 159 | break; |
| 160 | } |
| 161 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 162 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | static int acpi_ac_open_fs(struct inode *inode, struct file *file) |
| 166 | { |
| 167 | return single_open(file, acpi_ac_seq_show, PDE(inode)->data); |
| 168 | } |
| 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | static int acpi_ac_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | if (!acpi_device_dir(device)) { |
| 176 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | acpi_ac_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 179 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | acpi_device_dir(device)->owner = THIS_MODULE; |
| 181 | } |
| 182 | |
| 183 | /* 'state' [R] */ |
| 184 | entry = create_proc_entry(ACPI_AC_FILE_STATE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | S_IRUGO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 187 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | else { |
| 189 | entry->proc_fops = &acpi_ac_fops; |
| 190 | entry->data = acpi_driver_data(device); |
| 191 | entry->owner = THIS_MODULE; |
| 192 | } |
| 193 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 194 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | static int acpi_ac_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | if (acpi_device_dir(device)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | remove_proc_entry(acpi_device_bid(device), acpi_ac_dir); |
| 204 | acpi_device_dir(device) = NULL; |
| 205 | } |
| 206 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 207 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* -------------------------------------------------------------------------- |
| 211 | Driver Model |
| 212 | -------------------------------------------------------------------------- */ |
| 213 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 216 | struct acpi_ac *ac = data; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | if (!ac) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 221 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Patrick Mochel | af96179 | 2006-05-19 16:54:32 -0400 | [diff] [blame] | 223 | device = ac->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | switch (event) { |
| 225 | case ACPI_AC_NOTIFY_STATUS: |
Christian Lupien | 03d7825 | 2004-08-19 01:26:00 -0400 | [diff] [blame] | 226 | case ACPI_NOTIFY_BUS_CHECK: |
| 227 | case ACPI_NOTIFY_DEVICE_CHECK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | acpi_ac_get_state(ac); |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 229 | acpi_bus_generate_proc_event(device, event, (u32) ac->state); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 230 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
| 231 | device->dev.bus_id, event, |
| 232 | (u32) ac->state); |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 233 | kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | break; |
| 235 | default: |
| 236 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 241 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | static int acpi_ac_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | int result = 0; |
| 247 | acpi_status status = AE_OK; |
| 248 | struct acpi_ac *ac = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 252 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 254 | ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (!ac) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 256 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Patrick Mochel | af96179 | 2006-05-19 16:54:32 -0400 | [diff] [blame] | 258 | ac->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); |
| 260 | strcpy(acpi_device_class(device), ACPI_AC_CLASS); |
| 261 | acpi_driver_data(device) = ac; |
| 262 | |
| 263 | result = acpi_ac_get_state(ac); |
| 264 | if (result) |
| 265 | goto end; |
| 266 | |
| 267 | result = acpi_ac_add_fs(device); |
| 268 | if (result) |
| 269 | goto end; |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 270 | ac->charger.name = acpi_device_bid(device); |
| 271 | ac->charger.type = POWER_SUPPLY_TYPE_MAINS; |
| 272 | ac->charger.properties = ac_props; |
| 273 | ac->charger.num_properties = ARRAY_SIZE(ac_props); |
| 274 | ac->charger.get_property = get_ac_property; |
| 275 | power_supply_register(&ac->device->dev, &ac->charger); |
Patrick Mochel | a6ba5eb | 2006-05-19 16:54:41 -0400 | [diff] [blame] | 276 | status = acpi_install_notify_handler(device->handle, |
Christian Lupien | 03d7825 | 2004-08-19 01:26:00 -0400 | [diff] [blame] | 277 | ACPI_ALL_NOTIFY, acpi_ac_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | ac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | result = -ENODEV; |
| 281 | goto end; |
| 282 | } |
| 283 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
| 285 | acpi_device_name(device), acpi_device_bid(device), |
| 286 | ac->state ? "on-line" : "off-line"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (result) { |
| 290 | acpi_ac_remove_fs(device); |
| 291 | kfree(ac); |
| 292 | } |
| 293 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 294 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | static int acpi_ac_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | acpi_status status = AE_OK; |
| 300 | struct acpi_ac *ac = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 304 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 306 | ac = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Patrick Mochel | a6ba5eb | 2006-05-19 16:54:41 -0400 | [diff] [blame] | 308 | status = acpi_remove_notify_handler(device->handle, |
Christian Lupien | 03d7825 | 2004-08-19 01:26:00 -0400 | [diff] [blame] | 309 | ACPI_ALL_NOTIFY, acpi_ac_notify); |
Alexey Starikovskiy | d5b4a3d | 2007-09-26 19:44:06 +0400 | [diff] [blame^] | 310 | if (ac->charger.dev) |
| 311 | power_supply_unregister(&ac->charger); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | acpi_ac_remove_fs(device); |
| 313 | |
| 314 | kfree(ac); |
| 315 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 316 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | static int __init acpi_ac_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 321 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Pavel Machek | 4d8316d | 2006-08-14 22:37:22 -0700 | [diff] [blame] | 323 | if (acpi_disabled) |
| 324 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 326 | acpi_ac_dir = acpi_lock_ac_dir(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | if (!acpi_ac_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 328 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | result = acpi_bus_register_driver(&acpi_ac_driver); |
| 331 | if (result < 0) { |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 332 | acpi_unlock_ac_dir(acpi_ac_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 333 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 336 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | static void __exit acpi_ac_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | acpi_bus_unregister_driver(&acpi_ac_driver); |
| 343 | |
Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 344 | acpi_unlock_ac_dir(acpi_ac_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 346 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | module_init(acpi_ac_init); |
| 350 | module_exit(acpi_ac_exit); |