diff options
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r-- | drivers/acpi/battery.c | 171 |
1 files changed, 73 insertions, 98 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 702e857e98c5..9810e2a55d0a 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -59,6 +59,9 @@ ACPI_MODULE_NAME("acpi_battery") | |||
59 | MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); | 59 | MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); |
60 | MODULE_LICENSE("GPL"); | 60 | MODULE_LICENSE("GPL"); |
61 | 61 | ||
62 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | ||
63 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | ||
64 | |||
62 | static int acpi_battery_add(struct acpi_device *device); | 65 | static int acpi_battery_add(struct acpi_device *device); |
63 | static int acpi_battery_remove(struct acpi_device *device, int type); | 66 | static int acpi_battery_remove(struct acpi_device *device, int type); |
64 | 67 | ||
@@ -108,7 +111,7 @@ struct acpi_battery_trips { | |||
108 | }; | 111 | }; |
109 | 112 | ||
110 | struct acpi_battery { | 113 | struct acpi_battery { |
111 | acpi_handle handle; | 114 | struct acpi_device * device; |
112 | struct acpi_battery_flags flags; | 115 | struct acpi_battery_flags flags; |
113 | struct acpi_battery_trips trips; | 116 | struct acpi_battery_trips trips; |
114 | unsigned long alarm; | 117 | unsigned long alarm; |
@@ -132,17 +135,16 @@ acpi_battery_get_info(struct acpi_battery *battery, | |||
132 | struct acpi_buffer data = { 0, NULL }; | 135 | struct acpi_buffer data = { 0, NULL }; |
133 | union acpi_object *package = NULL; | 136 | union acpi_object *package = NULL; |
134 | 137 | ||
135 | ACPI_FUNCTION_TRACE("acpi_battery_get_info"); | ||
136 | 138 | ||
137 | if (!battery || !bif) | 139 | if (!battery || !bif) |
138 | return_VALUE(-EINVAL); | 140 | return -EINVAL; |
139 | 141 | ||
140 | /* Evalute _BIF */ | 142 | /* Evalute _BIF */ |
141 | 143 | ||
142 | status = acpi_evaluate_object(battery->handle, "_BIF", NULL, &buffer); | 144 | status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer); |
143 | if (ACPI_FAILURE(status)) { | 145 | if (ACPI_FAILURE(status)) { |
144 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BIF\n")); | 146 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); |
145 | return_VALUE(-ENODEV); | 147 | return -ENODEV; |
146 | } | 148 | } |
147 | 149 | ||
148 | package = (union acpi_object *)buffer.pointer; | 150 | package = (union acpi_object *)buffer.pointer; |
@@ -151,7 +153,7 @@ acpi_battery_get_info(struct acpi_battery *battery, | |||
151 | 153 | ||
152 | status = acpi_extract_package(package, &format, &data); | 154 | status = acpi_extract_package(package, &format, &data); |
153 | if (status != AE_BUFFER_OVERFLOW) { | 155 | if (status != AE_BUFFER_OVERFLOW) { |
154 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BIF\n")); | 156 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF")); |
155 | result = -ENODEV; | 157 | result = -ENODEV; |
156 | goto end; | 158 | goto end; |
157 | } | 159 | } |
@@ -165,19 +167,19 @@ acpi_battery_get_info(struct acpi_battery *battery, | |||
165 | 167 | ||
166 | status = acpi_extract_package(package, &format, &data); | 168 | status = acpi_extract_package(package, &format, &data); |
167 | if (ACPI_FAILURE(status)) { | 169 | if (ACPI_FAILURE(status)) { |
168 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BIF\n")); | 170 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF")); |
169 | kfree(data.pointer); | 171 | kfree(data.pointer); |
170 | result = -ENODEV; | 172 | result = -ENODEV; |
171 | goto end; | 173 | goto end; |
172 | } | 174 | } |
173 | 175 | ||
174 | end: | 176 | end: |
175 | acpi_os_free(buffer.pointer); | 177 | kfree(buffer.pointer); |
176 | 178 | ||
177 | if (!result) | 179 | if (!result) |
178 | (*bif) = (struct acpi_battery_info *)data.pointer; | 180 | (*bif) = (struct acpi_battery_info *)data.pointer; |
179 | 181 | ||
180 | return_VALUE(result); | 182 | return result; |
181 | } | 183 | } |
182 | 184 | ||
183 | static int | 185 | static int |
@@ -193,17 +195,16 @@ acpi_battery_get_status(struct acpi_battery *battery, | |||
193 | struct acpi_buffer data = { 0, NULL }; | 195 | struct acpi_buffer data = { 0, NULL }; |
194 | union acpi_object *package = NULL; | 196 | union acpi_object *package = NULL; |
195 | 197 | ||
196 | ACPI_FUNCTION_TRACE("acpi_battery_get_status"); | ||
197 | 198 | ||
198 | if (!battery || !bst) | 199 | if (!battery || !bst) |
199 | return_VALUE(-EINVAL); | 200 | return -EINVAL; |
200 | 201 | ||
201 | /* Evalute _BST */ | 202 | /* Evalute _BST */ |
202 | 203 | ||
203 | status = acpi_evaluate_object(battery->handle, "_BST", NULL, &buffer); | 204 | status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer); |
204 | if (ACPI_FAILURE(status)) { | 205 | if (ACPI_FAILURE(status)) { |
205 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _BST\n")); | 206 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); |
206 | return_VALUE(-ENODEV); | 207 | return -ENODEV; |
207 | } | 208 | } |
208 | 209 | ||
209 | package = (union acpi_object *)buffer.pointer; | 210 | package = (union acpi_object *)buffer.pointer; |
@@ -212,7 +213,7 @@ acpi_battery_get_status(struct acpi_battery *battery, | |||
212 | 213 | ||
213 | status = acpi_extract_package(package, &format, &data); | 214 | status = acpi_extract_package(package, &format, &data); |
214 | if (status != AE_BUFFER_OVERFLOW) { | 215 | if (status != AE_BUFFER_OVERFLOW) { |
215 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BST\n")); | 216 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST")); |
216 | result = -ENODEV; | 217 | result = -ENODEV; |
217 | goto end; | 218 | goto end; |
218 | } | 219 | } |
@@ -226,19 +227,19 @@ acpi_battery_get_status(struct acpi_battery *battery, | |||
226 | 227 | ||
227 | status = acpi_extract_package(package, &format, &data); | 228 | status = acpi_extract_package(package, &format, &data); |
228 | if (ACPI_FAILURE(status)) { | 229 | if (ACPI_FAILURE(status)) { |
229 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _BST\n")); | 230 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST")); |
230 | kfree(data.pointer); | 231 | kfree(data.pointer); |
231 | result = -ENODEV; | 232 | result = -ENODEV; |
232 | goto end; | 233 | goto end; |
233 | } | 234 | } |
234 | 235 | ||
235 | end: | 236 | end: |
236 | acpi_os_free(buffer.pointer); | 237 | kfree(buffer.pointer); |
237 | 238 | ||
238 | if (!result) | 239 | if (!result) |
239 | (*bst) = (struct acpi_battery_status *)data.pointer; | 240 | (*bst) = (struct acpi_battery_status *)data.pointer; |
240 | 241 | ||
241 | return_VALUE(result); | 242 | return result; |
242 | } | 243 | } |
243 | 244 | ||
244 | static int | 245 | static int |
@@ -248,25 +249,24 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) | |||
248 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | 249 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
249 | struct acpi_object_list arg_list = { 1, &arg0 }; | 250 | struct acpi_object_list arg_list = { 1, &arg0 }; |
250 | 251 | ||
251 | ACPI_FUNCTION_TRACE("acpi_battery_set_alarm"); | ||
252 | 252 | ||
253 | if (!battery) | 253 | if (!battery) |
254 | return_VALUE(-EINVAL); | 254 | return -EINVAL; |
255 | 255 | ||
256 | if (!battery->flags.alarm) | 256 | if (!battery->flags.alarm) |
257 | return_VALUE(-ENODEV); | 257 | return -ENODEV; |
258 | 258 | ||
259 | arg0.integer.value = alarm; | 259 | arg0.integer.value = alarm; |
260 | 260 | ||
261 | status = acpi_evaluate_object(battery->handle, "_BTP", &arg_list, NULL); | 261 | status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL); |
262 | if (ACPI_FAILURE(status)) | 262 | if (ACPI_FAILURE(status)) |
263 | return_VALUE(-ENODEV); | 263 | return -ENODEV; |
264 | 264 | ||
265 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", (u32) alarm)); | 265 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Alarm set to %d\n", (u32) alarm)); |
266 | 266 | ||
267 | battery->alarm = alarm; | 267 | battery->alarm = alarm; |
268 | 268 | ||
269 | return_VALUE(0); | 269 | return 0; |
270 | } | 270 | } |
271 | 271 | ||
272 | static int acpi_battery_check(struct acpi_battery *battery) | 272 | static int acpi_battery_check(struct acpi_battery *battery) |
@@ -277,18 +277,15 @@ static int acpi_battery_check(struct acpi_battery *battery) | |||
277 | struct acpi_device *device = NULL; | 277 | struct acpi_device *device = NULL; |
278 | struct acpi_battery_info *bif = NULL; | 278 | struct acpi_battery_info *bif = NULL; |
279 | 279 | ||
280 | ACPI_FUNCTION_TRACE("acpi_battery_check"); | ||
281 | 280 | ||
282 | if (!battery) | 281 | if (!battery) |
283 | return_VALUE(-EINVAL); | 282 | return -EINVAL; |
284 | 283 | ||
285 | result = acpi_bus_get_device(battery->handle, &device); | 284 | device = battery->device; |
286 | if (result) | ||
287 | return_VALUE(result); | ||
288 | 285 | ||
289 | result = acpi_bus_get_status(device); | 286 | result = acpi_bus_get_status(device); |
290 | if (result) | 287 | if (result) |
291 | return_VALUE(result); | 288 | return result; |
292 | 289 | ||
293 | /* Insertion? */ | 290 | /* Insertion? */ |
294 | 291 | ||
@@ -300,7 +297,7 @@ static int acpi_battery_check(struct acpi_battery *battery) | |||
300 | 297 | ||
301 | result = acpi_battery_get_info(battery, &bif); | 298 | result = acpi_battery_get_info(battery, &bif); |
302 | if (result) | 299 | if (result) |
303 | return_VALUE(result); | 300 | return result; |
304 | 301 | ||
305 | battery->flags.power_unit = bif->power_unit; | 302 | battery->flags.power_unit = bif->power_unit; |
306 | battery->trips.warning = bif->design_capacity_warning; | 303 | battery->trips.warning = bif->design_capacity_warning; |
@@ -309,7 +306,7 @@ static int acpi_battery_check(struct acpi_battery *battery) | |||
309 | 306 | ||
310 | /* See if alarms are supported, and if so, set default */ | 307 | /* See if alarms are supported, and if so, set default */ |
311 | 308 | ||
312 | status = acpi_get_handle(battery->handle, "_BTP", &handle); | 309 | status = acpi_get_handle(battery->device->handle, "_BTP", &handle); |
313 | if (ACPI_SUCCESS(status)) { | 310 | if (ACPI_SUCCESS(status)) { |
314 | battery->flags.alarm = 1; | 311 | battery->flags.alarm = 1; |
315 | acpi_battery_set_alarm(battery, battery->trips.warning); | 312 | acpi_battery_set_alarm(battery, battery->trips.warning); |
@@ -324,7 +321,7 @@ static int acpi_battery_check(struct acpi_battery *battery) | |||
324 | 321 | ||
325 | battery->flags.present = device->status.battery_present; | 322 | battery->flags.present = device->status.battery_present; |
326 | 323 | ||
327 | return_VALUE(result); | 324 | return result; |
328 | } | 325 | } |
329 | 326 | ||
330 | /* -------------------------------------------------------------------------- | 327 | /* -------------------------------------------------------------------------- |
@@ -339,7 +336,6 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) | |||
339 | struct acpi_battery_info *bif = NULL; | 336 | struct acpi_battery_info *bif = NULL; |
340 | char *units = "?"; | 337 | char *units = "?"; |
341 | 338 | ||
342 | ACPI_FUNCTION_TRACE("acpi_battery_read_info"); | ||
343 | 339 | ||
344 | if (!battery) | 340 | if (!battery) |
345 | goto end; | 341 | goto end; |
@@ -409,7 +405,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) | |||
409 | end: | 405 | end: |
410 | kfree(bif); | 406 | kfree(bif); |
411 | 407 | ||
412 | return_VALUE(0); | 408 | return 0; |
413 | } | 409 | } |
414 | 410 | ||
415 | static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) | 411 | static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) |
@@ -424,7 +420,6 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
424 | struct acpi_battery_status *bst = NULL; | 420 | struct acpi_battery_status *bst = NULL; |
425 | char *units = "?"; | 421 | char *units = "?"; |
426 | 422 | ||
427 | ACPI_FUNCTION_TRACE("acpi_battery_read_state"); | ||
428 | 423 | ||
429 | if (!battery) | 424 | if (!battery) |
430 | goto end; | 425 | goto end; |
@@ -458,8 +453,6 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
458 | if ((bst->state & 0x01) && (bst->state & 0x02)) { | 453 | if ((bst->state & 0x01) && (bst->state & 0x02)) { |
459 | seq_printf(seq, | 454 | seq_printf(seq, |
460 | "charging state: charging/discharging\n"); | 455 | "charging state: charging/discharging\n"); |
461 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
462 | "Battery Charging and Discharging?\n")); | ||
463 | } else if (bst->state & 0x01) | 456 | } else if (bst->state & 0x01) |
464 | seq_printf(seq, "charging state: discharging\n"); | 457 | seq_printf(seq, "charging state: discharging\n"); |
465 | else if (bst->state & 0x02) | 458 | else if (bst->state & 0x02) |
@@ -489,7 +482,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) | |||
489 | end: | 482 | end: |
490 | kfree(bst); | 483 | kfree(bst); |
491 | 484 | ||
492 | return_VALUE(0); | 485 | return 0; |
493 | } | 486 | } |
494 | 487 | ||
495 | static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) | 488 | static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) |
@@ -502,7 +495,6 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | |||
502 | struct acpi_battery *battery = (struct acpi_battery *)seq->private; | 495 | struct acpi_battery *battery = (struct acpi_battery *)seq->private; |
503 | char *units = "?"; | 496 | char *units = "?"; |
504 | 497 | ||
505 | ACPI_FUNCTION_TRACE("acpi_battery_read_alarm"); | ||
506 | 498 | ||
507 | if (!battery) | 499 | if (!battery) |
508 | goto end; | 500 | goto end; |
@@ -527,7 +519,7 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) | |||
527 | seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units); | 519 | seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units); |
528 | 520 | ||
529 | end: | 521 | end: |
530 | return_VALUE(0); | 522 | return 0; |
531 | } | 523 | } |
532 | 524 | ||
533 | static ssize_t | 525 | static ssize_t |
@@ -540,25 +532,24 @@ acpi_battery_write_alarm(struct file *file, | |||
540 | struct seq_file *m = (struct seq_file *)file->private_data; | 532 | struct seq_file *m = (struct seq_file *)file->private_data; |
541 | struct acpi_battery *battery = (struct acpi_battery *)m->private; | 533 | struct acpi_battery *battery = (struct acpi_battery *)m->private; |
542 | 534 | ||
543 | ACPI_FUNCTION_TRACE("acpi_battery_write_alarm"); | ||
544 | 535 | ||
545 | if (!battery || (count > sizeof(alarm_string) - 1)) | 536 | if (!battery || (count > sizeof(alarm_string) - 1)) |
546 | return_VALUE(-EINVAL); | 537 | return -EINVAL; |
547 | 538 | ||
548 | if (!battery->flags.present) | 539 | if (!battery->flags.present) |
549 | return_VALUE(-ENODEV); | 540 | return -ENODEV; |
550 | 541 | ||
551 | if (copy_from_user(alarm_string, buffer, count)) | 542 | if (copy_from_user(alarm_string, buffer, count)) |
552 | return_VALUE(-EFAULT); | 543 | return -EFAULT; |
553 | 544 | ||
554 | alarm_string[count] = '\0'; | 545 | alarm_string[count] = '\0'; |
555 | 546 | ||
556 | result = acpi_battery_set_alarm(battery, | 547 | result = acpi_battery_set_alarm(battery, |
557 | simple_strtoul(alarm_string, NULL, 0)); | 548 | simple_strtoul(alarm_string, NULL, 0)); |
558 | if (result) | 549 | if (result) |
559 | return_VALUE(result); | 550 | return result; |
560 | 551 | ||
561 | return_VALUE(count); | 552 | return count; |
562 | } | 553 | } |
563 | 554 | ||
564 | static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) | 555 | static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) |
@@ -566,7 +557,7 @@ static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) | |||
566 | return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); | 557 | return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); |
567 | } | 558 | } |
568 | 559 | ||
569 | static struct file_operations acpi_battery_info_ops = { | 560 | static const struct file_operations acpi_battery_info_ops = { |
570 | .open = acpi_battery_info_open_fs, | 561 | .open = acpi_battery_info_open_fs, |
571 | .read = seq_read, | 562 | .read = seq_read, |
572 | .llseek = seq_lseek, | 563 | .llseek = seq_lseek, |
@@ -574,7 +565,7 @@ static struct file_operations acpi_battery_info_ops = { | |||
574 | .owner = THIS_MODULE, | 565 | .owner = THIS_MODULE, |
575 | }; | 566 | }; |
576 | 567 | ||
577 | static struct file_operations acpi_battery_state_ops = { | 568 | static const struct file_operations acpi_battery_state_ops = { |
578 | .open = acpi_battery_state_open_fs, | 569 | .open = acpi_battery_state_open_fs, |
579 | .read = seq_read, | 570 | .read = seq_read, |
580 | .llseek = seq_lseek, | 571 | .llseek = seq_lseek, |
@@ -582,7 +573,7 @@ static struct file_operations acpi_battery_state_ops = { | |||
582 | .owner = THIS_MODULE, | 573 | .owner = THIS_MODULE, |
583 | }; | 574 | }; |
584 | 575 | ||
585 | static struct file_operations acpi_battery_alarm_ops = { | 576 | static const struct file_operations acpi_battery_alarm_ops = { |
586 | .open = acpi_battery_alarm_open_fs, | 577 | .open = acpi_battery_alarm_open_fs, |
587 | .read = seq_read, | 578 | .read = seq_read, |
588 | .write = acpi_battery_write_alarm, | 579 | .write = acpi_battery_write_alarm, |
@@ -595,13 +586,12 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
595 | { | 586 | { |
596 | struct proc_dir_entry *entry = NULL; | 587 | struct proc_dir_entry *entry = NULL; |
597 | 588 | ||
598 | ACPI_FUNCTION_TRACE("acpi_battery_add_fs"); | ||
599 | 589 | ||
600 | if (!acpi_device_dir(device)) { | 590 | if (!acpi_device_dir(device)) { |
601 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 591 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
602 | acpi_battery_dir); | 592 | acpi_battery_dir); |
603 | if (!acpi_device_dir(device)) | 593 | if (!acpi_device_dir(device)) |
604 | return_VALUE(-ENODEV); | 594 | return -ENODEV; |
605 | acpi_device_dir(device)->owner = THIS_MODULE; | 595 | acpi_device_dir(device)->owner = THIS_MODULE; |
606 | } | 596 | } |
607 | 597 | ||
@@ -609,9 +599,7 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
609 | entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, | 599 | entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, |
610 | S_IRUGO, acpi_device_dir(device)); | 600 | S_IRUGO, acpi_device_dir(device)); |
611 | if (!entry) | 601 | if (!entry) |
612 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 602 | return -ENODEV; |
613 | "Unable to create '%s' fs entry\n", | ||
614 | ACPI_BATTERY_FILE_INFO)); | ||
615 | else { | 603 | else { |
616 | entry->proc_fops = &acpi_battery_info_ops; | 604 | entry->proc_fops = &acpi_battery_info_ops; |
617 | entry->data = acpi_driver_data(device); | 605 | entry->data = acpi_driver_data(device); |
@@ -622,9 +610,7 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
622 | entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS, | 610 | entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS, |
623 | S_IRUGO, acpi_device_dir(device)); | 611 | S_IRUGO, acpi_device_dir(device)); |
624 | if (!entry) | 612 | if (!entry) |
625 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 613 | return -ENODEV; |
626 | "Unable to create '%s' fs entry\n", | ||
627 | ACPI_BATTERY_FILE_STATUS)); | ||
628 | else { | 614 | else { |
629 | entry->proc_fops = &acpi_battery_state_ops; | 615 | entry->proc_fops = &acpi_battery_state_ops; |
630 | entry->data = acpi_driver_data(device); | 616 | entry->data = acpi_driver_data(device); |
@@ -636,21 +622,18 @@ static int acpi_battery_add_fs(struct acpi_device *device) | |||
636 | S_IFREG | S_IRUGO | S_IWUSR, | 622 | S_IFREG | S_IRUGO | S_IWUSR, |
637 | acpi_device_dir(device)); | 623 | acpi_device_dir(device)); |
638 | if (!entry) | 624 | if (!entry) |
639 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 625 | return -ENODEV; |
640 | "Unable to create '%s' fs entry\n", | ||
641 | ACPI_BATTERY_FILE_ALARM)); | ||
642 | else { | 626 | else { |
643 | entry->proc_fops = &acpi_battery_alarm_ops; | 627 | entry->proc_fops = &acpi_battery_alarm_ops; |
644 | entry->data = acpi_driver_data(device); | 628 | entry->data = acpi_driver_data(device); |
645 | entry->owner = THIS_MODULE; | 629 | entry->owner = THIS_MODULE; |
646 | } | 630 | } |
647 | 631 | ||
648 | return_VALUE(0); | 632 | return 0; |
649 | } | 633 | } |
650 | 634 | ||
651 | static int acpi_battery_remove_fs(struct acpi_device *device) | 635 | static int acpi_battery_remove_fs(struct acpi_device *device) |
652 | { | 636 | { |
653 | ACPI_FUNCTION_TRACE("acpi_battery_remove_fs"); | ||
654 | 637 | ||
655 | if (acpi_device_dir(device)) { | 638 | if (acpi_device_dir(device)) { |
656 | remove_proc_entry(ACPI_BATTERY_FILE_ALARM, | 639 | remove_proc_entry(ACPI_BATTERY_FILE_ALARM, |
@@ -664,7 +647,7 @@ static int acpi_battery_remove_fs(struct acpi_device *device) | |||
664 | acpi_device_dir(device) = NULL; | 647 | acpi_device_dir(device) = NULL; |
665 | } | 648 | } |
666 | 649 | ||
667 | return_VALUE(0); | 650 | return 0; |
668 | } | 651 | } |
669 | 652 | ||
670 | /* -------------------------------------------------------------------------- | 653 | /* -------------------------------------------------------------------------- |
@@ -676,17 +659,17 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) | |||
676 | struct acpi_battery *battery = (struct acpi_battery *)data; | 659 | struct acpi_battery *battery = (struct acpi_battery *)data; |
677 | struct acpi_device *device = NULL; | 660 | struct acpi_device *device = NULL; |
678 | 661 | ||
679 | ACPI_FUNCTION_TRACE("acpi_battery_notify"); | ||
680 | 662 | ||
681 | if (!battery) | 663 | if (!battery) |
682 | return_VOID; | 664 | return; |
683 | 665 | ||
684 | if (acpi_bus_get_device(handle, &device)) | 666 | device = battery->device; |
685 | return_VOID; | ||
686 | 667 | ||
687 | switch (event) { | 668 | switch (event) { |
688 | case ACPI_BATTERY_NOTIFY_STATUS: | 669 | case ACPI_BATTERY_NOTIFY_STATUS: |
689 | case ACPI_BATTERY_NOTIFY_INFO: | 670 | case ACPI_BATTERY_NOTIFY_INFO: |
671 | case ACPI_NOTIFY_BUS_CHECK: | ||
672 | case ACPI_NOTIFY_DEVICE_CHECK: | ||
690 | acpi_battery_check(battery); | 673 | acpi_battery_check(battery); |
691 | acpi_bus_generate_event(device, event, battery->flags.present); | 674 | acpi_bus_generate_event(device, event, battery->flags.present); |
692 | break; | 675 | break; |
@@ -696,7 +679,7 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) | |||
696 | break; | 679 | break; |
697 | } | 680 | } |
698 | 681 | ||
699 | return_VOID; | 682 | return; |
700 | } | 683 | } |
701 | 684 | ||
702 | static int acpi_battery_add(struct acpi_device *device) | 685 | static int acpi_battery_add(struct acpi_device *device) |
@@ -705,17 +688,16 @@ static int acpi_battery_add(struct acpi_device *device) | |||
705 | acpi_status status = 0; | 688 | acpi_status status = 0; |
706 | struct acpi_battery *battery = NULL; | 689 | struct acpi_battery *battery = NULL; |
707 | 690 | ||
708 | ACPI_FUNCTION_TRACE("acpi_battery_add"); | ||
709 | 691 | ||
710 | if (!device) | 692 | if (!device) |
711 | return_VALUE(-EINVAL); | 693 | return -EINVAL; |
712 | 694 | ||
713 | battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); | 695 | battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); |
714 | if (!battery) | 696 | if (!battery) |
715 | return_VALUE(-ENOMEM); | 697 | return -ENOMEM; |
716 | memset(battery, 0, sizeof(struct acpi_battery)); | 698 | memset(battery, 0, sizeof(struct acpi_battery)); |
717 | 699 | ||
718 | battery->handle = device->handle; | 700 | battery->device = device; |
719 | strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); | 701 | strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); |
720 | strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); | 702 | strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); |
721 | acpi_driver_data(device) = battery; | 703 | acpi_driver_data(device) = battery; |
@@ -728,12 +710,10 @@ static int acpi_battery_add(struct acpi_device *device) | |||
728 | if (result) | 710 | if (result) |
729 | goto end; | 711 | goto end; |
730 | 712 | ||
731 | status = acpi_install_notify_handler(battery->handle, | 713 | status = acpi_install_notify_handler(device->handle, |
732 | ACPI_DEVICE_NOTIFY, | 714 | ACPI_ALL_NOTIFY, |
733 | acpi_battery_notify, battery); | 715 | acpi_battery_notify, battery); |
734 | if (ACPI_FAILURE(status)) { | 716 | if (ACPI_FAILURE(status)) { |
735 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
736 | "Error installing notify handler\n")); | ||
737 | result = -ENODEV; | 717 | result = -ENODEV; |
738 | goto end; | 718 | goto end; |
739 | } | 719 | } |
@@ -748,7 +728,7 @@ static int acpi_battery_add(struct acpi_device *device) | |||
748 | kfree(battery); | 728 | kfree(battery); |
749 | } | 729 | } |
750 | 730 | ||
751 | return_VALUE(result); | 731 | return result; |
752 | } | 732 | } |
753 | 733 | ||
754 | static int acpi_battery_remove(struct acpi_device *device, int type) | 734 | static int acpi_battery_remove(struct acpi_device *device, int type) |
@@ -756,56 +736,51 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
756 | acpi_status status = 0; | 736 | acpi_status status = 0; |
757 | struct acpi_battery *battery = NULL; | 737 | struct acpi_battery *battery = NULL; |
758 | 738 | ||
759 | ACPI_FUNCTION_TRACE("acpi_battery_remove"); | ||
760 | 739 | ||
761 | if (!device || !acpi_driver_data(device)) | 740 | if (!device || !acpi_driver_data(device)) |
762 | return_VALUE(-EINVAL); | 741 | return -EINVAL; |
763 | 742 | ||
764 | battery = (struct acpi_battery *)acpi_driver_data(device); | 743 | battery = (struct acpi_battery *)acpi_driver_data(device); |
765 | 744 | ||
766 | status = acpi_remove_notify_handler(battery->handle, | 745 | status = acpi_remove_notify_handler(device->handle, |
767 | ACPI_DEVICE_NOTIFY, | 746 | ACPI_ALL_NOTIFY, |
768 | acpi_battery_notify); | 747 | acpi_battery_notify); |
769 | if (ACPI_FAILURE(status)) | ||
770 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
771 | "Error removing notify handler\n")); | ||
772 | 748 | ||
773 | acpi_battery_remove_fs(device); | 749 | acpi_battery_remove_fs(device); |
774 | 750 | ||
775 | kfree(battery); | 751 | kfree(battery); |
776 | 752 | ||
777 | return_VALUE(0); | 753 | return 0; |
778 | } | 754 | } |
779 | 755 | ||
780 | static int __init acpi_battery_init(void) | 756 | static int __init acpi_battery_init(void) |
781 | { | 757 | { |
782 | int result = 0; | 758 | int result; |
783 | 759 | ||
784 | ACPI_FUNCTION_TRACE("acpi_battery_init"); | 760 | if (acpi_disabled) |
761 | return -ENODEV; | ||
785 | 762 | ||
786 | acpi_battery_dir = proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); | 763 | acpi_battery_dir = acpi_lock_battery_dir(); |
787 | if (!acpi_battery_dir) | 764 | if (!acpi_battery_dir) |
788 | return_VALUE(-ENODEV); | 765 | return -ENODEV; |
789 | acpi_battery_dir->owner = THIS_MODULE; | ||
790 | 766 | ||
791 | result = acpi_bus_register_driver(&acpi_battery_driver); | 767 | result = acpi_bus_register_driver(&acpi_battery_driver); |
792 | if (result < 0) { | 768 | if (result < 0) { |
793 | remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); | 769 | acpi_unlock_battery_dir(acpi_battery_dir); |
794 | return_VALUE(-ENODEV); | 770 | return -ENODEV; |
795 | } | 771 | } |
796 | 772 | ||
797 | return_VALUE(0); | 773 | return 0; |
798 | } | 774 | } |
799 | 775 | ||
800 | static void __exit acpi_battery_exit(void) | 776 | static void __exit acpi_battery_exit(void) |
801 | { | 777 | { |
802 | ACPI_FUNCTION_TRACE("acpi_battery_exit"); | ||
803 | 778 | ||
804 | acpi_bus_unregister_driver(&acpi_battery_driver); | 779 | acpi_bus_unregister_driver(&acpi_battery_driver); |
805 | 780 | ||
806 | remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); | 781 | acpi_unlock_battery_dir(acpi_battery_dir); |
807 | 782 | ||
808 | return_VOID; | 783 | return; |
809 | } | 784 | } |
810 | 785 | ||
811 | module_init(acpi_battery_init); | 786 | module_init(acpi_battery_init); |