diff options
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r-- | drivers/acpi/battery.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 192c244f6190..c4a769d1ba85 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <linux/types.h> | 31 | #include <linux/types.h> |
32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
33 | 33 | ||
34 | #ifdef CONFIG_ACPI_PROCFS | 34 | #ifdef CONFIG_ACPI_PROCFS_POWER |
35 | #include <linux/proc_fs.h> | 35 | #include <linux/proc_fs.h> |
36 | #include <linux/seq_file.h> | 36 | #include <linux/seq_file.h> |
37 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
@@ -40,7 +40,9 @@ | |||
40 | #include <acpi/acpi_bus.h> | 40 | #include <acpi/acpi_bus.h> |
41 | #include <acpi/acpi_drivers.h> | 41 | #include <acpi/acpi_drivers.h> |
42 | 42 | ||
43 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
43 | #include <linux/power_supply.h> | 44 | #include <linux/power_supply.h> |
45 | #endif | ||
44 | 46 | ||
45 | #define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF | 47 | #define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF |
46 | 48 | ||
@@ -63,7 +65,7 @@ static unsigned int cache_time = 1000; | |||
63 | module_param(cache_time, uint, 0644); | 65 | module_param(cache_time, uint, 0644); |
64 | MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); | 66 | MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); |
65 | 67 | ||
66 | #ifdef CONFIG_ACPI_PROCFS | 68 | #ifdef CONFIG_ACPI_PROCFS_POWER |
67 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); | 69 | extern struct proc_dir_entry *acpi_lock_battery_dir(void); |
68 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); | 70 | extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); |
69 | 71 | ||
@@ -86,7 +88,9 @@ MODULE_DEVICE_TABLE(acpi, battery_device_ids); | |||
86 | 88 | ||
87 | struct acpi_battery { | 89 | struct acpi_battery { |
88 | struct mutex lock; | 90 | struct mutex lock; |
91 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
89 | struct power_supply bat; | 92 | struct power_supply bat; |
93 | #endif | ||
90 | struct acpi_device *device; | 94 | struct acpi_device *device; |
91 | unsigned long update_time; | 95 | unsigned long update_time; |
92 | int current_now; | 96 | int current_now; |
@@ -117,6 +121,7 @@ inline int acpi_battery_present(struct acpi_battery *battery) | |||
117 | return battery->device->status.battery_present; | 121 | return battery->device->status.battery_present; |
118 | } | 122 | } |
119 | 123 | ||
124 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
120 | static int acpi_battery_technology(struct acpi_battery *battery) | 125 | static int acpi_battery_technology(struct acpi_battery *battery) |
121 | { | 126 | { |
122 | if (!strcasecmp("NiCd", battery->type)) | 127 | if (!strcasecmp("NiCd", battery->type)) |
@@ -125,7 +130,7 @@ static int acpi_battery_technology(struct acpi_battery *battery) | |||
125 | return POWER_SUPPLY_TECHNOLOGY_NiMH; | 130 | return POWER_SUPPLY_TECHNOLOGY_NiMH; |
126 | if (!strcasecmp("LION", battery->type)) | 131 | if (!strcasecmp("LION", battery->type)) |
127 | return POWER_SUPPLY_TECHNOLOGY_LION; | 132 | return POWER_SUPPLY_TECHNOLOGY_LION; |
128 | if (!strcasecmp("LI-ION", battery->type)) | 133 | if (!strncasecmp("LI-ION", battery->type, 6)) |
129 | return POWER_SUPPLY_TECHNOLOGY_LION; | 134 | return POWER_SUPPLY_TECHNOLOGY_LION; |
130 | if (!strcasecmp("LiP", battery->type)) | 135 | if (!strcasecmp("LiP", battery->type)) |
131 | return POWER_SUPPLY_TECHNOLOGY_LIPO; | 136 | return POWER_SUPPLY_TECHNOLOGY_LIPO; |
@@ -153,6 +158,8 @@ static int acpi_battery_get_property(struct power_supply *psy, | |||
153 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | 158 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
154 | else if (battery->state == 0) | 159 | else if (battery->state == 0) |
155 | val->intval = POWER_SUPPLY_STATUS_FULL; | 160 | val->intval = POWER_SUPPLY_STATUS_FULL; |
161 | else | ||
162 | val->intval = POWER_SUPPLY_STATUS_UNKNOWN; | ||
156 | break; | 163 | break; |
157 | case POWER_SUPPLY_PROP_PRESENT: | 164 | case POWER_SUPPLY_PROP_PRESENT: |
158 | val->intval = acpi_battery_present(battery); | 165 | val->intval = acpi_battery_present(battery); |
@@ -220,8 +227,9 @@ static enum power_supply_property energy_battery_props[] = { | |||
220 | POWER_SUPPLY_PROP_MODEL_NAME, | 227 | POWER_SUPPLY_PROP_MODEL_NAME, |
221 | POWER_SUPPLY_PROP_MANUFACTURER, | 228 | POWER_SUPPLY_PROP_MANUFACTURER, |
222 | }; | 229 | }; |
230 | #endif | ||
223 | 231 | ||
224 | #ifdef CONFIG_ACPI_PROCFS | 232 | #ifdef CONFIG_ACPI_PROCFS_POWER |
225 | inline char *acpi_battery_units(struct acpi_battery *battery) | 233 | inline char *acpi_battery_units(struct acpi_battery *battery) |
226 | { | 234 | { |
227 | return (battery->power_unit)?"mA":"mW"; | 235 | return (battery->power_unit)?"mA":"mW"; |
@@ -396,6 +404,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery) | |||
396 | return acpi_battery_set_alarm(battery); | 404 | return acpi_battery_set_alarm(battery); |
397 | } | 405 | } |
398 | 406 | ||
407 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
399 | static ssize_t acpi_battery_alarm_show(struct device *dev, | 408 | static ssize_t acpi_battery_alarm_show(struct device *dev, |
400 | struct device_attribute *attr, | 409 | struct device_attribute *attr, |
401 | char *buf) | 410 | char *buf) |
@@ -427,11 +436,6 @@ static int sysfs_add_battery(struct acpi_battery *battery) | |||
427 | { | 436 | { |
428 | int result; | 437 | int result; |
429 | 438 | ||
430 | battery->update_time = 0; | ||
431 | result = acpi_battery_get_info(battery); | ||
432 | acpi_battery_init_alarm(battery); | ||
433 | if (result) | ||
434 | return result; | ||
435 | if (battery->power_unit) { | 439 | if (battery->power_unit) { |
436 | battery->bat.properties = charge_battery_props; | 440 | battery->bat.properties = charge_battery_props; |
437 | battery->bat.num_properties = | 441 | battery->bat.num_properties = |
@@ -460,18 +464,31 @@ static void sysfs_remove_battery(struct acpi_battery *battery) | |||
460 | power_supply_unregister(&battery->bat); | 464 | power_supply_unregister(&battery->bat); |
461 | battery->bat.dev = NULL; | 465 | battery->bat.dev = NULL; |
462 | } | 466 | } |
467 | #endif | ||
463 | 468 | ||
464 | static int acpi_battery_update(struct acpi_battery *battery) | 469 | static int acpi_battery_update(struct acpi_battery *battery) |
465 | { | 470 | { |
466 | int result = acpi_battery_get_status(battery); | 471 | int result; |
472 | result = acpi_battery_get_status(battery); | ||
467 | if (result) | 473 | if (result) |
468 | return result; | 474 | return result; |
475 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
469 | if (!acpi_battery_present(battery)) { | 476 | if (!acpi_battery_present(battery)) { |
470 | sysfs_remove_battery(battery); | 477 | sysfs_remove_battery(battery); |
478 | battery->update_time = 0; | ||
471 | return 0; | 479 | return 0; |
472 | } | 480 | } |
481 | #endif | ||
482 | if (!battery->update_time) { | ||
483 | result = acpi_battery_get_info(battery); | ||
484 | if (result) | ||
485 | return result; | ||
486 | acpi_battery_init_alarm(battery); | ||
487 | } | ||
488 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
473 | if (!battery->bat.dev) | 489 | if (!battery->bat.dev) |
474 | sysfs_add_battery(battery); | 490 | sysfs_add_battery(battery); |
491 | #endif | ||
475 | return acpi_battery_get_state(battery); | 492 | return acpi_battery_get_state(battery); |
476 | } | 493 | } |
477 | 494 | ||
@@ -479,7 +496,7 @@ static int acpi_battery_update(struct acpi_battery *battery) | |||
479 | FS Interface (/proc) | 496 | FS Interface (/proc) |
480 | -------------------------------------------------------------------------- */ | 497 | -------------------------------------------------------------------------- */ |
481 | 498 | ||
482 | #ifdef CONFIG_ACPI_PROCFS | 499 | #ifdef CONFIG_ACPI_PROCFS_POWER |
483 | static struct proc_dir_entry *acpi_battery_dir; | 500 | static struct proc_dir_entry *acpi_battery_dir; |
484 | 501 | ||
485 | static int acpi_battery_print_info(struct seq_file *seq, int result) | 502 | static int acpi_battery_print_info(struct seq_file *seq, int result) |
@@ -765,9 +782,11 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) | |||
765 | acpi_bus_generate_netlink_event(device->pnp.device_class, | 782 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
766 | device->dev.bus_id, event, | 783 | device->dev.bus_id, event, |
767 | acpi_battery_present(battery)); | 784 | acpi_battery_present(battery)); |
785 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
768 | /* acpi_batter_update could remove power_supply object */ | 786 | /* acpi_batter_update could remove power_supply object */ |
769 | if (battery->bat.dev) | 787 | if (battery->bat.dev) |
770 | kobject_uevent(&battery->bat.dev->kobj, KOBJ_CHANGE); | 788 | kobject_uevent(&battery->bat.dev->kobj, KOBJ_CHANGE); |
789 | #endif | ||
771 | } | 790 | } |
772 | 791 | ||
773 | static int acpi_battery_add(struct acpi_device *device) | 792 | static int acpi_battery_add(struct acpi_device *device) |
@@ -786,7 +805,7 @@ static int acpi_battery_add(struct acpi_device *device) | |||
786 | acpi_driver_data(device) = battery; | 805 | acpi_driver_data(device) = battery; |
787 | mutex_init(&battery->lock); | 806 | mutex_init(&battery->lock); |
788 | acpi_battery_update(battery); | 807 | acpi_battery_update(battery); |
789 | #ifdef CONFIG_ACPI_PROCFS | 808 | #ifdef CONFIG_ACPI_PROCFS_POWER |
790 | result = acpi_battery_add_fs(device); | 809 | result = acpi_battery_add_fs(device); |
791 | if (result) | 810 | if (result) |
792 | goto end; | 811 | goto end; |
@@ -804,7 +823,7 @@ static int acpi_battery_add(struct acpi_device *device) | |||
804 | device->status.battery_present ? "present" : "absent"); | 823 | device->status.battery_present ? "present" : "absent"); |
805 | end: | 824 | end: |
806 | if (result) { | 825 | if (result) { |
807 | #ifdef CONFIG_ACPI_PROCFS | 826 | #ifdef CONFIG_ACPI_PROCFS_POWER |
808 | acpi_battery_remove_fs(device); | 827 | acpi_battery_remove_fs(device); |
809 | #endif | 828 | #endif |
810 | kfree(battery); | 829 | kfree(battery); |
@@ -823,10 +842,12 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
823 | status = acpi_remove_notify_handler(device->handle, | 842 | status = acpi_remove_notify_handler(device->handle, |
824 | ACPI_ALL_NOTIFY, | 843 | ACPI_ALL_NOTIFY, |
825 | acpi_battery_notify); | 844 | acpi_battery_notify); |
826 | #ifdef CONFIG_ACPI_PROCFS | 845 | #ifdef CONFIG_ACPI_PROCFS_POWER |
827 | acpi_battery_remove_fs(device); | 846 | acpi_battery_remove_fs(device); |
828 | #endif | 847 | #endif |
848 | #ifdef CONFIG_ACPI_SYSFS_POWER | ||
829 | sysfs_remove_battery(battery); | 849 | sysfs_remove_battery(battery); |
850 | #endif | ||
830 | mutex_destroy(&battery->lock); | 851 | mutex_destroy(&battery->lock); |
831 | kfree(battery); | 852 | kfree(battery); |
832 | return 0; | 853 | return 0; |
@@ -859,13 +880,13 @@ static int __init acpi_battery_init(void) | |||
859 | { | 880 | { |
860 | if (acpi_disabled) | 881 | if (acpi_disabled) |
861 | return -ENODEV; | 882 | return -ENODEV; |
862 | #ifdef CONFIG_ACPI_PROCFS | 883 | #ifdef CONFIG_ACPI_PROCFS_POWER |
863 | acpi_battery_dir = acpi_lock_battery_dir(); | 884 | acpi_battery_dir = acpi_lock_battery_dir(); |
864 | if (!acpi_battery_dir) | 885 | if (!acpi_battery_dir) |
865 | return -ENODEV; | 886 | return -ENODEV; |
866 | #endif | 887 | #endif |
867 | if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { | 888 | if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { |
868 | #ifdef CONFIG_ACPI_PROCFS | 889 | #ifdef CONFIG_ACPI_PROCFS_POWER |
869 | acpi_unlock_battery_dir(acpi_battery_dir); | 890 | acpi_unlock_battery_dir(acpi_battery_dir); |
870 | #endif | 891 | #endif |
871 | return -ENODEV; | 892 | return -ENODEV; |
@@ -876,7 +897,7 @@ static int __init acpi_battery_init(void) | |||
876 | static void __exit acpi_battery_exit(void) | 897 | static void __exit acpi_battery_exit(void) |
877 | { | 898 | { |
878 | acpi_bus_unregister_driver(&acpi_battery_driver); | 899 | acpi_bus_unregister_driver(&acpi_battery_driver); |
879 | #ifdef CONFIG_ACPI_PROCFS | 900 | #ifdef CONFIG_ACPI_PROCFS_POWER |
880 | acpi_unlock_battery_dir(acpi_battery_dir); | 901 | acpi_unlock_battery_dir(acpi_battery_dir); |
881 | #endif | 902 | #endif |
882 | } | 903 | } |