[ALSA] hda-codec - Add model for Acer Aspire 5315
[safe/jmp/linux-2.6] / drivers / pci / pci-driver.c
index de5b901..c4fa35d 100644 (file)
@@ -1,6 +1,11 @@
 /*
  * drivers/pci/pci-driver.c
  *
+ * (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <greg@kroah.com>
+ * (C) Copyright 2007 Novell Inc.
+ *
+ * Released under the GPL v2 only.
+ *
  */
 
 #include <linux/pci.h>
 #include "pci.h"
 
 /*
- *  Registration of PCI drivers and handling of hot-pluggable devices.
- */
-
-/* multithreaded probe logic */
-static int pci_multithread_probe =
-#ifdef CONFIG_PCI_MULTITHREAD_PROBE
-       1;
-#else
-       0;
-#endif
-__module_param_call("", pci_multithread_probe, param_set_bool, param_get_bool, &pci_multithread_probe, 0644);
-
-
-/*
  * Dynamic device IDs are disabled for !CONFIG_HOTPLUG
  */
 
@@ -52,7 +43,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
 {
        struct pci_dynid *dynid;
        struct pci_driver *pdrv = to_pci_driver(driver);
-       __u32 vendor=PCI_ANY_ID, device=PCI_ANY_ID, subvendor=PCI_ANY_ID,
+       __u32 vendor, device, subvendor=PCI_ANY_ID,
                subdevice=PCI_ANY_ID, class=0, class_mask=0;
        unsigned long driver_data=0;
        int fields=0;
@@ -61,14 +52,13 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
        fields = sscanf(buf, "%x %x %x %x %x %x %lux",
                        &vendor, &device, &subvendor, &subdevice,
                        &class, &class_mask, &driver_data);
-       if (fields < 0)
+       if (fields < 2)
                return -EINVAL;
 
        dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
        if (!dynid)
                return -ENOMEM;
 
-       INIT_LIST_HEAD(&dynid->node);
        dynid->id.vendor = vendor;
        dynid->id.device = device;
        dynid->id.subvendor = subvendor;
@@ -79,7 +69,7 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
                driver_data : 0UL;
 
        spin_lock(&pdrv->dynids.lock);
-       list_add_tail(&pdrv->dynids.list, &dynid->node);
+       list_add_tail(&dynid->node, &pdrv->dynids.list);
        spin_unlock(&pdrv->dynids.lock);
 
        if (get_driver(&pdrv->driver)) {
@@ -111,17 +101,21 @@ pci_create_newid_file(struct pci_driver *drv)
 {
        int error = 0;
        if (drv->probe != NULL)
-               error = sysfs_create_file(&drv->driver.kobj,
-                                         &driver_attr_new_id.attr);
+               error = driver_create_file(&drv->driver, &driver_attr_new_id);
        return error;
 }
 
+static void pci_remove_newid_file(struct pci_driver *drv)
+{
+       driver_remove_file(&drv->driver, &driver_attr_new_id);
+}
 #else /* !CONFIG_HOTPLUG */
 static inline void pci_free_dynids(struct pci_driver *drv) {}
 static inline int pci_create_newid_file(struct pci_driver *drv)
 {
        return 0;
 }
+static inline void pci_remove_newid_file(struct pci_driver *drv) {}
 #endif
 
 /**
@@ -133,7 +127,7 @@ static inline int pci_create_newid_file(struct pci_driver *drv)
  * system is in its list of supported devices.  Returns the matching
  * pci_device_id structure or %NULL if there is no match.
  *
- * Depreciated, don't use this as it will not catch any dynamic ids
+ * Deprecated, don't use this as it will not catch any dynamic ids
  * that a driver might want to check for.
  */
 const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
@@ -150,8 +144,7 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
 }
 
 /**
- * pci_match_device - Tell if a PCI device structure has a matching
- *                    PCI device id structure
+ * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure
  * @drv: the PCI driver to match against
  * @dev: the PCI device structure to match against
  *
@@ -159,8 +152,8 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
  * system is in its list of supported devices.  Returns the matching
  * pci_device_id structure or %NULL if there is no match.
  */
-const struct pci_device_id *pci_match_device(struct pci_driver *drv,
-                                            struct pci_dev *dev)
+static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
+                                                   struct pci_dev *dev)
 {
        struct pci_dynid *dynid;
 
@@ -325,8 +318,7 @@ static int pci_default_resume(struct pci_dev *pci_dev)
        /* restore the PCI config space */
        pci_restore_state(pci_dev);
        /* if the device was enabled before suspend, reenable */
-       if (atomic_read(&pci_dev->enable_cnt))
-               retval = __pci_enable_device(pci_dev);
+       retval = pci_reenable_device(pci_dev);
        /* if the device was busmaster before the suspend, make it busmaster again */
        if (pci_dev->is_busmaster)
                pci_set_master(pci_dev);
@@ -353,6 +345,8 @@ static int pci_device_resume_early(struct device * dev)
        struct pci_dev * pci_dev = to_pci_dev(dev);
        struct pci_driver * drv = pci_dev->driver;
 
+       pci_fixup_device(pci_fixup_resume, pci_dev);
+
        if (drv && drv->resume_early)
                error = drv->resume_early(pci_dev);
        return error;
@@ -367,61 +361,19 @@ static void pci_device_shutdown(struct device *dev)
                drv->shutdown(pci_dev);
 }
 
