i2c-pxa: only define 'blue_murder'-function if DEBUG is #defined
[safe/jmp/linux-2.6] / drivers / char / rocket.c
index 5bcbeb0..0e29a23 100644 (file)
  */
 
 /****** Defines ******/
-#ifdef PCI_NUM_RESOURCES
-#define PCI_BASE_ADDRESS(dev, r) ((dev)->resource[r].start)
-#else
-#define PCI_BASE_ADDRESS(dev, r) ((dev)->base_address[r])
-#endif
-
 #define ROCKET_PARANOIA_CHECK
 #define ROCKET_DISABLE_SIMUSAGE
 
 
 /****** Kernel includes ******/
 
-#ifdef MODVERSIONS
-#include <config/modversions.h>
-#endif                         
-
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/major.h>
 #include <linux/tty.h>
 #include <linux/tty_driver.h>
 #include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/fcntl.h>
 #include <linux/ptrace.h>
+#include <linux/mutex.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
+#include <linux/completion.h>
 #include <linux/wait.h>
 #include <linux/pci.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <asm/atomic.h>
+#include <asm/unaligned.h>
 #include <linux/bitops.h>
 #include <linux/spinlock.h>
-#include <asm/semaphore.h>
 #include <linux/init.h>
 
 /****** RocketPort includes ******/
 
 /****** RocketPort Local Variables ******/
 
+static void rp_do_poll(unsigned long dummy);
+
 static struct tty_driver *rocket_driver;
 
 static struct rocket_version driver_version = {        
@@ -116,7 +112,7 @@ static struct r_port *rp_table[MAX_RP_PORTS];              /*  The main repository of
 static unsigned int xmit_flags[NUM_BOARDS];           /*  Bit significant, indicates port had data to transmit. */
                                                       /*  eg.  Bit 0 indicates port 0 has xmit data, ...        */
 static atomic_t rp_num_ports_open;                    /*  Number of serial ports open                           */
-static struct timer_list rocket_timer;
+static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
 
 static unsigned long board1;                          /* ISA addresses, retrieved from rocketport.conf          */
 static unsigned long board2;
@@ -140,6 +136,7 @@ static int rcktpt_type[NUM_BOARDS];
 static int is_PCI[NUM_BOARDS];
 static rocketModel_t rocketModel[NUM_BOARDS];
 static int max_board;
+static const struct tty_port_operations rocket_port_ops;
 
 /*
  * The following arrays define the interrupt bits corresponding to each AIOP.
@@ -161,6 +158,64 @@ static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = {
        UPCI_AIOP_INTR_BIT_3
 };
 
+static Byte_t RData[RDATASIZE] = {
+       0x00, 0x09, 0xf6, 0x82,
+       0x02, 0x09, 0x86, 0xfb,
+       0x04, 0x09, 0x00, 0x0a,
+       0x06, 0x09, 0x01, 0x0a,
+       0x08, 0x09, 0x8a, 0x13,
+       0x0a, 0x09, 0xc5, 0x11,
+       0x0c, 0x09, 0x86, 0x85,
+       0x0e, 0x09, 0x20, 0x0a,
+       0x10, 0x09, 0x21, 0x0a,
+       0x12, 0x09, 0x41, 0xff,
+       0x14, 0x09, 0x82, 0x00,
+       0x16, 0x09, 0x82, 0x7b,
+       0x18, 0x09, 0x8a, 0x7d,
+       0x1a, 0x09, 0x88, 0x81,
+       0x1c, 0x09, 0x86, 0x7a,
+       0x1e, 0x09, 0x84, 0x81,
+       0x20, 0x09, 0x82, 0x7c,
+       0x22, 0x09, 0x0a, 0x0a
+};
+
+static Byte_t RRegData[RREGDATASIZE] = {
+       0x00, 0x09, 0xf6, 0x82, /* 00: Stop Rx processor */
+       0x08, 0x09, 0x8a, 0x13, /* 04: Tx software flow control */
+       0x0a, 0x09, 0xc5, 0x11, /* 08: XON char */
+       0x0c, 0x09, 0x86, 0x85, /* 0c: XANY */
+       0x12, 0x09, 0x41, 0xff, /* 10: Rx mask char */
+       0x14, 0x09, 0x82, 0x00, /* 14: Compare/Ignore #0 */
+       0x16, 0x09, 0x82, 0x7b, /* 18: Compare #1 */
+       0x18, 0x09, 0x8a, 0x7d, /* 1c: Compare #2 */
+       0x1a, 0x09, 0x88, 0x81, /* 20: Interrupt #1 */
+       0x1c, 0x09, 0x86, 0x7a, /* 24: Ignore/Replace #1 */
+       0x1e, 0x09, 0x84, 0x81, /* 28: Interrupt #2 */
+       0x20, 0x09, 0x82, 0x7c, /* 2c: Ignore/Replace #2 */
+       0x22, 0x09, 0x0a, 0x0a  /* 30: Rx FIFO Enable */
+};
+
+static CONTROLLER_T sController[CTL_SIZE] = {
+       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
+        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
+       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
+        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
+       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
+        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
+       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
+        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}}
+};
+
+static Byte_t sBitMapClrTbl[8] = {
+       0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f
+};
+
+static Byte_t sBitMapSetTbl[8] = {
+       0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+};
+
+static int sClockPrescale = 0x14;
+
 /*
  *  Line number is the ttySIx number (x), the Minor number.  We 
  *  assign them sequentially, starting at zero.  The following 
@@ -177,8 +232,27 @@ static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model);
 static unsigned char GetLineNumber(int ctrl, int aiop, int ch);
 static unsigned char SetLineNumber(int ctrl, int aiop, int ch);
 static void rp_start(struct tty_struct *tty);
+static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
+                    int ChanNum);
+static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode);
+static void sFlushRxFIFO(CHANNEL_T * ChP);
+static void sFlushTxFIFO(CHANNEL_T * ChP);
+static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags);
+static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags);
+static void sModemReset(CONTROLLER_T * CtlP, int chan, int on);
+static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on);
+static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data);
+static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
+                             ByteIO_t * AiopIOList, int AiopIOListSize,
+                             WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
+                             int PeriodicOnly, int altChanRingIndicator,
+                             int UPCIRingInd);
+static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
+                          ByteIO_t * AiopIOList, int AiopIOListSize,
+                          int IRQNum, Byte_t Frequency, int PeriodicOnly);
+static int sReadAiopID(ByteIO_t io);
+static int sReadAiopNumChan(WordIO_t io);
 
-#ifdef MODULE
 MODULE_AUTHOR("Theodore Ts'o");
 MODULE_DESCRIPTION("Comtrol RocketPort driver");
 module_param(board1, ulong, 0);
@@ -210,17 +284,14 @@ MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc1
 module_param_array(pc104_4, ulong, NULL, 0);
 MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");
 
-int rp_init(void);
+static int rp_init(void);
 static void rp_cleanup_module(void);
 
 module_init(rp_init);
 module_exit(rp_cleanup_module);
 
-#endif
 
-#ifdef MODULE_LICENSE
 MODULE_LICENSE("Dual BSD/GPL");
-#endif
 
 /*************************************************************************/
 /*                     Module code starts here                           */
