]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pnp/card.c
[PATCH] nvidiafb: fix unreachable code in nv10GetConfig
[linux-2.6-omap-h63xx.git] / drivers / pnp / card.c
index bd7c966ea2d7f8ee7dfe250bd4e4a26343a6fd72..227600cd636048478126adbb20bc7be1157577b1 100644 (file)
@@ -5,7 +5,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/pnp.h>
@@ -47,7 +46,7 @@ static void card_remove(struct pnp_dev * dev)
 {
        dev->card_link = NULL;
 }
+
 static void card_remove_first(struct pnp_dev * dev)
 {
        struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
@@ -60,29 +59,34 @@ static void card_remove_first(struct pnp_dev * dev)
        card_remove(dev);
 }
 
-static int card_probe(struct pnp_card * card, struct pnp_card_driver * drv)
+static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
 {
-       const struct pnp_card_device_id *id = match_card(drv,card);
-       if (id) {
-               struct pnp_card_link * clink = pnp_alloc(sizeof(struct pnp_card_link));
-               if (!clink)
-                       return 0;
-               clink->card = card;
-               clink->driver = drv;
-               if (drv->probe) {
-                       if (drv->probe(clink, id)>=0)
-                               return 1;
-                       else {
-                               struct pnp_dev * dev;
-                               card_for_each_dev(card, dev) {
-                                       if (dev->card_link == clink)
-                                               pnp_release_card_device(dev);
-                               }
-                               kfree(clink);
-                       }
-               } else
-                       return 1;
+       const struct pnp_card_device_id *id;
+       struct pnp_card_link *clink;
+       struct pnp_dev *dev;
+
+       if (!drv->probe)
+               return 0;
+       id = match_card(drv,card);
+       if (!id)
+               return 0;
+
+       clink = pnp_alloc(sizeof(*clink));
+       if (!clink)
+               return 0;
+       clink->card = card;
+       clink->driver = drv;
+       clink->pm_state = PMSG_ON;
+
+       if (drv->probe(clink, id) >= 0)
+               return 1;
+
+       /* Recovery */
+       card_for_each_dev(card, dev) {
+               if (dev->card_link == clink)
+                       pnp_release_card_device(dev);
        }
+       kfree(clink);
        return 0;
 }
 
@@ -302,13 +306,11 @@ found:
        down_write(&dev->dev.bus->subsys.rwsem);
        dev->card_link = clink;
        dev->dev.driver = &drv->link.driver;
-       if (drv->link.driver.probe) {
-               if (drv->link.driver.probe(&dev->dev)) {
-                       dev->dev.driver = NULL;
-                       dev->card_link = NULL;
-                       up_write(&dev->dev.bus->subsys.rwsem);
-                       return NULL;
-               }
+       if (pnp_bus_type.probe(&dev->dev)) {
+               dev->dev.driver = NULL;
+               dev->card_link = NULL;
+               up_write(&dev->dev.bus->subsys.rwsem);
+               return NULL;
        }
        device_bind_driver(&dev->dev);
        up_write(&dev->dev.bus->subsys.rwsem);
@@ -333,6 +335,28 @@ void pnp_release_card_device(struct pnp_dev * dev)
        up_write(&dev->dev.bus->subsys.rwsem);
 }
 
+/*
+ * suspend/resume callbacks
+ */
+static int card_suspend(struct pnp_dev *dev, pm_message_t state)
+{
+       struct pnp_card_link *link = dev->card_link;
+       if (link->pm_state.event == state.event)
+               return 0;
+       link->pm_state = state;
+       return link->driver->suspend(link, state);
+}
+
+static int card_resume(struct pnp_dev *dev)
+{
+       struct pnp_card_link *link = dev->card_link;
+       if (link->pm_state.event == PM_EVENT_ON)
+               return 0;
+       link->pm_state = PMSG_ON;
+       link->driver->resume(link);
+       return 0;
+}
+
 /**
  * pnp_register_card_driver - registers a PnP card driver with the PnP Layer
  * @drv: pointer to the driver to register
@@ -340,7 +364,7 @@ void pnp_release_card_device(struct pnp_dev * dev)
 
 int pnp_register_card_driver(struct pnp_card_driver * drv)
 {
-       int count = 0;
+       int error;
        struct list_head *pos, *temp;
 
        drv->link.name = drv->name;
@@ -348,17 +372,22 @@ int pnp_register_card_driver(struct pnp_card_driver * drv)
        drv->link.flags = drv->flags;
        drv->link.probe = NULL;
        drv->link.remove = &card_remove_first;
+       drv->link.suspend = drv->suspend ? card_suspend : NULL;
+       drv->link.resume = drv->resume ? card_resume : NULL;
+
+       error = pnp_register_driver(&drv->link);
+       if (error < 0)
+               return error;
 
        spin_lock(&pnp_lock);
        list_add_tail(&drv->global_list, &pnp_card_drivers);
        spin_unlock(&pnp_lock);
-       pnp_register_driver(&drv->link);
 
        list_for_each_safe(pos,temp,&pnp_cards){
                struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
-               count += card_probe(card,drv);
+               card_probe(card,drv);
        }
-       return count;
+       return 0;
 }
 
 /**