Pull misc-for-upstream into release branch
[pandora-kernel.git] / drivers / acpi / scan.c
index 2a82645..64f26db 100644 (file)
@@ -21,9 +21,15 @@ extern struct acpi_device *acpi_root;
 #define ACPI_BUS_DEVICE_NAME           "System Bus"
 
 static LIST_HEAD(acpi_device_list);
+static LIST_HEAD(acpi_bus_id_list);
 DEFINE_SPINLOCK(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 
+struct acpi_device_bus_id{
+       char bus_id[15];
+       unsigned int instance_no;
+       struct list_head node;
+};
 static int acpi_eject_operation(acpi_handle handle, int lockable)
 {
        struct acpi_object_list arg_list;
@@ -103,18 +109,61 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
 
 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
 
-static void acpi_device_setup_files(struct acpi_device *dev)
+static ssize_t
+acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+       return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id);
+}
+static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
+
+static ssize_t
+acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
+       int result;
+
+       result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
+       if(result)
+               goto end;
+
+       result = sprintf(buf, "%s\n", (char*)path.pointer);
+       kfree(path.pointer);
+  end:
+       return result;
+}
+static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
+
+static int acpi_device_setup_files(struct acpi_device *dev)
 {
        acpi_status status;
        acpi_handle temp;
+       int result = 0;
 
        /*
-        * If device has _EJ0, 'eject' file is created that is used to trigger
-        * hot-removal function from userland.
+        * Devices gotten from FADT don't have a "path" attribute
         */
+       if(dev->handle) {
+               result = device_create_file(&dev->dev, &dev_attr_path);
+               if(result)
+                       goto end;
+       }
+
+       if(dev->flags.hardware_id) {
+               result = device_create_file(&dev->dev, &dev_attr_hid);
+               if(result)
+                       goto end;
+       }
+
+        /*
+         * If device has _EJ0, 'eject' file is created that is used to trigger
+         * hot-removal function from userland.
+         */
        status = acpi_get_handle(dev->handle, "_EJ0", &temp);
        if (ACPI_SUCCESS(status))
-               device_create_file(&dev->dev, &dev_attr_eject);
+               result = device_create_file(&dev->dev, &dev_attr_eject);
+  end:
+       return result;
 }
 
 static void acpi_device_remove_files(struct acpi_device *dev)
@@ -129,6 +178,11 @@ static void acpi_device_remove_files(struct acpi_device *dev)
        status = acpi_get_handle(dev->handle, "_EJ0", &temp);
        if (ACPI_SUCCESS(status))
                device_remove_file(&dev->dev, &dev_attr_eject);
+
+       if(dev->flags.hardware_id)
+               device_remove_file(&dev->dev, &dev_attr_hid);
+       if(dev->handle)
+               device_remove_file(&dev->dev, &dev_attr_path);
 }
 /* --------------------------------------------------------------------------
                        ACPI Bus operations
@@ -166,8 +220,6 @@ 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);
 
-       if (acpi_drv->ops.match)
-               return !acpi_drv->ops.match(acpi_dev, acpi_drv);
        return !acpi_match_ids(acpi_dev, acpi_drv->ids);
 }
 
@@ -229,9 +281,9 @@ static int acpi_device_remove(struct device * dev)
 
        if (acpi_drv) {
                if (acpi_drv->ops.stop)
-                       acpi_drv->ops.stop(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
+                       acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
                if (acpi_drv->ops.remove)
-                       acpi_drv->ops.remove(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
+                       acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
        }
        acpi_dev->driver = NULL;
        acpi_driver_data(dev) = NULL;
@@ -262,9 +314,12 @@ static struct bus_type acpi_bus_type = {
        .uevent         = acpi_device_uevent,
 };
 
-static void acpi_device_register(struct acpi_device *device,
+static int acpi_device_register(struct acpi_device *device,
                                 struct acpi_device *parent)
 {
+       int result;
+       struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
+       int found = 0;
        /*
         * Linkage
         * -------
@@ -275,7 +330,33 @@ static void acpi_device_register(struct acpi_device *device,
        INIT_LIST_HEAD(&device->g_list);
        INIT_LIST_HEAD(&device->wakeup_list);
 
+       new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
+       if (!new_bus_id) {
+               printk(KERN_ERR PREFIX "Memory allocation error\n");
+               return -ENOMEM;
+       }
+
        spin_lock(&acpi_device_lock);
+       /*
+        * Find suitable bus_id and instance number in acpi_bus_id_list
+        * If failed, create one and link it into acpi_bus_id_list
+        */
+       list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
+               if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) {
+                       acpi_device_bus_id->instance_no ++;
+                       found = 1;
+                       kfree(new_bus_id);
+                       break;
+               }
+       }
+       if(!found) {
+               acpi_device_bus_id = new_bus_id;
+               strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device");
+               acpi_device_bus_id->instance_no = 0;
+               list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
+       }
+       sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
+
        if (device->parent) {
                list_add_tail(&device->node, &device->parent->children);
                list_add_tail(&device->g_list, &device->parent->g_list);
@@ -289,11 +370,29 @@ static void acpi_device_register(struct acpi_device *device,
                device->dev.parent = &parent->dev;
        device->dev.bus = &acpi_bus_type;
        device_initialize(&device->dev);
-       sprintf(device->dev.bus_id, "%s", device->pnp.bus_id);
        device->dev.release = &acpi_device_release;
-       device_add(&device->dev);
+       result = device_add(&device->dev);
+       if(result) {
+               printk("Error adding device %s", device->dev.bus_id);
+               goto end;
+       }
 
-       acpi_device_setup_files(device);
+       result = acpi_device_setup_files(device);
+       if(result)
+               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
+
+       device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
+       return 0;
+  end:
+       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);
+       return result;
 }
 
 static void acpi_device_unregister(struct acpi_device *device, int type)
