Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[pandora-kernel.git] / drivers / char / istallion.c
index 1386d6a..d6e0315 100644 (file)
@@ -26,7 +26,6 @@
 
 /*****************************************************************************/
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/wait.h>
+#include <linux/eisa.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
 
-#ifdef CONFIG_PCI
 #include <linux/pci.h>
-#endif
 
 /*****************************************************************************/
 
@@ -136,6 +134,10 @@ static stlconf_t   stli_brdconf[] = {
 
 static int     stli_nrbrds = ARRAY_SIZE(stli_brdconf);
 
+/* stli_lock must NOT be taken holding brd_lock */
+static spinlock_t stli_lock;   /* TTY logic lock */
+static spinlock_t brd_lock;    /* Board logic lock */
+
 /*
  *     There is some experimental EISA board detection code in this driver.
  *     By default it is disabled, but for those that want to try it out,
@@ -172,14 +174,6 @@ static char        *stli_serialname = "ttyE";
 
 static struct tty_driver       *stli_serial;
 
-/*
- *     We will need to allocate a temporary write buffer for chars that
- *     come direct from user space. The problem is that a copy from user
- *     space might cause a page fault (typically on a system that is
- *     swapping!). All ports will share one buffer - since if the system
- *     is already swapping a shared buffer won't make things any worse.
- */
-static char                    *stli_tmpwritebuf;
 
 #define        STLI_TXBUFSIZE          4096
 
@@ -287,7 +281,6 @@ static char *stli_brdnames[] = {
 
 /*****************************************************************************/
 
-#ifdef MODULE
 /*
  *     Define some string labels for arguments passed from the module
  *     load line. These allow for easy board definitions, and easy
@@ -386,8 +379,6 @@ MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
 module_param_array(board3, charp, NULL, 0);
 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
 
-#endif
-
 /*
  *     Set up a default memory address table for EISA board probing.
  *     The default addresses are all bellow 1Mbyte, which has to be the
@@ -418,7 +409,7 @@ static int  stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
 #endif
 
 static struct pci_device_id istallion_pci_tbl[] = {
-       { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
+       { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
@@ -621,16 +612,6 @@ MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
 #define        MINOR2BRD(min)          (((min) & 0xc0) >> 6)
 #define        MINOR2PORT(min)         ((min) & 0x3f)
 
-/*
- *     Define a baud rate table that converts termios baud rate selector
- *     into the actual baud rate value. All baud rate calculations are based
- *     on the actual baud rate required.
- */
-static unsigned int    stli_baudrates[] = {
-       0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
-       9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
-};
-
 /*****************************************************************************/
 
 /*
@@ -648,14 +629,8 @@ static unsigned int        stli_baudrates[] = {
  *     Prototype all functions in this driver!
  */
 
-#ifdef MODULE
-static void    stli_argbrds(void);
 static int     stli_parsebrd(stlconf_t *confp, char **argp);
-
-static unsigned long   stli_atol(char *str);
-#endif
-
-int            stli_init(void);
+static int     stli_init(void);
 static int     stli_open(struct tty_struct *tty, struct file *filp);
 static void    stli_close(struct tty_struct *tty, struct file *filp);
 static int     stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
@@ -681,7 +656,7 @@ static int  stli_startbrd(stlibrd_t *brdp);
 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
 static int     stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
-static void    stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
+static void    stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
 static void    stli_poll(unsigned long arg);
 static int     stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
 static int     stli_initopen(stlibrd_t *brdp, stliport_t *portp);
@@ -692,7 +667,8 @@ static void stli_dohangup(void *arg);
 static int     stli_setport(stliport_t *portp);
 static int     stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
 static void    stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
-static void    stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
+static void    __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
+static void    stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
 static void    stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
 static void    stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
 static long    stli_mktiocm(unsigned long sigvalue);
@@ -762,7 +738,7 @@ static int  stli_initpcibrd(int brdtype, struct pci_dev *devp);
  *     will give access to the shared memory on the Stallion intelligent
  *     board. This is also a very useful debugging tool.
  */
-static struct file_operations  stli_fsiomem = {
+static const struct file_operations    stli_fsiomem = {
        .owner          = THIS_MODULE,
        .read           = stli_memread,
        .write          = stli_memwrite,
@@ -790,26 +766,14 @@ static int        stli_timeron;
 
 static struct class *istallion_class;
 
-#ifdef MODULE
-
 /*
  *     Loadable module initialization stuff.
  */
 
 static int __init istallion_module_init(void)
 {
-       unsigned long   flags;
-
-#ifdef DEBUG
-       printk("init_module()\n");
-#endif
-
-       save_flags(flags);
-       cli();
        stli_init();
-       restore_flags(flags);
-
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -818,33 +782,24 @@ static void __exit istallion_module_exit(void)
 {
        stlibrd_t       *brdp;
        stliport_t      *portp;
-       unsigned long   flags;
        int             i, j;
 
-#ifdef DEBUG
-       printk("cleanup_module()\n");
-#endif
-
        printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
                stli_drvversion);
 
-       save_flags(flags);
-       cli();
-
-/*
- *     Free up all allocated resources used by the ports. This includes
- *     memory and interrupts.
- */
+       /*
+        *      Free up all allocated resources used by the ports. This includes
+        *      memory and interrupts.
+        */
        if (stli_timeron) {
                stli_timeron = 0;
-               del_timer(&stli_timerlist);
+               del_timer_sync(&stli_timerlist);
        }
 
        i = tty_unregister_driver(stli_serial);
        if (i) {
                printk("STALLION: failed to un-register tty driver, "
                        "errno=%d\n", -i);
-               restore_flags(flags);
                return;
        }
        put_tty_driver(stli_serial);
@@ -855,16 +810,15 @@ static void __exit istallion_module_exit(void)
                printk("STALLION: failed to un-register serial memory device, "
                        "errno=%d\n", -i);
 
-       kfree(stli_tmpwritebuf);
        kfree(stli_txcookbuf);
 
        for (i = 0; (i < stli_nrbrds); i++) {
-               if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
+               if ((brdp = stli_brds[i]) == NULL)
                        continue;
                for (j = 0; (j < STL_MAXPORTS); j++) {
                        portp = brdp->ports[j];
-                       if (portp != (stliport_t *) NULL) {
-                               if (portp->tty != (struct tty_struct *) NULL)
+                       if (portp != NULL) {
+                               if (portp->tty != NULL)
                                        tty_hangup(portp->tty);
                                kfree(portp);
                        }
@@ -874,10 +828,8 @@ static void __exit istallion_module_exit(void)
                if (brdp->iosize > 0)
                        release_region(brdp->iobase, brdp->iosize);
                kfree(brdp);
-               stli_brds[i] = (stlibrd_t *) NULL;
+               stli_brds[i] = NULL;
        }
-
-       restore_flags(flags);
 }
 
 module_init(istallion_module_init);
@@ -891,19 +843,15 @@ module_exit(istallion_module_exit);
 
 static void stli_argbrds(void)
 {
-       stlconf_t       conf;
-       stlibrd_t       *brdp;
-       int             i;
-
-#ifdef DEBUG
-       printk("stli_argbrds()\n");
-#endif
+       stlconf_t conf;
+       stlibrd_t *brdp;
+       int i;
 
        for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
                memset(&conf, 0, sizeof(conf));
                if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
                        continue;
-               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
+               if ((brdp = stli_allocbrd()) == NULL)
                        continue;
                stli_nrbrds = i + 1;
                brdp->brdnr = i;
@@ -922,9 +870,9 @@ static void stli_argbrds(void)
 
 static unsigned long stli_atol(char *str)
 {
-       unsigned long   val;
-       int             base, c;
-       char            *sp;
+       unsigned long val;
+       int base, c;
+       char *sp;
 
        val = 0;
        sp = str;
@@ -958,15 +906,11 @@ static unsigned long stli_atol(char *str)
 
 static int stli_parsebrd(stlconf_t *confp, char **argp)
 {
-       char    *sp;
-       int     i;
-
-#ifdef DEBUG
-       printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
-#endif
+       char *sp;
+       int i;
 
-       if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
-               return(0);
+       if (argp[0] == NULL || *argp[0] == 0)
+               return 0;
 
        for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
                *sp = TOLOWER(*sp);
@@ -981,47 +925,40 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
        }
 
        confp->brdtype = stli_brdstr[i].type;
-       if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
+       if (argp[1] != NULL && *argp[1] != 0)
                confp->ioaddr1 = stli_atol(argp[1]);
-       if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
+       if (argp[2] !=  NULL && *argp[2] != 0)
                confp->memaddr = stli_atol(argp[2]);
        return(1);
 }
 
-#endif
-
 /*****************************************************************************/
 
 static int stli_open(struct tty_struct *tty, struct file *filp)
 {
-       stlibrd_t       *brdp;
-       stliport_t      *portp;
-       unsigned int    minordev;
-       int             brdnr, portnr, rc;
-
-#ifdef DEBUG
-       printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
-               (int) filp, tty->name);
-#endif
+       stlibrd_t *brdp;
+       stliport_t *portp;
+       unsigned int minordev;
+       int brdnr, portnr, rc;
 
        minordev = tty->index;
        brdnr = MINOR2BRD(minordev);
        if (brdnr >= stli_nrbrds)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stli_brds[brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
        if ((brdp->state & BST_STARTED) == 0)
-               return(-ENODEV);
+               return -ENODEV;
        portnr = MINOR2PORT(minordev);
        if ((portnr < 0) || (portnr > brdp->nrports))
-               return(-ENODEV);
+               return -ENODEV;
 
        portp = brdp->ports[portnr];
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
+       if (portp == NULL)
+               return -ENODEV;
        if (portp->devnr < 1)
-               return(-ENODEV);
+               return -ENODEV;
 
 
 /*
@@ -1033,8 +970,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        if (portp->flags & ASYNC_CLOSING) {
                interruptible_sleep_on(&portp->close_wait);
                if (portp->flags & ASYNC_HUP_NOTIFY)
-                       return(-EAGAIN);
-               return(-ERESTARTSYS);
+                       return -EAGAIN;
+               return -ERESTARTSYS;
        }
 
 /*
@@ -1050,7 +987,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_INITIALIZING, &portp->state));
        if (signal_pending(current))
-               return(-ERESTARTSYS);
+               return -ERESTARTSYS;
 
        if ((portp->flags & ASYNC_INITIALIZED) == 0) {
                set_bit(ST_INITIALIZING, &portp->state);
@@ -1061,7 +998,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
                clear_bit(ST_INITIALIZING, &portp->state);
                wake_up_interruptible(&portp->raw_wait);
                if (rc < 0)
-                       return(rc);
+                       return rc;
        }
 
 /*
@@ -1073,8 +1010,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        if (portp->flags & ASYNC_CLOSING) {
                interruptible_sleep_on(&portp->close_wait);
                if (portp->flags & ASYNC_HUP_NOTIFY)
-                       return(-EAGAIN);
-               return(-ERESTARTSYS);
+                       return -EAGAIN;
+               return -ERESTARTSYS;
        }
 
 /*
@@ -1084,38 +1021,33 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
  */
        if (!(filp->f_flags & O_NONBLOCK)) {
                if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
-                       return(rc);
+                       return rc;
        }
        portp->flags |= ASYNC_NORMAL_ACTIVE;
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
 
 static void stli_close(struct tty_struct *tty, struct file *filp)
 {
-       stlibrd_t       *brdp;
-       stliport_t      *portp;
-       unsigned long   flags;
-
-#ifdef DEBUG
-       printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
-#endif
+       stlibrd_t *brdp;
+       stliport_t *portp;
+       unsigned long flags;
 
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&stli_lock, flags);
        if (tty_hung_up_p(filp)) {
-               restore_flags(flags);
+               spin_unlock_irqrestore(&stli_lock, flags);
                return;
        }
        if ((tty->count == 1) && (portp->refcount != 1))
                portp->refcount = 1;
        if (portp->refcount-- > 1) {
-               restore_flags(flags);
+               spin_unlock_irqrestore(&stli_lock, flags);
                return;
        }
 
@@ -1130,6 +1062,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        tty->closing = 1;
+       spin_unlock_irqrestore(&stli_lock, flags);
+
        if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
                tty_wait_until_sent(tty, portp->closing_wait);
 
@@ -1153,7 +1087,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
        stli_flushbuffer(tty);
 
        tty->closing = 0;
-       portp->tty = (struct tty_struct *) NULL;
+       portp->tty = NULL;
 
        if (portp->openwaitcnt) {
                if (portp->close_delay)
@@ -1163,7 +1097,6 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 
        portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
        wake_up_interruptible(&portp->close_wait);
-       restore_flags(flags);
 }
 
 /*****************************************************************************/
@@ -1178,45 +1111,41 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 
 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
 {
-       struct tty_struct       *tty;
-       asynotify_t             nt;
-       asyport_t               aport;
-       int                     rc;
-
-#ifdef DEBUG
-       printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
-#endif
+       struct tty_struct *tty;
+       asynotify_t nt;
+       asyport_t aport;
+       int rc;
 
        if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
-               return(rc);
+               return rc;
 
        memset(&nt, 0, sizeof(asynotify_t));
        nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
        nt.signal = SG_DCD;
        if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
            sizeof(asynotify_t), 0)) < 0)
-               return(rc);
+               return rc;
 
        tty = portp->tty;
-       if (tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
+       if (tty == NULL)
+               return -ENODEV;
        stli_mkasyport(portp, &aport, tty->termios);
        if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
            sizeof(asyport_t), 0)) < 0)
-               return(rc);
+               return rc;
 
        set_bit(ST_GETSIGS, &portp->state);
        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
            sizeof(asysigs_t), 1)) < 0)
-               return(rc);
+               return rc;
        if (test_and_clear_bit(ST_GETSIGS, &portp->state))
                portp->sigs = stli_mktiocm(portp->asig.sigvalue);
        stli_mkasysigs(&portp->asig, 1, 1);
        if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
            sizeof(asysigs_t), 0)) < 0)
