]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/host/sl811_cs.c
[PATCH] pcmcia: remove dev_list from drivers
[linux-2.6-omap-h63xx.git] / drivers / usb / host / sl811_cs.c
index 38aebe361ca140cb8e0255a474a0c5c87144dd8c..439709670d0bccac3360908ff0e243434f6088f1 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/string.h>
 #include <linux/timer.h>
 #include <linux/ioport.h>
+#include <linux/platform_device.h>
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
@@ -37,7 +38,7 @@ MODULE_LICENSE("GPL");
 /* MACROS                                                             */
 /*====================================================================*/
 
-#if defined(DEBUG) || defined(CONFIG_USB_DEBUG) || defined(PCMCIA_DEBUG)
+#if defined(DEBUG) || defined(PCMCIA_DEBUG)
 
 static int pc_debug = 0;
 module_param(pc_debug, int, 0644);
@@ -65,13 +66,13 @@ module_param(pc_debug, int, 0644);
 
 static const char driver_name[DEV_NAME_LEN]  = "sl811_cs";
 
-static dev_link_t *dev_list = NULL;
-
 typedef struct local_info_t {
        dev_link_t              link;
        dev_node_t              node;
 } local_info_t;
 
+static void sl811_cs_release(dev_link_t * link);
+
 /*====================================================================*/
 
 static void release_platform_dev(struct device * dev)
@@ -128,7 +129,8 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq)
        resources[2].end   = base_addr + 1;
 
        /* The driver core will probe for us.  We know sl811-hcd has been
-        * initialized already because of the link order dependency.
+        * initialized already because of the link order dependency created
+        * by referencing "sl811h_driver".
         */
        platform_dev.name = sl811h_driver.name;
        return platform_device_register(&platform_dev);
@@ -136,26 +138,16 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq)
 
 /*====================================================================*/
 
-static void sl811_cs_detach(dev_link_t *link)
+static void sl811_cs_detach(struct pcmcia_device *p_dev)
 {
-       dev_link_t **linkp;
+       dev_link_t *link = dev_to_instance(p_dev);
 
        DBG(0, "sl811_cs_detach(0x%p)\n", link);
 
-       /* Locate device structure */
-       for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) {
-               if (*linkp == link)
-                       break;
-       }
-       if (*linkp == NULL)
-               return;
-
-       /* Break the link with Card Services */
-       if (link->handle)
-               pcmcia_deregister_client(link->handle);
+       link->state &= ~DEV_PRESENT;
+       if (link->state & DEV_CONFIG)
+               sl811_cs_release(link);
 
-       /* Unlink device structure, and free it */
-       *linkp = link->next;
        /* This points to the parent local_info_t struct */
        kfree(link->priv);
 }
@@ -165,13 +157,6 @@ static void sl811_cs_release(dev_link_t * link)
 
        DBG(0, "sl811_cs_release(0x%p)\n", link);
 
-       if (link->open) {
-               DBG(1, "sl811_cs: release postponed, '%s' still open\n",
-                   link->dev->dev_name);
-               link->state |= DEV_STALE_CONFIG;
-               return;
-       }
-
        /* Unlink the device chain */
        link->dev = NULL;
 
@@ -182,9 +167,6 @@ static void sl811_cs_release(dev_link_t * link)
        if (link->irq.AssignedIRQ)
                pcmcia_release_irq(link->handle, &link->irq);
        link->state &= ~DEV_CONFIG;
-
-       if (link->state & DEV_STALE_LINK)
-               sl811_cs_detach(link);
 }
 
 static void sl811_cs_config(dev_link_t *link)
@@ -321,6 +303,28 @@ cs_failed:
        }
 }
 
+static int sl811_suspend(struct pcmcia_device *dev)
+{
+       dev_link_t *link = dev_to_instance(dev);
+
+       link->state |= DEV_SUSPEND;
+       if (link->state & DEV_CONFIG)
+               pcmcia_release_configuration(link->handle);
+
+       return 0;
+}
+
+static int sl811_resume(struct pcmcia_device *dev)
+{
+       dev_link_t *link = dev_to_instance(dev);
+
+       link->state &= ~DEV_SUSPEND;
+       if (link->state & DEV_CONFIG)
+               pcmcia_request_configuration(link->handle, &link->conf);
+
+       return 0;
+}
+
 static int
 sl811_cs_event(event_t event, int priority, event_callback_args_t *args)
 {
@@ -329,33 +333,10 @@ sl811_cs_event(event_t event, int priority, event_callback_args_t *args)
        DBG(1, "sl811_cs_event(0x%06x)\n", event);
 
        switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG)
-                       sl811_cs_release(link);
-               break;
-
        case CS_EVENT_CARD_INSERTION:
                link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
                sl811_cs_config(link);
                break;
-
-       case CS_EVENT_PM_SUSPEND:
-               link->state |= DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               if (link->state & DEV_CONFIG)
-                       pcmcia_release_configuration(link->handle);
-               break;
-
-       case CS_EVENT_PM_RESUME:
-               link->state &= ~DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               if (link->state & DEV_CONFIG)
-                       pcmcia_request_configuration(link->handle, &link->conf);
-               DBG(0, "reset sl811-hcd here?\n");
-               break;
        }
        return 0;
 }
@@ -384,8 +365,7 @@ static dev_link_t *sl811_cs_attach(void)
        link->conf.IntType = INT_MEMORY_AND_IO;
 
        /* Register with Card Services */
-       link->next = dev_list;
-       dev_list = link;
+       link->next = NULL;
        client_reg.dev_info = (dev_info_t *) &driver_name;
        client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
        client_reg.Version = 0x0210;
@@ -393,7 +373,7 @@ static dev_link_t *sl811_cs_attach(void)
        ret = pcmcia_register_client(&link->handle, &client_reg);
        if (ret != CS_SUCCESS) {
                cs_error(link->handle, RegisterClient, ret);
-               sl811_cs_detach(link);
+               sl811_cs_detach(link->handle);
                return NULL;
        }
 
@@ -413,8 +393,10 @@ static struct pcmcia_driver sl811_cs_driver = {
        },
        .attach         = sl811_cs_attach,
        .event          = sl811_cs_event,
-       .detach         = sl811_cs_detach,
+       .remove         = sl811_cs_detach,
        .id_table       = sl811_ids,
+       .suspend        = sl811_suspend,
+       .resume         = sl811_resume,
 };
 
 /*====================================================================*/