-#define kobj_to_pci_driver(obj) container_of(obj, struct device_driver, kobj)
-#define attr_to_driver_attribute(obj) container_of(obj, struct driver_attribute, attr)
-
-static ssize_t
-pci_driver_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
-{
-       struct device_driver *driver = kobj_to_pci_driver(kobj);
-       struct driver_attribute *dattr = attr_to_driver_attribute(attr);
-       ssize_t ret;
-
-       if (!get_driver(driver))
-               return -ENODEV;
-
-       ret = dattr->show ? dattr->show(driver, buf) : -EIO;
-
-       put_driver(driver);
-       return ret;
-}
-
-static ssize_t
-pci_driver_attr_store(struct kobject * kobj, struct attribute *attr,
-                     const char *buf, size_t count)
-{
-       struct device_driver *driver = kobj_to_pci_driver(kobj);
-       struct driver_attribute *dattr = attr_to_driver_attribute(attr);
-       ssize_t ret;
-
-       if (!get_driver(driver))
-               return -ENODEV;
-
-       ret = dattr->store ? dattr->store(driver, buf, count) : -EIO;
-
-       put_driver(driver);
-       return ret;
-}
-
-static struct sysfs_ops pci_driver_sysfs_ops = {
-       .show = pci_driver_attr_show,
-       .store = pci_driver_attr_store,
-};
-static struct kobj_type pci_driver_kobj_type = {
-       .sysfs_ops = &pci_driver_sysfs_ops,
-};
-
 /**
  * __pci_register_driver - register a new pci driver
  * @drv: the driver structure to register
  * @owner: owner module of drv
+ * @mod_name: module name string
  * 
  * Adds the driver structure to the list of registered drivers.
  * Returns a negative value on error, otherwise 0. 
  * If no error occurred, the driver remains registered even if 
  * no device was claimed during registration.
  */
-int __pci_register_driver(struct pci_driver *drv, struct module *owner)
+int __pci_register_driver(struct pci_driver *drv, struct module *owner,
+                         const char *mod_name)
 {
        int error;
 
@@ -429,12 +381,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
        drv->driver.name = drv->name;
        drv->driver.bus = &pci_bus_type;
        drv->driver.owner = owner;
-       drv->driver.kobj.ktype = &pci_driver_kobj_type;
-
-       if (pci_multithread_probe)
-               drv->driver.multithread_probe = pci_multithread_probe;
-       else
-               drv->driver.multithread_probe = drv->multithread_probe;
+       drv->driver.mod_name = mod_name;
 
        spin_lock_init(&drv->dynids.lock);
        INIT_LIST_HEAD(&drv->dynids.list);
@@ -464,6 +411,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
 void
 pci_unregister_driver(struct pci_driver *drv)
 {
+       pci_remove_newid_file(drv);
        driver_unregister(&drv->driver);
        pci_free_dynids(drv);
 }
@@ -548,8 +496,7 @@ void pci_dev_put(struct pci_dev *dev)
 }
 
 #ifndef CONFIG_HOTPLUG
-int pci_uevent(struct device *dev, char **envp, int num_envp,
-              char *buffer, int buffer_size)
+int pci_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
        return -ENODEV;
 }
@@ -577,7 +524,6 @@ static int __init pci_driver_init(void)
 postcore_initcall(pci_driver_init);
 
 EXPORT_SYMBOL(pci_match_id);
-EXPORT_SYMBOL(pci_match_device);
 EXPORT_SYMBOL(__pci_register_driver);
 EXPORT_SYMBOL(pci_unregister_driver);
 EXPORT_SYMBOL(pci_dev_driver);