-               return(rc);
+               return rc;
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -1230,22 +1159,15 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
 
 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
 {
-       volatile cdkhdr_t       *hdrp;
-       volatile cdkctrl_t      *cp;
-       volatile unsigned char  *bits;
-       unsigned long           flags;
-       int                     rc;
-
-#ifdef DEBUG
-       printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
-               (int) brdp, (int) portp, (int) arg, wait);
-#endif
+       cdkhdr_t __iomem *hdrp;
+       cdkctrl_t __iomem *cp;
+       unsigned char __iomem *bits;
+       unsigned long flags;
+       int rc;
 
 /*
  *     Send a message to the slave to open this port.
  */
-       save_flags(flags);
-       cli();
 
 /*
  *     Slave is already closing this port. This can happen if a hangup
@@ -1256,7 +1178,6 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CLOSING, &portp->state));
        if (signal_pending(current)) {
-               restore_flags(flags);
                return -ERESTARTSYS;
        }
 
@@ -1265,19 +1186,20 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
  *     memory. Once the message is in set the service bits to say that
  *     this port wants service.
  */
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
-       cp->openarg = arg;
-       cp->open = 1;
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       writel(arg, &cp->openarg);
+       writeb(1, &cp->open);
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       *bits |= portp->portbit;
+       writeb(readb(bits) | portp->portbit, bits);
        EBRDDISABLE(brdp);
 
        if (wait == 0) {
-               restore_flags(flags);
-               return(0);
+               spin_unlock_irqrestore(&brd_lock, flags);
+               return 0;
        }
 
 /*
@@ -1286,15 +1208,16 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
  */
        rc = 0;
        set_bit(ST_OPENING, &portp->state);
+       spin_unlock_irqrestore(&brd_lock, flags);
+
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_OPENING, &portp->state));
        if (signal_pending(current))
                rc = -ERESTARTSYS;
-       restore_flags(flags);
 
        if ((rc == 0) && (portp->rc != 0))
                rc = -EIO;
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -1307,19 +1230,11 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
 
 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
 {
-       volatile cdkhdr_t       *hdrp;
-       volatile cdkctrl_t      *cp;
-       volatile unsigned char  *bits;
-       unsigned long           flags;
-       int                     rc;
-
-#ifdef DEBUG
-       printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
-               (int) brdp, (int) portp, (int) arg, wait);
-#endif
-
-       save_flags(flags);
-       cli();
+       cdkhdr_t __iomem *hdrp;
+       cdkctrl_t __iomem *cp;
+       unsigned char __iomem *bits;
+       unsigned long flags;
+       int rc;
 
 /*
  *     Slave is already closing this port. This can happen if a hangup
@@ -1329,7 +1244,6 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
                wait_event_interruptible(portp->raw_wait,
                                !test_bit(ST_CLOSING, &portp->state));
                if (signal_pending(current)) {
-                       restore_flags(flags);
                        return -ERESTARTSYS;
                }
        }
@@ -1337,21 +1251,22 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
 /*
  *     Write the close command into shared memory.
  */
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
-       cp->closearg = arg;
-       cp->close = 1;
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       writel(arg, &cp->closearg);
+       writeb(1, &cp->close);
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       *bits |= portp->portbit;
+       writeb(readb(bits) |portp->portbit, bits);
        EBRDDISABLE(brdp);
 
        set_bit(ST_CLOSING, &portp->state);
-       if (wait == 0) {
-               restore_flags(flags);
-               return(0);
-       }
+       spin_unlock_irqrestore(&brd_lock, flags);
+
+       if (wait == 0)
+               return 0;
 
 /*
  *     Slave is in action, so now we must wait for the open acknowledgment
@@ -1362,11 +1277,10 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
                        !test_bit(ST_CLOSING, &portp->state));
        if (signal_pending(current))
                rc = -ERESTARTSYS;
-       restore_flags(flags);
 
        if ((rc == 0) && (portp->rc != 0))
                rc = -EIO;
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -1380,36 +1294,21 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
 
 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
 {
-       unsigned long   flags;
-
-#ifdef DEBUG
-       printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
-               "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
-               (int) arg, size, copyback);
-#endif
-
-       save_flags(flags);
-       cli();
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CMDING, &portp->state));
-       if (signal_pending(current)) {
-               restore_flags(flags);
+       if (signal_pending(current))
                return -ERESTARTSYS;
-       }
 
        stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
 
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CMDING, &portp->state));
-       if (signal_pending(current)) {
-               restore_flags(flags);
+       if (signal_pending(current))
                return -ERESTARTSYS;
-       }
-       restore_flags(flags);
 
        if (portp->rc != 0)
-               return(-EIO);
-       return(0);
+               return -EIO;
+       return 0;
 }
 
 /*****************************************************************************/
@@ -1421,22 +1320,18 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
 
 static int stli_setport(stliport_t *portp)
 {
-       stlibrd_t       *brdp;
-       asyport_t       aport;
-
-#ifdef DEBUG
-       printk("stli_setport(portp=%x)\n", (int) portp);
-#endif
+       stlibrd_t *brdp;
+       asyport_t aport;
 
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
-       if (portp->tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
-       if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
-               return(-ENODEV);
+       if (portp == NULL)
+               return -ENODEV;
+       if (portp->tty == NULL)
+               return -ENODEV;
+       if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
+               return -ENODEV;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
 
        stli_mkasyport(portp, &aport, portp->tty->termios);
        return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
@@ -1451,13 +1346,8 @@ static int stli_setport(stliport_t *portp)
 
 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
 {
-       unsigned long   flags;
-       int             rc, doclocal;
-
-#ifdef DEBUG
-       printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
-               (int) brdp, (int) portp, (int) filp);
-#endif
+       unsigned long flags;
+       int rc, doclocal;
 
        rc = 0;
        doclocal = 0;
@@ -1465,11 +1355,11 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
        if (portp->tty->termios->c_cflag & CLOCAL)
                doclocal++;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&stli_lock, flags);
        portp->openwaitcnt++;
        if (! tty_hung_up_p(filp))
                portp->refcount--;
+       spin_unlock_irqrestore(&stli_lock, flags);
 
        for (;;) {
                stli_mkasysigs(&portp->asig, 1, 1);
@@ -1495,12 +1385,13 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
                interruptible_sleep_on(&portp->open_wait);
        }
 
+       spin_lock_irqsave(&stli_lock, flags);
        if (! tty_hung_up_p(filp))
                portp->refcount++;
        portp->openwaitcnt--;
-       restore_flags(flags);
+       spin_unlock_irqrestore(&stli_lock, flags);
 
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -1513,46 +1404,38 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
 
 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
-       volatile cdkasy_t       *ap;
-       volatile cdkhdr_t       *hdrp;
-       volatile unsigned char  *bits;
-       unsigned char           *shbuf, *chbuf;
-       stliport_t              *portp;
-       stlibrd_t               *brdp;
-       unsigned int            len, stlen, head, tail, size;
-       unsigned long           flags;
-
-#ifdef DEBUG
-       printk("stli_write(tty=%x,buf=%x,count=%d)\n",
-               (int) tty, (int) buf, count);
-#endif
+       cdkasy_t __iomem *ap;
+       cdkhdr_t __iomem *hdrp;
+       unsigned char __iomem *bits;
+       unsigned char __iomem *shbuf;
+       unsigned char *chbuf;
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned int len, stlen, head, tail, size;
+       unsigned long flags;
 
-       if ((tty == (struct tty_struct *) NULL) ||
-           (stli_tmpwritebuf == (char *) NULL))
-               return(0);
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return(0);
+       if (portp == NULL)
+               return 0;
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
        chbuf = (unsigned char *) buf;
 
 /*
  *     All data is now local, shove as much as possible into shared memory.
  */
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
-       head = (unsigned int) ap->txq.head;
-       tail = (unsigned int) ap->txq.tail;
-       if (tail != ((unsigned int) ap->txq.tail))
-               tail = (unsigned int) ap->txq.tail;
+       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+       head = (unsigned int) readw(&ap->txq.head);
+       tail = (unsigned int) readw(&ap->txq.tail);
+       if (tail != ((unsigned int) readw(&ap->txq.tail)))
+               tail = (unsigned int) readw(&ap->txq.tail);
        size = portp->txsize;
        if (head >= tail) {
                len = size - (head - tail) - 1;
@@ -1564,11 +1447,11 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
 
        len = MIN(len, count);
        count = 0;
-       shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
+       shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
 
        while (len > 0) {
                stlen = MIN(len, stlen);
-               memcpy((shbuf + head), chbuf, stlen);
+               memcpy_toio(shbuf + head, chbuf, stlen);
                chbuf += stlen;
                len -= stlen;
                count += stlen;
@@ -1579,20 +1462,19 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
                }
        }
 
-       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
-       ap->txq.head = head;
+       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+       writew(head, &ap->txq.head);
        if (test_bit(ST_TXBUSY, &portp->state)) {
-               if (ap->changed.data & DT_TXEMPTY)
-                       ap->changed.data &= ~DT_TXEMPTY;
+               if (readl(&ap->changed.data) & DT_TXEMPTY)
+                       writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
        }
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       *bits |= portp->portbit;
+       writeb(readb(bits) | portp->portbit, bits);
        set_bit(ST_TXBUSY, &portp->state);
        EBRDDISABLE(brdp);
-
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 
        return(count);
 }
