ACPI: processor: unify arch_acpi_processor_init_pdc
[safe/jmp/linux-2.6] / drivers / acpi / ec.c
index dc55618..75b147f 100644 (file)
 #include <asm/io.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
+#include <linux/dmi.h>
 
 #define ACPI_EC_CLASS                  "embedded_controller"
 #define ACPI_EC_DEVICE_NAME            "Embedded Controller"
 #define ACPI_EC_FILE_INFO              "info"
 
-#undef PREFIX
 #define PREFIX                         "ACPI: EC: "
 
 /* EC status register */
@@ -119,6 +119,8 @@ static struct acpi_ec {
 } *boot_ec, *first_ec;
 
 static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
+static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */
+static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
 
 /* --------------------------------------------------------------------------
                              Transaction Management
@@ -232,10 +234,8 @@ static int ec_poll(struct acpi_ec *ec)
                        }
                        advance_transaction(ec, acpi_ec_read_status(ec));
                } while (time_before(jiffies, delay));
-               if (!ec->curr->irq_count ||
-                   (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
+               if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
                        break;
-               /* try restart command if we get any false interrupts */
                pr_debug(PREFIX "controller reset, restart transaction\n");
                spin_lock_irqsave(&ec->curr_lock, flags);
                start_transaction(ec);
@@ -744,6 +744,42 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
        return AE_CTRL_TERMINATE;
 }
 
+static int ec_install_handlers(struct acpi_ec *ec)
+{
+       acpi_status status;
+       if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
+               return 0;
+       status = acpi_install_gpe_handler(NULL, ec->gpe,
+                                 ACPI_GPE_EDGE_TRIGGERED,
+                                 &acpi_ec_gpe_handler, ec);
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
+       acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+       acpi_enable_gpe(NULL, ec->gpe);
+       status = acpi_install_address_space_handler(ec->handle,
+                                                   ACPI_ADR_SPACE_EC,
+                                                   &acpi_ec_space_handler,
+                                                   NULL, ec);
+       if (ACPI_FAILURE(status)) {
+               if (status == AE_NOT_FOUND) {
+                       /*
+                        * Maybe OS fails in evaluating the _REG object.
+                        * The AE_NOT_FOUND error will be ignored and OS
+                        * continue to initialize EC.
+                        */
+                       printk(KERN_ERR "Fail in evaluating the _REG object"
+                               " of EC device. Broken bios is suspected.\n");
+               } else {
+                       acpi_remove_gpe_handler(NULL, ec->gpe,
+                               &acpi_ec_gpe_handler);
+                       return -ENODEV;
+               }
+       }
+
+       set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
+       return 0;
+}
+
 static void ec_remove_handlers(struct acpi_ec *ec)
 {
        if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
@@ -758,9 +794,8 @@ static void ec_remove_handlers(struct acpi_ec *ec)
 static int acpi_ec_add(struct acpi_device *device)
 {
        struct acpi_ec *ec = NULL;
+       int ret;
 
-       if (!device)
-               return -EINVAL;
        strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
        strcpy(acpi_device_class(device), ACPI_EC_CLASS);
 
@@ -785,7 +820,7 @@ static int acpi_ec_add(struct acpi_device *device)
 
        /* Find and register all query methods */
        acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
-                           acpi_ec_register_query_methods, ec, NULL);
+                           acpi_ec_register_query_methods, NULL, ec, NULL);
 
        if (!first_ec)
                first_ec = ec;
@@ -793,7 +828,12 @@ static int acpi_ec_add(struct acpi_device *device)
        acpi_ec_add_fs(device);
        pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
                          ec->gpe, ec->command_addr, ec->data_addr);
-       return 0;
+
+       ret = ec_install_handlers(ec);
+
+       /* EC is fully operational, allow queries */
+       clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
+       return ret;
 }
 
 static int acpi_ec_remove(struct acpi_device *device, int type)
@@ -805,6 +845,7 @@ static int acpi_ec_remove(struct acpi_device *device, int type)
                return -EINVAL;
 
        ec = acpi_driver_data(device);
+       ec_remove_handlers(ec);
        mutex_lock(&ec->lock);
        list_for_each_entry_safe(handler, tmp, &ec->list, node) {
                list_del(&handler->node);
@@ -842,91 +883,60 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context)
        return AE_OK;
 }
 
