Merge to Fedora kernel-2.6.18-1.2257_FC5 patched with stable patch-2.6.18.5-vs2.0...
[linux-2.6.git] / drivers / char / pcxx.c
index e804fdc..b20a941 100644 (file)
@@ -65,6 +65,7 @@
 #include <linux/tty_driver.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/bitops.h>
 
 #ifndef MODULE
 #include <linux/ctype.h> /* We only need it for parsing the "digi="-line */
@@ -73,7 +74,6 @@
 #include <asm/system.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
-#include <asm/bitops.h>
 #include <asm/semaphore.h>
 
 #define VERSION        "1.6.3"
@@ -112,13 +112,13 @@ static int numports[]     = {0, 0, 0, 0};
 MODULE_AUTHOR("Bernhard Kaindl");
 MODULE_DESCRIPTION("Digiboard PC/X{i,e,eve} driver");
 MODULE_LICENSE("GPL");
-MODULE_PARM(verbose,     "i");
-MODULE_PARM(debug,       "i");
-MODULE_PARM(io,          "1-4i");
-MODULE_PARM(membase,     "1-4i");
-MODULE_PARM(memsize,     "1-4i");
-MODULE_PARM(altpin,      "1-4i");
-MODULE_PARM(numports,    "1-4i");
+module_param(verbose,     bool, 0644);
+module_param(debug,       bool, 0644);
+module_param_array(io,          int, NULL, 0);
+module_param_array(membase,     int, NULL, 0);
+module_param_array(memsize,     int, NULL, 0);
+module_param_array(altpin,      int, NULL, 0);
+module_param_array(numports,    int, NULL, 0);
 
 #endif /* MODULE */
 
@@ -130,7 +130,6 @@ static struct channel    *digi_channels;
 int pcxx_ncook=sizeof(pcxx_cook);
 int pcxx_nbios=sizeof(pcxx_bios);
 
-#define MIN(a,b)       ((a) < (b) ? (a) : (b))
 #define pcxxassert(x, msg)  if(!(x)) pcxx_error(__LINE__, msg)
 
 #define FEPTIMEOUT 200000  
@@ -149,7 +148,7 @@ static void pcxx_error(int, char *);
 static void pcxe_close(struct tty_struct *, struct file *);
 static int pcxe_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
 static void pcxe_set_termios(struct tty_struct *, struct termios *);
-static int pcxe_write(struct tty_struct *, int, const unsigned char *, int);
+static int pcxe_write(struct tty_struct *, const unsigned char *, int);
 static int pcxe_write_room(struct tty_struct *);
 static int pcxe_chars_in_buffer(struct tty_struct *);
 static void pcxe_flush_buffer(struct tty_struct *);
@@ -206,7 +205,7 @@ static void __exit pcxe_cleanup(void)
 {
 
        unsigned long   flags;
-       int e1, e2;
+       int e1;
 
        printk(KERN_NOTICE "Unloading PC/Xx version %s\n", VERSION);
 
@@ -223,12 +222,6 @@ static void __exit pcxe_cleanup(void)
        restore_flags(flags);
 }
 