@@ -1609,14 +1491,8 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
 
 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
 {
-#ifdef DEBUG
-       printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
        if (tty != stli_txcooktty) {
-               if (stli_txcooktty != (struct tty_struct *) NULL)
+               if (stli_txcooktty != NULL)
                        stli_flushchars(stli_txcooktty);
                stli_txcooktty = tty;
        }
@@ -1636,29 +1512,26 @@ static void stli_putchar(struct tty_struct *tty, unsigned char ch)
 
 static void stli_flushchars(struct tty_struct *tty)
 {
-       volatile cdkhdr_t       *hdrp;
-       volatile unsigned char  *bits;
-       volatile cdkasy_t       *ap;
-       struct tty_struct       *cooktty;
-       stliport_t              *portp;
-       stlibrd_t               *brdp;
-       unsigned int            len, stlen, head, tail, size, count, cooksize;
-       unsigned char           *buf, *shbuf;
-       unsigned long           flags;
-
-#ifdef DEBUG
-       printk("stli_flushchars(tty=%x)\n", (int) tty);
-#endif
+       cdkhdr_t __iomem *hdrp;
+       unsigned char __iomem *bits;
+       cdkasy_t __iomem *ap;
+       struct tty_struct *cooktty;
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned int len, stlen, head, tail, size, count, cooksize;
+       unsigned char *buf;
+       unsigned char __iomem *shbuf;
+       unsigned long flags;
 
        cooksize = stli_txcooksize;
        cooktty = stli_txcooktty;
        stli_txcooksize = 0;
        stli_txcookrealsize = 0;
-       stli_txcooktty = (struct tty_struct *) NULL;
+       stli_txcooktty = NULL;
 
-       if (tty == (struct tty_struct *) NULL)
+       if (tty == NULL)
                return;
-       if (cooktty == (struct tty_struct *) NULL)
+       if (cooktty == NULL)
                return;
        if (tty != cooktty)
                tty = cooktty;
@@ -1666,23 +1539,22 @@ static void stli_flushchars(struct tty_struct *tty)
                return;
 
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
 
-       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
-       head = (unsigned int) ap->txq.head;
-       tail = (unsigned int) ap->txq.tail;
-       if (tail != ((unsigned int) ap->txq.tail))
-               tail = (unsigned int) ap->txq.tail;
+       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+       head = (unsigned int) readw(&ap->txq.head);
+       tail = (unsigned int) readw(&ap->txq.tail);
+       if (tail != ((unsigned int) readw(&ap->txq.tail)))
+               tail = (unsigned int) readw(&ap->txq.tail);
        size = portp->txsize;
        if (head >= tail) {
                len = size - (head - tail) - 1;
@@ -1699,7 +1571,7 @@ static void stli_flushchars(struct tty_struct *tty)
 
        while (len > 0) {
                stlen = MIN(len, stlen);
-               memcpy((shbuf + head), buf, stlen);
+               memcpy_toio(shbuf + head, buf, stlen);
                buf += stlen;
                len -= stlen;
                count += stlen;
@@ -1710,73 +1582,66 @@ static void stli_flushchars(struct tty_struct *tty)
                }
        }
 
-       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
-       ap->txq.head = head;
+       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+       writew(head, &ap->txq.head);
 
        if (test_bit(ST_TXBUSY, &portp->state)) {
-               if (ap->changed.data & DT_TXEMPTY)
-                       ap->changed.data &= ~DT_TXEMPTY;
+               if (readl(&ap->changed.data) & DT_TXEMPTY)
+                       writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
        }
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       *bits |= portp->portbit;
+       writeb(readb(bits) | portp->portbit, bits);
        set_bit(ST_TXBUSY, &portp->state);
 
        EBRDDISABLE(brdp);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 }
 
 /*****************************************************************************/
 
 static int stli_writeroom(struct tty_struct *tty)
 {
-       volatile cdkasyrq_t     *rp;
-       stliport_t              *portp;
-       stlibrd_t               *brdp;
-       unsigned int            head, tail, len;
-       unsigned long           flags;
-
-#ifdef DEBUG
-       printk("stli_writeroom(tty=%x)\n", (int) tty);
-#endif
+       cdkasyrq_t __iomem *rp;
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned int head, tail, len;
+       unsigned long flags;
 
-       if (tty == (struct tty_struct *) NULL)
-               return(0);
        if (tty == stli_txcooktty) {
                if (stli_txcookrealsize != 0) {
                        len = stli_txcookrealsize - stli_txcooksize;
-                       return(len);
+                       return len;
                }
        }
 
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return(0);
+       if (portp == NULL)
+               return 0;
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
-       head = (unsigned int) rp->head;
-       tail = (unsigned int) rp->tail;
-       if (tail != ((unsigned int) rp->tail))
-               tail = (unsigned int) rp->tail;
+       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
+       head = (unsigned int) readw(&rp->head);
+       tail = (unsigned int) readw(&rp->tail);
+       if (tail != ((unsigned int) readw(&rp->tail)))
+               tail = (unsigned int) readw(&rp->tail);
        len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
        len--;
        EBRDDISABLE(brdp);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 
        if (tty == stli_txcooktty) {
                stli_txcookrealsize = len;
                len -= stli_txcooksize;
        }
-       return(len);
+       return len;
 }
 
 /*****************************************************************************/
@@ -1791,44 +1656,37 @@ static int stli_writeroom(struct tty_struct *tty)
 
 static int stli_charsinbuffer(struct tty_struct *tty)
 {
-       volatile cdkasyrq_t     *rp;
-       stliport_t              *portp;
-       stlibrd_t               *brdp;
-       unsigned int            head, tail, len;
-       unsigned long           flags;
-
-#ifdef DEBUG
-       printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
-#endif
+       cdkasyrq_t __iomem *rp;
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned int head, tail, len;
+       unsigned long flags;
 
-       if (tty == (struct tty_struct *) NULL)
-               return(0);
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return(0);
+       if (portp == NULL)
+               return 0;
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
-       head = (unsigned int) rp->head;
-       tail = (unsigned int) rp->tail;
-       if (tail != ((unsigned int) rp->tail))
-               tail = (unsigned int) rp->tail;
+       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
+       head = (unsigned int) readw(&rp->head);
+       tail = (unsigned int) readw(&rp->tail);
+       if (tail != ((unsigned int) readw(&rp->tail)))
+               tail = (unsigned int) readw(&rp->tail);
        len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
        if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
                len = 1;
        EBRDDISABLE(brdp);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 
-       return(len);
+       return len;
 }
 
 /*****************************************************************************/
@@ -1839,12 +1697,8 @@ static int stli_charsinbuffer(struct tty_struct *tty)
 
 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
 {
-       struct serial_struct    sio;
-       stlibrd_t               *brdp;
-
-#ifdef DEBUG
-       printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
-#endif
+       struct serial_struct sio;
+       stlibrd_t *brdp;
 
        memset(&sio, 0, sizeof(struct serial_struct));
        sio.type = PORT_UNKNOWN;
@@ -1859,7 +1713,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
        sio.hub6 = 0;
 
        brdp = stli_brds[portp->brdnr];
-       if (brdp != (stlibrd_t *) NULL)
+       if (brdp != NULL)
                sio.port = brdp->iobase;
                
        return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
@@ -1876,12 +1730,8 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
 
 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
 {
-       struct serial_struct    sio;
-       int                     rc;
-
-#ifdef DEBUG
-       printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
-#endif
+       struct serial_struct sio;
+       int rc;
 
        if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
                return -EFAULT;
@@ -1890,7 +1740,7 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
                    (sio.close_delay != portp->close_delay) ||
                    ((sio.flags & ~ASYNC_USR_MASK) !=
                    (portp->flags & ~ASYNC_USR_MASK)))
-                       return(-EPERM);
+                       return -EPERM;
        } 
 
        portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
@@ -1901,8 +1751,8 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
        portp->custom_divisor = sio.custom_divisor;
 
        if ((rc = stli_setport(portp)) < 0)
-               return(rc);
-       return(0);
+               return rc;
+       return 0;
 }
 
 /*****************************************************************************/
@@ -1913,19 +1763,19 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
        stlibrd_t *brdp;
        int rc;
 
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+       if (portp == NULL)
+               return -ENODEV;
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return(-EIO);
+               return -EIO;
 
        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
                               &portp->asig, sizeof(asysigs_t), 1)) < 0)
-               return(rc);
+               return rc;
 
        return stli_mktiocm(portp->asig.sigvalue);
 }
@@ -1937,15 +1787,15 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
        stlibrd_t *brdp;
        int rts = -1, dtr = -1;
 
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+       if (portp == NULL)
+               return -ENODEV;
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return(-EIO);
+               return -EIO;
 
        if (set & TIOCM_RTS)
                rts = 1;
@@ -1964,32 +1814,25 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
 
 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
 {
-       stliport_t      *portp;
-       stlibrd_t       *brdp;
-       unsigned int    ival;
-       int             rc;
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned int ival;
+       int rc;
        void __user *argp = (void __user *)arg;
 
-#ifdef DEBUG
-       printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
-               (int) tty, (int) file, cmd, (int) arg);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return(-ENODEV);
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return(0);
+       if (portp == NULL)
+               return -ENODEV;
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+               return 0;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(0);
+       if (brdp == NULL)
+               return 0;
 
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
            (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
                if (tty->flags & (1 << TTY_IO_ERROR))
-                       return(-EIO);
+                       return -EIO;
        }
 
        rc = 0;
