ACPI: add ACPI bus_type for driver model
[powerpc.git] / drivers / acpi / scan.c
index f8316a0..4647462 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/acpi.h>
 
 #include <acpi/acpi_drivers.h>
@@ -48,13 +49,13 @@ static void setup_sys_fs_device_files(struct acpi_device *dev,
 #define remove_sysfs_device_files(dev) \
        setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file)
 
-#define to_acpi_device(n) container_of(n, struct acpi_device, kobj)
+#define to_acpi_dev(n) container_of(n, struct acpi_device, kobj)
 #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr);
 
 static ssize_t acpi_device_attr_show(struct kobject *kobj,
                                     struct attribute *attr, char *buf)
 {
-       struct acpi_device *device = to_acpi_device(kobj);
+       struct acpi_device *device = to_acpi_dev(kobj);
        struct acpi_device_attribute *attribute = to_handle_attr(attr);
        return attribute->show ? attribute->show(device, buf) : -EIO;
 }
@@ -62,7 +63,7 @@ static ssize_t acpi_device_attr_store(struct kobject *kobj,
                                      struct attribute *attr, const char *buf,
                                      size_t len)
 {
-       struct acpi_device *device = to_acpi_device(kobj);
+       struct acpi_device *device = to_acpi_dev(kobj);
        struct acpi_device_attribute *attribute = to_handle_attr(attr);
        return attribute->store ? attribute->store(device, buf, len) : -EIO;
 }