-/*
- * pcxe_init() is our init_module():
- */
-module_init(pcxe_init);
-module_cleanup(pcxe_cleanup);
-
 static inline struct channel *chan(register struct tty_struct *tty)
 {
        if (tty) {
@@ -538,32 +531,14 @@ static void pcxe_close(struct tty_struct * tty, struct file * filp)
        
                if(tty->driver->flush_buffer)
                        tty->driver->flush_buffer(tty);
-               if(tty->ldisc.flush_buffer)
-                       tty->ldisc.flush_buffer(tty);
+               tty_ldisc_flush(tty);
                shutdown(info);
                tty->closing = 0;
                info->event = 0;
                info->tty = NULL;
-#ifndef MODULE
-/* ldiscs[] is not available in a MODULE
-** worth noting that while I'm not sure what this hunk of code is supposed
-** to do, it is not present in the serial.c driver.  Hmmm.  If you know,
-** please send me a note.  brian@ilinx.com
-** Don't know either what this is supposed to do christoph@lameter.com.
-*/
-               if(tty->ldisc.num != ldiscs[N_TTY].num) {
-                       if(tty->ldisc.close)
-                               (tty->ldisc.close)(tty);
-                       tty->ldisc = ldiscs[N_TTY];
-                       tty->termios->c_line = N_TTY;
-                       if(tty->ldisc.open)
-                               (tty->ldisc.open)(tty);
-               }
-#endif
                if(info->blocked_open) {
                        if(info->close_delay) {
-                               current->state = TASK_INTERRUPTIBLE;
-                               schedule_timeout(info->close_delay);
+                               msleep_interruptible(jiffies_to_msecs(info->close_delay));
                        }
                        wake_up_interruptible(&info->open_wait);
                }
@@ -595,7 +570,7 @@ void pcxe_hangup(struct tty_struct *tty)
 
 
 
-static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
+static int pcxe_write(struct tty_struct * tty, const unsigned char *buf, int count)
 {
        struct channel *ch;
        volatile struct board_chan *bc;
@@ -610,33 +585,6 @@ static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned cha
        bc = ch->brdchan;
        size = ch->txbufsize;
 
-       if (from_user) {
-
-               down(&ch->tmp_buf_sem);
-               save_flags(flags);
-               cli();
-               globalwinon(ch);
-               head = bc->tin & (size - 1);
-               /* It seems to be necessary to make sure that the value is stable here somehow
-                  This is a rather odd pice of code here. */
-               do
-               {
-                       tail = bc->tout;
-               } while (tail != bc->tout);
-               
-               tail &= (size - 1);
-               stlen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
-               count = MIN(stlen, count);
-               memoff(ch);
-               restore_flags(flags);
-
-               if (count)
-                       if (copy_from_user(ch->tmp_buf, buf, count))
-                               count = 0;
-
-               buf = ch->tmp_buf;
-       }
-
        /*
         * All data is now local
         */
@@ -658,11 +606,11 @@ static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned cha
                remain = tail - head - 1;
                stlen = remain;
        }
-       count = MIN(remain, count);
+       count = min(remain, count);
 
        txwinon(ch);
        while (count > 0) {
-               stlen = MIN(count, stlen);
+               stlen = min(count, stlen);
                memcpy(ch->txptr + head, buf, stlen);
                buf += stlen;
                count -= stlen;
@@ -683,16 +631,13 @@ static int pcxe_write(struct tty_struct * tty, int from_user, const unsigned cha
        memoff(ch);
        restore_flags(flags);
        
-       if(from_user)
-               up(&ch->tmp_buf_sem);
-
        return(total);
 }
 
 
 static void pcxe_put_char(struct tty_struct *tty, unsigned char c)
 {
-       pcxe_write(tty, 0, &c, 1);
+       pcxe_write(tty, &c, 1);
        return;
 }
 
@@ -800,9 +745,7 @@ static void pcxe_flush_buffer(struct tty_struct *tty)
        memoff(ch);
        restore_flags(flags);
 
-       wake_up_interruptible(&tty->write_wait);
-       if((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
-               (tty->ldisc.write_wakeup)(tty);
+       tty_wakeup(tty);
 }
 
 static void pcxe_flush_chars(struct tty_struct *tty)
@@ -1013,9 +956,6 @@ void __init pcxx_setup(char *str, int *ints)
 }
 #endif
 
-module_init(pcxe_init)
-module_exit(pcxe_exit)
-
 static struct tty_operations pcxe_ops = {
        .open = pcxe_open,
        .close = pcxe_close,
@@ -1561,6 +1501,8 @@ cleanup_boards:
        return ret;
 }
 
+module_init(pcxe_init)
+module_exit(pcxe_cleanup)
 
 static void pcxxpoll(unsigned long dummy)
 {
@@ -1675,10 +1617,7 @@ static void doevent(int crd)
                        if (event & LOWTX_IND) {
                                if (ch->statusflags & LOWWAIT) {
                                        ch->statusflags &= ~LOWWAIT;
-                                       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                                               tty->ldisc.write_wakeup)
-                                               (tty->ldisc.write_wakeup)(tty);
-                                       wake_up_interruptible(&tty->write_wait);
+                                       tty_wakeup(tty);
                                }
                        }
 
@@ -1686,10 +1625,7 @@ static void doevent(int crd)
                                ch->statusflags &= ~TXBUSY;
                                if (ch->statusflags & EMPTYWAIT) {
                                        ch->statusflags &= ~EMPTYWAIT;
-                                       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                                               tty->ldisc.write_wakeup)
-                                               (tty->ldisc.write_wakeup)(tty);
-                                       wake_up_interruptible(&tty->write_wait);
+                                       tty_wakeup(tty);
                                }
                        }
                }
@@ -1995,6 +1931,7 @@ static int pcxe_tiocmget(struct tty_struct *tty, struct file *file)
        volatile struct board_chan *bc;
        unsigned long flags;
        int mflag = 0;
+       int mstat;
 
        if(ch)
                bc = ch->brdchan;
@@ -2069,6 +2006,7 @@ static int pcxe_tiocmset(struct tty_struct *tty, struct file *file,
        pcxxparam(tty,ch);
        memoff(ch);
        restore_flags(flags);
+       return 0;
 }
 
 
@@ -2165,8 +2103,7 @@ static int pcxe_ioctl(struct tty_struct *tty, struct file * file,
                                tty_wait_until_sent(tty, 0);
                        }
                        else {
-                               if(tty->ldisc.flush_buffer)
-                                       tty->ldisc.flush_buffer(tty);
+                               tty_ldisc_flush(tty);
                        }
 
                        /* Fall Thru */