@@ -2036,7 +1879,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
                break;
        }
 
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -2048,24 +1891,20 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
 
 static void stli_settermios(struct tty_struct *tty, struct termios *old)
 {
-       stliport_t      *portp;
-       stlibrd_t       *brdp;
-       struct termios  *tiosp;
-       asyport_t       aport;
-
-#ifdef DEBUG
-       printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
-#endif
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       struct termios *tiosp;
+       asyport_t aport;
 
-       if (tty == (struct tty_struct *) NULL)
+       if (tty == NULL)
                return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
        tiosp = tty->termios;
@@ -2098,18 +1937,9 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
 
 static void stli_throttle(struct tty_struct *tty)
 {
-       stliport_t      *portp;
-
-#ifdef DEBUG
-       printk("stli_throttle(tty=%x)\n", (int) tty);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
-       portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       stliport_t      *portp = tty->driver_data;
+       if (portp == NULL)
                return;
-
        set_bit(ST_RXSTOP, &portp->state);
 }
 
@@ -2123,88 +1953,30 @@ static void stli_throttle(struct tty_struct *tty)
 
 static void stli_unthrottle(struct tty_struct *tty)
 {
-       stliport_t      *portp;
-
-#ifdef DEBUG
-       printk("stli_unthrottle(tty=%x)\n", (int) tty);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
-       portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       stliport_t      *portp = tty->driver_data;
+       if (portp == NULL)
                return;
-
        clear_bit(ST_RXSTOP, &portp->state);
 }
 
 /*****************************************************************************/
 
 /*
- *     Stop the transmitter. Basically to do this we will just turn TX
- *     interrupts off.
+ *     Stop the transmitter.
  */
 
 static void stli_stop(struct tty_struct *tty)
 {
-       stlibrd_t       *brdp;
-       stliport_t      *portp;
-       asyctrl_t       actrl;
-
-#ifdef DEBUG
-       printk("stli_stop(tty=%x)\n", (int) tty);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
-       portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return;
-       brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return;
-
-       memset(&actrl, 0, sizeof(asyctrl_t));
-       actrl.txctrl = CT_STOPFLOW;
-#if 0
-       stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
-#endif
 }
 
 /*****************************************************************************/
 
 /*
- *     Start the transmitter again. Just turn TX interrupts back on.
+ *     Start the transmitter again.
  */
 
 static void stli_start(struct tty_struct *tty)
 {
-       stliport_t      *portp;
-       stlibrd_t       *brdp;
-       asyctrl_t       actrl;
-
-#ifdef DEBUG
-       printk("stli_start(tty=%x)\n", (int) tty);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
-       portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
-               return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return;
-       brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return;
-
-       memset(&actrl, 0, sizeof(asyctrl_t));
-       actrl.txctrl = CT_STARTFLOW;
-#if 0
-       stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
-#endif
 }
 
 /*****************************************************************************/
@@ -2220,22 +1992,9 @@ static void stli_start(struct tty_struct *tty)
 
 static void stli_dohangup(void *arg)
 {
-       stliport_t      *portp;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
-#endif
-
-       /*
-        * FIXME: There's a module removal race here: tty_hangup
-        * calls schedule_work which will call into this
-        * driver later.
-        */
-       portp = (stliport_t *) arg;
-       if (portp != (stliport_t *) NULL) {
-               if (portp->tty != (struct tty_struct *) NULL) {
-                       tty_hangup(portp->tty);
-               }
+       stliport_t *portp = (stliport_t *) arg;
+       if (portp->tty != NULL) {
+               tty_hangup(portp->tty);
        }
 }
 
@@ -2250,31 +2009,25 @@ static void stli_dohangup(void *arg)
 
 static void stli_hangup(struct tty_struct *tty)
 {
-       stliport_t      *portp;
-       stlibrd_t       *brdp;
-       unsigned long   flags;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
-#endif
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned long flags;
 
-       if (tty == (struct tty_struct *) NULL)
-               return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
        portp->flags &= ~ASYNC_INITIALIZED;
 
-       save_flags(flags);
-       cli();
-       if (! test_bit(ST_CLOSING, &portp->state))
+       if (!test_bit(ST_CLOSING, &portp->state))
                stli_rawclose(brdp, portp, 0, 0);
+
+       spin_lock_irqsave(&stli_lock, flags);
        if (tty->termios->c_cflag & HUPCL) {
                stli_mkasysigs(&portp->asig, 0, 0);
                if (test_bit(ST_CMDING, &portp->state)) {
@@ -2286,14 +2039,15 @@ static void stli_hangup(struct tty_struct *tty)
                                &portp->asig, sizeof(asysigs_t), 0);
                }
        }
-       restore_flags(flags);
 
        clear_bit(ST_TXBUSY, &portp->state);
        clear_bit(ST_RXSTOP, &portp->state);
        set_bit(TTY_IO_ERROR, &tty->flags);
-       portp->tty = (struct tty_struct *) NULL;
+       portp->tty = NULL;
        portp->flags &= ~ASYNC_NORMAL_ACTIVE;
        portp->refcount = 0;
+       spin_unlock_irqrestore(&stli_lock, flags);
+
        wake_up_interruptible(&portp->open_wait);
 }
 
@@ -2308,29 +2062,22 @@ static void stli_hangup(struct tty_struct *tty)
 
 static void stli_flushbuffer(struct tty_struct *tty)
 {
-       stliport_t      *portp;
-       stlibrd_t       *brdp;
-       unsigned long   ftype, flags;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
-#endif
+       stliport_t *portp;
+       stlibrd_t *brdp;
+       unsigned long ftype, flags;
 
-       if (tty == (struct tty_struct *) NULL)
-               return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
        if (tty == stli_txcooktty) {
-               stli_txcooktty = (struct tty_struct *) NULL;
+               stli_txcooktty = NULL;
                stli_txcooksize = 0;
                stli_txcookrealsize = 0;
        }
@@ -2342,15 +2089,10 @@ static void stli_flushbuffer(struct tty_struct *tty)
                        ftype |= FLUSHRX;
                        clear_bit(ST_DOFLUSHRX, &portp->state);
                }
-               stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
-                       sizeof(unsigned long), 0);
+               __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
        }
-       restore_flags(flags);
-
-       wake_up_interruptible(&tty->write_wait);
-       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-           tty->ldisc.write_wakeup)
-               (tty->ldisc.write_wakeup)(tty);
+       spin_unlock_irqrestore(&brd_lock, flags);
+       tty_wakeup(tty);
 }
 
 /*****************************************************************************/
@@ -2360,55 +2102,31 @@ static void stli_breakctl(struct tty_struct *tty, int state)
        stlibrd_t       *brdp;
        stliport_t      *portp;
        long            arg;
-       /* long savestate, savetime; */
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
-/*
- *     Due to a bug in the tty send_break() code we need to preserve
- *     the current process state and timeout...
-       savetime = current->timeout;
-       savestate = current->state;
- */
-
        arg = (state == -1) ? BREAKON : BREAKOFF;
        stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
-
-/*
- *
-       current->timeout = savetime;
-       current->state = savestate;
- */
 }
 
 /*****************************************************************************/
 
 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
 {
-       stliport_t      *portp;
-       unsigned long   tend;
+       stliport_t *portp;
+       unsigned long tend;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
+       if (tty == NULL)
                return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
 
        if (timeout == 0)
@@ -2432,19 +2150,13 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
        stliport_t      *portp;
        asyctrl_t       actrl;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
-#endif
-
-       if (tty == (struct tty_struct *) NULL)
-               return;
        portp = tty->driver_data;
-       if (portp == (stliport_t *) NULL)
+       if (portp == NULL)
                return;
-       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
+       if (brdp == NULL)
                return;
 
        memset(&actrl, 0, sizeof(asyctrl_t));
@@ -2456,7 +2168,6 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
                actrl.txctrl = CT_SENDCHR;
                actrl.tximdch = ch;
        }
-
        stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
 }
 
@@ -2472,17 +2183,17 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
 
 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
 {
-       char    *sp, *uart;
-       int     rc, cnt;
+       char *sp, *uart;
+       int rc, cnt;
 
        rc = stli_portcmdstats(portp);
 
        uart = "UNKNOWN";
        if (brdp->state & BST_STARTED) {
                switch (stli_comstats.hwid) {
-               case 0:         uart = "2681"; break;
-               case 1:         uart = "SC26198"; break;
-               default:        uart = "CD1400"; break;
+               case 0: uart = "2681"; break;
+               case 1: uart = "SC26198"; break;
+               default:uart = "CD1400"; break;
                }
        }
 
@@ -2533,17 +2244,11 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
 
 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
 {
-       stlibrd_t       *brdp;
-       stliport_t      *portp;
-       int             brdnr, portnr, totalport;
-       int             curoff, maxoff;
-       char            *pos;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
-               "data=%x\n", (int) page, (int) start, (int) off, count,
-               (int) eof, (int) data);
-#endif
+       stlibrd_t *brdp;
+       stliport_t *portp;
+       int brdnr, portnr, totalport;
+       int curoff, maxoff;
+       char *pos;
 
        pos = page;
        totalport = 0;
@@ -2564,7 +2269,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
  */
        for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
                brdp = stli_brds[brdnr];
-               if (brdp == (stlibrd_t *) NULL)
+               if (brdp == NULL)
                        continue;
                if (brdp->state == 0)
                        continue;
@@ -2579,7 +2284,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
                for (portnr = 0; (portnr < brdp->nrports); portnr++,
                    totalport++) {
                        portp = brdp->ports[portnr];
-                       if (portp == (stliport_t *) NULL)
+                       if (portp == NULL)
                                continue;
                        if (off >= (curoff += MAXLINE))
                                continue;
@@ -2606,49 +2311,54 @@ stli_readdone:
  *     a poll routine that does not have user context. Therefore you cannot
  *     copy back directly into user space, or to the kernel stack of a
  *     process. This routine does not sleep, so can be called from anywhere.
+ *
+ *     The caller must hold the brd_lock (see also stli_sendcmd the usual
+ *     entry point)
  */
 
-static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
+static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
 {
-       volatile cdkhdr_t       *hdrp;
-       volatile cdkctrl_t      *cp;
-       volatile unsigned char  *bits;
-       unsigned long           flags;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
-               "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
-               (int) arg, size, copyback);
-#endif
+       cdkhdr_t __iomem *hdrp;
+       cdkctrl_t __iomem *cp;
+       unsigned char __iomem *bits;
+       unsigned long flags;
 
-       save_flags(flags);
-       cli();
+       spin_lock_irqsave(&brd_lock, flags);
 
        if (test_bit(ST_CMDING, &portp->state)) {
                printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
                                (int) cmd);
-               restore_flags(flags);
+               spin_unlock_irqrestore(&brd_lock, flags);
                return;
        }
 
        EBRDENABLE(brdp);
-       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
        if (size > 0) {
-               memcpy((void *) &(cp->args[0]), arg, size);
+               memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
                if (copyback) {
                        portp->argp = arg;
                        portp->argsize = size;
                }
        }
-       cp->status = 0;
-       cp->cmd = cmd;
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+       writel(0, &cp->status);
+       writel(cmd, &cp->cmd);
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       *bits |= portp->portbit;
+       writeb(readb(bits) | portp->portbit, bits);
        set_bit(ST_CMDING, &portp->state);
        EBRDDISABLE(brdp);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
+}
+
+static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
+{
+       unsigned long           flags;
+
+       spin_lock_irqsave(&brd_lock, flags);
+       __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
+       spin_unlock_irqrestore(&brd_lock, flags);
 }
 
 /*****************************************************************************/
@@ -2663,28 +2373,23 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
 
 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
 {
-       volatile cdkasyrq_t     *rp;
-       volatile char           *shbuf;
+       cdkasyrq_t __iomem *rp;
+       char __iomem *shbuf;
        struct tty_struct       *tty;
-       unsigned int            head, tail, size;
-       unsigned int            len, stlen;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
-                       (int) brdp, (int) portp);
-#endif
+       unsigned int head, tail, size;
+       unsigned int len, stlen;
 
        if (test_bit(ST_RXSTOP, &portp->state))
                return;
        tty = portp->tty;
-       if (tty == (struct tty_struct *) NULL)
+       if (tty == NULL)
                return;
 
-       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
-       head = (unsigned int) rp->head;
-       if (head != ((unsigned int) rp->head))
-               head = (unsigned int) rp->head;
-       tail = (unsigned int) rp->tail;
+       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
+       head = (unsigned int) readw(&rp->head);
+       if (head != ((unsigned int) readw(&rp->head)))
+               head = (unsigned int) readw(&rp->head);
+       tail = (unsigned int) readw(&rp->tail);
        size = portp->rxsize;
        if (head >= tail) {
                len = head - tail;
@@ -2695,12 +2400,15 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
        }
 
        len = tty_buffer_request_room(tty, len);
-       /* FIXME : iomap ? */
-       shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
+
+       shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
 
        while (len > 0) {
+               unsigned char *cptr;
+
                stlen = MIN(len, stlen);
-               tty_insert_flip_string(tty, (char *)(shbuf + tail), stlen);
+               tty_prepare_flip_string(tty, &cptr, stlen);
+               memcpy_fromio(cptr, shbuf + tail, stlen);
                len -= stlen;
                tail += stlen;
                if (tail >= size) {
@@ -2708,8 +2416,8 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
                        stlen = head;
                }
        }
-       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
-       rp->tail = tail;
+       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
+       writew(tail, &rp->tail);
 
        if (head != tail)
                set_bit(ST_RXING, &portp->state);
@@ -2725,9 +2433,9 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  *     difficult to deal with them here.
  */
 
