ACPI / PM: Attach ACPI power domain only once
authorMika Westerberg <mika.westerberg@linux.intel.com>
Mon, 27 Jul 2015 15:03:57 +0000 (18:03 +0300)
committerLee Jones <lee.jones@linaro.org>
Tue, 28 Jul 2015 07:50:42 +0000 (08:50 +0100)
Some devices, like MFD subdevices, share a single ACPI companion device so
that they are able to access their resources and children. However,
currently all these subdevices are attached to the ACPI power domain and
this might cause that the power methods for the companion device get called
more than once.

In order to solve this we attach the ACPI power domain only to the first
physical device that is bound to the ACPI companion device. In case of MFD
devices, this is the parent MFD device itself.

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/acpi/device_pm.c
drivers/acpi/internal.h
drivers/acpi/scan.c

index 717afcdb5f4a9657a9ca6f6af9825e109eba9688..08dc3ec7e89272ef4258c7148c39ecceb3fb1e22 100644 (file)
@@ -1123,6 +1123,14 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
        if (dev->pm_domain)
                return -EEXIST;
 
+       /*
+        * Only attach the power domain to the first device if the
+        * companion is shared by multiple. This is to prevent doing power
+        * management twice.
+        */
+       if (!acpi_device_is_first_physical_node(adev, dev))
+               return -EBUSY;
+
        acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
        dev->pm_domain = &acpi_general_pm_domain;
        if (power_on) {
index 4683a96932b917fcc5f3efc04e290eb07012efad..f6aefe984941de5a7f8fde3d15f2b38d199cf21e 100644 (file)
@@ -97,6 +97,8 @@ void acpi_device_add_finalize(struct acpi_device *device);
 void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
 bool acpi_device_is_present(struct acpi_device *adev);
 bool acpi_device_is_battery(struct acpi_device *adev);
+bool acpi_device_is_first_physical_node(struct acpi_device *adev,
+                                       const struct device *dev);
 
 /* --------------------------------------------------------------------------
                                   Power Resource
index ec256352f42367375bd3375ca7cad62cbd50bab7..89ff6d2eef8a00bd5352c9f06d1b0e14d1ff5d11 100644 (file)
@@ -226,6 +226,35 @@ static int create_of_modalias(struct acpi_device *acpi_dev, char *modalias,
        return len;
 }
 
+/**
+ * acpi_device_is_first_physical_node - Is given dev first physical node
+ * @adev: ACPI companion device
+ * @dev: Physical device to check
+ *
+ * Function checks if given @dev is the first physical devices attached to
+ * the ACPI companion device. This distinction is needed in some cases
+ * where the same companion device is shared between many physical devices.
+ *
+ * Note that the caller have to provide valid @adev pointer.
+ */
+bool acpi_device_is_first_physical_node(struct acpi_device *adev,
+                                       const struct device *dev)
+{
+       bool ret = false;
+
+       mutex_lock(&adev->physical_node_lock);
+       if (!list_empty(&adev->physical_node_list)) {
+               const struct acpi_device_physical_node *node;
+
+               node = list_first_entry(&adev->physical_node_list,
+                                       struct acpi_device_physical_node, node);
+               ret = node->dev == dev;
+       }
+       mutex_unlock(&adev->physical_node_lock);
+
+       return ret;
+}
+
 /*
  * acpi_companion_match() - Can we match via ACPI companion device
  * @dev: Device in question
@@ -250,7 +279,6 @@ static int create_of_modalias(struct acpi_device *acpi_dev, char *modalias,
 static struct acpi_device *acpi_companion_match(const struct device *dev)
 {
        struct acpi_device *adev;
-       struct mutex *physical_node_lock;
 
        adev = ACPI_COMPANION(dev);
        if (!adev)
@@ -259,21 +287,7 @@ static struct acpi_device *acpi_companion_match(const struct device *dev)
        if (list_empty(&adev->pnp.ids))
                return NULL;
 
-       physical_node_lock = &adev->physical_node_lock;
-       mutex_lock(physical_node_lock);
-       if (list_empty(&adev->physical_node_list)) {
-               adev = NULL;
-       } else {
-               const struct acpi_device_physical_node *node;
-
-               node = list_first_entry(&adev->physical_node_list,
-                                       struct acpi_device_physical_node, node);
-               if (node->dev != dev)
-                       adev = NULL;
-       }
-       mutex_unlock(physical_node_lock);
-
-       return adev;
+       return acpi_device_is_first_physical_node(adev, dev) ? adev : NULL;
 }
 
 static int __acpi_device_uevent_modalias(struct acpi_device *adev,
This page took 0.037046 seconds and 5 git commands to generate.