aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlexey Starikovskiy <aystarik@gmail.com>2007-05-11 13:18:55 -0400
committerLen Brown <len.brown@intel.com>2007-05-11 13:18:55 -0400
commit78490d82129f7331d1366737c8704c1c053221a3 (patch)
tree37244abd82fc46032a1e6b60ddb2264027603458 /drivers
parent6eedeef73e7fff32eb5fa25178c3c77b1db0ec0f (diff)
ACPI: battery: syntax cleanup
In response to review comments from Andrew Morton Signed-off-by: Alexey Starikovskiy <aystarik@gmail.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/battery.c418
1 files changed, 172 insertions, 246 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index b5df318978ed..cad932de383d 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -43,9 +43,6 @@
43#define ACPI_BATTERY_CLASS "battery" 43#define ACPI_BATTERY_CLASS "battery"
44#define ACPI_BATTERY_HID "PNP0C0A" 44#define ACPI_BATTERY_HID "PNP0C0A"
45#define ACPI_BATTERY_DEVICE_NAME "Battery" 45#define ACPI_BATTERY_DEVICE_NAME "Battery"
46#define ACPI_BATTERY_FILE_INFO "info"
47#define ACPI_BATTERY_FILE_STATE "state"
48#define ACPI_BATTERY_FILE_ALARM "alarm"
49#define ACPI_BATTERY_NOTIFY_STATUS 0x80 46#define ACPI_BATTERY_NOTIFY_STATUS 0x80
50#define ACPI_BATTERY_NOTIFY_INFO 0x81 47#define ACPI_BATTERY_NOTIFY_INFO 0x81
51#define ACPI_BATTERY_UNITS_WATTS "mW" 48#define ACPI_BATTERY_UNITS_WATTS "mW"
@@ -111,13 +108,18 @@ struct acpi_battery_info {
111 acpi_string oem_info; 108 acpi_string oem_info;
112}; 109};
113 110
111enum acpi_battery_files{
112 ACPI_BATTERY_INFO = 0,
113 ACPI_BATTERY_STATE,
114 ACPI_BATTERY_ALARM,
115 ACPI_BATTERY_NUMFILES,
116};
117
114struct acpi_battery_flags { 118struct acpi_battery_flags {
115 u8 battery_present_prev; 119 u8 battery_present_prev;
116 u8 alarm_present; 120 u8 alarm_present;
117 u8 init_update; 121 u8 init_update;
118 u8 info_update; 122 u8 update[ACPI_BATTERY_NUMFILES];
119 u8 state_update;
120 u8 alarm_update;
121 u8 power_unit; 123 u8 power_unit;
122}; 124};
123 125
@@ -128,47 +130,37 @@ struct acpi_battery {
128 struct acpi_buffer bif_data; 130 struct acpi_buffer bif_data;
129 struct acpi_buffer bst_data; 131 struct acpi_buffer bst_data;
130 unsigned long alarm; 132 unsigned long alarm;
131 unsigned long info_update_time; 133 unsigned long update_time[ACPI_BATTERY_NUMFILES];
132 unsigned long state_update_time;
133 unsigned long alarm_update_time;
134}; 134};
135 135
136#define acpi_battery_present(battery) battery->device->status.battery_present 136inline int acpi_battery_present(struct acpi_battery *battery)
137#define acpi_battery_present_prev(battery) battery->flags.battery_present_prev
138#define acpi_battery_alarm_present(battery) battery->flags.alarm_present
139#define acpi_battery_init_update_flag(battery) battery->flags.init_update
140#define acpi_battery_info_update_flag(battery) battery->flags.info_update
141#define acpi_battery_state_update_flag(battery) battery->flags.state_update
142#define acpi_battery_alarm_update_flag(battery) battery->flags.alarm_update
143#define acpi_battery_power_units(battery) battery->flags.power_unit ? \
144 ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS
145#define acpi_battery_handle(battery) battery->device->handle
146#define acpi_battery_inserted(battery) (!acpi_battery_present_prev(battery) & acpi_battery_present(battery))
147#define acpi_battery_removed(battery) (acpi_battery_present_prev(battery) & !acpi_battery_present(battery))
148#define acpi_battery_bid(battery) acpi_device_bid(battery->device)
149#define acpi_battery_status_str(battery) acpi_battery_present(battery) ? "present" : "absent"
150
151/* --------------------------------------------------------------------------
152 Battery Management
153 -------------------------------------------------------------------------- */
154
155static void acpi_battery_mutex_lock(struct acpi_battery *battery)
156{ 137{
157 mutex_lock(&battery->mutex); 138 return battery->device->status.battery_present;
139}
140inline char *acpi_battery_power_units(struct acpi_battery *battery)
141{
142 if (battery->flags.power_unit)
143 return ACPI_BATTERY_UNITS_AMPS;
144 else
145 return ACPI_BATTERY_UNITS_WATTS;
158} 146}
159 147
160static void acpi_battery_mutex_unlock(struct acpi_battery *battery) 148inline acpi_handle acpi_battery_handle(struct acpi_battery *battery)
161{ 149{
162 mutex_unlock(&battery->mutex); 150 return battery->device->handle;
163} 151}
164 152
153/* --------------------------------------------------------------------------
154 Battery Management
155 -------------------------------------------------------------------------- */
156
165static void acpi_battery_check_result(struct acpi_battery *battery, int result) 157static void acpi_battery_check_result(struct acpi_battery *battery, int result)
166{ 158{
167 if (!battery) 159 if (!battery)
168 return; 160 return;
169 161
170 if (result) { 162 if (result) {
171 acpi_battery_init_update_flag(battery) = 1; 163 battery->flags.init_update = 1;
172 } 164 }
173} 165}
174 166
@@ -189,9 +181,7 @@ static int acpi_battery_extract_package(struct acpi_battery *battery,
189 } 181 }
190 182
191 if (data_null.length != data->length) { 183 if (data_null.length != data->length) {
192 if (data->pointer) { 184 kfree(data->pointer);
193 kfree(data->pointer);
194 }
195 data->pointer = kzalloc(data_null.length, GFP_KERNEL); 185 data->pointer = kzalloc(data_null.length, GFP_KERNEL);
196 if (!data->pointer) { 186 if (!data->pointer) {
197 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()")); 187 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()"));
@@ -234,12 +224,12 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
234 struct acpi_buffer *data = NULL; 224 struct acpi_buffer *data = NULL;
235 struct acpi_battery_info *bif = NULL; 225 struct acpi_battery_info *bif = NULL;
236 226
237 battery->info_update_time = get_seconds(); 227 battery->update_time[ACPI_BATTERY_INFO] = get_seconds();
238 228
239 if (!acpi_battery_present(battery)) 229 if (!acpi_battery_present(battery))
240 return 0; 230 return 0;
241 231
242 /* Evalute _BIF */ 232 /* Evaluate _BIF */
243 233
244 status = 234 status =
245 acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, 235 acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL,
@@ -263,9 +253,7 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
263 253
264 end: 254 end:
265 255
266 if (buffer.pointer) { 256 kfree(buffer.pointer);
267 kfree(buffer.pointer);
268 }
269 257
270 if (!result) { 258 if (!result) {
271 bif = data->pointer; 259 bif = data->pointer;
@@ -286,12 +274,12 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
286 union acpi_object *package = NULL; 274 union acpi_object *package = NULL;
287 struct acpi_buffer *data = NULL; 275 struct acpi_buffer *data = NULL;
288 276
289 battery->state_update_time = get_seconds(); 277 battery->update_time[ACPI_BATTERY_STATE] = get_seconds();
290 278
291 if (!acpi_battery_present(battery)) 279 if (!acpi_battery_present(battery))
292 return 0; 280 return 0;
293 281
294 /* Evalute _BST */ 282 /* Evaluate _BST */
295 283
296 status = 284 status =
297 acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, 285 acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL,
@@ -314,16 +302,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
314 goto end; 302 goto end;
315 303
316 end: 304 end:
317 if (buffer.pointer) { 305 kfree(buffer.pointer);
318 kfree(buffer.pointer);
319 }
320 306
321 return result; 307 return result;
322} 308}
323 309
324static int acpi_battery_get_alarm(struct acpi_battery *battery) 310static int acpi_battery_get_alarm(struct acpi_battery *battery)
325{ 311{
326 battery->alarm_update_time = get_seconds(); 312 battery->update_time[ACPI_BATTERY_ALARM] = get_seconds();
327 313
328 return 0; 314 return 0;
329} 315}
@@ -335,12 +321,12 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
335 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 321 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
336 struct acpi_object_list arg_list = { 1, &arg0 }; 322 struct acpi_object_list arg_list = { 1, &arg0 };
337 323
338 battery->alarm_update_time = get_seconds(); 324 battery->update_time[ACPI_BATTERY_ALARM] = get_seconds();
339 325
340 if (!acpi_battery_present(battery)) 326 if (!acpi_battery_present(battery))
341 return -ENODEV; 327 return -ENODEV;
342 328
343 if (!acpi_battery_alarm_present(battery)) 329 if (!battery->flags.alarm_present)
344 return -ENODEV; 330 return -ENODEV;
345 331
346 arg0.integer.value = alarm; 332 arg0.integer.value = alarm;
@@ -370,7 +356,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery)
370 356
371 status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle); 357 status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle);
372 if (ACPI_SUCCESS(status)) { 358 if (ACPI_SUCCESS(status)) {
373 acpi_battery_alarm_present(battery) = 1; 359 battery->flags.alarm_present = 1;
374 if (!alarm && bif) { 360 if (!alarm && bif) {
375 alarm = bif->design_capacity_warning; 361 alarm = bif->design_capacity_warning;
376 } 362 }
@@ -378,7 +364,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery)
378 if (result) 364 if (result)
379 goto end; 365 goto end;
380 } else { 366 } else {
381 acpi_battery_alarm_present(battery) = 0; 367 battery->flags.alarm_present = 0;
382 } 368 }
383 369
384 end: 370 end:
@@ -394,7 +380,7 @@ static int acpi_battery_init_update(struct acpi_battery *battery)
394 if (result) 380 if (result)
395 return result; 381 return result;
396 382
397 acpi_battery_present_prev(battery) = acpi_battery_present(battery); 383 battery->flags.battery_present_prev = acpi_battery_present(battery);
398 384
399 if (acpi_battery_present(battery)) { 385 if (acpi_battery_present(battery)) {
400 result = acpi_battery_get_info(battery); 386 result = acpi_battery_get_info(battery);
@@ -420,20 +406,20 @@ static int acpi_battery_update(struct acpi_battery *battery,
420 update = 1; 406 update = 1;
421 } 407 }
422 408
423 if (acpi_battery_init_update_flag(battery)) { 409 if (battery->flags.init_update) {
424 result = acpi_battery_init_update(battery); 410 result = acpi_battery_init_update(battery);
425 if (result) 411 if (result)
426 goto end;; 412 goto end;
427 update_result = ACPI_BATTERY_INIT_UPDATE; 413 update_result = ACPI_BATTERY_INIT_UPDATE;
428 } else if (update) { 414 } else if (update) {
429 result = acpi_battery_get_status(battery); 415 result = acpi_battery_get_status(battery);
430 if (result) 416 if (result)
431 goto end;; 417 goto end;
432 if (acpi_battery_inserted(battery) 418 if ((!battery->flags.battery_present_prev & acpi_battery_present(battery))
433 || acpi_battery_removed(battery)) { 419 || (battery->flags.battery_present_prev & !acpi_battery_present(battery))) {
434 result = acpi_battery_init_update(battery); 420 result = acpi_battery_init_update(battery);
435 if (result) 421 if (result)
436 goto end;; 422 goto end;
437 update_result = ACPI_BATTERY_INIT_UPDATE; 423 update_result = ACPI_BATTERY_INIT_UPDATE;
438 } else { 424 } else {
439 update_result = ACPI_BATTERY_EASY_UPDATE; 425 update_result = ACPI_BATTERY_EASY_UPDATE;
@@ -442,7 +428,7 @@ static int acpi_battery_update(struct acpi_battery *battery,
442 428
443 end: 429 end:
444 430
445 acpi_battery_init_update_flag(battery) = (result != 0); 431 battery->flags.init_update = (result != 0);
446 432
447 *update_result_ptr = update_result; 433 *update_result_ptr = update_result;
448 434
@@ -453,16 +439,19 @@ static void acpi_battery_notify_update(struct acpi_battery *battery)
453{ 439{
454 acpi_battery_get_status(battery); 440 acpi_battery_get_status(battery);
455 441
456 if (acpi_battery_init_update_flag(battery)) { 442 if (battery->flags.init_update) {
457 return; 443 return;
458 } 444 }
459 445
460 if (acpi_battery_inserted(battery) || acpi_battery_removed(battery)) { 446 if ((!battery->flags.battery_present_prev &
461 acpi_battery_init_update_flag(battery) = 1; 447 acpi_battery_present(battery)) ||
448 (battery->flags.battery_present_prev &
449 !acpi_battery_present(battery))) {
450 battery->flags.init_update = 1;
462 } else { 451 } else {
463 acpi_battery_info_update_flag(battery) = 1; 452 battery->flags.update[ACPI_BATTERY_INFO] = 1;
464 acpi_battery_state_update_flag(battery) = 1; 453 battery->flags.update[ACPI_BATTERY_STATE] = 1;
465 acpi_battery_alarm_update_flag(battery) = 1; 454 battery->flags.update[ACPI_BATTERY_ALARM] = 1;
466 } 455 }
467} 456}
468 457
@@ -472,7 +461,7 @@ static void acpi_battery_notify_update(struct acpi_battery *battery)
472 461
473static struct proc_dir_entry *acpi_battery_dir; 462static struct proc_dir_entry *acpi_battery_dir;
474 463
475static int acpi_battery_read_info_print(struct seq_file *seq, int result) 464static int acpi_battery_print_info(struct seq_file *seq, int result)
476{ 465{
477 struct acpi_battery *battery = seq->private; 466 struct acpi_battery *battery = seq->private;
478 struct acpi_battery_info *bif = NULL; 467 struct acpi_battery_info *bif = NULL;
@@ -549,49 +538,7 @@ static int acpi_battery_read_info_print(struct seq_file *seq, int result)
549 return result; 538 return result;
550} 539}
551 540
552static int acpi_battery_read_info(struct seq_file *seq, void *offset) 541static int acpi_battery_print_state(struct seq_file *seq, int result)
553{
554 struct acpi_battery *battery = seq->private;
555 int result = 0;
556 int update_result = ACPI_BATTERY_NONE_UPDATE;
557 int update = 0;
558
559 acpi_battery_mutex_lock(battery);
560
561 update = (get_seconds() - battery->info_update_time >= update_time);
562 update = (update | acpi_battery_info_update_flag(battery));
563
564 result = acpi_battery_update(battery, update, &update_result);
565 if (result)
566 goto end;
567
568 /* Battery Info (_BIF) */
569
570 if (update_result == ACPI_BATTERY_EASY_UPDATE) {
571 result = acpi_battery_get_info(battery);
572 if (result)
573 goto end;
574 }
575
576 end:
577
578 result = acpi_battery_read_info_print(seq, result);
579
580 acpi_battery_check_result(battery, result);
581
582 acpi_battery_info_update_flag(battery) = result;
583
584 acpi_battery_mutex_unlock(battery);
585
586 return result;
587}
588
589static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
590{
591 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
592}
593
594static int acpi_battery_read_state_print(struct seq_file *seq, int result)
595{ 542{
596 struct acpi_battery *battery = seq->private; 543 struct acpi_battery *battery = seq->private;
597 struct acpi_battery_state *bst = NULL; 544 struct acpi_battery_state *bst = NULL;
@@ -661,49 +608,7 @@ static int acpi_battery_read_state_print(struct seq_file *seq, int result)
661 return result; 608 return result;
662} 609}
663 610
664static int acpi_battery_read_state(struct seq_file *seq, void *offset) 611static int acpi_battery_print_alarm(struct seq_file *seq, int result)
665{
666 struct acpi_battery *battery = seq->private;
667 int result = 0;
668 int update_result = ACPI_BATTERY_NONE_UPDATE;
669 int update = 0;
670
671 acpi_battery_mutex_lock(battery);
672
673 update = (get_seconds() - battery->state_update_time >= update_time);
674 update = (update | acpi_battery_state_update_flag(battery));
675
676 result = acpi_battery_update(battery, update, &update_result);
677 if (result)
678 goto end;
679
680 /* Battery State (_BST) */
681
682 if (update_result == ACPI_BATTERY_EASY_UPDATE) {
683 result = acpi_battery_get_state(battery);
684 if (result)
685 goto end;
686 }
687
688 end:
689
690 result = acpi_battery_read_state_print(seq, result);
691
692 acpi_battery_check_result(battery, result);
693
694 acpi_battery_state_update_flag(battery) = result;
695
696 acpi_battery_mutex_unlock(battery);
697
698 return result;
699}
700
701static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
702{
703 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
704}
705
706static int acpi_battery_read_alarm_print(struct seq_file *seq, int result)
707{ 612{
708 struct acpi_battery *battery = seq->private; 613 struct acpi_battery *battery = seq->private;
709 char *units = "?"; 614 char *units = "?";
@@ -734,43 +639,6 @@ static int acpi_battery_read_alarm_print(struct seq_file *seq, int result)
734 return result; 639 return result;
735} 640}
736 641
737static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
738{
739 struct acpi_battery *battery = seq->private;
740 int result = 0;
741 int update_result = ACPI_BATTERY_NONE_UPDATE;
742 int update = 0;
743
744 acpi_battery_mutex_lock(battery);
745
746 update = (get_seconds() - battery->alarm_update_time >= update_time);
747 update = (update | acpi_battery_alarm_update_flag(battery));
748
749 result = acpi_battery_update(battery, update, &update_result);
750 if (result)
751 goto end;
752
753 /* Battery Alarm */
754
755 if (update_result == ACPI_BATTERY_EASY_UPDATE) {
756 result = acpi_battery_get_alarm(battery);
757 if (result)
758 goto end;
759 }
760
761 end:
762
763 result = acpi_battery_read_alarm_print(seq, result);
764
765 acpi_battery_check_result(battery, result);
766
767 acpi_battery_alarm_update_flag(battery) = result;
768
769 acpi_battery_mutex_unlock(battery);
770
771 return result;
772}
773
774static ssize_t 642static ssize_t
775acpi_battery_write_alarm(struct file *file, 643acpi_battery_write_alarm(struct file *file,
776 const char __user * buffer, 644 const char __user * buffer,
@@ -785,7 +653,7 @@ acpi_battery_write_alarm(struct file *file,
785 if (!battery || (count > sizeof(alarm_string) - 1)) 653 if (!battery || (count > sizeof(alarm_string) - 1))
786 return -EINVAL; 654 return -EINVAL;
787 655
788 acpi_battery_mutex_lock(battery); 656 mutex_lock(&battery->mutex);
789 657
790 result = acpi_battery_update(battery, 1, &update_result); 658 result = acpi_battery_update(battery, 1, &update_result);
791 if (result) { 659 if (result) {
@@ -817,44 +685,128 @@ acpi_battery_write_alarm(struct file *file,
817 if (!result) 685 if (!result)
818 result = count; 686 result = count;
819 687
820 acpi_battery_mutex_unlock(battery); 688 mutex_unlock(&battery->mutex);
689
690 return result;
691}
692
693typedef int(*print_func)(struct seq_file *seq, int result);
694typedef int(*get_func)(struct acpi_battery *battery);
695
696static struct acpi_read_mux {
697 print_func print;
698 get_func get;
699} acpi_read_funcs[ACPI_BATTERY_NUMFILES] = {
700 {.get = acpi_battery_get_info, .print = acpi_battery_print_info},
701 {.get = acpi_battery_get_state, .print = acpi_battery_print_state},
702 {.get = acpi_battery_get_alarm, .print = acpi_battery_print_alarm},
703};
821 704
705static int acpi_battery_read(int fid, struct seq_file *seq)
706{
707 struct acpi_battery *battery = seq->private;
708 int result = 0;
709 int update_result = ACPI_BATTERY_NONE_UPDATE;
710 int update = 0;
711
712 mutex_lock(&battery->mutex);
713
714 update = (get_seconds() - battery->update_time[fid] >= update_time);
715 update = (update | battery->flags.update[fid]);
716
717 result = acpi_battery_update(battery, update, &update_result);
718 if (result)
719 goto end;
720
721 if (update_result == ACPI_BATTERY_EASY_UPDATE) {
722 result = acpi_read_funcs[fid].get(battery);
723 if (result)
724 goto end;
725 }
726
727 end:
728 result = acpi_read_funcs[fid].print(seq, result);
729 acpi_battery_check_result(battery, result);
730 battery->flags.update[fid] = result;
731 mutex_unlock(&battery->mutex);
822 return result; 732 return result;
823} 733}
824 734
735static int acpi_battery_read_info(struct seq_file *seq, void *offset)
736{
737 return acpi_battery_read(ACPI_BATTERY_INFO, seq);
738}
739
740static int acpi_battery_read_state(struct seq_file *seq, void *offset)
741{
742 return acpi_battery_read(ACPI_BATTERY_STATE, seq);
743}
744
745static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
746{
747 return acpi_battery_read(ACPI_BATTERY_ALARM, seq);
748}
749
750static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
751{
752 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
753}
754
755static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
756{
757 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
758}
759
825static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) 760static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
826{ 761{
827 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); 762 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
828} 763}
829 764
830static const struct file_operations acpi_battery_info_ops = { 765static struct battery_file {
766 struct file_operations ops;
767 mode_t mode;
768 char *name;
769} acpi_battery_file[] = {
770 {
771 .name = "info",
772 .mode = S_IRUGO,
773 .ops = {
831 .open = acpi_battery_info_open_fs, 774 .open = acpi_battery_info_open_fs,
832 .read = seq_read, 775 .read = seq_read,
833 .llseek = seq_lseek, 776 .llseek = seq_lseek,
834 .release = single_release, 777 .release = single_release,
835 .owner = THIS_MODULE, 778 .owner = THIS_MODULE,
836}; 779 },
837 780 },
838static const struct file_operations acpi_battery_state_ops = { 781 {
782 .name = "state",
783 .mode = S_IRUGO,
784 .ops = {
839 .open = acpi_battery_state_open_fs, 785 .open = acpi_battery_state_open_fs,
840 .read = seq_read, 786 .read = seq_read,
841 .llseek = seq_lseek, 787 .llseek = seq_lseek,
842 .release = single_release, 788 .release = single_release,
843 .owner = THIS_MODULE, 789 .owner = THIS_MODULE,
844}; 790 },
845 791 },
846static const struct file_operations acpi_battery_alarm_ops = { 792 {
793 .name = "alarm",
794 .mode = S_IFREG | S_IRUGO | S_IWUSR,
795 .ops = {
847 .open = acpi_battery_alarm_open_fs, 796 .open = acpi_battery_alarm_open_fs,
848 .read = seq_read, 797 .read = seq_read,
849 .write = acpi_battery_write_alarm, 798 .write = acpi_battery_write_alarm,
850 .llseek = seq_lseek, 799 .llseek = seq_lseek,
851 .release = single_release, 800 .release = single_release,
852 .owner = THIS_MODULE, 801 .owner = THIS_MODULE,
802 },
803 },
853}; 804};
854 805
855static int acpi_battery_add_fs(struct acpi_device *device) 806static int acpi_battery_add_fs(struct acpi_device *device)
856{ 807{
857 struct proc_dir_entry *entry = NULL; 808 struct proc_dir_entry *entry = NULL;
809 int i;
858 810
859 if (!acpi_device_dir(device)) { 811 if (!acpi_device_dir(device)) {
860 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 812 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
@@ -864,38 +816,16 @@ static int acpi_battery_add_fs(struct acpi_device *device)
864 acpi_device_dir(device)->owner = THIS_MODULE; 816 acpi_device_dir(device)->owner = THIS_MODULE;
865 } 817 }
866 818
867 /* 'info' [R] */ 819 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
868 entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, 820 entry = create_proc_entry(acpi_battery_file[i].name,
869 S_IRUGO, acpi_device_dir(device)); 821 acpi_battery_file[i].mode, acpi_device_dir(device));
870 if (!entry) 822 if (!entry)
871 return -ENODEV; 823 return -ENODEV;
872 else { 824 else {
873 entry->proc_fops = &acpi_battery_info_ops; 825 entry->proc_fops = &acpi_battery_file[i].ops;
874 entry->data = acpi_driver_data(device); 826 entry->data = acpi_driver_data(device);
875 entry->owner = THIS_MODULE; 827 entry->owner = THIS_MODULE;
876 } 828 }
877
878 /* 'status' [R] */
879 entry = create_proc_entry(ACPI_BATTERY_FILE_STATE,
880 S_IRUGO, acpi_device_dir(device));
881 if (!entry)
882 return -ENODEV;
883 else {
884 entry->proc_fops = &acpi_battery_state_ops;
885 entry->data = acpi_driver_data(device);
886 entry->owner = THIS_MODULE;
887 }
888
889 /* 'alarm' [R/W] */
890 entry = create_proc_entry(ACPI_BATTERY_FILE_ALARM,
891 S_IFREG | S_IRUGO | S_IWUSR,
892 acpi_device_dir(device));
893 if (!entry)
894 return -ENODEV;
895 else {
896 entry->proc_fops = &acpi_battery_alarm_ops;
897 entry->data = acpi_driver_data(device);
898 entry->owner = THIS_MODULE;
899 } 829 }
900 830
901 return 0; 831 return 0;
@@ -903,14 +833,12 @@ static int acpi_battery_add_fs(struct acpi_device *device)
903 833
904static int acpi_battery_remove_fs(struct acpi_device *device) 834static int acpi_battery_remove_fs(struct acpi_device *device)
905{ 835{
836 int i;
906 if (acpi_device_dir(device)) { 837 if (acpi_device_dir(device)) {
907 remove_proc_entry(ACPI_BATTERY_FILE_ALARM, 838 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
908 acpi_device_dir(device)); 839 remove_proc_entry(acpi_battery_file[i].name,
909 remove_proc_entry(ACPI_BATTERY_FILE_STATE,
910 acpi_device_dir(device));
911 remove_proc_entry(ACPI_BATTERY_FILE_INFO,
912 acpi_device_dir(device)); 840 acpi_device_dir(device));
913 841 }
914 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); 842 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
915 acpi_device_dir(device) = NULL; 843 acpi_device_dir(device) = NULL;
916 } 844 }
@@ -966,7 +894,7 @@ static int acpi_battery_add(struct acpi_device *device)
966 894
967 mutex_init(&battery->mutex); 895 mutex_init(&battery->mutex);
968 896
969 acpi_battery_mutex_lock(battery); 897 mutex_lock(&battery->mutex);
970 898
971 battery->device = device; 899 battery->device = device;
972 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 900 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
@@ -977,7 +905,7 @@ static int acpi_battery_add(struct acpi_device *device)
977 if (result) 905 if (result)
978 goto end; 906 goto end;
979 907
980 acpi_battery_init_update_flag(battery) = 1; 908 battery->flags.init_update = 1;
981 909
982 result = acpi_battery_add_fs(device); 910 result = acpi_battery_add_fs(device);
983 if (result) 911 if (result)
@@ -1003,7 +931,7 @@ static int acpi_battery_add(struct acpi_device *device)
1003 kfree(battery); 931 kfree(battery);
1004 } 932 }
1005 933
1006 acpi_battery_mutex_unlock(battery); 934 mutex_unlock(&battery->mutex);
1007 935
1008 return result; 936 return result;
1009} 937}
@@ -1018,7 +946,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
1018 946
1019 battery = acpi_driver_data(device); 947 battery = acpi_driver_data(device);
1020 948
1021 acpi_battery_mutex_lock(battery); 949 mutex_lock(&battery->mutex);
1022 950
1023 status = acpi_remove_notify_handler(device->handle, 951 status = acpi_remove_notify_handler(device->handle,
1024 ACPI_ALL_NOTIFY, 952 ACPI_ALL_NOTIFY,
@@ -1026,13 +954,11 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
1026 954
1027 acpi_battery_remove_fs(device); 955 acpi_battery_remove_fs(device);
1028 956
1029 if (battery->bif_data.pointer) 957 kfree(battery->bif_data.pointer);
1030 kfree(battery->bif_data.pointer);
1031 958
1032 if (battery->bst_data.pointer) 959 kfree(battery->bst_data.pointer);
1033 kfree(battery->bst_data.pointer);
1034 960
1035 acpi_battery_mutex_unlock(battery); 961 mutex_unlock(&battery->mutex);
1036 962
1037 mutex_destroy(&battery->mutex); 963 mutex_destroy(&battery->mutex);
1038 964
@@ -1051,7 +977,7 @@ static int acpi_battery_resume(struct acpi_device *device)
1051 977
1052 battery = device->driver_data; 978 battery = device->driver_data;
1053 979
1054 acpi_battery_init_update_flag(battery) = 1; 980 battery->flags.init_update = 1;
1055 981
1056 return 0; 982 return 0;
1057} 983}