-static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
+static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
 {
-       int     cmd;
+       int cmd;
 
        if (test_bit(ST_DOSIGS, &portp->state)) {
                if (test_bit(ST_DOFLUSHTX, &portp->state) &&
@@ -2742,10 +2450,10 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
                clear_bit(ST_DOFLUSHTX, &portp->state);
                clear_bit(ST_DOFLUSHRX, &portp->state);
                clear_bit(ST_DOSIGS, &portp->state);
-               memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
+               memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
                        sizeof(asysigs_t));
-               cp->status = 0;
-               cp->cmd = cmd;
+               writel(0, &cp->status);
+               writel(cmd, &cp->cmd);
                set_bit(ST_CMDING, &portp->state);
        } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
            test_bit(ST_DOFLUSHRX, &portp->state)) {
@@ -2753,9 +2461,9 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
                cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
                clear_bit(ST_DOFLUSHTX, &portp->state);
                clear_bit(ST_DOFLUSHRX, &portp->state);
-               memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
-               cp->status = 0;
-               cp->cmd = A_FLUSH;
+               memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
+               writel(0, &cp->status);
+               writel(A_FLUSH, &cp->cmd);
                set_bit(ST_CMDING, &portp->state);
        }
 }
@@ -2775,30 +2483,25 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
 
 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
 {
-       volatile cdkasy_t       *ap;
-       volatile cdkctrl_t      *cp;
-       struct tty_struct       *tty;
-       asynotify_t             nt;
-       unsigned long           oldsigs;
-       int                     rc, donerx;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
-                       (int) brdp, channr);
-#endif
-
-       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+       cdkasy_t __iomem *ap;
+       cdkctrl_t __iomem *cp;
+       struct tty_struct *tty;
+       asynotify_t nt;
+       unsigned long oldsigs;
+       int rc, donerx;
+
+       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
        cp = &ap->ctrl;
 
 /*
  *     Check if we are waiting for an open completion message.
  */
        if (test_bit(ST_OPENING, &portp->state)) {
-               rc = (int) cp->openarg;
-               if ((cp->open == 0) && (rc != 0)) {
+               rc = readl(&cp->openarg);
+               if (readb(&cp->open) == 0 && rc != 0) {
                        if (rc > 0)
                                rc--;
-                       cp->openarg = 0;
+                       writel(0, &cp->openarg);
                        portp->rc = rc;
                        clear_bit(ST_OPENING, &portp->state);
                        wake_up_interruptible(&portp->raw_wait);
@@ -2809,11 +2512,11 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     Check if we are waiting for a close completion message.
  */
        if (test_bit(ST_CLOSING, &portp->state)) {
-               rc = (int) cp->closearg;
-               if ((cp->close == 0) && (rc != 0)) {
+               rc = (int) readl(&cp->closearg);
+               if (readb(&cp->close) == 0 && rc != 0) {
                        if (rc > 0)
                                rc--;
-                       cp->closearg = 0;
+                       writel(0, &cp->closearg);
                        portp->rc = rc;
                        clear_bit(ST_CLOSING, &portp->state);
                        wake_up_interruptible(&portp->raw_wait);
@@ -2825,16 +2528,16 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     need to copy out the command results associated with this command.
  */
        if (test_bit(ST_CMDING, &portp->state)) {
-               rc = cp->status;
-               if ((cp->cmd == 0) && (rc != 0)) {
+               rc = readl(&cp->status);
+               if (readl(&cp->cmd) == 0 && rc != 0) {
                        if (rc > 0)
                                rc--;
-                       if (portp->argp != (void *) NULL) {
-                               memcpy(portp->argp, (void *) &(cp->args[0]),
+                       if (portp->argp != NULL) {
+                               memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
                                        portp->argsize);
-                               portp->argp = (void *) NULL;
+                               portp->argp = NULL;
                        }
-                       cp->status = 0;
+                       writel(0, &cp->status);
                        portp->rc = rc;
                        clear_bit(ST_CMDING, &portp->state);
                        stli_dodelaycmd(portp, cp);
@@ -2873,18 +2576,15 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
                if (nt.data & DT_TXEMPTY)
                        clear_bit(ST_TXBUSY, &portp->state);
                if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
-                       if (tty != (struct tty_struct *) NULL) {
-                               if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                                   tty->ldisc.write_wakeup) {
-                                       (tty->ldisc.write_wakeup)(tty);
-                                       EBRDENABLE(brdp);
-                               }
+                       if (tty != NULL) {
+                               tty_wakeup(tty);
+                               EBRDENABLE(brdp);
                                wake_up_interruptible(&tty->write_wait);
                        }
                }
 
                if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
-                       if (tty != (struct tty_struct *) NULL) {
+                       if (tty != NULL) {
                                tty_insert_flip_char(tty, 0, TTY_BREAK);
                                if (portp->flags & ASYNC_SAK) {
                                        do_SAK(tty);
@@ -2928,14 +2628,14 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     at the cdk header structure.
  */
 
-static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
+static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
 {
-       stliport_t      *portp;
-       unsigned char   hostbits[(STL_MAXCHANS / 8) + 1];
-       unsigned char   slavebits[(STL_MAXCHANS / 8) + 1];
-       unsigned char   *slavep;
-       int             bitpos, bitat, bitsize;
-       int             channr, nrdevs, slavebitchange;
+       stliport_t *portp;
+       unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
+       unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
+       unsigned char __iomem *slavep;
+       int bitpos, bitat, bitsize;
+       int channr, nrdevs, slavebitchange;
 
        bitsize = brdp->bitsize;
        nrdevs = brdp->nrdevs;
@@ -2947,7 +2647,7 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
  *     8 service bits at a time in the inner loop, so we can bypass
  *     the lot if none of them want service.
  */
-       memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
+       memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
                bitsize);
 
        memset(&slavebits[0], 0, bitsize);
@@ -2974,11 +2674,11 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
  *     service may initiate more slave requests.
  */
        if (slavebitchange) {
-               hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-               slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
+               hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+               slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
                for (bitpos = 0; (bitpos < bitsize); bitpos++) {
-                       if (slavebits[bitpos])
-                               slavep[bitpos] &= ~slavebits[bitpos];
+                       if (readb(slavebits + bitpos))
+                               writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
                }
        }
 }
@@ -2996,9 +2696,9 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
 
 static void stli_poll(unsigned long arg)
 {
-       volatile cdkhdr_t       *hdrp;
-       stlibrd_t               *brdp;
-       int                     brdnr;
+       cdkhdr_t __iomem *hdrp;
+       stlibrd_t *brdp;
+       int brdnr;
 
        stli_timerlist.expires = STLI_TIMEOUT;
        add_timer(&stli_timerlist);
@@ -3008,16 +2708,18 @@ static void stli_poll(unsigned long arg)
  */
        for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
                brdp = stli_brds[brdnr];
-               if (brdp == (stlibrd_t *) NULL)
+               if (brdp == NULL)
                        continue;
                if ((brdp->state & BST_STARTED) == 0)
                        continue;
 
+               spin_lock(&brd_lock);
                EBRDENABLE(brdp);
-               hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-               if (hdrp->hostreq)
+               hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+               if (readb(&hdrp->hostreq))
                        stli_brdpoll(brdp, hdrp);
                EBRDDISABLE(brdp);
+               spin_unlock(&brd_lock);
        }
 }
 
@@ -3030,25 +2732,12 @@ static void stli_poll(unsigned long arg)
 
 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
 {
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
-               (int) portp, (int) pp, (int) tiosp);
-#endif
-
        memset(pp, 0, sizeof(asyport_t));
 
 /*
  *     Start of by setting the baud, char size, parity and stop bit info.
  */
-       pp->baudout = tiosp->c_cflag & CBAUD;
-       if (pp->baudout & CBAUDEX) {
-               pp->baudout &= ~CBAUDEX;
-               if ((pp->baudout < 1) || (pp->baudout > 4))
-                       tiosp->c_cflag &= ~CBAUDEX;
-               else
-                       pp->baudout += 15;
-       }
-       pp->baudout = stli_baudrates[pp->baudout];
+       pp->baudout = tty_get_baud_rate(portp->tty);
        if ((tiosp->c_cflag & CBAUD) == B38400) {
                if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
                        pp->baudout = 57600;
@@ -3153,11 +2842,6 @@ static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tio
 
 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
 {
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
-                       (int) sp, dtr, rts);
-#endif
-
        memset(sp, 0, sizeof(asysigs_t));
        if (dtr >= 0) {
                sp->signal |= SG_DTR;
@@ -3178,13 +2862,7 @@ static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
 
 static long stli_mktiocm(unsigned long sigvalue)
 {
-       long    tiocm;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
-#endif
-
-       tiocm = 0;
+       long    tiocm = 0;
        tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
        tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
        tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
@@ -3206,10 +2884,6 @@ static int stli_initports(stlibrd_t *brdp)
        stliport_t      *portp;
        int             i, panelnr, panelport;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
-#endif
-
        for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
                portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
                if (!portp) {
@@ -3236,7 +2910,7 @@ static int stli_initports(stlibrd_t *brdp)
                brdp->ports[i] = portp;
        }
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -3249,10 +2923,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
-#endif
-
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
        udelay(10);
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3266,9 +2936,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
 
 static void stli_ecpenable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
-#endif
        outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
 }
 
@@ -3276,9 +2943,6 @@ static void stli_ecpenable(stlibrd_t *brdp)
 
 static void stli_ecpdisable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
-#endif
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
 }
 
@@ -3286,13 +2950,8 @@ static void stli_ecpdisable(stlibrd_t *brdp)
 
 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void            *ptr;
-       unsigned char   val;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
-               (int) offset);
-#endif
+       void *ptr;
+       unsigned char val;
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3312,10 +2971,6 @@ static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_ecpreset(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
        udelay(10);
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3326,9 +2981,6 @@ static void stli_ecpreset(stlibrd_t *brdp)
 
 static void stli_ecpintr(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
-#endif
        outb(0x1, brdp->iobase);
 }
 
@@ -3342,10 +2994,6 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
        outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
        udelay(10);
@@ -3379,11 +3027,6 @@ static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line
        void            *ptr;
        unsigned char   val;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
-               (int) brdp, (int) offset, line);
-#endif
-
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), brd=%d\n",
@@ -3433,8 +3076,8 @@ static void stli_ecpmcdisable(stlibrd_t *brdp)
 
 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void            *ptr;
-       unsigned char   val;
+       void *ptr;
+       unsigned char val;
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3468,10 +3111,6 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
 
 static void stli_ecppciinit(stlibrd_t *brdp)
 {
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
        udelay(10);
        outb(0, (brdp->iobase + ECP_PCICONFR));
@@ -3485,11 +3124,6 @@ static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int lin
        void            *ptr;
        unsigned char   val;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
-               (int) brdp, (int) offset, line);
-#endif
-
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), board=%d\n",
@@ -3524,10 +3158,6 @@ static void stli_onbinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
-#endif
-
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
        udelay(10);
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3543,9 +3173,6 @@ static void stli_onbinit(stlibrd_t *brdp)
 
 static void stli_onbenable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
-#endif
        outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
 }
 
@@ -3553,9 +3180,6 @@ static void stli_onbenable(stlibrd_t *brdp)
 
 static void stli_onbdisable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
-#endif
        outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
 }
 
@@ -3565,11 +3189,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
        void    *ptr;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
-               (int) offset);
-#endif
-
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), brd=%d\n",
@@ -3585,11 +3204,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_onbreset(stlibrd_t *brdp)
 {      
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
        udelay(10);
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3606,10 +3220,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
-#endif
-
        outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
        udelay(10);
@@ -3628,9 +3238,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
 
 static void stli_onbeenable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
-#endif
        outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
 }
 
@@ -3638,9 +3245,6 @@ static void stli_onbeenable(stlibrd_t *brdp)
 
 static void stli_onbedisable(stlibrd_t *brdp)
 {      
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
-#endif
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
 }
 
@@ -3648,13 +3252,8 @@ static void stli_onbedisable(stlibrd_t *brdp)
 
 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void            *ptr;
-       unsigned char   val;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
-               (int) brdp, (int) offset, line);
-#endif
+       void *ptr;
+       unsigned char val;
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3677,11 +3276,6 @@ static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_onbereset(stlibrd_t *brdp)
 {      
-
-#ifdef DEBUG
-       printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
        udelay(10);
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
@@ -3696,11 +3290,6 @@ static void stli_onbereset(stlibrd_t *brdp)
 
 static void stli_bbyinit(stlibrd_t *brdp)
 {
-
-#ifdef DEBUG
-       printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
-#endif
-
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
        udelay(10);
        outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3713,24 +3302,13 @@ static void stli_bbyinit(stlibrd_t *brdp)
 
 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void            *ptr;
-       unsigned char   val;
+       void *ptr;
+       unsigned char val;
 
-#ifdef DEBUG
-       printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
-               (int) offset);
-#endif
+       BUG_ON(offset > brdp->memsize);
 
-       if (offset > brdp->memsize) {
-               printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
-                               "range at line=%d(%d), brd=%d\n",
-                               (int) offset, line, __LINE__, brdp->brdnr);
-               ptr = NULL;
-               val = 0;
-       } else {
-               ptr = brdp->membase + (offset % BBY_PAGESIZE);
-               val = (unsigned char) (offset / BBY_PAGESIZE);
-       }
+       ptr = brdp->membase + (offset % BBY_PAGESIZE);
+       val = (unsigned char) (offset / BBY_PAGESIZE);
        outb(val, (brdp->iobase + BBY_ATCONFR));
        return(ptr);
 }
@@ -3739,11 +3317,6 @@ static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_bbyreset(stlibrd_t *brdp)
 {      
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
-#endif
-
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
        udelay(10);
        outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3758,11 +3331,6 @@ static void stli_bbyreset(stlibrd_t *brdp)
 
 static void stli_stalinit(stlibrd_t *brdp)
 {
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
-#endif
-
        outb(0x1, brdp->iobase);
        mdelay(1000);
 }
@@ -3771,36 +3339,18 @@ static void stli_stalinit(stlibrd_t *brdp)
 
 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void    *ptr;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
-               (int) offset);
-#endif
-
-       if (offset > brdp->memsize) {
-               printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
-                               "range at line=%d(%d), brd=%d\n",
-                               (int) offset, line, __LINE__, brdp->brdnr);
-               ptr = NULL;
-       } else {
-               ptr = brdp->membase + (offset % STAL_PAGESIZE);
-       }
-       return(ptr);
+       BUG_ON(offset > brdp->memsize);
+       return brdp->membase + (offset % STAL_PAGESIZE);
 }
 
 /*****************************************************************************/
 
 static void stli_stalreset(stlibrd_t *brdp)
 {      
-       volatile unsigned long  *vecp;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
-#endif
+       u32 __iomem *vecp;
 
-       vecp = (volatile unsigned long *) (brdp->membase + 0x30);
-       *vecp = 0xffff0000;
+       vecp = (u32 __iomem *) (brdp->membase + 0x30);
+       writel(0xffff0000, vecp);
        outb(0, brdp->iobase);
        mdelay(1000);
 }
