const: struct nla_policy
[safe/jmp/linux-2.6] / drivers / pnp / card.c
index b6a4f02..4a651f6 100644 (file)
@@ -5,8 +5,10 @@
  */
 
 #include <linux/module.h>
+#include <linux/ctype.h>
 #include <linux/slab.h>
 #include <linux/pnp.h>
+#include <linux/dma-mapping.h>
 #include "base.h"
 
 LIST_HEAD(pnp_cards);
@@ -25,13 +27,13 @@ static const struct pnp_card_device_id *match_card(struct pnp_card_driver *drv,
                                int found;
                                struct pnp_dev *dev;
 
-                               if (i == PNP_MAX_DEVICES
-                                   || !*drv_id->devs[i].id)
+                               if (i == PNP_MAX_DEVICES ||
+                                   !*drv_id->devs[i].id)
                                        return drv_id;
                                found = 0;
                                card_for_each_dev(card, dev) {
-                                       if (compare_pnp_id
-                                           (dev->id, drv_id->devs[i].id)) {
+                                       if (compare_pnp_id(dev->id,
+                                                  drv_id->devs[i].id)) {
                                                found = 1;
                                                break;
                                        }
@@ -100,23 +102,33 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
  * @id: pointer to a pnp_id structure
  * @card: pointer to the desired card
  */
-int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card)
+static struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id)
 {
-       struct pnp_id *ptr;
-
-       if (!id)
-               return -EINVAL;
-       if (!card)
-               return -EINVAL;
-       id->next = NULL;
+       struct pnp_id *dev_id, *ptr;
+
+       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+       if (!dev_id)
+               return NULL;
+
+       dev_id->id[0] = id[0];
+       dev_id->id[1] = id[1];
+       dev_id->id[2] = id[2];
+       dev_id->id[3] = tolower(id[3]);
+       dev_id->id[4] = tolower(id[4]);
+       dev_id->id[5] = tolower(id[5]);
+       dev_id->id[6] = tolower(id[6]);
+       dev_id->id[7] = '\0';
+
+       dev_id->next = NULL;
        ptr = card->id;
        while (ptr && ptr->next)
                ptr = ptr->next;
        if (ptr)
-               ptr->next = id;
+               ptr->next = dev_id;
        else
-               card->id = id;
-       return 0;
+               card->id = dev_id;
+
+       return dev_id;
 }
 
 static void pnp_free_card_ids(struct pnp_card *card)
@@ -124,8 +136,6 @@ static void pnp_free_card_ids(struct pnp_card *card)
        struct pnp_id *id;
        struct pnp_id *next;
 
-       if (!card)
-               return;
        id = card->id;
        while (id) {
                next = id->next;
@@ -142,6 +152,33 @@ static void pnp_release_card(struct device *dmdev)
        kfree(card);
 }
 
+struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
+{
+       struct pnp_card *card;
+       struct pnp_id *dev_id;
+
+       card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
+       if (!card)
+               return NULL;
+
+       card->protocol = protocol;
+       card->number = id;
+
+       card->dev.parent = &card->protocol->dev;
+       dev_set_name(&card->dev, "%02x:%02x", card->protocol->number, card->number);
+
+       card->dev.coherent_dma_mask = DMA_BIT_MASK(24);
+       card->dev.dma_mask = &card->dev.coherent_dma_mask;
+
+       dev_id = pnp_add_card_id(card, pnpid);
+       if (!dev_id) {
+               kfree(card);
+               return NULL;
+       }
+
+       return card;
+}
+
 static ssize_t pnp_show_card_name(struct device *dmdev,
                                  struct device_attribute *attr, char *buf)
 {
@@ -183,7 +220,7 @@ static int pnp_interface_attach_card(struct pnp_card *card)
 
        return 0;
 
-      err_name:
+err_name:
        device_remove_file(&card->dev, &dev_attr_name);
        return rc;
 }
@@ -197,42 +234,36 @@ int pnp_add_card(struct pnp_card *card)
        int error;
        struct list_head *pos, *temp;
 
-       if (!card || !card->protocol)
-               return -EINVAL;
-
-       sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
-               card->number);
-       card->dev.parent = &card->protocol->dev;
        card->dev.bus = NULL;
        card->dev.release = &pnp_release_card;
        error = device_register(&card->dev);
