]> Pileus Git - ~andy/linux/blobdiff - drivers/acpi/scan.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[~andy/linux] / drivers / acpi / scan.c
index e8efaac71e74836e740d5dd712af45d82b12e1bb..f8316a05ede72fe459a66341343f5cd40fa6ae09 100644 (file)
@@ -233,12 +233,9 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
 
 int acpi_match_ids(struct acpi_device *device, char *ids)
 {
-       int error = 0;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
        if (device->flags.hardware_id)
                if (strstr(ids, device->pnp.hardware_id))
-                       goto Done;
+                       return 0;
 
        if (device->flags.compatible_ids) {
                struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
@@ -247,15 +244,10 @@ int acpi_match_ids(struct acpi_device *device, char *ids)
                /* compare multiple _CID entries against driver ids */
                for (i = 0; i < cid_list->count; i++) {
                        if (strstr(ids, cid_list->id[i].value))
-                               goto Done;
+                               return 0;
                }
        }
-       error = -ENOENT;
-
-      Done:
-       if (buffer.pointer)
-               acpi_os_free(buffer.pointer);
-       return error;
+       return -ENOENT;
 }
 
 static acpi_status
@@ -440,10 +432,7 @@ acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
        islockable = device->flags.lockable;
        handle = device->handle;
 
-       if (type == ACPI_TYPE_PROCESSOR)
-               result = acpi_bus_trim(device, 0);
-       else
-               result = acpi_bus_trim(device, 1);
+       result = acpi_bus_trim(device, 1);
 
        if (!result)
                result = acpi_eject_operation(handle, islockable);
@@ -470,7 +459,6 @@ static int acpi_bus_get_perf_flags(struct acpi_device *device)
    -------------------------------------------------------------------------- */
 
 static LIST_HEAD(acpi_bus_drivers);
-static DECLARE_MUTEX(acpi_bus_drivers_lock);
 
 /**
  * acpi_bus_match - match device IDs to driver's supported IDs
@@ -1353,6 +1341,100 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
        return_VALUE(result);
 }
 
+
+static inline struct acpi_device * to_acpi_dev(struct device * dev)
+{
+       return container_of(dev, struct acpi_device, dev);
+}
+
+
+static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state)
+{
+       struct acpi_device * dev, * next;
+       int result;
+
+       spin_lock(&acpi_device_lock);
+       list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) {
+               if (dev->driver && dev->driver->ops.suspend) {
+                       spin_unlock(&acpi_device_lock);
+                       result = dev->driver->ops.suspend(dev, 0);
+                       if (result) {
+                               printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n",
+                                      acpi_device_name(dev),
+                                      acpi_device_bid(dev), result);
+                       }
+                       spin_lock(&acpi_device_lock);
+               }
+       }
+       spin_unlock(&acpi_device_lock);
+       return 0;
+}
+
+
+static int acpi_device_suspend(struct device * dev, pm_message_t state)
+{
+       struct acpi_device * acpi_dev = to_acpi_dev(dev);
+
+       /*
+        * For now, we should only register 1 generic device -
+        * the ACPI root device - and from there, we walk the
+        * tree of ACPI devices to suspend each one using the
+        * ACPI driver methods.
+        */
+       if (acpi_dev->handle == ACPI_ROOT_OBJECT)
+               root_suspend(acpi_dev, state);
+       return 0;
+}
+
+
+
+static int root_resume(struct acpi_device * acpi_dev)
+{
+       struct acpi_device * dev, * next;
+       int result;
+
+       spin_lock(&acpi_device_lock);
+       list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) {
+               if (dev->driver && dev->driver->ops.resume) {
+                       spin_unlock(&acpi_device_lock);
+                       result = dev->driver->ops.resume(dev, 0);
+                       if (result) {
+                               printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n",
+                                      acpi_device_name(dev),
+                                      acpi_device_bid(dev), result);
+                       }
+                       spin_lock(&acpi_device_lock);
+               }
+       }
+       spin_unlock(&acpi_device_lock);
+       return 0;
+}
+
+
+static int acpi_device_resume(struct device * dev)
+{
+       struct acpi_device * acpi_dev = to_acpi_dev(dev);
+
+       /*
+        * For now, we should only register 1 generic device -
+        * the ACPI root device - and from there, we walk the
+        * tree of ACPI devices to resume each one using the
+        * ACPI driver methods.
+        */
+       if (acpi_dev->handle == ACPI_ROOT_OBJECT)
+               root_resume(acpi_dev);
+       return 0;
+}
+
+
+struct bus_type acpi_bus_type = {
+       .name           = "acpi",
+       .suspend        = acpi_device_suspend,
+       .resume         = acpi_device_resume,
+};
+
+
+
 static int __init acpi_scan_init(void)
 {
        int result;
@@ -1365,6 +1447,12 @@ static int __init acpi_scan_init(void)
 
        kset_register(&acpi_namespace_kset);
 
+       result = bus_register(&acpi_bus_type);
+       if (result) {
+               /* We don't want to quit even if we failed to add suspend/resume */
+               printk(KERN_ERR PREFIX "Could not register bus type\n");
+       }
+
        /*
         * Create the root device in the bus's device tree
         */
@@ -1374,6 +1462,16 @@ static int __init acpi_scan_init(void)
                goto Done;
 
        result = acpi_start_single_object(acpi_root);
+       if (result)
+               goto Done;
+
+       acpi_root->dev.bus = &acpi_bus_type;
+       snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name);
+       result = device_register(&acpi_root->dev);
+       if (result) {
+               /* We don't want to quit even if we failed to add suspend/resume */
+               printk(KERN_ERR PREFIX "Could not register device\n");
+       }
 
        /*
         * Enumerate devices in the ACPI namespace.