@@ -3814,15 +3364,11 @@ static void stli_stalreset(stlibrd_t *brdp)
 
 static int stli_initecp(stlibrd_t *brdp)
 {
-       cdkecpsig_t     sig;
-       cdkecpsig_t     *sigsp;
-       unsigned int    status, nxtid;
-       char            *name;
-       int             panelnr, nrports;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
-#endif
+       cdkecpsig_t sig;
+       cdkecpsig_t __iomem *sigsp;
+       unsigned int status, nxtid;
+       char *name;
+       int panelnr, nrports;
 
        if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
                return -EIO;
@@ -3830,7 +3376,7 @@ static int stli_initecp(stlibrd_t *brdp)
        if ((brdp->iobase == 0) || (brdp->memaddr == 0))
        {
                release_region(brdp->iobase, brdp->iosize);
-               return(-ENODEV);
+               return -ENODEV;
        }
 
        brdp->iosize = ECP_IOSIZE;
@@ -3899,7 +3445,7 @@ static int stli_initecp(stlibrd_t *brdp)
 
        default:
                release_region(brdp->iobase, brdp->iosize);
-               return(-EINVAL);
+               return -EINVAL;
        }
 
 /*
@@ -3911,10 +3457,10 @@ static int stli_initecp(stlibrd_t *brdp)
        EBRDINIT(brdp);
 
        brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-       if (brdp->membase == (void *) NULL)
+       if (brdp->membase == NULL)
        {
                release_region(brdp->iobase, brdp->iosize);
-               return(-ENOMEM);
+               return -ENOMEM;
        }
 
 /*
@@ -3923,23 +3469,14 @@ static int stli_initecp(stlibrd_t *brdp)
  *     this is, and what it is connected to it.
  */
        EBRDENABLE(brdp);
-       sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
-       memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
+       sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
+       memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
        EBRDDISABLE(brdp);
 
-#if 0
-       printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
-               __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
-               (int) sig.panelid[1], (int) sig.panelid[2],
-               (int) sig.panelid[3], (int) sig.panelid[4],
-               (int) sig.panelid[5], (int) sig.panelid[6],
-               (int) sig.panelid[7]);
-#endif
-
-       if (sig.magic != ECP_MAGIC)
+       if (sig.magic != cpu_to_le32(ECP_MAGIC))
        {
                release_region(brdp->iobase, brdp->iosize);
-               return(-ENODEV);
+               return -ENODEV;
        }
 
 /*
@@ -3963,7 +3500,7 @@ static int stli_initecp(stlibrd_t *brdp)
 
 
        brdp->state |= BST_FOUND;
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -3975,20 +3512,16 @@ static int stli_initecp(stlibrd_t *brdp)
 
 static int stli_initonb(stlibrd_t *brdp)
 {
-       cdkonbsig_t     sig;
-       cdkonbsig_t     *sigsp;
-       char            *name;
-       int             i;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
-#endif
+       cdkonbsig_t sig;
+       cdkonbsig_t __iomem *sigsp;
+       char *name;
+       int i;
 
 /*
  *     Do a basic sanity check on the IO and memory addresses.
  */
-       if ((brdp->iobase == 0) || (brdp->memaddr == 0))
-               return(-ENODEV);
+       if (brdp->iobase == 0 || brdp->memaddr == 0)
+               return -ENODEV;
 
        brdp->iosize = ONB_IOSIZE;
        
@@ -4006,7 +3539,6 @@ static int stli_initonb(stlibrd_t *brdp)
        case BRD_ONBOARD2:
        case BRD_ONBOARD2_32:
        case BRD_ONBOARDRS:
-               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = ONB_MEMSIZE;
                brdp->pagesize = ONB_ATPAGESIZE;
                brdp->init = stli_onbinit;
@@ -4024,7 +3556,6 @@ static int stli_initonb(stlibrd_t *brdp)
                break;
 
        case BRD_ONBOARDE:
-               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = ONB_EIMEMSIZE;
                brdp->pagesize = ONB_EIPAGESIZE;
                brdp->init = stli_onbeinit;
@@ -4040,7 +3571,6 @@ static int stli_initonb(stlibrd_t *brdp)
        case BRD_BRUMBY4:
        case BRD_BRUMBY8:
        case BRD_BRUMBY16:
-               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = BBY_MEMSIZE;
                brdp->pagesize = BBY_PAGESIZE;
                brdp->init = stli_bbyinit;
@@ -4054,7 +3584,6 @@ static int stli_initonb(stlibrd_t *brdp)
                break;
 
        case BRD_STALLION:
-               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = STAL_MEMSIZE;
                brdp->pagesize = STAL_PAGESIZE;
                brdp->init = stli_stalinit;
@@ -4069,7 +3598,7 @@ static int stli_initonb(stlibrd_t *brdp)
 
        default:
                release_region(brdp->iobase, brdp->iosize);
-               return(-EINVAL);
+               return -EINVAL;
        }
 
 /*
@@ -4081,10 +3610,10 @@ static int stli_initonb(stlibrd_t *brdp)
        EBRDINIT(brdp);
 
        brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-       if (brdp->membase == (void *) NULL)
+       if (brdp->membase == NULL)
        {
                release_region(brdp->iobase, brdp->iosize);
-               return(-ENOMEM);
+               return -ENOMEM;
        }
 
 /*
@@ -4093,21 +3622,17 @@ static int stli_initonb(stlibrd_t *brdp)
  *     this is, and how many ports.
  */
        EBRDENABLE(brdp);
-       sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
-       memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
+       sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
+       memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
        EBRDDISABLE(brdp);
 
-#if 0
-       printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
-               __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
-               sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
-#endif
-
-       if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
-           (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
+       if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
+           sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
+           sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
+           sig.magic3 != cpu_to_le16(ONB_MAGIC3))
        {
                release_region(brdp->iobase, brdp->iosize);
-               return(-ENODEV);
+               return -ENODEV;
        }
 
 /*
@@ -4128,7 +3653,7 @@ static int stli_initonb(stlibrd_t *brdp)
 
 
        brdp->state |= BST_FOUND;
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4141,31 +3666,25 @@ static int stli_initonb(stlibrd_t *brdp)
 
 static int stli_startbrd(stlibrd_t *brdp)
 {
-       volatile cdkhdr_t       *hdrp;
-       volatile cdkmem_t       *memp;
-       volatile cdkasy_t       *ap;
-       unsigned long           flags;
-       stliport_t              *portp;
-       int                     portnr, nrdevs, i, rc;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
-#endif
-
-       rc = 0;
-
-       save_flags(flags);
-       cli();
+       cdkhdr_t __iomem *hdrp;
+       cdkmem_t __iomem *memp;
+       cdkasy_t __iomem *ap;
+       unsigned long flags;
+       stliport_t *portp;
+       int portnr, nrdevs, i, rc = 0;
+       u32 memoff;
+
+       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
        nrdevs = hdrp->nrdevs;
 
 #if 0
        printk("%s(%d): CDK version %d.%d.%d --> "
                "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
-                __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
-                hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
-                (int) hdrp->slavep);
+                __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
+                readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
+                readl(&hdrp->slavep));
 #endif
 
        if (nrdevs < (brdp->nrports + 1)) {
@@ -4177,14 +3696,14 @@ static int stli_startbrd(stlibrd_t *brdp)
        brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
        brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
        brdp->bitsize = (nrdevs + 7) / 8;
-       memp = (volatile cdkmem_t *) hdrp->memp;
-       if (((unsigned long) memp) > brdp->memsize) {
+       memoff = readl(&hdrp->memp);
+       if (memoff > brdp->memsize) {
                printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
                rc = -EIO;
                goto stli_donestartup;
        }
-       memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
-       if (memp->dtype != TYP_ASYNCTRL) {
+       memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
+       if (readw(&memp->dtype) != TYP_ASYNCTRL) {
                printk(KERN_ERR "STALLION: no slave control device found\n");
                goto stli_donestartup;
        }
@@ -4196,19 +3715,19 @@ static int stli_startbrd(stlibrd_t *brdp)
  *     change pages while reading memory map.
  */
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
-               if (memp->dtype != TYP_ASYNC)
+               if (readw(&memp->dtype) != TYP_ASYNC)
                        break;
                portp = brdp->ports[portnr];
-               if (portp == (stliport_t *) NULL)
+               if (portp == NULL)
                        break;
                portp->devnr = i;