@@ -81,7 +82,7 @@ static int namespace_uevent(struct kset *kset, struct kobject *kobj,
                             char **envp, int num_envp, char *buffer,
                             int buffer_size)
 {
-       struct acpi_device *dev = to_acpi_device(kobj);
+       struct acpi_device *dev = to_acpi_dev(kobj);
        int i = 0;
        int len = 0;
 
@@ -110,232 +111,6 @@ static struct kset acpi_namespace_kset = {
        .uevent_ops = &namespace_uevent_ops,
 };
 
-static void acpi_device_register(struct acpi_device *device,
-                                struct acpi_device *parent)
-{
-       /*
-        * Linkage
-        * -------
-        * Link this device to its parent and siblings.
-        */
-       INIT_LIST_HEAD(&device->children);
-       INIT_LIST_HEAD(&device->node);
-       INIT_LIST_HEAD(&device->g_list);
-       INIT_LIST_HEAD(&device->wakeup_list);
-
-       spin_lock(&acpi_device_lock);
-       if (device->parent) {
-               list_add_tail(&device->node, &device->parent->children);
-               list_add_tail(&device->g_list, &device->parent->g_list);
-       } else
-               list_add_tail(&device->g_list, &acpi_device_list);
-       if (device->wakeup.flags.valid)
-               list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
-       spin_unlock(&acpi_device_lock);
-
-       strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
-       if (parent)
-               device->kobj.parent = &parent->kobj;
-       device->kobj.ktype = &ktype_acpi_ns;
-       device->kobj.kset = &acpi_namespace_kset;
-       kobject_register(&device->kobj);
-       create_sysfs_device_files(device);
-}
-
-static void acpi_device_unregister(struct acpi_device *device, int type)
-{
-       spin_lock(&acpi_device_lock);
-       if (device->parent) {
-               list_del(&device->node);
-               list_del(&device->g_list);
-       } else
-               list_del(&device->g_list);
-
-       list_del(&device->wakeup_list);
-
-       spin_unlock(&acpi_device_lock);
-
-       acpi_detach_data(device->handle, acpi_bus_data_handler);
-       remove_sysfs_device_files(device);
-       kobject_unregister(&device->kobj);
-}
-
-void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
-{
-       ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
-
-       /* TBD */
-
-       return_VOID;
-}
-
-static int acpi_bus_get_power_flags(struct acpi_device *device)
-{
-       acpi_status status = 0;
-       acpi_handle handle = NULL;
-       u32 i = 0;
-
-       ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
-
-       /*
-        * Power Management Flags
-        */
-       status = acpi_get_handle(device->handle, "_PSC", &handle);
-       if (ACPI_SUCCESS(status))
-               device->power.flags.explicit_get = 1;
-       status = acpi_get_handle(device->handle, "_IRC", &handle);
-       if (ACPI_SUCCESS(status))
-               device->power.flags.inrush_current = 1;
-
-       /*
-        * Enumerate supported power management states
-        */
-       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
-               struct acpi_device_power_state *ps = &device->power.states[i];
-               char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
-
-               /* Evaluate "_PRx" to se if power resources are referenced */
-               acpi_evaluate_reference(device->handle, object_name, NULL,
-                                       &ps->resources);
-               if (ps->resources.count) {
-                       device->power.flags.power_resources = 1;
-                       ps->flags.valid = 1;
-               }
-
-               /* Evaluate "_PSx" to see if we can do explicit sets */
-               object_name[2] = 'S';
-               status = acpi_get_handle(device->handle, object_name, &handle);
-               if (ACPI_SUCCESS(status)) {
-                       ps->flags.explicit_set = 1;
-                       ps->flags.valid = 1;
-               }
-
-               /* State is valid if we have some power control */
-               if (ps->resources.count || ps->flags.explicit_set)
-                       ps->flags.valid = 1;
-
-               ps->power = -1; /* Unknown - driver assigned */
-               ps->latency = -1;       /* Unknown - driver assigned */
-       }
-
-       /* Set defaults for D0 and D3 states (always valid) */
-       device->power.states[ACPI_STATE_D0].flags.valid = 1;
-       device->power.states[ACPI_STATE_D0].power = 100;
-       device->power.states[ACPI_STATE_D3].flags.valid = 1;
-       device->power.states[ACPI_STATE_D3].power = 0;
-
-       /* TBD: System wake support and resource requirements. */
-
-       device->power.state = ACPI_STATE_UNKNOWN;
-
-       return_VALUE(0);
-}
-
-int acpi_match_ids(struct acpi_device *device, char *ids)
-{
-       if (device->flags.hardware_id)
-               if (strstr(ids, device->pnp.hardware_id))
-                       return 0;
-
-       if (device->flags.compatible_ids) {
-               struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
-               int i;
-
-               /* compare multiple _CID entries against driver ids */
-               for (i = 0; i < cid_list->count; i++) {
-                       if (strstr(ids, cid_list->id[i].value))
-                               return 0;
-               }
-       }
-       return -ENOENT;
-}
-
-static acpi_status
-acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
-                                            union acpi_object *package)
-{
-       int i = 0;
-       union acpi_object *element = NULL;
-
-       if (!device || !package || (package->package.count < 2))
-               return AE_BAD_PARAMETER;
-
-       element = &(package->package.elements[0]);
-       if (!element)
-               return AE_BAD_PARAMETER;
-       if (element->type == ACPI_TYPE_PACKAGE) {
-               if ((element->package.count < 2) ||
-                   (element->package.elements[0].type !=
-                    ACPI_TYPE_LOCAL_REFERENCE)
-                   || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
-                       return AE_BAD_DATA;
-               device->wakeup.gpe_device =
-                   element->package.elements[0].reference.handle;
-               device->wakeup.gpe_number =
-                   (u32) element->package.elements[1].integer.value;
-       } else if (element->type == ACPI_TYPE_INTEGER) {
-               device->wakeup.gpe_number = element->integer.value;
-       } else
-               return AE_BAD_DATA;
-
-       element = &(package->package.elements[1]);
-       if (element->type != ACPI_TYPE_INTEGER) {
-               return AE_BAD_DATA;
-       }
-       device->wakeup.sleep_state = element->integer.value;
-
-       if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
-               return AE_NO_MEMORY;
-       }
-       device->wakeup.resources.count = package->package.count - 2;
-       for (i = 0; i < device->wakeup.resources.count; i++) {
-               element = &(package->package.elements[i + 2]);
-               if (element->type != ACPI_TYPE_ANY) {
-                       return AE_BAD_DATA;
-               }
-
-               device->wakeup.resources.handles[i] = element->reference.handle;
-       }
-
-       return AE_OK;
-}
-
-static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
-{
-       acpi_status status = 0;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       union acpi_object *package = NULL;
-
-       ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
-
-       /* _PRW */
-       status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
-       if (ACPI_FAILURE(status)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n"));
-               goto end;
-       }
-
-       package = (union acpi_object *)buffer.pointer;
-       status = acpi_bus_extract_wakeup_device_power_package(device, package);
-       if (ACPI_FAILURE(status)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
-                                 "Error extracting _PRW package\n"));
-               goto end;
-       }
-
-       acpi_os_free(buffer.pointer);
-
-       device->wakeup.flags.valid = 1;
-       /* Power button, Lid switch always enable wakeup */
-       if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
-               device->wakeup.flags.run_wake = 1;
-
-      end:
-       if (ACPI_FAILURE(status))
-               device->flags.wake_capable = 0;
-       return_VALUE(0);
-}
-
 /* --------------------------------------------------------------------------
                ACPI sysfs device file support
    -------------------------------------------------------------------------- */
