aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r--drivers/acpi/battery.c47
1 files changed, 17 insertions, 30 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 81651032791b..d7b499fe0cd9 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -113,7 +113,7 @@ struct acpi_battery_info {
113 acpi_string oem_info; 113 acpi_string oem_info;
114}; 114};
115 115
116enum acpi_battery_files{ 116enum acpi_battery_files {
117 ACPI_BATTERY_INFO = 0, 117 ACPI_BATTERY_INFO = 0,
118 ACPI_BATTERY_STATE, 118 ACPI_BATTERY_STATE,
119 ACPI_BATTERY_ALARM, 119 ACPI_BATTERY_ALARM,
@@ -129,13 +129,14 @@ struct acpi_battery_flags {
129}; 129};
130 130
131struct acpi_battery { 131struct acpi_battery {
132 struct mutex mutex;
133 struct acpi_device *device; 132 struct acpi_device *device;
134 struct acpi_battery_flags flags; 133 struct acpi_battery_flags flags;
135 struct acpi_buffer bif_data; 134 struct acpi_buffer bif_data;
136 struct acpi_buffer bst_data; 135 struct acpi_buffer bst_data;
136 struct mutex lock;
137 unsigned long alarm; 137 unsigned long alarm;
138 unsigned long update_time[ACPI_BATTERY_NUMFILES]; 138 unsigned long update_time[ACPI_BATTERY_NUMFILES];
139
139}; 140};
140 141
141inline int acpi_battery_present(struct acpi_battery *battery) 142inline int acpi_battery_present(struct acpi_battery *battery)
@@ -235,10 +236,10 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
235 return 0; 236 return 0;
236 237
237 /* Evaluate _BIF */ 238 /* Evaluate _BIF */
238 239 mutex_lock(&battery->lock);
239 status = 240 status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF",
240 acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, 241 NULL, &buffer);
241 &buffer); 242 mutex_unlock(&battery->lock);
242 if (ACPI_FAILURE(status)) { 243 if (ACPI_FAILURE(status)) {
243 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); 244 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
244 return -ENODEV; 245 return -ENODEV;
@@ -285,10 +286,10 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
285 return 0; 286 return 0;
286 287
287 /* Evaluate _BST */ 288 /* Evaluate _BST */
288 289 mutex_lock(&battery->lock);
289 status = 290 status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST",
290 acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, 291 NULL, &buffer);
291 &buffer); 292 mutex_unlock(&battery->lock);
292 if (ACPI_FAILURE(status)) { 293 if (ACPI_FAILURE(status)) {
293 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); 294 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
294 return -ENODEV; 295 return -ENODEV;
@@ -336,9 +337,10 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
336 337
337 arg0.integer.value = alarm; 338 arg0.integer.value = alarm;
338 339
339 status = 340 mutex_lock(&battery->lock);
340 acpi_evaluate_object(acpi_battery_handle(battery), "_BTP", 341 status = acpi_evaluate_object(acpi_battery_handle(battery), "_BTP",
341 &arg_list, NULL); 342 &arg_list, NULL);
343 mutex_unlock(&battery->lock);
342 if (ACPI_FAILURE(status)) 344 if (ACPI_FAILURE(status))
343 return -ENODEV; 345 return -ENODEV;
344 346
@@ -658,8 +660,6 @@ acpi_battery_write_alarm(struct file *file,
658 if (!battery || (count > sizeof(alarm_string) - 1)) 660 if (!battery || (count > sizeof(alarm_string) - 1))
659 return -EINVAL; 661 return -EINVAL;
660 662
661 mutex_lock(&battery->mutex);
662
663 result = acpi_battery_update(battery, 1, &update_result); 663 result = acpi_battery_update(battery, 1, &update_result);
664 if (result) { 664 if (result) {
665 result = -ENODEV; 665 result = -ENODEV;
@@ -688,9 +688,7 @@ acpi_battery_write_alarm(struct file *file,
688 acpi_battery_check_result(battery, result); 688 acpi_battery_check_result(battery, result);
689 689
690 if (!result) 690 if (!result)
691 result = count; 691 return count;
692
693 mutex_unlock(&battery->mutex);
694 692
695 return result; 693 return result;
696} 694}
@@ -714,8 +712,6 @@ static int acpi_battery_read(int fid, struct seq_file *seq)
714 int update_result = ACPI_BATTERY_NONE_UPDATE; 712 int update_result = ACPI_BATTERY_NONE_UPDATE;
715 int update = 0; 713 int update = 0;
716 714
717 mutex_lock(&battery->mutex);
718
719 update = (get_seconds() - battery->update_time[fid] >= update_time); 715 update = (get_seconds() - battery->update_time[fid] >= update_time);
720 update = (update | battery->flags.update[fid]); 716 update = (update | battery->flags.update[fid]);
721 717
@@ -733,7 +729,6 @@ static int acpi_battery_read(int fid, struct seq_file *seq)
733 result = acpi_read_funcs[fid].print(seq, result); 729 result = acpi_read_funcs[fid].print(seq, result);
734 acpi_battery_check_result(battery, result); 730 acpi_battery_check_result(battery, result);
735 battery->flags.update[fid] = result; 731 battery->flags.update[fid] = result;
736 mutex_unlock(&battery->mutex);
737 return result; 732 return result;
738} 733}
739 734
@@ -897,10 +892,7 @@ static int acpi_battery_add(struct acpi_device *device)
897 if (!battery) 892 if (!battery)
898 return -ENOMEM; 893 return -ENOMEM;
899 894
900 mutex_init(&battery->mutex); 895 mutex_init(&battery->lock);
901
902 mutex_lock(&battery->mutex);
903
904 battery->device = device; 896 battery->device = device;
905 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 897 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
906 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); 898 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
@@ -936,7 +928,6 @@ static int acpi_battery_add(struct acpi_device *device)
936 kfree(battery); 928 kfree(battery);
937 } 929 }
938 930
939 mutex_unlock(&battery->mutex);
940 931
941 return result; 932 return result;
942} 933}
@@ -951,8 +942,6 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
951 942
952 battery = acpi_driver_data(device); 943 battery = acpi_driver_data(device);
953 944
954 mutex_lock(&battery->mutex);
955
956 status = acpi_remove_notify_handler(device->handle, 945 status = acpi_remove_notify_handler(device->handle,
957 ACPI_ALL_NOTIFY, 946 ACPI_ALL_NOTIFY,
958 acpi_battery_notify); 947 acpi_battery_notify);
@@ -963,9 +952,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
963 952
964 kfree(battery->bst_data.pointer); 953 kfree(battery->bst_data.pointer);
965 954
966 mutex_unlock(&battery->mutex); 955 mutex_destroy(&battery->lock);
967
968 mutex_destroy(&battery->mutex);
969 956
970 kfree(battery); 957 kfree(battery);
971 958