+       if (error) {
+               dev_err(&card->dev, "could not register (err=%d)\n", error);
+               return error;
+       }
 
-       if (error == 0) {
-               pnp_interface_attach_card(card);
-               spin_lock(&pnp_lock);
-               list_add_tail(&card->global_list, &pnp_cards);
-               list_add_tail(&card->protocol_list, &card->protocol->cards);
-               spin_unlock(&pnp_lock);
-
-               /* we wait until now to add devices in order to ensure the drivers
-                * will be able to use all of the related devices on the card
-                * without waiting any unresonable length of time */
-               list_for_each(pos, &card->devices) {
-                       struct pnp_dev *dev = card_to_pnp_dev(pos);
-                       __pnp_add_device(dev);
-               }
+       pnp_interface_attach_card(card);
+       spin_lock(&pnp_lock);
+       list_add_tail(&card->global_list, &pnp_cards);
+       list_add_tail(&card->protocol_list, &card->protocol->cards);
+       spin_unlock(&pnp_lock);
 
-               /* match with card drivers */
-               list_for_each_safe(pos, temp, &pnp_card_drivers) {
-                       struct pnp_card_driver *drv =
-                           list_entry(pos, struct pnp_card_driver,
-                                      global_list);
-                       card_probe(card, drv);
-               }
-       } else
-               pnp_err("sysfs failure, card '%s' will be unavailable",
-                       card->dev.bus_id);
-       return error;
+       /* we wait until now to add devices in order to ensure the drivers
+        * will be able to use all of the related devices on the card
+        * without waiting an unreasonable length of time */
+       list_for_each(pos, &card->devices) {
+               struct pnp_dev *dev = card_to_pnp_dev(pos);
+               __pnp_add_device(dev);
+       }
+
+       /* match with card drivers */
+       list_for_each_safe(pos, temp, &pnp_card_drivers) {
+               struct pnp_card_driver *drv =
+                   list_entry(pos, struct pnp_card_driver,
+                              global_list);
+               card_probe(card, drv);
+       }
+       return 0;
 }
 
 /**
@@ -243,8 +274,6 @@ void pnp_remove_card(struct pnp_card *card)
 {
        struct list_head *pos, *temp;
 
-       if (!card)
-               return;
        device_unregister(&card->dev);
        spin_lock(&pnp_lock);
        list_del(&card->global_list);
@@ -263,12 +292,10 @@ void pnp_remove_card(struct pnp_card *card)
  */
 int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev)
 {
-       if (!card || !dev || !dev->protocol)
-               return -EINVAL;
        dev->dev.parent = &card->dev;
        dev->card_link = NULL;
-       snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x",
-                dev->protocol->number, card->number, dev->number);
+       dev_set_name(&dev->dev, "%02x:%02x.%02x",
+                    dev->protocol->number, card->number, dev->number);
        spin_lock(&pnp_lock);
        dev->card = card;
        list_add_tail(&dev->card_list, &card->devices);
@@ -304,14 +331,15 @@ struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
        struct pnp_card *card;
 
        if (!clink || !id)
-               goto done;
+               return NULL;
+
        card = clink->card;
        drv = clink->driver;
        if (!from) {
                pos = card->devices.next;
        } else {
                if (from->card != card)
-                       goto done;
+                       return NULL;
                pos = from->card_list.next;
        }
        while (pos != &card->devices) {
@@ -321,10 +349,9 @@ struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
                pos = pos->next;
        }
 
-      done:
        return NULL;
 
-      found:
+found:
        dev->card_link = clink;
        dev->dev.driver = &drv->link.driver;
        if (pnp_bus_type.probe(&dev->dev))
@@ -334,7 +361,7 @@ struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
 
        return dev;
 
-      err_out:
+err_out:
        dev->dev.driver = NULL;
        dev->card_link = NULL;
        return NULL;
@@ -348,8 +375,6 @@ void pnp_release_card_device(struct pnp_dev *dev)
 {
        struct pnp_card_driver *drv = dev->card_link->driver;
 
-       if (!drv)
-               return;
        drv->link.remove = &card_remove;
        device_release_driver(&dev->dev);
        drv->link.remove = &card_remove_first;