[PATCH] pcmcia: new suspend core
[powerpc.git] / drivers / char / pcmcia / cm4000_cs.c
index ef011ef..05e9305 100644 (file)
@@ -1444,6 +1444,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
        dev_link_t *link;
        int size;
        int rc;
+       void __user *argp = (void __user *)arg;
 #ifdef PCMCIA_DEBUG
        char *ioctl_names[CM_IOC_MAXNR + 1] = {
                [_IOC_NR(CM_IOCGSTATUS)] "CM_IOCGSTATUS",
@@ -1481,11 +1482,11 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
              _IOC_DIR(cmd), _IOC_READ, _IOC_WRITE, size, cmd);
 
        if (_IOC_DIR(cmd) & _IOC_READ) {
-               if (!access_ok(VERIFY_WRITE, (void *)arg, size))
+               if (!access_ok(VERIFY_WRITE, argp, size))
                        return -EFAULT;
        }
        if (_IOC_DIR(cmd) & _IOC_WRITE) {
-               if (!access_ok(VERIFY_READ, (void *)arg, size))
+               if (!access_ok(VERIFY_READ, argp, size))
                        return -EFAULT;
        }
 
@@ -1506,14 +1507,14 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                                status |= CM_NO_READER;
                        if (test_bit(IS_BAD_CARD, &dev->flags))
                                status |= CM_BAD_CARD;
-                       if (copy_to_user((int *)arg, &status, sizeof(int)))
+                       if (copy_to_user(argp, &status, sizeof(int)))
                                return -EFAULT;
                }
                return 0;
        case CM_IOCGATR:
                DEBUGP(4, dev, "... in CM_IOCGATR\n");
                {
-                       struct atreq *atreq = (struct atreq *) arg;
+                       struct atreq __user *atreq = argp;
                        int tmp;
                        /* allow nonblocking io and being interrupted */
                        if (wait_event_interruptible
@@ -1597,7 +1598,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                {
                        struct ptsreq krnptsreq;
 
-                       if (copy_from_user(&krnptsreq, (struct ptsreq *) arg,
+                       if (copy_from_user(&krnptsreq, argp,
                                           sizeof(struct ptsreq)))
                                return -EFAULT;
 
@@ -1641,7 +1642,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                        int old_pc_debug = 0;
 
                        old_pc_debug = pc_debug;
-                       if (copy_from_user(&pc_debug, (int *)arg, sizeof(int)))
+                       if (copy_from_user(&pc_debug, argp, sizeof(int)))
                                return -EFAULT;
 
                        if (old_pc_debug != pc_debug)
@@ -1892,33 +1893,6 @@ static int cm4000_event(event_t event, int priority,
                link->state &= ~DEV_PRESENT;
                stop_monitor(dev);
                break;
-       case CS_EVENT_PM_SUSPEND:
-               DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND "
-                     "(fall-through to CS_EVENT_RESET_PHYSICAL)\n");
-               link->state |= DEV_SUSPEND;
-               /* fall-through */
-       case CS_EVENT_RESET_PHYSICAL:
-               DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n");
-               if (link->state & DEV_CONFIG) {
-                       DEBUGP(5, dev, "ReleaseConfiguration\n");
-                       pcmcia_release_configuration(link->handle);
-               }
-               stop_monitor(dev);
-               break;
-       case CS_EVENT_PM_RESUME:
-               DEBUGP(5, dev, "CS_EVENT_PM_RESUME "
-                     "(fall-through to CS_EVENT_CARD_RESET)\n");
-               link->state &= ~DEV_SUSPEND;
-               /* fall-through */
-       case CS_EVENT_CARD_RESET:
-               DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n");
-               if ((link->state & DEV_CONFIG)) {
-                       DEBUGP(5, dev, "RequestConfiguration\n");
-                       pcmcia_request_configuration(link->handle, &link->conf);
-               }
-               if (link->open)
-                       start_monitor(dev);
-               break;
        default:
                DEBUGP(5, dev, "unknown event %.2x\n", event);
                break;
@@ -1927,6 +1901,38 @@ static int cm4000_event(event_t event, int priority,
        return CS_SUCCESS;
 }
 
+static int cm4000_suspend(struct pcmcia_device *p_dev)
+{
+       dev_link_t *link = dev_to_instance(p_dev);
+       struct cm4000_dev *dev;
+
+       dev = link->priv;
+
+       link->state |= DEV_SUSPEND;
+       if (link->state & DEV_CONFIG)
+               pcmcia_release_configuration(link->handle);
+       stop_monitor(dev);
+
+       return 0;
+}
+
+static int cm4000_resume(struct pcmcia_device *p_dev)
+{
+       dev_link_t *link = dev_to_instance(p_dev);
+       struct cm4000_dev *dev;
+
+       dev = link->priv;
+
+       link->state &= ~DEV_SUSPEND;
+       if (link->state & DEV_CONFIG)
+               pcmcia_request_configuration(link->handle, &link->conf);
+
+       if (link->open)
+               start_monitor(dev);
+
+       return 0;
+}
+
 static void cm4000_release(dev_link_t *link)
 {
        cmm_cm4000_release(link->priv); /* delay release until device closed */
@@ -2043,6 +2049,8 @@ static struct pcmcia_driver cm4000_driver = {
                },
        .attach   = cm4000_attach,
        .detach   = cm4000_detach,
+       .suspend  = cm4000_suspend,
+       .resume   = cm4000_resume,
        .event    = cm4000_event,
        .id_table = cm4000_ids,
 };