@@ -705,6 +804,75 @@ static void acpi_device_get_busid(struct acpi_device *device,
        }
 }
 
+static int
+acpi_video_bus_match(struct acpi_device *device)
+{
+       acpi_handle h_dummy1;
+       acpi_handle h_dummy2;
+       acpi_handle h_dummy3;
+
+
+       if (!device)
+               return -EINVAL;
+
+       /* Since there is no HID, CID for ACPI Video drivers, we have
+        * to check well known required nodes for each feature we support.
+        */
+
+       /* Does this device able to support video switching ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
+               return 0;
+
+       /* Does this device able to retrieve a video ROM ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
+               return 0;
+
+       /* Does this device able to configure which video head to be POSTed ? */
+       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
+           ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
+               return 0;
+
+       return -ENODEV;
+}
+
+/*
+ * acpi_bay_match - see if a device is an ejectable driver bay
+ *
+ * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
+ * then we can safely call it an ejectable drive bay
+ */
+static int acpi_bay_match(struct acpi_device *device){
+       acpi_status status;
+       acpi_handle handle;
+       acpi_handle tmp;
+       acpi_handle phandle;
+
+       handle = device->handle;
+
+       status = acpi_get_handle(handle, "_EJ0", &tmp);
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
+
+       if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
+               (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
+               return 0;
+
+       if (acpi_get_parent(handle, &phandle))
+               return -ENODEV;
+
+        if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
+                (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
+                return 0;
+
+       return -ENODEV;
+}
+
 static void acpi_device_set_id(struct acpi_device *device,
                               struct acpi_device *parent, acpi_handle handle,
                               int type)
@@ -735,6 +903,16 @@ static void acpi_device_set_id(struct acpi_device *device,
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
                }
+
+               if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){
+                       status = acpi_video_bus_match(device);
+                       if(ACPI_SUCCESS(status))
+                               hid = ACPI_VIDEO_HID;
+
+                       status = acpi_bay_match(device);
+                       if (ACPI_SUCCESS(status))
+                               hid = ACPI_BAY_HID;
+               }
                break;
        case ACPI_BUS_TYPE_POWER:
                hid = ACPI_POWER_HID;
@@ -811,64 +989,24 @@ static int acpi_device_set_context(struct acpi_device *device, int type)
        return result;
 }
 
-static void acpi_device_get_debug_info(struct acpi_device *device,
-                                      acpi_handle handle, int type)
-{
-#ifdef CONFIG_ACPI_DEBUG_OUTPUT
-       char *type_string = NULL;
-       char name[80] = { '?', '\0' };
-       struct acpi_buffer buffer = { sizeof(name), name };
-
-       switch (type) {
-       case ACPI_BUS_TYPE_DEVICE:
-               type_string = "Device";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_POWER:
-               type_string = "Power Resource";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_PROCESSOR:
-               type_string = "Processor";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_SYSTEM:
-               type_string = "System";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_THERMAL:
-               type_string = "Thermal Zone";
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-               break;
-       case ACPI_BUS_TYPE_POWER_BUTTON:
-               type_string = "Power Button";
-               sprintf(name, "PWRB");
-               break;
-       case ACPI_BUS_TYPE_SLEEP_BUTTON:
-               type_string = "Sleep Button";
-               sprintf(name, "SLPB");
-               break;
-       }
-
-       printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
-#endif                         /*CONFIG_ACPI_DEBUG_OUTPUT */
-}
-
 static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
 {
        if (!dev)
                return -EINVAL;
 
+       dev->removal_type = ACPI_BUS_REMOVAL_EJECT;
        device_release_driver(&dev->dev);
 
        if (!rmdevice)
                return 0;
 
+       /*
+        * unbind _ADR-Based Devices when hot removal
+        */
        if (dev->flags.bus_address) {
                if ((dev->parent) && (dev->parent->ops.unbind))
                        dev->parent->ops.unbind(dev);
        }
-
        acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
 
        return 0;
@@ -886,12 +1024,11 @@ acpi_add_single_object(struct acpi_device **child,
        if (!child)
                return -EINVAL;
 
-       device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
+       device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
        if (!device) {
                printk(KERN_ERR PREFIX "Memory allocation error\n");
                return -ENOMEM;
        }
-       memset(device, 0, sizeof(struct acpi_device));
 
        device->handle = handle;
        device->parent = parent;
@@ -981,16 +1118,10 @@ acpi_add_single_object(struct acpi_device **child,
        if ((result = acpi_device_set_context(device, type)))
                goto end;
 
-       acpi_device_get_debug_info(device, handle, type);
-
-       acpi_device_register(device, parent);
+       result = acpi_device_register(device, parent);
 
        /*
-        * Bind _ADR-Based Devices
-        * -----------------------
-        * If there's a a bus address (_ADR) then we utilize the parent's 
-        * 'bind' function (if exists) to bind the ACPI- and natively-
-        * enumerated device representations.
+        * Bind _ADR-Based Devices when hot add
         */
        if (device->flags.bus_address) {
                if (device->parent && device->parent->ops.bind)
@@ -1231,14 +1362,14 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
        /*
         * Enumerate all fixed-feature devices.
         */
-       if (acpi_fadt.pwr_button == 0) {
+       if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
                result = acpi_add_single_object(&device, acpi_root,
                                                NULL,
                                                ACPI_BUS_TYPE_POWER_BUTTON,
                                                &ops);
        }
 
-       if (acpi_fadt.sleep_button == 0) {
+       if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
                result = acpi_add_single_object(&device, acpi_root,
                                                NULL,
                                                ACPI_BUS_TYPE_SLEEP_BUTTON,