]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/stallion.c
Merge branch 'upstream-jgarzik' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-omap-h63xx.git] / drivers / char / stallion.c
index 87bda40be61aaf4db5c54e6cd646a20ae1ca3eaf..e45113a7a472f7f1035d3fd92b2909b237bd298b 100644 (file)
@@ -63,7 +63,7 @@
 #define        BRD_EASYIOPCI   28
 
 struct stlconf {
-       int             brdtype;
+       unsigned int    brdtype;
        int             ioaddr1;
        int             ioaddr2;
        unsigned long   memaddr;
@@ -120,15 +120,6 @@ static struct ktermios             stl_deftermios = {
        .c_ospeed       = 9600,
 };
 
-/*
- *     Define global stats structures. Not used often, and can be
- *     re-used for each stats call.
- */
-static comstats_t      stl_comstats;
-static combrd_t                stl_brdstats;
-static struct stlbrd           stl_dummybrd;
-static struct stlport  stl_dummyport;
-
 /*
  *     Define global place to put buffer overflow characters.
  */
@@ -200,7 +191,7 @@ static char *stl_brdnames[] = {
  *     load line. These allow for easy board definitions, and easy
  *     modification of the io, memory and irq resoucres.
  */
-static int     stl_nargs = 0;
+static unsigned int stl_nargs;
 static char    *board0[4];
 static char    *board1[4];
 static char    *board2[4];
@@ -632,20 +623,20 @@ static struct class *stallion_class;
 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
 {
        char    *sp;
-       int     i;
+       unsigned int i;
 
        pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
 
        if ((argp[0] == NULL) || (*argp[0] == 0))
                return 0;
 
-       for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
+       for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
                *sp = tolower(*sp);
 
-       for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
+       for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
                if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
                        break;
-       }
+
        if (i == ARRAY_SIZE(stl_brdstr)) {
                printk("STALLION: unknown board name, %s?\n", argp[0]);
                return 0;
@@ -694,8 +685,8 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
 {
        struct stlport  *portp;
        struct stlbrd   *brdp;
-       unsigned int    minordev;
-       int             brdnr, panelnr, portnr, rc;
+       unsigned int    minordev, brdnr, panelnr;
+       int             portnr, rc;
 
        pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
 
@@ -707,7 +698,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
        if (brdp == NULL)
                return -ENODEV;
        minordev = MINOR2PORT(minordev);
-       for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
+       for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
                if (brdp->panels[panelnr] == NULL)
                        break;
                if (minordev < brdp->panels[panelnr]->nrports) {
@@ -766,10 +757,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
  *     previous opens still in effect. If we are a normal serial device
  *     then also we might have to wait for carrier.
  */
-       if (!(filp->f_flags & O_NONBLOCK)) {
+       if (!(filp->f_flags & O_NONBLOCK))
                if ((rc = stl_waitcarrier(portp, filp)) != 0)
                        return rc;
-       }
+
        portp->flags |= ASYNC_NORMAL_ACTIVE;
 
        return 0;
@@ -813,9 +804,8 @@ static int stl_waitcarrier(struct stlport *portp, struct file *filp)
                        break;
                }
                if (((portp->flags & ASYNC_CLOSING) == 0) &&
-                   (doclocal || (portp->sigs & TIOCM_CD))) {
+                   (doclocal || (portp->sigs & TIOCM_CD)))
                        break;
-               }
                if (signal_pending(current)) {
                        rc = -ERESTARTSYS;
                        break;
@@ -1091,7 +1081,7 @@ static int stl_writeroom(struct tty_struct *tty)
 
        head = portp->tx.head;
        tail = portp->tx.tail;
-       return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
+       return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
 }
 
 /*****************************************************************************/
@@ -1261,10 +1251,9 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
                return -ENODEV;
 
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
-           (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
+           (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
                if (tty->flags & (1 << TTY_IO_ERROR))
                        return -EIO;
-       }
 
        rc = 0;
 
@@ -1538,7 +1527,7 @@ static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
        *sp = ' ';
        sp += cnt;
 
-       for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
+       for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++)
                *sp++ = ' ';
        if (cnt >= MAXLINE)
                pos[(MAXLINE - 2)] = '+';
@@ -1558,8 +1547,8 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
        struct stlbrd   *brdp;
        struct stlpanel *panelp;
        struct stlport  *portp;
-       int             brdnr, panelnr, portnr, totalport;
-       int             curoff, maxoff;
+       unsigned int    brdnr, panelnr, portnr;
+       int             totalport, curoff, maxoff;
        char            *pos;
 
        pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
@@ -1582,7 +1571,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
  *     We scan through for each board, panel and port. The offset is
  *     calculated on the fly, and irrelevant ports are skipped.
  */
-       for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
+       for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
                brdp = stl_brds[brdnr];
                if (brdp == NULL)
                        continue;
@@ -1596,7 +1585,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
                }
 
                totalport = brdnr * STL_MAXPORTS;
-               for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
+               for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
                        panelp = brdp->panels[panelnr];
                        if (panelp == NULL)
                                continue;
@@ -1608,7 +1597,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
                                continue;
                        }
 
-                       for (portnr = 0; (portnr < panelp->nrports); portnr++,
+                       for (portnr = 0; portnr < panelp->nrports; portnr++,
                            totalport++) {
                                portp = panelp->ports[portnr];
                                if (portp == NULL)
@@ -1626,7 +1615,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
 
 stl_readdone:
        *start = page;
-       return (pos - page);
+       return pos - page;
 }
 
 /*****************************************************************************/
@@ -1677,15 +1666,14 @@ static int stl_eiointr(struct stlbrd *brdp)
 static int stl_echatintr(struct stlbrd *brdp)
 {
        struct stlpanel *panelp;
-       unsigned int    ioaddr;
-       int             bnknr;
+       unsigned int    ioaddr, bnknr;
        int             handled = 0;
 
        outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
 
        while (inb(brdp->iostatus) & ECH_INTRPEND) {
                handled = 1;
-               for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
+               for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
                                panelp = brdp->bnk2panel[bnknr];
@@ -1708,13 +1696,12 @@ static int stl_echatintr(struct stlbrd *brdp)
 static int stl_echmcaintr(struct stlbrd *brdp)
 {
        struct stlpanel *panelp;
-       unsigned int    ioaddr;
-       int             bnknr;
+       unsigned int    ioaddr, bnknr;
        int             handled = 0;
 
        while (inb(brdp->iostatus) & ECH_INTRPEND) {
                handled = 1;
-               for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
+               for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
                                panelp = brdp->bnk2panel[bnknr];
@@ -1734,13 +1721,12 @@ static int stl_echmcaintr(struct stlbrd *brdp)
 static int stl_echpciintr(struct stlbrd *brdp)
 {
        struct stlpanel *panelp;
-       unsigned int    ioaddr;
-       int             bnknr, recheck;
+       unsigned int    ioaddr, bnknr, recheck;
        int             handled = 0;
 
        while (1) {
                recheck = 0;
-               for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
+               for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
                        outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -1765,13 +1751,12 @@ static int stl_echpciintr(struct stlbrd *brdp)
 static int stl_echpci64intr(struct stlbrd *brdp)
 {
        struct stlpanel *panelp;
-       unsigned int    ioaddr;
-       int             bnknr;
+       unsigned int    ioaddr, bnknr;
        int             handled = 0;
 
        while (inb(brdp->ioctrl) & 0x1) {
                handled = 1;
-               for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
+               for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
                        ioaddr = brdp->bnkstataddr[bnknr];
                        if (inb(ioaddr) & ECH_PNLINTRPEND) {
                                panelp = brdp->bnk2panel[bnknr];
@@ -1804,19 +1789,18 @@ static void stl_offintr(struct work_struct *work)
                return;
 
        lock_kernel();
-       if (test_bit(ASYI_TXLOW, &portp->istate)) {
+       if (test_bit(ASYI_TXLOW, &portp->istate))
                tty_wakeup(tty);
-       }
+
        if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
                clear_bit(ASYI_DCDCHANGE, &portp->istate);
                oldsigs = portp->sigs;
                portp->sigs = stl_getsignals(portp);
                if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
                        wake_up_interruptible(&portp->open_wait);
-               if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
+               if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
                        if (portp->flags & ASYNC_CHECK_CD)
                                tty_hangup(tty);        /* FIXME: module removal race here - AKPM */
-               }
        }
        unlock_kernel();
 }
@@ -1829,8 +1813,9 @@ static void stl_offintr(struct work_struct *work)
 
 static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
 {
-       struct stlport  *portp;
-       int             chipmask, i;
+       struct stlport *portp;
+       unsigned int i;
+       int chipmask;
 
        pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
 
@@ -1840,7 +1825,7 @@ static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
  *     All UART's are initialized (if found!). Now go through and setup
  *     each ports data structures.
  */
-       for (i = 0; (i < panelp->nrports); i++) {
+       for (i = 0; i < panelp->nrports; i++) {
                portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
                if (!portp) {
                        printk("STALLION: failed to allocate memory "
@@ -1867,7 +1852,7 @@ static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
                stl_portinit(brdp, panelp, portp);
        }
 
-       return(0);
+       return 0;
 }
 
 static void stl_cleanup_panels(struct stlbrd *brdp)
@@ -2055,8 +2040,8 @@ err:
 static int __devinit stl_initech(struct stlbrd *brdp)
 {
        struct stlpanel *panelp;
-       unsigned int    status, nxtid, ioaddr, conflict;
-       int             panelnr, banknr, i, retval;
+       unsigned int    status, nxtid, ioaddr, conflict, panelnr, banknr, i;
+       int             retval;
        char            *name;
 
        pr_debug("stl_initech(brdp=%p)\n", brdp);
@@ -2092,7 +2077,7 @@ static int __devinit stl_initech(struct stlbrd *brdp)
                outb((status | ECH_BRDRESET), brdp->ioaddr1);
                brdp->ioctrlval = ECH_INTENABLE |
                        ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
-               for (i = 0; (i < 10); i++)
+               for (i = 0; i < 10; i++)
                        outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
                brdp->iosize1 = 2;
                brdp->iosize2 = 32;
@@ -2180,7 +2165,7 @@ static int __devinit stl_initech(struct stlbrd *brdp)
        panelnr = 0;
        nxtid = 0;
 
-       for (i = 0; (i < STL_MAXPANELS); i++) {
+       for (i = 0; i < STL_MAXPANELS; i++) {
                if (brdp->brdtype == BRD_ECHPCI) {
                        outb(nxtid, brdp->ioctrl);
                        ioaddr = brdp->ioaddr2;
@@ -2213,9 +2198,8 @@ static int __devinit stl_initech(struct stlbrd *brdp)
                                brdp->bnkpageaddr[banknr] = nxtid;
                                brdp->bnkstataddr[banknr++] = ioaddr + 4 +
                                        ECH_PNLSTATUS;
-                       } else {
+                       } else
                                panelp->nrports = 8;
-                       }
                } else {
                        panelp->uartp = &stl_cd1400uart;
                        panelp->isr = stl_cd1400echintr;
@@ -2311,7 +2295,7 @@ static int __devinit stl_brdinit(struct stlbrd *brdp)
                goto err_free;
        }
 
-       for (i = 0; (i < STL_MAXPANELS); i++)
+       for (i = 0; i < STL_MAXPANELS; i++)
                if (brdp->panels[i] != NULL)
                        stl_initports(brdp, brdp->panels[i]);
 
@@ -2341,16 +2325,16 @@ err:
 
 static int __devinit stl_getbrdnr(void)
 {
-       int     i;
+       unsigned int i;
 
-       for (i = 0; (i < STL_MAXBRDS); i++) {
+       for (i = 0; i < STL_MAXBRDS; i++)
                if (stl_brds[i] == NULL) {
                        if (i >= stl_nrbrds)
                                stl_nrbrds = i + 1;
-                       return(i);
+                       return i;
                }
-       }
-       return(-1);
+
+       return -1;
 }
 
 /*****************************************************************************/
@@ -2364,8 +2348,8 @@ static int __devinit stl_pciprobe(struct pci_dev *pdev,
                const struct pci_device_id *ent)
 {
        struct stlbrd *brdp;
-       unsigned int brdtype = ent->driver_data;
-       int retval = -ENODEV;
+       unsigned int i, brdtype = ent->driver_data;
+       int brdnr, retval = -ENODEV;
 
        if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
                goto err;
@@ -2382,13 +2366,14 @@ static int __devinit stl_pciprobe(struct pci_dev *pdev,
                goto err;
        }
        mutex_lock(&stl_brdslock);
-       brdp->brdnr = stl_getbrdnr();
-       if (brdp->brdnr < 0) {
+       brdnr = stl_getbrdnr();
+       if (brdnr < 0) {
                dev_err(&pdev->dev, "too many boards found, "
                        "maximum supported %d\n", STL_MAXBRDS);
                mutex_unlock(&stl_brdslock);
                goto err_fr;
        }
+       brdp->brdnr = (unsigned int)brdnr;
        stl_brds[brdp->brdnr] = brdp;
        mutex_unlock(&stl_brdslock);
 
@@ -2424,6 +2409,10 @@ static int __devinit stl_pciprobe(struct pci_dev *pdev,
 
        pci_set_drvdata(pdev, brdp);
 
+       for (i = 0; i < brdp->nrports; i++)
+               tty_register_device(stl_serial,
+                               brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
+
        return 0;
 err_null:
        stl_brds[brdp->brdnr] = NULL;
@@ -2436,6 +2425,7 @@ err:
 static void __devexit stl_pciremove(struct pci_dev *pdev)
 {
        struct stlbrd *brdp = pci_get_drvdata(pdev);
+       unsigned int i;
 
        free_irq(brdp->irq, brdp);
 
@@ -2445,6 +2435,10 @@ static void __devexit stl_pciremove(struct pci_dev *pdev)
        if (brdp->iosize2 > 0)
                release_region(brdp->ioaddr2, brdp->iosize2);
 
+       for (i = 0; i < brdp->nrports; i++)
+               tty_unregister_device(stl_serial,
+                               brdp->brdnr * STL_MAXPORTS + i);
+
        stl_brds[brdp->brdnr] = NULL;
        kfree(brdp);
 }
@@ -2464,17 +2458,18 @@ static struct pci_driver stl_pcidriver = {
 
 static int stl_getbrdstats(combrd_t __user *bp)
 {
+       combrd_t        stl_brdstats;
        struct stlbrd   *brdp;
        struct stlpanel *panelp;
-       int             i;
+       unsigned int i;
 
        if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
                return -EFAULT;
        if (stl_brdstats.brd >= STL_MAXBRDS)
-               return(-ENODEV);
+               return -ENODEV;
        brdp = stl_brds[stl_brdstats.brd];
        if (brdp == NULL)
-               return(-ENODEV);
+               return -ENODEV;
 
        memset(&stl_brdstats, 0, sizeof(combrd_t));
        stl_brdstats.brd = brdp->brdnr;
@@ -2486,7 +2481,7 @@ static int stl_getbrdstats(combrd_t __user *bp)
        stl_brdstats.irq = brdp->irq;
        stl_brdstats.nrpanels = brdp->nrpanels;
        stl_brdstats.nrports = brdp->nrports;
-       for (i = 0; (i < brdp->nrpanels); i++) {
+       for (i = 0; i < brdp->nrpanels; i++) {
                panelp = brdp->panels[i];
                stl_brdstats.panels[i].panel = i;
                stl_brdstats.panels[i].hwid = panelp->hwid;
@@ -2507,19 +2502,19 @@ static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
        struct stlbrd   *brdp;
        struct stlpanel *panelp;
 
-       if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
-               return(NULL);
+       if (brdnr < 0 || brdnr >= STL_MAXBRDS)
+               return NULL;
        brdp = stl_brds[brdnr];
        if (brdp == NULL)
-               return(NULL);
-       if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
-               return(NULL);
+               return NULL;
+       if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
+               return NULL;
        panelp = brdp->panels[panelnr];
        if (panelp == NULL)
-               return(NULL);
-       if ((portnr < 0) || (portnr >= panelp->nrports))
-               return(NULL);
-       return(panelp->ports[portnr]);
+               return NULL;
+       if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
+               return NULL;
+       return panelp->ports[portnr];
 }
 
 /*****************************************************************************/
@@ -2532,6 +2527,7 @@ static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
 
 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
 {
+       comstats_t      stl_comstats;
        unsigned char   *head, *tail;
        unsigned long   flags;
 
@@ -2541,7 +2537,7 @@ static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
                portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
                        stl_comstats.port);
                if (portp == NULL)
-                       return(-ENODEV);
+                       return -ENODEV;
        }
 
        portp->stats.state = portp->istate;
@@ -2556,7 +2552,7 @@ static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
        portp->stats.rxbuffered = 0;
 
        spin_lock_irqsave(&stallion_lock, flags);
-       if (portp->tty != NULL) {
+       if (portp->tty != NULL)
                if (portp->tty->driver_data == portp) {
                        portp->stats.ttystate = portp->tty->flags;
                        /* No longer available as a statistic */
@@ -2568,13 +2564,12 @@ static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
                                portp->stats.lflags = portp->tty->termios->c_lflag;
                        }
                }
-       }
        spin_unlock_irqrestore(&stallion_lock, flags);
 
        head = portp->tx.head;
        tail = portp->tx.tail;
-       portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
-               (STL_TXBUFSIZE - (tail - head)));
+       portp->stats.txbuffered = (head >= tail) ? (head - tail) :
+               (STL_TXBUFSIZE - (tail - head));
 
        portp->stats.signals = (unsigned long) stl_getsignals(portp);
 
@@ -2590,13 +2585,15 @@ static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
 
 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
 {
+       comstats_t      stl_comstats;
+
        if (!portp) {
                if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
                        return -EFAULT;
                portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
                        stl_comstats.port);
                if (portp == NULL)
-                       return(-ENODEV);
+                       return -ENODEV;
        }
 
        memset(&portp->stats, 0, sizeof(comstats_t));
@@ -2615,6 +2612,7 @@ static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
 
 static int stl_getportstruct(struct stlport __user *arg)
 {
+       struct stlport  stl_dummyport;
        struct stlport  *portp;
 
        if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
@@ -2634,15 +2632,16 @@ static int stl_getportstruct(struct stlport __user *arg)
 
 static int stl_getbrdstruct(struct stlbrd __user *arg)
 {
+       struct stlbrd   stl_dummybrd;
        struct stlbrd   *brdp;
 
        if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
                return -EFAULT;
-       if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
+       if (stl_dummybrd.brdnr >= STL_MAXBRDS)
                return -ENODEV;
        brdp = stl_brds[stl_dummybrd.brdnr];
        if (!brdp)
-               return(-ENODEV);
+               return -ENODEV;
        return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
 }
 
@@ -2663,7 +2662,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
 
        brdnr = iminor(ip);
        if (brdnr >= STL_MAXBRDS)
-               return(-ENODEV);
+               return -ENODEV;
        rc = 0;
 
        switch (cmd) {
@@ -2687,7 +2686,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
                break;
        }
 
-       return(rc);
+       return rc;
 }
 
 static const struct tty_operations stl_ops = {
@@ -2732,13 +2731,13 @@ static int stl_cd1400getreg(struct stlport *portp, int regnr)
 
 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
 {
-       outb((regnr + portp->uartaddr), portp->ioaddr);
+       outb(regnr + portp->uartaddr, portp->ioaddr);
        outb(value, portp->ioaddr + EREG_DATA);
 }
 
 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
 {
-       outb((regnr + portp->uartaddr), portp->ioaddr);
+       outb(regnr + portp->uartaddr, portp->ioaddr);
        if (inb(portp->ioaddr + EREG_DATA) != value) {
                outb(value, portp->ioaddr + EREG_DATA);
                return 1;
@@ -2771,13 +2770,12 @@ static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
  */
        chipmask = 0;
        nrchips = panelp->nrports / CD1400_PORTS;
-       for (i = 0; (i < nrchips); i++) {
+       for (i = 0; i < nrchips; i++) {
                if (brdp->brdtype == BRD_ECHPCI) {
                        outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
                        ioaddr = panelp->iobase;
-               } else {
+               } else
                        ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
-               }
                uartaddr = (i & 0x01) ? 0x080 : 0;
                outb((GFRCR + uartaddr), ioaddr);
                outb(0, (ioaddr + EREG_DATA));
@@ -2785,10 +2783,10 @@ static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
                outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
                outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
                outb((GFRCR + uartaddr), ioaddr);
-               for (j = 0; (j < CCR_MAXWAIT); j++) {
+               for (j = 0; j < CCR_MAXWAIT; j++)
                        if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
                                break;
-               }
+
                if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
                        printk("STALLION: cd1400 not responding, "
                                "brd=%d panel=%d chip=%d\n",
@@ -2846,11 +2844,9 @@ static void stl_cd1400ccrwait(struct stlport *portp)
 {
        int     i;
 
-       for (i = 0; (i < CCR_MAXWAIT); i++) {
-               if (stl_cd1400getreg(portp, CCR) == 0) {
+       for (i = 0; i < CCR_MAXWAIT; i++)
+               if (stl_cd1400getreg(portp, CCR) == 0)
                        return;
-               }
-       }
 
        printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
                portp->portnr, portp->panelnr, portp->brdnr);
@@ -2986,8 +2982,8 @@ static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
                baudrate = STL_CD1400MAXBAUD;
 
        if (baudrate > 0) {
-               for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
-                       clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
+               for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
+                       clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
                        if (clkdiv < 0x100)
                                break;
                }
@@ -3002,9 +2998,8 @@ static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
                mcor2 |= MCOR2_DCD;
                sreron |= SRER_MODEM;
                portp->flags |= ASYNC_CHECK_CD;
-       } else {
+       } else
                portp->flags &= ~ASYNC_CHECK_CD;
-       }
 
 /*
  *     Setup cd1400 enhanced modes if we can. In particular we want to
@@ -3648,18 +3643,16 @@ static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
                                                do_SAK(tty);
                                                BRDENABLE(portp->brdnr, portp->pagenr);
                                        }
-                               } else if (status & ST_PARITY) {
+                               } else if (status & ST_PARITY)
                                        status = TTY_PARITY;
-                               } else if (status & ST_FRAMING) {
+                               else if (status & ST_FRAMING)
                                        status = TTY_FRAME;
-                               } else if(status & ST_OVERRUN) {
+                               else if(status & ST_OVERRUN)
                                        status = TTY_OVERRUN;
-                               } else {
+                               else
                                        status = 0;
-                               }
-                       } else {
+                       } else
                                status = 0;
-                       }
                        tty_insert_flip_char(tty, ch, status);
                        tty_schedule_flip(tty);
                }
@@ -3786,7 +3779,7 @@ static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
        if (brdp->brdtype == BRD_ECHPCI)
                outb(panelp->pagenr, brdp->ioctrl);
 
-       for (i = 0; (i < nrchips); i++) {
+       for (i = 0; i < nrchips; i++) {
                ioaddr = panelp->iobase + (i * 4); 
                outb(SCCR, (ioaddr + XP_ADDR));
                outb(CR_RESETALL, (ioaddr + XP_DATA));
@@ -3906,9 +3899,8 @@ static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
                        mr1 |= (MR1_PARENB | MR1_PARODD);
                else
                        mr1 |= (MR1_PARENB | MR1_PAREVEN);
-       } else {
+       } else
                mr1 |= MR1_PARNONE;
-       }
 
        mr1 |= MR1_ERRBLOCK;
 
@@ -3948,12 +3940,10 @@ static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
        if (baudrate > STL_SC26198MAXBAUD)
                baudrate = STL_SC26198MAXBAUD;
 
-       if (baudrate > 0) {
-               for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
+       if (baudrate > 0)
+               for (clk = 0; clk < SC26198_NRBAUDS; clk++)
                        if (baudrate <= sc26198_baudtable[clk])
                                break;
-               }
-       }
 
 /*
  *     Check what form of modem signaling is required and set it up.
@@ -3975,9 +3965,9 @@ static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
        if (tiosp->c_iflag & IXON) {
                mr0 |= MR0_SWFTX | MR0_SWFT;
                imron |= IR_XONXOFF;
-       } else {
+       } else
                imroff |= IR_XONXOFF;
-       }
+
        if (tiosp->c_iflag & IXOFF)
                mr0 |= MR0_SWFRX;
 
@@ -4188,9 +4178,9 @@ static void stl_sc26198sendbreak(struct stlport *portp, int len)
        if (len == 1) {
                stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
                portp->stats.txbreaks++;
-       } else {
+       } else
                stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
-       }
+
        BRDDISABLE(portp->brdnr);
        spin_unlock_irqrestore(&brd_lock, flags);
 }
@@ -4374,7 +4364,7 @@ static void stl_sc26198wait(struct stlport *portp)
        if (portp == NULL)
                return;
 
-       for (i = 0; (i < 20); i++)
+       for (i = 0; i < 20; i++)
                stl_sc26198getglobreg(portp, TSTR);
 }
 
@@ -4583,18 +4573,16 @@ static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char
                                        do_SAK(tty);
                                        BRDENABLE(portp->brdnr, portp->pagenr);
                                }
-                       } else if (status & SR_RXPARITY) {
+                       } else if (status & SR_RXPARITY)
                                status = TTY_PARITY;
-                       } else if (status & SR_RXFRAMING) {
+                       else if (status & SR_RXFRAMING)
                                status = TTY_FRAME;
-                       } else if(status & SR_RXOVERRUN) {
+                       else if(status & SR_RXOVERRUN)
                                status = TTY_OVERRUN;
-                       } else {
+                       else
                                status = 0;
-                       }
-               } else {
+               } else
                        status = 0;
-               }
 
                tty_insert_flip_char(tty, ch, status);
                tty_schedule_flip(tty);
@@ -4714,7 +4702,7 @@ static int __init stallion_module_init(void)
 {
        struct stlbrd   *brdp;
        struct stlconf  conf;
-       unsigned int i;
+       unsigned int i, j;
        int retval;
 
        printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
@@ -4741,6 +4729,9 @@ static int __init stallion_module_init(void)
                if (stl_brdinit(brdp))
                        kfree(brdp);
                else {
+                       for (j = 0; j < brdp->nrports; j++)
+                               tty_register_device(stl_serial,
+                                       brdp->brdnr * STL_MAXPORTS + j, NULL);
                        stl_brds[brdp->brdnr] = brdp;
                        stl_nrbrds = i + 1;
                }
@@ -4782,7 +4773,7 @@ static int __init stallion_module_init(void)
        stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
        stl_serial->subtype = SERIAL_TYPE_NORMAL;
        stl_serial->init_termios = stl_deftermios;
-       stl_serial->flags = TTY_DRIVER_REAL_RAW;
+       stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
        tty_set_operations(stl_serial, &stl_ops);
 
        retval = tty_register_driver(stl_serial);
@@ -4808,7 +4799,9 @@ err:
 
 static void __exit stallion_module_exit(void)
 {
-       int             i;
+       struct stlbrd *brdp;
+       unsigned int i, j;
+       int retval;
 
        pr_debug("cleanup_module()\n");
 
@@ -4821,14 +4814,21 @@ static void __exit stallion_module_exit(void)
  *     a hangup on every open port - to try to flush out any processes
  *     hanging onto ports.
  */
+       for (i = 0; i < stl_nrbrds; i++) {
+               if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
+                       continue;
+               for (j = 0; j < brdp->nrports; j++)
+                       tty_unregister_device(stl_serial,
+                               brdp->brdnr * STL_MAXPORTS + j);
+       }
        tty_unregister_driver(stl_serial);
        put_tty_driver(stl_serial);
 
        for (i = 0; i < 4; i++)
                class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
-       if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
+       if ((retval = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
                printk("STALLION: failed to un-register serial memory device, "
-                       "errno=%d\n", -i);
+                       "errno=%d\n", -retval);
        class_destroy(stallion_class);
 
        pci_unregister_driver(&stl_pcidriver);