aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/battery.c
diff options
context:
space:
mode:
authorAlexey Starikovskiy <astarikovskiy@suse.de>2008-01-01 14:27:24 -0500
committerLen Brown <len.brown@intel.com>2008-01-01 14:27:24 -0500
commit97749cd9adbb2985e4b2aee1a59d6b970fe9c3a7 (patch)
tree22e32a16eb78178e4f50963e4f61320b8bf935ab /drivers/acpi/battery.c
parente697789d64f8748cb219d7f5c413c512953802cc (diff)
ACPI: Make sysfs interface in ACPI power optional.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=9494 Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r--drivers/acpi/battery.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 8f7505d304b5..c4a769d1ba85 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -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
@@ -86,7 +88,9 @@ MODULE_DEVICE_TABLE(acpi, battery_device_ids);
86 88
87struct acpi_battery { 89struct 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
120static int acpi_battery_technology(struct acpi_battery *battery) 125static int acpi_battery_technology(struct acpi_battery *battery)
121{ 126{
122 if (!strcasecmp("NiCd", battery->type)) 127 if (!strcasecmp("NiCd", battery->type))
@@ -222,6 +227,7 @@ static enum power_supply_property energy_battery_props[] = {
222 POWER_SUPPLY_PROP_MODEL_NAME, 227 POWER_SUPPLY_PROP_MODEL_NAME,
223 POWER_SUPPLY_PROP_MANUFACTURER, 228 POWER_SUPPLY_PROP_MANUFACTURER,
224}; 229};
230#endif
225 231
226#ifdef CONFIG_ACPI_PROCFS_POWER 232#ifdef CONFIG_ACPI_PROCFS_POWER
227inline char *acpi_battery_units(struct acpi_battery *battery) 233inline char *acpi_battery_units(struct acpi_battery *battery)
@@ -398,6 +404,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery)
398 return acpi_battery_set_alarm(battery); 404 return acpi_battery_set_alarm(battery);
399} 405}
400 406
407#ifdef CONFIG_ACPI_SYSFS_POWER
401static ssize_t acpi_battery_alarm_show(struct device *dev, 408static ssize_t acpi_battery_alarm_show(struct device *dev,
402 struct device_attribute *attr, 409 struct device_attribute *attr,
403 char *buf) 410 char *buf)
@@ -429,11 +436,6 @@ static int sysfs_add_battery(struct acpi_battery *battery)
429{ 436{
430 int result; 437 int result;
431 438
432 battery->update_time = 0;
433 result = acpi_battery_get_info(battery);
434 acpi_battery_init_alarm(battery);
435 if (result)
436 return result;
437 if (battery->power_unit) { 439 if (battery->power_unit) {
438 battery->bat.properties = charge_battery_props; 440 battery->bat.properties = charge_battery_props;
439 battery->bat.num_properties = 441 battery->bat.num_properties =
@@ -462,18 +464,31 @@ static void sysfs_remove_battery(struct acpi_battery *battery)
462 power_supply_unregister(&battery->bat); 464 power_supply_unregister(&battery->bat);
463 battery->bat.dev = NULL; 465 battery->bat.dev = NULL;
464} 466}
467#endif
465 468
466static int acpi_battery_update(struct acpi_battery *battery) 469static int acpi_battery_update(struct acpi_battery *battery)
467{ 470{
468 int result = acpi_battery_get_status(battery); 471 int result;
472 result = acpi_battery_get_status(battery);
469 if (result) 473 if (result)
470 return result; 474 return result;
475#ifdef CONFIG_ACPI_SYSFS_POWER
471 if (!acpi_battery_present(battery)) { 476 if (!acpi_battery_present(battery)) {
472 sysfs_remove_battery(battery); 477 sysfs_remove_battery(battery);
478 battery->update_time = 0;
473 return 0; 479 return 0;
474 } 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
475 if (!battery->bat.dev) 489 if (!battery->bat.dev)
476 sysfs_add_battery(battery); 490 sysfs_add_battery(battery);
491#endif
477 return acpi_battery_get_state(battery); 492 return acpi_battery_get_state(battery);
478} 493}
479 494
@@ -767,9 +782,11 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
767 acpi_bus_generate_netlink_event(device->pnp.device_class, 782 acpi_bus_generate_netlink_event(device->pnp.device_class,
768 device->dev.bus_id, event, 783 device->dev.bus_id, event,
769 acpi_battery_present(battery)); 784 acpi_battery_present(battery));
785#ifdef CONFIG_ACPI_SYSFS_POWER
770 /* acpi_batter_update could remove power_supply object */ 786 /* acpi_batter_update could remove power_supply object */
771 if (battery->bat.dev) 787 if (battery->bat.dev)
772 kobject_uevent(&battery->bat.dev->kobj, KOBJ_CHANGE); 788 kobject_uevent(&battery->bat.dev->kobj, KOBJ_CHANGE);
789#endif
773} 790}
774 791
775static int acpi_battery_add(struct acpi_device *device) 792static int acpi_battery_add(struct acpi_device *device)
@@ -828,7 +845,9 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
828#ifdef CONFIG_ACPI_PROCFS_POWER 845#ifdef CONFIG_ACPI_PROCFS_POWER
829 acpi_battery_remove_fs(device); 846 acpi_battery_remove_fs(device);
830#endif 847#endif
848#ifdef CONFIG_ACPI_SYSFS_POWER
831 sysfs_remove_battery(battery); 849 sysfs_remove_battery(battery);
850#endif
832 mutex_destroy(&battery->lock); 851 mutex_destroy(&battery->lock);
833 kfree(battery); 852 kfree(battery);
834 return 0; 853 return 0;