@@ -232,8 +303,8 @@ static inline int rocket_paranoia_check(struct r_port *info,
        if (!info)
                return 1;
        if (info->magic != RPORT_MAGIC) {
-               printk(KERN_INFO "Warning: bad magic number for rocketport struct in %s\n",
-                    routine);
+               printk(KERN_WARNING "Warning: bad magic number for rocketport "
+                               "struct in %s\n", routine);
                return 1;
        }
 #endif
@@ -250,33 +321,14 @@ static void rp_do_receive(struct r_port *info,
                          CHANNEL_t * cp, unsigned int ChanStatus)
 {
        unsigned int CharNStat;
-       int ToRecv, wRecv, space = 0, count;
+       int ToRecv, wRecv, space;
        unsigned char *cbuf;
-       char *fbuf;
-       struct tty_ldisc *ld;
-
-       ld = tty_ldisc_ref(tty);
 
        ToRecv = sGetRxCnt(cp);
-       if (ld)
-               space = ld->receive_room(tty);
-       if (space > 2 * TTY_FLIPBUF_SIZE)
-               space = 2 * TTY_FLIPBUF_SIZE;
-       cbuf = tty->flip.char_buf;
-       fbuf = tty->flip.flag_buf;
-       count = 0;
 #ifdef ROCKET_DEBUG_INTR
-       printk(KERN_INFO "rp_do_receive(%d, %d)...", ToRecv, space);
+       printk(KERN_INFO "rp_do_receive(%d)...\n", ToRecv);
 #endif
-
-       /*
-        * determine how many we can actually read in.  If we can't
-        * read any in then we have a software overrun condition.
-        */
-       if (ToRecv > space)
-               ToRecv = space;
-
-       if (ToRecv <= 0)
+       if (ToRecv == 0)
                return;
 
        /*
@@ -287,7 +339,7 @@ static void rp_do_receive(struct r_port *info,
        if (ChanStatus & (RXFOVERFL | RXBREAK | RXFRAME | RXPARITY)) {
                if (!(ChanStatus & STATMODE)) {
 #ifdef ROCKET_DEBUG_RECEIVE
-                       printk(KERN_INFO "Entering STATMODE...");
+                       printk(KERN_INFO "Entering STATMODE...\n");
 #endif
                        ChanStatus |= STATMODE;
                        sEnRxStatusMode(cp);
@@ -301,13 +353,15 @@ static void rp_do_receive(struct r_port *info,
         */
        if (ChanStatus & STATMODE) {
 #ifdef ROCKET_DEBUG_RECEIVE
-               printk(KERN_INFO "Ignore %x, read %x...", info->ignore_status_mask,
-                      info->read_status_mask);
+               printk(KERN_INFO "Ignore %x, read %x...\n",
+                       info->ignore_status_mask, info->read_status_mask);
 #endif
                while (ToRecv) {
+                       char flag;
+
                        CharNStat = sInW(sGetTxRxDataIO(cp));
 #ifdef ROCKET_DEBUG_RECEIVE
-                       printk(KERN_INFO "%x...", CharNStat);
+                       printk(KERN_INFO "%x...\n", CharNStat);
 #endif
                        if (CharNStat & STMBREAKH)
                                CharNStat &= ~(STMFRAMEH | STMPARITYH);
@@ -317,17 +371,16 @@ static void rp_do_receive(struct r_port *info,
                        }
                        CharNStat &= info->read_status_mask;
                        if (CharNStat & STMBREAKH)
-                               *fbuf++ = TTY_BREAK;
+                               flag = TTY_BREAK;
                        else if (CharNStat & STMPARITYH)
-                               *fbuf++ = TTY_PARITY;
+                               flag = TTY_PARITY;
                        else if (CharNStat & STMFRAMEH)
-                               *fbuf++ = TTY_FRAME;
+                               flag = TTY_FRAME;
                        else if (CharNStat & STMRCVROVRH)
-                               *fbuf++ = TTY_OVERRUN;
+                               flag = TTY_OVERRUN;
                        else
-                               *fbuf++ = 0;
-                       *cbuf++ = CharNStat & 0xff;
-                       count++;
+                               flag = TTY_NORMAL;
+                       tty_insert_flip_char(tty, CharNStat & 0xff, flag);
                        ToRecv--;
                }
 
@@ -347,19 +400,23 @@ static void rp_do_receive(struct r_port *info,
                 * characters at time by doing repeated word IO
                 * transfer.
                 */
+               space = tty_prepare_flip_string(tty, &cbuf, ToRecv);
+               if (space < ToRecv) {
+#ifdef ROCKET_DEBUG_RECEIVE
+                       printk(KERN_INFO "rp_do_receive:insufficient space ToRecv=%d space=%d\n", ToRecv, space);
+#endif
+                       if (space <= 0)
+                               return;
+                       ToRecv = space;
+               }
                wRecv = ToRecv >> 1;
                if (wRecv)
                        sInStrW(sGetTxRxDataIO(cp), (unsigned short *) cbuf, wRecv);
                if (ToRecv & 1)
                        cbuf[ToRecv - 1] = sInB(sGetTxRxDataIO(cp));
-               memset(fbuf, 0, ToRecv);
-               cbuf += ToRecv;
-               fbuf += ToRecv;
-               count += ToRecv;
        }
        /*  Push the data up to the tty layer */
-       ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
-       tty_ldisc_deref(ld);
+       tty_flip_buffer_push(tty);
 }
 
 /*
@@ -376,25 +433,27 @@ static void rp_do_transmit(struct r_port *info)
        unsigned long flags;
 
 #ifdef ROCKET_DEBUG_INTR
-       printk(KERN_INFO "rp_do_transmit ");
+       printk(KERN_DEBUG "%s\n", __func__);
 #endif
        if (!info)
                return;
-       if (!info->tty) {
-               printk(KERN_INFO  "rp: WARNING rp_do_transmit called with info->tty==NULL\n");
+       tty = tty_port_tty_get(&info->port);
+
+       if (tty == NULL) {
+               printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
                clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
                return;
        }
 
        spin_lock_irqsave(&info->slock, flags);
-       tty = info->tty;
        info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
 
        /*  Loop sending data to FIFO until done or FIFO full */
        while (1) {
                if (tty->stopped || tty->hw_stopped)
                        break;
-               c = min(info->xmit_fifo_room, min(info->xmit_cnt, XMIT_BUF_SIZE - info->xmit_tail));
+               c = min(info->xmit_fifo_room, info->xmit_cnt);
+               c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
                if (c <= 0 || info->xmit_fifo_room <= 0)
                        break;
                sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2);
@@ -405,7 +464,7 @@ static void rp_do_transmit(struct r_port *info)
                info->xmit_cnt -= c;
                info->xmit_fifo_room -= c;
 #ifdef ROCKET_DEBUG_INTR
-               printk(KERN_INFO "tx %d chars...", c);
+               printk(KERN_INFO "tx %d chars...\n", c);
 #endif
        }
 
@@ -414,16 +473,16 @@ static void rp_do_transmit(struct r_port *info)
 
        if (info->xmit_cnt < WAKEUP_CHARS) {
                tty_wakeup(tty);
-               wake_up_interruptible(&tty->write_wait);
 #ifdef ROCKETPORT_HAVE_POLL_WAIT
                wake_up_interruptible(&tty->poll_wait);
 #endif
        }
 
        spin_unlock_irqrestore(&info->slock, flags);
+       tty_kref_put(tty);
 
 #ifdef ROCKET_DEBUG_INTR
-       printk(KERN_INFO "(%d,%d,%d,%d)...", info->xmit_cnt, info->xmit_head,
+       printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
               info->xmit_tail, info->xmit_fifo_room);
 #endif
 }
@@ -442,20 +501,22 @@ static void rp_handle_port(struct r_port *info)
        if (!info)
                return;
 
-       if ((info->flags & ROCKET_INITIALIZED) == 0) {
-               printk(KERN_INFO "rp: WARNING: rp_handle_port called with info->flags & NOT_INIT\n");
+       if ((info->port.flags & ASYNC_INITIALIZED) == 0) {
+               printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
+                               "info->flags & NOT_INIT\n");
                return;
        }
-       if (!info->tty) {
-               printk(KERN_INFO "rp: WARNING: rp_handle_port called with info->tty==NULL\n");
+       tty = tty_port_tty_get(&info->port);
+       if (!tty) {
+               printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
+                               "tty==NULL\n");
                return;
        }
        cp = &info->channel;
-       tty = info->tty;
 
        IntMask = sGetChanIntID(cp) & info->intmask;
 #ifdef ROCKET_DEBUG_INTR
-       printk(KERN_INFO "rp_interrupt %02x...", IntMask);
+       printk(KERN_INFO "rp_interrupt %02x...\n", IntMask);
 #endif
        ChanStatus = sGetChanStatus(cp);
        if (IntMask & RXF_TRIG) {       /* Rx FIFO trigger level */
@@ -463,7 +524,7 @@ static void rp_handle_port(struct r_port *info)
        }
        if (IntMask & DELTA_CD) {       /* CD change  */
 #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_INTR) || defined(ROCKET_DEBUG_HANGUP))
-               printk(KERN_INFO "ttyR%d CD now %s...", info->line,
+               printk(KERN_INFO "ttyR%d CD now %s...\n", info->line,
                       (ChanStatus & CD_ACT) ? "on" : "off");
 #endif
                if (!(ChanStatus & CD_ACT) && info->cd_status) {
@@ -473,7 +534,7 @@ static void rp_handle_port(struct r_port *info)
                        tty_hangup(tty);
                }
                info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
-               wake_up_interruptible(&info->open_wait);
+               wake_up_interruptible(&info->port.open_wait);
        }
 #ifdef ROCKET_DEBUG_INTR
        if (IntMask & DELTA_CTS) {      /* CTS change */
@@ -483,6 +544,7 @@ static void rp_handle_port(struct r_port *info)
                printk(KERN_INFO "DSR change...\n");
        }
 #endif
+       tty_kref_put(tty);
 }
 
 /*
@@ -491,8 +553,8 @@ static void rp_handle_port(struct r_port *info)
 static void rp_do_poll(unsigned long dummy)
 {
        CONTROLLER_t *ctlp;
-       int ctrl, aiop, ch, line, i;
-       unsigned int xmitmask;
+       int ctrl, aiop, ch, line;
+       unsigned int xmitmask, i;
        unsigned int CtlMask;
        unsigned char AiopMask;
        Word_t bit;
@@ -505,7 +567,7 @@ static void rp_do_poll(unsigned long dummy)
                /*  Get a ptr to the board's control struct */
                ctlp = sCtlNumToCtlPtr(ctrl);
 
-               /*  Get the interupt status from the board */
+               /*  Get the interrupt status from the board */
 #ifdef CONFIG_PCI
                if (ctlp->BusType == isPCI)
                        CtlMask = sPCIGetControllerIntStatus(ctlp);
@@ -578,12 +640,12 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
        ctlp = sCtlNumToCtlPtr(board);
 
        /*  Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
-       info = kmalloc(sizeof (struct r_port), GFP_KERNEL);
+       info = kzalloc(sizeof (struct r_port), GFP_KERNEL);
        if (!info) {
-               printk(KERN_INFO "Couldn't allocate info struct for line #%d\n", line);
+               printk(KERN_ERR "Couldn't allocate info struct for line #%d\n",
+                               line);
                return;
        }
-       memset(info, 0, sizeof (struct r_port));
 
        info->magic = RPORT_MAGIC;
        info->line = line;
@@ -591,10 +653,9 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
        info->board = board;
        info->aiop = aiop;
        info->chan = chan;
-       info->closing_wait = 3000;
-       info->close_delay = 50;
-       init_waitqueue_head(&info->open_wait);
-       init_waitqueue_head(&info->close_wait);
+       tty_port_init(&info->port);
+       info->port.ops = &rocket_port_ops;
+       init_completion(&info->close_wait);
        info->flags &= ~ROCKET_MODE_MASK;
        switch (pc104[board][line]) {
        case 422:
@@ -611,7 +672,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
 
        info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
        if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
-               printk(KERN_INFO "RocketPort sInitChan(%d, %d, %d) failed!\n", board, aiop, chan);
+               printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n",
+                               board, aiop, chan);
                kfree(info);
                return;
        }
@@ -641,29 +703,28 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
                }
        }
        spin_lock_init(&info->slock);
-       sema_init(&info->write_sem, 1);
+       mutex_init(&info->write_mtx);
        rp_table[line] = info;
-       if (pci_dev)
-               tty_register_device(rocket_driver, line, &pci_dev->dev);
+       tty_register_device(rocket_driver, line, pci_dev ? &pci_dev->dev :
+                       NULL);
 }
 
 /*
  *  Configures a rocketport port according to its termio settings.  Called from 
  *  user mode into the driver (exception handler).  *info CD manipulation is spinlock protected.
  */
