]> git.hungrycats.org Git - linux/commitdiff
[PATCH] USB: cdc-acm: add support for new tty tiocmget and tiocmset functions.
authorGreg Kroah-Hartman <greg@kroah.com>
Wed, 23 Apr 2003 10:35:11 +0000 (03:35 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 23 Apr 2003 10:35:11 +0000 (03:35 -0700)
drivers/usb/class/cdc-acm.c

index 99233f6f06efc927b188275c82b538d722985cbc..e205b5ad008903496d0430b14f1f61f938ac1fff 100644 (file)
@@ -432,43 +432,47 @@ static void acm_tty_break_ctl(struct tty_struct *tty, int state)
                dbg("send break failed");
 }
 
-static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
+static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
 {
        struct acm *acm = tty->driver_data;
-       unsigned int mask, newctrl;
-
-       if (!ACM_READY(acm)) return -EINVAL;
 
-       switch (cmd) {
+       if (!ACM_READY(acm))
+               return -EINVAL;
+
+       return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
+              (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
+              (acm->ctrlin  & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
+              (acm->ctrlin  & ACM_CTRL_RI  ? TIOCM_RI  : 0) |
+              (acm->ctrlin  & ACM_CTRL_DCD ? TIOCM_CD  : 0) |
+              TIOCM_CTS;
+}
 
-               case TIOCMGET:
+static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
+                           unsigned int set, unsigned int clear)
+{
+       struct acm *acm = tty->driver_data;
+       unsigned int newctrl;
 
-                       return put_user((acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
-                               (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
-                               (acm->ctrlin  & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
-                               (acm->ctrlin  & ACM_CTRL_RI  ? TIOCM_RI  : 0) |
-                               (acm->ctrlin  & ACM_CTRL_DCD ? TIOCM_CD  : 0) |
-                                TIOCM_CTS, (unsigned long *) arg);
+       if (!ACM_READY(acm))
+               return -EINVAL;
 
-               case TIOCMSET:
-               case TIOCMBIS:
-               case TIOCMBIC:
+       newctrl = acm->ctrlout;
+       set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
+       clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
 
-                       if (get_user(mask, (unsigned long *) arg))
-                               return -EFAULT;
+       newctrl = (newctrl & ~clear) | set;
 
-                       newctrl = acm->ctrlout;
-                       mask = (mask & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (mask & TIOCM_RTS ? ACM_CTRL_RTS : 0);
+       if (acm->ctrlout == newctrl)
+               return 0;
+       return acm_set_control(acm, acm->ctrlout = newctrl);
+}
 
-                       switch (cmd) {
-                               case TIOCMSET: newctrl  =  mask; break;
-                               case TIOCMBIS: newctrl |=  mask; break;
-                               case TIOCMBIC: newctrl &= ~mask; break;
-                       }
+static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct acm *acm = tty->driver_data;
 
-                       if (acm->ctrlout == newctrl) return 0;
-                       return acm_set_control(acm, acm->ctrlout = newctrl);
-       }
+       if (!ACM_READY(acm))
+               return -EINVAL;
 
        return -ENOIOCTLCMD;
 }
@@ -750,7 +754,9 @@ static struct tty_driver acm_tty_driver = {
        .unthrottle =           acm_tty_unthrottle,
        .chars_in_buffer =      acm_tty_chars_in_buffer,
        .break_ctl =            acm_tty_break_ctl,
-       .set_termios =          acm_tty_set_termios
+       .set_termios =          acm_tty_set_termios,
+       .tiocmget =             acm_tty_tiocmget,
+       .tiocmset =             acm_tty_tiocmset,
 };
 
 /*