@@ -445,37 +220,188 @@ acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
 }
 
 /* --------------------------------------------------------------------------
-                              Performance Management
+                       ACPI Bus operations
    -------------------------------------------------------------------------- */
+static int acpi_device_suspend(struct device *dev, pm_message_t state)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
 
-static int acpi_bus_get_perf_flags(struct acpi_device *device)
+       if (acpi_drv && acpi_drv->ops.suspend)
+               return acpi_drv->ops.suspend(acpi_dev, state);
+       return 0;
+}
+
+static int acpi_device_resume(struct device *dev)
 {
-       device->performance.state = ACPI_STATE_UNKNOWN;
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
+
+       if (acpi_drv && acpi_drv->ops.resume)
+               return acpi_drv->ops.resume(acpi_dev);
        return 0;
 }
 
-/* --------------------------------------------------------------------------
-                                 Driver Management
-   -------------------------------------------------------------------------- */
+static int acpi_bus_match(struct device *dev, struct device_driver *drv)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = to_acpi_driver(drv);
 
-static LIST_HEAD(acpi_bus_drivers);
+       if (acpi_drv->ops.match)
+               return !acpi_drv->ops.match(acpi_dev, acpi_drv);
+       return !acpi_match_ids(acpi_dev, acpi_drv->ids);
+}
 
-/**
- * acpi_bus_match - match device IDs to driver's supported IDs
- * @device: the device that we are trying to match to a driver
- * @driver: driver whose device id table is being checked
- *
- * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
- * matches the specified driver's criteria.
- */
-static int
-acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver)
+static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
+       char *buffer, int buffer_size)
 {
-       if (driver && driver->ops.match)
-               return driver->ops.match(device, driver);
-       return acpi_match_ids(device, driver->ids);
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       int i = 0, length = 0, ret = 0;
+
+       if (acpi_dev->flags.hardware_id)
+               ret = add_uevent_var(envp, num_envp, &i,
+                       buffer, buffer_size, &length,
+                       "HWID=%s", acpi_dev->pnp.hardware_id);
+       if (ret)
+               return -ENOMEM;
+       if (acpi_dev->flags.compatible_ids) {
+               int j;
+               struct acpi_compatible_id_list *cid_list;
+
+               cid_list = acpi_dev->pnp.cid_list;
+
+               for (j = 0; j < cid_list->count; j++) {
+                       ret = add_uevent_var(envp, num_envp, &i, buffer,
+                               buffer_size, &length, "COMPTID=%s",
+                               cid_list->id[j].value);
+                       if (ret)
+                               return -ENOMEM;
+               }
+       }
+
+       envp[i] = NULL;
+       return 0;
 }
 
