Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
[powerpc.git] / drivers / isdn / gigaset / interface.c
index 2575086..74fd234 100644 (file)
@@ -33,7 +33,7 @@ static int if_lock(struct cardstate *cs, int *arg)
        }
 
        if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
-           && atomic_read(&cs->connected)) {
+           && 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);
@@ -107,6 +107,11 @@ static int if_config(struct cardstate *cs, int *arg)
        if (atomic_read(&cs->mstate) != MS_LOCKED)
                return -EBUSY;
 
+       if (!cs->connected) {
+               err("not connected!");
+               return -ENODEV;
+       }
+
        *arg = 0;
        return gigaset_enterconfigmode(cs);
 }
@@ -160,7 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
        if (!cs)
                return -ENODEV;
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
        tty->driver_data = cs;
 
@@ -173,7 +178,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
                tty->low_latency = 1; //FIXME test
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
        return 0;
 }
 
@@ -190,7 +195,7 @@ static void if_close(struct tty_struct *tty, struct file *filp)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       down(&cs->sem);
+       mutex_lock(&cs->mutex);
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
@@ -202,7 +207,7 @@ static void if_close(struct tty_struct *tty, struct file *filp)
                }
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 }
 
 static int if_ioctl(struct tty_struct *tty, struct file *file,
@@ -222,7 +227,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
 
        gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
        if (!cs->open_count)
@@ -246,7 +251,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;
@@ -279,7 +284,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
                }
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -297,13 +302,13 @@ static int if_tiocmget(struct tty_struct *tty, struct file *file)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
        // FIXME read from device?
        retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -324,10 +329,10 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
        gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
                cs->minor_index, __func__, set, clear);
 
-       if (down_interruptible(&cs->sem))
+       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 {
@@ -336,7 +341,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
                cs->control_state = mc;
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -354,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
        if (!cs->open_count)
@@ -362,7 +367,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
        else if (atomic_read(&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 {
@@ -370,7 +375,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
                                            &cs->if_wake_tasklet);
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -388,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
        if (!cs->open_count)
@@ -396,13 +401,13 @@ static int if_write_room(struct tty_struct *tty)
        else if (atomic_read(&cs->mstate) != MS_LOCKED) {
                warn("can't write to unlocked device");
                retval = -EBUSY; //FIXME
-       } else if (!atomic_read(&cs->connected)) {
+       } else if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't write to unplugged device");
                retval = -EBUSY; //FIXME
        } else
                retval = cs->ops->write_room(cs);
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -420,7 +425,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       if (down_interruptible(&cs->sem))
+       if (mutex_lock_interruptible(&cs->mutex))
                return -ERESTARTSYS; // FIXME -EINTR?
 
        if (!cs->open_count)
@@ -428,13 +433,13 @@ static int if_chars_in_buffer(struct tty_struct *tty)
        else if (atomic_read(&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
                retval = cs->ops->chars_in_buffer(cs);
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 
        return retval;
 }
@@ -451,7 +456,7 @@ static void if_throttle(struct tty_struct *tty)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       down(&cs->sem);
+       mutex_lock(&cs->mutex);
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
@@ -459,7 +464,7 @@ static void if_throttle(struct tty_struct *tty)
                //FIXME
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 }
 
 static void if_unthrottle(struct tty_struct *tty)
@@ -474,7 +479,7 @@ static void if_unthrottle(struct tty_struct *tty)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       down(&cs->sem);
+       mutex_lock(&cs->mutex);
 
        if (!cs->open_count)
                warn("%s: device not opened", __func__);
@@ -482,7 +487,7 @@ static void if_unthrottle(struct tty_struct *tty)
                //FIXME
        }
 
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 }
 
 static void if_set_termios(struct tty_struct *tty, struct termios *old)
@@ -501,14 +506,14 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
 
        gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
 
-       down(&cs->sem);
+       mutex_lock(&cs->mutex);
 
        if (!cs->open_count) {
                warn("%s: device not opened", __func__);
                goto out;
        }
 
-       if (!atomic_read(&cs->connected)) {
+       if (!cs->connected) {
                gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
                goto out;
        }
@@ -586,7 +591,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
        cs->control_state = control_state;
 
 out:
-       up(&cs->sem);
+       mutex_unlock(&cs->mutex);
 }
 
 
@@ -620,7 +625,14 @@ 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);
+       cs->class = tty_register_device(drv->tty, cs->minor_index, NULL);
+
+       if (!IS_ERR(cs->class))
+               class_set_devdata(cs->class, cs);
+       else {
+               warn("could not register device to the tty subsystem");
+               cs->class = NULL;
+       }
 }
 
 void gigaset_if_free(struct cardstate *cs)
@@ -633,6 +645,7 @@ void gigaset_if_free(struct cardstate *cs)
 
        tasklet_disable(&cs->if_wake_tasklet);
        tasklet_kill(&cs->if_wake_tasklet);
+       cs->class = NULL;
        tty_unregister_device(drv->tty, cs->minor_index);
 }