pull asus sony thinkpad into release branch
[safe/jmp/linux-2.6] / drivers / acpi / scan.c
index 769e54b..be74347 100644 (file)
 #include <acpi/acinterp.h>     /* for acpi_ex_eisa_id_to_string() */
 
 #define _COMPONENT             ACPI_BUS_COMPONENT
-ACPI_MODULE_NAME("scan")
+ACPI_MODULE_NAME("scan");
 #define STRUCT_TO_INT(s)       (*((int*)&s))
 extern struct acpi_device *acpi_root;
 
 #define ACPI_BUS_CLASS                 "system_bus"
-#define ACPI_BUS_HID                   "ACPI_BUS"
-#define ACPI_BUS_DRIVER_NAME           "ACPI Bus Driver"
+#define ACPI_BUS_HID                   "LNXSYBUS"
 #define ACPI_BUS_DEVICE_NAME           "System Bus"
 
 static LIST_HEAD(acpi_device_list);
@@ -26,10 +25,66 @@ DEFINE_SPINLOCK(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 
 struct acpi_device_bus_id{
-       char bus_id[9];
+       char bus_id[15];
        unsigned int instance_no;
        struct list_head node;
 };
+
+/*
+ * Creates hid/cid(s) string needed for modalias and uevent
+ * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
+ * char *modalias: "acpi:IBM0001:ACPI0001"
+*/
+int create_modalias(struct acpi_device *acpi_dev, char *modalias, int size){
+
+       int len;
+
+       if (!acpi_dev->flags.hardware_id)
+               return -ENODEV;
+
+       len = snprintf(modalias, size, "acpi:%s:",
+                      acpi_dev->pnp.hardware_id);
+       if (len < 0 || len >= size)
+               return -EINVAL;
+       size -= len;
+
+       if (acpi_dev->flags.compatible_ids) {
+               struct acpi_compatible_id_list *cid_list;
+               int i;
+               int count;
+
+               cid_list = acpi_dev->pnp.cid_list;
+               for (i = 0; i < cid_list->count; i++) {
+                       count = snprintf(&modalias[len], size, "%s:",
+                                        cid_list->id[i].value);
+                       if (count < 0 || count >= size) {
+                               printk(KERN_ERR "acpi: %s cid[%i] exceeds event buffer size",
+                                      acpi_dev->pnp.device_name, i);
+                               break;
+                       }
+                       len += count;
+                       size -= count;
+               }
+       }
+
+       modalias[len] = '\0';
+       return len;
+}
+
+static ssize_t
+acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+       int len;
+
+       /* Device has no HID and no CID or string is >1024 */
+       len = create_modalias(acpi_dev, buf, 1024);
+       if (len <= 0)
+               return 0;
+       buf[len++] = '\n';
+       return len;
+}
+static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
+
 static int acpi_eject_operation(acpi_handle handle, int lockable)
 {
        struct acpi_object_list arg_list;
@@ -155,6 +210,12 @@ static int acpi_device_setup_files(struct acpi_device *dev)
                        goto end;
        }
 
+       if (dev->flags.hardware_id || dev->flags.compatible_ids){
+               result = device_create_file(&dev->dev, &dev_attr_modalias);
+               if(result)
+                       goto end;
+       }
+
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
@@ -179,6 +240,9 @@ static void acpi_device_remove_files(struct acpi_device *dev)
        if (ACPI_SUCCESS(status))
                device_remove_file(&dev->dev, &dev_attr_eject);
 
+       if (dev->flags.hardware_id || dev->flags.compatible_ids)
+               device_remove_file(&dev->dev, &dev_attr_modalias);
+
        if(dev->flags.hardware_id)
                device_remove_file(&dev->dev, &dev_attr_hid);
        if(dev->handle)
@@ -187,6 +251,37 @@ static void acpi_device_remove_files(struct acpi_device *dev)
 /* --------------------------------------------------------------------------
                        ACPI Bus operations
    -------------------------------------------------------------------------- */
