ACPI: Add a powered attribute to the AC driver Signed-off-by: Brandon Philips --- drivers/acpi/ac.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) Index: linux-2.6-rc/drivers/acpi/ac.c =================================================================== --- linux-2.6-rc.orig/drivers/acpi/ac.c +++ linux-2.6-rc/drivers/acpi/ac.c @@ -211,6 +211,30 @@ static void acpi_ac_notify(acpi_handle h return; } +/* + * show_powered - read method for "powered" file in sysfs + */ +static ssize_t show_powered(struct acpi_device *dev, char *buf) +{ + struct acpi_ac *ac= (struct acpi_ac*)dev->driver_data; + return snprintf(buf, PAGE_SIZE, "%s\n", ac->state ? "on-line" : "off-line"); +} +ACPI_DEVICE_ATTR(powered, S_IRUGO, show_powered, NULL); + +static void ac_remove_sysfs_files(struct acpi_device *ad) { + sysfs_remove_file(&ad->kobj, &acpi_device_attr_powered.attr); +} + +static int ac_add_syfs_files(struct acpi_device *ad) { + int ret; + + ret = sysfs_create_file(&ad->kobj, &acpi_device_attr_powered.attr); + if (ret) + ac_remove_sysfs_files(ad);; + + return ret; +} + static int acpi_ac_add(struct acpi_device *device) { int result = 0; @@ -247,6 +271,11 @@ static int acpi_ac_add(struct acpi_devic goto end; } + device->driver_data = (void *)ac; + + if (ac_add_syfs_files(device)) + printk(KERN_ERR PREFIX "Unable to create sysfs files\n"); + printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), acpi_device_bid(device), ac->state ? "on-line" : "off-line"); @@ -275,6 +304,7 @@ static int acpi_ac_remove(struct acpi_de ACPI_ALL_NOTIFY, acpi_ac_notify); acpi_ac_remove_fs(device); + ac_remove_sysfs_files(device); kfree(ac);