]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pnp/pnpacpi/core.c
Merge branches 'release' and 'stats' into release
[linux-2.6-omap-h63xx.git] / drivers / pnp / pnpacpi / core.c
index a00548799e98f8655fbb9efcdd53c10e0837f06c..662b4c279cfcaff775739eb3e35f128bc065c12c 100644 (file)
 
 #include <linux/acpi.h>
 #include <linux/pnp.h>
+#include <linux/mod_devicetable.h>
 #include <acpi/acpi_bus.h>
+#include <acpi/actypes.h>
+
 #include "pnpacpi.h"
 
 static int num = 0;
@@ -31,17 +34,19 @@ static int num = 0;
  * used by the kernel (PCI root, ...), as it is harmless and there were
  * already present in pnpbios. But there is an exception for devices that
  * have irqs (PIC, Timer) because we call acpi_register_gsi.
- * Finaly only devices that have a CRS method need to be in this list.
+ * Finally, only devices that have a CRS method need to be in this list.
  */
-static char __initdata excluded_id_list[] =
-       "PNP0C09," /* EC */
-       "PNP0C0F," /* Link device */
-       "PNP0000," /* PIC */
-       "PNP0100," /* Timer */
-       ;
+static struct __initdata acpi_device_id excluded_id_list[] = {
+       {"PNP0C09", 0},         /* EC */
+       {"PNP0C0F", 0},         /* Link device */
+       {"PNP0000", 0},         /* PIC */
+       {"PNP0100", 0},         /* Timer */
+       {"", 0},
+};
+
 static inline int is_exclusive_device(struct acpi_device *dev)
 {
-       return (!acpi_match_ids(dev, excluded_id_list));
+       return (!acpi_match_device_ids(dev, excluded_id_list));
 }
 
 /*
@@ -79,15 +84,18 @@ static void __init pnpidacpi_to_pnpid(char *id, char *str)
        str[7] = '\0';
 }
 
-static int pnpacpi_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
+static int pnpacpi_get_resources(struct pnp_dev *dev,
+                                struct pnp_resource_table *res)
 {
        acpi_status status;
-       status = pnpacpi_parse_allocated_resource((acpi_handle)dev->data,
-               &dev->res);
+
+       status = pnpacpi_parse_allocated_resource((acpi_handle) dev->data,
+                                                 &dev->res);
        return ACPI_FAILURE(status) ? -ENODEV : 0;
 }
 
-static int pnpacpi_set_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
+static int pnpacpi_set_resources(struct pnp_dev *dev,
+                                struct pnp_resource_table *res)
 {
        acpi_handle handle = dev->data;
        struct acpi_buffer buffer;
@@ -114,16 +122,41 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev)
        acpi_status status;
 
        /* acpi_unregister_gsi(pnp_irq(dev, 0)); */
-       status = acpi_evaluate_object((acpi_handle)dev->data,
-               "_DIS", NULL, NULL);
+       status = acpi_evaluate_object((acpi_handle) dev->data,
+                                     "_DIS", NULL, NULL);
        return ACPI_FAILURE(status) ? -ENODEV : 0;
 }
 
+#ifdef CONFIG_ACPI_SLEEP
+static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
+{
+       int power_state;
+
+       power_state = acpi_pm_device_sleep_state(&dev->dev,
+                                               device_may_wakeup(&dev->dev),
+                                               NULL);
+       if (power_state < 0)
+               power_state = (state.event == PM_EVENT_ON) ?
+                               ACPI_STATE_D0 : ACPI_STATE_D3;
+
+       return acpi_bus_set_power((acpi_handle) dev->data, power_state);
+}
+
+static int pnpacpi_resume(struct pnp_dev *dev)
+{
+       return acpi_bus_set_power((acpi_handle) dev->data, ACPI_STATE_D0);
+}
+#endif
+
 static struct pnp_protocol pnpacpi_protocol = {
-       .name   = "Plug and Play ACPI",
-       .get    = pnpacpi_get_resources,
-       .set    = pnpacpi_set_resources,
+       .name    = "Plug and Play ACPI",
+       .get     = pnpacpi_get_resources,
+       .set     = pnpacpi_set_resources,
        .disable = pnpacpi_disable_resources,
+#ifdef CONFIG_ACPI_SLEEP
+       .suspend = pnpacpi_suspend,
+       .resume = pnpacpi_resume,
+#endif
 };
 
 static int __init pnpacpi_add_device(struct acpi_device *device)
@@ -135,23 +168,22 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 
        status = acpi_get_handle(device->handle, "_CRS", &temp);
        if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