-static int ec_install_handlers(struct acpi_ec *ec)
+int __init acpi_boot_ec_enable(void)
 {
-       acpi_status status;
-       if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
+       if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
+               return 0;
+       if (!ec_install_handlers(boot_ec)) {
+               first_ec = boot_ec;
                return 0;
-       status = acpi_install_gpe_handler(NULL, ec->gpe,
-                                 ACPI_GPE_EDGE_TRIGGERED,
-                                 &acpi_ec_gpe_handler, ec);
-       if (ACPI_FAILURE(status))
-               return -ENODEV;
-       acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
-       acpi_enable_gpe(NULL, ec->gpe);
-       status = acpi_install_address_space_handler(ec->handle,
-                                                   ACPI_ADR_SPACE_EC,
-                                                   &acpi_ec_space_handler,
-                                                   NULL, ec);
-       if (ACPI_FAILURE(status)) {
-               if (status == AE_NOT_FOUND) {
-                       /*
-                        * Maybe OS fails in evaluating the _REG object.
-                        * The AE_NOT_FOUND error will be ignored and OS
-                        * continue to initialize EC.
-                        */
-                       printk(KERN_ERR "Fail in evaluating the _REG object"
-                               " of EC device. Broken bios is suspected.\n");
-               } else {
-                       acpi_remove_gpe_handler(NULL, ec->gpe,
-                               &acpi_ec_gpe_handler);
-                       return -ENODEV;
-               }
        }
-
-       set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
-       return 0;
+       return -EFAULT;
 }
 
-static int acpi_ec_start(struct acpi_device *device)
-{
-       struct acpi_ec *ec;
-       int ret = 0;
-
-       if (!device)
-               return -EINVAL;
-
-       ec = acpi_driver_data(device);
-
-       if (!ec)
-               return -EINVAL;
-
-       ret = ec_install_handlers(ec);
+static const struct acpi_device_id ec_device_ids[] = {
+       {"PNP0C09", 0},
+       {"", 0},
+};
 
-       /* EC is fully operational, allow queries */
-       clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
-       return ret;
+/* Some BIOS do not survive early DSDT scan, skip it */
+static int ec_skip_dsdt_scan(const struct dmi_system_id *id)
+{
+       EC_FLAGS_SKIP_DSDT_SCAN = 1;
+       return 0;
 }
 
-static int acpi_ec_stop(struct acpi_device *device, int type)
+/* ASUStek often supplies us with broken ECDT, validate it */
+static int ec_validate_ecdt(const struct dmi_system_id *id)
 {
-       struct acpi_ec *ec;
-       if (!device)
-               return -EINVAL;
-       ec = acpi_driver_data(device);
-       if (!ec)
-               return -EINVAL;
-       ec_remove_handlers(ec);
-
+       EC_FLAGS_VALIDATE_ECDT = 1;
        return 0;
 }
 
-int __init acpi_boot_ec_enable(void)
+/* MSI EC needs special treatment, enable it */
+static int ec_flag_msi(const struct dmi_system_id *id)
 {
-       if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
-               return 0;
-       if (!ec_install_handlers(boot_ec)) {
-               first_ec = boot_ec;
-               return 0;
-       }
-       return -EFAULT;
+       EC_FLAGS_MSI = 1;
+       EC_FLAGS_VALIDATE_ECDT = 1;
+       return 0;
 }
 
-static const struct acpi_device_id ec_device_ids[] = {
-       {"PNP0C09", 0},
-       {"", 0},
+static struct dmi_system_id __initdata ec_dmi_table[] = {
+       {
+       ec_skip_dsdt_scan, "Compal JFL92", {
+       DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
+       DMI_MATCH(DMI_BOARD_NAME, "JFL92") }, NULL},
+       {
+       ec_flag_msi, "MSI hardware", {
+       DMI_MATCH(DMI_BIOS_VENDOR, "Micro-Star"),
+       DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-Star") }, NULL},
+       {
+       ec_validate_ecdt, "ASUS hardware", {
+       DMI_MATCH(DMI_BIOS_VENDOR, "ASUS") }, NULL},
+       {},
 };
 
+
 int __init acpi_ec_ecdt_probe(void)
 {
        acpi_status status;
@@ -939,11 +949,7 @@ int __init acpi_ec_ecdt_probe(void)
        /*
         * Generate a boot ec context
         */
-       if (dmi_name_in_vendors("Micro-Star") ||
-           dmi_name_in_vendors("Notebook")) {
-               pr_info(PREFIX "Enabling special treatment for EC from MSI.\n");
-               EC_FLAGS_MSI = 1;
-       }
+       dmi_check_system(ec_dmi_table);
        status = acpi_get_table(ACPI_SIG_ECDT, 1,
                                (struct acpi_table_header **)&ecdt_ptr);
        if (ACPI_SUCCESS(status)) {
@@ -954,7 +960,7 @@ int __init acpi_ec_ecdt_probe(void)
                boot_ec->handle = ACPI_ROOT_OBJECT;
                acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
                /* Don't trust ECDT, which comes from ASUSTek */
-               if (!dmi_name_in_vendors("ASUS") && EC_FLAGS_MSI == 0)
+               if (!EC_FLAGS_VALIDATE_ECDT)
                        goto install;
                saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
                if (!saved_ec)
@@ -962,6 +968,10 @@ int __init acpi_ec_ecdt_probe(void)
                memcpy(saved_ec, boot_ec, sizeof(struct acpi_ec));
        /* fall through */
        }
+
+       if (EC_FLAGS_SKIP_DSDT_SCAN)
+               return -ENODEV;
+
        /* This workaround is needed only on some broken machines,
         * which require early EC, but fail to provide ECDT */
        printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
@@ -1027,8 +1037,6 @@ static struct acpi_driver acpi_ec_driver = {
        .ops = {
                .add = acpi_ec_add,
                .remove = acpi_ec_remove,
-               .start = acpi_ec_start,
-               .stop = acpi_ec_stop,
                .suspend = acpi_ec_suspend,
                .resume = acpi_ec_resume,
                },