PNP: convert encoders to use pnp_get_resource(), not pnp_resource_table
[safe/jmp/linux-2.6] / drivers / pnp / core.c
index 61066fd..cf37701 100644 (file)
@@ -52,9 +52,6 @@ int pnp_register_protocol(struct pnp_protocol *protocol)
        int nodenum;
        struct list_head *pos;
 
-       if (!protocol)
-               return -EINVAL;
-
        INIT_LIST_HEAD(&protocol->devices);
        INIT_LIST_HEAD(&protocol->cards);
        nodenum = 0;
@@ -94,8 +91,6 @@ static void pnp_free_ids(struct pnp_dev *dev)
        struct pnp_id *id;
        struct pnp_id *next;
 
-       if (!dev)
-               return;
        id = dev->id;
        while (id) {
                next = id->next;
@@ -114,15 +109,42 @@ static void pnp_release_device(struct device *dmdev)
        kfree(dev);
 }
 
-int __pnp_add_device(struct pnp_dev *dev)
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
 {
-       int ret;
+       struct pnp_dev *dev;
+       struct pnp_id *dev_id;
 
-       pnp_fixup_device(dev);
+       dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+       if (!dev)
+               return NULL;
+
+       dev->protocol = protocol;
+       dev->number = id;
+       dev->dma_mask = DMA_24BIT_MASK;
+
+       dev->dev.parent = &dev->protocol->dev;
        dev->dev.bus = &pnp_bus_type;
        dev->dev.dma_mask = &dev->dma_mask;
-       dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
+       dev->dev.coherent_dma_mask = dev->dma_mask;
        dev->dev.release = &pnp_release_device;
+
+       sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
+               dev->number);
+
+       dev_id = pnp_add_id(dev, pnpid);
+       if (!dev_id) {
+               kfree(dev);
+               return NULL;
+       }
+
+       return dev;
+}
+
+int __pnp_add_device(struct pnp_dev *dev)
+{
+       int ret;
+
+       pnp_fixup_device(dev);
        dev->status = PNP_READY;
        spin_lock(&pnp_lock);
        list_add_tail(&dev->global_list, &pnp_global);
@@ -130,9 +152,11 @@ int __pnp_add_device(struct pnp_dev *dev)
        spin_unlock(&pnp_lock);
 
        ret = device_register(&dev->dev);
-       if (ret == 0)
-               pnp_interface_attach_device(dev);
-       return ret;
+       if (ret)
+               return ret;
+
+       pnp_interface_attach_device(dev);
+       return 0;
 }
 
 /*
@@ -143,12 +167,27 @@ int __pnp_add_device(struct pnp_dev *dev)
  */
 int pnp_add_device(struct pnp_dev *dev)
 {
-       if (!dev || !dev->protocol || dev->card)
+       int ret;
+
+       if (dev->card)
                return -EINVAL;
-       dev->dev.parent = &dev->protocol->dev;
-       sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
-               dev->number);
-       return __pnp_add_device(dev);
+
+       ret = __pnp_add_device(dev);
+       if (ret)
+               return ret;
+
+#ifdef CONFIG_PNP_DEBUG
+       {
+               struct pnp_id *id;
+
+               dev_printk(KERN_DEBUG, &dev->dev, "%s device, IDs",
+                       dev->protocol->name);
+               for (id = dev->id; id; id = id->next)
+                       printk(" %s", id->id);
+               printk(" (%s)\n", dev->active ? "active" : "disabled");
+       }
+#endif
+       return 0;
 }
 
 void __pnp_remove_device(struct pnp_dev *dev)