[PATCH] pcmcia: remove dev_link_t and client_handle_t indirection
[powerpc.git] / drivers / pcmcia / ds.c
index 211aa84..e8fe544 100644 (file)
@@ -10,7 +10,7 @@
  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  *
  * (C) 1999            David A. Hinds
- * (C) 2003 - 2005     Dominik Brodowski
+ * (C) 2003 - 2006     Dominik Brodowski
  */
 
 #include <linux/kernel.h>
@@ -390,7 +390,7 @@ static int pcmcia_device_probe(struct device * dev)
                goto put_dev;
        }
 
-       p_dev->state &= ~CLIENT_UNBOUND;
+       p_dev->p_state &= ~CLIENT_UNBOUND;
 
        ret = p_drv->probe(p_dev);
        if (ret)
@@ -433,17 +433,17 @@ static int pcmcia_device_remove(struct device * dev)
                p_drv->remove(p_dev);
 
        /* check for proper unloading */
-       if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED))
+       if (p_dev->p_state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED))
                printk(KERN_INFO "pcmcia: driver %s did not release config properly\n",
                       p_drv->drv.name);
 
        for (i = 0; i < MAX_WIN; i++)
-               if (p_dev->state & CLIENT_WIN_REQ(i))
+               if (p_dev->p_state & CLIENT_WIN_REQ(i))
                        printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n",
                               p_drv->drv.name);
 
        /* references from pcmcia_probe_device */
-       p_dev->state = CLIENT_UNBOUND;
+       p_dev->p_state = CLIENT_UNBOUND;
        pcmcia_put_dev(p_dev);
        module_put(p_drv->owner);
 
@@ -472,7 +472,7 @@ static void pcmcia_card_remove(struct pcmcia_socket *s)
                }
                p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
                list_del(&p_dev->socket_device_list);
-               p_dev->state |= CLIENT_STALE;
+               p_dev->p_state |= CLIENT_STALE;
                spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 
                device_unregister(&p_dev->dev);
@@ -588,8 +588,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
        p_dev->socket = s;
        p_dev->device_no = (s->device_count++);
        p_dev->func   = function;
-       if (s->functions < function)
-               s->functions = function;
+       if (s->functions <= function)
+               s->functions = function + 1;
 
        p_dev->dev.bus = &pcmcia_bus_type;
        p_dev->dev.parent = s->dev.dev;
@@ -602,7 +602,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
        sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
 
        /* compat */
-       p_dev->state = CLIENT_UNBOUND;
+       p_dev->p_state = CLIENT_UNBOUND;
 
 
        spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
@@ -1030,12 +1030,20 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
        struct pcmcia_driver *p_drv = NULL;
+       int ret;
 
        if (dev->driver)
                p_drv = to_pcmcia_drv(dev->driver);
 
-       if (p_drv && p_drv->suspend)
-               return p_drv->suspend(p_dev);
+       if (p_drv && p_drv->suspend) {
+               ret = p_drv->suspend(p_dev);
+               if (ret)
+                       return ret;
+               p_dev->state |= DEV_SUSPEND;
+                       if ((p_dev->state & DEV_CONFIG) &&
+                           !(p_dev->state & DEV_SUSPEND_NORELEASE))
+                               pcmcia_release_configuration(p_dev);
+       }
 
        return 0;
 }
@@ -1045,12 +1053,22 @@ static int pcmcia_dev_resume(struct device * dev)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
         struct pcmcia_driver *p_drv = NULL;
+       int ret;
 
        if (dev->driver)
                p_drv = to_pcmcia_drv(dev->driver);
 
-       if (p_drv && p_drv->resume)
+       if (p_drv && p_drv->resume) {
+               p_dev->state &= ~DEV_SUSPEND;
+                       if ((p_dev->state & DEV_CONFIG) &&
+                           !(p_dev->state & DEV_SUSPEND_NORELEASE)){
+                               ret = pcmcia_request_configuration(p_dev,
+                                                &p_dev->conf);
+                               if (ret)
+                                       return ret;
+                       }
                return p_drv->resume(p_dev);
+       }
 
        return 0;
 }