+static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
+static int acpi_start_single_object(struct acpi_device *);
+static int acpi_device_probe(struct device * dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
+       int ret;
+
+       ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
+       if (!ret) {
+               acpi_start_single_object(acpi_dev);
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                       "Found driver [%s] for device [%s]\n",
+                       acpi_drv->name, acpi_dev->pnp.bus_id));
+               get_device(dev);
+       }
+       return ret;
+}
+
+static int acpi_device_remove(struct device * dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
+
+       if (acpi_drv) {
+               if (acpi_drv->ops.stop)
+                       acpi_drv->ops.stop(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
+               if (acpi_drv->ops.remove)
+                       acpi_drv->ops.remove(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
+       }
+       acpi_dev->driver = NULL;
+       acpi_driver_data(dev) = NULL;
+
+       put_device(dev);
+       return 0;
+}
+
+static void acpi_device_shutdown(struct device *dev)
+{
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_driver *acpi_drv = acpi_dev->driver;
+
+       if (acpi_drv && acpi_drv->ops.shutdown)
+               acpi_drv->ops.shutdown(acpi_dev);
+
+       return ;
+}
+
+static struct bus_type acpi_bus_type = {
+       .name           = "acpi",
+       .suspend        = acpi_device_suspend,
+       .resume         = acpi_device_resume,
+       .shutdown       = acpi_device_shutdown,
+       .match          = acpi_bus_match,
+       .probe          = acpi_device_probe,
+       .remove         = acpi_device_remove,
+       .uevent         = acpi_device_uevent,
+};
+
+static void acpi_device_register(struct acpi_device *device,
+                                struct acpi_device *parent)
+{
+       int err;
+
+       /*
+        * Linkage
+        * -------
+        * Link this device to its parent and siblings.
+        */
+       INIT_LIST_HEAD(&device->children);
+       INIT_LIST_HEAD(&device->node);
+       INIT_LIST_HEAD(&device->g_list);
+       INIT_LIST_HEAD(&device->wakeup_list);
+
+       spin_lock(&acpi_device_lock);
+       if (device->parent) {
+               list_add_tail(&device->node, &device->parent->children);
+               list_add_tail(&device->g_list, &device->parent->g_list);
+       } else
+               list_add_tail(&device->g_list, &acpi_device_list);
+       if (device->wakeup.flags.valid)
+               list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
+       spin_unlock(&acpi_device_lock);
+
+       strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
+       if (parent)
+               device->kobj.parent = &parent->kobj;
+       device->kobj.ktype = &ktype_acpi_ns;
+       device->kobj.kset = &acpi_namespace_kset;
+       err = kobject_register(&device->kobj);
+       if (err < 0)
+               printk(KERN_WARNING "%s: kobject_register error: %d\n",
+                       __FUNCTION__, err);
+       create_sysfs_device_files(device);
+}
+
+static void acpi_device_unregister(struct acpi_device *device, int type)
+{
+       spin_lock(&acpi_device_lock);
+       if (device->parent) {
+               list_del(&device->node);
+               list_del(&device->g_list);
+       } else
+               list_del(&device->g_list);
+
+       list_del(&device->wakeup_list);
+
+       spin_unlock(&acpi_device_lock);
+
+       acpi_detach_data(device->handle, acpi_bus_data_handler);
+       remove_sysfs_device_files(device);
+       kobject_unregister(&device->kobj);
+}
+
+/* --------------------------------------------------------------------------
+                                 Driver Management
+   -------------------------------------------------------------------------- */
+static LIST_HEAD(acpi_bus_drivers);
+
 /**
  * acpi_bus_driver_init - add a device to a driver
  * @device: the device to add and initialize
@@ -489,19 +415,18 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
 {
        int result = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
 
        if (!device || !driver)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        if (!driver->ops.add)
-               return_VALUE(-ENOSYS);
+               return -ENOSYS;
 
        result = driver->ops.add(device);
        if (result) {
                device->driver = NULL;
                acpi_driver_data(device) = NULL;
-               return_VALUE(result);
+               return result;
        }
 
        device->driver = driver;
@@ -513,7 +438,7 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "Driver successfully bound to device\n"));
-       return_VALUE(0);
+       return 0;
 }
 
 static int acpi_start_single_object(struct acpi_device *device)
@@ -521,10 +446,9 @@ static int acpi_start_single_object(struct acpi_device *device)
        int result = 0;
        struct acpi_driver *driver;
 
-       ACPI_FUNCTION_TRACE("acpi_start_single_object");
 
        if (!(driver = device->driver))
-               return_VALUE(0);
+               return 0;
 
        if (driver->ops.start) {
                result = driver->ops.start(device);
@@ -532,14 +456,13 @@ static int acpi_start_single_object(struct acpi_device *device)
                        driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
        }
 
-       return_VALUE(result);
+       return result;
 }
 
 static void acpi_driver_attach(struct acpi_driver *drv)
 {
        struct list_head *node, *next;
 
-       ACPI_FUNCTION_TRACE("acpi_driver_attach");
 
        spin_lock(&acpi_device_lock);
        list_for_each_safe(node, next, &acpi_device_list) {
@@ -550,7 +473,7 @@ static void acpi_driver_attach(struct acpi_driver *drv)
                        continue;
                spin_unlock(&acpi_device_lock);
 
-               if (!acpi_bus_match(dev, drv)) {
+               if (!acpi_bus_match(&(dev->dev), &(drv->drv))) {
                        if (!acpi_bus_driver_init(dev, drv)) {
                                acpi_start_single_object(dev);
                                atomic_inc(&drv->references);
@@ -568,7 +491,6 @@ static void acpi_driver_detach(struct acpi_driver *drv)
 {
        struct list_head *node, *next;
 
-       ACPI_FUNCTION_TRACE("acpi_driver_detach");
 
        spin_lock(&acpi_device_lock);
        list_for_each_safe(node, next, &acpi_device_list) {
@@ -598,17 +520,16 @@ static void acpi_driver_detach(struct acpi_driver *drv)
  */
 int acpi_bus_register_driver(struct acpi_driver *driver)
 {
-       ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
 
        if (acpi_disabled)
-               return_VALUE(-ENODEV);
+               return -ENODEV;
 
        spin_lock(&acpi_device_lock);
        list_add_tail(&driver->node, &acpi_bus_drivers);
        spin_unlock(&acpi_device_lock);
        acpi_driver_attach(driver);
 
-       return_VALUE(0);
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_bus_register_driver);
@@ -646,7 +567,6 @@ static int acpi_bus_find_driver(struct acpi_device *device)
        int result = 0;
        struct list_head *node, *next;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
 
        spin_lock(&acpi_device_lock);
        list_for_each_safe(node, next, &acpi_bus_drivers) {
@@ -655,7 +575,7 @@ static int acpi_bus_find_driver(struct acpi_device *device)
 
                atomic_inc(&driver->references);
                spin_unlock(&acpi_device_lock);
-               if (!acpi_bus_match(device, driver)) {
+               if (!acpi_bus_match(&(device->dev), &(driver->drv))) {
                        result = acpi_bus_driver_init(device, driver);
                        if (!result)
                                goto Done;
@@ -666,19 +586,217 @@ static int acpi_bus_find_driver(struct acpi_device *device)
        spin_unlock(&acpi_device_lock);
 
       Done:
-       return_VALUE(result);
+       return result;
 }
 
 /* --------------------------------------------------------------------------
                                  Device Enumeration
    -------------------------------------------------------------------------- */
+acpi_status
+acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
+{
+       acpi_status status;
+       acpi_handle tmp;
+       struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+       union acpi_object *obj;
+
+       status = acpi_get_handle(handle, "_EJD", &tmp);
+       if (ACPI_FAILURE(status))
+               return status;
+
+       status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
+       if (ACPI_SUCCESS(status)) {
+               obj = buffer.pointer;
+               status = acpi_get_handle(NULL, obj->string.pointer, ejd);
+               kfree(buffer.pointer);
+       }
+       return status;
+}
+EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
+
+void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
+{
+
+       /* TBD */
+
+       return;
+}
+
+int acpi_match_ids(struct acpi_device *device, char *ids)
+{
+       if (device->flags.hardware_id)
+               if (strstr(ids, device->pnp.hardware_id))
+                       return 0;
+
+       if (device->flags.compatible_ids) {
+               struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
+               int i;
+
+               /* compare multiple _CID entries against driver ids */
+               for (i = 0; i < cid_list->count; i++) {
+                       if (strstr(ids, cid_list->id[i].value))
+                               return 0;
+               }
+       }
+       return -ENOENT;
+}
+
+static int acpi_bus_get_perf_flags(struct acpi_device *device)
+{
+       device->performance.state = ACPI_STATE_UNKNOWN;
+       return 0;
+}
+
+static acpi_status
+acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
+                                            union acpi_object *package)
+{
+       int i = 0;
+       union acpi_object *element = NULL;
+
+       if (!device || !package || (package->package.count < 2))
+               return AE_BAD_PARAMETER;
+
+       element = &(package->package.elements[0]);
+       if (!element)
+               return AE_BAD_PARAMETER;
+       if (element->type == ACPI_TYPE_PACKAGE) {
+               if ((element->package.count < 2) ||
+                   (element->package.elements[0].type !=
+                    ACPI_TYPE_LOCAL_REFERENCE)
+                   || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
+                       return AE_BAD_DATA;
+               device->wakeup.gpe_device =
+                   element->package.elements[0].reference.handle;
+               device->wakeup.gpe_number =
+                   (u32) element->package.elements[1].integer.value;
+       } else if (element->type == ACPI_TYPE_INTEGER) {
+               device->wakeup.gpe_number = element->integer.value;
+       } else
+               return AE_BAD_DATA;
+
+       element = &(package->package.elements[1]);
+       if (element->type != ACPI_TYPE_INTEGER) {
+               return AE_BAD_DATA;
+       }
+       device->wakeup.sleep_state = element->integer.value;
+
+       if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
+               return AE_NO_MEMORY;
+       }
+       device->wakeup.resources.count = package->package.count - 2;
+       for (i = 0; i < device->wakeup.resources.count; i++) {
+               element = &(package->package.elements[i + 2]);
+               if (element->type != ACPI_TYPE_ANY) {
+                       return AE_BAD_DATA;
+               }
+
+               device->wakeup.resources.handles[i] = element->reference.handle;
+       }
+
+       return AE_OK;
+}
+
+static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
+{
+       acpi_status status = 0;
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *package = NULL;
+
+
+       /* _PRW */
+       status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
+       if (ACPI_FAILURE(status)) {
+               ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
+               goto end;
+       }
+
+       package = (union acpi_object *)buffer.pointer;
+       status = acpi_bus_extract_wakeup_device_power_package(device, package);
+       if (ACPI_FAILURE(status)) {
+               ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
+               goto end;
+       }
+
+       kfree(buffer.pointer);
+
+       device->wakeup.flags.valid = 1;
+       /* Power button, Lid switch always enable wakeup */
+       if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
+               device->wakeup.flags.run_wake = 1;
+
+      end:
+       if (ACPI_FAILURE(status))
+               device->flags.wake_capable = 0;
+       return 0;
+}
+
+static int acpi_bus_get_power_flags(struct acpi_device *device)
+{
+       acpi_status status = 0;
+       acpi_handle handle = NULL;
+       u32 i = 0;
+
+
+       /*
+        * Power Management Flags
+        */
+       status = acpi_get_handle(device->handle, "_PSC", &handle);
+       if (ACPI_SUCCESS(status))
+               device->power.flags.explicit_get = 1;
+       status = acpi_get_handle(device->handle, "_IRC", &handle);
+       if (ACPI_SUCCESS(status))
+               device->power.flags.inrush_current = 1;
+
+       /*
+        * Enumerate supported power management states
+        */
+       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
+               struct acpi_device_power_state *ps = &device->power.states[i];
+               char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
+
+               /* Evaluate "_PRx" to se if power resources are referenced */
+               acpi_evaluate_reference(device->handle, object_name, NULL,
+                                       &ps->resources);
+               if (ps->resources.count) {
+                       device->power.flags.power_resources = 1;
+                       ps->flags.valid = 1;
+               }
+
+               /* Evaluate "_PSx" to see if we can do explicit sets */
+               object_name[2] = 'S';
+               status = acpi_get_handle(device->handle, object_name, &handle);
+               if (ACPI_SUCCESS(status)) {
+                       ps->flags.explicit_set = 1;
+                       ps->flags.valid = 1;
+               }
+
+               /* State is valid if we have some power control */
+               if (ps->resources.count || ps->flags.explicit_set)
+                       ps->flags.valid = 1;
+
+               ps->power = -1; /* Unknown - driver assigned */
+               ps->latency = -1;       /* Unknown - driver assigned */
+       }
+
+       /* Set defaults for D0 and D3 states (always valid) */
+       device->power.states[ACPI_STATE_D0].flags.valid = 1;
+       device->power.states[ACPI_STATE_D0].power = 100;
+       device->power.states[ACPI_STATE_D3].flags.valid = 1;
+       device->power.states[ACPI_STATE_D3].power = 0;
+
+       /* TBD: System wake support and resource requirements. */
+
+       device->power.state = ACPI_STATE_UNKNOWN;
+
+       return 0;
+}
 
 static int acpi_bus_get_flags(struct acpi_device *device)
 {
        acpi_status status = AE_OK;
        acpi_handle temp = NULL;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
 
        /* Presence of _STA indicates 'dynamic_status' */
        status = acpi_get_handle(device->handle, "_STA", &temp);
@@ -724,7 +842,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
 
        /* TBD: Peformance management */
 
-       return_VALUE(0);
+       return 0;
 }
 
 static void acpi_device_get_busid(struct acpi_device *device,
@@ -842,7 +960,7 @@ static void acpi_device_set_id(struct acpi_device *device,
                        printk(KERN_ERR "Memory allocation error\n");
        }
 
-       acpi_os_free(buffer.pointer);
+       kfree(buffer.pointer);
 }
 
 static int acpi_device_set_context(struct acpi_device *device, int type)
@@ -918,10 +1036,9 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
        int result = 0;
        struct acpi_driver *driver;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_remove");
 
        if (!dev)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        driver = dev->driver;
 
@@ -930,12 +1047,12 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
                if (driver->ops.stop) {
                        result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
                        if (result)
-                               return_VALUE(result);
+                               return result;
                }
 
                result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
                if (result) {
-                       return_VALUE(result);
+                       return result;
                }
 
                atomic_dec(&dev->driver->references);
@@ -944,7 +1061,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
        }
 
        if (!rmdevice)
-               return_VALUE(0);
+               return 0;
 
        if (dev->flags.bus_address) {
                if ((dev->parent) && (dev->parent->ops.unbind))
@@ -953,7 +1070,7 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
 
        acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
 
-       return_VALUE(0);
+       return 0;
 }
 
 static int
@@ -963,15 +1080,14 @@ acpi_add_single_object(struct acpi_device **child,
        int result = 0;
        struct acpi_device *device = NULL;
 
-       ACPI_FUNCTION_TRACE("acpi_add_single_object");
 
        if (!child)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
        if (!device) {
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n"));
-               return_VALUE(-ENOMEM);
+               printk(KERN_ERR PREFIX "Memory allocation error\n");
+               return -ENOMEM;
        }
        memset(device, 0, sizeof(struct acpi_device));
 
@@ -1096,7 +1212,7 @@ acpi_add_single_object(struct acpi_device **child,
                kfree(device);
        }
 
-       return_VALUE(result);
+       return result;
 }
 
 static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
@@ -1109,10 +1225,9 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
        acpi_object_type type = 0;
        u32 level = 1;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_scan");
 
        if (!start)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        parent = start;
        phandle = start->handle;
@@ -1209,7 +1324,7 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
                }
        }
 
