From patchwork Wed Dec 5 00:42:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 1839761 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 829D4DFF39 for ; Wed, 5 Dec 2012 00:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752720Ab2LEAhu (ORCPT ); Tue, 4 Dec 2012 19:37:50 -0500 Received: from hydra.sisk.pl ([212.160.235.94]:39776 "EHLO hydra.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752151Ab2LEAht (ORCPT ); Tue, 4 Dec 2012 19:37:49 -0500 Received: from vostro.rjw.lan (aeqz91.neoplus.adsl.tpnet.pl [79.191.181.91]) by hydra.sisk.pl (Postfix) with ESMTPSA id E58ABE3E62; Wed, 5 Dec 2012 01:39:28 +0100 (CET) From: "Rafael J. Wysocki" To: ACPI Devel Maling List Cc: Linux PM list , LKML , Greg Kroah-Hartman , Len Brown Subject: [PATCH 3/3] ACPI / PM: Export power states of ACPI devices via sysfs Date: Wed, 05 Dec 2012 01:42:35 +0100 Message-ID: <1711926.9E8yF37X23@vostro.rjw.lan> User-Agent: KMail/4.9.3 (Linux/3.7.0-rc8; KDE/4.9.3; x86_64; ; ) In-Reply-To: <1464990.iyrX0DeZyT@vostro.rjw.lan> References: <1464990.iyrX0DeZyT@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Make it possible to retrieve the current power state of an ACPI device from user space via sysfs by adding a new attribute power_state to the power subdirectory of the sysfs directory associated with the struct acpi_device representing the device's ACPI node. Signed-off-by: Rafael J. Wysocki --- Documentation/ABI/testing/sysfs-devices-power | 13 ++++++++ drivers/acpi/scan.c | 41 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux/drivers/acpi/scan.c =================================================================== --- linux.orig/drivers/acpi/scan.c +++ linux/drivers/acpi/scan.c @@ -174,6 +174,43 @@ err_out: } EXPORT_SYMBOL(acpi_bus_hot_remove_device); +#ifdef CONFIG_PM +static ssize_t power_state_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct acpi_device *adev = to_acpi_device(dev); + int state; + int ret; + + ret = acpi_device_get_power(adev, &state); + return ret ? ret : sprintf(buf, "%s\n", acpi_power_state_string(state)); +} + +static DEVICE_ATTR(power_state, 0444, power_state_show, NULL); + +static struct attribute *acpi_dev_pm_attrs[] = { + &dev_attr_power_state.attr, + NULL, +}; +static struct attribute_group acpi_dev_pm_attr_group = { + .name = power_group_name, + .attrs = acpi_dev_pm_attrs, +}; + +static void acpi_dev_pm_sysfs_add(struct device *dev) +{ + sysfs_merge_group(&dev->kobj, &acpi_dev_pm_attr_group); +} + +static void acpi_dev_pm_sysfs_remove(struct device *dev) +{ + sysfs_unmerge_group(&dev->kobj, &acpi_dev_pm_attr_group); +} +#else /* !CONFIG_PM */ +static inline void acpi_dev_pm_sysfs_add(struct device *dev) {} +static inline void acpi_dev_pm_sysfs_remove(struct device *dev) {} +#endif /* !CONFIG_PM */ + static ssize_t acpi_eject_store(struct device *d, struct device_attribute *attr, const char *buf, size_t count) @@ -367,6 +404,9 @@ static int acpi_device_setup_files(struc status = acpi_get_handle(dev->handle, "_EJ0", &temp); if (ACPI_SUCCESS(status)) result = device_create_file(&dev->dev, &dev_attr_eject); + + acpi_dev_pm_sysfs_add(&dev->dev); + end: return result; } @@ -376,6 +416,7 @@ static void acpi_device_remove_files(str acpi_status status; acpi_handle temp; + acpi_dev_pm_sysfs_remove(&dev->dev); /* * If device has _STR, remove 'description' file */ Index: linux/Documentation/ABI/testing/sysfs-devices-power =================================================================== --- linux.orig/Documentation/ABI/testing/sysfs-devices-power +++ linux/Documentation/ABI/testing/sysfs-devices-power @@ -235,3 +235,16 @@ Description: This attribute has no effect on system-wide suspend/resume and hibernation. + +What: /sys/devices/.../power/power_state +Date: December 2012 +Contact: Rafael J. Wysocki +Description: + The /sys/devices/.../power/power_state attribute is only present + for ACPI device nodes (i.e. objects of type struct acpi_device). + + If present, it contains the string representation of the current + ACPI power state of the device represented by the given ACPI + device node. + + This attribute is read-only.