drivers/char/rocket portability fixes
[sfrench/cifs-2.6.git] / drivers / char / rocket.c
index 56cbba7b6ec098a7cbc1e770098e348ad3e736b1..f585bc8579e9929aba1e6f6d35b00991844e0f39 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
 
 #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 <asm/atomic.h>
+#include <asm/unaligned.h>
 #include <linux/bitops.h>
 #include <linux/spinlock.h>
 #include <linux/init.h>
@@ -304,8 +300,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
@@ -327,7 +323,7 @@ static void rp_do_receive(struct r_port *info,
 
        ToRecv = sGetRxCnt(cp);
 #ifdef ROCKET_DEBUG_INTR
-       printk(KERN_INFO "rp_do_receive(%d)...", ToRecv);
+       printk(KERN_INFO "rp_do_receive(%d)...\n", ToRecv);
 #endif
        if (ToRecv == 0)
                return;
@@ -340,7 +336,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);
@@ -354,15 +350,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);
@@ -434,12 +430,13 @@ 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");
+               printk(KERN_WARNING "rp: WARNING %s called with "
+                               "info->tty==NULL\n", __func__);
                clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
                return;
        }
@@ -463,7 +460,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
        }
 
@@ -480,7 +477,7 @@ static void rp_do_transmit(struct r_port *info)
        spin_unlock_irqrestore(&info->slock, flags);
 
 #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
 }
@@ -500,11 +497,13 @@ static void rp_handle_port(struct r_port *info)
                return;
 
        if ((info->flags & ROCKET_INITIALIZED) == 0) {
-               printk(KERN_INFO "rp: WARNING: rp_handle_port called with info->flags & NOT_INIT\n");
+               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");
+               printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
+                               "info->tty==NULL\n");
                return;
        }
        cp = &info->channel;
@@ -512,7 +511,7 @@ static void rp_handle_port(struct r_port *info)
 
        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 */
@@ -520,7 +519,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) {
@@ -548,8 +547,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;
@@ -562,7 +561,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);
@@ -637,7 +636,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
        /*  Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
        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;
        }
 
@@ -650,7 +650,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
        info->closing_wait = 3000;
        info->close_delay = 50;
        init_waitqueue_head(&info->open_wait);
-       init_waitqueue_head(&info->close_wait);
+       init_completion(&info->close_wait);
        info->flags &= ~ROCKET_MODE_MASK;
        switch (pc104[board][line]) {
        case 422:
@@ -667,7 +667,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;
        }
@@ -699,8 +700,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
        spin_lock_init(&info->slock);
        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);
 }
 
 /*
@@ -715,11 +716,10 @@ static void configure_r_port(struct r_port *info,
        unsigned rocketMode;
        int bits, baud, divisor;
        CHANNEL_t *cp;
+       struct ktermios *t = info->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) {
@@ -754,10 +754,7 @@ static void configure_r_port(struct r_port *info,
                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;
@@ -769,6 +766,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(info->tty, baud, baud);
+
        if (cflag & CRTSCTS) {
                info->intmask |= DELTA_CTS;
                sEnCTSFlowCtl(cp);
@@ -878,7 +878,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
        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);
+               if (wait_for_completion_interruptible(&info->close_wait))
+                       return -ERESTARTSYS;
                return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
        }
 
@@ -974,7 +975,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
        CHANNEL_t *cp;
        unsigned long page;
 
-       line = TTY_GET_LINE(tty);
+       line = tty->index;
        if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL))
                return -ENXIO;
 
@@ -983,8 +984,10 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
                return -ENOMEM;
 
        if (info->flags & ROCKET_CLOSING) {
-               interruptible_sleep_on(&info->close_wait);
+               retval = wait_for_completion_interruptible(&info->close_wait);
                free_page(page);
+               if (retval)
+                       return retval;
                return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
        }
 
@@ -1003,7 +1006,8 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
                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
@@ -1099,13 +1103,13 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
                 * 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);
+               printk(KERN_WARNING "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);
+               printk(KERN_WARNING "rp_close: bad serial port count for "
+                               "ttyR%d: %d\n", info->line, info->count);
                info->count = 0;
        }
        if (info->count) {
@@ -1156,8 +1160,7 @@ 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);
 
@@ -1176,11 +1179,12 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
        }
        info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE);
        tty->closing = 0;
-       wake_up_interruptible(&info->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
 
@@ -1198,15 +1202,14 @@ 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);
 
@@ -1310,7 +1313,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;
 }
 
@@ -1397,6 +1400,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)
@@ -1565,9 +1571,9 @@ 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
        while (1) {
                txcnt = sGetTxCnt(cp);
@@ -1588,7 +1594,8 @@ 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))
@@ -1612,7 +1619,7 @@ static void rp_hangup(struct tty_struct *tty)
                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)
@@ -1660,7 +1667,7 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
        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);
@@ -1705,7 +1712,7 @@ static int rp_write(struct tty_struct *tty,
                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;
 
@@ -1742,7 +1749,7 @@ 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... */
+               if (!info->tty) /*   Seemingly obligatory check... */
                        goto end;
 
                c = min(count, min(XMIT_BUF_SIZE - info->xmit_cnt - 1, XMIT_BUF_SIZE - info->xmit_head));
@@ -1794,7 +1801,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;
 }
@@ -1814,7 +1821,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;
 }
@@ -1869,8 +1876,6 @@ static __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;
 
@@ -1878,12 +1883,6 @@ static __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;
@@ -2037,8 +2036,9 @@ static __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 {
@@ -2053,7 +2053,7 @@ static __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 {
@@ -2164,14 +2164,11 @@ static __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;
@@ -2194,10 +2191,10 @@ static __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);
@@ -2243,7 +2240,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);
        }
@@ -2312,10 +2311,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");
@@ -2362,26 +2361,14 @@ static const struct tty_operations rocket_ops = {
  */
 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;
-
-       /*
-        * 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 
@@ -2396,8 +2383,11 @@ static 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. */
@@ -2434,15 +2424,14 @@ static int __init rp_init(void)
        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_DYNAMIC_DEV;
+       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
@@ -2469,14 +2458,18 @@ static 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;
 }
 
 
@@ -2489,12 +2482,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++)
-               kfree(rp_table[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])
@@ -2802,7 +2799,7 @@ static int sReadAiopNumChan(WordIO_t io)
        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 */
@@ -2868,7 +2865,7 @@ static 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;
@@ -2891,43 +2888,43 @@ static 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;
@@ -2983,7 +2980,7 @@ static 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);
 }
 
 /***************************************************************************
@@ -3098,13 +3095,13 @@ static 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);
@@ -3151,11 +3148,11 @@ static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
        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];
@@ -3194,9 +3191,9 @@ static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
 
        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];