-static void configure_r_port(struct r_port *info,
-                            struct termios *old_termios)
+static void configure_r_port(struct tty_struct *tty, struct r_port *info,
+                            struct ktermios *old_termios)
 {
        unsigned cflag;
        unsigned long flags;
        unsigned rocketMode;
        int bits, baud, divisor;
        CHANNEL_t *cp;
+       struct ktermios *t = tty->termios;
 
-       if (!info->tty || !info->tty->termios)
-               return;
        cp = &info->channel;
-       cflag = info->tty->termios->c_cflag;
+       cflag = t->c_cflag;
 
        /* Byte size and parity */
        if ((cflag & CSIZE) == CS8) {
@@ -693,15 +754,12 @@ static void configure_r_port(struct r_port *info,
        }
 
        /* baud rate */
-       baud = tty_get_baud_rate(info->tty);
+       baud = tty_get_baud_rate(tty);
        if (!baud)
                baud = 9600;
        divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
        if ((divisor >= 8192 || divisor < 0) && old_termios) {
-               info->tty->termios->c_cflag &= ~CBAUD;
-               info->tty->termios->c_cflag |=
-                   (old_termios->c_cflag & CBAUD);
-               baud = tty_get_baud_rate(info->tty);
+               baud = tty_termios_baud_rate(old_termios);
                if (!baud)
                        baud = 9600;
                divisor = (rp_baud_base[info->board] / baud) - 1;
@@ -713,6 +771,9 @@ static void configure_r_port(struct r_port *info,
        info->cps = baud / bits;
        sSetBaud(cp, divisor);
 
+       /* FIXME: Should really back compute a baud rate from the divisor */
+       tty_encode_baud_rate(tty, baud, baud);
+
        if (cflag & CRTSCTS) {
                info->intmask |= DELTA_CTS;
                sEnCTSFlowCtl(cp);
@@ -736,15 +797,15 @@ static void configure_r_port(struct r_port *info,
         * Handle software flow control in the board
         */
 #ifdef ROCKET_SOFT_FLOW
-       if (I_IXON(info->tty)) {
+       if (I_IXON(tty)) {
                sEnTxSoftFlowCtl(cp);
-               if (I_IXANY(info->tty)) {
+               if (I_IXANY(tty)) {
                        sEnIXANY(cp);
                } else {
                        sDisIXANY(cp);
                }
-               sSetTxXONChar(cp, START_CHAR(info->tty));
-               sSetTxXOFFChar(cp, STOP_CHAR(info->tty));
+               sSetTxXONChar(cp, START_CHAR(tty));
+               sSetTxXOFFChar(cp, STOP_CHAR(tty));
        } else {
                sDisTxSoftFlowCtl(cp);
                sDisIXANY(cp);
@@ -756,24 +817,24 @@ static void configure_r_port(struct r_port *info,
         * Set up ignore/read mask words
         */
        info->read_status_mask = STMRCVROVRH | 0xFF;
-       if (I_INPCK(info->tty))
+       if (I_INPCK(tty))
                info->read_status_mask |= STMFRAMEH | STMPARITYH;
-       if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
+       if (I_BRKINT(tty) || I_PARMRK(tty))
                info->read_status_mask |= STMBREAKH;
 
        /*
         * Characters to ignore
         */
        info->ignore_status_mask = 0;
-       if (I_IGNPAR(info->tty))
+       if (I_IGNPAR(tty))
                info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
-       if (I_IGNBRK(info->tty)) {
+       if (I_IGNBRK(tty)) {
                info->ignore_status_mask |= STMBREAKH;
                /*
                 * If we're ignoring parity and break indicators,
                 * ignore overruns too.  (For real raw support).
                 */
-               if (I_IGNPAR(info->tty))
+               if (I_IGNPAR(tty))
                        info->ignore_status_mask |= STMRCVROVRH;
        }
 
@@ -806,105 +867,22 @@ static void configure_r_port(struct r_port *info,
        }
 }
 
-/*  info->count is considered critical, protected by spinlocks.  */
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
-                          struct r_port *info)
+static int carrier_raised(struct tty_port *port)
 {
-       DECLARE_WAITQUEUE(wait, current);
-       int retval;
-       int do_clocal = 0, extra_count = 0;
-       unsigned long flags;
-
-       /*
-        * If the device is in the middle of being closed, then block
-        * until it's done, and then try again.
-        */
-       if (tty_hung_up_p(filp))
-               return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
-       if (info->flags & ROCKET_CLOSING) {
-               interruptible_sleep_on(&info->close_wait);
-               return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
-       }
-
-       /*
-        * If non-blocking mode is set, or the port is not enabled,
-        * then make the check up front and then exit.
-        */
-       if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
-               info->flags |= ROCKET_NORMAL_ACTIVE;
-               return 0;
-       }
-       if (tty->termios->c_cflag & CLOCAL)
-               do_clocal = 1;
-
-       /*
-        * Block waiting for the carrier detect and the line to become free.  While we are in
-        * this loop, info->count is dropped by one, so that rp_close() knows when to free things.  
-         * We restore it upon exit, either normal or abnormal.
-        */
-       retval = 0;
-       add_wait_queue(&info->open_wait, &wait);
-#ifdef ROCKET_DEBUG_OPEN
-       printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, info->count);
-#endif
-       spin_lock_irqsave(&info->slock, flags);
-
-#ifdef ROCKET_DISABLE_SIMUSAGE
-       info->flags |= ROCKET_NORMAL_ACTIVE;
-#else
-       if (!tty_hung_up_p(filp)) {
-               extra_count = 1;
-               info->count--;
-       }
-#endif
-       info->blocked_open++;
-
-       spin_unlock_irqrestore(&info->slock, flags);
+       struct r_port *info = container_of(port, struct r_port, port);
+       return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
+}
 
-       while (1) {
-               if (tty->termios->c_cflag & CBAUD) {
-                       sSetDTR(&info->channel);
-                       sSetRTS(&info->channel);
-               }
-               set_current_state(TASK_INTERRUPTIBLE);
-               if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) {
-                       if (info->flags & ROCKET_HUP_NOTIFY)
-                               retval = -EAGAIN;
-                       else
-                               retval = -ERESTARTSYS;
-                       break;
-               }
-               if (!(info->flags & ROCKET_CLOSING) && (do_clocal || (sGetChanStatusLo(&info->channel) & CD_ACT)))
-                       break;
-               if (signal_pending(current)) {
-                       retval = -ERESTARTSYS;
-                       break;
-               }
-#ifdef ROCKET_DEBUG_OPEN
-               printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n",
-                    info->line, info->count, info->flags);
-#endif
-               schedule();     /*  Don't hold spinlock here, will hang PC */
+static void dtr_rts(struct tty_port *port, int on)
+{
+       struct r_port *info = container_of(port, struct r_port, port);
+       if (on) {
+               sSetDTR(&info->channel);
+               sSetRTS(&info->channel);
+       } else {
+               sClrDTR(&info->channel);
+               sClrRTS(&info->channel);
        }
-       current->state = TASK_RUNNING;
-       remove_wait_queue(&info->open_wait, &wait);
-
-       spin_lock_irqsave(&info->slock, flags);
-
-       if (extra_count)
-               info->count++;
-       info->blocked_open--;
-
-       spin_unlock_irqrestore(&info->slock, flags);
-
-#ifdef ROCKET_DEBUG_OPEN
-       printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n",
-              info->line, info->count);
-#endif
-       if (retval)
-               return retval;
-       info->flags |= ROCKET_NORMAL_ACTIVE;
-       return 0;
 }
 
 /*
@@ -914,22 +892,26 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
 static int rp_open(struct tty_struct *tty, struct file *filp)
 {
        struct r_port *info;
+       struct tty_port *port;
        int line = 0, retval;
        CHANNEL_t *cp;
        unsigned long page;
 
-       line = TTY_GET_LINE(tty);
-       if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL))
+       line = tty->index;
+       if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
                return -ENXIO;
-
+       port = &info->port;
+       
        page = __get_free_page(GFP_KERNEL);
        if (!page)
                return -ENOMEM;
 
-       if (info->flags & ROCKET_CLOSING) {
-               interruptible_sleep_on(&info->close_wait);
+       if (port->flags & ASYNC_CLOSING) {
+               retval = wait_for_completion_interruptible(&info->close_wait);
                free_page(page);
-               return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
+               if (retval)
+                       return retval;
+               return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
        }
 
        /*
@@ -941,26 +923,24 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
                info->xmit_buf = (unsigned char *) page;
 
        tty->driver_data = info;
-       info->tty = tty;
+       tty_port_tty_set(port, tty);
 
-       if (info->count++ == 0) {
+       if (port->count++ == 0) {
                atomic_inc(&rp_num_ports_open);
 
 #ifdef ROCKET_DEBUG_OPEN
-               printk(KERN_INFO "rocket mod++ = %d...", atomic_read(&rp_num_ports_open));
+               printk(KERN_INFO "rocket mod++ = %d...\n",
+                               atomic_read(&rp_num_ports_open));
 #endif
        }
 #ifdef ROCKET_DEBUG_OPEN
-       printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->count);
+       printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
 #endif
 
        /*
         * Info->count is now 1; so it's safe to sleep now.
         */
-       info->session = current->signal->session;
-       info->pgrp = process_group(current);
-
-       if ((info->flags & ROCKET_INITIALIZED) == 0) {
+       if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
                cp = &info->channel;
                sSetRxTrigger(cp, TRIG_1);
                if (sGetChanStatus(cp) & CD_ACT)
@@ -984,21 +964,21 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
                sEnRxFIFO(cp);
                sEnTransmit(cp);
 
-               info->flags |= ROCKET_INITIALIZED;
+               set_bit(ASYNCB_INITIALIZED, &info->port.flags);
 
                /*
                 * Set up the tty->alt_speed kludge
                 */
                if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
-                       info->tty->alt_speed = 57600;
+                       tty->alt_speed = 57600;
                if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
-                       info->tty->alt_speed = 115200;
+                       tty->alt_speed = 115200;
                if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
-                       info->tty->alt_speed = 230400;
+                       tty->alt_speed = 230400;
                if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
-                       info->tty->alt_speed = 460800;
+                       tty->alt_speed = 460800;
 
-               configure_r_port(info, NULL);
+               configure_r_port(tty, info, NULL);
                if (tty->termios->c_cflag & CBAUD) {
                        sSetDTR(cp);
                        sSetRTS(cp);
@@ -1007,7 +987,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
        /*  Starts (or resets) the maint polling loop */
        mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
 
-       retval = block_til_ready(tty, filp, info);
+       retval = tty_port_block_til_ready(port, tty, filp);
        if (retval) {
 #ifdef ROCKET_DEBUG_OPEN
                printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
@@ -1018,12 +998,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
 }
 
 /*
- *  Exception handler that closes a serial port. info->count is considered critical. 
+ *  Exception handler that closes a serial port. info->port.count is considered critical.
  */
 static void rp_close(struct tty_struct *tty, struct file *filp)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
-       unsigned long flags;
+       struct r_port *info = tty->driver_data;
+       struct tty_port *port = &info->port;
        int timeout;
        CHANNEL_t *cp;
        
@@ -1031,56 +1011,13 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
                return;
 
 #ifdef ROCKET_DEBUG_OPEN
-       printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->count);
+       printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count);
 #endif
 
-       if (tty_hung_up_p(filp))
+       if (tty_port_close_start(port, tty, filp) == 0)
                return;
-       spin_lock_irqsave(&info->slock, flags);
-
-       if ((tty->count == 1) && (info->count != 1)) {
-               /*
-                * Uh, oh.  tty->count is 1, which means that the tty
-                * structure will be freed.  Info->count should always
-                * be one in these conditions.  If it's greater than
-                * one, we've got real problems, since it means the
-                * serial port won't be shutdown.
-                */
-               printk(KERN_INFO "rp_close: bad serial port count; tty->count is 1, "
-                      "info->count is %d\n", info->count);
-               info->count = 1;
-       }
-       if (--info->count < 0) {
-               printk(KERN_INFO "rp_close: bad serial port count for ttyR%d: %d\n",
-                      info->line, info->count);
-               info->count = 0;
-       }
-       if (info->count) {
-               spin_unlock_irqrestore(&info->slock, flags);
-               return;
-       }
-       info->flags |= ROCKET_CLOSING;
-       spin_unlock_irqrestore(&info->slock, flags);
 
        cp = &info->channel;
-
-       /*
-        * Notify the line discpline to only process XON/XOFF characters
-        */
-       tty->closing = 1;
-
-       /*
-        * If transmission was throttled by the application request,
-        * just flush the xmit buffer.
-        */
-       if (tty->flow_stopped)
-               rp_flush_buffer(tty);
-
-       /*
-        * Wait for the transmit buffer to clear
-        */
-       if (info->closing_wait != ROCKET_CLOSING_WAIT_NONE)
-               tty_wait_until_sent(tty, info->closing_wait);
        /*
         * Before we drop DTR, make sure the UART transmitter
         * has completely drained; this is especially
@@ -1103,40 +1040,45 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
        if (C_HUPCL(tty))
                sClrDTR(cp);
 
-       if (TTY_DRIVER_FLUSH_BUFFER_EXISTS(tty))
-               TTY_DRIVER_FLUSH_BUFFER(tty);
+       rp_flush_buffer(tty);
                
        tty_ldisc_flush(tty);
 
        clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
 
-       if (info->blocked_open) {
-               if (info->close_delay) {
-                       msleep_interruptible(jiffies_to_msecs(info->close_delay));
+       /* We can't yet use tty_port_close_end as the buffer handling in this
+          driver is a bit different to the usual */
+
+       if (port->blocked_open) {
+               if (port->close_delay) {
+                       msleep_interruptible(jiffies_to_msecs(port->close_delay));
                }
-               wake_up_interruptible(&info->open_wait);
+               wake_up_interruptible(&port->open_wait);
        } else {
                if (info->xmit_buf) {
                        free_page((unsigned long) info->xmit_buf);
                        info->xmit_buf = NULL;
                }
        }
-       info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE);
+       info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
        tty->closing = 0;
-       wake_up_interruptible(&info->close_wait);
+       tty_port_tty_set(port, NULL);
+       wake_up_interruptible(&port->close_wait);
+       complete_all(&info->close_wait);
        atomic_dec(&rp_num_ports_open);
 
 #ifdef ROCKET_DEBUG_OPEN
-       printk(KERN_INFO "rocket mod-- = %d...", atomic_read(&rp_num_ports_open));
+       printk(KERN_INFO "rocket mod-- = %d...\n",
+                       atomic_read(&rp_num_ports_open));
        printk(KERN_INFO "rp_close ttyR%d complete shutdown\n", info->line);
 #endif
 
 }
 
 static void rp_set_termios(struct tty_struct *tty,
-                          struct termios *old_termios)
+                          struct ktermios *old_termios)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
        unsigned cflag;
 
@@ -1145,17 +1087,16 @@ static void rp_set_termios(struct tty_struct *tty,
 
        cflag = tty->termios->c_cflag;
 
-       if (cflag == old_termios->c_cflag)
-               return;
-
        /*
         * This driver doesn't support CS5 or CS6
         */
        if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
                tty->termios->c_cflag =
                    ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
+       /* Or CMSPAR */
+       tty->termios->c_cflag &= ~CMSPAR;
 
-       configure_r_port(info, old_termios);
+       configure_r_port(tty, info, old_termios);
 
        cp = &info->channel;
 
@@ -1178,13 +1119,13 @@ static void rp_set_termios(struct tty_struct *tty,
        }
 }
 
-static void rp_break(struct tty_struct *tty, int break_state)
+static int rp_break(struct tty_struct *tty, int break_state)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        unsigned long flags;
 
        if (rocket_paranoia_check(info, "rp_break"))
-               return;
+               return -EINVAL;
 
        spin_lock_irqsave(&info->slock, flags);
        if (break_state == -1)
@@ -1192,6 +1133,7 @@ static void rp_break(struct tty_struct *tty, int break_state)
        else
                sClrBreak(&info->channel);
        spin_unlock_irqrestore(&info->slock, flags);
+       return 0;
 }
 
 /*
@@ -1225,7 +1167,7 @@ static int sGetChanRI(CHANNEL_T * ChP)
  */
 static int rp_tiocmget(struct tty_struct *tty, struct file *file)
 {
-       struct r_port *info = (struct r_port *)tty->driver_data;
+       struct r_port *info = tty->driver_data;
        unsigned int control, result, ChanStatus;
 
        ChanStatus = sGetChanStatusLo(&info->channel);
@@ -1246,7 +1188,7 @@ static int rp_tiocmget(struct tty_struct *tty, struct file *file)
 static int rp_tiocmset(struct tty_struct *tty, struct file *file,
                    unsigned int set, unsigned int clear)
 {
-       struct r_port *info = (struct r_port *)tty->driver_data;
+       struct r_port *info = tty->driver_data;
 
        if (set & TIOCM_RTS)
                info->channel.TxControl[3] |= SET_RTS;
@@ -1257,7 +1199,7 @@ static int rp_tiocmset(struct tty_struct *tty, struct file *file,
        if (clear & TIOCM_DTR)
                info->channel.TxControl[3] &= ~SET_DTR;
 
-       sOutDW(info->channel.IndexAddr, *(DWord_t *) & (info->channel.TxControl[0]));
+       out32(info->channel.IndexAddr, info->channel.TxControl);
        return 0;
 }
 
@@ -1270,8 +1212,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
        memset(&tmp, 0, sizeof (tmp));
        tmp.line = info->line;
        tmp.flags = info->flags;
-       tmp.close_delay = info->close_delay;
-       tmp.closing_wait = info->closing_wait;
+       tmp.close_delay = info->port.close_delay;
+       tmp.closing_wait = info->port.closing_wait;
        tmp.port = rcktpt_io_addr[(info->line >> 5) & 3];
 
        if (copy_to_user(retinfo, &tmp, sizeof (*retinfo)))
@@ -1279,7 +1221,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
        return 0;
 }
 
-static int set_config(struct r_port *info, struct rocket_config __user *new_info)
+static int set_config(struct tty_struct *tty, struct r_port *info,
+                                       struct rocket_config __user *new_info)
 {
        struct rocket_config new_serial;
 
@@ -1291,24 +1234,24 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
                if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
                        return -EPERM;
                info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
-               configure_r_port(info, NULL);
+               configure_r_port(tty, info, NULL);
                return 0;
        }
 
        info->flags = ((info->flags & ~ROCKET_FLAGS) | (new_serial.flags & ROCKET_FLAGS));
-       info->close_delay = new_serial.close_delay;
-       info->closing_wait = new_serial.closing_wait;
+       info->port.close_delay = new_serial.close_delay;
+       info->port.closing_wait = new_serial.closing_wait;
 
        if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
-               info->tty->alt_speed = 57600;
+               tty->alt_speed = 57600;
        if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
-               info->tty->alt_speed = 115200;
+               tty->alt_speed = 115200;
        if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
-               info->tty->alt_speed = 230400;
+               tty->alt_speed = 230400;
        if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
-               info->tty->alt_speed = 460800;
+               tty->alt_speed = 460800;
 
-       configure_r_port(info, NULL);
+       configure_r_port(tty, info, NULL);
        return 0;
 }
 
@@ -1344,6 +1287,9 @@ static int reset_rm2(struct r_port *info, void __user *arg)
 {
        int reset;
 
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
        if (copy_from_user(&reset, arg, sizeof (int)))
                return -EFAULT;
        if (reset)
@@ -1372,36 +1318,45 @@ static int get_version(struct r_port *info, struct rocket_version __user *retver
 static int rp_ioctl(struct tty_struct *tty, struct file *file,
                    unsigned int cmd, unsigned long arg)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        void __user *argp = (void __user *)arg;
+       int ret = 0;
 
        if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
                return -ENXIO;
 
+       lock_kernel();
+
        switch (cmd) {
        case RCKP_GET_STRUCT:
                if (copy_to_user(argp, info, sizeof (struct r_port)))
-                       return -EFAULT;
-               return 0;
+                       ret = -EFAULT;
+               break;
        case RCKP_GET_CONFIG:
-               return get_config(info, argp);
+               ret = get_config(info, argp);
+               break;
        case RCKP_SET_CONFIG:
-               return set_config(info, argp);
+               ret = set_config(tty, info, argp);
+               break;
        case RCKP_GET_PORTS:
-               return get_ports(info, argp);
+               ret = get_ports(info, argp);
+               break;
        case RCKP_RESET_RM2:
-               return reset_rm2(info, argp);
+               ret = reset_rm2(info, argp);
+               break;
        case RCKP_GET_VERSION:
-               return get_version(info, argp);
+               ret = get_version(info, argp);
+               break;
        default:
-               return -ENOIOCTLCMD;
+               ret = -ENOIOCTLCMD;
        }
-       return 0;
+       unlock_kernel();
+       return ret;
 }
 
 static void rp_send_xchar(struct tty_struct *tty, char ch)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
 
        if (rocket_paranoia_check(info, "rp_send_xchar"))
@@ -1416,7 +1371,7 @@ static void rp_send_xchar(struct tty_struct *tty, char ch)
 
 static void rp_throttle(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
 
 #ifdef ROCKET_DEBUG_THROTTLE
@@ -1436,7 +1391,7 @@ static void rp_throttle(struct tty_struct *tty)
 
 static void rp_unthrottle(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
 #ifdef ROCKET_DEBUG_THROTTLE
        printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
@@ -1463,7 +1418,7 @@ static void rp_unthrottle(struct tty_struct *tty)
  */
 static void rp_stop(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
 
 #ifdef ROCKET_DEBUG_FLOW
        printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
@@ -1479,7 +1434,7 @@ static void rp_stop(struct tty_struct *tty)
 
 static void rp_start(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
 
 #ifdef ROCKET_DEBUG_FLOW
        printk(KERN_INFO "start %s: %d %d....\n", tty->name,
@@ -1499,7 +1454,7 @@ static void rp_start(struct tty_struct *tty)
  */
 static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
        unsigned long orig_jiffies;
        int check_time, exit_time;
@@ -1512,10 +1467,11 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
 
        orig_jiffies = jiffies;
 #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
-       printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...", timeout,
+       printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...\n", timeout,
               jiffies);
-       printk(KERN_INFO "cps=%d...", info->cps);
+       printk(KERN_INFO "cps=%d...\n", info->cps);
 #endif
+       lock_kernel();
        while (1) {
                txcnt = sGetTxCnt(cp);
                if (!txcnt) {
@@ -1535,13 +1491,15 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
                if (check_time == 0)
                        check_time = 1;
 #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
-               printk(KERN_INFO "txcnt = %d (jiff=%lu,check=%d)...", txcnt, jiffies, check_time);
+               printk(KERN_INFO "txcnt = %d (jiff=%lu,check=%d)...\n", txcnt,
+                               jiffies, check_time);
 #endif
                msleep_interruptible(jiffies_to_msecs(check_time));
                if (signal_pending(current))
                        break;
        }
-       current->state = TASK_RUNNING;
+       __set_current_state(TASK_RUNNING);
+       unlock_kernel();
 #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
        printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
 #endif
@@ -1553,24 +1511,22 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
 static void rp_hangup(struct tty_struct *tty)
 {
        CHANNEL_t *cp;
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
 
        if (rocket_paranoia_check(info, "rp_hangup"))
                return;
 
 #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_HANGUP))
-       printk(KERN_INFO "rp_hangup of ttyR%d...", info->line);
+       printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
 #endif
        rp_flush_buffer(tty);
-       if (info->flags & ROCKET_CLOSING)
+       if (info->port.flags & ASYNC_CLOSING)
                return;
-       if (info->count) 
+       if (info->port.count)
                atomic_dec(&rp_num_ports_open);
        clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
 
-       info->count = 0;
-       info->flags &= ~ROCKET_NORMAL_ACTIVE;
-       info->tty = NULL;
+       tty_port_hangup(&info->port);
 
        cp = &info->channel;
        sDisRxFIFO(cp);
@@ -1579,9 +1535,9 @@ static void rp_hangup(struct tty_struct *tty)
        sDisCTSFlowCtl(cp);
        sDisTxSoftFlowCtl(cp);
        sClrTxXOFF(cp);
-       info->flags &= ~ROCKET_INITIALIZED;
+       info->port.flags &= ~ASYNC_INITIALIZED;
 
-       wake_up_interruptible(&info->open_wait);
+       wake_up_interruptible(&info->port.open_wait);
 }
 
 /*
@@ -1591,20 +1547,23 @@ static void rp_hangup(struct tty_struct *tty)
  *  writing routines will write directly to transmit FIFO.
  *  Write buffer and counters protected by spinlocks
  */
-static void rp_put_char(struct tty_struct *tty, unsigned char ch)
+static int rp_put_char(struct tty_struct *tty, unsigned char ch)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
        unsigned long flags;
 
        if (rocket_paranoia_check(info, "rp_put_char"))
-               return;
+               return 0;
 
-       /*  Grab the port write semaphore, locking out other processes that try to write to this port */
-       down(&info->write_sem);
+       /*
+        * Grab the port write mutex, locking out other processes that try to
+        * write to this port
+        */
+       mutex_lock(&info->write_mtx);
 
 #ifdef ROCKET_DEBUG_WRITE
-       printk(KERN_INFO "rp_put_char %c...", ch);
+       printk(KERN_INFO "rp_put_char %c...\n", ch);
 #endif
 
        spin_lock_irqsave(&info->slock, flags);
@@ -1623,12 +1582,13 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
                info->xmit_fifo_room--;
        }
        spin_unlock_irqrestore(&info->slock, flags);
-       up(&info->write_sem);
+       mutex_unlock(&info->write_mtx);
+       return 1;
 }
 
 /*
  *  Exception handler - write routine, called when user app writes to the device.
- *  A per port write semaphore is used to protect from another process writing to
+ *  A per port write mutex is used to protect from another process writing to
  *  this port at the same time.  This other process could be running on the other CPU
  *  or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out). 
  *  Spinlocks protect the info xmit members.
@@ -1636,7 +1596,7 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
 static int rp_write(struct tty_struct *tty,
                    const unsigned char *buf, int count)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
        const unsigned char *b;
        int c, retval = 0;
@@ -1645,10 +1605,11 @@ static int rp_write(struct tty_struct *tty,
        if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
                return 0;
 
-       down_interruptible(&info->write_sem);
+       if (mutex_lock_interruptible(&info->write_mtx))
+               return -ERESTARTSYS;
 
 #ifdef ROCKET_DEBUG_WRITE
-       printk(KERN_INFO "rp_write %d chars...", count);
+       printk(KERN_INFO "rp_write %d chars...\n", count);
 #endif
        cp = &info->channel;
 
@@ -1685,10 +1646,11 @@ static int rp_write(struct tty_struct *tty,
 
        /*  Write remaining data into the port's xmit_buf */
        while (1) {
-               if (info->tty == 0)     /*   Seemingly obligatory check... */
+               /* Hung up ? */
+               if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags))
                        goto end;
-
-               c = min(count, min(XMIT_BUF_SIZE - info->xmit_cnt - 1, XMIT_BUF_SIZE - info->xmit_head));
+               c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
+               c = min(c, XMIT_BUF_SIZE - info->xmit_head);
                if (c <= 0)
                        break;
 
@@ -1712,12 +1674,11 @@ static int rp_write(struct tty_struct *tty,
 end:
        if (info->xmit_cnt < WAKEUP_CHARS) {
                tty_wakeup(tty);
-               wake_up_interruptible(&tty->write_wait);
 #ifdef ROCKETPORT_HAVE_POLL_WAIT
                wake_up_interruptible(&tty->poll_wait);
 #endif
        }
-       up(&info->write_sem);
+       mutex_unlock(&info->write_mtx);
        return retval;
 }
 
@@ -1728,7 +1689,7 @@ end:
  */
 static int rp_write_room(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        int ret;
 
        if (rocket_paranoia_check(info, "rp_write_room"))
@@ -1738,7 +1699,7 @@ static int rp_write_room(struct tty_struct *tty)
        if (ret < 0)
                ret = 0;
 #ifdef ROCKET_DEBUG_WRITE
-       printk(KERN_INFO "rp_write_room returns %d...", ret);
+       printk(KERN_INFO "rp_write_room returns %d...\n", ret);
 #endif
        return ret;
 }
@@ -1749,7 +1710,7 @@ static int rp_write_room(struct tty_struct *tty)
  */
 static int rp_chars_in_buffer(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
 
        if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
@@ -1758,7 +1719,7 @@ static int rp_chars_in_buffer(struct tty_struct *tty)
        cp = &info->channel;
 
 #ifdef ROCKET_DEBUG_WRITE
-       printk(KERN_INFO "rp_chars_in_buffer returns %d...", info->xmit_cnt);
+       printk(KERN_INFO "rp_chars_in_buffer returns %d...\n", info->xmit_cnt);
 #endif
        return info->xmit_cnt;
 }
@@ -1770,7 +1731,7 @@ static int rp_chars_in_buffer(struct tty_struct *tty)
  */
 static void rp_flush_buffer(struct tty_struct *tty)
 {
-       struct r_port *info = (struct r_port *) tty->driver_data;
+       struct r_port *info = tty->driver_data;
        CHANNEL_t *cp;
        unsigned long flags;
 
@@ -1781,7 +1742,6 @@ static void rp_flush_buffer(struct tty_struct *tty)
        info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
        spin_unlock_irqrestore(&info->slock, flags);
 
-       wake_up_interruptible(&tty->write_wait);
 #ifdef ROCKETPORT_HAVE_POLL_WAIT
        wake_up_interruptible(&tty->poll_wait);
 #endif
@@ -1793,12 +1753,18 @@ static void rp_flush_buffer(struct tty_struct *tty)
 
 #ifdef CONFIG_PCI
 
+static struct pci_device_id __devinitdata rocket_pci_ids[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
+       { }
+};
+MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
+
 /*
  *  Called when a PCI card is found.  Retrieves and stores model information,
  *  init's aiopic and serial port hardware.
  *  Inputs:  i is the board number (0-n)
  */
-__init int register_PCI(int i, struct pci_dev *dev)
+static __init int register_PCI(int i, struct pci_dev *dev)
 {
        int num_aiops, aiop, max_num_aiops, num_chan, chan;
        unsigned int aiopio[MAX_AIOPS_PER_BOARD];
@@ -1808,8 +1774,6 @@ __init int register_PCI(int i, struct pci_dev *dev)
        int fast_clock = 0;
        int altChanRingIndicator = 0;
        int ports_per_aiop = 8;
-       int ret;
-       unsigned int class_rev;
        WordIO_t ConfigIO = 0;
        ByteIO_t UPCIRingInd = 0;
 
@@ -1817,12 +1781,6 @@ __init int register_PCI(int i, struct pci_dev *dev)
                return 0;
 
        rcktpt_io_addr[i] = pci_resource_start(dev, 0);
-       ret = pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
-
-       if (ret) {
-               printk(KERN_INFO "  Error during register_PCI(), unable to read config dword \n");
-               return 0;
-       }
 
        rcktpt_type[i] = ROCKET_TYPE_NORMAL;
        rocketModel[i].loadrm2 = 0;
@@ -1976,8 +1934,9 @@ __init int register_PCI(int i, struct pci_dev *dev)
                ports_per_aiop = 6;
                str = "6-port";
 
-               /*  If class_rev is 1, the rocketmodem flash must be loaded.  If it is 2 it is a "socketed" version. */
-               if ((class_rev & 0xFF) == 1) {
+               /*  If revision is 1, the rocketmodem flash must be loaded.
+                *  If it is 2 it is a "socketed" version. */
+               if (dev->revision == 1) {
                        rcktpt_type[i] = ROCKET_TYPE_MODEMII;
                        rocketModel[i].loadrm2 = 1;
                } else {
@@ -1992,7 +1951,7 @@ __init int register_PCI(int i, struct pci_dev *dev)
                max_num_aiops = 1;
                ports_per_aiop = 4;
                str = "4-port";
-               if ((class_rev & 0xFF) == 1) {
+               if (dev->revision == 1) {
                        rcktpt_type[i] = ROCKET_TYPE_MODEMII;
                        rocketModel[i].loadrm2 = 1;
                } else {
@@ -2103,14 +2062,11 @@ __init int register_PCI(int i, struct pci_dev *dev)
        for (aiop = 0; aiop < max_num_aiops; aiop++)
                ctlp->AiopNumChan[aiop] = ports_per_aiop;
 
-       printk("Comtrol PCI controller #%d ID 0x%x found in bus:slot:fn %s at address %04lx, "
-            "%d AIOP(s) (%s)\n", i, dev->device, pci_name(dev),
-            rcktpt_io_addr[i], num_aiops, rocketModel[i].modelString);
-       printk(KERN_INFO "Installing %s, creating /dev/ttyR%d - %ld\n",
-              rocketModel[i].modelString,
-              rocketModel[i].startingPortNumber,
-              rocketModel[i].startingPortNumber +
-              rocketModel[i].numPorts - 1);
+       dev_info(&dev->dev, "comtrol PCI controller #%d found at "
+               "address %04lx, %d AIOP(s) (%s), creating ttyR%d - %ld\n",
+               i, rcktpt_io_addr[i], num_aiops, rocketModel[i].modelString,
+               rocketModel[i].startingPortNumber,
+               rocketModel[i].startingPortNumber + rocketModel[i].numPorts-1);
 
        if (num_aiops <= 0) {
                rcktpt_io_addr[i] = 0;
@@ -2133,10 +2089,10 @@ __init int register_PCI(int i, struct pci_dev *dev)
                num_chan = ports_per_aiop;
                for (chan = 0; chan < num_chan; chan++)
                        sPCIModemReset(ctlp, chan, 1);
-               mdelay(500);
+               msleep(500);
                for (chan = 0; chan < num_chan; chan++)
                        sPCIModemReset(ctlp, chan, 0);
-               mdelay(500);
+               msleep(500);
                rmSpeakerReset(ctlp, rocketModel[i].model);
        }
        return (1);
@@ -2154,7 +2110,7 @@ static int __init init_PCI(int boards_found)
        int count = 0;
 
        /*  Work through the PCI device list, pulling out ours */
-       while ((dev = pci_find_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
+       while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
                if (register_PCI(count + boards_found, dev))
                        count++;
        }
@@ -2182,7 +2138,9 @@ static int __init init_ISA(int i)
 
        /*  Reserve the IO region */
        if (!request_region(rcktpt_io_addr[i], 64, "Comtrol RocketPort")) {
-               printk(KERN_INFO "Unable to reserve IO region for configured ISA RocketPort at address 0x%lx, board not installed...\n", rcktpt_io_addr[i]);
+               printk(KERN_ERR "Unable to reserve IO region for configured "
+                               "ISA RocketPort at address 0x%lx, board not "
+                               "installed...\n", rcktpt_io_addr[i]);
                rcktpt_io_addr[i] = 0;
                return (0);
        }
@@ -2251,10 +2209,10 @@ static int __init init_ISA(int i)
                total_num_chan = num_chan;
                for (chan = 0; chan < num_chan; chan++)
                        sModemReset(ctlp, chan, 1);
-               mdelay(500);
+               msleep(500);
                for (chan = 0; chan < num_chan; chan++)
                        sModemReset(ctlp, chan, 0);
-               mdelay(500);
+               msleep(500);
                strcpy(rocketModel[i].modelString, "RocketModem ISA");
        } else {
                strcpy(rocketModel[i].modelString, "RocketPort ISA");
@@ -2274,7 +2232,7 @@ static int __init init_ISA(int i)
        return (1);
 }
 
-static struct tty_operations rocket_ops = {
+static const struct tty_operations rocket_ops = {
        .open = rp_open,
        .close = rp_close,
        .write = rp_write,
@@ -2296,37 +2254,24 @@ static struct tty_operations rocket_ops = {
        .tiocmset = rp_tiocmset,
 };
 
+static const struct tty_port_operations rocket_port_ops = {
+       .carrier_raised = carrier_raised,
+       .dtr_rts = dtr_rts,
+};
+
 /*
  * The module "startup" routine; it's run when the module is loaded.
  */
-int __init rp_init(void)
+static int __init rp_init(void)
 {
-       int retval, pci_boards_found, isa_boards_found, i;
+       int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
 
        printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
               ROCKET_VERSION, ROCKET_DATE);
 
        rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
        if (!rocket_driver)
-               return -ENOMEM;
-
-       /*
-        * Set up the timer channel.
-        */
-       init_timer(&rocket_timer);
-       rocket_timer.function = rp_do_poll;
-
-       /*
-        * Initialize the array of pointers to our own internal state
-        * structures.
-        */
-       memset(rp_table, 0, sizeof (rp_table));
-       memset(xmit_flags, 0, sizeof (xmit_flags));
-
-       for (i = 0; i < MAX_RP_PORTS; i++)
-               lineNumbers[i] = 0;
-       nextLineNumber = 0;
-       memset(rocketModel, 0, sizeof (rocketModel));
+               goto err;
 
        /*
         *  If board 1 is non-zero, there is at least one ISA configured.  If controller is 
@@ -2341,8 +2286,11 @@ int __init rp_init(void)
 
        /*  If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
        if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
-               printk(KERN_INFO "Unable to reserve IO region for first configured ISA RocketPort controller 0x%lx.  Driver exiting \n", controller);
-               return -EBUSY;
+               printk(KERN_ERR "Unable to reserve IO region for first "
+                       "configured ISA RocketPort controller 0x%lx.  "
+                       "Driver exiting\n", controller);
+               ret = -EBUSY;
+               goto err_tty;
        }
 
        /*  Store ISA variable retrieved from command line or .conf file. */
@@ -2366,8 +2314,7 @@ int __init rp_init(void)
         */
 
        rocket_driver->owner = THIS_MODULE;
-       rocket_driver->flags = TTY_DRIVER_NO_DEVFS;
-       rocket_driver->devfs_name = "tts/R";
+       rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV;
        rocket_driver->name = "ttyR";
        rocket_driver->driver_name = "Comtrol RocketPort";
        rocket_driver->major = TTY_ROCKET_MAJOR;
@@ -2377,16 +2324,17 @@ int __init rp_init(void)
        rocket_driver->init_termios = tty_std_termios;
        rocket_driver->init_termios.c_cflag =
            B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       rocket_driver->init_termios.c_ispeed = 9600;
+       rocket_driver->init_termios.c_ospeed = 9600;
 #ifdef ROCKET_SOFT_FLOW
-       rocket_driver->flags |= TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
+       rocket_driver->flags |= TTY_DRIVER_REAL_RAW;
 #endif
        tty_set_operations(rocket_driver, &rocket_ops);
 
-       retval = tty_register_driver(rocket_driver);
-       if (retval < 0) {
-               printk(KERN_INFO "Couldn't install tty RocketPort driver (error %d)\n", -retval);
-               put_tty_driver(rocket_driver);
-               return -1;
+       ret = tty_register_driver(rocket_driver);
+       if (ret < 0) {
+               printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
+               goto err_tty;
        }
 
 #ifdef ROCKET_DEBUG_OPEN
@@ -2413,17 +2361,20 @@ int __init rp_init(void)
        max_board = pci_boards_found + isa_boards_found;
 
        if (max_board == 0) {
-               printk(KERN_INFO "No rocketport ports found; unloading driver.\n");
-               del_timer_sync(&rocket_timer);
-               tty_unregister_driver(rocket_driver);
-               put_tty_driver(rocket_driver);
-               return -ENXIO;
+               printk(KERN_ERR "No rocketport ports found; unloading driver\n");
+               ret = -ENXIO;
+               goto err_ttyu;
        }
 
        return 0;
+err_ttyu:
+       tty_unregister_driver(rocket_driver);
+err_tty:
+       put_tty_driver(rocket_driver);
+err:
+       return ret;
 }
 
-#ifdef MODULE
 
 static void rp_cleanup_module(void)
 {
@@ -2434,14 +2385,16 @@ static void rp_cleanup_module(void)
 
        retval = tty_unregister_driver(rocket_driver);
        if (retval)
-               printk(KERN_INFO "Error %d while trying to unregister "
+               printk(KERN_ERR "Error %d while trying to unregister "
                       "rocketport driver\n", -retval);
-       put_tty_driver(rocket_driver);
 
-       for (i = 0; i < MAX_RP_PORTS; i++) {
-               if (rp_table[i])
+       for (i = 0; i < MAX_RP_PORTS; i++)
+               if (rp_table[i]) {
+                       tty_unregister_device(rocket_driver, i);
                        kfree(rp_table[i]);
-       }
+               }
+
+       put_tty_driver(rocket_driver);
 
        for (i = 0; i < NUM_BOARDS; i++) {
                if (rcktpt_io_addr[i] <= 0 || is_PCI[i])
@@ -2451,73 +2404,6 @@ static void rp_cleanup_module(void)
        if (controller)
                release_region(controller, 4);
 }
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-static Byte_t RData[RDATASIZE] = {
-       0x00, 0x09, 0xf6, 0x82,
-       0x02, 0x09, 0x86, 0xfb,
-       0x04, 0x09, 0x00, 0x0a,
-       0x06, 0x09, 0x01, 0x0a,
-       0x08, 0x09, 0x8a, 0x13,
-       0x0a, 0x09, 0xc5, 0x11,
-       0x0c, 0x09, 0x86, 0x85,
-       0x0e, 0x09, 0x20, 0x0a,
-       0x10, 0x09, 0x21, 0x0a,
-       0x12, 0x09, 0x41, 0xff,
-       0x14, 0x09, 0x82, 0x00,
-       0x16, 0x09, 0x82, 0x7b,
-       0x18, 0x09, 0x8a, 0x7d,
-       0x1a, 0x09, 0x88, 0x81,
-       0x1c, 0x09, 0x86, 0x7a,
-       0x1e, 0x09, 0x84, 0x81,
-       0x20, 0x09, 0x82, 0x7c,
-       0x22, 0x09, 0x0a, 0x0a
-};
-
-static Byte_t RRegData[RREGDATASIZE] = {
-       0x00, 0x09, 0xf6, 0x82, /* 00: Stop Rx processor */
-       0x08, 0x09, 0x8a, 0x13, /* 04: Tx software flow control */
-       0x0a, 0x09, 0xc5, 0x11, /* 08: XON char */
-       0x0c, 0x09, 0x86, 0x85, /* 0c: XANY */
-       0x12, 0x09, 0x41, 0xff, /* 10: Rx mask char */
-       0x14, 0x09, 0x82, 0x00, /* 14: Compare/Ignore #0 */
-       0x16, 0x09, 0x82, 0x7b, /* 18: Compare #1 */
-       0x18, 0x09, 0x8a, 0x7d, /* 1c: Compare #2 */
-       0x1a, 0x09, 0x88, 0x81, /* 20: Interrupt #1 */
-       0x1c, 0x09, 0x86, 0x7a, /* 24: Ignore/Replace #1 */
-       0x1e, 0x09, 0x84, 0x81, /* 28: Interrupt #2 */
-       0x20, 0x09, 0x82, 0x7c, /* 2c: Ignore/Replace #2 */
-       0x22, 0x09, 0x0a, 0x0a  /* 30: Rx FIFO Enable */
-};
-
-CONTROLLER_T sController[CTL_SIZE] = {
-       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
-        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
-       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
-        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
-       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
-        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
-       {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
-        {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}}
-};
-
-Byte_t sBitMapClrTbl[8] = {
-       0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f
-};
-
-Byte_t sBitMapSetTbl[8] = {
-       0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-};
-
-int sClockPrescale = 0x14;
 
 /***************************************************************************
 Function: sInitController
@@ -2554,22 +2440,22 @@ Call:     sInitController(CtlP,CtlNum,MudbacIO,AiopIOList,AiopIOListSize,
                       FREQ_4HZ - 4 Hertz
                    If IRQNum is set to 0 the Frequency parameter is
                    overidden, it is forced to a value of FREQ_DIS.
-          int PeriodicOnly: TRUE if all interrupts except the periodic
+          int PeriodicOnly: 1 if all interrupts except the periodic
                                interrupt are to be blocked.
-                            FALSE is both the periodic interrupt and
+                            0 is both the periodic interrupt and
                                other channel interrupts are allowed.
                             If IRQNum is set to 0 the PeriodicOnly parameter is
-                               overidden, it is forced to a value of FALSE.
+                               overidden, it is forced to a value of 0.
 Return:   int: Number of AIOPs on the controller, or CTLID_NULL if controller
                initialization failed.
 
 Comments:
           If periodic interrupts are to be disabled but AIOP interrupts
-          are allowed, set Frequency to FREQ_DIS and PeriodicOnly to FALSE.
+          are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
 
           If interrupts are to be completely disabled set IRQNum to 0.
 
-          Setting Frequency to FREQ_DIS and PeriodicOnly to TRUE is an
+          Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
           invalid combination.
 
           This function performs initialization of global interrupt modes,
@@ -2589,9 +2475,9 @@ Warnings: No range checking on any of the parameters is done.
           After this function all AIOPs on the controller are disabled,
           they can be enabled with sEnAiop().
 */
-int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
-                   ByteIO_t * AiopIOList, int AiopIOListSize, int IRQNum,
-                   Byte_t Frequency, int PeriodicOnly)
+static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
+                          ByteIO_t * AiopIOList, int AiopIOListSize,
+                          int IRQNum, Byte_t Frequency, int PeriodicOnly)
 {
        int i;
        ByteIO_t io;
@@ -2687,22 +2573,22 @@ Call:     sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
                       FREQ_4HZ - 4 Hertz
                    If IRQNum is set to 0 the Frequency parameter is
                    overidden, it is forced to a value of FREQ_DIS.
-          int PeriodicOnly: TRUE if all interrupts except the periodic
+          int PeriodicOnly: 1 if all interrupts except the periodic
                                interrupt are to be blocked.
-                            FALSE is both the periodic interrupt and
+                            0 is both the periodic interrupt and
                                other channel interrupts are allowed.
                             If IRQNum is set to 0 the PeriodicOnly parameter is
-                               overidden, it is forced to a value of FALSE.
+                               overidden, it is forced to a value of 0.
 Return:   int: Number of AIOPs on the controller, or CTLID_NULL if controller
                initialization failed.
 
 Comments:
           If periodic interrupts are to be disabled but AIOP interrupts
-          are allowed, set Frequency to FREQ_DIS and PeriodicOnly to FALSE.
+          are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
 
           If interrupts are to be completely disabled set IRQNum to 0.
 
-          Setting Frequency to FREQ_DIS and PeriodicOnly to TRUE is an
+          Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
           invalid combination.
 
           This function performs initialization of global interrupt modes,
@@ -2722,11 +2608,11 @@ Warnings: No range checking on any of the parameters is done.
           After this function all AIOPs on the controller are disabled,
           they can be enabled with sEnAiop().
 */
-int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
-                      ByteIO_t * AiopIOList, int AiopIOListSize,
-                      WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
-                      int PeriodicOnly, int altChanRingIndicator,
-                      int UPCIRingInd)
+static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
+                             ByteIO_t * AiopIOList, int AiopIOListSize,
+                             WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
+                             int PeriodicOnly, int altChanRingIndicator,
+                             int UPCIRingInd)
 {
        int i;
        ByteIO_t io;
@@ -2784,7 +2670,7 @@ Return:   int: Flag AIOPID_XXXX if a valid AIOP is found, where X
 Warnings: No context switches are allowed while executing this function.
 
 */
-int sReadAiopID(ByteIO_t io)
+static int sReadAiopID(ByteIO_t io)
 {
        Byte_t AiopID;          /* ID byte from AIOP */
 
@@ -2810,13 +2696,13 @@ Comments: The number of channels is determined by write/reads from identical
           AIOP, otherwise it is an 8 channel.
 Warnings: No context switches are allowed while executing this function.
 */
-int sReadAiopNumChan(WordIO_t io)
+static int sReadAiopNumChan(WordIO_t io)
 {
        Word_t x;
        static Byte_t R[4] = { 0x00, 0x00, 0x34, 0x12 };
 
        /* write to chan 0 SRAM */
-       sOutDW((DWordIO_t) io + _INDX_ADDR, *((DWord_t *) & R[0]));
+       out32((DWordIO_t) io + _INDX_ADDR, R);
        sOutW(io + _INDX_ADDR, 0);      /* read from SRAM, chan 0 */
        x = sInW(io + _INDX_DATA);
        sOutW(io + _INDX_ADDR, 0x4000); /* read from SRAM, chan 4 */
@@ -2834,15 +2720,15 @@ Call:     sInitChan(CtlP,ChP,AiopNum,ChanNum)
           CHANNEL_T *ChP; Ptr to channel structure
           int AiopNum; AIOP number within controller
           int ChanNum; Channel number within AIOP
-Return:   int: TRUE if initialization succeeded, FALSE if it fails because channel
+Return:   int: 1 if initialization succeeded, 0 if it fails because channel
                number exceeds number of channels available in AIOP.
 Comments: This function must be called before a channel can be used.
 Warnings: No range checking on any of the parameters is done.
 
           No context switches are allowed while executing this function.
 */
-int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
-             int ChanNum)
+static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
+                    int ChanNum)
 {
        int i;
        WordIO_t AiopIO;
@@ -2853,7 +2739,7 @@ int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
        int brd9600;
 
        if (ChanNum >= CtlP->AiopNumChan[AiopNum])
-               return (FALSE); /* exceeds num chans in AIOP */
+               return 0;       /* exceeds num chans in AIOP */
 
        /* Channel, AIOP, and controller identifiers */
        ChP->CtlP = CtlP;
@@ -2882,7 +2768,7 @@ int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
                R[1] = RData[i + 1] + 0x10 * ChanNum;
                R[2] = RData[i + 2];
                R[3] = RData[i + 3];
-               sOutDW(ChP->IndexAddr, *((DWord_t *) & R[0]));
+               out32(ChP->IndexAddr, R);
        }
 
        ChR = ChP->R;
@@ -2905,43 +2791,43 @@ int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
        ChP->BaudDiv[1] = (Byte_t) ((ChOff + _BAUD) >> 8);
        ChP->BaudDiv[2] = (Byte_t) brd9600;
        ChP->BaudDiv[3] = (Byte_t) (brd9600 >> 8);
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->BaudDiv[0]);
+       out32(ChP->IndexAddr, ChP->BaudDiv);
 
        ChP->TxControl[0] = (Byte_t) (ChOff + _TX_CTRL);
        ChP->TxControl[1] = (Byte_t) ((ChOff + _TX_CTRL) >> 8);
        ChP->TxControl[2] = 0;
        ChP->TxControl[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxControl[0]);
+       out32(ChP->IndexAddr, ChP->TxControl);
 
        ChP->RxControl[0] = (Byte_t) (ChOff + _RX_CTRL);
        ChP->RxControl[1] = (Byte_t) ((ChOff + _RX_CTRL) >> 8);
        ChP->RxControl[2] = 0;
        ChP->RxControl[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->RxControl[0]);
+       out32(ChP->IndexAddr, ChP->RxControl);
 
        ChP->TxEnables[0] = (Byte_t) (ChOff + _TX_ENBLS);
        ChP->TxEnables[1] = (Byte_t) ((ChOff + _TX_ENBLS) >> 8);
        ChP->TxEnables[2] = 0;
        ChP->TxEnables[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxEnables[0]);
+       out32(ChP->IndexAddr, ChP->TxEnables);
 
        ChP->TxCompare[0] = (Byte_t) (ChOff + _TXCMP1);
        ChP->TxCompare[1] = (Byte_t) ((ChOff + _TXCMP1) >> 8);
        ChP->TxCompare[2] = 0;
        ChP->TxCompare[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxCompare[0]);
+       out32(ChP->IndexAddr, ChP->TxCompare);
 
        ChP->TxReplace1[0] = (Byte_t) (ChOff + _TXREP1B1);
        ChP->TxReplace1[1] = (Byte_t) ((ChOff + _TXREP1B1) >> 8);
        ChP->TxReplace1[2] = 0;
        ChP->TxReplace1[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxReplace1[0]);
+       out32(ChP->IndexAddr, ChP->TxReplace1);
 
        ChP->TxReplace2[0] = (Byte_t) (ChOff + _TXREP2);
        ChP->TxReplace2[1] = (Byte_t) ((ChOff + _TXREP2) >> 8);
        ChP->TxReplace2[2] = 0;
        ChP->TxReplace2[3] = 0;
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxReplace2[0]);
+       out32(ChP->IndexAddr, ChP->TxReplace2);
 
        ChP->TxFIFOPtrs = ChOff + _TXF_OUTP;
        ChP->TxFIFO = ChOff + _TX_FIFO;
@@ -2968,7 +2854,7 @@ int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
        ChP->TxPrioBuf = ChOff + _TXP_BUF;
        sEnRxProcessor(ChP);    /* start the Rx processor */
 
-       return (TRUE);
+       return 1;
 }
 
 /***************************************************************************
@@ -2989,7 +2875,7 @@ Warnings: No context switches are allowed while executing this function.
           After calling this function a delay of 4 uS is required to ensure
           that the receive processor is no longer processing this channel.
 */
-void sStopRxProcessor(CHANNEL_T * ChP)
+static void sStopRxProcessor(CHANNEL_T * ChP)
 {
        Byte_t R[4];
 
@@ -2997,7 +2883,7 @@ void sStopRxProcessor(CHANNEL_T * ChP)
        R[1] = ChP->R[1];
        R[2] = 0x0a;
        R[3] = ChP->R[3];
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & R[0]);
+       out32(ChP->IndexAddr, R);
 }
 
 /***************************************************************************
@@ -3014,18 +2900,18 @@ Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
           this function.
 Warnings: No context switches are allowed while executing this function.
 */
-void sFlushRxFIFO(CHANNEL_T * ChP)
+static void sFlushRxFIFO(CHANNEL_T * ChP)
 {
        int i;
        Byte_t Ch;              /* channel number within AIOP */
-       int RxFIFOEnabled;      /* TRUE if Rx FIFO enabled */
+       int RxFIFOEnabled;      /* 1 if Rx FIFO enabled */
 
        if (sGetRxCnt(ChP) == 0)        /* Rx FIFO empty */
                return;         /* don't need to flush */
 
-       RxFIFOEnabled = FALSE;
+       RxFIFOEnabled = 0;
        if (ChP->R[0x32] == 0x08) {     /* Rx FIFO is enabled */
-               RxFIFOEnabled = TRUE;
+               RxFIFOEnabled = 1;
                sDisRxFIFO(ChP);        /* disable it */
                for (i = 0; i < 2000 / 200; i++)        /* delay 2 uS to allow proc to disable FIFO */
                        sInB(ChP->IntChan);     /* depends on bus i/o timing */
@@ -3056,18 +2942,18 @@ Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
           this function.
 Warnings: No context switches are allowed while executing this function.
 */
-void sFlushTxFIFO(CHANNEL_T * ChP)
+static void sFlushTxFIFO(CHANNEL_T * ChP)
 {
        int i;
        Byte_t Ch;              /* channel number within AIOP */
-       int TxEnabled;          /* TRUE if transmitter enabled */
+       int TxEnabled;          /* 1 if transmitter enabled */
 
        if (sGetTxCnt(ChP) == 0)        /* Tx FIFO empty */
                return;         /* don't need to flush */
 
-       TxEnabled = FALSE;
+       TxEnabled = 0;
        if (ChP->TxControl[3] & TX_ENABLE) {
-               TxEnabled = TRUE;
+               TxEnabled = 1;
                sDisTransmit(ChP);      /* disable transmitter */
        }
        sStopRxProcessor(ChP);  /* stop Rx processor */
@@ -3096,7 +2982,7 @@ Comments: The priority byte is transmitted before any data in the Tx FIFO.
 
 Warnings: No context switches are allowed while executing this function.
 */
-int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
+static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
 {
        Byte_t DWBuf[4];        /* buffer for double word writes */
        Word_t *WordPtr;        /* must be far because Win SS != DS */
@@ -3112,13 +2998,13 @@ int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
                *WordPtr = ChP->TxPrioBuf;      /* data byte address */
 
                DWBuf[2] = Data;        /* data byte value */
-               sOutDW(IndexAddr, *((DWord_t *) (&DWBuf[0])));  /* write it out */
+               out32(IndexAddr, DWBuf);        /* write it out */
 
                *WordPtr = ChP->TxPrioCnt;      /* Tx priority count address */
 
                DWBuf[2] = PRI_PEND + 1;        /* indicate 1 byte pending */
                DWBuf[3] = 0;   /* priority buffer pointer */
-               sOutDW(IndexAddr, *((DWord_t *) (&DWBuf[0])));  /* write it out */
+               out32(IndexAddr, DWBuf);        /* write it out */
        } else {                /* write it to Tx FIFO */
 
                sWriteTxByte(sGetTxRxDataIO(ChP), Data);
@@ -3158,18 +3044,18 @@ Comments: If an interrupt enable flag is set in Flags, that interrupt will be
           enable channel interrupts.  This would allow the global interrupt
           status register to be used to determine which AIOPs need service.
 */
-void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
+static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
 {
        Byte_t Mask;            /* Interrupt Mask Register */
 
        ChP->RxControl[2] |=
            ((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
 
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->RxControl[0]);
+       out32(ChP->IndexAddr, ChP->RxControl);
 
        ChP->TxControl[2] |= ((Byte_t) Flags & TXINT_EN);
 
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxControl[0]);
+       out32(ChP->IndexAddr, ChP->TxControl);
 
        if (Flags & CHANINT_EN) {
                Mask = sInB(ChP->IntMask) | sBitMapSetTbl[ChP->ChanNum];
@@ -3202,15 +3088,15 @@ Comments: If an interrupt flag is set in Flags, that interrupt will be
           this channel's bit from being set in the AIOP's Interrupt Channel
           Register.
 */
-void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
+static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
 {
        Byte_t Mask;            /* Interrupt Mask Register */
 
        ChP->RxControl[2] &=
            ~((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->RxControl[0]);
+       out32(ChP->IndexAddr, ChP->RxControl);
        ChP->TxControl[2] &= ~((Byte_t) Flags & TXINT_EN);
-       sOutDW(ChP->IndexAddr, *(DWord_t *) & ChP->TxControl[0]);
+       out32(ChP->IndexAddr, ChP->TxControl);
 
        if (Flags & CHANINT_EN) {
                Mask = sInB(ChP->IntMask) & sBitMapClrTbl[ChP->ChanNum];
@@ -3218,7 +3104,7 @@ void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
        }
 }
 
-void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
+static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
 {
        sOutB(ChP->CtlP->AiopIO[2], (mode & 0x18) | ChP->ChanNum);
 }
@@ -3227,7 +3113,7 @@ void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
  *  Not an official SSCI function, but how to reset RocketModems.
  *  ISA bus version
  */
-void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
+static void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
 {
        ByteIO_t addr;
        Byte_t val;
@@ -3252,7 +3138,7 @@ void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
  *  Not an official SSCI function, but how to reset RocketModems.
  *  PCI bus version
  */
-void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
+static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
 {
        ByteIO_t addr;