+
+int acpi_match_device_ids(struct acpi_device *device,
+                         const struct acpi_device_id *ids)
+{
+       const struct acpi_device_id *id;
+
+       if (device->flags.hardware_id) {
+               for (id = ids; id->id[0]; id++) {
+                       if (!strcmp((char*)id->id, device->pnp.hardware_id))
+                               return 0;
+               }
+       }
+
+       if (device->flags.compatible_ids) {
+               struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
+               int i;
+
+               for (id = ids; id->id[0]; id++) {
+                       /* compare multiple _CID entries against driver ids */
+                       for (i = 0; i < cid_list->count; i++) {
+                               if (!strcmp((char*)id->id,
+                                           cid_list->id[i].value))
+                                       return 0;
+                       }
+               }
+       }
+
+       return -ENOENT;
+}
+EXPORT_SYMBOL(acpi_match_device_ids);
+
 static void acpi_device_release(struct device *dev)
 {
        struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -220,37 +315,19 @@ 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);
 
-       return !acpi_match_ids(acpi_dev, acpi_drv->ids);
+       return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
 }
 
 static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
-       char *buffer, int buffer_size)
+                             char *buffer, int buffer_size)
 {
        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;
-               }
+       strcpy(buffer, "MODALIAS=");
+       if (create_modalias(acpi_dev, buffer + 9, buffer_size - 9) > 0) {
+               envp[0] = buffer;
+               envp[1] = NULL;
        }
-
-       envp[i] = NULL;
        return 0;
 }
 
@@ -303,7 +380,7 @@ static void acpi_device_shutdown(struct device *dev)
        return ;
 }
 
-static struct bus_type acpi_bus_type = {
+struct bus_type acpi_bus_type = {
        .name           = "acpi",
        .suspend        = acpi_device_suspend,
        .resume         = acpi_device_resume,
@@ -342,7 +419,7 @@ static int acpi_device_register(struct acpi_device *device,
         * 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 : "PNPIDNON")) {
+               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);
@@ -351,7 +428,7 @@ static int acpi_device_register(struct acpi_device *device,
        }
        if(!found) {
                acpi_device_bus_id = new_bus_id;
-               strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "PNPIDNON");
+               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);
        }
@@ -544,25 +621,6 @@ void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
        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;
@@ -625,6 +683,13 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *package = NULL;
 
+       struct acpi_device_id button_device_ids[] = {
+               {"PNP0C0D", 0},
+               {"PNP0C0C", 0},
+               {"PNP0C0E", 0},
+               {"", 0},
+       };
+
 
        /* _PRW */
        status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
@@ -644,7 +709,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
 
        device->wakeup.flags.valid = 1;
        /* Power button, Lid switch always enable wakeup */
-       if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
+       if (!acpi_match_device_ids(device, button_device_ids))
                device->wakeup.flags.run_wake = 1;
 
       end:
@@ -837,18 +902,40 @@ acpi_video_bus_match(struct acpi_device *device)
        return -ENODEV;
 }
 
-static int acpi_pci_bridge_match(struct acpi_device *device)
-{
-       acpi_status status;
-       acpi_handle handle;
-
-       /* pci bridge has _PRT but isn't PNP0A03 */
-       status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
-       if (ACPI_FAILURE(status))
-               return -ENODEV;
-       if (!acpi_match_ids(device, "PNP0A03"))
-               return -ENODEV;
-       return 0;
+/*
+ * 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,
@@ -887,9 +974,9 @@ static void acpi_device_set_id(struct acpi_device *device,
                        if(ACPI_SUCCESS(status))
                                hid = ACPI_VIDEO_HID;
 
-                       status = acpi_pci_bridge_match(device);
-                       if(ACPI_SUCCESS(status))
-                               hid = ACPI_PCI_BRIDGE_HID;
+                       status = acpi_bay_match(device);
+                       if (ACPI_SUCCESS(status))
+                               hid = ACPI_BAY_HID;
                }
                break;
        case ACPI_BUS_TYPE_POWER:
@@ -967,49 +1054,6 @@ 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)
@@ -1021,6 +1065,13 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
        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;
@@ -1038,12 +1089,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;
@@ -1084,7 +1134,9 @@ acpi_add_single_object(struct acpi_device **child,
                }
                break;
        default:
-               STRUCT_TO_INT(device->status) = 0x0F;
+               STRUCT_TO_INT(device->status) =
+                   ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
+                   ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
                break;
        }
 
@@ -1133,10 +1185,16 @@ 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);
-
        result = acpi_device_register(device, parent);
 
+       /*
+        * Bind _ADR-Based Devices when hot add
+        */
+       if (device->flags.bus_address) {
+               if (device->parent && device->parent->ops.bind)
+                       device->parent->ops.bind(device);
+       }
+
       end:
        if (!result)
                *child = device;
@@ -1371,14 +1429,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,