-               portp->addr = memp->offset;
+               portp->addr = readl(&memp->offset);
                portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
                portp->portidx = (unsigned char) (i / 8);
                portp->portbit = (unsigned char) (0x1 << (i % 8));
        }
 
-       hdrp->slavereq = 0xff;
+       writeb(0xff, &hdrp->slavereq);
 
 /*
  *     For each port setup a local copy of the RX and TX buffer offsets
@@ -4217,22 +3736,22 @@ static int stli_startbrd(stlibrd_t *brdp)
  */
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
                portp = brdp->ports[portnr];
-               if (portp == (stliport_t *) NULL)
+               if (portp == NULL)
                        break;
                if (portp->addr == 0)
                        break;
-               ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
-               if (ap != (volatile cdkasy_t *) NULL) {
-                       portp->rxsize = ap->rxq.size;
-                       portp->txsize = ap->txq.size;
-                       portp->rxoffset = ap->rxq.offset;
-                       portp->txoffset = ap->txq.offset;
+               ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+               if (ap != NULL) {
+                       portp->rxsize = readw(&ap->rxq.size);
+                       portp->txsize = readw(&ap->txq.size);
+                       portp->rxoffset = readl(&ap->rxq.offset);
+                       portp->txoffset = readl(&ap->txq.offset);
                }
        }
 
 stli_donestartup:
        EBRDDISABLE(brdp);
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 
        if (rc == 0)
                brdp->state |= BST_STARTED;
@@ -4243,7 +3762,7 @@ stli_donestartup:
                add_timer(&stli_timerlist);
        }
 
-       return(rc);
+       return rc;
 }
 
 /*****************************************************************************/
@@ -4254,10 +3773,6 @@ stli_donestartup:
 
 static int __init stli_brdinit(stlibrd_t *brdp)
 {
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
-#endif
-
        stli_brds[brdp->brdnr] = brdp;
 
        switch (brdp->brdtype) {
@@ -4285,11 +3800,11 @@ static int __init stli_brdinit(stlibrd_t *brdp)
        case BRD_ECHPCI:
                printk(KERN_ERR "STALLION: %s board type not supported in "
                                "this driver\n", stli_brdnames[brdp->brdtype]);
-               return(ENODEV);
+               return -ENODEV;
        default:
                printk(KERN_ERR "STALLION: board=%d is unknown board "
                                "type=%d\n", brdp->brdnr, brdp->brdtype);
-               return(ENODEV);
+               return -ENODEV;
        }
 
        if ((brdp->state & BST_FOUND) == 0) {
@@ -4297,7 +3812,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
                                "io=%x mem=%x\n",
                        stli_brdnames[brdp->brdtype], brdp->brdnr,
                        brdp->iobase, (int) brdp->memaddr);
-               return(ENODEV);
+               return -ENODEV;
        }
 
        stli_initports(brdp);
