diff options
author | Alexey Starikovskiy <astarikovskiy@suse.de> | 2007-09-26 11:43:11 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-09-27 15:50:22 -0400 |
commit | 3e58ea0d31659b22ba5753f7abf3d7db346eab81 (patch) | |
tree | ff968db5ec67b2fc75fdff7ed792355c4ff33c06 /drivers/acpi/battery.c | |
parent | d7380965752505951668e85de59c128d1d6fd21f (diff) |
ACPI: Battery: add sysfs alarm
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.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 057a5eb67ccc..681e26b56b11 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -687,6 +687,34 @@ static void acpi_battery_remove_fs(struct acpi_device *device) | |||
687 | } | 687 | } |
688 | 688 | ||
689 | #endif | 689 | #endif |
690 | |||
691 | static ssize_t acpi_battery_alarm_show(struct device *dev, | ||
692 | struct device_attribute *attr, | ||
693 | char *buf) | ||
694 | { | ||
695 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); | ||
696 | return sprintf(buf, "%d\n", battery->alarm * 1000); | ||
697 | } | ||
698 | |||
699 | static ssize_t acpi_battery_alarm_store(struct device *dev, | ||
700 | struct device_attribute *attr, | ||
701 | const char *buf, size_t count) | ||
702 | { | ||
703 | unsigned long x; | ||
704 | struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev)); | ||
705 | if (sscanf(buf, "%ld\n", &x) == 1) | ||
706 | battery->alarm = x/1000; | ||
707 | if (acpi_battery_present(battery)) | ||
708 | acpi_battery_set_alarm(battery); | ||
709 | return count; | ||
710 | } | ||
711 | |||
712 | static struct device_attribute alarm_attr = { | ||
713 | .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE}, | ||
714 | .show = acpi_battery_alarm_show, | ||
715 | .store = acpi_battery_alarm_store, | ||
716 | }; | ||
717 | |||
690 | /* -------------------------------------------------------------------------- | 718 | /* -------------------------------------------------------------------------- |
691 | Driver Interface | 719 | Driver Interface |
692 | -------------------------------------------------------------------------- */ | 720 | -------------------------------------------------------------------------- */ |
@@ -732,6 +760,7 @@ static int acpi_battery_add(struct acpi_device *device) | |||
732 | battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; | 760 | battery->bat.type = POWER_SUPPLY_TYPE_BATTERY; |
733 | battery->bat.get_property = acpi_battery_get_property; | 761 | battery->bat.get_property = acpi_battery_get_property; |
734 | result = power_supply_register(&battery->device->dev, &battery->bat); | 762 | result = power_supply_register(&battery->device->dev, &battery->bat); |
763 | result = device_create_file(battery->bat.dev, &alarm_attr); | ||
735 | status = acpi_install_notify_handler(device->handle, | 764 | status = acpi_install_notify_handler(device->handle, |
736 | ACPI_ALL_NOTIFY, | 765 | ACPI_ALL_NOTIFY, |
737 | acpi_battery_notify, battery); | 766 | acpi_battery_notify, battery); |
@@ -767,8 +796,10 @@ static int acpi_battery_remove(struct acpi_device *device, int type) | |||
767 | #ifdef CONFIG_ACPI_PROCFS | 796 | #ifdef CONFIG_ACPI_PROCFS |
768 | acpi_battery_remove_fs(device); | 797 | acpi_battery_remove_fs(device); |
769 | #endif | 798 | #endif |
770 | if (battery->bat.dev) | 799 | if (battery->bat.dev) { |
800 | device_remove_file(battery->bat.dev, &alarm_attr); | ||
771 | power_supply_unregister(&battery->bat); | 801 | power_supply_unregister(&battery->bat); |
802 | } | ||
772 | mutex_destroy(&battery->lock); | 803 | mutex_destroy(&battery->lock); |
773 | kfree(battery); | 804 | kfree(battery); |
774 | return 0; | 805 | return 0; |