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.c328
1 files changed, 1 insertions, 327 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 2c9958cd7a43..fbf1aceda8b8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -36,12 +36,6 @@
36#include <linux/suspend.h> 36#include <linux/suspend.h>
37#include <asm/unaligned.h> 37#include <asm/unaligned.h>
38 38
39#ifdef CONFIG_ACPI_PROCFS_POWER
40#include <linux/proc_fs.h>
41#include <linux/seq_file.h>
42#include <asm/uaccess.h>
43#endif
44
45#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
46#include <acpi/acpi_drivers.h> 40#include <acpi/acpi_drivers.h>
47#include <linux/power_supply.h> 41#include <linux/power_supply.h>
@@ -72,19 +66,6 @@ static unsigned int cache_time = 1000;
72module_param(cache_time, uint, 0644); 66module_param(cache_time, uint, 0644);
73MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 67MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
74 68
75#ifdef CONFIG_ACPI_PROCFS_POWER
76extern struct proc_dir_entry *acpi_lock_battery_dir(void);
77extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
78
79enum acpi_battery_files {
80 info_tag = 0,
81 state_tag,
82 alarm_tag,
83 ACPI_BATTERY_NUMFILES,
84};
85
86#endif
87
88static const struct acpi_device_id battery_device_ids[] = { 69static const struct acpi_device_id battery_device_ids[] = {
89 {"PNP0C0A", 0}, 70 {"PNP0C0A", 0},
90 {"", 0}, 71 {"", 0},
@@ -320,14 +301,6 @@ static enum power_supply_property energy_battery_props[] = {
320 POWER_SUPPLY_PROP_SERIAL_NUMBER, 301 POWER_SUPPLY_PROP_SERIAL_NUMBER,
321}; 302};
322 303
323#ifdef CONFIG_ACPI_PROCFS_POWER
324inline char *acpi_battery_units(struct acpi_battery *battery)
325{
326 return (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) ?
327 "mA" : "mW";
328}
329#endif
330
331/* -------------------------------------------------------------------------- 304/* --------------------------------------------------------------------------
332 Battery Management 305 Battery Management
333 -------------------------------------------------------------------------- */ 306 -------------------------------------------------------------------------- */
@@ -741,279 +714,6 @@ static void acpi_battery_refresh(struct acpi_battery *battery)
741} 714}
742 715
743/* -------------------------------------------------------------------------- 716/* --------------------------------------------------------------------------
744 FS Interface (/proc)
745 -------------------------------------------------------------------------- */
746
747#ifdef CONFIG_ACPI_PROCFS_POWER
748static struct proc_dir_entry *acpi_battery_dir;
749
750static int acpi_battery_print_info(struct seq_file *seq, int result)
751{
752 struct acpi_battery *battery = seq->private;
753
754 if (result)
755 goto end;
756
757 seq_printf(seq, "present: %s\n",
758 acpi_battery_present(battery) ? "yes" : "no");
759 if (!acpi_battery_present(battery))
760 goto end;
761 if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
762 seq_printf(seq, "design capacity: unknown\n");
763 else
764 seq_printf(seq, "design capacity: %d %sh\n",
765 battery->design_capacity,
766 acpi_battery_units(battery));
767
768 if (battery->full_charge_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
769 seq_printf(seq, "last full capacity: unknown\n");
770 else
771 seq_printf(seq, "last full capacity: %d %sh\n",
772 battery->full_charge_capacity,
773 acpi_battery_units(battery));
774
775 seq_printf(seq, "battery technology: %srechargeable\n",
776 (!battery->technology)?"non-":"");
777
778 if (battery->design_voltage == ACPI_BATTERY_VALUE_UNKNOWN)
779 seq_printf(seq, "design voltage: unknown\n");
780 else
781 seq_printf(seq, "design voltage: %d mV\n",
782 battery->design_voltage);
783 seq_printf(seq, "design capacity warning: %d %sh\n",
784 battery->design_capacity_warning,
785 acpi_battery_units(battery));
786 seq_printf(seq, "design capacity low: %d %sh\n",
787 battery->design_capacity_low,
788 acpi_battery_units(battery));
789 seq_printf(seq, "cycle count: %i\n", battery->cycle_count);
790 seq_printf(seq, "capacity granularity 1: %d %sh\n",
791 battery->capacity_granularity_1,
792 acpi_battery_units(battery));
793 seq_printf(seq, "capacity granularity 2: %d %sh\n",
794 battery->capacity_granularity_2,
795 acpi_battery_units(battery));
796 seq_printf(seq, "model number: %s\n", battery->model_number);
797 seq_printf(seq, "serial number: %s\n", battery->serial_number);
798 seq_printf(seq, "battery type: %s\n", battery->type);
799 seq_printf(seq, "OEM info: %s\n", battery->oem_info);
800 end:
801 if (result)
802 seq_printf(seq, "ERROR: Unable to read battery info\n");
803 return result;
804}
805
806static int acpi_battery_print_state(struct seq_file *seq, int result)
807{
808 struct acpi_battery *battery = seq->private;
809
810 if (result)
811 goto end;
812
813 seq_printf(seq, "present: %s\n",
814 acpi_battery_present(battery) ? "yes" : "no");
815 if (!acpi_battery_present(battery))
816 goto end;
817
818 seq_printf(seq, "capacity state: %s\n",
819 (battery->state & 0x04) ? "critical" : "ok");
820 if ((battery->state & 0x01) && (battery->state & 0x02))
821 seq_printf(seq,
822 "charging state: charging/discharging\n");
823 else if (battery->state & 0x01)
824 seq_printf(seq, "charging state: discharging\n");
825 else if (battery->state & 0x02)
826 seq_printf(seq, "charging state: charging\n");
827 else
828 seq_printf(seq, "charging state: charged\n");
829
830 if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN)
831 seq_printf(seq, "present rate: unknown\n");
832 else
833 seq_printf(seq, "present rate: %d %s\n",
834 battery->rate_now, acpi_battery_units(battery));
835
836 if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
837 seq_printf(seq, "remaining capacity: unknown\n");
838 else
839 seq_printf(seq, "remaining capacity: %d %sh\n",
840 battery->capacity_now, acpi_battery_units(battery));
841 if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
842 seq_printf(seq, "present voltage: unknown\n");
843 else
844 seq_printf(seq, "present voltage: %d mV\n",
845 battery->voltage_now);
846 end:
847 if (result)
848 seq_printf(seq, "ERROR: Unable to read battery state\n");
849
850 return result;
851}
852
853static int acpi_battery_print_alarm(struct seq_file *seq, int result)
854{
855 struct acpi_battery *battery = seq->private;
856
857 if (result)
858 goto end;
859
860 if (!acpi_battery_present(battery)) {
861 seq_printf(seq, "present: no\n");
862 goto end;
863 }
864 seq_printf(seq, "alarm: ");
865 if (!battery->alarm)
866 seq_printf(seq, "unsupported\n");
867 else
868 seq_printf(seq, "%u %sh\n", battery->alarm,
869 acpi_battery_units(battery));
870 end:
871 if (result)
872 seq_printf(seq, "ERROR: Unable to read battery alarm\n");
873 return result;
874}
875
876static ssize_t acpi_battery_write_alarm(struct file *file,
877 const char __user * buffer,
878 size_t count, loff_t * ppos)
879{
880 int result = 0;
881 char alarm_string[12] = { '\0' };
882 struct seq_file *m = file->private_data;
883 struct acpi_battery *battery = m->private;
884
885 if (!battery || (count > sizeof(alarm_string) - 1))
886 return -EINVAL;
887 if (!acpi_battery_present(battery)) {
888 result = -ENODEV;
889 goto end;
890 }
891 if (copy_from_user(alarm_string, buffer, count)) {
892 result = -EFAULT;
893 goto end;
894 }
895 alarm_string[count] = '\0';
896 battery->alarm = simple_strtol(alarm_string, NULL, 0);
897 result = acpi_battery_set_alarm(battery);
898 end:
899 if (!result)
900 return count;
901 return result;
902}
903
904typedef int(*print_func)(struct seq_file *seq, int result);
905
906static print_func acpi_print_funcs[ACPI_BATTERY_NUMFILES] = {
907 acpi_battery_print_info,
908 acpi_battery_print_state,
909 acpi_battery_print_alarm,
910};
911
912static int acpi_battery_read(int fid, struct seq_file *seq)
913{
914 struct acpi_battery *battery = seq->private;
915 int result = acpi_battery_update(battery);
916 return acpi_print_funcs[fid](seq, result);
917}
918
919#define DECLARE_FILE_FUNCTIONS(_name) \
920static int acpi_battery_read_##_name(struct seq_file *seq, void *offset) \
921{ \
922 return acpi_battery_read(_name##_tag, seq); \
923} \
924static int acpi_battery_##_name##_open_fs(struct inode *inode, struct file *file) \
925{ \
926 return single_open(file, acpi_battery_read_##_name, PDE_DATA(inode)); \
927}
928
929DECLARE_FILE_FUNCTIONS(info);
930DECLARE_FILE_FUNCTIONS(state);
931DECLARE_FILE_FUNCTIONS(alarm);
932
933#undef DECLARE_FILE_FUNCTIONS
934
935#define FILE_DESCRIPTION_RO(_name) \
936 { \
937 .name = __stringify(_name), \
938 .mode = S_IRUGO, \
939 .ops = { \
940 .open = acpi_battery_##_name##_open_fs, \
941 .read = seq_read, \
942 .llseek = seq_lseek, \
943 .release = single_release, \
944 .owner = THIS_MODULE, \
945 }, \
946 }
947
948#define FILE_DESCRIPTION_RW(_name) \
949 { \
950 .name = __stringify(_name), \
951 .mode = S_IFREG | S_IRUGO | S_IWUSR, \
952 .ops = { \
953 .open = acpi_battery_##_name##_open_fs, \
954 .read = seq_read, \
955 .llseek = seq_lseek, \
956 .write = acpi_battery_write_##_name, \
957 .release = single_release, \
958 .owner = THIS_MODULE, \
959 }, \
960 }
961
962static const struct battery_file {
963 struct file_operations ops;
964 umode_t mode;
965 const char *name;
966} acpi_battery_file[] = {
967 FILE_DESCRIPTION_RO(info),
968 FILE_DESCRIPTION_RO(state),
969 FILE_DESCRIPTION_RW(alarm),
970};
971
972#undef FILE_DESCRIPTION_RO
973#undef FILE_DESCRIPTION_RW
974
975static int acpi_battery_add_fs(struct acpi_device *device)
976{
977 struct proc_dir_entry *entry = NULL;
978 int i;
979
980 printk(KERN_WARNING PREFIX "Deprecated procfs I/F for battery is loaded,"
981 " please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
982 if (!acpi_device_dir(device)) {
983 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
984 acpi_battery_dir);
985 if (!acpi_device_dir(device))
986 return -ENODEV;
987 }
988
989 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
990 entry = proc_create_data(acpi_battery_file[i].name,
991 acpi_battery_file[i].mode,
992 acpi_device_dir(device),
993 &acpi_battery_file[i].ops,
994 acpi_driver_data(device));
995 if (!entry)
996 return -ENODEV;
997 }
998 return 0;
999}
1000
1001static void acpi_battery_remove_fs(struct acpi_device *device)
1002{
1003 int i;
1004 if (!acpi_device_dir(device))
1005 return;
1006 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i)
1007 remove_proc_entry(acpi_battery_file[i].name,
1008 acpi_device_dir(device));
1009
1010 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
1011 acpi_device_dir(device) = NULL;
1012}
1013
1014#endif
1015
1016/* --------------------------------------------------------------------------
1017 Driver Interface 717 Driver Interface
1018 -------------------------------------------------------------------------- */ 718 -------------------------------------------------------------------------- */
1019 719
@@ -1075,15 +775,6 @@ static int acpi_battery_add(struct acpi_device *device)
1075 result = acpi_battery_update(battery); 775 result = acpi_battery_update(battery);
1076 if (result) 776 if (result)
1077 goto fail; 777 goto fail;
1078#ifdef CONFIG_ACPI_PROCFS_POWER
1079 result = acpi_battery_add_fs(device);
1080#endif
1081 if (result) {
1082#ifdef CONFIG_ACPI_PROCFS_POWER
1083 acpi_battery_remove_fs(device);
1084#endif
1085 goto fail;
1086 }
1087 778
1088 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", 779 printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
1089 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), 780 ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
@@ -1110,9 +801,6 @@ static int acpi_battery_remove(struct acpi_device *device)
1110 return -EINVAL; 801 return -EINVAL;
1111 battery = acpi_driver_data(device); 802 battery = acpi_driver_data(device);
1112 unregister_pm_notifier(&battery->pm_nb); 803 unregister_pm_notifier(&battery->pm_nb);
1113#ifdef CONFIG_ACPI_PROCFS_POWER
1114 acpi_battery_remove_fs(device);
1115#endif
1116 sysfs_remove_battery(battery); 804 sysfs_remove_battery(battery);
1117 mutex_destroy(&battery->lock); 805 mutex_destroy(&battery->lock);
1118 mutex_destroy(&battery->sysfs_lock); 806 mutex_destroy(&battery->sysfs_lock);
@@ -1158,18 +846,7 @@ static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
1158{ 846{
1159 if (acpi_disabled) 847 if (acpi_disabled)
1160 return; 848 return;
1161#ifdef CONFIG_ACPI_PROCFS_POWER 849 acpi_bus_register_driver(&acpi_battery_driver);
1162 acpi_battery_dir = acpi_lock_battery_dir();
1163 if (!acpi_battery_dir)
1164 return;
1165#endif
1166 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
1167#ifdef CONFIG_ACPI_PROCFS_POWER
1168 acpi_unlock_battery_dir(acpi_battery_dir);
1169#endif
1170 return;
1171 }
1172 return;
1173} 850}
1174 851
1175static int __init acpi_battery_init(void) 852static int __init acpi_battery_init(void)
@@ -1181,9 +858,6 @@ static int __init acpi_battery_init(void)
1181static void __exit acpi_battery_exit(void) 858static void __exit acpi_battery_exit(void)
1182{ 859{
1183 acpi_bus_unregister_driver(&acpi_battery_driver); 860 acpi_bus_unregister_driver(&acpi_battery_driver);
1184#ifdef CONFIG_ACPI_PROCFS_POWER
1185 acpi_unlock_battery_dir(acpi_battery_dir);
1186#endif
1187} 861}
1188 862
1189module_init(acpi_battery_init); 863module_init(acpi_battery_init);