-               is_exclusive_device(device))
+           is_exclusive_device(device))
                return 0;
 
-       pnp_dbg("ACPI device : hid %s", acpi_device_hid(device));
-       dev =  kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+       dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
        if (!dev) {
                pnp_err("Out of memory");
                return -ENOMEM;
        }
        dev->data = device->handle;
-       /* .enabled means if the device can decode the resources */
+       /* .enabled means the device can decode the resources */
        dev->active = device->status.enabled;
        status = acpi_get_handle(device->handle, "_SRS", &temp);
        if (ACPI_SUCCESS(status))
                dev->capabilities |= PNP_CONFIGURABLE;
        dev->capabilities |= PNP_READ;
-       if (device->flags.dynamic_status)
+       if (device->flags.dynamic_status && (dev->capabilities & PNP_CONFIGURABLE))
                dev->capabilities |= PNP_WRITE;
        if (device->flags.removable)
                dev->capabilities |= PNP_REMOVABLE;
@@ -175,20 +207,23 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
        pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
        pnp_add_id(dev_id, dev);
 
-       if(dev->active) {
+       if (dev->active) {
                /* parse allocated resource */
-               status = pnpacpi_parse_allocated_resource(device->handle, &dev->res);
+               status = pnpacpi_parse_allocated_resource(device->handle,
+                                                         &dev->res);
                if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
-                       pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s", dev_id->id);
+                       pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
+                               dev_id->id);
                        goto err1;
                }
        }
 
-       if(dev->capabilities & PNP_CONFIGURABLE) {
+       if (dev->capabilities & PNP_CONFIGURABLE) {
                status = pnpacpi_parse_resource_option_data(device->handle,
-                       dev);
+                                                           dev);
                if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
-                       pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s", dev_id->id);
+                       pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
+                               dev_id->id);
                        goto err1;
                }
        }
@@ -214,7 +249,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
        if (!dev->active)
                pnp_init_resource_table(&dev->res);
        pnp_add_device(dev);
-       num ++;
+       num++;
 
        return AE_OK;
 err1:
@@ -225,7 +260,8 @@ err:
 }
 
 static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
-       u32 lvl, void *context, void **rv)
+                                                    u32 lvl, void *context,
+                                                    void **rv)
 {
        struct acpi_device *device;
 
@@ -238,23 +274,22 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
 
 static int __init acpi_pnp_match(struct device *dev, void *_pnp)
 {
-       struct acpi_device      *acpi = to_acpi_device(dev);
-       struct pnp_dev          *pnp = _pnp;
+       struct acpi_device *acpi = to_acpi_device(dev);
+       struct pnp_dev *pnp = _pnp;
 
        /* true means it matched */
        return acpi->flags.hardware_id
-               && !acpi_get_physical_device(acpi->handle)
-               && compare_pnp_id(pnp->id, acpi->pnp.hardware_id);
+           && !acpi_get_physical_device(acpi->handle)
+           && compare_pnp_id(pnp->id, acpi->pnp.hardware_id);
 }
 
-static int __init acpi_pnp_find_device(struct device *dev, acpi_handle *handle)
+static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle)
 {
-       struct device           *adev;
-       struct acpi_device      *acpi;
+       struct device *adev;
+       struct acpi_device *acpi;
 
        adev = bus_find_device(&acpi_bus_type, NULL,
-                       to_pnp_dev(dev),
-                       acpi_pnp_match);
+                              to_pnp_dev(dev), acpi_pnp_match);
        if (!adev)
                return -ENODEV;
 
@@ -268,7 +303,7 @@ static int __init acpi_pnp_find_device(struct device *dev, acpi_handle *handle)
  * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling.
  */
 static struct acpi_bus_type __initdata acpi_pnp_bus = {
-       .bus = &pnp_bus_type,
+       .bus         = &pnp_bus_type,
        .find_device = acpi_pnp_find_device,
 };
 
@@ -288,6 +323,7 @@ static int __init pnpacpi_init(void)
        pnp_platform_devices = 1;
        return 0;
 }
+
 subsys_initcall(pnpacpi_init);
 
 static int __init pnpacpi_setup(char *str)
@@ -298,8 +334,5 @@ static int __init pnpacpi_setup(char *str)
                pnpacpi_disabled = 1;
        return 1;
 }
-__setup("pnpacpi=", pnpacpi_setup);
 
-#if 0
-EXPORT_SYMBOL(pnpacpi_protocol);
-#endif
+__setup("pnpacpi=", pnpacpi_setup);