-       return_VALUE(0);
+       return 0;
 }
 
 int
@@ -1219,7 +1334,6 @@ acpi_bus_add(struct acpi_device **child,
        int result;
        struct acpi_bus_ops ops;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_add");
 
        result = acpi_add_single_object(child, parent, handle, type);
        if (!result) {
@@ -1227,7 +1341,7 @@ acpi_bus_add(struct acpi_device **child,
                ops.acpi_op_add = 1;
                result = acpi_bus_scan(*child, &ops);
        }
-       return_VALUE(result);
+       return result;
 }
 
 EXPORT_SYMBOL(acpi_bus_add);
@@ -1237,10 +1351,9 @@ int acpi_bus_start(struct acpi_device *device)
        int result;
        struct acpi_bus_ops ops;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_start");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        result = acpi_start_single_object(device);
        if (!result) {
@@ -1248,7 +1361,7 @@ int acpi_bus_start(struct acpi_device *device)
                ops.acpi_op_start = 1;
                result = acpi_bus_scan(device, &ops);
        }
-       return_VALUE(result);
+       return result;
 }
 
 EXPORT_SYMBOL(acpi_bus_start);
@@ -1314,10 +1427,9 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
        int result = 0;
        struct acpi_device *device = NULL;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
 
        if (!root)
-               return_VALUE(-ENODEV);
+               return -ENODEV;
 
        /*
         * Enumerate all fixed-feature devices.
@@ -1338,114 +1450,21 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
                        result = acpi_start_single_object(device);
        }
 
-       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;
+       return result;
 }
 
-
-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;
        struct acpi_bus_ops ops;
 
-       ACPI_FUNCTION_TRACE("acpi_scan_init");
 
        if (acpi_disabled)
-               return_VALUE(0);
+               return 0;
 
-       kset_register(&acpi_namespace_kset);
+       result = kset_register(&acpi_namespace_kset);
+       if (result < 0)
+               printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
 
        result = bus_register(&acpi_bus_type);
        if (result) {
@@ -1488,7 +1507,7 @@ static int __init acpi_scan_init(void)
                acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
 
       Done:
-       return_VALUE(result);
+       return result;
 }
 
 subsys_initcall(acpi_scan_init);