@@ -4305,7 +3820,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
                "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
                brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
                brdp->nrpanels, brdp->nrports);
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4317,14 +3832,10 @@ static int __init stli_brdinit(stlibrd_t *brdp)
 
 static int stli_eisamemprobe(stlibrd_t *brdp)
 {
-       cdkecpsig_t     ecpsig, *ecpsigp;
-       cdkonbsig_t     onbsig, *onbsigp;
+       cdkecpsig_t     ecpsig, __iomem *ecpsigp;
+       cdkonbsig_t     onbsig, __iomem *onbsigp;
        int             i, foundit;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
-#endif
-
 /*
  *     First up we reset the board, to get it into a known state. There
  *     is only 2 board types here we need to worry about. Don;t use the
@@ -4348,7 +3859,7 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
                mdelay(1);
                stli_onbeenable(brdp);
        } else {
-               return(-ENODEV);
+               return -ENODEV;
        }
 
        foundit = 0;
@@ -4360,25 +3871,24 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
  */
        for (i = 0; (i < stli_eisamempsize); i++) {
                brdp->memaddr = stli_eisamemprobeaddrs[i];
-               brdp->membase = (void *) brdp->memaddr;
                brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-               if (brdp->membase == (void *) NULL)
+               if (brdp->membase == NULL)
                        continue;
 
                if (brdp->brdtype == BRD_ECPE) {
-                       ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
+                       ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
                                CDK_SIGADDR, __LINE__);
-                       memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
-                       if (ecpsig.magic == ECP_MAGIC)
+                       memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
+                       if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
                                foundit = 1;
                } else {
-                       onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
+                       onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
                                CDK_SIGADDR, __LINE__);
-                       memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
-                       if ((onbsig.magic0 == ONB_MAGIC0) &&
-                           (onbsig.magic1 == ONB_MAGIC1) &&
-                           (onbsig.magic2 == ONB_MAGIC2) &&
-                           (onbsig.magic3 == ONB_MAGIC3))
+                       memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
+                       if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
+                           (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
+                           (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
+                           (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
                                foundit = 1;
                }
 
@@ -4402,9 +3912,9 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
                printk(KERN_ERR "STALLION: failed to probe shared memory "
                                "region for %s in EISA slot=%d\n",
                        stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
-               return(-ENODEV);
+               return -ENODEV;
        }
-       return(0);
+       return 0;
 }
 
 static int stli_getbrdnr(void)
@@ -4435,22 +3945,16 @@ static int stli_getbrdnr(void)
 
 static int stli_findeisabrds(void)
 {
-       stlibrd_t       *brdp;
-       unsigned int    iobase, eid;
-       int             i;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_findeisabrds()\n");
-#endif
+       stlibrd_t *brdp;
+       unsigned int iobase, eid;
+       int i;
 
 /*
- *     Firstly check if this is an EISA system. Do this by probing for
- *     the system board EISA ID. If this is not an EISA system then
+ *     Firstly check if this is an EISA system.  If this is not an EISA system then
  *     don't bother going any further!
  */
-       outb(0xff, 0xc80);
-       if (inb(0xc80) == 0xff)
-               return(0);
+       if (EISA_bus)
+               return 0;
 
 /*
  *     Looks like an EISA system, so go searching for EISA boards.
@@ -4468,7 +3972,7 @@ static int stli_findeisabrds(void)
  */
                for (i = 0; (i < STL_MAXBRDS); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == (stlibrd_t *) NULL)
+                       if (brdp == NULL)
                                continue;
                        if (brdp->iobase == iobase)
                                break;
@@ -4480,10 +3984,10 @@ static int stli_findeisabrds(void)
  *             We have found a Stallion board and it is not configured already.
  *             Allocate a board structure and initialize it.
  */
-               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
-                       return(-ENOMEM);
+               if ((brdp = stli_allocbrd()) == NULL)
+                       return -ENOMEM;
                if ((brdp->brdnr = stli_getbrdnr()) < 0)
-                       return(-ENOMEM);
+                       return -ENOMEM;
                eid = inb(iobase + 0xc82);
                if (eid == ECP_EISAID)
                        brdp->brdtype = BRD_ECPE;
@@ -4498,7 +4002,7 @@ static int stli_findeisabrds(void)
                stli_brdinit(brdp);
        }
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4519,32 +4023,18 @@ static int stli_findeisabrds(void)
 
 static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
 {
-       stlibrd_t       *brdp;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
-               brdtype, dev->bus->number, dev->devfn);
-#endif
+       stlibrd_t *brdp;
 
        if (pci_enable_device(devp))
-               return(-EIO);
-       if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
-               return(-ENOMEM);
+               return -EIO;
+       if ((brdp = stli_allocbrd()) == NULL)
+               return -ENOMEM;
        if ((brdp->brdnr = stli_getbrdnr()) < 0) {
                printk(KERN_INFO "STALLION: too many boards found, "
                        "maximum supported %d\n", STL_MAXBRDS);
-               return(0);
+               return 0;
        }
        brdp->brdtype = brdtype;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
-               pci_resource_start(devp, 0),
-               pci_resource_start(devp, 1),
-               pci_resource_start(devp, 2),
-               pci_resource_start(devp, 3));
-#endif
-
 /*
  *     We have all resources from the board, so lets setup the actual
  *     board structure now.
@@ -4553,7 +4043,7 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
        brdp->memaddr = pci_resource_start(devp, 2);
        stli_brdinit(brdp);
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4565,20 +4055,12 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
 
 static int stli_findpcibrds(void)
 {
-       struct pci_dev  *dev = NULL;
-       int             rc;
+       struct pci_dev *dev = NULL;
 
-#ifdef DEBUG
-       printk("stli_findpcibrds()\n");
-#endif
-
-       while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
-           PCI_DEVICE_ID_ECRA, dev))) {
-               if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
-                       return(rc);
+       while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
+               stli_initpcibrd(BRD_ECPPCI, dev);
        }
-
-       return(0);
+       return 0;
 }
 
 #endif
@@ -4591,17 +4073,16 @@ static int stli_findpcibrds(void)
 
 static stlibrd_t *stli_allocbrd(void)
 {
-       stlibrd_t       *brdp;
+       stlibrd_t *brdp;
 
        brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
        if (!brdp) {
                printk(KERN_ERR "STALLION: failed to allocate memory "
-                               "(size=%d)\n", sizeof(stlibrd_t));
+                               "(size=%Zd)\n", sizeof(stlibrd_t));
                return NULL;
        }
-
        brdp->magic = STLI_BOARDMAGIC;
-       return(brdp);
+       return brdp;
 }
 
 /*****************************************************************************/
@@ -4613,13 +4094,9 @@ static stlibrd_t *stli_allocbrd(void)
 
 static int stli_initbrds(void)
 {
-       stlibrd_t       *brdp, *nxtbrdp;
-       stlconf_t       *confp;
-       int             i, j;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_initbrds()\n");
-#endif
+       stlibrd_t *brdp, *nxtbrdp;
+       stlconf_t *confp;
+       int i, j;
 
        if (stli_nrbrds > STL_MAXBRDS) {
                printk(KERN_INFO "STALLION: too many boards in configuration "
@@ -4634,11 +4111,9 @@ static int stli_initbrds(void)
  */
        for (i = 0; (i < stli_nrbrds); i++) {
                confp = &stli_brdconf[i];
-#ifdef MODULE
                stli_parsebrd(confp, stli_brdsp[i]);
-#endif
-               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
-                       return(-ENOMEM);
+               if ((brdp = stli_allocbrd()) == NULL)
+                       return -ENOMEM;
                brdp->brdnr = i;
                brdp->brdtype = confp->brdtype;
                brdp->iobase = confp->ioaddr1;
@@ -4650,9 +4125,7 @@ static int stli_initbrds(void)
  *     Static configuration table done, so now use dynamic methods to
  *     see if any more boards should be configured.
  */
-#ifdef MODULE
        stli_argbrds();
-#endif
        if (STLI_EISAPROBE)
                stli_findeisabrds();
 #ifdef CONFIG_PCI
@@ -4668,11 +4141,11 @@ static int stli_initbrds(void)
        if (stli_nrbrds > 1) {
                for (i = 0; (i < stli_nrbrds); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == (stlibrd_t *) NULL)
+                       if (brdp == NULL)
                                continue;
                        for (j = i + 1; (j < stli_nrbrds); j++) {
                                nxtbrdp = stli_brds[j];
-                               if (nxtbrdp == (stlibrd_t *) NULL)
+                               if (nxtbrdp == NULL)
                                        continue;
                                if ((brdp->membase >= nxtbrdp->membase) &&
                                    (brdp->membase <= (nxtbrdp->membase +
@@ -4687,7 +4160,7 @@ static int stli_initbrds(void)
        if (stli_shared == 0) {
                for (i = 0; (i < stli_nrbrds); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == (stlibrd_t *) NULL)
+                       if (brdp == NULL)
                                continue;
                        if (brdp->state & BST_FOUND) {
                                EBRDENABLE(brdp);
@@ -4697,7 +4170,7 @@ static int stli_initbrds(void)
                }
        }
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4710,48 +4183,55 @@ static int stli_initbrds(void)
 
 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
 {
-       unsigned long   flags;
-       void            *memptr;
-       stlibrd_t       *brdp;
-       int             brdnr, size, n;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
-                       (int) fp, (int) buf, count, (int) offp);
-#endif
+       unsigned long flags;
+       void *memptr;
+       stlibrd_t *brdp;
+       int brdnr, size, n;
+       void *p;
+       loff_t off = *offp;
 
        brdnr = iminor(fp->f_dentry->d_inode);
        if (brdnr >= stli_nrbrds)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stli_brds[brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
        if (brdp->state == 0)
-               return(-ENODEV);
-       if (fp->f_pos >= brdp->memsize)
-               return(0);
+               return -ENODEV;
+       if (off >= brdp->memsize || off + count < off)
+               return 0;
 
-       size = MIN(count, (brdp->memsize - fp->f_pos));
+       size = MIN(count, (brdp->memsize - off));
+
+       /*
+        *      Copy the data a page at a time
+        */
+
+       p = (void *)__get_free_page(GFP_KERNEL);
+       if(p == NULL)
+               return -ENOMEM;
 
-       save_flags(flags);
-       cli();
-       EBRDENABLE(brdp);
        while (size > 0) {
-               memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
-               n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
-               if (copy_to_user(buf, memptr, n)) {
+               spin_lock_irqsave(&brd_lock, flags);
+               EBRDENABLE(brdp);
+               memptr = (void *) EBRDGETMEMPTR(brdp, off);
+               n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
+               n = MIN(n, PAGE_SIZE);
+               memcpy_fromio(p, memptr, n);
+               EBRDDISABLE(brdp);
+               spin_unlock_irqrestore(&brd_lock, flags);
+               if (copy_to_user(buf, p, n)) {
                        count = -EFAULT;
                        goto out;
                }
-               fp->f_pos += n;
+               off += n;
                buf += n;
                size -= n;
        }
 out:
-       EBRDDISABLE(brdp);
-       restore_flags(flags);
-
-       return(count);
+       *offp = off;
+       free_page((unsigned long)p);
+       return count;
 }
 
 /*****************************************************************************/
@@ -4760,54 +4240,65 @@ out:
  *     Code to handle an "staliomem" write operation. This device is the 
  *     contents of the board shared memory. It is used for down loading
  *     the slave image (and debugging :-)
+ *
+ *     FIXME: copy under lock
  */
 
 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
 {
-       unsigned long   flags;
-       void            *memptr;
-       stlibrd_t       *brdp;
-       char            __user *chbuf;
-       int             brdnr, size, n;
-
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
-                       (int) fp, (int) buf, count, (int) offp);
-#endif
+       unsigned long flags;
+       void *memptr;
+       stlibrd_t *brdp;
+       char __user *chbuf;
+       int brdnr, size, n;
+       void *p;
+       loff_t off = *offp;
 
        brdnr = iminor(fp->f_dentry->d_inode);
+
        if (brdnr >= stli_nrbrds)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stli_brds[brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
        if (brdp->state == 0)
-               return(-ENODEV);
-       if (fp->f_pos >= brdp->memsize)
-               return(0);
+               return -ENODEV;
+       if (off >= brdp->memsize || off + count < off)
+               return 0;
 
        chbuf = (char __user *) buf;
-       size = MIN(count, (brdp->memsize - fp->f_pos));
+       size = MIN(count, (brdp->memsize - off));
+
+       /*
+        *      Copy the data a page at a time
+        */
+
+       p = (void *)__get_free_page(GFP_KERNEL);
+       if(p == NULL)
+               return -ENOMEM;
 
-       save_flags(flags);
-       cli();
-       EBRDENABLE(brdp);
        while (size > 0) {
-               memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
-               n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
-               if (copy_from_user(memptr, chbuf, n)) {
-                       count = -EFAULT;
+               n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
+               n = MIN(n, PAGE_SIZE);
+               if (copy_from_user(p, chbuf, n)) {
+                       if (count == 0)
+                               count = -EFAULT;
                        goto out;
                }
-               fp->f_pos += n;
+               spin_lock_irqsave(&brd_lock, flags);
+               EBRDENABLE(brdp);
+               memptr = (void *) EBRDGETMEMPTR(brdp, off);
+               memcpy_toio(memptr, p, n);
+               EBRDDISABLE(brdp);
+               spin_unlock_irqrestore(&brd_lock, flags);
+               off += n;
                chbuf += n;
                size -= n;
        }
 out:
-       EBRDDISABLE(brdp);
-       restore_flags(flags);
-
-       return(count);
+       free_page((unsigned long) p);
+       *offp = off;
+       return count;
 }
 
 /*****************************************************************************/
@@ -4818,16 +4309,16 @@ out:
 
 static int stli_getbrdstats(combrd_t __user *bp)
 {
-       stlibrd_t       *brdp;
-       int             i;
+       stlibrd_t *brdp;
+       int i;
 
        if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
                return -EFAULT;
        if (stli_brdstats.brd >= STL_MAXBRDS)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stli_brds[stli_brdstats.brd];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
 
        memset(&stli_brdstats, 0, sizeof(combrd_t));
        stli_brdstats.brd = brdp->brdnr;
@@ -4846,7 +4337,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
 
        if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
                return -EFAULT;
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4857,19 +4348,19 @@ static int stli_getbrdstats(combrd_t __user *bp)
 
 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
 {
-       stlibrd_t       *brdp;
-       int             i;
+       stlibrd_t *brdp;
+       int i;
 
-       if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
-               return((stliport_t *) NULL);
+       if (brdnr < 0 || brdnr >= STL_MAXBRDS)
+               return NULL;
        brdp = stli_brds[brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return((stliport_t *) NULL);
+       if (brdp == NULL)
+               return NULL;
        for (i = 0; (i < panelnr); i++)
                portnr += brdp->panels[i];
        if ((portnr < 0) || (portnr >= brdp->nrports))
-               return((stliport_t *) NULL);
-       return(brdp->ports[portnr]);
+               return NULL;
+       return brdp->ports[portnr];
 }
 
 /*****************************************************************************/
@@ -4888,16 +4379,16 @@ static int stli_portcmdstats(stliport_t *portp)
 
        memset(&stli_comstats, 0, sizeof(comstats_t));
 
-       if (portp == (stliport_t *) NULL)
-               return(-ENODEV);
+       if (portp == NULL)
+               return -ENODEV;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == (stlibrd_t *) NULL)
-               return(-ENODEV);
+       if (brdp == NULL)
+               return -ENODEV;
 
        if (brdp->state & BST_STARTED) {
                if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
                    &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
-                       return(rc);
+                       return rc;
        } else {
                memset(&stli_cdkstats, 0, sizeof(asystats_t));
        }
@@ -4908,13 +4399,12 @@ static int stli_portcmdstats(stliport_t *portp)
        stli_comstats.state = portp->state;
        stli_comstats.flags = portp->flags;
 
-       save_flags(flags);
-       cli();
-       if (portp->tty != (struct tty_struct *) NULL) {
+       spin_lock_irqsave(&brd_lock, flags);
+       if (portp->tty != NULL) {
                if (portp->tty->driver_data == portp) {
                        stli_comstats.ttystate = portp->tty->flags;
-                       stli_comstats.rxbuffered = -1 /*portp->tty->flip.count*/;
-                       if (portp->tty->termios != (struct termios *) NULL) {
+                       stli_comstats.rxbuffered = -1;
+                       if (portp->tty->termios != NULL) {
                                stli_comstats.cflags = portp->tty->termios->c_cflag;
                                stli_comstats.iflags = portp->tty->termios->c_iflag;
                                stli_comstats.oflags = portp->tty->termios->c_oflag;
@@ -4922,7 +4412,7 @@ static int stli_portcmdstats(stliport_t *portp)
                        }
                }
        }
-       restore_flags(flags);
+       spin_unlock_irqrestore(&brd_lock, flags);
 
        stli_comstats.txtotal = stli_cdkstats.txchars;
        stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
@@ -4944,7 +4434,7 @@ static int stli_portcmdstats(stliport_t *portp)
        stli_comstats.hwid = stli_cdkstats.hwid;
        stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
 
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/
@@ -4957,8 +4447,8 @@ static int stli_portcmdstats(stliport_t *portp)
 
 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
 {
-       stlibrd_t       *brdp;
-       int             rc;
+       stlibrd_t *brdp;
+       int rc;
 
        if (!portp) {
                if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -4988,8 +4478,8 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
 
 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
 {
-       stlibrd_t       *brdp;
-       int             rc;
+       stlibrd_t *brdp;
+       int rc;
 
        if (!portp) {
                if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -5027,7 +4517,7 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
 
 static int stli_getportstruct(stliport_t __user *arg)
 {
-       stliport_t      *portp;
+       stliport_t *portp;
 
        if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
                return -EFAULT;
@@ -5048,7 +4538,7 @@ static int stli_getportstruct(stliport_t __user *arg)
 
 static int stli_getbrdstruct(stlibrd_t __user *arg)
 {
-       stlibrd_t       *brdp;
+       stlibrd_t *brdp;
 
        if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
                return -EFAULT;
@@ -5072,15 +4562,10 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
 
 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
 {
-       stlibrd_t       *brdp;
-       int             brdnr, rc, done;
+       stlibrd_t *brdp;
+       int brdnr, rc, done;
        void __user *argp = (void __user *)arg;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
-                       (int) ip, (int) fp, cmd, (int) arg);
-#endif
-
 /*
  *     First up handle the board independent ioctls.
  */
@@ -5111,7 +4596,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
        }
 
        if (done)
-               return(rc);
+               return rc;
 
 /*
  *     Now handle the board specific ioctls. These all depend on the
@@ -5119,12 +4604,12 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
  */
        brdnr = iminor(ip);
        if (brdnr >= STL_MAXBRDS)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stli_brds[brdnr];
        if (!brdp)
-               return(-ENODEV);
+               return -ENODEV;
        if (brdp->state == 0)
-               return(-ENODEV);
+               return -ENODEV;
 
        switch (cmd) {
        case STL_BINTR:
@@ -5148,11 +4633,10 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
                rc = -ENOIOCTLCMD;
                break;
        }
-
-       return(rc);
+       return rc;
 }
 
-static struct tty_operations stli_ops = {
+static const struct tty_operations stli_ops = {
        .open = stli_open,
        .close = stli_close,
        .write = stli_write,
@@ -5178,11 +4662,14 @@ static struct tty_operations stli_ops = {
 
 /*****************************************************************************/
 
-int __init stli_init(void)
+static int __init stli_init(void)
 {
        int i;
        printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
 
+       spin_lock_init(&stli_lock);
+       spin_lock_init(&brd_lock);
+
        stli_initbrds();
 
        stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -5192,10 +4679,6 @@ int __init stli_init(void)
 /*
  *     Allocate a temporary write buffer.
  */
-       stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
-       if (!stli_tmpwritebuf)
-               printk(KERN_ERR "STALLION: failed to allocate memory "
-                               "(size=%d)\n", STLI_TXBUFSIZE);
        stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
        if (!stli_txcookbuf)
                printk(KERN_ERR "STALLION: failed to allocate memory "
@@ -5234,7 +4717,7 @@ int __init stli_init(void)
                printk(KERN_ERR "STALLION: failed to register serial driver\n");
                return -EBUSY;
        }
-       return(0);
+       return 0;
 }
 
 /*****************************************************************************/