Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
[pandora-kernel.git] / drivers / isdn / gigaset / interface.c
index ac408ac..af195b0 100644 (file)
@@ -28,12 +28,11 @@ static int if_lock(struct cardstate *cs, int *arg)
                return -EINVAL;
 
        if (cmd < 0) {
-               *arg = atomic_read(&cs->mstate) == MS_LOCKED; //FIXME remove?
+               *arg = cs->mstate == MS_LOCKED;
                return 0;
        }
 
-       if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
-           && atomic_read(&cs->connected)) {
+       if (!cmd && cs->mstate == MS_LOCKED && cs->connected) {
                cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
                cs->ops->baud_rate(cs, B115200);
                cs->ops->set_line_ctrl(cs, CS8);
@@ -104,9 +103,14 @@ static int if_config(struct cardstate *cs, int *arg)
        if (*arg != 1)
                return -EINVAL;
 
-       if (atomic_read(&cs->mstate) != MS_LOCKED)
+       if (cs->mstate != MS_LOCKED)
                return -EBUSY;
 
+       if (!cs->connected) {
+               err("not connected!");
+               return -ENODEV;
+       }
+
        *arg = 0;
        return gigaset_enterconfigmode(cs);
 }
@@ -122,14 +126,14 @@ static int  if_write_room(struct tty_struct *tty);
 static int  if_chars_in_buffer(struct tty_struct *tty);
 static void if_throttle(struct tty_struct *tty);
 static void if_unthrottle(struct tty_struct *tty);
-static void if_set_termios(struct tty_struct *tty, struct termios *old);
+static void if_set_termios(struct tty_struct *tty, struct ktermios *old);
 static int  if_tiocmget(struct tty_struct *tty, struct file *file);
 static int  if_tiocmset(struct tty_struct *tty, struct file *file,
                        unsigned int set, unsigned int clear);
 static int  if_write(struct tty_struct *tty,
                     const unsigned char *buf, int count);
 
-static struct tty_operations if_ops = {
+static const struct tty_operations if_ops = {
        .open =                 if_open,
        .close =                if_close,
        .ioctl =                if_ioctl,
@@ -157,7 +161,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
        tty->driver_data = NULL;
 
        cs = gigaset_get_cs_by_tty(tty);
-       if (!cs)
+       if (!cs || !try_module_get(cs->driver->owner))
                return -ENODEV;
 
        if (mutex_lock_interruptible(&cs->mutex))
@@ -203,6 +207,8 @@ static void if_close(struct tty_struct *tty, struct file *filp)
        }
 
        mutex_unlock(&cs->mutex);
+
+       module_put(cs->driver->owner);
 }
 
 static int if_ioctl(struct tty_struct *tty, struct file *file,
@@ -246,7 +252,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
                        break;
                case GIGASET_BRKCHARS:
                        //FIXME test if MS_LOCKED
-                       if (!atomic_read(&cs->connected)) {
+                       if (!cs->connected) {
                                gig_dbg(DEBUG_ANY,
                                    "can't communicate with unplugged device");
                                retval = -ENODEV;
@@ -327,7 +333,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
        if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
-       if (!atomic_read(&cs->connected)) {
+       if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
                retval = -ENODEV;
        } else {
@@ -359,10 +365,10 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
                retval = -EBUSY;
-       } else if (!atomic_read(&cs->connected)) {
+       } else if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't write to unplugged device");
                retval = -EBUSY; //FIXME
        } else {
@@ -393,10 +399,10 @@ static int if_write_room(struct tty_struct *tty)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
-               retval = -EBUSY; //FIXME
-       } else if (!atomic_read(&cs->connected)) {
+               retval = -EBUSY;
+       } else if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't write to unplugged device");
                retval = -EBUSY; //FIXME
        } else
@@ -425,10 +431,10 @@ static int if_chars_in_buffer(struct tty_struct *tty)
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
-       else if (atomic_read(&cs->mstate) != MS_LOCKED) {
+       else if (cs->mstate != MS_LOCKED) {
                warn("can't write to unlocked device");
                retval = -EBUSY;
-       } else if (!atomic_read(&cs->connected)) {
+       } else if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't write to unplugged device");
                retval = -EBUSY; //FIXME
        } else
@@ -485,7 +491,7 @@ static void if_unthrottle(struct tty_struct *tty)
        mutex_unlock(&cs->mutex);
 }
 
-static void if_set_termios(struct tty_struct *tty, struct termios *old)
+static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
 {
        struct cardstate *cs;
        unsigned int iflag;
@@ -508,7 +514,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
                goto out;
        }
 
-       if (!atomic_read(&cs->connected)) {
+       if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
                goto out;
        }
@@ -594,19 +600,9 @@ out:
 static void if_wake(unsigned long data)
 {
        struct cardstate *cs = (struct cardstate *) data;
-       struct tty_struct *tty;
-
-       tty = cs->tty;
-       if (!tty)
-               return;
 
-       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-           tty->ldisc.write_wakeup) {
-               gig_dbg(DEBUG_IF, "write wakeup call");
-               tty->ldisc.write_wakeup(tty);
-       }
-
-       wake_up_interruptible(&tty->write_wait);
+       if (cs->tty)
+               tty_wakeup(cs->tty);
 }
 
 /*** interface to common ***/
@@ -620,7 +616,17 @@ void gigaset_if_init(struct cardstate *cs)
                return;
 
        tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
-       tty_register_device(drv->tty, cs->minor_index, NULL);
+
+       mutex_lock(&cs->mutex);
+       cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL);
+
+       if (!IS_ERR(cs->tty_dev))
+               dev_set_drvdata(cs->tty_dev, cs);
+       else {
+               warn("could not register device to the tty subsystem");
+               cs->tty_dev = NULL;
+       }
+       mutex_unlock(&cs->mutex);
 }
 
 void gigaset_if_free(struct cardstate *cs)
@@ -633,6 +639,7 @@ void gigaset_if_free(struct cardstate *cs)
 
        tasklet_disable(&cs->if_wake_tasklet);
        tasklet_kill(&cs->if_wake_tasklet);
+       cs->tty_dev = NULL;
        tty_unregister_device(drv->tty, cs->minor_index);
 }
 
@@ -660,10 +667,9 @@ EXPORT_SYMBOL_GPL(gigaset_if_receive);
  *     drv             Driver
  *     procname        Name of the driver (e.g. for /proc/tty/drivers)
  *     devname         Name of the device files (prefix without minor number)
- *     devfsname       Devfs name of the device files without %d
  */
 void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
-                          const char *devname, const char *devfsname)
+                          const char *devname)
 {
        unsigned minors = drv->minors;
        int ret;
@@ -679,7 +685,7 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
        tty->major =            GIG_MAJOR,
        tty->type =             TTY_DRIVER_TYPE_SERIAL,
        tty->subtype =          SERIAL_TYPE_NORMAL,
-       tty->flags =            TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
+       tty->flags =            TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
 
        tty->driver_name =      procname;
        tty->name =             devname;
@@ -687,7 +693,6 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
        tty->num =              drv->minors;
 
        tty->owner =            THIS_MODULE;
-       tty->devfs_name =       devfsname;
 
        tty->init_termios          = tty_std_termios; //FIXME
        tty->init_termios.c_cflag  = B9600 | CS8 | CREAD | HUPCL | CLOCAL; //FIXME